illuma-agents 1.0.27 → 1.0.29
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/dist/cjs/graphs/Graph.cjs +28 -2
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +108 -0
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/stream.cjs +27 -0
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/BrowserTools.cjs +109 -32
- package/dist/cjs/tools/BrowserTools.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +28 -2
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +108 -0
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/stream.mjs +27 -0
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/BrowserTools.mjs +109 -32
- package/dist/esm/tools/BrowserTools.mjs.map +1 -1
- package/dist/types/graphs/Graph.d.ts +14 -0
- package/dist/types/graphs/MultiAgentGraph.d.ts +41 -0
- package/dist/types/messages/format.d.ts +1 -1
- package/dist/types/tools/BrowserTools.d.ts +4 -1
- package/dist/types/types/stream.d.ts +13 -0
- package/package.json +4 -2
- package/src/graphs/Graph.ts +30 -2
- package/src/graphs/MultiAgentGraph.ts +119 -0
- package/src/messages/format.ts +2 -2
- package/src/scripts/multi-agent-chain.ts +59 -6
- package/src/scripts/multi-agent-parallel-start.ts +265 -0
- package/src/scripts/multi-agent-parallel.ts +61 -10
- package/src/scripts/multi-agent-sequence.ts +6 -1
- package/src/scripts/parallel-asymmetric-tools-test.ts +274 -0
- package/src/scripts/parallel-full-metadata-test.ts +240 -0
- package/src/scripts/parallel-tools-test.ts +340 -0
- package/src/scripts/sequential-full-metadata-test.ts +197 -0
- package/src/scripts/single-agent-metadata-test.ts +198 -0
- package/src/scripts/test-thinking-handoff.ts +8 -0
- package/src/scripts/tools.ts +31 -11
- package/src/stream.ts +32 -0
- package/src/tools/BrowserTools.ts +424 -350
- package/src/tools/__tests__/BrowserTools.test.ts +263 -257
- package/src/types/stream.ts +15 -0
|
@@ -1,350 +1,424 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { tool, DynamicStructuredTool } from '@langchain/core/tools';
|
|
3
|
-
import type * as
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Browser tool names - keep in sync with ranger-browser extension
|
|
7
|
-
* These tools execute locally in the browser extension, NOT on the server
|
|
8
|
-
*/
|
|
9
|
-
export const EBrowserTools = {
|
|
10
|
-
CLICK: 'browser_click',
|
|
11
|
-
TYPE: 'browser_type',
|
|
12
|
-
NAVIGATE: 'browser_navigate',
|
|
13
|
-
SCROLL: 'browser_scroll',
|
|
14
|
-
EXTRACT: 'browser_extract',
|
|
15
|
-
HOVER: 'browser_hover',
|
|
16
|
-
WAIT: 'browser_wait',
|
|
17
|
-
BACK: 'browser_back',
|
|
18
|
-
SCREENSHOT: 'browser_screenshot',
|
|
19
|
-
GET_PAGE_STATE: 'browser_get_page_state',
|
|
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
|
-
const
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*/
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
{
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
)
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { tool, DynamicStructuredTool } from '@langchain/core/tools';
|
|
3
|
+
import type * as _t from '@/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Browser tool names - keep in sync with ranger-browser extension
|
|
7
|
+
* These tools execute locally in the browser extension, NOT on the server
|
|
8
|
+
*/
|
|
9
|
+
export const EBrowserTools = {
|
|
10
|
+
CLICK: 'browser_click',
|
|
11
|
+
TYPE: 'browser_type',
|
|
12
|
+
NAVIGATE: 'browser_navigate',
|
|
13
|
+
SCROLL: 'browser_scroll',
|
|
14
|
+
EXTRACT: 'browser_extract',
|
|
15
|
+
HOVER: 'browser_hover',
|
|
16
|
+
WAIT: 'browser_wait',
|
|
17
|
+
BACK: 'browser_back',
|
|
18
|
+
SCREENSHOT: 'browser_screenshot',
|
|
19
|
+
GET_PAGE_STATE: 'browser_get_page_state',
|
|
20
|
+
// Skyvern-inspired additions for robust form handling
|
|
21
|
+
SELECT_OPTION: 'browser_select_option',
|
|
22
|
+
UPLOAD_FILE: 'browser_upload_file',
|
|
23
|
+
KEYPRESS: 'browser_keypress',
|
|
24
|
+
} as const;
|
|
25
|
+
|
|
26
|
+
export type BrowserToolName =
|
|
27
|
+
(typeof EBrowserTools)[keyof typeof EBrowserTools];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Callback function type for waiting on browser action results
|
|
31
|
+
* This allows the server (Ranger) to provide a callback that waits for the extension
|
|
32
|
+
* to POST results back to the server before returning to the LLM.
|
|
33
|
+
*
|
|
34
|
+
* @param action - The browser action (click, type, navigate, etc.)
|
|
35
|
+
* @param args - Arguments for the action
|
|
36
|
+
* @param toolCallId - Unique ID for this tool call (from config.toolCall.id)
|
|
37
|
+
* @returns Promise that resolves with the actual browser result (page state, etc.)
|
|
38
|
+
*/
|
|
39
|
+
export type BrowserToolCallback = (
|
|
40
|
+
action: string,
|
|
41
|
+
args: Record<string, unknown>,
|
|
42
|
+
toolCallId: string
|
|
43
|
+
) => Promise<BrowserActionResult>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Result returned from browser action execution
|
|
47
|
+
*/
|
|
48
|
+
export interface BrowserActionResult {
|
|
49
|
+
success: boolean;
|
|
50
|
+
url?: string;
|
|
51
|
+
title?: string;
|
|
52
|
+
elementList?: string; // Text-based element list
|
|
53
|
+
error?: string;
|
|
54
|
+
screenshot?: string; // Base64 screenshot (if requested)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Check if browser capability is available based on request headers or context
|
|
59
|
+
* The browser extension sets these headers when connected:
|
|
60
|
+
* - X-Ranger-Browser-Extension: true
|
|
61
|
+
* - X-Ranger-Browser-Capable: true
|
|
62
|
+
*/
|
|
63
|
+
export function hasBrowserCapability(req?: {
|
|
64
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
65
|
+
}): boolean {
|
|
66
|
+
if (!req?.headers) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const browserExtension = req.headers['x-ranger-browser-extension'];
|
|
71
|
+
const browserCapable = req.headers['x-ranger-browser-capable'];
|
|
72
|
+
|
|
73
|
+
return browserExtension === 'true' || browserCapable === 'true';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Tool schemas
|
|
77
|
+
const BrowserClickSchema = z.object({
|
|
78
|
+
index: z
|
|
79
|
+
.number()
|
|
80
|
+
.describe(
|
|
81
|
+
'The index number [0], [1], etc. of the element to click from the page state element list'
|
|
82
|
+
),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const BrowserTypeSchema = z.object({
|
|
86
|
+
index: z
|
|
87
|
+
.number()
|
|
88
|
+
.describe('The index number of the input element to type into'),
|
|
89
|
+
text: z.string().describe('The text to type into the element'),
|
|
90
|
+
pressEnter: z
|
|
91
|
+
.boolean()
|
|
92
|
+
.optional()
|
|
93
|
+
.describe('Whether to press Enter after typing (useful for search forms)'),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const BrowserNavigateSchema = z.object({
|
|
97
|
+
url: z
|
|
98
|
+
.string()
|
|
99
|
+
.describe('The full URL to navigate to (must include https://)'),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const BrowserScrollSchema = z.object({
|
|
103
|
+
direction: z
|
|
104
|
+
.enum(['up', 'down', 'left', 'right'])
|
|
105
|
+
.describe('Direction to scroll'),
|
|
106
|
+
amount: z
|
|
107
|
+
.number()
|
|
108
|
+
.optional()
|
|
109
|
+
.describe('Pixels to scroll (default: one viewport height)'),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const BrowserExtractSchema = z.object({
|
|
113
|
+
query: z
|
|
114
|
+
.string()
|
|
115
|
+
.optional()
|
|
116
|
+
.describe('Optional: specific content to extract from the page'),
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const BrowserHoverSchema = z.object({
|
|
120
|
+
index: z.number().describe('The index number of the element to hover over'),
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const BrowserWaitSchema = z.object({
|
|
124
|
+
duration: z
|
|
125
|
+
.number()
|
|
126
|
+
.optional()
|
|
127
|
+
.describe('Milliseconds to wait (default: 1000)'),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const BrowserBackSchema = z.object({});
|
|
131
|
+
|
|
132
|
+
const BrowserScreenshotSchema = z.object({});
|
|
133
|
+
|
|
134
|
+
const BrowserGetPageStateSchema = z.object({});
|
|
135
|
+
|
|
136
|
+
// Skyvern-inspired schemas for robust form handling
|
|
137
|
+
const BrowserSelectOptionSchema = z.object({
|
|
138
|
+
index: z
|
|
139
|
+
.number()
|
|
140
|
+
.describe('The index number of the select/dropdown element'),
|
|
141
|
+
value: z
|
|
142
|
+
.string()
|
|
143
|
+
.optional()
|
|
144
|
+
.describe('The value or label of the option to select. For native <select>, use the option text. For custom dropdowns, this is the option label to click.'),
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const BrowserUploadFileSchema = z.object({
|
|
148
|
+
index: z
|
|
149
|
+
.number()
|
|
150
|
+
.describe('The index number of the file input element'),
|
|
151
|
+
fileUrl: z
|
|
152
|
+
.string()
|
|
153
|
+
.describe('URL of the file to upload (the system will download and upload it)'),
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const BrowserKeypressSchema = z.object({
|
|
157
|
+
keys: z
|
|
158
|
+
.string()
|
|
159
|
+
.describe('Key(s) to press. Single key: "Enter", "Escape", "Tab", "ArrowDown". Combo: "Control+A", "Shift+Enter"'),
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Browser tool response interface
|
|
164
|
+
* This is what the extension returns after executing the action
|
|
165
|
+
*/
|
|
166
|
+
export interface BrowserToolResponse {
|
|
167
|
+
requiresBrowserExecution: true;
|
|
168
|
+
action: string;
|
|
169
|
+
args: Record<string, unknown>;
|
|
170
|
+
toolCallId?: string; // Added to help extension correlate with callback
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Options for creating browser tools
|
|
175
|
+
*/
|
|
176
|
+
export interface CreateBrowserToolsOptions {
|
|
177
|
+
/**
|
|
178
|
+
* Optional callback that waits for browser action results.
|
|
179
|
+
* When provided, tools will await this callback to get actual results from the extension.
|
|
180
|
+
* When not provided, tools return markers immediately (for non-server contexts).
|
|
181
|
+
*/
|
|
182
|
+
waitForResult?: BrowserToolCallback;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Format browser action result for LLM consumption
|
|
187
|
+
*/
|
|
188
|
+
function formatResultForLLM(
|
|
189
|
+
result: BrowserActionResult,
|
|
190
|
+
action: string
|
|
191
|
+
): string {
|
|
192
|
+
if (!result.success && result.error) {
|
|
193
|
+
return `Browser action "${action}" failed: ${result.error}`;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const parts: string[] = [];
|
|
197
|
+
|
|
198
|
+
if (result.url != null && result.url !== '') {
|
|
199
|
+
parts.push(`**Current URL:** ${result.url}`);
|
|
200
|
+
}
|
|
201
|
+
if (result.title != null && result.title !== '') {
|
|
202
|
+
parts.push(`**Page Title:** ${result.title}`);
|
|
203
|
+
}
|
|
204
|
+
if (result.elementList != null && result.elementList !== '') {
|
|
205
|
+
parts.push(`\n**Interactive Elements:**\n${result.elementList}`);
|
|
206
|
+
}
|
|
207
|
+
if (result.screenshot != null && result.screenshot !== '') {
|
|
208
|
+
parts.push('\n[Screenshot captured and displayed to user]');
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (parts.length === 0) {
|
|
212
|
+
return `Browser action "${action}" completed successfully.`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return parts.join('\n');
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Create browser tools with optional callback for waiting on results
|
|
220
|
+
*
|
|
221
|
+
* When waitForResult callback is provided:
|
|
222
|
+
* 1. Tool returns marker that triggers extension
|
|
223
|
+
* 2. Tool then awaits callback to get actual results
|
|
224
|
+
* 3. Returns real page state to LLM
|
|
225
|
+
*
|
|
226
|
+
* When no callback:
|
|
227
|
+
* 1. Tool returns marker only (for non-server contexts)
|
|
228
|
+
*
|
|
229
|
+
* NOTE: These tools use TEXT-BASED element lists, NOT screenshots
|
|
230
|
+
* Screenshots would be 100K+ tokens each - element lists are ~100 tokens
|
|
231
|
+
*/
|
|
232
|
+
export function createBrowserTools(
|
|
233
|
+
options?: CreateBrowserToolsOptions
|
|
234
|
+
): DynamicStructuredTool[] {
|
|
235
|
+
const { waitForResult } = options || {};
|
|
236
|
+
const tools: DynamicStructuredTool[] = [];
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Helper to create tool function that optionally waits for results
|
|
240
|
+
* The toolCallId is extracted from the RunnableConfig passed by LangChain
|
|
241
|
+
*/
|
|
242
|
+
const createToolFunction = (action: string) => {
|
|
243
|
+
return async (
|
|
244
|
+
args: Record<string, unknown>,
|
|
245
|
+
config?: { toolCall?: { id?: string } }
|
|
246
|
+
): Promise<string> => {
|
|
247
|
+
const toolCallId =
|
|
248
|
+
config?.toolCall?.id ??
|
|
249
|
+
`tool_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
250
|
+
|
|
251
|
+
// Create marker for extension
|
|
252
|
+
const marker: BrowserToolResponse = {
|
|
253
|
+
requiresBrowserExecution: true,
|
|
254
|
+
action,
|
|
255
|
+
args,
|
|
256
|
+
toolCallId,
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
// If no callback, return marker immediately (extension handles via SSE interception)
|
|
260
|
+
if (!waitForResult) {
|
|
261
|
+
return JSON.stringify(marker);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// With callback: wait for actual results from extension
|
|
265
|
+
// The marker is still returned initially via SSE, but we wait for the callback
|
|
266
|
+
try {
|
|
267
|
+
const result = await waitForResult(action, args, toolCallId);
|
|
268
|
+
return formatResultForLLM(result, action);
|
|
269
|
+
} catch (error) {
|
|
270
|
+
const errorMessage =
|
|
271
|
+
error instanceof Error ? error.message : String(error);
|
|
272
|
+
return `Browser action "${action}" failed: ${errorMessage}`;
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// browser_click
|
|
278
|
+
tools.push(
|
|
279
|
+
tool(createToolFunction('click'), {
|
|
280
|
+
name: EBrowserTools.CLICK,
|
|
281
|
+
description: `Click an element on the current web page by its index number.
|
|
282
|
+
The element list shows clickable items like: [0]<button>Submit</button> [1]<a href="/home">Home</a>
|
|
283
|
+
Use the index number in brackets to click that element.
|
|
284
|
+
After clicking, you receive an updated element list showing the new page state.`,
|
|
285
|
+
schema: BrowserClickSchema,
|
|
286
|
+
})
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
// browser_type
|
|
290
|
+
tools.push(
|
|
291
|
+
tool(createToolFunction('type'), {
|
|
292
|
+
name: EBrowserTools.TYPE,
|
|
293
|
+
description: `Type text into an input element on the page.
|
|
294
|
+
Find the input element in the list by its index (e.g., [5]<input placeholder="Search">).
|
|
295
|
+
Set pressEnter: true to submit forms after typing.
|
|
296
|
+
After typing, you receive an updated element list.`,
|
|
297
|
+
schema: BrowserTypeSchema,
|
|
298
|
+
})
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
// browser_navigate
|
|
302
|
+
tools.push(
|
|
303
|
+
tool(createToolFunction('navigate'), {
|
|
304
|
+
name: EBrowserTools.NAVIGATE,
|
|
305
|
+
description: `Navigate to a URL. Always include the full URL with https://.
|
|
306
|
+
After navigation, you receive the new page's element list.`,
|
|
307
|
+
schema: BrowserNavigateSchema,
|
|
308
|
+
})
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
// browser_scroll
|
|
312
|
+
tools.push(
|
|
313
|
+
tool(createToolFunction('scroll'), {
|
|
314
|
+
name: EBrowserTools.SCROLL,
|
|
315
|
+
description: `Scroll the page to reveal more content.
|
|
316
|
+
Use 'down' to scroll down, 'up' to scroll up.
|
|
317
|
+
After scrolling, you receive an updated element list with newly visible elements.`,
|
|
318
|
+
schema: BrowserScrollSchema,
|
|
319
|
+
})
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
// browser_extract
|
|
323
|
+
tools.push(
|
|
324
|
+
tool(createToolFunction('extract'), {
|
|
325
|
+
name: EBrowserTools.EXTRACT,
|
|
326
|
+
description: `Extract content from the current page.
|
|
327
|
+
Returns page URL, title, and element list.`,
|
|
328
|
+
schema: BrowserExtractSchema,
|
|
329
|
+
})
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
// browser_hover
|
|
333
|
+
tools.push(
|
|
334
|
+
tool(createToolFunction('hover'), {
|
|
335
|
+
name: EBrowserTools.HOVER,
|
|
336
|
+
description: `Hover over an element to reveal tooltips, dropdowns, or other hover-triggered content.
|
|
337
|
+
After hovering, you receive an updated element list with any newly revealed elements.`,
|
|
338
|
+
schema: BrowserHoverSchema,
|
|
339
|
+
})
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
// browser_wait
|
|
343
|
+
tools.push(
|
|
344
|
+
tool(createToolFunction('wait'), {
|
|
345
|
+
name: EBrowserTools.WAIT,
|
|
346
|
+
description: `Wait for a specified duration for page content to load.
|
|
347
|
+
Use this after actions that trigger async content loading.
|
|
348
|
+
After waiting, you receive an updated element list.`,
|
|
349
|
+
schema: BrowserWaitSchema,
|
|
350
|
+
})
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
// browser_back
|
|
354
|
+
tools.push(
|
|
355
|
+
tool(createToolFunction('back'), {
|
|
356
|
+
name: EBrowserTools.BACK,
|
|
357
|
+
description: `Go back to the previous page in browser history.
|
|
358
|
+
After going back, you receive the previous page's element list.`,
|
|
359
|
+
schema: BrowserBackSchema,
|
|
360
|
+
})
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
// browser_screenshot
|
|
364
|
+
tools.push(
|
|
365
|
+
tool(createToolFunction('screenshot'), {
|
|
366
|
+
name: EBrowserTools.SCREENSHOT,
|
|
367
|
+
description: `Capture a screenshot of the current page.
|
|
368
|
+
Returns the page state with a note that screenshot was displayed to the user.
|
|
369
|
+
Use browser_get_page_state to get the element list for automation.`,
|
|
370
|
+
schema: BrowserScreenshotSchema,
|
|
371
|
+
})
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
// browser_get_page_state
|
|
375
|
+
tools.push(
|
|
376
|
+
tool(createToolFunction('get_page_state'), {
|
|
377
|
+
name: EBrowserTools.GET_PAGE_STATE,
|
|
378
|
+
description: `Get the current page state including URL, title, and all interactive elements.
|
|
379
|
+
Use this at the start of a task to see what elements are available.
|
|
380
|
+
Returns a text list of elements with their index numbers for interaction.`,
|
|
381
|
+
schema: BrowserGetPageStateSchema,
|
|
382
|
+
})
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
// browser_select_option - Skyvern-inspired for robust dropdown handling
|
|
386
|
+
tools.push(
|
|
387
|
+
tool(createToolFunction('select_option'), {
|
|
388
|
+
name: EBrowserTools.SELECT_OPTION,
|
|
389
|
+
description: `Select an option from a dropdown or select element.
|
|
390
|
+
For native <select> elements: finds and selects the option by value/label.
|
|
391
|
+
For custom dropdowns: clicks to open, then clicks the matching option.
|
|
392
|
+
Use this instead of click for dropdowns - it handles both native and custom selects.
|
|
393
|
+
After selection, you receive an updated element list.`,
|
|
394
|
+
schema: BrowserSelectOptionSchema,
|
|
395
|
+
})
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
// browser_upload_file - Skyvern-inspired for file input handling
|
|
399
|
+
tools.push(
|
|
400
|
+
tool(createToolFunction('upload_file'), {
|
|
401
|
+
name: EBrowserTools.UPLOAD_FILE,
|
|
402
|
+
description: `Upload a file to a file input element.
|
|
403
|
+
Provide the index of the file input and the URL of the file to upload.
|
|
404
|
+
The system will download the file and attach it to the input.
|
|
405
|
+
After upload, you receive an updated element list.`,
|
|
406
|
+
schema: BrowserUploadFileSchema,
|
|
407
|
+
})
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
// browser_keypress - For keyboard shortcuts and special keys
|
|
411
|
+
tools.push(
|
|
412
|
+
tool(createToolFunction('keypress'), {
|
|
413
|
+
name: EBrowserTools.KEYPRESS,
|
|
414
|
+
description: `Press keyboard key(s) on the page.
|
|
415
|
+
Single keys: "Enter", "Escape", "Tab", "ArrowDown", "ArrowUp", "Backspace", "Delete"
|
|
416
|
+
Key combos: "Control+A" (select all), "Control+C" (copy), "Shift+Enter" (newline)
|
|
417
|
+
Use this for form submission, closing modals, navigating dropdowns.
|
|
418
|
+
After keypress, you receive an updated element list.`,
|
|
419
|
+
schema: BrowserKeypressSchema,
|
|
420
|
+
})
|
|
421
|
+
);
|
|
422
|
+
|
|
423
|
+
return tools;
|
|
424
|
+
}
|