@browserbasehq/orca 3.7.0-preview.1 → 3.7.2-gemini-cua

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 (165) hide show
  1. package/dist/cjs/lib/modelUtils.d.ts +10 -0
  2. package/dist/cjs/lib/modelUtils.js +11 -0
  3. package/dist/cjs/lib/modelUtils.js.map +1 -1
  4. package/dist/cjs/lib/v3/agent/AgentProvider.js +3 -0
  5. package/dist/cjs/lib/v3/agent/AgentProvider.js.map +1 -1
  6. package/dist/cjs/lib/v3/agent/GoogleCUAClient.d.ts +23 -0
  7. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js +363 -206
  8. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  9. package/dist/cjs/lib/v3/agent/tools/click.js +16 -5
  10. package/dist/cjs/lib/v3/agent/tools/click.js.map +1 -1
  11. package/dist/cjs/lib/v3/agent/tools/clickAndHold.js +1 -1
  12. package/dist/cjs/lib/v3/agent/tools/clickAndHold.js.map +1 -1
  13. package/dist/cjs/lib/v3/agent/tools/dragAndDrop.js +2 -2
  14. package/dist/cjs/lib/v3/agent/tools/dragAndDrop.js.map +1 -1
  15. package/dist/cjs/lib/v3/agent/tools/fillFormVision.js +18 -7
  16. package/dist/cjs/lib/v3/agent/tools/fillFormVision.js.map +1 -1
  17. package/dist/cjs/lib/v3/agent/tools/scroll.js +1 -1
  18. package/dist/cjs/lib/v3/agent/tools/scroll.js.map +1 -1
  19. package/dist/cjs/lib/v3/agent/tools/type.js +13 -4
  20. package/dist/cjs/lib/v3/agent/tools/type.js.map +1 -1
  21. package/dist/cjs/lib/v3/agent/utils/coordinateNormalization.d.ts +5 -2
  22. package/dist/cjs/lib/v3/agent/utils/coordinateNormalization.js +5 -7
  23. package/dist/cjs/lib/v3/agent/utils/coordinateNormalization.js.map +1 -1
  24. package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.js +3 -1
  25. package/dist/cjs/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -1
  26. package/dist/cjs/lib/v3/api.d.ts +1 -1
  27. package/dist/cjs/lib/v3/api.js +11 -1
  28. package/dist/cjs/lib/v3/api.js.map +1 -1
  29. package/dist/cjs/lib/v3/cache/AgentCache.js +6 -1
  30. package/dist/cjs/lib/v3/cache/AgentCache.js.map +1 -1
  31. package/dist/cjs/lib/v3/external_clients/aisdk.js +2 -0
  32. package/dist/cjs/lib/v3/external_clients/aisdk.js.map +1 -1
  33. package/dist/cjs/lib/v3/handlers/handlerUtils/actHandlerUtils.js +20 -0
  34. package/dist/cjs/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -1
  35. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +5 -4
  36. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  37. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.d.ts +4 -0
  38. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js +126 -20
  39. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  40. package/dist/cjs/lib/v3/index.d.ts +1 -1
  41. package/dist/cjs/lib/v3/launch/local.js +1 -1
  42. package/dist/cjs/lib/v3/launch/local.js.map +1 -1
  43. package/dist/cjs/lib/v3/llm/LLMProvider.js +9 -2
  44. package/dist/cjs/lib/v3/llm/LLMProvider.js.map +1 -1
  45. package/dist/cjs/lib/v3/llm/aisdk.js +5 -3
  46. package/dist/cjs/lib/v3/llm/aisdk.js.map +1 -1
  47. package/dist/cjs/lib/v3/llm/providerOptions.d.ts +7 -0
  48. package/dist/cjs/lib/v3/llm/providerOptions.js +9 -0
  49. package/dist/cjs/lib/v3/llm/providerOptions.js.map +1 -0
  50. package/dist/cjs/lib/v3/runtimePaths.js +0 -1
  51. package/dist/cjs/lib/v3/runtimePaths.js.map +1 -1
  52. package/dist/cjs/lib/v3/types/private/agent.d.ts +1 -1
  53. package/dist/cjs/lib/v3/types/private/agent.js +1 -0
  54. package/dist/cjs/lib/v3/types/private/agent.js.map +1 -1
  55. package/dist/cjs/lib/v3/types/public/agent.d.ts +1 -1
  56. package/dist/cjs/lib/v3/types/public/agent.js +3 -0
  57. package/dist/cjs/lib/v3/types/public/agent.js.map +1 -1
  58. package/dist/cjs/lib/v3/types/public/api.d.ts +53 -0
  59. package/dist/cjs/lib/v3/types/public/api.js +8 -0
  60. package/dist/cjs/lib/v3/types/public/api.js.map +1 -1
  61. package/dist/cjs/lib/v3/types/public/model.d.ts +12 -0
  62. package/dist/cjs/lib/v3/types/public/model.js.map +1 -1
  63. package/dist/cjs/lib/v3/types/public/options.d.ts +13 -0
  64. package/dist/cjs/lib/v3/types/public/options.js.map +1 -1
  65. package/dist/cjs/lib/v3/understudy/a11y/snapshot/capture.js +4 -3
  66. package/dist/cjs/lib/v3/understudy/a11y/snapshot/capture.js.map +1 -1
  67. package/dist/cjs/lib/v3/understudy/a11y/snapshot/coordinateResolver.js +39 -1
  68. package/dist/cjs/lib/v3/understudy/a11y/snapshot/coordinateResolver.js.map +1 -1
  69. package/dist/cjs/lib/v3/understudy/locator.d.ts +12 -0
  70. package/dist/cjs/lib/v3/understudy/locator.js +44 -0
  71. package/dist/cjs/lib/v3/understudy/locator.js.map +1 -1
  72. package/dist/cjs/lib/v3/understudy/page.d.ts +22 -3
  73. package/dist/cjs/lib/v3/understudy/page.js +55 -1
  74. package/dist/cjs/lib/v3/understudy/page.js.map +1 -1
  75. package/dist/cjs/lib/v3/v3.d.ts +14 -0
  76. package/dist/cjs/lib/v3/v3.js +81 -16
  77. package/dist/cjs/lib/v3/v3.js.map +1 -1
  78. package/dist/cjs/lib/v3/verifier/types.d.ts +3 -2
  79. package/dist/cjs/lib/v3/verifier/types.js.map +1 -1
  80. package/dist/cjs/lib/version.d.ts +1 -1
  81. package/dist/cjs/lib/version.js +1 -1
  82. package/dist/cjs/lib/version.js.map +1 -1
  83. package/dist/esm/lib/modelUtils.d.ts +10 -0
  84. package/dist/esm/lib/modelUtils.js +9 -0
  85. package/dist/esm/lib/modelUtils.js.map +1 -1
  86. package/dist/esm/lib/v3/agent/AgentProvider.js +3 -0
  87. package/dist/esm/lib/v3/agent/AgentProvider.js.map +1 -1
  88. package/dist/esm/lib/v3/agent/GoogleCUAClient.d.ts +23 -0
  89. package/dist/esm/lib/v3/agent/GoogleCUAClient.js +363 -206
  90. package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  91. package/dist/esm/lib/v3/agent/tools/click.js +16 -5
  92. package/dist/esm/lib/v3/agent/tools/click.js.map +1 -1
  93. package/dist/esm/lib/v3/agent/tools/clickAndHold.js +1 -1
  94. package/dist/esm/lib/v3/agent/tools/clickAndHold.js.map +1 -1
  95. package/dist/esm/lib/v3/agent/tools/dragAndDrop.js +2 -2
  96. package/dist/esm/lib/v3/agent/tools/dragAndDrop.js.map +1 -1
  97. package/dist/esm/lib/v3/agent/tools/fillFormVision.js +19 -8
  98. package/dist/esm/lib/v3/agent/tools/fillFormVision.js.map +1 -1
  99. package/dist/esm/lib/v3/agent/tools/scroll.js +1 -1
  100. package/dist/esm/lib/v3/agent/tools/scroll.js.map +1 -1
  101. package/dist/esm/lib/v3/agent/tools/type.js +13 -4
  102. package/dist/esm/lib/v3/agent/tools/type.js.map +1 -1
  103. package/dist/esm/lib/v3/agent/utils/coordinateNormalization.d.ts +5 -2
  104. package/dist/esm/lib/v3/agent/utils/coordinateNormalization.js +5 -7
  105. package/dist/esm/lib/v3/agent/utils/coordinateNormalization.js.map +1 -1
  106. package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js +3 -1
  107. package/dist/esm/lib/v3/agent/utils/handleDoneToolCall.js.map +1 -1
  108. package/dist/esm/lib/v3/api.d.ts +1 -1
  109. package/dist/esm/lib/v3/api.js +11 -1
  110. package/dist/esm/lib/v3/api.js.map +1 -1
  111. package/dist/esm/lib/v3/cache/AgentCache.js +6 -1
  112. package/dist/esm/lib/v3/cache/AgentCache.js.map +1 -1
  113. package/dist/esm/lib/v3/external_clients/aisdk.js +2 -0
  114. package/dist/esm/lib/v3/external_clients/aisdk.js.map +1 -1
  115. package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js +20 -0
  116. package/dist/esm/lib/v3/handlers/handlerUtils/actHandlerUtils.js.map +1 -1
  117. package/dist/esm/lib/v3/handlers/v3AgentHandler.js +5 -4
  118. package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  119. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.d.ts +4 -0
  120. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +126 -20
  121. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  122. package/dist/esm/lib/v3/index.d.ts +1 -1
  123. package/dist/esm/lib/v3/launch/local.js +1 -1
  124. package/dist/esm/lib/v3/launch/local.js.map +1 -1
  125. package/dist/esm/lib/v3/llm/LLMProvider.js +9 -2
  126. package/dist/esm/lib/v3/llm/LLMProvider.js.map +1 -1
  127. package/dist/esm/lib/v3/llm/aisdk.js +5 -3
  128. package/dist/esm/lib/v3/llm/aisdk.js.map +1 -1
  129. package/dist/esm/lib/v3/llm/providerOptions.d.ts +7 -0
  130. package/dist/esm/lib/v3/llm/providerOptions.js +6 -0
  131. package/dist/esm/lib/v3/llm/providerOptions.js.map +1 -0
  132. package/dist/esm/lib/v3/runtimePaths.js +0 -1
  133. package/dist/esm/lib/v3/runtimePaths.js.map +1 -1
  134. package/dist/esm/lib/v3/types/private/agent.d.ts +1 -1
  135. package/dist/esm/lib/v3/types/private/agent.js +1 -0
  136. package/dist/esm/lib/v3/types/private/agent.js.map +1 -1
  137. package/dist/esm/lib/v3/types/public/agent.d.ts +1 -1
  138. package/dist/esm/lib/v3/types/public/agent.js +3 -0
  139. package/dist/esm/lib/v3/types/public/agent.js.map +1 -1
  140. package/dist/esm/lib/v3/types/public/api.d.ts +53 -0
  141. package/dist/esm/lib/v3/types/public/api.js +8 -0
  142. package/dist/esm/lib/v3/types/public/api.js.map +1 -1
  143. package/dist/esm/lib/v3/types/public/model.d.ts +12 -0
  144. package/dist/esm/lib/v3/types/public/model.js.map +1 -1
  145. package/dist/esm/lib/v3/types/public/options.d.ts +13 -0
  146. package/dist/esm/lib/v3/types/public/options.js.map +1 -1
  147. package/dist/esm/lib/v3/understudy/a11y/snapshot/capture.js +4 -3
  148. package/dist/esm/lib/v3/understudy/a11y/snapshot/capture.js.map +1 -1
  149. package/dist/esm/lib/v3/understudy/a11y/snapshot/coordinateResolver.js +39 -1
  150. package/dist/esm/lib/v3/understudy/a11y/snapshot/coordinateResolver.js.map +1 -1
  151. package/dist/esm/lib/v3/understudy/locator.d.ts +12 -0
  152. package/dist/esm/lib/v3/understudy/locator.js +44 -0
  153. package/dist/esm/lib/v3/understudy/locator.js.map +1 -1
  154. package/dist/esm/lib/v3/understudy/page.d.ts +22 -3
  155. package/dist/esm/lib/v3/understudy/page.js +55 -1
  156. package/dist/esm/lib/v3/understudy/page.js.map +1 -1
  157. package/dist/esm/lib/v3/v3.d.ts +14 -0
  158. package/dist/esm/lib/v3/v3.js +82 -17
  159. package/dist/esm/lib/v3/v3.js.map +1 -1
  160. package/dist/esm/lib/v3/verifier/types.d.ts +3 -2
  161. package/dist/esm/lib/v3/verifier/types.js.map +1 -1
  162. package/dist/esm/lib/version.d.ts +1 -1
  163. package/dist/esm/lib/version.js +1 -1
  164. package/dist/esm/lib/version.js.map +1 -1
  165. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"fillFormVision.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/fillFormVision.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,wBAAwB,EA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EAAE,CAAC;gBAC3D,OAAO;oBACL,IAAI,EAAE,SAAS;oBACf,KAAK,EAAE;wBACL;4BACE,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gCACnB,OAAO,EAAE,MAAM,CAAC,OAAO;gCACvB,KAAK,EAAE,MAAM,CAAC,KAAK;6BACpB,CAAC;yBACH;qBACF;iBACF,CAAC;YACJ,CAAC;YAED,MAAM,OAAO,GAA6B;gBACxC;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;wBACnB,OAAO,EAAE,MAAM,CAAC,OAAO;wBACvB,WAAW,EAAE,MAAM,CAAC,mBAAmB,EAAE,MAAM,IAAI,CAAC;qBACrD,CAAC;iBACH;aACF,CAAC;YACF,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC;oBACX,IAAI,EAAE,OAAO;oBACb,SAAS,EAAE,WAAW;oBACtB,IAAI,EAAE,MAAM,CAAC,gBAAgB;iBAC9B,CAAC,CAAC;YACL,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type { Action } from \"../../types/public/methods.js\";\nimport type {\n FillFormVisionToolResult,\n ModelOutputContentItem,\n Variables,\n} from \"../../types/public/agent.js\";\nimport { processCoordinates } from \"../utils/coordinateNormalization.js\";\nimport { ensureXPath } from \"../utils/xpath.js\";\nimport { waitAndCaptureScreenshot } from \"../utils/screenshotHandler.js\";\nimport { substituteVariables } from \"../utils/variables.js\";\n\nexport const fillFormVisionTool = (\n v3: V3,\n provider?: string,\n variables?: Variables,\n) => {\n const hasVariables = variables && Object.keys(variables).length > 0;\n const valueDescription = hasVariables\n ? `Text to type into the target field. Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(\", \")}`\n : \"Text to type into the target field\";\n\n return tool({\n description: `FORM FILL - SPECIALIZED MULTI-FIELD INPUT TOOL\n\nCRITICAL: Use this for ANY form with 2+ input fields (text inputs, textareas, etc.)\nIMPORTANT: Ensure the fields are visible within the current viewport\n\nWHY THIS TOOL EXISTS:\n- Forms are the #1 use case for multi-field input\n- Optimized specifically for input/textarea elements\n- 4-6x faster than individual typing actions\n\nUse fillFormVision: Pure form filling (inputs, textareas only)\nMANDATORY USE CASES (always use fillFormVision for these):\n- Registration forms: name, email, password fields\n- Contact forms: name, email, message fields\n- Checkout forms: address, payment info fields\n- Profile updates: multiple user data fields\n- Search filters: multiple criteria inputs`,\n inputSchema: z.object({\n fields: z\n .array(\n z.object({\n action: z\n .string()\n .describe(\n \"Description of the typing action, e.g. 'type foo into the bar field'\",\n ),\n value: z.string().describe(valueDescription),\n coordinates: z\n .object({\n x: z.number(),\n y: z.number(),\n })\n .describe(\"Coordinates of the target field\"),\n }),\n )\n .min(2, \"Provide at least two fields to fill\"),\n }),\n execute: async ({ fields }): Promise<FillFormVisionToolResult> => {\n try {\n const page = await v3.context.awaitActivePage();\n\n // Process coordinates per field. Keep the original `value` (with any\n // `%variableName%` tokens) so substituted secrets never leak through\n // the tool result, replay cache, returned AgentResult.actions, or\n // anything that logs the action. Variables are substituted only at\n // typing time below.\n const safeFields = fields.map((field) => {\n const processed = processCoordinates(\n field.coordinates.x,\n field.coordinates.y,\n provider,\n v3,\n );\n return {\n action: field.action,\n value: field.value,\n coordinates: { x: processed.x, y: processed.y },\n };\n });\n\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: fillFormVision`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ fields }), // Don't log substituted values\n type: \"object\",\n },\n },\n });\n\n // Only request XPath when caching is enabled to avoid unnecessary computation\n const shouldCollectXpath = v3.isAgentReplayActive();\n const actions: Action[] = [];\n\n for (const field of safeFields) {\n // Click the field, only requesting XPath when caching is enabled\n const xpath = await page.click(\n field.coordinates.x,\n field.coordinates.y,\n {\n returnXpath: shouldCollectXpath,\n },\n );\n // Substitute variables only at the moment of typing so the resolved\n // value never leaves this scope.\n await page.type(substituteVariables(field.value, variables));\n\n // Build Action with XPath for deterministic replay (only when caching).\n // Store the placeholder value so cache entries don't contain secrets.\n if (shouldCollectXpath) {\n const normalizedXpath = ensureXPath(xpath);\n if (normalizedXpath) {\n actions.push({\n selector: normalizedXpath,\n description: field.action,\n method: \"type\",\n arguments: [field.value],\n });\n }\n }\n\n // Small delay between fields\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n\n const screenshotBase64 = await waitAndCaptureScreenshot(page, 100);\n\n // Record as \"act\" step with proper Actions for deterministic replay (only when caching)\n if (shouldCollectXpath && actions.length > 0) {\n v3.recordAgentReplayStep({\n type: \"act\",\n instruction: `Fill ${fields.length} form fields`,\n actions,\n actionDescription: `Fill ${fields.length} form fields`,\n });\n }\n\n return {\n success: true,\n playwrightArguments: safeFields,\n screenshotBase64,\n };\n } catch (error) {\n return {\n success: false,\n error: `Error filling form: ${error.message}`,\n };\n }\n },\n toModelOutput: (result) => {\n if (result.success === false || result.error !== undefined) {\n return {\n type: \"content\",\n value: [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n error: result.error,\n }),\n },\n ],\n };\n }\n\n const content: ModelOutputContentItem[] = [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n fieldsCount: result.playwrightArguments?.length ?? 0,\n }),\n },\n ];\n if (result.screenshotBase64) {\n content.push({\n type: \"media\",\n mediaType: \"image/png\",\n data: result.screenshotBase64,\n });\n }\n return { type: \"content\", value: content };\n },\n });\n};\n"]}
