@wingman-ai/gateway 0.5.3 → 0.5.4

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 (311) hide show
  1. package/dist/agent/config/agentConfig.cjs +4 -0
  2. package/dist/agent/config/agentConfig.d.ts +12 -0
  3. package/dist/agent/config/agentConfig.js +4 -0
  4. package/dist/agent/config/toolRegistry.cjs +75 -1
  5. package/dist/agent/config/toolRegistry.d.ts +3 -0
  6. package/dist/agent/config/toolRegistry.js +75 -1
  7. package/dist/agent/middleware/large-tool-results.cjs +207 -0
  8. package/dist/agent/middleware/large-tool-results.d.ts +16 -0
  9. package/dist/agent/middleware/large-tool-results.js +173 -0
  10. package/dist/agent/tools/browser_control.cjs +9 -1231
  11. package/dist/agent/tools/browser_control.d.ts +126 -234
  12. package/dist/agent/tools/browser_control.js +7 -1226
  13. package/dist/agent/tools/browser_runtime.cjs +1189 -0
  14. package/dist/agent/tools/browser_runtime.d.ts +560 -0
  15. package/dist/agent/tools/browser_runtime.js +1122 -0
  16. package/dist/agent/tools/browser_session.cjs +153 -0
  17. package/dist/agent/tools/browser_session.d.ts +741 -0
  18. package/dist/agent/tools/browser_session.js +110 -0
  19. package/dist/agent/tools/browser_session_manager.cjs +202 -0
  20. package/dist/agent/tools/browser_session_manager.d.ts +64 -0
  21. package/dist/agent/tools/browser_session_manager.js +165 -0
  22. package/dist/cli/commands/init.cjs +5 -1
  23. package/dist/cli/commands/init.js +5 -1
  24. package/dist/cli/config/loader.cjs +0 -5
  25. package/dist/cli/config/loader.js +0 -5
  26. package/dist/cli/config/schema.cjs +3 -7
  27. package/dist/cli/config/schema.d.ts +6 -6
  28. package/dist/cli/config/schema.js +3 -7
  29. package/dist/cli/core/agentInvoker.cjs +86 -22
  30. package/dist/cli/core/agentInvoker.d.ts +10 -3
  31. package/dist/cli/core/agentInvoker.js +86 -25
  32. package/dist/cli/core/outputManager.cjs +7 -2
  33. package/dist/cli/core/outputManager.d.ts +2 -2
  34. package/dist/cli/core/outputManager.js +7 -2
  35. package/dist/cli/types.d.ts +2 -1
  36. package/dist/webui/assets/index-XrEnkZiq.css +11 -0
  37. package/dist/webui/assets/index-mDs6HbKM.js +215 -0
  38. package/dist/webui/index.html +2 -2
  39. package/package.json +10 -10
  40. package/templates/agents/README.md +2 -1
  41. package/templates/agents/coding/agent.md +6 -13
  42. package/templates/agents/coding-v2/agent.md +6 -1
  43. package/templates/agents/game-dev/agent.md +8 -2
  44. package/templates/agents/game-dev/game-designer.md +4 -0
  45. package/templates/agents/game-dev/scene-engineer.md +4 -0
  46. package/templates/agents/main/agent.md +5 -0
  47. package/templates/agents/researcher/agent.md +11 -0
  48. package/templates/agents/stock-trader/agent.md +4 -0
  49. package/dist/agent/tests/agentConfig.test.cjs +0 -224
  50. package/dist/agent/tests/agentConfig.test.d.ts +0 -1
  51. package/dist/agent/tests/agentConfig.test.js +0 -218
  52. package/dist/agent/tests/agentLoader.test.cjs +0 -335
  53. package/dist/agent/tests/agentLoader.test.d.ts +0 -1
  54. package/dist/agent/tests/agentLoader.test.js +0 -329
  55. package/dist/agent/tests/backgroundTerminal.test.cjs +0 -70
  56. package/dist/agent/tests/backgroundTerminal.test.d.ts +0 -1
  57. package/dist/agent/tests/backgroundTerminal.test.js +0 -64
  58. package/dist/agent/tests/browserControlHelpers.test.cjs +0 -35
  59. package/dist/agent/tests/browserControlHelpers.test.d.ts +0 -1
  60. package/dist/agent/tests/browserControlHelpers.test.js +0 -29
  61. package/dist/agent/tests/browserControlTool.test.cjs +0 -2117
  62. package/dist/agent/tests/browserControlTool.test.d.ts +0 -1
  63. package/dist/agent/tests/browserControlTool.test.js +0 -2111
  64. package/dist/agent/tests/commandExecuteTool.test.cjs +0 -29
  65. package/dist/agent/tests/commandExecuteTool.test.d.ts +0 -1
  66. package/dist/agent/tests/commandExecuteTool.test.js +0 -23
  67. package/dist/agent/tests/internet_search.test.cjs +0 -107
  68. package/dist/agent/tests/internet_search.test.d.ts +0 -1
  69. package/dist/agent/tests/internet_search.test.js +0 -101
  70. package/dist/agent/tests/mcpClientManager.test.cjs +0 -290
  71. package/dist/agent/tests/mcpClientManager.test.d.ts +0 -1
  72. package/dist/agent/tests/mcpClientManager.test.js +0 -284
  73. package/dist/agent/tests/mcpResourceTools.test.cjs +0 -101
  74. package/dist/agent/tests/mcpResourceTools.test.d.ts +0 -1
  75. package/dist/agent/tests/mcpResourceTools.test.js +0 -95
  76. package/dist/agent/tests/modelFactory.test.cjs +0 -190
  77. package/dist/agent/tests/modelFactory.test.d.ts +0 -1
  78. package/dist/agent/tests/modelFactory.test.js +0 -184
  79. package/dist/agent/tests/terminalSessionManager.test.cjs +0 -121
  80. package/dist/agent/tests/terminalSessionManager.test.d.ts +0 -1
  81. package/dist/agent/tests/terminalSessionManager.test.js +0 -115
  82. package/dist/agent/tests/test-agent-loader.cjs +0 -33
  83. package/dist/agent/tests/test-agent-loader.d.ts +0 -1
  84. package/dist/agent/tests/test-agent-loader.js +0 -27
  85. package/dist/agent/tests/test-subagent-loading.cjs +0 -99
  86. package/dist/agent/tests/test-subagent-loading.d.ts +0 -1
  87. package/dist/agent/tests/test-subagent-loading.js +0 -93
  88. package/dist/agent/tests/toolRegistry.test.cjs +0 -147
  89. package/dist/agent/tests/toolRegistry.test.d.ts +0 -1
  90. package/dist/agent/tests/toolRegistry.test.js +0 -141
  91. package/dist/agent/tests/uiRegistryTools.test.cjs +0 -114
  92. package/dist/agent/tests/uiRegistryTools.test.d.ts +0 -1
  93. package/dist/agent/tests/uiRegistryTools.test.js +0 -105
  94. package/dist/agent/tests/xaiImageModel.test.cjs +0 -194
  95. package/dist/agent/tests/xaiImageModel.test.d.ts +0 -1
  96. package/dist/agent/tests/xaiImageModel.test.js +0 -188
  97. package/dist/tests/additionalMessageMiddleware.test.cjs +0 -216
  98. package/dist/tests/additionalMessageMiddleware.test.d.ts +0 -1
  99. package/dist/tests/additionalMessageMiddleware.test.js +0 -188
  100. package/dist/tests/agent-config-voice.test.cjs +0 -25
  101. package/dist/tests/agent-config-voice.test.d.ts +0 -1
  102. package/dist/tests/agent-config-voice.test.js +0 -19
  103. package/dist/tests/agentInvokerAttachments.test.cjs +0 -190
  104. package/dist/tests/agentInvokerAttachments.test.d.ts +0 -1
  105. package/dist/tests/agentInvokerAttachments.test.js +0 -184
  106. package/dist/tests/agentInvokerSummarization.test.cjs +0 -613
  107. package/dist/tests/agentInvokerSummarization.test.d.ts +0 -1
  108. package/dist/tests/agentInvokerSummarization.test.js +0 -607
  109. package/dist/tests/agentInvokerTokenUsage.test.cjs +0 -124
  110. package/dist/tests/agentInvokerTokenUsage.test.d.ts +0 -1
  111. package/dist/tests/agentInvokerTokenUsage.test.js +0 -118
  112. package/dist/tests/agentInvokerWorkdir.test.cjs +0 -150
  113. package/dist/tests/agentInvokerWorkdir.test.d.ts +0 -1
  114. package/dist/tests/agentInvokerWorkdir.test.js +0 -122
  115. package/dist/tests/agents-api.test.cjs +0 -324
  116. package/dist/tests/agents-api.test.d.ts +0 -1
  117. package/dist/tests/agents-api.test.js +0 -318
  118. package/dist/tests/attachments-utils.test.cjs +0 -46
  119. package/dist/tests/attachments-utils.test.d.ts +0 -1
  120. package/dist/tests/attachments-utils.test.js +0 -40
  121. package/dist/tests/browser-command.test.cjs +0 -264
  122. package/dist/tests/browser-command.test.d.ts +0 -1
  123. package/dist/tests/browser-command.test.js +0 -258
  124. package/dist/tests/browser-relay-server.test.cjs +0 -20
  125. package/dist/tests/browser-relay-server.test.d.ts +0 -1
  126. package/dist/tests/browser-relay-server.test.js +0 -14
  127. package/dist/tests/bunSqliteAdapter.test.cjs +0 -265
  128. package/dist/tests/bunSqliteAdapter.test.d.ts +0 -1
  129. package/dist/tests/bunSqliteAdapter.test.js +0 -259
  130. package/dist/tests/candleRange.test.cjs +0 -48
  131. package/dist/tests/candleRange.test.d.ts +0 -1
  132. package/dist/tests/candleRange.test.js +0 -42
  133. package/dist/tests/cli-config-loader.test.cjs +0 -532
  134. package/dist/tests/cli-config-loader.test.d.ts +0 -1
  135. package/dist/tests/cli-config-loader.test.js +0 -526
  136. package/dist/tests/cli-config-warnings.test.cjs +0 -94
  137. package/dist/tests/cli-config-warnings.test.d.ts +0 -1
  138. package/dist/tests/cli-config-warnings.test.js +0 -88
  139. package/dist/tests/cli-init.test.cjs +0 -225
  140. package/dist/tests/cli-init.test.d.ts +0 -1
  141. package/dist/tests/cli-init.test.js +0 -219
  142. package/dist/tests/cli-workspace-root.test.cjs +0 -114
  143. package/dist/tests/cli-workspace-root.test.d.ts +0 -1
  144. package/dist/tests/cli-workspace-root.test.js +0 -108
  145. package/dist/tests/codex-credentials-precedence.test.cjs +0 -94
  146. package/dist/tests/codex-credentials-precedence.test.d.ts +0 -1
  147. package/dist/tests/codex-credentials-precedence.test.js +0 -88
  148. package/dist/tests/codex-provider.test.cjs +0 -383
  149. package/dist/tests/codex-provider.test.d.ts +0 -1
  150. package/dist/tests/codex-provider.test.js +0 -377
  151. package/dist/tests/config-json-schema.test.cjs +0 -37
  152. package/dist/tests/config-json-schema.test.d.ts +0 -1
  153. package/dist/tests/config-json-schema.test.js +0 -31
  154. package/dist/tests/discord-adapter.test.cjs +0 -89
  155. package/dist/tests/discord-adapter.test.d.ts +0 -1
  156. package/dist/tests/discord-adapter.test.js +0 -83
  157. package/dist/tests/falRuntime.test.cjs +0 -78
  158. package/dist/tests/falRuntime.test.d.ts +0 -1
  159. package/dist/tests/falRuntime.test.js +0 -72
  160. package/dist/tests/falSummary.test.cjs +0 -51
  161. package/dist/tests/falSummary.test.d.ts +0 -1
  162. package/dist/tests/falSummary.test.js +0 -45
  163. package/dist/tests/fs-api.test.cjs +0 -138
  164. package/dist/tests/fs-api.test.d.ts +0 -1
  165. package/dist/tests/fs-api.test.js +0 -132
  166. package/dist/tests/gateway-command-workspace.test.cjs +0 -150
  167. package/dist/tests/gateway-command-workspace.test.d.ts +0 -1
  168. package/dist/tests/gateway-command-workspace.test.js +0 -144
  169. package/dist/tests/gateway-http-security.test.cjs +0 -318
  170. package/dist/tests/gateway-http-security.test.d.ts +0 -1
  171. package/dist/tests/gateway-http-security.test.js +0 -312
  172. package/dist/tests/gateway-node-mode.test.cjs +0 -174
  173. package/dist/tests/gateway-node-mode.test.d.ts +0 -1
  174. package/dist/tests/gateway-node-mode.test.js +0 -168
  175. package/dist/tests/gateway-origin-policy.test.cjs +0 -82
  176. package/dist/tests/gateway-origin-policy.test.d.ts +0 -1
  177. package/dist/tests/gateway-origin-policy.test.js +0 -76
  178. package/dist/tests/gateway-request-execution-overrides.test.cjs +0 -42
  179. package/dist/tests/gateway-request-execution-overrides.test.d.ts +0 -1
  180. package/dist/tests/gateway-request-execution-overrides.test.js +0 -36
  181. package/dist/tests/gateway.test.cjs +0 -700
  182. package/dist/tests/gateway.test.d.ts +0 -1
  183. package/dist/tests/gateway.test.js +0 -694
  184. package/dist/tests/hooks-matcher.test.cjs +0 -309
  185. package/dist/tests/hooks-matcher.test.d.ts +0 -1
  186. package/dist/tests/hooks-matcher.test.js +0 -303
  187. package/dist/tests/hooks-merger.test.cjs +0 -528
  188. package/dist/tests/hooks-merger.test.d.ts +0 -1
  189. package/dist/tests/hooks-merger.test.js +0 -522
  190. package/dist/tests/imagePersistence.test.cjs +0 -169
  191. package/dist/tests/imagePersistence.test.d.ts +0 -1
  192. package/dist/tests/imagePersistence.test.js +0 -163
  193. package/dist/tests/integration/agent-invocation.integration.test.cjs +0 -264
  194. package/dist/tests/integration/agent-invocation.integration.test.d.ts +0 -1
  195. package/dist/tests/integration/agent-invocation.integration.test.js +0 -258
  196. package/dist/tests/integration/finnhub-candles.integration.test.cjs +0 -98
  197. package/dist/tests/integration/finnhub-candles.integration.test.d.ts +0 -1
  198. package/dist/tests/integration/finnhub-candles.integration.test.js +0 -92
  199. package/dist/tests/integration/summarization-e2e.integration.test.cjs +0 -127
  200. package/dist/tests/integration/summarization-e2e.integration.test.d.ts +0 -1
  201. package/dist/tests/integration/summarization-e2e.integration.test.js +0 -121
  202. package/dist/tests/logger.test.cjs +0 -353
  203. package/dist/tests/logger.test.d.ts +0 -1
  204. package/dist/tests/logger.test.js +0 -347
  205. package/dist/tests/mediaCompatibilityMiddleware.test.cjs +0 -106
  206. package/dist/tests/mediaCompatibilityMiddleware.test.d.ts +0 -1
  207. package/dist/tests/mediaCompatibilityMiddleware.test.js +0 -100
  208. package/dist/tests/node-tools.test.cjs +0 -77
  209. package/dist/tests/node-tools.test.d.ts +0 -1
  210. package/dist/tests/node-tools.test.js +0 -71
  211. package/dist/tests/nodes-api.test.cjs +0 -86
  212. package/dist/tests/nodes-api.test.d.ts +0 -1
  213. package/dist/tests/nodes-api.test.js +0 -80
  214. package/dist/tests/outputManagerContextSummarized.test.cjs +0 -43
  215. package/dist/tests/outputManagerContextSummarized.test.d.ts +0 -1
  216. package/dist/tests/outputManagerContextSummarized.test.js +0 -37
  217. package/dist/tests/provider-command-codex.test.cjs +0 -57
  218. package/dist/tests/provider-command-codex.test.d.ts +0 -1
  219. package/dist/tests/provider-command-codex.test.js +0 -51
  220. package/dist/tests/routines-api.test.cjs +0 -107
  221. package/dist/tests/routines-api.test.d.ts +0 -1
  222. package/dist/tests/routines-api.test.js +0 -101
  223. package/dist/tests/run-terminal-bench-official-script.test.cjs +0 -61
  224. package/dist/tests/run-terminal-bench-official-script.test.d.ts +0 -1
  225. package/dist/tests/run-terminal-bench-official-script.test.js +0 -55
  226. package/dist/tests/sessionManager-uionly.test.cjs +0 -50
  227. package/dist/tests/sessionManager-uionly.test.d.ts +0 -1
  228. package/dist/tests/sessionManager-uionly.test.js +0 -44
  229. package/dist/tests/sessionMessageAttachments.test.cjs +0 -197
  230. package/dist/tests/sessionMessageAttachments.test.d.ts +0 -1
  231. package/dist/tests/sessionMessageAttachments.test.js +0 -191
  232. package/dist/tests/sessionMessageRole.test.cjs +0 -44
  233. package/dist/tests/sessionMessageRole.test.d.ts +0 -1
  234. package/dist/tests/sessionMessageRole.test.js +0 -38
  235. package/dist/tests/sessionStateMessages.test.cjs +0 -236
  236. package/dist/tests/sessionStateMessages.test.d.ts +0 -1
  237. package/dist/tests/sessionStateMessages.test.js +0 -230
  238. package/dist/tests/sessions-api.test.cjs +0 -250
  239. package/dist/tests/sessions-api.test.d.ts +0 -1
  240. package/dist/tests/sessions-api.test.js +0 -244
  241. package/dist/tests/skill-activation.test.cjs +0 -86
  242. package/dist/tests/skill-activation.test.d.ts +0 -1
  243. package/dist/tests/skill-activation.test.js +0 -80
  244. package/dist/tests/skill-metadata.test.cjs +0 -119
  245. package/dist/tests/skill-metadata.test.d.ts +0 -1
  246. package/dist/tests/skill-metadata.test.js +0 -113
  247. package/dist/tests/skill-repository.test.cjs +0 -469
  248. package/dist/tests/skill-repository.test.d.ts +0 -1
  249. package/dist/tests/skill-repository.test.js +0 -463
  250. package/dist/tests/skill-security-scanner.test.cjs +0 -126
  251. package/dist/tests/skill-security-scanner.test.d.ts +0 -1
  252. package/dist/tests/skill-security-scanner.test.js +0 -120
  253. package/dist/tests/sms-api.test.cjs +0 -183
  254. package/dist/tests/sms-api.test.d.ts +0 -1
  255. package/dist/tests/sms-api.test.js +0 -177
  256. package/dist/tests/sms-commands.test.cjs +0 -90
  257. package/dist/tests/sms-commands.test.d.ts +0 -1
  258. package/dist/tests/sms-commands.test.js +0 -84
  259. package/dist/tests/sms-policy-store.test.cjs +0 -69
  260. package/dist/tests/sms-policy-store.test.d.ts +0 -1
  261. package/dist/tests/sms-policy-store.test.js +0 -63
  262. package/dist/tests/teams-adapter.test.cjs +0 -58
  263. package/dist/tests/teams-adapter.test.d.ts +0 -1
  264. package/dist/tests/teams-adapter.test.js +0 -52
  265. package/dist/tests/technicalIndicators.test.cjs +0 -82
  266. package/dist/tests/technicalIndicators.test.d.ts +0 -1
  267. package/dist/tests/technicalIndicators.test.js +0 -76
  268. package/dist/tests/terminal-bench-adapters-helpers.test.cjs +0 -64
  269. package/dist/tests/terminal-bench-adapters-helpers.test.d.ts +0 -1
  270. package/dist/tests/terminal-bench-adapters-helpers.test.js +0 -58
  271. package/dist/tests/terminal-bench-cleanup.test.cjs +0 -93
  272. package/dist/tests/terminal-bench-cleanup.test.d.ts +0 -1
  273. package/dist/tests/terminal-bench-cleanup.test.js +0 -87
  274. package/dist/tests/terminal-bench-config.test.cjs +0 -62
  275. package/dist/tests/terminal-bench-config.test.d.ts +0 -1
  276. package/dist/tests/terminal-bench-config.test.js +0 -56
  277. package/dist/tests/terminal-bench-official.test.cjs +0 -194
  278. package/dist/tests/terminal-bench-official.test.d.ts +0 -1
  279. package/dist/tests/terminal-bench-official.test.js +0 -188
  280. package/dist/tests/terminal-bench-runner.test.cjs +0 -82
  281. package/dist/tests/terminal-bench-runner.test.d.ts +0 -1
  282. package/dist/tests/terminal-bench-runner.test.js +0 -76
  283. package/dist/tests/terminal-bench-scoring.test.cjs +0 -128
  284. package/dist/tests/terminal-bench-scoring.test.d.ts +0 -1
  285. package/dist/tests/terminal-bench-scoring.test.js +0 -122
  286. package/dist/tests/terminalProbe.test.cjs +0 -45
  287. package/dist/tests/terminalProbe.test.d.ts +0 -1
  288. package/dist/tests/terminalProbe.test.js +0 -39
  289. package/dist/tests/terminalProbeAuth.test.cjs +0 -85
  290. package/dist/tests/terminalProbeAuth.test.d.ts +0 -1
  291. package/dist/tests/terminalProbeAuth.test.js +0 -79
  292. package/dist/tests/toolDisplayHelpers.test.cjs +0 -46
  293. package/dist/tests/toolDisplayHelpers.test.d.ts +0 -1
  294. package/dist/tests/toolDisplayHelpers.test.js +0 -40
  295. package/dist/tests/uv.test.cjs +0 -47
  296. package/dist/tests/uv.test.d.ts +0 -1
  297. package/dist/tests/uv.test.js +0 -41
  298. package/dist/tests/voice-config.test.cjs +0 -35
  299. package/dist/tests/voice-config.test.d.ts +0 -1
  300. package/dist/tests/voice-config.test.js +0 -29
  301. package/dist/tests/websocket-transport.test.cjs +0 -31
  302. package/dist/tests/websocket-transport.test.d.ts +0 -1
  303. package/dist/tests/websocket-transport.test.js +0 -25
  304. package/dist/tests/yahooCandles.test.cjs +0 -111
  305. package/dist/tests/yahooCandles.test.d.ts +0 -1
  306. package/dist/tests/yahooCandles.test.js +0 -105
  307. package/dist/tools/finance/optionsAnalytics.test.cjs +0 -128
  308. package/dist/tools/finance/optionsAnalytics.test.d.ts +0 -1
  309. package/dist/tools/finance/optionsAnalytics.test.js +0 -122
  310. package/dist/webui/assets/index-BMf95nv5.js +0 -215
  311. package/dist/webui/assets/index-DhJQ8Mbn.css +0 -11
