@browserbasehq/orca 3.2.0-preview.1 → 3.2.0-preview.3

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 (49) hide show
  1. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -0
  2. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js +2 -2
  3. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
  4. package/dist/cjs/lib/v3/agent/tools/{search.js → braveSearch.js} +1 -1
  5. package/dist/cjs/lib/v3/agent/tools/braveSearch.js.map +1 -0
  6. package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.d.ts +13 -0
  7. package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.js +70 -0
  8. package/dist/cjs/lib/v3/agent/tools/browserbaseSearch.js.map +1 -0
  9. package/dist/cjs/lib/v3/agent/tools/index.d.ts +14 -3
  10. package/dist/cjs/lib/v3/agent/tools/index.js +7 -3
  11. package/dist/cjs/lib/v3/agent/tools/index.js.map +1 -1
  12. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +13 -3
  13. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  14. package/dist/cjs/lib/v3/types/public/agent.d.ts +16 -2
  15. package/dist/cjs/lib/v3/types/public/agent.js.map +1 -1
  16. package/dist/cjs/lib/v3/v3.d.ts +5 -0
  17. package/dist/cjs/lib/v3/v3.js +7 -0
  18. package/dist/cjs/lib/v3/v3.js.map +1 -1
  19. package/dist/cjs/tests/unit/public-api/public-types.test.js.map +1 -1
  20. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -0
  21. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js +2 -2
  22. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
  23. package/dist/esm/lib/v3/agent/tools/{search.js → braveSearch.js} +1 -1
  24. package/dist/esm/lib/v3/agent/tools/braveSearch.js.map +1 -0
  25. package/dist/esm/lib/v3/agent/tools/browserbaseSearch.d.ts +13 -0
  26. package/dist/esm/lib/v3/agent/tools/browserbaseSearch.js +66 -0
  27. package/dist/esm/lib/v3/agent/tools/browserbaseSearch.js.map +1 -0
  28. package/dist/esm/lib/v3/agent/tools/index.d.ts +14 -3
  29. package/dist/esm/lib/v3/agent/tools/index.js +7 -3
  30. package/dist/esm/lib/v3/agent/tools/index.js.map +1 -1
  31. package/dist/esm/lib/v3/handlers/v3AgentHandler.js +14 -4
  32. package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  33. package/dist/esm/lib/v3/types/public/agent.d.ts +16 -2
  34. package/dist/esm/lib/v3/types/public/agent.js.map +1 -1
  35. package/dist/esm/lib/v3/v3.d.ts +5 -0
  36. package/dist/esm/lib/v3/v3.js +7 -0
  37. package/dist/esm/lib/v3/v3.js.map +1 -1
  38. package/dist/esm/tests/unit/public-api/public-types.test.js.map +1 -1
  39. package/package.json +1 -3
  40. package/dist/cjs/lib/v3/agent/tools/search.js.map +0 -1
  41. package/dist/cjs/tests/unit/rerender-missing-shadows.test.d.ts +0 -1
  42. package/dist/cjs/tests/unit/rerender-missing-shadows.test.js +0 -209
  43. package/dist/cjs/tests/unit/rerender-missing-shadows.test.js.map +0 -1
  44. package/dist/esm/lib/v3/agent/tools/search.js.map +0 -1
  45. package/dist/esm/tests/unit/rerender-missing-shadows.test.d.ts +0 -1
  46. package/dist/esm/tests/unit/rerender-missing-shadows.test.js +0 -207
  47. package/dist/esm/tests/unit/rerender-missing-shadows.test.js.map +0 -1
  48. /package/dist/cjs/lib/v3/agent/tools/{search.d.ts → braveSearch.d.ts} +0 -0
  49. /package/dist/esm/lib/v3/agent/tools/{search.d.ts → braveSearch.d.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"public-types.test.js","sourceRoot":"","sources":["../../../../../tests/unit/public-api/public-types.test.ts"],"names":[],"mappings":";;AAAA,mCAAoD;AA4GpD,IAA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AAa,EAA8B,CAAC;QAC3F,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expectTypeOf, it } from \"vitest\";\nimport * as Stagehand from \"@browserbasehq/stagehand\";\n\n// Type-level manifest of all expected exported types\n// Since these types don't exist at runtime, we currently need to manually add new publicly exported types\n// to this list ourselves - it's not automatically going to catch changes like our export-surface.test.ts does.\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ntype ExpectedExportedTypes = {\n // Types from model.ts\n AvailableModel: Stagehand.AvailableModel;\n AvailableCuaModel: Stagehand.AvailableCuaModel;\n ModelProvider: Stagehand.ModelProvider;\n ClientOptions: Stagehand.ClientOptions;\n ModelConfiguration: Stagehand.ModelConfiguration;\n AnthropicJsonSchemaObject: Stagehand.AnthropicJsonSchemaObject;\n AISDKProvider: Stagehand.AISDKProvider;\n AISDKCustomProvider: Stagehand.AISDKCustomProvider;\n LLMTool: Stagehand.LLMTool;\n // Types from methods.ts\n ActOptions: Stagehand.ActOptions;\n ActResult: Stagehand.ActResult;\n ExtractResult: Stagehand.ExtractResult<Stagehand.StagehandZodSchema>;\n Action: Stagehand.Action;\n HistoryEntry: Stagehand.HistoryEntry;\n ExtractOptions: Stagehand.ExtractOptions;\n ObserveOptions: Stagehand.ObserveOptions;\n ObserveResult: Stagehand.ObserveResult;\n V3FunctionName: Stagehand.V3FunctionName;\n // Types from agent.ts\n Tool: Stagehand.Tool;\n AgentAction: Stagehand.AgentAction;\n AgentResult: Stagehand.AgentResult;\n AgentExecuteOptions: Stagehand.AgentExecuteOptions;\n AgentType: Stagehand.AgentType;\n AgentExecutionOptions: Stagehand.AgentExecutionOptions<Stagehand.AgentExecuteOptions>;\n AgentHandlerOptions: Stagehand.AgentHandlerOptions;\n ActionExecutionResult: Stagehand.ActionExecutionResult;\n ToolUseItem: Stagehand.ToolUseItem;\n AnthropicMessage: Stagehand.AnthropicMessage;\n AnthropicContentBlock: Stagehand.AnthropicContentBlock;\n AnthropicTextBlock: Stagehand.AnthropicTextBlock;\n AnthropicToolResult: Stagehand.AnthropicToolResult;\n ResponseItem: Stagehand.ResponseItem;\n ComputerCallItem: Stagehand.ComputerCallItem;\n FunctionCallItem: Stagehand.FunctionCallItem;\n ResponseInputItem: Stagehand.ResponseInputItem;\n AgentInstance: Stagehand.AgentInstance;\n AgentProviderType: Stagehand.AgentProviderType;\n AgentModelConfig: Stagehand.AgentModelConfig;\n AgentConfig: Stagehand.AgentConfig;\n AgentToolMode: Stagehand.AgentToolMode;\n VariableValue: Stagehand.VariableValue;\n Variables: Stagehand.Variables;\n AgentCallbacks: Stagehand.AgentCallbacks;\n AgentExecuteCallbacks: Stagehand.AgentExecuteCallbacks;\n AgentStreamCallbacks: Stagehand.AgentStreamCallbacks;\n AgentExecuteOptionsBase: Stagehand.AgentExecuteOptionsBase;\n AgentStreamExecuteOptions: Stagehand.AgentStreamExecuteOptions;\n ModelMessage: Stagehand.ModelMessage;\n // Types from agent/tools\n AgentTools: Stagehand.AgentTools;\n AgentToolTypesMap: Stagehand.AgentToolTypesMap;\n AgentUITools: Stagehand.AgentUITools;\n AgentToolCall: Stagehand.AgentToolCall;\n AgentToolResult: Stagehand.AgentToolResult;\n // Types from logs.ts\n LogLevel: Stagehand.LogLevel;\n LogLine: Stagehand.LogLine;\n Logger: Stagehand.Logger;\n // Types from metrics.ts\n StagehandMetrics: Stagehand.StagehandMetrics;\n // Types from options.ts\n V3Env: Stagehand.V3Env;\n LocalBrowserLaunchOptions: Stagehand.LocalBrowserLaunchOptions;\n V3Options: Stagehand.V3Options;\n // Types from page.ts\n AnyPage: Stagehand.AnyPage;\n Page: Stagehand.Page;\n PlaywrightPage: Stagehand.PlaywrightPage;\n PatchrightPage: Stagehand.PatchrightPage;\n PuppeteerPage: Stagehand.PuppeteerPage;\n ConsoleListener: Stagehand.ConsoleListener;\n LoadState: Stagehand.LoadState;\n // Types from LLMClient.ts\n ChatMessage: Stagehand.ChatMessage;\n ChatMessageContent: Stagehand.ChatMessageContent;\n ChatMessageImageContent: Stagehand.ChatMessageImageContent;\n ChatMessageTextContent: Stagehand.ChatMessageTextContent;\n ChatCompletionOptions: Stagehand.ChatCompletionOptions;\n LLMResponse: Stagehand.LLMResponse;\n CreateChatCompletionOptions: Stagehand.CreateChatCompletionOptions;\n LLMUsage: Stagehand.LLMUsage;\n LLMParsedResponse: Stagehand.LLMParsedResponse<Record<string, unknown>>;\n // Types from zodCompat.ts\n StagehandZodSchema: Stagehand.StagehandZodSchema;\n StagehandZodObject: Stagehand.StagehandZodObject;\n InferStagehandSchema: Stagehand.InferStagehandSchema<Stagehand.StagehandZodSchema>;\n JsonSchemaDocument: Stagehand.JsonSchemaDocument;\n // Types from utils.ts\n JsonSchema: Stagehand.JsonSchema;\n JsonSchemaProperty: Stagehand.JsonSchemaProperty;\n // Types from cookies.ts\n Cookie: Stagehand.Cookie;\n CookieParam: Stagehand.CookieParam;\n ClearCookieOptions: Stagehand.ClearCookieOptions;\n};\n\ndescribe(\"Stagehand public API types\", () => {\n describe(\"AnyPage\", () => {\n type ExpectedAnyPage =\n | Stagehand.PlaywrightPage\n | Stagehand.PuppeteerPage\n | Stagehand.PatchrightPage\n | Stagehand.Page;\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.AnyPage>().toEqualTypeOf<ExpectedAnyPage>();\n });\n });\n\n describe(\"ActOptions\", () => {\n type ExpectedActOptions = {\n model?: Stagehand.ModelConfiguration;\n variables?: Stagehand.Variables;\n timeout?: number;\n page?: Stagehand.AnyPage;\n serverCache?: boolean;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.ActOptions>().toEqualTypeOf<ExpectedActOptions>();\n });\n });\n\n describe(\"ActResult\", () => {\n type ExpectedActResult = {\n success: boolean;\n message: string;\n actionDescription: string;\n actions: Stagehand.Action[];\n cacheStatus?: \"HIT\" | \"MISS\";\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.ActResult>().toEqualTypeOf<ExpectedActResult>();\n });\n });\n\n describe(\"ExtractOptions\", () => {\n type ExpectedExtractOptions = {\n model?: Stagehand.ModelConfiguration;\n timeout?: number;\n selector?: string;\n page?: Stagehand.AnyPage;\n serverCache?: boolean;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.ExtractOptions>().toEqualTypeOf<ExpectedExtractOptions>();\n });\n });\n\n describe(\"ObserveOptions\", () => {\n type ExpectedObserveOptions = {\n model?: Stagehand.ModelConfiguration;\n timeout?: number;\n selector?: string;\n page?: Stagehand.AnyPage;\n serverCache?: boolean;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.ObserveOptions>().toEqualTypeOf<ExpectedObserveOptions>();\n });\n });\n\n describe(\"ObserveResult\", () => {\n it(\"is an Action array with optional cacheStatus\", () => {\n expectTypeOf<Stagehand.ObserveResult>().toExtend<Stagehand.Action[]>();\n expectTypeOf<Stagehand.ObserveResult[\"cacheStatus\"]>().toEqualTypeOf<\n \"HIT\" | \"MISS\" | undefined\n >();\n });\n });\n\n describe(\"Action\", () => {\n type ExpectedAction = {\n selector: string;\n description: string;\n method?: string;\n arguments?: string[];\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.Action>().toEqualTypeOf<ExpectedAction>();\n });\n });\n\n describe(\"AgentAction\", () => {\n // AgentAction is a separate type from Action, not an extension\n // It has additional fields like type, reasoning, taskCompleted, etc.\n it(\"has type field\", () => {\n type TestAction = { type: string } & Stagehand.AgentAction;\n expectTypeOf<TestAction[\"type\"]>().toEqualTypeOf<string>();\n });\n });\n\n describe(\"AgentExecuteOptions\", () => {\n type ExpectedAgentExecuteOptions = {\n instruction: string;\n maxSteps?: number;\n page?: Stagehand.AnyPage;\n highlightCursor?: boolean;\n messages?: Stagehand.ModelMessage[];\n signal?: AbortSignal;\n excludeTools?: string[];\n output?: Stagehand.StagehandZodObject;\n callbacks?: Stagehand.AgentExecuteCallbacks;\n variables?: Stagehand.Variables;\n toolTimeout?: number;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.AgentExecuteOptions>().toEqualTypeOf<ExpectedAgentExecuteOptions>();\n });\n });\n\n describe(\"AgentStreamExecuteOptions\", () => {\n type ExpectedAgentStreamExecuteOptions = {\n instruction: string;\n maxSteps?: number;\n page?: Stagehand.AnyPage;\n highlightCursor?: boolean;\n messages?: Stagehand.ModelMessage[];\n signal?: AbortSignal;\n excludeTools?: string[];\n output?: Stagehand.StagehandZodObject;\n callbacks?: Stagehand.AgentStreamCallbacks;\n variables?: Stagehand.Variables;\n toolTimeout?: number;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.AgentStreamExecuteOptions>().toEqualTypeOf<ExpectedAgentStreamExecuteOptions>();\n });\n });\n\n describe(\"AgentExecutionOptions\", () => {\n type ExpectedAgentExecutionOptions<T = Stagehand.AgentExecuteOptions> = {\n options: T;\n logger: (message: Stagehand.LogLine) => void;\n retries?: number;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<\n Stagehand.AgentExecutionOptions<Stagehand.AgentExecuteOptions>\n >().toEqualTypeOf<\n ExpectedAgentExecutionOptions<Stagehand.AgentExecuteOptions>\n >();\n });\n });\n\n describe(\"AgentResult\", () => {\n type ExpectedAgentResult = {\n success: boolean;\n message: string;\n actions: Stagehand.AgentAction[];\n completed: boolean;\n metadata?: Record<string, unknown>;\n usage?: {\n input_tokens: number;\n output_tokens: number;\n reasoning_tokens?: number;\n cached_input_tokens?: number;\n inference_time_ms: number;\n };\n messages?: Stagehand.ModelMessage[];\n output?: Record<string, unknown>;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.AgentResult>().toEqualTypeOf<ExpectedAgentResult>();\n });\n });\n\n describe(\"AgentConfig\", () => {\n type ExpectedAgentConfig = {\n systemPrompt?: string;\n integrations?: (unknown | string)[];\n tools?: unknown;\n cua?: boolean;\n model?: string | Stagehand.AgentModelConfig<string>;\n executionModel?: string | Stagehand.AgentModelConfig<string>;\n stream?: boolean;\n mode?: Stagehand.AgentToolMode;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.AgentConfig>().toExtend<ExpectedAgentConfig>();\n });\n });\n\n describe(\"AgentToolMode\", () => {\n type ExpectedAgentToolMode = \"dom\" | \"hybrid\" | \"cua\";\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.AgentToolMode>().toEqualTypeOf<ExpectedAgentToolMode>();\n });\n });\n\n describe(\"HistoryEntry\", () => {\n type ExpectedHistoryEntry = {\n method: \"act\" | \"extract\" | \"observe\" | \"navigate\" | \"agent\";\n parameters: unknown;\n result: unknown;\n timestamp: string;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.HistoryEntry>().toEqualTypeOf<ExpectedHistoryEntry>();\n });\n });\n\n describe(\"Cookie\", () => {\n type ExpectedCookie = {\n name: string;\n value: string;\n domain: string;\n path: string;\n expires: number;\n httpOnly: boolean;\n secure: boolean;\n sameSite: \"Strict\" | \"Lax\" | \"None\";\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.Cookie>().toEqualTypeOf<ExpectedCookie>();\n });\n });\n\n describe(\"CookieParam\", () => {\n type ExpectedCookieParam = {\n name: string;\n value: string;\n url?: string;\n domain?: string;\n path?: string;\n expires?: number;\n httpOnly?: boolean;\n secure?: boolean;\n sameSite?: \"Strict\" | \"Lax\" | \"None\";\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.CookieParam>().toEqualTypeOf<ExpectedCookieParam>();\n });\n });\n\n describe(\"ClearCookieOptions\", () => {\n type ExpectedClearCookieOptions = {\n name?: string | RegExp;\n domain?: string | RegExp;\n path?: string | RegExp;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.ClearCookieOptions>().toEqualTypeOf<ExpectedClearCookieOptions>();\n });\n });\n});\n"]}
