@edlsh/browse-core 0.4.0 → 0.5.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.
@@ -1,85 +1,246 @@
1
- /** Serialized into the worker: executable dependencies must stay inside this function. */
1
+ /**
2
+ * Asks a running batch to stop before its next step. A request of its own, since the worker runs it while the batch waits
3
+ * on a step. Serialized into the worker: no outside dependencies.
4
+ */
5
+ export async function cancelPageBatch(_context, input) {
6
+ // SAFETY: this worker global is created and read only by these two callbacks; page scripts have their own globals.
7
+ const batches = globalThis.__browseBatches ??= new Map();
8
+ const control = batches.get(input.id) ?? { cancelled: false };
9
+ control.cancelled = true;
10
+ batches.set(input.id, control);
11
+ // Kept in case the stop arrives before the batch starts; dropped if the batch never does.
12
+ setTimeout(() => { if (batches.get(input.id) === control)
13
+ batches.delete(input.id); }, input.ttlMs);
14
+ return true;
15
+ }
2
16
  export async function pageOperation({ page, context }, input) {
3
- const control = input.action === "click" || input.action === "fill" || input.action === "select";
4
- const base = control ? page.locator(input.selector) : undefined;
5
- const locator = input.nth === undefined ? base : base.nth(input.nth);
6
- if (control) {
7
- // Independent reads can overlap. Observe rejections even when cardinality rejects the target first.
8
- const settle = (work) => work.then(value => ({ ok: true, value }), (error) => ({ ok: false, error }));
9
- const optionsRead = input.action === "select" ? settle(locator.innerHtml()) : undefined;
10
- // Snapshot ref IDs name DOM nodes, so a fresh snapshot also detects an element replaced at the same XPath.
11
- const [count, url, fresh] = await Promise.all([base.count(), page.url(), input.reference ? page.snapshot({ includeIframes: true }) : undefined]);
12
- const found = count > (input.nth ?? 0);
13
- const optionsResult = found && optionsRead ? await optionsRead : undefined;
14
- if (optionsResult && !optionsResult.ok)
15
- throw optionsResult.error;
16
- const html = optionsResult?.ok ? optionsResult.value : undefined;
17
- const failure = (code, message) => ({ tabId: page.pageId, url, error: { code, message } });
18
- if (input.reference && (url !== input.reference.url || fresh.xpathMap[input.reference.id] !== input.reference.xpath)) {
19
- return failure("stale_ref", url !== input.reference.url
20
- ? "The tab navigated since that snapshot. Take a new snapshot."
21
- : "The referenced element changed or disappeared. Take a new snapshot.");
17
+ let batch;
18
+ if (!("steps" in input))
19
+ return execute(input);
20
+ // SAFETY: as in cancelPageBatch.
21
+ const batches = globalThis.__browseBatches ??= new Map();
22
+ const control = batches.get(input.id) ?? { cancelled: false };
23
+ batch = control;
24
+ batches.set(input.id, control);
25
+ const results = [];
26
+ const stop = (code, message, outcomeUnknown = false) => ({ results, failure: { index: results.length, code, message, outcomeUnknown } });
27
+ // Refs from before the batch name nodes of the page as it was: a step that can replace nodes ends their use.
28
+ let refsValid = true;
29
+ const expires = performance.now() + input.timeoutMs;
30
+ try {
31
+ for (const step of input.steps) {
32
+ const remaining = Math.ceil(expires - performance.now());
33
+ if (control.cancelled)
34
+ return stop("cancelled", "The batch was cancelled before this step.");
35
+ if (remaining <= 0)
36
+ return stop("timeout", "The batch's deadline passed before this step.");
37
+ if (step.reference && !refsValid)
38
+ return stop("stale_ref", "An earlier step in this batch ended the use of this snapshot reference. After a navigation, click, press, evaluate, or snapshot step, use a literal selector, or take a new snapshot and send the rest as another call.");
39
+ const result = await execute({ ...step, pageTimeoutMs: Math.min(step.pageTimeoutMs, Math.ceil(Math.max(remaining - 2_000, remaining / 2))), readTimeoutMs: Math.min(step.readTimeoutMs, remaining) });
40
+ if (result.error)
41
+ return stop(result.error.code, result.error.message);
42
+ results.push(result);
43
+ if (step.action !== "fill" && step.action !== "select" && step.action !== "scroll" && step.action !== "wait")
44
+ refsValid = false;
22
45
  }
23
- if (input.nth === undefined ? count !== 1 : count <= input.nth) {
24
- return failure(count && input.nth === undefined ? "ambiguous_target" : "not_found", `The selector matched ${count} element(s)${input.nth === undefined ? "; it must match exactly one" : `; position ${input.nth + 1} does not exist`}. `
25
- + "Use a ref from a fresh snapshot, or (xpath)[n] for the nth match. Playwright-only syntax such as :has-text() or >> nth= is not supported.");
46
+ return { results };
47
+ }
48
+ catch (cause) {
49
+ return stop("browser_error", cause instanceof Error ? cause.message : String(cause), true);
50
+ }
51
+ finally {
52
+ if (batches.get(input.id) === control)
53
+ batches.delete(input.id);
54
+ }
55
+ async function execute(input) {
56
+ const control = input.action === "click" || input.action === "fill" || input.action === "select";
57
+ const base = control ? page.locator(input.selector) : undefined;
58
+ const locator = input.nth === undefined ? base : base.nth(input.nth);
59
+ /** A tab's first history entry, before any page: about:blank, or Stagehand's own start page for tabs it opens. */
60
+ const startPage = /^(?:about:blank|chrome-extension:\/\/[a-p]{32}\/blank\.html)$/;
61
+ if (control || input.reference) {
62
+ // Independent reads can overlap. Observe rejections even when cardinality rejects the target first.
63
+ const settle = (work) => work.then(value => ({ ok: true, value }), (error) => ({ ok: false, error }));
64
+ const optionsRead = input.action === "select" ? settle(locator.innerHtml()) : undefined;
65
+ // Snapshot ref IDs name DOM nodes, so a fresh snapshot also detects an element replaced at the same XPath.
66
+ const [count, url, fresh] = await Promise.all([control ? base.count() : 0, page.url(), input.reference ? page.snapshot({ includeIframes: true }) : undefined]);
67
+ const found = count > (input.nth ?? 0);
68
+ const optionsResult = found && optionsRead ? await optionsRead : undefined;
69
+ if (optionsResult && !optionsResult.ok)
70
+ throw optionsResult.error;
71
+ const html = optionsResult?.ok ? optionsResult.value : undefined;
72
+ const failure = (code, message) => ({ tabId: page.pageId, url, error: { code, message } });
73
+ if (input.reference && (url !== input.reference.url || fresh.xpathMap[input.reference.id] !== input.reference.xpath)) {
74
+ return failure("stale_ref", url !== input.reference.url
75
+ ? "The tab navigated since that snapshot. Take a new snapshot."
76
+ : "The referenced element changed or disappeared. Take a new snapshot.");
77
+ }
78
+ if (control && (input.nth === undefined ? count !== 1 : count <= input.nth)) {
79
+ return failure(count && input.nth === undefined ? "ambiguous_target" : "not_found", `The selector matched ${count} element(s)${input.nth === undefined ? "; it must match exactly one" : `; position ${input.nth + 1} does not exist`}. `
80
+ + "Use a ref from a fresh snapshot, or (xpath)[n] for the nth match. Playwright-only syntax such as :has-text() or >> nth= is not supported.");
81
+ }
82
+ if (input.action === "select") {
83
+ // Keep the same value/label validation: the SDK otherwise deselects everything on a typo.
84
+ const entities = { amp: "&", lt: "<", gt: ">", quot: "\"", nbsp: "\u00a0" };
85
+ const decode = (text) => text.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (entity, name) => {
86
+ if (/^#x/i.test(name))
87
+ return String.fromCodePoint(Number.parseInt(name.slice(2), 16));
88
+ if (name[0] === "#")
89
+ return String.fromCodePoint(Number(name.slice(1)));
90
+ return entities[name.toLowerCase()] ?? entity;
91
+ });
92
+ const options = [...html.matchAll(/<option\b([^>]*)>([\s\S]*?)<\/option>/gi)].map(([, attributes, inner]) => {
93
+ const attribute = (name) => {
94
+ const found = new RegExp(`\\s${name}="([^"]*)"`, "i").exec(attributes);
95
+ return found ? decode(found[1]) : undefined;
96
+ };
97
+ const text = decode(inner.replace(/<[^>]*>/g, "")).replace(/[ \t\n\f\r]+/g, " ").trim();
98
+ return { value: (attribute("value") ?? text).trim(), label: (attribute("label") || text).trim() };
99
+ });
100
+ if (!options.length)
101
+ return failure("not_select", "select works only on a native <select> element with options. For a custom dropdown, click it and then click the option.");
102
+ const missing = input.values.filter(value => !options.some(option => option.value === value.trim() || option.label === value.trim()));
103
+ if (missing.length)
104
+ return failure("option_not_found", `No option matches ${JSON.stringify(missing)}; nothing was selected. `
105
+ + `Options (value/label): ${JSON.stringify(options.slice(0, 50).map(option => option.value === option.label ? option.value : `${option.value}/${option.label}`))}${options.length > 50 ? " …" : ""}`);
106
+ }
26
107
  }
27
- if (input.action === "select") {
28
- // Keep the same value/label validation: the SDK otherwise deselects everything on a typo.
29
- const entities = { amp: "&", lt: "<", gt: ">", quot: "\"", nbsp: "\u00a0" };
30
- const decode = (text) => text.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (entity, name) => {
31
- if (/^#x/i.test(name))
32
- return String.fromCodePoint(Number.parseInt(name.slice(2), 16));
33
- if (name[0] === "#")
34
- return String.fromCodePoint(Number(name.slice(1)));
35
- return entities[name.toLowerCase()] ?? entity;
36
- });
37
- const options = [...html.matchAll(/<option\b([^>]*)>([\s\S]*?)<\/option>/gi)].map(([, attributes, inner]) => {
38
- const attribute = (name) => {
39
- const found = new RegExp(`\\s${name}="([^"]*)"`, "i").exec(attributes);
40
- return found ? decode(found[1]) : undefined;
41
- };
42
- const text = decode(inner.replace(/<[^>]*>/g, "")).replace(/[ \t\n\f\r]+/g, " ").trim();
43
- return { value: (attribute("value") ?? text).trim(), label: (attribute("label") || text).trim() };
44
- });
45
- if (!options.length)
46
- return failure("not_select", "select works only on a native <select> element with options. For a custom dropdown, click it and then click the option.");
47
- const missing = input.values.filter(value => !options.some(option => option.value === value.trim() || option.label === value.trim()));
48
- if (missing.length)
49
- return failure("option_not_found", `No option matches ${JSON.stringify(missing)}; nothing was selected. `
50
- + `Options (value/label): ${JSON.stringify(options.slice(0, 50).map(option => option.value === option.label ? option.value : `${option.value}/${option.label}`))}${options.length > 50 ? " …" : ""}`);
108
+ let value;
109
+ let snapshot;
110
+ let snapshotUrl;
111
+ let navigation;
112
+ let image;
113
+ const stopped = async (code, message) => ({ tabId: page.pageId, url: await page.url(), error: { code, message } });
114
+ // A stop can arrive while the reference was being checked, before anything changed.
115
+ if (batch?.cancelled)
116
+ return stopped("cancelled", "The batch was cancelled before this step acted.");
117
+ switch (input.action) {
118
+ case "start":
119
+ case "open": {
120
+ if (!input.url)
121
+ break;
122
+ // Stagehand's goto resolves without a response when the browser cancels the navigation, leaving the tab on its start
123
+ // page; Helium does this to a navigation made in about its first second after launch. One retry covers that.
124
+ const started = performance.now();
125
+ for (let attempt = 1;; attempt++) {
126
+ const response = await page.goto(input.url, { waitUntil: "domcontentloaded", timeout: Math.max(1, Math.ceil(input.pageTimeoutMs - (performance.now() - started))) });
127
+ if (response || !startPage.test(await page.url())) {
128
+ navigation = { httpStatus: response?.status() };
129
+ break;
130
+ }
131
+ if (attempt === 2)
132
+ return stopped("navigation_cancelled", "The browser cancelled the navigation twice and the tab is still blank. An extension or policy in this browser may block the URL; check it in the browser, or retry open.");
133
+ }
134
+ // A redirect the fence refuses ends on Chrome's error page instead of throwing.
135
+ if (input.fenced && (await page.url()).startsWith("chrome-error://")) {
136
+ return stopped("domain_blocked", "The navigation ended on Chrome's error page; this browser's domain policy likely refused a redirect. Check status for the allowed and blocked domains.");
137
+ }
138
+ break;
139
+ }
140
+ case "back":
141
+ case "forward":
142
+ case "reload": {
143
+ const options = { waitUntil: "domcontentloaded", timeout: input.pageTimeoutMs };
144
+ const response = await (input.action === "back" ? page.goBack(options) : input.action === "forward" ? page.goForward(options) : page.reload(options));
145
+ // Going back to the start page would hand the model a blank tab, or an extension URL.
146
+ if (input.action === "back" && startPage.test(await page.url())) {
147
+ await page.goForward(options);
148
+ return stopped("no_history", "This tab has no earlier page to go back to; it stays on the current page.");
149
+ }
150
+ navigation = { httpStatus: response?.status() };
151
+ break;
152
+ }
153
+ case "wait":
154
+ if (input.selector)
155
+ await page.waitForSelector(input.selector, { state: input.state ?? "visible", timeout: input.pageTimeoutMs });
156
+ else if (input.loadState)
157
+ await page.waitForLoadState(input.loadState, input.pageTimeoutMs);
158
+ else
159
+ await page.waitForTimeout(input.durationMs);
160
+ break;
161
+ case "screenshot": {
162
+ const bytes = await page.screenshot({ type: "png", fullPage: input.fullPage ?? false, timeout: input.pageTimeoutMs });
163
+ let binary = "";
164
+ for (let at = 0; at < bytes.length; at += 0x8000)
165
+ binary += String.fromCharCode(...bytes.subarray(at, at + 0x8000));
166
+ image = btoa(binary);
167
+ break;
168
+ }
169
+ case "snapshot": {
170
+ // A full result carries an XPath for every DOM node, over a megabyte on a large page: return only what is shown.
171
+ const [fresh, at] = await Promise.all([page.snapshot({ includeIframes: true }), page.url()]);
172
+ const { version, maxChars } = input.snapshot;
173
+ const full = fresh.formattedTree.replace(/\[(\d+-\d+)\]/g, `[${version}:$1]`);
174
+ const tree = full.slice(0, maxChars);
175
+ const refs = {};
176
+ for (const [, id] of tree.matchAll(/\[s\d+:(\d+-\d+)\]/g)) {
177
+ const xpath = fresh.xpathMap[id];
178
+ if (xpath)
179
+ refs[id] = xpath;
180
+ }
181
+ snapshot = { tree, truncated: full.length > maxChars, refs };
182
+ snapshotUrl = at;
183
+ break;
184
+ }
185
+ case "click":
186
+ await locator.click();
187
+ break;
188
+ case "fill":
189
+ await locator.fill(input.value);
190
+ break;
191
+ case "select": {
192
+ const selected = await locator.selectOption(input.values);
193
+ if (!selected.length)
194
+ return stopped("not_select", "select works only on a native <select> element. For a custom dropdown, click it and then click the option.");
195
+ value = selected;
196
+ break;
197
+ }
198
+ case "press":
199
+ await page.keyPress(input.key);
200
+ break;
201
+ case "scroll":
202
+ await page.scroll(input.x ?? 640, input.y ?? 400, input.deltaX ?? 0, input.deltaY ?? 0);
203
+ break;
204
+ case "evaluate":
205
+ value = await page.evaluate(input.script);
206
+ break;
207
+ case "tab_select":
208
+ await context.setActivePage(page);
209
+ break;
210
+ }
211
+ // Keep URL retrieval independent of the bounded main-thread read so blocked tabs remain reportable.
212
+ let timer;
213
+ try {
214
+ const [url, view] = await Promise.all([
215
+ page.url(),
216
+ Promise.race([
217
+ page.evaluate(`(() => {
218
+ const title = document.title;
219
+ let dialogs = [];
220
+ try { const answered = globalThis.__browserbaseDialogs?.splice(0); if (Array.isArray(answered)) dialogs = answered; } catch {}
221
+ return { title, dialogs };
222
+ })()`),
223
+ new Promise(resolve => { timer = setTimeout(() => resolve(undefined), input.readTimeoutMs); }),
224
+ ]),
225
+ ]);
226
+ return {
227
+ tabId: page.pageId, url, title: view?.title ?? null,
228
+ ...(view === undefined ? { responsive: false } : {}),
229
+ ...(view?.dialogs.length ? { dialogs: view.dialogs } : {}),
230
+ ...(value === undefined ? {} : { value }), ...(snapshot ? { snapshot, snapshotUrl } : {}),
231
+ ...(navigation ? { navigation } : {}), ...(image ? { image } : {}),
232
+ };
233
+ }
234
+ finally {
235
+ clearTimeout(timer);
51
236
  }
52
237
  }
53
- let value;
54
- let snapshot;
55
- let snapshotUrl;
56
- switch (input.action) {
57
- case "snapshot":
58
- [snapshot, snapshotUrl] = await Promise.all([page.snapshot({ includeIframes: true }), page.url()]);
59
- break;
60
- case "click":
61
- await locator.click();
62
- break;
63
- case "fill":
64
- await locator.fill(input.value);
65
- break;
66
- case "select":
67
- value = await locator.selectOption(input.values);
68
- break;
69
- case "press":
70
- await page.keyPress(input.key);
71
- break;
72
- case "scroll":
73
- await page.scroll(input.x ?? 640, input.y ?? 400, input.deltaX ?? 0, input.deltaY ?? 0);
74
- break;
75
- case "evaluate":
76
- value = await page.evaluate(input.script);
77
- break;
78
- case "tab_select":
79
- await context.setActivePage(page);
80
- break;
81
- }
82
- // Keep URL retrieval independent of the bounded main-thread read so blocked tabs remain reportable.
238
+ }
239
+ /**
240
+ * Reads a tab's URL, title, answered dialogs, and document identity in one request. The main-thread read is bounded, so
241
+ * a blocked tab is reported unresponsive instead of failing. Serialized into the worker: no outside dependencies.
242
+ */
243
+ export async function viewOperation({ page }, input) {
83
244
  let timer;
84
245
  try {
85
246
  const [url, view] = await Promise.all([
@@ -89,22 +250,48 @@ export async function pageOperation({ page, context }, input) {
89
250
  const title = document.title;
90
251
  let dialogs = [];
91
252
  try { const answered = globalThis.__browserbaseDialogs?.splice(0); if (Array.isArray(answered)) dialogs = answered; } catch {}
92
- return { title, dialogs };
93
- })()`),
253
+ return { title, dialogs, origin: performance.timeOrigin };
254
+ })()`).catch(async () => ({ title: await page.title(), dialogs: [], origin: null })),
94
255
  new Promise(resolve => { timer = setTimeout(() => resolve(undefined), input.readTimeoutMs); }),
95
256
  ]),
96
257
  ]);
97
258
  return {
98
- tabId: page.pageId, url, title: view?.title ?? null,
99
- ...(view === undefined ? { responsive: false } : {}),
100
- ...(view?.dialogs.length ? { dialogs: view.dialogs } : {}),
101
- ...(value === undefined ? {} : { value }), ...(snapshot ? { snapshot, snapshotUrl } : {}),
259
+ tabId: page.pageId, url, title: view?.title ?? null, origin: view?.origin ?? null,
260
+ ...(view === undefined ? { responsive: false } : {}), ...(view?.dialogs.length ? { dialogs: view.dialogs } : {}),
102
261
  };
103
262
  }
104
263
  finally {
105
264
  clearTimeout(timer);
106
265
  }
107
266
  }
