@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.
Files changed (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +165 -0
  3. package/dist/index.d.ts +1611 -0
  4. package/dist/index.js +28681 -0
  5. package/dist/lib/api.d.ts +23 -0
  6. package/dist/lib/dom/build/scriptContent.d.ts +1 -0
  7. package/dist/lib/inference.d.ts +71 -0
  8. package/dist/lib/inferenceLogUtils.d.ts +12 -0
  9. package/dist/lib/logger.d.ts +54 -0
  10. package/dist/lib/prompt.d.ts +12 -0
  11. package/dist/lib/utils.d.ts +65 -0
  12. package/dist/lib/v3/agent/AgentClient.d.ts +18 -0
  13. package/dist/lib/v3/agent/AgentProvider.d.ts +18 -0
  14. package/dist/lib/v3/agent/AnthropicCUAClient.d.ts +55 -0
  15. package/dist/lib/v3/agent/OpenAICUAClient.d.ts +64 -0
  16. package/dist/lib/v3/agent/StagehandAgent.d.ts +15 -0
  17. package/dist/lib/v3/agent/tools/index.d.ts +229 -0
  18. package/dist/lib/v3/agent/tools/v3-act.d.ts +29 -0
  19. package/dist/lib/v3/agent/tools/v3-ariaTree.d.ts +11 -0
  20. package/dist/lib/v3/agent/tools/v3-close.d.ts +24 -0
  21. package/dist/lib/v3/agent/tools/v3-extract.d.ts +38 -0
  22. package/dist/lib/v3/agent/tools/v3-fillform.d.ts +37 -0
  23. package/dist/lib/v3/agent/tools/v3-goto.d.ts +29 -0
  24. package/dist/lib/v3/agent/tools/v3-navback.d.ts +17 -0
  25. package/dist/lib/v3/agent/tools/v3-screenshot.d.ts +13 -0
  26. package/dist/lib/v3/agent/tools/v3-scroll.d.ts +23 -0
  27. package/dist/lib/v3/agent/tools/v3-wait.d.ts +19 -0
  28. package/dist/lib/v3/agent/utils/cuaKeyMapping.d.ts +10 -0
  29. package/dist/lib/v3/agent/utils/imageCompression.d.ts +18 -0
  30. package/dist/lib/v3/agent/utils/messageProcessing.d.ts +13 -0
  31. package/dist/lib/v3/dom/build/scriptV3Content.d.ts +1 -0
  32. package/dist/lib/v3/dom/genDomScripts.d.ts +1 -0
  33. package/dist/lib/v3/dom/index.d.ts +1 -0
  34. package/dist/lib/v3/dom/piercer.entry.d.ts +1 -0
  35. package/dist/lib/v3/dom/piercer.runtime.d.ts +25 -0
  36. package/dist/lib/v3/handlers/actHandler.d.ts +18 -0
  37. package/dist/lib/v3/handlers/extractHandler.d.ts +29 -0
  38. package/dist/lib/v3/handlers/handlerUtils/actHandlerUtils.d.ts +18 -0
  39. package/dist/lib/v3/handlers/observeHandler.d.ts +15 -0
  40. package/dist/lib/v3/handlers/v3AgentHandler.d.ts +17 -0
  41. package/dist/lib/v3/handlers/v3CuaAgentHandler.d.ts +26 -0
  42. package/dist/lib/v3/index.d.ts +10 -0
  43. package/dist/lib/v3/launch/browserbase.d.ts +8 -0
  44. package/dist/lib/v3/launch/local.d.ts +13 -0
  45. package/dist/lib/v3/llm/AnthropicClient.d.ts +16 -0
  46. package/dist/lib/v3/llm/CerebrasClient.d.ts +17 -0
  47. package/dist/lib/v3/llm/GoogleClient.d.ts +19 -0
  48. package/dist/lib/v3/llm/GroqClient.d.ts +17 -0
  49. package/dist/lib/v3/llm/LLMClient.d.ts +99 -0
  50. package/dist/lib/v3/llm/LLMProvider.d.ts +10 -0
  51. package/dist/lib/v3/llm/OpenAIClient.d.ts +15 -0
  52. package/dist/lib/v3/llm/aisdk.d.ts +15 -0
  53. package/dist/lib/v3/logger.d.ts +48 -0
  54. package/dist/lib/v3/mcp/connection.d.ts +11 -0
  55. package/dist/lib/v3/mcp/utils.d.ts +3 -0
  56. package/dist/lib/v3/tests/default-page-tracking.spec.d.ts +1 -0
  57. package/dist/lib/v3/tests/perform-understudy-method.spec.d.ts +1 -0
  58. package/dist/lib/v3/tests/shadow-iframe.spec.d.ts +1 -0
  59. package/dist/lib/v3/tests/timeouts.spec.d.ts +1 -0
  60. package/dist/lib/v3/tests/v3.config.d.ts +4 -0
  61. package/dist/lib/v3/tests/v3.playwright.config.d.ts +2 -0
  62. package/dist/lib/v3/tests/xpath-for-location-deep.spec.d.ts +1 -0
  63. package/dist/lib/v3/types/act.d.ts +10 -0
  64. package/dist/lib/v3/types/agent.d.ts +132 -0
  65. package/dist/lib/v3/types/api.d.ts +40 -0
  66. package/dist/lib/v3/types/cache.d.ts +71 -0
  67. package/dist/lib/v3/types/context.d.ts +2 -0
  68. package/dist/lib/v3/types/evals.d.ts +71 -0
  69. package/dist/lib/v3/types/evaluator.d.ts +40 -0
  70. package/dist/lib/v3/types/llm.d.ts +11 -0
  71. package/dist/lib/v3/types/log.d.ts +23 -0
  72. package/dist/lib/v3/types/model.d.ts +20 -0
  73. package/dist/lib/v3/types/playwright.d.ts +6 -0
  74. package/dist/lib/v3/types/stagehand.d.ts +113 -0
  75. package/dist/lib/v3/types/stagehandApiErrors.d.ts +18 -0
  76. package/dist/lib/v3/types/stagehandErrors.d.ts +104 -0
  77. package/dist/lib/v3/types.d.ts +176 -0
  78. package/dist/lib/v3/understudy/a11y/snapshot.d.ts +71 -0
  79. package/dist/lib/v3/understudy/cdp.d.ts +58 -0
  80. package/dist/lib/v3/understudy/context.d.ts +120 -0
  81. package/dist/lib/v3/understudy/deepLocator.d.ts +69 -0
  82. package/dist/lib/v3/understudy/executionContextRegistry.d.ts +15 -0
  83. package/dist/lib/v3/understudy/frame.d.ts +63 -0
  84. package/dist/lib/v3/understudy/frameLocator.d.ts +46 -0
  85. package/dist/lib/v3/understudy/frameRegistry.d.ts +100 -0
  86. package/dist/lib/v3/understudy/locator.d.ts +196 -0
  87. package/dist/lib/v3/understudy/page.d.ts +241 -0
  88. package/dist/lib/v3/understudy/piercer.d.ts +4 -0
  89. package/dist/lib/v3/v3.d.ts +156 -0
  90. package/dist/lib/version.d.ts +5 -0
  91. package/package.json +130 -0
@@ -0,0 +1,29 @@
1
+ import { z } from "zod/v3";
2
+ import type { V3 } from "@/lib/v3/v3";
3
+ export declare const createActTool: (v3: V3, executionModel?: string) => import("ai/dist").Tool<z.ZodObject<{
4
+ action: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ action?: string;
7
+ }, {
8
+ action?: string;
9
+ }>, {
10
+ success: boolean;
11
+ action: string;
12
+ error?: undefined;
13
+ } | {
14
+ success: boolean;
15
+ error: any;
16
+ action?: undefined;
17
+ }> & {
18
+ execute: (args: {
19
+ action?: string;
20
+ }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
21
+ success: boolean;
22
+ action: string;
23
+ error?: undefined;
24
+ } | {
25
+ success: boolean;
26
+ error: any;
27
+ action?: undefined;
28
+ }>;
29
+ };
@@ -0,0 +1,11 @@
1
+ import { z } from "zod/v3";
2
+ import type { V3 } from "@/lib/v3/v3";
3
+ export declare const createAriaTreeTool: (v3: V3) => import("ai/dist").Tool<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, {
4
+ content: string;
5
+ pageUrl: string;
6
+ }> & {
7
+ execute: (args: {}, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
8
+ content: string;
9
+ pageUrl: string;
10
+ }>;
11
+ };
@@ -0,0 +1,24 @@
1
+ import { z } from "zod/v3";
2
+ export declare const createCloseTool: () => import("ai/dist").Tool<z.ZodObject<{
3
+ reasoning: z.ZodString;
4
+ taskComplete: z.ZodBoolean;
5
+ }, "strip", z.ZodTypeAny, {
6
+ reasoning?: string;
7
+ taskComplete?: boolean;
8
+ }, {
9
+ reasoning?: string;
10
+ taskComplete?: boolean;
11
+ }>, {
12
+ success: boolean;
13
+ reasoning: string;
14
+ taskComplete: boolean;
15
+ }> & {
16
+ execute: (args: {
17
+ reasoning?: string;
18
+ taskComplete?: boolean;
19
+ }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
20
+ success: boolean;
21
+ reasoning: string;
22
+ taskComplete: boolean;
23
+ }>;
24
+ };
@@ -0,0 +1,38 @@
1
+ import { z } from "zod/v3";
2
+ import type { V3 } from "@/lib/v3/v3";
3
+ import type { LogLine } from "../../types/log";
4
+ export declare const createExtractTool: (v3: V3, executionModel?: string, logger?: (message: LogLine) => void) => import("ai/dist").Tool<z.ZodObject<{
5
+ instruction: z.ZodOptional<z.ZodString>;
6
+ schema: z.ZodOptional<z.ZodString>;
7
+ selector: z.ZodOptional<z.ZodString>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ instruction?: string;
10
+ selector?: string;
11
+ schema?: string;
12
+ }, {
13
+ instruction?: string;
14
+ selector?: string;
15
+ schema?: string;
16
+ }>, {
17
+ success: boolean;
18
+ result: any;
19
+ error?: undefined;
20
+ } | {
21
+ success: boolean;
22
+ error: any;
23
+ result?: undefined;
24
+ }> & {
25
+ execute: (args: {
26
+ instruction?: string;
27
+ selector?: string;
28
+ schema?: string;
29
+ }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
30
+ success: boolean;
31
+ result: any;
32
+ error?: undefined;
33
+ } | {
34
+ success: boolean;
35
+ error: any;
36
+ result?: undefined;
37
+ }>;
38
+ };
@@ -0,0 +1,37 @@
1
+ import { z } from "zod/v3";
2
+ import type { V3 } from "@/lib/v3/v3";
3
+ export declare const createFillFormTool: (v3: V3, executionModel?: string) => import("ai/dist").Tool<z.ZodObject<{
4
+ fields: z.ZodArray<z.ZodObject<{
5
+ action: z.ZodString;
6
+ value: z.ZodString;
7
+ }, "strip", z.ZodTypeAny, {
8
+ value?: string;
9
+ action?: string;
10
+ }, {
11
+ value?: string;
12
+ action?: string;
13
+ }>, "many">;
14
+ }, "strip", z.ZodTypeAny, {
15
+ fields?: {
16
+ value?: string;
17
+ action?: string;
18
+ }[];
19
+ }, {
20
+ fields?: {
21
+ value?: string;
22
+ action?: string;
23
+ }[];
24
+ }>, {
25
+ success: boolean;
26
+ actions: unknown[];
27
+ }> & {
28
+ execute: (args: {
29
+ fields?: {
30
+ value?: string;
31
+ action?: string;
32
+ }[];
33
+ }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
34
+ success: boolean;
35
+ actions: unknown[];
36
+ }>;
37
+ };
@@ -0,0 +1,29 @@
1
+ import { z } from "zod/v3";
2
+ import type { V3 } from "@/lib/v3/v3";
3
+ export declare const createGotoTool: (v3: V3) => import("ai/dist").Tool<z.ZodObject<{
4
+ url: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ url?: string;
7
+ }, {
8
+ url?: string;
9
+ }>, {
10
+ success: boolean;
11
+ url: string;
12
+ error?: undefined;
13
+ } | {
14
+ success: boolean;
15
+ error: any;
16
+ url?: undefined;
17
+ }> & {
18
+ execute: (args: {
19
+ url?: string;
20
+ }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
21
+ success: boolean;
22
+ url: string;
23
+ error?: undefined;
24
+ } | {
25
+ success: boolean;
26
+ error: any;
27
+ url?: undefined;
28
+ }>;
29
+ };
@@ -0,0 +1,17 @@
1
+ import { z } from "zod/v3";
2
+ import type { V3 } from "@/lib/v3/v3";
3
+ export declare const createNavBackTool: (v3: V3) => import("ai/dist").Tool<z.ZodObject<{
4
+ reasoning: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ reasoning?: string;
7
+ }, {
8
+ reasoning?: string;
9
+ }>, {
10
+ success: boolean;
11
+ }> & {
12
+ execute: (args: {
13
+ reasoning?: string;
14
+ }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
15
+ success: boolean;
16
+ }>;
17
+ };
@@ -0,0 +1,13 @@
1
+ import { z } from "zod/v3";
2
+ import type { V3 } from "@/lib/v3/v3";
3
+ export declare const createScreenshotTool: (v3: V3) => import("ai/dist").Tool<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, {
4
+ base64: string;
5
+ timestamp: number;
6
+ pageUrl: string;
7
+ }> & {
8
+ execute: (args: {}, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
9
+ base64: string;
10
+ timestamp: number;
11
+ pageUrl: string;
12
+ }>;
13
+ };
@@ -0,0 +1,23 @@
1
+ import { z } from "zod/v3";
2
+ import type { V3 } from "@/lib/v3/v3";
3
+ export declare const createScrollTool: (v3: V3) => import("ai/dist").Tool<z.ZodObject<{
4
+ pixels: z.ZodNumber;
5
+ direction: z.ZodEnum<["up", "down"]>;
6
+ }, "strip", z.ZodTypeAny, {
7
+ pixels?: number;
8
+ direction?: "up" | "down";
9
+ }, {
10
+ pixels?: number;
11
+ direction?: "up" | "down";
12
+ }>, {
13
+ success: boolean;
14
+ pixels: number;
15
+ }> & {
16
+ execute: (args: {
17
+ pixels?: number;
18
+ direction?: "up" | "down";
19
+ }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
20
+ success: boolean;
21
+ pixels: number;
22
+ }>;
23
+ };
@@ -0,0 +1,19 @@
1
+ import { z } from "zod/v3";
2
+ import type { V3 } from "@/lib/v3/v3";
3
+ export declare const createWaitTool: (v3: V3) => import("ai/dist").Tool<z.ZodObject<{
4
+ timeMs: z.ZodNumber;
5
+ }, "strip", z.ZodTypeAny, {
6
+ timeMs?: number;
7
+ }, {
8
+ timeMs?: number;
9
+ }>, {
10
+ success: boolean;
11
+ waited: number;
12
+ }> & {
13
+ execute: (args: {
14
+ timeMs?: number;
15
+ }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
16
+ success: boolean;
17
+ waited: number;
18
+ }>;
19
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Universal key mapping utility for converting various key representations
3
+ * to Playwright-compatible key names. Used by all CUA clients and handlers.
4
+ */
5
+ /**
6
+ * Maps a key name from various formats to Playwright-compatible format
7
+ * @param key The key name in any supported format
8
+ * @returns The Playwright-compatible key name
9
+ */
10
+ export declare function mapKeyToPlaywright(key: string): string;
@@ -0,0 +1,18 @@
1
+ import { AnthropicMessage, AnthropicToolResult } from "../../types/agent";
2
+ export type ResponseInputItem = AnthropicMessage | AnthropicToolResult;
3
+ /**
4
+ * Finds all items in the conversation history that contain images
5
+ * @param items - Array of conversation items to check
6
+ * @returns Array of indices where images were found
7
+ */
8
+ export declare function findItemsWithImages(items: ResponseInputItem[]): number[];
9
+ /**
10
+ * Compresses conversation history by removing images from older items
11
+ * while keeping the most recent images intact
12
+ * @param items - Array of conversation items to process
13
+ * @param keepMostRecentCount - Number of most recent image-containing items to preserve (default: 2)
14
+ * @returns Object with processed items
15
+ */
16
+ export declare function compressConversationImages(items: ResponseInputItem[], keepMostRecentCount?: number): {
17
+ items: ResponseInputItem[];
18
+ };
@@ -0,0 +1,13 @@
1
+ import { type LanguageModelV1CallOptions } from "ai";
2
+ export interface CompressionStats {
3
+ originalSize: number;
4
+ compressedSize: number;
5
+ savedChars: number;
6
+ compressionRatio: number;
7
+ screenshotCount: number;
8
+ ariaTreeCount: number;
9
+ }
10
+ export declare function processMessages(params: LanguageModelV1CallOptions): {
11
+ processedPrompt: LanguageModelV1CallOptions["prompt"];
12
+ stats: CompressionStats;
13
+ };
@@ -0,0 +1 @@
1
+ export declare const v3ScriptContent = "(()=>{function b(_={}){let S=n=>{let{hostToRoot:l}=n,m=t=>{let o=[];if(t instanceof Document)return t.documentElement&&o.push(t.documentElement),o;if(t instanceof ShadowRoot||t instanceof DocumentFragment)return o.push(...Array.from(t.children)),o;if(t instanceof Element){o.push(...Array.from(t.children));let a=t.shadowRoot;a&&o.push(...Array.from(a.children));let r=l.get(t);return r&&o.push(...Array.from(r.children)),o}return o},v=t=>{let o=[],a=[...m(t)];for(;a.length;){let r=a.shift();o.push(r),a.push(...m(r))}return o},y=t=>{let o=String(t||\"\").trim();if(!o)return null;let a=o.replace(/^xpath=/i,\"\"),r=[];{let e=0;for(;e<a.length;){let d=\"child\";a.startsWith(\"//\",e)?(d=\"desc\",e+=2):a[e]===\"/\"&&(d=\"child\",e+=1);let h=e;for(;e<a.length&&a[e]!==\"/\";)e++;let u=a.slice(h,e).trim();if(!u)continue;let p=u.match(/^(.*?)(\\[(\\d+)\\])?$/u),i=(p?.[1]??u).trim(),c=p?.[3]?Math.max(1,Number(p[3])):null,R=i===\"\"?\"*\":i.toLowerCase();r.push({axis:d,raw:u,tag:R,index:c})}}n.debug&&console.info(\"[v3-piercer][resolve] start\",{url:location.href,steps:r.map(e=>({axis:e.axis,raw:e.raw,tag:e.tag,index:e.index}))});let g=[document];for(let e of r){let d=e.index,h=null;for(let u of g){let p=e.axis===\"child\"?m(u):v(u),i=[];for(let c of p)(e.tag===\"*\"||c.localName===e.tag)&&i.push(c);if(n.debug&&console.info(\"[v3-piercer][resolve] step\",{axis:e.axis,tag:e.tag,index:d,poolCount:p.length,matchesCount:i.length}),!!i.length){if(d!=null){let c=d-1;h=c>=0&&c<i.length?i[c]:null}else h=i[0];if(h)break}}if(!h)return n.debug&&console.info(\"[v3-piercer][resolve] no-match\",{step:e.raw}),null;g=[h]}let E=g.length?g[0]:null;return n.debug&&console.info(\"[v3-piercer][resolve] done\",{found:!!E,tag:E?.localName??\"\"}),E};window.__stagehandV3__={getClosedRoot:t=>l.get(t),stats:()=>({installed:!0,url:location.href,isTop:window.top===window,open:n.openCount,closed:n.closedCount}),resolveSimpleXPath:y}},f=Element.prototype.attachShadow;if(f.__v3Patched&&f.__v3State){f.__v3State.debug=!0,S(f.__v3State);return}let s={hostToRoot:new WeakMap,openCount:0,closedCount:0,debug:!0},x=f,w=function(n){let l=n?.mode??\"open\",m=x.call(this,n);try{s.hostToRoot.set(this,m),l===\"closed\"?s.closedCount++:s.openCount++,s.debug&&console.info(\"[v3-piercer] attachShadow\",{tag:this.tagName?.toLowerCase()??\"\",mode:l,url:location.href})}catch{}return m};if(w.__v3Patched=!0,w.__v3State=s,Object.defineProperty(Element.prototype,\"attachShadow\",{configurable:!0,writable:!0,value:w}),_.tagExisting)try{let n=document.createTreeWalker(document,NodeFilter.SHOW_ELEMENT);for(;n.nextNode();){let l=n.currentNode;l.shadowRoot&&(s.hostToRoot.set(l,l.shadowRoot),s.openCount++)}}catch{}window.__stagehandV3Injected=!0,S(s),s.debug&&console.info(\"[v3-piercer] installed\",{url:location.href,isTop:window.top===window,readyState:document.readyState})}b({debug:!0,tagExisting:!1});})();\n";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./piercer.runtime";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ export interface V3ShadowPatchOptions {
2
+ debug?: boolean;
3
+ tagExisting?: boolean;
4
+ }
5
+ export interface StagehandV3Backdoor {
6
+ /** Closed shadow-root accessors */
7
+ getClosedRoot(host: Element): ShadowRoot | undefined;
8
+ /** Stats + quick health check */
9
+ stats(): {
10
+ installed: true;
11
+ url: string;
12
+ isTop: boolean;
13
+ open: number;
14
+ closed: number;
15
+ };
16
+ /** Simple composed-tree resolver (axis '/', '//' and trailing [n] only; no iframe hops) */
17
+ resolveSimpleXPath(xp: string): Element | null;
18
+ }
19
+ declare global {
20
+ interface Window {
21
+ __stagehandV3Injected?: boolean;
22
+ __stagehandV3__?: StagehandV3Backdoor;
23
+ }
24
+ }
25
+ export declare function installV3ShadowPiercer(opts?: V3ShadowPatchOptions): void;
@@ -0,0 +1,18 @@
1
+ import { ActHandlerParams, V3FunctionName } from "@/lib/v3/types";
2
+ import { LLMClient } from "../llm/LLMClient";
3
+ import { AvailableModel, ClientOptions } from "../types/model";
4
+ import type { Page } from "../understudy/page";
5
+ import type { Action, ActResult } from "../types/stagehand";
6
+ export declare class ActHandler {
7
+ private readonly llmClient;
8
+ private readonly defaultModelName;
9
+ private readonly defaultClientOptions;
10
+ private readonly systemPrompt;
11
+ private readonly logInferenceToFile;
12
+ private readonly selfHeal;
13
+ private readonly onMetrics?;
14
+ private readonly defaultDomSettleTimeoutMs?;
15
+ constructor(llmClient: LLMClient, defaultModelName: AvailableModel, defaultClientOptions: ClientOptions, systemPrompt?: string, logInferenceToFile?: boolean, selfHeal?: boolean, onMetrics?: (functionName: V3FunctionName, promptTokens: number, completionTokens: number, inferenceTimeMs: number) => void, defaultDomSettleTimeoutMs?: number);
16
+ act(params: ActHandlerParams): Promise<ActResult>;
17
+ actFromObserveResult(action: Action, page: Page, domSettleTimeoutMs?: number): Promise<ActResult>;
18
+ }
@@ -0,0 +1,29 @@
1
+ import { z, ZodTypeAny } from "zod/v3";
2
+ import { ExtractHandlerParams, V3FunctionName } from "@/lib/v3/types";
3
+ import { LLMClient } from "../llm/LLMClient";
4
+ import { AvailableModel, ClientOptions } from "../types/model";
5
+ import { ZodPathSegments } from "../types/stagehand";
6
+ /**
7
+ * Scans the provided Zod schema for any `z.string().url()` fields and
8
+ * replaces them with `z.number()`.
9
+ *
10
+ * @param schema - The Zod object schema to transform.
11
+ * @returns A tuple containing:
12
+ * 1. The transformed schema (or the original schema if no changes were needed).
13
+ * 2. An array of {@link ZodPathSegments} objects representing all the replaced URL fields,
14
+ * with each path segment showing where in the schema the replacement occurred.
15
+ */
16
+ export declare function transformUrlStringsToNumericIds<T extends ZodTypeAny>(schema: T): [T, ZodPathSegments[]];
17
+ export declare class ExtractHandler {
18
+ private readonly llmClient;
19
+ private readonly defaultModelName;
20
+ private readonly defaultClientOptions;
21
+ private readonly systemPrompt;
22
+ private readonly logInferenceToFile;
23
+ private readonly experimental;
24
+ private readonly onMetrics?;
25
+ constructor(llmClient: LLMClient, defaultModelName: AvailableModel, defaultClientOptions: ClientOptions, systemPrompt?: string, logInferenceToFile?: boolean, experimental?: boolean, onMetrics?: (functionName: V3FunctionName, promptTokens: number, completionTokens: number, inferenceTimeMs: number) => void);
26
+ extract<T extends ZodTypeAny>(params: ExtractHandlerParams<T>): Promise<z.infer<T> | {
27
+ pageText: string;
28
+ }>;
29
+ }
@@ -0,0 +1,18 @@
1
+ import { Frame } from "../../understudy/frame";
2
+ import { Locator } from "../../understudy/locator";
3
+ import type { Page } from "../../understudy/page";
4
+ export declare class UnderstudyCommandException extends Error {
5
+ constructor(message: string);
6
+ }
7
+ export interface UnderstudyMethodHandlerContext {
8
+ method: string;
9
+ locator: Locator;
10
+ xpath: string;
11
+ args: ReadonlyArray<string>;
12
+ frame: Frame;
13
+ page: Page;
14
+ initialUrl: string;
15
+ domSettleTimeoutMs?: number;
16
+ }
17
+ export declare function performUnderstudyMethod(page: Page, frame: Frame, method: string, rawXPath: string, args: ReadonlyArray<unknown>, domSettleTimeoutMs?: number): Promise<void>;
18
+ export declare function selectOption(ctx: UnderstudyMethodHandlerContext): Promise<void>;
@@ -0,0 +1,15 @@
1
+ import { ObserveHandlerParams, V3FunctionName } from "@/lib/v3/types";
2
+ import { AvailableModel, ClientOptions } from "../types/model";
3
+ import { LLMClient } from "../llm/LLMClient";
4
+ import { Action } from "../types/stagehand";
5
+ export declare class ObserveHandler {
6
+ private readonly llmClient;
7
+ private readonly defaultModelName;
8
+ private readonly defaultClientOptions;
9
+ private readonly systemPrompt;
10
+ private readonly logInferenceToFile;
11
+ private readonly experimental;
12
+ private readonly onMetrics?;
13
+ constructor(llmClient: LLMClient, defaultModelName: AvailableModel, defaultClientOptions: ClientOptions, systemPrompt?: string, logInferenceToFile?: boolean, experimental?: boolean, onMetrics?: (functionName: V3FunctionName, promptTokens: number, completionTokens: number, inferenceTimeMs: number) => void);
14
+ observe(params: ObserveHandlerParams): Promise<Action[]>;
15
+ }
@@ -0,0 +1,17 @@
1
+ import { AgentExecuteOptions, AgentResult } from "../types/agent";
2
+ import { LogLine } from "../types/log";
3
+ import { LLMClient } from "../llm/LLMClient";
4
+ import { ToolSet } from "ai";
5
+ import { V3 } from "@/lib/v3/v3";
6
+ export declare class V3AgentHandler {
7
+ private v3;
8
+ private logger;
9
+ private llmClient;
10
+ private executionModel?;
11
+ private systemInstructions?;
12
+ private mcpTools?;
13
+ constructor(v3: V3, logger: (message: LogLine) => void, llmClient: LLMClient, executionModel?: string, systemInstructions?: string, mcpTools?: ToolSet);
14
+ execute(instructionOrOptions: string | AgentExecuteOptions): Promise<AgentResult>;
15
+ private buildSystemPrompt;
16
+ private createTools;
17
+ }
@@ -0,0 +1,26 @@
1
+ import { AgentExecuteOptions, AgentHandlerOptions, AgentResult } from "../types/agent";
2
+ import { LogLine } from "../types/log";
3
+ import { V3 } from "@/lib/v3/v3";
4
+ import { ToolSet } from "ai";
5
+ export declare class V3CuaAgentHandler {
6
+ private v3;
7
+ private agent;
8
+ private provider;
9
+ private logger;
10
+ private agentClient;
11
+ private options;
12
+ constructor(v3: V3, logger: (message: LogLine) => void, options: AgentHandlerOptions, tools?: ToolSet);
13
+ private setupAgentClient;
14
+ execute(optionsOrInstruction: AgentExecuteOptions | string): Promise<AgentResult>;
15
+ private executeAction;
16
+ private ensureXPath;
17
+ private describePointerAction;
18
+ private describeTypeAction;
19
+ private describeDragAction;
20
+ private buildInstructionFallback;
21
+ private recordCuaActStep;
22
+ private updateClientViewport;
23
+ private updateClientUrl;
24
+ captureAndSendScreenshot(): Promise<unknown>;
25
+ private injectCursor;
26
+ }
@@ -0,0 +1,10 @@
1
+ export { V3 } from "./v3";
2
+ export { V3 as Stagehand } from "./v3";
3
+ export * from "./types/agent";
4
+ export * from "./types/model";
5
+ export * from "./types/log";
6
+ export * from "./types/stagehand";
7
+ export * from "./types/stagehandApiErrors";
8
+ export * from "./types/stagehandErrors";
9
+ export * from "./llm/LLMClient";
10
+ export { connectToMCPServer } from "../v3/mcp/connection";
@@ -0,0 +1,8 @@
1
+ import Browserbase from "@browserbasehq/sdk";
2
+ export declare function createBrowserbaseSession(apiKey: string, projectId: string, params?: Omit<Browserbase.Sessions.SessionCreateParams, "projectId"> & {
3
+ projectId?: string;
4
+ }, resumeSessionId?: string): Promise<{
5
+ ws: string;
6
+ sessionId: string;
7
+ bb: Browserbase;
8
+ }>;
@@ -0,0 +1,13 @@
1
+ import { LaunchedChrome } from "chrome-launcher";
2
+ interface LaunchLocalOptions {
3
+ chromePath?: string;
4
+ chromeFlags?: string[];
5
+ headless?: boolean;
6
+ userDataDir?: string;
7
+ connectTimeoutMs?: number;
8
+ }
9
+ export declare function launchLocalChrome(opts: LaunchLocalOptions): Promise<{
10
+ ws: string;
11
+ chrome: LaunchedChrome;
12
+ }>;
13
+ export {};
@@ -0,0 +1,16 @@
1
+ import { ClientOptions } from "@anthropic-ai/sdk";
2
+ import { LogLine } from "../types/log";
3
+ import { AvailableModel } from "../types/model";
4
+ import { CreateChatCompletionOptions, LLMClient, LLMResponse } from "./LLMClient";
5
+ export declare class AnthropicClient extends LLMClient {
6
+ type: "anthropic";
7
+ private client;
8
+ clientOptions: ClientOptions;
9
+ constructor({ modelName, clientOptions, userProvidedInstructions, }: {
10
+ logger: (message: LogLine) => void;
11
+ modelName: AvailableModel;
12
+ clientOptions?: ClientOptions;
13
+ userProvidedInstructions?: string;
14
+ });
15
+ createChatCompletion<T = LLMResponse>({ options, retries, logger, }: CreateChatCompletionOptions): Promise<T>;
16
+ }
@@ -0,0 +1,17 @@
1
+ import type { ClientOptions } from "openai";
2
+ import { LogLine } from "../types/log";
3
+ import { AvailableModel } from "../types/model";
4
+ import { CreateChatCompletionOptions, LLMClient, LLMResponse } from "./LLMClient";
5
+ export declare class CerebrasClient extends LLMClient {
6
+ type: "cerebras";
7
+ private client;
8
+ clientOptions: ClientOptions;
9
+ hasVision: boolean;
10
+ constructor({ modelName, clientOptions, userProvidedInstructions, }: {
11
+ logger: (message: LogLine) => void;
12
+ modelName: AvailableModel;
13
+ clientOptions?: ClientOptions;
14
+ userProvidedInstructions?: string;
15
+ });
16
+ createChatCompletion<T = LLMResponse>({ options, retries, logger, }: CreateChatCompletionOptions): Promise<T>;
17
+ }
@@ -0,0 +1,19 @@
1
+ import { LogLine } from "../types/log";
2
+ import { AvailableModel, ClientOptions } from "../types/model";
3
+ import { CreateChatCompletionOptions, LLMClient, LLMResponse } from "./LLMClient";
4
+ export declare class GoogleClient extends LLMClient {
5
+ type: "google";
6
+ private client;
7
+ clientOptions: ClientOptions;
8
+ hasVision: boolean;
9
+ private logger;
10
+ constructor({ logger, // Added logger based on other clients
11
+ modelName, clientOptions, }: {
12
+ logger: (message: LogLine) => void;
13
+ modelName: AvailableModel;
14
+ clientOptions?: ClientOptions;
15
+ });
16
+ private formatMessages;
17
+ private formatTools;
18
+ createChatCompletion<T = LLMResponse>({ options, logger, retries, }: CreateChatCompletionOptions): Promise<T>;
19
+ }
@@ -0,0 +1,17 @@
1
+ import type { ClientOptions } from "openai";
2
+ import { LogLine } from "../types/log";
3
+ import { AvailableModel } from "../types/model";
4
+ import { CreateChatCompletionOptions, LLMClient, LLMResponse } from "./LLMClient";
5
+ export declare class GroqClient extends LLMClient {
6
+ type: "groq";
7
+ private client;
8
+ clientOptions: ClientOptions;
9
+ hasVision: boolean;
10
+ constructor({ modelName, clientOptions, userProvidedInstructions, }: {
11
+ logger: (message: LogLine) => void;
12
+ modelName: AvailableModel;
13
+ clientOptions?: ClientOptions;
14
+ userProvidedInstructions?: string;
15
+ });
16
+ createChatCompletion<T = LLMResponse>({ options, retries, logger, }: CreateChatCompletionOptions): Promise<T>;
17
+ }