fengming 0.3.8 → 0.3.10

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 (1255) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/abort-CCR8oZyg.js +277 -0
  3. package/dist/abort.runtime-eqx84NZa.js +2 -0
  4. package/dist/abort.runtime.js +1 -1
  5. package/dist/acp-spawn-BcDyvaXh.js +2 -0
  6. package/dist/acp-spawn-CCtSel-_.js +1286 -0
  7. package/dist/acp-stateful-target-driver-B3pCvuOV.js +89 -0
  8. package/dist/active-tool-schema-warnings-Cf-5q5WU.js +105 -0
  9. package/dist/active-tool-schema-warnings-Dzt3XE-y.js +2 -0
  10. package/dist/agent-1M2dVE2G.js +2 -0
  11. package/dist/agent-DLDIbUT4.js +1825 -0
  12. package/dist/agent-DZi6j3o6.js +3 -0
  13. package/dist/agent-command-ppfDBwET.js +1435 -0
  14. package/dist/agent-harness-runtime-C0bo62eY.d.ts +913 -0
  15. package/dist/agent-harness-runtime-RkTGiliR.js +207 -0
  16. package/dist/agent-runner-utils-B4YeVAO_.js +267 -0
  17. package/dist/agent-runner.runtime-T_3tlZN1.js +3784 -0
  18. package/dist/agent-runner.runtime.js +1 -1
  19. package/dist/agent-runtime-CloshyK-.d.ts +207 -0
  20. package/dist/agent-runtime-DZsmp1xr.js +199 -0
  21. package/dist/agent-tools-CET9usCz.js +2506 -0
  22. package/dist/agent-via-gateway-CZ0X0YkM.js +486 -0
  23. package/dist/agent-wait-dedupe-I81_F2tr.js +180 -0
  24. package/dist/agents/embedded-agent-runner/run/runtime-context-prompt.d.ts +1 -1
  25. package/dist/agents/embedded-agent-runner/tool-split.d.ts +1 -1
  26. package/dist/agents/model-catalog.runtime.d.ts +1 -1
  27. package/dist/api-BDB5xHYj.js +3 -0
  28. package/dist/api-BH7bfI5d.js +6 -0
  29. package/dist/api-BxJNXitd.js +2 -0
  30. package/dist/approval-client-helpers-CfQA9Jzh.d.ts +78 -0
  31. package/dist/approval-native-helpers-B2zyhxWc.d.ts +241 -0
  32. package/dist/approval-renderers-CMqSXyvm.d.ts +39 -0
  33. package/dist/assistant-Cu_Mzzgu.js +291 -0
  34. package/dist/attachment-normalize-Bb3v5iCC.js +213 -0
  35. package/dist/attempt-execution-BskbAq5I.js +584 -0
  36. package/dist/attempt-execution.runtime-BuT1wpNS.js +3 -0
  37. package/dist/attempt-execution.runtime.js +1 -1
  38. package/dist/attempt.prompt-helpers-ByKj-vQ7.js +543 -0
  39. package/dist/auto-reply/reply/commands-crestodian.d.ts +1 -1
  40. package/dist/binding-routing-EGRNvRC4.js +113 -0
  41. package/dist/binding-targets-B9vYS8n6.js +121 -0
  42. package/dist/bridge-server-DG9YtKQe.js +113 -0
  43. package/dist/browser-cli-B0Ou-Nbm.js +2 -0
  44. package/dist/browser-cli-GF25gL6M.js +230 -0
  45. package/dist/browser-cli-actions-input-CuER6RVe.js +522 -0
  46. package/dist/browser-cli-actions-observe-Dq-Zz_FA.js +81 -0
  47. package/dist/browser-cli-debug-7hvb49S1.js +137 -0
  48. package/dist/browser-cli-inspect-WU5KeWOK.js +117 -0
  49. package/dist/browser-cli-manage-B9D9BvSe.js +446 -0
  50. package/dist/browser-cli-resize-BUOusOPb.js +32 -0
  51. package/dist/browser-cli-shared-DmpSN-Qi.js +69 -0
  52. package/dist/browser-cli-state-D_YxTqRw.js +371 -0
  53. package/dist/browser-control-auth-Cqd1n9FA.js +2 -0
  54. package/dist/browser-profiles-9tQ05wYh.js +2 -0
  55. package/dist/browser-runtime-Bbzumoha.js +389 -0
  56. package/dist/build-CBXuT2K1.js +261 -0
  57. package/dist/build-info.json +3 -3
  58. package/dist/bundled/boot-md/handler.js +2 -2
  59. package/dist/bundled/session-memory/handler.js +1 -1
  60. package/dist/canvas-host/a2ui/.bundle.hash +1 -1
  61. package/dist/capability-cli-CiVGX7ut.js +1809 -0
  62. package/dist/channel-BIVwHq7P.js +2309 -0
  63. package/dist/channel-CiA2FVdL.d.ts +427 -0
  64. package/dist/channel-core-Cj9JTqeu.js +5 -0
  65. package/dist/channel-core-DjVpcH1C.d.ts +6 -0
  66. package/dist/channel-entry-contract-Bs_54m1D.d.ts +114 -0
  67. package/dist/channel-inbound-CdUdeQRa.js +121 -0
  68. package/dist/channel-inbound-iGiqx6CS.d.ts +97 -0
  69. package/dist/channel-message-C3QPaDUk.js +12 -0
  70. package/dist/channel-message-CXDjxb2U.d.ts +9 -0
  71. package/dist/channel-outbound-ofvvmMSK.d.ts +325 -0
  72. package/dist/channel-pairing-DKscOV1K.d.ts +58 -0
  73. package/dist/channel.runtime-VW6PW_ez.js +697 -0
  74. package/dist/channel.runtime.js +1 -1
  75. package/dist/chat-CFkQepUQ.js +3 -0
  76. package/dist/chat-Czh_tXM0.js +2940 -0
  77. package/dist/chrome-B2cq8YyH.js +1517 -0
  78. package/dist/cli/run-main.js +5 -5
  79. package/dist/cli-compaction-Dxv4nt7R.js +363 -0
  80. package/dist/cli-runner-CimXSTVs.js +2 -0
  81. package/dist/cli-runner-orCzE1Sr.js +597 -0
  82. package/dist/cli-runner.runtime-CsW0dXJW.js +3 -0
  83. package/dist/cli-runner.runtime-DgPrc1do.js +4 -0
  84. package/dist/cli-runner.runtime.js +1 -1
  85. package/dist/cli-startup-metadata.json +10 -12
  86. package/dist/command-registry-C5ooX6PF.js +4 -0
  87. package/dist/command-registry-DMB-HKIk.js +9 -0
  88. package/dist/command-registry-core-B2w_XWvn.js +114 -0
  89. package/dist/command-status.runtime-Bdy3Dkar.js +90 -0
  90. package/dist/command-status.runtime.js +1 -1
  91. package/dist/commands-compact.runtime-Bk2jTQo6.js +10 -0
  92. package/dist/commands-compact.runtime.js +1 -1
  93. package/dist/commands-handlers.runtime-Csw1og0U.js +6327 -0
  94. package/dist/commands-handlers.runtime.js +1 -1
  95. package/dist/commands-mRqmLIVz.d.ts +117 -0
  96. package/dist/commands-status-Dgrj_ubK.js +3 -0
  97. package/dist/commands-status-s32HJOpD.js +16 -0
  98. package/dist/commands-status.runtime-Dgrj_ubK.js +3 -0
  99. package/dist/commands-status.runtime.js +1 -1
  100. package/dist/commands-subagents-control.runtime-C_hnOO9l.js +2 -0
  101. package/dist/commands-subagents-control.runtime.js +1 -1
  102. package/dist/commands-system-prompt-CQV742Cc.js +2 -0
  103. package/dist/commands-system-prompt-DTfsKwK1.js +161 -0
  104. package/dist/commands-types-MXHhrssO.d.ts +132 -0
  105. package/dist/commands.runtime-akiVK67l.js +175 -0
  106. package/dist/commands.runtime.js +1 -1
  107. package/dist/commitments/runtime.js +1 -1
  108. package/dist/compact-U6ZhvPtD.js +1165 -0
  109. package/dist/compact.runtime-36E5vKsC.js +12 -0
  110. package/dist/compact.runtime.js +1 -1
  111. package/dist/completion-cli-Bf4mEw2W.js +393 -0
  112. package/dist/config-BJJhHN9E.js +374 -0
  113. package/dist/config-mutations-swLu-j_p.js +161 -0
  114. package/dist/config-schema-Tjner6bM.d.ts +20 -0
  115. package/dist/context-engine-host-compat-6fkn_daV.js +280 -0
  116. package/dist/context-engine-host-compat-DtAZC1bS.js +2 -0
  117. package/dist/context-engine-lifecycle-R__Idxi1.js +627 -0
  118. package/dist/control-auth-DnkI94_D.js +114 -0
  119. package/dist/control-service-BBsamNjq.js +40 -0
  120. package/dist/control-service-BGpHj7RL.js +3 -0
  121. package/dist/control-ui/assets/activity-D-mnRThU.js +124 -0
  122. package/dist/control-ui/assets/agents-U_KSP5I_.js +1030 -0
  123. package/dist/control-ui/assets/channels-ohK9_G1O.js +120 -0
  124. package/dist/control-ui/assets/cron-6ZCzfU29.js +1016 -0
  125. package/dist/control-ui/assets/debug-CSsDLg_s.js +97 -0
  126. package/dist/control-ui/assets/index-jUDczxhd.js +7214 -0
  127. package/dist/control-ui/assets/instances-782ZoDT4.js +57 -0
  128. package/dist/control-ui/assets/nodes-BMX16BKM.js +444 -0
  129. package/dist/control-ui/assets/sessions-jLGSApYa.js +425 -0
  130. package/dist/control-ui/assets/skills-DweBwUhs.js +362 -0
  131. package/dist/control-ui/assets/workboard-BsU-FXIo.js +402 -0
  132. package/dist/control-ui/index.html +1 -1
  133. package/dist/control-ui/sw.js +1 -1
  134. package/dist/conversation-runtime-DDekWU-U.js +31 -0
  135. package/dist/core-Bpk-qSJH.js +284 -0
  136. package/dist/core-Chrz4oRB.d.ts +223 -0
  137. package/dist/core-api-DSpUKNVW.js +2 -0
  138. package/dist/core-api-hLsW03Wo.js +5 -0
  139. package/dist/crestodian/crestodian.js +1 -1
  140. package/dist/crestodian/rescue-message.d.ts +1 -1
  141. package/dist/crestodian/rescue-message.js +1 -1
  142. package/dist/crestodian-C0x7JjF-.js +55 -0
  143. package/dist/delegate-BArFIZ4B.d.ts +30 -0
  144. package/dist/deliver-BnVp3VbL.d.ts +111 -0
  145. package/dist/delivery-queue-BFOASdf5.d.ts +161 -0
  146. package/dist/delivery-queue-runtime-BFfc8AEs.d.ts +9 -0
  147. package/dist/dialogue-No0NvYX7.js +37 -0
  148. package/dist/direct-dm-C-h88JJH.d.ts +79 -0
  149. package/dist/directive-handling.fast-lane-DTyDKhZb.js +70 -0
  150. package/dist/directive-handling.impl-DMReM6tu.js +2 -0
  151. package/dist/directive-handling.impl-DzPouhV-.js +823 -0
  152. package/dist/directive-handling.model-selection-BjwTBAZJ.js +122 -0
  153. package/dist/directive-handling.persist.runtime-D_O1okkR.js +274 -0
  154. package/dist/directive-handling.persist.runtime.js +1 -1
  155. package/dist/dispatch-Dtl-oRuN.js +2057 -0
  156. package/dist/dispatch-acp-transcript.runtime-M4y0Dq74.js +40 -0
  157. package/dist/dispatch-acp-transcript.runtime.js +1 -1
  158. package/dist/dispatch-acp.runtime-B8uCIKZS.js +18 -0
  159. package/dist/dispatch-acp.runtime.js +1 -1
  160. package/dist/dispatcher-DslvaRcj.js +106 -0
  161. package/dist/doctor-config-flow-LU2C94af.js +1819 -0
  162. package/dist/doctor-core-checks-BqcjExIZ.js +666 -0
  163. package/dist/doctor-core-checks-Diuk8l0N.js +2 -0
  164. package/dist/doctor-core-checks.runtime-DbS-kMZN.js +278 -0
  165. package/dist/doctor-core-checks.runtime.js +1 -1
  166. package/dist/doctor-health-BdqHwfYE.js +65 -0
  167. package/dist/doctor-health-contributions-DLLTVnll.js +874 -0
  168. package/dist/doctor-lint-PZqkVMWf.js +95 -0
  169. package/dist/doctor-mRfJMSb5.js +6 -0
  170. package/dist/doctor-state-integrity-Cdlm-peH.js +1257 -0
  171. package/dist/draft-stream-controls-B7uLonbw.d.ts +159 -0
  172. package/dist/embedded-agent-CEpOPW6X.js +4 -0
  173. package/dist/embedded-agent-CNINO_M-.d.ts +5 -0
  174. package/dist/embedded-agent-DxwzoZkp.js +4074 -0
  175. package/dist/embedded-agent.runtime-DDbhA85-.js +4 -0
  176. package/dist/embedded-agent.runtime.js +1 -1
  177. package/dist/embedded-backend-ChaKCepC.js +1581 -0
  178. package/dist/embedded-gateway-stub.runtime-e_ZxGhcW.js +12 -0
  179. package/dist/embedded-gateway-stub.runtime.js +1 -1
  180. package/dist/entry.d.ts +1 -1
  181. package/dist/extensionAPI.d.ts +2 -2
  182. package/dist/extensionAPI.js +1 -1
  183. package/dist/extensions/active-memory/index.d.ts +1 -1
  184. package/dist/extensions/active-memory/index.js +1 -1
  185. package/dist/extensions/admin-http-rpc/index.d.ts +1 -1
  186. package/dist/extensions/admin-http-rpc/index.js +1 -1
  187. package/dist/extensions/bonjour/index.d.ts +1 -1
  188. package/dist/extensions/browser/browser-bridge.js +1 -1
  189. package/dist/extensions/browser/browser-config.js +4 -4
  190. package/dist/extensions/browser/browser-control-auth.js +2 -2
  191. package/dist/extensions/browser/browser-doctor.js +2 -2
  192. package/dist/extensions/browser/browser-maintenance.js +1 -1
  193. package/dist/extensions/browser/browser-profiles.js +2 -2
  194. package/dist/extensions/browser/browser-runtime-api.js +12 -12
  195. package/dist/extensions/browser/cli-metadata.d.ts +1 -1
  196. package/dist/extensions/browser/cli-metadata.js +1 -1
  197. package/dist/extensions/browser/index.d.ts +1 -1
  198. package/dist/extensions/browser/index.js +1 -1
  199. package/dist/extensions/browser/plugin-registration.d.ts +1 -1
  200. package/dist/extensions/browser/plugin-registration.js +1 -1
  201. package/dist/extensions/browser/register.runtime.d.ts +2 -2
  202. package/dist/extensions/browser/register.runtime.js +4 -4
  203. package/dist/extensions/browser/runtime-api.d.ts +3 -3
  204. package/dist/extensions/browser/runtime-api.js +14 -14
  205. package/dist/extensions/browser/setup-api.d.ts +1 -1
  206. package/dist/extensions/canvas/cli-metadata.d.ts +1 -1
  207. package/dist/extensions/canvas/index.d.ts +1 -1
  208. package/dist/extensions/canvas/index.js +1 -1
  209. package/dist/extensions/canvas/setup-api.d.ts +1 -1
  210. package/dist/extensions/deepseek/api.d.ts +1 -1
  211. package/dist/extensions/deepseek/index.d.ts +1 -1
  212. package/dist/extensions/deepseek/provider-discovery.d.ts +1 -1
  213. package/dist/extensions/deepseek/stream.d.ts +1 -1
  214. package/dist/extensions/device-pair/api.d.ts +4 -4
  215. package/dist/extensions/device-pair/api.js +1 -1
  216. package/dist/extensions/device-pair/index.d.ts +1 -1
  217. package/dist/extensions/device-pair/notify.d.ts +1 -1
  218. package/dist/extensions/device-pair/pair-command-approve.js +1 -1
  219. package/dist/extensions/device-pair/qr-image.d.ts +1 -1
  220. package/dist/extensions/memory-core/api.d.ts +1 -1
  221. package/dist/extensions/memory-core/cli-metadata.d.ts +1 -1
  222. package/dist/extensions/memory-core/cli-metadata.js +1 -1
  223. package/dist/extensions/memory-core/index.d.ts +1 -1
  224. package/dist/extensions/memory-core/manager-runtime.d.ts +1 -1
  225. package/dist/extensions/memory-core/runtime-api.d.ts +3 -3
  226. package/dist/extensions/skill-workshop/api.d.ts +2 -2
  227. package/dist/extensions/skill-workshop/api.js +1 -1
  228. package/dist/extensions/skill-workshop/index.d.ts +1 -1
  229. package/dist/extensions/skill-workshop/index.js +2 -2
  230. package/dist/extensions/tavily/index.d.ts +1 -1
  231. package/dist/extensions/tavily/web-search-contract-api.d.ts +1 -1
  232. package/dist/extensions/tavily/web-search-provider.d.ts +1 -1
  233. package/dist/extensions/thread-ownership/api.d.ts +2 -2
  234. package/dist/extensions/thread-ownership/index.d.ts +1 -1
  235. package/dist/extensions/webhooks/api.d.ts +2 -2
  236. package/dist/extensions/webhooks/api.js +1 -1
  237. package/dist/extensions/webhooks/index.d.ts +1 -1
  238. package/dist/extensions/webhooks/index.js +1 -1
  239. package/dist/extensions/webhooks/runtime-api.d.ts +1 -1
  240. package/dist/extensions/workboard/api.d.ts +2 -2
  241. package/dist/extensions/workboard/index.d.ts +1 -1
  242. package/dist/extensions/workboard/index.js +1 -1
  243. package/dist/extensions/workboard/runtime-api.d.ts +1 -1
  244. package/dist/fengming-runtime-CtRd5677.d.ts +153 -0
  245. package/dist/fengming-tools-DBLsJfsf.js +12221 -0
  246. package/dist/gateway-cli-BgDV2HF9.js +443 -0
  247. package/dist/gateway-method-runtime-d9oN_XO9.js +21 -0
  248. package/dist/get-reply-CEMtvaTJ.js +5198 -0
  249. package/dist/get-reply-from-config.runtime-CE8zmX7o.js +2 -0
  250. package/dist/get-reply-from-config.runtime.js +1 -1
  251. package/dist/heartbeat-runner-H8SmaKmJ.js +5 -0
  252. package/dist/heartbeat-runner.runtime-6hUaxEbl.js +3 -0
  253. package/dist/heartbeat-runner.runtime.js +1 -1
  254. package/dist/hooks-DkEvkwzS.js +536 -0
  255. package/dist/host-compat-DeAq3dnI.d.ts +21 -0
  256. package/dist/http-registry-BDoApjTY.d.ts +23 -0
  257. package/dist/inbound-reply-dispatch-CIYP2OPo.d.ts +156 -0
  258. package/dist/inbound-reply-dispatch-geHu6oUK.js +147 -0
  259. package/dist/inbound-reply-dispatch-vwW5Hl-_.js +2 -0
  260. package/dist/index.js +1 -1
  261. package/dist/init-DpE_6dG4.js +59 -0
  262. package/dist/interactive-Cb_1f91G.d.ts +26 -0
  263. package/dist/isolated-agent-B_upYOOM.js +2 -0
  264. package/dist/isolated-agent-KH9uwWhw.js +1097 -0
  265. package/dist/kernel-BHnBXnm2.d.ts +241 -0
  266. package/dist/lifecycle-BmZwopzF.js +570 -0
  267. package/dist/list.probe-5kzWm9Jk.js +451 -0
  268. package/dist/list.probe-9zBcGGQ4.js +2 -0
  269. package/dist/list.status-command-DY2ifqp1.js +815 -0
  270. package/dist/llm-slug-generator-Bmx0I84M.js +78 -0
  271. package/dist/llm-slug-generator.js +1 -1
  272. package/dist/loader-BVz75gSb.d.ts +142 -0
  273. package/dist/local-dispatch.runtime-CX3IOY1E.js +10 -0
  274. package/dist/local-dispatch.runtime.js +1 -1
  275. package/dist/manager-BXGg8bfG.d.ts +409 -0
  276. package/dist/mcp-http-B1lnh67s.js +2 -0
  277. package/dist/mcp-http-CamghE-W.js +583 -0
  278. package/dist/media-runtime-DpykroJR.d.ts +261 -0
  279. package/dist/memory-core-host-engine-embeddings-N2dX5P40.d.ts +324 -0
  280. package/dist/memory-core-host-engine-storage-WQfkQMer.d.ts +54 -0
  281. package/dist/message-handler-Ca_pqGVS.js +1806 -0
  282. package/dist/model-catalog-BBMLIjhq.d.ts +88 -0
  283. package/dist/model-selection-Cq82FXLy.js +352 -0
  284. package/dist/models-cli-Dm_393dw.js +257 -0
  285. package/dist/monitor-d0eyE2k0.js +60 -0
  286. package/dist/monitor.account-vLQ3bKHu.js +5382 -0
  287. package/dist/nodes-Bunvrb33.js +1483 -0
  288. package/dist/nodes-edNlxb2I.js +3 -0
  289. package/dist/nodes-pending-DEIwVh9v.js +211 -0
  290. package/dist/openai-compat-errors-CvWEoG98.js +136 -0
  291. package/dist/openai-http-Bskdv4Tv.js +836 -0
  292. package/dist/openresponses-http-DxdgCxFU.js +1175 -0
  293. package/dist/operations-Z85LFqsT.js +805 -0
  294. package/dist/outbound.types-DVkbsxo8.d.ts +291 -0
  295. package/dist/plugin-enabled-fvhTpvYS.js +232 -0
  296. package/dist/plugin-entry-CunlVUw6.d.ts +47 -0
  297. package/dist/plugin-registration-9ovnK_Tk.js +97 -0
  298. package/dist/plugin-runtime-DH2ZM9P5.d.ts +117 -0
  299. package/dist/plugin-sdk/.boundary-entry-shims.stamp +1 -1
  300. package/dist/plugin-sdk/acp-runtime-backend.js +1 -1
  301. package/dist/plugin-sdk/acp-runtime.js +1 -1
  302. package/dist/plugin-sdk/agent-harness-runtime.js +5 -5
  303. package/dist/plugin-sdk/agent-harness-task-runtime.js +1 -1
  304. package/dist/plugin-sdk/agent-harness.js +6 -6
  305. package/dist/plugin-sdk/agent-runtime.js +2 -2
  306. package/dist/plugin-sdk/bundled-channel-config-schema-Dfn3b8sF.d.ts +3169 -0
  307. package/dist/plugin-sdk/bundled-channel-config-schema.d.ts +1 -1
  308. package/dist/plugin-sdk/channel-config-schema-legacy.d.ts +1 -1
  309. package/dist/plugin-sdk/channel-core.js +2 -2
  310. package/dist/plugin-sdk/channel-envelope.js +1 -1
  311. package/dist/plugin-sdk/channel-inbound-roots.js +1 -1
  312. package/dist/plugin-sdk/channel-inbound.js +2 -2
  313. package/dist/plugin-sdk/channel-location.js +1 -1
  314. package/dist/plugin-sdk/channel-message-runtime.js +3 -3
  315. package/dist/plugin-sdk/channel-message.js +2 -2
  316. package/dist/plugin-sdk/channel-runtime.js +0 -1
  317. package/dist/plugin-sdk/command-status-runtime.js +1 -1
  318. package/dist/plugin-sdk/compat.js +1 -1
  319. package/dist/plugin-sdk/conversation-binding-runtime.js +1 -1
  320. package/dist/plugin-sdk/conversation-runtime.js +3 -3
  321. package/dist/plugin-sdk/core.js +2 -2
  322. package/dist/plugin-sdk/discord.d.ts +1 -1
  323. package/dist/plugin-sdk/gateway-method-runtime.js +1 -1
  324. package/dist/plugin-sdk/health.js +1 -1
  325. package/dist/plugin-sdk/hook-runtime.js +0 -1
  326. package/dist/plugin-sdk/inbound-reply-dispatch.js +2 -2
  327. package/dist/plugin-sdk/index.js +1 -1
  328. package/dist/plugin-sdk/infra-runtime.js +3 -1
  329. package/dist/plugin-sdk/provider-auth-api-key.js +0 -1
  330. package/dist/plugin-sdk/provider-stream-family.js +0 -1
  331. package/dist/plugin-sdk/provider-usage.js +649 -1
  332. package/dist/plugin-sdk/reply-runtime.js +4 -4
  333. package/dist/plugin-sdk/video-generation.js +206 -1
  334. package/dist/plugin-service-BdZxoKBZ.js +1249 -0
  335. package/dist/plugin-service-quTl5hT0.d.ts +24 -0
  336. package/dist/plugins/build-smoke-entry.d.ts +2 -2
  337. package/dist/plugins/loader.d.ts +1 -1
  338. package/dist/plugins/provider-discovery.runtime.d.ts +1 -1
  339. package/dist/plugins/provider-runtime.runtime.d.ts +1 -1
  340. package/dist/plugins/runtime/index.d.ts +1 -1
  341. package/dist/plugins/runtime/index.js +4 -4
  342. package/dist/plugins/tools.d.ts +1 -1
  343. package/dist/prepare.runtime-DFvkUqBZ.js +798 -0
  344. package/dist/prepare.runtime.js +1 -1
  345. package/dist/preview-warnings-CGzc8ccG.js +618 -0
  346. package/dist/program-D19g2jaa.js +131 -0
  347. package/dist/provider-api-key-auth-B8GgTfo8.d.ts +27 -0
  348. package/dist/provider-auth-result-Diw-woMA.d.ts +21 -0
  349. package/dist/provider-catalog-shared-hMvzzDgL.d.ts +62 -0
  350. package/dist/provider-dispatcher-DCTc4lG_.js +22 -0
  351. package/dist/provider-dispatcher.runtime.js +1 -1
  352. package/dist/provider-model-shared-BUCh3uCL.d.ts +143 -0
  353. package/dist/provider-registry-BIokPlxa.d.ts +8 -0
  354. package/dist/provider-registry-CyUOXHG-.d.ts +8 -0
  355. package/dist/provider-registry-i--H79Ao.d.ts +29 -0
  356. package/dist/provider-self-hosted-setup-BF8UR8wg.d.ts +74 -0
  357. package/dist/provider-stream-NF0XJnar.d.ts +139 -0
  358. package/dist/provider-stream-shared-DLwDaYed.d.ts +132 -0
  359. package/dist/provider-web-search-contract-fields-D61Vl5Kl.d.ts +25 -0
  360. package/dist/pw-ai-DYR-D7xR.js +3064 -0
  361. package/dist/register.agent-DwW0mQPk.js +152 -0
  362. package/dist/register.crestodian-BhIukKDA.js +24 -0
  363. package/dist/register.maintenance-DWHlvztJ.js +85 -0
  364. package/dist/register.subclis-Bsvdh8RI.js +3 -0
  365. package/dist/register.subclis-DVk0HU4k.js +31 -0
  366. package/dist/register.subclis-core-BK7nVvl6.js +278 -0
  367. package/dist/registry-hscEPAcC.d.ts +8 -0
  368. package/dist/registry-types-Ce-n1tuw.d.ts +392 -0
  369. package/dist/repair-sequencing-0-qGNSUO.js +652 -0
  370. package/dist/reply-payload-mCw4ZND6.d.ts +200 -0
  371. package/dist/reply-turn-admission-DMWNadoS.js +2056 -0
  372. package/dist/reply.runtime-CE8zmX7o.js +2 -0
  373. package/dist/reply.runtime.js +1 -1
  374. package/dist/result-fallback-classifier-BZmv2ACy.js +98 -0
  375. package/dist/route-qQ-jYpFa.js +475 -0
  376. package/dist/routes-dTCmw98g.js +2 -0
  377. package/dist/routes-r8DRKa83.js +3701 -0
  378. package/dist/run-BgH7EPGH.js +1162 -0
  379. package/dist/run-command-DCsM-BVh.js +23 -0
  380. package/dist/run-command-I2ib4dwS.js +2 -0
  381. package/dist/run-context-CWaKUKKJ.js +66 -0
  382. package/dist/run-embedded.runtime-CBnDBWN0.js +4 -0
  383. package/dist/run-embedded.runtime.js +1 -1
  384. package/dist/run-execution-cli.runtime-DlYXI-lw.js +4 -0
  385. package/dist/run-execution-cli.runtime.js +1 -1
  386. package/dist/run-executor.runtime-DwepGrmB.js +330 -0
  387. package/dist/run-executor.runtime.js +1 -1
  388. package/dist/run-subagent-registry.runtime-CeVpoIhj.js +2 -0
  389. package/dist/run-subagent-registry.runtime.js +1 -1
  390. package/dist/runtime-D2ee-rNh.js +436 -0
  391. package/dist/runtime-api-B99ZlkNt.d.ts +5 -0
  392. package/dist/runtime-api-Cta2L_Yo.js +12 -0
  393. package/dist/runtime-channel-LKOkML3M.js +2 -0
  394. package/dist/runtime-channel-UtWvrTZ5.js +148 -0
  395. package/dist/runtime-embedded-agent.runtime-9O2Idzyb.js +2 -0
  396. package/dist/runtime-embedded-agent.runtime.js +1 -1
  397. package/dist/runtime-forwarders-DjI8RFL5.d.ts +39 -0
  398. package/dist/sdk-setup-tools-B-X04pa6.js +8 -0
  399. package/dist/selection-B02h8Old.js +3 -0
  400. package/dist/selection-DEPvzrW2.js +18365 -0
  401. package/dist/server-CMYi8gDo.js +24 -0
  402. package/dist/server-Cx07rsiY.js +72 -0
  403. package/dist/server-close.runtime.js +1 -1
  404. package/dist/server-context-BIemGRt4.js +2 -0
  405. package/dist/server-context-CB_an9iy.js +955 -0
  406. package/dist/server-cron-BeyuBUjb.js +3173 -0
  407. package/dist/server-cron-CV7KkVeB.js +2 -0
  408. package/dist/server-methods-C7EnpOhB.js +497 -0
  409. package/dist/server-node-events-DMMzZciN.js +597 -0
  410. package/dist/server-plugin-bootstrap-O6MzvzL8.js +71 -0
  411. package/dist/server-plugins-Dwnaz9kX.js +435 -0
  412. package/dist/server-reload-handlers-C-6TyPvI.js +719 -0
  413. package/dist/server-restart-sentinel-Dc35eYgk.js +700 -0
  414. package/dist/server-runtime-services-DCs-gqh_.js +3 -0
  415. package/dist/server-runtime-services-DF2fzzVd.js +147 -0
  416. package/dist/server-startup-plugins-t-YeYibm.js +127 -0
  417. package/dist/server-startup-post-attach-CiEki-DC.js +793 -0
  418. package/dist/server-ws-runtime-uaUpI-e8.js +374 -0
  419. package/dist/server.impl-MoHjSMr5.js +2622 -0
  420. package/dist/session-kill-http-CYCiQpt2.js +121 -0
  421. package/dist/session-reset-service-BYbADY57.js +651 -0
  422. package/dist/session-status.runtime-8NASbeO4.js +2 -0
  423. package/dist/session-status.runtime.js +1 -1
  424. package/dist/session-subagent-reactivation.runtime-DGeNY2Rb.js +2 -0
  425. package/dist/session-subagent-reactivation.runtime.js +1 -1
  426. package/dist/session-tab-registry-C2eElZrt.js +551 -0
  427. package/dist/sessions-DXAdVXIx.js +1917 -0
  428. package/dist/sessions-history-http-BwK7b8OH.js +432 -0
  429. package/dist/sessions-patch-BYC5gvY1.js +401 -0
  430. package/dist/sessions-resolve-C3ORcdmo.js +180 -0
  431. package/dist/sessions.runtime-BijldeSY.js +2 -0
  432. package/dist/sessions.runtime.js +1 -1
  433. package/dist/snapshot-urls-C5CfP3Co.js +317 -0
  434. package/dist/speech-core-wWkTZPpQ.d.ts +49 -0
  435. package/dist/standalone-CHrieUsw.js +42 -0
  436. package/dist/startup-context-CZfmG8-g.js +314 -0
  437. package/dist/status-subagents.runtime-D2XMebiS.js +32 -0
  438. package/dist/status-subagents.runtime.js +1 -1
  439. package/dist/status-text-JR7IPyzZ.js +301 -0
  440. package/dist/stream-BJgTkLEI.d.ts +5 -0
  441. package/dist/subagent-announce-B9cfs_KZ.js +353 -0
  442. package/dist/subagent-announce-delivery-CtmEvLTS.js +1369 -0
  443. package/dist/subagent-control-DVqLHi9O.js +492 -0
  444. package/dist/subagent-hooks-D251uSvy.js +230 -0
  445. package/dist/subagent-hooks-api-DvdMKxsC.js +23 -0
  446. package/dist/subagent-hooks-uLORYChc.js +2 -0
  447. package/dist/subagent-registry-BW2l_oYu.js +3 -0
  448. package/dist/subagent-registry-BxEMHuiN.js +2627 -0
  449. package/dist/subagent-registry.runtime.d.ts +1 -1
  450. package/dist/subagent-registry.runtime.js +1 -1
  451. package/dist/subagent-session-cleanup-BC5wV2qQ.js +390 -0
  452. package/dist/system-fvgHsr2x.js +111 -0
  453. package/dist/talk-DU0Sod_K.js +2454 -0
  454. package/dist/target-id-BR2xJIkd.js +107 -0
  455. package/dist/task-registry-control.runtime.js +1 -1
  456. package/dist/thread-bindings-8XNu5U2p.js +228 -0
  457. package/dist/tool-Boeg0N5g.js +143 -0
  458. package/dist/tool-dispatch-BhLLaL2g.js +155 -0
  459. package/dist/tool-resolution-CzsLs-87.js +153 -0
  460. package/dist/tool-split-Bedy42Ms.d.ts +19 -0
  461. package/dist/tools-B6egHpE3.d.ts +38 -0
  462. package/dist/tools-effective-NXscxK8n.js +442 -0
  463. package/dist/tools-effective-inventory-NsGMUVo-.js +379 -0
  464. package/dist/tools-invoke-_sSu96Kq.js +51 -0
  465. package/dist/tools-invoke-http-BDhlRl-G.js +68 -0
  466. package/dist/tools-invoke-shared-BH-T9Bcg.js +200 -0
  467. package/dist/tts-runtime-C1wu3o15.d.ts +230 -0
  468. package/dist/tui-C733Qov0.js +2 -0
  469. package/dist/tui-DqbscVN5.js +3 -0
  470. package/dist/tui-backend-_Pn3Byj-.js +257 -0
  471. package/dist/tui-cli-CAiC39zd.js +40 -0
  472. package/dist/tui-ink-run-ChXEGj1h.js +7414 -0
  473. package/dist/tui-ink-run-D4mSfLHj.js +2 -0
  474. package/dist/types-BQw1qXGl.d.ts +7034 -0
  475. package/dist/types-BzMoU6-C.d.ts +111 -0
  476. package/dist/types-DltHmoCX.d.ts +393 -0
  477. package/dist/types.public-C_bVIMBl.d.ts +70 -0
  478. package/dist/web-fetch/runtime.d.ts +1 -1
  479. package/dist/webhook-targets-DW2jhddP.d.ts +99 -0
  480. package/npm-shrinkwrap.json +12861 -11889
  481. package/package.json +2 -5
  482. package/skills/batch/SKILL.md +118 -0
  483. package/skills/code-review/SKILL.md +107 -0
  484. package/skills/debug/SKILL.md +83 -0
  485. package/skills/loop/SKILL.md +118 -0
  486. package/skills/run/SKILL.md +79 -0
  487. package/skills/run-skill-generator/SKILL.md +179 -0
  488. package/skills/verify/SKILL.md +103 -0
  489. package/dist/abort-DGskei2p.js +0 -277
  490. package/dist/abort.runtime-Buq9IZxn.js +0 -2
  491. package/dist/acp-spawn-DC6IyYaB.js +0 -1286
  492. package/dist/acp-spawn-Diqb3nel.js +0 -2
  493. package/dist/acp-stateful-target-driver-Clhe_L8v.js +0 -89
  494. package/dist/active-tool-schema-warnings-BRhKkyvt.js +0 -2
  495. package/dist/active-tool-schema-warnings-C6N0-ce6.js +0 -105
  496. package/dist/agent-C5lhsEZJ.js +0 -2
  497. package/dist/agent-WEb757bl.js +0 -1825
  498. package/dist/agent-command-iLD_nsVY.js +0 -1435
  499. package/dist/agent-core-BeDN8Ns5.d.ts +0 -13
  500. package/dist/agent-harness-runtime-C89_Q-bW.d.ts +0 -913
  501. package/dist/agent-harness-runtime-Dfn5rik2.js +0 -207
  502. package/dist/agent-runner-utils-DNiuuo43.js +0 -267
  503. package/dist/agent-runner.runtime-CFF_qJ5V.js +0 -3784
  504. package/dist/agent-runtime-BkMtWXxn.js +0 -199
  505. package/dist/agent-runtime-HufMO_YR.d.ts +0 -207
  506. package/dist/agent-tools-HmaDv4ot.js +0 -2506
  507. package/dist/agent-via-gateway-CZQG8RYL.js +0 -486
  508. package/dist/agent-wait-dedupe-C3xQk2Ww.js +0 -180
  509. package/dist/agent-z1cs3c7n.js +0 -3
  510. package/dist/api-B4IMKjSe.js +0 -3
  511. package/dist/api-BwSbBWI8.js +0 -3
  512. package/dist/api-CE9In9m4.js +0 -5
  513. package/dist/api-ClPvYNGa.js +0 -32
  514. package/dist/api-CntBCaZf.js +0 -3
  515. package/dist/api-DBZBwTsn.js +0 -6
  516. package/dist/api-OCPwGOvK.js +0 -2
  517. package/dist/api-yYhEo7gK.js +0 -4
  518. package/dist/approval-client-helpers-CfdQ3-vv.d.ts +0 -78
  519. package/dist/approval-native-helpers-DSHPksK4.d.ts +0 -241
  520. package/dist/approval-renderers-BfEfwk44.d.ts +0 -39
  521. package/dist/assistant-v5fdOYu7.js +0 -291
  522. package/dist/attachment-normalize-BHAbLiL2.js +0 -213
  523. package/dist/attempt-execution-5w9WYbaJ.js +0 -584
  524. package/dist/attempt-execution.runtime-DnhOWGzr.js +0 -3
  525. package/dist/attempt.prompt-helpers-C4M4erF7.js +0 -543
  526. package/dist/binding-routing-Dpes-QF1.js +0 -113
  527. package/dist/binding-targets-B6H5Pd-A.js +0 -121
  528. package/dist/bridge-server-BCpxCRm_.js +0 -113
  529. package/dist/browser-cli-DMhXHopl.js +0 -230
  530. package/dist/browser-cli-Dy_VugK0.js +0 -2
  531. package/dist/browser-cli-actions-input-WMP7_lm6.js +0 -522
  532. package/dist/browser-cli-actions-observe-DQWAWhwU.js +0 -81
  533. package/dist/browser-cli-debug-CaT2ZKAx.js +0 -137
  534. package/dist/browser-cli-inspect-DU-LUXq1.js +0 -117
  535. package/dist/browser-cli-manage-DAuogqIh.js +0 -446
  536. package/dist/browser-cli-resize-Cz5uO_aR.js +0 -32
  537. package/dist/browser-cli-shared-CjPZcG3j.js +0 -69
  538. package/dist/browser-cli-state-CC3l77-K.js +0 -371
  539. package/dist/browser-control-auth-ELccIUZy.js +0 -2
  540. package/dist/browser-profiles-Cuy4ia6_.js +0 -2
  541. package/dist/browser-runtime-De-iUfME.js +0 -389
  542. package/dist/build-DEF8Per9.js +0 -261
  543. package/dist/capability-cli-Bydel4E7.js +0 -1809
  544. package/dist/channel-6SGL4R5P.js +0 -2309
  545. package/dist/channel-D3Q3b8J-.d.ts +0 -427
  546. package/dist/channel-core-Bj71kAB5.d.ts +0 -6
  547. package/dist/channel-core-DMvyWnHg.js +0 -5
  548. package/dist/channel-entry-contract-zYxRmEdf.d.ts +0 -114
  549. package/dist/channel-inbound-DVJzBcJ8.d.ts +0 -97
  550. package/dist/channel-inbound-DlCa7eJe.js +0 -121
  551. package/dist/channel-message-CyPGMMFB.js +0 -12
  552. package/dist/channel-message-Czl4cdoA.d.ts +0 -9
  553. package/dist/channel-outbound-BNbhmruA.d.ts +0 -325
  554. package/dist/channel-pairing-BiS-tSvl.d.ts +0 -58
  555. package/dist/channel-runtime-D8hntg7H.js +0 -7
  556. package/dist/channel.runtime-DxErReJR.js +0 -697
  557. package/dist/chat-BLA8ORQI.js +0 -3
  558. package/dist/chat-DWRXkuvU.js +0 -2940
  559. package/dist/chrome-DPwFYi-g.js +0 -1517
  560. package/dist/cli-compaction-YZpssARf.js +0 -363
  561. package/dist/cli-runner-D2OAqxu3.js +0 -597
  562. package/dist/cli-runner-DO4SORQf.js +0 -2
  563. package/dist/cli-runner.runtime-CNSIpbeT.js +0 -4
  564. package/dist/cli-runner.runtime-DAOYvpVQ.js +0 -3
  565. package/dist/command-registry-DpD0fb8D.js +0 -4
  566. package/dist/command-registry-core-Cl3tLG8G.js +0 -114
  567. package/dist/command-registry-nbP7c8RT.js +0 -9
  568. package/dist/command-status.runtime-BBuXTkq0.js +0 -90
  569. package/dist/commands-CR8MVvlD.d.ts +0 -117
  570. package/dist/commands-compact.runtime-BoafIjjg.js +0 -10
  571. package/dist/commands-handlers.runtime-D9jViG_x.js +0 -6327
  572. package/dist/commands-status-BqqJ7PVq.js +0 -16
  573. package/dist/commands-status-CMd41Vxf.js +0 -3
  574. package/dist/commands-status.runtime-CMd41Vxf.js +0 -3
  575. package/dist/commands-subagents-control.runtime-CU4I3A_n.js +0 -2
  576. package/dist/commands-system-prompt-CTtu1D3-.js +0 -2
  577. package/dist/commands-system-prompt-xswhORdM.js +0 -161
  578. package/dist/commands-types-B67CsqXf.d.ts +0 -132
  579. package/dist/commands.runtime-BUFhkrjQ.js +0 -175
  580. package/dist/compact-Dz_WvRkQ.js +0 -1165
  581. package/dist/compact.runtime-n-AKErni.js +0 -12
  582. package/dist/completion-cli-DJYs_L4_.js +0 -393
  583. package/dist/config-CFMbHJb0.js +0 -374
  584. package/dist/config-mutations-DCAloTKR.js +0 -161
  585. package/dist/config-schema-Drw1zrnG.d.ts +0 -20
  586. package/dist/context-engine-host-compat-4mNm1HCE.js +0 -2
  587. package/dist/context-engine-host-compat-BzJ7fUIn.js +0 -280
  588. package/dist/context-engine-lifecycle-V4PNQp6k.js +0 -627
  589. package/dist/control-auth-DG_cw-aN.js +0 -114
  590. package/dist/control-service-CurYipgK.js +0 -3
  591. package/dist/control-service-VyncoV7j.js +0 -40
  592. package/dist/control-ui/assets/activity-D5Plhlo-.js +0 -124
  593. package/dist/control-ui/assets/agents-Chcdfe1E.js +0 -1030
  594. package/dist/control-ui/assets/channels-BEtB4H37.js +0 -120
  595. package/dist/control-ui/assets/cron-CZyPkxSU.js +0 -1016
  596. package/dist/control-ui/assets/debug-DvM8iG47.js +0 -97
  597. package/dist/control-ui/assets/index-Rmpgh0f1.js +0 -7214
  598. package/dist/control-ui/assets/instances-yTC_uu60.js +0 -57
  599. package/dist/control-ui/assets/nodes-vbAxVHIH.js +0 -444
  600. package/dist/control-ui/assets/sessions-DOviHme5.js +0 -425
  601. package/dist/control-ui/assets/skills-Bfp5HEGW.js +0 -362
  602. package/dist/control-ui/assets/workboard-5sU2kHsV.js +0 -402
  603. package/dist/conversation-runtime-DgaABwHh.js +0 -31
  604. package/dist/core-BeBXdneV.js +0 -284
  605. package/dist/core-Chqb7X6l.d.ts +0 -223
  606. package/dist/core-api-BlK0FgBM.js +0 -2
  607. package/dist/core-api-pAvYk716.js +0 -5
  608. package/dist/crestodian-FeGTBqO1.js +0 -55
  609. package/dist/delegate-BjIjSU_E.d.ts +0 -30
  610. package/dist/deliver-CvtWN4Ey.d.ts +0 -111
  611. package/dist/delivery-queue-CQ-cj3KG.d.ts +0 -161
  612. package/dist/delivery-queue-runtime-ut7MG04m.d.ts +0 -9
  613. package/dist/detect-BjXPyrwn.js +0 -115
  614. package/dist/detect-C1xeIemQ.d.ts +0 -16
  615. package/dist/dialogue-BowVYhEC.js +0 -37
  616. package/dist/direct-dm-DoZZHpA0.d.ts +0 -79
  617. package/dist/directive-handling.fast-lane-hnmQ_CvD.js +0 -70
  618. package/dist/directive-handling.impl-Cai-CFS1.js +0 -2
  619. package/dist/directive-handling.impl-DY84qIfU.js +0 -823
  620. package/dist/directive-handling.model-selection-DASssLFQ.js +0 -122
  621. package/dist/directive-handling.persist.runtime-BY7tJUs2.js +0 -274
  622. package/dist/dispatch-D5iG5A8j.js +0 -2057
  623. package/dist/dispatch-acp-transcript.runtime-D3r16hbD.js +0 -40
  624. package/dist/dispatch-acp.runtime-CAIau5qX.js +0 -18
  625. package/dist/dispatcher-7-d2gw3J.js +0 -106
  626. package/dist/doctor-DD5YEMmf.js +0 -6
  627. package/dist/doctor-config-flow-CdlLHJmX.js +0 -1819
  628. package/dist/doctor-core-checks-6MP99TQG.js +0 -666
  629. package/dist/doctor-core-checks-Dm_o576z.js +0 -2
  630. package/dist/doctor-core-checks.runtime-B2qbKATd.js +0 -278
  631. package/dist/doctor-health-BKrhOv1v.js +0 -65
  632. package/dist/doctor-health-contributions-bIBLmw69.js +0 -874
  633. package/dist/doctor-lint-aOLOWli4.js +0 -95
  634. package/dist/doctor-state-integrity-23NQNNuo.js +0 -1257
  635. package/dist/draft-stream-controls-Bk1GVJ1l.d.ts +0 -159
  636. package/dist/embedded-agent-BeK8FhZr.d.ts +0 -5
  637. package/dist/embedded-agent-CNp_y7jW.js +0 -4074
  638. package/dist/embedded-agent-NEmNlXDR.js +0 -4
  639. package/dist/embedded-agent.runtime-hEby8P2s.js +0 -4
  640. package/dist/embedded-backend-BdbgfpBP.js +0 -1581
  641. package/dist/embedded-gateway-stub.runtime-ySZUA3Gy.js +0 -12
  642. package/dist/extensions/alibaba/fengming.plugin.json +0 -47
  643. package/dist/extensions/alibaba/index.d.ts +0 -12
  644. package/dist/extensions/alibaba/index.js +0 -13
  645. package/dist/extensions/alibaba/package.json +0 -15
  646. package/dist/extensions/alibaba/video-generation-provider.d.ts +0 -6
  647. package/dist/extensions/alibaba/video-generation-provider.js +0 -2
  648. package/dist/extensions/baichuan/fengming.plugin.json +0 -69
  649. package/dist/extensions/baichuan/index.d.ts +0 -11
  650. package/dist/extensions/baichuan/index.js +0 -45
  651. package/dist/extensions/baichuan/models.d.ts +0 -7
  652. package/dist/extensions/baichuan/models.js +0 -2
  653. package/dist/extensions/baichuan/onboard.d.ts +0 -5
  654. package/dist/extensions/baichuan/onboard.js +0 -2
  655. package/dist/extensions/baichuan/package.json +0 -15
  656. package/dist/extensions/baichuan/provider-catalog.d.ts +0 -2
  657. package/dist/extensions/baichuan/provider-catalog.js +0 -2
  658. package/dist/extensions/baichuan/provider-discovery.d.ts +0 -2
  659. package/dist/extensions/baichuan/provider-discovery.js +0 -5
  660. package/dist/extensions/byteplus/api.d.ts +0 -3
  661. package/dist/extensions/byteplus/api.js +0 -3
  662. package/dist/extensions/byteplus/fengming.plugin.json +0 -196
  663. package/dist/extensions/byteplus/index.d.ts +0 -12
  664. package/dist/extensions/byteplus/index.js +0 -85
  665. package/dist/extensions/byteplus/models.d.ts +0 -2
  666. package/dist/extensions/byteplus/models.js +0 -2
  667. package/dist/extensions/byteplus/package.json +0 -15
  668. package/dist/extensions/byteplus/provider-catalog.d.ts +0 -2
  669. package/dist/extensions/byteplus/provider-catalog.js +0 -2
  670. package/dist/extensions/byteplus/provider-discovery.d.ts +0 -5
  671. package/dist/extensions/byteplus/provider-discovery.js +0 -23
  672. package/dist/extensions/byteplus/video-generation-provider.d.ts +0 -6
  673. package/dist/extensions/byteplus/video-generation-provider.js +0 -2
  674. package/dist/extensions/longcat/fengming.plugin.json +0 -84
  675. package/dist/extensions/longcat/index.d.ts +0 -11
  676. package/dist/extensions/longcat/index.js +0 -45
  677. package/dist/extensions/longcat/models.d.ts +0 -7
  678. package/dist/extensions/longcat/models.js +0 -2
  679. package/dist/extensions/longcat/onboard.d.ts +0 -5
  680. package/dist/extensions/longcat/onboard.js +0 -2
  681. package/dist/extensions/longcat/package.json +0 -15
  682. package/dist/extensions/longcat/provider-catalog.d.ts +0 -2
  683. package/dist/extensions/longcat/provider-catalog.js +0 -2
  684. package/dist/extensions/longcat/provider-discovery.d.ts +0 -2
  685. package/dist/extensions/longcat/provider-discovery.js +0 -5
  686. package/dist/extensions/minimax/api.d.ts +0 -5
  687. package/dist/extensions/minimax/api.js +0 -6
  688. package/dist/extensions/minimax/fengming.plugin.json +0 -206
  689. package/dist/extensions/minimax/image-generation-provider.d.ts +0 -6
  690. package/dist/extensions/minimax/image-generation-provider.js +0 -2
  691. package/dist/extensions/minimax/index.d.ts +0 -12
  692. package/dist/extensions/minimax/index.js +0 -29
  693. package/dist/extensions/minimax/media-understanding-provider.d.ts +0 -6
  694. package/dist/extensions/minimax/media-understanding-provider.js +0 -2
  695. package/dist/extensions/minimax/model-definitions.d.ts +0 -2
  696. package/dist/extensions/minimax/model-definitions.js +0 -2
  697. package/dist/extensions/minimax/music-generation-provider.d.ts +0 -6
  698. package/dist/extensions/minimax/music-generation-provider.js +0 -2
  699. package/dist/extensions/minimax/oauth.d.ts +0 -2
  700. package/dist/extensions/minimax/oauth.js +0 -2
  701. package/dist/extensions/minimax/oauth.runtime.d.ts +0 -2
  702. package/dist/extensions/minimax/oauth.runtime.js +0 -2
  703. package/dist/extensions/minimax/onboard.d.ts +0 -2
  704. package/dist/extensions/minimax/onboard.js +0 -2
  705. package/dist/extensions/minimax/package.json +0 -15
  706. package/dist/extensions/minimax/provider-catalog.d.ts +0 -2
  707. package/dist/extensions/minimax/provider-catalog.js +0 -2
  708. package/dist/extensions/minimax/provider-contract-api.d.ts +0 -6
  709. package/dist/extensions/minimax/provider-contract-api.js +0 -77
  710. package/dist/extensions/minimax/provider-discovery.d.ts +0 -5
  711. package/dist/extensions/minimax/provider-discovery.js +0 -23
  712. package/dist/extensions/minimax/provider-models.d.ts +0 -2
  713. package/dist/extensions/minimax/provider-models.js +0 -2
  714. package/dist/extensions/minimax/provider-registration.d.ts +0 -7
  715. package/dist/extensions/minimax/provider-registration.js +0 -2
  716. package/dist/extensions/minimax/speech-provider.d.ts +0 -5
  717. package/dist/extensions/minimax/speech-provider.js +0 -2
  718. package/dist/extensions/minimax/tts.d.ts +0 -20
  719. package/dist/extensions/minimax/tts.js +0 -2
  720. package/dist/extensions/minimax/video-generation-provider.d.ts +0 -7
  721. package/dist/extensions/minimax/video-generation-provider.js +0 -2
  722. package/dist/extensions/minimax/web-search-contract-api.d.ts +0 -5
  723. package/dist/extensions/minimax/web-search-contract-api.js +0 -31
  724. package/dist/extensions/minimax/web-search-provider.d.ts +0 -5
  725. package/dist/extensions/minimax/web-search-provider.js +0 -2
  726. package/dist/extensions/moonshot/api.d.ts +0 -3
  727. package/dist/extensions/moonshot/api.js +0 -4
  728. package/dist/extensions/moonshot/fengming.plugin.json +0 -250
  729. package/dist/extensions/moonshot/index.d.ts +0 -11
  730. package/dist/extensions/moonshot/index.js +0 -70
  731. package/dist/extensions/moonshot/media-understanding-provider.d.ts +0 -6
  732. package/dist/extensions/moonshot/media-understanding-provider.js +0 -2
  733. package/dist/extensions/moonshot/onboard.d.ts +0 -2
  734. package/dist/extensions/moonshot/onboard.js +0 -2
  735. package/dist/extensions/moonshot/package.json +0 -15
  736. package/dist/extensions/moonshot/provider-catalog.d.ts +0 -2
  737. package/dist/extensions/moonshot/provider-catalog.js +0 -2
  738. package/dist/extensions/moonshot/provider-contract-api.d.ts +0 -5
  739. package/dist/extensions/moonshot/provider-contract-api.js +0 -27
  740. package/dist/extensions/moonshot/provider-discovery.d.ts +0 -5
  741. package/dist/extensions/moonshot/provider-discovery.js +0 -15
  742. package/dist/extensions/moonshot/web-search-contract-api.d.ts +0 -5
  743. package/dist/extensions/moonshot/web-search-contract-api.js +0 -29
  744. package/dist/extensions/moonshot/web-search-provider.d.ts +0 -5
  745. package/dist/extensions/moonshot/web-search-provider.js +0 -2
  746. package/dist/extensions/qianfan/api.d.ts +0 -3
  747. package/dist/extensions/qianfan/api.js +0 -3
  748. package/dist/extensions/qianfan/fengming.plugin.json +0 -89
  749. package/dist/extensions/qianfan/index.d.ts +0 -11
  750. package/dist/extensions/qianfan/index.js +0 -26
  751. package/dist/extensions/qianfan/onboard.d.ts +0 -2
  752. package/dist/extensions/qianfan/onboard.js +0 -2
  753. package/dist/extensions/qianfan/package.json +0 -15
  754. package/dist/extensions/qianfan/provider-catalog.d.ts +0 -2
  755. package/dist/extensions/qianfan/provider-catalog.js +0 -2
  756. package/dist/extensions/qwen/api.d.ts +0 -4
  757. package/dist/extensions/qwen/api.js +0 -5
  758. package/dist/extensions/qwen/fengming.plugin.json +0 -389
  759. package/dist/extensions/qwen/index.d.ts +0 -11
  760. package/dist/extensions/qwen/index.js +0 -202
  761. package/dist/extensions/qwen/media-understanding-provider.d.ts +0 -6
  762. package/dist/extensions/qwen/media-understanding-provider.js +0 -2
  763. package/dist/extensions/qwen/model-definitions.d.ts +0 -2
  764. package/dist/extensions/qwen/model-definitions.js +0 -2
  765. package/dist/extensions/qwen/models.d.ts +0 -2
  766. package/dist/extensions/qwen/models.js +0 -2
  767. package/dist/extensions/qwen/onboard.d.ts +0 -21
  768. package/dist/extensions/qwen/onboard.js +0 -2
  769. package/dist/extensions/qwen/package.json +0 -15
  770. package/dist/extensions/qwen/provider-catalog.d.ts +0 -2
  771. package/dist/extensions/qwen/provider-catalog.js +0 -2
  772. package/dist/extensions/qwen/stream.d.ts +0 -2
  773. package/dist/extensions/qwen/stream.js +0 -2
  774. package/dist/extensions/qwen/video-generation-provider.d.ts +0 -6
  775. package/dist/extensions/qwen/video-generation-provider.js +0 -2
  776. package/dist/extensions/sensenova/fengming.plugin.json +0 -69
  777. package/dist/extensions/sensenova/index.d.ts +0 -11
  778. package/dist/extensions/sensenova/index.js +0 -45
  779. package/dist/extensions/sensenova/models.d.ts +0 -7
  780. package/dist/extensions/sensenova/models.js +0 -2
  781. package/dist/extensions/sensenova/onboard.d.ts +0 -5
  782. package/dist/extensions/sensenova/onboard.js +0 -2
  783. package/dist/extensions/sensenova/package.json +0 -15
  784. package/dist/extensions/sensenova/provider-catalog.d.ts +0 -2
  785. package/dist/extensions/sensenova/provider-catalog.js +0 -2
  786. package/dist/extensions/sensenova/provider-discovery.d.ts +0 -2
  787. package/dist/extensions/sensenova/provider-discovery.js +0 -5
  788. package/dist/extensions/stepfun/fengming.plugin.json +0 -162
  789. package/dist/extensions/stepfun/index.d.ts +0 -12
  790. package/dist/extensions/stepfun/index.js +0 -165
  791. package/dist/extensions/stepfun/onboard.d.ts +0 -7
  792. package/dist/extensions/stepfun/onboard.js +0 -2
  793. package/dist/extensions/stepfun/package.json +0 -15
  794. package/dist/extensions/stepfun/provider-catalog.d.ts +0 -14
  795. package/dist/extensions/stepfun/provider-catalog.js +0 -2
  796. package/dist/extensions/tencent/api.d.ts +0 -3
  797. package/dist/extensions/tencent/api.js +0 -4
  798. package/dist/extensions/tencent/fengming.plugin.json +0 -105
  799. package/dist/extensions/tencent/index.d.ts +0 -12
  800. package/dist/extensions/tencent/index.js +0 -62
  801. package/dist/extensions/tencent/models.d.ts +0 -2
  802. package/dist/extensions/tencent/models.js +0 -2
  803. package/dist/extensions/tencent/onboard.d.ts +0 -6
  804. package/dist/extensions/tencent/onboard.js +0 -2
  805. package/dist/extensions/tencent/package.json +0 -15
  806. package/dist/extensions/tencent/provider-catalog.d.ts +0 -2
  807. package/dist/extensions/tencent/provider-catalog.js +0 -2
  808. package/dist/extensions/tencent/provider-discovery.d.ts +0 -5
  809. package/dist/extensions/tencent/provider-discovery.js +0 -14
  810. package/dist/extensions/tiangong/fengming.plugin.json +0 -69
  811. package/dist/extensions/tiangong/index.d.ts +0 -11
  812. package/dist/extensions/tiangong/index.js +0 -45
  813. package/dist/extensions/tiangong/models.d.ts +0 -7
  814. package/dist/extensions/tiangong/models.js +0 -2
  815. package/dist/extensions/tiangong/onboard.d.ts +0 -5
  816. package/dist/extensions/tiangong/onboard.js +0 -2
  817. package/dist/extensions/tiangong/package.json +0 -15
  818. package/dist/extensions/tiangong/provider-catalog.d.ts +0 -2
  819. package/dist/extensions/tiangong/provider-catalog.js +0 -2
  820. package/dist/extensions/tiangong/provider-discovery.d.ts +0 -2
  821. package/dist/extensions/tiangong/provider-discovery.js +0 -5
  822. package/dist/extensions/volcengine/api.d.ts +0 -12
  823. package/dist/extensions/volcengine/api.js +0 -4
  824. package/dist/extensions/volcengine/fengming.plugin.json +0 -263
  825. package/dist/extensions/volcengine/index.d.ts +0 -12
  826. package/dist/extensions/volcengine/index.js +0 -88
  827. package/dist/extensions/volcengine/models.d.ts +0 -2
  828. package/dist/extensions/volcengine/models.js +0 -2
  829. package/dist/extensions/volcengine/package.json +0 -15
  830. package/dist/extensions/volcengine/provider-catalog.d.ts +0 -2
  831. package/dist/extensions/volcengine/provider-catalog.js +0 -2
  832. package/dist/extensions/volcengine/provider-discovery.d.ts +0 -5
  833. package/dist/extensions/volcengine/provider-discovery.js +0 -23
  834. package/dist/extensions/volcengine/speech-provider.d.ts +0 -5
  835. package/dist/extensions/volcengine/speech-provider.js +0 -2
  836. package/dist/extensions/volcengine/tts.d.ts +0 -22
  837. package/dist/extensions/volcengine/tts.js +0 -2
  838. package/dist/extensions/weixin/fengming.plugin.json +0 -22
  839. package/dist/extensions/weixin/index.d.ts +0 -26
  840. package/dist/extensions/weixin/index.js +0 -862
  841. package/dist/extensions/weixin/package.json +0 -45
  842. package/dist/extensions/xiaomi/api.d.ts +0 -3
  843. package/dist/extensions/xiaomi/api.js +0 -3
  844. package/dist/extensions/xiaomi/fengming.plugin.json +0 -260
  845. package/dist/extensions/xiaomi/index.d.ts +0 -12
  846. package/dist/extensions/xiaomi/index.js +0 -284
  847. package/dist/extensions/xiaomi/onboard.d.ts +0 -2
  848. package/dist/extensions/xiaomi/onboard.js +0 -2
  849. package/dist/extensions/xiaomi/package.json +0 -15
  850. package/dist/extensions/xiaomi/provider-catalog.d.ts +0 -2
  851. package/dist/extensions/xiaomi/provider-catalog.js +0 -2
  852. package/dist/extensions/xiaomi/speech-provider.d.ts +0 -5
  853. package/dist/extensions/xiaomi/speech-provider.js +0 -2
  854. package/dist/extensions/xiaomi/stream.d.ts +0 -5
  855. package/dist/extensions/xiaomi/stream.js +0 -2
  856. package/dist/extensions/xiaomi/thinking.d.ts +0 -11
  857. package/dist/extensions/xiaomi/thinking.js +0 -2
  858. package/dist/extensions/xingchen/fengming.plugin.json +0 -69
  859. package/dist/extensions/xingchen/index.d.ts +0 -11
  860. package/dist/extensions/xingchen/index.js +0 -45
  861. package/dist/extensions/xingchen/models.d.ts +0 -7
  862. package/dist/extensions/xingchen/models.js +0 -2
  863. package/dist/extensions/xingchen/onboard.d.ts +0 -5
  864. package/dist/extensions/xingchen/onboard.js +0 -2
  865. package/dist/extensions/xingchen/package.json +0 -15
  866. package/dist/extensions/xingchen/provider-catalog.d.ts +0 -2
  867. package/dist/extensions/xingchen/provider-catalog.js +0 -2
  868. package/dist/extensions/xingchen/provider-discovery.d.ts +0 -2
  869. package/dist/extensions/xingchen/provider-discovery.js +0 -5
  870. package/dist/extensions/yi/fengming.plugin.json +0 -84
  871. package/dist/extensions/yi/index.d.ts +0 -11
  872. package/dist/extensions/yi/index.js +0 -45
  873. package/dist/extensions/yi/models.d.ts +0 -7
  874. package/dist/extensions/yi/models.js +0 -2
  875. package/dist/extensions/yi/onboard.d.ts +0 -5
  876. package/dist/extensions/yi/onboard.js +0 -2
  877. package/dist/extensions/yi/package.json +0 -15
  878. package/dist/extensions/yi/provider-catalog.d.ts +0 -2
  879. package/dist/extensions/yi/provider-catalog.js +0 -2
  880. package/dist/extensions/yi/provider-discovery.d.ts +0 -2
  881. package/dist/extensions/yi/provider-discovery.js +0 -5
  882. package/dist/extensions/zai/api.d.ts +0 -4
  883. package/dist/extensions/zai/api.js +0 -4
  884. package/dist/extensions/zai/detect.d.ts +0 -2
  885. package/dist/extensions/zai/detect.js +0 -2
  886. package/dist/extensions/zai/fengming.plugin.json +0 -377
  887. package/dist/extensions/zai/index.d.ts +0 -12
  888. package/dist/extensions/zai/index.js +0 -297
  889. package/dist/extensions/zai/media-understanding-provider.d.ts +0 -5
  890. package/dist/extensions/zai/media-understanding-provider.js +0 -2
  891. package/dist/extensions/zai/model-definitions.d.ts +0 -2
  892. package/dist/extensions/zai/model-definitions.js +0 -2
  893. package/dist/extensions/zai/onboard.d.ts +0 -2
  894. package/dist/extensions/zai/onboard.js +0 -2
  895. package/dist/extensions/zai/package.json +0 -15
  896. package/dist/extensions/zai/runtime-api.d.ts +0 -2
  897. package/dist/extensions/zai/runtime-api.js +0 -2
  898. package/dist/extensions/zhinao/fengming.plugin.json +0 -69
  899. package/dist/extensions/zhinao/index.d.ts +0 -11
  900. package/dist/extensions/zhinao/index.js +0 -45
  901. package/dist/extensions/zhinao/models.d.ts +0 -7
  902. package/dist/extensions/zhinao/models.js +0 -2
  903. package/dist/extensions/zhinao/onboard.d.ts +0 -5
  904. package/dist/extensions/zhinao/onboard.js +0 -2
  905. package/dist/extensions/zhinao/package.json +0 -15
  906. package/dist/extensions/zhinao/provider-catalog.d.ts +0 -2
  907. package/dist/extensions/zhinao/provider-catalog.js +0 -2
  908. package/dist/extensions/zhinao/provider-discovery.d.ts +0 -2
  909. package/dist/extensions/zhinao/provider-discovery.js +0 -5
  910. package/dist/fengming-runtime-0jdu_329.d.ts +0 -153
  911. package/dist/fengming-tools-gQkwsWYz.js +0 -12221
  912. package/dist/fengming.plugin-C-Kdi1_5.js +0 -130
  913. package/dist/fengming.plugin-CRPqMj85.js +0 -166
  914. package/dist/gateway-cli-BV1V43-D.js +0 -443
  915. package/dist/gateway-method-runtime-J2OPP_oH.js +0 -21
  916. package/dist/get-reply-BE8ZGJos.js +0 -5198
  917. package/dist/get-reply-from-config.runtime-C5wfxVI_.js +0 -2
  918. package/dist/heartbeat-runner-_0HlObMb.js +0 -5
  919. package/dist/heartbeat-runner.runtime-DvYz_4Z3.js +0 -3
  920. package/dist/hook-runtime-BH9moP5T.js +0 -4
  921. package/dist/hooks-icCwsmrQ.js +0 -536
  922. package/dist/host-compat-dfJvEfe7.d.ts +0 -21
  923. package/dist/http-registry-Buj7R-F_.d.ts +0 -23
  924. package/dist/image-generation-provider-hrRXkkGc.js +0 -152
  925. package/dist/inbound-reply-dispatch-5AYt56Yt.js +0 -147
  926. package/dist/inbound-reply-dispatch-B5weFW8i.js +0 -2
  927. package/dist/inbound-reply-dispatch-cJh4H31y.d.ts +0 -156
  928. package/dist/infra-runtime-3_0R8nmO.js +0 -32
  929. package/dist/init-BnfkYG_k.js +0 -59
  930. package/dist/interactive-V8NfYsTW.d.ts +0 -26
  931. package/dist/isolated-agent-CgH7dfOj.js +0 -1097
  932. package/dist/isolated-agent-dBWkiw0a.js +0 -2
  933. package/dist/kernel-Ds2aqAJF.d.ts +0 -241
  934. package/dist/kimi-web-search-provider-QJT3Ftj3.js +0 -80
  935. package/dist/kimi-web-search-provider.runtime-Dj3SS4T5.js +0 -307
  936. package/dist/kimi-web-search-provider.runtime.js +0 -1
  937. package/dist/lib-Dg4yjNFQ.js +0 -871
  938. package/dist/lifecycle-B9k7QGsS.js +0 -570
  939. package/dist/list.probe-CbVHFNwf.js +0 -2
  940. package/dist/list.probe-CxiEBmyW.js +0 -451
  941. package/dist/list.status-command-DE-edGgB.js +0 -815
  942. package/dist/llm-slug-generator-DJgq9eFd.js +0 -78
  943. package/dist/loader-5AqYM9PC.d.ts +0 -142
  944. package/dist/local-dispatch.runtime-D3F4v51B.js +0 -10
  945. package/dist/manager-BWf1ks-Z.d.ts +0 -409
  946. package/dist/mcp-http-DU7Nsg4P.js +0 -583
  947. package/dist/mcp-http-iZCW6Cet.js +0 -2
  948. package/dist/media-runtime-DZ5RpQN7.d.ts +0 -261
  949. package/dist/media-understanding-DEdEyoQB.d.ts +0 -46
  950. package/dist/media-understanding-provider-4JHrQOUE.js +0 -70
  951. package/dist/media-understanding-provider-BV7O82XV.js +0 -29
  952. package/dist/media-understanding-provider-BlPRhYkx.js +0 -69
  953. package/dist/media-understanding-provider-BuX8eQLj.js +0 -13
  954. package/dist/memory-core-host-engine-embeddings-BDu5fx8E.d.ts +0 -324
  955. package/dist/memory-core-host-engine-storage-CdCuH-E2.d.ts +0 -54
  956. package/dist/message-handler-L6QLWNVP.js +0 -1806
  957. package/dist/minimax-web-search-provider-_gxeEOy8.js +0 -58
  958. package/dist/minimax-web-search-provider.runtime-BF4mGi6U.js +0 -148
  959. package/dist/minimax-web-search-provider.runtime.js +0 -1
  960. package/dist/model-catalog-DCnRkX8f.d.ts +0 -88
  961. package/dist/model-definitions-B2gY43hI.d.ts +0 -34
  962. package/dist/model-definitions-BLOyeH5h.js +0 -73
  963. package/dist/model-definitions-CoByf5mT.js +0 -243
  964. package/dist/model-definitions-WP3OmzbS.d.ts +0 -57
  965. package/dist/model-selection-DhTE6GZD.js +0 -352
  966. package/dist/models--iAR9QkZ.js +0 -175
  967. package/dist/models-8ImVEkvh.js +0 -36
  968. package/dist/models-BIDM8htk.js +0 -48
  969. package/dist/models-BRgRfrcS.js +0 -36
  970. package/dist/models-Bib5-APc.js +0 -67
  971. package/dist/models-Bl67zOoe.js +0 -36
  972. package/dist/models-BqDDYFE3.d.ts +0 -65
  973. package/dist/models-BtRQoRIu.js +0 -36
  974. package/dist/models-BvXmOXik.js +0 -48
  975. package/dist/models-C-sJciOD.d.ts +0 -9
  976. package/dist/models-COnXPdlL.js +0 -24
  977. package/dist/models-CXTmk-Da.d.ts +0 -8
  978. package/dist/models-Cz0C_8re.js +0 -36
  979. package/dist/models-DbwEIt-m.d.ts +0 -15
  980. package/dist/models-DgXkSADi.js +0 -30
  981. package/dist/models-cli-Bv3y3JgQ.js +0 -257
  982. package/dist/monitor-BiVOsbbN.js +0 -1024
  983. package/dist/monitor-BumfRp1t.js +0 -60
  984. package/dist/monitor.account-Cd6EwtuZ.js +0 -5382
  985. package/dist/music-generation-provider-ZdDMiC-c.js +0 -308
  986. package/dist/nodes-C0f8XgD5.js +0 -1483
  987. package/dist/nodes-Dk4vOgg9.js +0 -3
  988. package/dist/nodes-pending-Cjg09MXz.js +0 -211
  989. package/dist/oauth-BIO69Qw0.d.ts +0 -25
  990. package/dist/oauth-CnO10TN2.js +0 -207
  991. package/dist/onboard-B3BYT5k7.js +0 -34
  992. package/dist/onboard-BDMNV6RE.js +0 -23
  993. package/dist/onboard-B_WNNy5F.d.ts +0 -6
  994. package/dist/onboard-BbyMaErU.js +0 -69
  995. package/dist/onboard-BuYPNE6j2.js +0 -23
  996. package/dist/onboard-C394zMnM.d.ts +0 -11
  997. package/dist/onboard-CHn4oVbY.js +0 -24
  998. package/dist/onboard-CPpVbb0O.js +0 -73
  999. package/dist/onboard-CWDx7Crt.js +0 -23
  1000. package/dist/onboard-CbzkwBzu.d.ts +0 -12
  1001. package/dist/onboard-D099qUd0.js +0 -23
  1002. package/dist/onboard-D7dbzfHc.js +0 -23
  1003. package/dist/onboard-DB-x0nHF.js +0 -30
  1004. package/dist/onboard-DFVrRnxJ.js +0 -23
  1005. package/dist/onboard-DFiqoOc2.d.ts +0 -7
  1006. package/dist/onboard-DJaMK3rr.d.ts +0 -6
  1007. package/dist/onboard-DMdK8D_h.js +0 -67
  1008. package/dist/onboard-J-KL-I6m.js +0 -48
  1009. package/dist/onboard-MIBU-Rmv.js +0 -39
  1010. package/dist/onboard-vmGylfFe.js +0 -23
  1011. package/dist/openai-compat-errors-Dcr5Y8bF.js +0 -136
  1012. package/dist/openai-http-CcqspzU6.js +0 -836
  1013. package/dist/openresponses-http-BnyYYvUF.js +0 -1175
  1014. package/dist/operations-H2Oq0KYz.js +0 -805
  1015. package/dist/outbound.types-BhRehecY.d.ts +0 -291
  1016. package/dist/plugin-enabled-CEIKWKrq.js +0 -232
  1017. package/dist/plugin-entry-CTVRRaaA.d.ts +0 -47
  1018. package/dist/plugin-registration-BTyO5Fwt.js +0 -97
  1019. package/dist/plugin-runtime-_XF2N_UQ.d.ts +0 -117
  1020. package/dist/plugin-sdk/bundled-channel-config-schema-BsOWCrJT.d.ts +0 -3169
  1021. package/dist/plugin-service-B91jVlmZ.d.ts +0 -24
  1022. package/dist/plugin-service-CtGwVz8V.js +0 -1249
  1023. package/dist/prepare.runtime-9dlboph7.js +0 -798
  1024. package/dist/preview-warnings-DJx4KJpC.js +0 -618
  1025. package/dist/program-CWC-NBBB.js +0 -131
  1026. package/dist/provider-api-key-auth-BmNcYRMl.d.ts +0 -27
  1027. package/dist/provider-auth-api-key-CCaFiqY3.js +0 -5
  1028. package/dist/provider-auth-result-D_E9dcVc.d.ts +0 -21
  1029. package/dist/provider-catalog-5KZLmrDO.js +0 -11
  1030. package/dist/provider-catalog-7P6AvDzS.js +0 -11
  1031. package/dist/provider-catalog-B2gyTjTU.js +0 -88
  1032. package/dist/provider-catalog-B3YBhe77.js +0 -17
  1033. package/dist/provider-catalog-B7XEeuUm.js +0 -11
  1034. package/dist/provider-catalog-BFGPRd9v.js +0 -17
  1035. package/dist/provider-catalog-BLvkIMSk.d.ts +0 -6
  1036. package/dist/provider-catalog-BPBL9mJf.d.ts +0 -5
  1037. package/dist/provider-catalog-BRkZ6-HD.d.ts +0 -5
  1038. package/dist/provider-catalog-Bfl_AoTZ.js +0 -142
  1039. package/dist/provider-catalog-BpiHWHu1.js +0 -11
  1040. package/dist/provider-catalog-C1qDLekT.d.ts +0 -5
  1041. package/dist/provider-catalog-CKWNCfry.js +0 -11
  1042. package/dist/provider-catalog-CUHB2pSt.d.ts +0 -7
  1043. package/dist/provider-catalog-CWqN2j6J.d.ts +0 -5
  1044. package/dist/provider-catalog-CZ8oYbx3.js +0 -11
  1045. package/dist/provider-catalog-CcQ5-4ZW.d.ts +0 -6
  1046. package/dist/provider-catalog-Cd16uZ0U.js +0 -20
  1047. package/dist/provider-catalog-CpF2D0VK.js +0 -61
  1048. package/dist/provider-catalog-CvXq36zW.d.ts +0 -5
  1049. package/dist/provider-catalog-D2pgEME3.js +0 -48
  1050. package/dist/provider-catalog-DPzcupEl.d.ts +0 -5
  1051. package/dist/provider-catalog-DaeI606G.d.ts +0 -9
  1052. package/dist/provider-catalog-DrOCtTb-.js +0 -11
  1053. package/dist/provider-catalog-DwZ1J2Al.d.ts +0 -6
  1054. package/dist/provider-catalog-Dy7IcHmS.js +0 -107
  1055. package/dist/provider-catalog-TsZS52nq.d.ts +0 -10
  1056. package/dist/provider-catalog-YqIFRCND.d.ts +0 -5
  1057. package/dist/provider-catalog-Ywb5jRwG.d.ts +0 -5
  1058. package/dist/provider-catalog-evknl1oN.js +0 -11
  1059. package/dist/provider-catalog-l0hFpFO2.d.ts +0 -17
  1060. package/dist/provider-catalog-shared-DsRBv0Tp.d.ts +0 -62
  1061. package/dist/provider-dispatcher-BMy9mBJ1.js +0 -22
  1062. package/dist/provider-model-shared-CPAfQBNs.d.ts +0 -143
  1063. package/dist/provider-models-Diu65OcG.d.ts +0 -18
  1064. package/dist/provider-models-LE7PlLYY.js +0 -22
  1065. package/dist/provider-onboard-CpvXEmvz.d.ts +0 -91
  1066. package/dist/provider-registration-DF-LkmNE.js +0 -235
  1067. package/dist/provider-registry-D9cTPW1F.d.ts +0 -8
  1068. package/dist/provider-registry-DI7gMKUP.d.ts +0 -8
  1069. package/dist/provider-registry-DZtgZDkl.d.ts +0 -29
  1070. package/dist/provider-self-hosted-setup-CoHvoyKm.d.ts +0 -74
  1071. package/dist/provider-stream-BpXJr5Ap.d.ts +0 -139
  1072. package/dist/provider-stream-family-Bj5aBD8w.js +0 -2
  1073. package/dist/provider-stream-shared-BaUkhUHj.d.ts +0 -132
  1074. package/dist/provider-usage-DFUhW2do.js +0 -651
  1075. package/dist/provider-web-search-contract-fields-CkXzSsWu.d.ts +0 -25
  1076. package/dist/pw-ai-9Q_dIq4B.js +0 -3064
  1077. package/dist/register.agent-CbfrlzXB.js +0 -152
  1078. package/dist/register.crestodian-CEg0rPfK.js +0 -24
  1079. package/dist/register.maintenance-k9N8I4Wg.js +0 -85
  1080. package/dist/register.subclis-CrXOeaS3.js +0 -3
  1081. package/dist/register.subclis-DfKlni8N.js +0 -31
  1082. package/dist/register.subclis-core-Bg4wbDsO.js +0 -278
  1083. package/dist/registry-Bh3-P2HL.d.ts +0 -8
  1084. package/dist/registry-types-BmEUS4d3.d.ts +0 -392
  1085. package/dist/repair-sequencing-E4yViXG9.js +0 -652
  1086. package/dist/reply-payload-S2mrc_Mh.d.ts +0 -200
  1087. package/dist/reply-turn-admission-BBoPjmGB.js +0 -2056
  1088. package/dist/reply.runtime-C5wfxVI_.js +0 -2
  1089. package/dist/result-fallback-classifier-CX4iLD1G.js +0 -98
  1090. package/dist/route-CifxcQZ1.js +0 -475
  1091. package/dist/routes-B3XAOeWo.js +0 -2
  1092. package/dist/routes-H185h3U-.js +0 -3701
  1093. package/dist/run-CTJFbwbB.js +0 -1162
  1094. package/dist/run-command-B7B53tYk.js +0 -23
  1095. package/dist/run-command-BFuxRDxS.js +0 -2
  1096. package/dist/run-context-C7im9ICg.js +0 -66
  1097. package/dist/run-embedded.runtime-TljBTbzh.js +0 -4
  1098. package/dist/run-execution-cli.runtime-Bt5zwx1W.js +0 -4
  1099. package/dist/run-executor.runtime-hmbWX2Ct.js +0 -330
  1100. package/dist/run-subagent-registry.runtime-B70X80nS.js +0 -2
  1101. package/dist/runtime-DoKE0o7v.js +0 -436
  1102. package/dist/runtime-api-Ca4Llbgf.js +0 -12
  1103. package/dist/runtime-api-pa8xcEmg.d.ts +0 -5
  1104. package/dist/runtime-channel-CFQ59svm.js +0 -148
  1105. package/dist/runtime-channel-DRwCWGUx.js +0 -2
  1106. package/dist/runtime-embedded-agent.runtime-DwmqKUVp.js +0 -2
  1107. package/dist/runtime-forwarders-BMThPHg_.d.ts +0 -39
  1108. package/dist/sdk-setup-tools-Cg_Tabrf.js +0 -8
  1109. package/dist/selection-COhr7g82.js +0 -18365
  1110. package/dist/selection-_G44EVqd.js +0 -3
  1111. package/dist/send-media-BNc67G7I.js +0 -2072
  1112. package/dist/server-5rR0RCpI.js +0 -24
  1113. package/dist/server-context-BhiPROPA.js +0 -955
  1114. package/dist/server-context-OShBAJZQ.js +0 -2
  1115. package/dist/server-cron-Bkzb9edh.js +0 -3173
  1116. package/dist/server-cron-DdR-ugiU.js +0 -2
  1117. package/dist/server-lwtC1vaS.js +0 -72
  1118. package/dist/server-methods-BY_ZqDFJ.js +0 -497
  1119. package/dist/server-node-events-CLvE94AS.js +0 -597
  1120. package/dist/server-plugin-bootstrap-cKOAH5GL.js +0 -71
  1121. package/dist/server-plugins-CPpUykw5.js +0 -435
  1122. package/dist/server-reload-handlers-uzt4VDZ-.js +0 -719
  1123. package/dist/server-restart-sentinel-CpvV0t4O.js +0 -700
  1124. package/dist/server-runtime-services-BhOHoerM.js +0 -147
  1125. package/dist/server-runtime-services-D3Ig68nC.js +0 -3
  1126. package/dist/server-startup-plugins-DslzKVHK.js +0 -127
  1127. package/dist/server-startup-post-attach-DPFBTQez.js +0 -793
  1128. package/dist/server-ws-runtime-D0zoWoiz.js +0 -374
  1129. package/dist/server.impl-CzqLQ3qt.js +0 -2622
  1130. package/dist/session-kill-http-D8JhwZVS.js +0 -121
  1131. package/dist/session-reset-service-uoi7E4Xp.js +0 -651
  1132. package/dist/session-status.runtime-CZK5IU8w.js +0 -2
  1133. package/dist/session-subagent-reactivation.runtime-BSO00-FY.js +0 -2
  1134. package/dist/session-tab-registry-DM9U7e3o.js +0 -551
  1135. package/dist/sessions-B-SkIoaa.js +0 -1917
  1136. package/dist/sessions-history-http-DCiOG4FK.js +0 -432
  1137. package/dist/sessions-patch-DlAAvQvB.js +0 -401
  1138. package/dist/sessions-resolve-DfMXookg.js +0 -180
  1139. package/dist/sessions.runtime-0V2YxKxB.js +0 -2
  1140. package/dist/snapshot-urls-Ble1-NEW.js +0 -317
  1141. package/dist/speech-core-Bk60ZS_y.d.ts +0 -49
  1142. package/dist/speech-provider-DQO9eZd0.js +0 -233
  1143. package/dist/speech-provider-DnBCla4V.js +0 -171
  1144. package/dist/speech-provider-DyYHFxT5.js +0 -227
  1145. package/dist/standalone-9EWfcxeO.js +0 -42
  1146. package/dist/startup-context-nti4X0_w.js +0 -314
  1147. package/dist/status-subagents.runtime-CPZb1EF1.js +0 -32
  1148. package/dist/status-text-C1Hf37lF.js +0 -301
  1149. package/dist/stream-9VBt1MDs.js +0 -26
  1150. package/dist/stream-B_3P7v7P.js +0 -86
  1151. package/dist/stream-CXsue2-v.d.ts +0 -9
  1152. package/dist/stream-oNBFxfKt.d.ts +0 -5
  1153. package/dist/subagent-announce-CPjQQLy8.js +0 -353
  1154. package/dist/subagent-announce-delivery-B6iBOicL.js +0 -1369
  1155. package/dist/subagent-control-DP72sk-l.js +0 -492
  1156. package/dist/subagent-hooks-B1oUIYH3.js +0 -2
  1157. package/dist/subagent-hooks-BkGj4_xI.js +0 -230
  1158. package/dist/subagent-hooks-api-D2mulK3S.js +0 -23
  1159. package/dist/subagent-registry-CEKAUB5h.js +0 -3
  1160. package/dist/subagent-registry-OUVucPAn.js +0 -2627
  1161. package/dist/subagent-session-cleanup-Bx8d3kw0.js +0 -390
  1162. package/dist/system-CelaP2zI.js +0 -111
  1163. package/dist/talk-DGOI3Lu3.js +0 -2454
  1164. package/dist/target-id-BXRG7x9x.js +0 -107
  1165. package/dist/thinking-B8V29FhB.js +0 -35
  1166. package/dist/thread-bindings-DpVdEPZ0.js +0 -228
  1167. package/dist/tool-DHzDpxE4.js +0 -143
  1168. package/dist/tool-dispatch-ClP3Rc7g.js +0 -155
  1169. package/dist/tool-resolution-CZcLod1d.js +0 -153
  1170. package/dist/tool-split-BhiQ8676.d.ts +0 -19
  1171. package/dist/tools-ZvSvbsCW.d.ts +0 -38
  1172. package/dist/tools-effective-C2mHZT-A.js +0 -442
  1173. package/dist/tools-effective-inventory-ctnM7hc6.js +0 -379
  1174. package/dist/tools-invoke-Ci6Rux2s.js +0 -51
  1175. package/dist/tools-invoke-http-CJflXcJk.js +0 -68
  1176. package/dist/tools-invoke-shared-BLu_mJEX.js +0 -200
  1177. package/dist/tts-B2rPJPij.js +0 -83
  1178. package/dist/tts-Gp9FI3_n.js +0 -163
  1179. package/dist/tts-runtime-DNi1HXPF.d.ts +0 -230
  1180. package/dist/tui-BUhfQ9vD.js +0 -3
  1181. package/dist/tui-BhH5mvLf.js +0 -2
  1182. package/dist/tui-backend-C_4ajTHI.js +0 -257
  1183. package/dist/tui-cli-BhWJ-QoB.js +0 -40
  1184. package/dist/tui-ink-run-BTWbUQGb.js +0 -7414
  1185. package/dist/tui-ink-run-DfTdivkh.js +0 -2
  1186. package/dist/types-B4fW3r5y.d.ts +0 -111
  1187. package/dist/types-DI62NfFe.d.ts +0 -7034
  1188. package/dist/types-sAih_uQb.d.ts +0 -393
  1189. package/dist/types.public-B3MKhuo2.d.ts +0 -70
  1190. package/dist/video-generation-B9c6a5cw.js +0 -207
  1191. package/dist/video-generation-BgJp7UIA.d.ts +0 -224
  1192. package/dist/video-generation-provider-BjiVjf40.js +0 -325
  1193. package/dist/video-generation-provider-CsnQJg_h.js +0 -297
  1194. package/dist/video-generation-provider-DtU-ZPqP.js +0 -64
  1195. package/dist/video-generation-provider-wZ0bzv0e.js +0 -77
  1196. package/dist/webhook-targets-Cy8e7y3g.d.ts +0 -99
  1197. package/skills/canvas/SKILL.md +0 -78
  1198. package/skills/clawhub/SKILL.md +0 -77
  1199. package/skills/coding-agent/SKILL.md +0 -143
  1200. package/skills/diagram-maker/SKILL.md +0 -53
  1201. package/skills/diagram-maker/references/excalidraw-patterns.md +0 -85
  1202. package/skills/diagram-maker/references/svg-template.md +0 -112
  1203. package/skills/gemini/SKILL.md +0 -47
  1204. package/skills/gh-issues/SKILL.md +0 -213
  1205. package/skills/gifgrep/SKILL.md +0 -85
  1206. package/skills/github/SKILL.md +0 -84
  1207. package/skills/healthcheck/SKILL.md +0 -105
  1208. package/skills/mcporter/SKILL.md +0 -61
  1209. package/skills/meme-maker/SKILL.md +0 -42
  1210. package/skills/meme-maker/references/templates.json +0 -358
  1211. package/skills/meme-maker/scripts/meme.mjs +0 -398
  1212. package/skills/model-usage/SKILL.md +0 -71
  1213. package/skills/model-usage/references/codexbar-cli.md +0 -33
  1214. package/skills/model-usage/scripts/model_usage.py +0 -319
  1215. package/skills/model-usage/scripts/test_model_usage.py +0 -40
  1216. package/skills/nano-pdf/SKILL.md +0 -38
  1217. package/skills/node-connect/SKILL.md +0 -143
  1218. package/skills/node-inspect-debugger/SKILL.md +0 -85
  1219. package/skills/openai-whisper/SKILL.md +0 -38
  1220. package/skills/openai-whisper-api/SKILL.md +0 -71
  1221. package/skills/openai-whisper-api/scripts/transcribe.sh +0 -154
  1222. package/skills/oracle/SKILL.md +0 -126
  1223. package/skills/pyproject.toml +0 -10
  1224. package/skills/python-debugpy/SKILL.md +0 -73
  1225. package/skills/sag/SKILL.md +0 -87
  1226. package/skills/session-logs/SKILL.md +0 -151
  1227. package/skills/sherpa-onnx-tts/SKILL.md +0 -109
  1228. package/skills/sherpa-onnx-tts/bin/sherpa-onnx-tts +0 -178
  1229. package/skills/skill-creator/SKILL.md +0 -78
  1230. package/skills/skill-creator/license.txt +0 -202
  1231. package/skills/skill-creator/scripts/init_skill.py +0 -378
  1232. package/skills/skill-creator/scripts/package_skill.py +0 -139
  1233. package/skills/skill-creator/scripts/quick_validate.py +0 -169
  1234. package/skills/skill-creator/scripts/test_package_skill.py +0 -161
  1235. package/skills/skill-creator/scripts/test_quick_validate.py +0 -116
  1236. package/skills/spike/SKILL.md +0 -51
  1237. package/skills/summarize/SKILL.md +0 -87
  1238. package/skills/taskflow/SKILL.md +0 -149
  1239. package/skills/taskflow/examples/inbox-triage.lobster +0 -33
  1240. package/skills/taskflow/examples/pr-intake.lobster +0 -32
  1241. package/skills/taskflow-inbox-triage/SKILL.md +0 -119
  1242. package/skills/video-frames/SKILL.md +0 -46
  1243. package/skills/video-frames/scripts/frame.sh +0 -81
  1244. package/skills/voice-call/SKILL.md +0 -45
  1245. package/skills/weather/SKILL.md +0 -64
  1246. /package/dist/{acp-runtime-backend-DbchQ02o.js → acp-runtime-backend-DZ1Lnt7f.js} +0 -0
  1247. /package/dist/{delegate-k1aptKei.js → delegate-CwhxUdeb.js} +0 -0
  1248. /package/dist/{dispatch-acp-CD4YxPpf.js → dispatch-acp-BP4I5ZQf.js} +0 -0
  1249. /package/dist/{exec-approvals-ByWUCFQM.js → exec-approvals-ByWUCFQM2.js} +0 -0
  1250. /package/dist/{heartbeat-runner-CM0UZxa_.js → heartbeat-runner-CL3alQ8-.js} +0 -0
  1251. /package/dist/{index-B0VJdRJQ.d.ts → index-B0VJdRJQ2.d.ts} +0 -0
  1252. /package/dist/{library-CQ71yATP.js → library-CiTr_aqC.js} +0 -0
  1253. /package/dist/{run-session-state-DbDeH-q6.js → run-session-state-BOMUtBKZ.js} +0 -0
  1254. /package/dist/{session-subagent-reactivation-Bj91A2ms.js → session-subagent-reactivation-CH0C2I6Y.js} +0 -0
  1255. /package/dist/{types-C4HgagiY2.d.ts → types-C4HgagiY.d.ts} +0 -0