267
+ /**
268
+ * Reads a page for ask and JEV in one request: the snapshot tree, optionally the XPaths of the nodes a target can name
269
+ * and the viewport. Serialized into the worker: executable dependencies must stay inside this function.
270
+ */
271
+ export async function readOperation({ page }, input) {
272
+ const [origin, fresh, url, title, shot] = await Promise.all([
273
+ page.evaluate("performance.timeOrigin").catch(() => null),
274
+ page.snapshot({ includeIframes: true }), page.url(), page.title(),
275
+ // JPEG: smaller than PNG, and every image-capable classifier takes it.
276
+ input.image ? page.screenshot({ type: "jpeg", quality: 70, fullPage: false, timeout: 10_000 }) : undefined,
277
+ ]);
278
+ const read = { tabId: page.pageId, url, title, origin, tree: fresh.formattedTree };
279
+ if (input.refs) {
280
+ read.refs = {};
281
+ for (const [, id, role] of fresh.formattedTree.matchAll(/^\s*\[(\d+-\d+)\] ([^:\s]*)/gm)) {
282
+ const xpath = fresh.xpathMap[id];
283
+ if (xpath && role !== "StaticText" && role !== "InlineTextBox" && role !== "LineBreak")
284
+ read.refs[id] = xpath;
285
+ }
286
+ }
287
+ if (shot) {
288
+ let binary = "";
289
+ for (let at = 0; at < shot.length; at += 0x8000)
290
+ binary += String.fromCharCode(...shot.subarray(at, at + 0x8000));
291
+ read.image = btoa(binary);
292
+ }
293
+ return read;
294
+ }
108
295
  /** Context-only reads share one transport request; keep the same bounded title behavior for blocked tabs. */
