@browserbasehq/orca 3.0.0-preview.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 +165 -0
- package/dist/index.d.ts +1611 -0
- package/dist/index.js +28681 -0
- package/dist/lib/api.d.ts +23 -0
- package/dist/lib/dom/build/scriptContent.d.ts +1 -0
- package/dist/lib/inference.d.ts +71 -0
- package/dist/lib/inferenceLogUtils.d.ts +12 -0
- package/dist/lib/logger.d.ts +54 -0
- package/dist/lib/prompt.d.ts +12 -0
- package/dist/lib/utils.d.ts +65 -0
- package/dist/lib/v3/agent/AgentClient.d.ts +18 -0
- package/dist/lib/v3/agent/AgentProvider.d.ts +18 -0
- package/dist/lib/v3/agent/AnthropicCUAClient.d.ts +55 -0
- package/dist/lib/v3/agent/OpenAICUAClient.d.ts +64 -0
- package/dist/lib/v3/agent/StagehandAgent.d.ts +15 -0
- package/dist/lib/v3/agent/tools/index.d.ts +229 -0
- package/dist/lib/v3/agent/tools/v3-act.d.ts +29 -0
- package/dist/lib/v3/agent/tools/v3-ariaTree.d.ts +11 -0
- package/dist/lib/v3/agent/tools/v3-close.d.ts +24 -0
- package/dist/lib/v3/agent/tools/v3-extract.d.ts +38 -0
- package/dist/lib/v3/agent/tools/v3-fillform.d.ts +37 -0
- package/dist/lib/v3/agent/tools/v3-goto.d.ts +29 -0
- package/dist/lib/v3/agent/tools/v3-navback.d.ts +17 -0
- package/dist/lib/v3/agent/tools/v3-screenshot.d.ts +13 -0
- package/dist/lib/v3/agent/tools/v3-scroll.d.ts +23 -0
- package/dist/lib/v3/agent/tools/v3-wait.d.ts +19 -0
- package/dist/lib/v3/agent/utils/cuaKeyMapping.d.ts +10 -0
- package/dist/lib/v3/agent/utils/imageCompression.d.ts +18 -0
- package/dist/lib/v3/agent/utils/messageProcessing.d.ts +13 -0
- package/dist/lib/v3/dom/build/scriptV3Content.d.ts +1 -0
- package/dist/lib/v3/dom/genDomScripts.d.ts +1 -0
- package/dist/lib/v3/dom/index.d.ts +1 -0
- package/dist/lib/v3/dom/piercer.entry.d.ts +1 -0
- package/dist/lib/v3/dom/piercer.runtime.d.ts +25 -0
- package/dist/lib/v3/handlers/actHandler.d.ts +18 -0
- package/dist/lib/v3/handlers/extractHandler.d.ts +29 -0
- package/dist/lib/v3/handlers/handlerUtils/actHandlerUtils.d.ts +18 -0
- package/dist/lib/v3/handlers/observeHandler.d.ts +15 -0
- package/dist/lib/v3/handlers/v3AgentHandler.d.ts +17 -0
- package/dist/lib/v3/handlers/v3CuaAgentHandler.d.ts +26 -0
- package/dist/lib/v3/index.d.ts +10 -0
- package/dist/lib/v3/launch/browserbase.d.ts +8 -0
- package/dist/lib/v3/launch/local.d.ts +13 -0
- package/dist/lib/v3/llm/AnthropicClient.d.ts +16 -0
- package/dist/lib/v3/llm/CerebrasClient.d.ts +17 -0
- package/dist/lib/v3/llm/GoogleClient.d.ts +19 -0
- package/dist/lib/v3/llm/GroqClient.d.ts +17 -0
- package/dist/lib/v3/llm/LLMClient.d.ts +99 -0
- package/dist/lib/v3/llm/LLMProvider.d.ts +10 -0
- package/dist/lib/v3/llm/OpenAIClient.d.ts +15 -0
- package/dist/lib/v3/llm/aisdk.d.ts +15 -0
- package/dist/lib/v3/logger.d.ts +48 -0
- package/dist/lib/v3/mcp/connection.d.ts +11 -0
- package/dist/lib/v3/mcp/utils.d.ts +3 -0
- package/dist/lib/v3/tests/default-page-tracking.spec.d.ts +1 -0
- package/dist/lib/v3/tests/perform-understudy-method.spec.d.ts +1 -0
- package/dist/lib/v3/tests/shadow-iframe.spec.d.ts +1 -0
- package/dist/lib/v3/tests/timeouts.spec.d.ts +1 -0
- package/dist/lib/v3/tests/v3.config.d.ts +4 -0
- package/dist/lib/v3/tests/v3.playwright.config.d.ts +2 -0
- package/dist/lib/v3/tests/xpath-for-location-deep.spec.d.ts +1 -0
- package/dist/lib/v3/types/act.d.ts +10 -0
- package/dist/lib/v3/types/agent.d.ts +132 -0
- package/dist/lib/v3/types/api.d.ts +40 -0
- package/dist/lib/v3/types/cache.d.ts +71 -0
- package/dist/lib/v3/types/context.d.ts +2 -0
- package/dist/lib/v3/types/evals.d.ts +71 -0
- package/dist/lib/v3/types/evaluator.d.ts +40 -0
- package/dist/lib/v3/types/llm.d.ts +11 -0
- package/dist/lib/v3/types/log.d.ts +23 -0
- package/dist/lib/v3/types/model.d.ts +20 -0
- package/dist/lib/v3/types/playwright.d.ts +6 -0
- package/dist/lib/v3/types/stagehand.d.ts +113 -0
- package/dist/lib/v3/types/stagehandApiErrors.d.ts +18 -0
- package/dist/lib/v3/types/stagehandErrors.d.ts +104 -0
- package/dist/lib/v3/types.d.ts +176 -0
- package/dist/lib/v3/understudy/a11y/snapshot.d.ts +71 -0
- package/dist/lib/v3/understudy/cdp.d.ts +58 -0
- package/dist/lib/v3/understudy/context.d.ts +120 -0
- package/dist/lib/v3/understudy/deepLocator.d.ts +69 -0
- package/dist/lib/v3/understudy/executionContextRegistry.d.ts +15 -0
- package/dist/lib/v3/understudy/frame.d.ts +63 -0
- package/dist/lib/v3/understudy/frameLocator.d.ts +46 -0
- package/dist/lib/v3/understudy/frameRegistry.d.ts +100 -0
- package/dist/lib/v3/understudy/locator.d.ts +196 -0
- package/dist/lib/v3/understudy/page.d.ts +241 -0
- package/dist/lib/v3/understudy/piercer.d.ts +4 -0
- package/dist/lib/v3/v3.d.ts +156 -0
- package/dist/lib/version.d.ts +5 -0
- package/package.json +130 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { Protocol } from "devtools-protocol";
|
|
2
|
+
import type { CDPSessionLike } from "./cdp";
|
|
3
|
+
import { CdpConnection } from "./cdp";
|
|
4
|
+
import { Frame } from "./frame";
|
|
5
|
+
import { FrameLocator } from "./frameLocator";
|
|
6
|
+
import { LoadState } from "../types";
|
|
7
|
+
export declare class Page {
|
|
8
|
+
private readonly conn;
|
|
9
|
+
private readonly mainSession;
|
|
10
|
+
private readonly _targetId;
|
|
11
|
+
/** Every CDP child session this page owns (top-level + adopted OOPIF sessions). */
|
|
12
|
+
private readonly sessions;
|
|
13
|
+
/** Unified truth for frame topology + ownership. */
|
|
14
|
+
private readonly registry;
|
|
15
|
+
/** A convenience wrapper bound to the current main frame id (top-level session). */
|
|
16
|
+
private mainFrameWrapper;
|
|
17
|
+
/** Compact ordinal per frameId (used by snapshot encoding). */
|
|
18
|
+
private frameOrdinals;
|
|
19
|
+
private nextOrdinal;
|
|
20
|
+
/** cache Frames per frameId so everyone uses the same one */
|
|
21
|
+
private readonly frameCache;
|
|
22
|
+
/** Stable id for Frames created by this Page (use top-level TargetId). */
|
|
23
|
+
private readonly pageId;
|
|
24
|
+
private constructor();
|
|
25
|
+
private cursorEnabled;
|
|
26
|
+
private ensureCursorScript;
|
|
27
|
+
enableCursorOverlay(): Promise<void>;
|
|
28
|
+
private updateCursor;
|
|
29
|
+
/**
|
|
30
|
+
* Factory: create Page and seed registry with the shallow tree from Page.getFrameTree.
|
|
31
|
+
* Assumes Page domain is already enabled on the session passed in.
|
|
32
|
+
*/
|
|
33
|
+
static create(conn: CdpConnection, session: CDPSessionLike, targetId: string): Promise<Page>;
|
|
34
|
+
/**
|
|
35
|
+
* Parent/child session emitted a `frameAttached`.
|
|
36
|
+
* Topology update + ownership stamped to **emitting session**.
|
|
37
|
+
*/
|
|
38
|
+
onFrameAttached(frameId: string, parentId: string | null, session: CDPSessionLike): void;
|
|
39
|
+
/**
|
|
40
|
+
* Parent/child session emitted a `frameDetached`.
|
|
41
|
+
*/
|
|
42
|
+
onFrameDetached(frameId: string, reason?: "remove" | "swap" | string): void;
|
|
43
|
+
/**
|
|
44
|
+
* Parent/child session emitted a `frameNavigated`.
|
|
45
|
+
* Topology + ownership update. Handles root swaps.
|
|
46
|
+
*/
|
|
47
|
+
onFrameNavigated(frame: Protocol.Page.Frame, session: CDPSessionLike): void;
|
|
48
|
+
/**
|
|
49
|
+
* An OOPIF child session whose **main** frame id equals the parent iframe’s frameId
|
|
50
|
+
* has been attached; adopt the session into this Page and seed ownership for its subtree.
|
|
51
|
+
*/
|
|
52
|
+
adoptOopifSession(childSession: CDPSessionLike, childMainFrameId: string): void;
|
|
53
|
+
/** Detach an adopted child session and prune its subtree */
|
|
54
|
+
detachOopifSession(sessionId: string): void;
|
|
55
|
+
/** Return the owning CDP session for a frameId (falls back to main session) */
|
|
56
|
+
getSessionForFrame(frameId: string): CDPSessionLike;
|
|
57
|
+
/** Always returns a Frame bound to the owning session */
|
|
58
|
+
frameForId(frameId: string): Frame;
|
|
59
|
+
/** Expose a session by id (used by snapshot to resolve session id -> session) */
|
|
60
|
+
getSessionById(id: string): CDPSessionLike | undefined;
|
|
61
|
+
targetId(): string;
|
|
62
|
+
mainFrameId(): string;
|
|
63
|
+
mainFrame(): Frame;
|
|
64
|
+
/**
|
|
65
|
+
* Close this top-level page (tab). Best-effort via Target.closeTarget.
|
|
66
|
+
*/
|
|
67
|
+
close(): Promise<void>;
|
|
68
|
+
getFullFrameTree(): Protocol.Page.FrameTree;
|
|
69
|
+
asProtocolFrameTree(rootMainFrameId: string): Protocol.Page.FrameTree;
|
|
70
|
+
private ensureOrdinal;
|
|
71
|
+
/** Public getter for snapshot code / handlers. */
|
|
72
|
+
getOrdinal(frameId: string): number;
|
|
73
|
+
listAllFrameIds(): string[];
|
|
74
|
+
/**
|
|
75
|
+
* Navigate the page; optionally wait for a lifecycle state.
|
|
76
|
+
* Waits on the **current** main frame and follows root swaps during navigation.
|
|
77
|
+
*/
|
|
78
|
+
goto(url: string, options?: {
|
|
79
|
+
waitUntil?: LoadState;
|
|
80
|
+
timeoutMs?: number;
|
|
81
|
+
}): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Reload the page; optionally wait for a lifecycle state.
|
|
84
|
+
*/
|
|
85
|
+
reload(options?: {
|
|
86
|
+
waitUntil?: LoadState;
|
|
87
|
+
timeoutMs?: number;
|
|
88
|
+
ignoreCache?: boolean;
|
|
89
|
+
}): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Navigate back in history if possible; optionally wait for a lifecycle state.
|
|
92
|
+
*/
|
|
93
|
+
goBack(options?: {
|
|
94
|
+
waitUntil?: LoadState;
|
|
95
|
+
timeoutMs?: number;
|
|
96
|
+
}): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Navigate forward in history if possible; optionally wait for a lifecycle state.
|
|
99
|
+
*/
|
|
100
|
+
goForward(options?: {
|
|
101
|
+
waitUntil?: LoadState;
|
|
102
|
+
timeoutMs?: number;
|
|
103
|
+
}): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Return the current page URL (from navigation history).
|
|
106
|
+
*/
|
|
107
|
+
url(): Promise<string>;
|
|
108
|
+
/**
|
|
109
|
+
* Return the current page title.
|
|
110
|
+
* Prefers reading from the active document via Runtime.evaluate to reflect dynamic changes.
|
|
111
|
+
* Falls back to navigation history title if evaluation is unavailable.
|
|
112
|
+
*/
|
|
113
|
+
title(): Promise<string>;
|
|
114
|
+
/**
|
|
115
|
+
* Capture a screenshot (delegated to the current main frame).
|
|
116
|
+
*/
|
|
117
|
+
screenshot(options?: {
|
|
118
|
+
fullPage?: boolean;
|
|
119
|
+
}): Promise<string>;
|
|
120
|
+
/**
|
|
121
|
+
* Create a locator bound to the current main frame.
|
|
122
|
+
*/
|
|
123
|
+
locator(selector: string): ReturnType<Frame["locator"]>;
|
|
124
|
+
/**
|
|
125
|
+
* Deep locator that supports cross-iframe traversal.
|
|
126
|
+
* - Recognizes '>>' hop notation to enter iframe contexts.
|
|
127
|
+
* - Supports deep XPath that includes iframe steps (e.g., '/html/body/iframe[2]//div').
|
|
128
|
+
* Returns a Locator scoped to the appropriate frame.
|
|
129
|
+
*/
|
|
130
|
+
deepLocator(selector: string): import("./deepLocator").DeepLocatorDelegate;
|
|
131
|
+
/**
|
|
132
|
+
* Frame locator similar to Playwright: targets iframe elements and scopes
|
|
133
|
+
* subsequent locators to that frame. Supports chaining.
|
|
134
|
+
*/
|
|
135
|
+
frameLocator(selector: string): FrameLocator;
|
|
136
|
+
/**
|
|
137
|
+
* List all frames belonging to this page as Frame objects bound to their owning sessions.
|
|
138
|
+
* The list is ordered by a stable ordinal assigned during the page lifetime.
|
|
139
|
+
*/
|
|
140
|
+
frames(): Frame[];
|
|
141
|
+
/**
|
|
142
|
+
* Wait until the page reaches a lifecycle state on the current main frame.
|
|
143
|
+
* Mirrors Playwright's API signatures.
|
|
144
|
+
*/
|
|
145
|
+
waitForLoadState(state: LoadState, timeoutMs?: number): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Evaluate a function or expression in the current main frame's isolated world.
|
|
148
|
+
* - If a string is provided, it is treated as a JS expression.
|
|
149
|
+
* - If a function is provided, it is stringified and invoked with the optional argument.
|
|
150
|
+
* - The return value should be JSON-serializable. Non-serializable objects will
|
|
151
|
+
* best-effort serialize via JSON.stringify inside the page context.
|
|
152
|
+
*/
|
|
153
|
+
evaluate<R = unknown, Arg = unknown>(pageFunctionOrExpression: string | ((arg: Arg) => R | Promise<R>), arg?: Arg): Promise<R>;
|
|
154
|
+
/**
|
|
155
|
+
* Force the page viewport to an exact CSS size and device scale factor.
|
|
156
|
+
* Ensures screenshots match width x height pixels when deviceScaleFactor = 1.
|
|
157
|
+
*/
|
|
158
|
+
setViewportSize(width: number, height: number, options?: {
|
|
159
|
+
deviceScaleFactor?: number;
|
|
160
|
+
}): Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* Click at absolute page coordinates (CSS pixels).
|
|
163
|
+
* Dispatches mouseMoved → mousePressed → mouseReleased via CDP Input domain
|
|
164
|
+
* on the top-level page target's session. Coordinates are relative to the
|
|
165
|
+
* viewport origin (top-left). Does not scroll.
|
|
166
|
+
*/
|
|
167
|
+
click(x: number, y: number, options: {
|
|
168
|
+
button?: "left" | "right" | "middle";
|
|
169
|
+
clickCount?: number;
|
|
170
|
+
returnXpath: true;
|
|
171
|
+
}): Promise<string>;
|
|
172
|
+
click(x: number, y: number, options?: {
|
|
173
|
+
button?: "left" | "right" | "middle";
|
|
174
|
+
clickCount?: number;
|
|
175
|
+
returnXpath?: false;
|
|
176
|
+
}): Promise<void>;
|
|
177
|
+
click(x: number, y: number, options: {
|
|
178
|
+
button?: "left" | "right" | "middle";
|
|
179
|
+
clickCount?: number;
|
|
180
|
+
returnXpath: boolean;
|
|
181
|
+
}): Promise<void | string>;
|
|
182
|
+
scroll(x: number, y: number, deltaX: number, deltaY: number, options: {
|
|
183
|
+
returnXpath: true;
|
|
184
|
+
}): Promise<string>;
|
|
185
|
+
scroll(x: number, y: number, deltaX: number, deltaY: number, options?: {
|
|
186
|
+
returnXpath?: false;
|
|
187
|
+
}): Promise<void>;
|
|
188
|
+
scroll(x: number, y: number, deltaX: number, deltaY: number, options: {
|
|
189
|
+
returnXpath: boolean;
|
|
190
|
+
}): Promise<void | string>;
|
|
191
|
+
/**
|
|
192
|
+
* Drag from (fromX, fromY) to (toX, toY) using mouse events.
|
|
193
|
+
* Sends mouseMoved → mousePressed → mouseMoved (steps) → mouseReleased.
|
|
194
|
+
*/
|
|
195
|
+
dragAndDrop(fromX: number, fromY: number, toX: number, toY: number, options: {
|
|
196
|
+
button?: "left" | "right" | "middle";
|
|
197
|
+
steps?: number;
|
|
198
|
+
delay?: number;
|
|
199
|
+
returnXpath: true;
|
|
200
|
+
}): Promise<[string, string]>;
|
|
201
|
+
dragAndDrop(fromX: number, fromY: number, toX: number, toY: number, options?: {
|
|
202
|
+
button?: "left" | "right" | "middle";
|
|
203
|
+
steps?: number;
|
|
204
|
+
delay?: number;
|
|
205
|
+
returnXpath?: false;
|
|
206
|
+
}): Promise<void>;
|
|
207
|
+
dragAndDrop(fromX: number, fromY: number, toX: number, toY: number, options: {
|
|
208
|
+
button?: "left" | "right" | "middle";
|
|
209
|
+
steps?: number;
|
|
210
|
+
delay?: number;
|
|
211
|
+
returnXpath: boolean;
|
|
212
|
+
}): Promise<void | [string, string]>;
|
|
213
|
+
/**
|
|
214
|
+
* Type a string by dispatching keyDown/keyUp events per character.
|
|
215
|
+
* Focus must already be on the desired element. Uses CDP Input.dispatchKeyEvent
|
|
216
|
+
* and never falls back to Input.insertText. Optional delay applies between
|
|
217
|
+
* successive characters.
|
|
218
|
+
*/
|
|
219
|
+
type(text: string, options?: {
|
|
220
|
+
delay?: number;
|
|
221
|
+
withMistakes?: boolean;
|
|
222
|
+
}): Promise<void>;
|
|
223
|
+
/**
|
|
224
|
+
* Press a single key (keyDown then keyUp). For printable characters,
|
|
225
|
+
* uses the text path on keyDown; for named keys, sets key/code/VK.
|
|
226
|
+
*/
|
|
227
|
+
keyPress(key: string, options?: {
|
|
228
|
+
delay?: number;
|
|
229
|
+
}): Promise<void>;
|
|
230
|
+
/**
|
|
231
|
+
* Create an isolated world for the **current** main frame and return its context id.
|
|
232
|
+
*/
|
|
233
|
+
private createIsolatedWorldForCurrentMain;
|
|
234
|
+
/**
|
|
235
|
+
* Wait until the **current** main frame reaches a lifecycle state.
|
|
236
|
+
* - Fast path via `document.readyState`.
|
|
237
|
+
* - Event path listens at the session level and compares incoming `frameId`
|
|
238
|
+
* to `mainFrameId()` **at event time** to follow root swaps.
|
|
239
|
+
*/
|
|
240
|
+
private waitForMainLoadState;
|
|
241
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CDPSessionLike } from "./cdp";
|
|
2
|
+
export declare function installV3PiercerIntoSession(session: CDPSessionLike): Promise<void>;
|
|
3
|
+
/** (Optional) stream patch logs in your node console during bring-up */
|
|
4
|
+
export declare function tapPiercerConsole(session: CDPSessionLike, label: string): void;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { V3Options, ActOptions, ObserveOptions, V3Metrics, V3FunctionName, ExtractOptions } from "@/lib/v3/types";
|
|
2
|
+
import { V3Context } from "@/lib/v3/understudy/context";
|
|
3
|
+
import { LLMClient } from "./llm/LLMClient";
|
|
4
|
+
import { z } from "zod/v3";
|
|
5
|
+
import type { ZodTypeAny } from "zod/v3";
|
|
6
|
+
import { Action, ActResult, HistoryEntry, AgentConfig } from "./types/stagehand";
|
|
7
|
+
import { AgentExecuteOptions, AgentResult } from "./types/agent";
|
|
8
|
+
import { LogLine } from "./types/log";
|
|
9
|
+
import { defaultExtractSchema, pageTextSchema } from "./types";
|
|
10
|
+
import type { AgentReplayStep } from "./types/cache";
|
|
11
|
+
/**
|
|
12
|
+
* V3
|
|
13
|
+
*
|
|
14
|
+
* Purpose:
|
|
15
|
+
* A high-level orchestrator for Stagehand V3. Abstracts away whether the browser
|
|
16
|
+
* runs **locally via Chrome** or remotely on **Browserbase**, and exposes simple
|
|
17
|
+
* entrypoints (`act`, `extract`, `observe`) that delegate to the corresponding
|
|
18
|
+
* handler classes.
|
|
19
|
+
*
|
|
20
|
+
* Responsibilities:
|
|
21
|
+
* - Bootstraps Chrome or Browserbase, ensures a working CDP WebSocket, and builds a `V3Context`.
|
|
22
|
+
* - Manages lifecycle: init, context access, cleanup.
|
|
23
|
+
* - Bridges external page objects (Playwright/Puppeteer) into internal frameIds for handlers.
|
|
24
|
+
* - Provides a stable API surface for downstream code regardless of runtime environment.
|
|
25
|
+
*/
|
|
26
|
+
export declare class V3 {
|
|
27
|
+
private readonly opts;
|
|
28
|
+
private state;
|
|
29
|
+
private actHandler;
|
|
30
|
+
private extractHandler;
|
|
31
|
+
private observeHandler;
|
|
32
|
+
private ctx;
|
|
33
|
+
llmClient: LLMClient;
|
|
34
|
+
private modelName;
|
|
35
|
+
private modelClientOptions;
|
|
36
|
+
private llmProvider;
|
|
37
|
+
private readonly domSettleTimeoutMs?;
|
|
38
|
+
private _isClosing;
|
|
39
|
+
private _onCdpClosed;
|
|
40
|
+
readonly experimental: boolean;
|
|
41
|
+
readonly logInferenceToFile: boolean;
|
|
42
|
+
private externalLogger?;
|
|
43
|
+
verbose: 0 | 1 | 2;
|
|
44
|
+
private _history;
|
|
45
|
+
private readonly instanceId;
|
|
46
|
+
private static _processGuardsInstalled;
|
|
47
|
+
private static _instances;
|
|
48
|
+
private cacheDir?;
|
|
49
|
+
private _agentReplayRecording;
|
|
50
|
+
v3Metrics: V3Metrics;
|
|
51
|
+
/**
|
|
52
|
+
* Async property for metrics so callers can `await v3.metrics`.
|
|
53
|
+
* Returning a Promise future-proofs async aggregation/storage.
|
|
54
|
+
*/
|
|
55
|
+
get metrics(): Promise<V3Metrics>;
|
|
56
|
+
private cloneForCache;
|
|
57
|
+
private beginAgentReplayRecording;
|
|
58
|
+
private endAgentReplayRecording;
|
|
59
|
+
private discardAgentReplayRecording;
|
|
60
|
+
private isAgentReplayRecording;
|
|
61
|
+
isAgentReplayActive(): boolean;
|
|
62
|
+
recordAgentReplayStep(step: AgentReplayStep): void;
|
|
63
|
+
/**
|
|
64
|
+
* Async property for history so callers can `await v3.history`.
|
|
65
|
+
* Returns a frozen copy to avoid external mutation.
|
|
66
|
+
*/
|
|
67
|
+
get history(): Promise<ReadonlyArray<HistoryEntry>>;
|
|
68
|
+
addToHistory(method: HistoryEntry["method"], parameters: unknown, result?: unknown): void;
|
|
69
|
+
updateMetrics(functionName: V3FunctionName, promptTokens: number, completionTokens: number, inferenceTimeMs: number): void;
|
|
70
|
+
private updateTotalMetrics;
|
|
71
|
+
constructor(opts: V3Options);
|
|
72
|
+
private _immediateShutdown;
|
|
73
|
+
private static _installProcessGuards;
|
|
74
|
+
/**
|
|
75
|
+
* Entrypoint: initializes handlers, launches Chrome or Browserbase,
|
|
76
|
+
* and sets up a CDP context.
|
|
77
|
+
*/
|
|
78
|
+
init(): Promise<void>;
|
|
79
|
+
/** Apply post-connect local browser options that require CDP. */
|
|
80
|
+
private _applyPostConnectLocalOptions;
|
|
81
|
+
/**
|
|
82
|
+
* Run an "act" instruction through the ActHandler.
|
|
83
|
+
*
|
|
84
|
+
* New API:
|
|
85
|
+
* - act(instruction: string, options?: ActOptions)
|
|
86
|
+
* - act(action: Action, options?: ActOptions)
|
|
87
|
+
*/
|
|
88
|
+
act(instruction: string, options?: ActOptions): Promise<ActResult>;
|
|
89
|
+
act(action: Action, options?: ActOptions): Promise<ActResult>;
|
|
90
|
+
/**
|
|
91
|
+
* Run an "extract" instruction through the ExtractHandler.
|
|
92
|
+
*
|
|
93
|
+
* Accepted forms:
|
|
94
|
+
* - extract() → pageText
|
|
95
|
+
* - extract(options) → pageText
|
|
96
|
+
* - extract(instruction) → defaultExtractSchema
|
|
97
|
+
* - extract(instruction, schema) → schema-inferred
|
|
98
|
+
* - extract(instruction, schema, options)
|
|
99
|
+
*/
|
|
100
|
+
extract(): Promise<z.infer<typeof pageTextSchema>>;
|
|
101
|
+
extract(options: ExtractOptions): Promise<z.infer<typeof pageTextSchema>>;
|
|
102
|
+
extract(instruction: string, options?: ExtractOptions): Promise<z.infer<typeof defaultExtractSchema>>;
|
|
103
|
+
extract<T extends ZodTypeAny>(instruction: string, schema: T, options?: ExtractOptions): Promise<z.infer<T>>;
|
|
104
|
+
/**
|
|
105
|
+
* Run an "observe" instruction through the ObserveHandler.
|
|
106
|
+
*/
|
|
107
|
+
observe(): Promise<Action[]>;
|
|
108
|
+
observe(options: ObserveOptions): Promise<Action[]>;
|
|
109
|
+
observe(instruction: string, options?: ObserveOptions): Promise<Action[]>;
|
|
110
|
+
/** Return the browser-level CDP WebSocket endpoint. */
|
|
111
|
+
connectURL(): string;
|
|
112
|
+
/** Expose the current CDP-backed context. */
|
|
113
|
+
get context(): V3Context;
|
|
114
|
+
/** Best-effort cleanup of context and launched resources. */
|
|
115
|
+
close(opts?: {
|
|
116
|
+
force?: boolean;
|
|
117
|
+
}): Promise<void>;
|
|
118
|
+
/** Guard: ensure Browserbase credentials exist in options. */
|
|
119
|
+
private requireBrowserbaseCreds;
|
|
120
|
+
get logger(): (logLine: LogLine) => void;
|
|
121
|
+
/**
|
|
122
|
+
* Normalize a Playwright/Puppeteer page object into its top frame id,
|
|
123
|
+
* so handlers can resolve it to a `Page` within our V3Context.
|
|
124
|
+
*/
|
|
125
|
+
private resolveTopFrameId;
|
|
126
|
+
private isPlaywrightPage;
|
|
127
|
+
private isPatchrightPage;
|
|
128
|
+
private isPuppeteerPage;
|
|
129
|
+
private normalizeToV3Page;
|
|
130
|
+
private buildActCacheKey;
|
|
131
|
+
private safeGetPageUrl;
|
|
132
|
+
private readActCacheEntry;
|
|
133
|
+
private writeActCacheEntry;
|
|
134
|
+
private sanitizeAgentExecuteOptions;
|
|
135
|
+
private buildAgentCacheSignature;
|
|
136
|
+
private buildAgentCacheKey;
|
|
137
|
+
private readAgentCacheEntry;
|
|
138
|
+
private writeAgentCacheEntry;
|
|
139
|
+
private replayAgentCacheEntry;
|
|
140
|
+
private executeAgentReplayStep;
|
|
141
|
+
private replayAgentActStep;
|
|
142
|
+
private replayAgentFillFormStep;
|
|
143
|
+
private replayAgentGotoStep;
|
|
144
|
+
private replayAgentScrollStep;
|
|
145
|
+
private replayAgentWaitStep;
|
|
146
|
+
private replayAgentNavBackStep;
|
|
147
|
+
private replayCachedActions;
|
|
148
|
+
private runWithActTimeout;
|
|
149
|
+
/**
|
|
150
|
+
* Create a v3 agent instance (AISDK tool-based) with execute().
|
|
151
|
+
* Mirrors the v2 Stagehand.agent() tool mode (no CUA provider here).
|
|
152
|
+
*/
|
|
153
|
+
agent(options?: AgentConfig): {
|
|
154
|
+
execute: (instructionOrOptions: string | AgentExecuteOptions) => Promise<AgentResult>;
|
|
155
|
+
};
|
|
156
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@browserbasehq/orca",
|
|
3
|
+
"version": "3.0.0-preview.0",
|
|
4
|
+
"description": "An AI web browsing framework focused on simplicity and extensibility.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"evals": "./dist/evals/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"example": "pnpm --filter @browserbasehq/stagehand-examples run start",
|
|
13
|
+
"format": "prettier --write .",
|
|
14
|
+
"prettier": "prettier --check .",
|
|
15
|
+
"prettier:fix": "prettier --write .",
|
|
16
|
+
"eslint": "eslint .",
|
|
17
|
+
"cache:clear": "rm -rf .cache",
|
|
18
|
+
"docs": "pnpm --filter @browserbasehq/stagehand-docs run dev",
|
|
19
|
+
"evals": "tsx scripts/run-evals.ts",
|
|
20
|
+
"evals:legacy": "tsx scripts/run-evals.ts",
|
|
21
|
+
"e2e": "pnpm run build && cd evals/deterministic && playwright test --config=e2e.playwright.config.ts",
|
|
22
|
+
"e2e:bb": "pnpm run build && cd evals/deterministic && playwright test --config=bb.playwright.config.ts",
|
|
23
|
+
"e2e:local": "pnpm run build && cd evals/deterministic && playwright test --config=local.playwright.config.ts",
|
|
24
|
+
"build-v3-dom-scripts": "tsx lib/v3/dom/genDomScripts.ts",
|
|
25
|
+
"build-types": "tsc --emitDeclarationOnly --outDir dist",
|
|
26
|
+
"build-js": "tsup --entry.index lib/v3/index.ts --dts",
|
|
27
|
+
"build:cli": "tsup evals/cli.ts --outDir dist/evals --format cjs && cp evals/evals.config.json dist/evals/ && chmod +x dist/evals/cli.js && npm link",
|
|
28
|
+
"build": "pnpm run lint && pnpm run gen-version && pnpm run build-v3-dom-scripts && pnpm run build-js && pnpm run build-types",
|
|
29
|
+
"gen-version": "tsx scripts/gen-version.ts",
|
|
30
|
+
"prepare": "pnpm run build",
|
|
31
|
+
"lint": "pnpm run prettier:fix && pnpm run eslint",
|
|
32
|
+
"release": "pnpm run build && changeset publish",
|
|
33
|
+
"release-canary": "pnpm run build && changeset version --snapshot && changeset publish --tag alpha"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist/index.js",
|
|
37
|
+
"dist/index.d.ts",
|
|
38
|
+
"dist/lib",
|
|
39
|
+
"dist/types",
|
|
40
|
+
"dist/stagehand.config.d.ts"
|
|
41
|
+
],
|
|
42
|
+
"keywords": [],
|
|
43
|
+
"author": "Browserbase",
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@changesets/changelog-github": "^0.5.0",
|
|
47
|
+
"@changesets/cli": "^2.27.9",
|
|
48
|
+
"@eslint/js": "^9.16.0",
|
|
49
|
+
"@langchain/core": "^0.3.40",
|
|
50
|
+
"@langchain/openai": "^0.4.4",
|
|
51
|
+
"playwright-core": "^1.54.1",
|
|
52
|
+
"puppeteer-core": "^22.8.0",
|
|
53
|
+
"chrome-launcher": "^1.2.0",
|
|
54
|
+
"patchright-core": "^1.55.2",
|
|
55
|
+
"@playwright/test": "^1.42.1",
|
|
56
|
+
"@types/adm-zip": "^0.5.7",
|
|
57
|
+
"@types/cheerio": "^0.22.35",
|
|
58
|
+
"@types/express": "^4.17.21",
|
|
59
|
+
"@types/node": "^20.11.30",
|
|
60
|
+
"@types/ws": "^8.5.13",
|
|
61
|
+
"adm-zip": "^0.5.16",
|
|
62
|
+
"autoevals": "^0.0.64",
|
|
63
|
+
"braintrust": "^0.0.171",
|
|
64
|
+
"chalk": "^5.4.1",
|
|
65
|
+
"cheerio": "^1.0.0",
|
|
66
|
+
"chromium-bidi": "^0.10.0",
|
|
67
|
+
"esbuild": "^0.21.4",
|
|
68
|
+
"eslint": "^9.16.0",
|
|
69
|
+
"express": "^4.21.0",
|
|
70
|
+
"globals": "^15.13.0",
|
|
71
|
+
"multer": "^1.4.5-lts.1",
|
|
72
|
+
"prettier": "^3.2.5",
|
|
73
|
+
"string-comparison": "^1.3.0",
|
|
74
|
+
"tsup": "^8.2.1",
|
|
75
|
+
"tsx": "^4.10.5",
|
|
76
|
+
"typescript": "^5.2.2",
|
|
77
|
+
"typescript-eslint": "^8.17.0"
|
|
78
|
+
},
|
|
79
|
+
"peerDependencies": {
|
|
80
|
+
"deepmerge": "^4.3.1",
|
|
81
|
+
"dotenv": "^16.4.5",
|
|
82
|
+
"zod": "3.25.67"
|
|
83
|
+
},
|
|
84
|
+
"dependencies": {
|
|
85
|
+
"@anthropic-ai/sdk": "0.39.0",
|
|
86
|
+
"@browserbasehq/sdk": "^2.4.0",
|
|
87
|
+
"@google/genai": "^0.8.0",
|
|
88
|
+
"@modelcontextprotocol/sdk": "^1.17.2",
|
|
89
|
+
"ai": "^4.3.9",
|
|
90
|
+
"devtools-protocol": "^0.0.1464554",
|
|
91
|
+
"fetch-cookie": "^3.1.0",
|
|
92
|
+
"openai": "^4.87.1",
|
|
93
|
+
"pino": "^9.6.0",
|
|
94
|
+
"pino-pretty": "^13.0.0",
|
|
95
|
+
"playwright": "^1.52.0",
|
|
96
|
+
"ws": "^8.18.0",
|
|
97
|
+
"zod-to-json-schema": "^3.23.5"
|
|
98
|
+
},
|
|
99
|
+
"optionalDependencies": {
|
|
100
|
+
"@ai-sdk/anthropic": "^1.2.6",
|
|
101
|
+
"@ai-sdk/azure": "^1.3.19",
|
|
102
|
+
"@ai-sdk/cerebras": "^0.2.6",
|
|
103
|
+
"@ai-sdk/deepseek": "^0.2.13",
|
|
104
|
+
"@ai-sdk/google": "^1.2.6",
|
|
105
|
+
"@ai-sdk/groq": "^1.2.4",
|
|
106
|
+
"@ai-sdk/mistral": "^1.2.7",
|
|
107
|
+
"@ai-sdk/openai": "^1.0.14",
|
|
108
|
+
"@ai-sdk/perplexity": "^1.1.7",
|
|
109
|
+
"@ai-sdk/togetherai": "^0.2.6",
|
|
110
|
+
"@ai-sdk/xai": "^1.2.15",
|
|
111
|
+
"ollama-ai-provider": "^1.2.0"
|
|
112
|
+
},
|
|
113
|
+
"directories": {
|
|
114
|
+
"doc": "docs",
|
|
115
|
+
"example": "examples",
|
|
116
|
+
"lib": "lib"
|
|
117
|
+
},
|
|
118
|
+
"repository": {
|
|
119
|
+
"type": "git",
|
|
120
|
+
"url": "git+https://github.com/browserbase/stagehand.git"
|
|
121
|
+
},
|
|
122
|
+
"bugs": {
|
|
123
|
+
"url": "https://github.com/browserbase/stagehand/issues"
|
|
124
|
+
},
|
|
125
|
+
"homepage": "https://stagehand.dev",
|
|
126
|
+
"overrides": {
|
|
127
|
+
"whatwg-url": "^14.0.0"
|
|
128
|
+
},
|
|
129
|
+
"packageManager": "pnpm@9.15.0+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c"
|
|
130
|
+
}
|