1
+ {"version":3,"file":"public-types.test.js","sourceRoot":"","sources":["../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A,WAAE,EAAC,6BAA6B,EAAE,GAAG,EAAE;YACrC,IAAA,qBAAY,GAAgC,CAAC,aAAa,EAA8B,CAAC;QAC3F,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, expectTypeOf, it } from \"vitest\";\nimport * as Stagehand from \"@browserbasehq/stagehand\";\n\n// Type-level manifest of all expected exported types\n// Since these types don't exist at runtime, we currently need to manually add new publicly exported types\n// to this list ourselves - it's not automatically going to catch changes like our export-surface.test.ts does.\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ntype ExpectedExportedTypes = {\n // Types from model.ts\n AvailableModel: Stagehand.AvailableModel;\n AvailableCuaModel: Stagehand.AvailableCuaModel;\n ModelProvider: Stagehand.ModelProvider;\n ClientOptions: Stagehand.ClientOptions;\n ModelConfiguration: Stagehand.ModelConfiguration;\n AnthropicJsonSchemaObject: Stagehand.AnthropicJsonSchemaObject;\n AISDKProvider: Stagehand.AISDKProvider;\n AISDKCustomProvider: Stagehand.AISDKCustomProvider;\n LLMTool: Stagehand.LLMTool;\n // Types from methods.ts\n ActOptions: Stagehand.ActOptions;\n ActResult: Stagehand.ActResult;\n ExtractResult: Stagehand.ExtractResult<Stagehand.StagehandZodSchema>;\n Action: Stagehand.Action;\n HistoryEntry: Stagehand.HistoryEntry;\n ExtractOptions: Stagehand.ExtractOptions;\n ObserveOptions: Stagehand.ObserveOptions;\n ObserveResult: Stagehand.ObserveResult;\n V3FunctionName: Stagehand.V3FunctionName;\n // Types from agent.ts\n Tool: Stagehand.Tool;\n AgentAction: Stagehand.AgentAction;\n AgentResult: Stagehand.AgentResult;\n AgentExecuteOptions: Stagehand.AgentExecuteOptions;\n AgentType: Stagehand.AgentType;\n AgentExecutionOptions: Stagehand.AgentExecutionOptions<Stagehand.AgentExecuteOptions>;\n AgentHandlerOptions: Stagehand.AgentHandlerOptions;\n ActionExecutionResult: Stagehand.ActionExecutionResult;\n ToolUseItem: Stagehand.ToolUseItem;\n AnthropicMessage: Stagehand.AnthropicMessage;\n AnthropicContentBlock: Stagehand.AnthropicContentBlock;\n AnthropicTextBlock: Stagehand.AnthropicTextBlock;\n AnthropicToolResult: Stagehand.AnthropicToolResult;\n ResponseItem: Stagehand.ResponseItem;\n ComputerCallItem: Stagehand.ComputerCallItem;\n FunctionCallItem: Stagehand.FunctionCallItem;\n ResponseInputItem: Stagehand.ResponseInputItem;\n AgentInstance: Stagehand.AgentInstance;\n AgentProviderType: Stagehand.AgentProviderType;\n AgentModelConfig: Stagehand.AgentModelConfig;\n AgentConfig: Stagehand.AgentConfig;\n AgentToolMode: Stagehand.AgentToolMode;\n VariableValue: Stagehand.VariableValue;\n Variables: Stagehand.Variables;\n AgentCallbacks: Stagehand.AgentCallbacks;\n AgentExecuteCallbacks: Stagehand.AgentExecuteCallbacks;\n AgentStreamCallbacks: Stagehand.AgentStreamCallbacks;\n AgentExecuteOptionsBase: Stagehand.AgentExecuteOptionsBase;\n AgentStreamExecuteOptions: Stagehand.AgentStreamExecuteOptions;\n ModelMessage: Stagehand.ModelMessage;\n // Types from agent/tools\n AgentTools: Stagehand.AgentTools;\n AgentToolTypesMap: Stagehand.AgentToolTypesMap;\n AgentUITools: Stagehand.AgentUITools;\n AgentToolCall: Stagehand.AgentToolCall;\n AgentToolResult: Stagehand.AgentToolResult;\n // Types from logs.ts\n LogLevel: Stagehand.LogLevel;\n LogLine: Stagehand.LogLine;\n Logger: Stagehand.Logger;\n // Types from metrics.ts\n StagehandMetrics: Stagehand.StagehandMetrics;\n // Types from options.ts\n V3Env: Stagehand.V3Env;\n LocalBrowserLaunchOptions: Stagehand.LocalBrowserLaunchOptions;\n V3Options: Stagehand.V3Options;\n // Types from page.ts\n AnyPage: Stagehand.AnyPage;\n Page: Stagehand.Page;\n PlaywrightPage: Stagehand.PlaywrightPage;\n PatchrightPage: Stagehand.PatchrightPage;\n PuppeteerPage: Stagehand.PuppeteerPage;\n ConsoleListener: Stagehand.ConsoleListener;\n LoadState: Stagehand.LoadState;\n // Types from LLMClient.ts\n ChatMessage: Stagehand.ChatMessage;\n ChatMessageContent: Stagehand.ChatMessageContent;\n ChatMessageImageContent: Stagehand.ChatMessageImageContent;\n ChatMessageTextContent: Stagehand.ChatMessageTextContent;\n ChatCompletionOptions: Stagehand.ChatCompletionOptions;\n LLMResponse: Stagehand.LLMResponse;\n CreateChatCompletionOptions: Stagehand.CreateChatCompletionOptions;\n LLMUsage: Stagehand.LLMUsage;\n LLMParsedResponse: Stagehand.LLMParsedResponse<Record<string, unknown>>;\n // Types from zodCompat.ts\n StagehandZodSchema: Stagehand.StagehandZodSchema;\n StagehandZodObject: Stagehand.StagehandZodObject;\n InferStagehandSchema: Stagehand.InferStagehandSchema<Stagehand.StagehandZodSchema>;\n JsonSchemaDocument: Stagehand.JsonSchemaDocument;\n // Types from utils.ts\n JsonSchema: Stagehand.JsonSchema;\n JsonSchemaProperty: Stagehand.JsonSchemaProperty;\n // Types from cookies.ts\n Cookie: Stagehand.Cookie;\n CookieParam: Stagehand.CookieParam;\n ClearCookieOptions: Stagehand.ClearCookieOptions;\n};\n\ndescribe(\"Stagehand public API types\", () => {\n describe(\"AnyPage\", () => {\n type ExpectedAnyPage =\n | Stagehand.PlaywrightPage\n | Stagehand.PuppeteerPage\n | Stagehand.PatchrightPage\n | Stagehand.Page;\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.AnyPage>().toEqualTypeOf<ExpectedAnyPage>();\n });\n });\n\n describe(\"ActOptions\", () => {\n type ExpectedActOptions = {\n model?: Stagehand.ModelConfiguration;\n variables?: Stagehand.Variables;\n timeout?: number;\n page?: Stagehand.AnyPage;\n serverCache?: boolean;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.ActOptions>().toEqualTypeOf<ExpectedActOptions>();\n });\n });\n\n describe(\"ActResult\", () => {\n type ExpectedActResult = {\n success: boolean;\n message: string;\n actionDescription: string;\n actions: Stagehand.Action[];\n cacheStatus?: \"HIT\" | \"MISS\";\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.ActResult>().toEqualTypeOf<ExpectedActResult>();\n });\n });\n\n describe(\"ExtractOptions\", () => {\n type ExpectedExtractOptions = {\n model?: Stagehand.ModelConfiguration;\n timeout?: number;\n selector?: string;\n page?: Stagehand.AnyPage;\n serverCache?: boolean;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.ExtractOptions>().toEqualTypeOf<ExpectedExtractOptions>();\n });\n });\n\n describe(\"ObserveOptions\", () => {\n type ExpectedObserveOptions = {\n model?: Stagehand.ModelConfiguration;\n timeout?: number;\n selector?: string;\n page?: Stagehand.AnyPage;\n serverCache?: boolean;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.ObserveOptions>().toEqualTypeOf<ExpectedObserveOptions>();\n });\n });\n\n describe(\"ObserveResult\", () => {\n it(\"is an Action array with optional cacheStatus\", () => {\n expectTypeOf<Stagehand.ObserveResult>().toExtend<Stagehand.Action[]>();\n expectTypeOf<Stagehand.ObserveResult[\"cacheStatus\"]>().toEqualTypeOf<\n \"HIT\" | \"MISS\" | undefined\n >();\n });\n });\n\n describe(\"Action\", () => {\n type ExpectedAction = {\n selector: string;\n description: string;\n method?: string;\n arguments?: string[];\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.Action>().toEqualTypeOf<ExpectedAction>();\n });\n });\n\n describe(\"AgentAction\", () => {\n // AgentAction is a separate type from Action, not an extension\n // It has additional fields like type, reasoning, taskCompleted, etc.\n it(\"has type field\", () => {\n type TestAction = { type: string } & Stagehand.AgentAction;\n expectTypeOf<TestAction[\"type\"]>().toEqualTypeOf<string>();\n });\n });\n\n describe(\"AgentExecuteOptions\", () => {\n type ExpectedAgentExecuteOptions = {\n instruction: string;\n maxSteps?: number;\n page?: Stagehand.AnyPage;\n highlightCursor?: boolean;\n messages?: Stagehand.ModelMessage[];\n signal?: AbortSignal;\n excludeTools?: string[];\n output?: Stagehand.StagehandZodObject;\n callbacks?: Stagehand.AgentExecuteCallbacks;\n variables?: Stagehand.Variables;\n toolTimeout?: number;\n useSearch?: boolean;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.AgentExecuteOptions>().toEqualTypeOf<ExpectedAgentExecuteOptions>();\n });\n });\n\n describe(\"AgentStreamExecuteOptions\", () => {\n type ExpectedAgentStreamExecuteOptions = {\n instruction: string;\n maxSteps?: number;\n page?: Stagehand.AnyPage;\n highlightCursor?: boolean;\n messages?: Stagehand.ModelMessage[];\n signal?: AbortSignal;\n excludeTools?: string[];\n output?: Stagehand.StagehandZodObject;\n callbacks?: Stagehand.AgentStreamCallbacks;\n variables?: Stagehand.Variables;\n toolTimeout?: number;\n useSearch?: boolean;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.AgentStreamExecuteOptions>().toEqualTypeOf<ExpectedAgentStreamExecuteOptions>();\n });\n });\n\n describe(\"AgentExecutionOptions\", () => {\n type ExpectedAgentExecutionOptions<T = Stagehand.AgentExecuteOptions> = {\n options: T;\n logger: (message: Stagehand.LogLine) => void;\n retries?: number;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<\n Stagehand.AgentExecutionOptions<Stagehand.AgentExecuteOptions>\n >().toEqualTypeOf<\n ExpectedAgentExecutionOptions<Stagehand.AgentExecuteOptions>\n >();\n });\n });\n\n describe(\"AgentResult\", () => {\n type ExpectedAgentResult = {\n success: boolean;\n message: string;\n actions: Stagehand.AgentAction[];\n completed: boolean;\n metadata?: Record<string, unknown>;\n usage?: {\n input_tokens: number;\n output_tokens: number;\n reasoning_tokens?: number;\n cached_input_tokens?: number;\n inference_time_ms: number;\n };\n messages?: Stagehand.ModelMessage[];\n output?: Record<string, unknown>;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.AgentResult>().toEqualTypeOf<ExpectedAgentResult>();\n });\n });\n\n describe(\"AgentConfig\", () => {\n type ExpectedAgentConfig = {\n systemPrompt?: string;\n integrations?: (unknown | string)[];\n tools?: unknown;\n cua?: boolean;\n model?: string | Stagehand.AgentModelConfig<string>;\n executionModel?: string | Stagehand.AgentModelConfig<string>;\n stream?: boolean;\n mode?: Stagehand.AgentToolMode;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.AgentConfig>().toExtend<ExpectedAgentConfig>();\n });\n });\n\n describe(\"AgentToolMode\", () => {\n type ExpectedAgentToolMode = \"dom\" | \"hybrid\" | \"cua\";\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.AgentToolMode>().toEqualTypeOf<ExpectedAgentToolMode>();\n });\n });\n\n describe(\"HistoryEntry\", () => {\n type ExpectedHistoryEntry = {\n method: \"act\" | \"extract\" | \"observe\" | \"navigate\" | \"agent\";\n parameters: unknown;\n result: unknown;\n timestamp: string;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.HistoryEntry>().toEqualTypeOf<ExpectedHistoryEntry>();\n });\n });\n\n describe(\"Cookie\", () => {\n type ExpectedCookie = {\n name: string;\n value: string;\n domain: string;\n path: string;\n expires: number;\n httpOnly: boolean;\n secure: boolean;\n sameSite: \"Strict\" | \"Lax\" | \"None\";\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.Cookie>().toEqualTypeOf<ExpectedCookie>();\n });\n });\n\n describe(\"CookieParam\", () => {\n type ExpectedCookieParam = {\n name: string;\n value: string;\n url?: string;\n domain?: string;\n path?: string;\n expires?: number;\n httpOnly?: boolean;\n secure?: boolean;\n sameSite?: \"Strict\" | \"Lax\" | \"None\";\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.CookieParam>().toEqualTypeOf<ExpectedCookieParam>();\n });\n });\n\n describe(\"ClearCookieOptions\", () => {\n type ExpectedClearCookieOptions = {\n name?: string | RegExp;\n domain?: string | RegExp;\n path?: string | RegExp;\n };\n\n it(\"matches expected type shape\", () => {\n expectTypeOf<Stagehand.ClearCookieOptions>().toEqualTypeOf<ExpectedClearCookieOptions>();\n });\n });\n});\n"]}
@@ -10,5 +10,7 @@ export interface AgentSystemPromptOptions {
10
10
  excludeTools?: string[];
11
11
  /** Variables available to the agent for use in act/type tools */
12
12
  variables?: Variables;
13
+ /** Whether the search tool is enabled for this execution */
14
+ useSearch?: boolean;
13
15
  }
