activeclaw 2026.2.11 → 2026.2.13

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 (531) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/dist/{accounts-DbzMEfKN.js → accounts-DCDeFTra.js} +2 -2
  3. package/dist/{accounts-C2elk6PC.js → accounts-DeqIQjo1.js} +2 -2
  4. package/dist/{acp-cli-CVFTdsQY.js → acp-cli-CeYI4XRd.js} +15 -16
  5. package/dist/{acp-cli-BpJwIyLl.js → acp-cli-rNbGXICg.js} +14 -15
  6. package/dist/{agent-Bz1r5O8q.js → agent-BvNJF5QL.js} +19 -15
  7. package/dist/{agent-22-R4bNS.js → agent-CyMxTyrG.js} +20 -16
  8. package/dist/{agent-scope-D8miw9q_.js → agent-scope-BIEhVP4_.js} +172 -4
  9. package/dist/{agent-scope-CGmuusG9.js → agent-scope-CQCus0rI.js} +3 -3
  10. package/dist/{agent-scope-DQuy3dwI.js → agent-scope-CsRbLH4l.js} +4 -4
  11. package/dist/{agent-scope-BEf5crnU.js → agent-scope-DPIFau3f.js} +5 -1
  12. package/dist/audio-preflight-BU8W7uxc.js +60 -0
  13. package/dist/audio-preflight-CGsumMzb.js +60 -0
  14. package/dist/audio-preflight-SLmkJI6-.js +74 -0
  15. package/dist/audio-preflight-jZc5mFCZ.js +71 -0
  16. package/dist/{audit-C4wLaF0D.js → audit-Dmww_503.js} +71 -19
  17. package/dist/{audit-CY-yopxa.js → audit-wPu26VMb.js} +72 -20
  18. package/dist/{tailscale-DU6DgqVy.js → auth-9x3lqfIY.js} +208 -3
  19. package/dist/{tailscale-Cu-2HNvU.js → auth-CQNl_IaI.js} +190 -3
  20. package/dist/{auth-health-BFKUoCwJ.js → auth-health-C4L4FGBA.js} +1 -1
  21. package/dist/{auth-health-d7BMZlWG.js → auth-health-j6epgQbq.js} +1 -1
  22. package/dist/{auth-profiles-Bv1AEm-Y.js → auth-profiles-ByNs3eEm.js} +87 -31
  23. package/dist/build-info.json +3 -3
  24. package/dist/bundled/boot-md/handler.js +28 -22
  25. package/dist/bundled/session-memory/handler.js +33 -22
  26. package/dist/{call-7yrB6v4I.js → call-DVYCIV8m.js} +5 -5
  27. package/dist/{call-Bek1xlgk.js → call-SolyGS1r.js} +6 -6
  28. package/dist/canvas-host/a2ui/.bundle.hash +1 -1
  29. package/dist/{channel-options-3mdYN0C_.js → channel-options-BwC2yQcR.js} +4 -4
  30. package/dist/{channel-options-DJ0b1m7B.js → channel-options-Cq9BVDkP.js} +12 -7
  31. package/dist/{channel-selection-RZimme3j.js → channel-selection-D4D6ImhN.js} +2 -2
  32. package/dist/{channel-selection-B9b7Kuit.js → channel-selection-MZAHm4U8.js} +2 -2
  33. package/dist/{channels-cli-CYbK2Dku.js → channels-cli-9Dsk9Qm7.js} +57 -53
  34. package/dist/{channels-cli-BFznbGOs.js → channels-cli-BJUppQll.js} +59 -55
  35. package/dist/{channels-status-issues-B3KkflfR.js → channels-status-issues-D7GSV1GS.js} +1 -1
  36. package/dist/{channels-status-issues-DQkRaZts.js → channels-status-issues-DDAWeT-6.js} +1 -1
  37. package/dist/{chrome-Db7w64LF.js → chrome-BfB6JdKF.js} +4 -4
  38. package/dist/{chrome-Dm-EgOjJ.js → chrome-Cvr-57lg.js} +6 -5
  39. package/dist/{chrome-CF16STk9.js → chrome-DL0avO8n.js} +2 -1
  40. package/dist/{chrome-yIKmOzCO.js → chrome-foEwx3lN.js} +5 -4
  41. package/dist/{clack-prompter-BCiBkJVr.js → clack-prompter-Bz3Mmcl-.js} +5 -5
  42. package/dist/{clack-prompter-DuBVnTKy.js → clack-prompter-ChCGXfyt.js} +4 -4
  43. package/dist/cli/daemon-cli.js +1 -1
  44. package/dist/{cli-Cl3PdJei.js → cli-ZR9ugUBX.js} +42 -38
  45. package/dist/cli-miPe4Ujz.js +93 -0
  46. package/dist/{client-6xKrRC-1.js → client-BrYfyoDK.js} +54 -5
  47. package/dist/{client-DMloFP_O.js → client-CTwXnRl7.js} +54 -5
  48. package/dist/{command-format-ayFsmwwz.js → command-format-Bxe0mWee.js} +1 -1
  49. package/dist/{command-options-BTAzyqqb.js → command-options-BvgxzPbK.js} +9 -4
  50. package/dist/{commands-CjEGXOZ_.js → commands-BX_OIIVR.js} +4 -4
  51. package/dist/{completion-cli-DrJGfJGl.js → completion-cli-CR77-jyv.js} +3 -3
  52. package/dist/{completion-cli-DOec3E2Z.js → completion-cli-DnjpxAag.js} +30 -30
  53. package/dist/{config-B00lvFac.js → config-Bdhomfei.js} +21 -7
  54. package/dist/{config-XBdA0ciN.js → config-BvMsmctM.js} +83 -9
  55. package/dist/{config-BqGVMf1y.js → config-QYrbd7x7.js} +60 -6
  56. package/dist/{config--NUdpACy.js → config-aFQssWKX.js} +21 -7
  57. package/dist/{config-guard-4kCO_rnQ.js → config-guard-CljaSxJd.js} +160 -51
  58. package/dist/{configure-B69emwZv.js → configure-BXLiucXo.js} +28 -25
  59. package/dist/{configure-sMhpLzFf.js → configure-BYPqXzGZ.js} +28 -25
  60. package/dist/control-auth-8Cf4WXpR.js +54 -0
  61. package/dist/control-auth-DBCu3qyv.js +54 -0
  62. package/dist/{control-service-Db_1V-KY.js → control-service-B5KnPqGP.js} +11 -5
  63. package/dist/{control-service-IRAmbcbN.js → control-service-DKnttEus.js} +10 -4
  64. package/dist/control-ui/assets/{index-CnB9IO4a.js → index-B4LPvte9.js} +369 -369
  65. package/dist/control-ui/assets/index-B4LPvte9.js.map +1 -0
  66. package/dist/control-ui/index.html +1 -1
  67. package/dist/{cron-cli-Cum2324v.js → cron-cli-D7BRjDv2.js} +20 -20
  68. package/dist/{cron-cli-DhUWcYdk.js → cron-cli-z1zk_FXQ.js} +19 -19
  69. package/dist/{daemon-cli-q7nkEF5-.js → daemon-cli-BDkU2ocb.js} +60 -21
  70. package/dist/{daemon-cli-CTC2CHci.js → daemon-cli-cNSF93-v.js} +59 -20
  71. package/dist/{daemon-runtime-c0uXH4Dl.js → daemon-runtime-B0tg_LsX.js} +3 -3
  72. package/dist/{daemon-runtime-UsK-tOty.js → daemon-runtime-Bsjeut6m.js} +3 -3
  73. package/dist/{deliver-hf-WKyWd.js → deliver-CIU9Npgs.js} +373 -281
  74. package/dist/{deliver-CT6KiDqO.js → deliver-DYYCo1G7.js} +369 -278
  75. package/dist/{deliver-T9d44OpZ.js → deliver-LsxKETro.js} +371 -279
  76. package/dist/{deliver-CPy8jYj9.js → deliver-xUU3mGHo.js} +369 -277
  77. package/dist/{deps-Bv1kLtwo.js → deps-QSwGcoNZ.js} +2 -2
  78. package/dist/{deps-DFQdAWQc.js → deps-lAAA2zYI.js} +2 -2
  79. package/dist/{devices-cli-Cm7U1py9.js → devices-cli-BG3-2oqt.js} +14 -14
  80. package/dist/{devices-cli-ZpjlfK-e.js → devices-cli-VIQtOvt_.js} +14 -14
  81. package/dist/{directory-cli-B14TUSJA.js → directory-cli-BCJwjVC0.js} +16 -16
  82. package/dist/{directory-cli-67kzd4I5.js → directory-cli-jYzZ02gk.js} +14 -14
  83. package/dist/{dispatcher-3ElQWGVI.js → dispatcher-DY51b-Zc.js} +2 -2
  84. package/dist/{dns-cli-CU-xfhTN.js → dns-cli-DHIiMJjS.js} +12 -12
  85. package/dist/{dns-cli-Dqj7O6Q_.js → dns-cli-pZlv87Ib.js} +11 -11
  86. package/dist/{docs-cli-CamBqzb5.js → docs-cli-2JDiwfzP.js} +8 -8
  87. package/dist/{docs-cli-Cj3L5oqB.js → docs-cli-BhkYqoIQ.js} +7 -7
  88. package/dist/{doctor-BV1kvbMm.js → doctor-Bf8EhNtA.js} +36 -35
  89. package/dist/{doctor-BJirShBi.js → doctor-sYG5V4Co.js} +34 -33
  90. package/dist/entry.js +56 -18
  91. package/dist/{env-BxRc6wWv.js → env-ONzUVAG2.js} +1 -1
  92. package/dist/{exec-CijMSZd9.js → exec-B8lXct-k.js} +503 -14
  93. package/dist/{exec-B8JKbXKW.js → exec-CACT5OAW.js} +1 -1
  94. package/dist/{exec-57A8Rlc8.js → exec-CJFFoM7H.js} +32 -13
  95. package/dist/{exec-Cv_Ofd1m.js → exec-YIosokWE.js} +1 -1
  96. package/dist/{exec-approvals-cli-DEzz9Iai.js → exec-approvals-cli-7LH0lwhO.js} +21 -21
  97. package/dist/{exec-approvals-cli-DhXj3hQX.js → exec-approvals-cli-apGnQbpj.js} +21 -21
  98. package/dist/extensionAPI.js +7733 -8746
  99. package/dist/fetch-DmiOpALK.js +274 -0
  100. package/dist/fetch-timeout-BEtUjM1S.js +274 -0
  101. package/dist/fetch-timeout-DEoXG_SF.js +274 -0
  102. package/dist/fetch-timeout-DTK9vxex.js +274 -0
  103. package/dist/{gateway-cli-D1EdIq8I.js → gateway-cli-DUdYxlZS.js} +491 -136
  104. package/dist/{gateway-cli-B_xDUDy2.js → gateway-cli-DbvWmE-9.js} +495 -140
  105. package/dist/{gateway-rpc-3B5y445n.js → gateway-rpc-BByb2Snz.js} +3 -3
  106. package/dist/{gateway-rpc-BoL2vinh.js → gateway-rpc-wXSCUZXj.js} +3 -3
  107. package/dist/{github-copilot-auth-Omqrto0J.js → github-copilot-auth-D7ewvpMd.js} +205 -17
  108. package/dist/{github-copilot-auth-CZxurvdz.js → github-copilot-auth-DDispnyz.js} +205 -17
  109. package/dist/{github-copilot-token-SLWintYd.js → github-copilot-token-Cfs0Wxr8.js} +1 -1
  110. package/dist/{gmail-setup-utils-BXQKsLtI.js → gmail-setup-utils-Cfns8TQx.js} +3 -3
  111. package/dist/{gmail-setup-utils-CHcssBOA.js → gmail-setup-utils-DJb-_5kO.js} +4 -4
  112. package/dist/{health-format-Dy1caGsq.js → health-format-KGPokKJH.js} +97 -42
  113. package/dist/{health-format-DrGFg8bx.js → health-format-LZDxu3rv.js} +95 -40
  114. package/dist/{help-format-DAj7l5uV.js → help-format-C48TXngO.js} +1 -1
  115. package/dist/{help-format-CUnac_bT.js → help-format-R5fLToDw.js} +1 -1
  116. package/dist/{hooks-cli-ptEf6TIM.js → hooks-cli-CT8JCRkH.js} +51 -46
  117. package/dist/{hooks-cli-Bhf5VRp1.js → hooks-cli-S1MKumJO.js} +49 -44
  118. package/dist/{hooks-status-Br-2bK2G.js → hooks-status-Cw0xD8Lt.js} +3 -3
  119. package/dist/{hooks-status-DNQJSa4B.js → hooks-status-D9MhwHRp.js} +3 -3
  120. package/dist/{image-rOFfK3PJ.js → image-Brk1sJbw.js} +10 -7
  121. package/dist/{image-fUwR7slg.js → image-C4Nn2p3e.js} +10 -7
  122. package/dist/{image-Ds4NLGPR.js → image-DgtfXMcX.js} +9 -6
  123. package/dist/{image-Dnnxt82I.js → image-RKwc3fsL.js} +8 -5
  124. package/dist/index.js +208 -97
  125. package/dist/{installs-CRSjQxbR.js → installs-CrLcWYHe.js} +8 -7
  126. package/dist/{installs-89zeUsVn.js → installs-DscWb9b9.js} +8 -7
  127. package/dist/{links-7M-j83As.js → links-B8LAzWwg.js} +1 -1
  128. package/dist/{links-C591fM9M.js → links-Eax1UO3w.js} +1 -1
  129. package/dist/llm-slug-generator.js +18 -19
  130. package/dist/{loader-wXwp4rZJ.js → loader-KjT074JR.js} +5722 -6888
  131. package/dist/{logging-MMRGFxGI.js → logging-BAyPwvdH.js} +1 -1
  132. package/dist/{logging-DuK6YXuK.js → logging-CRq4h04P.js} +2 -2
  133. package/dist/{login-qr-wM8BnKJh.js → login-qr-B6ZgAuIf.js} +5 -5
  134. package/dist/{login-qr-CPEsT6dN.js → login-qr-Bua-p0nG.js} +3 -4
  135. package/dist/{login-qr-CGEu5TU-.js → login-qr-CuvemJj4.js} +6 -6
  136. package/dist/{login-qr-DH150tTp.js → login-qr-Djr1JfIf.js} +2 -2
  137. package/dist/{logs-cli-ClgkHnfT.js → logs-cli-9IAV7rWY.js} +38 -22
  138. package/dist/{logs-cli-CmfINsOj.js → logs-cli-EiKzUFPa.js} +37 -21
  139. package/dist/{manager-DYo4PlVM.js → manager-BIMh_eSm.js} +7 -8
  140. package/dist/{manager-D6EbxDV4.js → manager-CwinWQoz.js} +5 -5
  141. package/dist/{manager-BbnHek5T.js → manager-DkqF1GiK.js} +9 -9
  142. package/dist/{manager-CcVYv0N5.js → manager-T1XfGchB.js} +8 -8
  143. package/dist/{manifest-registry-3It8Z8yN.js → manifest-registry-CQhdnDBZ.js} +40 -2
  144. package/dist/{manifest-registry-D5SiA3xq.js → manifest-registry-u0okVSkU.js} +40 -2
  145. package/dist/{message-channel-Cu61-7H6.js → message-channel-BLi2a6Yw.js} +1 -1
  146. package/dist/{message-channel-BlgPSDAh.js → message-channel-C_MmebBt.js} +1 -1
  147. package/dist/{model-auth-ioeR_zLX.js → model-auth-CabXIF6O.js} +116 -34
  148. package/dist/{model-selection-BK7DuyH8.js → model-selection-BLuqsGVB.js} +86 -30
  149. package/dist/{model-selection-CezC36lH.js → model-selection-C1GmkTAV.js} +84 -28
  150. package/dist/{models-cli-C3uGdOrd.js → models-cli-9jmDv-h3.js} +52 -48
  151. package/dist/{models-cli-CUIVPgXE.js → models-cli-zS9rtWz8.js} +53 -49
  152. package/dist/{node-cli-BxBGSuPE.js → node-cli-CrpTxTTs.js} +28 -26
  153. package/dist/{node-cli-CdYAsuQQ.js → node-cli-wemUMCg-.js} +28 -26
  154. package/dist/{node-service-u8g85nD3.js → node-service-C8DTHTMg.js} +2 -2
  155. package/dist/{node-service-CM5vkdIo.js → node-service-WQuEKz6W.js} +2 -2
  156. package/dist/{nodes-cli-By6yeCTB.js → nodes-cli-BaU2SIFw.js} +20 -20
  157. package/dist/{nodes-cli-BaVMTAPc.js → nodes-cli-Dx23D72n.js} +20 -20
  158. package/dist/{nodes-screen-Dvl_ohUY.js → nodes-screen-C0IuBqUL.js} +1 -1
  159. package/dist/{note-5WqioBRA.js → note-BhRSeNeu.js} +2 -2
  160. package/dist/{note-Ci08TSbV.js → note-hhtubr2j.js} +1 -1
  161. package/dist/{onboard-channels-DxXvp8og.js → onboard-channels-C501x8GI.js} +8 -8
  162. package/dist/{onboard-channels-CXhnVy4E.js → onboard-channels-Dxzroasd.js} +8 -8
  163. package/dist/{onboard-skills-CBxsRGyf.js → onboard-skills-DV0Qzvjj.js} +440 -136
  164. package/dist/{onboard-skills-DQwOQ6Ry.js → onboard-skills-rlBHcu3Q.js} +439 -135
  165. package/dist/{onboarding-Du_7qEng.js → onboarding-CN-EDLjd.js} +38 -38
  166. package/dist/{openclaw-root-JLDMp6ux.js → openclaw-root-1VeFrph_.js} +4 -0
  167. package/dist/{openclaw-root-Dw6gumSU.js → openclaw-root-BNlEap4i.js} +4 -0
  168. package/dist/{pairing-cli-CRQDpj8f.js → pairing-cli-CDHG4xuI.js} +15 -15
  169. package/dist/{pairing-cli-Cng1KFWw.js → pairing-cli-CQP34Dlx.js} +15 -15
  170. package/dist/{pairing-labels-Ciu3Zoxj.js → pairing-labels-B6CN0SNH.js} +1 -1
  171. package/dist/{pairing-labels-CWFEtSc3.js → pairing-labels-CgNHnjzT.js} +1 -1
  172. package/dist/{pairing-store-c-QQ2u8p.js → pairing-store-CmlRVqOz.js} +2 -2
  173. package/dist/{pairing-store-CgXR3ZWJ.js → pairing-store-Dp5_JGnG.js} +3 -3
  174. package/dist/{path-env-CXWUFfFv.js → path-env-CLvYNwtL.js} +1 -1
  175. package/dist/{path-env-BgLvMbz_.js → path-env-CaYUVIML.js} +2 -2
  176. package/dist/{paths-MnZaxqPw.js → paths-B0a4ywSO.js} +30 -5
  177. package/dist/{paths-Bkhd_qY8.js → paths-B49s6UZQ.js} +30 -5
  178. package/dist/{paths-DL6EIRTw.js → paths-D0O87MfH.js} +30 -5
  179. package/dist/{paths-IivnSNkP.js → paths-DLINmNFQ.js} +31 -6
  180. package/dist/{pi-embedded-CgPTEqlB.js → pi-embedded-Ctrt2kz0.js} +8759 -9600
  181. package/dist/{pi-embedded-helpers-DYH6OWft.js → pi-embedded-helpers-CMKLjW6X.js} +68 -9
  182. package/dist/{pi-embedded-helpers-y1_Se0yq.js → pi-embedded-helpers-CUzTc1v6.js} +241 -24
  183. package/dist/{pi-embedded-helpers-Bkpd4fTr.js → pi-embedded-helpers-DfwkwPYD.js} +67 -8
  184. package/dist/{pi-embedded-helpers-BbWRSUnc.js → pi-embedded-helpers-WDwx99UA.js} +347 -32
  185. package/dist/{pi-tools.policy-akYsGFiA.js → pi-tools.policy-BpsROZbz.js} +4 -4
  186. package/dist/{plugin-auto-enable-lZwe2yX5.js → plugin-auto-enable-Bqhc3w5n.js} +5 -5
  187. package/dist/{plugin-auto-enable-AOSOJ-v1.js → plugin-auto-enable-PW76g_PJ.js} +5 -5
  188. package/dist/plugin-sdk/agents/bash-process-registry.d.ts +1 -0
  189. package/dist/plugin-sdk/agents/models-config.providers.d.ts +10 -0
  190. package/dist/plugin-sdk/agents/pi-embedded-helpers/errors.d.ts +5 -1
  191. package/dist/plugin-sdk/agents/pi-embedded-helpers.d.ts +1 -1
  192. package/dist/plugin-sdk/agents/pi-embedded-runner/google.d.ts +1 -0
  193. package/dist/plugin-sdk/agents/pi-embedded-runner/run/params.d.ts +2 -0
  194. package/dist/plugin-sdk/agents/pi-embedded-runner/run/payloads.d.ts +1 -0
  195. package/dist/plugin-sdk/agents/pi-embedded-runner/run/types.d.ts +2 -0
  196. package/dist/plugin-sdk/agents/pi-embedded-runner/types.d.ts +15 -0
  197. package/dist/plugin-sdk/agents/pi-embedded-subscribe.handlers.tools.d.ts +1 -1
  198. package/dist/plugin-sdk/agents/pi-embedded-subscribe.handlers.types.d.ts +2 -0
  199. package/dist/plugin-sdk/agents/pi-embedded-subscribe.types.d.ts +2 -0
  200. package/dist/plugin-sdk/agents/session-tool-result-guard-wrapper.d.ts +2 -0
  201. package/dist/plugin-sdk/agents/session-tool-result-guard.d.ts +4 -0
  202. package/dist/plugin-sdk/agents/tools/agent-step.d.ts +3 -0
  203. package/dist/plugin-sdk/agents/tools/browser-tool.schema.d.ts +1 -1
  204. package/dist/plugin-sdk/agents/tools/web-search.d.ts +10 -1
  205. package/dist/plugin-sdk/agents/usage.d.ts +1 -0
  206. package/dist/plugin-sdk/auto-reply/heartbeat.d.ts +1 -1
  207. package/dist/plugin-sdk/auto-reply/reply/get-reply-directives.d.ts +1 -0
  208. package/dist/plugin-sdk/auto-reply/reply/mentions.d.ts +1 -0
  209. package/dist/plugin-sdk/auto-reply/reply/model-selection.d.ts +3 -0
  210. package/dist/plugin-sdk/auto-reply/reply/reply-reference.d.ts +1 -1
  211. package/dist/plugin-sdk/auto-reply/reply/session-run-accounting.d.ts +11 -0
  212. package/dist/plugin-sdk/auto-reply/reply/session-usage.d.ts +8 -0
  213. package/dist/plugin-sdk/auto-reply/types.d.ts +2 -0
  214. package/dist/plugin-sdk/browser/control-auth.d.ts +13 -0
  215. package/dist/plugin-sdk/channels/plugins/onboarding/signal.d.ts +1 -0
  216. package/dist/plugin-sdk/cli/prompt.d.ts +1 -0
  217. package/dist/plugin-sdk/commands/agent/types.d.ts +2 -0
  218. package/dist/plugin-sdk/commands/onboard-types.d.ts +7 -1
  219. package/dist/plugin-sdk/config/sessions/paths.d.ts +7 -2
  220. package/dist/plugin-sdk/config/types.agents.d.ts +2 -0
  221. package/dist/plugin-sdk/config/types.discord.d.ts +5 -0
  222. package/dist/plugin-sdk/config/types.gateway.d.ts +15 -0
  223. package/dist/plugin-sdk/config/types.hooks.d.ts +15 -0
  224. package/dist/plugin-sdk/config/types.memory.d.ts +2 -0
  225. package/dist/plugin-sdk/config/zod-schema.agents.d.ts +1 -0
  226. package/dist/plugin-sdk/config/zod-schema.d.ts +13 -1
  227. package/dist/plugin-sdk/config/zod-schema.hooks.d.ts +1 -1
  228. package/dist/plugin-sdk/config/zod-schema.providers-core.d.ts +9 -0
  229. package/dist/plugin-sdk/config/zod-schema.providers.d.ts +4 -0
  230. package/dist/plugin-sdk/cron/service/jobs.d.ts +8 -0
  231. package/dist/plugin-sdk/cron/service/state.d.ts +1 -0
  232. package/dist/plugin-sdk/cron/types.d.ts +2 -0
  233. package/dist/plugin-sdk/discord/monitor/allow-list.d.ts +15 -0
  234. package/dist/plugin-sdk/discord/send.types.d.ts +5 -0
  235. package/dist/plugin-sdk/gateway/auth.d.ts +36 -0
  236. package/dist/plugin-sdk/gateway/protocol/index.d.ts +0 -3
  237. package/dist/plugin-sdk/gateway/protocol/schema/agent.d.ts +7 -1
  238. package/dist/plugin-sdk/gateway/session-utils.fs.d.ts +3 -1
  239. package/dist/plugin-sdk/index.js +935 -660
  240. package/dist/plugin-sdk/infra/binaries.d.ts +3 -0
  241. package/dist/plugin-sdk/infra/heartbeat-active-hours.d.ts +5 -0
  242. package/dist/plugin-sdk/infra/heartbeat-runner.d.ts +1 -0
  243. package/dist/plugin-sdk/infra/net/fetch-guard.d.ts +1 -0
  244. package/dist/plugin-sdk/infra/net/ssrf.d.ts +1 -0
  245. package/dist/plugin-sdk/infra/tailscale.d.ts +34 -0
  246. package/dist/plugin-sdk/infra/tmp-openclaw-dir.d.ts +10 -0
  247. package/dist/plugin-sdk/logging/console.d.ts +1 -0
  248. package/dist/plugin-sdk/logging/logger.d.ts +1 -1
  249. package/dist/plugin-sdk/logging/state.d.ts +1 -0
  250. package/dist/plugin-sdk/markdown/ir.d.ts +1 -1
  251. package/dist/plugin-sdk/markdown/whatsapp.d.ts +14 -0
  252. package/dist/plugin-sdk/media/input-files.d.ts +5 -0
  253. package/dist/plugin-sdk/media-understanding/audio-preflight.d.ts +16 -0
  254. package/dist/plugin-sdk/media-understanding/types.d.ts +1 -0
  255. package/dist/plugin-sdk/memory/backend-config.d.ts +2 -1
  256. package/dist/plugin-sdk/memory/qmd-manager.d.ts +2 -0
  257. package/dist/plugin-sdk/memory/qmd-query-parser.d.ts +8 -0
  258. package/dist/plugin-sdk/process/command-queue.d.ts +16 -0
  259. package/dist/plugin-sdk/routing/resolve-route.d.ts +3 -1
  260. package/dist/plugin-sdk/security/external-content.d.ts +1 -1
  261. package/dist/plugin-sdk/security/secret-equal.d.ts +1 -0
  262. package/dist/plugin-sdk/sessions/input-provenance.d.ts +16 -0
  263. package/dist/plugin-sdk/signal/monitor/event-handler.types.d.ts +8 -0
  264. package/dist/plugin-sdk/signal/monitor/mentions.d.ts +2 -0
  265. package/dist/plugin-sdk/slack/monitor/commands.d.ts +5 -0
  266. package/dist/plugin-sdk/telegram/bot-message-context.d.ts +2 -1
  267. package/dist/plugin-sdk/telegram/send.d.ts +3 -0
  268. package/dist/plugin-sdk/web/media.d.ts +2 -0
  269. package/dist/{plugins-Db5BiELK.js → plugins-4Hqd1WGf.js} +3 -3
  270. package/dist/{plugins-CNaHNND_.js → plugins-X7d_tfTE.js} +4 -4
  271. package/dist/{plugins-cli-8G-hQPCu.js → plugins-cli-Bgku3EGj.js} +253 -44
  272. package/dist/{plugins-cli-CDiocaDE.js → plugins-cli-CVToH3if.js} +257 -48
  273. package/dist/{ports-BeebfNCb.js → ports-qkt29rdC.js} +2 -2
  274. package/dist/{program-0Cj9YxRN.js → program-Cf7lkBur.js} +82 -80
  275. package/dist/{progress-DIQJt9Va.js → progress-C9kngsTD.js} +1 -1
  276. package/dist/{progress-Da1ehW-x.js → progress-DWqhRakV.js} +1 -1
  277. package/dist/{prompt-style-Dc0C5HC9.js → prompt-style-BFH5D5LN.js} +1 -1
  278. package/dist/{prompt-style-CjQRlDx4.js → prompt-style-CIbmaxSa.js} +1 -1
  279. package/dist/{pw-ai-C43wv1ZF.js → pw-ai-8mdv3h-d.js} +7 -6
  280. package/dist/{pw-ai-COWYvUfG.js → pw-ai-CM1IsSgZ.js} +6 -6
  281. package/dist/{pw-ai-BxJ-KCIy.js → pw-ai-FGoRVblI.js} +5 -6
  282. package/dist/{pw-ai-CsvaObGM.js → pw-ai-sS1fRKW_.js} +3 -3
  283. package/dist/{qmd-manager-CpsjQyaZ.js → qmd-manager-C67Fc8aN.js} +79 -26
  284. package/dist/{qmd-manager-C9YWFeG6.js → qmd-manager-CXVbfg99.js} +81 -26
  285. package/dist/{qmd-manager-C02E8ixK.js → qmd-manager-RMRE8Tqt.js} +81 -26
  286. package/dist/{qmd-manager-BzY2LQTT.js → qmd-manager-pyc_MTIe.js} +78 -23
  287. package/dist/{register.subclis-DUkirdHn.js → register.subclis-C02e4zuJ.js} +29 -29
  288. package/dist/{reply--b7BsXGP.js → reply-DICXkh_C.js} +7289 -8455
  289. package/dist/{routes-DUkEKAc1.js → routes-CmOI1hIH.js} +29 -11
  290. package/dist/{routes-B4QQiFju.js → routes-DewK5tq2.js} +29 -12
  291. package/dist/{rpc-CuMtxrRT.js → rpc-DHr30euf.js} +3 -3
  292. package/dist/{rpc-Blt6MJ4F.js → rpc-T300F8zI.js} +3 -3
  293. package/dist/{run-main-XZcPA23b.js → run-main-C5wpthq1.js} +84 -82
  294. package/dist/runner-CY0nmVme.js +1886 -0
  295. package/dist/runner-Cfm5nTMc.js +1785 -0
  296. package/dist/runner-D_dujMod.js +1886 -0
  297. package/dist/runner-DrGYLH5K.js +1785 -0
  298. package/dist/{sandbox-Aks-9EcZ.js → sandbox-BKYnhYQH.js} +24 -17
  299. package/dist/{sandbox-DqUO2K83.js → sandbox-Bhjnh1Xg.js} +23 -16
  300. package/dist/{sandbox-cli-C99Thxi8.js → sandbox-cli-DBsAjZJN.js} +21 -21
  301. package/dist/{sandbox-cli-CJqRM4V6.js → sandbox-cli-rV9LtFeu.js} +21 -21
  302. package/dist/{security-cli-iqYLMOz3.js → security-cli-BIwJM_rs.js} +27 -27
  303. package/dist/{security-cli-DW3lCz-o.js → security-cli-BRjny8Yu.js} +27 -27
  304. package/dist/{server-context-fX4xiYRh.js → server-context-BGpGs3qd.js} +7 -7
  305. package/dist/{server-context-8Qt35QdF.js → server-context-Cl0U0vE3.js} +7 -7
  306. package/dist/{server-node-events-CHWXfb_T.js → server-node-events-CBfTbiTA.js} +48 -44
  307. package/dist/{server-node-events-BzrEnKLX.js → server-node-events-QCvh8EgI.js} +45 -41
  308. package/dist/{service-Cd4BxKuo.js → service--nPk7DvT.js} +8 -4
  309. package/dist/{service-DDPRbf8a.js → service-99RDXwX4.js} +8 -4
  310. package/dist/{service-audit-CCFxuvKs.js → service-audit-DnLmRGQt.js} +4 -4
  311. package/dist/{service-audit-x6jCN-6a.js → service-audit-ckBaRCVC.js} +4 -4
  312. package/dist/{session-cost-usage-CcCEQNuc.js → session-cost-usage-D7HuoSSD.js} +12 -10
  313. package/dist/{session-cost-usage-PvyVZz-g.js → session-cost-usage-D9hHANWI.js} +12 -10
  314. package/dist/{shared-ILguacOr.js → shared-Bs4vduG4.js} +3 -3
  315. package/dist/{shared-CagUDdmp.js → shared-CEY5IkwG.js} +3 -3
  316. package/dist/{shared-gOyV38rM.js → shared-DRohONn_.js} +4 -4
  317. package/dist/{shared-BDk_zC9p.js → shared-ICqOZibV.js} +4 -4
  318. package/dist/{skill-scanner-C_fQzVDu.js → skill-scanner-CucvxYhu.js} +1 -1
  319. package/dist/{skill-scanner-DrVEHfC6.js → skill-scanner-rHMtUHtP.js} +1 -1
  320. package/dist/{skills-D5UZZZSY.js → skills-DRjfSQT3.js} +141 -6
  321. package/dist/{skills-ccAgQ3Ad.js → skills-DprQj9X2.js} +142 -7
  322. package/dist/{skills-cli-DQilTG3n.js → skills-cli-9WO-C55s.js} +12 -12
  323. package/dist/{skills-cli-ggyLBtAY.js → skills-cli-B9eej-EW.js} +13 -13
  324. package/dist/{skills-status-BosMnzIs.js → skills-status-5U3P3YfJ.js} +3 -3
  325. package/dist/{skills-status-DjtPPMnY.js → skills-status-TDIgVd1K.js} +2 -2
  326. package/dist/{sqlite-B7FPASCO.js → sqlite-BINzs1U0.js} +2 -2
  327. package/dist/{sqlite-Btrgi7-j.js → sqlite-D4w5TejA.js} +3 -3
  328. package/dist/{sqlite-BrQ9tw8B.js → sqlite-DRRHmlug.js} +3 -3
  329. package/dist/{sqlite-HepBVDoX.js → sqlite-F6PGkEm1.js} +2 -2
  330. package/dist/{status-BByCntWS.js → status-BKGkKC_v.js} +3 -3
  331. package/dist/{status-Dt7RE_Yy.js → status-CiHtHdaa.js} +4 -4
  332. package/dist/{status-zfL4Yej7.js → status-DDWoOpeB.js} +37 -37
  333. package/dist/{subsystem-Bh1Y_6Uv.js → subsystem-BoExtIHo.js} +52 -17
  334. package/dist/{system-cli-DwuUkdkH.js → system-cli-B6lr60Io.js} +14 -14
  335. package/dist/{system-cli-Clqsx8U5.js → system-cli-CprW9G3h.js} +14 -14
  336. package/dist/{systemd-BEWwfwn0.js → systemd-C0VZriGM.js} +3 -3
  337. package/dist/{systemd-D6wTPnHi.js → systemd-DrmBtJ5T.js} +3 -3
  338. package/dist/{systemd-hints-zi4ohCOY.js → systemd-hints-DZtXiVHa.js} +1 -1
  339. package/dist/{systemd-linger-CDo2UbHM.js → systemd-linger-NC2kl1SC.js} +2 -2
  340. package/dist/{systemd-linger-BxjTrgoH.js → systemd-linger-xdn3BdPh.js} +2 -2
  341. package/dist/{table-DEnmtvl5.js → table-B8dx3v4v.js} +2 -2
  342. package/dist/{table-cCoGqLsk.js → table-CwulTLQp.js} +1 -1
  343. package/dist/{tool-display-DskiU8Kt.js → tool-display-CZRIDMRm.js} +2 -2
  344. package/dist/{tool-display-o-dDAlqF.js → tool-display-ClRud3pg.js} +2 -2
  345. package/dist/{tui-BdJWZdto.js → tui-CVTQn-dC.js} +14 -13
  346. package/dist/{tui-Bc7XUQGP.js → tui-Lu8FdrlK.js} +13 -14
  347. package/dist/{tui-cli-BGYh0UL0.js → tui-cli-BLpTj1X9.js} +27 -27
  348. package/dist/{tui-cli-D3n-O9zB.js → tui-cli-BLx5kL2I.js} +26 -26
  349. package/dist/{tui-formatters-CA85v4U2.js → tui-formatters-CNySEfJN.js} +6 -6
  350. package/dist/{tui-formatters-C3NarH24.js → tui-formatters-DePhZK3J.js} +6 -6
  351. package/dist/{update-JB16aPIY.js → update-DHVxMTpQ.js} +3 -3
  352. package/dist/{update-Ct9sqJC_.js → update-DU1geolI.js} +3 -3
  353. package/dist/{update-cli-wWKDS3cm.js → update-cli-C0hUvJWK.js} +89 -71
  354. package/dist/{update-cli-DDXp_N9B.js → update-cli-Wb1GB3rL.js} +88 -70
  355. package/dist/{update-runner-ChTf6O6p.js → update-runner--ixK4J3W.js} +11 -11
  356. package/dist/{update-runner-CmE6cHdn.js → update-runner-7Qa1T9y6.js} +10 -10
  357. package/dist/{utils-Dk86IbEs.js → utils-BLJAc3ZV.js} +1 -1
  358. package/dist/{utils-es4ygvQ-.js → utils-Cd9QdCHh.js} +1 -1
  359. package/dist/{webhooks-cli-CVIE9TtX.js → webhooks-cli-DgcMy7RG.js} +12 -12
  360. package/dist/{webhooks-cli-BmKSiQQC.js → webhooks-cli-aVzUcJY9.js} +11 -11
  361. package/dist/{widearea-dns-2ah0bkAj.js → widearea-dns-BaIgNEhY.js} +3 -3
  362. package/dist/{widearea-dns-CMIG6-74.js → widearea-dns-DzuRdwk5.js} +3 -3
  363. package/dist/{ws-DtDKpbLR.js → ws-CHCQHs0F.js} +1 -1
  364. package/dist/{ws-log-BP3z_g6Z.js → ws-log-CIXbLCka.js} +1 -1
  365. package/dist/{ws-log-D7MkvKhg.js → ws-log-DcQFZByi.js} +2 -2
  366. package/dist/{wsl-Cwo7X0Un.js → wsl-BUOkxKJu.js} +2 -2
  367. package/docs/assets/install-script.svg +1 -0
  368. package/docs/automation/hooks.md +1 -38
  369. package/docs/automation/webhook.md +43 -2
  370. package/docs/channels/discord.md +389 -381
  371. package/docs/channels/imessage.md +229 -218
  372. package/docs/channels/slack.md +294 -415
  373. package/docs/channels/telegram.md +401 -505
  374. package/docs/channels/whatsapp.md +338 -310
  375. package/docs/ci.md +0 -12
  376. package/docs/cli/hooks.md +1 -14
  377. package/docs/cli/index.md +6 -1
  378. package/docs/cli/logs.md +4 -0
  379. package/docs/cli/onboard.md +30 -0
  380. package/docs/cli/plugins.md +20 -1
  381. package/docs/cli/security.md +1 -0
  382. package/docs/concepts/memory.md +7 -4
  383. package/docs/concepts/session-tool.md +1 -0
  384. package/docs/docs.json +11 -11
  385. package/docs/gateway/configuration-examples.md +9 -2
  386. package/docs/gateway/configuration-reference.md +2329 -0
  387. package/docs/gateway/configuration.md +338 -3304
  388. package/docs/gateway/index.md +162 -238
  389. package/docs/gateway/openresponses-http-api.md +15 -0
  390. package/docs/gateway/security/index.md +3 -0
  391. package/docs/help/faq.md +9 -0
  392. package/docs/install/hetzner.md +21 -0
  393. package/docs/install/installer.md +20 -0
  394. package/docs/nodes/audio.md +19 -0
  395. package/docs/platforms/mac/release.md +7 -7
  396. package/docs/providers/glm.md +3 -3
  397. package/docs/providers/index.md +1 -0
  398. package/docs/providers/litellm.md +153 -0
  399. package/docs/providers/zai.md +2 -2
  400. package/docs/reference/templates/AGENTS.md +26 -26
  401. package/docs/reference/templates/HEARTBEAT.md +31 -2
  402. package/docs/reference/templates/SOUL.md +14 -8
  403. package/docs/reference/transcript-hygiene.md +18 -0
  404. package/docs/start/getting-started.md +5 -0
  405. package/docs/start/wizard-cli-automation.md +17 -0
  406. package/docs/start/wizard-cli-reference.md +12 -0
  407. package/docs/tools/browser.md +6 -0
  408. package/docs/zh-CN/automation/hooks.md +1 -38
  409. package/docs/zh-CN/cli/hooks.md +1 -14
  410. package/extensions/bluebubbles/package.json +1 -1
  411. package/extensions/bluebubbles/src/monitor.test.ts +40 -28
  412. package/extensions/bluebubbles/src/monitor.ts +0 -4
  413. package/extensions/copilot-proxy/package.json +1 -1
  414. package/extensions/diagnostics-otel/package.json +10 -10
  415. package/extensions/discord/package.json +1 -1
  416. package/extensions/feishu/package.json +2 -5
  417. package/extensions/feishu/src/bot.checkBotMentioned.test.ts +64 -0
  418. package/extensions/feishu/src/bot.ts +1 -1
  419. package/extensions/feishu/src/channel.test.ts +48 -0
  420. package/extensions/feishu/src/channel.ts +1 -3
  421. package/extensions/feishu/src/config-schema.ts +6 -0
  422. package/extensions/feishu/src/docx.ts +14 -4
  423. package/extensions/feishu/src/media.test.ts +151 -0
  424. package/extensions/feishu/src/media.ts +27 -13
  425. package/extensions/feishu/src/reply-dispatcher.test.ts +116 -0
  426. package/extensions/feishu/src/reply-dispatcher.ts +124 -67
  427. package/extensions/feishu/src/streaming-card.ts +223 -0
  428. package/extensions/feishu/src/targets.test.ts +16 -0
  429. package/extensions/feishu/src/targets.ts +1 -1
  430. package/extensions/google-antigravity-auth/package.json +1 -1
  431. package/extensions/google-gemini-cli-auth/package.json +1 -1
  432. package/extensions/googlechat/package.json +1 -1
  433. package/extensions/imessage/package.json +1 -1
  434. package/extensions/irc/package.json +1 -1
  435. package/extensions/irc/src/client.ts +1 -1
  436. package/extensions/line/package.json +1 -1
  437. package/extensions/llm-task/package.json +1 -1
  438. package/extensions/lobster/package.json +1 -1
  439. package/extensions/matrix/CHANGELOG.md +6 -0
  440. package/extensions/matrix/package.json +2 -2
  441. package/extensions/mattermost/package.json +1 -1
  442. package/extensions/memory-core/package.json +1 -1
  443. package/extensions/memory-lancedb/index.ts +6 -2
  444. package/extensions/memory-lancedb/package.json +2 -2
  445. package/extensions/minimax-portal-auth/index.ts +7 -5
  446. package/extensions/minimax-portal-auth/package.json +1 -1
  447. package/extensions/msteams/CHANGELOG.md +6 -0
  448. package/extensions/msteams/package.json +1 -1
  449. package/extensions/nextcloud-talk/package.json +1 -1
  450. package/extensions/nostr/CHANGELOG.md +6 -0
  451. package/extensions/nostr/package.json +2 -2
  452. package/extensions/open-prose/package.json +1 -1
  453. package/extensions/signal/package.json +1 -1
  454. package/extensions/slack/package.json +1 -1
  455. package/extensions/telegram/package.json +1 -1
  456. package/extensions/tlon/package.json +1 -1
  457. package/extensions/twitch/CHANGELOG.md +6 -0
  458. package/extensions/twitch/package.json +1 -1
  459. package/extensions/voice-call/CHANGELOG.md +6 -0
  460. package/extensions/voice-call/package.json +1 -1
  461. package/extensions/voice-call/src/media-stream.ts +7 -1
  462. package/extensions/voice-call/src/providers/twilio.test.ts +5 -3
  463. package/extensions/voice-call/src/providers/twilio.ts +12 -1
  464. package/extensions/whatsapp/package.json +1 -1
  465. package/extensions/zalo/CHANGELOG.md +6 -0
  466. package/extensions/zalo/package.json +1 -1
  467. package/extensions/zalouser/CHANGELOG.md +6 -0
  468. package/extensions/zalouser/package.json +1 -1
  469. package/package.json +26 -22
  470. package/dist/auth-BcNHFK-i.js +0 -184
  471. package/dist/auth-BvIPpm7G.js +0 -184
  472. package/dist/boolean-M-esQJt6.js +0 -30
  473. package/dist/bundled/soul-evil/HOOK.md +0 -71
  474. package/dist/bundled/soul-evil/handler.js +0 -194
  475. package/dist/cli-DJbWJ9aB.js +0 -89
  476. package/dist/config-CI7EpvlP.js +0 -15
  477. package/dist/control-ui/assets/index-CnB9IO4a.js.map +0 -1
  478. package/dist/date-time-c6HTX6IW.js +0 -187
  479. package/dist/frontmatter-xwTm0734.js +0 -105
  480. package/dist/parse-duration-De_tAQSe.js +0 -24
  481. package/dist/session-key-nXYQSv-a.js +0 -167
  482. package/dist/utils-dp_OM900.js +0 -476
  483. package/docs/hooks/soul-evil.md +0 -69
  484. package/docs/zh-CN/hooks/soul-evil.md +0 -72
  485. /package/dist/{archive-CXhvR9nU.js → archive-beaSfAzA.js} +0 -0
  486. /package/dist/{brew-BIrWdDps.js → brew-BUIxHEkn.js} +0 -0
  487. /package/dist/{brew-B7YK4ZoL.js → brew-ROHf0-Xp.js} +0 -0
  488. /package/dist/{cli-utils-PlLcDZlM.js → cli-utils-CRhVAaLV.js} +0 -0
  489. /package/dist/{cli-utils-R-ECs5cY.js → cli-utils-LcHOt63h.js} +0 -0
  490. /package/dist/{command-format-BUxhT1xL.js → command-format-qUVxzqYm.js} +0 -0
  491. /package/dist/{constants-CNTiY-ZN.js → constants-BvQ6S8j5.js} +0 -0
  492. /package/dist/{constants-DuoCkWRh.js → constants-JPeoOZnw.js} +0 -0
  493. /package/dist/{errors-D3tYRJWG.js → errors-B91HIDPD.js} +0 -0
  494. /package/dist/{errors-B0eT3jVv.js → errors-Bv81hF2P.js} +0 -0
  495. /package/dist/{errors-x4NYs-1P.js → errors-DjZBTJJ3.js} +0 -0
  496. /package/dist/{exec-approvals-DGPTjO0N.js → exec-approvals-Cb4ZLukq.js} +0 -0
  497. /package/dist/{exec-approvals-DhmKpiIo.js → exec-approvals-DQ8TVVmj.js} +0 -0
  498. /package/dist/{format-CaxeRcue.js → format-CNU-Zkrz.js} +0 -0
  499. /package/dist/{format-DLOJPZmo.js → format-DcfK-dwd.js} +0 -0
  500. /package/dist/{format-duration-Be5Z7JdJ.js → format-duration-84n6_DgO.js} +0 -0
  501. /package/dist/{format-duration-CEmFWLyX.js → format-duration-Bo9zNKwO.js} +0 -0
  502. /package/dist/{format-relative-79_Y1n2Y.js → format-relative-CZOlQ2pA.js} +0 -0
  503. /package/dist/{format-relative-Db7eqEu8.js → format-relative-cegC_FF5.js} +0 -0
  504. /package/dist/{github-copilot-token-C9IJh2Pn.js → github-copilot-token-DkiRbJdR.js} +0 -0
  505. /package/dist/{helpers-CQI-5xS9.js → helpers-8O7IVGO-.js} +0 -0
  506. /package/dist/{helpers-CRzoyyXS.js → helpers-D_jqdWkd.js} +0 -0
  507. /package/dist/{helpers-C89IG08W.js → helpers-HyeZXsnu.js} +0 -0
  508. /package/dist/{is-main-WWuz28Ip.js → is-main-BWoXGz7p.js} +0 -0
  509. /package/dist/{logging-BzvBIA3Y.js → logging-fywhKCmE.js} +0 -0
  510. /package/dist/{nodes-screen-lykd2cny.js → nodes-screen-CdCWeiwy.js} +0 -0
  511. /package/dist/{parse-Cjiudy6x.js → parse-Bw0oH-rT.js} +0 -0
  512. /package/dist/{parse-DqAvJRIf.js → parse-ioZhOtha.js} +0 -0
  513. /package/dist/{parse-log-line-CUrpqe1w.js → parse-log-line-BoDqomM4.js} +0 -0
  514. /package/dist/{parse-log-line-D2UGw0wR.js → parse-log-line-DPxH1XZx.js} +0 -0
  515. /package/dist/{parse-timeout-DFSPLxpY.js → parse-timeout-D1XX_zN_.js} +0 -0
  516. /package/dist/{parse-timeout-DV8NQQWk.js → parse-timeout-DMW-z4Iz.js} +0 -0
  517. /package/dist/{pi-model-discovery-CV2V1HHz.js → pi-model-discovery-DqgqUyAv.js} +0 -0
  518. /package/dist/{pi-model-discovery-DzFOAbQt.js → pi-model-discovery-EwKVHlZB.js} +0 -0
  519. /package/dist/{prompts--d-6l5Ln.js → prompts-Bg96reub.js} +0 -0
  520. /package/dist/{redact-DAKeu7PA.js → redact-BRsnXqwD.js} +0 -0
  521. /package/dist/{redact-DuEEf1p1.js → redact-Br9GfacZ.js} +0 -0
  522. /package/dist/{redact-BOIof271.js → redact-BrXLgslJ.js} +0 -0
  523. /package/dist/{status-Cv36yYdi.js → status-BRZfQbJ2.js} +0 -0
  524. /package/dist/{status-Drziap9H.js → status-CoAy6bEC.js} +0 -0
  525. /package/dist/{systemd-hints-CH4pbCFD.js → systemd-hints-CXNtLw9Q.js} +0 -0
  526. /package/dist/{tailnet-DGRSvYuQ.js → tailnet-DATIFSsY.js} +0 -0
  527. /package/dist/{transcript-events-BlIONGVn.js → transcript-events-BHS7QoRl.js} +0 -0
  528. /package/dist/{transcript-events-C1hdue6u.js → transcript-events-Bp7fGnwv.js} +0 -0
  529. /package/dist/{transcript-events-CZ8CG4ht.js → transcript-events-BtNd-j6q.js} +0 -0
  530. /package/dist/{usage-format-6Uar63S0.js → usage-format-C4JfTbSp.js} +0 -0
  531. /package/dist/{usage-format-hd37en6b.js → usage-format-CpORtVCG.js} +0 -0
