@edlsh/browse-core 0.4.1 → 0.6.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 +17 -0
- package/dist/ask.d.ts +6 -2
- package/dist/ask.js +1 -1
- package/dist/broker-client.d.ts +2 -0
- package/dist/broker-client.js +7 -1
- package/dist/broker-protocol.d.ts +33 -0
- package/dist/broker-protocol.js +12 -2
- package/dist/broker.js +4 -4
- package/dist/cdp-guard.js +8 -7
- package/dist/extension-cache.d.ts +23 -0
- package/dist/extension-cache.js +48 -0
- package/dist/har.d.ts +39 -0
- package/dist/har.js +32 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/jev.d.ts +5 -0
- package/dist/jev.js +31 -0
- package/dist/page-operations.d.ts +91 -4
- package/dist/page-operations.js +270 -83
- package/dist/real-browser-ai.d.ts +16 -0
- package/dist/real-browser-ai.js +54 -0
- package/dist/real-browser-client.d.ts +36 -0
- package/dist/real-browser-client.js +127 -0
- package/dist/real-browser-session.d.ts +55 -0
- package/dist/real-browser-session.js +255 -0
- package/dist/schema.d.ts +202 -1
- package/dist/schema.js +116 -18
- package/dist/session.d.ts +79 -7
- package/dist/session.js +518 -270
- package/package.json +3 -2
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { NetworkCapture } from "./har.ts";
|
|
2
|
+
import type { BrowserParams } from "./schema.ts";
|
|
3
|
+
import { type BrowserOutput } from "./session.ts";
|
|
4
|
+
export interface RealBrowserPage {
|
|
5
|
+
tabId: string;
|
|
6
|
+
url: string;
|
|
7
|
+
title: string | null;
|
|
8
|
+
outline: string;
|
|
9
|
+
text: string;
|
|
10
|
+
image?: {
|
|
11
|
+
data: string;
|
|
12
|
+
mimeType: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare class RealBrowserSession {
|
|
16
|
+
private readonly client;
|
|
17
|
+
private readonly release;
|
|
18
|
+
readonly owner: string;
|
|
19
|
+
private readonly group;
|
|
20
|
+
private readonly allowedOrigins?;
|
|
21
|
+
/** The tab this conversation's next call acts on. */
|
|
22
|
+
private tab?;
|
|
23
|
+
/** Whether this conversation opened a tab, so close has a group to close. */
|
|
24
|
+
private opened;
|
|
25
|
+
private released;
|
|
26
|
+
/** The tab whose network traffic har_start is capturing. */
|
|
27
|
+
private recording?;
|
|
28
|
+
/** `group` titles this conversation's tab group in the browser; `allowedOrigins` fences every tab it opens. */
|
|
29
|
+
static open(command: readonly string[], identity: {
|
|
30
|
+
name: string;
|
|
31
|
+
version: string;
|
|
32
|
+
}, owner: string, group: string, allowedOrigins?: string[]): RealBrowserSession;
|
|
33
|
+
private constructor();
|
|
34
|
+
run(p: BrowserParams, signal: AbortSignal, timeoutMs: number): Promise<BrowserOutput>;
|
|
35
|
+
/** Reads a tab for ask and JEV in one script, so the outline, the text, and the viewport are of the same page. */
|
|
36
|
+
read(tabId: string | undefined, image: boolean, signal: AbortSignal, timeoutMs: number): Promise<RealBrowserPage>;
|
|
37
|
+
/** Runs one script in a tab and returns what it handed back, with the image when it took a screenshot. */
|
|
38
|
+
private script;
|
|
39
|
+
/** Opens a background tab in this conversation's group and selects it. */
|
|
40
|
+
private newTab;
|
|
41
|
+
/** Ends har_start's capture and returns it with the recorded tab's view. */
|
|
42
|
+
harStop(signal: AbortSignal, timeoutMs: number): Promise<{
|
|
43
|
+
capture: NetworkCapture;
|
|
44
|
+
view: Pick<BrowserOutput, "tabId" | "url" | "title">;
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* batch: the steps run in order, one script each, under one deadline. The first failure stops the rest and nothing
|
|
48
|
+
* is rolled back; the result says how many steps completed.
|
|
49
|
+
*/
|
|
50
|
+
private sequence;
|
|
51
|
+
/** Closes every tab this conversation opened. The browser, and the tabs the person lent, stay. */
|
|
52
|
+
close(signal: AbortSignal): Promise<void>;
|
|
53
|
+
private list;
|
|
54
|
+
private output;
|
|
55
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// One conversation's tabs in the user's real browser, driven through OpenCode Browse (see real-browser-client.ts).
|
|
2
|
+
import { RealBrowserClient } from "./real-browser-client.js";
|
|
3
|
+
import { BrowseToolError } from "./session.js";
|
|
4
|
+
/** One client per command for the conversations using it; the last to close ends its process, so a host can exit. */
|
|
5
|
+
const clients = new Map();
|
|
6
|
+
function toTab(tabId) {
|
|
7
|
+
return /^\d+$/.test(tabId) ? Number(tabId) : tabId;
|
|
8
|
+
}
|
|
9
|
+
/** The arguments a script reads from `p`. */
|
|
10
|
+
const ARGUMENTS = ["url", "selector", "value", "values", "key", "script", "fullPage", "durationMs", "loadState", "state", "deltaX", "deltaY", "x", "y", "message"];
|
|
11
|
+
/**
|
|
12
|
+
* `el` takes a snapshot ref (e12) or a selector; a bare XPath gets the prefix Playwright-style locators need. `timeout`
|
|
13
|
+
* ends a wait for an element or a page before the script's own deadline, whose error would not say what was missing.
|
|
14
|
+
*/
|
|
15
|
+
const PRELUDE = String.raw `const el = selector => /^e\d+$/.test(selector) ? ref(selector) : page.locator(/^\(*\/\//.test(selector) ? "xpath=" + selector : selector);
|
|
16
|
+
let data, shot, extra;`;
|
|
17
|
+
/**
|
|
18
|
+
* What a script hands back. OpenCode Browse returns a string as it is and anything else as JSON, and adds lines of its
|
|
19
|
+
* own around either, so the view travels percent-encoded between markers that survive both. A screenshot has to be
|
|
20
|
+
* returned as a value of its own for the result to carry the image, and `extra` is for a value too large to encode:
|
|
21
|
+
* it comes back as part of the JSON.
|
|
22
|
+
*/
|
|
23
|
+
const EPILOGUE = `const view = "@@browse-core:" + encodeURIComponent(JSON.stringify({ data, url: page.url(), title: await page.title().catch(() => null) })) + "@@";
|
|
24
|
+
return shot || extra !== undefined ? { view, shot, extra } : view;`;
|
|
25
|
+
const VIEW = /@@browse-core:([^@]*)@@/;
|
|
26
|
+
/** Each control as the body of an `execute` script, on OpenCode Browse's Playwright-style `page`. */
|
|
27
|
+
const BODIES = {
|
|
28
|
+
start: "if (p.url) await page.goto(p.url, { timeout });",
|
|
29
|
+
open: "await page.goto(p.url, { timeout });",
|
|
30
|
+
back: "await page.goBack();",
|
|
31
|
+
forward: "await page.goForward();",
|
|
32
|
+
reload: "await page.reload();",
|
|
33
|
+
// The default of 80 lines hides most of a long page.
|
|
34
|
+
snapshot: "data = String(await snapshot({ maxItems: 200 }));",
|
|
35
|
+
click: "await el(p.selector).click({ timeout });",
|
|
36
|
+
fill: "await el(p.selector).fill(p.value, { timeout });",
|
|
37
|
+
select: "data = { selected: await el(p.selector).selectOption(p.values, { timeout }) };",
|
|
38
|
+
press: "await page.keyboard.press(p.key);",
|
|
39
|
+
scroll: "await page.mouse.move(p.x ?? 640, p.y ?? 400); await page.mouse.wheel(p.deltaX ?? 0, p.deltaY ?? 0);",
|
|
40
|
+
wait: `if (p.durationMs !== undefined) await page.waitForTimeout(p.durationMs);
|
|
41
|
+
else if (p.selector !== undefined) await el(p.selector).waitFor({ state: p.state ?? "visible", timeout });
|
|
42
|
+
else await page.waitForLoadState(p.loadState, { timeout });`,
|
|
43
|
+
evaluate: "data = (await page.evaluate(p.script)) ?? null;",
|
|
44
|
+
screenshot: "shot = await page.screenshot({ fullPage: p.fullPage === true });",
|
|
45
|
+
handoff: "data = { handoff: (await handoff(p.message)) ?? null };",
|
|
46
|
+
har_start: 'await browse.network({ action: "start" });',
|
|
47
|
+
};
|
|
48
|
+
/** A page as ask and JEV read it: the outline with its refs, the visible text, and the viewport when asked for. */
|
|
49
|
+
const READ = `data = { outline: String(await snapshot({ maxItems: 200 })), text: await page.evaluate("document.body ? document.body.innerText : ''") };
|
|
50
|
+
if (p.image) shot = await page.screenshot({ fullPage: false });`;
|
|
51
|
+
export class RealBrowserSession {
|
|
52
|
+
client;
|
|
53
|
+
release;
|
|
54
|
+
owner;
|
|
55
|
+
group;
|
|
56
|
+
allowedOrigins;
|
|
57
|
+
/** The tab this conversation's next call acts on. */
|
|
58
|
+
tab;
|
|
59
|
+
/** Whether this conversation opened a tab, so close has a group to close. */
|
|
60
|
+
opened = false;
|
|
61
|
+
released = false;
|
|
62
|
+
/** The tab whose network traffic har_start is capturing. */
|
|
63
|
+
recording;
|
|
64
|
+
/** `group` titles this conversation's tab group in the browser; `allowedOrigins` fences every tab it opens. */
|
|
65
|
+
static open(command, identity, owner, group, allowedOrigins) {
|
|
66
|
+
const key = JSON.stringify(command);
|
|
67
|
+
let shared = clients.get(key);
|
|
68
|
+
if (!shared)
|
|
69
|
+
clients.set(key, shared = { client: new RealBrowserClient(command, identity), users: 0 });
|
|
70
|
+
const { client } = shared;
|
|
71
|
+
shared.users++;
|
|
72
|
+
return new RealBrowserSession(client, () => {
|
|
73
|
+
if (--shared.users)
|
|
74
|
+
return;
|
|
75
|
+
clients.delete(key);
|
|
76
|
+
client.close();
|
|
77
|
+
}, owner, group, allowedOrigins);
|
|
78
|
+
}
|
|
79
|
+
constructor(client, release, owner, group, allowedOrigins) {
|
|
80
|
+
this.client = client;
|
|
81
|
+
this.release = release;
|
|
82
|
+
this.owner = owner;
|
|
83
|
+
this.group = group;
|
|
84
|
+
this.allowedOrigins = allowedOrigins;
|
|
85
|
+
}
|
|
86
|
+
async run(p, signal, timeoutMs) {
|
|
87
|
+
if (p.action === "status")
|
|
88
|
+
return this.output(p.action, { data: { state: this.tab === undefined ? "no_tab" : "running", realBrowser: true, group: this.group } });
|
|
89
|
+
if (p.action === "close") {
|
|
90
|
+
await this.close(signal);
|
|
91
|
+
return { action: p.action, sessionId: null, backend: "local", origin: "connected", data: { closed: true, browserClosed: false } };
|
|
92
|
+
}
|
|
93
|
+
if (p.action === "tabs") {
|
|
94
|
+
const tabs = await this.list(signal);
|
|
95
|
+
return this.output(p.action, { data: { tabs: tabs.map(tab => ({ tabId: String(tab.tab), url: tab.url, title: tab.title, selected: tab.tab === this.tab })) } });
|
|
96
|
+
}
|
|
97
|
+
if (p.action === "tab_select" || p.action === "tab_close") {
|
|
98
|
+
const tabs = await this.list(signal);
|
|
99
|
+
const found = tabs.find(tab => String(tab.tab) === p.tabId);
|
|
100
|
+
if (!found)
|
|
101
|
+
throw new BrowseToolError("tab_missing", "This conversation has no such tab in the real browser. Call tabs to list its tabs.");
|
|
102
|
+
if (p.action === "tab_select") {
|
|
103
|
+
this.tab = found.tab;
|
|
104
|
+
return this.output(p.action, { url: found.url, title: found.title });
|
|
105
|
+
}
|
|
106
|
+
await this.client.call("tabs", { action: "close", tab: found.tab }, signal);
|
|
107
|
+
if (this.tab === found.tab)
|
|
108
|
+
this.tab = tabs.find(tab => tab.tab !== found.tab)?.tab;
|
|
109
|
+
return this.output(p.action, { data: { closedTabId: String(found.tab), selectedTabId: this.tab === undefined ? null : String(this.tab) } });
|
|
110
|
+
}
|
|
111
|
+
if (p.action === "tab_new" || ((p.action === "start" || p.action === "open") && this.tab === undefined)) {
|
|
112
|
+
const opened = await this.newTab(p.url, signal);
|
|
113
|
+
return this.output(p.action, { url: opened.url, title: opened.title });
|
|
114
|
+
}
|
|
115
|
+
if (p.action === "har_start") {
|
|
116
|
+
if (this.recording !== undefined)
|
|
117
|
+
throw new BrowseToolError("har_active", "A recording is already running. Call har_stop to write it first.");
|
|
118
|
+
// The capture belongs to a tab, so a recording that starts before any page has a blank one to start in.
|
|
119
|
+
if (this.tab === undefined)
|
|
120
|
+
await this.newTab(undefined, signal);
|
|
121
|
+
}
|
|
122
|
+
if (p.action === "batch")
|
|
123
|
+
return this.sequence(p, signal, timeoutMs);
|
|
124
|
+
const body = p.target === undefined ? BODIES[p.action] : undefined;
|
|
125
|
+
if (body === undefined) {
|
|
126
|
+
throw new BrowseToolError("unsupported_backend", `${p.target === undefined ? p.action : "target"} is not available in the user's real browser. Close it and start with backend "browserbase", or with headless true for a browser of your own.`);
|
|
127
|
+
}
|
|
128
|
+
const args = Object.fromEntries(ARGUMENTS.flatMap(name => p[name] === undefined ? [] : [[name, p[name]]]));
|
|
129
|
+
const { tab, view, image } = await this.script(p.action, p.tabId, args, body, signal, timeoutMs);
|
|
130
|
+
let data = view.data;
|
|
131
|
+
if (p.action === "har_start") {
|
|
132
|
+
this.recording = tab;
|
|
133
|
+
data = { recording: true, note: "Recording this tab only; a tab opened later is not recorded." };
|
|
134
|
+
}
|
|
135
|
+
if (p.action === "snapshot") {
|
|
136
|
+
const tree = String(data), limit = p.maxChars ?? 20_000;
|
|
137
|
+
data = { tree: tree.slice(0, limit), truncated: tree.length > limit };
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
...this.output(p.action, { url: view.url, title: view.title, ...(data === undefined ? {} : { data }) }, tab),
|
|
141
|
+
...(image ? { image: new Uint8Array(Buffer.from(image.data, "base64")) } : {}),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/** Reads a tab for ask and JEV in one script, so the outline, the text, and the viewport are of the same page. */
|
|
145
|
+
async read(tabId, image, signal, timeoutMs) {
|
|
146
|
+
const { tab, view, image: shot } = await this.script("read", tabId, { image }, READ, signal, timeoutMs);
|
|
147
|
+
const { outline, text } = view.data;
|
|
148
|
+
return { tabId: String(tab), url: view.url, title: view.title, outline, text, ...(shot ? { image: shot } : {}) };
|
|
149
|
+
}
|
|
150
|
+
/** Runs one script in a tab and returns what it handed back, with the image when it took a screenshot. */
|
|
151
|
+
async script(action, tabId, args, body, signal, timeoutMs) {
|
|
152
|
+
const tab = tabId === undefined ? this.tab : typeof tabId === "string" ? toTab(tabId) : tabId;
|
|
153
|
+
if (tab === undefined)
|
|
154
|
+
throw new BrowseToolError("tab_missing", "No tab is open in the real browser. Call open with a url.");
|
|
155
|
+
const code = [`const p = ${JSON.stringify(args)}, timeout = ${Math.max(500, timeoutMs - 2000)};`, PRELUDE, body, EPILOGUE].join("\n");
|
|
156
|
+
const result = await this.client.call("execute", { tab, code, timeoutMs: Math.max(1500, timeoutMs - 1000) }, signal).catch(error => {
|
|
157
|
+
// A failed script's message starts with the tab it ran in, which the caller already knows, and ends with where in the script it threw.
|
|
158
|
+
if (error instanceof BrowseToolError && error.code === "real_browser_error")
|
|
159
|
+
throw new BrowseToolError(error.code, error.message.replace(/^tab: \S+\s+/, "").replace(/\n\s+at .*$/s, ""));
|
|
160
|
+
throw error;
|
|
161
|
+
});
|
|
162
|
+
const encoded = VIEW.exec(result.text)?.[1];
|
|
163
|
+
if (encoded === undefined)
|
|
164
|
+
throw new BrowseToolError("real_browser_error", `The real browser returned no result for ${action}: ${result.text.slice(0, 300)}`);
|
|
165
|
+
this.tab ??= tab;
|
|
166
|
+
return { tab, view: JSON.parse(decodeURIComponent(encoded)), image: result.images[0], text: result.text };
|
|
167
|
+
}
|
|
168
|
+
/** Opens a background tab in this conversation's group and selects it. */
|
|
169
|
+
async newTab(url, signal) {
|
|
170
|
+
const created = await this.client.call("tabs", {
|
|
171
|
+
action: "new", group: this.group, ...(url ? { url } : {}), ...(this.allowedOrigins ? { allowedOrigins: this.allowedOrigins } : {}),
|
|
172
|
+
}, signal);
|
|
173
|
+
const opened = JSON.parse(created.text);
|
|
174
|
+
this.tab = opened.tab;
|
|
175
|
+
this.opened = true;
|
|
176
|
+
return opened;
|
|
177
|
+
}
|
|
178
|
+
/** Ends har_start's capture and returns it with the recorded tab's view. */
|
|
179
|
+
async harStop(signal, timeoutMs) {
|
|
180
|
+
const recording = this.recording;
|
|
181
|
+
if (recording === undefined)
|
|
182
|
+
throw new BrowseToolError("har_not_started", "No recording is running in this browser. Call har_start, perform the actions, then har_stop.");
|
|
183
|
+
const { view, text } = await this.script("har_stop", recording, {}, 'extra = await browse.network({ action: "stop" });', signal, timeoutMs);
|
|
184
|
+
this.recording = undefined;
|
|
185
|
+
// The capture is the JSON between OpenCode Browse's first line (the tab) and its closing notes.
|
|
186
|
+
const start = text.indexOf("\n\n") + 2, end = text.indexOf("\n\n", start);
|
|
187
|
+
let capture;
|
|
188
|
+
try {
|
|
189
|
+
capture = JSON.parse(text.slice(start, end < 0 ? undefined : end)).extra;
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
throw new BrowseToolError("har_failed", "The recording stopped, but the real browser's reply could not be read, so no HAR was written.");
|
|
193
|
+
}
|
|
194
|
+
return { capture, view: { tabId: String(recording), url: view.url, title: view.title } };
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* batch: the steps run in order, one script each, under one deadline. The first failure stops the rest and nothing
|
|
198
|
+
* is rolled back; the result says how many steps completed.
|
|
199
|
+
*/
|
|
200
|
+
async sequence(p, signal, timeoutMs) {
|
|
201
|
+
// SAFETY: a step is a direct control's arguments, and every direct control is a BrowserParams.
|
|
202
|
+
const steps = p.steps.map(step => ({ ...step, tabId: p.tabId }));
|
|
203
|
+
const began = Date.now();
|
|
204
|
+
const results = [];
|
|
205
|
+
const progress = { total: steps.length, completed: 0, outcomeUnknown: false };
|
|
206
|
+
for (const step of steps) {
|
|
207
|
+
try {
|
|
208
|
+
const { action, url, title, data } = await this.run(step, signal, Math.max(1_000, timeoutMs - (Date.now() - began)));
|
|
209
|
+
results.push({ action, url, title, ...(data === undefined ? {} : { data }) });
|
|
210
|
+
progress.completed = results.length;
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
// A deadline or cancellation leaves the step's outcome unknown, which the caller reports.
|
|
214
|
+
if (signal.aborted || !(error instanceof BrowseToolError))
|
|
215
|
+
throw error;
|
|
216
|
+
progress.failedIndex = results.length;
|
|
217
|
+
// A script that failed did not act; a server that went away may have.
|
|
218
|
+
progress.outcomeUnknown = error.code === "real_browser_unreachable";
|
|
219
|
+
progress.error = { code: error.code, message: error.message.slice(0, 4000) };
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const last = results.at(-1);
|
|
224
|
+
return {
|
|
225
|
+
...this.output(p.action, last ? { url: last.url, title: last.title } : {}),
|
|
226
|
+
// Progress comes before the results, so it survives a host that truncates a long result.
|
|
227
|
+
batch: progress, data: { results },
|
|
228
|
+
...(progress.error ? {
|
|
229
|
+
isError: true, code: progress.error.code,
|
|
230
|
+
note: "The batch stopped at the failed step: later steps did not run, and earlier ones were not rolled back. Inspect the page before repeating anything.",
|
|
231
|
+
} : {}),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/** Closes every tab this conversation opened. The browser, and the tabs the person lent, stay. */
|
|
235
|
+
async close(signal) {
|
|
236
|
+
if (this.released)
|
|
237
|
+
return;
|
|
238
|
+
this.released = true;
|
|
239
|
+
try {
|
|
240
|
+
if (this.opened)
|
|
241
|
+
await this.client.call("tabs", { action: "close", group: this.group }, signal);
|
|
242
|
+
}
|
|
243
|
+
finally {
|
|
244
|
+
this.tab = undefined;
|
|
245
|
+
this.recording = undefined;
|
|
246
|
+
this.release();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
async list(signal) {
|
|
250
|
+
return JSON.parse((await this.client.call("tabs", { action: "list", group: this.group }, signal)).text).tabs;
|
|
251
|
+
}
|
|
252
|
+
output(action, view, tab = this.tab) {
|
|
253
|
+
return { action, sessionId: null, backend: "local", origin: "connected", ...(tab === undefined ? {} : { tabId: String(tab) }), ...view };
|
|
254
|
+
}
|
|
255
|
+
}
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,5 +1,126 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
/** A step has no arguments of its own: every field is the direct control's definition above, so it validates the same way. */
|
|
3
|
+
declare const batchStepFields: z.ZodObject<{
|
|
4
|
+
action: z.ZodEnum<{
|
|
5
|
+
back: "back";
|
|
6
|
+
click: "click";
|
|
7
|
+
evaluate: "evaluate";
|
|
8
|
+
fill: "fill";
|
|
9
|
+
forward: "forward";
|
|
10
|
+
open: "open";
|
|
11
|
+
press: "press";
|
|
12
|
+
reload: "reload";
|
|
13
|
+
scroll: "scroll";
|
|
14
|
+
select: "select";
|
|
15
|
+
snapshot: "snapshot";
|
|
16
|
+
wait: "wait";
|
|
17
|
+
}>;
|
|
18
|
+
url: z.ZodOptional<z.ZodURL>;
|
|
19
|
+
selector: z.ZodOptional<z.ZodString>;
|
|
20
|
+
value: z.ZodOptional<z.ZodString>;
|
|
21
|
+
values: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
22
|
+
key: z.ZodOptional<z.ZodString>;
|
|
23
|
+
deltaX: z.ZodOptional<z.ZodNumber>;
|
|
24
|
+
deltaY: z.ZodOptional<z.ZodNumber>;
|
|
25
|
+
x: z.ZodOptional<z.ZodNumber>;
|
|
26
|
+
y: z.ZodOptional<z.ZodNumber>;
|
|
27
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
28
|
+
loadState: z.ZodOptional<z.ZodEnum<{
|
|
29
|
+
domcontentloaded: "domcontentloaded";
|
|
30
|
+
load: "load";
|
|
31
|
+
networkidle: "networkidle";
|
|
32
|
+
}>>;
|
|
33
|
+
state: z.ZodOptional<z.ZodEnum<{
|
|
34
|
+
attached: "attached";
|
|
35
|
+
detached: "detached";
|
|
36
|
+
hidden: "hidden";
|
|
37
|
+
visible: "visible";
|
|
38
|
+
}>>;
|
|
39
|
+
script: z.ZodOptional<z.ZodString>;
|
|
40
|
+
maxChars: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
}, z.core.$strict>;
|
|
42
|
+
/** One validated batch step. It is a flat object, so `{ ...step, tabId }` runs like the same call on its own. */
|
|
43
|
+
export type BatchStep = z.infer<typeof batchStepFields>;
|
|
44
|
+
/** The browse tool's parameters without batch: what a host that has not adopted batch registers. */
|
|
2
45
|
export declare const browserParameters: z.ZodObject<{
|
|
46
|
+
backend: z.ZodOptional<z.ZodEnum<{
|
|
47
|
+
browserbase: "browserbase";
|
|
48
|
+
local: "local";
|
|
49
|
+
}>>;
|
|
50
|
+
cdpUrl: z.ZodOptional<z.ZodURL>;
|
|
51
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
52
|
+
extensionCdpUrl: z.ZodOptional<z.ZodURL>;
|
|
53
|
+
endpoint: z.ZodOptional<z.ZodString>;
|
|
54
|
+
headless: z.ZodOptional<z.ZodBoolean>;
|
|
55
|
+
tabId: z.ZodOptional<z.ZodString>;
|
|
56
|
+
url: z.ZodOptional<z.ZodURL>;
|
|
57
|
+
contextId: z.ZodOptional<z.ZodString>;
|
|
58
|
+
allowedDomains: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
59
|
+
blockedDomains: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
60
|
+
proxyCountry: z.ZodOptional<z.ZodString>;
|
|
61
|
+
name: z.ZodOptional<z.ZodString>;
|
|
62
|
+
browser: z.ZodOptional<z.ZodEnum<{
|
|
63
|
+
arc: "arc";
|
|
64
|
+
brave: "brave";
|
|
65
|
+
chrome: "chrome";
|
|
66
|
+
chromium: "chromium";
|
|
67
|
+
edge: "edge";
|
|
68
|
+
helium: "helium";
|
|
69
|
+
opera: "opera";
|
|
70
|
+
vivaldi: "vivaldi";
|
|
71
|
+
}>>;
|
|
72
|
+
domains: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
73
|
+
profile: z.ZodOptional<z.ZodString>;
|
|
74
|
+
selector: z.ZodOptional<z.ZodString>;
|
|
75
|
+
target: z.ZodOptional<z.ZodString>;
|
|
76
|
+
visual: z.ZodOptional<z.ZodBoolean>;
|
|
77
|
+
value: z.ZodOptional<z.ZodString>;
|
|
78
|
+
values: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
79
|
+
key: z.ZodOptional<z.ZodString>;
|
|
80
|
+
deltaX: z.ZodOptional<z.ZodNumber>;
|
|
81
|
+
deltaY: z.ZodOptional<z.ZodNumber>;
|
|
82
|
+
x: z.ZodOptional<z.ZodNumber>;
|
|
83
|
+
y: z.ZodOptional<z.ZodNumber>;
|
|
84
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
85
|
+
loadState: z.ZodOptional<z.ZodEnum<{
|
|
86
|
+
domcontentloaded: "domcontentloaded";
|
|
87
|
+
load: "load";
|
|
88
|
+
networkidle: "networkidle";
|
|
89
|
+
}>>;
|
|
90
|
+
state: z.ZodOptional<z.ZodEnum<{
|
|
91
|
+
attached: "attached";
|
|
92
|
+
detached: "detached";
|
|
93
|
+
hidden: "hidden";
|
|
94
|
+
visible: "visible";
|
|
95
|
+
}>>;
|
|
96
|
+
script: z.ZodOptional<z.ZodString>;
|
|
97
|
+
fullPage: z.ZodOptional<z.ZodBoolean>;
|
|
98
|
+
maxChars: z.ZodOptional<z.ZodNumber>;
|
|
99
|
+
fields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
100
|
+
type: z.ZodEnum<{
|
|
101
|
+
bool: "bool";
|
|
102
|
+
choice: "choice";
|
|
103
|
+
date: "date";
|
|
104
|
+
datetime: "datetime";
|
|
105
|
+
duration: "duration";
|
|
106
|
+
number: "number";
|
|
107
|
+
text: "text";
|
|
108
|
+
}>;
|
|
109
|
+
instructions: z.ZodString;
|
|
110
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
111
|
+
unit: z.ZodOptional<z.ZodEnum<{
|
|
112
|
+
days: "days";
|
|
113
|
+
hours: "hours";
|
|
114
|
+
minutes: "minutes";
|
|
115
|
+
months: "months";
|
|
116
|
+
seconds: "seconds";
|
|
117
|
+
weeks: "weeks";
|
|
118
|
+
years: "years";
|
|
119
|
+
}>>;
|
|
120
|
+
}, z.core.$strict>>>;
|
|
121
|
+
message: z.ZodOptional<z.ZodString>;
|
|
122
|
+
path: z.ZodOptional<z.ZodString>;
|
|
123
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
3
124
|
action: z.ZodEnum<{
|
|
4
125
|
ask: "ask";
|
|
5
126
|
back: "back";
|
|
@@ -11,6 +132,7 @@ export declare const browserParameters: z.ZodObject<{
|
|
|
11
132
|
evaluate: "evaluate";
|
|
12
133
|
fill: "fill";
|
|
13
134
|
forward: "forward";
|
|
135
|
+
handoff: "handoff";
|
|
14
136
|
har_start: "har_start";
|
|
15
137
|
har_stop: "har_stop";
|
|
16
138
|
live_view: "live_view";
|
|
@@ -29,6 +151,12 @@ export declare const browserParameters: z.ZodObject<{
|
|
|
29
151
|
tabs: "tabs";
|
|
30
152
|
wait: "wait";
|
|
31
153
|
}>;
|
|
154
|
+
}, z.core.$strict>;
|
|
155
|
+
/**
|
|
156
|
+
* The browse tool's parameters with the batch action. A host opts in by registering this schema, since it owns the
|
|
157
|
+
* prompts and approval rules a batch needs: one call can navigate, act, and run page script.
|
|
158
|
+
*/
|
|
159
|
+
export declare const browserBatchParameters: z.ZodObject<{
|
|
32
160
|
backend: z.ZodOptional<z.ZodEnum<{
|
|
33
161
|
browserbase: "browserbase";
|
|
34
162
|
local: "local";
|
|
@@ -104,8 +232,79 @@ export declare const browserParameters: z.ZodObject<{
|
|
|
104
232
|
years: "years";
|
|
105
233
|
}>>;
|
|
106
234
|
}, z.core.$strict>>>;
|
|
235
|
+
message: z.ZodOptional<z.ZodString>;
|
|
107
236
|
path: z.ZodOptional<z.ZodString>;
|
|
108
237
|
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
238
|
+
action: z.ZodEnum<{
|
|
239
|
+
ask: "ask";
|
|
240
|
+
back: "back";
|
|
241
|
+
batch: "batch";
|
|
242
|
+
click: "click";
|
|
243
|
+
close: "close";
|
|
244
|
+
context_create: "context_create";
|
|
245
|
+
cookie_import: "cookie_import";
|
|
246
|
+
cookie_profiles: "cookie_profiles";
|
|
247
|
+
evaluate: "evaluate";
|
|
248
|
+
fill: "fill";
|
|
249
|
+
forward: "forward";
|
|
250
|
+
handoff: "handoff";
|
|
251
|
+
har_start: "har_start";
|
|
252
|
+
har_stop: "har_stop";
|
|
253
|
+
live_view: "live_view";
|
|
254
|
+
open: "open";
|
|
255
|
+
press: "press";
|
|
256
|
+
reload: "reload";
|
|
257
|
+
screenshot: "screenshot";
|
|
258
|
+
scroll: "scroll";
|
|
259
|
+
select: "select";
|
|
260
|
+
snapshot: "snapshot";
|
|
261
|
+
start: "start";
|
|
262
|
+
status: "status";
|
|
263
|
+
tab_close: "tab_close";
|
|
264
|
+
tab_new: "tab_new";
|
|
265
|
+
tab_select: "tab_select";
|
|
266
|
+
tabs: "tabs";
|
|
267
|
+
wait: "wait";
|
|
268
|
+
}>;
|
|
269
|
+
steps: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
270
|
+
action: z.ZodEnum<{
|
|
271
|
+
back: "back";
|
|
272
|
+
click: "click";
|
|
273
|
+
evaluate: "evaluate";
|
|
274
|
+
fill: "fill";
|
|
275
|
+
forward: "forward";
|
|
276
|
+
open: "open";
|
|
277
|
+
press: "press";
|
|
278
|
+
reload: "reload";
|
|
279
|
+
scroll: "scroll";
|
|
280
|
+
select: "select";
|
|
281
|
+
snapshot: "snapshot";
|
|
282
|
+
wait: "wait";
|
|
283
|
+
}>;
|
|
284
|
+
url: z.ZodOptional<z.ZodURL>;
|
|
285
|
+
selector: z.ZodOptional<z.ZodString>;
|
|
286
|
+
value: z.ZodOptional<z.ZodString>;
|
|
287
|
+
values: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
288
|
+
key: z.ZodOptional<z.ZodString>;
|
|
289
|
+
deltaX: z.ZodOptional<z.ZodNumber>;
|
|
290
|
+
deltaY: z.ZodOptional<z.ZodNumber>;
|
|
291
|
+
x: z.ZodOptional<z.ZodNumber>;
|
|
292
|
+
y: z.ZodOptional<z.ZodNumber>;
|
|
293
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
294
|
+
loadState: z.ZodOptional<z.ZodEnum<{
|
|
295
|
+
domcontentloaded: "domcontentloaded";
|
|
296
|
+
load: "load";
|
|
297
|
+
networkidle: "networkidle";
|
|
298
|
+
}>>;
|
|
299
|
+
state: z.ZodOptional<z.ZodEnum<{
|
|
300
|
+
attached: "attached";
|
|
301
|
+
detached: "detached";
|
|
302
|
+
hidden: "hidden";
|
|
303
|
+
visible: "visible";
|
|
304
|
+
}>>;
|
|
305
|
+
script: z.ZodOptional<z.ZodString>;
|
|
306
|
+
maxChars: z.ZodOptional<z.ZodNumber>;
|
|
307
|
+
}, z.core.$strict>>>;
|
|
109
308
|
}, z.core.$strict>;
|
|
110
309
|
export declare const aiParameters: z.ZodObject<{
|
|
111
310
|
action: z.ZodEnum<{
|
|
@@ -118,6 +317,8 @@ export declare const aiParameters: z.ZodObject<{
|
|
|
118
317
|
schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
119
318
|
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
120
319
|
}, z.core.$strict>;
|
|
121
|
-
|
|
320
|
+
/** Every call the core runs, batch included; a host that registers browserParameters never sends one. */
|
|
321
|
+
export type BrowserParams = z.infer<typeof browserBatchParameters>;
|
|
122
322
|
export type AskFields = NonNullable<BrowserParams["fields"]>;
|
|
123
323
|
export type AIParams = z.infer<typeof aiParameters>;
|
|
324
|
+
export {};
|