14
16
  export declare function buildAgentSystemPrompt(options: AgentSystemPromptOptions): string;
@@ -71,12 +71,12 @@ function buildToolsSection(isHybridMode, hasSearch, excludeTools) {
71
71
  return `<tools>\n${toolLines}\n </tools>`;
72
72
  }
73
73
  export function buildAgentSystemPrompt(options) {
74
- const { url, executionInstruction, mode, systemInstructions, isBrowserbase = false, excludeTools, variables, } = options;
74
+ const { url, executionInstruction, mode, systemInstructions, isBrowserbase = false, excludeTools, variables, useSearch = false, } = options;
75
75
  const localeDate = new Date().toLocaleDateString();
76
76
  const isoDate = new Date().toISOString();
77
77
  const cdata = (text) => `<![CDATA[${text}]]>`;
78
78
  const isHybridMode = mode === "hybrid";
79
- const hasSearch = Boolean(process.env.BRAVE_API_KEY);
79
+ const hasSearch = useSearch || Boolean(process.env.BRAVE_API_KEY);
80
80
  // Tools section differs based on mode and excluded tools
81
81
  const toolsSection = buildToolsSection(isHybridMode, hasSearch, excludeTools);
82
82
  // Strategy differs based on mode
@@ -1 +1 @@
1
- {"version":3,"file":"agentSystemPrompt.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/prompts/agentSystemPrompt.ts"],"names":[],"mappings":"AA0BA,SAAS,iBAAiB,CACxB,YAAqB,EACrB,SAAkB,EAClB,YAAuB;IAEvB,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;IAE/C,MAAM,WAAW,GAAqB;QACpC;YACE,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,4DAA4D;SAC1E;QACD;YACE,IAAI,EAAE,UAAU;YAChB,WAAW,EACT,+DAA+D;SAClE;QACD;YACE,IAAI,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AC,CAAC,gGAAgG;QAClG,CAAC,CAAC,8EAA8E,CAAC;IACnF,MAAM,gBAAgB,GAAG,YAAY;QACnC,CAAC,CAAC;;aAEO,iBAAiB;;MAExB,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;aACxB,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE;YACjB,MAAM,WAAW,GACf,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,IAAI,CAAC;gBACjD,CAAC,CAAC,CAAC,CAAC,WAAW;gBACf,CAAC,CAAC,SAAS,CAAC;YAChB,OAAO,WAAW;gBAChB,CAAC,CAAC,mBAAmB,IAAI,KAAK,WAAW,aAAa;gBACtD,CAAC,CAAC,mBAAmB,IAAI,MAAM,CAAC;QACpC,CAAC,CAAC;aACD,IAAI,CAAC,QAAQ,CAAC;eACN;QACX,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO;;IAEL,uBAAuB;YACf,KAAK,CAAC,oBAAoB,CAAC;iCACN,OAAO,KAAK,UAAU;;;;2DAII,GAAG;;;;;;;;;;;;IAY1D,yBAAyB;;;MAGvB,SAAS,CAAC,CAAC,CAAC,mFAAmF,CAAC,CAAC,CAAC,EAAE;;IAEtG,YAAY;;MAEV,eAAe;MACf,mBAAmB;;IAErB,iBAAiB;IACjB,gBAAgB;;;;;;;;UAQV,CAAC;AACX,CAAC","sourcesContent":["import type { AgentToolMode, Variables } from \"../../types/public/agent.js\";\n\nexport interface AgentSystemPromptOptions {\n url: string;\n executionInstruction: string;\n mode: AgentToolMode;\n systemInstructions?: string;\n /** Whether running on Browserbase (enables captcha solver messaging) */\n isBrowserbase?: boolean;\n /** Tools to exclude from the system prompt */\n excludeTools?: string[];\n /** Variables available to the agent for use in act/type tools */\n variables?: Variables;\n}\n\n/**\n * Builds the system prompt for the agent based on the tool mode.\n *\n * @param options - The prompt configuration options\n * @returns The formatted system prompt string\n */\ninterface ToolDefinition {\n name: string;\n description: string;\n}\n\nfunction buildToolsSection(\n isHybridMode: boolean,\n hasSearch: boolean,\n excludeTools?: string[],\n): string {\n const excludeSet = new Set(excludeTools ?? []);\n\n const hybridTools: ToolDefinition[] = [\n {\n name: \"screenshot\",\n description: \"Take a compressed JPEG screenshot for quick visual context\",\n },\n {\n name: \"ariaTree\",\n description:\n \"Get an accessibility (ARIA) hybrid tree for full page context\",\n },\n {\n name: \"click\",\n description:\n \"Click on an element (PREFERRED - more reliable when element is visible in viewport)\",\n },\n {\n name: \"type\",\n description:\n \"Type text into an element (PREFERRED - more reliable when element is visible in viewport)\",\n },\n {\n name: \"act\",\n description:\n \"Perform a specific atomic action (click, type, etc.) - ONLY use when element is in ariaTree but NOT visible in screenshot. Less reliable but can interact with out-of-viewport elements.\",\n },\n { name: \"dragAndDrop\", description: \"Drag and drop an element\" },\n { name: \"clickAndHold\", description: \"Click and hold on an element\" },\n { name: \"keys\", description: \"Press a keyboard key\" },\n {\n name: \"fillFormVision\",\n description: \"Fill out a form using coordinates\",\n },\n { name: \"think\", description: \"Think about the task\" },\n { name: \"extract\", description: \"Extract structured data\" },\n { name: \"goto\", description: \"Navigate to a URL\" },\n { name: \"wait\", description: \"Wait for a specified time\" },\n { name: \"navback\", description: \"Navigate back in browser history\" },\n { name: \"scroll\", description: \"Scroll the page x pixels up or down\" },\n ];\n\n const domTools: ToolDefinition[] = [\n {\n name: \"screenshot\",\n description: \"Take a compressed JPEG screenshot for quick visual context\",\n },\n {\n name: \"ariaTree\",\n description:\n \"Get an accessibility (ARIA) hybrid tree for full page context\",\n },\n {\n name: \"act\",\n description: \"Perform a specific atomic action (click, type)\",\n },\n { name: \"keys\", description: \"Press a keyboard key\" },\n { name: \"fillForm\", description: \"Fill out a form\" },\n { name: \"think\", description: \"Think about the task\" },\n { name: \"extract\", description: \"Extract structured data\" },\n { name: \"goto\", description: \"Navigate to a URL\" },\n { name: \"wait\", description: \"Wait for a specified time\" },\n { name: \"navback\", description: \"Navigate back in browser history\" },\n { name: \"scroll\", description: \"Scroll the page x pixels up or down\" },\n ];\n\n const baseTools = isHybridMode ? hybridTools : domTools;\n\n if (hasSearch) {\n baseTools.push({\n name: \"search\",\n description:\n \"Perform a web search and return results. Prefer this over navigating to Google and searching within the page for reliability and efficiency.\",\n });\n }\n\n const filteredTools = baseTools.filter((tool) => !excludeSet.has(tool.name));\n\n const toolLines = filteredTools\n .map((tool) => ` <tool name=\"${tool.name}\">${tool.description}</tool>`)\n .join(\"\\n\");\n\n return `<tools>\\n${toolLines}\\n </tools>`;\n}\n\nexport function buildAgentSystemPrompt(\n options: AgentSystemPromptOptions,\n): string {\n const {\n url,\n executionInstruction,\n mode,\n systemInstructions,\n isBrowserbase = false,\n excludeTools,\n variables,\n } = options;\n const localeDate = new Date().toLocaleDateString();\n const isoDate = new Date().toISOString();\n const cdata = (text: string) => `<![CDATA[${text}]]>`;\n\n const isHybridMode = mode === \"hybrid\";\n const hasSearch = Boolean(process.env.BRAVE_API_KEY);\n\n // Tools section differs based on mode and excluded tools\n const toolsSection = buildToolsSection(isHybridMode, hasSearch, excludeTools);\n\n // Strategy differs based on mode\n const strategyItems = isHybridMode\n ? [\n `<item>Tool selection priority: Use specific tools (click, type) when elements are visible in viewport for maximum reliability.</item>`,\n `<item>Always use screenshot to get proper grounding of the coordinates you want to type/click into.</item>`,\n `<item>When interacting with an input, always use the type tool to type into the input, over clicking and then typing into it.</item>`,\n `<item>Use ariaTree as a secondary tool when elements aren't visible in screenshot or to get full page context.</item>`,\n `<item>Only use act when element is in ariaTree but NOT visible in screenshot.</item>`,\n ]\n : [\n `<item>Tool selection priority: Use act tool for all clicking and typing on a page.</item>`,\n `<item>Always check ariaTree first to understand full page content without scrolling - it shows all elements including those below the fold.</item>`,\n `<item>When interacting with an input, always use the act tool to type into the input, over clicking and then typing.</item>`,\n `<item>If an element is present in the ariaTree, use act to interact with it directly - this eliminates the need to scroll.</item>`,\n `<item>Use screenshot for visual confirmation when needed, but rely primarily on ariaTree for element detection.</item>`,\n ];\n\n const strategySection = strategyItems.join(\"\\n \");\n\n const commonStrategyItems = `\n <item>CRITICAL: Use extract ONLY when the task explicitly requires structured data output (e.g., \"get job listings\", \"extract product details\"). For reading page content or understanding elements, always use ${isHybridMode ? \"screenshot or ariaTree\" : \"ariaTree\"} instead - it's faster and more reliable.</item>\n <item>Keep actions atomic and verify outcomes before proceeding.</item>\n <item>For each action, provide clear reasoning about why you're taking that step.</item>\n <item>When you need to input text that could be entered character-by-character or through multiple separate inputs, prefer using the keys tool to type the entire sequence at once. This is more efficient for scenarios like verification codes split across multiple fields, or when virtual keyboards are present but direct typing would be faster.</item>\n `;\n\n // Page understanding protocol differs based on mode\n const pageUnderstandingProtocol = isHybridMode\n ? `<page_understanding_protocol>\n <step_1>\n <title>UNDERSTAND THE PAGE</title>\n <primary_tool>\n <name>screenshot</name>\n <usage>Visual confirmation when needed. Ideally after navigating to a new page.</usage>\n </primary_tool>\n <secondary_tool>\n <name>ariaTree</name>\n <usage>Get complete page context before taking actions</usage>\n <benefit>Eliminates the need to scroll and provides full accessible content</benefit>\n </secondary_tool>\n </step_1>\n </page_understanding_protocol>`\n : `<page_understanding_protocol>\n <step_1>\n <title>UNDERSTAND THE PAGE</title>\n <primary_tool>\n <name>ariaTree</name>\n <usage>Get complete page context before taking actions</usage>\n <benefit>Eliminates the need to scroll and provides full accessible content</benefit>\n </primary_tool>\n <secondary_tool>\n <name>screenshot</name>\n <usage>Visual confirmation when needed. Ideally after navigating to a new page.</usage>\n </secondary_tool>\n </step_1>\n </page_understanding_protocol>`;\n\n // Roadblocks section only shown when running on Browserbase (has captcha solver)\n const roadblocksSection = isBrowserbase\n ? `<roadblocks>\n <note>captchas, popups, etc.</note>\n <captcha>If you see a captcha, use the wait tool. It will automatically be solved by our internal solver.</captcha>\n </roadblocks>`\n : \"\";\n\n // Build customInstructions block only if provided\n const customInstructionsBlock = systemInstructions\n ? `<customInstructions>${cdata(systemInstructions)}</customInstructions>\\n `\n : \"\";\n\n // Build variables section only if variables are provided\n const hasVariables = variables && Object.keys(variables).length > 0;\n const variableToolsNote = isHybridMode\n ? \"Use %variableName% syntax in the type, fillFormVision, or act tool's value/text/action fields.\"\n : \"Use %variableName% syntax in the act or fillForm tool's value/action fields.\";\n const variablesSection = hasVariables\n ? `<variables>\n <note>You have access to the following variables. Use %variableName% syntax to substitute variable values. This is especially important for sensitive data like passwords.</note>\n <usage>${variableToolsNote}</usage>\n <example>To type a password, use: type %password% into the password field</example>\n ${Object.entries(variables)\n .map(([name, v]) => {\n const description =\n typeof v === \"object\" && v !== null && \"value\" in v\n ? v.description\n : undefined;\n return description\n ? `<variable name=\"${name}\">${description}</variable>`\n : `<variable name=\"${name}\" />`;\n })\n .join(\"\\n \")}\n </variables>`\n : \"\";\n\n return `<system>\n <identity>You are a web automation assistant using browser automation tools to accomplish the user's goal.</identity>\n ${customInstructionsBlock}<task>\n <goal>${cdata(executionInstruction)}</goal>\n <date display=\"local\" iso=\"${isoDate}\">${localeDate}</date>\n <note>You may think the date is different due to knowledge cutoff, but this is the actual date.</note>\n </task>\n <page>\n <startingUrl>you are starting your task on this url: ${url}</startingUrl>\n </page>\n <mindset>\n <note>Be very intentional about your action. The initial instruction is very important, and slight variations of the actual goal can lead to failures.</note>\n <importantNote>If something fails to meet a single condition of the task, move on from it rather than seeing if it meets other criteria. We only care that it meets all of it</importantNote>\n <note>When the task is complete, do not seek more information; you have completed the task.</note>\n </mindset>\n <guidelines>\n <item>Always start by understanding the current page state</item>\n <item>Use the screenshot tool to verify page state when needed</item>\n <item>Use appropriate tools for each action</item>\n </guidelines>\n ${pageUnderstandingProtocol}\n <navigation>\n <rule>If you are confident in the URL, navigate directly to it.</rule>\n ${hasSearch ? `<rule>If you are not confident in the URL, use the search tool to find it.</rule>` : ``}\n </navigation>\n ${toolsSection}\n <strategy>\n ${strategySection}\n ${commonStrategyItems}\n </strategy>\n ${roadblocksSection}\n ${variablesSection}\n <completion>\n <note>When you complete the task, explain any information that was found that was relevant to the original task.</note>\n <examples>\n <example>If you were asked for specific flights, list the flights you found.</example>\n <example>If you were asked for information about a product, list the product information you were asked for.</example>\n </examples>\n </completion>\n</system>`;\n}\n"]}
1
+ {"version":3,"file":"agentSystemPrompt.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/prompts/agentSystemPrompt.ts"],"names":[],"mappings":"AA4BA,SAAS,iBAAiB,CACxB,YAAqB,EACrB,SAAkB,EAClB,YAAuB;IAEvB,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;IAE/C,MAAM,WAAW,GAAqB;QACpC;YACE,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,4DAA4D;SAC1E;QACD;YACE,IAAI,EAAE,UAAU;YAChB,WAAW,EACT,+DAA+D;SAClE;QACD;YACE,IAAI,EAAE,OAAO;YACb,WAAW,EACT,qFAAqF;SACxF;QACD;YACE,IAAI,EAAE,MAAM;YACZ,WAAW,EACT,2FAA2F;SAC9F;QACD;YACE,IAAI,EAAE,KAAK;YACX,WAAW,EACT,0LAA0L;SAC7L;QACD,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,0BAA0B,EAAE;QAChE,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,8BAA8B,EAAE;QACrE,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,sBAAsB,EAAE;QACrD;YACE,IAAI,EAAE,gBAAgB;YACtB,WAAW,EAAE,mCAAmC;SACjD;QACD,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE;QACtD,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,yBAAyB,EAAE;QAC3D,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,mBAAmB,EAAE;QAClD,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,2BAA2B,EAAE;QAC1D,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,kCAAkC,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G;;;;;;;;;;;;IAY1D,yBAAyB;;;MAGvB,SAAS,CAAC,CAAC,CAAC,mFAAmF,CAAC,CAAC,CAAC,EAAE;;IAEtG,YAAY;;MAEV,eAAe;MACf,mBAAmB;;IAErB,iBAAiB;IACjB,gBAAgB;;;;;;;;UAQV,CAAC;AACX,CAAC","sourcesContent":["import type { AgentToolMode, Variables } from \"../../types/public/agent.js\";\n\nexport interface AgentSystemPromptOptions {\n url: string;\n executionInstruction: string;\n mode: AgentToolMode;\n systemInstructions?: string;\n /** Whether running on Browserbase (enables captcha solver messaging) */\n isBrowserbase?: boolean;\n /** Tools to exclude from the system prompt */\n excludeTools?: string[];\n /** Variables available to the agent for use in act/type tools */\n variables?: Variables;\n /** Whether the search tool is enabled for this execution */\n useSearch?: boolean;\n}\n\n/**\n * Builds the system prompt for the agent based on the tool mode.\n *\n * @param options - The prompt configuration options\n * @returns The formatted system prompt string\n */\ninterface ToolDefinition {\n name: string;\n description: string;\n}\n\nfunction buildToolsSection(\n isHybridMode: boolean,\n hasSearch: boolean,\n excludeTools?: string[],\n): string {\n const excludeSet = new Set(excludeTools ?? []);\n\n const hybridTools: ToolDefinition[] = [\n {\n name: \"screenshot\",\n description: \"Take a compressed JPEG screenshot for quick visual context\",\n },\n {\n name: \"ariaTree\",\n description:\n \"Get an accessibility (ARIA) hybrid tree for full page context\",\n },\n {\n name: \"click\",\n description:\n \"Click on an element (PREFERRED - more reliable when element is visible in viewport)\",\n },\n {\n name: \"type\",\n description:\n \"Type text into an element (PREFERRED - more reliable when element is visible in viewport)\",\n },\n {\n name: \"act\",\n description:\n \"Perform a specific atomic action (click, type, etc.) - ONLY use when element is in ariaTree but NOT visible in screenshot. Less reliable but can interact with out-of-viewport elements.\",\n },\n { name: \"dragAndDrop\", description: \"Drag and drop an element\" },\n { name: \"clickAndHold\", description: \"Click and hold on an element\" },\n { name: \"keys\", description: \"Press a keyboard key\" },\n {\n name: \"fillFormVision\",\n description: \"Fill out a form using coordinates\",\n },\n { name: \"think\", description: \"Think about the task\" },\n { name: \"extract\", description: \"Extract structured data\" },\n { name: \"goto\", description: \"Navigate to a URL\" },\n { name: \"wait\", description: \"Wait for a specified time\" },\n { name: \"navback\", description: \"Navigate back in browser history\" },\n { name: \"scroll\", description: \"Scroll the page x pixels up or down\" },\n ];\n\n const domTools: ToolDefinition[] = [\n {\n name: \"screenshot\",\n description: \"Take a compressed JPEG screenshot for quick visual context\",\n },\n {\n name: \"ariaTree\",\n description:\n \"Get an accessibility (ARIA) hybrid tree for full page context\",\n },\n {\n name: \"act\",\n description: \"Perform a specific atomic action (click, type)\",\n },\n { name: \"keys\", description: \"Press a keyboard key\" },\n { name: \"fillForm\", description: \"Fill out a form\" },\n { name: \"think\", description: \"Think about the task\" },\n { name: \"extract\", description: \"Extract structured data\" },\n { name: \"goto\", description: \"Navigate to a URL\" },\n { name: \"wait\", description: \"Wait for a specified time\" },\n { name: \"navback\", description: \"Navigate back in browser history\" },\n { name: \"scroll\", description: \"Scroll the page x pixels up or down\" },\n ];\n\n const baseTools = isHybridMode ? hybridTools : domTools;\n\n if (hasSearch) {\n baseTools.push({\n name: \"search\",\n description:\n \"Perform a web search and return results. Prefer this over navigating to Google and searching within the page for reliability and efficiency.\",\n });\n }\n\n const filteredTools = baseTools.filter((tool) => !excludeSet.has(tool.name));\n\n const toolLines = filteredTools\n .map((tool) => ` <tool name=\"${tool.name}\">${tool.description}</tool>`)\n .join(\"\\n\");\n\n return `<tools>\\n${toolLines}\\n </tools>`;\n}\n\nexport function buildAgentSystemPrompt(\n options: AgentSystemPromptOptions,\n): string {\n const {\n url,\n executionInstruction,\n mode,\n systemInstructions,\n isBrowserbase = false,\n excludeTools,\n variables,\n useSearch = false,\n } = options;\n const localeDate = new Date().toLocaleDateString();\n const isoDate = new Date().toISOString();\n const cdata = (text: string) => `<![CDATA[${text}]]>`;\n\n const isHybridMode = mode === \"hybrid\";\n const hasSearch = useSearch || Boolean(process.env.BRAVE_API_KEY);\n\n // Tools section differs based on mode and excluded tools\n const toolsSection = buildToolsSection(isHybridMode, hasSearch, excludeTools);\n\n // Strategy differs based on mode\n const strategyItems = isHybridMode\n ? [\n `<item>Tool selection priority: Use specific tools (click, type) when elements are visible in viewport for maximum reliability.</item>`,\n `<item>Always use screenshot to get proper grounding of the coordinates you want to type/click into.</item>`,\n `<item>When interacting with an input, always use the type tool to type into the input, over clicking and then typing into it.</item>`,\n `<item>Use ariaTree as a secondary tool when elements aren't visible in screenshot or to get full page context.</item>`,\n `<item>Only use act when element is in ariaTree but NOT visible in screenshot.</item>`,\n ]\n : [\n `<item>Tool selection priority: Use act tool for all clicking and typing on a page.</item>`,\n `<item>Always check ariaTree first to understand full page content without scrolling - it shows all elements including those below the fold.</item>`,\n `<item>When interacting with an input, always use the act tool to type into the input, over clicking and then typing.</item>`,\n `<item>If an element is present in the ariaTree, use act to interact with it directly - this eliminates the need to scroll.</item>`,\n `<item>Use screenshot for visual confirmation when needed, but rely primarily on ariaTree for element detection.</item>`,\n ];\n\n const strategySection = strategyItems.join(\"\\n \");\n\n const commonStrategyItems = `\n <item>CRITICAL: Use extract ONLY when the task explicitly requires structured data output (e.g., \"get job listings\", \"extract product details\"). For reading page content or understanding elements, always use ${isHybridMode ? \"screenshot or ariaTree\" : \"ariaTree\"} instead - it's faster and more reliable.</item>\n <item>Keep actions atomic and verify outcomes before proceeding.</item>\n <item>For each action, provide clear reasoning about why you're taking that step.</item>\n <item>When you need to input text that could be entered character-by-character or through multiple separate inputs, prefer using the keys tool to type the entire sequence at once. This is more efficient for scenarios like verification codes split across multiple fields, or when virtual keyboards are present but direct typing would be faster.</item>\n `;\n\n // Page understanding protocol differs based on mode\n const pageUnderstandingProtocol = isHybridMode\n ? `<page_understanding_protocol>\n <step_1>\n <title>UNDERSTAND THE PAGE</title>\n <primary_tool>\n <name>screenshot</name>\n <usage>Visual confirmation when needed. Ideally after navigating to a new page.</usage>\n </primary_tool>\n <secondary_tool>\n <name>ariaTree</name>\n <usage>Get complete page context before taking actions</usage>\n <benefit>Eliminates the need to scroll and provides full accessible content</benefit>\n </secondary_tool>\n </step_1>\n </page_understanding_protocol>`\n : `<page_understanding_protocol>\n <step_1>\n <title>UNDERSTAND THE PAGE</title>\n <primary_tool>\n <name>ariaTree</name>\n <usage>Get complete page context before taking actions</usage>\n <benefit>Eliminates the need to scroll and provides full accessible content</benefit>\n </primary_tool>\n <secondary_tool>\n <name>screenshot</name>\n <usage>Visual confirmation when needed. Ideally after navigating to a new page.</usage>\n </secondary_tool>\n </step_1>\n </page_understanding_protocol>`;\n\n // Roadblocks section only shown when running on Browserbase (has captcha solver)\n const roadblocksSection = isBrowserbase\n ? `<roadblocks>\n <note>captchas, popups, etc.</note>\n <captcha>If you see a captcha, use the wait tool. It will automatically be solved by our internal solver.</captcha>\n </roadblocks>`\n : \"\";\n\n // Build customInstructions block only if provided\n const customInstructionsBlock = systemInstructions\n ? `<customInstructions>${cdata(systemInstructions)}</customInstructions>\\n `\n : \"\";\n\n // Build variables section only if variables are provided\n const hasVariables = variables && Object.keys(variables).length > 0;\n const variableToolsNote = isHybridMode\n ? \"Use %variableName% syntax in the type, fillFormVision, or act tool's value/text/action fields.\"\n : \"Use %variableName% syntax in the act or fillForm tool's value/action fields.\";\n const variablesSection = hasVariables\n ? `<variables>\n <note>You have access to the following variables. Use %variableName% syntax to substitute variable values. This is especially important for sensitive data like passwords.</note>\n <usage>${variableToolsNote}</usage>\n <example>To type a password, use: type %password% into the password field</example>\n ${Object.entries(variables)\n .map(([name, v]) => {\n const description =\n typeof v === \"object\" && v !== null && \"value\" in v\n ? v.description\n : undefined;\n return description\n ? `<variable name=\"${name}\">${description}</variable>`\n : `<variable name=\"${name}\" />`;\n })\n .join(\"\\n \")}\n </variables>`\n : \"\";\n\n return `<system>\n <identity>You are a web automation assistant using browser automation tools to accomplish the user's goal.</identity>\n ${customInstructionsBlock}<task>\n <goal>${cdata(executionInstruction)}</goal>\n <date display=\"local\" iso=\"${isoDate}\">${localeDate}</date>\n <note>You may think the date is different due to knowledge cutoff, but this is the actual date.</note>\n </task>\n <page>\n <startingUrl>you are starting your task on this url: ${url}</startingUrl>\n </page>\n <mindset>\n <note>Be very intentional about your action. The initial instruction is very important, and slight variations of the actual goal can lead to failures.</note>\n <importantNote>If something fails to meet a single condition of the task, move on from it rather than seeing if it meets other criteria. We only care that it meets all of it</importantNote>\n <note>When the task is complete, do not seek more information; you have completed the task.</note>\n </mindset>\n <guidelines>\n <item>Always start by understanding the current page state</item>\n <item>Use the screenshot tool to verify page state when needed</item>\n <item>Use appropriate tools for each action</item>\n </guidelines>\n ${pageUnderstandingProtocol}\n <navigation>\n <rule>If you are confident in the URL, navigate directly to it.</rule>\n ${hasSearch ? `<rule>If you are not confident in the URL, use the search tool to find it.</rule>` : ``}\n </navigation>\n ${toolsSection}\n <strategy>\n ${strategySection}\n ${commonStrategyItems}\n </strategy>\n ${roadblocksSection}\n ${variablesSection}\n <completion>\n <note>When you complete the task, explain any information that was found that was relevant to the original task.</note>\n <examples>\n <example>If you were asked for specific flights, list the flights you found.</example>\n <example>If you were asked for information about a product, list the product information you were asked for.</example>\n </examples>\n </completion>\n</system>`;\n}\n"]}
@@ -70,4 +70,4 @@ export const searchTool = (v3) => tool({
70
70
  };
71
71
  },
