@browserbasehq/orca 3.2.0-preview.4 → 3.2.0-preview.5

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 (195) hide show
  1. package/dist/cjs/lib/inference.d.ts +3 -1
  2. package/dist/cjs/lib/inference.js +2 -2
  3. package/dist/cjs/lib/inference.js.map +1 -1
  4. package/dist/cjs/lib/prompt.d.ts +1 -1
  5. package/dist/cjs/lib/prompt.js +11 -2
  6. package/dist/cjs/lib/prompt.js.map +1 -1
  7. package/dist/cjs/lib/v3/agent/AgentClient.d.ts +8 -0
  8. package/dist/cjs/lib/v3/agent/AgentClient.js +13 -0
  9. package/dist/cjs/lib/v3/agent/AgentClient.js.map +1 -1
  10. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js +1 -0
  11. package/dist/cjs/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  12. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js +1 -0
  13. package/dist/cjs/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  14. package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js +1 -0
  15. package/dist/cjs/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
  16. package/dist/cjs/lib/v3/agent/OpenAICUAClient.d.ts +4 -4
  17. package/dist/cjs/lib/v3/agent/OpenAICUAClient.js +62 -1
  18. package/dist/cjs/lib/v3/agent/OpenAICUAClient.js.map +1 -1
  19. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -2
  20. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js +10 -11
  21. package/dist/cjs/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
  22. package/dist/cjs/lib/v3/agent/tools/fillform.d.ts +0 -1
  23. package/dist/cjs/lib/v3/agent/tools/fillform.js +7 -10
  24. package/dist/cjs/lib/v3/agent/tools/fillform.js.map +1 -1
  25. package/dist/cjs/lib/v3/agent/utils/captchaSolver.d.ts +76 -0
  26. package/dist/cjs/lib/v3/agent/utils/captchaSolver.js +175 -0
  27. package/dist/cjs/lib/v3/agent/utils/captchaSolver.js.map +1 -0
  28. package/dist/cjs/lib/v3/agent/utils/variables.d.ts +5 -0
  29. package/dist/cjs/lib/v3/agent/utils/variables.js +9 -0
  30. package/dist/cjs/lib/v3/agent/utils/variables.js.map +1 -1
  31. package/dist/cjs/lib/v3/api.js +2 -9
  32. package/dist/cjs/lib/v3/api.js.map +1 -1
  33. package/dist/cjs/lib/v3/flowlogger/EventStore.js +1 -1
  34. package/dist/cjs/lib/v3/flowlogger/EventStore.js.map +1 -1
  35. package/dist/cjs/lib/v3/handlers/observeHandler.js +2 -1
  36. package/dist/cjs/lib/v3/handlers/observeHandler.js.map +1 -1
  37. package/dist/cjs/lib/v3/handlers/v3AgentHandler.d.ts +2 -1
  38. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js +110 -46
  39. package/dist/cjs/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  40. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.d.ts +5 -0
  41. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js +125 -1
  42. package/dist/cjs/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  43. package/dist/cjs/lib/v3/types/private/cache.d.ts +0 -1
  44. package/dist/cjs/lib/v3/types/private/cache.js.map +1 -1
  45. package/dist/cjs/lib/v3/types/private/handlers.d.ts +1 -0
  46. package/dist/cjs/lib/v3/types/private/handlers.js.map +1 -1
  47. package/dist/cjs/lib/v3/types/public/api.d.ts +24 -7
  48. package/dist/cjs/lib/v3/types/public/api.js +41 -14
  49. package/dist/cjs/lib/v3/types/public/api.js.map +1 -1
  50. package/dist/cjs/lib/v3/types/public/methods.d.ts +1 -0
  51. package/dist/cjs/lib/v3/types/public/methods.js.map +1 -1
  52. package/dist/cjs/lib/v3/types/public/variables.d.ts +7 -0
  53. package/dist/cjs/lib/v3/types/public/variables.js +22 -0
  54. package/dist/cjs/lib/v3/types/public/variables.js.map +1 -0
  55. package/dist/cjs/lib/v3/v3.d.ts +5 -0
  56. package/dist/cjs/lib/v3/v3.js +19 -4
  57. package/dist/cjs/lib/v3/v3.js.map +1 -1
  58. package/dist/cjs/lib/version.d.ts +1 -1
  59. package/dist/cjs/lib/version.js +1 -1
  60. package/dist/cjs/lib/version.js.map +1 -1
  61. package/dist/cjs/tests/integration/agent-captcha-autosolve.spec.d.ts +1 -0
  62. package/dist/cjs/tests/integration/agent-captcha-autosolve.spec.js +56 -0
  63. package/dist/cjs/tests/integration/agent-captcha-autosolve.spec.js.map +1 -0
  64. package/dist/cjs/tests/integration/agent-hybrid-mode.spec.js +6 -6
  65. package/dist/cjs/tests/integration/agent-hybrid-mode.spec.js.map +1 -1
  66. package/dist/cjs/tests/integration/timeouts.spec.js +1 -1
  67. package/dist/cjs/tests/integration/timeouts.spec.js.map +1 -1
  68. package/dist/cjs/tests/unit/agent-captcha-hooks.test.d.ts +1 -0
  69. package/dist/cjs/tests/unit/agent-captcha-hooks.test.js +285 -0
  70. package/dist/cjs/tests/unit/agent-captcha-hooks.test.js.map +1 -0
  71. package/dist/cjs/tests/unit/agent-execution-model.test.js +25 -3
  72. package/dist/cjs/tests/unit/agent-execution-model.test.js.map +1 -1
  73. package/dist/cjs/tests/unit/agent-system-prompt-variables.test.d.ts +1 -0
  74. package/dist/cjs/tests/unit/agent-system-prompt-variables.test.js +23 -0
  75. package/dist/cjs/tests/unit/agent-system-prompt-variables.test.js.map +1 -0
  76. package/dist/cjs/tests/unit/api-client-observe-variables.test.d.ts +1 -0
  77. package/dist/cjs/tests/unit/api-client-observe-variables.test.js +86 -0
  78. package/dist/cjs/tests/unit/api-client-observe-variables.test.js.map +1 -0
  79. package/dist/cjs/tests/unit/api-variables-schema.test.d.ts +1 -0
  80. package/dist/cjs/tests/unit/api-variables-schema.test.js +37 -0
  81. package/dist/cjs/tests/unit/api-variables-schema.test.js.map +1 -0
  82. package/dist/cjs/tests/unit/browserbase-session-accessors.test.js +20 -0
  83. package/dist/cjs/tests/unit/browserbase-session-accessors.test.js.map +1 -1
  84. package/dist/cjs/tests/unit/captcha-solver.test.d.ts +1 -0
  85. package/dist/cjs/tests/unit/captcha-solver.test.js +154 -0
  86. package/dist/cjs/tests/unit/captcha-solver.test.js.map +1 -0
  87. package/dist/cjs/tests/unit/flowlogger-eventstore.test.js +1 -1
  88. package/dist/cjs/tests/unit/flowlogger-eventstore.test.js.map +1 -1
  89. package/dist/cjs/tests/unit/openai-cua-client.test.d.ts +1 -0
  90. package/dist/cjs/tests/unit/openai-cua-client.test.js +71 -0
  91. package/dist/cjs/tests/unit/openai-cua-client.test.js.map +1 -0
  92. package/dist/cjs/tests/unit/prompt-observe-variables.test.d.ts +1 -0
  93. package/dist/cjs/tests/unit/prompt-observe-variables.test.js +19 -0
  94. package/dist/cjs/tests/unit/prompt-observe-variables.test.js.map +1 -0
  95. package/dist/cjs/tests/unit/public-api/public-types.test.js.map +1 -1
  96. package/dist/cjs/tests/unit/timeout-handlers.test.js +50 -0
  97. package/dist/cjs/tests/unit/timeout-handlers.test.js.map +1 -1
  98. package/dist/esm/lib/inference.d.ts +3 -1
  99. package/dist/esm/lib/inference.js +2 -2
  100. package/dist/esm/lib/inference.js.map +1 -1
  101. package/dist/esm/lib/prompt.d.ts +1 -1
  102. package/dist/esm/lib/prompt.js +11 -2
  103. package/dist/esm/lib/prompt.js.map +1 -1
  104. package/dist/esm/lib/v3/agent/AgentClient.d.ts +8 -0
  105. package/dist/esm/lib/v3/agent/AgentClient.js +13 -0
  106. package/dist/esm/lib/v3/agent/AgentClient.js.map +1 -1
  107. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js +1 -0
  108. package/dist/esm/lib/v3/agent/AnthropicCUAClient.js.map +1 -1
  109. package/dist/esm/lib/v3/agent/GoogleCUAClient.js +1 -0
  110. package/dist/esm/lib/v3/agent/GoogleCUAClient.js.map +1 -1
  111. package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js +1 -0
  112. package/dist/esm/lib/v3/agent/MicrosoftCUAClient.js.map +1 -1
  113. package/dist/esm/lib/v3/agent/OpenAICUAClient.d.ts +4 -4
  114. package/dist/esm/lib/v3/agent/OpenAICUAClient.js +62 -1
  115. package/dist/esm/lib/v3/agent/OpenAICUAClient.js.map +1 -1
  116. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.d.ts +2 -2
  117. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js +10 -11
  118. package/dist/esm/lib/v3/agent/prompts/agentSystemPrompt.js.map +1 -1
  119. package/dist/esm/lib/v3/agent/tools/fillform.d.ts +0 -1
  120. package/dist/esm/lib/v3/agent/tools/fillform.js +7 -10
  121. package/dist/esm/lib/v3/agent/tools/fillform.js.map +1 -1
  122. package/dist/esm/lib/v3/agent/utils/captchaSolver.d.ts +76 -0
  123. package/dist/esm/lib/v3/agent/utils/captchaSolver.js +171 -0
  124. package/dist/esm/lib/v3/agent/utils/captchaSolver.js.map +1 -0
  125. package/dist/esm/lib/v3/agent/utils/variables.d.ts +5 -0
  126. package/dist/esm/lib/v3/agent/utils/variables.js +8 -0
  127. package/dist/esm/lib/v3/agent/utils/variables.js.map +1 -1
  128. package/dist/esm/lib/v3/api.js +2 -9
  129. package/dist/esm/lib/v3/api.js.map +1 -1
  130. package/dist/esm/lib/v3/flowlogger/EventStore.js +1 -1
  131. package/dist/esm/lib/v3/flowlogger/EventStore.js.map +1 -1
  132. package/dist/esm/lib/v3/handlers/observeHandler.js +2 -1
  133. package/dist/esm/lib/v3/handlers/observeHandler.js.map +1 -1
  134. package/dist/esm/lib/v3/handlers/v3AgentHandler.d.ts +2 -1
  135. package/dist/esm/lib/v3/handlers/v3AgentHandler.js +110 -46
  136. package/dist/esm/lib/v3/handlers/v3AgentHandler.js.map +1 -1
  137. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.d.ts +5 -0
  138. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js +125 -1
  139. package/dist/esm/lib/v3/handlers/v3CuaAgentHandler.js.map +1 -1
  140. package/dist/esm/lib/v3/types/private/cache.d.ts +0 -1
  141. package/dist/esm/lib/v3/types/private/cache.js.map +1 -1
  142. package/dist/esm/lib/v3/types/private/handlers.d.ts +1 -0
  143. package/dist/esm/lib/v3/types/private/handlers.js.map +1 -1
  144. package/dist/esm/lib/v3/types/public/api.d.ts +24 -7
  145. package/dist/esm/lib/v3/types/public/api.js +36 -12
  146. package/dist/esm/lib/v3/types/public/api.js.map +1 -1
  147. package/dist/esm/lib/v3/types/public/methods.d.ts +1 -0
  148. package/dist/esm/lib/v3/types/public/methods.js.map +1 -1
  149. package/dist/esm/lib/v3/types/public/variables.d.ts +7 -0
  150. package/dist/esm/lib/v3/types/public/variables.js +19 -0
  151. package/dist/esm/lib/v3/types/public/variables.js.map +1 -0
  152. package/dist/esm/lib/v3/v3.d.ts +5 -0
  153. package/dist/esm/lib/v3/v3.js +19 -4
  154. package/dist/esm/lib/v3/v3.js.map +1 -1
  155. package/dist/esm/lib/version.d.ts +1 -1
  156. package/dist/esm/lib/version.js +1 -1
  157. package/dist/esm/lib/version.js.map +1 -1
  158. package/dist/esm/tests/integration/agent-captcha-autosolve.spec.d.ts +1 -0
  159. package/dist/esm/tests/integration/agent-captcha-autosolve.spec.js +54 -0
  160. package/dist/esm/tests/integration/agent-captcha-autosolve.spec.js.map +1 -0
  161. package/dist/esm/tests/integration/agent-hybrid-mode.spec.js +6 -6
  162. package/dist/esm/tests/integration/agent-hybrid-mode.spec.js.map +1 -1
  163. package/dist/esm/tests/integration/timeouts.spec.js +1 -1
  164. package/dist/esm/tests/integration/timeouts.spec.js.map +1 -1
  165. package/dist/esm/tests/unit/agent-captcha-hooks.test.d.ts +1 -0
  166. package/dist/esm/tests/unit/agent-captcha-hooks.test.js +283 -0
  167. package/dist/esm/tests/unit/agent-captcha-hooks.test.js.map +1 -0
  168. package/dist/esm/tests/unit/agent-execution-model.test.js +25 -3
  169. package/dist/esm/tests/unit/agent-execution-model.test.js.map +1 -1
  170. package/dist/esm/tests/unit/agent-system-prompt-variables.test.d.ts +1 -0
  171. package/dist/esm/tests/unit/agent-system-prompt-variables.test.js +21 -0
  172. package/dist/esm/tests/unit/agent-system-prompt-variables.test.js.map +1 -0
  173. package/dist/esm/tests/unit/api-client-observe-variables.test.d.ts +1 -0
  174. package/dist/esm/tests/unit/api-client-observe-variables.test.js +84 -0
  175. package/dist/esm/tests/unit/api-client-observe-variables.test.js.map +1 -0
  176. package/dist/esm/tests/unit/api-variables-schema.test.d.ts +1 -0
  177. package/dist/esm/tests/unit/api-variables-schema.test.js +35 -0
  178. package/dist/esm/tests/unit/api-variables-schema.test.js.map +1 -0
  179. package/dist/esm/tests/unit/browserbase-session-accessors.test.js +20 -0
  180. package/dist/esm/tests/unit/browserbase-session-accessors.test.js.map +1 -1
  181. package/dist/esm/tests/unit/captcha-solver.test.d.ts +1 -0
  182. package/dist/esm/tests/unit/captcha-solver.test.js +152 -0
  183. package/dist/esm/tests/unit/captcha-solver.test.js.map +1 -0
  184. package/dist/esm/tests/unit/flowlogger-eventstore.test.js +1 -1
  185. package/dist/esm/tests/unit/flowlogger-eventstore.test.js.map +1 -1
  186. package/dist/esm/tests/unit/openai-cua-client.test.d.ts +1 -0
  187. package/dist/esm/tests/unit/openai-cua-client.test.js +69 -0
  188. package/dist/esm/tests/unit/openai-cua-client.test.js.map +1 -0
  189. package/dist/esm/tests/unit/prompt-observe-variables.test.d.ts +1 -0
  190. package/dist/esm/tests/unit/prompt-observe-variables.test.js +17 -0
  191. package/dist/esm/tests/unit/prompt-observe-variables.test.js.map +1 -0
  192. package/dist/esm/tests/unit/public-api/public-types.test.js.map +1 -1
  193. package/dist/esm/tests/unit/timeout-handlers.test.js +50 -0
  194. package/dist/esm/tests/unit/timeout-handlers.test.js.map +1 -1
  195. package/package.json +2 -2
