@noxsoft/anima 2.0.2 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (829) hide show
  1. package/README.md +1260 -28
  2. package/dist/accounts-Bth3PpPD.js +260 -0
  3. package/dist/accounts-D8CPKNkN.js +259 -0
  4. package/dist/acp-cli-ByK6lS6c.js +1081 -0
  5. package/dist/acp-cli-CaQCjIw4.js +1084 -0
  6. package/dist/agent-BgIkqd3F.js +725 -0
  7. package/dist/agent-N5BDcge4.js +725 -0
  8. package/dist/agent-events-COH7NDW2.js +182 -0
  9. package/dist/agent-scope-CPphqq-U.js +452 -0
  10. package/dist/agent-scope-DZgptr9J.js +452 -0
  11. package/dist/agent-scope-cj2QCT6R.js +112 -0
  12. package/dist/agents-NEudYMdg.js +774 -0
  13. package/dist/agents.config-Bujs-NIy.js +182 -0
  14. package/dist/agents.config-jp7OLssr.js +182 -0
  15. package/dist/argv-BMZMiW7v.js +73 -0
  16. package/dist/audit-C-UJhfdv.js +2401 -0
  17. package/dist/audit-CeCO7SK5.js +2401 -0
  18. package/dist/auth-BNZsOHGF.js +648 -0
  19. package/dist/auth-DMPZWzEa.js +639 -0
  20. package/dist/auth-choice-5VnaGMD-.js +2681 -0
  21. package/dist/auth-choice-DA2k4vs8.js +2681 -0
  22. package/dist/auth-health-B7FqA26_.js +149 -0
  23. package/dist/auth-health-VO_MPqVX.js +149 -0
  24. package/dist/auth-profiles-BDrNYX_n.js +1564 -0
  25. package/dist/auth-profiles-CxSHydjn.js +2689 -0
  26. package/dist/banner-BtDZPRzi.js +294 -0
  27. package/dist/browser-cli-8yQMpxb8.js +1679 -0
  28. package/dist/browser-cli-Czg3JtDH.js +1676 -0
  29. package/dist/build-info.json +3 -3
  30. package/dist/bundled/boot-md/handler.js +16 -16
  31. package/dist/bundled/bootstrap-extra-files/handler.js +4 -4
  32. package/dist/bundled/command-logger/handler.js +1 -1
  33. package/dist/bundled/session-memory/handler.js +5 -5
  34. package/dist/call-BIzCaKZb.js +282 -0
  35. package/dist/call-BYDpTVCZ.js +282 -0
  36. package/dist/canvas-host/a2ui/.bundle.hash +1 -1
  37. package/dist/catalog-CqKiUgu6.js +185 -0
  38. package/dist/catalog-DMfEg-oK.js +185 -0
  39. package/dist/channel-options-BrtCtyrT.js +32 -0
  40. package/dist/channel-options-CO21Gl8p.js +33 -0
  41. package/dist/channel-selection-Bbm1lq3P.js +51 -0
  42. package/dist/channel-selection-CqcX7Ocw.js +51 -0
  43. package/dist/channel-web-DrsT6OAE.js +2162 -0
  44. package/dist/channels-cli-Juyh1S6n.js +1304 -0
  45. package/dist/channels-cli-zNvi1m5c.js +1306 -0
  46. package/dist/channels-status-issues-CqzqshW4.js +18 -0
  47. package/dist/channels-status-issues-DdJdO866.js +18 -0
  48. package/dist/chrome-C4dOMO8z.js +1601 -0
  49. package/dist/chrome-DdcDzAtH.js +1629 -0
  50. package/dist/chrome-U3DRzjJD.js +1601 -0
  51. package/dist/chunk-D2nLsrEW.js +348 -0
  52. package/dist/clack-prompter-BI3RDW5w.js +92 -0
  53. package/dist/clack-prompter-Dwr1m_IZ.js +92 -0
  54. package/dist/cli/daemon-cli.js +1 -1
  55. package/dist/cli-C3cpDaz8.js +99 -0
  56. package/dist/cli-CjWUGdGC.js +101 -0
  57. package/dist/cli-session-BVjY_XrW.js +5463 -0
  58. package/dist/cli-session-gtuYN2Iq.js +5408 -0
  59. package/dist/client-Dswwze5_.js +1692 -0
  60. package/dist/client-LRKFjo4A.js +1692 -0
  61. package/dist/clipboard-BZKS9O1u.js +31 -0
  62. package/dist/clipboard-DES8b1AM.js +31 -0
  63. package/dist/command-format-CP1YTNCl.js +52 -0
  64. package/dist/command-format-CVL4K5cj.js +52 -0
  65. package/dist/command-format-G6N2zghg.js +38 -0
  66. package/dist/command-registry-BBvNvysr.js +248 -0
  67. package/dist/commands-AZ3n8Y2c.js +726 -0
  68. package/dist/commands-BMnD_QRY.js +726 -0
  69. package/dist/commands-registry-cFqZ6Ib4.js +766 -0
  70. package/dist/commands-registry-q13H7ng5.js +766 -0
  71. package/dist/common-CX5458fH.js +287 -0
  72. package/dist/common-DJbnT8ws.js +287 -0
  73. package/dist/completion-cli-BADRBcIl.js +432 -0
  74. package/dist/completion-cli-DMQgiObF.js +431 -0
  75. package/dist/config-CU-Axg8P.js +5704 -0
  76. package/dist/config-DaqbUdkI.js +5705 -0
  77. package/dist/config-cli-BPlbwiuA.js +244 -0
  78. package/dist/config-cli-DXgZJkPU.js +247 -0
  79. package/dist/config-guard-Ba49JNds.js +76 -0
  80. package/dist/config-guard-Cu0qMKZJ.js +93 -0
  81. package/dist/config-kVVm5EYV.js +6523 -0
  82. package/dist/config-sync-CzLnLTXt.js +91 -0
  83. package/dist/config-sync-DuydxPWx.js +91 -0
  84. package/dist/configure-CHgacLyi.js +960 -0
  85. package/dist/configure-DfHXDa1L.js +959 -0
  86. package/dist/context-DzgXOckU.js +60 -0
  87. package/dist/control-service-8_wKHwBa.js +72 -0
  88. package/dist/control-service-BtL1Jto_.js +72 -0
  89. package/dist/cron-cli-BCzSR2c0.js +448 -0
  90. package/dist/cron-cli-CCWNkykU.js +451 -0
  91. package/dist/daemon-cli-Bjkbu9Vy.js +565 -0
  92. package/dist/daemon-cli-CmlHcC1J.js +566 -0
  93. package/dist/daemon-cli.js +16 -16
  94. package/dist/daemon-runtime-C0tz7VAC.js +460 -0
  95. package/dist/daemon-runtime-rUTqCVwJ.js +460 -0
  96. package/dist/deliver-BBggsviM.js +1097 -0
  97. package/dist/deliver-CePITOl8.js +1162 -0
  98. package/dist/deliver-DFnVaetP.js +1097 -0
  99. package/dist/delivery-queue-BJQK3oh5.js +220 -0
  100. package/dist/deps-CeEKhrp7.js +42 -0
  101. package/dist/devices-cli-DQrDMrZH.js +198 -0
  102. package/dist/devices-cli-Oe-A1Dv0.js +195 -0
  103. package/dist/diagnostics-DxMFrBLO.js +35 -0
  104. package/dist/diagnostics-m79ZlMmZ.js +35 -0
  105. package/dist/directory-cli-BL6h8cGF.js +246 -0
  106. package/dist/directory-cli-Cjgmi_sj.js +243 -0
  107. package/dist/dispatcher-DAFbQM-c.js +100 -0
  108. package/dist/dispatcher-DNd40gUn.js +100 -0
  109. package/dist/dist-CqDI82ei.js +929 -0
  110. package/dist/dist-DnHRxR5U.js +929 -0
  111. package/dist/dns-cli-CFtV3BXK.js +200 -0
  112. package/dist/dns-cli-NyIHvQ5S.js +197 -0
  113. package/dist/dock-BdXLb5oY.js +753 -0
  114. package/dist/dock-jYICmNcI.js +753 -0
  115. package/dist/docs-cli-CrOaIK_H.js +161 -0
  116. package/dist/docs-cli-D_cmJDSr.js +159 -0
  117. package/dist/doctor-BpGxKrBl.js +1815 -0
  118. package/dist/doctor-D12wNQPU.js +1813 -0
  119. package/dist/doctor-completion-DeOfofek.js +92 -0
  120. package/dist/doctor-completion-DwjqdEcK.js +92 -0
  121. package/dist/doctor-config-flow-BI3mpkbd.js +1232 -0
  122. package/dist/doctor-config-flow-wMHheFkC.js +1232 -0
  123. package/dist/engine-BCtL-AMw.js +563 -0
  124. package/dist/engine-Bk_UT413.js +563 -0
  125. package/dist/entry.js +5 -5
  126. package/dist/env-v6411I8h.js +32 -0
  127. package/dist/exec-B7sUS164.js +1167 -0
  128. package/dist/exec-approvals-CroGJRUg.js +1221 -0
  129. package/dist/exec-approvals-cli-BTxF_RsH.js +371 -0
  130. package/dist/exec-approvals-cli-n1gyGwH2.js +368 -0
  131. package/dist/exec-mhSykkaa.js +255 -0
  132. package/dist/extensionAPI.js +3 -3
  133. package/dist/frontmatter-BmHq0vRD.js +204 -0
  134. package/dist/gateway-cli-DDBadlrS.js +19971 -0
  135. package/dist/gateway-cli-IZNkOMBe.js +19972 -0
  136. package/dist/gateway-rpc-Dtx8HN-n.js +28 -0
  137. package/dist/gateway-rpc-L2PVSqGj.js +28 -0
  138. package/dist/github-copilot-auth-DKyqDaGU.js +1418 -0
  139. package/dist/github-copilot-auth-DXpOMSd3.js +1418 -0
  140. package/dist/gmail-setup-utils-BKNczIJ9.js +428 -0
  141. package/dist/gmail-setup-utils-co0ppccC.js +428 -0
  142. package/dist/health-Bm8ZTvC3.js +1253 -0
  143. package/dist/health-DUf1gt4E.js +1258 -0
  144. package/dist/health-format-BksT6F68.js +208 -0
  145. package/dist/health-format-uzh1xYLD.js +208 -0
  146. package/dist/heartbeat-visibility-1TJb1Zao.js +98 -0
  147. package/dist/heartbeat-visibility-CwodtdcX.js +98 -0
  148. package/dist/help-format-C6cv_aZp.js +17 -0
  149. package/dist/helpers-N-uSFKOn.js +10 -0
  150. package/dist/hooks-cli-1POsXqOl.js +993 -0
  151. package/dist/hooks-cli-BGjILbze.js +991 -0
  152. package/dist/hooks-status-DE07n5RC.js +356 -0
  153. package/dist/hooks-status-Du-d1jde.js +356 -0
  154. package/dist/image-ops-B_AYV3tp.js +541 -0
  155. package/dist/image-ops-Bp0C6Mvr.js +541 -0
  156. package/dist/index.js +82 -82
  157. package/dist/init-9A0s7bWG.js +122 -0
  158. package/dist/init-DoyCHJDC.js +122 -0
  159. package/dist/installs-D1C9wHAq.js +383 -0
  160. package/dist/installs-Dh4dHayM.js +383 -0
  161. package/dist/ipv4-DCItfaJo.js +1964 -0
  162. package/dist/ipv4-DSOUVx0i.js +1964 -0
  163. package/dist/lanes-BvSnHq2h.js +232 -0
  164. package/dist/lifecycle-core-BY4WIf9g.js +388 -0
  165. package/dist/lifecycle-core-TQKyXO-6.js +387 -0
  166. package/dist/links-CNu_8RZl.js +15 -0
  167. package/dist/links-D2tt2ouh.js +15 -0
  168. package/dist/llm-slug-generator.js +4 -4
  169. package/dist/logging-BIeRw0WR.js +15 -0
  170. package/dist/logging-C7lb3Vjc.js +15 -0
  171. package/dist/login-DXWKewA2.js +59 -0
  172. package/dist/login-Fhh4uWmf.js +61 -0
  173. package/dist/login-pPs3UO38.js +61 -0
  174. package/dist/login-qr-CevLD8cV.js +326 -0
  175. package/dist/login-qr-GF2JMIy-.js +323 -0
  176. package/dist/login-qr-ZYYKD6Yt.js +321 -0
  177. package/dist/logs-cli-CzXbX8HZ.js +242 -0
  178. package/dist/logs-cli-D9ngH9PF.js +245 -0
  179. package/dist/manager-BD5rA3w0.js +3244 -0
  180. package/dist/manager-BDPgBQSH.js +3246 -0
  181. package/dist/manager-DRWMWM--.js +3244 -0
  182. package/dist/manifest-registry-DbvPaBXY.js +748 -0
  183. package/dist/manifest-registry-kHX_MFa1.js +748 -0
  184. package/dist/markdown-tables-CqwihY2m.js +347 -0
  185. package/dist/markdown-tables-DJV7eAJZ.js +348 -0
  186. package/dist/media-lUqN-0O9.js +1342 -0
  187. package/dist/memory-cli-BLXSpgnN.js +868 -0
  188. package/dist/memory-cli-BcGVkkRJ.js +869 -0
  189. package/dist/message-channel-D_jIO87f.js +110 -0
  190. package/dist/migrate-BpVOar4L.js +157 -0
  191. package/dist/migrate-CkgGDkWy.js +157 -0
  192. package/dist/model-selection-Cqt6aJ0G.js +2691 -0
  193. package/dist/models-CExsNQPH.js +2510 -0
  194. package/dist/models-cli-Ba3Jmwev.js +2739 -0
  195. package/dist/models-cli-iDAlsbL2.js +258 -0
  196. package/dist/net-0A_zcaQD.js +218 -0
  197. package/dist/node-cli-ATmwCXIk.js +1319 -0
  198. package/dist/node-cli-DYFR_V25.js +1322 -0
  199. package/dist/node-service-CN4LqR1A.js +67 -0
  200. package/dist/node-service-CWt3MdSC.js +67 -0
  201. package/dist/nodes-cli-BeVmhTz3.js +1197 -0
  202. package/dist/nodes-cli-QeJIfa18.js +1200 -0
  203. package/dist/nodes-screen-DHyWAlla.js +234 -0
  204. package/dist/nodes-screen-qs3jRBPk.js +234 -0
  205. package/dist/note-CSlg2BnB.js +73 -0
  206. package/dist/note-Ctvglhp1.js +73 -0
  207. package/dist/npm-registry-spec-DQd4M22q.js +351 -0
  208. package/dist/npm-registry-spec-PxisIMts.js +351 -0
  209. package/dist/onboard-DeruD10m.js +1166 -0
  210. package/dist/onboard-SAcu5N6N.js +1165 -0
  211. package/dist/onboard-channels-C4iSfFXR.js +672 -0
  212. package/dist/onboard-channels-oVTVgoyg.js +672 -0
  213. package/dist/onboard-helpers-B8roRwLP.js +365 -0
  214. package/dist/onboard-helpers-Dgh26hgP.js +365 -0
  215. package/dist/onboarding-Bi-ac8we.js +911 -0
  216. package/dist/onboarding-C2gjB2u8.js +910 -0
  217. package/dist/orchestrator-DlbAYMQP.js +357 -0
  218. package/dist/orchestrator-DlwVRVDA.js +357 -0
  219. package/dist/outbound-CkKgc6iR.js +2062 -0
  220. package/dist/outbound-Vfm5yDh3.js +214 -0
  221. package/dist/outbound-bs_VK51X.js +214 -0
  222. package/dist/outbound-send-deps-DDjiMfEL.js +55 -0
  223. package/dist/pairing-cli-CJYeuEik.js +118 -0
  224. package/dist/pairing-cli-mqopHI8s.js +121 -0
  225. package/dist/pairing-store-BsXzUDPv.js +388 -0
  226. package/dist/pairing-store-DoNj00-X.js +388 -0
  227. package/dist/path-env-C_xpiG8l.js +89 -0
  228. package/dist/path-env-DSSMHu5A.js +89 -0
  229. package/dist/paths-B1vRVCad.js +126 -0
  230. package/dist/paths-BMuHNFxg.js +238 -0
  231. package/dist/paths-BXQQzXGQ.js +129 -0
  232. package/dist/paths-Buw_geoe.js +54 -0
  233. package/dist/paths-DA9WYabg.js +222 -0
  234. package/dist/paths-DfQGx0_k.js +129 -0
  235. package/dist/pi-auth-json-DOPW3e4X.js +78 -0
  236. package/dist/pi-auth-json-MruLmI_X.js +82 -0
  237. package/dist/pi-auth-json-lae_wwwo.js +80 -0
  238. package/dist/pi-model-discovery-7q0GxMrp.js +3 -0
  239. package/dist/pi-tools.policy-Csmla32P.js +200 -0
  240. package/dist/pi-tools.policy-xYdDLEv9.js +200 -0
  241. package/dist/plugin-auto-enable-CViVVWgg.js +282 -0
  242. package/dist/plugin-auto-enable-CjZ238UI.js +282 -0
  243. package/dist/plugin-registry-B4Aw2hzq.js +32 -0
  244. package/dist/plugin-registry-DW81arxW.js +32 -0
  245. package/dist/plugin-sdk/cli/cli-name.d.ts +1 -1
  246. package/dist/plugin-sdk/config/paths.d.ts +2 -2
  247. package/dist/plugin-sdk/index.js +7 -7
  248. package/dist/plugins-DhcGAPDB.js +38 -0
  249. package/dist/plugins-DtghNRtM.js +168 -0
  250. package/dist/plugins-cli-4vWTmOAb.js +736 -0
  251. package/dist/plugins-cli-CdTMbP0X.js +734 -0
  252. package/dist/polls-D6eCdatA.js +1343 -0
  253. package/dist/ports-BtZx-JKD.js +96 -0
  254. package/dist/ports-C8bKN8s0.js +96 -0
  255. package/dist/ports-DHiKnPRX.js +344 -0
  256. package/dist/ports-vd93M_Pt.js +317 -0
  257. package/dist/program-CX3aUVeb.js +176 -0
  258. package/dist/program-context-BPos0ivo.js +496 -0
  259. package/dist/progress-oiAjiiNi.js +133 -0
  260. package/dist/prompt-style-Cm4wOtKm.js +9 -0
  261. package/dist/pw-ai-4QbK5YFe.js +1865 -0
  262. package/dist/pw-ai-BWz3Cxt7.js +1868 -0
  263. package/dist/pw-ai-C83HBue2.js +1867 -0
  264. package/dist/qmd-manager-BcMeZiGD.js +938 -0
  265. package/dist/qmd-manager-CPypGJ0P.js +935 -0
  266. package/dist/qmd-manager-CRrSkfia.js +937 -0
  267. package/dist/register.agent-DDY8KJhn.js +265 -0
  268. package/dist/register.agent-DKawm-9d.js +1003 -0
  269. package/dist/register.anima-CEWUo29k.js +193 -0
  270. package/dist/register.anima-DBWz2rk_.js +193 -0
  271. package/dist/register.configure-BX67qV8k.js +103 -0
  272. package/dist/register.configure-CWsySuiq.js +101 -0
  273. package/dist/register.maintenance-0k-ZNhDg.js +543 -0
  274. package/dist/register.maintenance-BIwx1fzX.js +543 -0
  275. package/dist/register.message-CXPsoakA.js +657 -0
  276. package/dist/register.message-DA3jvfgI.js +660 -0
  277. package/dist/register.onboard-C4HG7Hqv.js +170 -0
  278. package/dist/register.onboard-GOpdif-j.js +170 -0
  279. package/dist/register.setup-B17vZT7C.js +175 -0
  280. package/dist/register.setup-GJyUDCqh.js +175 -0
  281. package/dist/register.status-health-sessions-D5876dGx.js +313 -0
  282. package/dist/register.status-health-sessions-lOewVIZR.js +142 -0
  283. package/dist/register.subclis-Dwnujj5C.js +255 -0
  284. package/dist/reply-CR5T_oQJ.js +32212 -0
  285. package/dist/reply-prefix-BcrS4Umd.js +100 -0
  286. package/dist/reply-prefix-Btb5o2NH.js +100 -0
  287. package/dist/reply-r089HuRA.js +32212 -0
  288. package/dist/routes-B4czFzIb.js +1820 -0
  289. package/dist/routes-ucJWAk5O.js +1820 -0
  290. package/dist/rpc-BnKxnQ0v.js +70 -0
  291. package/dist/rpc-DgE-xnyx.js +70 -0
  292. package/dist/run-main-B74kv84C.js +371 -0
  293. package/dist/runtime-guard-CKFdts2L.js +60 -0
  294. package/dist/sandbox-CJTS3er6.js +858 -0
  295. package/dist/sandbox-DBSiVHt_.js +859 -0
  296. package/dist/sandbox-cli-CrkjyU5M.js +461 -0
  297. package/dist/sandbox-cli-D1r5y6Sz.js +458 -0
  298. package/dist/security-cli-BZUdnkhn.js +462 -0
  299. package/dist/security-cli-DS09ebvA.js +465 -0
  300. package/dist/server-context-C0xZbYhg.js +824 -0
  301. package/dist/server-context-DVh2z7om.js +824 -0
  302. package/dist/server-node-events-bu9lpkMH.js +233 -0
  303. package/dist/server-node-events-i1Rrww31.js +231 -0
  304. package/dist/service-CJJwLEor.js +642 -0
  305. package/dist/service-DxLxBhaU.js +642 -0
  306. package/dist/service-audit-DB4Y3Ekp.js +488 -0
  307. package/dist/service-audit-M8y4TXVb.js +488 -0
  308. package/dist/session-CGxOLFs2.js +179 -0
  309. package/dist/session-DTTbdKb0.js +181 -0
  310. package/dist/session-cost-usage-FcdJl9c3.js +600 -0
  311. package/dist/session-cost-usage-qdfsGU2a.js +600 -0
  312. package/dist/session-yOhWcsD2.js +181 -0
  313. package/dist/sessions-B-Cu7JZq.js +1296 -0
  314. package/dist/sessions-BgLN4KFr.js +180 -0
  315. package/dist/sessions-CnRjwdVr.js +1296 -0
  316. package/dist/sessions-wRKla1Qh.js +2038 -0
  317. package/dist/shared-DS3UaJSP.js +66 -0
  318. package/dist/shared-DxNHzky3.js +77 -0
  319. package/dist/shared-Qpt4hUDi.js +66 -0
  320. package/dist/shared-kzrojZ1B.js +77 -0
  321. package/dist/skill-scanner-DLJji5Ye.js +263 -0
  322. package/dist/skills-BWFIEp4j.js +807 -0
  323. package/dist/skills-DV4zKdCx.js +808 -0
  324. package/dist/skills-cli-BY53ILm2.js +289 -0
  325. package/dist/skills-cli-CO3gxl8A.js +286 -0
  326. package/dist/skills-status-DX5pcqY3.js +166 -0
  327. package/dist/skills-status-zhcKzGkp.js +166 -0
  328. package/dist/sqlite-B6MojU1I.js +321 -0
  329. package/dist/sqlite-CuprTGR7.js +453 -0
  330. package/dist/sqlite-dzD-jMjs.js +368 -0
  331. package/dist/start-Cu3aLoSf.js +297 -0
  332. package/dist/start-Dz7tMAl8.js +296 -0
  333. package/dist/status-CaSxhxfV.js +2132 -0
  334. package/dist/status-D2C0JCX3.js +2137 -0
  335. package/dist/status-DlFMsQzh.js +27 -0
  336. package/dist/status-G0CITnKR.js +27 -0
  337. package/dist/status.update-CHjhVxJY.js +79 -0
  338. package/dist/status.update-DVFelehi.js +79 -0
  339. package/dist/subagent-registry-3Xb4el-8.js +14 -0
  340. package/dist/subagent-registry-CdSjz14I.js +2760 -0
  341. package/dist/subagent-registry-DNDhbHWi.js +2759 -0
  342. package/dist/subsystem-DfKstnEK.js +860 -0
  343. package/dist/system-cli-B5mt0FWa.js +82 -0
  344. package/dist/system-cli-Dg3UQ3Zz.js +79 -0
  345. package/dist/systemd-B43AvOGx.js +452 -0
  346. package/dist/systemd-RpPE0XGg.js +452 -0
  347. package/dist/systemd-hints-DMJT-Bbc.js +36 -0
  348. package/dist/systemd-hints-vRInKcz9.js +36 -0
  349. package/dist/systemd-linger-Dzyxqsod.js +75 -0
  350. package/dist/systemd-linger-EujbmI5A.js +75 -0
  351. package/dist/table-DhXHfRX2.js +279 -0
  352. package/dist/table-bWCLW-3P.js +279 -0
  353. package/dist/timeout-Ddn-5kAO.js +232 -0
  354. package/dist/tokens-3psI_Qk2.js +14 -0
  355. package/dist/tokens-BaM53PEx.js +14 -0
  356. package/dist/trash-Bmxs1Rnm.js +23 -0
  357. package/dist/trash-C39a6hKA.js +23 -0
  358. package/dist/tui-BHgBWhHE.js +3894 -0
  359. package/dist/tui-cli-B9Sq5-cC.js +50 -0
  360. package/dist/tui-cli-Dw7v4JoJ.js +47 -0
  361. package/dist/tui-mUwDwqvd.js +3894 -0
  362. package/dist/update-DF0GHG0j.js +317 -0
  363. package/dist/update-DoZLVjva.js +317 -0
  364. package/dist/update-check-Bt1dVPVN.js +400 -0
  365. package/dist/update-check-D5qAKes7.js +400 -0
  366. package/dist/update-cli-BNu2Oi7H.js +1105 -0
  367. package/dist/update-cli-D36AmALA.js +1105 -0
  368. package/dist/update-runner-CNQQaTwA.js +894 -0
  369. package/dist/update-runner-CvxZmbu-.js +894 -0
  370. package/dist/usage-BGCwNnjk.js +4516 -0
  371. package/dist/utils-DZ8pnOD5.js +243 -0
  372. package/dist/web-B5QG839O.js +46842 -0
  373. package/dist/web-Cmnvk9v0.js +2203 -0
  374. package/dist/web-Cv2KnTnL.js +63 -0
  375. package/dist/webhooks-cli-B6y89Pj_.js +319 -0
  376. package/dist/webhooks-cli-BDzHON4w.js +316 -0
  377. package/dist/whatsapp-actions-C_5MwVxM.js +45 -0
  378. package/dist/whatsapp-actions-hgYA12To.js +53 -0
  379. package/dist/whatsapp-actions-zTiVOoOV.js +49 -0
  380. package/dist/widearea-dns-BeIdnISJ.js +127 -0
  381. package/dist/widearea-dns-CF1gxpJ-.js +127 -0
  382. package/dist/workspace-DLna1IxR.js +649 -0
  383. package/dist/ws-log-Q4wO1Ztb.js +267 -0
  384. package/dist/ws-log-xF0kxDzp.js +267 -0
  385. package/package.json +1 -2
  386. package/dist/accounts-Cc5E4IDO.js +0 -260
  387. package/dist/accounts-CcVrwKqv.js +0 -259
  388. package/dist/acp-cli-DvphOKuh.js +0 -1081
  389. package/dist/acp-cli-p28pQ65a.js +0 -1084
  390. package/dist/agent-Cj7uDJaZ.js +0 -725
  391. package/dist/agent-Cuj9-2sT.js +0 -725
  392. package/dist/agent-events-BEBQsyE5.js +0 -182
  393. package/dist/agent-scope-BVf4aSwY.js +0 -112
  394. package/dist/agent-scope-OZi7lb8S.js +0 -452
  395. package/dist/agent-scope-V1bi9OYL.js +0 -452
  396. package/dist/agents-BUWqn_Ui.js +0 -774
  397. package/dist/agents.config-Dvo2ULxs.js +0 -182
  398. package/dist/agents.config-d6H0_3oj.js +0 -182
  399. package/dist/argv-DqUHKf0o.js +0 -73
  400. package/dist/audit-C6okOOSh.js +0 -2401
  401. package/dist/audit-VWjIdwC7.js +0 -2401
  402. package/dist/auth-91o2YM96.js +0 -648
  403. package/dist/auth-choice-CAmACV13.js +0 -2681
  404. package/dist/auth-choice-p3SeHPj2.js +0 -2681
  405. package/dist/auth-health-B_jXrWe6.js +0 -149
  406. package/dist/auth-health-DCicUKYR.js +0 -149
  407. package/dist/auth-lZ26wsbN.js +0 -639
  408. package/dist/auth-profiles-CCDD56dU.js +0 -1564
  409. package/dist/auth-profiles-DxI8L7bs.js +0 -2689
  410. package/dist/banner-Cohn04J6.js +0 -294
  411. package/dist/browser-cli-DANzjztE.js +0 -1676
  412. package/dist/browser-cli-WjsVH741.js +0 -1679
  413. package/dist/call-BAHvlu2G.js +0 -282
  414. package/dist/call-Ct7EGP_L.js +0 -282
  415. package/dist/catalog-BAayBt1L.js +0 -185
  416. package/dist/catalog-BNsf97BM.js +0 -185
  417. package/dist/channel-options-Dx9nPlX8.js +0 -33
  418. package/dist/channel-options-ZdvXrTGs.js +0 -32
  419. package/dist/channel-selection-CujyiWGM.js +0 -51
  420. package/dist/channel-selection-DfGpCyh2.js +0 -51
  421. package/dist/channel-web-CC0hkgkR.js +0 -2162
  422. package/dist/channels-cli-D7lNBpIb.js +0 -1304
  423. package/dist/channels-cli-DUPG8WDv.js +0 -1306
  424. package/dist/channels-status-issues-DBc1pU_R.js +0 -18
  425. package/dist/channels-status-issues-DjO9MHIG.js +0 -18
  426. package/dist/chrome-Bi6iZ5sG.js +0 -1601
  427. package/dist/chrome-DNSv7Cpy.js +0 -1629
  428. package/dist/chrome-DScZx4Lk.js +0 -1601
  429. package/dist/chunk-mxPVo000.js +0 -348
  430. package/dist/clack-prompter-B0kl7shw.js +0 -92
  431. package/dist/clack-prompter-B1YxZdRy.js +0 -92
  432. package/dist/cli-CfHUkOD0.js +0 -101
  433. package/dist/cli-ClMrIh6l.js +0 -99
  434. package/dist/cli-session-BkPTd9Pk.js +0 -5463
  435. package/dist/cli-session-Dd8DKb5a.js +0 -5408
  436. package/dist/client-C1avc0vD.js +0 -1692
  437. package/dist/client-CC94YZrT.js +0 -1692
  438. package/dist/clipboard-B2fBy8tG.js +0 -31
  439. package/dist/clipboard-BbGnZskJ.js +0 -31
  440. package/dist/command-format-Clp46jkj.js +0 -38
  441. package/dist/command-format-DELazozB.js +0 -52
  442. package/dist/command-format-SkzzRqR1.js +0 -52
  443. package/dist/command-registry-DZ4hkmA0.js +0 -248
  444. package/dist/commands-DtYZJSPn.js +0 -568
  445. package/dist/commands-Dujk1JmY.js +0 -568
  446. package/dist/commands-registry-Bd0xbvwG.js +0 -766
  447. package/dist/commands-registry-DYfRSVF3.js +0 -766
  448. package/dist/common-D6bu0zHC.js +0 -287
  449. package/dist/common-zW9Y2P1B.js +0 -287
  450. package/dist/completion-cli-tSe7Pmqm.js +0 -431
  451. package/dist/completion-cli-vn4IScs5.js +0 -432
  452. package/dist/config-C8rUDJXY.js +0 -5704
  453. package/dist/config-CLZ_XGVw.js +0 -6523
  454. package/dist/config-SY8M0kM_.js +0 -5705
  455. package/dist/config-cli-1V7D2Wsw.js +0 -247
  456. package/dist/config-cli-CjWEC81L.js +0 -244
  457. package/dist/config-guard-BW2gpKj_.js +0 -93
  458. package/dist/config-guard-BvxuzHpo.js +0 -76
  459. package/dist/config-sync-CoIIbEOe.js +0 -91
  460. package/dist/config-sync-DvAttep0.js +0 -91
  461. package/dist/configure-Bf0oupCE.js +0 -959
  462. package/dist/configure-DRM-7zFf.js +0 -960
  463. package/dist/context-D5iEFzv9.js +0 -60
  464. package/dist/control-service-C8m8F9pr.js +0 -72
  465. package/dist/control-service-DKotCWCg.js +0 -72
  466. package/dist/cron-cli-DB_FLYHD.js +0 -448
  467. package/dist/cron-cli-bxm5lrrO.js +0 -451
  468. package/dist/daemon-cli-1LsOnICv.js +0 -566
  469. package/dist/daemon-cli-CC2NrJ7a.js +0 -565
  470. package/dist/daemon-runtime-BXZhtBL9.js +0 -460
  471. package/dist/daemon-runtime-DW4USC7r.js +0 -460
  472. package/dist/deliver-B4HuPwJA.js +0 -1162
  473. package/dist/deliver-LiY5oL52.js +0 -1097
  474. package/dist/deliver-xrmk7xjh.js +0 -1097
  475. package/dist/delivery-queue-TnQykYsg.js +0 -220
  476. package/dist/deps-CMMOiOsF.js +0 -42
  477. package/dist/devices-cli-Be5he2SA.js +0 -195
  478. package/dist/devices-cli-z6ecoFe9.js +0 -198
  479. package/dist/diagnostics-Dj75aEHN.js +0 -35
  480. package/dist/diagnostics-DlIw6fqD.js +0 -35
  481. package/dist/directory-cli-CEy-0nxj.js +0 -243
  482. package/dist/directory-cli-DpzKcigr.js +0 -246
  483. package/dist/dispatcher-10Shiuz3.js +0 -100
  484. package/dist/dispatcher-3Jae6AiW.js +0 -100
  485. package/dist/dns-cli-Bat1pkc-.js +0 -200
  486. package/dist/dns-cli-NohNyEo0.js +0 -197
  487. package/dist/dock-DbxBBv30.js +0 -753
  488. package/dist/dock-cPBY4qGl.js +0 -753
  489. package/dist/docs-cli-BWp6p-Tq.js +0 -161
  490. package/dist/docs-cli-x22FnZfL.js +0 -159
  491. package/dist/doctor-BrT5m_on.js +0 -1815
  492. package/dist/doctor-Pp2HVnjM.js +0 -1813
  493. package/dist/doctor-completion-DNTimX9o.js +0 -92
  494. package/dist/doctor-completion-ylN9QAJ6.js +0 -92
  495. package/dist/doctor-config-flow-D1w3700T.js +0 -1232
  496. package/dist/doctor-config-flow-Dq50iE1R.js +0 -1232
  497. package/dist/engine-B9avUJL5.js +0 -563
  498. package/dist/engine-BiUQ25D4.js +0 -563
  499. package/dist/env-0lJfCPsw.js +0 -32
  500. package/dist/exec-BenD3A5l.js +0 -1167
  501. package/dist/exec-Bv3pyjeM.js +0 -255
  502. package/dist/exec-approvals-CdLmKX2R.js +0 -1221
  503. package/dist/exec-approvals-cli-DXfV6G8H.js +0 -368
  504. package/dist/exec-approvals-cli-J2cZs10o.js +0 -371
  505. package/dist/frontmatter-YijVi0FQ.js +0 -204
  506. package/dist/gateway-cli-DOAbA0pc.js +0 -19972
  507. package/dist/gateway-cli-QpWtBhQy.js +0 -19971
  508. package/dist/gateway-rpc-DJKBil9s.js +0 -28
  509. package/dist/gateway-rpc-DVterpLP.js +0 -28
  510. package/dist/github-copilot-auth-4IUFp669.js +0 -1418
  511. package/dist/github-copilot-auth-C9E0IROs.js +0 -1418
  512. package/dist/gmail-setup-utils-BPo_LkKI.js +0 -428
  513. package/dist/gmail-setup-utils-D3Yqgor7.js +0 -428
  514. package/dist/health-BeZnqp6m.js +0 -1258
  515. package/dist/health-Cn2OoVWZ.js +0 -1253
  516. package/dist/health-format-CdP99j3Y.js +0 -208
  517. package/dist/health-format-JEChH08S.js +0 -208
  518. package/dist/heartbeat-visibility-BL3WAchI.js +0 -98
  519. package/dist/heartbeat-visibility-CQ9QimI7.js +0 -98
  520. package/dist/help-format-Dl4bsrLI.js +0 -17
  521. package/dist/helpers-ZKNRexvX.js +0 -10
  522. package/dist/hooks-cli-D99hXt7K.js +0 -991
  523. package/dist/hooks-cli-DMB8RiEO.js +0 -993
  524. package/dist/hooks-status-B-e96dZj.js +0 -356
  525. package/dist/hooks-status-C_9sE0ox.js +0 -356
  526. package/dist/image-ops-Dlt3T7th.js +0 -541
  527. package/dist/image-ops-omlvdfah.js +0 -541
  528. package/dist/init-Bm04RagW.js +0 -122
  529. package/dist/init-CaJBf4p1.js +0 -122
  530. package/dist/installs-C2iMRBVz.js +0 -383
  531. package/dist/installs-D-cPGdCw.js +0 -383
  532. package/dist/ipv4-Bf7NS3QU.js +0 -1964
  533. package/dist/ipv4-wWNs8IH_.js +0 -1964
  534. package/dist/lanes-CNxj3tit.js +0 -232
  535. package/dist/lifecycle-core-B_7XRcvF.js +0 -388
  536. package/dist/lifecycle-core-By83PVAK.js +0 -387
  537. package/dist/links-BfjHVTB_.js +0 -15
  538. package/dist/links-DPGe0OHw.js +0 -15
  539. package/dist/logging-DB6BQmhi.js +0 -15
  540. package/dist/logging-mcb66J0p.js +0 -15
  541. package/dist/login-BDCg6D0N.js +0 -61
  542. package/dist/login-BDfnbjnZ.js +0 -59
  543. package/dist/login-BqH1itcg.js +0 -61
  544. package/dist/login-qr-CyOw3R4r.js +0 -321
  545. package/dist/login-qr-D8ECtb72.js +0 -323
  546. package/dist/login-qr-RnR7e4Bw.js +0 -326
  547. package/dist/logs-cli--j89L74J.js +0 -245
  548. package/dist/logs-cli-DpEMg_Gq.js +0 -242
  549. package/dist/manager-B4OyvcxT.js +0 -3244
  550. package/dist/manager-Cqc1CeH7.js +0 -3246
  551. package/dist/manager-DUyQPFvj.js +0 -3244
  552. package/dist/manifest-registry-CW1zCyRF.js +0 -748
  553. package/dist/manifest-registry-D4lM2RdV.js +0 -748
  554. package/dist/markdown-tables-BT1X6jqH.js +0 -347
  555. package/dist/markdown-tables-DHgOK2vI.js +0 -348
  556. package/dist/media-THyainiE.js +0 -1342
  557. package/dist/memory-cli-BKocCWXM.js +0 -868
  558. package/dist/memory-cli-Jmma-xI_.js +0 -869
  559. package/dist/message-channel-dSTVVCyX.js +0 -110
  560. package/dist/migrate-BR6iAIjO.js +0 -157
  561. package/dist/migrate-D0EcMs0f.js +0 -157
  562. package/dist/model-selection-YcSr9CgC.js +0 -2691
  563. package/dist/models-1vUQBVfw.js +0 -2510
  564. package/dist/models-cli-BK3BwUhL.js +0 -2739
  565. package/dist/models-cli-DECrM8oA.js +0 -258
  566. package/dist/net-B5lXhYLV.js +0 -218
  567. package/dist/node-cli-cLHUNpPD.js +0 -1319
  568. package/dist/node-cli-fO7Y132S.js +0 -1322
  569. package/dist/node-service-BFxHJsno.js +0 -67
  570. package/dist/node-service-DUnan4uK.js +0 -67
  571. package/dist/nodes-cli-BCq35E6N.js +0 -1200
  572. package/dist/nodes-cli-vD7MwAKP.js +0 -1197
  573. package/dist/nodes-screen-1YiLkqr5.js +0 -234
  574. package/dist/nodes-screen-DZeD8hE5.js +0 -234
  575. package/dist/note-Bi8Wb8DV.js +0 -73
  576. package/dist/note-uiuPxhyX.js +0 -73
  577. package/dist/npm-registry-spec-B-XIShkB.js +0 -351
  578. package/dist/npm-registry-spec-za3itb5Y.js +0 -351
  579. package/dist/onboard-Ds6w_sWo.js +0 -1165
  580. package/dist/onboard-SAVx3bp4.js +0 -1166
  581. package/dist/onboard-channels-Cg_EkBa4.js +0 -672
  582. package/dist/onboard-channels-D7NbA55V.js +0 -672
  583. package/dist/onboard-helpers-DO_hgZb9.js +0 -365
  584. package/dist/onboard-helpers-_XgJgeqh.js +0 -365
  585. package/dist/onboarding-3hLmDd0r.js +0 -911
  586. package/dist/onboarding-B4LKLsbU.js +0 -910
  587. package/dist/orchestrator-BKzmyBWy.js +0 -357
  588. package/dist/orchestrator-BN3QCz2s.js +0 -357
  589. package/dist/outbound-BgA9hNlP.js +0 -2062
  590. package/dist/outbound-CjdvVhUI.js +0 -214
  591. package/dist/outbound-DOGe6qb2.js +0 -214
  592. package/dist/outbound-send-deps-Du5aBpd7.js +0 -55
  593. package/dist/pairing-cli-2vnyg_Nd.js +0 -118
  594. package/dist/pairing-cli-BH1KQtNV.js +0 -121
  595. package/dist/pairing-store-DJz_9Gv0.js +0 -388
  596. package/dist/pairing-store-DmOzxcuk.js +0 -388
  597. package/dist/path-env-Bu6k0jDQ.js +0 -89
  598. package/dist/path-env-C0zQSjw8.js +0 -89
  599. package/dist/paths-BTc4nk-6.js +0 -126
  600. package/dist/paths-BgUi2Z2G.js +0 -54
  601. package/dist/paths-C6VCWKo3.js +0 -238
  602. package/dist/paths-CCxa0o9c.js +0 -222
  603. package/dist/paths-CxRf2rBG.js +0 -129
  604. package/dist/paths-hcX1Gqg5.js +0 -129
  605. package/dist/pi-auth-json-B68R7q7_.js +0 -82
  606. package/dist/pi-auth-json-CR0jXAgq.js +0 -78
  607. package/dist/pi-auth-json-ZYzi3nxs.js +0 -80
  608. package/dist/pi-model-discovery-Cxs4pvC2.js +0 -3
  609. package/dist/pi-tools.policy-D81U5xy0.js +0 -200
  610. package/dist/pi-tools.policy-DSHkkb5b.js +0 -200
  611. package/dist/plugin-auto-enable-CxF4bpDN.js +0 -282
  612. package/dist/plugin-auto-enable-jNaAeyEh.js +0 -282
  613. package/dist/plugin-registry-C7XWotZG.js +0 -32
  614. package/dist/plugin-registry-DcUCbGax.js +0 -32
  615. package/dist/plugins-B362e77G.js +0 -168
  616. package/dist/plugins-CmSUIUNi.js +0 -38
  617. package/dist/plugins-cli-BsCEnoQ7.js +0 -734
  618. package/dist/plugins-cli-QSIsMUG7.js +0 -736
  619. package/dist/polls-CItfB1H8.js +0 -1343
  620. package/dist/ports-BVLMN1Sr.js +0 -96
  621. package/dist/ports-CqLSlU6Z.js +0 -317
  622. package/dist/ports-D94CwCrv.js +0 -344
  623. package/dist/ports-D_NHthOz.js +0 -96
  624. package/dist/program-DkJHjI0R.js +0 -176
  625. package/dist/program-context-DnyGM2SC.js +0 -496
  626. package/dist/progress-Bek_GyWS.js +0 -133
  627. package/dist/prompt-style-lu0clOOE.js +0 -9
  628. package/dist/pw-ai-BLVMuSLv.js +0 -1867
  629. package/dist/pw-ai-DZJWEF_f.js +0 -1865
  630. package/dist/pw-ai-dzf-ptcn.js +0 -1868
  631. package/dist/qmd-manager-Cur_Ekn0.js +0 -937
  632. package/dist/qmd-manager-DNAUuwjK.js +0 -938
  633. package/dist/qmd-manager-DepEoASu.js +0 -935
  634. package/dist/register.agent-CSWvzOkR.js +0 -265
  635. package/dist/register.agent-UeH2NXmH.js +0 -1003
  636. package/dist/register.anima-DOdee0dh.js +0 -193
  637. package/dist/register.anima-HHDWsz6r.js +0 -193
  638. package/dist/register.configure-CSJFxdz9.js +0 -103
  639. package/dist/register.configure-D84Fvcz4.js +0 -101
  640. package/dist/register.maintenance-B3pvNbZb.js +0 -543
  641. package/dist/register.maintenance-BKVOwkw6.js +0 -543
  642. package/dist/register.message-BAO6CPl2.js +0 -657
  643. package/dist/register.message-OXoOKE_6.js +0 -660
  644. package/dist/register.onboard-BK_ixVmD.js +0 -170
  645. package/dist/register.onboard-cfCaPx6j.js +0 -170
  646. package/dist/register.setup-BGfDnzph.js +0 -175
  647. package/dist/register.setup-Y-Q74M-0.js +0 -175
  648. package/dist/register.status-health-sessions-CT14eitH.js +0 -142
  649. package/dist/register.status-health-sessions-TfZMzAUn.js +0 -313
  650. package/dist/register.subclis-BZwdlNHC.js +0 -255
  651. package/dist/reply-mlsExaZm.js +0 -32212
  652. package/dist/reply-prefix-B0CfR4bM.js +0 -100
  653. package/dist/reply-prefix-w4a39ybC.js +0 -100
  654. package/dist/reply-qalRISe_.js +0 -32212
  655. package/dist/routes-CENsHJyg.js +0 -1820
  656. package/dist/routes-DO0HqW2e.js +0 -1820
  657. package/dist/rpc-C0pjNhBi.js +0 -70
  658. package/dist/rpc-DZ44PIXE.js +0 -70
  659. package/dist/run-main-BMpKw8Mp.js +0 -371
  660. package/dist/runtime-guard-BSUFiAQV.js +0 -60
  661. package/dist/sandbox-BIGfMYEI.js +0 -858
  662. package/dist/sandbox-DxP3IpUP.js +0 -859
  663. package/dist/sandbox-cli-DtLGH8sL.js +0 -461
  664. package/dist/sandbox-cli-_Tg7lfJ_.js +0 -458
  665. package/dist/security-cli-BRwgbedo.js +0 -462
  666. package/dist/security-cli-D3bSuyZt.js +0 -465
  667. package/dist/server-context-49XFFxFg.js +0 -824
  668. package/dist/server-context-LrlgrZzS.js +0 -824
  669. package/dist/server-node-events-Dm52i7NW.js +0 -231
  670. package/dist/server-node-events-QX523UyF.js +0 -233
  671. package/dist/service-BNVpYcQe.js +0 -642
  672. package/dist/service-D56aMXUB.js +0 -642
  673. package/dist/service-audit-D0X_XAB2.js +0 -488
  674. package/dist/service-audit-qmf6XMmP.js +0 -488
  675. package/dist/session-CrQQLLhx.js +0 -179
  676. package/dist/session-LocsOOWJ.js +0 -181
  677. package/dist/session-Vlce2BAT.js +0 -181
  678. package/dist/session-cost-usage-BwiTZuKl.js +0 -600
  679. package/dist/session-cost-usage-DT9YNXTJ.js +0 -600
  680. package/dist/sessions-BfV53TbG.js +0 -1296
  681. package/dist/sessions-BimpX_km.js +0 -180
  682. package/dist/sessions-DcXpzig0.js +0 -1296
  683. package/dist/sessions-Wd18dukK.js +0 -2038
  684. package/dist/shared-Bsr69u_7.js +0 -77
  685. package/dist/shared-Cgly1vPb.js +0 -66
  686. package/dist/shared-JOo05hST.js +0 -66
  687. package/dist/shared-f7dvQsi7.js +0 -77
  688. package/dist/skill-scanner-CkaVLABv.js +0 -263
  689. package/dist/skills-B-G7UHOa.js +0 -808
  690. package/dist/skills-B5LQx4lT.js +0 -807
  691. package/dist/skills-cli-DUGe2ZWW.js +0 -286
  692. package/dist/skills-cli-DtOk0bvK.js +0 -289
  693. package/dist/skills-status-Clq9ZnYu.js +0 -166
  694. package/dist/skills-status-JQluhU-P.js +0 -166
  695. package/dist/sqlite-BukcjdJa.js +0 -321
  696. package/dist/sqlite-CGcOZZ0C.js +0 -368
  697. package/dist/sqlite-Ck6f9KWc.js +0 -453
  698. package/dist/start--xmSFepB.js +0 -372
  699. package/dist/start-BdlZbqrr.js +0 -371
  700. package/dist/status-BgoeFm6g.js +0 -2137
  701. package/dist/status-BjjDrUq7.js +0 -27
  702. package/dist/status-Ct0DgOZ-.js +0 -2132
  703. package/dist/status-RA_uNmK0.js +0 -27
  704. package/dist/status.update-BjOH3GlS.js +0 -79
  705. package/dist/status.update-DLU1qBf0.js +0 -79
  706. package/dist/subagent-registry-9RLdKxES.js +0 -2760
  707. package/dist/subagent-registry-Byuex3zp.js +0 -2759
  708. package/dist/subagent-registry-DOBunBYS.js +0 -14
  709. package/dist/subsystem-Dowf8fSU.js +0 -860
  710. package/dist/system-cli-C5oBpzni.js +0 -79
  711. package/dist/system-cli-DXNKD_Id.js +0 -82
  712. package/dist/systemd-BSrHDyeU.js +0 -452
  713. package/dist/systemd-By5xdSB4.js +0 -452
  714. package/dist/systemd-hints-BtjL_5Rh.js +0 -36
  715. package/dist/systemd-hints-sJmr6cjb.js +0 -36
  716. package/dist/systemd-linger-CTmV2Gci.js +0 -75
  717. package/dist/systemd-linger-CmyqQkeC.js +0 -75
  718. package/dist/table-BL0lJzsm.js +0 -279
  719. package/dist/table-DoiRPsn0.js +0 -279
  720. package/dist/timeout-CswI_K-U.js +0 -232
  721. package/dist/tokens-C-X7wDKj.js +0 -14
  722. package/dist/tokens-DkvqA72p.js +0 -14
  723. package/dist/trash-BJLK1vMn.js +0 -23
  724. package/dist/trash-_x5UZ94k.js +0 -23
  725. package/dist/tui-BHjxDFZC.js +0 -3894
  726. package/dist/tui-CgOocwN8.js +0 -3894
  727. package/dist/tui-cli-5ANH8dE5.js +0 -47
  728. package/dist/tui-cli-BQ4P-JW_.js +0 -50
  729. package/dist/update-LFgxHHPd.js +0 -317
  730. package/dist/update-TxptCqk7.js +0 -317
  731. package/dist/update-check-CWc7YXmc.js +0 -400
  732. package/dist/update-check-IhlWaui6.js +0 -400
  733. package/dist/update-cli-PtXU62w7.js +0 -1105
  734. package/dist/update-cli-Va0EtETG.js +0 -1105
  735. package/dist/update-runner-BLeKFkiB.js +0 -894
  736. package/dist/update-runner-Iuzpc-_y.js +0 -894
  737. package/dist/usage-ApGvBLVg.js +0 -4516
  738. package/dist/utils-Bsw__U-F.js +0 -243
  739. package/dist/web-B6_Ky60G.js +0 -63
  740. package/dist/web-EZLQEWXY.js +0 -46842
  741. package/dist/web-pec8YJUX.js +0 -2203
  742. package/dist/webhooks-cli-BYQKTHTp.js +0 -319
  743. package/dist/webhooks-cli-C2_xtsUQ.js +0 -316
  744. package/dist/whatsapp-actions-C72VCq8f.js +0 -49
  745. package/dist/whatsapp-actions-Ck9Uv0Nw.js +0 -45
  746. package/dist/whatsapp-actions-D0reTj2k.js +0 -53
  747. package/dist/widearea-dns-B6ocX23x.js +0 -127
  748. package/dist/widearea-dns-NsEUNYwz.js +0 -127
  749. package/dist/workspace-Dcfoy5JJ.js +0 -649
  750. package/dist/ws-log-N8R5MvGE.js +0 -267
  751. package/dist/ws-log-gwFxPxj5.js +0 -267
  752. /package/dist/{auto-update-CUeF99gI.js → auto-update-CpF0fycd.js} +0 -0
  753. /package/dist/{auto-update-cgkp9ZTJ.js → auto-update-DNWdO7uF.js} +0 -0
  754. /package/dist/{brew-CVZkr0GU.js → brew-nqf_MiE4.js} +0 -0
  755. /package/dist/{budget-DxYQSekw.js → budget-CPedI-qW.js} +0 -0
  756. /package/dist/{budget-BWBp8Res.js → budget-CRpvqDRX.js} +0 -0
  757. /package/dist/{cli-utils-DtAxdCte.js → cli-utils-C1YHVD4o.js} +0 -0
  758. /package/dist/{command-options-CSbuuqHr.js → command-options-BbponVnw.js} +0 -0
  759. /package/dist/{command-options-Cp1tf96a.js → command-options-s0gnvXnS.js} +0 -0
  760. /package/dist/{constants-O8yBqCBv.js → constants-Dhb6zSIV.js} +0 -0
  761. /package/dist/{dangerous-tools-5ObDWy1N.js → dangerous-tools-DGTtJ_JR.js} +0 -0
  762. /package/dist/{dangerous-tools-Jwr7jqNw.js → dangerous-tools-DxrfTOfT.js} +0 -0
  763. /package/dist/{delivery-queue-B6IHz4Ry.js → delivery-queue-Bxm0nzw7.js} +0 -0
  764. /package/dist/{display-BDOsXu8F.js → display-Jy3UdGzA.js} +0 -0
  765. /package/dist/{errors-CHow2wtt.js → errors-CKaCqKga.js} +0 -0
  766. /package/dist/{exec-BizYYQgP.js → exec-DDmuVVNq.js} +0 -0
  767. /package/dist/{format-Mq6iU0_5.js → format-ByEjgyTF.js} +0 -0
  768. /package/dist/{format-duration-DhWzz_5b.js → format-duration-Aaj5tjJd.js} +0 -0
  769. /package/dist/{format-relative-C6kUHuOj.js → format-relative-79_Y1n2Y.js} +0 -0
  770. /package/dist/{help-format-DUBI91Ti.js → help-format-BMKzarov.js} +0 -0
  771. /package/dist/{helpers-eJFa4K6r.js → helpers-DpEB9Mh0.js} +0 -0
  772. /package/dist/{helpers-DLgbkcEn.js → helpers-FMld9sBT.js} +0 -0
  773. /package/dist/{input-provenance-DJBdpeKk.js → input-provenance-Cy_KnBlP.js} +0 -0
  774. /package/dist/{is-main-Dt9DTcH1.js → is-main-yjaVwMtJ.js} +0 -0
  775. /package/dist/{loader-l2OBdJ8x.js → loader-Br7Vr0zn.js} +0 -0
  776. /package/dist/{loader-BoYxRfcW.js → loader-CkmOrXcC.js} +0 -0
  777. /package/dist/{logging-BdnOSVPD.js → logging-CY-Q5cwf.js} +0 -0
  778. /package/dist/{message-channel-w4F2b2F6.js → message-channel-dua8OOGJ.js} +0 -0
  779. /package/dist/{mime-B1ZoR53M.js → mime-CBg4KybI.js} +0 -0
  780. /package/dist/{model-param-b-DPwyNGn8.js → model-param-b-DW9f0NN8.js} +0 -0
  781. /package/dist/{node-match-8XZnaid6.js → node-match-BV8bTBd4.js} +0 -0
  782. /package/dist/{normalize-GDK8JTNW.js → normalize-_lmlBOW9.js} +0 -0
  783. /package/dist/{openclaw-root-C85WMnVV.js → openclaw-root-JPvmPTf7.js} +0 -0
  784. /package/dist/{outbound-send-deps-ANnAhImn.js → outbound-send-deps-BfUvuWGa.js} +0 -0
  785. /package/dist/{parse-6-2MDhdT.js → parse-CZRwKocn.js} +0 -0
  786. /package/dist/{parse-log-line-Bqh1SSzC.js → parse-log-line-CvrZEK6A.js} +0 -0
  787. /package/dist/{parse-log-line-DUZCjXbl.js → parse-log-line-mLdat0AH.js} +0 -0
  788. /package/dist/{parse-port-BKB9Exlg.js → parse-port-BSOOdo7I.js} +0 -0
  789. /package/dist/{parse-port-DrfvwwiL.js → parse-port-Y0NK62x1.js} +0 -0
  790. /package/dist/{parse-timeout-Di_tcEmi.js → parse-timeout-DVPQ3n9j.js} +0 -0
  791. /package/dist/{paths-DcVEkYX5.js → paths-DHjlJ6cn.js} +0 -0
  792. /package/dist/{pi-model-discovery-DsRqYJLy.js → pi-model-discovery-DzEIEgHL.js} +0 -0
  793. /package/dist/{plugins-CDJw924T.js → plugins-D6PBOdkn.js} +0 -0
  794. /package/dist/{program-context-Bvn8046-.js → program-context-Q1hkT73c.js} +0 -0
  795. /package/dist/{progress-CbZ2D53A.js → progress-C9Ha1NJh.js} +0 -0
  796. /package/dist/{prompt-style-DKy6qQxR.js → prompt-style-DQi8j03a.js} +0 -0
  797. /package/dist/{prompts-BI__va99.js → prompts-BEHxUC3w.js} +0 -0
  798. /package/dist/{prompts-_dDWkCAz.js → prompts-CSOhuiqe.js} +0 -0
  799. /package/dist/{queue-D_u34pbL.js → queue-BJGo7kAB.js} +0 -0
  800. /package/dist/{queue-PG591iID.js → queue-DYgUbdoq.js} +0 -0
  801. /package/dist/{redact-ClVwO7Nn.js → redact-CyKvdFrg.js} +0 -0
  802. /package/dist/{registry-Bs_DJK9E.js → registry-C5MAYD4V.js} +0 -0
  803. /package/dist/{registry-D_zlP1U-.js → registry-CRrXXVs0.js} +0 -0
  804. /package/dist/{requirements-BzZxj2Wu.js → requirements-CGkxTCu4.js} +0 -0
  805. /package/dist/{requirements-DIW1svgA.js → requirements-CIDaOcbO.js} +0 -0
  806. /package/dist/{runtime-guard-DeOXA_86.js → runtime-guard-nL3Lp8T-.js} +0 -0
  807. /package/dist/{secret-equal-Dghy3xsA.js → secret-equal-DJpmLXlG.js} +0 -0
  808. /package/dist/{send-BhAfdGII.js → send-CTcxgDDU.js} +0 -0
  809. /package/dist/{send-ga9udK1_.js → send-DPezUR3-.js} +0 -0
  810. /package/dist/{send-C2t9xpXI.js → send-DZQTaG7-.js} +0 -0
  811. /package/dist/{send-DigO-i9j.js → send-VDff2gra.js} +0 -0
  812. /package/dist/{send-Dz2BDHll.js → send-bgQNV8d1.js} +0 -0
  813. /package/dist/{session-key-BGiG_JcT.js → session-key-CQT-NR6w.js} +0 -0
  814. /package/dist/{shell-argv-CAq1mLa2.js → shell-argv-n9IueeJQ.js} +0 -0
  815. /package/dist/{skill-scanner-Coo4QoCd.js → skill-scanner-o6NgVMD9.js} +0 -0
  816. /package/dist/{status-CMnlcBVc.js → status-C53kTIXF.js} +0 -0
  817. /package/dist/{status-tDZPwewW.js → status-CZDDA_Sy.js} +0 -0
  818. /package/dist/{system-run-command-X9lDJIy0.js → system-run-command-BCjUffN9.js} +0 -0
  819. /package/dist/{system-run-command-DGk7dwQP.js → system-run-command-CqAqKL9K.js} +0 -0
  820. /package/dist/{tailnet-CuiNECdL.js → tailnet-Ciwjv243.js} +0 -0
  821. /package/dist/{templates-CeYJjVzw.js → templates-37RKpACb.js} +0 -0
  822. /package/dist/{templates-I3Z0xplD.js → templates-DPalk30o.js} +0 -0
  823. /package/dist/{thinking-BXEswx1X.js → thinking-2hxwmvTl.js} +0 -0
  824. /package/dist/{transcript-events-C1hdue6u.js → transcript-events-Bp7fGnwv.js} +0 -0
  825. /package/dist/{transcript-tools-DuyYOkUq.js → transcript-tools-D4Lbxlka.js} +0 -0
  826. /package/dist/{usage-format-BAirWUSO.js → usage-format-6Uar63S0.js} +0 -0
  827. /package/dist/{utils-C9sj30YY.js → utils-DT8uXjFS.js} +0 -0
  828. /package/dist/{wsl-CqyuRvtM.js → wsl-CrPvx2kZ.js} +0 -0
  829. /package/dist/{wsl-ymJYvc9Q.js → wsl-UvJ5dHah.js} +0 -0