72
72
  });
73
- //# sourceMappingURL=search.js.map
73
+ //# sourceMappingURL=braveSearch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"braveSearch.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/braveSearch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgCxB,KAAK,UAAU,kBAAkB,CAAC,KAAa;IAC7C,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC/C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,oDAAoD,YAAY,EAAE,EAClE;YACE,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,OAAO,EAAE,EAAE,EAAE;SACtB,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EAAM,EAAE,EAAE,CACnC,IAAI,CAAC;IACH,WAAW,EACT,wSAAwS;IAC1S,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,yCAAyC,CAAC;KACtE,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;QAC3B,EAAE,CAAC,MAAM,CAAC;YACR,QAAQ,EAAE,OAAO;YACjB,OAAO,EAAE,4BAA4B;YACrC,KAAK,EAAE,CAAC;YACR,SAAS,EAAE;gBACT,SAAS,EAAE;oBACT,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC;oBAChC,IAAI,EAAE,QAAQ;iBACf;aACF;SACF,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAE/C,EAAE,CAAC,qBAAqB,CAAC;YACvB,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,KAAK;YAClB,mBAAmB,EAAE,EAAE,KAAK,EAAE;YAC9B,OAAO,EACL,MAAM,CAAC,KAAK,IAAI,SAAS,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC,UAAU;SACtE,CAAC,CAAC;QAEH,OAAO;YACL,GAAG,MAAM;YACT,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\n\nexport interface BraveSearchResult {\n title: string;\n url: string;\n description?: string;\n}\n\ninterface SearchResponse {\n data?: {\n results: BraveSearchResult[];\n };\n error?: string;\n}\n\ninterface BraveWebResult {\n title?: string;\n url?: string;\n description?: string;\n age?: string;\n meta_url?: {\n favicon?: string;\n };\n}\n\ninterface BraveApiResponse {\n web?: {\n results?: BraveWebResult[];\n };\n}\n\nasync function performBraveSearch(query: string): Promise<SearchResponse> {\n try {\n const encodedQuery = encodeURIComponent(query);\n const response = await fetch(\n `https://api.search.brave.com/res/v1/web/search?q=${encodedQuery}`,\n {\n method: \"GET\",\n headers: {\n Accept: \"application/json\",\n \"Accept-Encoding\": \"gzip\",\n \"X-Subscription-Token\": process.env.BRAVE_API_KEY!,\n },\n },\n );\n\n if (!response.ok) {\n return {\n error: `Brave API error: ${response.status} ${response.statusText}`,\n data: { results: [] },\n };\n }\n\n const data = (await response.json()) as BraveApiResponse;\n const results: BraveSearchResult[] = [];\n\n if (data?.web?.results && Array.isArray(data.web.results)) {\n for (const item of data.web.results.slice(0, 5)) {\n if (item.title && item.url) {\n results.push({\n title: item.title,\n url: item.url,\n description: item.description,\n });\n }\n }\n }\n\n return { data: { results } };\n } catch (error) {\n console.error(\"Search error\", error);\n return {\n error: `Error performing search: ${(error as Error).message}`,\n data: { results: [] },\n };\n }\n}\n\nexport const searchTool = (v3: V3) =>\n tool({\n description:\n \"Perform a web search and returns results. Use this tool when you need information from the web or when you are unsure of the exact URL you want to navigate to. This can be used to find the ideal entry point, resulting in a task that is easier to complete due to starting further in the process.\",\n inputSchema: z.object({\n query: z.string().describe(\"The search query to look for on the web\"),\n }),\n execute: async ({ query }) => {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: search`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ query }),\n type: \"object\",\n },\n },\n });\n\n const result = await performBraveSearch(query);\n\n v3.recordAgentReplayStep({\n type: \"search\",\n instruction: query,\n playwrightArguments: { query },\n message:\n result.error ?? `Found ${result.data?.results.length ?? 0} results`,\n });\n\n return {\n ...result,\n timestamp: Date.now(),\n };\n },\n });\n"]}
@@ -0,0 +1,13 @@
1
+ import type { V3 } from "../../v3.js";
2
+ export interface SearchResult {
3
+ title: string;
4
+ url: string;
5
+ publishedDate?: string;
6
+ }
7
+ export declare const searchTool: (v3: V3, apiKey: string) => import("ai").Tool<{
8
+ query: string;
9
+ }, {
10
+ timestamp: number;
11
+ results: SearchResult[];
12
+ error?: string;
13
+ }>;
@@ -0,0 +1,66 @@
1
+ import { tool } from "ai";
2
+ import { z } from "zod";
3
+ async function performBrowserbaseSearch(v3, query, apiKey, numResults = 5) {
4
+ try {
5
+ const response = await fetch("https://api.browserbase.com/v1/search", {
6
+ method: "POST",
7
+ headers: {
8
+ "Content-Type": "application/json",
9
+ "x-bb-api-key": apiKey,
10
+ },
11
+ body: JSON.stringify({ query, numResults }),
12
+ });
13
+ if (!response.ok) {
14
+ return {
15
+ results: [],
16
+ error: `Browserbase Search API error: ${response.status} ${response.statusText}`,
17
+ };
18
+ }
19
+ const data = (await response.json());
20
+ const results = (data?.results ?? []).map(({ title, url, publishedDate }) => ({
21
+ title: title,
22
+ url: url,
23
+ ...(publishedDate && { publishedDate }),
24
+ }));
25
+ return { results };
26
+ }
27
+ catch (error) {
28
+ v3.logger({
29
+ category: "agent",
30
+ message: `Search error: ${error.message}`,
31
+ level: 0,
32
+ });
33
+ return {
34
+ results: [],
35
+ error: `Error performing search: ${error.message}`,
36
+ };
37
+ }
38
+ }
39
+ export const searchTool = (v3, apiKey) => tool({
40
+ description: "Perform a web search and returns results. Use this tool when you need information from the web or when you are unsure of the exact URL you want to navigate to. This can be used to find the ideal entry point, resulting in a task that is easier to complete due to starting further in the process.",
41
+ inputSchema: z.object({
42
+ query: z.string().describe("The search query to look for on the web"),
43
+ }),
44
+ execute: async ({ query }) => {
45
+ v3.logger({
46
+ category: "agent",
47
+ message: `Agent calling tool: search`,
48
+ level: 1,
49
+ auxiliary: {
50
+ arguments: {
51
+ value: JSON.stringify({ query }),
52
+ type: "object",
53
+ },
54
+ },
55
+ });
56
+ const result = await performBrowserbaseSearch(v3, query, apiKey);
57
+ v3.recordAgentReplayStep({
58
+ type: "search",
59
+ instruction: query,
60
+ playwrightArguments: { query },
61
+ message: result.error ?? `Found ${result.results.length} results`,
62
+ });
63
+ return { ...result, timestamp: Date.now() };
64
+ },
65
+ });
66
+ //# sourceMappingURL=browserbaseSearch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browserbaseSearch.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/browserbaseSearch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAmBxB,KAAK,UAAU,wBAAwB,CACrC,EAAM,EACN,KAAa,EACb,MAAc,EACd,aAAqB,CAAC;IAEtB,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,uCAAuC,EAAE;YACpE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,cAAc,EAAE,MAAM;aACvB;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;SAC5C,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,OAAO;gBACL,OAAO,EAAE,EAAE;gBACX,KAAK,EAAE,iCAAiC,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE;aACjF,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA2B,CAAC;QAC/D,MAAM,OAAO,GAAmB,CAAC,IAAI,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CACvD,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC,CAAC;YAClC,KAAK,EAAE,KAAK;YACZ,GAAG,EAAE,GAAG;YACR,GAAG,CAAC,aAAa,IAAI,EAAE,aAAa,EAAE,CAAC;SACxC,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;QAEH,OAAO,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;IAC9C,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\n\nexport interface SearchResult {\n title: string;\n url: string;\n publishedDate?: string;\n}\n\ninterface BrowserbaseRawResult {\n title?: string;\n url?: string;\n publishedDate?: string;\n}\n\ninterface BrowserbaseApiResponse {\n results?: BrowserbaseRawResult[];\n}\n\nasync function performBrowserbaseSearch(\n v3: V3,\n query: string,\n apiKey: string,\n numResults: number = 5,\n): Promise<{ results: SearchResult[]; error?: string }> {\n try {\n const response = await fetch(\"https://api.browserbase.com/v1/search\", {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-bb-api-key\": apiKey,\n },\n body: JSON.stringify({ query, numResults }),\n });\n\n if (!response.ok) {\n return {\n results: [],\n error: `Browserbase Search API error: ${response.status} ${response.statusText}`,\n };\n }\n\n const data = (await response.json()) as BrowserbaseApiResponse;\n const results: SearchResult[] = (data?.results ?? []).map(\n ({ title, url, publishedDate }) => ({\n title: title,\n url: url,\n ...(publishedDate && { publishedDate }),\n }),\n );\n\n return { results };\n } catch (error) {\n v3.logger({\n category: \"agent\",\n message: `Search error: ${(error as Error).message}`,\n level: 0,\n });\n return {\n results: [],\n error: `Error performing search: ${(error as Error).message}`,\n };\n }\n}\n\nexport const searchTool = (v3: V3, apiKey: string) =>\n tool({\n description:\n \"Perform a web search and returns results. Use this tool when you need information from the web or when you are unsure of the exact URL you want to navigate to. This can be used to find the ideal entry point, resulting in a task that is easier to complete due to starting further in the process.\",\n inputSchema: z.object({\n query: z.string().describe(\"The search query to look for on the web\"),\n }),\n execute: async ({ query }) => {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: search`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ query }),\n type: \"object\",\n },\n },\n });\n\n const result = await performBrowserbaseSearch(v3, query, apiKey);\n\n v3.recordAgentReplayStep({\n type: \"search\",\n instruction: query,\n playwrightArguments: { query },\n message: result.error ?? `Found ${result.results.length} results`,\n });\n\n return { ...result, timestamp: Date.now() };\n },\n });\n"]}
@@ -14,7 +14,8 @@ import { clickAndHoldTool } from "./clickAndHold.js";
14
14
  import { keysTool } from "./keys.js";
