@handstage/agent 1.0.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/src/schemas.ts ADDED
@@ -0,0 +1,207 @@
1
+ import { z } from "zod"
2
+
3
+ export const LoadStateSchema = z
4
+ .enum(["load", "domcontentloaded", "networkidle"])
5
+ .optional()
6
+ .describe("Wait until this lifecycle event (navigation / reload / history)")
7
+
8
+ export const PageIdSchema = z
9
+ .string()
10
+ .describe("Target id of the page tab (from pages or newPage)")
11
+
12
+ export const PagesInputSchema = z.object({})
13
+
14
+ export const NewPageInputSchema = z.object({
15
+ url: z.string().optional().describe('Initial URL (default "about:blank")'),
16
+ })
17
+
18
+ export const BringToFrontInputSchema = z.object({ pageId: PageIdSchema })
19
+
20
+ export const ClosePageInputSchema = z.object({ pageId: PageIdSchema })
21
+
22
+ export const GotoInputSchema = z.object({
23
+ pageId: PageIdSchema,
24
+ url: z.string().min(1),
25
+ waitUntil: LoadStateSchema,
26
+ timeoutMs: z.number().positive().optional(),
27
+ })
28
+
29
+ export const ReloadInputSchema = z.object({
30
+ pageId: PageIdSchema,
31
+ waitUntil: LoadStateSchema,
32
+ timeoutMs: z.number().positive().optional(),
33
+ ignoreCache: z.boolean().optional(),
34
+ })
35
+
36
+ export const GoBackInputSchema = z.object({
37
+ pageId: PageIdSchema,
38
+ waitUntil: LoadStateSchema,
39
+ timeoutMs: z.number().positive().optional(),
40
+ })
41
+
42
+ export const GoForwardInputSchema = z.object({
43
+ pageId: PageIdSchema,
44
+ waitUntil: LoadStateSchema,
45
+ timeoutMs: z.number().positive().optional(),
46
+ })
47
+
48
+ export const SnapshotDomInputSchema = z.object({
49
+ pageId: PageIdSchema,
50
+ includeIframes: z.boolean().optional(),
51
+ })
52
+
53
+ export const PageInfoInputSchema = z.object({ pageId: PageIdSchema })
54
+
55
+ export const ClickInputSchema = z.object({
56
+ pageId: PageIdSchema,
57
+ x: z.number(),
58
+ y: z.number(),
59
+ button: z.enum(["left", "right", "middle"]).optional(),
60
+ clickCount: z.number().int().positive().optional(),
61
+ })
62
+
63
+ export const HoverInputSchema = z.object({
64
+ pageId: PageIdSchema,
65
+ x: z.number(),
66
+ y: z.number(),
67
+ })
68
+
69
+ export const ScrollInputSchema = z.object({
70
+ pageId: PageIdSchema,
71
+ x: z.number(),
72
+ y: z.number(),
73
+ deltaX: z.number(),
74
+ deltaY: z.number(),
75
+ })
76
+
77
+ export const TypeInputSchema = z.object({
78
+ pageId: PageIdSchema,
79
+ text: z.string(),
80
+ delay: z.number().nonnegative().optional(),
81
+ withMistakes: z.boolean().optional(),
82
+ })
83
+
84
+ export const ClickOnInputSchema = z.object({
85
+ pageId: PageIdSchema,
86
+ select: z
87
+ .string()
88
+ .min(1)
89
+ .describe("CSS selector or XPath (e.g. //button[@id='x'])"),
90
+ })
91
+
92
+ export const FillOnInputSchema = z.object({
93
+ pageId: PageIdSchema,
94
+ select: z.string().min(1).describe("CSS selector or XPath"),
95
+ value: z.string(),
96
+ })
97
+
98
+ export const TypeOnInputSchema = z.object({
99
+ pageId: PageIdSchema,
100
+ select: z.string().min(1).describe("CSS selector or XPath"),
101
+ text: z.string(),
102
+ delay: z.number().nonnegative().optional(),
103
+ })
104
+
105
+ export const HoverOnInputSchema = z.object({
106
+ pageId: PageIdSchema,
107
+ select: z.string().min(1).describe("CSS selector or XPath"),
108
+ })
109
+
110
+ /** Encoded node id from snapshot_dom (e.g. `1-42` — frameOrdinal-backendNodeId). */
111
+ export const A11yEncodedIdSchema = z
112
+ .string()
113
+ .min(1)
114
+ .regex(/^\d+-\d+$/, "Expected frameOrdinal-backendNodeId from snapshot_dom")
115
+ .describe("Encoded node id from snapshot_dom (bracketed id in the a11y tree)")
116
+
117
+ export const ClickOnIdInputSchema = z.object({
118
+ pageId: PageIdSchema,
119
+ id: A11yEncodedIdSchema,
120
+ })
121
+
122
+ export const FillOnIdInputSchema = z.object({
123
+ pageId: PageIdSchema,
124
+ id: A11yEncodedIdSchema,
125
+ value: z.string(),
126
+ })
127
+
128
+ export const TypeOnIdInputSchema = z.object({
129
+ pageId: PageIdSchema,
130
+ id: A11yEncodedIdSchema,
131
+ text: z.string(),
132
+ delay: z.number().nonnegative().optional(),
133
+ })
134
+
135
+ export const HoverOnIdInputSchema = z.object({
136
+ pageId: PageIdSchema,
137
+ id: A11yEncodedIdSchema,
138
+ })
139
+
140
+ /** Shared `{ ok: true } | { ok: false; error }` tool result shape */
141
+ export const HandstageAgentOkOrErrOutputSchema = z.discriminatedUnion("ok", [
142
+ z.object({ ok: z.literal(true) }),
143
+ z.object({ ok: z.literal(false), error: z.string() }),
144
+ ])
145
+
146
+ export const HandstageAgentPageEntrySchema = z.object({
147
+ pageId: z.string(),
148
+ url: z.string(),
149
+ title: z.string(),
150
+ })
151
+
152
+ export const PagesOutputSchema = z.object({
153
+ pages: z.array(HandstageAgentPageEntrySchema),
154
+ })
155
+
156
+ export const NewPageOutputSchema = z.object({ pageId: z.string() })
157
+
158
+ export const BringToFrontOutputSchema = HandstageAgentOkOrErrOutputSchema
159
+
160
+ export const ClosePageOutputSchema = HandstageAgentOkOrErrOutputSchema
161
+
162
+ export const GotoOutputSchema = z.discriminatedUnion("ok", [
163
+ z.object({ ok: z.literal(true), url: z.string() }),
164
+ z.object({ ok: z.literal(false), error: z.string() }),
165
+ ])
166
+
167
+ export const ReloadOutputSchema = GotoOutputSchema
168
+
169
+ export const HistoryNavOutputSchema = z.discriminatedUnion("ok", [
170
+ z.object({
171
+ ok: z.literal(true),
172
+ navigated: z.boolean(),
173
+ url: z.string(),
174
+ }),
175
+ z.object({ ok: z.literal(false), error: z.string() }),
176
+ ])
177
+
178
+ export const SnapshotDomOutputSchema = z.discriminatedUnion("ok", [
179
+ z.object({
180
+ ok: z.literal(true),
181
+ tree: z.string(),
182
+ xpathMap: z.record(z.string(), z.string()),
183
+ urlMap: z.record(z.string(), z.string()),
184
+ }),
185
+ z.object({ ok: z.literal(false), error: z.string() }),
186
+ ])
187
+
188
+ export const PageInfoOutputSchema = z.discriminatedUnion("ok", [
189
+ z.object({
190
+ ok: z.literal(true),
191
+ url: z.string(),
192
+ title: z.string(),
193
+ }),
194
+ z.object({ ok: z.literal(false), error: z.string() }),
195
+ ])
196
+
197
+ export const PointerOutputSchema = z.discriminatedUnion("ok", [
198
+ z.object({
199
+ ok: z.literal(true),
200
+ xpathAtPoint: z.string().optional(),
201
+ }),
202
+ z.object({ ok: z.literal(false), error: z.string() }),
203
+ ])
204
+
205
+ export const TypeOutputSchema = HandstageAgentOkOrErrOutputSchema
206
+
207
+ export const ElementActionOutputSchema = HandstageAgentOkOrErrOutputSchema
package/src/types.ts ADDED
@@ -0,0 +1,108 @@
1
+ import type { z } from "zod"
2
+ import type {
3
+ // ClickInputSchema,
4
+ ClickOnIdInputSchema,
5
+ // BringToFrontInputSchema,
6
+ // BringToFrontOutputSchema,
7
+ ClosePageInputSchema,
8
+ ClosePageOutputSchema,
9
+ // ClickOnInputSchema,
10
+ ElementActionOutputSchema,
11
+ FillOnIdInputSchema,
12
+ // FillOnInputSchema,
13
+ GoBackInputSchema,
14
+ GoForwardInputSchema,
15
+ GotoInputSchema,
16
+ GotoOutputSchema,
17
+ HandstageAgentPageEntrySchema,
18
+ HistoryNavOutputSchema,
19
+ // HoverInputSchema,
20
+ HoverOnIdInputSchema,
21
+ // HoverOnInputSchema,
22
+ NewPageInputSchema,
23
+ NewPageOutputSchema,
24
+ // PageInfoInputSchema,
25
+ // PageInfoOutputSchema,
26
+ PagesInputSchema,
27
+ PagesOutputSchema,
28
+ // PointerOutputSchema,
29
+ ReloadInputSchema,
30
+ ReloadOutputSchema,
31
+ // ScrollInputSchema,
32
+ SnapshotDomInputSchema,
33
+ SnapshotDomOutputSchema,
34
+ // TypeInputSchema,
35
+ TypeOnIdInputSchema,
36
+ // TypeOnInputSchema,
37
+ // TypeOutputSchema,
38
+ } from "./schemas"
39
+
40
+ export type PagesInput = z.infer<typeof PagesInputSchema>
41
+ export type PagesOutput = z.infer<typeof PagesOutputSchema>
42
+ export type PageEntry = z.infer<typeof HandstageAgentPageEntrySchema>
43
+
44
+ export type NewPageInput = z.infer<typeof NewPageInputSchema>
45
+ export type NewPageOutput = z.infer<typeof NewPageOutputSchema>
46
+
47
+ // export type BringToFrontInput = z.infer<typeof BringToFrontInputSchema>
48
+ // export type BringToFrontOutput = z.infer<typeof BringToFrontOutputSchema>
49
+
50
+ export type ClosePageInput = z.infer<typeof ClosePageInputSchema>
51
+ export type ClosePageOutput = z.infer<typeof ClosePageOutputSchema>
52
+
53
+ export type GotoInput = z.infer<typeof GotoInputSchema>
54
+ export type GotoOutput = z.infer<typeof GotoOutputSchema>
55
+
56
+ export type ReloadInput = z.infer<typeof ReloadInputSchema>
57
+ export type ReloadOutput = z.infer<typeof ReloadOutputSchema>
58
+
59
+ export type GoBackInput = z.infer<typeof GoBackInputSchema>
60
+ export type GoBackOutput = z.infer<typeof HistoryNavOutputSchema>
61
+
62
+ export type GoForwardInput = z.infer<typeof GoForwardInputSchema>
63
+ export type GoForwardOutput = z.infer<typeof HistoryNavOutputSchema>
64
+
65
+ export type SnapshotDomInput = z.infer<typeof SnapshotDomInputSchema>
66
+ export type SnapshotDomOutput = z.infer<typeof SnapshotDomOutputSchema>
67
+
68
+ // export type PageInfoInput = z.infer<typeof PageInfoInputSchema>
69
+ // export type PageInfoOutput = z.infer<typeof PageInfoOutputSchema>
70
+
71
+ // export type ClickInput = z.infer<typeof ClickInputSchema>
72
+ // export type ClickOutput = z.infer<typeof PointerOutputSchema>
73
+
74
+ // export type HoverInput = z.infer<typeof HoverInputSchema>
75
+ // export type HoverOutput = z.infer<typeof PointerOutputSchema>
76
+
77
+ // export type ScrollInput = z.infer<typeof ScrollInputSchema>
78
+ // export type ScrollOutput = z.infer<typeof PointerOutputSchema>
79
+
80
+ // export type TypeInput = z.infer<typeof TypeInputSchema>
81
+ // export type TypeOutput = z.infer<typeof TypeOutputSchema>
82
+
83
+ // export type ClickOnInput = z.infer<typeof ClickOnInputSchema>
84
+ // export type ClickOnOutput = z.infer<typeof ElementActionOutputSchema>
85
+
86
+ // export type FillOnInput = z.infer<typeof FillOnInputSchema>
87
+ // export type FillOnOutput = z.infer<typeof ElementActionOutputSchema>
88
+
89
+ // export type TypeOnInput = z.infer<typeof TypeOnInputSchema>
90
+ // export type TypeOnOutput = z.infer<typeof ElementActionOutputSchema>
91
+
92
+ // export type HoverOnInput = z.infer<typeof HoverOnInputSchema>
93
+ // export type HoverOnOutput = z.infer<typeof ElementActionOutputSchema>
94
+
95
+ export type ClickOnIdInput = z.infer<typeof ClickOnIdInputSchema>
96
+ export type ClickOnIdOutput = z.infer<typeof ElementActionOutputSchema>
97
+
98
+ export type FillOnIdInput = z.infer<typeof FillOnIdInputSchema>
99
+ export type FillOnIdOutput = z.infer<typeof ElementActionOutputSchema>
100
+
101
+ export type TypeOnIdInput = z.infer<typeof TypeOnIdInputSchema>
102
+ export type TypeOnIdOutput = z.infer<typeof ElementActionOutputSchema>
103
+
104
+ export type HoverOnIdInput = z.infer<typeof HoverOnIdInputSchema>
105
+ export type HoverOnIdOutput = z.infer<typeof ElementActionOutputSchema>
106
+
107
+ export type OkResult = Extract<ClickOnIdOutput, { ok: true }>
108
+ export type ErrResult = Extract<ClickOnIdOutput, { ok: false }>