@vymalo/opencode-browser 0.7.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/LICENSE +21 -0
- package/README.md +321 -0
- package/dist/agent-client.d.ts +54 -0
- package/dist/agent-client.js +180 -0
- package/dist/agent-client.js.map +1 -0
- package/dist/broker.d.ts +70 -0
- package/dist/broker.js +457 -0
- package/dist/broker.js.map +1 -0
- package/dist/catalog.d.ts +45 -0
- package/dist/catalog.js +532 -0
- package/dist/catalog.js.map +1 -0
- package/dist/endpoint.d.ts +41 -0
- package/dist/endpoint.js +117 -0
- package/dist/endpoint.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/lib.d.ts +12 -0
- package/dist/lib.js +12 -0
- package/dist/lib.js.map +1 -0
- package/dist/logging.d.ts +15 -0
- package/dist/logging.js +69 -0
- package/dist/logging.js.map +1 -0
- package/dist/opencode.d.ts +20 -0
- package/dist/opencode.js +149 -0
- package/dist/opencode.js.map +1 -0
- package/dist/protocol.d.ts +138 -0
- package/dist/protocol.js +126 -0
- package/dist/protocol.js.map +1 -0
- package/dist/schema.d.ts +51 -0
- package/dist/schema.js +50 -0
- package/dist/schema.js.map +1 -0
- package/dist/token-file.d.ts +12 -0
- package/dist/token-file.js +40 -0
- package/dist/token-file.js.map +1 -0
- package/dist/tools.d.ts +24 -0
- package/dist/tools.js +140 -0
- package/dist/tools.js.map +1 -0
- package/dist/transport.d.ts +32 -0
- package/dist/transport.js +71 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +74 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +66 -0
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
export const TOOL_GROUPS = ["page", "control", "debug"];
|
|
2
|
+
/** Groups registered when the operator doesn't specify — `debug` is opt-in. */
|
|
3
|
+
export const DEFAULT_GROUPS = ["page", "control"];
|
|
4
|
+
// ─── reusable fields ─────────────────────────────────────────────────────────
|
|
5
|
+
const group = {
|
|
6
|
+
type: "string",
|
|
7
|
+
description: "Named tab group the action targets. Created on first browser_open."
|
|
8
|
+
};
|
|
9
|
+
const tabId = {
|
|
10
|
+
type: "number",
|
|
11
|
+
optional: true,
|
|
12
|
+
description: "Specific tab id; defaults to the group's active tab."
|
|
13
|
+
};
|
|
14
|
+
const refField = {
|
|
15
|
+
type: "string",
|
|
16
|
+
optional: true,
|
|
17
|
+
description: "Element ref from a prior browser_snapshot."
|
|
18
|
+
};
|
|
19
|
+
const selectorField = { type: "string", optional: true, description: "CSS selector." };
|
|
20
|
+
// ─── helpers ─────────────────────────────────────────────────────────────────
|
|
21
|
+
function rec(value) {
|
|
22
|
+
return typeof value === "object" && value !== null ? value : {};
|
|
23
|
+
}
|
|
24
|
+
function describeTarget(a) {
|
|
25
|
+
if (typeof a.ref === "string") {
|
|
26
|
+
return `ref ${a.ref}`;
|
|
27
|
+
}
|
|
28
|
+
if (typeof a.selector === "string") {
|
|
29
|
+
return `selector ${a.selector}`;
|
|
30
|
+
}
|
|
31
|
+
if (typeof a.x === "number" && typeof a.y === "number") {
|
|
32
|
+
return `(${a.x}, ${a.y})`;
|
|
33
|
+
}
|
|
34
|
+
return "element";
|
|
35
|
+
}
|
|
36
|
+
const text = (t) => ({ kind: "text", text: t });
|
|
37
|
+
const json = (data, t) => ({ kind: "json", data, text: t });
|
|
38
|
+
/**
|
|
39
|
+
* The single source of truth for the browser tool surface, shared by the
|
|
40
|
+
* OpenCode plugin and the MCP server. Filter by `group` to gate what an agent
|
|
41
|
+
* sees.
|
|
42
|
+
*/
|
|
43
|
+
export const BROWSER_TOOLS = [
|
|
44
|
+
{
|
|
45
|
+
name: "browser_open",
|
|
46
|
+
group: "control",
|
|
47
|
+
action: "open",
|
|
48
|
+
description: "Open a new browser tab inside a named tab group (creates the group if it doesn't exist yet). Returns the tab id, final URL and page title.",
|
|
49
|
+
input: {
|
|
50
|
+
group,
|
|
51
|
+
url: { type: "string", optional: true, description: "URL to load. Omit for a blank tab." },
|
|
52
|
+
focus: {
|
|
53
|
+
type: "boolean",
|
|
54
|
+
optional: true,
|
|
55
|
+
description: "Bring the tab to the foreground (default true)."
|
|
56
|
+
},
|
|
57
|
+
target: {
|
|
58
|
+
type: "string",
|
|
59
|
+
optional: true,
|
|
60
|
+
description: "Which browser to open in (label or id from browser_targets). Omit unless several browsers are connected."
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
result: (data, args) => {
|
|
64
|
+
const d = rec(data);
|
|
65
|
+
return {
|
|
66
|
+
kind: "json",
|
|
67
|
+
data: d,
|
|
68
|
+
text: `Opened tab in group "${args.group}": ${d.title ?? "(untitled)"} — ${d.url ?? args.url ?? "about:blank"}`
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "browser_navigate",
|
|
74
|
+
group: "control",
|
|
75
|
+
action: "navigate",
|
|
76
|
+
description: "Navigate an existing tab in the group to a new URL.",
|
|
77
|
+
input: { group, url: { type: "string", description: "URL to navigate to." }, tabId },
|
|
78
|
+
result: (data, args) => {
|
|
79
|
+
const d = rec(data);
|
|
80
|
+
return {
|
|
81
|
+
kind: "json",
|
|
82
|
+
data: d,
|
|
83
|
+
text: `Navigated to ${d.url ?? args.url} (${d.title ?? ""})`.trim()
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "browser_click",
|
|
89
|
+
group: "control",
|
|
90
|
+
action: "click",
|
|
91
|
+
description: "Click an element. Target it by `ref` (from browser_snapshot, most reliable), CSS `selector`, or absolute `x`/`y` coordinates.",
|
|
92
|
+
input: {
|
|
93
|
+
group,
|
|
94
|
+
ref: refField,
|
|
95
|
+
selector: selectorField,
|
|
96
|
+
x: { type: "number", optional: true, description: "Absolute x coordinate (with y)." },
|
|
97
|
+
y: { type: "number", optional: true, description: "Absolute y coordinate (with x)." },
|
|
98
|
+
button: {
|
|
99
|
+
type: "string",
|
|
100
|
+
optional: true,
|
|
101
|
+
enum: ["left", "middle", "right"],
|
|
102
|
+
description: "Mouse button (default left)."
|
|
103
|
+
},
|
|
104
|
+
tabId
|
|
105
|
+
},
|
|
106
|
+
result: (_data, args) => text(`Clicked ${describeTarget(args)} in group "${args.group}".`)
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "browser_double_click",
|
|
110
|
+
group: "control",
|
|
111
|
+
action: "double_click",
|
|
112
|
+
description: "Double-click an element, targeted by `ref`, CSS `selector`, or `x`/`y` coordinates.",
|
|
113
|
+
input: {
|
|
114
|
+
group,
|
|
115
|
+
ref: refField,
|
|
116
|
+
selector: selectorField,
|
|
117
|
+
x: { type: "number", optional: true },
|
|
118
|
+
y: { type: "number", optional: true },
|
|
119
|
+
tabId
|
|
120
|
+
},
|
|
121
|
+
result: (_data, args) => text(`Double-clicked ${describeTarget(args)} in group "${args.group}".`)
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "browser_type",
|
|
125
|
+
group: "control",
|
|
126
|
+
action: "type",
|
|
127
|
+
description: "Type text into the focused element (or first focus `ref`/`selector`). Optionally press Enter after.",
|
|
128
|
+
input: {
|
|
129
|
+
group,
|
|
130
|
+
text: { type: "string", description: "Text to type." },
|
|
131
|
+
ref: refField,
|
|
132
|
+
selector: selectorField,
|
|
133
|
+
submit: { type: "boolean", optional: true, description: "Press Enter after typing." },
|
|
134
|
+
tabId
|
|
135
|
+
},
|
|
136
|
+
result: (_data, args) => text(`Typed ${String(args.text ?? "").length} character(s) into ${describeTarget(args)}${args.submit ? " and submitted" : ""}.`)
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "browser_fill",
|
|
140
|
+
group: "control",
|
|
141
|
+
action: "fill",
|
|
142
|
+
description: "Fill several form fields in one call. Each field targets a `ref` or CSS `selector` and sets its `value`.",
|
|
143
|
+
input: {
|
|
144
|
+
group,
|
|
145
|
+
fields: {
|
|
146
|
+
type: "array",
|
|
147
|
+
description: "Fields to fill, in order.",
|
|
148
|
+
items: {
|
|
149
|
+
type: "object",
|
|
150
|
+
properties: { ref: refField, selector: selectorField, value: { type: "string" } }
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
tabId
|
|
154
|
+
},
|
|
155
|
+
result: (data, args) => {
|
|
156
|
+
const requested = Array.isArray(args.fields) ? args.fields.length : 0;
|
|
157
|
+
const filled = typeof rec(data).filled === "number" ? rec(data).filled : requested;
|
|
158
|
+
const missed = requested - filled;
|
|
159
|
+
return text(`Filled ${filled} of ${requested} field(s) in group "${args.group}".${missed > 0 ? ` (${missed} not found)` : ""}`);
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: "browser_select",
|
|
164
|
+
group: "control",
|
|
165
|
+
action: "select",
|
|
166
|
+
description: "Choose option(s) in a <select> element, or set the selection of a control.",
|
|
167
|
+
input: {
|
|
168
|
+
group,
|
|
169
|
+
ref: refField,
|
|
170
|
+
selector: selectorField,
|
|
171
|
+
value: { type: "string", optional: true, description: "Single value to select." },
|
|
172
|
+
values: {
|
|
173
|
+
type: "array",
|
|
174
|
+
optional: true,
|
|
175
|
+
description: "Multiple values (multi-select).",
|
|
176
|
+
items: { type: "string" }
|
|
177
|
+
},
|
|
178
|
+
tabId
|
|
179
|
+
},
|
|
180
|
+
result: (_data, args) => {
|
|
181
|
+
const chosen = Array.isArray(args.values) ? args.values.join(", ") : (args.value ?? "");
|
|
182
|
+
return text(`Selected ${chosen} in ${describeTarget(args)}.`);
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
name: "browser_scroll",
|
|
187
|
+
group: "control",
|
|
188
|
+
action: "scroll",
|
|
189
|
+
description: "Scroll the page (or an element). Provide `deltaX`/`deltaY`, or `to: 'top' | 'bottom'`.",
|
|
190
|
+
input: {
|
|
191
|
+
group,
|
|
192
|
+
deltaX: { type: "number", optional: true },
|
|
193
|
+
deltaY: { type: "number", optional: true },
|
|
194
|
+
ref: {
|
|
195
|
+
type: "string",
|
|
196
|
+
optional: true,
|
|
197
|
+
description: "Scroll within this element instead of the page."
|
|
198
|
+
},
|
|
199
|
+
to: { type: "string", optional: true, enum: ["top", "bottom"] },
|
|
200
|
+
tabId
|
|
201
|
+
},
|
|
202
|
+
result: (_data, args) => text(`Scrolled in group "${args.group}".`)
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: "browser_press_key",
|
|
206
|
+
group: "control",
|
|
207
|
+
action: "press_key",
|
|
208
|
+
description: 'Press a single key or chord (e.g. "Enter", "Escape", "Control+a").',
|
|
209
|
+
input: { group, key: { type: "string", description: 'Key name, e.g. "Enter".' }, tabId },
|
|
210
|
+
result: (_data, args) => text(`Pressed ${args.key} in group "${args.group}".`)
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: "browser_wait",
|
|
214
|
+
group: "control",
|
|
215
|
+
action: "wait",
|
|
216
|
+
description: "Wait for a fixed delay (`ms`) or until a `selector` reaches `state` (visible/hidden/attached).",
|
|
217
|
+
input: {
|
|
218
|
+
group,
|
|
219
|
+
ms: { type: "number", optional: true, description: "Fixed delay in milliseconds." },
|
|
220
|
+
selector: { type: "string", optional: true, description: "CSS selector to wait for." },
|
|
221
|
+
state: { type: "string", optional: true, enum: ["visible", "hidden", "attached"] },
|
|
222
|
+
tabId
|
|
223
|
+
},
|
|
224
|
+
result: (_data, args) => text(args.selector
|
|
225
|
+
? `Waited for ${args.selector} (${args.state ?? "visible"}).`
|
|
226
|
+
: `Waited ${args.ms ?? 0}ms.`)
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: "browser_close",
|
|
230
|
+
group: "control",
|
|
231
|
+
action: "close",
|
|
232
|
+
description: "Close a tab (pass `tabId`) or the whole group (omit `tabId`).",
|
|
233
|
+
input: { group, tabId },
|
|
234
|
+
result: (_data, args) => text(args.tabId
|
|
235
|
+
? `Closed tab ${args.tabId} in group "${args.group}".`
|
|
236
|
+
: `Closed group "${args.group}".`)
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
name: "browser_release",
|
|
240
|
+
group: "control",
|
|
241
|
+
action: "release",
|
|
242
|
+
description: "Release control of the browser: stop driving and detach the debugger (clears the 'being debugged' banner) without closing tabs. The next browser_* call re-attaches. Use this when you're done so the user gets their browser back.",
|
|
243
|
+
input: {},
|
|
244
|
+
result: () => text("Released browser control. Tabs are left open; the next browser_* action re-attaches.")
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: "browser_snapshot",
|
|
248
|
+
group: "page",
|
|
249
|
+
action: "snapshot",
|
|
250
|
+
description: "Capture an accessibility/DOM snapshot of the page with stable element refs. Prefer this over guessing selectors — pass the returned refs to browser_click/type/etc.",
|
|
251
|
+
input: { group, tabId },
|
|
252
|
+
result: (data) => {
|
|
253
|
+
const d = rec(data);
|
|
254
|
+
return text(typeof d.snapshot === "string" ? d.snapshot : JSON.stringify(d, null, 2));
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: "browser_get_text",
|
|
259
|
+
group: "page",
|
|
260
|
+
action: "get_text",
|
|
261
|
+
description: "Extract the visible text / readable content of the group's active tab.",
|
|
262
|
+
input: { group, tabId },
|
|
263
|
+
result: (data) => {
|
|
264
|
+
const d = rec(data);
|
|
265
|
+
return text(typeof d.text === "string" ? d.text : JSON.stringify(d));
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
name: "browser_tabs",
|
|
270
|
+
group: "page",
|
|
271
|
+
action: "tabs",
|
|
272
|
+
description: "List open tab groups and their tabs. Omit `group` to list everything.",
|
|
273
|
+
input: { group: { type: "string", optional: true, description: "Restrict to one group." } },
|
|
274
|
+
params: (args) => ({ group: args.group }),
|
|
275
|
+
result: (data) => ({ kind: "json", data, text: JSON.stringify(data, null, 2) })
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
name: "browser_targets",
|
|
279
|
+
group: "page",
|
|
280
|
+
action: "targets",
|
|
281
|
+
description: "List the browsers (extensions) currently connected to the bridge, with their id, label, browser and owned groups. Use a returned id/label as `target` in browser_open when several are connected.",
|
|
282
|
+
input: {},
|
|
283
|
+
result: (data) => ({ kind: "json", data, text: JSON.stringify(data, null, 2) })
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
name: "browser_screenshot",
|
|
287
|
+
group: "page",
|
|
288
|
+
action: "screenshot",
|
|
289
|
+
description: "Capture a screenshot of the group's active tab. Returns the image (the OpenCode plugin saves it to disk and returns the path — use the read tool to view it).",
|
|
290
|
+
input: {
|
|
291
|
+
group,
|
|
292
|
+
fullPage: {
|
|
293
|
+
type: "boolean",
|
|
294
|
+
optional: true,
|
|
295
|
+
description: "Capture the full scrollable page, not just the viewport."
|
|
296
|
+
},
|
|
297
|
+
tabId
|
|
298
|
+
},
|
|
299
|
+
result: (data) => {
|
|
300
|
+
const d = rec(data);
|
|
301
|
+
const width = Number(d.width ?? 0);
|
|
302
|
+
const height = Number(d.height ?? 0);
|
|
303
|
+
return {
|
|
304
|
+
kind: "image",
|
|
305
|
+
base64: String(d.base64 ?? ""),
|
|
306
|
+
mimeType: "image/png",
|
|
307
|
+
width,
|
|
308
|
+
height,
|
|
309
|
+
partial: Boolean(d.partial),
|
|
310
|
+
text: `screenshot ${width}×${height}`
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
// ─── navigation (control) ──────────────────────────────────────────────────
|
|
315
|
+
{
|
|
316
|
+
name: "browser_back",
|
|
317
|
+
group: "control",
|
|
318
|
+
action: "back",
|
|
319
|
+
description: "Go back in the tab's history.",
|
|
320
|
+
input: { group, tabId },
|
|
321
|
+
result: (data) => json(rec(data), `Went back to ${rec(data).url ?? ""}`.trim())
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
name: "browser_forward",
|
|
325
|
+
group: "control",
|
|
326
|
+
action: "forward",
|
|
327
|
+
description: "Go forward in the tab's history.",
|
|
328
|
+
input: { group, tabId },
|
|
329
|
+
result: (data) => json(rec(data), `Went forward to ${rec(data).url ?? ""}`.trim())
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
name: "browser_reload",
|
|
333
|
+
group: "control",
|
|
334
|
+
action: "reload",
|
|
335
|
+
description: "Reload the group's active tab.",
|
|
336
|
+
input: { group, tabId },
|
|
337
|
+
result: (data) => json(rec(data), `Reloaded ${rec(data).url ?? ""}`.trim())
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
name: "browser_activate",
|
|
341
|
+
group: "control",
|
|
342
|
+
action: "activate",
|
|
343
|
+
description: "Bring a group's tab to the foreground (focus its window and tab).",
|
|
344
|
+
input: { group, tabId },
|
|
345
|
+
result: (data) => json(rec(data), `Activated tab ${rec(data).tabId ?? ""}`.trim())
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
name: "browser_hover",
|
|
349
|
+
group: "control",
|
|
350
|
+
action: "hover",
|
|
351
|
+
description: "Move the pointer over an element (reveals hover menus/tooltips). Target by `ref`, `selector`, or `x`/`y`.",
|
|
352
|
+
input: {
|
|
353
|
+
group,
|
|
354
|
+
ref: refField,
|
|
355
|
+
selector: selectorField,
|
|
356
|
+
x: { type: "number", optional: true },
|
|
357
|
+
y: { type: "number", optional: true },
|
|
358
|
+
tabId
|
|
359
|
+
},
|
|
360
|
+
result: (_d, args) => text(`Hovered ${describeTarget(args)} in group "${args.group}".`)
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
name: "browser_drag",
|
|
364
|
+
group: "control",
|
|
365
|
+
action: "drag",
|
|
366
|
+
description: "Drag from a source element to a target element (each by `ref` or `selector`).",
|
|
367
|
+
input: {
|
|
368
|
+
group,
|
|
369
|
+
fromRef: { type: "string", optional: true, description: "Source element ref." },
|
|
370
|
+
fromSelector: { type: "string", optional: true, description: "Source CSS selector." },
|
|
371
|
+
ref: { type: "string", optional: true, description: "Target element ref." },
|
|
372
|
+
selector: { type: "string", optional: true, description: "Target CSS selector." },
|
|
373
|
+
tabId
|
|
374
|
+
},
|
|
375
|
+
result: (_d, args) => text(`Dragged to ${describeTarget(args)} in group "${args.group}".`)
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
name: "browser_upload",
|
|
379
|
+
group: "control",
|
|
380
|
+
action: "upload",
|
|
381
|
+
description: "Set the files on a file <input>, by absolute path(s) on the machine running the bridge. CDP executor only (Chromium).",
|
|
382
|
+
input: {
|
|
383
|
+
group,
|
|
384
|
+
ref: refField,
|
|
385
|
+
selector: selectorField,
|
|
386
|
+
paths: {
|
|
387
|
+
type: "array",
|
|
388
|
+
description: "Absolute file path(s) to attach.",
|
|
389
|
+
items: { type: "string" }
|
|
390
|
+
},
|
|
391
|
+
tabId
|
|
392
|
+
},
|
|
393
|
+
result: (_d, args) => text(`Uploaded ${Array.isArray(args.paths) ? args.paths.length : 0} file(s) to ${describeTarget(args)}.`)
|
|
394
|
+
},
|
|
395
|
+
// ─── reading (page) ────────────────────────────────────────────────────────
|
|
396
|
+
{
|
|
397
|
+
name: "browser_get_html",
|
|
398
|
+
group: "page",
|
|
399
|
+
action: "get_html",
|
|
400
|
+
description: "Get the HTML of the page (or of a `ref`/`selector` element). `outer: false` for innerHTML.",
|
|
401
|
+
input: {
|
|
402
|
+
group,
|
|
403
|
+
ref: refField,
|
|
404
|
+
selector: selectorField,
|
|
405
|
+
outer: { type: "boolean", optional: true, description: "Outer HTML (default true)." },
|
|
406
|
+
tabId
|
|
407
|
+
},
|
|
408
|
+
result: (data) => text(String(rec(data).html ?? ""))
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
name: "browser_get_attribute",
|
|
412
|
+
group: "page",
|
|
413
|
+
action: "get_attribute",
|
|
414
|
+
description: "Read an element's tag, text, value, checked state, bounding box, and attributes (or one named attribute).",
|
|
415
|
+
input: {
|
|
416
|
+
group,
|
|
417
|
+
ref: refField,
|
|
418
|
+
selector: selectorField,
|
|
419
|
+
name: { type: "string", optional: true, description: "A single attribute name to read." },
|
|
420
|
+
tabId
|
|
421
|
+
},
|
|
422
|
+
result: (data) => json(rec(data), JSON.stringify(rec(data), null, 2))
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
name: "browser_query",
|
|
426
|
+
group: "page",
|
|
427
|
+
action: "query",
|
|
428
|
+
description: "Find visible elements matching a CSS selector. Returns each with a stable ref you can pass to other tools.",
|
|
429
|
+
input: {
|
|
430
|
+
group,
|
|
431
|
+
selector: { type: "string", description: "CSS selector to match." },
|
|
432
|
+
limit: { type: "number", optional: true, description: "Max matches (default 50)." },
|
|
433
|
+
tabId
|
|
434
|
+
},
|
|
435
|
+
result: (data) => json(rec(data), JSON.stringify(rec(data), null, 2))
|
|
436
|
+
},
|
|
437
|
+
// ─── debug (off by default) ────────────────────────────────────────────────
|
|
438
|
+
{
|
|
439
|
+
name: "browser_eval",
|
|
440
|
+
group: "debug",
|
|
441
|
+
action: "eval",
|
|
442
|
+
description: "Evaluate JavaScript in the page's DOM context and return the JSON-serializable result. Powerful — enabled only when the `debug` group is on.",
|
|
443
|
+
input: { group, code: { type: "string", description: "JavaScript to evaluate." }, tabId },
|
|
444
|
+
result: (data) => {
|
|
445
|
+
const r = rec(data).result;
|
|
446
|
+
return json(rec(data), typeof r === "string" ? r : JSON.stringify(r, null, 2));
|
|
447
|
+
}
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
name: "browser_console",
|
|
451
|
+
group: "debug",
|
|
452
|
+
action: "console",
|
|
453
|
+
description: "Return recent console output (logs, warnings, errors). CDP executor only (Chromium).",
|
|
454
|
+
input: { group, tabId },
|
|
455
|
+
result: (data) => {
|
|
456
|
+
const entries = rec(data).entries ?? [];
|
|
457
|
+
return json(rec(data), JSON.stringify(entries, null, 2));
|
|
458
|
+
}
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
name: "browser_network",
|
|
462
|
+
group: "debug",
|
|
463
|
+
action: "network",
|
|
464
|
+
description: "Return recent network requests (method, URL, status). CDP executor only (Chromium).",
|
|
465
|
+
input: { group, tabId },
|
|
466
|
+
result: (data) => {
|
|
467
|
+
const entries = rec(data).entries ?? [];
|
|
468
|
+
return json(rec(data), JSON.stringify(entries, null, 2));
|
|
469
|
+
}
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
name: "browser_handle_dialog",
|
|
473
|
+
group: "debug",
|
|
474
|
+
action: "handle_dialog",
|
|
475
|
+
description: "Accept or dismiss a pending JavaScript dialog (alert/confirm/prompt). CDP executor only (Chromium).",
|
|
476
|
+
input: {
|
|
477
|
+
group,
|
|
478
|
+
accept: { type: "boolean", optional: true, description: "Accept (default true) or dismiss." },
|
|
479
|
+
promptText: { type: "string", optional: true, description: "Text for a prompt() dialog." },
|
|
480
|
+
tabId
|
|
481
|
+
},
|
|
482
|
+
result: (_d, args) => text(`${args.accept === false ? "Dismissed" : "Accepted"} the dialog.`)
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
name: "browser_set_viewport",
|
|
486
|
+
group: "debug",
|
|
487
|
+
action: "set_viewport",
|
|
488
|
+
description: "Emulate a viewport size / device metrics. CDP executor only (Chromium).",
|
|
489
|
+
input: {
|
|
490
|
+
group,
|
|
491
|
+
width: { type: "number", description: "Viewport width in CSS px." },
|
|
492
|
+
height: { type: "number", description: "Viewport height in CSS px." },
|
|
493
|
+
mobile: { type: "boolean", optional: true, description: "Emulate a mobile device." },
|
|
494
|
+
deviceScaleFactor: {
|
|
495
|
+
type: "number",
|
|
496
|
+
optional: true,
|
|
497
|
+
description: "Device pixel ratio (0 = default)."
|
|
498
|
+
},
|
|
499
|
+
tabId
|
|
500
|
+
},
|
|
501
|
+
result: (_d, args) => text(`Set viewport to ${args.width}×${args.height}.`)
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
name: "browser_cookies",
|
|
505
|
+
group: "debug",
|
|
506
|
+
action: "cookies",
|
|
507
|
+
description: "Read or modify cookies. `op`: get (by url+name), list (by url), set (url+name+value), clear (url+name).",
|
|
508
|
+
input: {
|
|
509
|
+
group: {
|
|
510
|
+
type: "string",
|
|
511
|
+
optional: true,
|
|
512
|
+
description: "Group (unused; cookies are profile-wide)."
|
|
513
|
+
},
|
|
514
|
+
op: { type: "string", enum: ["get", "list", "set", "clear"], description: "Operation." },
|
|
515
|
+
url: { type: "string", optional: true, description: "URL the cookie applies to." },
|
|
516
|
+
name: { type: "string", optional: true },
|
|
517
|
+
value: { type: "string", optional: true },
|
|
518
|
+
domain: { type: "string", optional: true },
|
|
519
|
+
path: { type: "string", optional: true }
|
|
520
|
+
},
|
|
521
|
+
params: (args) => ({
|
|
522
|
+
op: args.op,
|
|
523
|
+
url: args.url,
|
|
524
|
+
name: args.name,
|
|
525
|
+
value: args.value,
|
|
526
|
+
domain: args.domain,
|
|
527
|
+
path: args.path
|
|
528
|
+
}),
|
|
529
|
+
result: (data) => json(rec(data), JSON.stringify(rec(data), null, 2))
|
|
530
|
+
}
|
|
531
|
+
];
|
|
532
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,WAAW,GAAyB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAU,CAAC;AACvF,+EAA+E;AAC/E,MAAM,CAAC,MAAM,cAAc,GAAyB,CAAC,MAAM,EAAE,SAAS,CAAU,CAAC;AAiCjF,gFAAgF;AAChF,MAAM,KAAK,GAAU;IACnB,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,oEAAoE;CAClF,CAAC;AACF,MAAM,KAAK,GAAU;IACnB,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,IAAI;IACd,WAAW,EAAE,sDAAsD;CACpE,CAAC;AACF,MAAM,QAAQ,GAAU;IACtB,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,IAAI;IACd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EAAE,4BAA4B,EAAE;YAClF,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;YACxC,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;YACzC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;YAC1C,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;SACzC;QACD,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACjB,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC;QACF,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;KACtE;CACF,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type AgentSocketFactory } from "./agent-client.js";
|
|
2
|
+
import { Broker } from "./broker.js";
|
|
3
|
+
import type { Logger } from "./logging.js";
|
|
4
|
+
import type { BrowserAction } from "./protocol.js";
|
|
5
|
+
import { type BridgeTransport } from "./transport.js";
|
|
6
|
+
export type EndpointMode = "host" | "guest" | "electing";
|
|
7
|
+
export interface EndpointOptions {
|
|
8
|
+
host: string;
|
|
9
|
+
port: number;
|
|
10
|
+
token: string;
|
|
11
|
+
executor?: "auto" | "cdp" | "content";
|
|
12
|
+
timeoutMs: number;
|
|
13
|
+
/** Descriptor sent in the agent hello (guest mode). */
|
|
14
|
+
label?: string;
|
|
15
|
+
/** Delay before retrying election after a drop. */
|
|
16
|
+
reelectMs?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface EndpointDeps {
|
|
19
|
+
logger: Logger;
|
|
20
|
+
/** Server transport for host mode (Bun.serve / Node ws). */
|
|
21
|
+
createServerTransport: () => BridgeTransport;
|
|
22
|
+
/** Client socket factory for guest mode. */
|
|
23
|
+
createAgentSocket: AgentSocketFactory;
|
|
24
|
+
/** ws URL to dial as a guest; defaults to ws://host:port. */
|
|
25
|
+
url?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface Endpoint {
|
|
28
|
+
send(action: BrowserAction, group: string, params: Record<string, unknown>, signal?: AbortSignal, target?: string): Promise<unknown>;
|
|
29
|
+
release(): void;
|
|
30
|
+
shutdown(): void;
|
|
31
|
+
mode(): EndpointMode;
|
|
32
|
+
/** The broker, when this endpoint is the host (else null) — for tests/extras. */
|
|
33
|
+
broker(): Broker | null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Unifies host and guest: tries to **bind** the port (election) — on success it
|
|
37
|
+
* hosts the broker and drives it via an in-process agent; on `EADDRINUSE` it
|
|
38
|
+
* connects to the existing broker as a guest agent. Re-elects on drop. Tools
|
|
39
|
+
* call `send()` and never know which mode they're in.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createEndpoint(opts: EndpointOptions, deps: EndpointDeps): Promise<Endpoint>;
|