1
+ {"version":3,"file":"fillFormVision.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/fillFormVision.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,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BACb,SAAS,EAAE,WAAW;oBACtB,IAAI,EAAE,MAAM,CAAC,gBAAgB;iBAC9B,CAAC,CAAC;YACL,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type { Action } from \"../../types/public/methods.js\";\nimport type {\n FillFormVisionToolResult,\n ModelOutputContentItem,\n Variables,\n} from \"../../types/public/agent.js\";\nimport {\n isGoogleProvider,\n processCoordinates,\n} from \"../utils/coordinateNormalization.js\";\nimport { ensureXPath } from \"../utils/xpath.js\";\nimport { waitAndCaptureScreenshot } from \"../utils/screenshotHandler.js\";\nimport { substituteVariables } from \"../utils/variables.js\";\n\nexport const fillFormVisionTool = (\n v3: V3,\n provider?: string,\n variables?: Variables,\n) => {\n const hasVariables = variables && Object.keys(variables).length > 0;\n const valueDescription = hasVariables\n ? `Text to type into the target field. Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(\", \")}`\n : \"Text to type into the target field\";\n\n return tool({\n description: `FORM FILL - SPECIALIZED MULTI-FIELD INPUT TOOL\n\nCRITICAL: Use this for ANY form with 2+ input fields (text inputs, textareas, etc.)\nIMPORTANT: Ensure the fields are visible within the current viewport\n\nWHY THIS TOOL EXISTS:\n- Forms are the #1 use case for multi-field input\n- Optimized specifically for input/textarea elements\n- 4-6x faster than individual typing actions\n\nUse fillFormVision: Pure form filling (inputs, textareas only)\nMANDATORY USE CASES (always use fillFormVision for these):\n- Registration forms: name, email, password fields\n- Contact forms: name, email, message fields\n- Checkout forms: address, payment info fields\n- Profile updates: multiple user data fields\n- Search filters: multiple criteria inputs`,\n inputSchema: z.object({\n fields: z\n .array(\n z.object({\n action: z\n .string()\n .describe(\n \"Description of the typing action, e.g. 'type foo into the bar field'\",\n ),\n value: z.string().describe(valueDescription),\n coordinates: z\n .object({\n x: z.number(),\n y: z.number(),\n })\n .describe(\"Coordinates of the target field\"),\n }),\n )\n .min(2, \"Provide at least two fields to fill\"),\n }),\n execute: async ({ fields }): Promise<FillFormVisionToolResult> => {\n try {\n const page = await v3.context.awaitActivePage();\n const viewport = isGoogleProvider(provider)\n ? await v3.resolveViewport()\n : undefined;\n\n // Process coordinates per field. Keep the original `value` (with any\n // `%variableName%` tokens) so substituted secrets never leak through\n // the tool result, replay cache, returned AgentResult.actions, or\n // anything that logs the action. Variables are substituted only at\n // typing time below.\n const safeFields = await Promise.all(\n fields.map(async (field) => {\n const processed = await processCoordinates(\n field.coordinates.x,\n field.coordinates.y,\n provider,\n v3,\n viewport,\n );\n return {\n action: field.action,\n value: field.value,\n coordinates: { x: processed.x, y: processed.y },\n };\n }),\n );\n\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: fillFormVision`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ fields }), // Don't log substituted values\n type: \"object\",\n },\n },\n });\n\n // Only request XPath when caching is enabled to avoid unnecessary computation\n const shouldCollectXpath = v3.isAgentReplayActive();\n const actions: Action[] = [];\n\n for (const field of safeFields) {\n // Focus the field, only requesting XPath when caching is enabled. On a\n // touch session this must be a trusted tap — a synthesized mouse click\n // never registers on touch-gated mobile layouts, so the field would stay\n // unfocused and the value go nowhere. The recorded step stays a \"type\",\n // whose replay focuses via the selector rather than a pointer event.\n const xpath = v3.usesTouch\n ? await page.tap(field.coordinates.x, field.coordinates.y, {\n returnXpath: shouldCollectXpath,\n })\n : await page.click(field.coordinates.x, field.coordinates.y, {\n returnXpath: shouldCollectXpath,\n });\n // Substitute variables only at the moment of typing so the resolved\n // value never leaves this scope.\n await page.type(substituteVariables(field.value, variables));\n\n // Build Action with XPath for deterministic replay (only when caching).\n // Store the placeholder value so cache entries don't contain secrets.\n if (shouldCollectXpath) {\n const normalizedXpath = ensureXPath(xpath);\n if (normalizedXpath) {\n actions.push({\n selector: normalizedXpath,\n description: field.action,\n method: \"type\",\n arguments: [field.value],\n });\n }\n }\n\n // Small delay between fields\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n\n const screenshotBase64 = await waitAndCaptureScreenshot(page, 100);\n\n // Record as \"act\" step with proper Actions for deterministic replay (only when caching)\n if (shouldCollectXpath && actions.length > 0) {\n v3.recordAgentReplayStep({\n type: \"act\",\n instruction: `Fill ${fields.length} form fields`,\n actions,\n actionDescription: `Fill ${fields.length} form fields`,\n });\n }\n\n return {\n success: true,\n playwrightArguments: safeFields,\n screenshotBase64,\n };\n } catch (error) {\n return {\n success: false,\n error: `Error filling form: ${error.message}`,\n };\n }\n },\n toModelOutput: (result) => {\n if (result.success === false || result.error !== undefined) {\n return {\n type: \"content\",\n value: [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n error: result.error,\n }),\n },\n ],\n };\n }\n\n const content: ModelOutputContentItem[] = [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n fieldsCount: result.playwrightArguments?.length ?? 0,\n }),\n },\n ];\n if (result.screenshotBase64) {\n content.push({\n type: \"media\",\n mediaType: \"image/png\",\n data: result.screenshotBase64,\n });\n }\n return { type: \"content\", value: content };\n },\n });\n};\n"]}
@@ -81,7 +81,7 @@ export const scrollVisionTool = (v3, provider) => tool({
81
81
  let cx;
82
82
  let cy;
83
83
  if (coordinates) {
84
- const processed = processCoordinates(coordinates[0], coordinates[1], provider, v3);
84
+ const processed = await processCoordinates(coordinates[0], coordinates[1], provider, v3);
85
85
  cx = processed.x;
86
86
  cy = processed.y;
87
87
  }
@@ -1 +1 @@
1
- {"version":3,"file":"scroll.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/scroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE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MAAM,CAAC,EAAE,CAAC;aACxD,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAA6B;YACxC;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,cAAc,EAAE,MAAM,CAAC,cAAc;iBACtC,CAAC;aACH;SACF,CAAC;QACF,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;YAC5B,OAAO,CAAC,IAAI,CAAC;gBACX,IAAI,EAAE,OAAO;gBACb,SAAS,EAAE,WAAW;gBACtB,IAAI,EAAE,MAAM,CAAC,gBAAgB;aAC9B,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IAC7C,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type {\n ScrollToolResult,\n ScrollVisionToolResult,\n ModelOutputContentItem,\n} from \"../../types/public/agent.js\";\nimport { processCoordinates } from \"../utils/coordinateNormalization.js\";\nimport { waitAndCaptureScreenshot } from \"../utils/screenshotHandler.js\";\n\n/**\n * Simple scroll tool for DOM mode (non-grounding models).\n * No coordinates - scrolls from viewport center.\n */\nexport const scrollTool = (v3: V3) =>\n tool({\n description:\n \"Scroll the page up or down by a percentage of the viewport height. Default is 80%, and what should be typically used for general page scrolling\",\n inputSchema: z.object({\n direction: z.enum([\"up\", \"down\"]),\n percentage: z.number().min(1).max(200).optional(),\n }),\n execute: async ({\n direction,\n percentage = 80,\n }): Promise<ScrollToolResult> => {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: scroll`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ direction, percentage }),\n type: \"object\",\n },\n },\n });\n\n const page = await v3.context.awaitActivePage();\n\n const { w, h } = await page.mainFrame().evaluate<{\n w: number;\n h: number;\n }>(\"({ w: window.innerWidth, h: window.innerHeight })\");\n\n const scrollDistance = Math.round((h * percentage) / 100);\n const cx = Math.floor(w / 2);\n const cy = Math.floor(h / 2);\n const deltaY = direction === \"up\" ? -scrollDistance : scrollDistance;\n\n await page.scroll(cx, cy, 0, deltaY);\n\n v3.recordAgentReplayStep({\n type: \"scroll\",\n deltaX: 0,\n deltaY,\n anchor: { x: cx, y: cy },\n });\n\n return {\n success: true,\n message: `Scrolled ${percentage}% ${direction} (${scrollDistance}px)`,\n scrolledPixels: scrollDistance,\n };\n },\n toModelOutput: (result) => {\n if (result.success === false || result.error !== undefined) {\n return {\n type: \"content\",\n value: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n }\n\n return {\n type: \"json\",\n value: {\n success: result.success,\n message: result.message,\n scrolledPixels: result.scrolledPixels,\n },\n };\n },\n });\n\n/**\n * Scroll tool for hybrid mode (grounding models).\n * Supports optional coordinates for scrolling within nested scrollable elements.\n */\nexport const scrollVisionTool = (v3: V3, provider?: string) =>\n tool({\n description: `Scroll the page up or down. For general page scrolling, no coordinates needed. Only provide coordinates when scrolling inside a nested scrollable element (e.g., a dropdown menu, modal with overflow, or scrollable sidebar). Default is 80%, and what should be typically used for general page scrolling`,\n inputSchema: z.object({\n direction: z.enum([\"up\", \"down\"]),\n coordinates: z\n .array(z.number())\n .optional()\n .describe(\n \"Only use coordinates for scrolling inside a nested scrollable element - provide (x, y) within that element\",\n ),\n percentage: z.number().min(1).max(200).optional(),\n }),\n execute: async ({\n direction,\n coordinates,\n percentage = 80,\n }): Promise<ScrollVisionToolResult> => {\n const page = await v3.context.awaitActivePage();\n\n const { w, h } = await page.mainFrame().evaluate<{\n w: number;\n h: number;\n }>(\"({ w: window.innerWidth, h: window.innerHeight })\");\n\n // Process coordinates if provided, otherwise use viewport center\n let cx: number;\n let cy: number;\n if (coordinates) {\n const processed = processCoordinates(\n coordinates[0],\n coordinates[1],\n provider,\n v3,\n );\n cx = processed.x;\n cy = processed.y;\n } else {\n cx = Math.floor(w / 2);\n cy = Math.floor(h / 2);\n }\n\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: scroll`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({\n direction,\n coordinates,\n percentage,\n processed: { cx, cy },\n }),\n type: \"object\",\n },\n },\n });\n\n const scrollDistance = Math.round((h * percentage) / 100);\n const deltaY = direction === \"up\" ? -scrollDistance : scrollDistance;\n\n await page.scroll(cx, cy, 0, deltaY);\n\n const screenshotBase64 = await waitAndCaptureScreenshot(page, 100);\n\n v3.recordAgentReplayStep({\n type: \"scroll\",\n deltaX: 0,\n deltaY,\n anchor: { x: cx, y: cy },\n });\n\n return {\n success: true,\n message: coordinates\n ? `Scrolled ${percentage}% ${direction} at (${cx}, ${cy})`\n : `Scrolled ${percentage}% ${direction}`,\n scrolledPixels: scrollDistance,\n screenshotBase64,\n };\n },\n toModelOutput: (result) => {\n if (result.success === false || result.error !== undefined) {\n return {\n type: \"content\",\n value: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n }\n\n const content: ModelOutputContentItem[] = [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n message: result.message,\n scrolledPixels: result.scrolledPixels,\n }),\n },\n ];\n if (result.screenshotBase64) {\n content.push({\n type: \"media\",\n mediaType: \"image/png\",\n data: result.screenshotBase64,\n });\n }\n return { type: \"content\", value: content };\n },\n });\n"]}
1
+ {"version":3,"file":"scroll.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/scroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE;;;GAGG;AACH,MAAM,CAAC,MAAM,U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E,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,cAAc,EAAE,MAAM,CAAC,cAAc;iBACtC,CAAC;aACH;SACF,CAAC;QACF,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;YAC5B,OAAO,CAAC,IAAI,CAAC;gBACX,IAAI,EAAE,OAAO;gBACb,SAAS,EAAE,WAAW;gBACtB,IAAI,EAAE,MAAM,CAAC,gBAAgB;aAC9B,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IAC7C,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type {\n ScrollToolResult,\n ScrollVisionToolResult,\n ModelOutputContentItem,\n} from \"../../types/public/agent.js\";\nimport { processCoordinates } from \"../utils/coordinateNormalization.js\";\nimport { waitAndCaptureScreenshot } from \"../utils/screenshotHandler.js\";\n\n/**\n * Simple scroll tool for DOM mode (non-grounding models).\n * No coordinates - scrolls from viewport center.\n */\nexport const scrollTool = (v3: V3) =>\n tool({\n description:\n \"Scroll the page up or down by a percentage of the viewport height. Default is 80%, and what should be typically used for general page scrolling\",\n inputSchema: z.object({\n direction: z.enum([\"up\", \"down\"]),\n percentage: z.number().min(1).max(200).optional(),\n }),\n execute: async ({\n direction,\n percentage = 80,\n }): Promise<ScrollToolResult> => {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: scroll`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ direction, percentage }),\n type: \"object\",\n },\n },\n });\n\n const page = await v3.context.awaitActivePage();\n\n const { w, h } = await page.mainFrame().evaluate<{\n w: number;\n h: number;\n }>(\"({ w: window.innerWidth, h: window.innerHeight })\");\n\n const scrollDistance = Math.round((h * percentage) / 100);\n const cx = Math.floor(w / 2);\n const cy = Math.floor(h / 2);\n const deltaY = direction === \"up\" ? -scrollDistance : scrollDistance;\n\n await page.scroll(cx, cy, 0, deltaY);\n\n v3.recordAgentReplayStep({\n type: \"scroll\",\n deltaX: 0,\n deltaY,\n anchor: { x: cx, y: cy },\n });\n\n return {\n success: true,\n message: `Scrolled ${percentage}% ${direction} (${scrollDistance}px)`,\n scrolledPixels: scrollDistance,\n };\n },\n toModelOutput: (result) => {\n if (result.success === false || result.error !== undefined) {\n return {\n type: \"content\",\n value: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n }\n\n return {\n type: \"json\",\n value: {\n success: result.success,\n message: result.message,\n scrolledPixels: result.scrolledPixels,\n },\n };\n },\n });\n\n/**\n * Scroll tool for hybrid mode (grounding models).\n * Supports optional coordinates for scrolling within nested scrollable elements.\n */\nexport const scrollVisionTool = (v3: V3, provider?: string) =>\n tool({\n description: `Scroll the page up or down. For general page scrolling, no coordinates needed. Only provide coordinates when scrolling inside a nested scrollable element (e.g., a dropdown menu, modal with overflow, or scrollable sidebar). Default is 80%, and what should be typically used for general page scrolling`,\n inputSchema: z.object({\n direction: z.enum([\"up\", \"down\"]),\n coordinates: z\n .array(z.number())\n .optional()\n .describe(\n \"Only use coordinates for scrolling inside a nested scrollable element - provide (x, y) within that element\",\n ),\n percentage: z.number().min(1).max(200).optional(),\n }),\n execute: async ({\n direction,\n coordinates,\n percentage = 80,\n }): Promise<ScrollVisionToolResult> => {\n const page = await v3.context.awaitActivePage();\n\n const { w, h } = await page.mainFrame().evaluate<{\n w: number;\n h: number;\n }>(\"({ w: window.innerWidth, h: window.innerHeight })\");\n\n // Process coordinates if provided, otherwise use viewport center\n let cx: number;\n let cy: number;\n if (coordinates) {\n const processed = await processCoordinates(\n coordinates[0],\n coordinates[1],\n provider,\n v3,\n );\n cx = processed.x;\n cy = processed.y;\n } else {\n cx = Math.floor(w / 2);\n cy = Math.floor(h / 2);\n }\n\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: scroll`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({\n direction,\n coordinates,\n percentage,\n processed: { cx, cy },\n }),\n type: \"object\",\n },\n },\n });\n\n const scrollDistance = Math.round((h * percentage) / 100);\n const deltaY = direction === \"up\" ? -scrollDistance : scrollDistance;\n\n await page.scroll(cx, cy, 0, deltaY);\n\n const screenshotBase64 = await waitAndCaptureScreenshot(page, 100);\n\n v3.recordAgentReplayStep({\n type: \"scroll\",\n deltaX: 0,\n deltaY,\n anchor: { x: cx, y: cy },\n });\n\n return {\n success: true,\n message: coordinates\n ? `Scrolled ${percentage}% ${direction} at (${cx}, ${cy})`\n : `Scrolled ${percentage}% ${direction}`,\n scrolledPixels: scrollDistance,\n screenshotBase64,\n };\n },\n toModelOutput: (result) => {\n if (result.success === false || result.error !== undefined) {\n return {\n type: \"content\",\n value: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n }\n\n const content: ModelOutputContentItem[] = [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n message: result.message,\n scrolledPixels: result.scrolledPixels,\n }),\n },\n ];\n if (result.screenshotBase64) {\n content.push({\n type: \"media\",\n mediaType: \"image/png\",\n data: result.screenshotBase64,\n });\n }\n return { type: \"content\", value: content };\n },\n });\n"]}
@@ -23,7 +23,7 @@ export const typeTool = (v3, provider, variables) => {
23
23
  execute: async ({ describe, coordinates, text, }) => {
24
24
  try {
25
25
  const page = await v3.context.awaitActivePage();
26
- const processed = processCoordinates(coordinates[0], coordinates[1], provider, v3);
26
+ const processed = await processCoordinates(coordinates[0], coordinates[1], provider, v3);
27
27
  // Substitute any %variableName% tokens in the text
28
28
  const actualText = substituteVariables(text, variables);
29
29
  v3.logger({
@@ -39,9 +39,18 @@ export const typeTool = (v3, provider, variables) => {
39
39
  });
40
40
  // Only request XPath when caching is enabled to avoid unnecessary computation
41
41
  const shouldCollectXpath = v3.isAgentReplayActive();
42
- const xpath = await page.click(processed.x, processed.y, {
43
- returnXpath: shouldCollectXpath,
44
- });
42
+ // Focus the field the way the session's input actually works: on a touch
43
+ // session a synthesized mouse click never registers on touch-gated mobile
44
+ // layouts, so the field would stay unfocused and the text go nowhere.
45
+ // Only the actuation changes — the recorded step is a "type", whose replay
46
+ // focuses via the selector rather than a pointer event.
47
+ const xpath = v3.usesTouch
48
+ ? await page.tap(processed.x, processed.y, {
49
+ returnXpath: shouldCollectXpath,
50
+ })
51
+ : await page.click(processed.x, processed.y, {
52
+ returnXpath: shouldCollectXpath,
53
+ });
45
54
  await page.type(actualText);
46
55
  const screenshotBase64 = await waitAndCaptureScreenshot(page);
47
56
  // Record as an "act" step with proper Action for deterministic replay (only when caching)
@@ -1 +1 @@
1
- {"version":3,"file":"type.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAM,EAAE,QAAiB,EAAE,SAAqB,EAAE,EAAE;IAC3E,MAAM,YAAY,GAAG,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACpE,MAAM,eAAe,GAAG,YAAY;QAClC,CAAC,CAAC,oGAAoG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACzI,CAAC,CAAC,mCAAmC,CAAC;IAExC,OAAO,IAAI,CAAC;QACV,WAA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AM;oBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;wBACnB,OAAO,EAAE,MAAM,CAAC,OAAO;wBACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ;wBACzB,IAAI,EAAE,MAAM,CAAC,IAAI;qBAClB,CAAC;iBACH;aACF,CAAC;YACF,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC;oBACX,IAAI,EAAE,OAAO;oBACb,SAAS,EAAE,WAAW;oBACtB,IAAI,EAAE,MAAM,CAAC,gBAAgB;iBAC9B,CAAC,CAAC;YACL,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type { Action } from \"../../types/public/methods.js\";\nimport type {\n TypeToolResult,\n ModelOutputContentItem,\n Variables,\n} from \"../../types/public/agent.js\";\nimport { processCoordinates } from \"../utils/coordinateNormalization.js\";\nimport { ensureXPath } from \"../utils/xpath.js\";\nimport { waitAndCaptureScreenshot } from \"../utils/screenshotHandler.js\";\nimport { substituteVariables } from \"../utils/variables.js\";\n\nexport const typeTool = (v3: V3, provider?: string, variables?: Variables) => {\n const hasVariables = variables && Object.keys(variables).length > 0;\n const textDescription = hasVariables\n ? `The text to type into the element. Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(\", \")}`\n : \"The text to type into the element\";\n\n return tool({\n description:\n \"Type text into an element using its coordinates. This will click the element and then type the text into it (this is the most reliable way to type into an element, always use this over act, unless the element is not visible in the screenshot, but shown in ariaTree)\",\n inputSchema: z.object({\n describe: z\n .string()\n .describe(\n \"Describe the element to type into in a short, specific phrase that mentions the element type and a good visual description\",\n ),\n text: z.string().describe(textDescription),\n coordinates: z\n .array(z.number())\n .describe(\"The (x, y) coordinates to type into the element\"),\n }),\n execute: async ({\n describe,\n coordinates,\n text,\n }): Promise<TypeToolResult> => {\n try {\n const page = await v3.context.awaitActivePage();\n const processed = processCoordinates(\n coordinates[0],\n coordinates[1],\n provider,\n v3,\n );\n\n // Substitute any %variableName% tokens in the text\n const actualText = substituteVariables(text, variables);\n\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: type`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ describe, text }),\n type: \"object\",\n },\n },\n });\n\n // Only request XPath when caching is enabled to avoid unnecessary computation\n const shouldCollectXpath = v3.isAgentReplayActive();\n const xpath = await page.click(processed.x, processed.y, {\n returnXpath: shouldCollectXpath,\n });\n\n await page.type(actualText);\n\n const screenshotBase64 = await waitAndCaptureScreenshot(page);\n\n // Record as an \"act\" step with proper Action for deterministic replay (only when caching)\n if (shouldCollectXpath) {\n const normalizedXpath = ensureXPath(xpath);\n if (normalizedXpath) {\n const action: Action = {\n selector: normalizedXpath,\n description: describe,\n method: \"type\",\n arguments: [text],\n };\n v3.recordAgentReplayStep({\n type: \"act\",\n instruction: describe,\n actions: [action],\n actionDescription: describe,\n });\n }\n }\n\n return {\n success: true,\n describe,\n text, // Return original text (with %variableName% tokens) to avoid exposing sensitive values to LLM\n screenshotBase64,\n };\n } catch (error) {\n return {\n success: false,\n error: `Error typing: ${error.message}`,\n };\n }\n },\n toModelOutput: (result) => {\n if (result.success === false || result.error !== undefined) {\n return {\n type: \"content\",\n value: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n }\n\n const content: ModelOutputContentItem[] = [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n describe: result.describe,\n text: result.text,\n }),\n },\n ];\n if (result.screenshotBase64) {\n content.push({\n type: \"media\",\n mediaType: \"image/png\",\n data: result.screenshotBase64,\n });\n }\n return { type: \"content\", value: content };\n },\n });\n};\n"]}
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/type.ts"],"names":[],"mappings":"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AI,EAAE,OAAO;oBACb,SAAS,EAAE,WAAW;oBACtB,IAAI,EAAE,MAAM,CAAC,gBAAgB;iBAC9B,CAAC,CAAC;YACL,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { tool } from \"ai\";\nimport { z } from \"zod\";\nimport type { V3 } from \"../../v3.js\";\nimport type { Action } from \"../../types/public/methods.js\";\nimport type {\n TypeToolResult,\n ModelOutputContentItem,\n Variables,\n} from \"../../types/public/agent.js\";\nimport { processCoordinates } from \"../utils/coordinateNormalization.js\";\nimport { ensureXPath } from \"../utils/xpath.js\";\nimport { waitAndCaptureScreenshot } from \"../utils/screenshotHandler.js\";\nimport { substituteVariables } from \"../utils/variables.js\";\n\nexport const typeTool = (v3: V3, provider?: string, variables?: Variables) => {\n const hasVariables = variables && Object.keys(variables).length > 0;\n const textDescription = hasVariables\n ? `The text to type into the element. Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(\", \")}`\n : \"The text to type into the element\";\n\n return tool({\n description:\n \"Type text into an element using its coordinates. This will click the element and then type the text into it (this is the most reliable way to type into an element, always use this over act, unless the element is not visible in the screenshot, but shown in ariaTree)\",\n inputSchema: z.object({\n describe: z\n .string()\n .describe(\n \"Describe the element to type into in a short, specific phrase that mentions the element type and a good visual description\",\n ),\n text: z.string().describe(textDescription),\n coordinates: z\n .array(z.number())\n .describe(\"The (x, y) coordinates to type into the element\"),\n }),\n execute: async ({\n describe,\n coordinates,\n text,\n }): Promise<TypeToolResult> => {\n try {\n const page = await v3.context.awaitActivePage();\n const processed = await processCoordinates(\n coordinates[0],\n coordinates[1],\n provider,\n v3,\n );\n\n // Substitute any %variableName% tokens in the text\n const actualText = substituteVariables(text, variables);\n\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: type`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify({ describe, text }),\n type: \"object\",\n },\n },\n });\n\n // Only request XPath when caching is enabled to avoid unnecessary computation\n const shouldCollectXpath = v3.isAgentReplayActive();\n // Focus the field the way the session's input actually works: on a touch\n // session a synthesized mouse click never registers on touch-gated mobile\n // layouts, so the field would stay unfocused and the text go nowhere.\n // Only the actuation changes — the recorded step is a \"type\", whose replay\n // focuses via the selector rather than a pointer event.\n const xpath = v3.usesTouch\n ? await page.tap(processed.x, processed.y, {\n returnXpath: shouldCollectXpath,\n })\n : await page.click(processed.x, processed.y, {\n returnXpath: shouldCollectXpath,\n });\n\n await page.type(actualText);\n\n const screenshotBase64 = await waitAndCaptureScreenshot(page);\n\n // Record as an \"act\" step with proper Action for deterministic replay (only when caching)\n if (shouldCollectXpath) {\n const normalizedXpath = ensureXPath(xpath);\n if (normalizedXpath) {\n const action: Action = {\n selector: normalizedXpath,\n description: describe,\n method: \"type\",\n arguments: [text],\n };\n v3.recordAgentReplayStep({\n type: \"act\",\n instruction: describe,\n actions: [action],\n actionDescription: describe,\n });\n }\n }\n\n return {\n success: true,\n describe,\n text, // Return original text (with %variableName% tokens) to avoid exposing sensitive values to LLM\n screenshotBase64,\n };\n } catch (error) {\n return {\n success: false,\n error: `Error typing: ${error.message}`,\n };\n }\n },\n toModelOutput: (result) => {\n if (result.success === false || result.error !== undefined) {\n return {\n type: \"content\",\n value: [{ type: \"text\", text: JSON.stringify(result) }],\n };\n }\n\n const content: ModelOutputContentItem[] = [\n {\n type: \"text\",\n text: JSON.stringify({\n success: result.success,\n describe: result.describe,\n text: result.text,\n }),\n },\n ];\n if (result.screenshotBase64) {\n content.push({\n type: \"media\",\n mediaType: \"image/png\",\n data: result.screenshotBase64,\n });\n }\n return { type: \"content\", value: content };\n },\n });\n};\n"]}
@@ -7,7 +7,10 @@ export declare function normalizeGoogleCoordinates(x: number, y: number, viewpor
7
7
  x: number;
8
8
  y: number;
9
9
  };
10
- export declare function processCoordinates(x: number, y: number, provider?: string, v3?: V3): {
10
+ export declare function processCoordinates(x: number, y: number, provider?: string, v3?: V3, resolvedViewport?: {
11
+ width: number;
12
+ height: number;
13
+ }): Promise<{
11
14
  x: number;
12
15
  y: number;
13
- };
16
+ }>;
@@ -1,5 +1,3 @@
1
- // Default viewport for Browserbase managed fingerprinting mode
2
- const STEALTH_VIEWPORT = { width: 1288, height: 711 };
3
1
  export function isGoogleProvider(provider) {
4
2
  if (!provider)
5
3
  return false;
@@ -15,11 +13,11 @@ export function normalizeGoogleCoordinates(x, y, viewport) {
15
13
  y: Math.floor((clampedY / 1000) * viewport.height),
16
14
  };
17
15
  }
18
- export function processCoordinates(x, y, provider, v3) {
19
- if (isGoogleProvider(provider) && v3) {
20
- // Browserbase managed fingerprinting uses a fixed viewport fallback.
21
- const viewport = v3.isVerified ? STEALTH_VIEWPORT : v3.configuredViewport;
22
- return normalizeGoogleCoordinates(x, y, viewport);
16
+ export async function processCoordinates(x, y, provider, v3, resolvedViewport) {
17
+ if (isGoogleProvider(provider)) {
18
+ const viewport = resolvedViewport ?? (v3 ? await v3.resolveViewport() : undefined);
19
+ if (viewport)
20
+ return normalizeGoogleCoordinates(x, y, viewport);
23
21
  }
24
22
  return { x, y };
25
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"coordinateNormalization.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/utils/coordinateNormalization.ts"],"names":[],"mappings":"AAEA,+DAA+D;AAC/D,MAAM,gBAAgB,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AAEtD,MAAM,UAAU,gBAAgB,CAAC,QAAiB;IAChD,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5B,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACnD,CAAC;AAED,qEAAqE;AACrE,kCAAkC;AAClC,MAAM,UAAU,0BAA0B,CACxC,CAAS,EACT,CAAS,EACT,QAA2C;IAE3C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/C,OAAO;QACL,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;QACjD,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC;KACnD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,CAAS,EACT,CAAS,EACT,QAAiB,EACjB,EAAO;IAEP,IAAI,gBAAgB,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;QACrC,qEAAqE;QACrE,MAAM,QAAQ,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,kBAAkB,CAAC;QAC1E,OAAO,0BAA0B,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import type { V3 } from \"../../v3.js\";\n\n// Default viewport for Browserbase managed fingerprinting mode\nconst STEALTH_VIEWPORT = { width: 1288, height: 711 };\n\nexport function isGoogleProvider(provider?: string): boolean {\n if (!provider) return false;\n return provider.toLowerCase().includes(\"google\");\n}\n\n// Google returns coordinates in a 0-1000 range, we need to normalize\n// them to the viewport dimensions\nexport function normalizeGoogleCoordinates(\n x: number,\n y: number,\n viewport: { width: number; height: number },\n): { x: number; y: number } {\n const clampedX = Math.min(999, Math.max(0, x));\n const clampedY = Math.min(999, Math.max(0, y));\n return {\n x: Math.floor((clampedX / 1000) * viewport.width),\n y: Math.floor((clampedY / 1000) * viewport.height),\n };\n}\n\nexport function processCoordinates(\n x: number,\n y: number,\n provider?: string,\n v3?: V3,\n): { x: number; y: number } {\n if (isGoogleProvider(provider) && v3) {\n // Browserbase managed fingerprinting uses a fixed viewport fallback.\n const viewport = v3.isVerified ? STEALTH_VIEWPORT : v3.configuredViewport;\n return normalizeGoogleCoordinates(x, y, viewport);\n }\n return { x, y };\n}\n"]}
1
+ {"version":3,"file":"coordinateNormalization.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/utils/coordinateNormalization.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gBAAgB,CAAC,QAAiB;IAChD,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5B,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACnD,CAAC;AAED,qEAAqE;AACrE,kCAAkC;AAClC,MAAM,UAAU,0BAA0B,CACxC,CAAS,EACT,CAAS,EACT,QAA2C;IAE3C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/C,OAAO;QACL,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;QACjD,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC;KACnD,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,CAAS,EACT,CAAS,EACT,QAAiB,EACjB,EAAO,EACP,gBAAoD;IAEpD,IAAI,gBAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/B,MAAM,QAAQ,GACZ,gBAAgB,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACpE,IAAI,QAAQ;YAAE,OAAO,0BAA0B,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import type { V3 } from \"../../v3.js\";\n\nexport function isGoogleProvider(provider?: string): boolean {\n if (!provider) return false;\n return provider.toLowerCase().includes(\"google\");\n}\n\n// Google returns coordinates in a 0-1000 range, we need to normalize\n// them to the viewport dimensions\nexport function normalizeGoogleCoordinates(\n x: number,\n y: number,\n viewport: { width: number; height: number },\n): { x: number; y: number } {\n const clampedX = Math.min(999, Math.max(0, x));\n const clampedY = Math.min(999, Math.max(0, y));\n return {\n x: Math.floor((clampedX / 1000) * viewport.width),\n y: Math.floor((clampedY / 1000) * viewport.height),\n };\n}\n\nexport async function processCoordinates(\n x: number,\n y: number,\n provider?: string,\n v3?: V3,\n resolvedViewport?: { width: number; height: number },\n): Promise<{ x: number; y: number }> {\n if (isGoogleProvider(provider)) {\n const viewport =\n resolvedViewport ?? (v3 ? await v3.resolveViewport() : undefined);\n if (viewport) return normalizeGoogleCoordinates(x, y, viewport);\n }\n return { x, y };\n}\n"]}
@@ -3,6 +3,7 @@ import { z } from "zod";
3
3
  import { tool } from "ai";