@@ -1,2203 +0,0 @@
1
- import { D as shouldLogVerbose, N as getChildLogger, h as defaultRuntime, o as createSubsystemLogger, w as logVerbose } from "./entry.js";
2
- import "./auth-profiles-DxI8L7bs.js";
3
- import { t as formatCliCommand } from "./command-format-Clp46jkj.js";
4
- import { i as buildAgentMainSessionKey, l as normalizeAgentId, o as buildGroupHistoryKey, r as DEFAULT_MAIN_KEY } from "./session-key-BGiG_JcT.js";
5
- import { C as sleep, T as toWhatsappJid, f as isSelfChatMode, m as normalizeE164, n as clamp, p as jidToE164, v as resolveJidToE164 } from "./utils-C9sj30YY.js";
6
- import "./exec-BizYYQgP.js";
7
- import "./agent-scope-OZi7lb8S.js";
8
- import "./pi-model-discovery-DsRqYJLy.js";
9
- import "./skills-B5LQx4lT.js";
10
- import "./manifest-registry-D4lM2RdV.js";
11
- import { i as loadConfig } from "./config-C8rUDJXY.js";
12
- import "./client-C1avc0vD.js";
13
- import "./call-BAHvlu2G.js";
14
- import "./message-channel-w4F2b2F6.js";
15
- import "./timeout-CswI_K-U.js";
16
- import { a as readSessionUpdatedAt, c as updateLastRoute, i as loadSessionStore, k as resolveGroupSessionKey, o as recordSessionMetaFromInbound } from "./sessions-DcXpzig0.js";
17
- import { B as resolveIdentityNamePrefix, V as resolveMessagePrefix } from "./subagent-registry-Byuex3zp.js";
18
- import "./logging-BdnOSVPD.js";
19
- import { a as logWebSelfId, c as pickWebChannel, i as getWebAuthAgeMs, l as readWebSelfId, n as resolveWhatsAppAccount, p as webAuthExists, r as WA_WEB_AUTH_DIR } from "./accounts-CcVrwKqv.js";
20
- import { $ as buildAgentSessionKey, At as registerUnhandledRejectionHandler, Dt as buildMentionRegexes, Gt as finalizeInboundContext, Ot as normalizeMentionText, _t as hasControlCommand, at as recordChannelActivity, ct as dispatchReplyWithBufferedBlockDispatcher, et as resolveAgentRoute, f as normalizeGroupActivation, ft as createDedupeCache, gt as resolveEnvelopeFormatOptions, ht as formatInboundEnvelope, mt as resolveInboundDebounceMs, p as parseActivationCommand, pt as createInboundDebouncer, rt as buildPairingReply, st as shouldAckReactionForWhatsApp, t as getReplyFromConfig, vt as shouldComputeCommandAuthorized } from "./reply-mlsExaZm.js";
21
- import "./plugins-CDJw924T.js";
22
- import "./tokens-C-X7wDKj.js";
23
- import { o as resolveChannelGroupPolicy, s as resolveChannelGroupRequireMention } from "./dock-DbxBBv30.js";
24
- import { c as resolveStorePath } from "./paths-CxRf2rBG.js";
25
- import { c as resolveTextChunkLimit, i as chunkMarkdownTextWithMode, s as resolveChunkMode, u as resolveMarkdownTableMode } from "./chunk-mxPVo000.js";
26
- import { d as setActiveWebListener, n as loadWebMedia, p as convertMarkdownTables } from "./media-THyainiE.js";
27
- import { i as markdownToWhatsApp, n as sendMessageWhatsApp, r as sendReactionWhatsApp } from "./outbound-DOGe6qb2.js";
28
- import "./mime-B1ZoR53M.js";
29
- import "./image-ops-Dlt3T7th.js";
30
- import "./common-D6bu0zHC.js";
31
- import "./server-context-49XFFxFg.js";
32
- import "./chrome-Bi6iZ5sG.js";
33
- import "./auth-lZ26wsbN.js";
34
- import "./ports-CqLSlU6Z.js";
35
- import "./trash-BJLK1vMn.js";
36
- import "./control-service-DKotCWCg.js";
37
- import { Wt as enqueueSystemEvent } from "./cli-session-Dd8DKb5a.js";
38
- import "./thinking-BXEswx1X.js";
39
- import "./context-D5iEFzv9.js";
40
- import "./sandbox-BIGfMYEI.js";
41
- import { r as saveMediaBuffer } from "./routes-DO0HqW2e.js";
42
- import "./paths-DcVEkYX5.js";
43
- import "./commands-registry-Bd0xbvwG.js";
44
- import "./deliver-LiY5oL52.js";
45
- import { i as readChannelAllowFromStore, o as upsertChannelPairingRequest } from "./pairing-store-DmOzxcuk.js";
46
- import "./nodes-screen-DZeD8hE5.js";
47
- import { r as formatDurationPrecise } from "./format-duration-DhWzz_5b.js";
48
- import "./memory-cli-BKocCWXM.js";
49
- import "./manager-B4OyvcxT.js";
50
- import "./sqlite-BukcjdJa.js";
51
- import "./redact-ClVwO7Nn.js";
52
- import "./links-BfjHVTB_.js";
53
- import "./progress-CbZ2D53A.js";
54
- import "./dispatcher-10Shiuz3.js";
55
- import "./channel-selection-DfGpCyh2.js";
56
- import "./delivery-queue-B6IHz4Ry.js";
57
- import "./pi-tools.policy-DSHkkb5b.js";
58
- import "./session-cost-usage-BwiTZuKl.js";
59
- import { i as waitForWaConnection, n as formatError, r as getStatusCode, t as createWaSocket } from "./session-LocsOOWJ.js";
60
- import { i as recordPendingHistoryEntryIfEnabled, n as DEFAULT_GROUP_HISTORY_LIMIT, r as buildHistoryContextFromEntries, t as createReplyPrefixOptions } from "./reply-prefix-w4a39ybC.js";
61
- import { t as loginWeb } from "./login-BqH1itcg.js";
62
- import { randomUUID } from "node:crypto";
63
- import { setTimeout } from "node:timers/promises";
64
- import { DisconnectReason, downloadMediaMessage, extractMessageContent, getContentType, isJidGroup, normalizeMessageContent } from "@whiskeysockets/baileys";
65
-
66
- //#region src/web/auto-reply/constants.ts
67
- const DEFAULT_WEB_MEDIA_BYTES = 5 * 1024 * 1024;
68
-
69
- //#endregion
70
- //#region src/infra/backoff.ts
71
- function computeBackoff(policy, attempt) {
72
- const base = policy.initialMs * policy.factor ** Math.max(attempt - 1, 0);
73
- const jitter = base * policy.jitter * Math.random();
74
- return Math.min(policy.maxMs, Math.round(base + jitter));
75
- }
76
- async function sleepWithAbort(ms, abortSignal) {
77
- if (ms <= 0) return;
78
- try {
79
- await setTimeout(ms, void 0, { signal: abortSignal });
80
- } catch (err) {
81
- if (abortSignal?.aborted) throw new Error("aborted", { cause: err });
82
- throw err;
83
- }
84
- }
85
-
86
- //#endregion
87
- //#region src/web/reconnect.ts
88
- const DEFAULT_HEARTBEAT_SECONDS = 60;
89
- const DEFAULT_RECONNECT_POLICY = {
90
- initialMs: 2e3,
91
- maxMs: 3e4,
92
- factor: 1.8,
93
- jitter: .25,
94
- maxAttempts: 12
95
- };
96
- function resolveHeartbeatSeconds(cfg, overrideSeconds) {
97
- const candidate = overrideSeconds ?? cfg.web?.heartbeatSeconds;
98
- if (typeof candidate === "number" && candidate > 0) return candidate;
99
- return DEFAULT_HEARTBEAT_SECONDS;
100
- }
101
- function resolveReconnectPolicy(cfg, overrides) {
102
- const reconnectOverrides = cfg.web?.reconnect ?? {};
103
- const overrideConfig = overrides ?? {};
104
- const merged = {
105
- ...DEFAULT_RECONNECT_POLICY,
106
- ...reconnectOverrides,
107
- ...overrideConfig
108
- };
109
- merged.initialMs = Math.max(250, merged.initialMs);
110
- merged.maxMs = Math.max(merged.initialMs, merged.maxMs);
111
- merged.factor = clamp(merged.factor, 1.1, 10);
112
- merged.jitter = clamp(merged.jitter, 0, 1);
113
- merged.maxAttempts = Math.max(0, Math.floor(merged.maxAttempts));
114
- return merged;
115
- }
116
- function newConnectionId() {
117
- return randomUUID();
118
- }
119
-
120
- //#endregion
121
- //#region src/web/auto-reply/loggers.ts
122
- const whatsappLog = createSubsystemLogger("gateway/channels/whatsapp");
123
- const whatsappInboundLog = whatsappLog.child("inbound");
124
- const whatsappOutboundLog = whatsappLog.child("outbound");
125
- const whatsappHeartbeatLog = whatsappLog.child("heartbeat");
126
-
127
- //#endregion
128
- //#region src/web/auto-reply/util.ts
129
- function elide(text, limit = 400) {
130
- if (!text) return text;
131
- if (text.length <= limit) return text;
132
- return `${text.slice(0, limit)}… (truncated ${text.length - limit} chars)`;
133
- }
134
- function isLikelyWhatsAppCryptoError(reason) {
135
- const formatReason = (value) => {
136
- if (value == null) return "";
137
- if (typeof value === "string") return value;
138
- if (value instanceof Error) return `${value.message}\n${value.stack ?? ""}`;
139
- if (typeof value === "object") try {
140
- return JSON.stringify(value);
141
- } catch {
142
- return Object.prototype.toString.call(value);
143
- }
144
- if (typeof value === "number") return String(value);
145
- if (typeof value === "boolean") return String(value);
146
- if (typeof value === "bigint") return String(value);
147
- if (typeof value === "symbol") return value.description ?? value.toString();
148
- if (typeof value === "function") return value.name ? `[function ${value.name}]` : "[function]";
149
- return Object.prototype.toString.call(value);
150
- };
151
- const haystack = (reason instanceof Error ? `${reason.message}\n${reason.stack ?? ""}` : formatReason(reason)).toLowerCase();
152
- if (!(haystack.includes("unsupported state or unable to authenticate data") || haystack.includes("bad mac"))) return false;
153
- return haystack.includes("@whiskeysockets/baileys") || haystack.includes("baileys") || haystack.includes("noise-handler") || haystack.includes("aesdecryptgcm");
154
- }
155
-
156
- //#endregion
157
- //#region src/cli/wait.ts
158
- function waitForever() {
159
- setInterval(() => {}, 1e6).unref();
160
- return new Promise(() => {});
161
- }
162
-
163
- //#endregion
164
- //#region src/web/inbound/dedupe.ts
165
- const recentInboundMessages = createDedupeCache({
166
- ttlMs: 20 * 6e4,
167
- maxSize: 5e3
168
- });
169
- function isRecentInboundMessage(key) {
170
- return recentInboundMessages.check(key);
171
- }
172
-
173
- //#endregion
174
- //#region src/channels/location.ts
175
- function resolveLocation(location) {
176
- const source = location.source ?? (location.isLive ? "live" : location.name || location.address ? "place" : "pin");
177
- const isLive = Boolean(location.isLive ?? source === "live");
178
- return {
179
- ...location,
180
- source,
181
- isLive
182
- };
183
- }
184
- function formatAccuracy(accuracy) {
185
- if (!Number.isFinite(accuracy)) return "";
186
- return ` ±${Math.round(accuracy ?? 0)}m`;
187
- }
188
- function formatCoords(latitude, longitude) {
189
- return `${latitude.toFixed(6)}, ${longitude.toFixed(6)}`;
190
- }
191
- function formatLocationText(location) {
192
- const resolved = resolveLocation(location);
193
- const coords = formatCoords(resolved.latitude, resolved.longitude);
194
- const accuracy = formatAccuracy(resolved.accuracy);
195
- const caption = resolved.caption?.trim();
196
- let header = "";
197
- if (resolved.source === "live" || resolved.isLive) header = `🛰 Live location: ${coords}${accuracy}`;
198
- else if (resolved.name || resolved.address) header = `📍 ${[resolved.name, resolved.address].filter(Boolean).join(" — ")} (${coords}${accuracy})`;
199
- else header = `📍 ${coords}${accuracy}`;
200
- return caption ? `${header}\n${caption}` : header;
201
- }
202
- function toLocationContext(location) {
203
- const resolved = resolveLocation(location);
204
- return {
205
- LocationLat: resolved.latitude,
206
- LocationLon: resolved.longitude,
207
- LocationAccuracy: resolved.accuracy,
208
- LocationName: resolved.name,
209
- LocationAddress: resolved.address,
210
- LocationSource: resolved.source,
211
- LocationIsLive: resolved.isLive
212
- };
213
- }
214
-
215
- //#endregion
216
- //#region src/web/vcard.ts
217
- const ALLOWED_VCARD_KEYS = new Set([
218
- "FN",
219
- "N",
220
- "TEL"
221
- ]);
222
- function parseVcard(vcard) {
223
- if (!vcard) return { phones: [] };
224
- const lines = vcard.split(/\r?\n/);
225
- let nameFromN;
226
- let nameFromFn;
227
- const phones = [];
228
- for (const rawLine of lines) {
229
- const line = rawLine.trim();
230
- if (!line) continue;
231
- const colonIndex = line.indexOf(":");
232
- if (colonIndex === -1) continue;
233
- const key = line.slice(0, colonIndex).toUpperCase();
234
- const rawValue = line.slice(colonIndex + 1).trim();
235
- if (!rawValue) continue;
236
- const baseKey = normalizeVcardKey(key);
237
- if (!baseKey || !ALLOWED_VCARD_KEYS.has(baseKey)) continue;
238
- const value = cleanVcardValue(rawValue);
239
- if (!value) continue;
240
- if (baseKey === "FN" && !nameFromFn) {
241
- nameFromFn = normalizeVcardName(value);
242
- continue;
243
- }
244
- if (baseKey === "N" && !nameFromN) {
245
- nameFromN = normalizeVcardName(value);
246
- continue;
247
- }
248
- if (baseKey === "TEL") {
249
- const phone = normalizeVcardPhone(value);
250
- if (phone) phones.push(phone);
251
- }
252
- }
253
- return {
254
- name: nameFromFn ?? nameFromN,
255
- phones
256
- };
257
- }
258
- function normalizeVcardKey(key) {
259
- const [primary] = key.split(";");
260
- if (!primary) return;
261
- const segments = primary.split(".");
262
- return segments[segments.length - 1] || void 0;
263
- }
264
- function cleanVcardValue(value) {
265
- return value.replace(/\\n/gi, " ").replace(/\\,/g, ",").replace(/\\;/g, ";").trim();
266
- }
267
- function normalizeVcardName(value) {
268
- return value.replace(/;/g, " ").replace(/\s+/g, " ").trim();
269
- }
270
- function normalizeVcardPhone(value) {
271
- const trimmed = value.trim();
272
- if (!trimmed) return "";
273
- if (trimmed.toLowerCase().startsWith("tel:")) return trimmed.slice(4).trim();
274
- return trimmed;
275
- }
276
-
277
- //#endregion
278
- //#region src/web/inbound/extract.ts
279
- function unwrapMessage$1(message) {
280
- return normalizeMessageContent(message);
281
- }
282
- function extractContextInfo(message) {
283
- if (!message) return;
284
- const contentType = getContentType(message);
285
- const candidate = contentType ? message[contentType] : void 0;
286
- const contextInfo = candidate && typeof candidate === "object" && "contextInfo" in candidate ? candidate.contextInfo : void 0;
287
- if (contextInfo) return contextInfo;
288
- const fallback = message.extendedTextMessage?.contextInfo ?? message.imageMessage?.contextInfo ?? message.videoMessage?.contextInfo ?? message.documentMessage?.contextInfo ?? message.audioMessage?.contextInfo ?? message.stickerMessage?.contextInfo ?? message.buttonsResponseMessage?.contextInfo ?? message.listResponseMessage?.contextInfo ?? message.templateButtonReplyMessage?.contextInfo ?? message.interactiveResponseMessage?.contextInfo ?? message.buttonsMessage?.contextInfo ?? message.listMessage?.contextInfo;
289
- if (fallback) return fallback;
290
- for (const value of Object.values(message)) {
291
- if (!value || typeof value !== "object") continue;
292
- if (!("contextInfo" in value)) continue;
293
- const candidateContext = value.contextInfo;
294
- if (candidateContext) return candidateContext;
295
- }
296
- }
297
- function extractMentionedJids(rawMessage) {
298
- const message = unwrapMessage$1(rawMessage);
299
- if (!message) return;
300
- const flattened = [
301
- message.extendedTextMessage?.contextInfo?.mentionedJid,
302
- message.extendedTextMessage?.contextInfo?.quotedMessage?.extendedTextMessage?.contextInfo?.mentionedJid,
303
- message.imageMessage?.contextInfo?.mentionedJid,
304
- message.videoMessage?.contextInfo?.mentionedJid,
305
- message.documentMessage?.contextInfo?.mentionedJid,
306
- message.audioMessage?.contextInfo?.mentionedJid,
307
- message.stickerMessage?.contextInfo?.mentionedJid,
308
- message.buttonsResponseMessage?.contextInfo?.mentionedJid,
309
- message.listResponseMessage?.contextInfo?.mentionedJid
310
- ].flatMap((arr) => arr ?? []).filter(Boolean);
311
- if (flattened.length === 0) return;
312
- return Array.from(new Set(flattened));
313
- }
314
- function extractText(rawMessage) {
315
- const message = unwrapMessage$1(rawMessage);
316
- if (!message) return;
317
- const extracted = extractMessageContent(message);
318
- const candidates = [message, extracted && extracted !== message ? extracted : void 0];
319
- for (const candidate of candidates) {
320
- if (!candidate) continue;
321
- if (typeof candidate.conversation === "string" && candidate.conversation.trim()) return candidate.conversation.trim();
322
- const extended = candidate.extendedTextMessage?.text;
323
- if (extended?.trim()) return extended.trim();
324
- const caption = candidate.imageMessage?.caption ?? candidate.videoMessage?.caption ?? candidate.documentMessage?.caption;
325
- if (caption?.trim()) return caption.trim();
326
- }
327
- const contactPlaceholder = extractContactPlaceholder(message) ?? (extracted && extracted !== message ? extractContactPlaceholder(extracted) : void 0);
328
- if (contactPlaceholder) return contactPlaceholder;
329
- }
330
- function extractMediaPlaceholder(rawMessage) {
331
- const message = unwrapMessage$1(rawMessage);
332
- if (!message) return;
333
- if (message.imageMessage) return "<media:image>";
334
- if (message.videoMessage) return "<media:video>";
335
- if (message.audioMessage) return "<media:audio>";
336
- if (message.documentMessage) return "<media:document>";
337
- if (message.stickerMessage) return "<media:sticker>";
338
- }
339
- function extractContactPlaceholder(rawMessage) {
340
- const message = unwrapMessage$1(rawMessage);
341
- if (!message) return;
342
- const contact = message.contactMessage ?? void 0;
343
- if (contact) {
344
- const { name, phones } = describeContact({
345
- displayName: contact.displayName,
346
- vcard: contact.vcard
347
- });
348
- return formatContactPlaceholder(name, phones);
349
- }
350
- const contactsArray = message.contactsArrayMessage?.contacts ?? void 0;
351
- if (!contactsArray || contactsArray.length === 0) return;
352
- return formatContactsPlaceholder(contactsArray.map((entry) => describeContact({
353
- displayName: entry.displayName,
354
- vcard: entry.vcard
355
- })).map((entry) => formatContactLabel(entry.name, entry.phones)).filter((value) => Boolean(value)), contactsArray.length);
356
- }
357
- function describeContact(input) {
358
- const displayName = (input.displayName ?? "").trim();
359
- const parsed = parseVcard(input.vcard ?? void 0);
360
- return {
361
- name: displayName || parsed.name,
362
- phones: parsed.phones
363
- };
364
- }
365
- function formatContactPlaceholder(name, phones) {
366
- const label = formatContactLabel(name, phones);
367
- if (!label) return "<contact>";
368
- return `<contact: ${label}>`;
369
- }
370
- function formatContactsPlaceholder(labels, total) {
371
- const cleaned = labels.map((label) => label.trim()).filter(Boolean);
372
- if (cleaned.length === 0) return `<contacts: ${total} ${total === 1 ? "contact" : "contacts"}>`;
373
- const remaining = Math.max(total - cleaned.length, 0);
374
- const suffix = remaining > 0 ? ` +${remaining} more` : "";
375
- return `<contacts: ${cleaned.join(", ")}${suffix}>`;
376
- }
377
- function formatContactLabel(name, phones) {
378
- const parts = [name, formatPhoneList(phones)].filter((value) => Boolean(value));
379
- if (parts.length === 0) return;
380
- return parts.join(", ");
381
- }
382
- function formatPhoneList(phones) {
383
- const cleaned = phones?.map((phone) => phone.trim()).filter(Boolean) ?? [];
384
- if (cleaned.length === 0) return;
385
- const { shown, remaining } = summarizeList(cleaned, cleaned.length, 1);
386
- const [primary] = shown;
387
- if (!primary) return;
388
- if (remaining === 0) return primary;
389
- return `${primary} (+${remaining} more)`;
390
- }
391
- function summarizeList(values, total, maxShown) {
392
- const shown = values.slice(0, maxShown);
393
- return {
394
- shown,
395
- remaining: Math.max(total - shown.length, 0)
396
- };
397
- }
398
- function extractLocationData(rawMessage) {
399
- const message = unwrapMessage$1(rawMessage);
400
- if (!message) return null;
401
- const live = message.liveLocationMessage ?? void 0;
402
- if (live) {
403
- const latitudeRaw = live.degreesLatitude;
404
- const longitudeRaw = live.degreesLongitude;
405
- if (latitudeRaw != null && longitudeRaw != null) {
406
- const latitude = Number(latitudeRaw);
407
- const longitude = Number(longitudeRaw);
408
- if (Number.isFinite(latitude) && Number.isFinite(longitude)) return {
409
- latitude,
410
- longitude,
411
- accuracy: live.accuracyInMeters ?? void 0,
412
- caption: live.caption ?? void 0,
413
- source: "live",
414
- isLive: true
415
- };
416
- }
417
- }
418
- const location = message.locationMessage ?? void 0;
419
- if (location) {
420
- const latitudeRaw = location.degreesLatitude;
421
- const longitudeRaw = location.degreesLongitude;
422
- if (latitudeRaw != null && longitudeRaw != null) {
423
- const latitude = Number(latitudeRaw);
424
- const longitude = Number(longitudeRaw);
425
- if (Number.isFinite(latitude) && Number.isFinite(longitude)) {
426
- const isLive = Boolean(location.isLive);
427
- return {
428
- latitude,
429
- longitude,
430
- accuracy: location.accuracyInMeters ?? void 0,
431
- name: location.name ?? void 0,
432
- address: location.address ?? void 0,
433
- caption: location.comment ?? void 0,
434
- source: isLive ? "live" : location.name || location.address ? "place" : "pin",
435
- isLive
436
- };
437
- }
438
- }
439
- }
440
- return null;
441
- }
442
- function describeReplyContext(rawMessage) {
443
- const message = unwrapMessage$1(rawMessage);
444
- if (!message) return null;
445
- const contextInfo = extractContextInfo(message);
446
- const quoted = normalizeMessageContent(contextInfo?.quotedMessage);
447
- if (!quoted) return null;
448
- const location = extractLocationData(quoted);
449
- const locationText = location ? formatLocationText(location) : void 0;
450
- let body = [extractText(quoted), locationText].filter(Boolean).join("\n").trim();
451
- if (!body) body = extractMediaPlaceholder(quoted);
452
- if (!body) {
453
- const quotedType = quoted ? getContentType(quoted) : void 0;
454
- logVerbose(`Quoted message missing extractable body${quotedType ? ` (type ${quotedType})` : ""}`);
455
- return null;
456
- }
457
- const senderJid = contextInfo?.participant ?? void 0;
458
- const senderE164 = senderJid ? jidToE164(senderJid) ?? senderJid : void 0;
459
- const sender = senderE164 ?? "unknown sender";
460
- return {
461
- id: contextInfo?.stanzaId ? String(contextInfo.stanzaId) : void 0,
462
- body,
463
- sender,
464
- senderJid,
465
- senderE164
466
- };
467
- }
468
-
469
- //#endregion
470
- //#region src/web/inbound/access-control.ts
471
- const PAIRING_REPLY_HISTORY_GRACE_MS = 3e4;
472
- async function checkInboundAccessControl(params) {
473
- const cfg = loadConfig();
474
- const account = resolveWhatsAppAccount({
475
- cfg,
476
- accountId: params.accountId
477
- });
478
- const dmPolicy = account.dmPolicy ?? "pairing";
479
- const configuredAllowFrom = account.allowFrom;
480
- const storeAllowFrom = await readChannelAllowFromStore("whatsapp").catch(() => []);
481
- const combinedAllowFrom = Array.from(new Set([...configuredAllowFrom ?? [], ...storeAllowFrom]));
482
- const defaultAllowFrom = combinedAllowFrom.length === 0 && params.selfE164 ? [params.selfE164] : void 0;
483
- const allowFrom = combinedAllowFrom.length > 0 ? combinedAllowFrom : defaultAllowFrom;
484
- const groupAllowFrom = account.groupAllowFrom ?? (configuredAllowFrom && configuredAllowFrom.length > 0 ? configuredAllowFrom : void 0);
485
- const isSamePhone = params.from === params.selfE164;
486
- const isSelfChat = isSelfChatMode(params.selfE164, configuredAllowFrom);
487
- const pairingGraceMs = typeof params.pairingGraceMs === "number" && params.pairingGraceMs > 0 ? params.pairingGraceMs : PAIRING_REPLY_HISTORY_GRACE_MS;
488
- const suppressPairingReply = typeof params.connectedAtMs === "number" && typeof params.messageTimestampMs === "number" && params.messageTimestampMs < params.connectedAtMs - pairingGraceMs;
489
- const dmHasWildcard = allowFrom?.includes("*") ?? false;
490
- const normalizedAllowFrom = allowFrom && allowFrom.length > 0 ? allowFrom.filter((entry) => entry !== "*").map(normalizeE164) : [];
491
- const groupHasWildcard = groupAllowFrom?.includes("*") ?? false;
492
- const normalizedGroupAllowFrom = groupAllowFrom && groupAllowFrom.length > 0 ? groupAllowFrom.filter((entry) => entry !== "*").map(normalizeE164) : [];
493
- const defaultGroupPolicy = cfg.channels?.defaults?.groupPolicy;
494
- const groupPolicy = account.groupPolicy ?? defaultGroupPolicy ?? "open";
495
- if (params.group && groupPolicy === "disabled") {
496
- logVerbose("Blocked group message (groupPolicy: disabled)");
497
- return {
498
- allowed: false,
499
- shouldMarkRead: false,
500
- isSelfChat,
501
- resolvedAccountId: account.accountId
502
- };
503
- }
504
- if (params.group && groupPolicy === "allowlist") {
505
- if (!groupAllowFrom || groupAllowFrom.length === 0) {
506
- logVerbose("Blocked group message (groupPolicy: allowlist, no groupAllowFrom)");
507
- return {
508
- allowed: false,
509
- shouldMarkRead: false,
510
- isSelfChat,
511
- resolvedAccountId: account.accountId
512
- };
513
- }
514
- if (!(groupHasWildcard || params.senderE164 != null && normalizedGroupAllowFrom.includes(params.senderE164))) {
515
- logVerbose(`Blocked group message from ${params.senderE164 ?? "unknown sender"} (groupPolicy: allowlist)`);
516
- return {
517
- allowed: false,
518
- shouldMarkRead: false,
519
- isSelfChat,
520
- resolvedAccountId: account.accountId
521
- };
522
- }
523
- }
524
- if (!params.group) {
525
- if (params.isFromMe && !isSamePhone) {
526
- logVerbose("Skipping outbound DM (fromMe); no pairing reply needed.");
527
- return {
528
- allowed: false,
529
- shouldMarkRead: false,
530
- isSelfChat,
531
- resolvedAccountId: account.accountId
532
- };
533
- }
534
- if (dmPolicy === "disabled") {
535
- logVerbose("Blocked dm (dmPolicy: disabled)");
536
- return {
537
- allowed: false,
538
- shouldMarkRead: false,
539
- isSelfChat,
540
- resolvedAccountId: account.accountId
541
- };
542
- }
543
- if (dmPolicy !== "open" && !isSamePhone) {
544
- const candidate = params.from;
545
- if (!(dmHasWildcard || normalizedAllowFrom.length > 0 && normalizedAllowFrom.includes(candidate))) {
546
- if (dmPolicy === "pairing") if (suppressPairingReply) logVerbose(`Skipping pairing reply for historical DM from ${candidate}.`);
547
- else {
548
- const { code, created } = await upsertChannelPairingRequest({
549
- channel: "whatsapp",
550
- id: candidate,
551
- meta: { name: (params.pushName ?? "").trim() || void 0 }
552
- });
553
- if (created) {
554
- logVerbose(`whatsapp pairing request sender=${candidate} name=${params.pushName ?? "unknown"}`);
555
- try {
556
- await params.sock.sendMessage(params.remoteJid, { text: buildPairingReply({
557
- channel: "whatsapp",
558
- idLine: `Your WhatsApp phone number: ${candidate}`,
559
- code
560
- }) });
561
- } catch (err) {
562
- logVerbose(`whatsapp pairing reply failed for ${candidate}: ${String(err)}`);
563
- }
564
- }
565
- }
566
- else logVerbose(`Blocked unauthorized sender ${candidate} (dmPolicy=${dmPolicy})`);
567
- return {
568
- allowed: false,
569
- shouldMarkRead: false,
570
- isSelfChat,
571
- resolvedAccountId: account.accountId
572
- };
573
- }
574
- }
575
- }
576
- return {
577
- allowed: true,
578
- shouldMarkRead: true,
579
- isSelfChat,
580
- resolvedAccountId: account.accountId
581
- };
582
- }
583
-
584
- //#endregion
585
- //#region src/web/inbound/media.ts
586
- function unwrapMessage(message) {
587
- return normalizeMessageContent(message);
588
- }
589
- /**
590
- * Resolve the MIME type for an inbound media message.
591
- * Falls back to WhatsApp's standard formats when Baileys omits the MIME.
592
- */
593
- function resolveMediaMimetype(message) {
594
- const explicit = message.imageMessage?.mimetype ?? message.videoMessage?.mimetype ?? message.documentMessage?.mimetype ?? message.audioMessage?.mimetype ?? message.stickerMessage?.mimetype ?? void 0;
595
- if (explicit) return explicit;
596
- if (message.audioMessage) return "audio/ogg; codecs=opus";
597
- if (message.imageMessage) return "image/jpeg";
598
- if (message.videoMessage) return "video/mp4";
599
- if (message.stickerMessage) return "image/webp";
600
- }
601
- async function downloadInboundMedia(msg, sock) {
602
- const message = unwrapMessage(msg.message);
603
- if (!message) return;
604
- const mimetype = resolveMediaMimetype(message);
605
- const fileName = message.documentMessage?.fileName ?? void 0;
606
- if (!message.imageMessage && !message.videoMessage && !message.documentMessage && !message.audioMessage && !message.stickerMessage) return;
607
- try {
608
- return {
609
- buffer: await downloadMediaMessage(msg, "buffer", {}, {
610
- reuploadRequest: sock.updateMediaMessage,
611
- logger: sock.logger
612
- }),
613
- mimetype,
614
- fileName
615
- };
616
- } catch (err) {
617
- logVerbose(`downloadMediaMessage failed: ${String(err)}`);
618
- return;
619
- }
620
- }
621
-
622
- //#endregion
623
- //#region src/web/inbound/send-api.ts
624
- function createWebSendApi(params) {
625
- return {
626
- sendMessage: async (to, text, mediaBuffer, mediaType, sendOptions) => {
627
- const jid = toWhatsappJid(to);
628
- let payload;
629
- if (mediaBuffer && mediaType) if (mediaType.startsWith("image/")) payload = {
630
- image: mediaBuffer,
631
- caption: text || void 0,
632
- mimetype: mediaType
633
- };
634
- else if (mediaType.startsWith("audio/")) payload = {
635
- audio: mediaBuffer,
636
- ptt: true,
637
- mimetype: mediaType
638
- };
639
- else if (mediaType.startsWith("video/")) {
640
- const gifPlayback = sendOptions?.gifPlayback;
641
- payload = {
642
- video: mediaBuffer,
643
- caption: text || void 0,
644
- mimetype: mediaType,
645
- ...gifPlayback ? { gifPlayback: true } : {}
646
- };
647
- } else payload = {
648
- document: mediaBuffer,
649
- fileName: sendOptions?.fileName?.trim() || "file",
650
- caption: text || void 0,
651
- mimetype: mediaType
652
- };
653
- else payload = { text };
654
- const result = await params.sock.sendMessage(jid, payload);
655
- recordChannelActivity({
656
- channel: "whatsapp",
657
- accountId: sendOptions?.accountId ?? params.defaultAccountId,
658
- direction: "outbound"
659
- });
660
- return { messageId: typeof result === "object" && result && "key" in result ? String(result.key?.id ?? "unknown") : "unknown" };
661
- },
662
- sendPoll: async (to, poll) => {
663
- const jid = toWhatsappJid(to);
664
- const result = await params.sock.sendMessage(jid, { poll: {
665
- name: poll.question,
666
- values: poll.options,
667
- selectableCount: poll.maxSelections ?? 1
668
- } });
669
- recordChannelActivity({
670
- channel: "whatsapp",
671
- accountId: params.defaultAccountId,
672
- direction: "outbound"
673
- });
674
- return { messageId: typeof result === "object" && result && "key" in result ? String(result.key?.id ?? "unknown") : "unknown" };
675
- },
676
- sendReaction: async (chatJid, messageId, emoji, fromMe, participant) => {
677
- const jid = toWhatsappJid(chatJid);
678
- await params.sock.sendMessage(jid, { react: {
679
- text: emoji,
680
- key: {
681
- remoteJid: jid,
682
- id: messageId,
683
- fromMe,
684
- participant: participant ? toWhatsappJid(participant) : void 0
685
- }
686
- } });
687
- },
688
- sendComposingTo: async (to) => {
689
- const jid = toWhatsappJid(to);
690
- await params.sock.sendPresenceUpdate("composing", jid);
691
- }
692
- };
693
- }
694
-
695
- //#endregion
696
- //#region src/web/inbound/monitor.ts
697
- async function monitorWebInbox(options) {
698
- const inboundLogger = getChildLogger({ module: "web-inbound" });
699
- const inboundConsoleLog = createSubsystemLogger("gateway/channels/whatsapp").child("inbound");
700
- const sock = await createWaSocket(false, options.verbose, { authDir: options.authDir });
701
- await waitForWaConnection(sock);
702
- const connectedAtMs = Date.now();
703
- let onCloseResolve = null;
704
- const onClose = new Promise((resolve) => {
705
- onCloseResolve = resolve;
706
- });
707
- const resolveClose = (reason) => {
708
- if (!onCloseResolve) return;
709
- const resolver = onCloseResolve;
710
- onCloseResolve = null;
711
- resolver(reason);
712
- };
713
- try {
714
- await sock.sendPresenceUpdate("available");
715
- if (shouldLogVerbose()) logVerbose("Sent global 'available' presence on connect");
716
- } catch (err) {
717
- logVerbose(`Failed to send 'available' presence on connect: ${String(err)}`);
718
- }
719
- const selfJid = sock.user?.id;
720
- const selfE164 = selfJid ? jidToE164(selfJid) : null;
721
- const debouncer = createInboundDebouncer({
722
- debounceMs: options.debounceMs ?? 0,
723
- buildKey: (msg) => {
724
- const senderKey = msg.chatType === "group" ? msg.senderJid ?? msg.senderE164 ?? msg.senderName ?? msg.from : msg.from;
725
- if (!senderKey) return null;
726
- const conversationKey = msg.chatType === "group" ? msg.chatId : msg.from;
727
- return `${msg.accountId}:${conversationKey}:${senderKey}`;
728
- },
729
- shouldDebounce: options.shouldDebounce,
730
- onFlush: async (entries) => {
731
- const last = entries.at(-1);
732
- if (!last) return;
733
- if (entries.length === 1) {
734
- await options.onMessage(last);
735
- return;
736
- }
737
- const mentioned = /* @__PURE__ */ new Set();
738
- for (const entry of entries) for (const jid of entry.mentionedJids ?? []) mentioned.add(jid);
739
- const combinedBody = entries.map((entry) => entry.body).filter(Boolean).join("\n");
740
- const combinedMessage = {
741
- ...last,
742
- body: combinedBody,
743
- mentionedJids: mentioned.size > 0 ? Array.from(mentioned) : void 0
744
- };
745
- await options.onMessage(combinedMessage);
746
- },
747
- onError: (err) => {
748
- inboundLogger.error({ error: String(err) }, "failed handling inbound web message");
749
- inboundConsoleLog.error(`Failed handling inbound web message: ${String(err)}`);
750
- }
751
- });
752
- const groupMetaCache = /* @__PURE__ */ new Map();
753
- const GROUP_META_TTL_MS = 300 * 1e3;
754
- const lidLookup = sock.signalRepository?.lidMapping;
755
- const resolveInboundJid = async (jid) => resolveJidToE164(jid, {
756
- authDir: options.authDir,
757
- lidLookup
758
- });
759
- const getGroupMeta = async (jid) => {
760
- const cached = groupMetaCache.get(jid);
761
- if (cached && cached.expires > Date.now()) return cached;
762
- try {
763
- const meta = await sock.groupMetadata(jid);
764
- const participants = (await Promise.all(meta.participants?.map(async (p) => {
765
- return await resolveInboundJid(p.id) ?? p.id;
766
- }) ?? [])).filter(Boolean) ?? [];
767
- const entry = {
768
- subject: meta.subject,
769
- participants,
770
- expires: Date.now() + GROUP_META_TTL_MS
771
- };
772
- groupMetaCache.set(jid, entry);
773
- return entry;
774
- } catch (err) {
775
- logVerbose(`Failed to fetch group metadata for ${jid}: ${String(err)}`);
776
- return { expires: Date.now() + GROUP_META_TTL_MS };
777
- }
778
- };
779
- const handleMessagesUpsert = async (upsert) => {
780
- if (upsert.type !== "notify" && upsert.type !== "append") return;
781
- for (const msg of upsert.messages ?? []) {
782
- recordChannelActivity({
783
- channel: "whatsapp",
784
- accountId: options.accountId,
785
- direction: "inbound"
786
- });
787
- const id = msg.key?.id ?? void 0;
788
- const remoteJid = msg.key?.remoteJid;
789
- if (!remoteJid) continue;
790
- if (remoteJid.endsWith("@status") || remoteJid.endsWith("@broadcast")) continue;
791
- const group = isJidGroup(remoteJid) === true;
792
- if (id) {
793
- if (isRecentInboundMessage(`${options.accountId}:${remoteJid}:${id}`)) continue;
794
- }
795
- const participantJid = msg.key?.participant ?? void 0;
796
- const from = group ? remoteJid : await resolveInboundJid(remoteJid);
797
- if (!from) continue;
798
- const senderE164 = group ? participantJid ? await resolveInboundJid(participantJid) : null : from;
799
- let groupSubject;
800
- let groupParticipants;
801
- if (group) {
802
- const meta = await getGroupMeta(remoteJid);
803
- groupSubject = meta.subject;
804
- groupParticipants = meta.participants;
805
- }
806
- const messageTimestampMs = msg.messageTimestamp ? Number(msg.messageTimestamp) * 1e3 : void 0;
807
- const access = await checkInboundAccessControl({
808
- accountId: options.accountId,
809
- from,
810
- selfE164,
811
- senderE164,
812
- group,
813
- pushName: msg.pushName ?? void 0,
814
- isFromMe: Boolean(msg.key?.fromMe),
815
- messageTimestampMs,
816
- connectedAtMs,
817
- sock: { sendMessage: (jid, content) => sock.sendMessage(jid, content) },
818
- remoteJid
819
- });
820
- if (!access.allowed) continue;
821
- if (id && !access.isSelfChat && options.sendReadReceipts !== false) {
822
- const participant = msg.key?.participant;
823
- try {
824
- await sock.readMessages([{
825
- remoteJid,
826
- id,
827
- participant,
828
- fromMe: false
829
- }]);
830
- if (shouldLogVerbose()) logVerbose(`Marked message ${id} as read for ${remoteJid}${participant ? ` (participant ${participant})` : ""}`);
831
- } catch (err) {
832
- logVerbose(`Failed to mark message ${id} read: ${String(err)}`);
833
- }
834
- } else if (id && access.isSelfChat && shouldLogVerbose()) logVerbose(`Self-chat mode: skipping read receipt for ${id}`);
835
- if (upsert.type === "append") continue;
836
- const location = extractLocationData(msg.message ?? void 0);
837
- const locationText = location ? formatLocationText(location) : void 0;
838
- let body = extractText(msg.message ?? void 0);
839
- if (locationText) body = [body, locationText].filter(Boolean).join("\n").trim();
840
- if (!body) {
841
- body = extractMediaPlaceholder(msg.message ?? void 0);
842
- if (!body) continue;
843
- }
844
- const replyContext = describeReplyContext(msg.message);
845
- let mediaPath;
846
- let mediaType;
847
- let mediaFileName;
848
- try {
849
- const inboundMedia = await downloadInboundMedia(msg, sock);
850
- if (inboundMedia) {
851
- const maxBytes = (typeof options.mediaMaxMb === "number" && options.mediaMaxMb > 0 ? options.mediaMaxMb : 50) * 1024 * 1024;
852
- mediaPath = (await saveMediaBuffer(inboundMedia.buffer, inboundMedia.mimetype, "inbound", maxBytes, inboundMedia.fileName)).path;
853
- mediaType = inboundMedia.mimetype;
854
- mediaFileName = inboundMedia.fileName;
855
- }
856
- } catch (err) {
857
- logVerbose(`Inbound media download failed: ${String(err)}`);
858
- }
859
- const chatJid = remoteJid;
860
- const sendComposing = async () => {
861
- try {
862
- await sock.sendPresenceUpdate("composing", chatJid);
863
- } catch (err) {
864
- logVerbose(`Presence update failed: ${String(err)}`);
865
- }
866
- };
867
- const reply = async (text) => {
868
- await sock.sendMessage(chatJid, { text });
869
- };
870
- const sendMedia = async (payload) => {
871
- await sock.sendMessage(chatJid, payload);
872
- };
873
- const timestamp = messageTimestampMs;
874
- const mentionedJids = extractMentionedJids(msg.message);
875
- const senderName = msg.pushName ?? void 0;
876
- inboundLogger.info({
877
- from,
878
- to: selfE164 ?? "me",
879
- body,
880
- mediaPath,
881
- mediaType,
882
- mediaFileName,
883
- timestamp
884
- }, "inbound message");
885
- const inboundMessage = {
886
- id,
887
- from,
888
- conversationId: from,
889
- to: selfE164 ?? "me",
890
- accountId: access.resolvedAccountId,
891
- body,
892
- pushName: senderName,
893
- timestamp,
894
- chatType: group ? "group" : "direct",
895
- chatId: remoteJid,
896
- senderJid: participantJid,
897
- senderE164: senderE164 ?? void 0,
898
- senderName,
899
- replyToId: replyContext?.id,
900
- replyToBody: replyContext?.body,
901
- replyToSender: replyContext?.sender,
902
- replyToSenderJid: replyContext?.senderJid,
903
- replyToSenderE164: replyContext?.senderE164,
904
- groupSubject,
905
- groupParticipants,
906
- mentionedJids: mentionedJids ?? void 0,
907
- selfJid,
908
- selfE164,
909
- location: location ?? void 0,
910
- sendComposing,
911
- reply,
912
- sendMedia,
913
- mediaPath,
914
- mediaType,
915
- mediaFileName
916
- };
917
- try {
918
- Promise.resolve(debouncer.enqueue(inboundMessage)).catch((err) => {
919
- inboundLogger.error({ error: String(err) }, "failed handling inbound web message");
920
- inboundConsoleLog.error(`Failed handling inbound web message: ${String(err)}`);
921
- });
922
- } catch (err) {
923
- inboundLogger.error({ error: String(err) }, "failed handling inbound web message");
924
- inboundConsoleLog.error(`Failed handling inbound web message: ${String(err)}`);
925
- }
926
- }
927
- };
928
- sock.ev.on("messages.upsert", handleMessagesUpsert);
929
- const handleConnectionUpdate = (update) => {
930
- try {
931
- if (update.connection === "close") {
932
- const status = getStatusCode(update.lastDisconnect?.error);
933
- resolveClose({
934
- status,
935
- isLoggedOut: status === DisconnectReason.loggedOut,
936
- error: update.lastDisconnect?.error
937
- });
938
- }
939
- } catch (err) {
940
- inboundLogger.error({ error: String(err) }, "connection.update handler error");
941
- resolveClose({
942
- status: void 0,
943
- isLoggedOut: false,
944
- error: err
945
- });
946
- }
947
- };
948
- sock.ev.on("connection.update", handleConnectionUpdate);
949
- return {
950
- close: async () => {
951
- try {
952
- const ev = sock.ev;
953
- const messagesUpsertHandler = handleMessagesUpsert;
954
- const connectionUpdateHandler = handleConnectionUpdate;
955
- if (typeof ev.off === "function") {
956
- ev.off("messages.upsert", messagesUpsertHandler);
957
- ev.off("connection.update", connectionUpdateHandler);
958
- } else if (typeof ev.removeListener === "function") {
959
- ev.removeListener("messages.upsert", messagesUpsertHandler);
960
- ev.removeListener("connection.update", connectionUpdateHandler);
961
- }
962
- sock.ws?.close();
963
- } catch (err) {
964
- logVerbose(`Socket close failed: ${String(err)}`);
965
- }
966
- },
967
- onClose,
968
- signalClose: (reason) => {
969
- resolveClose(reason ?? {
970
- status: void 0,
971
- isLoggedOut: false,
972
- error: "closed"
973
- });
974
- },
975
- ...createWebSendApi({
976
- sock: {
977
- sendMessage: (jid, content) => sock.sendMessage(jid, content),
978
- sendPresenceUpdate: (presence, jid) => sock.sendPresenceUpdate(presence, jid)
979
- },
980
- defaultAccountId: options.accountId
981
- })
982
- };
983
- }
984
-
985
- //#endregion
986
- //#region src/web/auto-reply/mentions.ts
987
- function buildMentionConfig(cfg, agentId) {
988
- return {
989
- mentionRegexes: buildMentionRegexes(cfg, agentId),
990
- allowFrom: cfg.channels?.whatsapp?.allowFrom
991
- };
992
- }
993
- function resolveMentionTargets(msg, authDir) {
994
- const jidOptions = authDir ? { authDir } : void 0;
995
- return {
996
- normalizedMentions: msg.mentionedJids?.length ? msg.mentionedJids.map((jid) => jidToE164(jid, jidOptions) ?? jid).filter(Boolean) : [],
997
- selfE164: msg.selfE164 ?? (msg.selfJid ? jidToE164(msg.selfJid, jidOptions) : null),
998
- selfJid: msg.selfJid ? msg.selfJid.replace(/:\\d+/, "") : null
999
- };
1000
- }
1001
- function isBotMentionedFromTargets(msg, mentionCfg, targets) {
1002
- const clean = (text) => normalizeMentionText(text);
1003
- const isSelfChat = isSelfChatMode(targets.selfE164, mentionCfg.allowFrom);
1004
- const hasMentions = (msg.mentionedJids?.length ?? 0) > 0;
1005
- if (hasMentions && !isSelfChat) {
1006
- if (targets.selfE164 && targets.normalizedMentions.includes(targets.selfE164)) return true;
1007
- if (targets.selfJid) {
1008
- if (targets.normalizedMentions.includes(targets.selfJid)) return true;
1009
- }
1010
- return false;
1011
- } else if (hasMentions && isSelfChat) {}
1012
- const bodyClean = clean(msg.body);
1013
- if (mentionCfg.mentionRegexes.some((re) => re.test(bodyClean))) return true;
1014
- if (targets.selfE164) {
1015
- const selfDigits = targets.selfE164.replace(/\D/g, "");
1016
- if (selfDigits) {
1017
- if (bodyClean.replace(/[^\d]/g, "").includes(selfDigits)) return true;
1018
- const bodyNoSpace = msg.body.replace(/[\s-]/g, "");
1019
- if (new RegExp(`\\+?${selfDigits}`, "i").test(bodyNoSpace)) return true;
1020
- }
1021
- }
1022
- return false;
1023
- }
1024
- function debugMention(msg, mentionCfg, authDir) {
1025
- const mentionTargets = resolveMentionTargets(msg, authDir);
1026
- return {
1027
- wasMentioned: isBotMentionedFromTargets(msg, mentionCfg, mentionTargets),
1028
- details: {
1029
- from: msg.from,
1030
- body: msg.body,
1031
- bodyClean: normalizeMentionText(msg.body),
1032
- mentionedJids: msg.mentionedJids ?? null,
1033
- normalizedMentionedJids: mentionTargets.normalizedMentions.length ? mentionTargets.normalizedMentions : null,
1034
- selfJid: msg.selfJid ?? null,
1035
- selfJidBare: mentionTargets.selfJid,
1036
- selfE164: msg.selfE164 ?? null,
1037
- resolvedSelfE164: mentionTargets.selfE164
1038
- }
1039
- };
1040
- }
1041
- function resolveOwnerList(mentionCfg, selfE164) {
1042
- const allowFrom = mentionCfg.allowFrom;
1043
- return (Array.isArray(allowFrom) && allowFrom.length > 0 ? allowFrom : selfE164 ? [selfE164] : []).filter((entry) => Boolean(entry && entry !== "*")).map((entry) => normalizeE164(entry)).filter((entry) => Boolean(entry));
1044
- }
1045
-
1046
- //#endregion
1047
- //#region src/web/auto-reply/monitor/echo.ts
1048
- function createEchoTracker(params) {
1049
- const recentlySent = /* @__PURE__ */ new Set();
1050
- const maxItems = Math.max(1, params.maxItems ?? 100);
1051
- const buildCombinedKey = (p) => `combined:${p.sessionKey}:${p.combinedBody}`;
1052
- const trim = () => {
1053
- while (recentlySent.size > maxItems) {
1054
- const firstKey = recentlySent.values().next().value;
1055
- if (!firstKey) break;
1056
- recentlySent.delete(firstKey);
1057
- }
1058
- };
1059
- const rememberText = (text, opts) => {
1060
- if (!text) return;
1061
- recentlySent.add(text);
1062
- if (opts.combinedBody && opts.combinedBodySessionKey) recentlySent.add(buildCombinedKey({
1063
- sessionKey: opts.combinedBodySessionKey,
1064
- combinedBody: opts.combinedBody
1065
- }));
1066
- if (opts.logVerboseMessage) params.logVerbose?.(`Added to echo detection set (size now: ${recentlySent.size}): ${text.substring(0, 50)}...`);
1067
- trim();
1068
- };
1069
- return {
1070
- rememberText,
1071
- has: (key) => recentlySent.has(key),
1072
- forget: (key) => {
1073
- recentlySent.delete(key);
1074
- },
1075
- buildCombinedKey
1076
- };
1077
- }
1078
-
1079
- //#endregion
1080
- //#region src/web/auto-reply/monitor/broadcast.ts
1081
- async function maybeBroadcastMessage(params) {
1082
- const broadcastAgents = params.cfg.broadcast?.[params.peerId];
1083
- if (!broadcastAgents || !Array.isArray(broadcastAgents)) return false;
1084
- if (broadcastAgents.length === 0) return false;
1085
- const strategy = params.cfg.broadcast?.strategy || "parallel";
1086
- whatsappInboundLog.info(`Broadcasting message to ${broadcastAgents.length} agents (${strategy})`);
1087
- const agentIds = params.cfg.agents?.list?.map((agent) => normalizeAgentId(agent.id));
1088
- const hasKnownAgents = (agentIds?.length ?? 0) > 0;
1089
- const groupHistorySnapshot = params.msg.chatType === "group" ? params.groupHistories.get(params.groupHistoryKey) ?? [] : void 0;
1090
- const processForAgent = async (agentId) => {
1091
- const normalizedAgentId = normalizeAgentId(agentId);
1092
- if (hasKnownAgents && !agentIds?.includes(normalizedAgentId)) {
1093
- whatsappInboundLog.warn(`Broadcast agent ${agentId} not found in agents.list; skipping`);
1094
- return false;
1095
- }
1096
- const agentRoute = {
1097
- ...params.route,
1098
- agentId: normalizedAgentId,
1099
- sessionKey: buildAgentSessionKey({
1100
- agentId: normalizedAgentId,
1101
- channel: "whatsapp",
1102
- accountId: params.route.accountId,
1103
- peer: {
1104
- kind: params.msg.chatType === "group" ? "group" : "direct",
1105
- id: params.peerId
1106
- },
1107
- dmScope: params.cfg.session?.dmScope,
1108
- identityLinks: params.cfg.session?.identityLinks
1109
- }),
1110
- mainSessionKey: buildAgentMainSessionKey({
1111
- agentId: normalizedAgentId,
1112
- mainKey: DEFAULT_MAIN_KEY
1113
- })
1114
- };
1115
- try {
1116
- return await params.processMessage(params.msg, agentRoute, params.groupHistoryKey, {
1117
- groupHistory: groupHistorySnapshot,
1118
- suppressGroupHistoryClear: true
1119
- });
1120
- } catch (err) {
1121
- whatsappInboundLog.error(`Broadcast agent ${agentId} failed: ${formatError(err)}`);
1122
- return false;
1123
- }
1124
- };
1125
- if (strategy === "sequential") for (const agentId of broadcastAgents) await processForAgent(agentId);
1126
- else await Promise.allSettled(broadcastAgents.map(processForAgent));
1127
- if (params.msg.chatType === "group") params.groupHistories.set(params.groupHistoryKey, []);
1128
- return true;
1129
- }
1130
-
1131
- //#endregion
1132
- //#region src/channels/mention-gating.ts
1133
- function resolveMentionGating(params) {
1134
- const implicit = params.implicitMention === true;
1135
- const bypass = params.shouldBypassMention === true;
1136
- const effectiveWasMentioned = params.wasMentioned || implicit || bypass;
1137
- return {
1138
- effectiveWasMentioned,
1139
- shouldSkip: params.requireMention && params.canDetectMention && !effectiveWasMentioned
1140
- };
1141
- }
1142
-
1143
- //#endregion
1144
- //#region src/web/auto-reply/monitor/commands.ts
1145
- function stripMentionsForCommand(text, mentionRegexes, selfE164) {
1146
- let result = text;
1147
- for (const re of mentionRegexes) result = result.replace(re, " ");
1148
- if (selfE164) {
1149
- const digits = selfE164.replace(/\D/g, "");
1150
- if (digits) {
1151
- const pattern = new RegExp(`\\+?${digits}`, "g");
1152
- result = result.replace(pattern, " ");
1153
- }
1154
- }
1155
- return result.replace(/\s+/g, " ").trim();
1156
- }
1157
-
1158
- //#endregion
1159
- //#region src/web/auto-reply/monitor/group-activation.ts
1160
- function resolveGroupPolicyFor(cfg, conversationId) {
1161
- const groupId = resolveGroupSessionKey({
1162
- From: conversationId,
1163
- ChatType: "group",
1164
- Provider: "whatsapp"
1165
- })?.id;
1166
- return resolveChannelGroupPolicy({
1167
- cfg,
1168
- channel: "whatsapp",
1169
- groupId: groupId ?? conversationId
1170
- });
1171
- }
1172
- function resolveGroupRequireMentionFor(cfg, conversationId) {
1173
- const groupId = resolveGroupSessionKey({
1174
- From: conversationId,
1175
- ChatType: "group",
1176
- Provider: "whatsapp"
1177
- })?.id;
1178
- return resolveChannelGroupRequireMention({
1179
- cfg,
1180
- channel: "whatsapp",
1181
- groupId: groupId ?? conversationId
1182
- });
1183
- }
1184
- function resolveGroupActivationFor(params) {
1185
- const entry = loadSessionStore(resolveStorePath(params.cfg.session?.store, { agentId: params.agentId }))[params.sessionKey];
1186
- const defaultActivation = !resolveGroupRequireMentionFor(params.cfg, params.conversationId) ? "always" : "mention";
1187
- return normalizeGroupActivation(entry?.groupActivation) ?? defaultActivation;
1188
- }
1189
-
1190
- //#endregion
1191
- //#region src/web/auto-reply/monitor/group-members.ts
1192
- function noteGroupMember(groupMemberNames, conversationId, e164, name) {
1193
- if (!e164 || !name) return;
1194
- const key = normalizeE164(e164) ?? e164;
1195
- if (!key) return;
1196
- let roster = groupMemberNames.get(conversationId);
1197
- if (!roster) {
1198
- roster = /* @__PURE__ */ new Map();
1199
- groupMemberNames.set(conversationId, roster);
1200
- }
1201
- roster.set(key, name);
1202
- }
1203
- function formatGroupMembers(params) {
1204
- const { participants, roster, fallbackE164 } = params;
1205
- const seen = /* @__PURE__ */ new Set();
1206
- const ordered = [];
1207
- if (participants?.length) for (const entry of participants) {
1208
- if (!entry) continue;
1209
- const normalized = normalizeE164(entry) ?? entry;
1210
- if (!normalized || seen.has(normalized)) continue;
1211
- seen.add(normalized);
1212
- ordered.push(normalized);
1213
- }
1214
- if (roster) for (const entry of roster.keys()) {
1215
- const normalized = normalizeE164(entry) ?? entry;
1216
- if (!normalized || seen.has(normalized)) continue;
1217
- seen.add(normalized);
1218
- ordered.push(normalized);
1219
- }
1220
- if (ordered.length === 0 && fallbackE164) {
1221
- const normalized = normalizeE164(fallbackE164) ?? fallbackE164;
1222
- if (normalized) ordered.push(normalized);
1223
- }
1224
- if (ordered.length === 0) return;
1225
- return ordered.map((entry) => {
1226
- const name = roster?.get(entry);
1227
- return name ? `${name} (${entry})` : entry;
1228
- }).join(", ");
1229
- }
1230
-
1231
- //#endregion
1232
- //#region src/web/auto-reply/monitor/group-gating.ts
1233
- function isOwnerSender(baseMentionConfig, msg) {
1234
- const sender = normalizeE164(msg.senderE164 ?? "");
1235
- if (!sender) return false;
1236
- return resolveOwnerList(baseMentionConfig, msg.selfE164 ?? void 0).includes(sender);
1237
- }
1238
- function recordPendingGroupHistoryEntry(params) {
1239
- const sender = params.msg.senderName && params.msg.senderE164 ? `${params.msg.senderName} (${params.msg.senderE164})` : params.msg.senderName ?? params.msg.senderE164 ?? "Unknown";
1240
- recordPendingHistoryEntryIfEnabled({
1241
- historyMap: params.groupHistories,
1242
- historyKey: params.groupHistoryKey,
1243
- limit: params.groupHistoryLimit,
1244
- entry: {
1245
- sender,
1246
- body: params.msg.body,
1247
- timestamp: params.msg.timestamp,
1248
- id: params.msg.id,
1249
- senderJid: params.msg.senderJid
1250
- }
1251
- });
1252
- }
1253
- function applyGroupGating(params) {
1254
- const groupPolicy = resolveGroupPolicyFor(params.cfg, params.conversationId);
1255
- if (groupPolicy.allowlistEnabled && !groupPolicy.allowed) {
1256
- params.logVerbose(`Skipping group message ${params.conversationId} (not in allowlist)`);
1257
- return { shouldProcess: false };
1258
- }
1259
- noteGroupMember(params.groupMemberNames, params.groupHistoryKey, params.msg.senderE164, params.msg.senderName);
1260
- const mentionConfig = buildMentionConfig(params.cfg, params.agentId);
1261
- const commandBody = stripMentionsForCommand(params.msg.body, mentionConfig.mentionRegexes, params.msg.selfE164);
1262
- const activationCommand = parseActivationCommand(commandBody);
1263
- const owner = isOwnerSender(params.baseMentionConfig, params.msg);
1264
- const shouldBypassMention = owner && hasControlCommand(commandBody, params.cfg);
1265
- if (activationCommand.hasCommand && !owner) {
1266
- params.logVerbose(`Ignoring /activation from non-owner in group ${params.conversationId}`);
1267
- recordPendingGroupHistoryEntry({
1268
- msg: params.msg,
1269
- groupHistories: params.groupHistories,
1270
- groupHistoryKey: params.groupHistoryKey,
1271
- groupHistoryLimit: params.groupHistoryLimit
1272
- });
1273
- return { shouldProcess: false };
1274
- }
1275
- const mentionDebug = debugMention(params.msg, mentionConfig, params.authDir);
1276
- params.replyLogger.debug({
1277
- conversationId: params.conversationId,
1278
- wasMentioned: mentionDebug.wasMentioned,
1279
- ...mentionDebug.details
1280
- }, "group mention debug");
1281
- const wasMentioned = mentionDebug.wasMentioned;
1282
- const requireMention = resolveGroupActivationFor({
1283
- cfg: params.cfg,
1284
- agentId: params.agentId,
1285
- sessionKey: params.sessionKey,
1286
- conversationId: params.conversationId
1287
- }) !== "always";
1288
- const selfJid = params.msg.selfJid?.replace(/:\\d+/, "");
1289
- const replySenderJid = params.msg.replyToSenderJid?.replace(/:\\d+/, "");
1290
- const selfE164 = params.msg.selfE164 ? normalizeE164(params.msg.selfE164) : null;
1291
- const replySenderE164 = params.msg.replyToSenderE164 ? normalizeE164(params.msg.replyToSenderE164) : null;
1292
- const mentionGate = resolveMentionGating({
1293
- requireMention,
1294
- canDetectMention: true,
1295
- wasMentioned,
1296
- implicitMention: Boolean(selfJid && replySenderJid && selfJid === replySenderJid || selfE164 && replySenderE164 && selfE164 === replySenderE164),
1297
- shouldBypassMention
1298
- });
1299
- params.msg.wasMentioned = mentionGate.effectiveWasMentioned;
1300
- if (!shouldBypassMention && requireMention && mentionGate.shouldSkip) {
1301
- params.logVerbose(`Group message stored for context (no mention detected) in ${params.conversationId}: ${params.msg.body}`);
1302
- recordPendingGroupHistoryEntry({
1303
- msg: params.msg,
1304
- groupHistories: params.groupHistories,
1305
- groupHistoryKey: params.groupHistoryKey,
1306
- groupHistoryLimit: params.groupHistoryLimit
1307
- });
1308
- return { shouldProcess: false };
1309
- }
1310
- return { shouldProcess: true };
1311
- }
1312
-
1313
- //#endregion
1314
- //#region src/web/auto-reply/monitor/last-route.ts
1315
- function trackBackgroundTask(backgroundTasks, task) {
1316
- backgroundTasks.add(task);
1317
- task.finally(() => {
1318
- backgroundTasks.delete(task);
1319
- });
1320
- }
1321
- function updateLastRouteInBackground(params) {
1322
- const storePath = resolveStorePath(params.cfg.session?.store, { agentId: params.storeAgentId });
1323
- const task = updateLastRoute({
1324
- storePath,
1325
- sessionKey: params.sessionKey,
1326
- deliveryContext: {
1327
- channel: params.channel,
1328
- to: params.to,
1329
- accountId: params.accountId
1330
- },
1331
- ctx: params.ctx
1332
- }).catch((err) => {
1333
- params.warn({
1334
- error: formatError(err),
1335
- storePath,
1336
- sessionKey: params.sessionKey,
1337
- to: params.to
1338
- }, "failed updating last route");
1339
- });
1340
- trackBackgroundTask(params.backgroundTasks, task);
1341
- }
1342
-
1343
- //#endregion
1344
- //#region src/web/auto-reply/monitor/peer.ts
1345
- function resolvePeerId(msg) {
1346
- if (msg.chatType === "group") return msg.conversationId ?? msg.from;
1347
- if (msg.senderE164) return normalizeE164(msg.senderE164) ?? msg.senderE164;
1348
- if (msg.from.includes("@")) return jidToE164(msg.from) ?? msg.from;
1349
- return normalizeE164(msg.from) ?? msg.from;
1350
- }
1351
-
1352
- //#endregion
1353
- //#region src/web/auto-reply/deliver-reply.ts
1354
- async function deliverWebReply(params) {
1355
- const { replyResult, msg, maxMediaBytes, textLimit, replyLogger, connectionId, skipLog } = params;
1356
- const replyStarted = Date.now();
1357
- const tableMode = params.tableMode ?? "code";
1358
- const chunkMode = params.chunkMode ?? "length";
1359
- const textChunks = chunkMarkdownTextWithMode(markdownToWhatsApp(convertMarkdownTables(replyResult.text || "", tableMode)), textLimit, chunkMode);
1360
- const mediaList = replyResult.mediaUrls?.length ? replyResult.mediaUrls : replyResult.mediaUrl ? [replyResult.mediaUrl] : [];
1361
- const sendWithRetry = async (fn, label, maxAttempts = 3) => {
1362
- let lastErr;
1363
- for (let attempt = 1; attempt <= maxAttempts; attempt++) try {
1364
- return await fn();
1365
- } catch (err) {
1366
- lastErr = err;
1367
- const errText = formatError(err);
1368
- const isLast = attempt === maxAttempts;
1369
- if (!/closed|reset|timed\\s*out|disconnect/i.test(errText) || isLast) throw err;
1370
- const backoffMs = 500 * attempt;
1371
- logVerbose(`Retrying ${label} to ${msg.from} after failure (${attempt}/${maxAttempts - 1}) in ${backoffMs}ms: ${errText}`);
1372
- await sleep(backoffMs);
1373
- }
1374
- throw lastErr;
1375
- };
1376
- if (mediaList.length === 0 && textChunks.length) {
1377
- const totalChunks = textChunks.length;
1378
- for (const [index, chunk] of textChunks.entries()) {
1379
- const chunkStarted = Date.now();
1380
- await sendWithRetry(() => msg.reply(chunk), "text");
1381
- if (!skipLog) {
1382
- const durationMs = Date.now() - chunkStarted;
1383
- whatsappOutboundLog.debug(`Sent chunk ${index + 1}/${totalChunks} to ${msg.from} (${durationMs.toFixed(0)}ms)`);
1384
- }
1385
- }
1386
- replyLogger.info({
1387
- correlationId: msg.id ?? newConnectionId(),
1388
- connectionId: connectionId ?? null,
1389
- to: msg.from,
1390
- from: msg.to,
1391
- text: elide(replyResult.text, 240),
1392
- mediaUrl: null,
1393
- mediaSizeBytes: null,
1394
- mediaKind: null,
1395
- durationMs: Date.now() - replyStarted
1396
- }, "auto-reply sent (text)");
1397
- return;
1398
- }
1399
- const remainingText = [...textChunks];
1400
- for (const [index, mediaUrl] of mediaList.entries()) {
1401
- const caption = index === 0 ? remainingText.shift() || void 0 : void 0;
1402
- try {
1403
- const media = await loadWebMedia(mediaUrl, maxMediaBytes);
1404
- if (shouldLogVerbose()) {
1405
- logVerbose(`Web auto-reply media size: ${(media.buffer.length / (1024 * 1024)).toFixed(2)}MB`);
1406
- logVerbose(`Web auto-reply media source: ${mediaUrl} (kind ${media.kind})`);
1407
- }
1408
- if (media.kind === "image") await sendWithRetry(() => msg.sendMedia({
1409
- image: media.buffer,
1410
- caption,
1411
- mimetype: media.contentType
1412
- }), "media:image");
1413
- else if (media.kind === "audio") await sendWithRetry(() => msg.sendMedia({
1414
- audio: media.buffer,
1415
- ptt: true,
1416
- mimetype: media.contentType,
1417
- caption
1418
- }), "media:audio");
1419
- else if (media.kind === "video") await sendWithRetry(() => msg.sendMedia({
1420
- video: media.buffer,
1421
- caption,
1422
- mimetype: media.contentType
1423
- }), "media:video");
1424
- else {
1425
- const fileName = media.fileName ?? mediaUrl.split("/").pop() ?? "file";
1426
- const mimetype = media.contentType ?? "application/octet-stream";
1427
- await sendWithRetry(() => msg.sendMedia({
1428
- document: media.buffer,
1429
- fileName,
1430
- caption,
1431
- mimetype
1432
- }), "media:document");
1433
- }
1434
- whatsappOutboundLog.info(`Sent media reply to ${msg.from} (${(media.buffer.length / (1024 * 1024)).toFixed(2)}MB)`);
1435
- replyLogger.info({
1436
- correlationId: msg.id ?? newConnectionId(),
1437
- connectionId: connectionId ?? null,
1438
- to: msg.from,
1439
- from: msg.to,
1440
- text: caption ?? null,
1441
- mediaUrl,
1442
- mediaSizeBytes: media.buffer.length,
1443
- mediaKind: media.kind,
1444
- durationMs: Date.now() - replyStarted
1445
- }, "auto-reply sent (media)");
1446
- } catch (err) {
1447
- whatsappOutboundLog.error(`Failed sending web media to ${msg.from}: ${formatError(err)}`);
1448
- replyLogger.warn({
1449
- err,
1450
- mediaUrl
1451
- }, "failed to send web media reply");
1452
- if (index === 0) {
1453
- const warning = err instanceof Error ? `⚠️ Media failed: ${err.message}` : "⚠️ Media failed.";
1454
- const fallbackText = [remainingText.shift() ?? caption ?? "", warning].filter(Boolean).join("\n");
1455
- if (fallbackText) {
1456
- whatsappOutboundLog.warn(`Media skipped; sent text-only to ${msg.from}`);
1457
- await msg.reply(fallbackText);
1458
- }
1459
- }
1460
- }
1461
- }
1462
- for (const chunk of remainingText) await msg.reply(chunk);
1463
- }
1464
-
1465
- //#endregion
1466
- //#region src/web/auto-reply/monitor/ack-reaction.ts
1467
- function maybeSendAckReaction(params) {
1468
- if (!params.msg.id) return;
1469
- const ackConfig = params.cfg.channels?.whatsapp?.ackReaction;
1470
- const emoji = (ackConfig?.emoji ?? "").trim();
1471
- const directEnabled = ackConfig?.direct ?? true;
1472
- const groupMode = ackConfig?.group ?? "mentions";
1473
- const conversationIdForCheck = params.msg.conversationId ?? params.msg.from;
1474
- const activation = params.msg.chatType === "group" ? resolveGroupActivationFor({
1475
- cfg: params.cfg,
1476
- agentId: params.agentId,
1477
- sessionKey: params.sessionKey,
1478
- conversationId: conversationIdForCheck
1479
- }) : null;
1480
- const shouldSendReaction = () => shouldAckReactionForWhatsApp({
1481
- emoji,
1482
- isDirect: params.msg.chatType === "direct",
1483
- isGroup: params.msg.chatType === "group",
1484
- directEnabled,
1485
- groupMode,
1486
- wasMentioned: params.msg.wasMentioned === true,
1487
- groupActivated: activation === "always"
1488
- });
1489
- if (!shouldSendReaction()) return;
1490
- params.info({
1491
- chatId: params.msg.chatId,
1492
- messageId: params.msg.id,
1493
- emoji
1494
- }, "sending ack reaction");
1495
- sendReactionWhatsApp(params.msg.chatId, params.msg.id, emoji, {
1496
- verbose: params.verbose,
1497
- fromMe: false,
1498
- participant: params.msg.senderJid,
1499
- accountId: params.accountId
1500
- }).catch((err) => {
1501
- params.warn({
1502
- error: formatError(err),
1503
- chatId: params.msg.chatId,
1504
- messageId: params.msg.id
1505
- }, "failed to send ack reaction");
1506
- logVerbose(`WhatsApp ack reaction failed for chat ${params.msg.chatId}: ${formatError(err)}`);
1507
- });
1508
- }
1509
-
1510
- //#endregion
1511
- //#region src/web/auto-reply/monitor/message-line.ts
1512
- function formatReplyContext(msg) {
1513
- if (!msg.replyToBody) return null;
1514
- return `[Replying to ${msg.replyToSender ?? "unknown sender"}${msg.replyToId ? ` id:${msg.replyToId}` : ""}]\n${msg.replyToBody}\n[/Replying]`;
1515
- }
1516
- function buildInboundLine(params) {
1517
- const { cfg, msg, agentId, previousTimestamp, envelope } = params;
1518
- const messagePrefix = resolveMessagePrefix(cfg, agentId, {
1519
- configured: cfg.channels?.whatsapp?.messagePrefix,
1520
- hasAllowFrom: (cfg.channels?.whatsapp?.allowFrom?.length ?? 0) > 0
1521
- });
1522
- const prefixStr = messagePrefix ? `${messagePrefix} ` : "";
1523
- const replyContext = formatReplyContext(msg);
1524
- const baseLine = `${prefixStr}${msg.body}${replyContext ? `\n\n${replyContext}` : ""}`;
1525
- return formatInboundEnvelope({
1526
- channel: "WhatsApp",
1527
- from: msg.chatType === "group" ? msg.from : msg.from?.replace(/^whatsapp:/, ""),
1528
- timestamp: msg.timestamp,
1529
- body: baseLine,
1530
- chatType: msg.chatType,
1531
- sender: {
1532
- name: msg.senderName,
1533
- e164: msg.senderE164,
1534
- id: msg.senderJid
1535
- },
1536
- previousTimestamp,
1537
- envelope
1538
- });
1539
- }
1540
-
1541
- //#endregion
1542
- //#region src/web/auto-reply/monitor/process-message.ts
1543
- function normalizeAllowFromE164(values) {
1544
- return (Array.isArray(values) ? values : []).map((entry) => String(entry).trim()).filter((entry) => entry && entry !== "*").map((entry) => normalizeE164(entry)).filter((entry) => Boolean(entry));
1545
- }
1546
- async function resolveWhatsAppCommandAuthorized(params) {
1547
- if (!(params.cfg.commands?.useAccessGroups !== false)) return true;
1548
- const isGroup = params.msg.chatType === "group";
1549
- const senderE164 = normalizeE164(isGroup ? params.msg.senderE164 ?? "" : params.msg.senderE164 ?? params.msg.from ?? "");
1550
- if (!senderE164) return false;
1551
- const configuredAllowFrom = params.cfg.channels?.whatsapp?.allowFrom ?? [];
1552
- const configuredGroupAllowFrom = params.cfg.channels?.whatsapp?.groupAllowFrom ?? (configuredAllowFrom.length > 0 ? configuredAllowFrom : void 0);
1553
- if (isGroup) {
1554
- if (!configuredGroupAllowFrom || configuredGroupAllowFrom.length === 0) return false;
1555
- if (configuredGroupAllowFrom.some((v) => String(v).trim() === "*")) return true;
1556
- return normalizeAllowFromE164(configuredGroupAllowFrom).includes(senderE164);
1557
- }
1558
- const storeAllowFrom = await readChannelAllowFromStore("whatsapp").catch(() => []);
1559
- const combinedAllowFrom = Array.from(new Set([...configuredAllowFrom ?? [], ...storeAllowFrom]));
1560
- const allowFrom = combinedAllowFrom.length > 0 ? combinedAllowFrom : params.msg.selfE164 ? [params.msg.selfE164] : [];
1561
- if (allowFrom.some((v) => String(v).trim() === "*")) return true;
1562
- return normalizeAllowFromE164(allowFrom).includes(senderE164);
1563
- }
1564
- async function processMessage(params) {
1565
- const conversationId = params.msg.conversationId ?? params.msg.from;
1566
- const storePath = resolveStorePath(params.cfg.session?.store, { agentId: params.route.agentId });
1567
- const envelopeOptions = resolveEnvelopeFormatOptions(params.cfg);
1568
- const previousTimestamp = readSessionUpdatedAt({
1569
- storePath,
1570
- sessionKey: params.route.sessionKey
1571
- });
1572
- let combinedBody = buildInboundLine({
1573
- cfg: params.cfg,
1574
- msg: params.msg,
1575
- agentId: params.route.agentId,
1576
- previousTimestamp,
1577
- envelope: envelopeOptions
1578
- });
1579
- let shouldClearGroupHistory = false;
1580
- if (params.msg.chatType === "group") {
1581
- const history = params.groupHistory ?? params.groupHistories.get(params.groupHistoryKey) ?? [];
1582
- if (history.length > 0) combinedBody = buildHistoryContextFromEntries({
1583
- entries: history.map((m) => ({
1584
- sender: m.sender,
1585
- body: m.body,
1586
- timestamp: m.timestamp
1587
- })),
1588
- currentMessage: combinedBody,
1589
- excludeLast: false,
1590
- formatEntry: (entry) => {
1591
- return formatInboundEnvelope({
1592
- channel: "WhatsApp",
1593
- from: conversationId,
1594
- timestamp: entry.timestamp,
1595
- body: entry.body,
1596
- chatType: "group",
1597
- senderLabel: entry.sender,
1598
- envelope: envelopeOptions
1599
- });
1600
- }
1601
- });
1602
- shouldClearGroupHistory = !(params.suppressGroupHistoryClear ?? false);
1603
- }
1604
- const combinedEchoKey = params.buildCombinedEchoKey({
1605
- sessionKey: params.route.sessionKey,
1606
- combinedBody
1607
- });
1608
- if (params.echoHas(combinedEchoKey)) {
1609
- logVerbose("Skipping auto-reply: detected echo for combined message");
1610
- params.echoForget(combinedEchoKey);
1611
- return false;
1612
- }
1613
- maybeSendAckReaction({
1614
- cfg: params.cfg,
1615
- msg: params.msg,
1616
- agentId: params.route.agentId,
1617
- sessionKey: params.route.sessionKey,
1618
- conversationId,
1619
- verbose: params.verbose,
1620
- accountId: params.route.accountId,
1621
- info: params.replyLogger.info.bind(params.replyLogger),
1622
- warn: params.replyLogger.warn.bind(params.replyLogger)
1623
- });
1624
- const correlationId = params.msg.id ?? newConnectionId();
1625
- params.replyLogger.info({
1626
- connectionId: params.connectionId,
1627
- correlationId,
1628
- from: params.msg.chatType === "group" ? conversationId : params.msg.from,
1629
- to: params.msg.to,
1630
- body: elide(combinedBody, 240),
1631
- mediaType: params.msg.mediaType ?? null,
1632
- mediaPath: params.msg.mediaPath ?? null
1633
- }, "inbound web message");
1634
- const fromDisplay = params.msg.chatType === "group" ? conversationId : params.msg.from;
1635
- const kindLabel = params.msg.mediaType ? `, ${params.msg.mediaType}` : "";
1636
- whatsappInboundLog.info(`Inbound message ${fromDisplay} -> ${params.msg.to} (${params.msg.chatType}${kindLabel}, ${combinedBody.length} chars)`);
1637
- if (shouldLogVerbose()) whatsappInboundLog.debug(`Inbound body: ${elide(combinedBody, 400)}`);
1638
- const dmRouteTarget = params.msg.chatType !== "group" ? (() => {
1639
- if (params.msg.senderE164) return normalizeE164(params.msg.senderE164);
1640
- if (params.msg.from.includes("@")) return jidToE164(params.msg.from);
1641
- return normalizeE164(params.msg.from);
1642
- })() : void 0;
1643
- const textLimit = params.maxMediaTextChunkLimit ?? resolveTextChunkLimit(params.cfg, "whatsapp");
1644
- const chunkMode = resolveChunkMode(params.cfg, "whatsapp", params.route.accountId);
1645
- const tableMode = resolveMarkdownTableMode({
1646
- cfg: params.cfg,
1647
- channel: "whatsapp",
1648
- accountId: params.route.accountId
1649
- });
1650
- let didLogHeartbeatStrip = false;
1651
- let didSendReply = false;
1652
- const commandAuthorized = shouldComputeCommandAuthorized(params.msg.body, params.cfg) ? await resolveWhatsAppCommandAuthorized({
1653
- cfg: params.cfg,
1654
- msg: params.msg
1655
- }) : void 0;
1656
- const configuredResponsePrefix = params.cfg.messages?.responsePrefix;
1657
- const { onModelSelected, ...prefixOptions } = createReplyPrefixOptions({
1658
- cfg: params.cfg,
1659
- agentId: params.route.agentId,
1660
- channel: "whatsapp",
1661
- accountId: params.route.accountId
1662
- });
1663
- const isSelfChat = params.msg.chatType !== "group" && Boolean(params.msg.selfE164) && normalizeE164(params.msg.from) === normalizeE164(params.msg.selfE164 ?? "");
1664
- const responsePrefix = prefixOptions.responsePrefix ?? (configuredResponsePrefix === void 0 && isSelfChat ? resolveIdentityNamePrefix(params.cfg, params.route.agentId) ?? "[anima]" : void 0);
1665
- const inboundHistory = params.msg.chatType === "group" ? (params.groupHistory ?? params.groupHistories.get(params.groupHistoryKey) ?? []).map((entry) => ({
1666
- sender: entry.sender,
1667
- body: entry.body,
1668
- timestamp: entry.timestamp
1669
- })) : void 0;
1670
- const ctxPayload = finalizeInboundContext({
1671
- Body: combinedBody,
1672
- BodyForAgent: params.msg.body,
1673
- InboundHistory: inboundHistory,
1674
- RawBody: params.msg.body,
1675
- CommandBody: params.msg.body,
1676
- From: params.msg.from,
1677
- To: params.msg.to,
1678
- SessionKey: params.route.sessionKey,
1679
- AccountId: params.route.accountId,
1680
- MessageSid: params.msg.id,
1681
- ReplyToId: params.msg.replyToId,
1682
- ReplyToBody: params.msg.replyToBody,
1683
- ReplyToSender: params.msg.replyToSender,
1684
- MediaPath: params.msg.mediaPath,
1685
- MediaUrl: params.msg.mediaUrl,
1686
- MediaType: params.msg.mediaType,
1687
- ChatType: params.msg.chatType,
1688
- ConversationLabel: params.msg.chatType === "group" ? conversationId : params.msg.from,
1689
- GroupSubject: params.msg.groupSubject,
1690
- GroupMembers: formatGroupMembers({
1691
- participants: params.msg.groupParticipants,
1692
- roster: params.groupMemberNames.get(params.groupHistoryKey),
1693
- fallbackE164: params.msg.senderE164
1694
- }),
1695
- SenderName: params.msg.senderName,
1696
- SenderId: params.msg.senderJid?.trim() || params.msg.senderE164,
1697
- SenderE164: params.msg.senderE164,
1698
- CommandAuthorized: commandAuthorized,
1699
- WasMentioned: params.msg.wasMentioned,
1700
- ...params.msg.location ? toLocationContext(params.msg.location) : {},
1701
- Provider: "whatsapp",
1702
- Surface: "whatsapp",
1703
- OriginatingChannel: "whatsapp",
1704
- OriginatingTo: params.msg.from
1705
- });
1706
- if (dmRouteTarget) updateLastRouteInBackground({
1707
- cfg: params.cfg,
1708
- backgroundTasks: params.backgroundTasks,
1709
- storeAgentId: params.route.agentId,
1710
- sessionKey: params.route.mainSessionKey,
1711
- channel: "whatsapp",
1712
- to: dmRouteTarget,
1713
- accountId: params.route.accountId,
1714
- ctx: ctxPayload,
1715
- warn: params.replyLogger.warn.bind(params.replyLogger)
1716
- });
1717
- const metaTask = recordSessionMetaFromInbound({
1718
- storePath,
1719
- sessionKey: params.route.sessionKey,
1720
- ctx: ctxPayload
1721
- }).catch((err) => {
1722
- params.replyLogger.warn({
1723
- error: formatError(err),
1724
- storePath,
1725
- sessionKey: params.route.sessionKey
1726
- }, "failed updating session meta");
1727
- });
1728
- trackBackgroundTask(params.backgroundTasks, metaTask);
1729
- const { queuedFinal } = await dispatchReplyWithBufferedBlockDispatcher({
1730
- ctx: ctxPayload,
1731
- cfg: params.cfg,
1732
- replyResolver: params.replyResolver,
1733
- dispatcherOptions: {
1734
- ...prefixOptions,
1735
- responsePrefix,
1736
- onHeartbeatStrip: () => {
1737
- if (!didLogHeartbeatStrip) {
1738
- didLogHeartbeatStrip = true;
1739
- logVerbose("Stripped stray HEARTBEAT_OK token from web reply");
1740
- }
1741
- },
1742
- deliver: async (payload, info) => {
1743
- await deliverWebReply({
1744
- replyResult: payload,
1745
- msg: params.msg,
1746
- maxMediaBytes: params.maxMediaBytes,
1747
- textLimit,
1748
- chunkMode,
1749
- replyLogger: params.replyLogger,
1750
- connectionId: params.connectionId,
1751
- skipLog: info.kind !== "final",
1752
- tableMode
1753
- });
1754
- didSendReply = true;
1755
- if (info.kind === "tool") {
1756
- params.rememberSentText(payload.text, {});
1757
- return;
1758
- }
1759
- const shouldLog = info.kind === "final" && payload.text ? true : void 0;
1760
- params.rememberSentText(payload.text, {
1761
- combinedBody,
1762
- combinedBodySessionKey: params.route.sessionKey,
1763
- logVerboseMessage: shouldLog
1764
- });
1765
- if (info.kind === "final") {
1766
- const fromDisplay = params.msg.chatType === "group" ? conversationId : params.msg.from ?? "unknown";
1767
- const hasMedia = Boolean(payload.mediaUrl || payload.mediaUrls?.length);
1768
- whatsappOutboundLog.info(`Auto-replied to ${fromDisplay}${hasMedia ? " (media)" : ""}`);
1769
- if (shouldLogVerbose()) {
1770
- const preview = payload.text != null ? elide(payload.text, 400) : "<media>";
1771
- whatsappOutboundLog.debug(`Reply body: ${preview}${hasMedia ? " (media)" : ""}`);
1772
- }
1773
- }
1774
- },
1775
- onError: (err, info) => {
1776
- const label = info.kind === "tool" ? "tool update" : info.kind === "block" ? "block update" : "auto-reply";
1777
- whatsappOutboundLog.error(`Failed sending web ${label} to ${params.msg.from ?? conversationId}: ${formatError(err)}`);
1778
- },
1779
- onReplyStart: params.msg.sendComposing
1780
- },
1781
- replyOptions: {
1782
- disableBlockStreaming: typeof params.cfg.channels?.whatsapp?.blockStreaming === "boolean" ? !params.cfg.channels.whatsapp.blockStreaming : void 0,
1783
- onModelSelected
1784
- }
1785
- });
1786
- if (!queuedFinal) {
1787
- if (shouldClearGroupHistory) params.groupHistories.set(params.groupHistoryKey, []);
1788
- logVerbose("Skipping auto-reply: silent token or no text/media returned from resolver");
1789
- return false;
1790
- }
1791
- if (shouldClearGroupHistory) params.groupHistories.set(params.groupHistoryKey, []);
1792
- return didSendReply;
1793
- }
1794
-
1795
- //#endregion
1796
- //#region src/web/auto-reply/monitor/on-message.ts
1797
- function createWebOnMessageHandler(params) {
1798
- const processForRoute = async (msg, route, groupHistoryKey, opts) => processMessage({
1799
- cfg: params.cfg,
1800
- msg,
1801
- route,
1802
- groupHistoryKey,
1803
- groupHistories: params.groupHistories,
1804
- groupMemberNames: params.groupMemberNames,
1805
- connectionId: params.connectionId,
1806
- verbose: params.verbose,
1807
- maxMediaBytes: params.maxMediaBytes,
1808
- replyResolver: params.replyResolver,
1809
- replyLogger: params.replyLogger,
1810
- backgroundTasks: params.backgroundTasks,
1811
- rememberSentText: params.echoTracker.rememberText,
1812
- echoHas: params.echoTracker.has,
1813
- echoForget: params.echoTracker.forget,
1814
- buildCombinedEchoKey: params.echoTracker.buildCombinedKey,
1815
- groupHistory: opts?.groupHistory,
1816
- suppressGroupHistoryClear: opts?.suppressGroupHistoryClear
1817
- });
1818
- return async (msg) => {
1819
- const conversationId = msg.conversationId ?? msg.from;
1820
- const peerId = resolvePeerId(msg);
1821
- const route = resolveAgentRoute({
1822
- cfg: loadConfig(),
1823
- channel: "whatsapp",
1824
- accountId: msg.accountId,
1825
- peer: {
1826
- kind: msg.chatType === "group" ? "group" : "direct",
1827
- id: peerId
1828
- }
1829
- });
1830
- const groupHistoryKey = msg.chatType === "group" ? buildGroupHistoryKey({
1831
- channel: "whatsapp",
1832
- accountId: route.accountId,
1833
- peerKind: "group",
1834
- peerId
1835
- }) : route.sessionKey;
1836
- if (msg.from === msg.to) logVerbose(`📱 Same-phone mode detected (from === to: ${msg.from})`);
1837
- if (params.echoTracker.has(msg.body)) {
1838
- logVerbose("Skipping auto-reply: detected echo (message matches recently sent text)");
1839
- params.echoTracker.forget(msg.body);
1840
- return;
1841
- }
1842
- if (msg.chatType === "group") {
1843
- const metaCtx = {
1844
- From: msg.from,
1845
- To: msg.to,
1846
- SessionKey: route.sessionKey,
1847
- AccountId: route.accountId,
1848
- ChatType: msg.chatType,
1849
- ConversationLabel: conversationId,
1850
- GroupSubject: msg.groupSubject,
1851
- SenderName: msg.senderName,
1852
- SenderId: msg.senderJid?.trim() || msg.senderE164,
1853
- SenderE164: msg.senderE164,
1854
- Provider: "whatsapp",
1855
- Surface: "whatsapp",
1856
- OriginatingChannel: "whatsapp",
1857
- OriginatingTo: conversationId
1858
- };
1859
- updateLastRouteInBackground({
1860
- cfg: params.cfg,
1861
- backgroundTasks: params.backgroundTasks,
1862
- storeAgentId: route.agentId,
1863
- sessionKey: route.sessionKey,
1864
- channel: "whatsapp",
1865
- to: conversationId,
1866
- accountId: route.accountId,
1867
- ctx: metaCtx,
1868
- warn: params.replyLogger.warn.bind(params.replyLogger)
1869
- });
1870
- if (!applyGroupGating({
1871
- cfg: params.cfg,
1872
- msg,
1873
- conversationId,
1874
- groupHistoryKey,
1875
- agentId: route.agentId,
1876
- sessionKey: route.sessionKey,
1877
- baseMentionConfig: params.baseMentionConfig,
1878
- authDir: params.account.authDir,
1879
- groupHistories: params.groupHistories,
1880
- groupHistoryLimit: params.groupHistoryLimit,
1881
- groupMemberNames: params.groupMemberNames,
1882
- logVerbose,
1883
- replyLogger: params.replyLogger
1884
- }).shouldProcess) return;
1885
- } else if (!msg.senderE164 && peerId && peerId.startsWith("+")) msg.senderE164 = normalizeE164(peerId) ?? msg.senderE164;
1886
- if (await maybeBroadcastMessage({
1887
- cfg: params.cfg,
1888
- msg,
1889
- peerId,
1890
- route,
1891
- groupHistoryKey,
1892
- groupHistories: params.groupHistories,
1893
- processMessage: processForRoute
1894
- })) return;
1895
- await processForRoute(msg, route, groupHistoryKey);
1896
- };
1897
- }
1898
-
1899
- //#endregion
1900
- //#region src/web/auto-reply/monitor.ts
1901
- async function monitorWebChannel(verbose, listenerFactory = monitorWebInbox, keepAlive = true, replyResolver = getReplyFromConfig, runtime = defaultRuntime, abortSignal, tuning = {}) {
1902
- const runId = newConnectionId();
1903
- const replyLogger = getChildLogger({
1904
- module: "web-auto-reply",
1905
- runId
1906
- });
1907
- const heartbeatLogger = getChildLogger({
1908
- module: "web-heartbeat",
1909
- runId
1910
- });
1911
- const reconnectLogger = getChildLogger({
1912
- module: "web-reconnect",
1913
- runId
1914
- });
1915
- const status = {
1916
- running: true,
1917
- connected: false,
1918
- reconnectAttempts: 0,
1919
- lastConnectedAt: null,
1920
- lastDisconnect: null,
1921
- lastMessageAt: null,
1922
- lastEventAt: null,
1923
- lastError: null
1924
- };
1925
- const emitStatus = () => {
1926
- tuning.statusSink?.({
1927
- ...status,
1928
- lastDisconnect: status.lastDisconnect ? { ...status.lastDisconnect } : null
1929
- });
1930
- };
1931
- emitStatus();
1932
- const baseCfg = loadConfig();
1933
- const account = resolveWhatsAppAccount({
1934
- cfg: baseCfg,
1935
- accountId: tuning.accountId
1936
- });
1937
- const cfg = {
1938
- ...baseCfg,
1939
- channels: {
1940
- ...baseCfg.channels,
1941
- whatsapp: {
1942
- ...baseCfg.channels?.whatsapp,
1943
- ackReaction: account.ackReaction,
1944
- messagePrefix: account.messagePrefix,
1945
- allowFrom: account.allowFrom,
1946
- groupAllowFrom: account.groupAllowFrom,
1947
- groupPolicy: account.groupPolicy,
1948
- textChunkLimit: account.textChunkLimit,
1949
- chunkMode: account.chunkMode,
1950
- mediaMaxMb: account.mediaMaxMb,
1951
- blockStreaming: account.blockStreaming,
1952
- groups: account.groups
1953
- }
1954
- }
1955
- };
1956
- const configuredMaxMb = cfg.agents?.defaults?.mediaMaxMb;
1957
- const maxMediaBytes = typeof configuredMaxMb === "number" && configuredMaxMb > 0 ? configuredMaxMb * 1024 * 1024 : DEFAULT_WEB_MEDIA_BYTES;
1958
- const heartbeatSeconds = resolveHeartbeatSeconds(cfg, tuning.heartbeatSeconds);
1959
- const reconnectPolicy = resolveReconnectPolicy(cfg, tuning.reconnect);
1960
- const baseMentionConfig = buildMentionConfig(cfg);
1961
- const groupHistoryLimit = cfg.channels?.whatsapp?.accounts?.[tuning.accountId ?? ""]?.historyLimit ?? cfg.channels?.whatsapp?.historyLimit ?? cfg.messages?.groupChat?.historyLimit ?? DEFAULT_GROUP_HISTORY_LIMIT;
1962
- const groupHistories = /* @__PURE__ */ new Map();
1963
- const groupMemberNames = /* @__PURE__ */ new Map();
1964
- const echoTracker = createEchoTracker({
1965
- maxItems: 100,
1966
- logVerbose
1967
- });
1968
- const sleep = tuning.sleep ?? ((ms, signal) => sleepWithAbort(ms, signal ?? abortSignal));
1969
- const stopRequested = () => abortSignal?.aborted === true;
1970
- const abortPromise = abortSignal && new Promise((resolve) => abortSignal.addEventListener("abort", () => resolve("aborted"), { once: true }));
1971
- const currentMaxListeners = process.getMaxListeners?.() ?? 10;
1972
- if (process.setMaxListeners && currentMaxListeners < 50) process.setMaxListeners(50);
1973
- let sigintStop = false;
1974
- const handleSigint = () => {
1975
- sigintStop = true;
1976
- };
1977
- process.once("SIGINT", handleSigint);
1978
- let reconnectAttempts = 0;
1979
- while (true) {
1980
- if (stopRequested()) break;
1981
- const connectionId = newConnectionId();
1982
- const startedAt = Date.now();
1983
- let heartbeat = null;
1984
- let watchdogTimer = null;
1985
- let lastMessageAt = null;
1986
- let handledMessages = 0;
1987
- let unregisterUnhandled = null;
1988
- const MESSAGE_TIMEOUT_MS = 1800 * 1e3;
1989
- const WATCHDOG_CHECK_MS = 60 * 1e3;
1990
- const backgroundTasks = /* @__PURE__ */ new Set();
1991
- const onMessage = createWebOnMessageHandler({
1992
- cfg,
1993
- verbose,
1994
- connectionId,
1995
- maxMediaBytes,
1996
- groupHistoryLimit,
1997
- groupHistories,
1998
- groupMemberNames,
1999
- echoTracker,
2000
- backgroundTasks,
2001
- replyResolver: replyResolver ?? getReplyFromConfig,
2002
- replyLogger,
2003
- baseMentionConfig,
2004
- account
2005
- });
2006
- const inboundDebounceMs = resolveInboundDebounceMs({
2007
- cfg,
2008
- channel: "whatsapp"
2009
- });
2010
- const shouldDebounce = (msg) => {
2011
- if (msg.mediaPath || msg.mediaType) return false;
2012
- if (msg.location) return false;
2013
- if (msg.replyToId || msg.replyToBody) return false;
2014
- return !hasControlCommand(msg.body, cfg);
2015
- };
2016
- const listener = await (listenerFactory ?? monitorWebInbox)({
2017
- verbose,
2018
- accountId: account.accountId,
2019
- authDir: account.authDir,
2020
- mediaMaxMb: account.mediaMaxMb,
2021
- sendReadReceipts: account.sendReadReceipts,
2022
- debounceMs: inboundDebounceMs,
2023
- shouldDebounce,
2024
- onMessage: async (msg) => {
2025
- handledMessages += 1;
2026
- lastMessageAt = Date.now();
2027
- status.lastMessageAt = lastMessageAt;
2028
- status.lastEventAt = lastMessageAt;
2029
- emitStatus();
2030
- await onMessage(msg);
2031
- }
2032
- });
2033
- status.connected = true;
2034
- status.lastConnectedAt = Date.now();
2035
- status.lastEventAt = status.lastConnectedAt;
2036
- status.lastError = null;
2037
- emitStatus();
2038
- const { e164: selfE164 } = readWebSelfId(account.authDir);
2039
- const connectRoute = resolveAgentRoute({
2040
- cfg,
2041
- channel: "whatsapp",
2042
- accountId: account.accountId
2043
- });
2044
- enqueueSystemEvent(`WhatsApp gateway connected${selfE164 ? ` as ${selfE164}` : ""}.`, { sessionKey: connectRoute.sessionKey });
2045
- setActiveWebListener(account.accountId, listener);
2046
- unregisterUnhandled = registerUnhandledRejectionHandler((reason) => {
2047
- if (!isLikelyWhatsAppCryptoError(reason)) return false;
2048
- const errorStr = formatError(reason);
2049
- reconnectLogger.warn({
2050
- connectionId,
2051
- error: errorStr
2052
- }, "web reconnect: unhandled rejection from WhatsApp socket; forcing reconnect");
2053
- listener.signalClose?.({
2054
- status: 499,
2055
- isLoggedOut: false,
2056
- error: reason
2057
- });
2058
- return true;
2059
- });
2060
- const closeListener = async () => {
2061
- setActiveWebListener(account.accountId, null);
2062
- if (unregisterUnhandled) {
2063
- unregisterUnhandled();
2064
- unregisterUnhandled = null;
2065
- }
2066
- if (heartbeat) clearInterval(heartbeat);
2067
- if (watchdogTimer) clearInterval(watchdogTimer);
2068
- if (backgroundTasks.size > 0) {
2069
- await Promise.allSettled(backgroundTasks);
2070
- backgroundTasks.clear();
2071
- }
2072
- try {
2073
- await listener.close();
2074
- } catch (err) {
2075
- logVerbose(`Socket close failed: ${formatError(err)}`);
2076
- }
2077
- };
2078
- if (keepAlive) {
2079
- heartbeat = setInterval(() => {
2080
- const authAgeMs = getWebAuthAgeMs(account.authDir);
2081
- const minutesSinceLastMessage = lastMessageAt ? Math.floor((Date.now() - lastMessageAt) / 6e4) : null;
2082
- const logData = {
2083
- connectionId,
2084
- reconnectAttempts,
2085
- messagesHandled: handledMessages,
2086
- lastMessageAt,
2087
- authAgeMs,
2088
- uptimeMs: Date.now() - startedAt,
2089
- ...minutesSinceLastMessage !== null && minutesSinceLastMessage > 30 ? { minutesSinceLastMessage } : {}
2090
- };
2091
- if (minutesSinceLastMessage && minutesSinceLastMessage > 30) heartbeatLogger.warn(logData, "⚠️ web gateway heartbeat - no messages in 30+ minutes");
2092
- else heartbeatLogger.info(logData, "web gateway heartbeat");
2093
- }, heartbeatSeconds * 1e3);
2094
- watchdogTimer = setInterval(() => {
2095
- if (!lastMessageAt) return;
2096
- const timeSinceLastMessage = Date.now() - lastMessageAt;
2097
- if (timeSinceLastMessage <= MESSAGE_TIMEOUT_MS) return;
2098
- const minutesSinceLastMessage = Math.floor(timeSinceLastMessage / 6e4);
2099
- heartbeatLogger.warn({
2100
- connectionId,
2101
- minutesSinceLastMessage,
2102
- lastMessageAt: new Date(lastMessageAt),
2103
- messagesHandled: handledMessages
2104
- }, "Message timeout detected - forcing reconnect");
2105
- whatsappHeartbeatLog.warn(`No messages received in ${minutesSinceLastMessage}m - restarting connection`);
2106
- closeListener().catch((err) => {
2107
- logVerbose(`Close listener failed: ${formatError(err)}`);
2108
- });
2109
- listener.signalClose?.({
2110
- status: 499,
2111
- isLoggedOut: false,
2112
- error: "watchdog-timeout"
2113
- });
2114
- }, WATCHDOG_CHECK_MS);
2115
- }
2116
- whatsappLog.info("Listening for personal WhatsApp inbound messages.");
2117
- if (process.stdout.isTTY || process.stderr.isTTY) whatsappLog.raw("Ctrl+C to stop.");
2118
- if (!keepAlive) {
2119
- await closeListener();
2120
- process.removeListener("SIGINT", handleSigint);
2121
- return;
2122
- }
2123
- const reason = await Promise.race([listener.onClose?.catch((err) => {
2124
- reconnectLogger.error({ error: formatError(err) }, "listener.onClose rejected");
2125
- return {
2126
- status: 500,
2127
- isLoggedOut: false,
2128
- error: err
2129
- };
2130
- }) ?? waitForever(), abortPromise ?? waitForever()]);
2131
- if (Date.now() - startedAt > heartbeatSeconds * 1e3) reconnectAttempts = 0;
2132
- status.reconnectAttempts = reconnectAttempts;
2133
- emitStatus();
2134
- if (stopRequested() || sigintStop || reason === "aborted") {
2135
- await closeListener();
2136
- break;
2137
- }
2138
- const statusCode = (typeof reason === "object" && reason && "status" in reason ? reason.status : void 0) ?? "unknown";
2139
- const loggedOut = typeof reason === "object" && reason && "isLoggedOut" in reason && reason.isLoggedOut;
2140
- const errorStr = formatError(reason);
2141
- status.connected = false;
2142
- status.lastEventAt = Date.now();
2143
- status.lastDisconnect = {
2144
- at: status.lastEventAt,
2145
- status: typeof statusCode === "number" ? statusCode : void 0,
2146
- error: errorStr,
2147
- loggedOut: Boolean(loggedOut)
2148
- };
2149
- status.lastError = errorStr;
2150
- status.reconnectAttempts = reconnectAttempts;
2151
- emitStatus();
2152
- reconnectLogger.info({
2153
- connectionId,
2154
- status: statusCode,
2155
- loggedOut,
2156
- reconnectAttempts,
2157
- error: errorStr
2158
- }, "web reconnect: connection closed");
2159
- enqueueSystemEvent(`WhatsApp gateway disconnected (status ${statusCode ?? "unknown"})`, { sessionKey: connectRoute.sessionKey });
2160
- if (loggedOut) {
2161
- runtime.error(`WhatsApp session logged out. Run \`${formatCliCommand("anima channels login --channel web")}\` to relink.`);
2162
- await closeListener();
2163
- break;
2164
- }
2165
- reconnectAttempts += 1;
2166
- status.reconnectAttempts = reconnectAttempts;
2167
- emitStatus();
2168
- if (reconnectPolicy.maxAttempts > 0 && reconnectAttempts >= reconnectPolicy.maxAttempts) {
2169
- reconnectLogger.warn({
2170
- connectionId,
2171
- status: statusCode,
2172
- reconnectAttempts,
2173
- maxAttempts: reconnectPolicy.maxAttempts
2174
- }, "web reconnect: max attempts reached; continuing in degraded mode");
2175
- runtime.error(`WhatsApp Web reconnect: max attempts reached (${reconnectAttempts}/${reconnectPolicy.maxAttempts}). Stopping web monitoring.`);
2176
- await closeListener();
2177
- break;
2178
- }
2179
- const delay = computeBackoff(reconnectPolicy, reconnectAttempts);
2180
- reconnectLogger.info({
2181
- connectionId,
2182
- status: statusCode,
2183
- reconnectAttempts,
2184
- maxAttempts: reconnectPolicy.maxAttempts || "unlimited",
2185
- delayMs: delay
2186
- }, "web reconnect: scheduling retry");
2187
- runtime.error(`WhatsApp Web connection closed (status ${statusCode}). Retry ${reconnectAttempts}/${reconnectPolicy.maxAttempts || "∞"} in ${formatDurationPrecise(delay)}… (${errorStr})`);
2188
- await closeListener();
2189
- try {
2190
- await sleep(delay, abortSignal);
2191
- } catch {
2192
- break;
2193
- }
2194
- }
2195
- status.running = false;
2196
- status.connected = false;
2197
- status.lastEventAt = Date.now();
2198
- emitStatus();
2199
- process.removeListener("SIGINT", handleSigint);
2200
- }
2201
-
2202
- //#endregion
2203
- export { WA_WEB_AUTH_DIR, createWaSocket, logWebSelfId, loginWeb, monitorWebChannel, monitorWebInbox, pickWebChannel, sendMessageWhatsApp, waitForWaConnection, webAuthExists };