@@ -7,7 +7,10 @@ import { v7 as uuidv7 } from "uuid";
7
7
  * Client for OpenAI's Computer Use Assistant API
8
8
  * This implementation uses the official OpenAI Responses API for Computer Use
9
9
  */
10
+ const CAPTCHA_PROCEED_TOOL = "captchaSolvedProceed";
10
11
  export class OpenAICUAClient extends AgentClient {
12
+ pendingContextNotes = [];
13
+ captchaSolvedToolActive = false;
11
14
  apiKey;
12
15
  organization;
13
16
  baseURL;
@@ -63,6 +66,15 @@ export class OpenAICUAClient extends AgentClient {
63
66
  setSafetyConfirmationHandler(handler) {
64
67
  this.safetyConfirmationHandler = handler;
65
68
  }
69
+ addContextNote(note) {
70
+ this.pendingContextNotes.push(note);
71
+ // When a captcha-related note arrives, expose a tool that the model can
72
+ // call instead of asking the user for confirmation. This replaces
73
+ // fragile English-phrase parsing with a structured tool call.
74
+ if (note.toLowerCase().includes("captcha")) {
75
+ this.captchaSolvedToolActive = true;
76
+ }
77
+ }
66
78
  /**
67
79
  * Execute a task with the OpenAI CUA
68
80
  * This is the main entry point for the agent
@@ -87,6 +99,7 @@ export class OpenAICUAClient extends AgentClient {
87
99
  try {
88
100
  // Execute steps until completion or max steps reached
89
101
  while (!completed && currentStep < maxSteps) {
102
+ await this.preStepHook?.();
90
103
  logger({
91
104
  category: "agent",
92
105
  message: `Executing step ${currentStep + 1}/${maxSteps}`,
@@ -105,6 +118,16 @@ export class OpenAICUAClient extends AgentClient {
105
118
  // Update the input items for the next step if we're continuing
106
119
  if (!completed) {
107
120
  inputItems = result.nextInputItems;
121
+ const contextNotes = this.drainContextNotes();
122
+ if (contextNotes.length > 0) {
123
+ inputItems = [
124
+ ...inputItems,
125
+ ...contextNotes.map((note) => ({
126
+ role: "user",
127
+ content: note,
128
+ })),
129
+ ];
130
+ }
108
131
  }
109
132
  // Record any message for this step
110
133
  if (result.message) {
@@ -179,7 +202,7 @@ export class OpenAICUAClient extends AgentClient {
179
202
  if (item.type === "computer_call" && this.isComputerCallItem(item)) {
180
203
  logger({
181
204
  category: "agent",
182
- message: `Found computer_call: ${item.action.type}, call_id: ${item.call_id}`,
205
+ message: `Found computer_call: ${item.action.type}, payload: ${JSON.stringify(item.action)}, call_id: ${item.call_id}`,
183
206
  level: 2,
184
207
  });
185
208
  const action = this.convertComputerCallToAction(item);
@@ -346,6 +369,25 @@ export class OpenAICUAClient extends AgentClient {
346
369
  ...customTools,
347
370
  ];
348
371
  }
372
+ // When a captcha was just solved, expose a tool the model can call
373
+ // to confirm it should proceed. This avoids fragile English-phrase
374
+ // parsing and works regardless of the model's output language.
375
+ if (this.captchaSolvedToolActive) {
376
+ requestParams.tools = [
377
+ ...requestParams.tools,
378
+ {
379
+ type: "function",
380
+ name: CAPTCHA_PROCEED_TOOL,
381
+ function: {
382
+ name: CAPTCHA_PROCEED_TOOL,
383
+ description: "The captcha on this page was solved automatically. " +
384
+ "Call this tool to confirm and continue with your task " +
385
+ "instead of asking the user for permission.",
386
+ parameters: { type: "object", properties: {}, required: [] },
387
+ },
388
+ },
389
+ ];
390
+ }
349
391
  // Add previous_response_id if available
350
392
  if (previousResponseId) {
351
393
  requestParams.previous_response_id = previousResponseId;
@@ -498,6 +540,17 @@ export class OpenAICUAClient extends AgentClient {
498
540
  }
499
541
  else if (item.type === "function_call" &&
500
542
  this.isFunctionCallItem(item)) {
543
+ // Handle the captcha-proceed tool — just return a confirmation and
544
+ // deactivate the tool so it doesn't appear on subsequent steps.
545
+ if (item.name === CAPTCHA_PROCEED_TOOL) {
546
+ this.captchaSolvedToolActive = false;
547
+ nextInputItems.push({
548
+ type: "function_call_output",
549
+ call_id: item.call_id,
550
+ output: "Confirmed. The captcha is solved. Continue completing the original task autonomously without asking for further confirmation.",
551
+ });
552
+ continue;
553
+ }
501
554
  // Handle function calls (tool calls)
502
555
  try {
503
556
  const action = this.convertFunctionCallToAction(item);
@@ -577,6 +630,14 @@ export class OpenAICUAClient extends AgentClient {
577
630
  ...action, // Spread all properties from the action
578
631
  };
579
632
  }
633
+ drainContextNotes() {
634
+ if (this.pendingContextNotes.length === 0) {
635
+ return [];
636
+ }
637
+ const notes = [...this.pendingContextNotes];
638
+ this.pendingContextNotes = [];
639
+ return notes;
640
+ }
580
641
  convertFunctionCallToAction(call) {
581
642
  try {
582
643
  const args = JSON.parse(call.arguments);
@@ -1 +1 @@
1
- {"version":3,"file":"OpenAICUAClient.js","sourceRoot":"","sources":["../../../../../lib/v3/agent/OpenAICUAClient.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAe5B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACL,4BAA4B,EAC5B,oBAAoB,GACrB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,UAAU,EACV,0BAA0B,EAC1B,4BAA4B,GAC7B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,WAAW;IACtC,MAAM,CAAS;IACf,YAAY,CAAU;IACtB,OAAO,CAAS;IAChB,MAAM,CAAS;IAChB,cAAc,CAAU;IACvB,eAAe,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;IAC/C,UAAU,CAAU;IACpB,kBAAkB,CAAyB;IAC3C,aAAa,CAA0C;IACvD,cAAc,GAA8B,IAAI,GAAG,EAAE,CAAC;IACtD,WAAW,GAAW,SAAS,CAAC,CAAC,2CAA2C;IAC5E,KAAK,CAAW;IAChB,yBAAyB,CAA6B;IAE9D,YACE,IAAe,EACf,SAAiB,EACjB,wBAAiC,EACjC,aAA6B,EAC7B,KAAe;QAEf,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,wBAAwB,CAAC,CAAC;QAEjD,yBAAyB;QACzB,IAAI,CAAC,MAAM;YACR,aAAa,EAAE,MAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC;QACxE,IAAI,CAAC,OAAO,GAAI,aAAa,EAAE,OAAkB,IAAI,SAAS,CAAC;QAC/D,IAAI,CAAC,YAAY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AEtB,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAExB,2FAA2F;QAC3F,6FAA6F;QAC7F,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAc;YAC3B,GAAG,MAAM,EAAE,wCAAwC;SACpD,CAAC;IACJ,CAAC;IAEO,2BAA2B,CACjC,IAAsB;QAEtB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAExC,OAAO;gBACL,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,MAAM,EAAE,IAAI;aACb,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;YAC/D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,OAGvB;QACC,oCAAoC;QACpC,IAAI,OAAO,EAAE,WAAW,EAAE,CAAC;YACzB,OAAO,yBAAyB,OAAO,CAAC,WAAW,EAAE,CAAC;QACxD,CAAC;QAED,2CAA2C;QAC3C,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,IAAI,CAAC;gBACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBACpD,OAAO,yBAAyB,WAAW,EAAE,CAAC;YAChD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;gBACpD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QAED,MAAM,IAAI,4BAA4B,CACpC,yCAAyC;YACvC,iGAAiG,CACpG,CAAC;IACJ,CAAC;CACF","sourcesContent":["import OpenAI from \"openai\";\nimport { LogLine } from \"../types/public/logs.js\";\nimport {\n AgentAction,\n AgentResult,\n AgentType,\n AgentExecutionOptions,\n ResponseInputItem,\n ResponseItem,\n ComputerCallItem,\n FunctionCallItem,\n SafetyCheck,\n SafetyConfirmationHandler,\n} from \"../types/public/agent.js\";\nimport { ClientOptions } from \"../types/public/model.js\";\nimport { AgentClient } from \"./AgentClient.js\";\nimport {\n AgentScreenshotProviderError,\n StagehandClosedError,\n} from \"../types/public/sdkErrors.js\";\nimport { ToolSet } from \"ai\";\nimport {\n FlowLogger,\n extractLlmCuaPromptSummary,\n extractLlmCuaResponseSummary,\n} from \"../flowlogger/FlowLogger.js\";\nimport { v7 as uuidv7 } from \"uuid\";\n\n/**\n * Client for OpenAI's Computer Use Assistant API\n * This implementation uses the official OpenAI Responses API for Computer Use\n */\nexport class OpenAICUAClient extends AgentClient {\n private apiKey: string;\n private organization?: string;\n private baseURL: string;\n private client: OpenAI;\n public lastResponseId?: string;\n private currentViewport = { width: 1288, height: 711 };\n private currentUrl?: string;\n private screenshotProvider?: () => Promise<string>;\n private actionHandler?: (action: AgentAction) => Promise<void>;\n private reasoningItems: Map<string, ResponseItem> = new Map();\n private environment: string = \"browser\"; // \"browser\", \"mac\", \"windows\", or \"ubuntu\"\n private tools?: ToolSet;\n private safetyConfirmationHandler?: SafetyConfirmationHandler;\n\n constructor(\n type: AgentType,\n modelName: string,\n userProvidedInstructions?: string,\n clientOptions?: ClientOptions,\n tools?: ToolSet,\n ) {\n super(type, modelName, userProvidedInstructions);\n\n // Process client options\n this.apiKey =\n (clientOptions?.apiKey as string) || process.env.OPENAI_API_KEY || \"\";\n this.baseURL = (clientOptions?.baseURL as string) || undefined;\n this.organization =\n (clientOptions?.organization as string) || process.env.OPENAI_ORG;\n\n // Get environment if specified\n if (\n clientOptions?.environment &&\n typeof clientOptions.environment === \"string\"\n ) {\n this.environment = clientOptions.environment;\n }\n\n // Store client options for reference\n this.clientOptions = {\n apiKey: this.apiKey,\n };\n\n if (this.baseURL) {\n this.clientOptions.baseURL = this.baseURL;\n }\n\n // Initialize the OpenAI client\n this.client = new OpenAI(this.clientOptions);\n\n this.tools = tools;\n }\n\n setViewport(width: number, height: number): void {\n this.currentViewport = { width, height };\n }\n\n setCurrentUrl(url: string): void {\n this.currentUrl = url;\n }\n\n setScreenshotProvider(provider: () => Promise<string>): void {\n this.screenshotProvider = provider;\n }\n\n setActionHandler(handler: (action: AgentAction) => Promise<void>): void {\n this.actionHandler = handler;\n }\n\n setTools(tools: ToolSet): void {\n this.tools = tools;\n }\n\n setSafetyConfirmationHandler(handler?: SafetyConfirmationHandler): void {\n this.safetyConfirmationHandler = handler;\n }\n\n /**\n * Execute a task with the OpenAI CUA\n * This is the main entry point for the agent\n * @implements AgentClient.execute\n */\n async execute(executionOptions: AgentExecutionOptions): Promise<AgentResult> {\n const { options, logger } = executionOptions;\n const { instruction } = options;\n const maxSteps = options.maxSteps || 10;\n\n let currentStep = 0;\n let completed = false;\n const actions: AgentAction[] = [];\n const messageList: string[] = [];\n let finalMessage = \"\";\n this.reasoningItems.clear(); // Clear any previous reasoning items\n\n // Start with the initial instruction\n let inputItems = this.createInitialInputItems(instruction);\n let previousResponseId: string | undefined = undefined;\n let totalInputTokens = 0;\n let totalOutputTokens = 0;\n let totalInferenceTime = 0;\n\n try {\n // Execute steps until completion or max steps reached\n while (!completed && currentStep < maxSteps) {\n logger({\n category: \"agent\",\n message: `Executing step ${currentStep + 1}/${maxSteps}`,\n level: 1,\n });\n\n const result = await this.executeStep(\n inputItems,\n previousResponseId,\n logger,\n );\n totalInputTokens += result.usage.input_tokens;\n totalOutputTokens += result.usage.output_tokens;\n totalInferenceTime += result.usage.inference_time_ms;\n\n // Add actions to the list\n actions.push(...result.actions);\n\n // Update completion status\n completed = result.completed;\n\n // Store the previous response ID for the next request\n previousResponseId = result.responseId;\n\n // Update the input items for the next step if we're continuing\n if (!completed) {\n inputItems = result.nextInputItems;\n }\n\n // Record any message for this step\n if (result.message) {\n messageList.push(result.message);\n finalMessage = result.message;\n }\n\n // Increment step counter\n currentStep++;\n }\n\n // Return the final result\n return {\n success: completed,\n actions,\n message: finalMessage,\n completed,\n usage: {\n input_tokens: totalInputTokens,\n output_tokens: totalOutputTokens,\n inference_time_ms: totalInferenceTime,\n },\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing agent task: ${errorMessage}`,\n level: 0,\n });\n\n return {\n success: false,\n actions,\n message: `Failed to execute task: ${errorMessage}`,\n completed: false,\n usage: {\n input_tokens: totalInputTokens,\n output_tokens: totalOutputTokens,\n inference_time_ms: totalInferenceTime,\n },\n };\n }\n }\n\n /**\n * Execute a single step of the agent\n * This coordinates the flow: Request → Get Action → Execute Action\n */\n async executeStep(\n inputItems: ResponseInputItem[],\n previousResponseId: string | undefined,\n logger: (message: LogLine) => void,\n ): Promise<{\n actions: AgentAction[];\n message: string;\n completed: boolean;\n nextInputItems: ResponseInputItem[];\n responseId: string;\n usage: {\n input_tokens: number;\n output_tokens: number;\n inference_time_ms: number;\n };\n }> {\n try {\n // Get response from the model\n const result = await this.getAction(inputItems, previousResponseId);\n const output = result.output;\n const responseId = result.responseId;\n const usage = {\n input_tokens: result.usage.input_tokens,\n output_tokens: result.usage.output_tokens,\n inference_time_ms: result.usage.inference_time_ms,\n };\n\n // Add any reasoning items to our map\n for (const item of output) {\n if (item.type === \"reasoning\") {\n this.reasoningItems.set(item.id, item);\n logger({\n category: \"agent\",\n message: `Reasoning: ${String(item.content || \"\")}`,\n level: 1,\n });\n }\n }\n\n // Extract actions from the output\n const stepActions: AgentAction[] = [];\n for (const item of output) {\n if (item.type === \"computer_call\" && this.isComputerCallItem(item)) {\n logger({\n category: \"agent\",\n message: `Found computer_call: ${item.action.type}, call_id: ${item.call_id}`,\n level: 2,\n });\n const action = this.convertComputerCallToAction(item);\n if (action) {\n stepActions.push(action);\n logger({\n category: \"agent\",\n message: `Converted computer_call to action: ${action.type}`,\n level: 2,\n });\n }\n } else if (\n item.type === \"function_call\" &&\n this.isFunctionCallItem(item)\n ) {\n logger({\n category: \"agent\",\n message: `Found function_call: ${item.name}, call_id: ${item.call_id}`,\n level: 2,\n });\n const action = this.convertFunctionCallToAction(item);\n if (action) {\n stepActions.push(action);\n logger({\n category: \"agent\",\n message: `Converted function_call to action: ${action.type}`,\n level: 2,\n });\n }\n }\n }\n\n // Extract message text\n let message = \"\";\n for (const item of output) {\n if (item.type === \"message\") {\n logger({\n category: \"agent\",\n message: `Found message block`,\n level: 2,\n });\n if (item.content && Array.isArray(item.content)) {\n for (const content of item.content) {\n if (content.type === \"output_text\" && content.text) {\n message += content.text + \"\\n\";\n logger({\n category: \"agent\",\n message: `Message text: ${String(content.text || \"\")}`,\n level: 1,\n });\n }\n }\n }\n }\n }\n\n // Take actions and get results\n const nextInputItems = await this.takeAction(output, logger);\n\n // Check if completed\n const completed =\n output.length === 0 ||\n output.every(\n (item) => item.type === \"message\" || item.type === \"reasoning\",\n );\n\n return {\n actions: stepActions,\n message: message.trim(),\n completed,\n nextInputItems,\n responseId,\n usage: usage,\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing step: ${errorMessage}`,\n level: 0,\n });\n\n throw error;\n }\n }\n\n private isComputerCallItem(item: ResponseItem): item is ComputerCallItem {\n return (\n item.type === \"computer_call\" &&\n \"call_id\" in item &&\n \"action\" in item &&\n typeof item.action === \"object\"\n );\n }\n\n private async handleSafetyConfirmation(\n pendingSafetyChecks: SafetyCheck[],\n logger: (message: LogLine) => void,\n ): Promise<SafetyCheck[] | undefined> {\n if (this.safetyConfirmationHandler) {\n logger({\n category: \"agent\",\n message: `Requesting safety confirmation for ${pendingSafetyChecks.length} check(s): ${pendingSafetyChecks.map((c) => c.code).join(\", \")}`,\n level: 1,\n });\n\n const response =\n await this.safetyConfirmationHandler(pendingSafetyChecks);\n\n if (response.acknowledged) {\n logger({\n category: \"agent\",\n message: `Safety checks acknowledged by user`,\n level: 1,\n });\n return pendingSafetyChecks;\n } else {\n logger({\n category: \"agent\",\n message: `Safety checks rejected by user`,\n level: 1,\n });\n return undefined;\n }\n }\n\n logger({\n category: \"agent\",\n message: `Auto-acknowledging ${pendingSafetyChecks.length} safety check(s)`,\n level: 2,\n });\n return pendingSafetyChecks;\n }\n\n private isFunctionCallItem(item: ResponseItem): item is FunctionCallItem {\n return (\n item.type === \"function_call\" &&\n \"call_id\" in item &&\n \"name\" in item &&\n \"arguments\" in item\n );\n }\n\n private createInitialInputItems(instruction: string): ResponseInputItem[] {\n // For the initial request, we use a simple array with the user's instruction\n return [\n {\n role: \"system\",\n content: this.userProvidedInstructions,\n },\n {\n role: \"user\",\n content: instruction,\n },\n ];\n }\n\n async getAction(\n inputItems: ResponseInputItem[],\n previousResponseId?: string,\n ): Promise<{\n output: ResponseItem[];\n responseId: string;\n usage: Record<string, number>;\n }> {\n try {\n // Create the request parameters\n const requestParams: Record<string, unknown> = {\n model: this.modelName,\n tools: [\n {\n type: \"computer_use_preview\",\n display_width: this.currentViewport.width,\n display_height: this.currentViewport.height,\n environment: this.environment,\n },\n ],\n input: inputItems,\n truncation: \"auto\",\n };\n\n // Add custom tools if available\n if (this.tools && Object.keys(this.tools).length > 0) {\n const customTools = Object.entries(this.tools).map(([name, tool]) => ({\n type: \"function\" as const,\n name,\n function: {\n name,\n description: tool.description,\n parameters: tool.inputSchema,\n },\n }));\n\n requestParams.tools = [\n ...(requestParams.tools as Record<string, unknown>[]),\n ...customTools,\n ];\n }\n\n // Add previous_response_id if available\n if (previousResponseId) {\n requestParams.previous_response_id = previousResponseId;\n }\n\n // Log LLM request\n const llmRequestId = uuidv7();\n FlowLogger.logLlmRequest({\n requestId: llmRequestId,\n model: this.modelName,\n prompt: extractLlmCuaPromptSummary(inputItems),\n });\n\n const startTime = Date.now();\n // Create the response using the OpenAI Responses API\n // @ts-expect-error - Force type to match what the OpenAI SDK expects\n const response = await this.client.responses.create(requestParams);\n const endTime = Date.now();\n const elapsedMs = endTime - startTime;\n\n // Extract only the input_tokens and output_tokens\n const usage = {\n input_tokens: response.usage.input_tokens,\n output_tokens: response.usage.output_tokens,\n inference_time_ms: elapsedMs,\n };\n\n // Log LLM response\n FlowLogger.logLlmResponse({\n requestId: llmRequestId,\n model: this.modelName,\n output: extractLlmCuaResponseSummary(response.output),\n inputTokens: response.usage.input_tokens,\n outputTokens: response.usage.output_tokens,\n });\n\n // Store the response ID for future use\n this.lastResponseId = response.id;\n\n // Return the output and response ID\n return {\n output: response.output as unknown as ResponseItem[],\n responseId: response.id,\n usage,\n };\n } catch (error) {\n console.error(\"Error getting action from OpenAI:\", error);\n throw error;\n }\n }\n\n async takeAction(\n output: ResponseItem[],\n logger: (message: LogLine) => void,\n ): Promise<ResponseInputItem[]> {\n const nextInputItems: ResponseInputItem[] = [];\n\n // Process each output item\n for (const item of output) {\n if (item.type === \"computer_call\" && this.isComputerCallItem(item)) {\n // Handle computer calls\n try {\n const action = this.convertComputerCallToAction(item);\n\n if (action && this.actionHandler) {\n logger({\n category: \"agent\",\n message: `Executing computer action: ${action.type}`,\n level: 1,\n });\n await this.actionHandler(action);\n }\n\n // Capture a screenshot\n const screenshot = await this.captureScreenshot();\n\n // Create a computer_call_output for the next request\n const outputItem = {\n type: \"computer_call_output\" as const,\n call_id: item.call_id,\n output: {\n type: \"input_image\" as const,\n image_url: screenshot,\n },\n } as ResponseInputItem;\n\n logger({\n category: \"agent\",\n message: `Added computer_call_output for call_id: ${item.call_id}`,\n level: 2,\n });\n\n // Add current URL if available\n if (this.currentUrl) {\n const computerCallOutput = outputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n current_url?: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.output.current_url = this.currentUrl;\n }\n\n if (\n item.pending_safety_checks &&\n item.pending_safety_checks.length > 0\n ) {\n const acknowledgedChecks = await this.handleSafetyConfirmation(\n item.pending_safety_checks,\n logger,\n );\n\n if (acknowledgedChecks) {\n const computerCallOutput = outputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.acknowledged_safety_checks =\n acknowledgedChecks;\n }\n }\n\n nextInputItems.push(outputItem);\n } catch (error) {\n if (error instanceof StagehandClosedError) {\n throw error;\n }\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n\n logger({\n category: \"agent\",\n message: `Error executing computer call: ${errorMessage}`,\n level: 0,\n });\n\n try {\n // Capture a screenshot even on error\n const screenshot = await this.captureScreenshot();\n\n const errorOutputItem = {\n type: \"computer_call_output\" as const,\n call_id: item.call_id,\n output: {\n type: \"input_image\" as const,\n image_url: screenshot,\n error: errorMessage,\n },\n } as ResponseInputItem;\n\n // Add current URL if available\n if (this.currentUrl) {\n const computerCallOutput = errorOutputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n current_url?: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.output.current_url = this.currentUrl;\n }\n\n if (\n item.pending_safety_checks &&\n item.pending_safety_checks.length > 0\n ) {\n const acknowledgedChecks = await this.handleSafetyConfirmation(\n item.pending_safety_checks,\n logger,\n );\n\n if (acknowledgedChecks) {\n const computerCallOutput = errorOutputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.acknowledged_safety_checks =\n acknowledgedChecks;\n }\n }\n\n nextInputItems.push(errorOutputItem);\n } catch (screenshotError) {\n if (screenshotError instanceof StagehandClosedError) {\n throw screenshotError;\n }\n // If we can't capture a screenshot, just send the error\n logger({\n category: \"agent\",\n message: `Error capturing screenshot: ${String(screenshotError)}`,\n level: 0,\n });\n\n // For error cases without a screenshot, we need to use a string output\n nextInputItems.push({\n type: \"computer_call_output\",\n call_id: item.call_id,\n output: `Error: ${errorMessage}`,\n } as ResponseInputItem);\n }\n }\n } else if (\n item.type === \"function_call\" &&\n this.isFunctionCallItem(item)\n ) {\n // Handle function calls (tool calls)\n try {\n const action = this.convertFunctionCallToAction(item);\n\n if (action && this.actionHandler) {\n await this.actionHandler(action);\n }\n\n // Execute the tool if available\n let toolResult = \"Tool executed successfully\";\n if (this.tools && item.name in this.tools) {\n try {\n const tool = this.tools[item.name];\n const args = JSON.parse(item.arguments);\n\n logger({\n category: \"agent\",\n message: `Executing tool call: ${item.name} with args: ${item.arguments}`,\n level: 1,\n });\n\n const result = await tool.execute(args, {\n toolCallId: item.call_id,\n messages: [],\n });\n toolResult = JSON.stringify(result);\n\n logger({\n category: \"agent\",\n message: `Tool ${item.name} completed successfully. Result: ${toolResult}`,\n level: 1,\n });\n } catch (toolError) {\n const errorMessage =\n toolError instanceof Error\n ? toolError.message\n : String(toolError);\n toolResult = `Error executing tool: ${errorMessage}`;\n\n logger({\n category: \"agent\",\n message: `Error executing tool ${item.name}: ${errorMessage}`,\n level: 0,\n });\n }\n }\n\n // Create a function_call_output for the next request\n const outputItem: ResponseInputItem = {\n type: \"function_call_output\",\n call_id: item.call_id,\n output: toolResult,\n };\n\n nextInputItems.push(outputItem);\n } catch (error) {\n if (error instanceof StagehandClosedError) {\n throw error;\n }\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n\n logger({\n category: \"agent\",\n message: `Error executing function call: ${errorMessage}`,\n level: 0,\n });\n\n // Send error result back\n const errorOutputItem: ResponseInputItem = {\n type: \"function_call_output\",\n call_id: item.call_id,\n output: `Error: ${errorMessage}`,\n };\n\n nextInputItems.push(errorOutputItem);\n }\n }\n }\n\n return nextInputItems;\n }\n\n private convertComputerCallToAction(\n call: ComputerCallItem,\n ): AgentAction | null {\n const { action } = call;\n\n // Instead of wrapping the action in a params object, spread the action properties directly\n // This ensures properties like x, y, button, etc. are directly accessible on the AgentAction\n return {\n type: action.type as string,\n ...action, // Spread all properties from the action\n };\n }\n\n private convertFunctionCallToAction(\n call: FunctionCallItem,\n ): AgentAction | null {\n try {\n const args = JSON.parse(call.arguments);\n\n return {\n type: call.name,\n params: args,\n };\n } catch (error) {\n console.error(\"Error parsing function call arguments:\", error);\n return null;\n }\n }\n\n async captureScreenshot(options?: {\n base64Image?: string;\n currentUrl?: string;\n }): Promise<string> {\n // Use provided options if available\n if (options?.base64Image) {\n return `data:image/png;base64,${options.base64Image}`;\n }\n\n // Use the screenshot provider if available\n if (this.screenshotProvider) {\n try {\n const base64Image = await this.screenshotProvider();\n return `data:image/png;base64,${base64Image}`;\n } catch (error) {\n console.error(\"Error capturing screenshot:\", error);\n throw error;\n }\n }\n\n throw new AgentScreenshotProviderError(\n \"`screenshotProvider` has not been set. \" +\n \"Please call `setScreenshotProvider()` with a valid function that returns a base64-encoded image\",\n );\n }\n}\n"]}
1
+ {"version":3,"file":"OpenAICUAClient.js","sourceRoot":"","sources":["../../../../../lib/v3/agent/OpenAICUAClient.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAe5B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACL,4BAA4B,EAC5B,oBAAoB,GACrB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,UAAU,EACV,0BAA0B,EAC1B,4BAA4B,GAC7B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC;;;GAGG;AACH,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAEpD,MAAM,OAAO,eAAgB,SAAQ,WAAW;IACtC,mBAAmB,GAAa,EAAE,CAAC;IACnC,uBAAuB,GAAG,KAAK,CAAC;IAChC,MAAM,CAAS;IACf,YAAY,CAAU;IACtB,OAAO,CAAS;IAChB,MAAM,CAAS;IAChB,cAAc,CAAU;IACvB,eAAe,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;IAC/C,UAAU,CAAU;IACpB,kBAAkB,CAAyB;IAC3C,aAAa,CAA0C;I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,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAExC,OAAO;gBACL,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,MAAM,EAAE,IAAI;aACb,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;YAC/D,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,OAGvB;QACC,oCAAoC;QACpC,IAAI,OAAO,EAAE,WAAW,EAAE,CAAC;YACzB,OAAO,yBAAyB,OAAO,CAAC,WAAW,EAAE,CAAC;QACxD,CAAC;QAED,2CAA2C;QAC3C,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,IAAI,CAAC;gBACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBACpD,OAAO,yBAAyB,WAAW,EAAE,CAAC;YAChD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;gBACpD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QAED,MAAM,IAAI,4BAA4B,CACpC,yCAAyC;YACvC,iGAAiG,CACpG,CAAC;IACJ,CAAC;CACF","sourcesContent":["import OpenAI from \"openai\";\nimport { LogLine } from \"../types/public/logs.js\";\nimport {\n AgentAction,\n AgentResult,\n AgentType,\n AgentExecutionOptions,\n ResponseInputItem,\n ResponseItem,\n ComputerCallItem,\n FunctionCallItem,\n SafetyCheck,\n SafetyConfirmationHandler,\n} from \"../types/public/agent.js\";\nimport { ClientOptions } from \"../types/public/model.js\";\nimport { AgentClient } from \"./AgentClient.js\";\nimport {\n AgentScreenshotProviderError,\n StagehandClosedError,\n} from \"../types/public/sdkErrors.js\";\nimport { ToolSet } from \"ai\";\nimport {\n FlowLogger,\n extractLlmCuaPromptSummary,\n extractLlmCuaResponseSummary,\n} from \"../flowlogger/FlowLogger.js\";\nimport { v7 as uuidv7 } from \"uuid\";\n\n/**\n * Client for OpenAI's Computer Use Assistant API\n * This implementation uses the official OpenAI Responses API for Computer Use\n */\nconst CAPTCHA_PROCEED_TOOL = \"captchaSolvedProceed\";\n\nexport class OpenAICUAClient extends AgentClient {\n private pendingContextNotes: string[] = [];\n private captchaSolvedToolActive = false;\n private apiKey: string;\n private organization?: string;\n private baseURL: string;\n private client: OpenAI;\n public lastResponseId?: string;\n private currentViewport = { width: 1288, height: 711 };\n private currentUrl?: string;\n private screenshotProvider?: () => Promise<string>;\n private actionHandler?: (action: AgentAction) => Promise<void>;\n private reasoningItems: Map<string, ResponseItem> = new Map();\n private environment: string = \"browser\"; // \"browser\", \"mac\", \"windows\", or \"ubuntu\"\n private tools?: ToolSet;\n private safetyConfirmationHandler?: SafetyConfirmationHandler;\n\n constructor(\n type: AgentType,\n modelName: string,\n userProvidedInstructions?: string,\n clientOptions?: ClientOptions,\n tools?: ToolSet,\n ) {\n super(type, modelName, userProvidedInstructions);\n\n // Process client options\n this.apiKey =\n (clientOptions?.apiKey as string) || process.env.OPENAI_API_KEY || \"\";\n this.baseURL = (clientOptions?.baseURL as string) || undefined;\n this.organization =\n (clientOptions?.organization as string) || process.env.OPENAI_ORG;\n\n // Get environment if specified\n if (\n clientOptions?.environment &&\n typeof clientOptions.environment === \"string\"\n ) {\n this.environment = clientOptions.environment;\n }\n\n // Store client options for reference\n this.clientOptions = {\n apiKey: this.apiKey,\n };\n\n if (this.baseURL) {\n this.clientOptions.baseURL = this.baseURL;\n }\n\n // Initialize the OpenAI client\n this.client = new OpenAI(this.clientOptions);\n\n this.tools = tools;\n }\n\n setViewport(width: number, height: number): void {\n this.currentViewport = { width, height };\n }\n\n setCurrentUrl(url: string): void {\n this.currentUrl = url;\n }\n\n setScreenshotProvider(provider: () => Promise<string>): void {\n this.screenshotProvider = provider;\n }\n\n setActionHandler(handler: (action: AgentAction) => Promise<void>): void {\n this.actionHandler = handler;\n }\n\n setTools(tools: ToolSet): void {\n this.tools = tools;\n }\n\n setSafetyConfirmationHandler(handler?: SafetyConfirmationHandler): void {\n this.safetyConfirmationHandler = handler;\n }\n\n addContextNote(note: string): void {\n this.pendingContextNotes.push(note);\n\n // When a captcha-related note arrives, expose a tool that the model can\n // call instead of asking the user for confirmation. This replaces\n // fragile English-phrase parsing with a structured tool call.\n if (note.toLowerCase().includes(\"captcha\")) {\n this.captchaSolvedToolActive = true;\n }\n }\n\n /**\n * Execute a task with the OpenAI CUA\n * This is the main entry point for the agent\n * @implements AgentClient.execute\n */\n async execute(executionOptions: AgentExecutionOptions): Promise<AgentResult> {\n const { options, logger } = executionOptions;\n const { instruction } = options;\n const maxSteps = options.maxSteps || 10;\n\n let currentStep = 0;\n let completed = false;\n const actions: AgentAction[] = [];\n const messageList: string[] = [];\n let finalMessage = \"\";\n this.reasoningItems.clear(); // Clear any previous reasoning items\n\n // Start with the initial instruction\n let inputItems = this.createInitialInputItems(instruction);\n let previousResponseId: string | undefined = undefined;\n let totalInputTokens = 0;\n let totalOutputTokens = 0;\n let totalInferenceTime = 0;\n\n try {\n // Execute steps until completion or max steps reached\n while (!completed && currentStep < maxSteps) {\n await this.preStepHook?.();\n\n logger({\n category: \"agent\",\n message: `Executing step ${currentStep + 1}/${maxSteps}`,\n level: 1,\n });\n\n const result = await this.executeStep(\n inputItems,\n previousResponseId,\n logger,\n );\n totalInputTokens += result.usage.input_tokens;\n totalOutputTokens += result.usage.output_tokens;\n totalInferenceTime += result.usage.inference_time_ms;\n\n // Add actions to the list\n actions.push(...result.actions);\n\n // Update completion status\n completed = result.completed;\n\n // Store the previous response ID for the next request\n previousResponseId = result.responseId;\n\n // Update the input items for the next step if we're continuing\n if (!completed) {\n inputItems = result.nextInputItems;\n const contextNotes = this.drainContextNotes();\n if (contextNotes.length > 0) {\n inputItems = [\n ...inputItems,\n ...contextNotes.map((note) => ({\n role: \"user\" as const,\n content: note,\n })),\n ];\n }\n }\n\n // Record any message for this step\n if (result.message) {\n messageList.push(result.message);\n finalMessage = result.message;\n }\n\n // Increment step counter\n currentStep++;\n }\n\n // Return the final result\n return {\n success: completed,\n actions,\n message: finalMessage,\n completed,\n usage: {\n input_tokens: totalInputTokens,\n output_tokens: totalOutputTokens,\n inference_time_ms: totalInferenceTime,\n },\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing agent task: ${errorMessage}`,\n level: 0,\n });\n\n return {\n success: false,\n actions,\n message: `Failed to execute task: ${errorMessage}`,\n completed: false,\n usage: {\n input_tokens: totalInputTokens,\n output_tokens: totalOutputTokens,\n inference_time_ms: totalInferenceTime,\n },\n };\n }\n }\n\n /**\n * Execute a single step of the agent\n * This coordinates the flow: Request → Get Action → Execute Action\n */\n async executeStep(\n inputItems: ResponseInputItem[],\n previousResponseId: string | undefined,\n logger: (message: LogLine) => void,\n ): Promise<{\n actions: AgentAction[];\n message: string;\n completed: boolean;\n nextInputItems: ResponseInputItem[];\n responseId: string;\n usage: {\n input_tokens: number;\n output_tokens: number;\n inference_time_ms: number;\n };\n }> {\n try {\n // Get response from the model\n const result = await this.getAction(inputItems, previousResponseId);\n const output = result.output;\n const responseId = result.responseId;\n const usage = {\n input_tokens: result.usage.input_tokens,\n output_tokens: result.usage.output_tokens,\n inference_time_ms: result.usage.inference_time_ms,\n };\n\n // Add any reasoning items to our map\n for (const item of output) {\n if (item.type === \"reasoning\") {\n this.reasoningItems.set(item.id, item);\n logger({\n category: \"agent\",\n message: `Reasoning: ${String(item.content || \"\")}`,\n level: 1,\n });\n }\n }\n\n // Extract actions from the output\n const stepActions: AgentAction[] = [];\n for (const item of output) {\n if (item.type === \"computer_call\" && this.isComputerCallItem(item)) {\n logger({\n category: \"agent\",\n message: `Found computer_call: ${item.action.type}, payload: ${JSON.stringify(item.action)}, call_id: ${item.call_id}`,\n level: 2,\n });\n const action = this.convertComputerCallToAction(item);\n if (action) {\n stepActions.push(action);\n logger({\n category: \"agent\",\n message: `Converted computer_call to action: ${action.type}`,\n level: 2,\n });\n }\n } else if (\n item.type === \"function_call\" &&\n this.isFunctionCallItem(item)\n ) {\n logger({\n category: \"agent\",\n message: `Found function_call: ${item.name}, call_id: ${item.call_id}`,\n level: 2,\n });\n const action = this.convertFunctionCallToAction(item);\n if (action) {\n stepActions.push(action);\n logger({\n category: \"agent\",\n message: `Converted function_call to action: ${action.type}`,\n level: 2,\n });\n }\n }\n }\n\n // Extract message text\n let message = \"\";\n for (const item of output) {\n if (item.type === \"message\") {\n logger({\n category: \"agent\",\n message: `Found message block`,\n level: 2,\n });\n if (item.content && Array.isArray(item.content)) {\n for (const content of item.content) {\n if (content.type === \"output_text\" && content.text) {\n message += content.text + \"\\n\";\n logger({\n category: \"agent\",\n message: `Message text: ${String(content.text || \"\")}`,\n level: 1,\n });\n }\n }\n }\n }\n }\n\n // Take actions and get results\n const nextInputItems = await this.takeAction(output, logger);\n\n // Check if completed\n const completed =\n output.length === 0 ||\n output.every(\n (item) => item.type === \"message\" || item.type === \"reasoning\",\n );\n\n return {\n actions: stepActions,\n message: message.trim(),\n completed,\n nextInputItems,\n responseId,\n usage: usage,\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n logger({\n category: \"agent\",\n message: `Error executing step: ${errorMessage}`,\n level: 0,\n });\n\n throw error;\n }\n }\n\n private isComputerCallItem(item: ResponseItem): item is ComputerCallItem {\n return (\n item.type === \"computer_call\" &&\n \"call_id\" in item &&\n \"action\" in item &&\n typeof item.action === \"object\"\n );\n }\n\n private async handleSafetyConfirmation(\n pendingSafetyChecks: SafetyCheck[],\n logger: (message: LogLine) => void,\n ): Promise<SafetyCheck[] | undefined> {\n if (this.safetyConfirmationHandler) {\n logger({\n category: \"agent\",\n message: `Requesting safety confirmation for ${pendingSafetyChecks.length} check(s): ${pendingSafetyChecks.map((c) => c.code).join(\", \")}`,\n level: 1,\n });\n\n const response =\n await this.safetyConfirmationHandler(pendingSafetyChecks);\n\n if (response.acknowledged) {\n logger({\n category: \"agent\",\n message: `Safety checks acknowledged by user`,\n level: 1,\n });\n return pendingSafetyChecks;\n } else {\n logger({\n category: \"agent\",\n message: `Safety checks rejected by user`,\n level: 1,\n });\n return undefined;\n }\n }\n\n logger({\n category: \"agent\",\n message: `Auto-acknowledging ${pendingSafetyChecks.length} safety check(s)`,\n level: 2,\n });\n return pendingSafetyChecks;\n }\n\n private isFunctionCallItem(item: ResponseItem): item is FunctionCallItem {\n return (\n item.type === \"function_call\" &&\n \"call_id\" in item &&\n \"name\" in item &&\n \"arguments\" in item\n );\n }\n\n private createInitialInputItems(instruction: string): ResponseInputItem[] {\n // For the initial request, we use a simple array with the user's instruction\n return [\n {\n role: \"system\",\n content: this.userProvidedInstructions,\n },\n {\n role: \"user\",\n content: instruction,\n },\n ];\n }\n\n async getAction(\n inputItems: ResponseInputItem[],\n previousResponseId?: string,\n ): Promise<{\n output: ResponseItem[];\n responseId: string;\n usage: Record<string, number>;\n }> {\n try {\n // Create the request parameters\n const requestParams: Record<string, unknown> = {\n model: this.modelName,\n tools: [\n {\n type: \"computer_use_preview\",\n display_width: this.currentViewport.width,\n display_height: this.currentViewport.height,\n environment: this.environment,\n },\n ],\n input: inputItems,\n truncation: \"auto\",\n };\n\n // Add custom tools if available\n if (this.tools && Object.keys(this.tools).length > 0) {\n const customTools = Object.entries(this.tools).map(([name, tool]) => ({\n type: \"function\" as const,\n name,\n function: {\n name,\n description: tool.description,\n parameters: tool.inputSchema,\n },\n }));\n\n requestParams.tools = [\n ...(requestParams.tools as Record<string, unknown>[]),\n ...customTools,\n ];\n }\n\n // When a captcha was just solved, expose a tool the model can call\n // to confirm it should proceed. This avoids fragile English-phrase\n // parsing and works regardless of the model's output language.\n if (this.captchaSolvedToolActive) {\n requestParams.tools = [\n ...(requestParams.tools as Record<string, unknown>[]),\n {\n type: \"function\" as const,\n name: CAPTCHA_PROCEED_TOOL,\n function: {\n name: CAPTCHA_PROCEED_TOOL,\n description:\n \"The captcha on this page was solved automatically. \" +\n \"Call this tool to confirm and continue with your task \" +\n \"instead of asking the user for permission.\",\n parameters: { type: \"object\", properties: {}, required: [] },\n },\n },\n ];\n }\n\n // Add previous_response_id if available\n if (previousResponseId) {\n requestParams.previous_response_id = previousResponseId;\n }\n\n // Log LLM request\n const llmRequestId = uuidv7();\n FlowLogger.logLlmRequest({\n requestId: llmRequestId,\n model: this.modelName,\n prompt: extractLlmCuaPromptSummary(inputItems),\n });\n\n const startTime = Date.now();\n // Create the response using the OpenAI Responses API\n // @ts-expect-error - Force type to match what the OpenAI SDK expects\n const response = await this.client.responses.create(requestParams);\n const endTime = Date.now();\n const elapsedMs = endTime - startTime;\n\n // Extract only the input_tokens and output_tokens\n const usage = {\n input_tokens: response.usage.input_tokens,\n output_tokens: response.usage.output_tokens,\n inference_time_ms: elapsedMs,\n };\n\n // Log LLM response\n FlowLogger.logLlmResponse({\n requestId: llmRequestId,\n model: this.modelName,\n output: extractLlmCuaResponseSummary(response.output),\n inputTokens: response.usage.input_tokens,\n outputTokens: response.usage.output_tokens,\n });\n\n // Store the response ID for future use\n this.lastResponseId = response.id;\n\n // Return the output and response ID\n return {\n output: response.output as unknown as ResponseItem[],\n responseId: response.id,\n usage,\n };\n } catch (error) {\n console.error(\"Error getting action from OpenAI:\", error);\n throw error;\n }\n }\n\n async takeAction(\n output: ResponseItem[],\n logger: (message: LogLine) => void,\n ): Promise<ResponseInputItem[]> {\n const nextInputItems: ResponseInputItem[] = [];\n\n // Process each output item\n for (const item of output) {\n if (item.type === \"computer_call\" && this.isComputerCallItem(item)) {\n // Handle computer calls\n try {\n const action = this.convertComputerCallToAction(item);\n\n if (action && this.actionHandler) {\n logger({\n category: \"agent\",\n message: `Executing computer action: ${action.type}`,\n level: 1,\n });\n await this.actionHandler(action);\n }\n\n // Capture a screenshot\n const screenshot = await this.captureScreenshot();\n\n // Create a computer_call_output for the next request\n const outputItem = {\n type: \"computer_call_output\" as const,\n call_id: item.call_id,\n output: {\n type: \"input_image\" as const,\n image_url: screenshot,\n },\n } as ResponseInputItem;\n\n logger({\n category: \"agent\",\n message: `Added computer_call_output for call_id: ${item.call_id}`,\n level: 2,\n });\n\n // Add current URL if available\n if (this.currentUrl) {\n const computerCallOutput = outputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n current_url?: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.output.current_url = this.currentUrl;\n }\n\n if (\n item.pending_safety_checks &&\n item.pending_safety_checks.length > 0\n ) {\n const acknowledgedChecks = await this.handleSafetyConfirmation(\n item.pending_safety_checks,\n logger,\n );\n\n if (acknowledgedChecks) {\n const computerCallOutput = outputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.acknowledged_safety_checks =\n acknowledgedChecks;\n }\n }\n\n nextInputItems.push(outputItem);\n } catch (error) {\n if (error instanceof StagehandClosedError) {\n throw error;\n }\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n\n logger({\n category: \"agent\",\n message: `Error executing computer call: ${errorMessage}`,\n level: 0,\n });\n\n try {\n // Capture a screenshot even on error\n const screenshot = await this.captureScreenshot();\n\n const errorOutputItem = {\n type: \"computer_call_output\" as const,\n call_id: item.call_id,\n output: {\n type: \"input_image\" as const,\n image_url: screenshot,\n error: errorMessage,\n },\n } as ResponseInputItem;\n\n // Add current URL if available\n if (this.currentUrl) {\n const computerCallOutput = errorOutputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n current_url?: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.output.current_url = this.currentUrl;\n }\n\n if (\n item.pending_safety_checks &&\n item.pending_safety_checks.length > 0\n ) {\n const acknowledgedChecks = await this.handleSafetyConfirmation(\n item.pending_safety_checks,\n logger,\n );\n\n if (acknowledgedChecks) {\n const computerCallOutput = errorOutputItem as {\n type: \"computer_call_output\";\n call_id: string;\n output: {\n type: \"input_image\";\n image_url: string;\n };\n acknowledged_safety_checks?: SafetyCheck[];\n };\n computerCallOutput.acknowledged_safety_checks =\n acknowledgedChecks;\n }\n }\n\n nextInputItems.push(errorOutputItem);\n } catch (screenshotError) {\n if (screenshotError instanceof StagehandClosedError) {\n throw screenshotError;\n }\n // If we can't capture a screenshot, just send the error\n logger({\n category: \"agent\",\n message: `Error capturing screenshot: ${String(screenshotError)}`,\n level: 0,\n });\n\n // For error cases without a screenshot, we need to use a string output\n nextInputItems.push({\n type: \"computer_call_output\",\n call_id: item.call_id,\n output: `Error: ${errorMessage}`,\n } as ResponseInputItem);\n }\n }\n } else if (\n item.type === \"function_call\" &&\n this.isFunctionCallItem(item)\n ) {\n // Handle the captcha-proceed tool — just return a confirmation and\n // deactivate the tool so it doesn't appear on subsequent steps.\n if (item.name === CAPTCHA_PROCEED_TOOL) {\n this.captchaSolvedToolActive = false;\n nextInputItems.push({\n type: \"function_call_output\",\n call_id: item.call_id,\n output:\n \"Confirmed. The captcha is solved. Continue completing the original task autonomously without asking for further confirmation.\",\n } as ResponseInputItem);\n continue;\n }\n\n // Handle function calls (tool calls)\n try {\n const action = this.convertFunctionCallToAction(item);\n\n if (action && this.actionHandler) {\n await this.actionHandler(action);\n }\n\n // Execute the tool if available\n let toolResult = \"Tool executed successfully\";\n if (this.tools && item.name in this.tools) {\n try {\n const tool = this.tools[item.name];\n const args = JSON.parse(item.arguments);\n\n logger({\n category: \"agent\",\n message: `Executing tool call: ${item.name} with args: ${item.arguments}`,\n level: 1,\n });\n\n const result = await tool.execute(args, {\n toolCallId: item.call_id,\n messages: [],\n });\n toolResult = JSON.stringify(result);\n\n logger({\n category: \"agent\",\n message: `Tool ${item.name} completed successfully. Result: ${toolResult}`,\n level: 1,\n });\n } catch (toolError) {\n const errorMessage =\n toolError instanceof Error\n ? toolError.message\n : String(toolError);\n toolResult = `Error executing tool: ${errorMessage}`;\n\n logger({\n category: \"agent\",\n message: `Error executing tool ${item.name}: ${errorMessage}`,\n level: 0,\n });\n }\n }\n\n // Create a function_call_output for the next request\n const outputItem: ResponseInputItem = {\n type: \"function_call_output\",\n call_id: item.call_id,\n output: toolResult,\n };\n\n nextInputItems.push(outputItem);\n } catch (error) {\n if (error instanceof StagehandClosedError) {\n throw error;\n }\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n\n logger({\n category: \"agent\",\n message: `Error executing function call: ${errorMessage}`,\n level: 0,\n });\n\n // Send error result back\n const errorOutputItem: ResponseInputItem = {\n type: \"function_call_output\",\n call_id: item.call_id,\n output: `Error: ${errorMessage}`,\n };\n\n nextInputItems.push(errorOutputItem);\n }\n }\n }\n\n return nextInputItems;\n }\n\n private convertComputerCallToAction(\n call: ComputerCallItem,\n ): AgentAction | null {\n const { action } = call;\n\n // Instead of wrapping the action in a params object, spread the action properties directly\n // This ensures properties like x, y, button, etc. are directly accessible on the AgentAction\n return {\n type: action.type as string,\n ...action, // Spread all properties from the action\n };\n }\n\n private drainContextNotes(): string[] {\n if (this.pendingContextNotes.length === 0) {\n return [];\n }\n\n const notes = [...this.pendingContextNotes];\n this.pendingContextNotes = [];\n return notes;\n }\n\n private convertFunctionCallToAction(\n call: FunctionCallItem,\n ): AgentAction | null {\n try {\n const args = JSON.parse(call.arguments);\n\n return {\n type: call.name,\n params: args,\n };\n } catch (error) {\n console.error(\"Error parsing function call arguments:\", error);\n return null;\n }\n }\n\n async captureScreenshot(options?: {\n base64Image?: string;\n currentUrl?: string;\n }): Promise<string> {\n // Use provided options if available\n if (options?.base64Image) {\n return `data:image/png;base64,${options.base64Image}`;\n }\n\n // Use the screenshot provider if available\n if (this.screenshotProvider) {\n try {\n const base64Image = await this.screenshotProvider();\n return `data:image/png;base64,${base64Image}`;\n } catch (error) {\n console.error(\"Error capturing screenshot:\", error);\n throw error;\n }\n }\n\n throw new AgentScreenshotProviderError(\n \"`screenshotProvider` has not been set. \" +\n \"Please call `setScreenshotProvider()` with a valid function that returns a base64-encoded image\",\n );\n }\n}\n"]}
@@ -4,8 +4,8 @@ export interface AgentSystemPromptOptions {
4
4
  executionInstruction: string;
5
5
  mode: AgentToolMode;
6
6
  systemInstructions?: string;
7
- /** Whether running on Browserbase (enables captcha solver messaging) */
8
- isBrowserbase?: boolean;
7
+ /** Whether captchas are automatically solved by the browser environment */
8
+ captchasAutoSolve?: boolean;
9
9
  /** Tools to exclude from the system prompt */
10
10
  excludeTools?: string[];
11
11
  /** Variables available to the agent for use in act/type tools */
@@ -1,3 +1,5 @@
1
+ import { CAPTCHA_SYSTEM_PROMPT_NOTE } from "../utils/captchaSolver.js";
2
+ import { getVariablePromptEntries } from "../utils/variables.js";
1
3
  function buildToolsSection(isHybridMode, hasSearch, excludeTools) {
2
4
  const excludeSet = new Set(excludeTools ?? []);
3
5
  const hybridTools = [
@@ -71,7 +73,7 @@ function buildToolsSection(isHybridMode, hasSearch, excludeTools) {
71
73
  return `<tools>\n${toolLines}\n </tools>`;
72
74
  }
73
75
  export function buildAgentSystemPrompt(options) {
74
- const { url, executionInstruction, mode, systemInstructions, isBrowserbase = false, excludeTools, variables, useSearch = false, } = options;
76
+ const { url, executionInstruction, mode, systemInstructions, captchasAutoSolve = false, excludeTools, variables, useSearch = false, } = options;
75
77
  const localeDate = new Date().toLocaleDateString();
76
78
  const isoDate = new Date().toISOString();
77
79
  const cdata = (text) => `<![CDATA[${text}]]>`;
@@ -132,11 +134,10 @@ export function buildAgentSystemPrompt(options) {
132
134
  </secondary_tool>
133
135
  </step_1>
134
136
  </page_understanding_protocol>`;
135
- // Roadblocks section only shown when running on Browserbase (has captcha solver)
136
- const roadblocksSection = isBrowserbase
137
+ // Roadblocks section only shown when captchas are auto-solved
138
+ const roadblocksSection = captchasAutoSolve
137
139
  ? `<roadblocks>
138
- <note>captchas, popups, etc.</note>
139
- <captcha>If you see a captcha, use the wait tool. It will automatically be solved by our internal solver.</captcha>
140
+ <note>${CAPTCHA_SYSTEM_PROMPT_NOTE}</note>
140
141
  </roadblocks>`
141
142
  : "";
142
143
  // Build customInstructions block only if provided
@@ -147,17 +148,15 @@ export function buildAgentSystemPrompt(options) {
147
148
  const hasVariables = variables && Object.keys(variables).length > 0;
148
149
  const variableToolsNote = isHybridMode
149
150
  ? "Use %variableName% syntax in the type, fillFormVision, or act tool's value/text/action fields."
150
- : "Use %variableName% syntax in the act or fillForm tool's value/action fields.";
151
+ : "Use %variableName% syntax in the act or fillForm tool's action fields.";
152
+ const variableEntries = getVariablePromptEntries(variables);
151
153
  const variablesSection = hasVariables
152
154
  ? `<variables>
153
155
  <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>
154
156
  <usage>${variableToolsNote}</usage>
155
157
  <example>To type a password, use: type %password% into the password field</example>
156
- ${Object.entries(variables)
157
- .map(([name, v]) => {
158
- const description = typeof v === "object" && v !== null && "value" in v
159
- ? v.description
160
- : undefined;
158
+ ${variableEntries
159
+ .map(({ name, description }) => {
161
160
  return description
162
161
  ? `<variable name="${name}">${description}</variable>`
163
162
  : `<variable name="${name}" />`;
@@ -1 +1 @@
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,2FAA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,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 /** 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"]}
1
+ {"version":3,"file":"agentSystemPrompt.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/prompts/agentSystemPrompt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AA4BjE,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,IA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;;;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\";\nimport { CAPTCHA_SYSTEM_PROMPT_NOTE } from \"../utils/captchaSolver.js\";\nimport { getVariablePromptEntries } from \"../utils/variables.js\";\n\nexport interface AgentSystemPromptOptions {\n url: string;\n executionInstruction: string;\n mode: AgentToolMode;\n systemInstructions?: string;\n /** Whether captchas are automatically solved by the browser environment */\n captchasAutoSolve?: 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 captchasAutoSolve = 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 captchas are auto-solved\n const roadblocksSection = captchasAutoSolve\n ? `<roadblocks>\n <note>${CAPTCHA_SYSTEM_PROMPT_NOTE}</note>\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 action fields.\";\n const variableEntries = getVariablePromptEntries(variables);\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 ${variableEntries\n .map(({ name, description }) => {\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"]}
@@ -4,7 +4,6 @@ import type { AgentModelConfig, Variables } from "../../types/public/agent.js";
4
4
  export declare const fillFormTool: (v3: V3, executionModel?: string | AgentModelConfig, variables?: Variables, toolTimeout?: number) => import("ai").Tool<{
5
5
  fields: {
6
6
  action: string;
7
- value: string;
8
7
  }[];
9
8
  }, {
10
9
  success: boolean;
@@ -3,18 +3,15 @@ import { z } from "zod";
3
3
  import { TimeoutError } from "../../types/public/sdkErrors.js";
4
4
  export const fillFormTool = (v3, executionModel, variables, toolTimeout) => {
5
5
  const hasVariables = variables && Object.keys(variables).length > 0;
6
- const valueDescription = hasVariables
7
- ? `Text to type into the target. Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(", ")}`
8
- : "Text to type into the target";
6
+ const actionDescription = hasVariables
7
+ ? `Must follow the pattern: "type <exact value> into the <field name> <fieldType>". Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(", ")}. Examples: "type %email% into the email input", "type %password% into the password input"`
8
+ : 'Must follow the pattern: "type <exact value> into the <field name> <fieldType>". Examples: "type john@example.com into the email input", "type John into the first name input"';
9
9
  return tool({
10
- description: `📝 FORM FILL - MULTI-FIELD INPUT TOOL\nFor any form with 2+ inputs/textareas. Faster than individual typing.`,
10
+ description: 'FORM FILL - MULTI-FIELD INPUT TOOL\nFill 2+ form inputs/textareas at once. Each action MUST include the exact text to type and the target field, e.g. "type john@example.com into the email field".',
11
11
  inputSchema: z.object({
12
12
  fields: z
13
13
  .array(z.object({
14
- action: z
15
- .string()
16
- .describe('Description of typing action, e.g. "type foo into the email field"'),
17
- value: z.string().describe(valueDescription),
14
+ action: z.string().describe(actionDescription),
18
15
  }))
19
16
  .min(1, "Provide at least one field to fill"),
20
17
  }),
@@ -35,8 +32,8 @@ export const fillFormTool = (v3, executionModel, variables, toolTimeout) => {
35
32
  .map((f) => f.action)
36
33
  .join(", ")}`;
37
34
  const observeOptions = executionModel
38
- ? { model: executionModel, timeout: toolTimeout }
39
- : { timeout: toolTimeout };
35
+ ? { model: executionModel, variables, timeout: toolTimeout }
36
+ : { variables, timeout: toolTimeout };
40
37
  const observeResults = await v3.observe(instruction, observeOptions);
41
38
  const completed = [];
42
39
  const replayableActions = [];
@@ -1 +1 @@
1
- {"version":3,"file":"fillform.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/fillform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,EAAM,EACN,cAA0C,EAC1C,SAAqB,EACrB,WAAoB,EACpB,EAAE;IACF,MAAM,YAAY,GAAG,SAAS,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AAC","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 { AgentModelConfig, Variables } from \"../../types/public/agent.js\";\nimport { TimeoutError } from \"../../types/public/sdkErrors.js\";\n\nexport const fillFormTool = (\n v3: V3,\n executionModel?: string | AgentModelConfig,\n variables?: Variables,\n toolTimeout?: number,\n) => {\n const hasVariables = variables && Object.keys(variables).length > 0;\n const valueDescription = hasVariables\n ? `Text to type into the target. Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(\", \")}`\n : \"Text to type into the target\";\n\n return tool({\n description: `📝 FORM FILL - MULTI-FIELD INPUT TOOL\\nFor any form with 2+ inputs/textareas. Faster than individual typing.`,\n inputSchema: z.object({\n fields: z\n .array(\n z.object({\n action: z\n .string()\n .describe(\n 'Description of typing action, e.g. \"type foo into the email field\"',\n ),\n value: z.string().describe(valueDescription),\n }),\n )\n .min(1, \"Provide at least one field to fill\"),\n }),\n execute: async ({ fields }) => {\n try {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: fillForm`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify(fields),\n type: \"object\",\n },\n },\n });\n const instruction = `Return observation results for the following actions: ${fields\n .map((f) => f.action)\n .join(\", \")}`;\n\n const observeOptions = executionModel\n ? { model: executionModel, timeout: toolTimeout }\n : { timeout: toolTimeout };\n const observeResults = await v3.observe(instruction, observeOptions);\n\n const completed = [] as unknown[];\n const replayableActions: Action[] = [];\n for (const res of observeResults) {\n const actOptions = variables\n ? { variables, timeout: toolTimeout }\n : { timeout: toolTimeout };\n const actResult = await v3.act(res, actOptions);\n completed.push(actResult);\n if (Array.isArray(actResult.actions)) {\n replayableActions.push(...(actResult.actions as Action[]));\n }\n }\n v3.recordAgentReplayStep({\n type: \"fillForm\",\n fields,\n observeResults,\n actions: replayableActions,\n });\n return {\n success: true,\n actions: completed,\n playwrightArguments: replayableActions,\n };\n } catch (error) {\n if (error instanceof TimeoutError) {\n throw error;\n }\n return {\n success: false,\n error: error?.message ?? String(error),\n };\n }\n },\n });\n};\n"]}
1
+ {"version":3,"file":"fillform.js","sourceRoot":"","sources":["../../../../../../lib/v3/agent/tools/fillform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,EAAM,EACN,cAA0C,EAC1C,SAAqB,EACrB,WAAoB,EACpB,EAAE;IACF,MAAM,YAAY,GAAG,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACpE,MAAM,iBAAiB,GAAG,YAAY;QACpC,CAAC,CAAC,kJAAkJ,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,4FAA4F;QACjR,CAAC,CAAC,gLAAgL,CAAC;IAErL,OAAO,IAAI,CAAC;QACV,WAAW,EACT,qMAAqM;QACvM,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;YACpB,MAAM,EAAE,CAAC;iBACN,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;gBACP,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC;aAC/C,CAAC,CACH;iBACA,GAAG,CAAC,CAAC,EAAE,oCAAoC,CAAC;SAChD,CAAC;QACF,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;YAC5B,IAAI,CAAC;gBACH,EAAE,CAAC,MAAM,CAAC;oBACR,QAAQ,EAAE,OAAO;oBACjB,OAAO,EAAE,8BAA8B;oBACvC,KAAK,EAAE,CAAC;oBACR,SAAS,EAAE;wBACT,SAAS,EAAE;4BACT,KAA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AAC,CAAC;gBACH,OAAO;oBACL,OAAO,EAAE,IAAI;oBACb,OAAO,EAAE,SAAS;oBAClB,mBAAmB,EAAE,iBAAiB;iBACvC,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;oBAClC,MAAM,KAAK,CAAC;gBACd,CAAC;gBACD,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,KAAK,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC;iBACvC,CAAC;YACJ,CAAC;QACH,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 { AgentModelConfig, Variables } from \"../../types/public/agent.js\";\nimport { TimeoutError } from \"../../types/public/sdkErrors.js\";\n\nexport const fillFormTool = (\n v3: V3,\n executionModel?: string | AgentModelConfig,\n variables?: Variables,\n toolTimeout?: number,\n) => {\n const hasVariables = variables && Object.keys(variables).length > 0;\n const actionDescription = hasVariables\n ? `Must follow the pattern: \"type <exact value> into the <field name> <fieldType>\". Use %variableName% to substitute a variable value. Available: ${Object.keys(variables).join(\", \")}. Examples: \"type %email% into the email input\", \"type %password% into the password input\"`\n : 'Must follow the pattern: \"type <exact value> into the <field name> <fieldType>\". Examples: \"type john@example.com into the email input\", \"type John into the first name input\"';\n\n return tool({\n description:\n 'FORM FILL - MULTI-FIELD INPUT TOOL\\nFill 2+ form inputs/textareas at once. Each action MUST include the exact text to type and the target field, e.g. \"type john@example.com into the email field\".',\n inputSchema: z.object({\n fields: z\n .array(\n z.object({\n action: z.string().describe(actionDescription),\n }),\n )\n .min(1, \"Provide at least one field to fill\"),\n }),\n execute: async ({ fields }) => {\n try {\n v3.logger({\n category: \"agent\",\n message: `Agent calling tool: fillForm`,\n level: 1,\n auxiliary: {\n arguments: {\n value: JSON.stringify(fields),\n type: \"object\",\n },\n },\n });\n const instruction = `Return observation results for the following actions: ${fields\n .map((f) => f.action)\n .join(\", \")}`;\n\n const observeOptions = executionModel\n ? { model: executionModel, variables, timeout: toolTimeout }\n : { variables, timeout: toolTimeout };\n const observeResults = await v3.observe(instruction, observeOptions);\n\n const completed = [] as unknown[];\n const replayableActions: Action[] = [];\n for (const res of observeResults) {\n const actOptions = variables\n ? { variables, timeout: toolTimeout }\n : { timeout: toolTimeout };\n const actResult = await v3.act(res, actOptions);\n completed.push(actResult);\n if (Array.isArray(actResult.actions)) {\n replayableActions.push(...(actResult.actions as Action[]));\n }\n }\n v3.recordAgentReplayStep({\n type: \"fillForm\",\n fields,\n observeResults,\n actions: replayableActions,\n });\n return {\n success: true,\n actions: completed,\n playwrightArguments: replayableActions,\n };\n } catch (error) {\n if (error instanceof TimeoutError) {\n throw error;\n }\n return {\n success: false,\n error: error?.message ?? String(error),\n };\n }\n },\n });\n};\n"]}