15
15
  import { fillFormVisionTool } from "./fillFormVision.js";
16
16
  import { thinkTool } from "./think.js";
17
- import { searchTool } from "./search.js";
17
+ import { searchTool as browserbaseSearchTool } from "./browserbaseSearch.js";
18
+ import { searchTool as braveSearchTool } from "./braveSearch.js";
18
19
  import type { ToolSet, InferUITools } from "ai";
19
20
  import type { V3 } from "../../v3.js";
20
21
  import type { LogLine } from "../../types/public/logs.js";
@@ -47,12 +48,22 @@ export interface V3AgentToolOptions {
47
48
  * Forwarded to the underlying v3 call's `timeout` option.
48
49
  */
49
50
  toolTimeout?: number;
51
+ /**
52
+ * Whether to enable the Browserbase-powered web search tool.
53
+ * Requires a valid Browserbase API key.
54
+ */
55
+ useSearch?: boolean;
56
+ /**
57
+ * The Browserbase API key used for the search tool.
58
+ * Resolved from BROWSERBASE_API_KEY env var or the Stagehand constructor.
59
+ */
60
+ browserbaseApiKey?: string;
50
61
  }
51
62
  export declare function createAgentTools(v3: V3, options?: V3AgentToolOptions): ToolSet;
52
63
  export type AgentTools = ReturnType<typeof createAgentTools>;
