1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { z as zod } from '../../mcpBundle';
import type * as z from 'zod';
const modifiersSchema = zod.array(
zod.enum(['Alt', 'Control', 'ControlOrMeta', 'Meta', 'Shift'])
);
const navigateActionSchema = zod.object({
method: zod.literal('navigate'),
url: zod.string(),
});
export type NavigateAction = z.infer<typeof navigateActionSchema>;
const clickActionSchema = zod.object({
method: zod.literal('click'),
selector: zod.string(),
button: zod.enum(['left', 'right', 'middle']).optional(),
clickCount: zod.number().optional(),
modifiers: modifiersSchema.optional(),
});
export type ClickAction = z.infer<typeof clickActionSchema>;
const dragActionSchema = zod.object({
method: zod.literal('drag'),
sourceSelector: zod.string(),
targetSelector: zod.string(),
});
export type DragAction = z.infer<typeof dragActionSchema>;
const hoverActionSchema = zod.object({
method: zod.literal('hover'),
selector: zod.string(),
modifiers: modifiersSchema.optional(),
});
export type HoverAction = z.infer<typeof hoverActionSchema>;
const selectOptionActionSchema = zod.object({
method: zod.literal('selectOption'),
selector: zod.string(),
labels: zod.array(zod.string()),
});
export type SelectOptionAction = z.infer<typeof selectOptionActionSchema>;
const pressActionSchema = zod.object({
method: zod.literal('pressKey'),
key: zod.string(),
});
export type PressAction = z.infer<typeof pressActionSchema>;
const pressSequentiallyActionSchema = zod.object({
method: zod.literal('pressSequentially'),
selector: zod.string(),
text: zod.string(),
submit: zod.boolean().optional(),
});
export type PressSequentiallyAction = z.infer<typeof pressSequentiallyActionSchema>;
const fillActionSchema = zod.object({
method: zod.literal('fill'),
selector: zod.string(),
text: zod.string(),
submit: zod.boolean().optional(),
});
export type FillAction = z.infer<typeof fillActionSchema>;
const setCheckedSchema = zod.object({
method: zod.literal('setChecked'),
selector: zod.string(),
checked: zod.boolean(),
});
export type SetChecked = z.infer<typeof setCheckedSchema>;
const expectVisibleSchema = zod.object({
method: zod.literal('expectVisible'),
selector: zod.string(),
isNot: zod.boolean().optional(),
});
export type ExpectVisible = z.infer<typeof expectVisibleSchema>;
const expectValueSchema = zod.object({
method: zod.literal('expectValue'),
selector: zod.string(),
type: zod.enum(['textbox', 'checkbox', 'radio', 'combobox', 'slider']),
value: zod.string(),
isNot: zod.boolean().optional(),
});
export type ExpectValue = z.infer<typeof expectValueSchema>;
const expectAriaSchema = zod.object({
method: zod.literal('expectAria'),
template: zod.string(),
isNot: zod.boolean().optional(),
});
export type ExpectAria = z.infer<typeof expectAriaSchema>;
const expectURLSchema = zod.object({
method: zod.literal('expectURL'),
value: zod.string().optional(),
regex: zod.string().optional(),
isNot: zod.boolean().optional(),
});
export type ExpectURL = z.infer<typeof expectURLSchema>;
const actionSchema = zod.discriminatedUnion('method', [
navigateActionSchema,
clickActionSchema,
dragActionSchema,
hoverActionSchema,
selectOptionActionSchema,
pressActionSchema,
pressSequentiallyActionSchema,
fillActionSchema,
setCheckedSchema,
expectVisibleSchema,
expectValueSchema,
expectAriaSchema,
expectURLSchema,
]);
export type Action = z.infer<typeof actionSchema>;
const actionWithCodeSchema = actionSchema.and(zod.object({
code: zod.string(),
}));
export type ActionWithCode = z.infer<typeof actionWithCodeSchema>;
export const cachedActionsSchema = zod.record(zod.string(), zod.object({
actions: zod.array(actionWithCodeSchema),
}));
export type CachedActions = z.infer<typeof cachedActionsSchema>;