@browserbasehq/orca 3.0.3-patch → 3.0.3-zod-1

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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.d.ts +56 -31
  3. package/dist/index.js +521 -256
  4. package/package.json +23 -21
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Browserbase Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import z, { ZodType, z as z$1, ZodError, ZodTypeAny } from 'zod/v3';
1
+ import { ZodTypeAny, z, ZodObject, ZodRawShape, ZodError } from 'zod';
2
+ import * as z3 from 'zod/v3';
2
3
  import { ClientOptions as ClientOptions$2 } from '@anthropic-ai/sdk';
3
4
  import { LanguageModelV2 } from '@ai-sdk/provider';
4
5
  import { ClientOptions as ClientOptions$1 } from 'openai';
@@ -17,6 +18,16 @@ import { ChatCompletion } from 'openai/resources';
17
18
  import { ToolSet as ToolSet$1 } from 'ai/dist';
18
19
  import { Schema } from '@google/genai';
19
20
 
21
+ type StagehandZodSchema = ZodTypeAny | z3.ZodTypeAny;
22
+ type StagehandZodObject = ZodObject<ZodRawShape> | z3.ZodObject<z3.ZodRawShape>;
23
+ type InferStagehandSchema<T extends StagehandZodSchema> = T extends z3.ZodTypeAny ? z3.infer<T> : T extends ZodTypeAny ? z.infer<T> : never;
24
+ declare const isZod4Schema: (schema: StagehandZodSchema) => schema is ZodTypeAny & {
25
+ _zod: unknown;
26
+ };
27
+ declare const isZod3Schema: (schema: StagehandZodSchema) => schema is z3.ZodTypeAny;
28
+ type JsonSchemaDocument = Record<string, unknown>;
29
+ declare function toJsonSchema(schema: StagehandZodSchema): JsonSchemaDocument;
30
+
20
31
  type AnthropicJsonSchemaObject = {
21
32
  definitions?: {
22
33
  MySchema?: {
@@ -102,7 +113,7 @@ interface ChatCompletionOptions {
102
113
  };
103
114
  response_model?: {
104
115
  name: string;
105
- schema: ZodType;
116
+ schema: StagehandZodSchema;
106
117
  };
107
118
  tools?: LLMTool[];
108
119
  tool_choice?: "auto" | "none" | "required";
@@ -141,6 +152,21 @@ interface CreateChatCompletionOptions {
141
152
  logger: (message: LogLine) => void;
142
153
  retries?: number;
143
154
  }
155
+ /** Simple usage shape if your LLM returns usage tokens. */
156
+ interface LLMUsage {
157
+ prompt_tokens: number;
158
+ completion_tokens: number;
159
+ total_tokens: number;
160
+ reasoning_tokens?: number;
161
+ cached_input_tokens?: number;
162
+ }
163
+ /**
164
+ * For calls that use a schema: the LLMClient may return { data: T; usage?: LLMUsage }
165
+ */
166
+ interface LLMParsedResponse<T> {
167
+ data: T;
168
+ usage?: LLMUsage;
169
+ }
144
170
  declare abstract class LLMClient {
145
171
  type: "openai" | "anthropic" | "cerebras" | "groq" | (string & {});
146
172
  modelName: AvailableModel | (string & {});
@@ -148,9 +174,15 @@ declare abstract class LLMClient {
148
174
  clientOptions: ClientOptions;
149
175
  userProvidedInstructions?: string;
150
176
  constructor(modelName: AvailableModel, userProvidedInstructions?: string);
151
- abstract createChatCompletion<T = LLMResponse & {
152
- usage?: LLMResponse["usage"];
153
- }>(options: CreateChatCompletionOptions): Promise<T>;
177
+ abstract createChatCompletion<T>(options: CreateChatCompletionOptions & {
178
+ options: {
179
+ response_model: {
180
+ name: string;
181
+ schema: StagehandZodSchema;
182
+ };
183
+ };
184
+ }): Promise<LLMParsedResponse<T>>;
185
+ abstract createChatCompletion<T = LLMResponse>(options: CreateChatCompletionOptions): Promise<T>;
154
186
  generateObject: typeof generateObject;
155
187
  generateText: typeof generateText;
156
188
  streamText: typeof streamText;
@@ -757,7 +789,7 @@ declare class StagehandAPIClient {
757
789
  constructor({ apiKey, projectId, logger }: StagehandAPIConstructorParams);
758
790
  init({ modelName, modelApiKey, domSettleTimeoutMs, verbose, systemPrompt, selfHeal, browserbaseSessionCreateParams, browserbaseSessionID, }: StartSessionParams): Promise<StartSessionResult>;
759
791
  act({ input, options, frameId }: APIActParameters): Promise<ActResult>;
760
- extract<T extends z.AnyZodObject>({ instruction, schema: zodSchema, options, frameId, }: APIExtractParameters): Promise<ExtractResult<T>>;
792
+ extract<T extends StagehandZodSchema>({ instruction, schema: zodSchema, options, frameId, }: APIExtractParameters): Promise<ExtractResult<T>>;
761
793
  observe({ instruction, options, frameId, }: APIObserveParameters): Promise<Action[]>;
762
794
  goto(url: string, options?: {
763
795
  waitUntil?: "load" | "domcontentloaded" | "networkidle";
@@ -1312,7 +1344,7 @@ interface ActResult {
1312
1344
  actionDescription: string;
1313
1345
  actions: Action[];
1314
1346
  }
1315
- type ExtractResult<T extends z$1.AnyZodObject> = z$1.infer<T>;
1347
+ type ExtractResult<T extends StagehandZodSchema> = InferStagehandSchema<T>;
1316
1348
  interface Action {
1317
1349
  selector: string;
1318
1350
  description: string;
@@ -1331,20 +1363,12 @@ interface ExtractOptions {
1331
1363
  selector?: string;
1332
1364
  page?: Page$1 | Page$2 | Page$3 | Page;
1333
1365
  }
1334
- declare const defaultExtractSchema: z$1.ZodObject<{
1335
- extraction: z$1.ZodString;
1336
- }, "strip", z$1.ZodTypeAny, {
1337
- extraction?: string;
1338
- }, {
1339
- extraction?: string;
1340
- }>;
1341
- declare const pageTextSchema: z$1.ZodObject<{
1342
- pageText: z$1.ZodString;
1343
- }, "strip", z$1.ZodTypeAny, {
1344
- pageText?: string;
1345
- }, {
1346
- pageText?: string;
1347
- }>;
1366
+ declare const defaultExtractSchema: z.ZodObject<{
1367
+ extraction: z.ZodString;
1368
+ }, z.core.$strip>;
1369
+ declare const pageTextSchema: z.ZodObject<{
1370
+ pageText: z.ZodString;
1371
+ }, z.core.$strip>;
1348
1372
  interface ObserveOptions {
1349
1373
  model?: ModelConfiguration;
1350
1374
  timeout?: number;
@@ -1610,7 +1634,7 @@ interface APIActParameters {
1610
1634
  }
1611
1635
  interface APIExtractParameters {
1612
1636
  instruction?: string;
1613
- schema?: ZodTypeAny;
1637
+ schema?: StagehandZodSchema;
1614
1638
  options?: ExtractOptions;
1615
1639
  frameId?: string;
1616
1640
  }
@@ -1954,10 +1978,10 @@ declare class V3 {
1954
1978
  * - extract(instruction, schema) → schema-inferred
1955
1979
  * - extract(instruction, schema, options)
1956
1980
  */
1957
- extract(): Promise<z$1.infer<typeof pageTextSchema>>;
1958
- extract(options: ExtractOptions): Promise<z$1.infer<typeof pageTextSchema>>;
1959
- extract(instruction: string, options?: ExtractOptions): Promise<z$1.infer<typeof defaultExtractSchema>>;
1960
- extract<T extends ZodTypeAny>(instruction: string, schema: T, options?: ExtractOptions): Promise<z$1.infer<T>>;
1981
+ extract(): Promise<z.infer<typeof pageTextSchema>>;
1982
+ extract(options: ExtractOptions): Promise<z.infer<typeof pageTextSchema>>;
1983
+ extract(instruction: string, options?: ExtractOptions): Promise<z.infer<typeof defaultExtractSchema>>;
1984
+ extract<T extends StagehandZodSchema>(instruction: string, schema: T, options?: ExtractOptions): Promise<InferStagehandSchema<T>>;
1961
1985
  /**
1962
1986
  * Run an "observe" instruction through the ObserveHandler.
1963
1987
  */
@@ -2029,14 +2053,14 @@ declare class AgentProvider {
2029
2053
  static getAgentProvider(modelName: string): AgentProviderType;
2030
2054
  }
2031
2055
 
2032
- declare function validateZodSchema(schema: z$1.ZodTypeAny, data: unknown): boolean;
2056
+ declare function validateZodSchema(schema: StagehandZodSchema, data: unknown): boolean;
2033
2057
  /**
2034
2058
  * Detects if the code is running in the Bun runtime environment.
2035
2059
  * @returns {boolean} True if running in Bun, false otherwise.
2036
2060
  */
2037
2061
  declare function isRunningInBun(): boolean;
2038
- declare function toGeminiSchema(zodSchema: z$1.ZodTypeAny): Schema;
2039
- declare function getZodType(schema: z$1.ZodTypeAny): string;
2062
+ declare function toGeminiSchema(zodSchema: StagehandZodSchema): Schema;
2063
+ declare function getZodType(schema: StagehandZodSchema): string;
2040
2064
  /**
2041
2065
  * Recursively traverses a given Zod schema, scanning for any fields of type `z.string().url()`.
2042
2066
  * For each such field, it replaces the `z.string().url()` with `z.number()`.
@@ -2050,7 +2074,7 @@ declare function getZodType(schema: z$1.ZodTypeAny): string;
2050
2074
  * 1. The updated Zod schema, with any `.url()` fields replaced by `z.number()`.
2051
2075
  * 2. An array of {@link ZodPathSegments} objects representing each replaced field, including the path segments.
2052
2076
  */
2053
- declare function transformSchema(schema: z$1.ZodTypeAny, currentPath: Array<string | number>): [z$1.ZodTypeAny, ZodPathSegments[]];
2077
+ declare function transformSchema(schema: StagehandZodSchema, currentPath: Array<string | number>): [StagehandZodSchema, ZodPathSegments[]];
2054
2078
  /**
2055
2079
  * Once we get the final extracted object that has numeric IDs in place of URLs,
2056
2080
  * use `injectUrls` to walk the object and replace numeric IDs
@@ -2079,6 +2103,7 @@ interface JsonSchemaProperty {
2079
2103
  minimum?: number;
2080
2104
  maximum?: number;
2081
2105
  description?: string;
2106
+ format?: string;
2082
2107
  }
2083
2108
  interface JsonSchema extends JsonSchemaProperty {
2084
2109
  type: string;
@@ -2119,4 +2144,4 @@ declare class V3Evaluator {
2119
2144
  private _evaluateWithMultipleScreenshots;
2120
2145
  }
2121
2146
 
2122
- export { type AISDKCustomProvider, type AISDKProvider, AISdkClient, AVAILABLE_CUA_MODELS, type ActOptions, type ActResult, type Action, type ActionExecutionResult, type AgentAction, type AgentConfig, type AgentExecuteOptions, type AgentExecutionOptions, type AgentHandlerOptions, type AgentInstance, type AgentModelConfig, AgentProvider, type AgentProviderType, type AgentResult, AgentScreenshotProviderError, type AgentType, AnnotatedScreenshotText, type AnthropicContentBlock, type AnthropicJsonSchemaObject, type AnthropicMessage, type AnthropicTextBlock, type AnthropicToolResult, type AnyPage, type AvailableCuaModel, type AvailableModel, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, type ChatCompletionOptions, type ChatMessage, type ChatMessageContent, type ChatMessageImageContent, type ChatMessageTextContent, type ClientOptions, type ComputerCallItem, ConnectionTimeoutError, type ConsoleListener, ConsoleMessage, ContentFrameNotFoundError, type CreateChatCompletionOptions, CreateChatCompletionResponseError, CuaModelRequiredError, ElementNotVisibleError, ExperimentalApiConflictError, ExperimentalNotConfiguredError, type ExtractOptions, type ExtractResult, type FunctionCallItem, HandlerNotInitializedError, type HistoryEntry, InvalidAISDKModelFormatError, type JsonSchema, type JsonSchemaProperty, LLMClient, type LLMResponse, LLMResponseError, type LLMTool, LOG_LEVEL_NAMES, type LoadState, type LocalBrowserLaunchOptions, type LogLevel, type LogLine, type Logger, MCPConnectionError, MissingEnvironmentVariableError, MissingLLMConfigurationError, type ModelConfiguration, type ModelProvider, type ObserveOptions, Page, PageNotFoundError, Response$1 as Response, ResponseBodyError, type ResponseInputItem, type ResponseItem, ResponseParseError, V3 as Stagehand, StagehandAPIError, StagehandAPIUnauthorizedError, StagehandClickError, StagehandDefaultError, StagehandDomProcessError, StagehandElementNotFoundError, StagehandEnvironmentError, StagehandError, StagehandEvalError, StagehandHttpError, StagehandIframeError, StagehandInitError, StagehandInvalidArgumentError, type StagehandMetrics, StagehandMissingArgumentError, StagehandNotInitializedError, StagehandResponseBodyError, StagehandResponseParseError, StagehandServerError, StagehandShadowRootMissingError, StagehandShadowSegmentEmptyError, StagehandShadowSegmentNotFoundError, TimeoutError, type ToolUseItem, UnsupportedAISDKModelProviderError, UnsupportedModelError, UnsupportedModelProviderError, V3, type V3Env, V3Evaluator, V3FunctionName, type V3Options, XPathResolutionError, ZodSchemaValidationError, connectToMCPServer, defaultExtractSchema, getZodType, injectUrls, isRunningInBun, jsonSchemaToZod, loadApiKeyFromEnv, modelToAgentProviderMap, pageTextSchema, providerEnvVarMap, toGeminiSchema, transformSchema, trimTrailingTextNode, validateZodSchema };
2147
+ export { type AISDKCustomProvider, type AISDKProvider, AISdkClient, AVAILABLE_CUA_MODELS, type ActOptions, type ActResult, type Action, type ActionExecutionResult, type AgentAction, type AgentConfig, type AgentExecuteOptions, type AgentExecutionOptions, type AgentHandlerOptions, type AgentInstance, type AgentModelConfig, AgentProvider, type AgentProviderType, type AgentResult, AgentScreenshotProviderError, type AgentType, AnnotatedScreenshotText, type AnthropicContentBlock, type AnthropicJsonSchemaObject, type AnthropicMessage, type AnthropicTextBlock, type AnthropicToolResult, type AnyPage, type AvailableCuaModel, type AvailableModel, BrowserbaseSessionNotFoundError, CaptchaTimeoutError, type ChatCompletionOptions, type ChatMessage, type ChatMessageContent, type ChatMessageImageContent, type ChatMessageTextContent, type ClientOptions, type ComputerCallItem, ConnectionTimeoutError, type ConsoleListener, ConsoleMessage, ContentFrameNotFoundError, type CreateChatCompletionOptions, CreateChatCompletionResponseError, CuaModelRequiredError, ElementNotVisibleError, ExperimentalApiConflictError, ExperimentalNotConfiguredError, type ExtractOptions, type ExtractResult, type FunctionCallItem, HandlerNotInitializedError, type HistoryEntry, type InferStagehandSchema, InvalidAISDKModelFormatError, type JsonSchema, type JsonSchemaDocument, type JsonSchemaProperty, LLMClient, type LLMParsedResponse, type LLMResponse, LLMResponseError, type LLMTool, type LLMUsage, LOG_LEVEL_NAMES, type LoadState, type LocalBrowserLaunchOptions, type LogLevel, type LogLine, type Logger, MCPConnectionError, MissingEnvironmentVariableError, MissingLLMConfigurationError, type ModelConfiguration, type ModelProvider, type ObserveOptions, Page, PageNotFoundError, Response$1 as Response, ResponseBodyError, type ResponseInputItem, type ResponseItem, ResponseParseError, V3 as Stagehand, StagehandAPIError, StagehandAPIUnauthorizedError, StagehandClickError, StagehandDefaultError, StagehandDomProcessError, StagehandElementNotFoundError, StagehandEnvironmentError, StagehandError, StagehandEvalError, StagehandHttpError, StagehandIframeError, StagehandInitError, StagehandInvalidArgumentError, type StagehandMetrics, StagehandMissingArgumentError, StagehandNotInitializedError, StagehandResponseBodyError, StagehandResponseParseError, StagehandServerError, StagehandShadowRootMissingError, StagehandShadowSegmentEmptyError, StagehandShadowSegmentNotFoundError, type StagehandZodObject, type StagehandZodSchema, TimeoutError, type ToolUseItem, UnsupportedAISDKModelProviderError, UnsupportedModelError, UnsupportedModelProviderError, V3, type V3Env, V3Evaluator, V3FunctionName, type V3Options, XPathResolutionError, ZodSchemaValidationError, connectToMCPServer, defaultExtractSchema, getZodType, injectUrls, isRunningInBun, isZod3Schema, isZod4Schema, jsonSchemaToZod, loadApiKeyFromEnv, modelToAgentProviderMap, pageTextSchema, providerEnvVarMap, toGeminiSchema, toJsonSchema, transformSchema, trimTrailingTextNode, validateZodSchema };