playwright-mimic 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +446 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/mimic.d.ts +26 -0
- package/dist/mimic.d.ts.map +1 -0
- package/dist/mimic.js +71 -0
- package/dist/mimic.js.map +1 -0
- package/dist/mimicry/actionType.d.ts +6 -0
- package/dist/mimicry/actionType.d.ts.map +1 -0
- package/dist/mimicry/actionType.js +32 -0
- package/dist/mimicry/actionType.js.map +1 -0
- package/dist/mimicry/click.d.ts +20 -0
- package/dist/mimicry/click.d.ts.map +1 -0
- package/dist/mimicry/click.js +152 -0
- package/dist/mimicry/click.js.map +1 -0
- package/dist/mimicry/forms.d.ts +31 -0
- package/dist/mimicry/forms.d.ts.map +1 -0
- package/dist/mimicry/forms.js +154 -0
- package/dist/mimicry/forms.js.map +1 -0
- package/dist/mimicry/navigation.d.ts +6 -0
- package/dist/mimicry/navigation.d.ts.map +1 -0
- package/dist/mimicry/navigation.js +52 -0
- package/dist/mimicry/navigation.js.map +1 -0
- package/dist/mimicry/schema/action.d.ts +312 -0
- package/dist/mimicry/schema/action.d.ts.map +1 -0
- package/dist/mimicry/schema/action.js +194 -0
- package/dist/mimicry/schema/action.js.map +1 -0
- package/dist/mimicry/selector.d.ts +118 -0
- package/dist/mimicry/selector.d.ts.map +1 -0
- package/dist/mimicry/selector.js +682 -0
- package/dist/mimicry/selector.js.map +1 -0
- package/dist/mimicry.d.ts +24 -0
- package/dist/mimicry.d.ts.map +1 -0
- package/dist/mimicry.js +71 -0
- package/dist/mimicry.js.map +1 -0
- package/dist/utils/token-counter.d.ts +63 -0
- package/dist/utils/token-counter.d.ts.map +1 -0
- package/dist/utils/token-counter.js +171 -0
- package/dist/utils/token-counter.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Shared: identifiers and primitive helpers
|
|
4
|
+
*/
|
|
5
|
+
export declare const zPoint: z.ZodObject<{
|
|
6
|
+
x: z.ZodNumber;
|
|
7
|
+
y: z.ZodNumber;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
export declare const zMouseButton: z.ZodEnum<{
|
|
10
|
+
left: "left";
|
|
11
|
+
middle: "middle";
|
|
12
|
+
right: "right";
|
|
13
|
+
}>;
|
|
14
|
+
export declare const zModifierKeys: z.ZodDefault<z.ZodArray<z.ZodEnum<{
|
|
15
|
+
Alt: "Alt";
|
|
16
|
+
Control: "Control";
|
|
17
|
+
Meta: "Meta";
|
|
18
|
+
Shift: "Shift";
|
|
19
|
+
}>>>;
|
|
20
|
+
export declare const zFrameDescription: z.ZodObject<{
|
|
21
|
+
pageGuid: z.ZodString;
|
|
22
|
+
pageAlias: z.ZodString;
|
|
23
|
+
framePath: z.ZodArray<z.ZodString>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
/**
|
|
26
|
+
* ACTION INTENT (PASS 1): coarse category only
|
|
27
|
+
* Keep this small so an LLM can commit early with high accuracy.
|
|
28
|
+
*/
|
|
29
|
+
export declare const zActionKind: z.ZodEnum<{
|
|
30
|
+
click: "click";
|
|
31
|
+
"form update": "form update";
|
|
32
|
+
navigation: "navigation";
|
|
33
|
+
assertion: "assertion";
|
|
34
|
+
other: "other";
|
|
35
|
+
}>;
|
|
36
|
+
export declare const zGeneralActionPlan: z.ZodObject<{
|
|
37
|
+
kind: z.ZodEnum<{
|
|
38
|
+
click: "click";
|
|
39
|
+
"form update": "form update";
|
|
40
|
+
navigation: "navigation";
|
|
41
|
+
assertion: "assertion";
|
|
42
|
+
other: "other";
|
|
43
|
+
}>;
|
|
44
|
+
description: z.ZodString;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
/**
|
|
47
|
+
* ACTION SUBTYPE (PASS 2): constrained sub-choices within the category? maybe add as object with values or special
|
|
48
|
+
*/
|
|
49
|
+
export declare const zMouseType: z.ZodEnum<{
|
|
50
|
+
click: "click";
|
|
51
|
+
doubleClick: "doubleClick";
|
|
52
|
+
hover: "hover";
|
|
53
|
+
}>;
|
|
54
|
+
export declare const zFormUpdateTypes: z.ZodEnum<{
|
|
55
|
+
press: "press";
|
|
56
|
+
type: "type";
|
|
57
|
+
fill: "fill";
|
|
58
|
+
select: "select";
|
|
59
|
+
uncheck: "uncheck";
|
|
60
|
+
check: "check";
|
|
61
|
+
setInputFiles: "setInputFiles";
|
|
62
|
+
clear: "clear";
|
|
63
|
+
}>;
|
|
64
|
+
export declare const zNavigationType: z.ZodEnum<{
|
|
65
|
+
openPage: "openPage";
|
|
66
|
+
navigate: "navigate";
|
|
67
|
+
closePage: "closePage";
|
|
68
|
+
goBack: "goBack";
|
|
69
|
+
goForward: "goForward";
|
|
70
|
+
refresh: "refresh";
|
|
71
|
+
openInNewTab: "openInNewTab";
|
|
72
|
+
}>;
|
|
73
|
+
export declare const zAssertionType: z.ZodEnum<{
|
|
74
|
+
"text visible": "text visible";
|
|
75
|
+
"value visible": "value visible";
|
|
76
|
+
"checked visible": "checked visible";
|
|
77
|
+
"aria snapshot visible": "aria snapshot visible";
|
|
78
|
+
"screenshot of element": "screenshot of element";
|
|
79
|
+
}>;
|
|
80
|
+
export declare const zMouseAction: z.ZodObject<{
|
|
81
|
+
type: z.ZodEnum<{
|
|
82
|
+
click: "click";
|
|
83
|
+
doubleClick: "doubleClick";
|
|
84
|
+
hover: "hover";
|
|
85
|
+
}>;
|
|
86
|
+
params: z.ZodObject<{
|
|
87
|
+
button: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
88
|
+
left: "left";
|
|
89
|
+
middle: "middle";
|
|
90
|
+
right: "right";
|
|
91
|
+
}>>>>;
|
|
92
|
+
position: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
93
|
+
x: z.ZodNumber;
|
|
94
|
+
y: z.ZodNumber;
|
|
95
|
+
}, z.core.$strip>>>;
|
|
96
|
+
modifiers: z.ZodOptional<z.ZodNullable<z.ZodDefault<z.ZodArray<z.ZodEnum<{
|
|
97
|
+
Alt: "Alt";
|
|
98
|
+
Control: "Control";
|
|
99
|
+
Meta: "Meta";
|
|
100
|
+
Shift: "Shift";
|
|
101
|
+
}>>>>>;
|
|
102
|
+
}, z.core.$strip>;
|
|
103
|
+
}, z.core.$strip>;
|
|
104
|
+
export declare const zFormUpdateAction: z.ZodObject<{
|
|
105
|
+
type: z.ZodEnum<{
|
|
106
|
+
press: "press";
|
|
107
|
+
type: "type";
|
|
108
|
+
fill: "fill";
|
|
109
|
+
select: "select";
|
|
110
|
+
uncheck: "uncheck";
|
|
111
|
+
check: "check";
|
|
112
|
+
setInputFiles: "setInputFiles";
|
|
113
|
+
clear: "clear";
|
|
114
|
+
}>;
|
|
115
|
+
params: z.ZodObject<{
|
|
116
|
+
value: z.ZodString;
|
|
117
|
+
modifiers: z.ZodOptional<z.ZodNullable<z.ZodDefault<z.ZodArray<z.ZodEnum<{
|
|
118
|
+
Alt: "Alt";
|
|
119
|
+
Control: "Control";
|
|
120
|
+
Meta: "Meta";
|
|
121
|
+
Shift: "Shift";
|
|
122
|
+
}>>>>>;
|
|
123
|
+
}, z.core.$strip>;
|
|
124
|
+
}, z.core.$strip>;
|
|
125
|
+
export declare const zNavigationAction: z.ZodObject<{
|
|
126
|
+
type: z.ZodEnum<{
|
|
127
|
+
openPage: "openPage";
|
|
128
|
+
navigate: "navigate";
|
|
129
|
+
closePage: "closePage";
|
|
130
|
+
goBack: "goBack";
|
|
131
|
+
goForward: "goForward";
|
|
132
|
+
refresh: "refresh";
|
|
133
|
+
openInNewTab: "openInNewTab";
|
|
134
|
+
}>;
|
|
135
|
+
params: z.ZodObject<{
|
|
136
|
+
url: z.ZodNullable<z.ZodString>;
|
|
137
|
+
}, z.core.$strip>;
|
|
138
|
+
}, z.core.$strip>;
|
|
139
|
+
export type NavigationAction = z.infer<typeof zNavigationAction>;
|
|
140
|
+
/**
|
|
141
|
+
* Click action result schema
|
|
142
|
+
* Contains top candidate elements matched against a Gherkin step
|
|
143
|
+
*/
|
|
144
|
+
export declare const zClickActionResult: z.ZodObject<{
|
|
145
|
+
candidates: z.ZodArray<z.ZodObject<{
|
|
146
|
+
index: z.ZodNumber;
|
|
147
|
+
tag: z.ZodString;
|
|
148
|
+
text: z.ZodString;
|
|
149
|
+
id: z.ZodNullable<z.ZodString>;
|
|
150
|
+
role: z.ZodNullable<z.ZodString>;
|
|
151
|
+
label: z.ZodNullable<z.ZodString>;
|
|
152
|
+
ariaLabel: z.ZodNullable<z.ZodString>;
|
|
153
|
+
confidence: z.ZodNullable<z.ZodNumber>;
|
|
154
|
+
}, z.core.$strip>>;
|
|
155
|
+
clickType: z.ZodEnum<{
|
|
156
|
+
left: "left";
|
|
157
|
+
middle: "middle";
|
|
158
|
+
right: "right";
|
|
159
|
+
hover: "hover";
|
|
160
|
+
double: "double";
|
|
161
|
+
}>;
|
|
162
|
+
reasoning: z.ZodString;
|
|
163
|
+
}, z.core.$strip>;
|
|
164
|
+
export type ClickActionResult = z.infer<typeof zClickActionResult>;
|
|
165
|
+
export declare const zAssertionAction: z.ZodObject<{
|
|
166
|
+
type: z.ZodEnum<{
|
|
167
|
+
"text visible": "text visible";
|
|
168
|
+
"value visible": "value visible";
|
|
169
|
+
"checked visible": "checked visible";
|
|
170
|
+
"aria snapshot visible": "aria snapshot visible";
|
|
171
|
+
"screenshot of element": "screenshot of element";
|
|
172
|
+
}>;
|
|
173
|
+
params: z.ZodObject<{
|
|
174
|
+
expected: z.ZodString;
|
|
175
|
+
}, z.core.$strip>;
|
|
176
|
+
}, z.core.$strip>;
|
|
177
|
+
export declare const zOtherAction: z.ZodObject<{
|
|
178
|
+
type: z.ZodLiteral<"custom">;
|
|
179
|
+
params: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
180
|
+
}, z.core.$strip>;
|
|
181
|
+
/**
|
|
182
|
+
* ACTION SUBTYPE (PASS 2): Union of all subtype schemas with kind
|
|
183
|
+
* This allows progressive refinement: first get kind, then get specific subtype.
|
|
184
|
+
*/
|
|
185
|
+
export declare const zActionPass2: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
186
|
+
kind: z.ZodLiteral<"mouse">;
|
|
187
|
+
type: z.ZodEnum<{
|
|
188
|
+
click: "click";
|
|
189
|
+
doubleClick: "doubleClick";
|
|
190
|
+
hover: "hover";
|
|
191
|
+
}>;
|
|
192
|
+
params: z.ZodObject<{
|
|
193
|
+
button: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
194
|
+
left: "left";
|
|
195
|
+
middle: "middle";
|
|
196
|
+
right: "right";
|
|
197
|
+
}>>>>;
|
|
198
|
+
position: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
199
|
+
x: z.ZodNumber;
|
|
200
|
+
y: z.ZodNumber;
|
|
201
|
+
}, z.core.$strip>>>;
|
|
202
|
+
modifiers: z.ZodOptional<z.ZodNullable<z.ZodDefault<z.ZodArray<z.ZodEnum<{
|
|
203
|
+
Alt: "Alt";
|
|
204
|
+
Control: "Control";
|
|
205
|
+
Meta: "Meta";
|
|
206
|
+
Shift: "Shift";
|
|
207
|
+
}>>>>>;
|
|
208
|
+
}, z.core.$strip>;
|
|
209
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
210
|
+
kind: z.ZodLiteral<"form update">;
|
|
211
|
+
type: z.ZodEnum<{
|
|
212
|
+
press: "press";
|
|
213
|
+
type: "type";
|
|
214
|
+
fill: "fill";
|
|
215
|
+
select: "select";
|
|
216
|
+
uncheck: "uncheck";
|
|
217
|
+
check: "check";
|
|
218
|
+
setInputFiles: "setInputFiles";
|
|
219
|
+
clear: "clear";
|
|
220
|
+
}>;
|
|
221
|
+
params: z.ZodObject<{
|
|
222
|
+
value: z.ZodString;
|
|
223
|
+
modifiers: z.ZodOptional<z.ZodNullable<z.ZodDefault<z.ZodArray<z.ZodEnum<{
|
|
224
|
+
Alt: "Alt";
|
|
225
|
+
Control: "Control";
|
|
226
|
+
Meta: "Meta";
|
|
227
|
+
Shift: "Shift";
|
|
228
|
+
}>>>>>;
|
|
229
|
+
}, z.core.$strip>;
|
|
230
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
231
|
+
kind: z.ZodLiteral<"navigation">;
|
|
232
|
+
type: z.ZodEnum<{
|
|
233
|
+
openPage: "openPage";
|
|
234
|
+
navigate: "navigate";
|
|
235
|
+
closePage: "closePage";
|
|
236
|
+
goBack: "goBack";
|
|
237
|
+
goForward: "goForward";
|
|
238
|
+
refresh: "refresh";
|
|
239
|
+
openInNewTab: "openInNewTab";
|
|
240
|
+
}>;
|
|
241
|
+
params: z.ZodObject<{
|
|
242
|
+
url: z.ZodNullable<z.ZodString>;
|
|
243
|
+
}, z.core.$strip>;
|
|
244
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
245
|
+
kind: z.ZodLiteral<"assertion">;
|
|
246
|
+
type: z.ZodEnum<{
|
|
247
|
+
"text visible": "text visible";
|
|
248
|
+
"value visible": "value visible";
|
|
249
|
+
"checked visible": "checked visible";
|
|
250
|
+
"aria snapshot visible": "aria snapshot visible";
|
|
251
|
+
"screenshot of element": "screenshot of element";
|
|
252
|
+
}>;
|
|
253
|
+
params: z.ZodObject<{
|
|
254
|
+
expected: z.ZodString;
|
|
255
|
+
}, z.core.$strip>;
|
|
256
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
257
|
+
kind: z.ZodLiteral<"other">;
|
|
258
|
+
type: z.ZodLiteral<"custom">;
|
|
259
|
+
params: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
260
|
+
}, z.core.$strip>], "kind">;
|
|
261
|
+
/**
|
|
262
|
+
* ACTION DETAILS (PASS 3): parameters, selector link, and signals
|
|
263
|
+
* Each subtype has a focused schema to minimize ambiguity.
|
|
264
|
+
*/
|
|
265
|
+
export declare const zMouseParams: z.ZodObject<{
|
|
266
|
+
button: z.ZodDefault<z.ZodEnum<{
|
|
267
|
+
left: "left";
|
|
268
|
+
middle: "middle";
|
|
269
|
+
right: "right";
|
|
270
|
+
}>>;
|
|
271
|
+
clickCount: z.ZodDefault<z.ZodNumber>;
|
|
272
|
+
position: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
273
|
+
x: z.ZodNumber;
|
|
274
|
+
y: z.ZodNumber;
|
|
275
|
+
}, z.core.$strip>>>;
|
|
276
|
+
modifiers: z.ZodDefault<z.ZodArray<z.ZodEnum<{
|
|
277
|
+
Alt: "Alt";
|
|
278
|
+
Control: "Control";
|
|
279
|
+
Meta: "Meta";
|
|
280
|
+
Shift: "Shift";
|
|
281
|
+
}>>>;
|
|
282
|
+
}, z.core.$strip>;
|
|
283
|
+
export declare const zKeyboardPressParams: z.ZodObject<{
|
|
284
|
+
key: z.ZodString;
|
|
285
|
+
modifiers: z.ZodDefault<z.ZodArray<z.ZodEnum<{
|
|
286
|
+
Alt: "Alt";
|
|
287
|
+
Control: "Control";
|
|
288
|
+
Meta: "Meta";
|
|
289
|
+
Shift: "Shift";
|
|
290
|
+
}>>>;
|
|
291
|
+
}, z.core.$strip>;
|
|
292
|
+
export declare const zKeyboardTypeParams: z.ZodObject<{
|
|
293
|
+
text: z.ZodString;
|
|
294
|
+
delayMs: z.ZodDefault<z.ZodNumber>;
|
|
295
|
+
}, z.core.$strip>;
|
|
296
|
+
export declare const zKeyboardFillParams: z.ZodObject<{
|
|
297
|
+
value: z.ZodString;
|
|
298
|
+
}, z.core.$strip>;
|
|
299
|
+
export declare const zOpenPageParams: z.ZodObject<{
|
|
300
|
+
url: z.ZodString;
|
|
301
|
+
}, z.core.$strip>;
|
|
302
|
+
export declare const zNavigateParams: z.ZodObject<{
|
|
303
|
+
url: z.ZodString;
|
|
304
|
+
}, z.core.$strip>;
|
|
305
|
+
export declare const zClosePageParams: z.ZodObject<{
|
|
306
|
+
reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
307
|
+
}, z.core.$strip>;
|
|
308
|
+
/**
|
|
309
|
+
* Type exports for convenience
|
|
310
|
+
*/
|
|
311
|
+
export type Point = z.infer<typeof zPoint>;
|
|
312
|
+
//# sourceMappingURL=action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../../src/mimicry/schema/action.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,eAAO,MAAM,MAAM;;;iBAGjB,CAAC;AAEH,eAAO,MAAM,YAAY;;;;EAAuE,CAAC;AACjG,eAAO,MAAM,aAAa;;;;;IAGZ,CAAC;AAEf,eAAO,MAAM,iBAAiB;;;;iBAI5B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,WAAW;;;;;;EAEkB,CAAC;AAE3C,eAAO,MAAM,kBAAkB;;;;;;;;;iBAK7B,CAAC;AAEH;;GAEG;AAEH,eAAO,MAAM,UAAU;;;;EAEc,CAAC;AACtC,eAAO,MAAM,gBAAgB;;;;;;;;;EAE0B,CAAC;AACxD,eAAO,MAAM,eAAe;;;;;;;;EAEc,CAAC;AAC3C,eAAO,MAAM,cAAc;;;;;;EAEM,CAAC;AAElC,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;iBAOvB,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;iBAM5B,CAAC;AAGH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;iBAQ5B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEjE;;;GAGG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;iBAyD7B,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAGnE,eAAO,MAAM,gBAAgB;;;;;;;;;;;iBAK3B,CAAC;AAGH,eAAO,MAAM,YAAY;;;iBAGvB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAM2C,CAAC;AAErE;;;GAGG;AAGH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;iBAKvB,CAAC;AAGH,eAAO,MAAM,oBAAoB;;;;;;;;iBAK/B,CAAC;AACH,eAAO,MAAM,mBAAmB;;;iBAG9B,CAAC;AACH,eAAO,MAAM,mBAAmB;;iBAE9B,CAAC;AAGH,eAAO,MAAM,eAAe;;iBAE1B,CAAC;AACH,eAAO,MAAM,eAAe;;iBAE1B,CAAC;AACH,eAAO,MAAM,gBAAgB;;iBAE3B,CAAC;AAoGH;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// zod-schemas.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/**
|
|
4
|
+
* Shared: identifiers and primitive helpers
|
|
5
|
+
*/
|
|
6
|
+
export const zPoint = z.object({
|
|
7
|
+
x: z.number().describe("X coordinate relative to the page or element bounding box."),
|
|
8
|
+
y: z.number().describe("Y coordinate relative to the page or element bounding box."),
|
|
9
|
+
});
|
|
10
|
+
export const zMouseButton = z.enum(["left", "middle", "right"]).describe("Mouse button to use.");
|
|
11
|
+
export const zModifierKeys = z
|
|
12
|
+
.array(z.enum(["Alt", "Control", "Meta", "Shift"]))
|
|
13
|
+
.describe("Zero or more modifier keys held for this action.")
|
|
14
|
+
.default([]);
|
|
15
|
+
export const zFrameDescription = z.object({
|
|
16
|
+
pageGuid: z.string().describe("Stable GUID for the page instance."),
|
|
17
|
+
pageAlias: z.string().describe("Human-friendly alias for the page (e.g., 'main', 'popup-1')."),
|
|
18
|
+
framePath: z.array(z.string()).describe("Ordered list of frame selectors/aliases from top to target frame."),
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* ACTION INTENT (PASS 1): coarse category only
|
|
22
|
+
* Keep this small so an LLM can commit early with high accuracy.
|
|
23
|
+
*/
|
|
24
|
+
export const zActionKind = z
|
|
25
|
+
.enum(["click", "form update", "navigation", "assertion", "other"])
|
|
26
|
+
.describe("High-level action category.");
|
|
27
|
+
export const zGeneralActionPlan = z.object({
|
|
28
|
+
kind: zActionKind.describe("Coarse action category chosen first."),
|
|
29
|
+
description: z
|
|
30
|
+
.string()
|
|
31
|
+
.describe("the reasoning behind the classification based on the literal intent of the Gherkin step."),
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* ACTION SUBTYPE (PASS 2): constrained sub-choices within the category? maybe add as object with values or special
|
|
35
|
+
*/
|
|
36
|
+
export const zMouseType = z
|
|
37
|
+
.enum(["click", "doubleClick", "hover"])
|
|
38
|
+
.describe("Specific mouse action.");
|
|
39
|
+
export const zFormUpdateTypes = z
|
|
40
|
+
.enum(["press", "type", "fill", 'select', 'uncheck', 'check', 'setInputFiles', 'clear'])
|
|
41
|
+
.describe("Specific form action to update the form.");
|
|
42
|
+
export const zNavigationType = z
|
|
43
|
+
.enum(["openPage", "navigate", "closePage", 'goBack', 'goForward', 'refresh', 'openInNewTab'])
|
|
44
|
+
.describe("Specific navigation action.");
|
|
45
|
+
export const zAssertionType = z
|
|
46
|
+
.enum(["text visible", "value visible", "checked visible", "aria snapshot visible", "screenshot of element"])
|
|
47
|
+
.describe("Assertion subtype.");
|
|
48
|
+
export const zMouseAction = z.object({
|
|
49
|
+
type: zMouseType,
|
|
50
|
+
params: z.object({
|
|
51
|
+
button: zMouseButton.nullish().default("left").describe("Optional, mouse button to use, not needed for hover, for others it will be left click by default."),
|
|
52
|
+
position: zPoint.nullish().describe("Optional relative offset inside the target element."),
|
|
53
|
+
modifiers: zModifierKeys.nullish().describe("Optional modifier keys to use, not needed for hover, for others it will be no modifiers by default."),
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
export const zFormUpdateAction = z.object({
|
|
57
|
+
type: zFormUpdateTypes,
|
|
58
|
+
params: z.object({
|
|
59
|
+
value: z.string().describe("Value to set for the form update."),
|
|
60
|
+
modifiers: zModifierKeys.nullish().describe("Optional modifier keys to use for the form update."),
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
// TODO: navigation or opening pop ups needs more work most likely
|
|
64
|
+
export const zNavigationAction = z.object({
|
|
65
|
+
type: zNavigationType,
|
|
66
|
+
params: z.object({
|
|
67
|
+
url: z
|
|
68
|
+
.string()
|
|
69
|
+
.nullable()
|
|
70
|
+
.describe("URL to navigate to. Must be a valid URL (starting with http:// or https://) for 'openPage' and 'navigate' types. Empty string for other navigation types (goBack, goForward, refresh, closePage)."),
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* Click action result schema
|
|
75
|
+
* Contains top candidate elements matched against a Gherkin step
|
|
76
|
+
*/
|
|
77
|
+
export const zClickActionResult = z.object({
|
|
78
|
+
/**
|
|
79
|
+
* Array of up to 5 candidate elements, ranked by likelihood
|
|
80
|
+
* Each candidate includes its index in the original TargetInfo array
|
|
81
|
+
*/
|
|
82
|
+
candidates: z
|
|
83
|
+
.array(z.object({
|
|
84
|
+
/**
|
|
85
|
+
* Index in the original TargetInfo array (0-based)
|
|
86
|
+
* Used to reference back to the captured element
|
|
87
|
+
*/
|
|
88
|
+
index: z.number().int().min(0).describe("Index in the original TargetInfo array (0-based)"),
|
|
89
|
+
/**
|
|
90
|
+
* Element tag name (e.g., 'button', 'a', 'input')
|
|
91
|
+
*/
|
|
92
|
+
tag: z.string().describe("Element tag name"),
|
|
93
|
+
/**
|
|
94
|
+
* Visible text content of the element
|
|
95
|
+
*/
|
|
96
|
+
text: z.string().describe("Visible text content"),
|
|
97
|
+
/**
|
|
98
|
+
* Element ID attribute if present
|
|
99
|
+
*/
|
|
100
|
+
id: z.string().nullable().describe("Element ID attribute if present"),
|
|
101
|
+
/**
|
|
102
|
+
* Inferred or explicit ARIA role
|
|
103
|
+
*/
|
|
104
|
+
role: z.string().nullable().describe("Inferred or explicit ARIA role"),
|
|
105
|
+
/**
|
|
106
|
+
* Associated label text (from label element or aria-labelledby)
|
|
107
|
+
*/
|
|
108
|
+
label: z.string().nullable().describe("Associated label text"),
|
|
109
|
+
/**
|
|
110
|
+
* aria-label attribute value
|
|
111
|
+
*/
|
|
112
|
+
ariaLabel: z.string().nullable().describe("aria-label attribute value"),
|
|
113
|
+
/**
|
|
114
|
+
* Optional confidence score (0-1) indicating match likelihood
|
|
115
|
+
* Using nullable instead of optional for compatibility with OpenAI structured outputs
|
|
116
|
+
*/
|
|
117
|
+
confidence: z.number().min(0).nullable().describe("Confidence score (0-1) indicating match likelihood"),
|
|
118
|
+
}))
|
|
119
|
+
.max(5)
|
|
120
|
+
.describe("Top 5 candidate elements ranked by likelihood"),
|
|
121
|
+
/**
|
|
122
|
+
* Single click type for all candidates
|
|
123
|
+
* Determined from the Gherkin step (e.g., "right click", "double click")
|
|
124
|
+
*/
|
|
125
|
+
clickType: z
|
|
126
|
+
.enum(["left", "right", "double", "middle", "hover"])
|
|
127
|
+
.describe("Click type determined from the Gherkin step"),
|
|
128
|
+
/**
|
|
129
|
+
* Brief explanation of the matching logic and reasoning
|
|
130
|
+
*/
|
|
131
|
+
reasoning: z.string().describe("Brief explanation of the matching logic and reasoning"),
|
|
132
|
+
});
|
|
133
|
+
// TODO: this maybe needs to be more complex? to make sure it gives the right value and such
|
|
134
|
+
export const zAssertionAction = z.object({
|
|
135
|
+
type: zAssertionType,
|
|
136
|
+
params: z.object({
|
|
137
|
+
expected: z.string().describe("Expected value to assert."),
|
|
138
|
+
}),
|
|
139
|
+
});
|
|
140
|
+
// TODO: this probably will need to just be logged for now
|
|
141
|
+
export const zOtherAction = z.object({
|
|
142
|
+
type: z.literal("custom"),
|
|
143
|
+
params: z.record(z.string(), z.unknown()).describe("Custom parameters for the action."),
|
|
144
|
+
});
|
|
145
|
+
/**
|
|
146
|
+
* ACTION SUBTYPE (PASS 2): Union of all subtype schemas with kind
|
|
147
|
+
* This allows progressive refinement: first get kind, then get specific subtype.
|
|
148
|
+
*/
|
|
149
|
+
export const zActionPass2 = z.discriminatedUnion("kind", [
|
|
150
|
+
z.object({ kind: z.literal("mouse") }).merge(zMouseAction),
|
|
151
|
+
z.object({ kind: z.literal("form update") }).merge(zFormUpdateAction),
|
|
152
|
+
z.object({ kind: z.literal("navigation") }).merge(zNavigationAction),
|
|
153
|
+
z.object({ kind: z.literal("assertion") }).merge(zAssertionAction),
|
|
154
|
+
z.object({ kind: z.literal("other") }).merge(zOtherAction),
|
|
155
|
+
]).describe("Action subtype determined after choosing action kind.");
|
|
156
|
+
/**
|
|
157
|
+
* ACTION DETAILS (PASS 3): parameters, selector link, and signals
|
|
158
|
+
* Each subtype has a focused schema to minimize ambiguity.
|
|
159
|
+
*/
|
|
160
|
+
// Mouse params
|
|
161
|
+
export const zMouseParams = z.object({
|
|
162
|
+
button: zMouseButton.default("left"),
|
|
163
|
+
clickCount: z.number().int().min(1).max(2).default(1).describe("1 for click, 2 for double-click."),
|
|
164
|
+
position: zPoint.nullish().describe("Optional relative offset inside the target element."),
|
|
165
|
+
modifiers: zModifierKeys,
|
|
166
|
+
});
|
|
167
|
+
// Keyboard params
|
|
168
|
+
export const zKeyboardPressParams = z.object({
|
|
169
|
+
key: z
|
|
170
|
+
.string()
|
|
171
|
+
.describe("Single key to press. Use Playwright key names (e.g., 'Enter', 'Tab', 'ArrowDown', 'Control+K')."),
|
|
172
|
+
modifiers: zModifierKeys,
|
|
173
|
+
});
|
|
174
|
+
export const zKeyboardTypeParams = z.object({
|
|
175
|
+
text: z.string().describe("Literal text to type (respects existing cursor/focus)."),
|
|
176
|
+
delayMs: z.number().int().min(0).default(0).describe("Optional delay per character."),
|
|
177
|
+
});
|
|
178
|
+
export const zKeyboardFillParams = z.object({
|
|
179
|
+
value: z.string().describe("Final value of the input after filling (replaces existing content)."),
|
|
180
|
+
});
|
|
181
|
+
// Navigation params
|
|
182
|
+
export const zOpenPageParams = z.object({
|
|
183
|
+
url: z.string().url().describe("Absolute URL to open in a new page/tab/context."),
|
|
184
|
+
});
|
|
185
|
+
export const zNavigateParams = z.object({
|
|
186
|
+
url: z.string().describe("URL or path to navigate current page to."),
|
|
187
|
+
});
|
|
188
|
+
export const zClosePageParams = z.object({
|
|
189
|
+
reason: z.string().nullish().describe("Optional rationale for closing (cleanup, end of flow, etc.)."),
|
|
190
|
+
});
|
|
191
|
+
// export type SelectorPlan = z.infer<typeof zSelectorPlan>;
|
|
192
|
+
// export type ActionPlan = z.infer<typeof zActionPlan>;
|
|
193
|
+
// export type ActionInContext = z.infer<typeof zActionInContext>;
|
|
194
|
+
//# sourceMappingURL=action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.js","sourceRoot":"","sources":["../../../src/mimicry/schema/action.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4DAA4D,CAAC;IACpF,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4DAA4D,CAAC;CACrF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC;AACjG,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC;KAC3B,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,SAA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AAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,+BAA+B,CAAC;CACtF,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,qEAAqE,CAAC;CAClG,CAAC,CAAC;AAEH,oBAAoB;AACpB,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,iDAAiD,CAAC;CAClF,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,0CAA0C,CAAC;CACrE,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,8DAA8D,CAAC;CACtG,CAAC,CAAC;AAwGH,4DAA4D;AAC5D,wDAAwD;AACxD,kEAAkE"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Locator, Page } from '@playwright/test';
|
|
2
|
+
/**
|
|
3
|
+
* TargetInfo: Normalized metadata for a candidate element
|
|
4
|
+
*
|
|
5
|
+
* This represents an element that could be targeted by a Gherkin step.
|
|
6
|
+
* Collected via Playwright page.evaluate in the browser context.
|
|
7
|
+
*/
|
|
8
|
+
export type TargetInfo = {
|
|
9
|
+
tag: string;
|
|
10
|
+
text: string;
|
|
11
|
+
id: string | null;
|
|
12
|
+
role: string | null;
|
|
13
|
+
label: string | null;
|
|
14
|
+
ariaLabel: string | null;
|
|
15
|
+
typeAttr: string | null;
|
|
16
|
+
nameAttr: string | null;
|
|
17
|
+
href: string | null;
|
|
18
|
+
dataset: Record<string, string>;
|
|
19
|
+
nthOfType: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Element category types for classification
|
|
23
|
+
*/
|
|
24
|
+
export type ElementCategory = 'clickable' | 'form' | 'text';
|
|
25
|
+
/**
|
|
26
|
+
* Comprehensive element information for selector generation
|
|
27
|
+
*/
|
|
28
|
+
export interface SelectorElement {
|
|
29
|
+
/** Element category: clickable, form, or text */
|
|
30
|
+
category: ElementCategory;
|
|
31
|
+
/** HTML tag name */
|
|
32
|
+
tag: string;
|
|
33
|
+
/** Primary visible text content */
|
|
34
|
+
text: string;
|
|
35
|
+
/** All text-related attributes combined for context */
|
|
36
|
+
descriptiveText: string;
|
|
37
|
+
/** Element ID if present */
|
|
38
|
+
id: string | null;
|
|
39
|
+
/** Inferred or explicit ARIA role */
|
|
40
|
+
role: string | null;
|
|
41
|
+
/** Associated label text */
|
|
42
|
+
label: string | null;
|
|
43
|
+
/** aria-label attribute */
|
|
44
|
+
ariaLabel: string | null;
|
|
45
|
+
/** alt text for images */
|
|
46
|
+
altText: string | null;
|
|
47
|
+
/** title attribute */
|
|
48
|
+
title: string | null;
|
|
49
|
+
/** placeholder text for inputs */
|
|
50
|
+
placeholder: string | null;
|
|
51
|
+
/** aria-describedby text */
|
|
52
|
+
ariaDescribedBy: string | null;
|
|
53
|
+
/** Input type attribute */
|
|
54
|
+
typeAttr: string | null;
|
|
55
|
+
/** Name attribute */
|
|
56
|
+
nameAttr: string | null;
|
|
57
|
+
/** href for links */
|
|
58
|
+
href: string | null;
|
|
59
|
+
/** value attribute for form elements */
|
|
60
|
+
value: string | null;
|
|
61
|
+
/** All data-* attributes */
|
|
62
|
+
dataset: Record<string, string>;
|
|
63
|
+
/** nth-of-type index (1-based) */
|
|
64
|
+
nthOfType: number;
|
|
65
|
+
/** CSS selector path for this element */
|
|
66
|
+
selector: string;
|
|
67
|
+
/** Whether element is visible */
|
|
68
|
+
isVisible: boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Result structure containing all categorized elements
|
|
72
|
+
*/
|
|
73
|
+
export interface SelectorResult {
|
|
74
|
+
/** All clickable/interactive elements (buttons, links, etc.) */
|
|
75
|
+
clickableElements: SelectorElement[];
|
|
76
|
+
/** All form input elements */
|
|
77
|
+
formElements: SelectorElement[];
|
|
78
|
+
/** All text/content elements */
|
|
79
|
+
textElements: SelectorElement[];
|
|
80
|
+
/** Total count of all elements */
|
|
81
|
+
totalCount: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Options for capturing target elements
|
|
85
|
+
*/
|
|
86
|
+
export interface CaptureTargetsOptions {
|
|
87
|
+
/**
|
|
88
|
+
* If true, only capture interactable elements (buttons, links, inputs, etc.)
|
|
89
|
+
* If false (default), capture both interactive and content elements
|
|
90
|
+
*/
|
|
91
|
+
interactableOnly?: boolean;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Capture target elements from the page
|
|
95
|
+
*
|
|
96
|
+
* @param page - Playwright Page object
|
|
97
|
+
* @param options - Optional configuration for capturing targets
|
|
98
|
+
* @returns Promise resolving to array of TargetInfo objects
|
|
99
|
+
*/
|
|
100
|
+
export declare function captureTargets(page: Page, options?: CaptureTargetsOptions): Promise<TargetInfo[]>;
|
|
101
|
+
/**
|
|
102
|
+
* Build the best Playwright locator for a given target element
|
|
103
|
+
*
|
|
104
|
+
* Follows Playwright's recommended selector priority:
|
|
105
|
+
* 1. data-testid (use page.getByTestId()) - #1 recommendation, most stable
|
|
106
|
+
* 2. Role-based (use page.getByRole()) - #2 recommendation, accessibility-based
|
|
107
|
+
* 3. Text-based (use page.getByText()) - #3 recommendation, good for visible text
|
|
108
|
+
* 4. CSS selectors as fallback (ID, data attributes, name, tag selectors)
|
|
109
|
+
*
|
|
110
|
+
* If a locator matches multiple elements, this function will evaluate each
|
|
111
|
+
* and return the one that best matches the target information.
|
|
112
|
+
*
|
|
113
|
+
* @param page - Playwright Page object
|
|
114
|
+
* @param target - TargetInfo object containing element metadata
|
|
115
|
+
* @returns Playwright Locator for the target element, prioritized by Playwright's best practices
|
|
116
|
+
*/
|
|
117
|
+
export declare function buildSelectorForTarget(page: Page, target?: TargetInfo): Promise<Locator | null>;
|
|
118
|
+
//# sourceMappingURL=selector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../../src/mimicry/selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AASjD;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAuBF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,QAAQ,EAAE,eAAe,CAAC;IAC1B,oBAAoB;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,eAAe,EAAE,MAAM,CAAC;IACxB,4BAA4B;IAC5B,EAAE,EAAE,MAAM,GAAG,IAA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