@@ -0,0 +1,1886 @@
1
+ import { S as logVerbose, T as shouldLogVerbose } from "./entry.js";
2
+ import { S as resolveOpenClawAgentDir, U as normalizeGoogleModelId, ct as resolveApiKeyForProvider, k as normalizeProviderId, st as requireApiKey } from "./auth-profiles-ByNs3eEm.js";
3
+ import { n as runExec } from "./exec-CACT5OAW.js";
4
+ import { i as loadConfig } from "./config-Bdhomfei.js";
5
+ import { r as formatUncaughtError, t as extractErrorCode } from "./errors-DjZBTJJ3.js";
6
+ import { _ as normalizeChatType } from "./plugins-4Hqd1WGf.js";
7
+ import { _ as isAudioFileName, h as getFileExtension, p as detectMime, y as kindFromMime } from "./routes-DewK5tq2.js";
8
+ import { i as fetchWithSsrFGuard, n as MediaFetchError, r as fetchRemoteMedia, t as fetchWithTimeout } from "./fetch-timeout-DTK9vxex.js";
9
+ import { t as describeImageWithModel, y as ensureOpenClawModelsJson } from "./image-DgtfXMcX.js";
10
+ import path from "node:path";
11
+ import process$1 from "node:process";
12
+ import os from "node:os";
13
+ import { constants } from "node:fs";
14
+ import fs$1 from "node:fs/promises";
15
+ import { fileURLToPath } from "node:url";
16
+ import crypto from "node:crypto";
17
+
18
+ //#region src/agents/model-catalog.ts
19
+ let modelCatalogPromise = null;
20
+ let hasLoggedModelCatalogError = false;
21
+ const defaultImportPiSdk = () => import("./pi-model-discovery-DzEIEgHL.js").then((n) => n.r);
22
+ let importPiSdk = defaultImportPiSdk;
23
+ async function loadModelCatalog(params) {
24
+ if (params?.useCache === false) modelCatalogPromise = null;
25
+ if (modelCatalogPromise) return modelCatalogPromise;
26
+ modelCatalogPromise = (async () => {
27
+ const models = [];
28
+ const sortModels = (entries) => entries.sort((a, b) => {
29
+ const p = a.provider.localeCompare(b.provider);
30
+ if (p !== 0) return p;
31
+ return a.name.localeCompare(b.name);
32
+ });
33
+ try {
34
+ await ensureOpenClawModelsJson(params?.config ?? loadConfig());
35
+ const piSdk = await importPiSdk();
36
+ const agentDir = resolveOpenClawAgentDir();
37
+ const { join } = await import("node:path");
38
+ const authStorage = new piSdk.AuthStorage(join(agentDir, "auth.json"));
39
+ const registry = new piSdk.ModelRegistry(authStorage, join(agentDir, "models.json"));
40
+ const entries = Array.isArray(registry) ? registry : registry.getAll();
41
+ for (const entry of entries) {
42
+ const id = String(entry?.id ?? "").trim();
43
+ if (!id) continue;
44
+ const provider = String(entry?.provider ?? "").trim();
45
+ if (!provider) continue;
46
+ const name = String(entry?.name ?? id).trim() || id;
47
+ const contextWindow = typeof entry?.contextWindow === "number" && entry.contextWindow > 0 ? entry.contextWindow : void 0;
48
+ const reasoning = typeof entry?.reasoning === "boolean" ? entry.reasoning : void 0;
49
+ const input = Array.isArray(entry?.input) ? entry.input : void 0;
50
+ models.push({
51
+ id,
52
+ name,
53
+ provider,
54
+ contextWindow,
55
+ reasoning,
56
+ input
57
+ });
58
+ }
59
+ if (models.length === 0) modelCatalogPromise = null;
60
+ return sortModels(models);
61
+ } catch (error) {
62
+ if (!hasLoggedModelCatalogError) {
63
+ hasLoggedModelCatalogError = true;
64
+ console.warn(`[model-catalog] Failed to load model catalog: ${String(error)}`);
65
+ }
66
+ modelCatalogPromise = null;
67
+ if (models.length > 0) return sortModels(models);
68
+ return [];
69
+ }
70
+ })();
71
+ return modelCatalogPromise;
72
+ }
73
+ /**
74
+ * Check if a model supports image input based on its catalog entry.
75
+ */
76
+ function modelSupportsVision(entry) {
77
+ return entry?.input?.includes("image") ?? false;
78
+ }
79
+ /**
80
+ * Find a model in the catalog by provider and model ID.
81
+ */
82
+ function findModelInCatalog(catalog, provider, modelId) {
83
+ const normalizedProvider = provider.toLowerCase().trim();
84
+ const normalizedModelId = modelId.toLowerCase().trim();
85
+ return catalog.find((entry) => entry.provider.toLowerCase() === normalizedProvider && entry.id.toLowerCase() === normalizedModelId);
86
+ }
87
+
88
+ //#endregion
89
+ //#region src/infra/unhandled-rejections.ts
90
+ const handlers = /* @__PURE__ */ new Set();
91
+ const FATAL_ERROR_CODES = new Set([
92
+ "ERR_OUT_OF_MEMORY",
93
+ "ERR_SCRIPT_EXECUTION_TIMEOUT",
94
+ "ERR_WORKER_OUT_OF_MEMORY",
95
+ "ERR_WORKER_UNCAUGHT_EXCEPTION",
96
+ "ERR_WORKER_INITIALIZATION_FAILED"
97
+ ]);
98
+ const CONFIG_ERROR_CODES = new Set([
99
+ "INVALID_CONFIG",
100
+ "MISSING_API_KEY",
101
+ "MISSING_CREDENTIALS"
102
+ ]);
103
+ const TRANSIENT_NETWORK_CODES = new Set([
104
+ "ECONNRESET",
105
+ "ECONNREFUSED",
106
+ "ENOTFOUND",
107
+ "ETIMEDOUT",
108
+ "ESOCKETTIMEDOUT",
109
+ "ECONNABORTED",
110
+ "EPIPE",
111
+ "EHOSTUNREACH",
112
+ "ENETUNREACH",
113
+ "EAI_AGAIN",
114
+ "UND_ERR_CONNECT_TIMEOUT",
115
+ "UND_ERR_DNS_RESOLVE_FAILED",
116
+ "UND_ERR_CONNECT",
117
+ "UND_ERR_SOCKET",
118
+ "UND_ERR_HEADERS_TIMEOUT",
119
+ "UND_ERR_BODY_TIMEOUT"
120
+ ]);
121
+ function getErrorCause(err) {
122
+ if (!err || typeof err !== "object") return;
123
+ return err.cause;
124
+ }
125
+ function extractErrorCodeWithCause(err) {
126
+ const direct = extractErrorCode(err);
127
+ if (direct) return direct;
128
+ return extractErrorCode(getErrorCause(err));
129
+ }
130
+ /**
131
+ * Checks if an error is an AbortError.
132
+ * These are typically intentional cancellations (e.g., during shutdown) and shouldn't crash.
133
+ */
134
+ function isAbortError(err) {
135
+ if (!err || typeof err !== "object") return false;
136
+ if (("name" in err ? String(err.name) : "") === "AbortError") return true;
137
+ if (("message" in err && typeof err.message === "string" ? err.message : "") === "This operation was aborted") return true;
138
+ return false;
139
+ }
140
+ function isFatalError(err) {
141
+ const code = extractErrorCodeWithCause(err);
142
+ return code !== void 0 && FATAL_ERROR_CODES.has(code);
143
+ }
144
+ function isConfigError(err) {
145
+ const code = extractErrorCodeWithCause(err);
146
+ return code !== void 0 && CONFIG_ERROR_CODES.has(code);
147
+ }
148
+ /**
149
+ * Checks if an error is a transient network error that shouldn't crash the gateway.
150
+ * These are typically temporary connectivity issues that will resolve on their own.
151
+ */
152
+ function isTransientNetworkError(err) {
153
+ if (!err) return false;
154
+ const code = extractErrorCodeWithCause(err);
155
+ if (code && TRANSIENT_NETWORK_CODES.has(code)) return true;
156
+ if (err instanceof TypeError && err.message === "fetch failed") {
157
+ const cause = getErrorCause(err);
158
+ if (cause) return isTransientNetworkError(cause);
159
+ return true;
160
+ }
161
+ const cause = getErrorCause(err);
162
+ if (cause && cause !== err) return isTransientNetworkError(cause);
163
+ if (err instanceof AggregateError && err.errors?.length) return err.errors.some((e) => isTransientNetworkError(e));
164
+ return false;
165
+ }
166
+ function registerUnhandledRejectionHandler(handler) {
167
+ handlers.add(handler);
168
+ return () => {
169
+ handlers.delete(handler);
170
+ };
171
+ }
172
+ function isUnhandledRejectionHandled(reason) {
173
+ for (const handler of handlers) try {
174
+ if (handler(reason)) return true;
175
+ } catch (err) {
176
+ console.error("[openclaw] Unhandled rejection handler failed:", err instanceof Error ? err.stack ?? err.message : err);
177
+ }
178
+ return false;
179
+ }
180
+ function installUnhandledRejectionHandler() {
181
+ process$1.on("unhandledRejection", (reason, _promise) => {
182
+ if (isUnhandledRejectionHandled(reason)) return;
183
+ if (isAbortError(reason)) {
184
+ console.warn("[openclaw] Suppressed AbortError:", formatUncaughtError(reason));
185
+ return;
186
+ }
187
+ if (isFatalError(reason)) {
188
+ console.error("[openclaw] FATAL unhandled rejection:", formatUncaughtError(reason));
189
+ process$1.exit(1);
190
+ return;
191
+ }
192
+ if (isConfigError(reason)) {
193
+ console.error("[openclaw] CONFIGURATION ERROR - requires fix:", formatUncaughtError(reason));
194
+ process$1.exit(1);
195
+ return;
196
+ }
197
+ if (isTransientNetworkError(reason)) {
198
+ console.warn("[openclaw] Non-fatal unhandled rejection (continuing):", formatUncaughtError(reason));
199
+ return;
200
+ }
201
+ console.error("[openclaw] Unhandled promise rejection:", formatUncaughtError(reason));
202
+ process$1.exit(1);
203
+ });
204
+ }
205
+
206
+ //#endregion
207
+ //#region src/auto-reply/templating.ts
208
+ function formatTemplateValue(value) {
209
+ if (value == null) return "";
210
+ if (typeof value === "string") return value;
211
+ if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") return String(value);
212
+ if (typeof value === "symbol" || typeof value === "function") return value.toString();
213
+ if (Array.isArray(value)) return value.flatMap((entry) => {
214
+ if (entry == null) return [];
215
+ if (typeof entry === "string") return [entry];
216
+ if (typeof entry === "number" || typeof entry === "boolean" || typeof entry === "bigint") return [String(entry)];
217
+ return [];
218
+ }).join(",");
219
+ if (typeof value === "object") return "";
220
+ return "";
221
+ }
222
+ function applyTemplate(str, ctx) {
223
+ if (!str) return "";
224
+ return str.replace(/{{\s*(\w+)\s*}}/g, (_, key) => {
225
+ const value = ctx[key];
226
+ return formatTemplateValue(value);
227
+ });
228
+ }
229
+
230
+ //#endregion
231
+ //#region src/media-understanding/defaults.ts
232
+ const MB = 1024 * 1024;
233
+ const DEFAULT_MAX_CHARS = 500;
234
+ const DEFAULT_MAX_CHARS_BY_CAPABILITY = {
235
+ image: DEFAULT_MAX_CHARS,
236
+ audio: void 0,
237
+ video: DEFAULT_MAX_CHARS
238
+ };
239
+ const DEFAULT_MAX_BYTES = {
240
+ image: 10 * MB,
241
+ audio: 20 * MB,
242
+ video: 50 * MB
243
+ };
244
+ const DEFAULT_TIMEOUT_SECONDS = {
245
+ image: 60,
246
+ audio: 60,
247
+ video: 120
248
+ };
249
+ const DEFAULT_PROMPT = {
250
+ image: "Describe the image.",
251
+ audio: "Transcribe the audio.",
252
+ video: "Describe the video."
253
+ };
254
+ const DEFAULT_VIDEO_MAX_BASE64_BYTES = 70 * MB;
255
+ const DEFAULT_AUDIO_MODELS = {
256
+ groq: "whisper-large-v3-turbo",
257
+ openai: "gpt-4o-mini-transcribe",
258
+ deepgram: "nova-3"
259
+ };
260
+ const AUTO_AUDIO_KEY_PROVIDERS = [
261
+ "openai",
262
+ "groq",
263
+ "deepgram",
264
+ "google"
265
+ ];
266
+ const AUTO_IMAGE_KEY_PROVIDERS = [
267
+ "openai",
268
+ "anthropic",
269
+ "google",
270
+ "minimax",
271
+ "zai"
272
+ ];
273
+ const AUTO_VIDEO_KEY_PROVIDERS = ["google"];
274
+ const DEFAULT_IMAGE_MODELS = {
275
+ openai: "gpt-5-mini",
276
+ anthropic: "claude-opus-4-6",
277
+ google: "gemini-3-flash-preview",
278
+ minimax: "MiniMax-VL-01",
279
+ zai: "glm-4.6v"
280
+ };
281
+ const CLI_OUTPUT_MAX_BUFFER = 5 * MB;
282
+ const DEFAULT_MEDIA_CONCURRENCY = 2;
283
+
284
+ //#endregion
285
+ //#region src/media-understanding/providers/anthropic/index.ts
286
+ const anthropicProvider = {
287
+ id: "anthropic",
288
+ capabilities: ["image"],
289
+ describeImage: describeImageWithModel
290
+ };
291
+
292
+ //#endregion
293
+ //#region src/media-understanding/providers/shared.ts
294
+ const MAX_ERROR_CHARS = 300;
295
+ function normalizeBaseUrl(baseUrl, fallback) {
296
+ return (baseUrl?.trim() || fallback).replace(/\/+$/, "");
297
+ }
298
+ async function fetchWithTimeoutGuarded(url, init, timeoutMs, fetchFn, options) {
299
+ return await fetchWithSsrFGuard({
300
+ url,
301
+ fetchImpl: fetchFn,
302
+ init,
303
+ timeoutMs,
304
+ policy: options?.ssrfPolicy,
305
+ lookupFn: options?.lookupFn,
306
+ pinDns: options?.pinDns
307
+ });
308
+ }
309
+ async function readErrorResponse(res) {
310
+ try {
311
+ const collapsed = (await res.text()).replace(/\s+/g, " ").trim();
312
+ if (!collapsed) return;
313
+ if (collapsed.length <= MAX_ERROR_CHARS) return collapsed;
314
+ return `${collapsed.slice(0, MAX_ERROR_CHARS)}…`;
315
+ } catch {
316
+ return;
317
+ }
318
+ }
319
+
320
+ //#endregion
321
+ //#region src/media-understanding/providers/deepgram/audio.ts
322
+ const DEFAULT_DEEPGRAM_AUDIO_BASE_URL = "https://api.deepgram.com/v1";
323
+ const DEFAULT_DEEPGRAM_AUDIO_MODEL = "nova-3";
324
+ function resolveModel$3(model) {
325
+ return model?.trim() || DEFAULT_DEEPGRAM_AUDIO_MODEL;
326
+ }
327
+ async function transcribeDeepgramAudio(params) {
328
+ const fetchFn = params.fetchFn ?? fetch;
329
+ const baseUrl = normalizeBaseUrl(params.baseUrl, DEFAULT_DEEPGRAM_AUDIO_BASE_URL);
330
+ const allowPrivate = Boolean(params.baseUrl?.trim());
331
+ const model = resolveModel$3(params.model);
332
+ const url = new URL(`${baseUrl}/listen`);
333
+ url.searchParams.set("model", model);
334
+ if (params.language?.trim()) url.searchParams.set("language", params.language.trim());
335
+ if (params.query) for (const [key, value] of Object.entries(params.query)) {
336
+ if (value === void 0) continue;
337
+ url.searchParams.set(key, String(value));
338
+ }
339
+ const headers = new Headers(params.headers);
340
+ if (!headers.has("authorization")) headers.set("authorization", `Token ${params.apiKey}`);
341
+ if (!headers.has("content-type")) headers.set("content-type", params.mime ?? "application/octet-stream");
342
+ const body = new Uint8Array(params.buffer);
343
+ const { response: res, release } = await fetchWithTimeoutGuarded(url.toString(), {
344
+ method: "POST",
345
+ headers,
346
+ body
347
+ }, params.timeoutMs, fetchFn, allowPrivate ? { ssrfPolicy: { allowPrivateNetwork: true } } : void 0);
348
+ try {
349
+ if (!res.ok) {
350
+ const detail = await readErrorResponse(res);
351
+ const suffix = detail ? `: ${detail}` : "";
352
+ throw new Error(`Audio transcription failed (HTTP ${res.status})${suffix}`);
353
+ }
354
+ const transcript = (await res.json()).results?.channels?.[0]?.alternatives?.[0]?.transcript?.trim();
355
+ if (!transcript) throw new Error("Audio transcription response missing transcript");
356
+ return {
357
+ text: transcript,
358
+ model
359
+ };
360
+ } finally {
361
+ await release();
362
+ }
363
+ }
364
+
365
+ //#endregion
366
+ //#region src/media-understanding/providers/deepgram/index.ts
367
+ const deepgramProvider = {
368
+ id: "deepgram",
369
+ capabilities: ["audio"],
370
+ transcribeAudio: transcribeDeepgramAudio
371
+ };
372
+
373
+ //#endregion
374
+ //#region src/media-understanding/providers/google/audio.ts
375
+ const DEFAULT_GOOGLE_AUDIO_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
376
+ const DEFAULT_GOOGLE_AUDIO_MODEL = "gemini-3-flash-preview";
377
+ const DEFAULT_GOOGLE_AUDIO_PROMPT = "Transcribe the audio.";
378
+ function resolveModel$2(model) {
379
+ const trimmed = model?.trim();
380
+ if (!trimmed) return DEFAULT_GOOGLE_AUDIO_MODEL;
381
+ return normalizeGoogleModelId(trimmed);
382
+ }
383
+ function resolvePrompt$2(prompt) {
384
+ return prompt?.trim() || DEFAULT_GOOGLE_AUDIO_PROMPT;
385
+ }
386
+ async function transcribeGeminiAudio(params) {
387
+ const fetchFn = params.fetchFn ?? fetch;
388
+ const baseUrl = normalizeBaseUrl(params.baseUrl, DEFAULT_GOOGLE_AUDIO_BASE_URL);
389
+ const allowPrivate = Boolean(params.baseUrl?.trim());
390
+ const model = resolveModel$2(params.model);
391
+ const url = `${baseUrl}/models/${model}:generateContent`;
392
+ const headers = new Headers(params.headers);
393
+ if (!headers.has("content-type")) headers.set("content-type", "application/json");
394
+ if (!headers.has("x-goog-api-key")) headers.set("x-goog-api-key", params.apiKey);
395
+ const body = { contents: [{
396
+ role: "user",
397
+ parts: [{ text: resolvePrompt$2(params.prompt) }, { inline_data: {
398
+ mime_type: params.mime ?? "audio/wav",
399
+ data: params.buffer.toString("base64")
400
+ } }]
401
+ }] };
402
+ const { response: res, release } = await fetchWithTimeoutGuarded(url, {
403
+ method: "POST",
404
+ headers,
405
+ body: JSON.stringify(body)
406
+ }, params.timeoutMs, fetchFn, allowPrivate ? { ssrfPolicy: { allowPrivateNetwork: true } } : void 0);
407
+ try {
408
+ if (!res.ok) {
409
+ const detail = await readErrorResponse(res);
410
+ const suffix = detail ? `: ${detail}` : "";
411
+ throw new Error(`Audio transcription failed (HTTP ${res.status})${suffix}`);
412
+ }
413
+ const text = ((await res.json()).candidates?.[0]?.content?.parts ?? []).map((part) => part?.text?.trim()).filter(Boolean).join("\n");
414
+ if (!text) throw new Error("Audio transcription response missing text");
415
+ return {
416
+ text,
417
+ model
418
+ };
419
+ } finally {
420
+ await release();
421
+ }
422
+ }
423
+
424
+ //#endregion
425
+ //#region src/media-understanding/providers/google/video.ts
426
+ const DEFAULT_GOOGLE_VIDEO_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
427
+ const DEFAULT_GOOGLE_VIDEO_MODEL = "gemini-3-flash-preview";
428
+ const DEFAULT_GOOGLE_VIDEO_PROMPT = "Describe the video.";
429
+ function resolveModel$1(model) {
430
+ const trimmed = model?.trim();
431
+ if (!trimmed) return DEFAULT_GOOGLE_VIDEO_MODEL;
432
+ return normalizeGoogleModelId(trimmed);
433
+ }
434
+ function resolvePrompt$1(prompt) {
435
+ return prompt?.trim() || DEFAULT_GOOGLE_VIDEO_PROMPT;
436
+ }
437
+ async function describeGeminiVideo(params) {
438
+ const fetchFn = params.fetchFn ?? fetch;
439
+ const baseUrl = normalizeBaseUrl(params.baseUrl, DEFAULT_GOOGLE_VIDEO_BASE_URL);
440
+ const allowPrivate = Boolean(params.baseUrl?.trim());
441
+ const model = resolveModel$1(params.model);
442
+ const url = `${baseUrl}/models/${model}:generateContent`;
443
+ const headers = new Headers(params.headers);
444
+ if (!headers.has("content-type")) headers.set("content-type", "application/json");
445
+ if (!headers.has("x-goog-api-key")) headers.set("x-goog-api-key", params.apiKey);
446
+ const body = { contents: [{
447
+ role: "user",
448
+ parts: [{ text: resolvePrompt$1(params.prompt) }, { inline_data: {
449
+ mime_type: params.mime ?? "video/mp4",
450
+ data: params.buffer.toString("base64")
451
+ } }]
452
+ }] };
453
+ const { response: res, release } = await fetchWithTimeoutGuarded(url, {
454
+ method: "POST",
455
+ headers,
456
+ body: JSON.stringify(body)
457
+ }, params.timeoutMs, fetchFn, allowPrivate ? { ssrfPolicy: { allowPrivateNetwork: true } } : void 0);
458
+ try {
459
+ if (!res.ok) {
460
+ const detail = await readErrorResponse(res);
461
+ const suffix = detail ? `: ${detail}` : "";
462
+ throw new Error(`Video description failed (HTTP ${res.status})${suffix}`);
463
+ }
464
+ const text = ((await res.json()).candidates?.[0]?.content?.parts ?? []).map((part) => part?.text?.trim()).filter(Boolean).join("\n");
465
+ if (!text) throw new Error("Video description response missing text");
466
+ return {
467
+ text,
468
+ model
469
+ };
470
+ } finally {
471
+ await release();
472
+ }
473
+ }
474
+
475
+ //#endregion
476
+ //#region src/media-understanding/providers/google/index.ts
477
+ const googleProvider = {
478
+ id: "google",
479
+ capabilities: [
480
+ "image",
481
+ "audio",
482
+ "video"
483
+ ],
484
+ describeImage: describeImageWithModel,
485
+ transcribeAudio: transcribeGeminiAudio,
486
+ describeVideo: describeGeminiVideo
487
+ };
488
+
489
+ //#endregion
490
+ //#region src/media-understanding/providers/openai/audio.ts
491
+ const DEFAULT_OPENAI_AUDIO_BASE_URL = "https://api.openai.com/v1";
492
+ const DEFAULT_OPENAI_AUDIO_MODEL = "gpt-4o-mini-transcribe";
493
+ function resolveModel(model) {
494
+ return model?.trim() || DEFAULT_OPENAI_AUDIO_MODEL;
495
+ }
496
+ async function transcribeOpenAiCompatibleAudio(params) {
497
+ const fetchFn = params.fetchFn ?? fetch;
498
+ const baseUrl = normalizeBaseUrl(params.baseUrl, DEFAULT_OPENAI_AUDIO_BASE_URL);
499
+ const allowPrivate = Boolean(params.baseUrl?.trim());
500
+ const url = `${baseUrl}/audio/transcriptions`;
501
+ const model = resolveModel(params.model);
502
+ const form = new FormData();
503
+ const fileName = params.fileName?.trim() || path.basename(params.fileName) || "audio";
504
+ const bytes = new Uint8Array(params.buffer);
505
+ const blob = new Blob([bytes], { type: params.mime ?? "application/octet-stream" });
506
+ form.append("file", blob, fileName);
507
+ form.append("model", model);
508
+ if (params.language?.trim()) form.append("language", params.language.trim());
509
+ if (params.prompt?.trim()) form.append("prompt", params.prompt.trim());
510
+ const headers = new Headers(params.headers);
511
+ if (!headers.has("authorization")) headers.set("authorization", `Bearer ${params.apiKey}`);
512
+ const { response: res, release } = await fetchWithTimeoutGuarded(url, {
513
+ method: "POST",
514
+ headers,
515
+ body: form
516
+ }, params.timeoutMs, fetchFn, allowPrivate ? { ssrfPolicy: { allowPrivateNetwork: true } } : void 0);
517
+ try {
518
+ if (!res.ok) {
519
+ const detail = await readErrorResponse(res);
520
+ const suffix = detail ? `: ${detail}` : "";
521
+ throw new Error(`Audio transcription failed (HTTP ${res.status})${suffix}`);
522
+ }
523
+ const text = (await res.json()).text?.trim();
524
+ if (!text) throw new Error("Audio transcription response missing text");
525
+ return {
526
+ text,
527
+ model
528
+ };
529
+ } finally {
530
+ await release();
531
+ }
532
+ }
533
+
534
+ //#endregion
535
+ //#region src/media-understanding/providers/groq/index.ts
536
+ const DEFAULT_GROQ_AUDIO_BASE_URL = "https://api.groq.com/openai/v1";
537
+ const groqProvider = {
538
+ id: "groq",
539
+ capabilities: ["audio"],
540
+ transcribeAudio: (req) => transcribeOpenAiCompatibleAudio({
541
+ ...req,
542
+ baseUrl: req.baseUrl ?? DEFAULT_GROQ_AUDIO_BASE_URL
543
+ })
544
+ };
545
+
546
+ //#endregion
547
+ //#region src/media-understanding/providers/minimax/index.ts
548
+ const minimaxProvider = {
549
+ id: "minimax",
550
+ capabilities: ["image"],
551
+ describeImage: describeImageWithModel
552
+ };
553
+
554
+ //#endregion
555
+ //#region src/media-understanding/providers/openai/index.ts
556
+ const openaiProvider = {
557
+ id: "openai",
558
+ capabilities: ["image"],
559
+ describeImage: describeImageWithModel,
560
+ transcribeAudio: transcribeOpenAiCompatibleAudio
561
+ };
562
+
563
+ //#endregion
564
+ //#region src/media-understanding/providers/zai/index.ts
565
+ const zaiProvider = {
566
+ id: "zai",
567
+ capabilities: ["image"],
568
+ describeImage: describeImageWithModel
569
+ };
570
+
571
+ //#endregion
572
+ //#region src/media-understanding/providers/index.ts
573
+ const PROVIDERS = [
574
+ groqProvider,
575
+ openaiProvider,
576
+ googleProvider,
577
+ anthropicProvider,
578
+ minimaxProvider,
579
+ zaiProvider,
580
+ deepgramProvider
581
+ ];
582
+ function normalizeMediaProviderId(id) {
583
+ const normalized = normalizeProviderId(id);
584
+ if (normalized === "gemini") return "google";
585
+ return normalized;
586
+ }
587
+ function buildMediaUnderstandingRegistry(overrides) {
588
+ const registry = /* @__PURE__ */ new Map();
589
+ for (const provider of PROVIDERS) registry.set(normalizeMediaProviderId(provider.id), provider);
590
+ if (overrides) for (const [key, provider] of Object.entries(overrides)) {
591
+ const normalizedKey = normalizeMediaProviderId(key);
592
+ const existing = registry.get(normalizedKey);
593
+ const merged = existing ? {
594
+ ...existing,
595
+ ...provider,
596
+ capabilities: provider.capabilities ?? existing.capabilities
597
+ } : provider;
598
+ registry.set(normalizedKey, merged);
599
+ }
600
+ return registry;
601
+ }
602
+ function getMediaUnderstandingProvider(id, registry) {
603
+ return registry.get(normalizeMediaProviderId(id));
604
+ }
605
+
606
+ //#endregion
607
+ //#region src/media-understanding/scope.ts
608
+ function normalizeDecision(value) {
609
+ const normalized = value?.trim().toLowerCase();
610
+ if (normalized === "allow") return "allow";
611
+ if (normalized === "deny") return "deny";
612
+ }
613
+ function normalizeMatch(value) {
614
+ return value?.trim().toLowerCase() || void 0;
615
+ }
616
+ function normalizeMediaUnderstandingChatType(raw) {
617
+ return normalizeChatType(raw ?? void 0);
618
+ }
619
+ function resolveMediaUnderstandingScope(params) {
620
+ const scope = params.scope;
621
+ if (!scope) return "allow";
622
+ const channel = normalizeMatch(params.channel);
623
+ const chatType = normalizeMediaUnderstandingChatType(params.chatType);
624
+ const sessionKey = normalizeMatch(params.sessionKey) ?? "";
625
+ for (const rule of scope.rules ?? []) {
626
+ if (!rule) continue;
627
+ const action = normalizeDecision(rule.action) ?? "allow";
628
+ const match = rule.match ?? {};
629
+ const matchChannel = normalizeMatch(match.channel);
630
+ const matchChatType = normalizeMediaUnderstandingChatType(match.chatType);
631
+ const matchPrefix = normalizeMatch(match.keyPrefix);
632
+ if (matchChannel && matchChannel !== channel) continue;
633
+ if (matchChatType && matchChatType !== chatType) continue;
634
+ if (matchPrefix && !sessionKey.startsWith(matchPrefix)) continue;
635
+ return action;
636
+ }
637
+ return normalizeDecision(scope.default) ?? "allow";
638
+ }
639
+
640
+ //#endregion
641
+ //#region src/media-understanding/resolve.ts
642
+ function resolveTimeoutMs(seconds, fallbackSeconds) {
643
+ const value = typeof seconds === "number" && Number.isFinite(seconds) ? seconds : fallbackSeconds;
644
+ return Math.max(1e3, Math.floor(value * 1e3));
645
+ }
646
+ function resolvePrompt(capability, prompt, maxChars) {
647
+ const base = prompt?.trim() || DEFAULT_PROMPT[capability];
648
+ if (!maxChars || capability === "audio") return base;
649
+ return `${base} Respond in at most ${maxChars} characters.`;
650
+ }
651
+ function resolveMaxChars(params) {
652
+ const { capability, entry, cfg } = params;
653
+ const configured = entry.maxChars ?? params.config?.maxChars ?? cfg.tools?.media?.[capability]?.maxChars;
654
+ if (typeof configured === "number") return configured;
655
+ return DEFAULT_MAX_CHARS_BY_CAPABILITY[capability];
656
+ }
657
+ function resolveMaxBytes(params) {
658
+ const configured = params.entry.maxBytes ?? params.config?.maxBytes ?? params.cfg.tools?.media?.[params.capability]?.maxBytes;
659
+ if (typeof configured === "number") return configured;
660
+ return DEFAULT_MAX_BYTES[params.capability];
661
+ }
662
+ function resolveScopeDecision(params) {
663
+ return resolveMediaUnderstandingScope({
664
+ scope: params.scope,
665
+ sessionKey: params.ctx.SessionKey,
666
+ channel: params.ctx.Surface ?? params.ctx.Provider,
667
+ chatType: normalizeMediaUnderstandingChatType(params.ctx.ChatType)
668
+ });
669
+ }
670
+ function resolveEntryCapabilities(params) {
671
+ if ((params.entry.type ?? (params.entry.command ? "cli" : "provider")) === "cli") return;
672
+ const providerId = normalizeMediaProviderId(params.entry.provider ?? "");
673
+ if (!providerId) return;
674
+ return params.providerRegistry.get(providerId)?.capabilities;
675
+ }
676
+ function resolveModelEntries(params) {
677
+ const { cfg, capability, config } = params;
678
+ const sharedModels = cfg.tools?.media?.models ?? [];
679
+ const entries = [...(config?.models ?? []).map((entry) => ({
680
+ entry,
681
+ source: "capability"
682
+ })), ...sharedModels.map((entry) => ({
683
+ entry,
684
+ source: "shared"
685
+ }))];
686
+ if (entries.length === 0) return [];
687
+ return entries.filter(({ entry, source }) => {
688
+ const caps = entry.capabilities && entry.capabilities.length > 0 ? entry.capabilities : source === "shared" ? resolveEntryCapabilities({
689
+ entry,
690
+ providerRegistry: params.providerRegistry
691
+ }) : void 0;
692
+ if (!caps || caps.length === 0) {
693
+ if (source === "shared") {
694
+ if (shouldLogVerbose()) logVerbose(`Skipping shared media model without capabilities: ${entry.provider ?? entry.command ?? "unknown"}`);
695
+ return false;
696
+ }
697
+ return true;
698
+ }
699
+ return caps.includes(capability);
700
+ }).map(({ entry }) => entry);
701
+ }
702
+ function resolveConcurrency(cfg) {
703
+ const configured = cfg.tools?.media?.concurrency;
704
+ if (typeof configured === "number" && Number.isFinite(configured) && configured > 0) return Math.floor(configured);
705
+ return DEFAULT_MEDIA_CONCURRENCY;
706
+ }
707
+
708
+ //#endregion
709
+ //#region src/media-understanding/errors.ts
710
+ var MediaUnderstandingSkipError = class extends Error {
711
+ constructor(reason, message) {
712
+ super(message);
713
+ this.reason = reason;
714
+ this.name = "MediaUnderstandingSkipError";
715
+ }
716
+ };
717
+ function isMediaUnderstandingSkipError(err) {
718
+ return err instanceof MediaUnderstandingSkipError;
719
+ }
720
+
721
+ //#endregion
722
+ //#region src/media-understanding/attachments.ts
723
+ const DEFAULT_MAX_ATTACHMENTS = 1;
724
+ function normalizeAttachmentPath(raw) {
725
+ const value = raw?.trim();
726
+ if (!value) return;
727
+ if (value.startsWith("file://")) try {
728
+ return fileURLToPath(value);
729
+ } catch {
730
+ return;
731
+ }
732
+ return value;
733
+ }
734
+ function normalizeAttachments(ctx) {
735
+ const pathsFromArray = Array.isArray(ctx.MediaPaths) ? ctx.MediaPaths : void 0;
736
+ const urlsFromArray = Array.isArray(ctx.MediaUrls) ? ctx.MediaUrls : void 0;
737
+ const typesFromArray = Array.isArray(ctx.MediaTypes) ? ctx.MediaTypes : void 0;
738
+ const resolveMime = (count, index) => {
739
+ const typeHint = typesFromArray?.[index];
740
+ const trimmed = typeof typeHint === "string" ? typeHint.trim() : "";
741
+ if (trimmed) return trimmed;
742
+ return count === 1 ? ctx.MediaType : void 0;
743
+ };
744
+ if (pathsFromArray && pathsFromArray.length > 0) {
745
+ const count = pathsFromArray.length;
746
+ const urls = urlsFromArray && urlsFromArray.length > 0 ? urlsFromArray : void 0;
747
+ return pathsFromArray.map((value, index) => ({
748
+ path: value?.trim() || void 0,
749
+ url: urls?.[index] ?? ctx.MediaUrl,
750
+ mime: resolveMime(count, index),
751
+ index
752
+ })).filter((entry) => Boolean(entry.path?.trim() || entry.url?.trim()));
753
+ }
754
+ if (urlsFromArray && urlsFromArray.length > 0) {
755
+ const count = urlsFromArray.length;
756
+ return urlsFromArray.map((value, index) => ({
757
+ path: void 0,
758
+ url: value?.trim() || void 0,
759
+ mime: resolveMime(count, index),
760
+ index
761
+ })).filter((entry) => Boolean(entry.url?.trim()));
762
+ }
763
+ const pathValue = ctx.MediaPath?.trim();
764
+ const url = ctx.MediaUrl?.trim();
765
+ if (!pathValue && !url) return [];
766
+ return [{
767
+ path: pathValue || void 0,
768
+ url: url || void 0,
769
+ mime: ctx.MediaType,
770
+ index: 0
771
+ }];
772
+ }
773
+ function resolveAttachmentKind(attachment) {
774
+ const kind = kindFromMime(attachment.mime);
775
+ if (kind === "image" || kind === "audio" || kind === "video") return kind;
776
+ const ext = getFileExtension(attachment.path ?? attachment.url);
777
+ if (!ext) return "unknown";
778
+ if ([
779
+ ".mp4",
780
+ ".mov",
781
+ ".mkv",
782
+ ".webm",
783
+ ".avi",
784
+ ".m4v"
785
+ ].includes(ext)) return "video";
786
+ if (isAudioFileName(attachment.path ?? attachment.url)) return "audio";
787
+ if ([
788
+ ".png",
789
+ ".jpg",
790
+ ".jpeg",
791
+ ".webp",
792
+ ".gif",
793
+ ".bmp",
794
+ ".tiff",
795
+ ".tif"
796
+ ].includes(ext)) return "image";
797
+ return "unknown";
798
+ }
799
+ function isVideoAttachment(attachment) {
800
+ return resolveAttachmentKind(attachment) === "video";
801
+ }
802
+ function isAudioAttachment(attachment) {
803
+ return resolveAttachmentKind(attachment) === "audio";
804
+ }
805
+ function isImageAttachment(attachment) {
806
+ return resolveAttachmentKind(attachment) === "image";
807
+ }
808
+ function resolveRequestUrl(input) {
809
+ if (typeof input === "string") return input;
810
+ if (input instanceof URL) return input.toString();
811
+ return input.url;
812
+ }
813
+ function orderAttachments(attachments, prefer) {
814
+ if (!prefer || prefer === "first") return attachments;
815
+ if (prefer === "last") return [...attachments].toReversed();
816
+ if (prefer === "path") {
817
+ const withPath = attachments.filter((item) => item.path);
818
+ const withoutPath = attachments.filter((item) => !item.path);
819
+ return [...withPath, ...withoutPath];
820
+ }
821
+ if (prefer === "url") {
822
+ const withUrl = attachments.filter((item) => item.url);
823
+ const withoutUrl = attachments.filter((item) => !item.url);
824
+ return [...withUrl, ...withoutUrl];
825
+ }
826
+ return attachments;
827
+ }
828
+ function selectAttachments(params) {
829
+ const { capability, attachments, policy } = params;
830
+ const matches = attachments.filter((item) => {
831
+ if (capability === "audio" && item.alreadyTranscribed) return false;
832
+ if (capability === "image") return isImageAttachment(item);
833
+ if (capability === "audio") return isAudioAttachment(item);
834
+ return isVideoAttachment(item);
835
+ });
836
+ if (matches.length === 0) return [];
837
+ const ordered = orderAttachments(matches, policy?.prefer);
838
+ const mode = policy?.mode ?? "first";
839
+ const maxAttachments = policy?.maxAttachments ?? DEFAULT_MAX_ATTACHMENTS;
840
+ if (mode === "all") return ordered.slice(0, Math.max(1, maxAttachments));
841
+ return ordered.slice(0, 1);
842
+ }
843
+ var MediaAttachmentCache = class {
844
+ constructor(attachments) {
845
+ this.entries = /* @__PURE__ */ new Map();
846
+ this.attachments = attachments;
847
+ for (const attachment of attachments) this.entries.set(attachment.index, { attachment });
848
+ }
849
+ async getBuffer(params) {
850
+ const entry = await this.ensureEntry(params.attachmentIndex);
851
+ if (entry.buffer) {
852
+ if (entry.buffer.length > params.maxBytes) throw new MediaUnderstandingSkipError("maxBytes", `Attachment ${params.attachmentIndex + 1} exceeds maxBytes ${params.maxBytes}`);
853
+ return {
854
+ buffer: entry.buffer,
855
+ mime: entry.bufferMime,
856
+ fileName: entry.bufferFileName ?? `media-${params.attachmentIndex + 1}`,
857
+ size: entry.buffer.length
858
+ };
859
+ }
860
+ if (entry.resolvedPath) {
861
+ const size = await this.ensureLocalStat(entry);
862
+ if (entry.resolvedPath) {
863
+ if (size !== void 0 && size > params.maxBytes) throw new MediaUnderstandingSkipError("maxBytes", `Attachment ${params.attachmentIndex + 1} exceeds maxBytes ${params.maxBytes}`);
864
+ const buffer = await fs$1.readFile(entry.resolvedPath);
865
+ entry.buffer = buffer;
866
+ entry.bufferMime = entry.bufferMime ?? entry.attachment.mime ?? await detectMime({
867
+ buffer,
868
+ filePath: entry.resolvedPath
869
+ });
870
+ entry.bufferFileName = path.basename(entry.resolvedPath) || `media-${params.attachmentIndex + 1}`;
871
+ return {
872
+ buffer,
873
+ mime: entry.bufferMime,
874
+ fileName: entry.bufferFileName,
875
+ size: buffer.length
876
+ };
877
+ }
878
+ }
879
+ const url = entry.attachment.url?.trim();
880
+ if (!url) throw new MediaUnderstandingSkipError("empty", `Attachment ${params.attachmentIndex + 1} has no path or URL.`);
881
+ try {
882
+ const fetchImpl = (input, init) => fetchWithTimeout(resolveRequestUrl(input), init ?? {}, params.timeoutMs, fetch);
883
+ const fetched = await fetchRemoteMedia({
884
+ url,
885
+ fetchImpl,
886
+ maxBytes: params.maxBytes
887
+ });
888
+ entry.buffer = fetched.buffer;
889
+ entry.bufferMime = entry.attachment.mime ?? fetched.contentType ?? await detectMime({
890
+ buffer: fetched.buffer,
891
+ filePath: fetched.fileName ?? url
892
+ });
893
+ entry.bufferFileName = fetched.fileName ?? `media-${params.attachmentIndex + 1}`;
894
+ return {
895
+ buffer: fetched.buffer,
896
+ mime: entry.bufferMime,
897
+ fileName: entry.bufferFileName,
898
+ size: fetched.buffer.length
899
+ };
900
+ } catch (err) {
901
+ if (err instanceof MediaFetchError && err.code === "max_bytes") throw new MediaUnderstandingSkipError("maxBytes", `Attachment ${params.attachmentIndex + 1} exceeds maxBytes ${params.maxBytes}`);
902
+ if (isAbortError(err)) throw new MediaUnderstandingSkipError("timeout", `Attachment ${params.attachmentIndex + 1} timed out while fetching.`);
903
+ throw err;
904
+ }
905
+ }
906
+ async getPath(params) {
907
+ const entry = await this.ensureEntry(params.attachmentIndex);
908
+ if (entry.resolvedPath) {
909
+ if (params.maxBytes) {
910
+ const size = await this.ensureLocalStat(entry);
911
+ if (entry.resolvedPath) {
912
+ if (size !== void 0 && size > params.maxBytes) throw new MediaUnderstandingSkipError("maxBytes", `Attachment ${params.attachmentIndex + 1} exceeds maxBytes ${params.maxBytes}`);
913
+ }
914
+ }
915
+ if (entry.resolvedPath) return { path: entry.resolvedPath };
916
+ }
917
+ if (entry.tempPath) {
918
+ if (params.maxBytes && entry.buffer && entry.buffer.length > params.maxBytes) throw new MediaUnderstandingSkipError("maxBytes", `Attachment ${params.attachmentIndex + 1} exceeds maxBytes ${params.maxBytes}`);
919
+ return {
920
+ path: entry.tempPath,
921
+ cleanup: entry.tempCleanup
922
+ };
923
+ }
924
+ const maxBytes = params.maxBytes ?? Number.POSITIVE_INFINITY;
925
+ const bufferResult = await this.getBuffer({
926
+ attachmentIndex: params.attachmentIndex,
927
+ maxBytes,
928
+ timeoutMs: params.timeoutMs
929
+ });
930
+ const extension = path.extname(bufferResult.fileName || "") || "";
931
+ const tmpPath = path.join(os.tmpdir(), `openclaw-media-${crypto.randomUUID()}${extension}`);
932
+ await fs$1.writeFile(tmpPath, bufferResult.buffer);
933
+ entry.tempPath = tmpPath;
934
+ entry.tempCleanup = async () => {
935
+ await fs$1.unlink(tmpPath).catch(() => {});
936
+ };
937
+ return {
938
+ path: tmpPath,
939
+ cleanup: entry.tempCleanup
940
+ };
941
+ }
942
+ async cleanup() {
943
+ const cleanups = [];
944
+ for (const entry of this.entries.values()) if (entry.tempCleanup) {
945
+ cleanups.push(Promise.resolve(entry.tempCleanup()));
946
+ entry.tempCleanup = void 0;
947
+ }
948
+ await Promise.all(cleanups);
949
+ }
950
+ async ensureEntry(attachmentIndex) {
951
+ const existing = this.entries.get(attachmentIndex);
952
+ if (existing) {
953
+ if (!existing.resolvedPath) existing.resolvedPath = this.resolveLocalPath(existing.attachment);
954
+ return existing;
955
+ }
956
+ const attachment = this.attachments.find((item) => item.index === attachmentIndex) ?? { index: attachmentIndex };
957
+ const entry = {
958
+ attachment,
959
+ resolvedPath: this.resolveLocalPath(attachment)
960
+ };
961
+ this.entries.set(attachmentIndex, entry);
962
+ return entry;
963
+ }
964
+ resolveLocalPath(attachment) {
965
+ const rawPath = normalizeAttachmentPath(attachment.path);
966
+ if (!rawPath) return;
967
+ return path.isAbsolute(rawPath) ? rawPath : path.resolve(rawPath);
968
+ }
969
+ async ensureLocalStat(entry) {
970
+ if (!entry.resolvedPath) return;
971
+ if (entry.statSize !== void 0) return entry.statSize;
972
+ try {
973
+ const stat = await fs$1.stat(entry.resolvedPath);
974
+ if (!stat.isFile()) {
975
+ entry.resolvedPath = void 0;
976
+ return;
977
+ }
978
+ entry.statSize = stat.size;
979
+ return stat.size;
980
+ } catch (err) {
981
+ entry.resolvedPath = void 0;
982
+ if (shouldLogVerbose()) logVerbose(`Failed to read attachment ${entry.attachment.index + 1}: ${String(err)}`);
983
+ return;
984
+ }
985
+ }
986
+ };
987
+
988
+ //#endregion
989
+ //#region src/media-understanding/video.ts
990
+ function estimateBase64Size(bytes) {
991
+ return Math.ceil(bytes / 3) * 4;
992
+ }
993
+ function resolveVideoMaxBase64Bytes(maxBytes) {
994
+ const expanded = Math.floor(maxBytes * (4 / 3));
995
+ return Math.min(expanded, DEFAULT_VIDEO_MAX_BASE64_BYTES);
996
+ }
997
+
998
+ //#endregion
999
+ //#region src/media-understanding/runner.ts
1000
+ function buildProviderRegistry(overrides) {
1001
+ return buildMediaUnderstandingRegistry(overrides);
1002
+ }
1003
+ function normalizeMediaAttachments(ctx) {
1004
+ return normalizeAttachments(ctx);
1005
+ }
1006
+ function createMediaAttachmentCache(attachments) {
1007
+ return new MediaAttachmentCache(attachments);
1008
+ }
1009
+ const binaryCache = /* @__PURE__ */ new Map();
1010
+ const geminiProbeCache = /* @__PURE__ */ new Map();
1011
+ function expandHomeDir(value) {
1012
+ if (!value.startsWith("~")) return value;
1013
+ const home = os.homedir();
1014
+ if (value === "~") return home;
1015
+ if (value.startsWith("~/")) return path.join(home, value.slice(2));
1016
+ return value;
1017
+ }
1018
+ function hasPathSeparator(value) {
1019
+ return value.includes("/") || value.includes("\\");
1020
+ }
1021
+ function candidateBinaryNames(name) {
1022
+ if (process.platform !== "win32") return [name];
1023
+ if (path.extname(name)) return [name];
1024
+ const pathext = (process.env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";").map((item) => item.trim()).filter(Boolean).map((item) => item.startsWith(".") ? item : `.${item}`);
1025
+ return [name, ...Array.from(new Set(pathext)).map((item) => `${name}${item}`)];
1026
+ }
1027
+ async function isExecutable(filePath) {
1028
+ try {
1029
+ if (!(await fs$1.stat(filePath)).isFile()) return false;
1030
+ if (process.platform === "win32") return true;
1031
+ await fs$1.access(filePath, constants.X_OK);
1032
+ return true;
1033
+ } catch {
1034
+ return false;
1035
+ }
1036
+ }
1037
+ async function findBinary(name) {
1038
+ const cached = binaryCache.get(name);
1039
+ if (cached) return cached;
1040
+ const resolved = (async () => {
1041
+ const direct = expandHomeDir(name.trim());
1042
+ if (direct && hasPathSeparator(direct)) {
1043
+ for (const candidate of candidateBinaryNames(direct)) if (await isExecutable(candidate)) return candidate;
1044
+ }
1045
+ const searchName = name.trim();
1046
+ if (!searchName) return null;
1047
+ const pathEntries = (process.env.PATH ?? "").split(path.delimiter);
1048
+ const candidates = candidateBinaryNames(searchName);
1049
+ for (const entryRaw of pathEntries) {
1050
+ const entry = expandHomeDir(entryRaw.trim().replace(/^"(.*)"$/, "$1"));
1051
+ if (!entry) continue;
1052
+ for (const candidate of candidates) {
1053
+ const fullPath = path.join(entry, candidate);
1054
+ if (await isExecutable(fullPath)) return fullPath;
1055
+ }
1056
+ }
1057
+ return null;
1058
+ })();
1059
+ binaryCache.set(name, resolved);
1060
+ return resolved;
1061
+ }
1062
+ async function hasBinary(name) {
1063
+ return Boolean(await findBinary(name));
1064
+ }
1065
+ async function fileExists(filePath) {
1066
+ if (!filePath) return false;
1067
+ try {
1068
+ await fs$1.stat(filePath);
1069
+ return true;
1070
+ } catch {
1071
+ return false;
1072
+ }
1073
+ }
1074
+ function extractLastJsonObject(raw) {
1075
+ const trimmed = raw.trim();
1076
+ const start = trimmed.lastIndexOf("{");
1077
+ if (start === -1) return null;
1078
+ const slice = trimmed.slice(start);
1079
+ try {
1080
+ return JSON.parse(slice);
1081
+ } catch {
1082
+ return null;
1083
+ }
1084
+ }
1085
+ function extractGeminiResponse(raw) {
1086
+ const payload = extractLastJsonObject(raw);
1087
+ if (!payload || typeof payload !== "object") return null;
1088
+ const response = payload.response;
1089
+ if (typeof response !== "string") return null;
1090
+ return response.trim() || null;
1091
+ }
1092
+ function extractSherpaOnnxText(raw) {
1093
+ const tryParse = (value) => {
1094
+ const trimmed = value.trim();
1095
+ if (!trimmed) return null;
1096
+ const head = trimmed[0];
1097
+ if (head !== "{" && head !== "\"") return null;
1098
+ try {
1099
+ const parsed = JSON.parse(trimmed);
1100
+ if (typeof parsed === "string") return tryParse(parsed);
1101
+ if (parsed && typeof parsed === "object") {
1102
+ const text = parsed.text;
1103
+ if (typeof text === "string" && text.trim()) return text.trim();
1104
+ }
1105
+ } catch {}
1106
+ return null;
1107
+ };
1108
+ const direct = tryParse(raw);
1109
+ if (direct) return direct;
1110
+ const lines = raw.split("\n").map((line) => line.trim()).filter(Boolean);
1111
+ for (let i = lines.length - 1; i >= 0; i -= 1) {
1112
+ const parsed = tryParse(lines[i] ?? "");
1113
+ if (parsed) return parsed;
1114
+ }
1115
+ return null;
1116
+ }
1117
+ async function probeGeminiCli() {
1118
+ const cached = geminiProbeCache.get("gemini");
1119
+ if (cached) return cached;
1120
+ const resolved = (async () => {
1121
+ if (!await hasBinary("gemini")) return false;
1122
+ try {
1123
+ const { stdout } = await runExec("gemini", [
1124
+ "--output-format",
1125
+ "json",
1126
+ "ok"
1127
+ ], { timeoutMs: 8e3 });
1128
+ return Boolean(extractGeminiResponse(stdout) ?? stdout.toLowerCase().includes("ok"));
1129
+ } catch {
1130
+ return false;
1131
+ }
1132
+ })();
1133
+ geminiProbeCache.set("gemini", resolved);
1134
+ return resolved;
1135
+ }
1136
+ async function resolveLocalWhisperCppEntry() {
1137
+ if (!await hasBinary("whisper-cli")) return null;
1138
+ const envModel = process.env.WHISPER_CPP_MODEL?.trim();
1139
+ const modelPath = envModel && await fileExists(envModel) ? envModel : "/opt/homebrew/share/whisper-cpp/for-tests-ggml-tiny.bin";
1140
+ if (!await fileExists(modelPath)) return null;
1141
+ return {
1142
+ type: "cli",
1143
+ command: "whisper-cli",
1144
+ args: [
1145
+ "-m",
1146
+ modelPath,
1147
+ "-otxt",
1148
+ "-of",
1149
+ "{{OutputBase}}",
1150
+ "-np",
1151
+ "-nt",
1152
+ "{{MediaPath}}"
1153
+ ]
1154
+ };
1155
+ }
1156
+ async function resolveLocalWhisperEntry() {
1157
+ if (!await hasBinary("whisper")) return null;
1158
+ return {
1159
+ type: "cli",
1160
+ command: "whisper",
1161
+ args: [
1162
+ "--model",
1163
+ "turbo",
1164
+ "--output_format",
1165
+ "txt",
1166
+ "--output_dir",
1167
+ "{{OutputDir}}",
1168
+ "--verbose",
1169
+ "False",
1170
+ "{{MediaPath}}"
1171
+ ]
1172
+ };
1173
+ }
1174
+ async function resolveSherpaOnnxEntry() {
1175
+ if (!await hasBinary("sherpa-onnx-offline")) return null;
1176
+ const modelDir = process.env.SHERPA_ONNX_MODEL_DIR?.trim();
1177
+ if (!modelDir) return null;
1178
+ const tokens = path.join(modelDir, "tokens.txt");
1179
+ const encoder = path.join(modelDir, "encoder.onnx");
1180
+ const decoder = path.join(modelDir, "decoder.onnx");
1181
+ const joiner = path.join(modelDir, "joiner.onnx");
1182
+ if (!await fileExists(tokens)) return null;
1183
+ if (!await fileExists(encoder)) return null;
1184
+ if (!await fileExists(decoder)) return null;
1185
+ if (!await fileExists(joiner)) return null;
1186
+ return {
1187
+ type: "cli",
1188
+ command: "sherpa-onnx-offline",
1189
+ args: [
1190
+ `--tokens=${tokens}`,
1191
+ `--encoder=${encoder}`,
1192
+ `--decoder=${decoder}`,
1193
+ `--joiner=${joiner}`,
1194
+ "{{MediaPath}}"
1195
+ ]
1196
+ };
1197
+ }
1198
+ async function resolveLocalAudioEntry() {
1199
+ const sherpa = await resolveSherpaOnnxEntry();
1200
+ if (sherpa) return sherpa;
1201
+ const whisperCpp = await resolveLocalWhisperCppEntry();
1202
+ if (whisperCpp) return whisperCpp;
1203
+ return await resolveLocalWhisperEntry();
1204
+ }
1205
+ async function resolveGeminiCliEntry(_capability) {
1206
+ if (!await probeGeminiCli()) return null;
1207
+ return {
1208
+ type: "cli",
1209
+ command: "gemini",
1210
+ args: [
1211
+ "--output-format",
1212
+ "json",
1213
+ "--allowed-tools",
1214
+ "read_many_files",
1215
+ "--include-directories",
1216
+ "{{MediaDir}}",
1217
+ "{{Prompt}}",
1218
+ "Use read_many_files to read {{MediaPath}} and respond with only the text output."
1219
+ ]
1220
+ };
1221
+ }
1222
+ async function resolveKeyEntry(params) {
1223
+ const { cfg, agentDir, providerRegistry, capability } = params;
1224
+ const checkProvider = async (providerId, model) => {
1225
+ const provider = getMediaUnderstandingProvider(providerId, providerRegistry);
1226
+ if (!provider) return null;
1227
+ if (capability === "audio" && !provider.transcribeAudio) return null;
1228
+ if (capability === "image" && !provider.describeImage) return null;
1229
+ if (capability === "video" && !provider.describeVideo) return null;
1230
+ try {
1231
+ await resolveApiKeyForProvider({
1232
+ provider: providerId,
1233
+ cfg,
1234
+ agentDir
1235
+ });
1236
+ return {
1237
+ type: "provider",
1238
+ provider: providerId,
1239
+ model
1240
+ };
1241
+ } catch {
1242
+ return null;
1243
+ }
1244
+ };
1245
+ if (capability === "image") {
1246
+ const activeProvider = params.activeModel?.provider?.trim();
1247
+ if (activeProvider) {
1248
+ const activeEntry = await checkProvider(activeProvider, params.activeModel?.model);
1249
+ if (activeEntry) return activeEntry;
1250
+ }
1251
+ for (const providerId of AUTO_IMAGE_KEY_PROVIDERS) {
1252
+ const model = DEFAULT_IMAGE_MODELS[providerId];
1253
+ const entry = await checkProvider(providerId, model);
1254
+ if (entry) return entry;
1255
+ }
1256
+ return null;
1257
+ }
1258
+ if (capability === "video") {
1259
+ const activeProvider = params.activeModel?.provider?.trim();
1260
+ if (activeProvider) {
1261
+ const activeEntry = await checkProvider(activeProvider, params.activeModel?.model);
1262
+ if (activeEntry) return activeEntry;
1263
+ }
1264
+ for (const providerId of AUTO_VIDEO_KEY_PROVIDERS) {
1265
+ const entry = await checkProvider(providerId, void 0);
1266
+ if (entry) return entry;
1267
+ }
1268
+ return null;
1269
+ }
1270
+ const activeProvider = params.activeModel?.provider?.trim();
1271
+ if (activeProvider) {
1272
+ const activeEntry = await checkProvider(activeProvider, params.activeModel?.model);
1273
+ if (activeEntry) return activeEntry;
1274
+ }
1275
+ for (const providerId of AUTO_AUDIO_KEY_PROVIDERS) {
1276
+ const entry = await checkProvider(providerId, void 0);
1277
+ if (entry) return entry;
1278
+ }
1279
+ return null;
1280
+ }
1281
+ async function resolveAutoEntries(params) {
1282
+ const activeEntry = await resolveActiveModelEntry(params);
1283
+ if (activeEntry) return [activeEntry];
1284
+ if (params.capability === "audio") {
1285
+ const localAudio = await resolveLocalAudioEntry();
1286
+ if (localAudio) return [localAudio];
1287
+ }
1288
+ const gemini = await resolveGeminiCliEntry(params.capability);
1289
+ if (gemini) return [gemini];
1290
+ const keys = await resolveKeyEntry(params);
1291
+ if (keys) return [keys];
1292
+ return [];
1293
+ }
1294
+ async function resolveAutoImageModel(params) {
1295
+ const providerRegistry = buildProviderRegistry();
1296
+ const toActive = (entry) => {
1297
+ if (!entry || entry.type === "cli") return null;
1298
+ const provider = entry.provider;
1299
+ if (!provider) return null;
1300
+ const model = entry.model ?? DEFAULT_IMAGE_MODELS[provider];
1301
+ if (!model) return null;
1302
+ return {
1303
+ provider,
1304
+ model
1305
+ };
1306
+ };
1307
+ const resolvedActive = toActive(await resolveActiveModelEntry({
1308
+ cfg: params.cfg,
1309
+ agentDir: params.agentDir,
1310
+ providerRegistry,
1311
+ capability: "image",
1312
+ activeModel: params.activeModel
1313
+ }));
1314
+ if (resolvedActive) return resolvedActive;
1315
+ return toActive(await resolveKeyEntry({
1316
+ cfg: params.cfg,
1317
+ agentDir: params.agentDir,
1318
+ providerRegistry,
1319
+ capability: "image",
1320
+ activeModel: params.activeModel
1321
+ }));
1322
+ }
1323
+ async function resolveActiveModelEntry(params) {
1324
+ const activeProviderRaw = params.activeModel?.provider?.trim();
1325
+ if (!activeProviderRaw) return null;
1326
+ const providerId = normalizeMediaProviderId(activeProviderRaw);
1327
+ if (!providerId) return null;
1328
+ const provider = getMediaUnderstandingProvider(providerId, params.providerRegistry);
1329
+ if (!provider) return null;
1330
+ if (params.capability === "audio" && !provider.transcribeAudio) return null;
1331
+ if (params.capability === "image" && !provider.describeImage) return null;
1332
+ if (params.capability === "video" && !provider.describeVideo) return null;
1333
+ try {
1334
+ await resolveApiKeyForProvider({
1335
+ provider: providerId,
1336
+ cfg: params.cfg,
1337
+ agentDir: params.agentDir
1338
+ });
1339
+ } catch {
1340
+ return null;
1341
+ }
1342
+ return {
1343
+ type: "provider",
1344
+ provider: providerId,
1345
+ model: params.activeModel?.model
1346
+ };
1347
+ }
1348
+ function trimOutput(text, maxChars) {
1349
+ const trimmed = text.trim();
1350
+ if (!maxChars || trimmed.length <= maxChars) return trimmed;
1351
+ return trimmed.slice(0, maxChars).trim();
1352
+ }
1353
+ function commandBase(command) {
1354
+ return path.parse(command).name;
1355
+ }
1356
+ function findArgValue(args, keys) {
1357
+ for (let i = 0; i < args.length; i += 1) if (keys.includes(args[i] ?? "")) {
1358
+ const value = args[i + 1];
1359
+ if (value) return value;
1360
+ }
1361
+ }
1362
+ function hasArg(args, keys) {
1363
+ return args.some((arg) => keys.includes(arg));
1364
+ }
1365
+ function resolveWhisperOutputPath(args, mediaPath) {
1366
+ const outputDir = findArgValue(args, ["--output_dir", "-o"]);
1367
+ const outputFormat = findArgValue(args, ["--output_format"]);
1368
+ if (!outputDir || !outputFormat) return null;
1369
+ if (!outputFormat.split(",").map((value) => value.trim()).includes("txt")) return null;
1370
+ const base = path.parse(mediaPath).name;
1371
+ return path.join(outputDir, `${base}.txt`);
1372
+ }
1373
+ function resolveWhisperCppOutputPath(args) {
1374
+ if (!hasArg(args, ["-otxt", "--output-txt"])) return null;
1375
+ const outputBase = findArgValue(args, ["-of", "--output-file"]);
1376
+ if (!outputBase) return null;
1377
+ return `${outputBase}.txt`;
1378
+ }
1379
+ async function resolveCliOutput(params) {
1380
+ const commandId = commandBase(params.command);
1381
+ const fileOutput = commandId === "whisper-cli" ? resolveWhisperCppOutputPath(params.args) : commandId === "whisper" ? resolveWhisperOutputPath(params.args, params.mediaPath) : null;
1382
+ if (fileOutput && await fileExists(fileOutput)) try {
1383
+ const content = await fs$1.readFile(fileOutput, "utf8");
1384
+ if (content.trim()) return content.trim();
1385
+ } catch {}
1386
+ if (commandId === "gemini") {
1387
+ const response = extractGeminiResponse(params.stdout);
1388
+ if (response) return response;
1389
+ }
1390
+ if (commandId === "sherpa-onnx-offline") {
1391
+ const response = extractSherpaOnnxText(params.stdout);
1392
+ if (response) return response;
1393
+ }
1394
+ return params.stdout.trim();
1395
+ }
1396
+ function normalizeProviderQuery(options) {
1397
+ if (!options) return;
1398
+ const query = {};
1399
+ for (const [key, value] of Object.entries(options)) {
1400
+ if (value === void 0) continue;
1401
+ query[key] = value;
1402
+ }
1403
+ return Object.keys(query).length > 0 ? query : void 0;
1404
+ }
1405
+ function buildDeepgramCompatQuery(options) {
1406
+ if (!options) return;
1407
+ const query = {};
1408
+ if (typeof options.detectLanguage === "boolean") query.detect_language = options.detectLanguage;
1409
+ if (typeof options.punctuate === "boolean") query.punctuate = options.punctuate;
1410
+ if (typeof options.smartFormat === "boolean") query.smart_format = options.smartFormat;
1411
+ return Object.keys(query).length > 0 ? query : void 0;
1412
+ }
1413
+ function normalizeDeepgramQueryKeys(query) {
1414
+ const normalized = { ...query };
1415
+ if ("detectLanguage" in normalized) {
1416
+ normalized.detect_language = normalized.detectLanguage;
1417
+ delete normalized.detectLanguage;
1418
+ }
1419
+ if ("smartFormat" in normalized) {
1420
+ normalized.smart_format = normalized.smartFormat;
1421
+ delete normalized.smartFormat;
1422
+ }
1423
+ return normalized;
1424
+ }
1425
+ function resolveProviderQuery(params) {
1426
+ const { providerId, config, entry } = params;
1427
+ const mergedOptions = normalizeProviderQuery({
1428
+ ...config?.providerOptions?.[providerId],
1429
+ ...entry.providerOptions?.[providerId]
1430
+ });
1431
+ if (providerId !== "deepgram") return mergedOptions;
1432
+ let query = normalizeDeepgramQueryKeys(mergedOptions ?? {});
1433
+ const compat = buildDeepgramCompatQuery({
1434
+ ...config?.deepgram,
1435
+ ...entry.deepgram
1436
+ });
1437
+ for (const [key, value] of Object.entries(compat ?? {})) if (query[key] === void 0) query[key] = value;
1438
+ return Object.keys(query).length > 0 ? query : void 0;
1439
+ }
1440
+ function buildModelDecision(params) {
1441
+ if (params.entryType === "cli") {
1442
+ const command = params.entry.command?.trim();
1443
+ return {
1444
+ type: "cli",
1445
+ provider: command ?? "cli",
1446
+ model: params.entry.model ?? command,
1447
+ outcome: params.outcome,
1448
+ reason: params.reason
1449
+ };
1450
+ }
1451
+ const providerIdRaw = params.entry.provider?.trim();
1452
+ return {
1453
+ type: "provider",
1454
+ provider: (providerIdRaw ? normalizeMediaProviderId(providerIdRaw) : void 0) ?? providerIdRaw,
1455
+ model: params.entry.model,
1456
+ outcome: params.outcome,
1457
+ reason: params.reason
1458
+ };
1459
+ }
1460
+ function formatDecisionSummary(decision) {
1461
+ const total = decision.attachments.length;
1462
+ const success = decision.attachments.filter((entry) => entry.chosen?.outcome === "success").length;
1463
+ const chosen = decision.attachments.find((entry) => entry.chosen)?.chosen;
1464
+ const provider = chosen?.provider?.trim();
1465
+ const model = chosen?.model?.trim();
1466
+ const modelLabel = provider ? model ? `${provider}/${model}` : provider : void 0;
1467
+ const reason = decision.attachments.flatMap((entry) => entry.attempts.map((attempt) => attempt.reason).filter(Boolean)).find(Boolean);
1468
+ const shortReason = reason ? reason.split(":")[0]?.trim() : void 0;
1469
+ const countLabel = total > 0 ? ` (${success}/${total})` : "";
1470
+ const viaLabel = modelLabel ? ` via ${modelLabel}` : "";
1471
+ const reasonLabel = shortReason ? ` reason=${shortReason}` : "";
1472
+ return `${decision.capability}: ${decision.outcome}${countLabel}${viaLabel}${reasonLabel}`;
1473
+ }
1474
+ async function runProviderEntry(params) {
1475
+ const { entry, capability, cfg } = params;
1476
+ const providerIdRaw = entry.provider?.trim();
1477
+ if (!providerIdRaw) throw new Error(`Provider entry missing provider for ${capability}`);
1478
+ const providerId = normalizeMediaProviderId(providerIdRaw);
1479
+ const maxBytes = resolveMaxBytes({
1480
+ capability,
1481
+ entry,
1482
+ cfg,
1483
+ config: params.config
1484
+ });
1485
+ const maxChars = resolveMaxChars({
1486
+ capability,
1487
+ entry,
1488
+ cfg,
1489
+ config: params.config
1490
+ });
1491
+ const timeoutMs = resolveTimeoutMs(entry.timeoutSeconds ?? params.config?.timeoutSeconds ?? cfg.tools?.media?.[capability]?.timeoutSeconds, DEFAULT_TIMEOUT_SECONDS[capability]);
1492
+ const prompt = resolvePrompt(capability, entry.prompt ?? params.config?.prompt ?? cfg.tools?.media?.[capability]?.prompt, maxChars);
1493
+ if (capability === "image") {
1494
+ if (!params.agentDir) throw new Error("Image understanding requires agentDir");
1495
+ const modelId = entry.model?.trim();
1496
+ if (!modelId) throw new Error("Image understanding requires model id");
1497
+ const media = await params.cache.getBuffer({
1498
+ attachmentIndex: params.attachmentIndex,
1499
+ maxBytes,
1500
+ timeoutMs
1501
+ });
1502
+ const provider = getMediaUnderstandingProvider(providerId, params.providerRegistry);
1503
+ const result = provider?.describeImage ? await provider.describeImage({
1504
+ buffer: media.buffer,
1505
+ fileName: media.fileName,
1506
+ mime: media.mime,
1507
+ model: modelId,
1508
+ provider: providerId,
1509
+ prompt,
1510
+ timeoutMs,
1511
+ profile: entry.profile,
1512
+ preferredProfile: entry.preferredProfile,
1513
+ agentDir: params.agentDir,
1514
+ cfg: params.cfg
1515
+ }) : await describeImageWithModel({
1516
+ buffer: media.buffer,
1517
+ fileName: media.fileName,
1518
+ mime: media.mime,
1519
+ model: modelId,
1520
+ provider: providerId,
1521
+ prompt,
1522
+ timeoutMs,
1523
+ profile: entry.profile,
1524
+ preferredProfile: entry.preferredProfile,
1525
+ agentDir: params.agentDir,
1526
+ cfg: params.cfg
1527
+ });
1528
+ return {
1529
+ kind: "image.description",
1530
+ attachmentIndex: params.attachmentIndex,
1531
+ text: trimOutput(result.text, maxChars),
1532
+ provider: providerId,
1533
+ model: result.model ?? modelId
1534
+ };
1535
+ }
1536
+ const provider = getMediaUnderstandingProvider(providerId, params.providerRegistry);
1537
+ if (!provider) throw new Error(`Media provider not available: ${providerId}`);
1538
+ if (capability === "audio") {
1539
+ if (!provider.transcribeAudio) throw new Error(`Audio transcription provider "${providerId}" not available.`);
1540
+ const media = await params.cache.getBuffer({
1541
+ attachmentIndex: params.attachmentIndex,
1542
+ maxBytes,
1543
+ timeoutMs
1544
+ });
1545
+ const apiKey = requireApiKey(await resolveApiKeyForProvider({
1546
+ provider: providerId,
1547
+ cfg,
1548
+ profileId: entry.profile,
1549
+ preferredProfile: entry.preferredProfile,
1550
+ agentDir: params.agentDir
1551
+ }), providerId);
1552
+ const providerConfig = cfg.models?.providers?.[providerId];
1553
+ const baseUrl = entry.baseUrl ?? params.config?.baseUrl ?? providerConfig?.baseUrl;
1554
+ const mergedHeaders = {
1555
+ ...providerConfig?.headers,
1556
+ ...params.config?.headers,
1557
+ ...entry.headers
1558
+ };
1559
+ const headers = Object.keys(mergedHeaders).length > 0 ? mergedHeaders : void 0;
1560
+ const providerQuery = resolveProviderQuery({
1561
+ providerId,
1562
+ config: params.config,
1563
+ entry
1564
+ });
1565
+ const model = entry.model?.trim() || DEFAULT_AUDIO_MODELS[providerId] || entry.model;
1566
+ const result = await provider.transcribeAudio({
1567
+ buffer: media.buffer,
1568
+ fileName: media.fileName,
1569
+ mime: media.mime,
1570
+ apiKey,
1571
+ baseUrl,
1572
+ headers,
1573
+ model,
1574
+ language: entry.language ?? params.config?.language ?? cfg.tools?.media?.audio?.language,
1575
+ prompt,
1576
+ query: providerQuery,
1577
+ timeoutMs
1578
+ });
1579
+ return {
1580
+ kind: "audio.transcription",
1581
+ attachmentIndex: params.attachmentIndex,
1582
+ text: trimOutput(result.text, maxChars),
1583
+ provider: providerId,
1584
+ model: result.model ?? model
1585
+ };
1586
+ }
1587
+ if (!provider.describeVideo) throw new Error(`Video understanding provider "${providerId}" not available.`);
1588
+ const media = await params.cache.getBuffer({
1589
+ attachmentIndex: params.attachmentIndex,
1590
+ maxBytes,
1591
+ timeoutMs
1592
+ });
1593
+ const estimatedBase64Bytes = estimateBase64Size(media.size);
1594
+ const maxBase64Bytes = resolveVideoMaxBase64Bytes(maxBytes);
1595
+ if (estimatedBase64Bytes > maxBase64Bytes) throw new MediaUnderstandingSkipError("maxBytes", `Video attachment ${params.attachmentIndex + 1} base64 payload ${estimatedBase64Bytes} exceeds ${maxBase64Bytes}`);
1596
+ const apiKey = requireApiKey(await resolveApiKeyForProvider({
1597
+ provider: providerId,
1598
+ cfg,
1599
+ profileId: entry.profile,
1600
+ preferredProfile: entry.preferredProfile,
1601
+ agentDir: params.agentDir
1602
+ }), providerId);
1603
+ const providerConfig = cfg.models?.providers?.[providerId];
1604
+ const result = await provider.describeVideo({
1605
+ buffer: media.buffer,
1606
+ fileName: media.fileName,
1607
+ mime: media.mime,
1608
+ apiKey,
1609
+ baseUrl: providerConfig?.baseUrl,
1610
+ headers: providerConfig?.headers,
1611
+ model: entry.model,
1612
+ prompt,
1613
+ timeoutMs
1614
+ });
1615
+ return {
1616
+ kind: "video.description",
1617
+ attachmentIndex: params.attachmentIndex,
1618
+ text: trimOutput(result.text, maxChars),
1619
+ provider: providerId,
1620
+ model: result.model ?? entry.model
1621
+ };
1622
+ }
1623
+ async function runCliEntry(params) {
1624
+ const { entry, capability, cfg, ctx } = params;
1625
+ const command = entry.command?.trim();
1626
+ const args = entry.args ?? [];
1627
+ if (!command) throw new Error(`CLI entry missing command for ${capability}`);
1628
+ const maxBytes = resolveMaxBytes({
1629
+ capability,
1630
+ entry,
1631
+ cfg,
1632
+ config: params.config
1633
+ });
1634
+ const maxChars = resolveMaxChars({
1635
+ capability,
1636
+ entry,
1637
+ cfg,
1638
+ config: params.config
1639
+ });
1640
+ const timeoutMs = resolveTimeoutMs(entry.timeoutSeconds ?? params.config?.timeoutSeconds ?? cfg.tools?.media?.[capability]?.timeoutSeconds, DEFAULT_TIMEOUT_SECONDS[capability]);
1641
+ const prompt = resolvePrompt(capability, entry.prompt ?? params.config?.prompt ?? cfg.tools?.media?.[capability]?.prompt, maxChars);
1642
+ const pathResult = await params.cache.getPath({
1643
+ attachmentIndex: params.attachmentIndex,
1644
+ maxBytes,
1645
+ timeoutMs
1646
+ });
1647
+ const outputDir = await fs$1.mkdtemp(path.join(os.tmpdir(), "openclaw-media-cli-"));
1648
+ const mediaPath = pathResult.path;
1649
+ const outputBase = path.join(outputDir, path.parse(mediaPath).name);
1650
+ const templCtx = {
1651
+ ...ctx,
1652
+ MediaPath: mediaPath,
1653
+ MediaDir: path.dirname(mediaPath),
1654
+ OutputDir: outputDir,
1655
+ OutputBase: outputBase,
1656
+ Prompt: prompt,
1657
+ MaxChars: maxChars
1658
+ };
1659
+ const argv = [command, ...args].map((part, index) => index === 0 ? part : applyTemplate(part, templCtx));
1660
+ try {
1661
+ if (shouldLogVerbose()) logVerbose(`Media understanding via CLI: ${argv.join(" ")}`);
1662
+ const { stdout } = await runExec(argv[0], argv.slice(1), {
1663
+ timeoutMs,
1664
+ maxBuffer: CLI_OUTPUT_MAX_BUFFER
1665
+ });
1666
+ const text = trimOutput(await resolveCliOutput({
1667
+ command,
1668
+ args: argv.slice(1),
1669
+ stdout,
1670
+ mediaPath
1671
+ }), maxChars);
1672
+ if (!text) return null;
1673
+ return {
1674
+ kind: capability === "audio" ? "audio.transcription" : `${capability}.description`,
1675
+ attachmentIndex: params.attachmentIndex,
1676
+ text,
1677
+ provider: "cli",
1678
+ model: command
1679
+ };
1680
+ } finally {
1681
+ await fs$1.rm(outputDir, {
1682
+ recursive: true,
1683
+ force: true
1684
+ }).catch(() => {});
1685
+ }
1686
+ }
1687
+ async function runAttachmentEntries(params) {
1688
+ const { entries, capability } = params;
1689
+ const attempts = [];
1690
+ for (const entry of entries) {
1691
+ const entryType = entry.type ?? (entry.command ? "cli" : "provider");
1692
+ try {
1693
+ const result = entryType === "cli" ? await runCliEntry({
1694
+ capability,
1695
+ entry,
1696
+ cfg: params.cfg,
1697
+ ctx: params.ctx,
1698
+ attachmentIndex: params.attachmentIndex,
1699
+ cache: params.cache,
1700
+ config: params.config
1701
+ }) : await runProviderEntry({
1702
+ capability,
1703
+ entry,
1704
+ cfg: params.cfg,
1705
+ ctx: params.ctx,
1706
+ attachmentIndex: params.attachmentIndex,
1707
+ cache: params.cache,
1708
+ agentDir: params.agentDir,
1709
+ providerRegistry: params.providerRegistry,
1710
+ config: params.config
1711
+ });
1712
+ if (result) {
1713
+ const decision = buildModelDecision({
1714
+ entry,
1715
+ entryType,
1716
+ outcome: "success"
1717
+ });
1718
+ if (result.provider) decision.provider = result.provider;
1719
+ if (result.model) decision.model = result.model;
1720
+ attempts.push(decision);
1721
+ return {
1722
+ output: result,
1723
+ attempts
1724
+ };
1725
+ }
1726
+ attempts.push(buildModelDecision({
1727
+ entry,
1728
+ entryType,
1729
+ outcome: "skipped",
1730
+ reason: "empty output"
1731
+ }));
1732
+ } catch (err) {
1733
+ if (isMediaUnderstandingSkipError(err)) {
1734
+ attempts.push(buildModelDecision({
1735
+ entry,
1736
+ entryType,
1737
+ outcome: "skipped",
1738
+ reason: `${err.reason}: ${err.message}`
1739
+ }));
1740
+ if (shouldLogVerbose()) logVerbose(`Skipping ${capability} model due to ${err.reason}: ${err.message}`);
1741
+ continue;
1742
+ }
1743
+ attempts.push(buildModelDecision({
1744
+ entry,
1745
+ entryType,
1746
+ outcome: "failed",
1747
+ reason: String(err)
1748
+ }));
1749
+ if (shouldLogVerbose()) logVerbose(`${capability} understanding failed: ${String(err)}`);
1750
+ }
1751
+ }
1752
+ return {
1753
+ output: null,
1754
+ attempts
1755
+ };
1756
+ }
1757
+ async function runCapability(params) {
1758
+ const { capability, cfg, ctx } = params;
1759
+ const config = params.config ?? cfg.tools?.media?.[capability];
1760
+ if (config?.enabled === false) return {
1761
+ outputs: [],
1762
+ decision: {
1763
+ capability,
1764
+ outcome: "disabled",
1765
+ attachments: []
1766
+ }
1767
+ };
1768
+ const attachmentPolicy = config?.attachments;
1769
+ const selected = selectAttachments({
1770
+ capability,
1771
+ attachments: params.media,
1772
+ policy: attachmentPolicy
1773
+ });
1774
+ if (selected.length === 0) return {
1775
+ outputs: [],
1776
+ decision: {
1777
+ capability,
1778
+ outcome: "no-attachment",
1779
+ attachments: []
1780
+ }
1781
+ };
1782
+ if (resolveScopeDecision({
1783
+ scope: config?.scope,
1784
+ ctx
1785
+ }) === "deny") {
1786
+ if (shouldLogVerbose()) logVerbose(`${capability} understanding disabled by scope policy.`);
1787
+ return {
1788
+ outputs: [],
1789
+ decision: {
1790
+ capability,
1791
+ outcome: "scope-deny",
1792
+ attachments: selected.map((item) => ({
1793
+ attachmentIndex: item.index,
1794
+ attempts: []
1795
+ }))
1796
+ }
1797
+ };
1798
+ }
1799
+ const activeProvider = params.activeModel?.provider?.trim();
1800
+ if (capability === "image" && activeProvider) {
1801
+ if (modelSupportsVision(findModelInCatalog(await loadModelCatalog({ config: cfg }), activeProvider, params.activeModel?.model ?? ""))) {
1802
+ if (shouldLogVerbose()) logVerbose("Skipping image understanding: primary model supports vision natively");
1803
+ const model = params.activeModel?.model?.trim();
1804
+ const reason = "primary model supports vision natively";
1805
+ return {
1806
+ outputs: [],
1807
+ decision: {
1808
+ capability,
1809
+ outcome: "skipped",
1810
+ attachments: selected.map((item) => {
1811
+ const attempt = {
1812
+ type: "provider",
1813
+ provider: activeProvider,
1814
+ model: model || void 0,
1815
+ outcome: "skipped",
1816
+ reason
1817
+ };
1818
+ return {
1819
+ attachmentIndex: item.index,
1820
+ attempts: [attempt],
1821
+ chosen: attempt
1822
+ };
1823
+ })
1824
+ }
1825
+ };
1826
+ }
1827
+ }
1828
+ let resolvedEntries = resolveModelEntries({
1829
+ cfg,
1830
+ capability,
1831
+ config,
1832
+ providerRegistry: params.providerRegistry
1833
+ });
1834
+ if (resolvedEntries.length === 0) resolvedEntries = await resolveAutoEntries({
1835
+ cfg,
1836
+ agentDir: params.agentDir,
1837
+ providerRegistry: params.providerRegistry,
1838
+ capability,
1839
+ activeModel: params.activeModel
1840
+ });
1841
+ if (resolvedEntries.length === 0) return {
1842
+ outputs: [],
1843
+ decision: {
1844
+ capability,
1845
+ outcome: "skipped",
1846
+ attachments: selected.map((item) => ({
1847
+ attachmentIndex: item.index,
1848
+ attempts: []
1849
+ }))
1850
+ }
1851
+ };
1852
+ const outputs = [];
1853
+ const attachmentDecisions = [];
1854
+ for (const attachment of selected) {
1855
+ const { output, attempts } = await runAttachmentEntries({
1856
+ capability,
1857
+ cfg,
1858
+ ctx,
1859
+ attachmentIndex: attachment.index,
1860
+ agentDir: params.agentDir,
1861
+ providerRegistry: params.providerRegistry,
1862
+ cache: params.attachments,
1863
+ entries: resolvedEntries,
1864
+ config
1865
+ });
1866
+ if (output) outputs.push(output);
1867
+ attachmentDecisions.push({
1868
+ attachmentIndex: attachment.index,
1869
+ attempts,
1870
+ chosen: attempts.find((attempt) => attempt.outcome === "success")
1871
+ });
1872
+ }
1873
+ const decision = {
1874
+ capability,
1875
+ outcome: outputs.length > 0 ? "success" : "skipped",
1876
+ attachments: attachmentDecisions
1877
+ };
1878
+ if (shouldLogVerbose()) logVerbose(`Media understanding ${formatDecisionSummary(decision)}`);
1879
+ return {
1880
+ outputs,
1881
+ decision
1882
+ };
1883
+ }
1884
+
1885
+ //#endregion
1886
+ export { loadModelCatalog as _, runCapability as a, resolveConcurrency as c, resolveMediaUnderstandingScope as d, CLI_OUTPUT_MAX_BUFFER as f, findModelInCatalog as g, registerUnhandledRejectionHandler as h, resolveAutoImageModel as i, resolveTimeoutMs as l, installUnhandledRejectionHandler as m, createMediaAttachmentCache as n, isAudioAttachment as o, applyTemplate as p, normalizeMediaAttachments as r, resolveAttachmentKind as s, buildProviderRegistry as t, normalizeMediaUnderstandingChatType as u, modelSupportsVision as v };