53
64
  /**
54
65
  * Type map of all agent tools for strong typing of tool calls and results.
55
- * Note: `search` is optional as it's only available when BRAVE_API_KEY is configured.
66
+ * Note: `search` is optional enabled via useSearch: true (Browserbase) or BRAVE_API_KEY env var (legacy).
56
67
  */
57
68
  export type AgentToolTypesMap = {
58
69
  act: ReturnType<typeof actTool>;
@@ -68,7 +79,7 @@ export type AgentToolTypesMap = {
68
79
  navback: ReturnType<typeof navBackTool>;
69
80
  screenshot: ReturnType<typeof screenshotTool>;
70
81
  scroll: ReturnType<typeof scrollTool> | ReturnType<typeof scrollVisionTool>;
71
- search?: ReturnType<typeof searchTool>;
82
+ search?: ReturnType<typeof browserbaseSearchTool> | ReturnType<typeof braveSearchTool>;
72
83
  think: ReturnType<typeof thinkTool>;
73
84
  type: ReturnType<typeof typeTool>;
74
85
  wait: ReturnType<typeof waitTool>;
@@ -14,7 +14,8 @@ import { clickAndHoldTool } from "./clickAndHold.js";
14
14
  import { keysTool } from "./keys.js";
15
15
  import { fillFormVisionTool } from "./fillFormVision.js";
16
16
  import { thinkTool } from "./think.js";
17
- import { searchTool } from "./search.js";
17
+ import { searchTool as browserbaseSearchTool } from "./browserbaseSearch.js";
18
+ import { searchTool as braveSearchTool } from "./braveSearch.js";
18
19
  /**
19
20
  * Filters tools based on mode and explicit exclusions.
20
21
  * - 'dom' mode: Removes coordinate-based tools (click, type, dragAndDrop, clickAndHold, fillFormVision)
@@ -67,8 +68,11 @@ export function createAgentTools(v3, options) {
67
68
  type: typeTool(v3, provider, variables),
68
69
  wait: waitTool(v3, mode),
69
70
  };
70
- if (process.env.BRAVE_API_KEY) {
71
- allTools.search = searchTool(v3);
71
+ if (options?.useSearch && options.browserbaseApiKey) {
72
+ allTools.search = browserbaseSearchTool(v3, options.browserbaseApiKey);
73
+ }
74
+ else if (process.env.BRAVE_API_KEY) {
75
+ allTools.search = braveSearchTool(v3);
72
76
  }
73
77
  return filterTools(allTools, mode, excludeTools);
74
78
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,M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AAS,EAAE;QAClB,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,CAAC;QACvC,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;KACzB,CAAC;IAEF,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;QAC9B,QAAQ,CAAC,MAAM,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import { gotoTool } from \"./goto.js\";\nimport { actTool } from \"./act.js\";\nimport { screenshotTool } from \"./screenshot.js\";\nimport { waitTool } from \"./wait.js\";\nimport { navBackTool } from \"./navback.js\";\nimport { ariaTreeTool } from \"./ariaTree.js\";\nimport { fillFormTool } from \"./fillform.js\";\nimport { scrollTool, scrollVisionTool } from \"./scroll.js\";\nimport { extractTool } from \"./extract.js\";\nimport { clickTool } from \"./click.js\";\nimport { typeTool } from \"./type.js\";\nimport { dragAndDropTool } from \"./dragAndDrop.js\";\nimport { clickAndHoldTool } from \"./clickAndHold.js\";\nimport { keysTool } from \"./keys.js\";\nimport { fillFormVisionTool } from \"./fillFormVision.js\";\nimport { thinkTool } from \"./think.js\";\nimport { searchTool } from \"./search.js\";\n\nimport type { ToolSet, InferUITools } from \"ai\";\nimport type { V3 } from \"../../v3.js\";\nimport type { LogLine } from \"../../types/public/logs.js\";\nimport type {\n AgentToolMode,\n AgentModelConfig,\n Variables,\n} from \"../../types/public/agent.js\";\n\nexport interface V3AgentToolOptions {\n executionModel?: string | AgentModelConfig;\n logger?: (message: LogLine) => void;\n /**\n * Tool mode determines which set of tools are available.\n * - 'dom' (default): Uses DOM-based tools (act, fillForm) - removes coordinate-based tools\n * - 'hybrid': Uses coordinate-based tools (click, type, dragAndDrop, etc.) - removes fillForm\n */\n mode?: AgentToolMode;\n /**\n * The model provider. Used for model-specific coordinate handling\n */\n provider?: string;\n /**\n * Tools to exclude from the available toolset.\n * These tools will be filtered out after mode-based filtering.\n */\n excludeTools?: string[];\n /**\n * Variables available to the agent for use in act/type tools.\n * When provided, these tools will have an optional useVariable field.\n */\n variables?: Variables;\n /**\n * Timeout in milliseconds for tool calls that invoke v3 methods (act, extract, fillForm, ariaTree).\n * Forwarded to the underlying v3 call's `timeout` option.\n */\n toolTimeout?: number;\n}\n\n/**\n * Filters tools based on mode and explicit exclusions.\n * - 'dom' mode: Removes coordinate-based tools (click, type, dragAndDrop, clickAndHold, fillFormVision)\n * - 'hybrid' mode: Removes DOM-based form tool (fillForm) in favor of coordinate-based fillFormVision\n * - excludeTools: Additional tools to remove from the toolset\n */\nfunction filterTools(\n tools: ToolSet,\n mode: AgentToolMode,\n excludeTools?: string[],\n): ToolSet {\n const filtered: ToolSet = { ...tools };\n\n // Mode-based filtering\n if (mode === \"hybrid\") {\n delete filtered.fillForm;\n } else {\n // DOM mode (default)\n delete filtered.click;\n delete filtered.type;\n delete filtered.dragAndDrop;\n delete filtered.clickAndHold;\n delete filtered.fillFormVision;\n }\n\n if (excludeTools) {\n for (const toolName of excludeTools) {\n delete filtered[toolName];\n }\n }\n\n return filtered;\n}\n\nexport function createAgentTools(v3: V3, options?: V3AgentToolOptions) {\n const executionModel = options?.executionModel;\n const mode = options?.mode ?? \"dom\";\n const provider = options?.provider;\n const excludeTools = options?.excludeTools;\n const variables = options?.variables;\n const toolTimeout = options?.toolTimeout;\n\n const allTools: ToolSet = {\n act: actTool(v3, executionModel, variables, toolTimeout),\n ariaTree: ariaTreeTool(v3, toolTimeout),\n click: clickTool(v3, provider),\n clickAndHold: clickAndHoldTool(v3, provider),\n dragAndDrop: dragAndDropTool(v3, provider),\n extract: extractTool(v3, executionModel, toolTimeout),\n fillForm: fillFormTool(v3, executionModel, variables, toolTimeout),\n fillFormVision: fillFormVisionTool(v3, provider, variables),\n goto: gotoTool(v3),\n keys: keysTool(v3),\n navback: navBackTool(v3),\n screenshot: screenshotTool(v3),\n scroll: mode === \"hybrid\" ? scrollVisionTool(v3, provider) : scrollTool(v3),\n think: thinkTool(),\n type: typeTool(v3, provider, variables),\n wait: waitTool(v3, mode),\n };\n\n if (process.env.BRAVE_API_KEY) {\n allTools.search = searchTool(v3);\n }\n\n return filterTools(allTools, mode, excludeTools);\n}\n\nexport type AgentTools = ReturnType<typeof createAgentTools>;\n\n/**\n * Type map of all agent tools for strong typing of tool calls and results.\n * Note: `search` is optional as it's only available when BRAVE_API_KEY is configured.\n */\nexport type AgentToolTypesMap = {\n act: ReturnType<typeof actTool>;\n ariaTree: ReturnType<typeof ariaTreeTool>;\n click: ReturnType<typeof clickTool>;\n clickAndHold: ReturnType<typeof clickAndHoldTool>;\n dragAndDrop: ReturnType<typeof dragAndDropTool>;\n extract: ReturnType<typeof extractTool>;\n fillForm: ReturnType<typeof fillFormTool>;\n fillFormVision: ReturnType<typeof fillFormVisionTool>;\n goto: ReturnType<typeof gotoTool>;\n keys: ReturnType<typeof keysTool>;\n navback: ReturnType<typeof navBackTool>;\n screenshot: ReturnType<typeof screenshotTool>;\n scroll: ReturnType<typeof scrollTool> | ReturnType<typeof scrollVisionTool>;\n search?: ReturnType<typeof searchTool>;\n think: ReturnType<typeof thinkTool>;\n type: ReturnType<typeof typeTool>;\n wait: ReturnType<typeof waitTool>;\n};\n\n/**\n * Inferred UI tools type for type-safe tool inputs and outputs.\n * Use with UIMessage for full type safety in UI contexts.\n */\nexport type AgentUITools = InferUITools<AgentToolTypesMap>;\n\n/**\n * Union type for all possible agent tool calls.\n * Provides type-safe access to tool call arguments.\n */\nexport type AgentToolCall = {\n [K in keyof AgentToolTypesMap]: {\n toolName: K;\n toolCallId: string;\n args: AgentUITools[K][\"input\"];\n };\n}[keyof AgentToolTypesMap];\n\n/**\n * Union type for all possible agent tool results.\n * Provides type-safe access to tool result values.\n */\nexport type AgentToolResult = {\n [K in keyof AgentToolTypesMap]: {\n toolName: K;\n toolCallId: string;\n result: AgentUITools[K][\"output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QAAQ,EAAE,YAAY,CAAC,EAAE,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,CAAC;QAClE,cAAc,EAAE,kBAAkB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,CAAC;QAC3D,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC;QAClB,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC;QAClB,OAAO,EAAE,WAAW,CAAC,EAAE,CAAC;QACxB,UAAU,EAAE,cAAc,CAAC,EAAE,CAAC;QAC9B,MAAM,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3E,KAAK,EAAE,SAAS,EAAE;QAClB,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,CAAC;QACvC,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;KACzB,CAAC;IAEF,IAAI,OAAO,EAAE,SAAS,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;QACpD,QAAQ,CAAC,MAAM,GAAG,qBAAqB,CAAC,EAAE,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACzE,CAAC;SAAM,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;QACrC,QAAQ,CAAC,MAAM,GAAG,eAAe,CAAC,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import { gotoTool } from \"./goto.js\";\nimport { actTool } from \"./act.js\";\nimport { screenshotTool } from \"./screenshot.js\";\nimport { waitTool } from \"./wait.js\";\nimport { navBackTool } from \"./navback.js\";\nimport { ariaTreeTool } from \"./ariaTree.js\";\nimport { fillFormTool } from \"./fillform.js\";\nimport { scrollTool, scrollVisionTool } from \"./scroll.js\";\nimport { extractTool } from \"./extract.js\";\nimport { clickTool } from \"./click.js\";\nimport { typeTool } from \"./type.js\";\nimport { dragAndDropTool } from \"./dragAndDrop.js\";\nimport { clickAndHoldTool } from \"./clickAndHold.js\";\nimport { keysTool } from \"./keys.js\";\nimport { fillFormVisionTool } from \"./fillFormVision.js\";\nimport { thinkTool } from \"./think.js\";\nimport { searchTool as browserbaseSearchTool } from \"./browserbaseSearch.js\";\nimport { searchTool as braveSearchTool } from \"./braveSearch.js\";\n\nimport type { ToolSet, InferUITools } from \"ai\";\nimport type { V3 } from \"../../v3.js\";\nimport type { LogLine } from \"../../types/public/logs.js\";\nimport type {\n AgentToolMode,\n AgentModelConfig,\n Variables,\n} from \"../../types/public/agent.js\";\n\nexport interface V3AgentToolOptions {\n executionModel?: string | AgentModelConfig;\n logger?: (message: LogLine) => void;\n /**\n * Tool mode determines which set of tools are available.\n * - 'dom' (default): Uses DOM-based tools (act, fillForm) - removes coordinate-based tools\n * - 'hybrid': Uses coordinate-based tools (click, type, dragAndDrop, etc.) - removes fillForm\n */\n mode?: AgentToolMode;\n /**\n * The model provider. Used for model-specific coordinate handling\n */\n provider?: string;\n /**\n * Tools to exclude from the available toolset.\n * These tools will be filtered out after mode-based filtering.\n */\n excludeTools?: string[];\n /**\n * Variables available to the agent for use in act/type tools.\n * When provided, these tools will have an optional useVariable field.\n */\n variables?: Variables;\n /**\n * Timeout in milliseconds for tool calls that invoke v3 methods (act, extract, fillForm, ariaTree).\n * Forwarded to the underlying v3 call's `timeout` option.\n */\n toolTimeout?: number;\n /**\n * Whether to enable the Browserbase-powered web search tool.\n * Requires a valid Browserbase API key.\n */\n useSearch?: boolean;\n /**\n * The Browserbase API key used for the search tool.\n * Resolved from BROWSERBASE_API_KEY env var or the Stagehand constructor.\n */\n browserbaseApiKey?: string;\n}\n\n/**\n * Filters tools based on mode and explicit exclusions.\n * - 'dom' mode: Removes coordinate-based tools (click, type, dragAndDrop, clickAndHold, fillFormVision)\n * - 'hybrid' mode: Removes DOM-based form tool (fillForm) in favor of coordinate-based fillFormVision\n * - excludeTools: Additional tools to remove from the toolset\n */\nfunction filterTools(\n tools: ToolSet,\n mode: AgentToolMode,\n excludeTools?: string[],\n): ToolSet {\n const filtered: ToolSet = { ...tools };\n\n // Mode-based filtering\n if (mode === \"hybrid\") {\n delete filtered.fillForm;\n } else {\n // DOM mode (default)\n delete filtered.click;\n delete filtered.type;\n delete filtered.dragAndDrop;\n delete filtered.clickAndHold;\n delete filtered.fillFormVision;\n }\n\n if (excludeTools) {\n for (const toolName of excludeTools) {\n delete filtered[toolName];\n }\n }\n\n return filtered;\n}\n\nexport function createAgentTools(v3: V3, options?: V3AgentToolOptions) {\n const executionModel = options?.executionModel;\n const mode = options?.mode ?? \"dom\";\n const provider = options?.provider;\n const excludeTools = options?.excludeTools;\n const variables = options?.variables;\n const toolTimeout = options?.toolTimeout;\n\n const allTools: ToolSet = {\n act: actTool(v3, executionModel, variables, toolTimeout),\n ariaTree: ariaTreeTool(v3, toolTimeout),\n click: clickTool(v3, provider),\n clickAndHold: clickAndHoldTool(v3, provider),\n dragAndDrop: dragAndDropTool(v3, provider),\n extract: extractTool(v3, executionModel, toolTimeout),\n fillForm: fillFormTool(v3, executionModel, variables, toolTimeout),\n fillFormVision: fillFormVisionTool(v3, provider, variables),\n goto: gotoTool(v3),\n keys: keysTool(v3),\n navback: navBackTool(v3),\n screenshot: screenshotTool(v3),\n scroll: mode === \"hybrid\" ? scrollVisionTool(v3, provider) : scrollTool(v3),\n think: thinkTool(),\n type: typeTool(v3, provider, variables),\n wait: waitTool(v3, mode),\n };\n\n if (options?.useSearch && options.browserbaseApiKey) {\n allTools.search = browserbaseSearchTool(v3, options.browserbaseApiKey);\n } else if (process.env.BRAVE_API_KEY) {\n allTools.search = braveSearchTool(v3);\n }\n\n return filterTools(allTools, mode, excludeTools);\n}\n\nexport type AgentTools = ReturnType<typeof createAgentTools>;\n\n/**\n * Type map of all agent tools for strong typing of tool calls and results.\n * Note: `search` is optional enabled via useSearch: true (Browserbase) or BRAVE_API_KEY env var (legacy).\n */\nexport type AgentToolTypesMap = {\n act: ReturnType<typeof actTool>;\n ariaTree: ReturnType<typeof ariaTreeTool>;\n click: ReturnType<typeof clickTool>;\n clickAndHold: ReturnType<typeof clickAndHoldTool>;\n dragAndDrop: ReturnType<typeof dragAndDropTool>;\n extract: ReturnType<typeof extractTool>;\n fillForm: ReturnType<typeof fillFormTool>;\n fillFormVision: ReturnType<typeof fillFormVisionTool>;\n goto: ReturnType<typeof gotoTool>;\n keys: ReturnType<typeof keysTool>;\n navback: ReturnType<typeof navBackTool>;\n screenshot: ReturnType<typeof screenshotTool>;\n scroll: ReturnType<typeof scrollTool> | ReturnType<typeof scrollVisionTool>;\n search?:\n | ReturnType<typeof browserbaseSearchTool>\n | ReturnType<typeof braveSearchTool>;\n think: ReturnType<typeof thinkTool>;\n type: ReturnType<typeof typeTool>;\n wait: ReturnType<typeof waitTool>;\n};\n\n/**\n * Inferred UI tools type for type-safe tool inputs and outputs.\n * Use with UIMessage for full type safety in UI contexts.\n */\nexport type AgentUITools = InferUITools<AgentToolTypesMap>;\n\n/**\n * Union type for all possible agent tool calls.\n * Provides type-safe access to tool call arguments.\n */\nexport type AgentToolCall = {\n [K in keyof AgentToolTypesMap]: {\n toolName: K;\n toolCallId: string;\n args: AgentUITools[K][\"input\"];\n };\n}[keyof AgentToolTypesMap];\n\n/**\n * Union type for all possible agent tool results.\n * Provides type-safe access to tool result values.\n */\nexport type AgentToolResult = {\n [K in keyof AgentToolTypesMap]: {\n toolName: K;\n toolCallId: string;\n result: AgentUITools[K][\"output\"];\n };\n}[keyof AgentToolTypesMap];\n"]}
@@ -5,7 +5,7 @@ import { processMessages } from "../agent/utils/messageProcessing.js";
5
5
  import { SessionFileLogger } from "../flowLogger.js";
6
6
  import { V3FunctionName } from "../types/public/methods.js";
7
7
  import { mapToolResultToActions } from "../agent/utils/actionMapping.js";
8
- import { MissingLLMConfigurationError, StreamingCallbacksInNonStreamingModeError, AgentAbortError, } from "../types/public/sdkErrors.js";
8
+ import { MissingLLMConfigurationError, MissingEnvironmentVariableError, StreamingCallbacksInNonStreamingModeError, AgentAbortError, } from "../types/public/sdkErrors.js";
9
9
  import { handleDoneToolCall } from "../agent/utils/handleDoneToolCall.js";
10
10
  function getErrorMessage(error) {
11
11
  return error instanceof Error ? error.message : String(error);
@@ -62,8 +62,15 @@ export class V3AgentHandler {
62
62
  isBrowserbase: this.v3.isBrowserbase,
63
63
  excludeTools: options.excludeTools,
64
64
  variables: options.variables,
65
+ useSearch: options.useSearch,
65
66
  });
66
- const tools = this.createTools(options.excludeTools, options.variables, options.toolTimeout);
67
+ if (options.useSearch) {
68
+ const bbApiKey = this.v3.browserbaseApiKey;
69
+ if (!bbApiKey) {
70
+ throw new MissingEnvironmentVariableError("BROWSERBASE_API_KEY", "agent search (useSearch: true)");
71
+ }
72
+ }
73
+ const tools = this.createTools(options.excludeTools, options.variables, options.toolTimeout, options.useSearch);
67
74
  const allTools = { ...tools, ...this.mcpTools };
68
75
  // Use provided messages for continuation, or start fresh with the instruction
69
76
  const messages = options.messages?.length
@@ -236,7 +243,8 @@ export class V3AgentHandler {
236
243
  }
237
244
  catch (error) {
238
245
  // Re-throw validation errors that should propagate to the caller
239
- if (error instanceof StreamingCallbacksInNonStreamingModeError) {
246
+ if (error instanceof StreamingCallbacksInNonStreamingModeError ||
247
+ error instanceof MissingEnvironmentVariableError) {
240
248
  throw error;
241
249
  }
242
250
  // Re-throw abort errors wrapped in AgentAbortError for consistent error typing
@@ -379,7 +387,7 @@ export class V3AgentHandler {
379
387
  messages: inputMessages,
380
388
  };
381
389
  }
382
- createTools(excludeTools, variables, toolTimeout) {
390
+ createTools(excludeTools, variables, toolTimeout, useSearch) {
383
391
  const provider = this.llmClient?.getLanguageModel?.()?.provider;
384
392
  return createAgentTools(this.v3, {
385
393
  executionModel: this.executionModel,
@@ -389,6 +397,8 @@ export class V3AgentHandler {
389
397
  excludeTools,
390
398
  variables,
391
399
  toolTimeout,
400
+ useSearch,
401
+ browserbaseApiKey: useSearch ? this.v3.browserbaseApiKey : undefined,
392
402
  });
393
403
  }
394
404
  handleStop(result, maxSteps) {