109
296
  export async function tabsOperation({ context }, input) {
110
297
  return Promise.all((await context.pages()).map(async (page) => {
package/dist/schema.d.ts CHANGED
@@ -1,5 +1,125 @@
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
+ path: z.ZodOptional<z.ZodString>;
122
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
3
123
  action: z.ZodEnum<{
4
124
  ask: "ask";
5
125
  back: "back";
@@ -29,6 +149,12 @@ export declare const browserParameters: z.ZodObject<{
29
149
  tabs: "tabs";
30
150
  wait: "wait";
31
151
  }>;
152
+ }, z.core.$strict>;
153
+ /**
154
+ * The browse tool's parameters with the batch action. A host opts in by registering this schema, since it owns the
155
+ * prompts and approval rules a batch needs: one call can navigate, act, and run page script.
156
+ */
157
+ export declare const browserBatchParameters: z.ZodObject<{
32
158
  backend: z.ZodOptional<z.ZodEnum<{
33
159
  browserbase: "browserbase";
34
160
  local: "local";
@@ -106,6 +232,75 @@ export declare const browserParameters: z.ZodObject<{
106
232
  }, z.core.$strict>>>;
107
233
  path: z.ZodOptional<z.ZodString>;
108
234
  timeoutMs: z.ZodOptional<z.ZodNumber>;
235
+ action: z.ZodEnum<{
236
+ ask: "ask";
237
+ back: "back";
238
+ batch: "batch";
239
+ click: "click";
240
+ close: "close";
241
+ context_create: "context_create";
242
+ cookie_import: "cookie_import";
243
+ cookie_profiles: "cookie_profiles";
244
+ evaluate: "evaluate";
245
+ fill: "fill";
246
+ forward: "forward";
247
+ har_start: "har_start";
248
+ har_stop: "har_stop";
249
+ live_view: "live_view";
250
+ open: "open";
251
+ press: "press";
252
+ reload: "reload";
253
+ screenshot: "screenshot";
254
+ scroll: "scroll";
255
+ select: "select";
256
+ snapshot: "snapshot";
257
+ start: "start";
258
+ status: "status";
259
+ tab_close: "tab_close";
260
+ tab_new: "tab_new";
261
+ tab_select: "tab_select";
262
+ tabs: "tabs";
263
+ wait: "wait";
264
+ }>;
265
+ steps: z.ZodOptional<z.ZodArray<z.ZodObject<{
266
+ action: z.ZodEnum<{
267
+ back: "back";
268
+ click: "click";
269
+ evaluate: "evaluate";
270
+ fill: "fill";
271
+ forward: "forward";
272
+ open: "open";
273
+ press: "press";
274
+ reload: "reload";
275
+ scroll: "scroll";
276
+ select: "select";
277
+ snapshot: "snapshot";
278
+ wait: "wait";
279
+ }>;
280
+ url: z.ZodOptional<z.ZodURL>;
281
+ selector: z.ZodOptional<z.ZodString>;
282
+ value: z.ZodOptional<z.ZodString>;
283
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
284
+ key: z.ZodOptional<z.ZodString>;
285
+ deltaX: z.ZodOptional<z.ZodNumber>;
286
+ deltaY: z.ZodOptional<z.ZodNumber>;
287
+ x: z.ZodOptional<z.ZodNumber>;
288
+ y: z.ZodOptional<z.ZodNumber>;
289
+ durationMs: z.ZodOptional<z.ZodNumber>;
290
+ loadState: z.ZodOptional<z.ZodEnum<{
291
+ domcontentloaded: "domcontentloaded";
292
+ load: "load";
293
+ networkidle: "networkidle";
294
+ }>>;
295
+ state: z.ZodOptional<z.ZodEnum<{
296
+ attached: "attached";
297
+ detached: "detached";
298
+ hidden: "hidden";
299
+ visible: "visible";
300
+ }>>;
301
+ script: z.ZodOptional<z.ZodString>;
302
+ maxChars: z.ZodOptional<z.ZodNumber>;
303
+ }, z.core.$strict>>>;
109
304
  }, z.core.$strict>;
110
305
  export declare const aiParameters: z.ZodObject<{
111
306
  action: z.ZodEnum<{
@@ -118,6 +313,8 @@ export declare const aiParameters: z.ZodObject<{
118
313
  schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
119
314
  timeoutMs: z.ZodOptional<z.ZodNumber>;
120
315
  }, z.core.$strict>;
121
- export type BrowserParams = z.infer<typeof browserParameters>;
316
+ /** Every call the core runs, batch included; a host that registers browserParameters never sends one. */
317
+ export type BrowserParams = z.infer<typeof browserBatchParameters>;
122
318
  export type AskFields = NonNullable<BrowserParams["fields"]>;
123
319
  export type AIParams = z.infer<typeof aiParameters>;
320
+ export {};