4
4
  import { anthropicFallbacksOptions, rejectsForcedToolUse, } from "../../llm/anthropicOptions.js";
5
5
  import { getZFactory } from "../../../utils.js";
6
+ import { openAIStoreProviderOptions } from "../../llm/providerOptions.js";
6
7
  /**
7
8
  * Deep-remove `undefined` values from the run history before it is re-submitted
8
9
  * to the forced "done" call.
@@ -105,6 +106,7 @@ Call the "done" tool with:
105
106
  : "Provide your final assessment.",
106
107
  };
107
108
  const modelId = typeof model === "string" ? model : model.modelId;
109
+ const modelProvider = typeof model === "string" ? undefined : model.provider;
108
110
  const fallbacks = anthropicFallbacksOptions(modelId);
109
111
  // Models whose always-on thinking rejects forced tool use go straight to
110
112
  // "auto" — the prompt already instructs calling "done", and the
@@ -119,7 +121,7 @@ Call the "done" tool with:
119
121
  : { type: "tool", toolName: "done" },
120
122
  providerOptions: {
121
123
  google: { mediaResolution: "MEDIA_RESOLUTION_HIGH" },
122
- openai: { store: false },
124
+ ...openAIStoreProviderOptions(modelProvider),
123
125
  ...(fallbacks ? { anthropic: fallbacks } : {}),
124
126
  },
125
127
  });
@@ -1 +1 @@
1
- {"version":3,"file":"handleDoneToolCall.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/utils/handleDoneToolCall.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAwC,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE1B,OAAO,EACL,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAUhD;;;;;;;;;;;;;;;;GAgBG;AACH,SAAS,kBAAkB,CAAI,KAAQ;IACrC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAiB,CAAC;IACjE,CAAC;IACD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC3C,IAAI,KAAK,KAAK,MAAM,C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C,SAAS;QAC1B,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,QAAQ,EAAE,cAAc;QACxB,MAAM,EAAE,KAAK,CAAC,MAAM;KACrB,CAAC;AACJ,CAAC","sourcesContent":["import { generateText, ModelMessage, LanguageModel, ToolSet } from \"ai\";\nimport { z } from \"zod\";\nimport { tool } from \"ai\";\nimport { LogLine } from \"../../types/public/logs.js\";\nimport {\n anthropicFallbacksOptions,\n rejectsForcedToolUse,\n} from \"../../llm/anthropicOptions.js\";\nimport { StagehandZodObject } from \"../../zodCompat.js\";\nimport { getZFactory } from \"../../../utils.js\";\nimport type { StagehandZodSchema } from \"../../zodCompat.js\";\n\ninterface DoneResult {\n reasoning: string;\n taskComplete: boolean;\n messages: ModelMessage[];\n output?: Record<string, unknown>;\n}\n\n/**\n * Deep-remove `undefined` values from the run history before it is re-submitted\n * to the forced \"done\" call.\n *\n * The AI SDK validates re-submitted messages against its `ModelMessage` schema,\n * whose JSON-value schema rejects `undefined` (only null/string/number/boolean/\n * object/array are allowed). A custom tool that returns an object with an\n * optional field left `undefined` (e.g. `{ matchedExpected: undefined }`) lands\n * that `undefined` inside a tool-result `output.value`, and reasoning models can\n * leave `undefined` in part fields too. Either makes the forced \"done\" call\n * throw `Invalid prompt: messages must be a ModelMessage[]` (STG-2335) — a red\n * error that fires after the run has already completed. Stripping `undefined`\n * keeps the history valid without dropping any real content.\n *\n * Only plain objects and arrays are traversed; class instances (URL, typed\n * arrays for binary image data, Date, …) are passed through untouched.\n */\nfunction stripUndefinedDeep<T>(value: T): T {\n if (Array.isArray(value)) {\n return value.map((v) => stripUndefinedDeep(v)) as unknown as T;\n }\n if (value !== null && typeof value === \"object\") {\n const proto = Object.getPrototypeOf(value);\n if (proto === Object.prototype || proto === null) {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n if (v !== undefined) out[k] = stripUndefinedDeep(v);\n }\n return out as T;\n }\n }\n return value;\n}\n\nexport function sanitizeMessagesForResubmission(\n messages: ModelMessage[],\n): ModelMessage[] {\n return stripUndefinedDeep(messages);\n}\n\nfunction buildBaseDoneSchema(factory: typeof z) {\n return factory.object({\n reasoning: factory\n .string()\n .describe(\"Brief summary of what actions were taken and the outcome\"),\n taskComplete: factory\n .boolean()\n .describe(\"true if the task was fully completed, false otherwise\"),\n });\n}\n\n/**\n * Force a done tool call at the end of an agent run.\n * This ensures we always get a structured final response,\n * even if the main loop ended without calling done.\n */\nexport async function handleDoneToolCall(options: {\n model: LanguageModel;\n inputMessages: ModelMessage[];\n instruction: string;\n outputSchema?: StagehandZodObject;\n logger: (message: LogLine) => void;\n}): Promise<DoneResult> {\n const { model, inputMessages, instruction, outputSchema, logger } = options;\n\n logger({\n category: \"agent\",\n message: \"Agent calling tool: done\",\n level: 1,\n });\n // Use the same Zod version as the user's outputSchema to avoid v3/v4 mixing\n const factory = outputSchema\n ? getZFactory(outputSchema as StagehandZodSchema)\n : z;\n const baseDoneSchema = buildBaseDoneSchema(factory);\n\n // Merge base done schema with user-provided output schema if present\n const doneToolSchema = outputSchema\n ? baseDoneSchema.extend({\n output: outputSchema.describe(\n \"The specific data the user requested from this task\",\n ),\n })\n : baseDoneSchema;\n\n const outputInstructions = outputSchema\n ? `\\n\\nThe user also requested the following information from this task. Provide it in the \"output\" field:\\n${JSON.stringify(\n Object.fromEntries(\n Object.entries(outputSchema.shape).map(\n ([key, value]: [string, StagehandZodSchema]) => [\n key,\n value.description || \"no description\",\n ],\n ),\n ),\n null,\n 2,\n )}`\n : \"\";\n\n const systemPrompt = `You are a web automation assistant that was tasked with completing a task.\n\nThe task was:\n\"${instruction}\"\n\nReview what was accomplished and provide your final assessment in whether the task was completed successfully. you have been provided with the history of the actions taken so far, use this to determine if the task was completed successfully.${outputInstructions}\n\nCall the \"done\" tool with:\n1. A brief summary of what was done\n2. Whether the task was completed successfully${outputSchema ? \"\\n3. The requested output data based on what you found\" : \"\"}`;\n\n const doneTool = tool({\n description: outputSchema\n ? \"Complete the task with your assessment and the requested output data.\"\n : \"Complete the task with your final assessment.\",\n inputSchema: doneToolSchema,\n execute: async (params) => {\n return { success: true, ...params };\n },\n });\n\n const userPrompt: ModelMessage = {\n role: \"user\",\n content: outputSchema\n ? \"Provide your final assessment and the requested output data.\"\n : \"Provide your final assessment.\",\n };\n\n const modelId = typeof model === \"string\" ? model : model.modelId;\n const fallbacks = anthropicFallbacksOptions(modelId);\n\n // Models whose always-on thinking rejects forced tool use go straight to\n // \"auto\" — the prompt already instructs calling \"done\", and the\n // no-tool-call case below handles a plain-text answer.\n const result = await generateText({\n model,\n system: systemPrompt,\n messages: [...sanitizeMessagesForResubmission(inputMessages), userPrompt],\n tools: { done: doneTool } as ToolSet,\n toolChoice: rejectsForcedToolUse(modelId)\n ? \"auto\"\n : { type: \"tool\", toolName: \"done\" },\n providerOptions: {\n google: { mediaResolution: \"MEDIA_RESOLUTION_HIGH\" },\n openai: { store: false },\n ...(fallbacks ? { anthropic: fallbacks } : {}),\n },\n });\n\n const doneToolCall = result.toolCalls?.find((tc) => tc.toolName === \"done\");\n const outputMessages: ModelMessage[] = [\n userPrompt,\n ...(result.response?.messages || []),\n ];\n\n if (!doneToolCall) {\n return {\n reasoning: result.text || \"Task execution completed\",\n taskComplete: false,\n messages: outputMessages,\n };\n }\n\n const input = doneToolCall.input as {\n reasoning: string;\n taskComplete: boolean;\n output?: Record<string, unknown>;\n };\n logger({\n category: \"agent\",\n message: `Task completed`,\n level: 1,\n });\n\n return {\n reasoning: input.reasoning,\n taskComplete: input.taskComplete,\n messages: outputMessages,\n output: input.output,\n };\n}\n"]}
1
+ {"version":3,"file":"handleDoneToolCall.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/utils/handleDoneToolCall.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAwC,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC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E,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/C;KACF,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC;IAC5E,MAAM,cAAc,GAAmB;QACrC,UAAU;QACV,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC;KACrC,CAAC;IAEF,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO;YACL,SAAS,EAAE,MAAM,CAAC,IAAI,IAAI,0BAA0B;YACpD,YAAY,EAAE,KAAK;YACnB,QAAQ,EAAE,cAAc;SACzB,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAG,YAAY,CAAC,KAI1B,CAAC;IACF,MAAM,CAAC;QACL,QAAQ,EAAE,OAAO;QACjB,OAAO,EAAE,gBAAgB;QACzB,KAAK,EAAE,CAAC;KACT,CAAC,CAAC;IAEH,OAAO;QACL,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,QAAQ,EAAE,cAAc;QACxB,MAAM,EAAE,KAAK,CAAC,MAAM;KACrB,CAAC;AACJ,CAAC","sourcesContent":["import { generateText, ModelMessage, LanguageModel, ToolSet } from \"ai\";\nimport { z } from \"zod\";\nimport { tool } from \"ai\";\nimport { LogLine } from \"../../types/public/logs.js\";\nimport {\n anthropicFallbacksOptions,\n rejectsForcedToolUse,\n} from \"../../llm/anthropicOptions.js\";\nimport { StagehandZodObject } from \"../../zodCompat.js\";\nimport { getZFactory } from \"../../../utils.js\";\nimport type { StagehandZodSchema } from \"../../zodCompat.js\";\nimport { openAIStoreProviderOptions } from \"../../llm/providerOptions.js\";\n\ninterface DoneResult {\n reasoning: string;\n taskComplete: boolean;\n messages: ModelMessage[];\n output?: Record<string, unknown>;\n}\n\n/**\n * Deep-remove `undefined` values from the run history before it is re-submitted\n * to the forced \"done\" call.\n *\n * The AI SDK validates re-submitted messages against its `ModelMessage` schema,\n * whose JSON-value schema rejects `undefined` (only null/string/number/boolean/\n * object/array are allowed). A custom tool that returns an object with an\n * optional field left `undefined` (e.g. `{ matchedExpected: undefined }`) lands\n * that `undefined` inside a tool-result `output.value`, and reasoning models can\n * leave `undefined` in part fields too. Either makes the forced \"done\" call\n * throw `Invalid prompt: messages must be a ModelMessage[]` (STG-2335) — a red\n * error that fires after the run has already completed. Stripping `undefined`\n * keeps the history valid without dropping any real content.\n *\n * Only plain objects and arrays are traversed; class instances (URL, typed\n * arrays for binary image data, Date, …) are passed through untouched.\n */\nfunction stripUndefinedDeep<T>(value: T): T {\n if (Array.isArray(value)) {\n return value.map((v) => stripUndefinedDeep(v)) as unknown as T;\n }\n if (value !== null && typeof value === \"object\") {\n const proto = Object.getPrototypeOf(value);\n if (proto === Object.prototype || proto === null) {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n if (v !== undefined) out[k] = stripUndefinedDeep(v);\n }\n return out as T;\n }\n }\n return value;\n}\n\nexport function sanitizeMessagesForResubmission(\n messages: ModelMessage[],\n): ModelMessage[] {\n return stripUndefinedDeep(messages);\n}\n\nfunction buildBaseDoneSchema(factory: typeof z) {\n return factory.object({\n reasoning: factory\n .string()\n .describe(\"Brief summary of what actions were taken and the outcome\"),\n taskComplete: factory\n .boolean()\n .describe(\"true if the task was fully completed, false otherwise\"),\n });\n}\n\n/**\n * Force a done tool call at the end of an agent run.\n * This ensures we always get a structured final response,\n * even if the main loop ended without calling done.\n */\nexport async function handleDoneToolCall(options: {\n model: LanguageModel;\n inputMessages: ModelMessage[];\n instruction: string;\n outputSchema?: StagehandZodObject;\n logger: (message: LogLine) => void;\n}): Promise<DoneResult> {\n const { model, inputMessages, instruction, outputSchema, logger } = options;\n\n logger({\n category: \"agent\",\n message: \"Agent calling tool: done\",\n level: 1,\n });\n // Use the same Zod version as the user's outputSchema to avoid v3/v4 mixing\n const factory = outputSchema\n ? getZFactory(outputSchema as StagehandZodSchema)\n : z;\n const baseDoneSchema = buildBaseDoneSchema(factory);\n\n // Merge base done schema with user-provided output schema if present\n const doneToolSchema = outputSchema\n ? baseDoneSchema.extend({\n output: outputSchema.describe(\n \"The specific data the user requested from this task\",\n ),\n })\n : baseDoneSchema;\n\n const outputInstructions = outputSchema\n ? `\\n\\nThe user also requested the following information from this task. Provide it in the \"output\" field:\\n${JSON.stringify(\n Object.fromEntries(\n Object.entries(outputSchema.shape).map(\n ([key, value]: [string, StagehandZodSchema]) => [\n key,\n value.description || \"no description\",\n ],\n ),\n ),\n null,\n 2,\n )}`\n : \"\";\n\n const systemPrompt = `You are a web automation assistant that was tasked with completing a task.\n\nThe task was:\n\"${instruction}\"\n\nReview what was accomplished and provide your final assessment in whether the task was completed successfully. you have been provided with the history of the actions taken so far, use this to determine if the task was completed successfully.${outputInstructions}\n\nCall the \"done\" tool with:\n1. A brief summary of what was done\n2. Whether the task was completed successfully${outputSchema ? \"\\n3. The requested output data based on what you found\" : \"\"}`;\n\n const doneTool = tool({\n description: outputSchema\n ? \"Complete the task with your assessment and the requested output data.\"\n : \"Complete the task with your final assessment.\",\n inputSchema: doneToolSchema,\n execute: async (params) => {\n return { success: true, ...params };\n },\n });\n\n const userPrompt: ModelMessage = {\n role: \"user\",\n content: outputSchema\n ? \"Provide your final assessment and the requested output data.\"\n : \"Provide your final assessment.\",\n };\n\n const modelId = typeof model === \"string\" ? model : model.modelId;\n const modelProvider = typeof model === \"string\" ? undefined : model.provider;\n const fallbacks = anthropicFallbacksOptions(modelId);\n\n // Models whose always-on thinking rejects forced tool use go straight to\n // \"auto\" — the prompt already instructs calling \"done\", and the\n // no-tool-call case below handles a plain-text answer.\n const result = await generateText({\n model,\n system: systemPrompt,\n messages: [...sanitizeMessagesForResubmission(inputMessages), userPrompt],\n tools: { done: doneTool } as ToolSet,\n toolChoice: rejectsForcedToolUse(modelId)\n ? \"auto\"\n : { type: \"tool\", toolName: \"done\" },\n providerOptions: {\n google: { mediaResolution: \"MEDIA_RESOLUTION_HIGH\" },\n ...openAIStoreProviderOptions(modelProvider),\n ...(fallbacks ? { anthropic: fallbacks } : {}),\n },\n });\n\n const doneToolCall = result.toolCalls?.find((tc) => tc.toolName === \"done\");\n const outputMessages: ModelMessage[] = [\n userPrompt,\n ...(result.response?.messages || []),\n ];\n\n if (!doneToolCall) {\n return {\n reasoning: result.text || \"Task execution completed\",\n taskComplete: false,\n messages: outputMessages,\n };\n }\n\n const input = doneToolCall.input as {\n reasoning: string;\n taskComplete: boolean;\n output?: Record<string, unknown>;\n };\n logger({\n category: \"agent\",\n message: `Task completed`,\n level: 1,\n });\n\n return {\n reasoning: input.reasoning,\n taskComplete: input.taskComplete,\n messages: outputMessages,\n output: input.output,\n };\n}\n"]}
@@ -91,7 +91,7 @@ export declare class StagehandAPIClient {
91
91
  private latestAgentCacheEntry;
92
92
  private warnedStagehandBaseUrl;
93
93
  constructor({ apiKey, projectId, logger, serverCache, }: StagehandAPIConstructorParams);
94
- init({ modelName, modelApiKey, defaultModelConfig, domSettleTimeoutMs, verbose, systemPrompt, selfHeal, browserbaseSessionCreateParams, browserbaseSessionID, }: ClientSessionStartParams): Promise<Api.SessionStartResult>;
94
+ init({ modelName, modelApiKey, defaultModelConfig, domSettleTimeoutMs, verbose, systemPrompt, selfHeal, useTouch, browserbaseSessionCreateParams, browserbaseSessionID, }: ClientSessionStartParams): Promise<Api.SessionStartResult>;
95
95
  act({ input, options, frameId, }: ClientActParameters): Promise<ActResult>;
96
96
  extract<T extends StagehandZodSchema>({ instruction, schema: zodSchema, options, frameId, }: ClientExtractParameters): Promise<ExtractResult<T>>;
97
97
  observe({ instruction, options, frameId, }: ClientObserveParameters): Promise<ObserveResult>;
@@ -1,5 +1,6 @@
1
1
  import makeFetchCookie from "fetch-cookie";
2
2
  import { getInheritableModelOptions, hasModelProviderAuth, loadApiKeyFromEnv, } from "../utils.js";
3
+ import { isAutoModel } from "../modelUtils.js";
3
4
  import { STAGEHAND_VERSION } from "../version.js";
4
5
  import { StagehandAPIError, StagehandAPIUnauthorizedError, StagehandHttpError, StagehandResponseBodyError, StagehandResponseParseError, StagehandServerError, ExperimentalNotConfiguredError, } from "./types/public/index.js";
5
6
  import { toJsonSchema } from "./zodCompat.js";
@@ -51,7 +52,7 @@ export class StagehandAPIClient {
51
52
  // Create a single cookie jar instance that will persist across all requests
52
53
  this.fetchWithCookies = makeFetchCookie(fetch);
53
54
  }
54
- async init({ modelName, modelApiKey, defaultModelConfig, domSettleTimeoutMs, verbose, systemPrompt, selfHeal, browserbaseSessionCreateParams, browserbaseSessionID,
55
+ async init({ modelName, modelApiKey, defaultModelConfig, domSettleTimeoutMs, verbose, systemPrompt, selfHeal, useTouch, browserbaseSessionCreateParams, browserbaseSessionID,
55
56
  // browser, TODO for local browsers
56
57
  }) {
57
58
  this.modelApiKey = modelApiKey;
@@ -76,6 +77,7 @@ export class StagehandAPIClient {
76
77
  verbose,
77
78
  systemPrompt,
78
79
  selfHeal,
80
+ useTouch,
79
81
  browserbaseSessionCreateParams,
80
82
  browserbaseSessionID,
81
83
  // browser, TODO: only send when connected to local fastify
@@ -412,6 +414,14 @@ export class StagehandAPIClient {
412
414
  * model provider differs from the one used to init the session.
413
415
  */
414
416
  prepareModelConfig(model) {
417
+ // "auto" delegates model selection to the API, so never inherit the
418
+ // default model's provider config or API key — the server picks the
419
+ // provider. Explicit per-call options are still passed through.
420
+ if (isAutoModel(model)) {
421
+ return typeof model === "string"
422
+ ? { modelName: model }
423
+ : { ...model };
424
+ }
415
425
  if (typeof model === "string") {
416
426
  // Extract provider from model string (e.g., "openai/gpt-5-nano" -> "openai")
417
427
  const provider = this.getModelProvider(model);