@@ -1,3701 +0,0 @@
1
- import { a as normalizeLowercaseStringOrEmpty, c as normalizeOptionalString$1, p as readStringValue } from "./string-coerce-DKw2K5wM.js";
2
- import { _ as parseStrictPositiveInteger, g as parseStrictNonNegativeInteger, h as parseStrictInteger, m as parseStrictFiniteNumber } from "./number-coercion-D1aDmIZp.js";
3
- import { i as formatErrorMessage } from "./errors-C_Wa6a5T.js";
4
- import { _ as uniqueStrings } from "./string-normalization-B8G0vlWE.js";
5
- import { u as pathScope } from "./fs-safe-CR_om3kX.js";
6
- import { p as resolveUserPath } from "./utils-v5zGdVpj.js";
7
- import { i as getRuntimeConfig } from "./io-T1CV3Z1L.js";
8
- import { d as isImageProcessorUnavailableError, g as resizeToJpeg, l as getImageMetadata, o as buildImageResizeSideGrid, r as IMAGE_REDUCE_QUALITY_STEPS } from "./media-services-CWbIUZDe.js";
9
- import { a as ensureMediaDir, u as saveMediaBuffer } from "./store-BCRjjjf9.js";
10
- import "./number-runtime-Cu8gqEYx.js";
11
- import "./string-coerce-runtime-BurriTLB.js";
12
- import { n as redactCdpUrl, t as parseBrowserHttpUrl } from "./browser-config-CemTZ_17.js";
13
- import { i as normalizeActBoundedNonNegativeMs, n as ACT_MAX_VIEWPORT_DIMENSION, r as ACT_MAX_WAIT_TIME_MS, t as ACT_MAX_CLICK_DELAY_MS } from "./act-policy-gF8d1KDG.js";
14
- import { C as BrowserTargetAmbiguousError, I as DEFAULT_AI_SNAPSHOT_EFFICIENT_MAX_CHARS, L as DEFAULT_AI_SNAPSHOT_MAX_CHARS, S as BrowserTabNotFoundError, T as toBrowserErrorResponse, U as DEFAULT_BROWSER_SCREENSHOT_TIMEOUT_MS, _ as BrowserError, d as withCdpSocket, f as normalizeBrowserTimerDelayMs, g as BrowserConflictError, n as assertCdpEndpointAllowed, v as BrowserProfileNotFoundError, w as BrowserValidationError, y as BrowserProfileUnavailableError } from "./cdp.helpers-DtlBcug2.js";
15
- import { a as DEFAULT_DOWNLOAD_DIR, i as resolveProfile, o as DEFAULT_TRACE_DIR, r as resolveManagedBrowserHeadlessMode, s as DEFAULT_UPLOAD_DIR } from "./config-CFMbHJb0.js";
16
- import "./errors-bTbwOddL.js";
17
- import { i as isValidProfileName, n as deleteBrowserProfileConfig, t as createBrowserProfileConfig } from "./config-mutations-DCAloTKR.js";
18
- import { r as resolveBrowserExecutableForPlatform } from "./chrome.executables-BzsaKNh7.js";
19
- import { t as movePathToTrash } from "./trash-C86kWoJK.js";
20
- import { n as normalizeString } from "./record-shared-CrsRVgBe.js";
21
- import "./sdk-setup-tools-Cg_Tabrf.js";
22
- import { D as takeChromeMcpScreenshot, O as takeChromeMcpSnapshot, S as resizeChromeMcpPage, a as closeChromeMcpTab, b as pressChromeMcpKey, d as fillChromeMcpForm, h as hoverChromeMcpElement, k as uploadChromeMcpFile, l as evaluateChromeMcpScript, n as clickChromeMcpCoords, p as getChromeMcpPid, r as clickChromeMcpElement, s as dragChromeMcpElement, u as fillChromeMcpElement, v as navigateChromeMcpPage } from "./chrome-mcp-CtHIeWEY.js";
23
- import { E as withBrowserNavigationPolicy, S as assertBrowserNavigationAllowed, _ as INTERACTIVE_ROLES, a as resolveFengMingUserDataDir, b as resolveBrowserNavigationProxyMode, g as CONTENT_ROLES, h as snapshotRoleViaCdp, m as snapshotAria, t as getChromeWebSocketUrl, u as captureScreenshot, v as STRUCTURAL_ROLES, w as assertBrowserNavigationResultAllowed, y as ensureOutputDirectory } from "./chrome-DPwFYi-g.js";
24
- import { a as shouldUsePlaywrightForAriaSnapshot, i as resolveDefaultSnapshotFormat, n as getPwAiModule$1, o as shouldUsePlaywrightForScreenshot, r as getBrowserProfileCapabilities, t as resolveTargetIdFromTabs } from "./target-id-BXRG7x9x.js";
25
- import { i as getRoleSnapshotStats, l as matchBrowserUrlPattern, s as normalizeBrowserFormField, t as appendSnapshotUrls } from "./snapshot-urls-Ble1-NEW.js";
26
- import fs from "node:fs";
27
- import path from "node:path";
28
- import crypto from "node:crypto";
29
- //#region extensions/browser/src/browser/routes/utils.ts
30
- function normalizeOptionalString(value) {
31
- return value.trim() || void 0;
32
- }
33
- function asyncBrowserRoute(handler) {
34
- return (req, res) => handler(req, res);
35
- }
36
- /**
37
- * Extract profile name from query string or body and get profile context.
38
- * Query string takes precedence over body for consistency with GET routes.
39
- */
40
- function getProfileContext(req, ctx) {
41
- let profileName;
42
- if (typeof req.query.profile === "string") profileName = normalizeOptionalString(req.query.profile);
43
- if (!profileName && req.body && typeof req.body === "object") {
44
- const body = req.body;
45
- if (typeof body.profile === "string") profileName = normalizeOptionalString(body.profile);
46
- }
47
- try {
48
- return ctx.forProfile(profileName);
49
- } catch (err) {
50
- return {
51
- error: String(err),
52
- status: 404
53
- };
54
- }
55
- }
56
- function jsonError(res, status, message) {
57
- res.status(status).json({ error: message });
58
- }
59
- function toStringOrEmpty(value) {
60
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return normalizeOptionalString(String(value)) ?? "";
61
- return "";
62
- }
63
- function toNumber(value) {
64
- if (typeof value === "number" && Number.isFinite(value)) return value;
65
- const normalized = typeof value === "string" ? normalizeOptionalString(value) : void 0;
66
- if (normalized) {
67
- const parsed = Number(normalized);
68
- return Number.isFinite(parsed) ? parsed : void 0;
69
- }
70
- }
71
- function toBoolean(value) {
72
- if (typeof value === "boolean") return value;
73
- if (typeof value !== "string" && typeof value !== "number") return;
74
- const normalized = String(value).trim().toLowerCase();
75
- if (normalized === "true" || normalized === "1" || normalized === "yes") return true;
76
- if (normalized === "false" || normalized === "0" || normalized === "no") return false;
77
- }
78
- function toStringArray(value) {
79
- if (!Array.isArray(value)) return;
80
- const strings = value.map((v) => toStringOrEmpty(v)).filter(Boolean);
81
- return strings.length ? strings : void 0;
82
- }
83
- //#endregion
84
- //#region extensions/browser/src/browser/routes/agent.shared.ts
85
- const SELECTOR_UNSUPPORTED_MESSAGE = [
86
- "Error: 'selector' is not supported. Use 'ref' from snapshot instead.",
87
- "",
88
- "Example workflow:",
89
- "1. snapshot action to get page state with refs",
90
- "2. act with ref: \"e123\" to interact with element",
91
- "",
92
- "This is more reliable for modern SPAs."
93
- ].join("\n");
94
- function readBody(req) {
95
- const body = req.body;
96
- if (!body || typeof body !== "object" || Array.isArray(body)) return {};
97
- return body;
98
- }
99
- function resolveTargetIdFromBody(body) {
100
- return (normalizeOptionalString$1(body.targetId) ?? "") || void 0;
101
- }
102
- function resolveTargetIdFromQuery(query) {
103
- return (normalizeOptionalString$1(query.targetId) ?? "") || void 0;
104
- }
105
- function handleRouteError(ctx, res, err) {
106
- const mapped = ctx.mapTabError(err);
107
- if (mapped) return jsonError(res, mapped.status, mapped.message);
108
- const browserMapped = toBrowserErrorResponse(err);
109
- if (browserMapped) return jsonError(res, browserMapped.status, browserMapped.message);
110
- jsonError(res, 500, String(err));
111
- }
112
- function resolveProfileContext(req, res, ctx) {
113
- const profileCtx = getProfileContext(req, ctx);
114
- if ("error" in profileCtx) {
115
- jsonError(res, profileCtx.status, profileCtx.error);
116
- return null;
117
- }
118
- return profileCtx;
119
- }
120
- function browserNavigationPolicyForProfile(ctx, profileCtx) {
121
- return withBrowserNavigationPolicy(ctx.state().resolved.ssrfPolicy, { browserProxyMode: resolveBrowserNavigationProxyMode({
122
- resolved: ctx.state().resolved,
123
- profile: profileCtx.profile
124
- }) });
125
- }
126
- async function getPwAiModule() {
127
- return await getPwAiModule$1({ mode: "soft" });
128
- }
129
- async function requirePwAi(res, feature) {
130
- const mod = await getPwAiModule();
131
- if (mod) return mod;
132
- jsonError(res, 501, [
133
- `Playwright is not available in this gateway build; '${feature}' is unsupported.`,
134
- "Reinstall or update FengMing so the core browser runtime dependency is present, then restart the gateway. In Docker, also install Chromium with the bundled playwright-core CLI.",
135
- "Docs: /tools/browser#playwright-requirement"
136
- ].join("\n"));
137
- return null;
138
- }
139
- async function withRouteTabContext(params) {
140
- const profileCtx = resolveProfileContext(params.req, params.res, params.ctx);
141
- if (!profileCtx) return;
142
- try {
143
- const tab = await profileCtx.ensureTabAvailable(params.targetId);
144
- if (params.enforceCurrentUrlAllowed) await assertBrowserNavigationResultAllowed({
145
- url: tab.url,
146
- ...browserNavigationPolicyForProfile(params.ctx, profileCtx)
147
- });
148
- return await params.run({
149
- profileCtx,
150
- tab,
151
- cdpUrl: profileCtx.profile.cdpUrl,
152
- resolveTabUrl: (fallbackUrl) => resolveSafeRouteTabUrl({
153
- ctx: params.ctx,
154
- profileCtx,
155
- targetId: tab.targetId,
156
- fallbackUrl
157
- })
158
- });
159
- } catch (err) {
160
- handleRouteError(params.ctx, params.res, err);
161
- return;
162
- }
163
- }
164
- /**
165
- * Response-only URL redaction. This swallows policy failures and must not be used as
166
- * an execution gate; use enforceCurrentUrlAllowed on the route helper instead.
167
- */
168
- async function resolveSafeRouteTabUrl(params) {
169
- const candidateUrl = (await params.profileCtx.listTabs().catch(() => [])).find((tab) => tab.targetId === params.targetId)?.url ?? params.fallbackUrl;
170
- if (!candidateUrl) return;
171
- try {
172
- await assertBrowserNavigationResultAllowed({
173
- url: candidateUrl,
174
- ...browserNavigationPolicyForProfile(params.ctx, params.profileCtx)
175
- });
176
- return candidateUrl;
177
- } catch {
178
- return;
179
- }
180
- }
181
- async function withPlaywrightRouteContext(params) {
182
- return await withRouteTabContext({
183
- req: params.req,
184
- res: params.res,
185
- ctx: params.ctx,
186
- targetId: params.targetId,
187
- enforceCurrentUrlAllowed: params.enforceCurrentUrlAllowed,
188
- run: async ({ profileCtx, tab, cdpUrl, resolveTabUrl }) => {
189
- const pw = await requirePwAi(params.res, params.feature);
190
- if (!pw) return;
191
- return await params.run({
192
- profileCtx,
193
- tab,
194
- cdpUrl,
195
- resolveTabUrl,
196
- pw
197
- });
198
- }
199
- });
200
- }
201
- //#endregion
202
- //#region extensions/browser/src/browser/routes/existing-session-limits.ts
203
- const EXISTING_SESSION_LIMITS = {
204
- act: {
205
- clickSelector: "existing-session click does not support selector targeting yet; use ref.",
206
- clickButtonOrModifiers: "existing-session click currently supports left-click only (no button overrides/modifiers).",
207
- typeSelector: "existing-session type does not support selector targeting yet; use ref.",
208
- typeSlowly: "existing-session type does not support slowly=true; use fill/press instead.",
209
- typeTimeout: "existing-session type does not support timeoutMs overrides.",
210
- pressDelay: "existing-session press does not support delayMs.",
211
- hoverSelector: "existing-session hover does not support selector targeting yet; use ref.",
212
- hoverTimeout: "existing-session hover does not support timeoutMs overrides.",
213
- scrollSelector: "existing-session scrollIntoView does not support selector targeting yet; use ref.",
214
- scrollTimeout: "existing-session scrollIntoView does not support timeoutMs overrides.",
215
- dragSelector: "existing-session drag does not support selector targeting yet; use startRef/endRef.",
216
- dragTimeout: "existing-session drag does not support timeoutMs overrides.",
217
- selectSelector: "existing-session select does not support selector targeting yet; use ref.",
218
- selectSingleValue: "existing-session select currently supports a single value only.",
219
- selectTimeout: "existing-session select does not support timeoutMs overrides.",
220
- fillTimeout: "existing-session fill does not support timeoutMs overrides.",
221
- waitNetworkIdle: "existing-session wait does not support loadState=networkidle yet.",
222
- evaluateTimeout: "existing-session evaluate does not support timeoutMs overrides.",
223
- batch: "existing-session batch is not supported yet; send actions individually."
224
- },
225
- hooks: {
226
- uploadElement: "existing-session file uploads do not support element selectors; use ref/inputRef.",
227
- uploadSingleFile: "existing-session file uploads currently support one file at a time.",
228
- uploadRefRequired: "existing-session file uploads require ref or inputRef.",
229
- dialogId: "existing-session dialog handling does not support dialogId.",
230
- dialogTimeout: "existing-session dialog handling does not support timeoutMs."
231
- },
232
- download: {
233
- waitUnsupported: "download waiting is not supported for existing-session profiles yet.",
234
- downloadUnsupported: "downloads are not supported for existing-session profiles yet."
235
- },
236
- snapshot: {
237
- pdfUnsupported: "pdf is not supported for existing-session profiles yet; use screenshot/snapshot instead.",
238
- screenshotElement: "element screenshots are not supported for existing-session profiles; use ref from snapshot.",
239
- snapshotSelector: "selector/frame snapshots are not supported for existing-session profiles; snapshot the whole page and use refs."
240
- },
241
- responseBody: "response body is not supported for existing-session profiles yet."
242
- };
243
- //#endregion
244
- //#region extensions/browser/src/browser/routes/output-paths.ts
245
- async function ensureOutputRootDir(rootDir) {
246
- await ensureOutputDirectory(rootDir);
247
- }
248
- async function resolveWritableOutputPathOrRespond(params) {
249
- if (params.ensureRootDir) await ensureOutputRootDir(params.rootDir);
250
- const pathResult = await pathScope(params.rootDir, { label: params.scopeLabel }).writable(params.requestedPath, { defaultName: params.defaultFileName });
251
- if (!pathResult.ok) {
252
- params.res.status(400).json({ error: pathResult.error });
253
- return null;
254
- }
255
- return pathResult.path;
256
- }
257
- //#endregion
258
- //#region extensions/browser/src/browser/routes/route-numeric.ts
259
- function hasRouteInputValue(value) {
260
- return value != null;
261
- }
262
- function readRouteFiniteNumber(value, fieldName) {
263
- const parsed = parseStrictFiniteNumber(value);
264
- if (parsed === void 0 && hasRouteInputValue(value)) throw new Error(`${fieldName} must be a finite number.`);
265
- return parsed;
266
- }
267
- function readOptionalRouteFiniteNumber(value, fieldName) {
268
- if (typeof value === "string" && value.trim() === "") return;
269
- return readRouteFiniteNumber(value, fieldName);
270
- }
271
- function readRouteInteger(value, fieldName, options) {
272
- const parsed = parseStrictInteger(value);
273
- if (parsed === void 0 && hasRouteInputValue(value)) throw new Error(options?.invalidMessage ?? `${fieldName} must be an integer.`);
274
- return parsed;
275
- }
276
- function readRoutePositiveInteger(value, fieldName, options) {
277
- const parsed = parseStrictPositiveInteger(value);
278
- if (parsed === void 0 && hasRouteInputValue(value)) throw new Error(options?.invalidMessage ?? `${fieldName} must be a positive integer.`);
279
- return parsed;
280
- }
281
- function readRouteTimerTimeoutMs(value, fieldName = "timeoutMs", opts) {
282
- const parsed = readRoutePositiveInteger(value, fieldName, opts);
283
- return parsed === void 0 ? void 0 : normalizeBrowserTimerDelayMs(parsed, opts);
284
- }
285
- function readRouteNonNegativeInteger(value, fieldName, options) {
286
- const parsed = parseStrictNonNegativeInteger(value);
287
- if (parsed === void 0 && hasRouteInputValue(value)) throw new Error(options?.invalidMessage ?? `${fieldName} must be a non-negative integer.`);
288
- return parsed;
289
- }
290
- //#endregion
291
- //#region extensions/browser/src/browser/routes/agent.act.download.ts
292
- function buildDownloadRequestBase(cdpUrl, targetId, timeoutMs) {
293
- return {
294
- cdpUrl,
295
- targetId,
296
- timeoutMs: timeoutMs ?? void 0
297
- };
298
- }
299
- function registerBrowserAgentActDownloadRoutes(app, ctx) {
300
- app.post("/wait/download", asyncBrowserRoute(async (req, res) => {
301
- const body = readBody(req);
302
- const targetId = resolveTargetIdFromBody(body);
303
- const out = toStringOrEmpty(body.path) || "";
304
- let timeoutMs;
305
- try {
306
- timeoutMs = readRouteTimerTimeoutMs(body.timeoutMs);
307
- } catch (err) {
308
- return jsonError(res, 400, formatErrorMessage(err));
309
- }
310
- await withRouteTabContext({
311
- req,
312
- res,
313
- ctx,
314
- targetId,
315
- run: async ({ profileCtx, cdpUrl, tab }) => {
316
- if (getBrowserProfileCapabilities(profileCtx.profile).usesChromeMcp) return jsonError(res, 501, EXISTING_SESSION_LIMITS.download.waitUnsupported);
317
- const pw = await requirePwAi(res, "wait for download");
318
- if (!pw) return;
319
- await ensureOutputRootDir(DEFAULT_DOWNLOAD_DIR);
320
- let downloadPath;
321
- if (out.trim()) {
322
- const resolvedDownloadPath = await resolveWritableOutputPathOrRespond({
323
- res,
324
- rootDir: DEFAULT_DOWNLOAD_DIR,
325
- requestedPath: out,
326
- scopeLabel: "downloads directory"
327
- });
328
- if (!resolvedDownloadPath) return;
329
- downloadPath = resolvedDownloadPath;
330
- }
331
- const requestBase = buildDownloadRequestBase(cdpUrl, tab.targetId, timeoutMs);
332
- const result = await pw.waitForDownloadViaPlaywright({
333
- ...requestBase,
334
- path: downloadPath,
335
- rootDir: DEFAULT_DOWNLOAD_DIR
336
- });
337
- res.json({
338
- ok: true,
339
- targetId: tab.targetId,
340
- download: result
341
- });
342
- }
343
- });
344
- }));
345
- app.post("/download", asyncBrowserRoute(async (req, res) => {
346
- const body = readBody(req);
347
- const targetId = resolveTargetIdFromBody(body);
348
- const ref = toStringOrEmpty(body.ref);
349
- const out = toStringOrEmpty(body.path);
350
- let timeoutMs;
351
- try {
352
- timeoutMs = readRouteTimerTimeoutMs(body.timeoutMs);
353
- } catch (err) {
354
- return jsonError(res, 400, formatErrorMessage(err));
355
- }
356
- if (!ref) return jsonError(res, 400, "ref is required");
357
- if (!out) return jsonError(res, 400, "path is required");
358
- await withRouteTabContext({
359
- req,
360
- res,
361
- ctx,
362
- targetId,
363
- run: async ({ profileCtx, cdpUrl, tab }) => {
364
- if (getBrowserProfileCapabilities(profileCtx.profile).usesChromeMcp) return jsonError(res, 501, EXISTING_SESSION_LIMITS.download.downloadUnsupported);
365
- const pw = await requirePwAi(res, "download");
366
- if (!pw) return;
367
- await ensureOutputRootDir(DEFAULT_DOWNLOAD_DIR);
368
- const downloadPath = await resolveWritableOutputPathOrRespond({
369
- res,
370
- rootDir: DEFAULT_DOWNLOAD_DIR,
371
- requestedPath: out,
372
- scopeLabel: "downloads directory"
373
- });
374
- if (!downloadPath) return;
375
- const requestBase = buildDownloadRequestBase(cdpUrl, tab.targetId, timeoutMs);
376
- const result = await pw.downloadViaPlaywright({
377
- ...requestBase,
378
- ref,
379
- path: downloadPath,
380
- rootDir: DEFAULT_DOWNLOAD_DIR
381
- });
382
- res.json({
383
- ok: true,
384
- targetId: tab.targetId,
385
- download: result
386
- });
387
- }
388
- });
389
- }));
390
- }
391
- //#endregion
392
- //#region extensions/browser/src/browser/routes/agent.act.errors.ts
393
- const ACT_ERROR_CODES = {
394
- kindRequired: "ACT_KIND_REQUIRED",
395
- invalidRequest: "ACT_INVALID_REQUEST",
396
- selectorUnsupported: "ACT_SELECTOR_UNSUPPORTED",
397
- evaluateDisabled: "ACT_EVALUATE_DISABLED",
398
- unsupportedForExistingSession: "ACT_EXISTING_SESSION_UNSUPPORTED",
399
- targetIdMismatch: "ACT_TARGET_ID_MISMATCH"
400
- };
401
- function jsonActError(res, status, code, message) {
402
- res.status(status).json({
403
- error: message,
404
- code
405
- });
406
- }
407
- function browserEvaluateDisabledMessage(action) {
408
- return [action === "wait" ? "wait --fn is disabled by config (browser.evaluateEnabled=false)." : "act:evaluate is disabled by config (browser.evaluateEnabled=false).", "Docs: /gateway/configuration#browser-fengming-managed-browser"].join("\n");
409
- }
410
- //#endregion
411
- //#region extensions/browser/src/browser/routes/agent.act.hooks.ts
412
- function registerBrowserAgentActHookRoutes(app, ctx) {
413
- app.post("/hooks/file-chooser", asyncBrowserRoute(async (req, res) => {
414
- const body = readBody(req);
415
- const targetId = resolveTargetIdFromBody(body);
416
- const ref = toStringOrEmpty(body.ref) || void 0;
417
- const inputRef = toStringOrEmpty(body.inputRef) || void 0;
418
- const element = toStringOrEmpty(body.element) || void 0;
419
- const paths = toStringArray(body.paths) ?? [];
420
- let timeoutMs;
421
- try {
422
- timeoutMs = readRouteTimerTimeoutMs(body.timeoutMs);
423
- } catch (err) {
424
- return jsonError(res, 400, formatErrorMessage(err));
425
- }
426
- if (!paths.length) return jsonError(res, 400, "paths are required");
427
- await withRouteTabContext({
428
- req,
429
- res,
430
- ctx,
431
- targetId,
432
- run: async ({ profileCtx, cdpUrl, tab }) => {
433
- const uploadPathsResult = await pathScope(DEFAULT_UPLOAD_DIR, { label: `uploads directory (${DEFAULT_UPLOAD_DIR})` }).existing(paths);
434
- if (!uploadPathsResult.ok) {
435
- res.status(400).json({ error: uploadPathsResult.error });
436
- return;
437
- }
438
- const resolvedPaths = uploadPathsResult.paths;
439
- if (getBrowserProfileCapabilities(profileCtx.profile).usesChromeMcp) {
440
- if (element) return jsonError(res, 501, EXISTING_SESSION_LIMITS.hooks.uploadElement);
441
- if (resolvedPaths.length !== 1) return jsonError(res, 501, EXISTING_SESSION_LIMITS.hooks.uploadSingleFile);
442
- const uid = inputRef || ref;
443
- if (!uid) return jsonError(res, 501, EXISTING_SESSION_LIMITS.hooks.uploadRefRequired);
444
- await uploadChromeMcpFile({
445
- profileName: profileCtx.profile.name,
446
- profile: profileCtx.profile,
447
- targetId: tab.targetId,
448
- uid,
449
- filePath: resolvedPaths[0] ?? ""
450
- });
451
- return res.json({ ok: true });
452
- }
453
- const pw = await requirePwAi(res, "file chooser hook");
454
- if (!pw) return;
455
- if (inputRef || element) {
456
- if (ref) return jsonError(res, 400, "ref cannot be combined with inputRef/element");
457
- await pw.setInputFilesViaPlaywright({
458
- cdpUrl,
459
- targetId: tab.targetId,
460
- inputRef,
461
- element,
462
- paths: resolvedPaths
463
- });
464
- } else {
465
- await pw.armFileUploadViaPlaywright({
466
- cdpUrl,
467
- targetId: tab.targetId,
468
- paths: resolvedPaths,
469
- timeoutMs: timeoutMs ?? void 0
470
- });
471
- if (ref) await pw.clickViaPlaywright({
472
- cdpUrl,
473
- targetId: tab.targetId,
474
- ssrfPolicy: ctx.state().resolved.ssrfPolicy,
475
- ref
476
- });
477
- }
478
- res.json({ ok: true });
479
- }
480
- });
481
- }));
482
- app.post("/hooks/dialog", asyncBrowserRoute(async (req, res) => {
483
- const body = readBody(req);
484
- const targetId = resolveTargetIdFromBody(body);
485
- const accept = toBoolean(body.accept);
486
- const promptText = toStringOrEmpty(body.promptText) || void 0;
487
- let timeoutMs;
488
- try {
489
- timeoutMs = readRouteTimerTimeoutMs(body.timeoutMs);
490
- } catch (err) {
491
- return jsonError(res, 400, formatErrorMessage(err));
492
- }
493
- const dialogId = toStringOrEmpty(body.dialogId) || void 0;
494
- if (accept === void 0) return jsonError(res, 400, "accept is required");
495
- await withRouteTabContext({
496
- req,
497
- res,
498
- ctx,
499
- targetId,
500
- run: async ({ profileCtx, cdpUrl, tab }) => {
501
- if (getBrowserProfileCapabilities(profileCtx.profile).usesChromeMcp) {
502
- if (dialogId) return jsonError(res, 501, EXISTING_SESSION_LIMITS.hooks.dialogId);
503
- if (timeoutMs) return jsonError(res, 501, EXISTING_SESSION_LIMITS.hooks.dialogTimeout);
504
- await evaluateChromeMcpScript({
505
- profileName: profileCtx.profile.name,
506
- profile: profileCtx.profile,
507
- targetId: tab.targetId,
508
- fn: `() => {
509
- const state = (window.__fengmingDialogHook ??= {});
510
- if (!state.originals) {
511
- state.originals = {
512
- alert: window.alert.bind(window),
513
- confirm: window.confirm.bind(window),
514
- prompt: window.prompt.bind(window),
515
- };
516
- }
517
- const originals = state.originals;
518
- const restore = () => {
519
- window.alert = originals.alert;
520
- window.confirm = originals.confirm;
521
- window.prompt = originals.prompt;
522
- delete window.__fengmingDialogHook;
523
- };
524
- window.alert = (...args) => {
525
- try {
526
- return undefined;
527
- } finally {
528
- restore();
529
- }
530
- };
531
- window.confirm = (...args) => {
532
- try {
533
- return ${accept ? "true" : "false"};
534
- } finally {
535
- restore();
536
- }
537
- };
538
- window.prompt = (...args) => {
539
- try {
540
- return ${accept ? JSON.stringify(promptText ?? "") : "null"};
541
- } finally {
542
- restore();
543
- }
544
- };
545
- return true;
546
- }`
547
- });
548
- return res.json({ ok: true });
549
- }
550
- const pw = await requirePwAi(res, "dialog hook");
551
- if (!pw) return;
552
- await pw.armDialogViaPlaywright({
553
- cdpUrl,
554
- targetId: tab.targetId,
555
- dialogId,
556
- accept,
557
- promptText,
558
- timeoutMs: timeoutMs ?? void 0
559
- });
560
- res.json({ ok: true });
561
- }
562
- });
563
- }));
564
- }
565
- //#endregion
566
- //#region extensions/browser/src/browser/routes/agent.act.shared.ts
567
- const ACT_KINDS = [
568
- "batch",
569
- "click",
570
- "clickCoords",
571
- "close",
572
- "drag",
573
- "evaluate",
574
- "fill",
575
- "hover",
576
- "scrollIntoView",
577
- "press",
578
- "resize",
579
- "select",
580
- "type",
581
- "wait"
582
- ];
583
- function isActKind(value) {
584
- if (typeof value !== "string") return false;
585
- return ACT_KINDS.includes(value);
586
- }
587
- const ALLOWED_CLICK_MODIFIERS = new Set([
588
- "Alt",
589
- "Control",
590
- "ControlOrMeta",
591
- "Meta",
592
- "Shift"
593
- ]);
594
- function parseClickButton(raw) {
595
- if (raw === "left" || raw === "right" || raw === "middle") return raw;
596
- }
597
- function parseClickModifiers(raw) {
598
- if (raw.filter((m) => !ALLOWED_CLICK_MODIFIERS.has(m)).length) return { error: "modifiers must be Alt|Control|ControlOrMeta|Meta|Shift" };
599
- return { modifiers: raw.length ? raw : void 0 };
600
- }
601
- //#endregion
602
- //#region extensions/browser/src/browser/routes/agent.act.normalize.ts
603
- function normalizeActKind(raw) {
604
- const kind = toStringOrEmpty(raw);
605
- if (!isActKind(kind)) throw new Error("kind 是必需的");
606
- return kind;
607
- }
608
- function countBatchActions(actions) {
609
- let count = 0;
610
- for (const action of actions) {
611
- count += 1;
612
- if (action.kind === "batch") count += countBatchActions(action.actions);
613
- }
614
- return count;
615
- }
616
- function validateBatchTargetIds(actions, targetId) {
617
- for (const action of actions) {
618
- if (action.targetId && action.targetId !== targetId) return "batched action targetId must match request targetId";
619
- if (action.kind === "batch") {
620
- const nestedError = validateBatchTargetIds(action.actions, targetId);
621
- if (nestedError) return nestedError;
622
- }
623
- }
624
- return null;
625
- }
626
- function normalizeFields(rawFields) {
627
- return (Array.isArray(rawFields) ? rawFields : []).map((field) => {
628
- if (!field || typeof field !== "object") return null;
629
- return normalizeBrowserFormField(field);
630
- }).filter((field) => field !== null);
631
- }
632
- function normalizeBatchAction(value) {
633
- if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("batch actions 必须是对象");
634
- return normalizeActRequest(value, { source: "batch" });
635
- }
636
- function readActionNonNegativeInteger(body, key) {
637
- return readRouteNonNegativeInteger(body[key], key);
638
- }
639
- function readActionTimeoutMs(body) {
640
- return readRouteTimerTimeoutMs(body.timeoutMs);
641
- }
642
- function readBoundedActionDurationMs(body, key, fieldName, maxMs) {
643
- return normalizeActBoundedNonNegativeMs(readActionNonNegativeInteger(body, key), fieldName, maxMs);
644
- }
645
- function readResizeDimension(body, key) {
646
- const value = readRouteInteger(body[key], key, { invalidMessage: "resize requires positive width and height" });
647
- if (value === void 0 && Object.hasOwn(body, key)) throw new Error("resize 需要正数的宽度和高度");
648
- return value;
649
- }
650
- function normalizeActRequest(body, options) {
651
- const source = options?.source ?? "request";
652
- const kind = normalizeActKind(body.kind);
653
- switch (kind) {
654
- case "click": {
655
- const ref = toStringOrEmpty(body.ref) || void 0;
656
- const selector = toStringOrEmpty(body.selector) || void 0;
657
- if (!ref && !selector) throw new Error("click 需要 ref 或 selector");
658
- const buttonRaw = toStringOrEmpty(body.button);
659
- const button = buttonRaw ? parseClickButton(buttonRaw) : void 0;
660
- if (buttonRaw && !button) throw new Error("click button 必须是 left、right 或 middle");
661
- const parsedModifiers = parseClickModifiers(toStringArray(body.modifiers) ?? []);
662
- if (parsedModifiers.error) throw new Error(parsedModifiers.error);
663
- const doubleClick = toBoolean(body.doubleClick);
664
- const delayMs = readBoundedActionDurationMs(body, "delayMs", "click delayMs", ACT_MAX_CLICK_DELAY_MS);
665
- const timeoutMs = readActionTimeoutMs(body);
666
- const targetId = toStringOrEmpty(body.targetId) || void 0;
667
- return {
668
- kind,
669
- ...ref ? { ref } : {},
670
- ...selector ? { selector } : {},
671
- ...targetId ? { targetId } : {},
672
- ...doubleClick !== void 0 ? { doubleClick } : {},
673
- ...button ? { button } : {},
674
- ...parsedModifiers.modifiers ? { modifiers: parsedModifiers.modifiers } : {},
675
- ...delayMs !== void 0 ? { delayMs } : {},
676
- ...timeoutMs !== void 0 ? { timeoutMs } : {}
677
- };
678
- }
679
- case "clickCoords": {
680
- const x = toNumber(body.x);
681
- const y = toNumber(body.y);
682
- if (x === void 0 || y === void 0 || x < 0 || y < 0) throw new Error("clickCoords 需要非负的 x 和 y");
683
- const buttonRaw = toStringOrEmpty(body.button);
684
- const button = buttonRaw ? parseClickButton(buttonRaw) : void 0;
685
- if (buttonRaw && !button) throw new Error("clickCoords button 必须是 left、right 或 middle");
686
- const doubleClick = toBoolean(body.doubleClick);
687
- const delayMs = readBoundedActionDurationMs(body, "delayMs", "clickCoords delayMs", ACT_MAX_CLICK_DELAY_MS);
688
- const timeoutMs = readActionTimeoutMs(body);
689
- const targetId = toStringOrEmpty(body.targetId) || void 0;
690
- return {
691
- kind,
692
- x,
693
- y,
694
- ...targetId ? { targetId } : {},
695
- ...doubleClick !== void 0 ? { doubleClick } : {},
696
- ...button ? { button } : {},
697
- ...delayMs !== void 0 ? { delayMs } : {},
698
- ...timeoutMs !== void 0 ? { timeoutMs } : {}
699
- };
700
- }
701
- case "type": {
702
- const ref = toStringOrEmpty(body.ref) || void 0;
703
- const selector = toStringOrEmpty(body.selector) || void 0;
704
- const text = body.text;
705
- if (!ref && !selector) throw new Error("type 需要 ref 或 selector");
706
- if (typeof text !== "string") throw new Error("type 需要 text 参数");
707
- const targetId = toStringOrEmpty(body.targetId) || void 0;
708
- const submit = toBoolean(body.submit);
709
- const slowly = toBoolean(body.slowly);
710
- const timeoutMs = readActionTimeoutMs(body);
711
- return {
712
- kind,
713
- ...ref ? { ref } : {},
714
- ...selector ? { selector } : {},
715
- text,
716
- ...targetId ? { targetId } : {},
717
- ...submit !== void 0 ? { submit } : {},
718
- ...slowly !== void 0 ? { slowly } : {},
719
- ...timeoutMs !== void 0 ? { timeoutMs } : {}
720
- };
721
- }
722
- case "press": {
723
- const key = toStringOrEmpty(body.key);
724
- if (!key) throw new Error("press 需要 key 参数");
725
- const targetId = toStringOrEmpty(body.targetId) || void 0;
726
- const delayMs = readActionNonNegativeInteger(body, "delayMs");
727
- return {
728
- kind,
729
- key,
730
- ...targetId ? { targetId } : {},
731
- ...delayMs !== void 0 ? { delayMs } : {}
732
- };
733
- }
734
- case "hover":
735
- case "scrollIntoView": {
736
- const ref = toStringOrEmpty(body.ref) || void 0;
737
- const selector = toStringOrEmpty(body.selector) || void 0;
738
- if (!ref && !selector) throw new Error(`${kind} requires ref or selector`);
739
- const targetId = toStringOrEmpty(body.targetId) || void 0;
740
- const timeoutMs = readActionTimeoutMs(body);
741
- return {
742
- kind,
743
- ...ref ? { ref } : {},
744
- ...selector ? { selector } : {},
745
- ...targetId ? { targetId } : {},
746
- ...timeoutMs !== void 0 ? { timeoutMs } : {}
747
- };
748
- }
749
- case "drag": {
750
- const startRef = toStringOrEmpty(body.startRef) || void 0;
751
- const startSelector = toStringOrEmpty(body.startSelector) || void 0;
752
- const endRef = toStringOrEmpty(body.endRef) || void 0;
753
- const endSelector = toStringOrEmpty(body.endSelector) || void 0;
754
- if (!startRef && !startSelector) throw new Error("drag 需要 startRef 或 startSelector");
755
- if (!endRef && !endSelector) throw new Error("drag 需要 endRef 或 endSelector");
756
- const targetId = toStringOrEmpty(body.targetId) || void 0;
757
- const timeoutMs = readActionTimeoutMs(body);
758
- return {
759
- kind,
760
- ...startRef ? { startRef } : {},
761
- ...startSelector ? { startSelector } : {},
762
- ...endRef ? { endRef } : {},
763
- ...endSelector ? { endSelector } : {},
764
- ...targetId ? { targetId } : {},
765
- ...timeoutMs !== void 0 ? { timeoutMs } : {}
766
- };
767
- }
768
- case "select": {
769
- const ref = toStringOrEmpty(body.ref) || void 0;
770
- const selector = toStringOrEmpty(body.selector) || void 0;
771
- const values = toStringArray(body.values);
772
- if (!ref && !selector || !values?.length) throw new Error("select 需要 ref/selector 和 values");
773
- const targetId = toStringOrEmpty(body.targetId) || void 0;
774
- const timeoutMs = readActionTimeoutMs(body);
775
- return {
776
- kind,
777
- ...ref ? { ref } : {},
778
- ...selector ? { selector } : {},
779
- values,
780
- ...targetId ? { targetId } : {},
781
- ...timeoutMs !== void 0 ? { timeoutMs } : {}
782
- };
783
- }
784
- case "fill": {
785
- const fields = normalizeFields(body.fields);
786
- if (!fields.length) throw new Error("fill 需要 fields 参数");
787
- const targetId = toStringOrEmpty(body.targetId) || void 0;
788
- const timeoutMs = readActionTimeoutMs(body);
789
- return {
790
- kind,
791
- fields,
792
- ...targetId ? { targetId } : {},
793
- ...timeoutMs !== void 0 ? { timeoutMs } : {}
794
- };
795
- }
796
- case "resize": {
797
- const width = readResizeDimension(body, "width");
798
- const height = readResizeDimension(body, "height");
799
- if (width === void 0 || height === void 0 || width <= 0 || height <= 0) throw new Error("resize 需要正数的宽度和高度");
800
- if (width > 8192 || height > 8192) throw new Error(`resize width and height must not exceed ${ACT_MAX_VIEWPORT_DIMENSION}`);
801
- const targetId = toStringOrEmpty(body.targetId) || void 0;
802
- return {
803
- kind,
804
- width,
805
- height,
806
- ...targetId ? { targetId } : {}
807
- };
808
- }
809
- case "wait": {
810
- const loadStateRaw = toStringOrEmpty(body.loadState);
811
- const loadState = loadStateRaw === "load" || loadStateRaw === "domcontentloaded" || loadStateRaw === "networkidle" ? loadStateRaw : void 0;
812
- const timeMs = readBoundedActionDurationMs(body, "timeMs", "wait timeMs", ACT_MAX_WAIT_TIME_MS);
813
- const text = toStringOrEmpty(body.text) || void 0;
814
- const textGone = toStringOrEmpty(body.textGone) || void 0;
815
- const selector = toStringOrEmpty(body.selector) || void 0;
816
- const url = toStringOrEmpty(body.url) || void 0;
817
- const fn = toStringOrEmpty(body.fn) || void 0;
818
- if (timeMs === void 0 && !text && !textGone && !selector && !url && !loadState && !fn) throw new Error("wait requires at least one of: timeMs, text, textGone, selector, url, loadState, fn");
819
- const targetId = toStringOrEmpty(body.targetId) || void 0;
820
- const timeoutMs = readActionTimeoutMs(body);
821
- return {
822
- kind,
823
- ...timeMs !== void 0 ? { timeMs } : {},
824
- ...text ? { text } : {},
825
- ...textGone ? { textGone } : {},
826
- ...selector ? { selector } : {},
827
- ...url ? { url } : {},
828
- ...loadState ? { loadState } : {},
829
- ...fn ? { fn } : {},
830
- ...targetId ? { targetId } : {},
831
- ...timeoutMs !== void 0 ? { timeoutMs } : {}
832
- };
833
- }
834
- case "evaluate": {
835
- const fn = toStringOrEmpty(body.fn);
836
- if (!fn) throw new Error("evaluate 需要 fn 参数");
837
- const ref = toStringOrEmpty(body.ref) || void 0;
838
- const targetId = toStringOrEmpty(body.targetId) || void 0;
839
- const timeoutMs = readActionTimeoutMs(body);
840
- return {
841
- kind,
842
- fn,
843
- ...ref ? { ref } : {},
844
- ...targetId ? { targetId } : {},
845
- ...timeoutMs !== void 0 ? { timeoutMs } : {}
846
- };
847
- }
848
- case "close": {
849
- const targetId = toStringOrEmpty(body.targetId) || void 0;
850
- return {
851
- kind,
852
- ...targetId ? { targetId } : {}
853
- };
854
- }
855
- case "batch": {
856
- const actions = Array.isArray(body.actions) ? body.actions.map(normalizeBatchAction) : [];
857
- if (!actions.length) throw new Error(source === "batch" ? "batch requires actions" : "actions are required");
858
- if (countBatchActions(actions) > 100) throw new Error(`batch exceeds maximum of 100 actions`);
859
- const targetId = toStringOrEmpty(body.targetId) || void 0;
860
- const stopOnError = toBoolean(body.stopOnError);
861
- return {
862
- kind,
863
- actions,
864
- ...targetId ? { targetId } : {},
865
- ...stopOnError !== void 0 ? { stopOnError } : {}
866
- };
867
- }
868
- }
869
- throw new Error("不支持的浏览器操作类型");
870
- }
871
- //#endregion
872
- //#region extensions/browser/src/browser/routes/agent.snapshot-target.ts
873
- /** Resolve the correct targetId after a navigation that may trigger a renderer swap. */
874
- async function resolveTargetIdAfterNavigate(opts) {
875
- let currentTargetId = opts.oldTargetId;
876
- try {
877
- const pickReplacement = (tabs, options) => {
878
- if (tabs.some((tab) => tab.targetId === opts.oldTargetId)) return {
879
- targetId: opts.oldTargetId,
880
- shouldRetry: false
881
- };
882
- const byUrl = tabs.filter((tab) => tab.url === opts.navigatedUrl);
883
- if (byUrl.length === 1) return {
884
- targetId: byUrl[0]?.targetId ?? opts.oldTargetId,
885
- shouldRetry: false
886
- };
887
- const uniqueReplacement = byUrl.filter((tab) => tab.targetId !== opts.oldTargetId);
888
- if (uniqueReplacement.length === 1) return {
889
- targetId: uniqueReplacement[0]?.targetId ?? opts.oldTargetId,
890
- shouldRetry: false
891
- };
892
- if (options?.allowSingleTabFallback && tabs.length === 1) return {
893
- targetId: tabs[0]?.targetId ?? opts.oldTargetId,
894
- shouldRetry: false
895
- };
896
- return {
897
- targetId: opts.oldTargetId,
898
- shouldRetry: true
899
- };
900
- };
901
- const first = pickReplacement(await opts.listTabs());
902
- currentTargetId = first.targetId;
903
- if (first.shouldRetry) {
904
- await new Promise((r) => setTimeout(r, opts.retryDelayMs ?? 800));
905
- currentTargetId = pickReplacement(await opts.listTabs(), { allowSingleTabFallback: true }).targetId;
906
- }
907
- } catch {}
908
- return currentTargetId;
909
- }
910
- //#endregion
911
- //#region extensions/browser/src/browser/routes/agent.act.ts
912
- function sleep(ms) {
913
- return new Promise((resolve) => setTimeout(resolve, ms));
914
- }
915
- const EXISTING_SESSION_INTERACTION_NAVIGATION_RECHECK_DELAYS_MS = [
916
- 0,
917
- 250,
918
- 500
919
- ];
920
- async function readExistingSessionLocationHref(params) {
921
- const currentUrl = await evaluateChromeMcpScript({
922
- profileName: params.profileName,
923
- profile: params.profile,
924
- userDataDir: params.userDataDir,
925
- targetId: params.targetId,
926
- fn: "() => window.location.href"
927
- });
928
- if (typeof currentUrl !== "string") throw new Error("位置探测返回了非字符串结果");
929
- const normalizedUrl = currentUrl.trim();
930
- if (!normalizedUrl) throw new Error("位置探测返回了空 URL");
931
- return normalizedUrl;
932
- }
933
- async function assertExistingSessionPostInteractionNavigationAllowed(params) {
934
- const ssrfPolicyOpts = withBrowserNavigationPolicy(params.ssrfPolicy);
935
- if (!ssrfPolicyOpts.ssrfPolicy) return;
936
- const listTabs = params.listTabs;
937
- const initialTabTargetIds = params.initialTabTargetIds;
938
- const assertNewTabsAllowed = async () => {
939
- const tabs = await listTabs();
940
- for (const tab of tabs) {
941
- if (initialTabTargetIds.has(tab.targetId)) continue;
942
- await assertBrowserNavigationResultAllowed({
943
- url: tab.url,
944
- ...ssrfPolicyOpts
945
- });
946
- }
947
- };
948
- let lastObservedUrl;
949
- let sawStableAllowedUrl = false;
950
- for (const delayMs of EXISTING_SESSION_INTERACTION_NAVIGATION_RECHECK_DELAYS_MS) {
951
- if (delayMs > 0) await sleep(delayMs);
952
- let currentUrl;
953
- try {
954
- currentUrl = await readExistingSessionLocationHref(params);
955
- } catch {
956
- sawStableAllowedUrl = false;
957
- continue;
958
- }
959
- await assertBrowserNavigationResultAllowed({
960
- url: currentUrl,
961
- ...ssrfPolicyOpts
962
- });
963
- if (currentUrl === lastObservedUrl) sawStableAllowedUrl = true;
964
- else sawStableAllowedUrl = false;
965
- lastObservedUrl = currentUrl;
966
- }
967
- if (sawStableAllowedUrl) {
968
- await assertNewTabsAllowed();
969
- return;
970
- }
971
- if (lastObservedUrl) {
972
- const lastDelay = EXISTING_SESSION_INTERACTION_NAVIGATION_RECHECK_DELAYS_MS[EXISTING_SESSION_INTERACTION_NAVIGATION_RECHECK_DELAYS_MS.length - 1];
973
- await sleep(lastDelay);
974
- try {
975
- const followUpUrl = await readExistingSessionLocationHref(params);
976
- await assertBrowserNavigationResultAllowed({
977
- url: followUpUrl,
978
- ...ssrfPolicyOpts
979
- });
980
- if (followUpUrl === lastObservedUrl) {
981
- await assertNewTabsAllowed();
982
- return;
983
- }
984
- } catch {}
985
- }
986
- throw new Error("Unable to verify stable post-interaction navigation");
987
- }
988
- async function runExistingSessionActionWithNavigationGuard(params) {
989
- let actionError;
990
- let result;
991
- try {
992
- result = await params.execute();
993
- } catch (error) {
994
- actionError = error;
995
- }
996
- if (params.guard) await assertExistingSessionPostInteractionNavigationAllowed(params.guard);
997
- if (actionError) throw actionError;
998
- return result;
999
- }
1000
- function buildExistingSessionWaitPredicate(params) {
1001
- const checks = [];
1002
- if (params.text) checks.push(`Boolean(document.body?.innerText?.includes(${JSON.stringify(params.text)}))`);
1003
- if (params.textGone) checks.push(`!document.body?.innerText?.includes(${JSON.stringify(params.textGone)})`);
1004
- if (params.selector) checks.push(`Boolean(document.querySelector(${JSON.stringify(params.selector)}))`);
1005
- if (params.loadState === "domcontentloaded") checks.push(`document.readyState === "interactive" || document.readyState === "complete"`);
1006
- else if (params.loadState === "load") checks.push(`document.readyState === "complete"`);
1007
- if (params.fn) checks.push(`Boolean(await (${params.fn})())`);
1008
- if (checks.length === 0) return null;
1009
- return checks.length === 1 ? checks[0] : checks.map((check) => `(${check})`).join(" && ");
1010
- }
1011
- async function waitForExistingSessionCondition(params) {
1012
- if (params.timeMs && params.timeMs > 0) await sleep(params.timeMs);
1013
- const predicate = buildExistingSessionWaitPredicate(params);
1014
- if (!predicate && !params.url) return;
1015
- const timeoutMs = Math.max(250, params.timeoutMs ?? 1e4);
1016
- const deadline = Date.now() + timeoutMs;
1017
- while (Date.now() < deadline) {
1018
- let ready = true;
1019
- if (predicate) ready = Boolean(await evaluateChromeMcpScript({
1020
- profileName: params.profileName,
1021
- profile: params.profile,
1022
- userDataDir: params.userDataDir,
1023
- targetId: params.targetId,
1024
- fn: `async () => ${predicate}`
1025
- }));
1026
- if (ready && params.url) {
1027
- const currentUrl = await evaluateChromeMcpScript({
1028
- profileName: params.profileName,
1029
- profile: params.profile,
1030
- userDataDir: params.userDataDir,
1031
- targetId: params.targetId,
1032
- fn: "() => window.location.href"
1033
- });
1034
- ready = typeof currentUrl === "string" && matchBrowserUrlPattern(params.url, currentUrl);
1035
- }
1036
- if (ready) return;
1037
- await sleep(250);
1038
- }
1039
- throw new Error("等待条件超时");
1040
- }
1041
- const SELECTOR_ALLOWED_KINDS = new Set([
1042
- "batch",
1043
- "click",
1044
- "drag",
1045
- "hover",
1046
- "scrollIntoView",
1047
- "select",
1048
- "type",
1049
- "wait"
1050
- ]);
1051
- function shouldEnforceCurrentUrlForAct(action) {
1052
- return action.kind !== "resize" && action.kind !== "close";
1053
- }
1054
- function getExistingSessionUnsupportedMessage(action) {
1055
- switch (action.kind) {
1056
- case "click":
1057
- if (action.selector) return EXISTING_SESSION_LIMITS.act.clickSelector;
1058
- if (action.button && action.button !== "left" || Array.isArray(action.modifiers) && action.modifiers.length > 0) return EXISTING_SESSION_LIMITS.act.clickButtonOrModifiers;
1059
- return null;
1060
- case "clickCoords": return null;
1061
- case "type":
1062
- if (action.selector) return EXISTING_SESSION_LIMITS.act.typeSelector;
1063
- if (action.slowly) return EXISTING_SESSION_LIMITS.act.typeSlowly;
1064
- return action.timeoutMs ? EXISTING_SESSION_LIMITS.act.typeTimeout : null;
1065
- case "press": return action.delayMs ? EXISTING_SESSION_LIMITS.act.pressDelay : null;
1066
- case "hover":
1067
- if (action.selector) return EXISTING_SESSION_LIMITS.act.hoverSelector;
1068
- return action.timeoutMs ? EXISTING_SESSION_LIMITS.act.hoverTimeout : null;
1069
- case "scrollIntoView":
1070
- if (action.selector) return EXISTING_SESSION_LIMITS.act.scrollSelector;
1071
- return action.timeoutMs ? EXISTING_SESSION_LIMITS.act.scrollTimeout : null;
1072
- case "drag":
1073
- if (action.startSelector || action.endSelector) return EXISTING_SESSION_LIMITS.act.dragSelector;
1074
- return action.timeoutMs ? EXISTING_SESSION_LIMITS.act.dragTimeout : null;
1075
- case "select":
1076
- if (action.selector) return EXISTING_SESSION_LIMITS.act.selectSelector;
1077
- if (action.values.length !== 1) return EXISTING_SESSION_LIMITS.act.selectSingleValue;
1078
- return action.timeoutMs ? EXISTING_SESSION_LIMITS.act.selectTimeout : null;
1079
- case "fill": return action.timeoutMs ? EXISTING_SESSION_LIMITS.act.fillTimeout : null;
1080
- case "wait": return action.loadState === "networkidle" ? EXISTING_SESSION_LIMITS.act.waitNetworkIdle : null;
1081
- case "evaluate": return action.timeoutMs !== void 0 ? EXISTING_SESSION_LIMITS.act.evaluateTimeout : null;
1082
- case "batch": return EXISTING_SESSION_LIMITS.act.batch;
1083
- case "resize":
1084
- case "close": return null;
1085
- }
1086
- throw new Error("不支持的浏览器操作类型");
1087
- }
1088
- function registerBrowserAgentActRoutes(app, ctx) {
1089
- app.post("/act", asyncBrowserRoute(async (req, res) => {
1090
- const body = readBody(req);
1091
- const kindRaw = toStringOrEmpty(body.kind);
1092
- if (!isActKind(kindRaw)) return jsonActError(res, 400, ACT_ERROR_CODES.kindRequired, "kind is required");
1093
- const kind = kindRaw;
1094
- let action;
1095
- try {
1096
- action = normalizeActRequest(body);
1097
- } catch (err) {
1098
- return jsonActError(res, 400, ACT_ERROR_CODES.invalidRequest, formatErrorMessage(err));
1099
- }
1100
- const targetId = resolveTargetIdFromBody(body);
1101
- if (Object.hasOwn(body, "selector") && !SELECTOR_ALLOWED_KINDS.has(kind)) return jsonActError(res, 400, ACT_ERROR_CODES.selectorUnsupported, SELECTOR_UNSUPPORTED_MESSAGE);
1102
- const earlyFn = action.kind === "wait" || action.kind === "evaluate" ? action.fn : "";
1103
- if ((action.kind === "evaluate" || action.kind === "wait" && earlyFn) && !ctx.state().resolved.evaluateEnabled) return jsonActError(res, 403, ACT_ERROR_CODES.evaluateDisabled, browserEvaluateDisabledMessage(action.kind === "evaluate" ? "evaluate" : "wait"));
1104
- await withRouteTabContext({
1105
- req,
1106
- res,
1107
- ctx,
1108
- targetId,
1109
- enforceCurrentUrlAllowed: shouldEnforceCurrentUrlForAct(action),
1110
- run: async ({ profileCtx, cdpUrl, tab, resolveTabUrl }) => {
1111
- const evaluateEnabled = ctx.state().resolved.evaluateEnabled;
1112
- const ssrfPolicy = ctx.state().resolved.ssrfPolicy;
1113
- const isExistingSession = getBrowserProfileCapabilities(profileCtx.profile).usesChromeMcp;
1114
- const hasNavigationResultPolicy = Boolean(withBrowserNavigationPolicy(ssrfPolicy).ssrfPolicy);
1115
- const jsonOk = async (extra, options) => {
1116
- const responseTargetId = options?.resolveCurrentTarget && (!isExistingSession || hasNavigationResultPolicy) ? await resolveTargetIdAfterNavigate({
1117
- oldTargetId: tab.targetId,
1118
- navigatedUrl: tab.url,
1119
- listTabs: () => profileCtx.listTabs()
1120
- }) : tab.targetId;
1121
- const url = responseTargetId === tab.targetId ? await resolveTabUrl(tab.url) : await resolveSafeRouteTabUrl({
1122
- ctx,
1123
- profileCtx,
1124
- targetId: responseTargetId,
1125
- fallbackUrl: tab.url
1126
- });
1127
- return res.json({
1128
- ok: true,
1129
- targetId: responseTargetId,
1130
- ...url ? { url } : {},
1131
- ...extra
1132
- });
1133
- };
1134
- if (action.targetId && action.targetId !== tab.targetId) return jsonActError(res, 403, ACT_ERROR_CODES.targetIdMismatch, "action targetId must match request targetId");
1135
- const profileName = profileCtx.profile.name;
1136
- if (isExistingSession) {
1137
- const initialTabTargetIds = hasNavigationResultPolicy ? new Set((await profileCtx.listTabs()).map((currentTab) => currentTab.targetId)) : /* @__PURE__ */ new Set();
1138
- const existingSessionNavigationGuard = {
1139
- profileName,
1140
- profile: profileCtx.profile,
1141
- targetId: tab.targetId,
1142
- ssrfPolicy,
1143
- listTabs: () => profileCtx.listTabs(),
1144
- initialTabTargetIds
1145
- };
1146
- const unsupportedMessage = getExistingSessionUnsupportedMessage(action);
1147
- if (unsupportedMessage) return jsonActError(res, 501, ACT_ERROR_CODES.unsupportedForExistingSession, unsupportedMessage);
1148
- switch (action.kind) {
1149
- case "click":
1150
- await runExistingSessionActionWithNavigationGuard({
1151
- execute: () => clickChromeMcpElement({
1152
- profileName,
1153
- profile: profileCtx.profile,
1154
- targetId: tab.targetId,
1155
- uid: action.ref,
1156
- doubleClick: action.doubleClick ?? false,
1157
- timeoutMs: action.timeoutMs,
1158
- signal: req.signal
1159
- }),
1160
- guard: existingSessionNavigationGuard
1161
- });
1162
- return await jsonOk(void 0, { resolveCurrentTarget: true });
1163
- case "clickCoords":
1164
- await runExistingSessionActionWithNavigationGuard({
1165
- execute: () => clickChromeMcpCoords({
1166
- profileName,
1167
- profile: profileCtx.profile,
1168
- targetId: tab.targetId,
1169
- x: action.x,
1170
- y: action.y,
1171
- doubleClick: action.doubleClick ?? false,
1172
- button: action.button,
1173
- delayMs: action.delayMs
1174
- }),
1175
- guard: existingSessionNavigationGuard
1176
- });
1177
- return await jsonOk(void 0, { resolveCurrentTarget: true });
1178
- case "type":
1179
- await runExistingSessionActionWithNavigationGuard({
1180
- execute: async () => {
1181
- await fillChromeMcpElement({
1182
- profileName,
1183
- profile: profileCtx.profile,
1184
- targetId: tab.targetId,
1185
- uid: action.ref,
1186
- value: action.text
1187
- });
1188
- if (action.submit) await pressChromeMcpKey({
1189
- profileName,
1190
- profile: profileCtx.profile,
1191
- targetId: tab.targetId,
1192
- key: "Enter"
1193
- });
1194
- },
1195
- guard: existingSessionNavigationGuard
1196
- });
1197
- return await jsonOk(void 0, { resolveCurrentTarget: true });
1198
- case "press":
1199
- await runExistingSessionActionWithNavigationGuard({
1200
- execute: () => pressChromeMcpKey({
1201
- profileName,
1202
- profile: profileCtx.profile,
1203
- targetId: tab.targetId,
1204
- key: action.key
1205
- }),
1206
- guard: existingSessionNavigationGuard
1207
- });
1208
- return await jsonOk(void 0, { resolveCurrentTarget: true });
1209
- case "hover":
1210
- await runExistingSessionActionWithNavigationGuard({
1211
- execute: () => hoverChromeMcpElement({
1212
- profileName,
1213
- profile: profileCtx.profile,
1214
- targetId: tab.targetId,
1215
- uid: action.ref
1216
- }),
1217
- guard: existingSessionNavigationGuard
1218
- });
1219
- return await jsonOk();
1220
- case "scrollIntoView":
1221
- await runExistingSessionActionWithNavigationGuard({
1222
- execute: () => evaluateChromeMcpScript({
1223
- profileName,
1224
- profile: profileCtx.profile,
1225
- targetId: tab.targetId,
1226
- fn: `(el) => { el.scrollIntoView({ block: "center", inline: "center" }); return true; }`,
1227
- args: [action.ref]
1228
- }),
1229
- guard: existingSessionNavigationGuard
1230
- });
1231
- return await jsonOk();
1232
- case "drag":
1233
- await runExistingSessionActionWithNavigationGuard({
1234
- execute: () => dragChromeMcpElement({
1235
- profileName,
1236
- profile: profileCtx.profile,
1237
- targetId: tab.targetId,
1238
- fromUid: action.startRef,
1239
- toUid: action.endRef
1240
- }),
1241
- guard: existingSessionNavigationGuard
1242
- });
1243
- return await jsonOk();
1244
- case "select":
1245
- await runExistingSessionActionWithNavigationGuard({
1246
- execute: () => fillChromeMcpElement({
1247
- profileName,
1248
- profile: profileCtx.profile,
1249
- targetId: tab.targetId,
1250
- uid: action.ref,
1251
- value: action.values[0] ?? ""
1252
- }),
1253
- guard: existingSessionNavigationGuard
1254
- });
1255
- return await jsonOk();
1256
- case "fill":
1257
- await runExistingSessionActionWithNavigationGuard({
1258
- execute: () => fillChromeMcpForm({
1259
- profileName,
1260
- profile: profileCtx.profile,
1261
- targetId: tab.targetId,
1262
- elements: action.fields.map((field) => ({
1263
- uid: field.ref,
1264
- value: String(field.value ?? "")
1265
- }))
1266
- }),
1267
- guard: existingSessionNavigationGuard
1268
- });
1269
- return await jsonOk();
1270
- case "resize":
1271
- await resizeChromeMcpPage({
1272
- profileName,
1273
- profile: profileCtx.profile,
1274
- targetId: tab.targetId,
1275
- width: action.width,
1276
- height: action.height
1277
- });
1278
- return await jsonOk();
1279
- case "wait":
1280
- await waitForExistingSessionCondition({
1281
- profileName,
1282
- profile: profileCtx.profile,
1283
- targetId: tab.targetId,
1284
- timeMs: action.timeMs,
1285
- text: action.text,
1286
- textGone: action.textGone,
1287
- selector: action.selector,
1288
- url: action.url,
1289
- loadState: action.loadState,
1290
- fn: action.fn,
1291
- timeoutMs: action.timeoutMs
1292
- });
1293
- return await jsonOk();
1294
- case "evaluate": return await jsonOk({ result: await runExistingSessionActionWithNavigationGuard({
1295
- execute: () => evaluateChromeMcpScript({
1296
- profileName,
1297
- profile: profileCtx.profile,
1298
- targetId: tab.targetId,
1299
- fn: action.fn,
1300
- args: action.ref ? [action.ref] : void 0
1301
- }),
1302
- guard: existingSessionNavigationGuard
1303
- }) });
1304
- case "close":
1305
- await closeChromeMcpTab(profileName, tab.targetId, profileCtx.profile);
1306
- return await jsonOk();
1307
- case "batch": return jsonActError(res, 501, ACT_ERROR_CODES.unsupportedForExistingSession, EXISTING_SESSION_LIMITS.act.batch);
1308
- }
1309
- }
1310
- const pw = await requirePwAi(res, `act:${kind}`);
1311
- if (!pw) return;
1312
- if (action.kind === "batch") {
1313
- const targetIdError = validateBatchTargetIds(action.actions, tab.targetId);
1314
- if (targetIdError) return jsonActError(res, 403, ACT_ERROR_CODES.targetIdMismatch, targetIdError);
1315
- }
1316
- const result = await pw.executeActViaPlaywright({
1317
- cdpUrl,
1318
- action,
1319
- targetId: tab.targetId,
1320
- evaluateEnabled,
1321
- ssrfPolicy,
1322
- signal: req.signal
1323
- });
1324
- if (result.blockedByDialog) return await jsonOk({
1325
- blockedByDialog: true,
1326
- browserState: result.browserState
1327
- });
1328
- switch (action.kind) {
1329
- case "batch": return await jsonOk({ results: result.results ?? [] }, { resolveCurrentTarget: true });
1330
- case "evaluate": return await jsonOk({ result: result.result }, { resolveCurrentTarget: true });
1331
- case "click":
1332
- case "clickCoords": return await jsonOk(void 0, { resolveCurrentTarget: true });
1333
- case "resize": return await jsonOk();
1334
- default: return await jsonOk(void 0, { resolveCurrentTarget: true });
1335
- }
1336
- }
1337
- });
1338
- }));
1339
- registerBrowserAgentActHookRoutes(app, ctx);
1340
- registerBrowserAgentActDownloadRoutes(app, ctx);
1341
- app.post("/response/body", asyncBrowserRoute(async (req, res) => {
1342
- const body = readBody(req);
1343
- const targetId = resolveTargetIdFromBody(body);
1344
- const url = toStringOrEmpty(body.url);
1345
- let timeoutMs;
1346
- let maxChars;
1347
- try {
1348
- timeoutMs = readRouteTimerTimeoutMs(body.timeoutMs);
1349
- maxChars = readRoutePositiveInteger(body.maxChars, "maxChars");
1350
- } catch (err) {
1351
- return jsonError(res, 400, formatErrorMessage(err));
1352
- }
1353
- if (!url) return jsonError(res, 400, "url is required");
1354
- await withRouteTabContext({
1355
- req,
1356
- res,
1357
- ctx,
1358
- targetId,
1359
- enforceCurrentUrlAllowed: true,
1360
- run: async ({ profileCtx, cdpUrl, tab, resolveTabUrl }) => {
1361
- if (getBrowserProfileCapabilities(profileCtx.profile).usesChromeMcp) return jsonError(res, 501, EXISTING_SESSION_LIMITS.responseBody);
1362
- const pw = await requirePwAi(res, "response body");
1363
- if (!pw) return;
1364
- const result = await pw.responseBodyViaPlaywright({
1365
- cdpUrl,
1366
- targetId: tab.targetId,
1367
- url,
1368
- timeoutMs: timeoutMs ?? void 0,
1369
- maxChars: maxChars ?? void 0
1370
- });
1371
- const currentUrl = await resolveTabUrl(tab.url);
1372
- res.json({
1373
- ok: true,
1374
- targetId: tab.targetId,
1375
- ...currentUrl ? { url: currentUrl } : {},
1376
- response: result
1377
- });
1378
- }
1379
- });
1380
- }));
1381
- app.post("/highlight", asyncBrowserRoute(async (req, res) => {
1382
- const body = readBody(req);
1383
- const targetId = resolveTargetIdFromBody(body);
1384
- const ref = toStringOrEmpty(body.ref);
1385
- if (!ref) return jsonError(res, 400, "ref is required");
1386
- await withRouteTabContext({
1387
- req,
1388
- res,
1389
- ctx,
1390
- targetId,
1391
- enforceCurrentUrlAllowed: true,
1392
- run: async ({ profileCtx, cdpUrl, tab, resolveTabUrl }) => {
1393
- const jsonOk = async () => {
1394
- const currentUrl = await resolveTabUrl(tab.url);
1395
- return res.json({
1396
- ok: true,
1397
- targetId: tab.targetId,
1398
- ...currentUrl ? { url: currentUrl } : {}
1399
- });
1400
- };
1401
- if (getBrowserProfileCapabilities(profileCtx.profile).usesChromeMcp) {
1402
- await evaluateChromeMcpScript({
1403
- profileName: profileCtx.profile.name,
1404
- profile: profileCtx.profile,
1405
- targetId: tab.targetId,
1406
- args: [ref],
1407
- fn: `(el) => {
1408
- if (!(el instanceof Element)) {
1409
- return false;
1410
- }
1411
- el.scrollIntoView({ block: "center", inline: "center" });
1412
- const previousOutline = el.style.outline;
1413
- const previousOffset = el.style.outlineOffset;
1414
- el.style.outline = "3px solid #FF4500";
1415
- el.style.outlineOffset = "2px";
1416
- setTimeout(() => {
1417
- el.style.outline = previousOutline;
1418
- el.style.outlineOffset = previousOffset;
1419
- }, 2000);
1420
- return true;
1421
- }`
1422
- });
1423
- return await jsonOk();
1424
- }
1425
- const pw = await requirePwAi(res, "highlight");
1426
- if (!pw) return;
1427
- await pw.highlightViaPlaywright({
1428
- cdpUrl,
1429
- targetId: tab.targetId,
1430
- ref
1431
- });
1432
- await jsonOk();
1433
- }
1434
- });
1435
- }));
1436
- }
1437
- //#endregion
1438
- //#region extensions/browser/src/browser/routes/agent.debug.ts
1439
- function browserDebugTargetPayload(targetId, url) {
1440
- return {
1441
- ok: true,
1442
- targetId,
1443
- ...url ? { url } : {}
1444
- };
1445
- }
1446
- async function sendPlaywrightDebugCollection(params) {
1447
- await withPlaywrightRouteContext({
1448
- req: params.req,
1449
- res: params.res,
1450
- ctx: params.ctx,
1451
- targetId: params.targetId,
1452
- feature: params.feature,
1453
- enforceCurrentUrlAllowed: true,
1454
- run: async ({ cdpUrl, tab, pw, resolveTabUrl }) => {
1455
- const result = await params.collect({
1456
- cdpUrl,
1457
- targetId: tab.targetId,
1458
- pw
1459
- });
1460
- const url = await resolveTabUrl(tab.url);
1461
- params.res.json({
1462
- ...browserDebugTargetPayload(tab.targetId, url),
1463
- ...result
1464
- });
1465
- }
1466
- });
1467
- }
1468
- function registerBrowserAgentDebugRoutes(app, ctx) {
1469
- app.get("/console", asyncBrowserRoute(async (req, res) => {
1470
- const targetId = resolveTargetIdFromQuery(req.query);
1471
- const level = typeof req.query.level === "string" ? req.query.level : "";
1472
- await withPlaywrightRouteContext({
1473
- req,
1474
- res,
1475
- ctx,
1476
- targetId,
1477
- feature: "console messages",
1478
- enforceCurrentUrlAllowed: true,
1479
- run: async ({ cdpUrl, tab, pw, resolveTabUrl }) => {
1480
- const messages = await pw.getConsoleMessagesViaPlaywright({
1481
- cdpUrl,
1482
- targetId: tab.targetId,
1483
- level: normalizeOptionalString$1(level)
1484
- });
1485
- const url = await resolveTabUrl(tab.url);
1486
- res.json({
1487
- ...browserDebugTargetPayload(tab.targetId, url),
1488
- messages
1489
- });
1490
- }
1491
- });
1492
- }));
1493
- app.get("/errors", asyncBrowserRoute(async (req, res) => {
1494
- const targetId = resolveTargetIdFromQuery(req.query);
1495
- const clear = toBoolean(req.query.clear) ?? false;
1496
- await sendPlaywrightDebugCollection({
1497
- req,
1498
- res,
1499
- ctx,
1500
- targetId,
1501
- feature: "page errors",
1502
- collect: async ({ cdpUrl, targetId, pw }) => await pw.getPageErrorsViaPlaywright({
1503
- cdpUrl,
1504
- targetId,
1505
- clear
1506
- })
1507
- });
1508
- }));
1509
- app.get("/requests", asyncBrowserRoute(async (req, res) => {
1510
- const targetId = resolveTargetIdFromQuery(req.query);
1511
- const filter = typeof req.query.filter === "string" ? req.query.filter : "";
1512
- const clear = toBoolean(req.query.clear) ?? false;
1513
- await sendPlaywrightDebugCollection({
1514
- req,
1515
- res,
1516
- ctx,
1517
- targetId,
1518
- feature: "network requests",
1519
- collect: async ({ cdpUrl, targetId, pw }) => await pw.getNetworkRequestsViaPlaywright({
1520
- cdpUrl,
1521
- targetId,
1522
- filter: normalizeOptionalString$1(filter),
1523
- clear
1524
- })
1525
- });
1526
- }));
1527
- app.get("/dialogs", asyncBrowserRoute(async (req, res) => {
1528
- await withPlaywrightRouteContext({
1529
- req,
1530
- res,
1531
- ctx,
1532
- targetId: resolveTargetIdFromQuery(req.query),
1533
- feature: "dialog state",
1534
- enforceCurrentUrlAllowed: true,
1535
- run: async ({ cdpUrl, tab, pw, resolveTabUrl }) => {
1536
- const browserState = await pw.getObservedBrowserStateViaPlaywright({
1537
- cdpUrl,
1538
- targetId: tab.targetId,
1539
- ssrfPolicy: ctx.state().resolved.ssrfPolicy
1540
- });
1541
- const url = await resolveTabUrl(tab.url);
1542
- res.json({
1543
- ...browserDebugTargetPayload(tab.targetId, url),
1544
- browserState
1545
- });
1546
- }
1547
- });
1548
- }));
1549
- app.post("/trace/start", asyncBrowserRoute(async (req, res) => {
1550
- const body = readBody(req);
1551
- const targetId = resolveTargetIdFromBody(body);
1552
- const screenshots = toBoolean(body.screenshots) ?? void 0;
1553
- const snapshots = toBoolean(body.snapshots) ?? void 0;
1554
- const sources = toBoolean(body.sources) ?? void 0;
1555
- await withPlaywrightRouteContext({
1556
- req,
1557
- res,
1558
- ctx,
1559
- targetId,
1560
- feature: "trace start",
1561
- enforceCurrentUrlAllowed: true,
1562
- run: async ({ cdpUrl, tab, pw, resolveTabUrl }) => {
1563
- await pw.traceStartViaPlaywright({
1564
- cdpUrl,
1565
- targetId: tab.targetId,
1566
- screenshots,
1567
- snapshots,
1568
- sources
1569
- });
1570
- const url = await resolveTabUrl(tab.url);
1571
- res.json(browserDebugTargetPayload(tab.targetId, url));
1572
- }
1573
- });
1574
- }));
1575
- app.post("/trace/stop", asyncBrowserRoute(async (req, res) => {
1576
- const body = readBody(req);
1577
- const targetId = resolveTargetIdFromBody(body);
1578
- const out = toStringOrEmpty(body.path) || "";
1579
- await withPlaywrightRouteContext({
1580
- req,
1581
- res,
1582
- ctx,
1583
- targetId,
1584
- feature: "trace stop",
1585
- enforceCurrentUrlAllowed: true,
1586
- run: async ({ cdpUrl, tab, pw, resolveTabUrl }) => {
1587
- const tracePath = await resolveWritableOutputPathOrRespond({
1588
- res,
1589
- rootDir: DEFAULT_TRACE_DIR,
1590
- requestedPath: out,
1591
- scopeLabel: "trace directory",
1592
- defaultFileName: `browser-trace-${crypto.randomUUID()}.zip`,
1593
- ensureRootDir: true
1594
- });
1595
- if (!tracePath) return;
1596
- await pw.traceStopViaPlaywright({
1597
- cdpUrl,
1598
- targetId: tab.targetId,
1599
- path: tracePath
1600
- });
1601
- const url = await resolveTabUrl(tab.url);
1602
- res.json({
1603
- ...browserDebugTargetPayload(tab.targetId, url),
1604
- path: path.resolve(tracePath)
1605
- });
1606
- }
1607
- });
1608
- }));
1609
- }
1610
- //#endregion
1611
- //#region extensions/browser/src/browser/chrome-mcp.snapshot.ts
1612
- function normalizeRole(node) {
1613
- return normalizeLowercaseStringOrEmpty(node.role) || "generic";
1614
- }
1615
- function escapeQuoted(value) {
1616
- return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
1617
- }
1618
- function shouldIncludeNode(params) {
1619
- if (params.options?.interactive && !INTERACTIVE_ROLES.has(params.role)) return false;
1620
- if (params.options?.compact && STRUCTURAL_ROLES.has(params.role) && !params.name) return false;
1621
- return true;
1622
- }
1623
- function shouldCreateRef(role, name) {
1624
- return INTERACTIVE_ROLES.has(role) || CONTENT_ROLES.has(role) && Boolean(name);
1625
- }
1626
- function createDuplicateTracker() {
1627
- return {
1628
- counts: /* @__PURE__ */ new Map(),
1629
- keysByRef: /* @__PURE__ */ new Map(),
1630
- duplicates: /* @__PURE__ */ new Set()
1631
- };
1632
- }
1633
- function registerRef(tracker, ref, role, name) {
1634
- const key = `${role}:${name ?? ""}`;
1635
- const count = tracker.counts.get(key) ?? 0;
1636
- tracker.counts.set(key, count + 1);
1637
- tracker.keysByRef.set(ref, key);
1638
- if (count > 0) {
1639
- tracker.duplicates.add(key);
1640
- return count;
1641
- }
1642
- }
1643
- function flattenChromeMcpSnapshotToAriaNodes(root, limit = 500) {
1644
- const boundedLimit = Math.max(1, Math.min(2e3, Math.floor(limit)));
1645
- const out = [];
1646
- const visit = (node, depth) => {
1647
- if (out.length >= boundedLimit) return;
1648
- const ref = normalizeString(node.id);
1649
- if (ref) out.push({
1650
- ref,
1651
- role: normalizeRole(node),
1652
- name: normalizeString(node.name) ?? "",
1653
- value: normalizeString(node.value),
1654
- description: normalizeString(node.description),
1655
- depth
1656
- });
1657
- for (const child of node.children ?? []) {
1658
- visit(child, depth + 1);
1659
- if (out.length >= boundedLimit) return;
1660
- }
1661
- };
1662
- visit(root, 0);
1663
- return out;
1664
- }
1665
- function buildAiSnapshotFromChromeMcpSnapshot(params) {
1666
- const refs = {};
1667
- const tracker = createDuplicateTracker();
1668
- const lines = [];
1669
- const visit = (node, depth) => {
1670
- const role = normalizeRole(node);
1671
- const name = normalizeString(node.name);
1672
- const value = normalizeString(node.value);
1673
- const description = normalizeString(node.description);
1674
- const maxDepth = params.options?.maxDepth;
1675
- if (maxDepth !== void 0 && depth > maxDepth) return;
1676
- if (shouldIncludeNode({
1677
- role,
1678
- name,
1679
- options: params.options
1680
- })) {
1681
- let line = `${" ".repeat(depth)}- ${role}`;
1682
- if (name) line += ` "${escapeQuoted(name)}"`;
1683
- const ref = normalizeString(node.id);
1684
- if (ref && shouldCreateRef(role, name)) {
1685
- const nth = registerRef(tracker, ref, role, name);
1686
- refs[ref] = nth === void 0 ? {
1687
- role,
1688
- name
1689
- } : {
1690
- role,
1691
- name,
1692
- nth
1693
- };
1694
- line += ` [ref=${ref}]`;
1695
- }
1696
- if (value) line += ` value="${escapeQuoted(value)}"`;
1697
- if (description) line += ` description="${escapeQuoted(description)}"`;
1698
- lines.push(line);
1699
- }
1700
- for (const child of node.children ?? []) visit(child, depth + 1);
1701
- };
1702
- visit(params.root, 0);
1703
- for (const [ref, data] of Object.entries(refs)) {
1704
- const key = tracker.keysByRef.get(ref);
1705
- if (key && !tracker.duplicates.has(key)) delete data.nth;
1706
- }
1707
- let snapshot = lines.join("\n");
1708
- let truncated = false;
1709
- const maxChars = typeof params.maxChars === "number" && Number.isFinite(params.maxChars) && params.maxChars > 0 ? Math.floor(params.maxChars) : void 0;
1710
- if (maxChars && snapshot.length > maxChars) {
1711
- snapshot = `${snapshot.slice(0, maxChars)}\n\n[...TRUNCATED - page too large]`;
1712
- truncated = true;
1713
- }
1714
- const stats = getRoleSnapshotStats(snapshot, refs);
1715
- return truncated ? {
1716
- snapshot,
1717
- truncated,
1718
- refs,
1719
- stats
1720
- } : {
1721
- snapshot,
1722
- refs,
1723
- stats
1724
- };
1725
- }
1726
- //#endregion
1727
- //#region extensions/browser/src/browser/screenshot.ts
1728
- const DEFAULT_BROWSER_SCREENSHOT_MAX_SIDE = 2e3;
1729
- const DEFAULT_BROWSER_SCREENSHOT_MAX_BYTES = 5 * 1024 * 1024;
1730
- async function normalizeBrowserScreenshot(buffer, opts) {
1731
- const maxSide = Math.max(1, Math.round(opts?.maxSide ?? 2e3));
1732
- const maxBytes = Math.max(1, Math.round(opts?.maxBytes ?? 5242880));
1733
- const meta = await getImageMetadata(buffer);
1734
- const width = meta?.width ?? 0;
1735
- const height = meta?.height ?? 0;
1736
- const maxDim = Math.max(width, height);
1737
- if (buffer.byteLength <= maxBytes && (maxDim === 0 || width <= maxSide && height <= maxSide)) return { buffer };
1738
- const sideGrid = buildImageResizeSideGrid(maxSide, maxDim > 0 ? Math.min(maxSide, maxDim) : maxSide);
1739
- let smallest = null;
1740
- let processorUnavailableError;
1741
- for (const side of sideGrid) {
1742
- for (const quality of IMAGE_REDUCE_QUALITY_STEPS) {
1743
- let out;
1744
- try {
1745
- out = await resizeToJpeg({
1746
- buffer,
1747
- maxSide: side,
1748
- quality,
1749
- withoutEnlargement: true
1750
- });
1751
- } catch (err) {
1752
- if (isImageProcessorUnavailableError(err)) {
1753
- processorUnavailableError = err;
1754
- break;
1755
- }
1756
- throw err;
1757
- }
1758
- if (!smallest || out.byteLength < smallest.size) smallest = {
1759
- buffer: out,
1760
- size: out.byteLength
1761
- };
1762
- if (out.byteLength <= maxBytes) return {
1763
- buffer: out,
1764
- contentType: "image/jpeg"
1765
- };
1766
- }
1767
- if (processorUnavailableError) break;
1768
- }
1769
- if (processorUnavailableError) throw processorUnavailableError;
1770
- const best = smallest?.buffer ?? buffer;
1771
- throw new Error(`Browser screenshot could not be reduced below ${(maxBytes / (1024 * 1024)).toFixed(0)}MB (got ${(best.byteLength / (1024 * 1024)).toFixed(2)}MB)`);
1772
- }
1773
- //#endregion
1774
- //#region extensions/browser/src/browser/routes/agent.snapshot.plan.ts
1775
- function resolveSnapshotPlan(params) {
1776
- const mode = params.query.mode === "efficient" ? "efficient" : void 0;
1777
- const labels = toBoolean(params.query.labels) ?? void 0;
1778
- const urls = toBoolean(params.query.urls) ?? void 0;
1779
- const explicitFormat = params.query.format === "aria" ? "aria" : params.query.format === "ai" ? "ai" : void 0;
1780
- const format = resolveDefaultSnapshotFormat({
1781
- profile: params.profile,
1782
- hasPlaywright: params.hasPlaywright,
1783
- explicitFormat,
1784
- mode
1785
- });
1786
- const limit = parseStrictPositiveInteger(params.query.limit);
1787
- const hasMaxChars = Object.hasOwn(params.query, "maxChars");
1788
- const maxCharsRaw = parseStrictNonNegativeInteger(params.query.maxChars);
1789
- const resolvedMaxChars = format === "ai" ? hasMaxChars ? maxCharsRaw === void 0 ? mode === "efficient" ? DEFAULT_AI_SNAPSHOT_EFFICIENT_MAX_CHARS : DEFAULT_AI_SNAPSHOT_MAX_CHARS : maxCharsRaw !== void 0 && maxCharsRaw > 0 ? maxCharsRaw : void 0 : mode === "efficient" ? DEFAULT_AI_SNAPSHOT_EFFICIENT_MAX_CHARS : DEFAULT_AI_SNAPSHOT_MAX_CHARS : void 0;
1790
- const interactiveRaw = toBoolean(params.query.interactive);
1791
- const compactRaw = toBoolean(params.query.compact);
1792
- const depthRaw = parseStrictNonNegativeInteger(params.query.depth);
1793
- const refsModeRaw = toStringOrEmpty(params.query.refs).trim();
1794
- const refsMode = refsModeRaw === "aria" ? "aria" : refsModeRaw === "role" ? "role" : void 0;
1795
- const interactive = interactiveRaw ?? (mode === "efficient" ? true : void 0);
1796
- const compact = compactRaw ?? (mode === "efficient" ? true : void 0);
1797
- const depth = depthRaw ?? (mode === "efficient" ? 6 : void 0);
1798
- const selectorValue = normalizeOptionalString$1(toStringOrEmpty(params.query.selector));
1799
- const frameSelectorValue = normalizeOptionalString$1(toStringOrEmpty(params.query.frame));
1800
- const timeoutMsRaw = parseStrictPositiveInteger(params.query.timeoutMs);
1801
- return {
1802
- format,
1803
- mode,
1804
- labels,
1805
- urls,
1806
- limit,
1807
- resolvedMaxChars,
1808
- interactive,
1809
- compact,
1810
- depth,
1811
- refsMode,
1812
- selectorValue,
1813
- frameSelectorValue,
1814
- timeoutMs: timeoutMsRaw !== void 0 ? normalizeBrowserTimerDelayMs(timeoutMsRaw) : void 0,
1815
- wantsRoleSnapshot: labels === true || urls === true || mode === "efficient" || interactive === true || compact === true || depth !== void 0 || Boolean(selectorValue) || Boolean(frameSelectorValue)
1816
- };
1817
- }
1818
- //#endregion
1819
- //#region extensions/browser/src/browser/routes/agent.snapshot.ts
1820
- const CHROME_MCP_OVERLAY_ATTR = "data-fengming-mcp-overlay";
1821
- async function collectChromeMcpSnapshotUrls(params) {
1822
- const result = await evaluateChromeMcpScript({
1823
- profileName: params.profileName,
1824
- profile: params.profile,
1825
- userDataDir: params.userDataDir,
1826
- targetId: params.targetId,
1827
- fn: `() => {
1828
- const seen = new Set();
1829
- const out = [];
1830
- for (const anchor of Array.from(document.querySelectorAll("a[href]"))) {
1831
- const href = anchor.href || "";
1832
- if (!href || seen.has(href)) continue;
1833
- const text = (anchor.innerText || anchor.textContent || anchor.getAttribute("aria-label") || "")
1834
- .replace(/\\s+/g, " ")
1835
- .trim()
1836
- .slice(0, 120) || href;
1837
- seen.add(href);
1838
- out.push({ text, url: href });
1839
- if (out.length >= 100) break;
1840
- }
1841
- return out;
1842
- }`
1843
- }).catch(() => []);
1844
- return Array.isArray(result) ? result.filter((entry) => entry && typeof entry === "object" && typeof entry.text === "string" && typeof entry.url === "string") : [];
1845
- }
1846
- async function clearChromeMcpOverlay(params) {
1847
- await evaluateChromeMcpScript({
1848
- profileName: params.profileName,
1849
- profile: params.profile,
1850
- userDataDir: params.userDataDir,
1851
- targetId: params.targetId,
1852
- fn: `() => {
1853
- document.querySelectorAll("[${CHROME_MCP_OVERLAY_ATTR}]").forEach((node) => node.remove());
1854
- return true;
1855
- }`
1856
- }).catch(() => {});
1857
- }
1858
- async function renderChromeMcpLabels(params) {
1859
- const refList = JSON.stringify(params.refs);
1860
- const result = await evaluateChromeMcpScript({
1861
- profileName: params.profileName,
1862
- profile: params.profile,
1863
- userDataDir: params.userDataDir,
1864
- targetId: params.targetId,
1865
- args: params.refs,
1866
- fn: `(...elements) => {
1867
- const refs = ${refList};
1868
- document.querySelectorAll("[${CHROME_MCP_OVERLAY_ATTR}]").forEach((node) => node.remove());
1869
- const root = document.createElement("div");
1870
- root.setAttribute("${CHROME_MCP_OVERLAY_ATTR}", "labels");
1871
- root.style.position = "fixed";
1872
- root.style.inset = "0";
1873
- root.style.pointerEvents = "none";
1874
- root.style.zIndex = "2147483647";
1875
- let labels = 0;
1876
- let skipped = 0;
1877
- elements.forEach((el, index) => {
1878
- if (!(el instanceof Element)) {
1879
- skipped += 1;
1880
- return;
1881
- }
1882
- const rect = el.getBoundingClientRect();
1883
- if (rect.width <= 0 && rect.height <= 0) {
1884
- skipped += 1;
1885
- return;
1886
- }
1887
- labels += 1;
1888
- const badge = document.createElement("div");
1889
- badge.setAttribute("${CHROME_MCP_OVERLAY_ATTR}", "label");
1890
- badge.textContent = refs[index] || String(labels);
1891
- badge.style.position = "fixed";
1892
- badge.style.left = \`\${Math.max(0, rect.left)}px\`;
1893
- badge.style.top = \`\${Math.max(0, rect.top)}px\`;
1894
- badge.style.transform = "translateY(-100%)";
1895
- badge.style.padding = "2px 6px";
1896
- badge.style.borderRadius = "999px";
1897
- badge.style.background = "#FF4500";
1898
- badge.style.color = "#fff";
1899
- badge.style.font = "600 12px ui-monospace, SFMono-Regular, Menlo, monospace";
1900
- badge.style.boxShadow = "0 2px 6px rgba(0,0,0,0.35)";
1901
- badge.style.whiteSpace = "nowrap";
1902
- root.appendChild(badge);
1903
- });
1904
- document.documentElement.appendChild(root);
1905
- return { labels, skipped };
1906
- }`
1907
- });
1908
- return {
1909
- labels: result && typeof result === "object" && typeof result.labels === "number" ? result.labels : 0,
1910
- skipped: result && typeof result === "object" && typeof result.skipped === "number" ? result.skipped : 0
1911
- };
1912
- }
1913
- async function saveNormalizedScreenshotResponse(params) {
1914
- const normalized = await normalizeBrowserScreenshot(params.buffer, {
1915
- maxSide: DEFAULT_BROWSER_SCREENSHOT_MAX_SIDE,
1916
- maxBytes: DEFAULT_BROWSER_SCREENSHOT_MAX_BYTES
1917
- });
1918
- await saveBrowserMediaResponse({
1919
- res: params.res,
1920
- buffer: normalized.buffer,
1921
- contentType: normalized.contentType ?? `image/${params.type}`,
1922
- maxBytes: DEFAULT_BROWSER_SCREENSHOT_MAX_BYTES,
1923
- targetId: params.targetId,
1924
- url: params.url,
1925
- labels: params.labels,
1926
- labelsCount: params.labelsCount,
1927
- labelsSkipped: params.labelsSkipped
1928
- });
1929
- }
1930
- async function saveBrowserMediaResponse(params) {
1931
- await ensureMediaDir();
1932
- const saved = await saveMediaBuffer(params.buffer, params.contentType, "browser", params.maxBytes);
1933
- params.res.json({
1934
- ok: true,
1935
- path: path.resolve(saved.path),
1936
- targetId: params.targetId,
1937
- url: params.url,
1938
- ...params.labels ? { labels: true } : {},
1939
- ...typeof params.labelsCount === "number" ? { labelsCount: params.labelsCount } : {},
1940
- ...typeof params.labelsSkipped === "number" ? { labelsSkipped: params.labelsSkipped } : {}
1941
- });
1942
- }
1943
- function hasObservableBrowserState(state) {
1944
- if (!state || typeof state !== "object") return false;
1945
- const dialogs = state.dialogs;
1946
- return Boolean(dialogs?.pending?.length || dialogs?.recent?.length);
1947
- }
1948
- function hasPendingDialogs(state) {
1949
- if (!state || typeof state !== "object") return false;
1950
- const dialogs = state.dialogs;
1951
- return Boolean(dialogs?.pending?.length);
1952
- }
1953
- function browserStateResponseFields(state) {
1954
- return hasObservableBrowserState(state) ? { browserState: state } : {};
1955
- }
1956
- function registerBrowserAgentSnapshotRoutes(app, ctx) {
1957
- app.post("/navigate", asyncBrowserRoute(async (req, res) => {
1958
- const body = readBody(req);
1959
- const url = toStringOrEmpty(body.url);
1960
- const targetId = toStringOrEmpty(body.targetId) || void 0;
1961
- if (!url) return jsonError(res, 400, "url is required");
1962
- await withRouteTabContext({
1963
- req,
1964
- res,
1965
- ctx,
1966
- targetId,
1967
- run: async ({ profileCtx, tab, cdpUrl }) => {
1968
- if (getBrowserProfileCapabilities(profileCtx.profile).usesChromeMcp) {
1969
- const ssrfPolicyOpts = browserNavigationPolicyForProfile(ctx, profileCtx);
1970
- await assertBrowserNavigationAllowed({
1971
- url,
1972
- ...ssrfPolicyOpts
1973
- });
1974
- const result = await navigateChromeMcpPage({
1975
- profileName: profileCtx.profile.name,
1976
- profile: profileCtx.profile,
1977
- targetId: tab.targetId,
1978
- url
1979
- });
1980
- await assertBrowserNavigationResultAllowed({
1981
- url: result.url,
1982
- ...ssrfPolicyOpts
1983
- });
1984
- return res.json({
1985
- ok: true,
1986
- targetId: tab.targetId,
1987
- ...result
1988
- });
1989
- }
1990
- const pw = await requirePwAi(res, "navigate");
1991
- if (!pw) return;
1992
- const result = await pw.navigateViaPlaywright({
1993
- cdpUrl,
1994
- targetId: tab.targetId,
1995
- url,
1996
- ...browserNavigationPolicyForProfile(ctx, profileCtx)
1997
- });
1998
- const currentTargetId = await resolveTargetIdAfterNavigate({
1999
- oldTargetId: tab.targetId,
2000
- navigatedUrl: result.url,
2001
- listTabs: () => profileCtx.listTabs()
2002
- });
2003
- res.json({
2004
- ok: true,
2005
- targetId: currentTargetId,
2006
- ...result
2007
- });
2008
- }
2009
- });
2010
- }));
2011
- app.post("/pdf", asyncBrowserRoute(async (req, res) => {
2012
- const targetId = toStringOrEmpty(readBody(req).targetId) || void 0;
2013
- const profileCtx = resolveProfileContext(req, res, ctx);
2014
- if (!profileCtx) return;
2015
- if (getBrowserProfileCapabilities(profileCtx.profile).usesChromeMcp) return jsonError(res, 501, EXISTING_SESSION_LIMITS.snapshot.pdfUnsupported);
2016
- await withPlaywrightRouteContext({
2017
- req,
2018
- res,
2019
- ctx,
2020
- targetId,
2021
- feature: "pdf",
2022
- enforceCurrentUrlAllowed: true,
2023
- run: async ({ cdpUrl, tab, pw }) => {
2024
- const pdf = await pw.pdfViaPlaywright({
2025
- cdpUrl,
2026
- targetId: tab.targetId
2027
- });
2028
- await saveBrowserMediaResponse({
2029
- res,
2030
- buffer: pdf.buffer,
2031
- contentType: "application/pdf",
2032
- maxBytes: pdf.buffer.byteLength,
2033
- targetId: tab.targetId,
2034
- url: tab.url
2035
- });
2036
- }
2037
- });
2038
- }));
2039
- app.post("/screenshot", asyncBrowserRoute(async (req, res) => {
2040
- const body = readBody(req);
2041
- const targetId = toStringOrEmpty(body.targetId) || void 0;
2042
- const fullPage = toBoolean(body.fullPage) ?? false;
2043
- const ref = toStringOrEmpty(body.ref) || void 0;
2044
- const element = toStringOrEmpty(body.element) || void 0;
2045
- const labels = toBoolean(body.labels) ?? false;
2046
- const type = body.type === "jpeg" ? "jpeg" : "png";
2047
- let timeoutMs;
2048
- try {
2049
- const timeoutMsRaw = readRoutePositiveInteger(body.timeoutMs, "timeoutMs");
2050
- timeoutMs = timeoutMsRaw !== void 0 ? normalizeBrowserTimerDelayMs(timeoutMsRaw) : DEFAULT_BROWSER_SCREENSHOT_TIMEOUT_MS;
2051
- } catch (err) {
2052
- return jsonError(res, 400, String(err instanceof Error ? err.message : err));
2053
- }
2054
- if (fullPage && (ref || element)) return jsonError(res, 400, "fullPage is not supported for element screenshots");
2055
- await withRouteTabContext({
2056
- req,
2057
- res,
2058
- ctx,
2059
- targetId,
2060
- enforceCurrentUrlAllowed: true,
2061
- run: async ({ profileCtx, tab, cdpUrl }) => {
2062
- if (getBrowserProfileCapabilities(profileCtx.profile).usesChromeMcp) {
2063
- const ssrfPolicyOpts = browserNavigationPolicyForProfile(ctx, profileCtx);
2064
- if (ssrfPolicyOpts.ssrfPolicy) await assertBrowserNavigationResultAllowed({
2065
- url: tab.url,
2066
- ...ssrfPolicyOpts
2067
- });
2068
- if (element) return jsonError(res, 400, EXISTING_SESSION_LIMITS.snapshot.screenshotElement);
2069
- if (labels) {
2070
- const built = buildAiSnapshotFromChromeMcpSnapshot({ root: await takeChromeMcpSnapshot({
2071
- profileName: profileCtx.profile.name,
2072
- profile: profileCtx.profile,
2073
- targetId: tab.targetId
2074
- }) });
2075
- const labelResult = await renderChromeMcpLabels({
2076
- profileName: profileCtx.profile.name,
2077
- profile: profileCtx.profile,
2078
- targetId: tab.targetId,
2079
- refs: Object.keys(built.refs)
2080
- });
2081
- try {
2082
- await saveNormalizedScreenshotResponse({
2083
- res,
2084
- buffer: await takeChromeMcpScreenshot({
2085
- profileName: profileCtx.profile.name,
2086
- profile: profileCtx.profile,
2087
- targetId: tab.targetId,
2088
- fullPage,
2089
- format: type,
2090
- timeoutMs
2091
- }),
2092
- type,
2093
- targetId: tab.targetId,
2094
- url: tab.url,
2095
- labels: true,
2096
- labelsCount: labelResult.labels,
2097
- labelsSkipped: labelResult.skipped
2098
- });
2099
- } finally {
2100
- await clearChromeMcpOverlay({
2101
- profileName: profileCtx.profile.name,
2102
- profile: profileCtx.profile,
2103
- targetId: tab.targetId
2104
- });
2105
- }
2106
- return;
2107
- }
2108
- await saveNormalizedScreenshotResponse({
2109
- res,
2110
- buffer: await takeChromeMcpScreenshot({
2111
- profileName: profileCtx.profile.name,
2112
- profile: profileCtx.profile,
2113
- targetId: tab.targetId,
2114
- uid: ref,
2115
- fullPage,
2116
- format: type,
2117
- timeoutMs
2118
- }),
2119
- type,
2120
- targetId: tab.targetId,
2121
- url: tab.url
2122
- });
2123
- return;
2124
- }
2125
- let buffer;
2126
- if (labels || shouldUsePlaywrightForScreenshot({
2127
- profile: profileCtx.profile,
2128
- wsUrl: tab.wsUrl,
2129
- ref,
2130
- element
2131
- })) {
2132
- const pw = await requirePwAi(res, "screenshot");
2133
- if (!pw) return;
2134
- if (labels) {
2135
- const snap = await pw.snapshotRoleViaPlaywright({
2136
- cdpUrl,
2137
- targetId: tab.targetId,
2138
- ssrfPolicy: ctx.state().resolved.ssrfPolicy
2139
- });
2140
- const labeled = await pw.screenshotWithLabelsViaPlaywright({
2141
- cdpUrl,
2142
- targetId: tab.targetId,
2143
- refs: snap.refs,
2144
- type,
2145
- timeoutMs
2146
- });
2147
- await saveNormalizedScreenshotResponse({
2148
- res,
2149
- buffer: labeled.buffer,
2150
- type,
2151
- targetId: tab.targetId,
2152
- url: tab.url,
2153
- labels: true,
2154
- labelsCount: labeled.labels,
2155
- labelsSkipped: labeled.skipped
2156
- });
2157
- return;
2158
- }
2159
- buffer = (await pw.takeScreenshotViaPlaywright({
2160
- cdpUrl,
2161
- targetId: tab.targetId,
2162
- ref,
2163
- element,
2164
- fullPage,
2165
- type,
2166
- timeoutMs
2167
- })).buffer;
2168
- } else buffer = await captureScreenshot({
2169
- wsUrl: tab.wsUrl ?? "",
2170
- fullPage,
2171
- format: type,
2172
- quality: type === "jpeg" ? 85 : void 0,
2173
- timeoutMs
2174
- });
2175
- await saveNormalizedScreenshotResponse({
2176
- res,
2177
- buffer,
2178
- type,
2179
- targetId: tab.targetId,
2180
- url: tab.url
2181
- });
2182
- }
2183
- });
2184
- }));
2185
- app.get("/snapshot", asyncBrowserRoute(async (req, res) => {
2186
- const profileCtx = resolveProfileContext(req, res, ctx);
2187
- if (!profileCtx) return;
2188
- const targetId = typeof req.query.targetId === "string" ? req.query.targetId.trim() : "";
2189
- const pwModule = await getPwAiModule();
2190
- const hasPlaywright = Boolean(pwModule);
2191
- const plan = resolveSnapshotPlan({
2192
- profile: profileCtx.profile,
2193
- query: req.query,
2194
- hasPlaywright
2195
- });
2196
- try {
2197
- const tab = await profileCtx.ensureTabAvailable(targetId || void 0);
2198
- const usesChromeMcp = getBrowserProfileCapabilities(profileCtx.profile).usesChromeMcp;
2199
- const ssrfPolicyOpts = browserNavigationPolicyForProfile(ctx, profileCtx);
2200
- if ((plan.labels || plan.mode === "efficient") && plan.format === "aria") return jsonError(res, 400, "labels/mode=efficient require format=ai");
2201
- if (usesChromeMcp && (plan.selectorValue || plan.frameSelectorValue)) return jsonError(res, 400, EXISTING_SESSION_LIMITS.snapshot.snapshotSelector);
2202
- if (ssrfPolicyOpts.ssrfPolicy) await assertBrowserNavigationResultAllowed({
2203
- url: tab.url,
2204
- ...ssrfPolicyOpts
2205
- });
2206
- let observedBrowserState;
2207
- if (!usesChromeMcp && pwModule) observedBrowserState = await pwModule.getObservedBrowserStateViaPlaywright({
2208
- cdpUrl: profileCtx.profile.cdpUrl,
2209
- targetId: tab.targetId,
2210
- ssrfPolicy: ctx.state().resolved.ssrfPolicy
2211
- }).catch(() => void 0);
2212
- if (usesChromeMcp) {
2213
- const snapshot = await takeChromeMcpSnapshot({
2214
- profileName: profileCtx.profile.name,
2215
- profile: profileCtx.profile,
2216
- targetId: tab.targetId,
2217
- timeoutMs: plan.timeoutMs
2218
- });
2219
- if (plan.format === "aria") return res.json({
2220
- ok: true,
2221
- format: "aria",
2222
- targetId: tab.targetId,
2223
- url: tab.url,
2224
- nodes: flattenChromeMcpSnapshotToAriaNodes(snapshot, plan.limit)
2225
- });
2226
- const built = buildAiSnapshotFromChromeMcpSnapshot({
2227
- root: snapshot,
2228
- options: {
2229
- interactive: plan.interactive ?? void 0,
2230
- compact: plan.compact ?? void 0,
2231
- maxDepth: plan.depth ?? void 0
2232
- },
2233
- maxChars: plan.resolvedMaxChars
2234
- });
2235
- const builtWithUrls = plan.urls ? {
2236
- ...built,
2237
- snapshot: appendSnapshotUrls(built.snapshot, await collectChromeMcpSnapshotUrls({
2238
- profileName: profileCtx.profile.name,
2239
- profile: profileCtx.profile,
2240
- targetId: tab.targetId
2241
- }))
2242
- } : built;
2243
- if (plan.labels) {
2244
- const refs = Object.keys(builtWithUrls.refs);
2245
- const labelResult = await renderChromeMcpLabels({
2246
- profileName: profileCtx.profile.name,
2247
- profile: profileCtx.profile,
2248
- targetId: tab.targetId,
2249
- refs
2250
- });
2251
- try {
2252
- const normalized = await normalizeBrowserScreenshot(await takeChromeMcpScreenshot({
2253
- profileName: profileCtx.profile.name,
2254
- profile: profileCtx.profile,
2255
- targetId: tab.targetId,
2256
- format: "png",
2257
- timeoutMs: plan.timeoutMs
2258
- }), {
2259
- maxSide: DEFAULT_BROWSER_SCREENSHOT_MAX_SIDE,
2260
- maxBytes: DEFAULT_BROWSER_SCREENSHOT_MAX_BYTES
2261
- });
2262
- await ensureMediaDir();
2263
- const saved = await saveMediaBuffer(normalized.buffer, normalized.contentType ?? "image/png", "browser", DEFAULT_BROWSER_SCREENSHOT_MAX_BYTES);
2264
- return res.json({
2265
- ok: true,
2266
- format: "ai",
2267
- targetId: tab.targetId,
2268
- url: tab.url,
2269
- labels: true,
2270
- labelsCount: labelResult.labels,
2271
- labelsSkipped: labelResult.skipped,
2272
- imagePath: path.resolve(saved.path),
2273
- imageType: normalized.contentType?.includes("jpeg") ? "jpeg" : "png",
2274
- ...builtWithUrls
2275
- });
2276
- } finally {
2277
- await clearChromeMcpOverlay({
2278
- profileName: profileCtx.profile.name,
2279
- profile: profileCtx.profile,
2280
- targetId: tab.targetId
2281
- });
2282
- }
2283
- }
2284
- return res.json({
2285
- ok: true,
2286
- format: "ai",
2287
- targetId: tab.targetId,
2288
- url: tab.url,
2289
- ...builtWithUrls
2290
- });
2291
- }
2292
- if (hasPendingDialogs(observedBrowserState)) return res.json({
2293
- ok: true,
2294
- format: plan.format,
2295
- targetId: tab.targetId,
2296
- url: tab.url,
2297
- blockedByDialog: true,
2298
- ...browserStateResponseFields(observedBrowserState),
2299
- ...plan.format === "aria" ? { nodes: [] } : {
2300
- snapshot: "",
2301
- refs: {}
2302
- }
2303
- });
2304
- if (plan.format === "ai") {
2305
- const roleSnapshotArgs = {
2306
- cdpUrl: profileCtx.profile.cdpUrl,
2307
- targetId: tab.targetId,
2308
- selector: plan.selectorValue,
2309
- frameSelector: plan.frameSelectorValue,
2310
- refsMode: plan.refsMode,
2311
- ssrfPolicy: ctx.state().resolved.ssrfPolicy,
2312
- urls: plan.urls,
2313
- timeoutMs: plan.timeoutMs,
2314
- options: {
2315
- interactive: plan.interactive ?? void 0,
2316
- compact: plan.compact ?? void 0,
2317
- maxDepth: plan.depth ?? void 0
2318
- }
2319
- };
2320
- const cdpRoleSnapshot = async () => {
2321
- if (!tab.wsUrl) return null;
2322
- if (plan.selectorValue || plan.frameSelectorValue) return null;
2323
- return await snapshotRoleViaCdp({
2324
- wsUrl: tab.wsUrl,
2325
- urls: plan.urls,
2326
- timeoutMs: plan.timeoutMs,
2327
- options: {
2328
- interactive: plan.interactive ?? void 0,
2329
- compact: plan.compact ?? void 0,
2330
- maxDepth: plan.depth ?? void 0
2331
- }
2332
- });
2333
- };
2334
- const pw = await getPwAiModule();
2335
- const snap = plan.wantsRoleSnapshot ? pw ? await pw.snapshotRoleViaPlaywright(roleSnapshotArgs).catch(async (err) => {
2336
- const fallback = await cdpRoleSnapshot();
2337
- if (fallback) return fallback;
2338
- throw err;
2339
- }) : await cdpRoleSnapshot() : pw ? await pw.snapshotAiViaPlaywright({
2340
- cdpUrl: profileCtx.profile.cdpUrl,
2341
- targetId: tab.targetId,
2342
- ssrfPolicy: ctx.state().resolved.ssrfPolicy,
2343
- urls: plan.urls,
2344
- timeoutMs: plan.timeoutMs,
2345
- ...typeof plan.resolvedMaxChars === "number" ? { maxChars: plan.resolvedMaxChars } : {}
2346
- }) : await cdpRoleSnapshot();
2347
- if (!snap) {
2348
- await requirePwAi(res, "ai snapshot");
2349
- return;
2350
- }
2351
- if (plan.labels) {
2352
- if (!pw) return jsonError(res, 501, "Snapshot labels require Playwright.");
2353
- const labeled = await pw.screenshotWithLabelsViaPlaywright({
2354
- cdpUrl: profileCtx.profile.cdpUrl,
2355
- targetId: tab.targetId,
2356
- refs: "refs" in snap ? snap.refs : {},
2357
- type: "png",
2358
- timeoutMs: plan.timeoutMs
2359
- });
2360
- const normalized = await normalizeBrowserScreenshot(labeled.buffer, {
2361
- maxSide: DEFAULT_BROWSER_SCREENSHOT_MAX_SIDE,
2362
- maxBytes: DEFAULT_BROWSER_SCREENSHOT_MAX_BYTES
2363
- });
2364
- await ensureMediaDir();
2365
- const saved = await saveMediaBuffer(normalized.buffer, normalized.contentType ?? "image/png", "browser", DEFAULT_BROWSER_SCREENSHOT_MAX_BYTES);
2366
- const imageType = normalized.contentType?.includes("jpeg") ? "jpeg" : "png";
2367
- return res.json({
2368
- ok: true,
2369
- format: plan.format,
2370
- targetId: tab.targetId,
2371
- url: tab.url,
2372
- ...browserStateResponseFields(observedBrowserState),
2373
- labels: true,
2374
- labelsCount: labeled.labels,
2375
- labelsSkipped: labeled.skipped,
2376
- imagePath: path.resolve(saved.path),
2377
- imageType,
2378
- ...snap
2379
- });
2380
- }
2381
- return res.json({
2382
- ok: true,
2383
- format: plan.format,
2384
- targetId: tab.targetId,
2385
- url: tab.url,
2386
- ...browserStateResponseFields(observedBrowserState),
2387
- ...snap
2388
- });
2389
- }
2390
- const usePlaywrightAriaSnapshot = shouldUsePlaywrightForAriaSnapshot({
2391
- profile: profileCtx.profile,
2392
- wsUrl: tab.wsUrl
2393
- });
2394
- const snap = usePlaywrightAriaSnapshot ? requirePwAi(res, "aria snapshot").then(async (pw) => {
2395
- if (!pw) return null;
2396
- return await pw.snapshotAriaViaPlaywright({
2397
- cdpUrl: profileCtx.profile.cdpUrl,
2398
- targetId: tab.targetId,
2399
- limit: plan.limit,
2400
- timeoutMs: plan.timeoutMs,
2401
- ssrfPolicy: ctx.state().resolved.ssrfPolicy
2402
- });
2403
- }) : snapshotAria({
2404
- wsUrl: tab.wsUrl ?? "",
2405
- limit: plan.limit,
2406
- timeoutMs: plan.timeoutMs
2407
- });
2408
- const resolved = await Promise.resolve(snap);
2409
- if (!resolved) return;
2410
- if (!usePlaywrightAriaSnapshot) await pwModule?.storeAriaSnapshotRefsViaPlaywright?.({
2411
- cdpUrl: profileCtx.profile.cdpUrl,
2412
- targetId: tab.targetId,
2413
- nodes: resolved.nodes
2414
- });
2415
- return res.json({
2416
- ok: true,
2417
- format: plan.format,
2418
- targetId: tab.targetId,
2419
- url: tab.url,
2420
- ...browserStateResponseFields(observedBrowserState),
2421
- ...resolved
2422
- });
2423
- } catch (err) {
2424
- handleRouteError(ctx, res, err);
2425
- }
2426
- }));
2427
- }
2428
- //#endregion
2429
- //#region extensions/browser/src/browser/routes/agent.storage.ts
2430
- function parseStorageKind(raw) {
2431
- if (raw === "local" || raw === "session") return raw;
2432
- return null;
2433
- }
2434
- function parseStorageMutationRequest(kindParam, body) {
2435
- return {
2436
- kind: parseStorageKind(toStringOrEmpty(kindParam)),
2437
- targetId: resolveTargetIdFromBody(body)
2438
- };
2439
- }
2440
- function parseRequiredStorageMutationRequest(kindParam, body) {
2441
- const parsed = parseStorageMutationRequest(kindParam, body);
2442
- if (!parsed.kind) return null;
2443
- return {
2444
- kind: parsed.kind,
2445
- targetId: parsed.targetId
2446
- };
2447
- }
2448
- function parseStorageMutationOrRespond(res, kindParam, body) {
2449
- const parsed = parseRequiredStorageMutationRequest(kindParam, body);
2450
- if (!parsed) {
2451
- jsonError(res, 400, "kind must be local|session");
2452
- return null;
2453
- }
2454
- return parsed;
2455
- }
2456
- function parseStorageMutationFromRequest(req, res) {
2457
- const body = readBody(req);
2458
- const parsed = parseStorageMutationOrRespond(res, req.params.kind, body);
2459
- if (!parsed) return null;
2460
- return {
2461
- body,
2462
- parsed
2463
- };
2464
- }
2465
- function assertRange(value, fieldName, min, max) {
2466
- if (value === void 0) return;
2467
- if (value < min || value > max) throw new Error(`${fieldName} must be between ${min} and ${max}.`);
2468
- return value;
2469
- }
2470
- function parseCookieSetOptions(cookie) {
2471
- return {
2472
- name: toStringOrEmpty(cookie.name),
2473
- value: toStringOrEmpty(cookie.value),
2474
- url: toStringOrEmpty(cookie.url) || void 0,
2475
- domain: toStringOrEmpty(cookie.domain) || void 0,
2476
- path: toStringOrEmpty(cookie.path) || void 0,
2477
- expires: readOptionalRouteFiniteNumber(cookie.expires, "cookie.expires"),
2478
- httpOnly: toBoolean(cookie.httpOnly) ?? void 0,
2479
- secure: toBoolean(cookie.secure) ?? void 0,
2480
- sameSite: cookie.sameSite === "Lax" || cookie.sameSite === "None" || cookie.sameSite === "Strict" ? cookie.sameSite : void 0
2481
- };
2482
- }
2483
- function parseGeolocationOptions(body) {
2484
- const clear = toBoolean(body.clear) ?? false;
2485
- const origin = toStringOrEmpty(body.origin) || void 0;
2486
- if (clear) return {
2487
- clear,
2488
- origin
2489
- };
2490
- const latitude = assertRange(readRouteFiniteNumber(body.latitude, "latitude"), "latitude", -90, 90);
2491
- const longitude = assertRange(readRouteFiniteNumber(body.longitude, "longitude"), "longitude", -180, 180);
2492
- const accuracy = readRouteFiniteNumber(body.accuracy, "accuracy");
2493
- if (accuracy !== void 0 && accuracy < 0) throw new Error("精度不能为负数");
2494
- if (!clear && (latitude === void 0 || longitude === void 0)) throw new Error("latitude and longitude are required (or set clear=true)");
2495
- return {
2496
- clear,
2497
- latitude,
2498
- longitude,
2499
- accuracy,
2500
- origin
2501
- };
2502
- }
2503
- function registerBrowserAgentStorageRoutes(app, ctx) {
2504
- app.get("/cookies", asyncBrowserRoute(async (req, res) => {
2505
- await withPlaywrightRouteContext({
2506
- req,
2507
- res,
2508
- ctx,
2509
- targetId: resolveTargetIdFromQuery(req.query),
2510
- feature: "cookies",
2511
- enforceCurrentUrlAllowed: true,
2512
- run: async ({ cdpUrl, tab, pw }) => {
2513
- const result = await pw.cookiesGetViaPlaywright({
2514
- cdpUrl,
2515
- targetId: tab.targetId
2516
- });
2517
- res.json({
2518
- ok: true,
2519
- targetId: tab.targetId,
2520
- ...result
2521
- });
2522
- }
2523
- });
2524
- }));
2525
- app.post("/cookies/set", asyncBrowserRoute(async (req, res) => {
2526
- const body = readBody(req);
2527
- const targetId = resolveTargetIdFromBody(body);
2528
- const cookie = body.cookie && typeof body.cookie === "object" && !Array.isArray(body.cookie) ? body.cookie : null;
2529
- if (!cookie) return jsonError(res, 400, "cookie is required");
2530
- let parsedCookie;
2531
- try {
2532
- parsedCookie = parseCookieSetOptions(cookie);
2533
- } catch (err) {
2534
- return jsonError(res, 400, formatErrorMessage(err));
2535
- }
2536
- await withPlaywrightRouteContext({
2537
- req,
2538
- res,
2539
- ctx,
2540
- targetId,
2541
- feature: "cookies set",
2542
- run: async ({ cdpUrl, tab, pw }) => {
2543
- await pw.cookiesSetViaPlaywright({
2544
- cdpUrl,
2545
- targetId: tab.targetId,
2546
- cookie: parsedCookie
2547
- });
2548
- res.json({
2549
- ok: true,
2550
- targetId: tab.targetId
2551
- });
2552
- }
2553
- });
2554
- }));
2555
- app.post("/cookies/clear", asyncBrowserRoute(async (req, res) => {
2556
- await withPlaywrightRouteContext({
2557
- req,
2558
- res,
2559
- ctx,
2560
- targetId: resolveTargetIdFromBody(readBody(req)),
2561
- feature: "cookies clear",
2562
- run: async ({ cdpUrl, tab, pw }) => {
2563
- await pw.cookiesClearViaPlaywright({
2564
- cdpUrl,
2565
- targetId: tab.targetId
2566
- });
2567
- res.json({
2568
- ok: true,
2569
- targetId: tab.targetId
2570
- });
2571
- }
2572
- });
2573
- }));
2574
- app.get("/storage/:kind", asyncBrowserRoute(async (req, res) => {
2575
- const kind = parseStorageKind(toStringOrEmpty(req.params.kind));
2576
- if (!kind) return jsonError(res, 400, "kind must be local|session");
2577
- const targetId = resolveTargetIdFromQuery(req.query);
2578
- const key = toStringOrEmpty(req.query.key);
2579
- await withPlaywrightRouteContext({
2580
- req,
2581
- res,
2582
- ctx,
2583
- targetId,
2584
- feature: "storage get",
2585
- enforceCurrentUrlAllowed: true,
2586
- run: async ({ cdpUrl, tab, pw }) => {
2587
- const result = await pw.storageGetViaPlaywright({
2588
- cdpUrl,
2589
- targetId: tab.targetId,
2590
- kind,
2591
- key: normalizeOptionalString$1(key)
2592
- });
2593
- res.json({
2594
- ok: true,
2595
- targetId: tab.targetId,
2596
- ...result
2597
- });
2598
- }
2599
- });
2600
- }));
2601
- app.post("/storage/:kind/set", asyncBrowserRoute(async (req, res) => {
2602
- const mutation = parseStorageMutationFromRequest(req, res);
2603
- if (!mutation) return;
2604
- const key = toStringOrEmpty(mutation.body.key);
2605
- if (!key) return jsonError(res, 400, "key is required");
2606
- const value = typeof mutation.body.value === "string" ? mutation.body.value : "";
2607
- await withPlaywrightRouteContext({
2608
- req,
2609
- res,
2610
- ctx,
2611
- targetId: mutation.parsed.targetId,
2612
- feature: "storage set",
2613
- run: async ({ cdpUrl, tab, pw }) => {
2614
- await pw.storageSetViaPlaywright({
2615
- cdpUrl,
2616
- targetId: tab.targetId,
2617
- kind: mutation.parsed.kind,
2618
- key,
2619
- value
2620
- });
2621
- res.json({
2622
- ok: true,
2623
- targetId: tab.targetId
2624
- });
2625
- }
2626
- });
2627
- }));
2628
- app.post("/storage/:kind/clear", asyncBrowserRoute(async (req, res) => {
2629
- const mutation = parseStorageMutationFromRequest(req, res);
2630
- if (!mutation) return;
2631
- await withPlaywrightRouteContext({
2632
- req,
2633
- res,
2634
- ctx,
2635
- targetId: mutation.parsed.targetId,
2636
- feature: "storage clear",
2637
- run: async ({ cdpUrl, tab, pw }) => {
2638
- await pw.storageClearViaPlaywright({
2639
- cdpUrl,
2640
- targetId: tab.targetId,
2641
- kind: mutation.parsed.kind
2642
- });
2643
- res.json({
2644
- ok: true,
2645
- targetId: tab.targetId
2646
- });
2647
- }
2648
- });
2649
- }));
2650
- app.post("/set/offline", asyncBrowserRoute(async (req, res) => {
2651
- const body = readBody(req);
2652
- const targetId = resolveTargetIdFromBody(body);
2653
- const offline = toBoolean(body.offline);
2654
- if (offline === void 0) return jsonError(res, 400, "offline is required");
2655
- await withPlaywrightRouteContext({
2656
- req,
2657
- res,
2658
- ctx,
2659
- targetId,
2660
- feature: "offline",
2661
- run: async ({ cdpUrl, tab, pw }) => {
2662
- await pw.setOfflineViaPlaywright({
2663
- cdpUrl,
2664
- targetId: tab.targetId,
2665
- offline
2666
- });
2667
- res.json({
2668
- ok: true,
2669
- targetId: tab.targetId
2670
- });
2671
- }
2672
- });
2673
- }));
2674
- app.post("/set/headers", asyncBrowserRoute(async (req, res) => {
2675
- const body = readBody(req);
2676
- const targetId = resolveTargetIdFromBody(body);
2677
- const headers = body.headers && typeof body.headers === "object" && !Array.isArray(body.headers) ? body.headers : null;
2678
- if (!headers) return jsonError(res, 400, "headers is required");
2679
- const parsed = {};
2680
- for (const [k, v] of Object.entries(headers)) if (typeof v === "string") parsed[k] = v;
2681
- await withPlaywrightRouteContext({
2682
- req,
2683
- res,
2684
- ctx,
2685
- targetId,
2686
- feature: "headers",
2687
- run: async ({ cdpUrl, tab, pw }) => {
2688
- await pw.setExtraHTTPHeadersViaPlaywright({
2689
- cdpUrl,
2690
- targetId: tab.targetId,
2691
- headers: parsed
2692
- });
2693
- res.json({
2694
- ok: true,
2695
- targetId: tab.targetId
2696
- });
2697
- }
2698
- });
2699
- }));
2700
- app.post("/set/credentials", asyncBrowserRoute(async (req, res) => {
2701
- const body = readBody(req);
2702
- const targetId = resolveTargetIdFromBody(body);
2703
- const clear = toBoolean(body.clear) ?? false;
2704
- const username = toStringOrEmpty(body.username) || void 0;
2705
- const password = readStringValue(body.password);
2706
- await withPlaywrightRouteContext({
2707
- req,
2708
- res,
2709
- ctx,
2710
- targetId,
2711
- feature: "http credentials",
2712
- run: async ({ cdpUrl, tab, pw }) => {
2713
- await pw.setHttpCredentialsViaPlaywright({
2714
- cdpUrl,
2715
- targetId: tab.targetId,
2716
- username,
2717
- password,
2718
- clear
2719
- });
2720
- res.json({
2721
- ok: true,
2722
- targetId: tab.targetId
2723
- });
2724
- }
2725
- });
2726
- }));
2727
- app.post("/set/geolocation", asyncBrowserRoute(async (req, res) => {
2728
- const body = readBody(req);
2729
- const targetId = resolveTargetIdFromBody(body);
2730
- let geolocation;
2731
- try {
2732
- geolocation = parseGeolocationOptions(body);
2733
- } catch (err) {
2734
- return jsonError(res, 400, formatErrorMessage(err));
2735
- }
2736
- await withPlaywrightRouteContext({
2737
- req,
2738
- res,
2739
- ctx,
2740
- targetId,
2741
- feature: "geolocation",
2742
- run: async ({ cdpUrl, tab, pw }) => {
2743
- await pw.setGeolocationViaPlaywright({
2744
- cdpUrl,
2745
- targetId: tab.targetId,
2746
- ...geolocation
2747
- });
2748
- res.json({
2749
- ok: true,
2750
- targetId: tab.targetId
2751
- });
2752
- }
2753
- });
2754
- }));
2755
- app.post("/set/media", asyncBrowserRoute(async (req, res) => {
2756
- const body = readBody(req);
2757
- const targetId = resolveTargetIdFromBody(body);
2758
- const schemeRaw = toStringOrEmpty(body.colorScheme);
2759
- const colorScheme = schemeRaw === "dark" || schemeRaw === "light" || schemeRaw === "no-preference" ? schemeRaw : schemeRaw === "none" ? null : void 0;
2760
- if (colorScheme === void 0) return jsonError(res, 400, "colorScheme must be dark|light|no-preference|none");
2761
- await withPlaywrightRouteContext({
2762
- req,
2763
- res,
2764
- ctx,
2765
- targetId,
2766
- feature: "media emulation",
2767
- run: async ({ cdpUrl, tab, pw }) => {
2768
- await pw.emulateMediaViaPlaywright({
2769
- cdpUrl,
2770
- targetId: tab.targetId,
2771
- colorScheme
2772
- });
2773
- res.json({
2774
- ok: true,
2775
- targetId: tab.targetId
2776
- });
2777
- }
2778
- });
2779
- }));
2780
- app.post("/set/timezone", asyncBrowserRoute(async (req, res) => {
2781
- const body = readBody(req);
2782
- const targetId = resolveTargetIdFromBody(body);
2783
- const timezoneId = toStringOrEmpty(body.timezoneId);
2784
- if (!timezoneId) return jsonError(res, 400, "timezoneId is required");
2785
- await withPlaywrightRouteContext({
2786
- req,
2787
- res,
2788
- ctx,
2789
- targetId,
2790
- feature: "timezone",
2791
- run: async ({ cdpUrl, tab, pw }) => {
2792
- await pw.setTimezoneViaPlaywright({
2793
- cdpUrl,
2794
- targetId: tab.targetId,
2795
- timezoneId
2796
- });
2797
- res.json({
2798
- ok: true,
2799
- targetId: tab.targetId
2800
- });
2801
- }
2802
- });
2803
- }));
2804
- app.post("/set/locale", asyncBrowserRoute(async (req, res) => {
2805
- const body = readBody(req);
2806
- const targetId = resolveTargetIdFromBody(body);
2807
- const locale = toStringOrEmpty(body.locale);
2808
- if (!locale) return jsonError(res, 400, "locale is required");
2809
- await withPlaywrightRouteContext({
2810
- req,
2811
- res,
2812
- ctx,
2813
- targetId,
2814
- feature: "locale",
2815
- run: async ({ cdpUrl, tab, pw }) => {
2816
- await pw.setLocaleViaPlaywright({
2817
- cdpUrl,
2818
- targetId: tab.targetId,
2819
- locale
2820
- });
2821
- res.json({
2822
- ok: true,
2823
- targetId: tab.targetId
2824
- });
2825
- }
2826
- });
2827
- }));
2828
- app.post("/set/device", asyncBrowserRoute(async (req, res) => {
2829
- const body = readBody(req);
2830
- const targetId = resolveTargetIdFromBody(body);
2831
- const name = toStringOrEmpty(body.name);
2832
- if (!name) return jsonError(res, 400, "name is required");
2833
- await withPlaywrightRouteContext({
2834
- req,
2835
- res,
2836
- ctx,
2837
- targetId,
2838
- feature: "device emulation",
2839
- run: async ({ cdpUrl, tab, pw }) => {
2840
- await pw.setDeviceViaPlaywright({
2841
- cdpUrl,
2842
- targetId: tab.targetId,
2843
- name
2844
- });
2845
- res.json({
2846
- ok: true,
2847
- targetId: tab.targetId
2848
- });
2849
- }
2850
- });
2851
- }));
2852
- }
2853
- //#endregion
2854
- //#region extensions/browser/src/browser/routes/agent.ts
2855
- function registerBrowserAgentRoutes(app, ctx) {
2856
- registerBrowserAgentSnapshotRoutes(app, ctx);
2857
- registerBrowserAgentActRoutes(app, ctx);
2858
- registerBrowserAgentDebugRoutes(app, ctx);
2859
- registerBrowserAgentStorageRoutes(app, ctx);
2860
- }
2861
- //#endregion
2862
- //#region extensions/browser/src/browser/doctor.ts
2863
- function buildBrowserDoctorReport(params) {
2864
- const status = params.status;
2865
- const checks = [];
2866
- const transport = status.transport === "chrome-mcp" ? "chrome-mcp" : "cdp";
2867
- checks.push({
2868
- id: "plugin-enabled",
2869
- label: "Browser plugin",
2870
- status: status.enabled ? "pass" : "fail",
2871
- summary: status.enabled ? "enabled" : "disabled",
2872
- ...status.enabled ? {} : { fixHint: "Enable the browser plugin and restart the Gateway." }
2873
- });
2874
- checks.push({
2875
- id: "profile",
2876
- label: "Profile",
2877
- status: "pass",
2878
- summary: `${status.profile ?? "fengming"} via ${transport}`
2879
- });
2880
- if (transport === "chrome-mcp") checks.push({
2881
- id: "attach-target",
2882
- label: "Existing browser attach",
2883
- status: status.running ? "pass" : "fail",
2884
- summary: status.running ? "Chrome MCP target is reachable" : "Chrome MCP target is not reachable",
2885
- ...status.running ? {} : { fixHint: "Keep the matching Chromium browser running, enable remote debugging in chrome://inspect, and accept the attach prompt." }
2886
- });
2887
- else {
2888
- checks.push({
2889
- id: "managed-executable",
2890
- label: "Chromium executable",
2891
- status: status.detectError ? "fail" : status.detectedExecutablePath ? "pass" : "warn",
2892
- summary: status.detectError ? status.detectError : status.detectedExecutablePath ? `${status.detectedBrowser ?? "chromium"} at ${status.detectedExecutablePath}` : "No Chromium executable detected",
2893
- ...status.detectedExecutablePath || status.detectError ? {} : { fixHint: "Install Chrome/Chromium/Brave/Edge or set browser.executablePath." }
2894
- });
2895
- const platform = params.platform ?? process.platform;
2896
- const env = params.env ?? process.env;
2897
- const uid = params.uid ?? process.getuid?.();
2898
- const missingDisplay = platform === "linux" && !status.headless && !env.DISPLAY && !env.WAYLAND_DISPLAY;
2899
- if (status.headlessSource === "linux-display-fallback") checks.push({
2900
- id: "headless-mode",
2901
- label: "Headless mode",
2902
- status: "pass",
2903
- summary: "Linux no-display fallback selected headless mode"
2904
- });
2905
- if (missingDisplay) checks.push({
2906
- id: "display",
2907
- label: "Display",
2908
- status: "warn",
2909
- summary: `No DISPLAY or WAYLAND_DISPLAY is set while headed mode is selected (${status.headlessSource ?? "unknown"})`,
2910
- fixHint: "Use a desktop session, Xvfb, set FENGMING_BROWSER_HEADLESS=1, or remove the headed override."
2911
- });
2912
- if (platform === "linux" && uid === 0 && !status.noSandbox) checks.push({
2913
- id: "linux-sandbox",
2914
- label: "Linux sandbox",
2915
- status: "warn",
2916
- summary: "Gateway is running as root while browser.noSandbox is false",
2917
- fixHint: "Set browser.noSandbox: true for container/root Chromium runtimes."
2918
- });
2919
- checks.push({
2920
- id: "cdp-http",
2921
- label: "CDP HTTP",
2922
- status: status.cdpHttp ? "pass" : status.running ? "fail" : "info",
2923
- summary: status.cdpHttp ? "CDP HTTP endpoint is reachable" : status.running ? "CDP HTTP endpoint is not reachable" : "Browser is not currently running",
2924
- ...status.cdpHttp || !status.running ? {} : { fixHint: "Run fengming browser start or inspect browser.cdpUrl/CDP port reachability." }
2925
- });
2926
- checks.push({
2927
- id: "cdp-websocket",
2928
- label: "CDP WebSocket",
2929
- status: status.cdpReady ? "pass" : status.running ? "fail" : "info",
2930
- summary: status.cdpReady ? "CDP WebSocket is reachable" : status.running ? "CDP WebSocket is not reachable" : "Browser is launchable but not running",
2931
- ...status.cdpReady || !status.running ? {} : { fixHint: "Check Chrome launch logs, stale locks, proxy env, and port conflicts." }
2932
- });
2933
- }
2934
- return {
2935
- ok: checks.every((check) => check.status !== "fail"),
2936
- profile: status.profile ?? "fengming",
2937
- transport,
2938
- checks,
2939
- status
2940
- };
2941
- }
2942
- //#endregion
2943
- //#region extensions/browser/src/browser/profiles-service.ts
2944
- const HEX_COLOR_RE = /^#[0-9A-Fa-f]{6}$/;
2945
- function createBrowserProfilesService(ctx) {
2946
- const listProfiles = async () => {
2947
- return await ctx.listProfiles();
2948
- };
2949
- const createProfile = async (params) => {
2950
- const name = params.name.trim();
2951
- const rawCdpUrl = normalizeOptionalString$1(params.cdpUrl);
2952
- const rawUserDataDir = normalizeOptionalString$1(params.userDataDir);
2953
- const normalizedUserDataDir = rawUserDataDir ? resolveUserPath(rawUserDataDir) : void 0;
2954
- const driver = params.driver === "existing-session" ? "existing-session" : void 0;
2955
- if (!isValidProfileName(name)) throw new BrowserValidationError("invalid profile name: use lowercase letters, numbers, and hyphens only");
2956
- const state = ctx.state();
2957
- if (name in state.resolved.profiles) throw new BrowserConflictError(`profile "${name}" already exists`);
2958
- if (name in (getRuntimeConfig().browser?.profiles ?? {})) throw new BrowserConflictError(`profile "${name}" already exists`);
2959
- const explicitProfileColor = params.color && HEX_COLOR_RE.test(params.color) ? params.color : void 0;
2960
- let parsedCdpUrl;
2961
- if (normalizedUserDataDir && driver !== "existing-session") throw new BrowserValidationError("driver=existing-session is required when userDataDir is provided");
2962
- if (normalizedUserDataDir && !fs.existsSync(normalizedUserDataDir)) throw new BrowserValidationError(`browser user data directory not found: ${normalizedUserDataDir}`);
2963
- if (rawCdpUrl) {
2964
- if (driver === "existing-session") throw new BrowserValidationError("driver=existing-session does not accept cdpUrl; it attaches via the Chrome MCP auto-connect flow");
2965
- let parsed;
2966
- try {
2967
- parsed = parseBrowserHttpUrl(rawCdpUrl, "browser.profiles.cdpUrl");
2968
- await assertCdpEndpointAllowed(parsed.normalized, state.resolved.ssrfPolicy);
2969
- } catch (err) {
2970
- throw new BrowserValidationError(formatErrorMessage(err));
2971
- }
2972
- parsedCdpUrl = parsed.normalized;
2973
- }
2974
- const profileConfig = await createBrowserProfileConfig({
2975
- name,
2976
- resolved: state.resolved,
2977
- ...explicitProfileColor ? { color: explicitProfileColor } : {},
2978
- ...parsedCdpUrl ? { parsedCdpUrl } : {},
2979
- ...normalizedUserDataDir ? { userDataDir: normalizedUserDataDir } : {},
2980
- ...driver ? { driver } : {}
2981
- });
2982
- if (!profileConfig) throw new BrowserProfileNotFoundError(`profile "${name}" not found after creation`);
2983
- state.resolved.profiles[name] = profileConfig;
2984
- const resolved = resolveProfile(state.resolved, name);
2985
- if (!resolved) throw new BrowserProfileNotFoundError(`profile "${name}" not found after creation`);
2986
- const capabilities = getBrowserProfileCapabilities(resolved);
2987
- return {
2988
- ok: true,
2989
- profile: name,
2990
- transport: capabilities.usesChromeMcp ? "chrome-mcp" : "cdp",
2991
- cdpPort: capabilities.usesChromeMcp ? null : resolved.cdpPort,
2992
- cdpUrl: capabilities.usesChromeMcp ? null : resolved.cdpUrl,
2993
- userDataDir: resolved.userDataDir ?? null,
2994
- color: resolved.color,
2995
- isRemote: !resolved.cdpIsLoopback
2996
- };
2997
- };
2998
- const deleteProfile = async (nameRaw) => {
2999
- const name = nameRaw.trim();
3000
- if (!name) throw new BrowserValidationError("profile name is required");
3001
- if (!isValidProfileName(name)) throw new BrowserValidationError("invalid profile name");
3002
- const state = ctx.state();
3003
- const cfg = getRuntimeConfig();
3004
- const profiles = cfg.browser?.profiles ?? {};
3005
- if (name === (cfg.browser?.defaultProfile ?? state.resolved.defaultProfile)) throw new BrowserValidationError(`cannot delete the default profile "${name}"; change browser.defaultProfile first`);
3006
- if (!(name in profiles)) throw new BrowserProfileNotFoundError(`profile "${name}" not found`);
3007
- let deleted = false;
3008
- const resolved = resolveProfile(state.resolved, name);
3009
- if (resolved?.cdpIsLoopback && resolved.driver === "fengming") {
3010
- try {
3011
- await ctx.forProfile(name).stopRunningBrowser();
3012
- } catch {}
3013
- const userDataDir = resolveFengMingUserDataDir(name);
3014
- const profileDir = path.dirname(userDataDir);
3015
- if (fs.existsSync(profileDir)) {
3016
- await movePathToTrash(profileDir);
3017
- deleted = true;
3018
- }
3019
- }
3020
- await deleteBrowserProfileConfig(name);
3021
- delete state.resolved.profiles[name];
3022
- state.profiles.delete(name);
3023
- return {
3024
- ok: true,
3025
- profile: name,
3026
- deleted
3027
- };
3028
- };
3029
- return {
3030
- listProfiles,
3031
- createProfile,
3032
- deleteProfile
3033
- };
3034
- }
3035
- //#endregion
3036
- //#region extensions/browser/src/browser/routes/basic.ts
3037
- const STATUS_CDP_HTTP_TIMEOUT_MS = 300;
3038
- const STATUS_CDP_TRANSPORT_TIMEOUT_MS = 600;
3039
- const STATUS_CHROME_MCP_TOTAL_TIMEOUT_MS = 7e3;
3040
- const STATUS_CHROME_MCP_TRANSPORT_TIMEOUT_MS = 5e3;
3041
- function remainingChromeMcpStatusTimeoutMs(startedAtMs) {
3042
- return Math.max(1, STATUS_CHROME_MCP_TOTAL_TIMEOUT_MS - (Date.now() - startedAtMs));
3043
- }
3044
- async function probeChromeMcpPageReady(profileCtx, timeoutMs) {
3045
- const abort = new AbortController();
3046
- const timer = setTimeout(() => {
3047
- abort.abort(/* @__PURE__ */ new Error(`Chrome MCP page-readiness probe timed out after ${timeoutMs}ms.`));
3048
- }, timeoutMs);
3049
- try {
3050
- return await profileCtx.isReachable(timeoutMs, {
3051
- ephemeral: true,
3052
- signal: abort.signal
3053
- });
3054
- } catch {
3055
- return false;
3056
- } finally {
3057
- clearTimeout(timer);
3058
- }
3059
- }
3060
- function handleBrowserRouteError(res, err) {
3061
- const mapped = toBrowserErrorResponse(err);
3062
- if (mapped) return jsonError(res, mapped.status, mapped.message);
3063
- jsonError(res, 500, String(err));
3064
- }
3065
- async function sendBasicJsonResponse(params) {
3066
- try {
3067
- params.res.json(await params.run());
3068
- } catch (err) {
3069
- return handleBrowserRouteError(params.res, err);
3070
- }
3071
- }
3072
- async function withBasicProfileRoute(params) {
3073
- const profileCtx = resolveProfileContext(params.req, params.res, params.ctx);
3074
- if (!profileCtx) return;
3075
- try {
3076
- await params.run(profileCtx);
3077
- } catch (err) {
3078
- return handleBrowserRouteError(params.res, err);
3079
- }
3080
- }
3081
- function registerBasicProfilePost(app, ctx, path, run) {
3082
- app.post(path, asyncBrowserRoute(async (req, res) => {
3083
- await withBasicProfileRoute({
3084
- req,
3085
- res,
3086
- ctx,
3087
- run: async (profileCtx) => await run({
3088
- req,
3089
- res,
3090
- profileCtx
3091
- })
3092
- });
3093
- }));
3094
- }
3095
- async function withProfilesServiceMutation(params) {
3096
- try {
3097
- const service = createBrowserProfilesService(params.ctx);
3098
- const result = await params.run(service);
3099
- params.res.json(result);
3100
- } catch (err) {
3101
- return handleBrowserRouteError(params.res, err);
3102
- }
3103
- }
3104
- async function buildBrowserStatus(req, ctx) {
3105
- let current;
3106
- try {
3107
- current = ctx.state();
3108
- } catch {
3109
- throw new BrowserError("browser server not started", 503);
3110
- }
3111
- const profileCtx = getProfileContext(req, ctx);
3112
- if ("error" in profileCtx) throw new BrowserError(profileCtx.error, profileCtx.status);
3113
- const capabilities = getBrowserProfileCapabilities(profileCtx.profile);
3114
- const [cdpHttp, cdpReady, pageReady] = capabilities.usesChromeMcp ? await (async () => {
3115
- const statusStartedAtMs = Date.now();
3116
- const transportReady = await profileCtx.isTransportAvailable(STATUS_CHROME_MCP_TRANSPORT_TIMEOUT_MS);
3117
- if (!transportReady) return [
3118
- false,
3119
- false,
3120
- false
3121
- ];
3122
- return [
3123
- transportReady,
3124
- transportReady,
3125
- await probeChromeMcpPageReady(profileCtx, remainingChromeMcpStatusTimeoutMs(statusStartedAtMs))
3126
- ];
3127
- })() : await (async () => {
3128
- const [http, ready] = await Promise.all([profileCtx.isHttpReachable(STATUS_CDP_HTTP_TIMEOUT_MS), profileCtx.isTransportAvailable(STATUS_CDP_TRANSPORT_TIMEOUT_MS)]);
3129
- return [
3130
- http,
3131
- ready,
3132
- ready
3133
- ];
3134
- })();
3135
- const profileState = current.profiles.get(profileCtx.profile.name);
3136
- let detectedBrowser = null;
3137
- let detectedExecutablePath = null;
3138
- let detectError = null;
3139
- try {
3140
- const detected = resolveBrowserExecutableForPlatform(current.resolved, process.platform);
3141
- if (detected) {
3142
- detectedBrowser = detected.kind;
3143
- detectedExecutablePath = detected.path;
3144
- }
3145
- } catch (err) {
3146
- detectError = String(err);
3147
- }
3148
- const configuredHeadlessMode = resolveManagedBrowserHeadlessMode(current.resolved, profileCtx.profile);
3149
- const headlessMode = typeof profileState?.running?.headless === "boolean" ? {
3150
- headless: profileState.running.headless,
3151
- source: profileState.running.headlessSource ?? configuredHeadlessMode.source
3152
- } : configuredHeadlessMode;
3153
- return {
3154
- enabled: current.resolved.enabled,
3155
- profile: profileCtx.profile.name,
3156
- driver: profileCtx.profile.driver,
3157
- transport: capabilities.usesChromeMcp ? "chrome-mcp" : "cdp",
3158
- running: cdpReady,
3159
- cdpReady,
3160
- cdpHttp,
3161
- pageReady,
3162
- pid: capabilities.usesChromeMcp ? getChromeMcpPid(profileCtx.profile.name) : profileState?.running?.pid ?? null,
3163
- cdpPort: capabilities.usesChromeMcp ? null : profileCtx.profile.cdpPort,
3164
- cdpUrl: capabilities.usesChromeMcp ? null : redactCdpUrl(profileCtx.profile.cdpUrl) ?? null,
3165
- chosenBrowser: profileState?.running?.exe.kind ?? null,
3166
- detectedBrowser,
3167
- detectedExecutablePath,
3168
- detectError,
3169
- userDataDir: profileState?.running?.userDataDir ?? profileCtx.profile.userDataDir ?? null,
3170
- color: profileCtx.profile.color,
3171
- headless: headlessMode.headless,
3172
- headlessSource: headlessMode.source,
3173
- noSandbox: current.resolved.noSandbox,
3174
- executablePath: profileCtx.profile.executablePath ?? null,
3175
- attachOnly: profileCtx.profile.attachOnly
3176
- };
3177
- }
3178
- async function runBrowserLiveProbe(req, ctx) {
3179
- const profileCtx = getProfileContext(req, ctx);
3180
- if ("error" in profileCtx) return {
3181
- id: "live-snapshot",
3182
- label: "Live snapshot",
3183
- status: "fail",
3184
- summary: profileCtx.error
3185
- };
3186
- const capabilities = getBrowserProfileCapabilities(profileCtx.profile);
3187
- try {
3188
- const tab = await profileCtx.ensureTabAvailable();
3189
- if (capabilities.usesChromeMcp) {
3190
- const { takeChromeMcpSnapshot } = await import("./chrome-mcp-C-YwCqW4.js");
3191
- await takeChromeMcpSnapshot({
3192
- profileName: profileCtx.profile.name,
3193
- profile: profileCtx.profile,
3194
- targetId: tab.targetId
3195
- });
3196
- return {
3197
- id: "live-snapshot",
3198
- label: "Live snapshot",
3199
- status: "pass",
3200
- summary: `Chrome MCP snapshot succeeded on ${tab.suggestedTargetId ?? tab.targetId}`
3201
- };
3202
- }
3203
- if (!tab.wsUrl) return {
3204
- id: "live-snapshot",
3205
- label: "Live snapshot",
3206
- status: "warn",
3207
- summary: "No per-tab CDP WebSocket available for the lightweight live snapshot probe"
3208
- };
3209
- const snap = await snapshotAria({
3210
- wsUrl: tab.wsUrl,
3211
- limit: 25
3212
- });
3213
- return {
3214
- id: "live-snapshot",
3215
- label: "Live snapshot",
3216
- status: snap.nodes.length > 0 ? "pass" : "warn",
3217
- summary: snap.nodes.length > 0 ? `CDP accessibility snapshot returned ${snap.nodes.length} nodes on ${tab.suggestedTargetId ?? tab.targetId}` : `CDP accessibility snapshot returned no nodes on ${tab.suggestedTargetId ?? tab.targetId}`
3218
- };
3219
- } catch (err) {
3220
- return {
3221
- id: "live-snapshot",
3222
- label: "Live snapshot",
3223
- status: "fail",
3224
- summary: String(err),
3225
- fixHint: "Run fengming browser start, then retry with fengming browser doctor --deep."
3226
- };
3227
- }
3228
- }
3229
- function hasQueryKey(query, key) {
3230
- return Object.prototype.hasOwnProperty.call(query ?? {}, key);
3231
- }
3232
- function parseHeadlessStartOverride(params) {
3233
- if (!hasQueryKey(params.req.query, "headless")) return { ok: true };
3234
- const headless = toBoolean(params.req.query.headless);
3235
- if (typeof headless !== "boolean") {
3236
- jsonError(params.res, 400, "Invalid headless value. Use \"true\" or \"false\".");
3237
- return { ok: false };
3238
- }
3239
- const capabilities = getBrowserProfileCapabilities(params.profileCtx.profile);
3240
- if (params.profileCtx.profile.driver !== "fengming" || params.profileCtx.profile.attachOnly || capabilities.isRemote) {
3241
- jsonError(params.res, 400, `Headless start override is only supported for locally launched fengming profiles. Profile "${params.profileCtx.profile.name}" is attach-only, remote, or existing-session.`);
3242
- return { ok: false };
3243
- }
3244
- return {
3245
- ok: true,
3246
- headless
3247
- };
3248
- }
3249
- function registerBrowserBasicRoutes(app, ctx) {
3250
- app.get("/profiles", asyncBrowserRoute(async (_req, res) => {
3251
- try {
3252
- const profiles = await createBrowserProfilesService(ctx).listProfiles();
3253
- res.json({ profiles });
3254
- } catch (err) {
3255
- jsonError(res, 500, String(err));
3256
- }
3257
- }));
3258
- app.get("/", asyncBrowserRoute(async (req, res) => {
3259
- await sendBasicJsonResponse({
3260
- res,
3261
- run: async () => await buildBrowserStatus(req, ctx)
3262
- });
3263
- }));
3264
- app.get("/doctor", asyncBrowserRoute(async (req, res) => {
3265
- await sendBasicJsonResponse({
3266
- res,
3267
- run: async () => {
3268
- const report = buildBrowserDoctorReport({ status: await buildBrowserStatus(req, ctx) });
3269
- if (toBoolean(req.query.deep) === true || toBoolean(req.query.live) === true) {
3270
- report.checks.push(await runBrowserLiveProbe(req, ctx));
3271
- report.ok = report.checks.every((check) => check.status !== "fail");
3272
- }
3273
- return report;
3274
- }
3275
- });
3276
- }));
3277
- registerBasicProfilePost(app, ctx, "/start", async ({ req, res, profileCtx }) => {
3278
- const headlessOverride = parseHeadlessStartOverride({
3279
- req,
3280
- res,
3281
- profileCtx
3282
- });
3283
- if (!headlessOverride.ok) return;
3284
- await profileCtx.ensureBrowserAvailable({ headless: headlessOverride.headless });
3285
- res.json({
3286
- ok: true,
3287
- profile: profileCtx.profile.name
3288
- });
3289
- });
3290
- registerBasicProfilePost(app, ctx, "/stop", async ({ res, profileCtx }) => {
3291
- const result = await profileCtx.stopRunningBrowser();
3292
- res.json({
3293
- ok: true,
3294
- stopped: result.stopped,
3295
- profile: profileCtx.profile.name
3296
- });
3297
- });
3298
- registerBasicProfilePost(app, ctx, "/reset-profile", async ({ res, profileCtx }) => {
3299
- const result = await profileCtx.resetProfile();
3300
- res.json({
3301
- ok: true,
3302
- profile: profileCtx.profile.name,
3303
- ...result
3304
- });
3305
- });
3306
- app.post("/profiles/create", asyncBrowserRoute(async (req, res) => {
3307
- const name = toStringOrEmpty(req.body?.name);
3308
- const color = toStringOrEmpty(req.body?.color);
3309
- const cdpUrl = toStringOrEmpty(req.body?.cdpUrl);
3310
- const userDataDir = toStringOrEmpty(req.body?.userDataDir);
3311
- const driver = toStringOrEmpty(req.body?.driver);
3312
- if (!name) return jsonError(res, 400, "name is required");
3313
- if (driver && driver !== "fengming" && driver !== "clawd" && driver !== "existing-session") return jsonError(res, 400, `unsupported profile driver "${driver}"; use "fengming", "clawd", or "existing-session"`);
3314
- await withProfilesServiceMutation({
3315
- res,
3316
- ctx,
3317
- run: async (service) => await service.createProfile({
3318
- name,
3319
- color: color || void 0,
3320
- cdpUrl: cdpUrl || void 0,
3321
- userDataDir: userDataDir || void 0,
3322
- driver: driver === "existing-session" ? "existing-session" : driver === "fengming" || driver === "clawd" ? "fengming" : void 0
3323
- })
3324
- });
3325
- }));
3326
- app.delete("/profiles/:name", asyncBrowserRoute(async (req, res) => {
3327
- const name = toStringOrEmpty(req.params.name);
3328
- if (!name) return jsonError(res, 400, "profile name is required");
3329
- await withProfilesServiceMutation({
3330
- res,
3331
- ctx,
3332
- run: async (service) => await service.deleteProfile(name)
3333
- });
3334
- }));
3335
- }
3336
- //#endregion
3337
- //#region extensions/browser/src/browser/routes/permissions.ts
3338
- const permissionRouteDeps = { getPwAiModule: getPwAiModule$1 };
3339
- function readOrigin(raw) {
3340
- const value = toStringOrEmpty(raw);
3341
- if (!value) return null;
3342
- try {
3343
- const parsed = new URL(value);
3344
- if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return null;
3345
- return parsed.origin;
3346
- } catch {
3347
- return null;
3348
- }
3349
- }
3350
- function readPermissions(raw) {
3351
- if (!Array.isArray(raw)) return null;
3352
- const permissions = raw.map((value) => typeof value === "string" ? value.trim() : "").filter(Boolean);
3353
- if (permissions.length !== raw.length) return null;
3354
- return uniqueStrings(permissions);
3355
- }
3356
- async function grantPermissions(params) {
3357
- const allPermissions = [...new Set([...params.requiredPermissions, ...params.optionalPermissions])];
3358
- const playwrightRequiredPermissions = params.requiredPermissions.map(toPlaywrightPermission);
3359
- if (playwrightRequiredPermissions.every((value) => Boolean(value)) && params.requiredPermissions.length > 0) {
3360
- const pw = await permissionRouteDeps.getPwAiModule({ mode: "soft" });
3361
- if (pw) try {
3362
- await (await pw.getPageForTargetId({
3363
- cdpUrl: params.profileCtx.profile.cdpUrl,
3364
- targetId: params.targetId,
3365
- ssrfPolicy: params.ssrfPolicy
3366
- })).context().grantPermissions(playwrightRequiredPermissions, { origin: params.origin });
3367
- return {
3368
- grantedPermissions: params.requiredPermissions,
3369
- unsupportedPermissions: params.optionalPermissions,
3370
- grantMethod: "playwright"
3371
- };
3372
- } catch {}
3373
- }
3374
- let unsupportedPermissions = [];
3375
- await withCdpSocket(params.wsUrl, async (send) => {
3376
- try {
3377
- await send("Browser.grantPermissions", {
3378
- origin: params.origin,
3379
- permissions: allPermissions
3380
- });
3381
- return;
3382
- } catch (error) {
3383
- if (params.optionalPermissions.length === 0) throw error;
3384
- }
3385
- await send("Browser.grantPermissions", {
3386
- origin: params.origin,
3387
- permissions: params.requiredPermissions
3388
- });
3389
- unsupportedPermissions = params.optionalPermissions;
3390
- }, { commandTimeoutMs: params.timeoutMs });
3391
- return {
3392
- grantedPermissions: allPermissions.filter((value) => !unsupportedPermissions.includes(value)),
3393
- unsupportedPermissions,
3394
- grantMethod: "cdp"
3395
- };
3396
- }
3397
- function toPlaywrightPermission(permission) {
3398
- switch (permission) {
3399
- case "audioCapture": return "microphone";
3400
- case "videoCapture": return "camera";
3401
- default: return;
3402
- }
3403
- }
3404
- function registerBrowserPermissionRoutes(app, ctx) {
3405
- app.post("/permissions/grant", asyncBrowserRoute(async (req, res) => {
3406
- const profileCtx = getProfileContext(req, ctx);
3407
- if ("error" in profileCtx) return jsonError(res, profileCtx.status, profileCtx.error);
3408
- const body = req.body ?? {};
3409
- const origin = readOrigin(body.origin);
3410
- if (!origin) return jsonError(res, 400, "origin must be an http(s) origin");
3411
- const requiredPermissions = readPermissions(body.permissions);
3412
- if (!requiredPermissions || requiredPermissions.length === 0) return jsonError(res, 400, "permissions must be a non-empty string array");
3413
- const optionalPermissions = readPermissions(body.optionalPermissions ?? []) ?? [];
3414
- const targetId = toStringOrEmpty(body.targetId) || void 0;
3415
- let timeoutMs;
3416
- try {
3417
- timeoutMs = readRouteTimerTimeoutMs(body.timeoutMs, "timeoutMs", { minMs: 1e3 }) ?? 5e3;
3418
- } catch (err) {
3419
- return jsonError(res, 400, formatErrorMessage(err));
3420
- }
3421
- try {
3422
- await profileCtx.ensureBrowserAvailable();
3423
- const wsUrl = await getChromeWebSocketUrl(profileCtx.profile.cdpUrl, timeoutMs, ctx.state().resolved.ssrfPolicy);
3424
- if (!wsUrl) return jsonError(res, 409, "browser CDP WebSocket unavailable");
3425
- const granted = await grantPermissions({
3426
- profileCtx,
3427
- targetId,
3428
- wsUrl,
3429
- origin,
3430
- requiredPermissions,
3431
- optionalPermissions,
3432
- timeoutMs,
3433
- ssrfPolicy: ctx.state().resolved.ssrfPolicy
3434
- });
3435
- return res.json({
3436
- ok: true,
3437
- origin,
3438
- ...granted
3439
- });
3440
- } catch (error) {
3441
- return jsonError(res, 500, error instanceof Error ? error.message : String(error));
3442
- }
3443
- }));
3444
- }
3445
- //#endregion
3446
- //#region extensions/browser/src/browser/routes/tabs.ts
3447
- function handleTabsRouteError(ctx, res, err, opts) {
3448
- if (opts?.mapTabError) {
3449
- const mapped = ctx.mapTabError(err);
3450
- if (mapped) return jsonError(res, mapped.status, mapped.message);
3451
- }
3452
- return jsonError(res, 500, String(err));
3453
- }
3454
- async function withTabsProfileRoute(params) {
3455
- const profileCtx = resolveProfileContext(params.req, params.res, params.ctx);
3456
- if (!profileCtx) return;
3457
- try {
3458
- await params.run(profileCtx);
3459
- } catch (err) {
3460
- handleTabsRouteError(params.ctx, params.res, err, { mapTabError: params.mapTabError });
3461
- }
3462
- }
3463
- async function ensureBrowserRunning(profileCtx, res) {
3464
- if (!await profileCtx.isReachable(300)) {
3465
- jsonError(res, new BrowserProfileUnavailableError("browser not running").status, "browser not running");
3466
- return false;
3467
- }
3468
- return true;
3469
- }
3470
- async function redactBlockedTabUrls(params) {
3471
- const ssrfPolicyOpts = withBrowserNavigationPolicy(params.ssrfPolicy);
3472
- if (!ssrfPolicyOpts.ssrfPolicy) return params.tabs;
3473
- const redactedTabs = [];
3474
- for (const tab of params.tabs) try {
3475
- await assertBrowserNavigationResultAllowed({
3476
- url: tab.url,
3477
- ...ssrfPolicyOpts
3478
- });
3479
- redactedTabs.push(tab);
3480
- } catch {
3481
- redactedTabs.push({
3482
- ...tab,
3483
- url: ""
3484
- });
3485
- }
3486
- return redactedTabs;
3487
- }
3488
- function resolveIndexedTab(tabs, index) {
3489
- return typeof index === "number" ? tabs[index] : tabs.at(0);
3490
- }
3491
- function parseRequiredTargetId(res, rawTargetId) {
3492
- const targetId = toStringOrEmpty(rawTargetId);
3493
- if (!targetId) {
3494
- jsonError(res, 400, "targetId is required");
3495
- return null;
3496
- }
3497
- return targetId;
3498
- }
3499
- function readOptionalTabLabel(body) {
3500
- return toStringOrEmpty(body?.label) || void 0;
3501
- }
3502
- function readTabIndex(res, body, opts) {
3503
- const record = body && typeof body === "object" ? body : {};
3504
- if (!Object.hasOwn(record, "index")) {
3505
- if (opts?.required) {
3506
- jsonError(res, 400, "index is required");
3507
- return null;
3508
- }
3509
- return;
3510
- }
3511
- if (record.index == null) {
3512
- jsonError(res, 400, "index must be a non-negative integer");
3513
- return null;
3514
- }
3515
- try {
3516
- return readRouteNonNegativeInteger(record.index, "index", { invalidMessage: "index must be a non-negative integer" });
3517
- } catch (error) {
3518
- jsonError(res, 400, error instanceof Error ? error.message : String(error));
3519
- return null;
3520
- }
3521
- }
3522
- async function runTabTargetMutation(params) {
3523
- await withTabsProfileRoute({
3524
- req: params.req,
3525
- res: params.res,
3526
- ctx: params.ctx,
3527
- mapTabError: true,
3528
- run: async (profileCtx) => {
3529
- if (!await ensureBrowserRunning(profileCtx, params.res)) return;
3530
- await params.mutate(profileCtx, params.targetId);
3531
- params.res.json({ ok: true });
3532
- }
3533
- });
3534
- }
3535
- function registerBrowserTabRoutes(app, ctx) {
3536
- app.get("/tabs", asyncBrowserRoute(async (req, res) => {
3537
- await withTabsProfileRoute({
3538
- req,
3539
- res,
3540
- ctx,
3541
- run: async (profileCtx) => {
3542
- if (!await profileCtx.isReachable(300)) return res.json({
3543
- running: false,
3544
- tabs: []
3545
- });
3546
- const tabs = await redactBlockedTabUrls({
3547
- tabs: await profileCtx.listTabs(),
3548
- ssrfPolicy: ctx.state().resolved.ssrfPolicy
3549
- });
3550
- res.json({
3551
- running: true,
3552
- tabs
3553
- });
3554
- }
3555
- });
3556
- }));
3557
- app.post("/tabs/open", asyncBrowserRoute(async (req, res) => {
3558
- const url = toStringOrEmpty(req.body?.url);
3559
- const label = readOptionalTabLabel(req.body);
3560
- if (!url) return jsonError(res, 400, "url is required");
3561
- await withTabsProfileRoute({
3562
- req,
3563
- res,
3564
- ctx,
3565
- mapTabError: true,
3566
- run: async (profileCtx) => {
3567
- await assertBrowserNavigationAllowed({
3568
- url,
3569
- ...browserNavigationPolicyForProfile(ctx, profileCtx)
3570
- });
3571
- await profileCtx.ensureBrowserAvailable();
3572
- const tab = await profileCtx.openTab(url, { label });
3573
- res.json(tab);
3574
- }
3575
- });
3576
- }));
3577
- app.post("/tabs/focus", asyncBrowserRoute(async (req, res) => {
3578
- const targetId = parseRequiredTargetId(res, req.body?.targetId);
3579
- if (!targetId) return;
3580
- await runTabTargetMutation({
3581
- req,
3582
- res,
3583
- ctx,
3584
- targetId,
3585
- mutate: async (profileCtx, id) => {
3586
- const tabs = await profileCtx.listTabs();
3587
- const resolved = resolveTargetIdFromTabs(id, tabs);
3588
- if (!resolved.ok) {
3589
- if (resolved.reason === "ambiguous") throw new BrowserTargetAmbiguousError();
3590
- throw new BrowserTabNotFoundError({ input: id });
3591
- }
3592
- const tab = tabs.find((currentTab) => currentTab.targetId === resolved.targetId);
3593
- if (!tab) throw new BrowserTabNotFoundError({ input: id });
3594
- const ssrfPolicyOpts = browserNavigationPolicyForProfile(ctx, profileCtx);
3595
- if (ssrfPolicyOpts.ssrfPolicy) await assertBrowserNavigationResultAllowed({
3596
- url: tab.url,
3597
- ...ssrfPolicyOpts
3598
- });
3599
- await profileCtx.focusTab(resolved.targetId);
3600
- }
3601
- });
3602
- }));
3603
- app.delete("/tabs/:targetId", asyncBrowserRoute(async (req, res) => {
3604
- const targetId = parseRequiredTargetId(res, req.params.targetId);
3605
- if (!targetId) return;
3606
- await runTabTargetMutation({
3607
- req,
3608
- res,
3609
- ctx,
3610
- targetId,
3611
- mutate: async (profileCtx, id) => {
3612
- await profileCtx.closeTab(id);
3613
- }
3614
- });
3615
- }));
3616
- app.post("/tabs/action", asyncBrowserRoute(async (req, res) => {
3617
- const action = toStringOrEmpty(req.body?.action);
3618
- await withTabsProfileRoute({
3619
- req,
3620
- res,
3621
- ctx,
3622
- mapTabError: true,
3623
- run: async (profileCtx) => {
3624
- if (action === "list") {
3625
- if (!await profileCtx.isReachable(300)) return res.json({
3626
- ok: true,
3627
- tabs: []
3628
- });
3629
- const tabs = await redactBlockedTabUrls({
3630
- tabs: await profileCtx.listTabs(),
3631
- ssrfPolicy: ctx.state().resolved.ssrfPolicy
3632
- });
3633
- return res.json({
3634
- ok: true,
3635
- tabs
3636
- });
3637
- }
3638
- if (action === "new") {
3639
- await profileCtx.ensureBrowserAvailable();
3640
- const tab = await profileCtx.openTab("about:blank", { label: readOptionalTabLabel(req.body) });
3641
- return res.json({
3642
- ok: true,
3643
- tab
3644
- });
3645
- }
3646
- if (action === "label") {
3647
- if (!await ensureBrowserRunning(profileCtx, res)) return;
3648
- const targetId = parseRequiredTargetId(res, req.body?.targetId);
3649
- if (!targetId) return;
3650
- const label = readOptionalTabLabel(req.body);
3651
- if (!label) return jsonError(res, 400, "label is required");
3652
- const tab = await profileCtx.labelTab(targetId, label);
3653
- return res.json({
3654
- ok: true,
3655
- tab
3656
- });
3657
- }
3658
- if (action === "close") {
3659
- if (!await ensureBrowserRunning(profileCtx, res)) return;
3660
- const index = readTabIndex(res, req.body);
3661
- if (index === null) return;
3662
- const target = resolveIndexedTab(await profileCtx.listTabs(), index);
3663
- if (!target) throw new BrowserTabNotFoundError();
3664
- await profileCtx.closeTab(target.targetId);
3665
- return res.json({
3666
- ok: true,
3667
- targetId: target.targetId
3668
- });
3669
- }
3670
- if (action === "select") {
3671
- const index = readTabIndex(res, req.body, { required: true });
3672
- if (index === null || index === void 0) return;
3673
- if (!await ensureBrowserRunning(profileCtx, res)) return;
3674
- const target = (await profileCtx.listTabs())[index];
3675
- if (!target) throw new BrowserTabNotFoundError();
3676
- const ssrfPolicyOpts = browserNavigationPolicyForProfile(ctx, profileCtx);
3677
- if (ssrfPolicyOpts.ssrfPolicy) await assertBrowserNavigationResultAllowed({
3678
- url: target.url,
3679
- ...ssrfPolicyOpts
3680
- });
3681
- await profileCtx.focusTab(target.targetId);
3682
- return res.json({
3683
- ok: true,
3684
- targetId: target.targetId
3685
- });
3686
- }
3687
- return jsonError(res, 400, "unknown tab action");
3688
- }
3689
- });
3690
- }));
3691
- }
3692
- //#endregion
3693
- //#region extensions/browser/src/browser/routes/index.ts
3694
- function registerBrowserRoutes(app, ctx) {
3695
- registerBrowserBasicRoutes(app, ctx);
3696
- registerBrowserTabRoutes(app, ctx);
3697
- registerBrowserPermissionRoutes(app, ctx);
3698
- registerBrowserAgentRoutes(app, ctx);
3699
- }
3700
- //#endregion
3701
- export { registerBrowserRoutes as t };