@@ -1,2117 +0,0 @@
1
- "use strict";
2
- var __webpack_exports__ = {};
3
- const external_node_fs_namespaceObject = require("node:fs");
4
- const external_node_child_process_namespaceObject = require("node:child_process");
5
- const external_node_os_namespaceObject = require("node:os");
6
- const external_node_path_namespaceObject = require("node:path");
7
- const external_vitest_namespaceObject = require("vitest");
8
- const browser_control_cjs_namespaceObject = require("../tools/browser_control.cjs");
9
- (0, external_vitest_namespaceObject.describe)("browser_control tool", ()=>{
10
- const workspaces = [];
11
- (0, external_vitest_namespaceObject.afterEach)(()=>{
12
- for (const workspace of workspaces)(0, external_node_fs_namespaceObject.rmSync)(workspace, {
13
- recursive: true,
14
- force: true
15
- });
16
- workspaces.length = 0;
17
- });
18
- (0, external_vitest_namespaceObject.it)("runs browser actions through injected CDP/playwright dependencies", async ()=>{
19
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
20
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
21
- workspaces.push(workspace, tempDir);
22
- let currentUrl = "about:blank";
23
- let browserClosed = false;
24
- let chromeClosed = false;
25
- const actionCalls = [];
26
- const page = {
27
- goto: async (url)=>{
28
- currentUrl = url;
29
- actionCalls.push(`goto:${url}`);
30
- },
31
- click: async (selector)=>{
32
- actionCalls.push(`click:${selector}`);
33
- },
34
- fill: async (selector, text)=>{
35
- actionCalls.push(`fill:${selector}:${text}`);
36
- },
37
- keyboard: {
38
- press: async (key)=>{
39
- actionCalls.push(`press:${key}`);
40
- }
41
- },
42
- waitForTimeout: async (ms)=>{
43
- actionCalls.push(`wait:${ms}`);
44
- },
45
- textContent: async (selector)=>{
46
- actionCalls.push(`text:${selector}`);
47
- return "body" === selector ? "Example page body content" : "Selector content";
48
- },
49
- evaluate: async (expression)=>{
50
- actionCalls.push(`eval:${expression}`);
51
- return {
52
- ok: true
53
- };
54
- },
55
- screenshot: async ({ path })=>{
56
- actionCalls.push(`screenshot:${path}`);
57
- (0, external_node_fs_namespaceObject.writeFileSync)(path, "test image data");
58
- },
59
- title: async ()=>"Example Title",
60
- url: ()=>currentUrl
61
- };
62
- const context = {
63
- pages: ()=>[
64
- page
65
- ],
66
- newPage: async ()=>page
67
- };
68
- const browser = {
69
- contexts: ()=>[
70
- context
71
- ],
72
- close: async ()=>{
73
- browserClosed = true;
74
- }
75
- };
76
- const testDeps = {
77
- importPlaywright: async ()=>({
78
- chromium: {
79
- connectOverCDP: async ()=>browser
80
- }
81
- }),
82
- startChrome: async ()=>({
83
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
84
- close: async ()=>{
85
- chromeClosed = true;
86
- }
87
- }),
88
- mkTempDir: ()=>tempDir,
89
- removeDir: ()=>{},
90
- now: ()=>1700000000000
91
- };
92
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
93
- workspace
94
- }, testDeps);
95
- const result = await tool.invoke({
96
- url: "https://example.com",
97
- actions: [
98
- {
99
- type: "click",
100
- selector: "#cta"
101
- },
102
- {
103
- type: "type",
104
- selector: "#query",
105
- text: "wingman",
106
- submit: true
107
- },
108
- {
109
- type: "extract_text",
110
- selector: "body",
111
- maxChars: 10
112
- },
113
- {
114
- type: "evaluate",
115
- expression: "window.location.href"
116
- },
117
- {
118
- type: "screenshot",
119
- path: "artifacts/shot.png",
120
- fullPage: false
121
- }
122
- ]
123
- });
124
- const parsed = JSON.parse(String(result));
125
- (0, external_vitest_namespaceObject.expect)(parsed.browser).toBe("chrome-cdp");
126
- (0, external_vitest_namespaceObject.expect)(parsed.finalUrl).toBe("https://example.com");
127
- (0, external_vitest_namespaceObject.expect)(parsed.title).toBe("Example Title");
128
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults).toHaveLength(5);
129
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[2].text).toBe("Example pa");
130
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[4].path).toBe("artifacts/shot.png");
131
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("click:#cta");
132
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("press:Enter");
133
- (0, external_vitest_namespaceObject.expect)(browserClosed).toBe(true);
134
- (0, external_vitest_namespaceObject.expect)(chromeClosed).toBe(true);
135
- });
136
- (0, external_vitest_namespaceObject.it)("targets the most recently opened tab in the CDP context", async ()=>{
137
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
138
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
139
- workspaces.push(workspace, tempDir);
140
- const stalePageCalls = [];
141
- const activePageCalls = [];
142
- let currentUrl = "about:blank";
143
- const stalePage = {
144
- goto: async (url)=>{
145
- stalePageCalls.push(`goto:${url}`);
146
- },
147
- click: async ()=>{},
148
- fill: async ()=>{},
149
- keyboard: {
150
- press: async ()=>{}
151
- },
152
- waitForTimeout: async ()=>{},
153
- textContent: async ()=>"",
154
- evaluate: async ()=>({}),
155
- screenshot: async ()=>{},
156
- title: async ()=>"Stale",
157
- url: ()=>"about:blank"
158
- };
159
- const activePage = {
160
- goto: async (url)=>{
161
- currentUrl = url;
162
- activePageCalls.push(`goto:${url}`);
163
- },
164
- bringToFront: async ()=>{
165
- activePageCalls.push("bringToFront");
166
- },
167
- click: async ()=>{},
168
- fill: async ()=>{},
169
- keyboard: {
170
- press: async ()=>{}
171
- },
172
- waitForTimeout: async ()=>{},
173
- textContent: async ()=>"",
174
- evaluate: async ()=>({}),
175
- screenshot: async ()=>{},
176
- title: async ()=>"Active",
177
- url: ()=>currentUrl
178
- };
179
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
180
- workspace
181
- }, {
182
- importPlaywright: async ()=>({
183
- chromium: {
184
- connectOverCDP: async ()=>({
185
- contexts: ()=>[
186
- {
187
- pages: ()=>[
188
- stalePage,
189
- activePage
190
- ],
191
- newPage: async ()=>activePage
192
- }
193
- ],
194
- close: async ()=>{}
195
- })
196
- }
197
- }),
198
- startChrome: async ()=>({
199
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
200
- close: async ()=>{}
201
- }),
202
- mkTempDir: ()=>tempDir,
203
- removeDir: ()=>{},
204
- now: ()=>1700000000000
205
- });
206
- const result = await tool.invoke({
207
- url: "https://example.com"
208
- });
209
- const parsed = JSON.parse(String(result));
210
- (0, external_vitest_namespaceObject.expect)(parsed.finalUrl).toBe("https://example.com");
211
- (0, external_vitest_namespaceObject.expect)(stalePageCalls).toHaveLength(0);
212
- (0, external_vitest_namespaceObject.expect)(activePageCalls).toContain("bringToFront");
213
- (0, external_vitest_namespaceObject.expect)(activePageCalls).toContain("goto:https://example.com");
214
- });
215
- (0, external_vitest_namespaceObject.it)("uses a context with pages when the first CDP context is empty", async ()=>{
216
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
217
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
218
- workspaces.push(workspace, tempDir);
219
- const hiddenContextCalls = [];
220
- const visibleContextCalls = [];
221
- let currentUrl = "about:blank";
222
- const hiddenContext = {
223
- pages: ()=>[],
224
- newPage: async ()=>{
225
- hiddenContextCalls.push("newPage");
226
- return {
227
- goto: async (url)=>hiddenContextCalls.push(`goto:${url}`),
228
- click: async ()=>{},
229
- fill: async ()=>{},
230
- keyboard: {
231
- press: async ()=>{}
232
- },
233
- waitForTimeout: async ()=>{},
234
- textContent: async ()=>"",
235
- evaluate: async ()=>({}),
236
- screenshot: async ()=>{},
237
- title: async ()=>"Hidden",
238
- url: ()=>"about:blank"
239
- };
240
- }
241
- };
242
- const visiblePage = {
243
- goto: async (url)=>{
244
- currentUrl = url;
245
- visibleContextCalls.push(`goto:${url}`);
246
- },
247
- bringToFront: async ()=>{
248
- visibleContextCalls.push("bringToFront");
249
- },
250
- click: async ()=>{},
251
- fill: async ()=>{},
252
- keyboard: {
253
- press: async ()=>{}
254
- },
255
- waitForTimeout: async ()=>{},
256
- textContent: async ()=>"",
257
- evaluate: async ()=>({}),
258
- screenshot: async ()=>{},
259
- title: async ()=>"Visible",
260
- url: ()=>currentUrl
261
- };
262
- const visibleContext = {
263
- pages: ()=>[
264
- visiblePage
265
- ],
266
- newPage: async ()=>visiblePage
267
- };
268
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
269
- workspace
270
- }, {
271
- importPlaywright: async ()=>({
272
- chromium: {
273
- connectOverCDP: async ()=>({
274
- contexts: ()=>[
275
- hiddenContext,
276
- visibleContext
277
- ],
278
- close: async ()=>{}
279
- })
280
- }
281
- }),
282
- startChrome: async ()=>({
283
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
284
- close: async ()=>{}
285
- }),
286
- mkTempDir: ()=>tempDir,
287
- removeDir: ()=>{},
288
- now: ()=>1700000000000
289
- });
290
- const result = await tool.invoke({
291
- url: "https://robinhood.com/login",
292
- actions: [
293
- {
294
- type: "wait",
295
- ms: 50
296
- }
297
- ]
298
- });
299
- const parsed = JSON.parse(String(result));
300
- (0, external_vitest_namespaceObject.expect)(parsed.finalUrl).toBe("https://robinhood.com/login");
301
- (0, external_vitest_namespaceObject.expect)(hiddenContextCalls).toHaveLength(0);
302
- (0, external_vitest_namespaceObject.expect)(visibleContextCalls).toContain("bringToFront");
303
- (0, external_vitest_namespaceObject.expect)(visibleContextCalls).toContain("goto:https://robinhood.com/login");
304
- });
305
- (0, external_vitest_namespaceObject.it)("accepts larger top-level timeoutMs values for long browser runs", async ()=>{
306
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
307
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
308
- workspaces.push(workspace, tempDir);
309
- let capturedLaunchTimeoutMs = 0;
310
- let capturedCdpTimeoutMs = 0;
311
- const page = {
312
- goto: async ()=>{},
313
- click: async ()=>{},
314
- fill: async ()=>{},
315
- keyboard: {
316
- press: async ()=>{}
317
- },
318
- waitForTimeout: async ()=>{},
319
- textContent: async ()=>"",
320
- evaluate: async ()=>"ok",
321
- screenshot: async ()=>{},
322
- title: async ()=>"Timeout Test",
323
- url: ()=>"about:blank"
324
- };
325
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
326
- workspace,
327
- launchTimeoutMs: 15000
328
- }, {
329
- importPlaywright: async ()=>({
330
- chromium: {
331
- connectOverCDP: async (_wsEndpoint, options)=>{
332
- capturedCdpTimeoutMs = options?.timeout ?? 0;
333
- return {
334
- contexts: ()=>[
335
- {
336
- pages: ()=>[
337
- page
338
- ],
339
- newPage: async ()=>page
340
- }
341
- ],
342
- close: async ()=>{}
343
- };
344
- }
345
- }
346
- }),
347
- startChrome: async (input)=>{
348
- capturedLaunchTimeoutMs = input.launchTimeoutMs;
349
- return {
350
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
351
- close: async ()=>{}
352
- };
353
- },
354
- mkTempDir: ()=>tempDir,
355
- removeDir: ()=>{},
356
- now: ()=>1700000000000
357
- });
358
- await tool.invoke({
359
- actions: [
360
- {
361
- type: "evaluate",
362
- expression: "document.title"
363
- }
364
- ],
365
- timeoutMs: 180000
366
- });
367
- (0, external_vitest_namespaceObject.expect)(capturedLaunchTimeoutMs).toBe(180000);
368
- (0, external_vitest_namespaceObject.expect)(capturedCdpTimeoutMs).toBe(180000);
369
- });
370
- (0, external_vitest_namespaceObject.it)("accepts large extract_text maxChars values for long page content", async ()=>{
371
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
372
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
373
- workspaces.push(workspace, tempDir);
374
- const largeBody = "A".repeat(1020000);
375
- const page = {
376
- goto: async ()=>{},
377
- click: async ()=>{},
378
- fill: async ()=>{},
379
- keyboard: {
380
- press: async ()=>{}
381
- },
382
- waitForTimeout: async ()=>{},
383
- textContent: async ()=>largeBody,
384
- evaluate: async ()=>"ok",
385
- screenshot: async ()=>{},
386
- title: async ()=>"Large Extract",
387
- url: ()=>"https://robinhood.com"
388
- };
389
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
390
- workspace
391
- }, {
392
- importPlaywright: async ()=>({
393
- chromium: {
394
- connectOverCDP: async ()=>({
395
- contexts: ()=>[
396
- {
397
- pages: ()=>[
398
- page
399
- ],
400
- newPage: async ()=>page
401
- }
402
- ],
403
- close: async ()=>{}
404
- })
405
- }
406
- }),
407
- startChrome: async ()=>({
408
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
409
- close: async ()=>{}
410
- }),
411
- mkTempDir: ()=>tempDir,
412
- removeDir: ()=>{},
413
- now: ()=>1700000000000
414
- });
415
- const result = await tool.invoke({
416
- actions: [
417
- {
418
- type: "extract_text",
419
- selector: "body",
420
- maxChars: 1000000
421
- }
422
- ],
423
- timeoutMs: 60000
424
- });
425
- const parsed = JSON.parse(String(result));
426
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[0].type).toBe("extract_text");
427
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[0].selector).toBe("body");
428
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[0].text.length).toBe(1000000);
429
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[0].truncated).toBe(true);
430
- });
431
- (0, external_vitest_namespaceObject.it)("uses persistent Playwright launch when preferred", async ()=>{
432
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
433
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
434
- workspaces.push(workspace, tempDir);
435
- const fakeChromePath = (0, external_node_path_namespaceObject.join)(tempDir, "chrome-bin");
436
- (0, external_node_fs_namespaceObject.writeFileSync)(fakeChromePath, "fake chrome binary");
437
- let launchCalled = false;
438
- let closeCalled = false;
439
- let currentUrl = "about:blank";
440
- const page = {
441
- goto: async (url)=>{
442
- currentUrl = url;
443
- },
444
- click: async ()=>{},
445
- fill: async ()=>{},
446
- keyboard: {
447
- press: async ()=>{}
448
- },
449
- waitForTimeout: async ()=>{},
450
- textContent: async ()=>"",
451
- evaluate: async ()=>"ok",
452
- screenshot: async ()=>{},
453
- title: async ()=>"Persistent",
454
- url: ()=>currentUrl
455
- };
456
- const result = await (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
457
- workspace,
458
- preferPersistentLaunch: true,
459
- defaultExecutablePath: fakeChromePath
460
- }, {
461
- importPlaywright: async ()=>({
462
- chromium: {
463
- connectOverCDP: async ()=>{
464
- throw new Error("connectOverCDP should not be called");
465
- },
466
- launchPersistentContext: async ()=>{
467
- launchCalled = true;
468
- return {
469
- pages: ()=>[
470
- page
471
- ],
472
- newPage: async ()=>page,
473
- close: async ()=>{
474
- closeCalled = true;
475
- }
476
- };
477
- }
478
- }
479
- }),
480
- mkTempDir: ()=>tempDir,
481
- removeDir: ()=>{},
482
- now: ()=>1700000000000
483
- }).invoke({
484
- url: "https://example.com",
485
- actions: [
486
- {
487
- type: "evaluate",
488
- expression: "document.title"
489
- }
490
- ]
491
- });
492
- const parsed = JSON.parse(String(result));
493
- (0, external_vitest_namespaceObject.expect)(launchCalled).toBe(true);
494
- (0, external_vitest_namespaceObject.expect)(closeCalled).toBe(true);
495
- (0, external_vitest_namespaceObject.expect)(parsed.browser).toBe("chrome-playwright");
496
- (0, external_vitest_namespaceObject.expect)(parsed.transport).toBe("persistent-context");
497
- (0, external_vitest_namespaceObject.expect)(parsed.finalUrl).toBe("https://example.com");
498
- });
499
- (0, external_vitest_namespaceObject.it)("falls back to persistent launch when CDP connection fails", async ()=>{
500
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
501
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
502
- workspaces.push(workspace, tempDir);
503
- const fakeChromePath = (0, external_node_path_namespaceObject.join)(tempDir, "chrome-bin");
504
- (0, external_node_fs_namespaceObject.writeFileSync)(fakeChromePath, "fake chrome binary");
505
- let startChromeCalled = false;
506
- let cdpCalled = false;
507
- let cdpChromeClosed = false;
508
- let persistentClosed = false;
509
- let currentUrl = "about:blank";
510
- const page = {
511
- goto: async (url)=>{
512
- currentUrl = url;
513
- },
514
- click: async ()=>{},
515
- fill: async ()=>{},
516
- keyboard: {
517
- press: async ()=>{}
518
- },
519
- waitForTimeout: async ()=>{},
520
- textContent: async ()=>"",
521
- evaluate: async ()=>"ok",
522
- screenshot: async ()=>{},
523
- title: async ()=>"Fallback",
524
- url: ()=>currentUrl
525
- };
526
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
527
- workspace,
528
- preferPersistentLaunch: false,
529
- defaultExecutablePath: fakeChromePath
530
- }, {
531
- importPlaywright: async ()=>({
532
- chromium: {
533
- connectOverCDP: async ()=>{
534
- cdpCalled = true;
535
- throw new Error("overCDP: Timeout 30000ms exceeded.");
536
- },
537
- launchPersistentContext: async ()=>({
538
- pages: ()=>[
539
- page
540
- ],
541
- newPage: async ()=>page,
542
- close: async ()=>{
543
- persistentClosed = true;
544
- }
545
- })
546
- }
547
- }),
548
- startChrome: async ()=>{
549
- startChromeCalled = true;
550
- return {
551
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
552
- close: async ()=>{
553
- cdpChromeClosed = true;
554
- }
555
- };
556
- },
557
- mkTempDir: ()=>tempDir,
558
- removeDir: ()=>{},
559
- now: ()=>1700000000000
560
- });
561
- const result = await tool.invoke({
562
- url: "https://robinhood.com/login",
563
- actions: [
564
- {
565
- type: "evaluate",
566
- expression: "document.title"
567
- }
568
- ],
569
- timeoutMs: 120000
570
- });
571
- const parsed = JSON.parse(String(result));
572
- (0, external_vitest_namespaceObject.expect)(startChromeCalled).toBe(true);
573
- (0, external_vitest_namespaceObject.expect)(cdpCalled).toBe(true);
574
- (0, external_vitest_namespaceObject.expect)(cdpChromeClosed).toBe(true);
575
- (0, external_vitest_namespaceObject.expect)(persistentClosed).toBe(true);
576
- (0, external_vitest_namespaceObject.expect)(parsed.browser).toBe("chrome-playwright");
577
- (0, external_vitest_namespaceObject.expect)(parsed.transport).toBe("persistent-context");
578
- (0, external_vitest_namespaceObject.expect)(parsed.finalUrl).toBe("https://robinhood.com/login");
579
- });
580
- (0, external_vitest_namespaceObject.it)("uses relay transport when explicitly requested", async ()=>{
581
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
582
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
583
- workspaces.push(workspace, tempDir);
584
- let capturedRelayTimeout = 0;
585
- let capturedRelayConfig = null;
586
- let capturedWsEndpoint = "";
587
- let startChromeCalled = false;
588
- let currentUrl = "about:blank";
589
- const page = {
590
- goto: async (url)=>{
591
- currentUrl = url;
592
- },
593
- click: async ()=>{},
594
- fill: async ()=>{},
595
- keyboard: {
596
- press: async ()=>{}
597
- },
598
- waitForTimeout: async ()=>{},
599
- textContent: async ()=>"",
600
- evaluate: async ()=>"ok",
601
- screenshot: async ()=>{},
602
- title: async ()=>"Relay Mode",
603
- url: ()=>currentUrl
604
- };
605
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
606
- workspace,
607
- browserTransport: "relay",
608
- relayConfig: {
609
- enabled: true,
610
- host: "127.0.0.1",
611
- port: 18792,
612
- requireAuth: true,
613
- authToken: "test-relay-token-123456"
614
- }
615
- }, {
616
- importPlaywright: async ()=>({
617
- chromium: {
618
- connectOverCDP: async (wsEndpoint, options)=>{
619
- capturedWsEndpoint = wsEndpoint;
620
- capturedRelayTimeout = options?.timeout ?? 0;
621
- return {
622
- contexts: ()=>[
623
- {
624
- pages: ()=>[
625
- page
626
- ],
627
- newPage: async ()=>page
628
- }
629
- ],
630
- close: async ()=>{}
631
- };
632
- }
633
- }
634
- }),
635
- startChrome: async ()=>{
636
- startChromeCalled = true;
637
- return {
638
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
639
- close: async ()=>{}
640
- };
641
- },
642
- resolveRelayWsEndpoint: async (config, timeoutMs)=>{
643
- capturedRelayConfig = {
644
- host: config.host,
645
- port: config.port
646
- };
647
- capturedRelayTimeout = timeoutMs;
648
- return "ws://127.0.0.1:18792/cdp?token=test-relay-token-123456";
649
- },
650
- mkTempDir: ()=>tempDir,
651
- removeDir: ()=>{},
652
- now: ()=>1700000000000
653
- });
654
- const result = await tool.invoke({
655
- url: "https://example.com",
656
- actions: [
657
- {
658
- type: "evaluate",
659
- expression: "document.title"
660
- }
661
- ],
662
- timeoutMs: 45000
663
- });
664
- const parsed = JSON.parse(String(result));
665
- (0, external_vitest_namespaceObject.expect)(startChromeCalled).toBe(false);
666
- (0, external_vitest_namespaceObject.expect)(parsed.transportRequested).toBe("relay");
667
- (0, external_vitest_namespaceObject.expect)(parsed.transport).toBe("relay-cdp");
668
- (0, external_vitest_namespaceObject.expect)(parsed.browser).toBe("chrome-relay");
669
- (0, external_vitest_namespaceObject.expect)(parsed.finalUrl).toBe("https://example.com");
670
- (0, external_vitest_namespaceObject.expect)(parsed.fallbackReason).toBeNull();
671
- (0, external_vitest_namespaceObject.expect)(capturedRelayConfig?.host).toBe("127.0.0.1");
672
- (0, external_vitest_namespaceObject.expect)(capturedRelayConfig?.port).toBe(18792);
673
- (0, external_vitest_namespaceObject.expect)(capturedRelayTimeout).toBe(45000);
674
- (0, external_vitest_namespaceObject.expect)(capturedWsEndpoint).toContain("/cdp");
675
- });
676
- (0, external_vitest_namespaceObject.it)("falls back to relay in auto mode when playwright startup fails", async ()=>{
677
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
678
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
679
- workspaces.push(workspace, tempDir);
680
- let startChromeCalled = false;
681
- let relayResolveCalled = false;
682
- let currentUrl = "about:blank";
683
- const page = {
684
- goto: async (url)=>{
685
- currentUrl = url;
686
- },
687
- click: async ()=>{},
688
- fill: async ()=>{},
689
- keyboard: {
690
- press: async ()=>{}
691
- },
692
- waitForTimeout: async ()=>{},
693
- textContent: async ()=>"",
694
- evaluate: async ()=>"ok",
695
- screenshot: async ()=>{},
696
- title: async ()=>"Auto Relay Fallback",
697
- url: ()=>currentUrl
698
- };
699
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
700
- workspace,
701
- browserTransport: "auto",
702
- relayConfig: {
703
- enabled: true,
704
- host: "127.0.0.1",
705
- port: 18792,
706
- requireAuth: false
707
- }
708
- }, {
709
- importPlaywright: async ()=>({
710
- chromium: {
711
- connectOverCDP: async (wsEndpoint)=>{
712
- if (wsEndpoint.includes("18792")) return {
713
- contexts: ()=>[
714
- {
715
- pages: ()=>[
716
- page
717
- ],
718
- newPage: async ()=>page
719
- }
720
- ],
721
- close: async ()=>{}
722
- };
723
- throw new Error("playwright cdp endpoint refused");
724
- }
725
- }
726
- }),
727
- startChrome: async ()=>{
728
- startChromeCalled = true;
729
- throw new Error("Failed to launch Chrome for CDP connection");
730
- },
731
- resolveRelayWsEndpoint: async ()=>{
732
- relayResolveCalled = true;
733
- return "ws://127.0.0.1:18792/cdp";
734
- },
735
- mkTempDir: ()=>tempDir,
736
- removeDir: ()=>{},
737
- now: ()=>1700000000000
738
- });
739
- const result = await tool.invoke({
740
- url: "https://example.com/auto",
741
- actions: [
742
- {
743
- type: "evaluate",
744
- expression: "document.title"
745
- }
746
- ],
747
- timeoutMs: 90000
748
- });
749
- const parsed = JSON.parse(String(result));
750
- (0, external_vitest_namespaceObject.expect)(startChromeCalled).toBe(true);
751
- (0, external_vitest_namespaceObject.expect)(relayResolveCalled).toBe(true);
752
- (0, external_vitest_namespaceObject.expect)(parsed.transportRequested).toBe("auto");
753
- (0, external_vitest_namespaceObject.expect)(parsed.transport).toBe("relay-cdp");
754
- (0, external_vitest_namespaceObject.expect)(parsed.browser).toBe("chrome-relay");
755
- (0, external_vitest_namespaceObject.expect)(parsed.fallbackReason).toContain("playwright initialization failed");
756
- (0, external_vitest_namespaceObject.expect)(parsed.finalUrl).toBe("https://example.com/auto");
757
- });
758
- (0, external_vitest_namespaceObject.it)("does not fall back to relay when transport is explicitly playwright", async ()=>{
759
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
760
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
761
- workspaces.push(workspace, tempDir);
762
- let relayResolveCalled = false;
763
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
764
- workspace,
765
- browserTransport: "playwright",
766
- relayConfig: {
767
- enabled: true,
768
- host: "127.0.0.1",
769
- port: 18792,
770
- requireAuth: false
771
- }
772
- }, {
773
- importPlaywright: async ()=>({
774
- chromium: {
775
- connectOverCDP: async ()=>{
776
- throw new Error("playwright cdp endpoint refused");
777
- }
778
- }
779
- }),
780
- startChrome: async ()=>{
781
- throw new Error("CDP startup failed");
782
- },
783
- resolveRelayWsEndpoint: async ()=>{
784
- relayResolveCalled = true;
785
- return "ws://127.0.0.1:18792/cdp";
786
- },
787
- mkTempDir: ()=>tempDir,
788
- removeDir: ()=>{},
789
- now: ()=>1700000000000
790
- });
791
- const result = await tool.invoke({
792
- url: "https://example.com/playwright-only"
793
- });
794
- (0, external_vitest_namespaceObject.expect)(relayResolveCalled).toBe(false);
795
- (0, external_vitest_namespaceObject.expect)(String(result)).toContain("Error running browser_control");
796
- (0, external_vitest_namespaceObject.expect)(String(result)).toContain("CDP startup failed");
797
- });
798
- (0, external_vitest_namespaceObject.it)("rejects screenshot paths that escape the workspace", async ()=>{
799
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
800
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
801
- workspaces.push(workspace, tempDir);
802
- const page = {
803
- goto: async ()=>{},
804
- click: async ()=>{},
805
- fill: async ()=>{},
806
- keyboard: {
807
- press: async ()=>{}
808
- },
809
- waitForTimeout: async ()=>{},
810
- textContent: async ()=>"",
811
- evaluate: async ()=>({}),
812
- screenshot: async ()=>{},
813
- title: async ()=>"Example",
814
- url: ()=>"about:blank"
815
- };
816
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
817
- workspace
818
- }, {
819
- importPlaywright: async ()=>({
820
- chromium: {
821
- connectOverCDP: async ()=>({
822
- contexts: ()=>[
823
- {
824
- pages: ()=>[
825
- page
826
- ],
827
- newPage: async ()=>page
828
- }
829
- ],
830
- close: async ()=>{}
831
- })
832
- }
833
- }),
834
- startChrome: async ()=>({
835
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
836
- close: async ()=>{}
837
- }),
838
- mkTempDir: ()=>tempDir,
839
- removeDir: ()=>{},
840
- now: ()=>1700000000000
841
- });
842
- const result = await tool.invoke({
843
- actions: [
844
- {
845
- type: "screenshot",
846
- path: "../escape.png"
847
- }
848
- ]
849
- });
850
- (0, external_vitest_namespaceObject.expect)(String(result)).toContain("Error running browser_control");
851
- (0, external_vitest_namespaceObject.expect)(String(result)).toContain("inside the workspace");
852
- });
853
- (0, external_vitest_namespaceObject.it)("supports alias action types used by some agent prompts", async ()=>{
854
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
855
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
856
- workspaces.push(workspace, tempDir);
857
- let currentUrl = "about:blank";
858
- const actionCalls = [];
859
- const page = {
860
- goto: async (url)=>{
861
- currentUrl = url;
862
- actionCalls.push(`goto:${url}`);
863
- },
864
- click: async ()=>{},
865
- fill: async ()=>{},
866
- keyboard: {
867
- press: async ()=>{}
868
- },
869
- waitForTimeout: async (ms)=>{
870
- actionCalls.push(`wait:${ms}`);
871
- },
872
- textContent: async (selector)=>{
873
- actionCalls.push(`text:${selector}`);
874
- return "Robinhood";
875
- },
876
- evaluate: async (expression)=>{
877
- actionCalls.push(`eval:${expression}`);
878
- return "Robinhood - Investing";
879
- },
880
- screenshot: async ({ path })=>{
881
- actionCalls.push(`screenshot:${path}`);
882
- (0, external_node_fs_namespaceObject.writeFileSync)(path, "test image data");
883
- },
884
- title: async ()=>"Robinhood - Investing",
885
- url: ()=>currentUrl
886
- };
887
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
888
- workspace
889
- }, {
890
- importPlaywright: async ()=>({
891
- chromium: {
892
- connectOverCDP: async ()=>({
893
- contexts: ()=>[
894
- {
895
- pages: ()=>[
896
- page
897
- ],
898
- newPage: async ()=>page
899
- }
900
- ],
901
- close: async ()=>{}
902
- })
903
- }
904
- }),
905
- startChrome: async ()=>({
906
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
907
- close: async ()=>{}
908
- }),
909
- mkTempDir: ()=>tempDir,
910
- removeDir: ()=>{},
911
- now: ()=>1700000000000
912
- });
913
- const result = await tool.invoke({
914
- url: "https://robinhood.com/?classic=1",
915
- actions: [
916
- {
917
- type: "url",
918
- url: "https://robinhood.com/?classic=1"
919
- },
920
- {
921
- type: "ms",
922
- ms: 4000
923
- },
924
- {
925
- type: "selector",
926
- selector: "body",
927
- maxChars: 4000
928
- },
929
- {
930
- type: "expression",
931
- expression: "document.title"
932
- },
933
- {
934
- type: "path",
935
- path: "robinhood.png",
936
- fullPage: true
937
- }
938
- ],
939
- headless: true,
940
- timeoutMs: 60000
941
- });
942
- const parsed = JSON.parse(String(result));
943
- (0, external_vitest_namespaceObject.expect)(parsed.finalUrl).toBe("https://robinhood.com/?classic=1");
944
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[0].type).toBe("navigate");
945
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[1].type).toBe("wait");
946
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[2].type).toBe("extract_text");
947
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[3].type).toBe("evaluate");
948
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[4].type).toBe("screenshot");
949
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[4].path).toBe("robinhood.png");
950
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("goto:https://robinhood.com/?classic=1");
951
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("wait:4000");
952
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("text:body");
953
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("eval:document.title");
954
- });
955
- (0, external_vitest_namespaceObject.it)("supports snapshot alias for screenshot actions", async ()=>{
956
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
957
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
958
- workspaces.push(workspace, tempDir);
959
- let currentUrl = "about:blank";
960
- const actionCalls = [];
961
- const page = {
962
- goto: async (url)=>{
963
- currentUrl = url;
964
- actionCalls.push(`goto:${url}`);
965
- },
966
- click: async ()=>{},
967
- fill: async ()=>{},
968
- keyboard: {
969
- press: async ()=>{}
970
- },
971
- waitForTimeout: async ()=>{},
972
- textContent: async ()=>"",
973
- evaluate: async ()=>"ok",
974
- screenshot: async ({ path })=>{
975
- actionCalls.push(`screenshot:${path}`);
976
- (0, external_node_fs_namespaceObject.writeFileSync)(path, "test image data");
977
- },
978
- title: async ()=>"Robinhood",
979
- url: ()=>currentUrl
980
- };
981
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
982
- workspace
983
- }, {
984
- importPlaywright: async ()=>({
985
- chromium: {
986
- connectOverCDP: async ()=>({
987
- contexts: ()=>[
988
- {
989
- pages: ()=>[
990
- page
991
- ],
992
- newPage: async ()=>page
993
- }
994
- ],
995
- close: async ()=>{}
996
- })
997
- }
998
- }),
999
- startChrome: async ()=>({
1000
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
1001
- close: async ()=>{}
1002
- }),
1003
- mkTempDir: ()=>tempDir,
1004
- removeDir: ()=>{},
1005
- now: ()=>1700000000000
1006
- });
1007
- const result = await tool.invoke({
1008
- url: "https://robinhood.com/?classic=1",
1009
- actions: [
1010
- {
1011
- type: "navigate",
1012
- url: "https://robinhood.com/?classic=1"
1013
- },
1014
- {
1015
- type: "wait",
1016
- ms: 10
1017
- },
1018
- {
1019
- type: "snapshot",
1020
- path: "robinhood_classic.png",
1021
- fullPage: true
1022
- }
1023
- ],
1024
- headless: true,
1025
- timeoutMs: 60000
1026
- });
1027
- const parsed = JSON.parse(String(result));
1028
- (0, external_vitest_namespaceObject.expect)(parsed.finalUrl).toBe("https://robinhood.com/?classic=1");
1029
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[2].type).toBe("screenshot");
1030
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[2].path).toBe("robinhood_classic.png");
1031
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("goto:https://robinhood.com/?classic=1");
1032
- });
1033
- (0, external_vitest_namespaceObject.it)("supports additional action aliases for robust prompting", async ()=>{
1034
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
1035
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
1036
- workspaces.push(workspace, tempDir);
1037
- let currentUrl = "about:blank";
1038
- const actionCalls = [];
1039
- const page = {
1040
- goto: async (url)=>{
1041
- currentUrl = url;
1042
- actionCalls.push(`goto:${url}`);
1043
- },
1044
- click: async ()=>{},
1045
- fill: async ()=>{},
1046
- keyboard: {
1047
- press: async ()=>{}
1048
- },
1049
- waitForTimeout: async (ms)=>{
1050
- actionCalls.push(`wait:${ms}`);
1051
- },
1052
- textContent: async ()=>"",
1053
- evaluate: async (expression)=>{
1054
- actionCalls.push(`eval:${expression}`);
1055
- return "ok";
1056
- },
1057
- screenshot: async ({ path })=>{
1058
- actionCalls.push(`screenshot:${path}`);
1059
- (0, external_node_fs_namespaceObject.writeFileSync)(path, "test image data");
1060
- },
1061
- title: async ()=>"Alias Test",
1062
- url: ()=>currentUrl
1063
- };
1064
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
1065
- workspace
1066
- }, {
1067
- importPlaywright: async ()=>({
1068
- chromium: {
1069
- connectOverCDP: async ()=>({
1070
- contexts: ()=>[
1071
- {
1072
- pages: ()=>[
1073
- page
1074
- ],
1075
- newPage: async ()=>page
1076
- }
1077
- ],
1078
- close: async ()=>{}
1079
- })
1080
- }
1081
- }),
1082
- startChrome: async ()=>({
1083
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
1084
- close: async ()=>{}
1085
- }),
1086
- mkTempDir: ()=>tempDir,
1087
- removeDir: ()=>{},
1088
- now: ()=>1700000000000
1089
- });
1090
- const result = await tool.invoke({
1091
- url: "https://example.com",
1092
- actions: [
1093
- {
1094
- type: "open",
1095
- url: "https://example.com/docs"
1096
- },
1097
- {
1098
- type: "sleep",
1099
- ms: 25
1100
- },
1101
- {
1102
- type: "js",
1103
- expression: "document.title"
1104
- },
1105
- {
1106
- type: "capture",
1107
- path: "alias-capture.png",
1108
- fullPage: true
1109
- }
1110
- ],
1111
- headless: true
1112
- });
1113
- const parsed = JSON.parse(String(result));
1114
- (0, external_vitest_namespaceObject.expect)(parsed.finalUrl).toBe("https://example.com/docs");
1115
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[0].type).toBe("navigate");
1116
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[1].type).toBe("wait");
1117
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[2].type).toBe("evaluate");
1118
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[3].type).toBe("screenshot");
1119
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("goto:https://example.com/docs");
1120
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("wait:25");
1121
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("eval:document.title");
1122
- });
1123
- (0, external_vitest_namespaceObject.it)("supports extract alias for text extraction", async ()=>{
1124
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
1125
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
1126
- workspaces.push(workspace, tempDir);
1127
- let currentUrl = "about:blank";
1128
- const actionCalls = [];
1129
- const page = {
1130
- goto: async (url)=>{
1131
- currentUrl = url;
1132
- actionCalls.push(`goto:${url}`);
1133
- },
1134
- click: async ()=>{},
1135
- fill: async ()=>{},
1136
- keyboard: {
1137
- press: async ()=>{}
1138
- },
1139
- waitForTimeout: async ()=>{},
1140
- waitForLoadState: async (state)=>{
1141
- actionCalls.push(`load:${state}`);
1142
- },
1143
- textContent: async (selector)=>{
1144
- actionCalls.push(`text:${selector}`);
1145
- return "Robinhood support content";
1146
- },
1147
- evaluate: async ()=>"ok",
1148
- screenshot: async ()=>{},
1149
- title: async ()=>"Support",
1150
- url: ()=>currentUrl
1151
- };
1152
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
1153
- workspace
1154
- }, {
1155
- importPlaywright: async ()=>({
1156
- chromium: {
1157
- connectOverCDP: async ()=>({
1158
- contexts: ()=>[
1159
- {
1160
- pages: ()=>[
1161
- page
1162
- ],
1163
- newPage: async ()=>page
1164
- }
1165
- ],
1166
- close: async ()=>{}
1167
- })
1168
- }
1169
- }),
1170
- startChrome: async ()=>({
1171
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
1172
- close: async ()=>{}
1173
- }),
1174
- mkTempDir: ()=>tempDir,
1175
- removeDir: ()=>{},
1176
- now: ()=>1700000000000
1177
- });
1178
- const result = await tool.invoke({
1179
- url: "https://robinhood.com",
1180
- actions: [
1181
- {
1182
- type: "goto",
1183
- url: "https://robinhood.com/"
1184
- },
1185
- {
1186
- type: "wait",
1187
- load: "networkidle",
1188
- timeoutMs: 30000
1189
- },
1190
- {
1191
- type: "extract",
1192
- selector: "body",
1193
- maxChars: 5000
1194
- }
1195
- ],
1196
- headless: true,
1197
- timeoutMs: 60000
1198
- });
1199
- const parsed = JSON.parse(String(result));
1200
- (0, external_vitest_namespaceObject.expect)(parsed.finalUrl).toBe("https://robinhood.com/");
1201
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[2].type).toBe("extract_text");
1202
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[2].selector).toBe("body");
1203
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("goto:https://robinhood.com/");
1204
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("load:networkidle");
1205
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("text:body");
1206
- });
1207
- (0, external_vitest_namespaceObject.it)("supports getContent alias for text extraction", async ()=>{
1208
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
1209
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
1210
- workspaces.push(workspace, tempDir);
1211
- let currentUrl = "about:blank";
1212
- const actionCalls = [];
1213
- const page = {
1214
- goto: async (url)=>{
1215
- currentUrl = url;
1216
- actionCalls.push(`goto:${url}`);
1217
- },
1218
- click: async ()=>{},
1219
- fill: async ()=>{},
1220
- keyboard: {
1221
- press: async ()=>{}
1222
- },
1223
- waitForTimeout: async ()=>{},
1224
- waitForLoadState: async (state)=>{
1225
- actionCalls.push(`load:${state}`);
1226
- },
1227
- textContent: async (selector)=>{
1228
- actionCalls.push(`text:${selector}`);
1229
- return "Robinhood homepage content";
1230
- },
1231
- evaluate: async ()=>"ok",
1232
- screenshot: async ()=>{},
1233
- title: async ()=>"Robinhood",
1234
- url: ()=>currentUrl
1235
- };
1236
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
1237
- workspace
1238
- }, {
1239
- importPlaywright: async ()=>({
1240
- chromium: {
1241
- connectOverCDP: async ()=>({
1242
- contexts: ()=>[
1243
- {
1244
- pages: ()=>[
1245
- page
1246
- ],
1247
- newPage: async ()=>page
1248
- }
1249
- ],
1250
- close: async ()=>{}
1251
- })
1252
- }
1253
- }),
1254
- startChrome: async ()=>({
1255
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
1256
- close: async ()=>{}
1257
- }),
1258
- mkTempDir: ()=>tempDir,
1259
- removeDir: ()=>{},
1260
- now: ()=>1700000000000
1261
- });
1262
- const result = await tool.invoke({
1263
- url: "https://robinhood.com/",
1264
- actions: [
1265
- {
1266
- type: "goto",
1267
- url: "https://robinhood.com/"
1268
- },
1269
- {
1270
- type: "wait",
1271
- load: "networkidle",
1272
- timeoutMs: 30000
1273
- },
1274
- {
1275
- type: "getContent",
1276
- selector: "body",
1277
- maxChars: 5000
1278
- }
1279
- ],
1280
- timeoutMs: 60000
1281
- });
1282
- const parsed = JSON.parse(String(result));
1283
- (0, external_vitest_namespaceObject.expect)(parsed.finalUrl).toBe("https://robinhood.com/");
1284
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[2].type).toBe("extract_text");
1285
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[2].selector).toBe("body");
1286
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("goto:https://robinhood.com/");
1287
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("load:networkidle");
1288
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("text:body");
1289
- });
1290
- (0, external_vitest_namespaceObject.it)("supports querySelector alias for text extraction", async ()=>{
1291
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
1292
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
1293
- workspaces.push(workspace, tempDir);
1294
- let currentUrl = "about:blank";
1295
- const actionCalls = [];
1296
- const page = {
1297
- goto: async (url)=>{
1298
- currentUrl = url;
1299
- actionCalls.push(`goto:${url}`);
1300
- },
1301
- click: async ()=>{},
1302
- fill: async ()=>{},
1303
- keyboard: {
1304
- press: async ()=>{}
1305
- },
1306
- waitForTimeout: async ()=>{},
1307
- waitForLoadState: async (state)=>{
1308
- actionCalls.push(`load:${state}`);
1309
- },
1310
- textContent: async (selector)=>{
1311
- actionCalls.push(`text:${selector}`);
1312
- return "Robinhood homepage content";
1313
- },
1314
- evaluate: async ()=>"ok",
1315
- screenshot: async ()=>{},
1316
- title: async ()=>"Robinhood",
1317
- url: ()=>currentUrl
1318
- };
1319
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
1320
- workspace
1321
- }, {
1322
- importPlaywright: async ()=>({
1323
- chromium: {
1324
- connectOverCDP: async ()=>({
1325
- contexts: ()=>[
1326
- {
1327
- pages: ()=>[
1328
- page
1329
- ],
1330
- newPage: async ()=>page
1331
- }
1332
- ],
1333
- close: async ()=>{}
1334
- })
1335
- }
1336
- }),
1337
- startChrome: async ()=>({
1338
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
1339
- close: async ()=>{}
1340
- }),
1341
- mkTempDir: ()=>tempDir,
1342
- removeDir: ()=>{},
1343
- now: ()=>1700000000000
1344
- });
1345
- const result = await tool.invoke({
1346
- url: "https://robinhood.com",
1347
- actions: [
1348
- {
1349
- type: "navigate",
1350
- url: "https://robinhood.com"
1351
- },
1352
- {
1353
- type: "wait",
1354
- load: "networkidle",
1355
- timeoutMs: 30000
1356
- },
1357
- {
1358
- type: "querySelector",
1359
- selector: "body",
1360
- maxChars: 4000
1361
- }
1362
- ],
1363
- timeoutMs: 30000
1364
- });
1365
- const parsed = JSON.parse(String(result));
1366
- (0, external_vitest_namespaceObject.expect)(parsed.finalUrl).toBe("https://robinhood.com");
1367
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[2].type).toBe("extract_text");
1368
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[2].selector).toBe("body");
1369
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("goto:https://robinhood.com");
1370
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("load:networkidle");
1371
- (0, external_vitest_namespaceObject.expect)(actionCalls).toContain("text:body");
1372
- });
1373
- (0, external_vitest_namespaceObject.it)("supports wait_for conditions", async ()=>{
1374
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
1375
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
1376
- workspaces.push(workspace, tempDir);
1377
- const waitCalls = [];
1378
- const page = {
1379
- goto: async ()=>{},
1380
- click: async ()=>{},
1381
- fill: async ()=>{},
1382
- keyboard: {
1383
- press: async ()=>{}
1384
- },
1385
- waitForTimeout: async ()=>{},
1386
- waitForSelector: async (selector)=>{
1387
- waitCalls.push(`selector:${selector}`);
1388
- },
1389
- waitForURL: async ()=>{
1390
- waitCalls.push("url");
1391
- },
1392
- waitForLoadState: async (state)=>{
1393
- waitCalls.push(`load:${state}`);
1394
- },
1395
- waitForFunction: async (expression)=>{
1396
- waitCalls.push(`fn:${expression}`);
1397
- },
1398
- textContent: async ()=>"",
1399
- evaluate: async ()=>"ok",
1400
- screenshot: async ()=>{},
1401
- title: async ()=>"Wait For Test",
1402
- url: ()=>"https://example.com/dashboard"
1403
- };
1404
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
1405
- workspace
1406
- }, {
1407
- importPlaywright: async ()=>({
1408
- chromium: {
1409
- connectOverCDP: async ()=>({
1410
- contexts: ()=>[
1411
- {
1412
- pages: ()=>[
1413
- page
1414
- ],
1415
- newPage: async ()=>page
1416
- }
1417
- ],
1418
- close: async ()=>{}
1419
- })
1420
- }
1421
- }),
1422
- startChrome: async ()=>({
1423
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
1424
- close: async ()=>{}
1425
- }),
1426
- mkTempDir: ()=>tempDir,
1427
- removeDir: ()=>{},
1428
- now: ()=>1700000000000
1429
- });
1430
- const result = await tool.invoke({
1431
- actions: [
1432
- {
1433
- type: "wait_for",
1434
- selector: "#portfolio-root",
1435
- url: "https://example.com/**",
1436
- load: "domcontentloaded",
1437
- fn: "document.readyState === 'complete'",
1438
- timeoutMs: 25000
1439
- }
1440
- ],
1441
- headless: true,
1442
- timeoutMs: 60000
1443
- });
1444
- const parsed = JSON.parse(String(result));
1445
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[0].type).toBe("wait_for");
1446
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[0].timeoutMs).toBe(25000);
1447
- (0, external_vitest_namespaceObject.expect)(waitCalls).toContain("selector:#portfolio-root");
1448
- (0, external_vitest_namespaceObject.expect)(waitCalls).toContain("url");
1449
- (0, external_vitest_namespaceObject.expect)(waitCalls).toContain("load:domcontentloaded");
1450
- (0, external_vitest_namespaceObject.expect)(waitCalls).toContain("fn:document.readyState === 'complete'");
1451
- });
1452
- (0, external_vitest_namespaceObject.it)("supports wait with load/timeoutMs alias style", async ()=>{
1453
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
1454
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
1455
- workspaces.push(workspace, tempDir);
1456
- const waitCalls = [];
1457
- const page = {
1458
- goto: async ()=>{},
1459
- click: async ()=>{},
1460
- fill: async ()=>{},
1461
- keyboard: {
1462
- press: async ()=>{}
1463
- },
1464
- waitForTimeout: async ()=>{},
1465
- waitForLoadState: async (state)=>{
1466
- waitCalls.push(`load:${state}`);
1467
- },
1468
- textContent: async ()=>"",
1469
- evaluate: async ()=>"ok",
1470
- screenshot: async ()=>{},
1471
- title: async ()=>"Wait Alias Test",
1472
- url: ()=>"https://support.robinhood.com"
1473
- };
1474
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
1475
- workspace
1476
- }, {
1477
- importPlaywright: async ()=>({
1478
- chromium: {
1479
- connectOverCDP: async ()=>({
1480
- contexts: ()=>[
1481
- {
1482
- pages: ()=>[
1483
- page
1484
- ],
1485
- newPage: async ()=>page
1486
- }
1487
- ],
1488
- close: async ()=>{}
1489
- })
1490
- }
1491
- }),
1492
- startChrome: async ()=>({
1493
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
1494
- close: async ()=>{}
1495
- }),
1496
- mkTempDir: ()=>tempDir,
1497
- removeDir: ()=>{},
1498
- now: ()=>1700000000000
1499
- });
1500
- const result = await tool.invoke({
1501
- actions: [
1502
- {
1503
- type: "wait",
1504
- load: "networkidle",
1505
- timeoutMs: 180000
1506
- }
1507
- ],
1508
- headless: true
1509
- });
1510
- const parsed = JSON.parse(String(result));
1511
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[0].type).toBe("wait_for");
1512
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[0].load).toBe("networkidle");
1513
- (0, external_vitest_namespaceObject.expect)(parsed.actionResults[0].timeoutMs).toBe(180000);
1514
- (0, external_vitest_namespaceObject.expect)(waitCalls).toContain("load:networkidle");
1515
- });
1516
- (0, external_vitest_namespaceObject.it)("auto-provisions bundled wingman extension when configured path is missing", async ()=>{
1517
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
1518
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
1519
- workspaces.push(workspace, tempDir);
1520
- let capturedChromeArgs = [];
1521
- const page = {
1522
- goto: async ()=>{},
1523
- click: async ()=>{},
1524
- fill: async ()=>{},
1525
- keyboard: {
1526
- press: async ()=>{}
1527
- },
1528
- waitForTimeout: async ()=>{},
1529
- textContent: async ()=>"",
1530
- evaluate: async ()=>"ok",
1531
- screenshot: async ()=>{},
1532
- title: async ()=>"Bundled Extension",
1533
- url: ()=>"about:blank"
1534
- };
1535
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
1536
- workspace,
1537
- defaultExtensions: [
1538
- "wingman"
1539
- ]
1540
- }, {
1541
- importPlaywright: async ()=>({
1542
- chromium: {
1543
- connectOverCDP: async ()=>({
1544
- contexts: ()=>[
1545
- {
1546
- pages: ()=>[
1547
- page
1548
- ],
1549
- newPage: async ()=>page
1550
- }
1551
- ],
1552
- close: async ()=>{}
1553
- })
1554
- }
1555
- }),
1556
- startChrome: async (input)=>{
1557
- capturedChromeArgs = input.chromeArgs || [];
1558
- return {
1559
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
1560
- close: async ()=>{}
1561
- };
1562
- },
1563
- mkTempDir: ()=>tempDir,
1564
- removeDir: ()=>{},
1565
- now: ()=>1700000000000
1566
- });
1567
- const result = await tool.invoke({
1568
- actions: [
1569
- {
1570
- type: "evaluate",
1571
- expression: "document.title"
1572
- }
1573
- ]
1574
- });
1575
- const parsed = JSON.parse(String(result));
1576
- (0, external_vitest_namespaceObject.expect)(parsed.extensions).toContain("wingman");
1577
- (0, external_vitest_namespaceObject.expect)((0, external_node_fs_namespaceObject.existsSync)((0, external_node_path_namespaceObject.join)(workspace, ".wingman", "browser-extensions", "wingman", "manifest.json"))).toBe(true);
1578
- (0, external_vitest_namespaceObject.expect)(capturedChromeArgs.some((arg)=>arg.startsWith("--load-extension="))).toBe(true);
1579
- });
1580
- (0, external_vitest_namespaceObject.it)("resolves configured extension paths relative to config workspace", async ()=>{
1581
- const executionWorkspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
1582
- const configWorkspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-config-workspace-"));
1583
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
1584
- workspaces.push(executionWorkspace, configWorkspace, tempDir);
1585
- const extensionDir = (0, external_node_path_namespaceObject.join)(configWorkspace, ".wingman", "browser-extensions", "relay");
1586
- (0, external_node_fs_namespaceObject.mkdirSync)(extensionDir, {
1587
- recursive: true
1588
- });
1589
- (0, external_node_fs_namespaceObject.writeFileSync)((0, external_node_path_namespaceObject.join)(extensionDir, "manifest.json"), JSON.stringify({
1590
- manifest_version: 3,
1591
- name: "Relay Test Extension",
1592
- version: "0.0.1"
1593
- }));
1594
- let capturedChromeArgs = [];
1595
- const page = {
1596
- goto: async ()=>{},
1597
- click: async ()=>{},
1598
- fill: async ()=>{},
1599
- keyboard: {
1600
- press: async ()=>{}
1601
- },
1602
- waitForTimeout: async ()=>{},
1603
- textContent: async ()=>"",
1604
- evaluate: async ()=>"ok",
1605
- screenshot: async ()=>{},
1606
- title: async ()=>"Config Workspace Extension",
1607
- url: ()=>"about:blank"
1608
- };
1609
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
1610
- workspace: executionWorkspace,
1611
- configWorkspace,
1612
- defaultExtensions: [
1613
- "relay"
1614
- ]
1615
- }, {
1616
- importPlaywright: async ()=>({
1617
- chromium: {
1618
- connectOverCDP: async ()=>({
1619
- contexts: ()=>[
1620
- {
1621
- pages: ()=>[
1622
- page
1623
- ],
1624
- newPage: async ()=>page
1625
- }
1626
- ],
1627
- close: async ()=>{}
1628
- })
1629
- }
1630
- }),
1631
- startChrome: async (input)=>{
1632
- capturedChromeArgs = input.chromeArgs || [];
1633
- return {
1634
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
1635
- close: async ()=>{}
1636
- };
1637
- },
1638
- mkTempDir: ()=>tempDir,
1639
- removeDir: ()=>{},
1640
- now: ()=>1700000000000
1641
- });
1642
- const result = await tool.invoke({
1643
- actions: [
1644
- {
1645
- type: "evaluate",
1646
- expression: "document.title"
1647
- }
1648
- ]
1649
- });
1650
- const parsed = JSON.parse(String(result));
1651
- (0, external_vitest_namespaceObject.expect)(parsed.extensions).toContain("relay");
1652
- (0, external_vitest_namespaceObject.expect)(capturedChromeArgs.some((arg)=>arg.includes(extensionDir))).toBe(true);
1653
- });
1654
- (0, external_vitest_namespaceObject.it)("uses persistent named browser profile when configured", async ()=>{
1655
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
1656
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
1657
- workspaces.push(workspace, tempDir);
1658
- let capturedUserDataDir = "";
1659
- let capturedHeadless = null;
1660
- let capturedIgnoreDefaultArgs = [];
1661
- let removedTempDir = false;
1662
- const page = {
1663
- goto: async ()=>{},
1664
- click: async ()=>{},
1665
- fill: async ()=>{},
1666
- keyboard: {
1667
- press: async ()=>{}
1668
- },
1669
- waitForTimeout: async ()=>{},
1670
- textContent: async ()=>"",
1671
- evaluate: async ()=>"ok",
1672
- screenshot: async ()=>{},
1673
- title: async ()=>"Profile Session",
1674
- url: ()=>"about:blank"
1675
- };
1676
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
1677
- workspace,
1678
- browserProfile: "trading"
1679
- }, {
1680
- importPlaywright: async ()=>({
1681
- chromium: {
1682
- connectOverCDP: async ()=>{
1683
- throw new Error("connectOverCDP should not be called");
1684
- },
1685
- launchPersistentContext: async (userDataDir, launchOptions)=>{
1686
- capturedUserDataDir = userDataDir;
1687
- capturedHeadless = launchOptions?.headless ?? null;
1688
- capturedIgnoreDefaultArgs = launchOptions?.ignoreDefaultArgs || [];
1689
- return {
1690
- pages: ()=>[
1691
- page
1692
- ],
1693
- newPage: async ()=>page,
1694
- close: async ()=>{}
1695
- };
1696
- }
1697
- }
1698
- }),
1699
- mkTempDir: ()=>tempDir,
1700
- removeDir: ()=>{
1701
- removedTempDir = true;
1702
- },
1703
- now: ()=>1700000000000
1704
- });
1705
- const result = await tool.invoke({
1706
- actions: [
1707
- {
1708
- type: "evaluate",
1709
- expression: "document.title"
1710
- }
1711
- ]
1712
- });
1713
- const parsed = JSON.parse(String(result));
1714
- (0, external_vitest_namespaceObject.expect)(parsed.persistentProfile).toBe(true);
1715
- (0, external_vitest_namespaceObject.expect)(parsed.profileId).toBe("trading");
1716
- (0, external_vitest_namespaceObject.expect)(parsed.profilePath).toBe(capturedUserDataDir);
1717
- (0, external_vitest_namespaceObject.expect)(parsed.transport).toBe("persistent-context");
1718
- (0, external_vitest_namespaceObject.expect)(parsed.mode).toBe("headed");
1719
- (0, external_vitest_namespaceObject.expect)(capturedHeadless).toBe(false);
1720
- (0, external_vitest_namespaceObject.expect)(capturedIgnoreDefaultArgs).toContain("--password-store=basic");
1721
- (0, external_vitest_namespaceObject.expect)(capturedIgnoreDefaultArgs).toContain("--use-mock-keychain");
1722
- (0, external_vitest_namespaceObject.expect)(capturedUserDataDir).toContain(".wingman/browser-profiles/trading");
1723
- (0, external_vitest_namespaceObject.expect)(removedTempDir).toBe(false);
1724
- });
1725
- (0, external_vitest_namespaceObject.it)("honors headless requests for persistent browser profiles", async ()=>{
1726
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
1727
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
1728
- workspaces.push(workspace, tempDir);
1729
- let capturedHeadless = null;
1730
- const page = {
1731
- goto: async ()=>{},
1732
- click: async ()=>{},
1733
- fill: async ()=>{},
1734
- keyboard: {
1735
- press: async ()=>{}
1736
- },
1737
- waitForTimeout: async ()=>{},
1738
- textContent: async ()=>"",
1739
- evaluate: async ()=>"ok",
1740
- screenshot: async ()=>{},
1741
- title: async ()=>"Profile Session",
1742
- url: ()=>"about:blank"
1743
- };
1744
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
1745
- workspace,
1746
- browserProfile: "trading"
1747
- }, {
1748
- importPlaywright: async ()=>({
1749
- chromium: {
1750
- connectOverCDP: async ()=>{
1751
- throw new Error("connectOverCDP should not be called");
1752
- },
1753
- launchPersistentContext: async (_userDataDir, launchOptions)=>{
1754
- capturedHeadless = launchOptions?.headless ?? null;
1755
- return {
1756
- pages: ()=>[
1757
- page
1758
- ],
1759
- newPage: async ()=>page,
1760
- close: async ()=>{}
1761
- };
1762
- }
1763
- }
1764
- }),
1765
- mkTempDir: ()=>tempDir,
1766
- removeDir: ()=>{},
1767
- now: ()=>1700000000000
1768
- });
1769
- const result = await tool.invoke({
1770
- headless: true,
1771
- actions: [
1772
- {
1773
- type: "evaluate",
1774
- expression: "document.title"
1775
- }
1776
- ]
1777
- });
1778
- const parsed = JSON.parse(String(result));
1779
- (0, external_vitest_namespaceObject.expect)(parsed.mode).toBe("headless");
1780
- (0, external_vitest_namespaceObject.expect)(capturedHeadless).toBe(true);
1781
- });
1782
- (0, external_vitest_namespaceObject.it)("retries CDP once for persistent profiles without switching transport", async ()=>{
1783
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
1784
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
1785
- workspaces.push(workspace, tempDir);
1786
- let startChromeCalls = 0;
1787
- let connectCalls = 0;
1788
- let persistentLaunchCalled = false;
1789
- const page = {
1790
- goto: async ()=>{},
1791
- click: async ()=>{},
1792
- fill: async ()=>{},
1793
- keyboard: {
1794
- press: async ()=>{}
1795
- },
1796
- waitForTimeout: async ()=>{},
1797
- textContent: async ()=>"",
1798
- evaluate: async ()=>"ok",
1799
- screenshot: async ()=>{},
1800
- title: async ()=>"Profile Retry",
1801
- url: ()=>"about:blank"
1802
- };
1803
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
1804
- workspace,
1805
- browserProfile: "trading",
1806
- preferPersistentLaunch: false
1807
- }, {
1808
- importPlaywright: async ()=>({
1809
- chromium: {
1810
- connectOverCDP: async ()=>{
1811
- connectCalls += 1;
1812
- if (1 === connectCalls) throw new Error("overCDP: WebSocket error: ECONNREFUSED");
1813
- return {
1814
- contexts: ()=>[
1815
- {
1816
- pages: ()=>[
1817
- page
1818
- ],
1819
- newPage: async ()=>page
1820
- }
1821
- ],
1822
- close: async ()=>{}
1823
- };
1824
- },
1825
- launchPersistentContext: async ()=>{
1826
- persistentLaunchCalled = true;
1827
- return {
1828
- pages: ()=>[
1829
- page
1830
- ],
1831
- newPage: async ()=>page
1832
- };
1833
- }
1834
- }
1835
- }),
1836
- startChrome: async ()=>{
1837
- startChromeCalls += 1;
1838
- return {
1839
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
1840
- close: async ()=>{}
1841
- };
1842
- },
1843
- mkTempDir: ()=>tempDir,
1844
- removeDir: ()=>{},
1845
- now: ()=>1700000000000
1846
- });
1847
- const result = await tool.invoke({
1848
- actions: [
1849
- {
1850
- type: "evaluate",
1851
- expression: "document.title"
1852
- }
1853
- ]
1854
- });
1855
- const parsed = JSON.parse(String(result));
1856
- (0, external_vitest_namespaceObject.expect)(parsed.persistentProfile).toBe(true);
1857
- (0, external_vitest_namespaceObject.expect)(parsed.transport).toBe("cdp");
1858
- (0, external_vitest_namespaceObject.expect)(connectCalls).toBe(2);
1859
- (0, external_vitest_namespaceObject.expect)(startChromeCalls).toBe(2);
1860
- (0, external_vitest_namespaceObject.expect)(persistentLaunchCalled).toBe(false);
1861
- });
1862
- (0, external_vitest_namespaceObject.it)("falls back to persistent launch when persistent-profile CDP retry fails", async ()=>{
1863
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
1864
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
1865
- workspaces.push(workspace, tempDir);
1866
- let startChromeCalls = 0;
1867
- let connectCalls = 0;
1868
- let persistentLaunchCalled = false;
1869
- const page = {
1870
- goto: async ()=>{},
1871
- click: async ()=>{},
1872
- fill: async ()=>{},
1873
- keyboard: {
1874
- press: async ()=>{}
1875
- },
1876
- waitForTimeout: async ()=>{},
1877
- textContent: async ()=>"",
1878
- evaluate: async ()=>"ok",
1879
- screenshot: async ()=>{},
1880
- title: async ()=>"Profile Fallback",
1881
- url: ()=>"about:blank"
1882
- };
1883
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
1884
- workspace,
1885
- browserProfile: "trading",
1886
- preferPersistentLaunch: false
1887
- }, {
1888
- importPlaywright: async ()=>({
1889
- chromium: {
1890
- connectOverCDP: async ()=>{
1891
- connectCalls += 1;
1892
- throw new Error("overCDP: WebSocket error: ECONNREFUSED");
1893
- },
1894
- launchPersistentContext: async ()=>{
1895
- persistentLaunchCalled = true;
1896
- return {
1897
- pages: ()=>[
1898
- page
1899
- ],
1900
- newPage: async ()=>page
1901
- };
1902
- }
1903
- }
1904
- }),
1905
- startChrome: async ()=>{
1906
- startChromeCalls += 1;
1907
- return {
1908
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
1909
- close: async ()=>{}
1910
- };
1911
- },
1912
- mkTempDir: ()=>tempDir,
1913
- removeDir: ()=>{},
1914
- now: ()=>1700000000000
1915
- });
1916
- const result = await tool.invoke({
1917
- actions: [
1918
- {
1919
- type: "evaluate",
1920
- expression: "document.title"
1921
- }
1922
- ]
1923
- });
1924
- const parsed = JSON.parse(String(result));
1925
- (0, external_vitest_namespaceObject.expect)(parsed.persistentProfile).toBe(true);
1926
- (0, external_vitest_namespaceObject.expect)(parsed.transport).toBe("persistent-context");
1927
- (0, external_vitest_namespaceObject.expect)(connectCalls).toBe(2);
1928
- (0, external_vitest_namespaceObject.expect)(startChromeCalls).toBe(2);
1929
- (0, external_vitest_namespaceObject.expect)(persistentLaunchCalled).toBe(true);
1930
- });
1931
- (0, external_vitest_namespaceObject.it)("resolves persistent profile paths relative to config workspace", async ()=>{
1932
- const executionWorkspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
1933
- const configWorkspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-config-workspace-"));
1934
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
1935
- workspaces.push(executionWorkspace, configWorkspace, tempDir);
1936
- let capturedUserDataDir = "";
1937
- const page = {
1938
- goto: async ()=>{},
1939
- click: async ()=>{},
1940
- fill: async ()=>{},
1941
- keyboard: {
1942
- press: async ()=>{}
1943
- },
1944
- waitForTimeout: async ()=>{},
1945
- textContent: async ()=>"",
1946
- evaluate: async ()=>"ok",
1947
- screenshot: async ()=>{},
1948
- title: async ()=>"Config Workspace Profile",
1949
- url: ()=>"about:blank"
1950
- };
1951
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
1952
- workspace: executionWorkspace,
1953
- configWorkspace,
1954
- browserProfile: "trading"
1955
- }, {
1956
- importPlaywright: async ()=>({
1957
- chromium: {
1958
- connectOverCDP: async ()=>{
1959
- throw new Error("connectOverCDP should not be called");
1960
- },
1961
- launchPersistentContext: async (userDataDir)=>{
1962
- capturedUserDataDir = userDataDir;
1963
- return {
1964
- pages: ()=>[
1965
- page
1966
- ],
1967
- newPage: async ()=>page,
1968
- close: async ()=>{}
1969
- };
1970
- }
1971
- }
1972
- }),
1973
- mkTempDir: ()=>tempDir,
1974
- removeDir: ()=>{},
1975
- now: ()=>1700000000000
1976
- });
1977
- const result = await tool.invoke({
1978
- actions: [
1979
- {
1980
- type: "evaluate",
1981
- expression: "document.title"
1982
- }
1983
- ]
1984
- });
1985
- const parsed = JSON.parse(String(result));
1986
- (0, external_vitest_namespaceObject.expect)(parsed.persistentProfile).toBe(true);
1987
- (0, external_vitest_namespaceObject.expect)(parsed.configWorkspace).toBe(configWorkspace);
1988
- (0, external_vitest_namespaceObject.expect)(parsed.executionWorkspace).toBe(executionWorkspace);
1989
- (0, external_vitest_namespaceObject.expect)(parsed.profilePath).toBe(capturedUserDataDir);
1990
- (0, external_vitest_namespaceObject.expect)(capturedUserDataDir).toBe((0, external_node_path_namespaceObject.join)(configWorkspace, ".wingman", "browser-profiles", "trading"));
1991
- (0, external_vitest_namespaceObject.expect)((0, external_node_fs_namespaceObject.existsSync)(capturedUserDataDir)).toBe(true);
1992
- (0, external_vitest_namespaceObject.expect)((0, external_node_fs_namespaceObject.existsSync)((0, external_node_path_namespaceObject.join)(executionWorkspace, ".wingman", "browser-profiles", "trading"))).toBe(false);
1993
- });
1994
- (0, external_vitest_namespaceObject.it)("rejects concurrent runs when profile lock belongs to an active process", async ()=>{
1995
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
1996
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
1997
- workspaces.push(workspace, tempDir);
1998
- const profileDir = (0, external_node_path_namespaceObject.join)(workspace, ".wingman", "browser-profiles", "trading");
1999
- (0, external_node_fs_namespaceObject.mkdirSync)(profileDir, {
2000
- recursive: true
2001
- });
2002
- const blocker = (0, external_node_child_process_namespaceObject.spawn)("sleep", [
2003
- "30"
2004
- ], {
2005
- stdio: "ignore"
2006
- });
2007
- try {
2008
- (0, external_node_fs_namespaceObject.writeFileSync)((0, external_node_path_namespaceObject.join)(profileDir, ".wingman-browser.lock"), JSON.stringify({
2009
- pid: blocker.pid
2010
- }));
2011
- let startChromeCalled = false;
2012
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
2013
- workspace,
2014
- browserProfile: "trading"
2015
- }, {
2016
- importPlaywright: async ()=>({
2017
- chromium: {
2018
- connectOverCDP: async ()=>({
2019
- contexts: ()=>[],
2020
- close: async ()=>{}
2021
- })
2022
- }
2023
- }),
2024
- startChrome: async ()=>{
2025
- startChromeCalled = true;
2026
- return {
2027
- wsEndpoint: "ws://127.0.0.1:1234/devtools/browser/test",
2028
- close: async ()=>{}
2029
- };
2030
- },
2031
- mkTempDir: ()=>tempDir,
2032
- removeDir: ()=>{},
2033
- now: ()=>1700000000000
2034
- });
2035
- const result = await tool.invoke({
2036
- actions: [
2037
- {
2038
- type: "wait",
2039
- ms: 10
2040
- }
2041
- ]
2042
- });
2043
- (0, external_vitest_namespaceObject.expect)(startChromeCalled).toBe(false);
2044
- (0, external_vitest_namespaceObject.expect)(String(result)).toContain("already in use");
2045
- } finally{
2046
- try {
2047
- blocker.kill("SIGKILL");
2048
- } catch {}
2049
- }
2050
- });
2051
- (0, external_vitest_namespaceObject.it)("recovers from stale profile lock when lock PID is no longer alive", async ()=>{
2052
- const workspace = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-workspace-"));
2053
- const tempDir = (0, external_node_fs_namespaceObject.mkdtempSync)((0, external_node_path_namespaceObject.join)((0, external_node_os_namespaceObject.tmpdir)(), "wingman-browser-temp-"));
2054
- workspaces.push(workspace, tempDir);
2055
- const profileDir = (0, external_node_path_namespaceObject.join)(workspace, ".wingman", "browser-profiles", "trading");
2056
- (0, external_node_fs_namespaceObject.mkdirSync)(profileDir, {
2057
- recursive: true
2058
- });
2059
- (0, external_node_fs_namespaceObject.writeFileSync)((0, external_node_path_namespaceObject.join)(profileDir, ".wingman-browser.lock"), JSON.stringify({
2060
- pid: 999999,
2061
- createdAt: "2026-01-01T00:00:00.000Z"
2062
- }));
2063
- let startChromeCalled = false;
2064
- const page = {
2065
- goto: async ()=>{},
2066
- click: async ()=>{},
2067
- fill: async ()=>{},
2068
- keyboard: {
2069
- press: async ()=>{}
2070
- },
2071
- waitForTimeout: async ()=>{},
2072
- textContent: async ()=>"",
2073
- evaluate: async ()=>"ok",
2074
- screenshot: async ()=>{},
2075
- title: async ()=>"Recovered",
2076
- url: ()=>"about:blank"
2077
- };
2078
- const tool = (0, browser_control_cjs_namespaceObject.createBrowserControlTool)({
2079
- workspace,
2080
- browserProfile: "trading"
2081
- }, {
2082
- importPlaywright: async ()=>({
2083
- chromium: {
2084
- connectOverCDP: async ()=>{
2085
- throw new Error("connectOverCDP should not be called");
2086
- },
2087
- launchPersistentContext: async ()=>({
2088
- pages: ()=>[
2089
- page
2090
- ],
2091
- newPage: async ()=>page,
2092
- close: async ()=>{}
2093
- })
2094
- }
2095
- }),
2096
- mkTempDir: ()=>tempDir,
2097
- removeDir: ()=>{},
2098
- now: ()=>1700000000000
2099
- });
2100
- const result = await tool.invoke({
2101
- actions: [
2102
- {
2103
- type: "evaluate",
2104
- expression: "document.title"
2105
- }
2106
- ]
2107
- });
2108
- const parsed = JSON.parse(String(result));
2109
- (0, external_vitest_namespaceObject.expect)(startChromeCalled).toBe(false);
2110
- (0, external_vitest_namespaceObject.expect)(parsed.persistentProfile).toBe(true);
2111
- (0, external_vitest_namespaceObject.expect)(String(result)).not.toContain("already in use");
2112
- });
2113
- });
2114
- for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
2115
- Object.defineProperty(exports, '__esModule', {
2116
- value: true
2117
- });