@spacebar_ai/moldclaw-core 2026.3.14 → 2026.3.16

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 (1074) hide show
  1. package/README.md +108 -3
  2. package/dist/account-id-plS5L20e.d.ts +1 -0
  3. package/dist/accounts-BAYVGC2k.js +109 -0
  4. package/dist/accounts-DrjRgReV.d.ts +103 -0
  5. package/dist/acp-cli-at_UYEOS.js +2088 -0
  6. package/dist/acpx-Chy1GQ_k.d.ts +5 -0
  7. package/dist/actions.runtime-C0F7dMfO.js +114 -0
  8. package/dist/actions.runtime-caI2LG9o.js +128 -0
  9. package/dist/agent-media-payload-CkpAqaOh.d.ts +16 -0
  10. package/dist/agents-B98yPGc5.js +853 -0
  11. package/dist/agents-BrLr08L3.js +217 -0
  12. package/dist/allow-from-BIwT4dl7.d.ts +42 -0
  13. package/dist/allow-list-CHt7yvAf.js +81 -0
  14. package/dist/allowlist-CxQo2wQc.js +142 -0
  15. package/dist/allowlist-resolution-B7ib7gye.d.ts +17 -0
  16. package/dist/api-Co7TNHbL.js +6953 -0
  17. package/dist/api-cEQ_ql_8.js +112 -0
  18. package/dist/audit-AnKnnlaZ.js +787 -0
  19. package/dist/audit-channel.collect.runtime-CAk1DFQ3.js +600 -0
  20. package/dist/audit-channel.runtime-5phdZp_m.js +116 -0
  21. package/dist/audit-extra.async-B8ZXFxic.js +813 -0
  22. package/dist/audit-hdKa3D-u.js +54 -0
  23. package/dist/audit-membership-runtime-CJV5XvGU.js +157 -0
  24. package/dist/audit.deep.runtime-DNMcRQrp.js +24 -0
  25. package/dist/audit.nondeep.runtime-DhNDL6yM.js +831 -0
  26. package/dist/audit.runtime-Bx7uWEh8.js +113 -0
  27. package/dist/auth-choice-C37W9MA7.js +268 -0
  28. package/dist/auth-choice-CNppOY_V.js +117 -0
  29. package/dist/auth-choice-XYFnp6fI.js +502 -0
  30. package/dist/auth-choice-options-D6oZY4Xo.js +123 -0
  31. package/dist/auth-choice-prompt-BhRqchJx.js +110 -0
  32. package/dist/auth-choice-prompt-C1xv0N08.js +36 -0
  33. package/dist/auth-choice.plugin-providers.runtime-DhLEtbmR.js +114 -0
  34. package/dist/auth-profiles-9zZdaXJK.js +127756 -0
  35. package/dist/auth-profiles.runtime-HONFDgiu.js +111 -0
  36. package/dist/bluebubbles-BY8JhO4y.js +64 -0
  37. package/dist/bluebubbles-CQjEnzK_.d.ts +6 -0
  38. package/dist/bluebubbles-RmcKgkBa.d.ts +45 -0
  39. package/dist/boolean-param-F1sMwnPu.d.ts +5 -0
  40. package/dist/bot-BGh-ATV7.d.ts +478 -0
  41. package/dist/brave-CljenznH.js +24 -0
  42. package/dist/browser-cli-CX8i0wf0.js +1492 -0
  43. package/dist/build-info.json +3 -3
  44. package/dist/bundled/boot-md/handler.d.ts +6 -0
  45. package/dist/bundled/boot-md/handler.js +26 -26
  46. package/dist/bundled/bootstrap-extra-files/handler.d.ts +6 -0
  47. package/dist/bundled/command-logger/handler.d.ts +9 -0
  48. package/dist/bundled/session-memory/handler.d.ts +9 -0
  49. package/dist/bundled/session-memory/handler.js +27 -27
  50. package/dist/call-Bc257L16.js +37 -0
  51. package/dist/call-DYFR7oGy.js +639 -0
  52. package/dist/canvas-host/a2ui/.bundle.hash +1 -1
  53. package/dist/channel-Bd-igGEW.js +803 -0
  54. package/dist/channel-BgRMb6bZ.js +575 -0
  55. package/dist/channel-BtcLrU6J.js +1598 -0
  56. package/dist/channel-Bwf6m_hD.js +538 -0
  57. package/dist/channel-C7-kgDBd.js +562 -0
  58. package/dist/channel-CEXOAxIc.js +949 -0
  59. package/dist/channel-CpZ3p9MJ.js +226 -0
  60. package/dist/channel-CqBlN6A2.js +619 -0
  61. package/dist/channel-DKhfHW4U.js +352 -0
  62. package/dist/channel-DS3t_KdJ2.js +316 -0
  63. package/dist/channel-DY24FA1v.js +4681 -0
  64. package/dist/channel-DYFGmImJ.js +542 -0
  65. package/dist/channel-DcyIqX5p.js +207 -0
  66. package/dist/channel-J-2XcAli.js +214 -0
  67. package/dist/channel-N616f4gZ.js +306 -0
  68. package/dist/channel-NY7aU2Gj.js +397 -0
  69. package/dist/channel-PNI8BOmm.js +1321 -0
  70. package/dist/channel-UcXepDJs.js +943 -0
  71. package/dist/channel-account-context-CL3hEq1j.js +103 -0
  72. package/dist/channel-config-schema-Q2nzcCCR.d.ts +1 -0
  73. package/dist/channel-jA_jodJo.js +920 -0
  74. package/dist/channel-options-CtgU5qkG.js +50 -0
  75. package/dist/channel-policy-7wXDp6d3.d.ts +1 -0
  76. package/dist/channel-rGI8uig4.js +497 -0
  77. package/dist/channel-summary-DGJZXo0r.js +106 -0
  78. package/dist/channel.runtime--WZvlNJM.js +413 -0
  79. package/dist/channel.runtime-B0ct42DL.js +122 -0
  80. package/dist/channel.runtime-BEZUZrYB.js +177 -0
  81. package/dist/channel.runtime-BMuWmsIC.js +166 -0
  82. package/dist/channel.runtime-BtvHP0po.js +4006 -0
  83. package/dist/channel.runtime-Cwf993pX.js +194 -0
  84. package/dist/channel.runtime-Cy4lEpTX.js +174 -0
  85. package/dist/channel.runtime-DAz6axda.js +865 -0
  86. package/dist/channel.runtime-DdQ2mOVh.js +236 -0
  87. package/dist/channel.runtime-Dy3HPgOU.js +399 -0
  88. package/dist/channel.runtime-iqfC25k7.js +213 -0
  89. package/dist/channel.setup-B4VYMZlQ.js +9 -0
  90. package/dist/channel.setup-BohGbCbI.js +57 -0
  91. package/dist/channel.setup-Bq2AQqqc.js +6 -0
  92. package/dist/channel.setup-BxiSfLp1.js +8 -0
  93. package/dist/channel.setup-DOUS6fjO.js +8 -0
  94. package/dist/channel.setup-DXhdYU3g.js +9 -0
  95. package/dist/channel.setup-N51CgfNy.js +11 -0
  96. package/dist/channels/plugins/actions/discord.d.ts +3 -0
  97. package/dist/channels/plugins/actions/discord.js +26 -26
  98. package/dist/channels/plugins/actions/signal.d.ts +2 -0
  99. package/dist/channels/plugins/actions/signal.js +26 -26
  100. package/dist/channels/plugins/actions/telegram.d.ts +3 -0
  101. package/dist/channels/plugins/actions/telegram.js +26 -26
  102. package/dist/channels/plugins/agent-tools/whatsapp-login.d.ts +4 -0
  103. package/dist/channels/plugins/agent-tools/whatsapp-login.js +26 -26
  104. package/dist/channels-CueeFf0q.js +404 -0
  105. package/dist/channels-PheAd73E.js +1113 -0
  106. package/dist/channels-cli-CXzVF84v.js +286 -0
  107. package/dist/channels-status-issues-BjWBQHhU.js +16 -0
  108. package/dist/chat-type-BlSN0vo4.d.ts +5 -0
  109. package/dist/clawbot-cli-BBehDXW1.js +113 -0
  110. package/dist/cli/daemon-cli.d.ts +58 -0
  111. package/dist/cli/daemon-cli.js +1 -1
  112. package/dist/cli-CIm7d5Id.js +149 -0
  113. package/dist/command-format-pq3tS8t2.d.ts +4 -0
  114. package/dist/command-registry-CDkp__KH.js +13 -0
  115. package/dist/command-registry-DSEkUBW1.js +212 -0
  116. package/dist/command-secret-gateway-CqP_o0n8.js +106 -0
  117. package/dist/compact.runtime-Qm_csEtG.js +111 -0
  118. package/dist/completion-cli-Ch1sgSLQ.js +445 -0
  119. package/dist/completion-cli-vF067Tso.js +16 -0
  120. package/dist/config-B2W1zTP1.js +44 -0
  121. package/dist/config-CMhKplgO.js +938 -0
  122. package/dist/config-DchtRsvs.js +30 -0
  123. package/dist/config-cli-C41d88_c.js +428 -0
  124. package/dist/config-guard-B_vjkXCQ.js +117 -0
  125. package/dist/config-schema-pPBCF4hz.js +31 -0
  126. package/dist/config-validation-6om9cBUx.js +262 -0
  127. package/dist/config-value-Dl3XEpA6.js +132 -0
  128. package/dist/configure-BxzvDSzu.js +1100 -0
  129. package/dist/configure-CLMLoWAn.js +238 -0
  130. package/dist/control-ui-shared-E8Nz6uKZ.js +29 -0
  131. package/dist/core-Cd3fMFKq.d.ts +87 -0
  132. package/dist/credentials-yYt6VWCq.js +268 -0
  133. package/dist/cron-cli-CA3lV3kh.js +634 -0
  134. package/dist/daemon-cli-BtQuIXEk.js +339 -0
  135. package/dist/daemon-install-BWKGzgMm.js +175 -0
  136. package/dist/deliver-CgMNmfTy.js +106 -0
  137. package/dist/deliver-runtime-Bn1KWoiQ.js +106 -0
  138. package/dist/devices-cli-D601npiL.js +340 -0
  139. package/dist/diagnostic-CkiYEGqt.js +310 -0
  140. package/dist/diffs-B5tZ8Coj.d.ts +1 -0
  141. package/dist/directory-cli-skEV8MT7.js +306 -0
  142. package/dist/directory-config-helpers-B-tiBKIv.d.ts +38 -0
  143. package/dist/directory-runtime-BEJ2fCIR.d.ts +1 -0
  144. package/dist/directory.static-CnyzoWbV.js +44 -0
  145. package/dist/discord-B_gbzPti.js +109 -0
  146. package/dist/discovery-CqI-e_Mv.js +48 -0
  147. package/dist/dm-policy-shared-nybkS1uP.d.ts +95 -0
  148. package/dist/dns-cli-Cjes3Ruw.js +216 -0
  149. package/dist/docs-cli-C3g3Gi_d.js +173 -0
  150. package/dist/doctor-completion-TvgV4SZH.js +90 -0
  151. package/dist/doctor-config-flow-0w9Ux7V8.js +107 -0
  152. package/dist/doctor-config-flow-DLzr8W7Y.js +2437 -0
  153. package/dist/enable-VYzv8b2z.js +24 -0
  154. package/dist/entry.d.ts +7 -0
  155. package/dist/entry.js +1 -1
  156. package/dist/env-overrides-DYVIkuvN.js +434 -0
  157. package/dist/env-overrides.runtime-6kijpIuu.js +17 -0
  158. package/dist/exec-approvals-cli-D_lkTG-l.js +419 -0
  159. package/dist/exec-sVmouhA9.d.ts +39 -0
  160. package/dist/extensions/acpx/index.d.ts +11 -0
  161. package/dist/extensions/acpx/index.js +1 -1
  162. package/dist/extensions/amazon-bedrock/index.d.ts +11 -0
  163. package/dist/extensions/anthropic/index.d.ts +11 -0
  164. package/dist/extensions/anthropic/index.js +26 -26
  165. package/dist/extensions/bluebubbles/index.d.ts +11 -0
  166. package/dist/extensions/bluebubbles/index.js +30 -30
  167. package/dist/extensions/bluebubbles/setup-entry.d.ts +59 -0
  168. package/dist/extensions/bluebubbles/setup-entry.js +30 -30
  169. package/dist/extensions/brave/index.d.ts +11 -0
  170. package/dist/extensions/brave/index.js +2 -2
  171. package/dist/extensions/byteplus/index.d.ts +11 -0
  172. package/dist/extensions/byteplus/index.js +26 -26
  173. package/dist/extensions/cloudflare-ai-gateway/index.d.ts +11 -0
  174. package/dist/extensions/cloudflare-ai-gateway/index.js +27 -27
  175. package/dist/extensions/copilot-proxy/index.d.ts +11 -0
  176. package/dist/extensions/device-pair/index.d.ts +12 -0
  177. package/dist/extensions/diagnostics-otel/index.d.ts +11 -0
  178. package/dist/extensions/diffs/index.d.ts +11 -0
  179. package/dist/extensions/discord/index.d.ts +11 -0
  180. package/dist/extensions/discord/index.js +31 -31
  181. package/dist/extensions/discord/setup-entry.d.ts +7 -0
  182. package/dist/extensions/discord/setup-entry.js +29 -29
  183. package/dist/extensions/elevenlabs/index.d.ts +11 -0
  184. package/dist/extensions/elevenlabs/index.js +26 -26
  185. package/dist/extensions/feishu/index.d.ts +229 -0
  186. package/dist/extensions/feishu/index.js +31 -31
  187. package/dist/extensions/feishu/setup-entry.d.ts +9 -0
  188. package/dist/extensions/feishu/setup-entry.js +28 -28
  189. package/dist/extensions/firecrawl/index.d.ts +11 -0
  190. package/dist/extensions/firecrawl/index.js +26 -26
  191. package/dist/extensions/github-copilot/index.d.ts +11 -0
  192. package/dist/extensions/github-copilot/index.js +27 -27
  193. package/dist/extensions/google/index.d.ts +11 -0
  194. package/dist/extensions/google/index.js +26 -26
  195. package/dist/extensions/googlechat/index.d.ts +11 -0
  196. package/dist/extensions/googlechat/index.js +30 -30
  197. package/dist/extensions/googlechat/setup-entry.d.ts +19 -0
  198. package/dist/extensions/googlechat/setup-entry.js +30 -30
  199. package/dist/extensions/huggingface/index.d.ts +11 -0
  200. package/dist/extensions/huggingface/index.js +26 -26
  201. package/dist/extensions/imessage/index.d.ts +11 -0
  202. package/dist/extensions/imessage/index.js +30 -30
  203. package/dist/extensions/imessage/setup-entry.d.ts +7 -0
  204. package/dist/extensions/imessage/setup-entry.js +30 -30
  205. package/dist/extensions/irc/index.d.ts +11 -0
  206. package/dist/extensions/irc/index.js +29 -29
  207. package/dist/extensions/irc/setup-entry.d.ts +8 -0
  208. package/dist/extensions/irc/setup-entry.js +29 -29
  209. package/dist/extensions/kakao-talkchannel/index.d.ts +19 -0
  210. package/dist/extensions/kakao-talkchannel/index.js +1762 -0
  211. package/dist/extensions/kakao-talkchannel/moldclaw.plugin.json +111 -0
  212. package/dist/extensions/kakao-talkchannel/package.json +12 -0
  213. package/dist/extensions/kilocode/index.d.ts +11 -0
  214. package/dist/extensions/kilocode/index.js +26 -26
  215. package/dist/extensions/kimi-coding/index.d.ts +11 -0
  216. package/dist/extensions/kimi-coding/index.js +26 -26
  217. package/dist/extensions/line/index.d.ts +11 -0
  218. package/dist/extensions/line/index.js +28 -28
  219. package/dist/extensions/line/setup-entry.d.ts +7 -0
  220. package/dist/extensions/line/setup-entry.js +28 -28
  221. package/dist/extensions/llm-task/index.d.ts +11 -0
  222. package/dist/extensions/llm-task/index.js +28 -28
  223. package/dist/extensions/lobster/index.d.ts +11 -0
  224. package/dist/extensions/matrix/index.d.ts +11 -0
  225. package/dist/extensions/matrix/index.js +31 -31
  226. package/dist/extensions/matrix/setup-entry.d.ts +20 -0
  227. package/dist/extensions/matrix/setup-entry.js +31 -31
  228. package/dist/extensions/mattermost/index.d.ts +11 -0
  229. package/dist/extensions/mattermost/index.js +28 -28
  230. package/dist/extensions/mattermost/setup-entry.d.ts +88 -0
  231. package/dist/extensions/mattermost/setup-entry.js +28 -28
  232. package/dist/extensions/memory-core/index.d.ts +11 -0
  233. package/dist/extensions/memory-lancedb/index.d.ts +25 -0
  234. package/dist/extensions/microsoft/index.d.ts +11 -0
  235. package/dist/extensions/microsoft/index.js +26 -26
  236. package/dist/extensions/minimax/index.d.ts +11 -0
  237. package/dist/extensions/minimax/index.js +26 -26
  238. package/dist/extensions/mistral/index.d.ts +11 -0
  239. package/dist/extensions/mistral/index.js +26 -26
  240. package/dist/extensions/modelstudio/index.d.ts +11 -0
  241. package/dist/extensions/modelstudio/index.js +26 -26
  242. package/dist/extensions/moonshot/index.d.ts +11 -0
  243. package/dist/extensions/moonshot/index.js +26 -26
  244. package/dist/extensions/msteams/index.d.ts +11 -0
  245. package/dist/extensions/msteams/index.js +31 -31
  246. package/dist/extensions/msteams/setup-entry.d.ts +11 -0
  247. package/dist/extensions/msteams/setup-entry.js +31 -31
  248. package/dist/extensions/nextcloud-talk/index.d.ts +11 -0
  249. package/dist/extensions/nextcloud-talk/index.js +28 -28
  250. package/dist/extensions/nextcloud-talk/setup-entry.d.ts +60 -0
  251. package/dist/extensions/nextcloud-talk/setup-entry.js +28 -28
  252. package/dist/extensions/nostr/index.d.ts +11 -0
  253. package/dist/extensions/nostr/index.js +28 -28
  254. package/dist/extensions/nostr/setup-entry.d.ts +49 -0
  255. package/dist/extensions/nostr/setup-entry.js +28 -28
  256. package/dist/extensions/nvidia/index.d.ts +11 -0
  257. package/dist/extensions/ollama/index.d.ts +11 -0
  258. package/dist/extensions/open-prose/index.d.ts +11 -0
  259. package/dist/extensions/openai/index.d.ts +11 -0
  260. package/dist/extensions/openai/index.js +26 -26
  261. package/dist/extensions/opencode/index.d.ts +11 -0
  262. package/dist/extensions/opencode/index.js +26 -26
  263. package/dist/extensions/opencode-go/index.d.ts +11 -0
  264. package/dist/extensions/opencode-go/index.js +26 -26
  265. package/dist/extensions/openrouter/index.d.ts +11 -0
  266. package/dist/extensions/openrouter/index.js +26 -26
  267. package/dist/extensions/openshell/index.d.ts +11 -0
  268. package/dist/extensions/openshell/index.js +26 -26
  269. package/dist/extensions/perplexity/index.d.ts +11 -0
  270. package/dist/extensions/perplexity/index.js +2 -2
  271. package/dist/extensions/phone-control/index.d.ts +12 -0
  272. package/dist/extensions/qianfan/index.d.ts +11 -0
  273. package/dist/extensions/qianfan/index.js +26 -26
  274. package/dist/extensions/qwen-portal-auth/index.d.ts +12 -0
  275. package/dist/extensions/qwen-portal-auth/index.js +26 -26
  276. package/dist/extensions/sglang/index.d.ts +11 -0
  277. package/dist/extensions/sglang/index.js +26 -26
  278. package/dist/extensions/signal/index.d.ts +11 -0
  279. package/dist/extensions/signal/index.js +29 -29
  280. package/dist/extensions/signal/setup-entry.d.ts +7 -0
  281. package/dist/extensions/signal/setup-entry.js +29 -29
  282. package/dist/extensions/slack/index.d.ts +11 -0
  283. package/dist/extensions/slack/index.js +30 -30
  284. package/dist/extensions/slack/setup-entry.d.ts +7 -0
  285. package/dist/extensions/slack/setup-entry.js +29 -29
  286. package/dist/extensions/synology-chat/index.d.ts +11 -0
  287. package/dist/extensions/synology-chat/index.js +28 -28
  288. package/dist/extensions/synology-chat/setup-entry.d.ts +138 -0
  289. package/dist/extensions/synology-chat/setup-entry.js +28 -28
  290. package/dist/extensions/synthetic/index.d.ts +11 -0
  291. package/dist/extensions/synthetic/index.js +26 -26
  292. package/dist/extensions/talk-voice/index.d.ts +12 -0
  293. package/dist/extensions/talk-voice/index.js +26 -26
  294. package/dist/extensions/telegram/index.d.ts +11 -0
  295. package/dist/extensions/telegram/index.js +29 -29
  296. package/dist/extensions/telegram/setup-entry.d.ts +7 -0
  297. package/dist/extensions/telegram/setup-entry.js +28 -28
  298. package/dist/extensions/thread-ownership/index.d.ts +12 -0
  299. package/dist/extensions/tlon/index.d.ts +11 -0
  300. package/dist/extensions/tlon/index.js +28 -28
  301. package/dist/extensions/tlon/setup-entry.d.ts +7 -0
  302. package/dist/extensions/tlon/setup-entry.js +28 -28
  303. package/dist/extensions/together/index.d.ts +11 -0
  304. package/dist/extensions/together/index.js +26 -26
  305. package/dist/extensions/twitch/index.d.ts +39 -0
  306. package/dist/extensions/twitch/index.js +28 -28
  307. package/dist/extensions/venice/index.d.ts +11 -0
  308. package/dist/extensions/venice/index.js +26 -26
  309. package/dist/extensions/vercel-ai-gateway/index.d.ts +11 -0
  310. package/dist/extensions/vercel-ai-gateway/index.js +26 -26
  311. package/dist/extensions/vllm/index.d.ts +11 -0
  312. package/dist/extensions/vllm/index.js +26 -26
  313. package/dist/extensions/voice-call/index.d.ts +11 -0
  314. package/dist/extensions/voice-call/index.js +26 -26
  315. package/dist/extensions/volcengine/index.d.ts +11 -0
  316. package/dist/extensions/volcengine/index.js +26 -26
  317. package/dist/extensions/whatsapp/index.d.ts +11 -0
  318. package/dist/extensions/whatsapp/index.js +29 -29
  319. package/dist/extensions/whatsapp/setup-entry.d.ts +7 -0
  320. package/dist/extensions/whatsapp/setup-entry.js +29 -29
  321. package/dist/extensions/xai/index.d.ts +11 -0
  322. package/dist/extensions/xai/index.js +26 -26
  323. package/dist/extensions/xiaomi/index.d.ts +11 -0
  324. package/dist/extensions/xiaomi/index.js +26 -26
  325. package/dist/extensions/zai/index.d.ts +11 -0
  326. package/dist/extensions/zai/index.js +26 -26
  327. package/dist/extensions/zalo/index.d.ts +11 -0
  328. package/dist/extensions/zalo/index.js +30 -30
  329. package/dist/extensions/zalo/setup-entry.d.ts +34 -0
  330. package/dist/extensions/zalo/setup-entry.js +30 -30
  331. package/dist/extensions/zalouser/index.d.ts +11 -0
  332. package/dist/extensions/zalouser/index.js +31 -31
  333. package/dist/extensions/zalouser/setup-entry.d.ts +42 -0
  334. package/dist/extensions/zalouser/setup-entry.js +31 -31
  335. package/dist/feishu-DCKEC3ao.d.ts +36 -0
  336. package/dist/gateway-cli-DN1Ii6J-.js +26432 -0
  337. package/dist/gateway-install-token-CJYFJBaC.js +163 -0
  338. package/dist/gateway-rpc-CroQg9MB.js +26 -0
  339. package/dist/gateway-runtime-D9FRZqKP.js +69 -0
  340. package/dist/googlechat-CBCkerAy.js +307 -0
  341. package/dist/googlechat-CSUNieHX.d.ts +12 -0
  342. package/dist/group-access-rSvkIglb.d.ts +61 -0
  343. package/dist/health-B6WwLJp4.js +570 -0
  344. package/dist/health-CAlJydXv.js +108 -0
  345. package/dist/history-BwNxb0sJ.d.ts +75 -0
  346. package/dist/hooks-BYlfU3Nf.d.ts +6 -0
  347. package/dist/hooks-cli-DuKmdo_H.js +995 -0
  348. package/dist/http-registry-DX_LVtuK.d.ts +20 -0
  349. package/dist/image-generation-DKkdRpve.d.ts +9 -0
  350. package/dist/imessage-7abjbe2Q.js +31 -0
  351. package/dist/imessage-DOH1yaDE.js +110 -0
  352. package/dist/inbound-envelope-CmvweL6U.d.ts +78 -0
  353. package/dist/inbound-reply-dispatch-BvnKTOec.js +71 -0
  354. package/dist/inbound-reply-dispatch-C7LjHRZN.d.ts +72 -0
  355. package/dist/index-DTQqfqj9.d.ts +1 -0
  356. package/dist/index.d.ts +27 -0
  357. package/dist/index.js +2 -2
  358. package/dist/infra/warning-filter.d.ts +10 -0
  359. package/dist/install-target-tXRD7VkM.js +574 -0
  360. package/dist/installs-C8fz8sm3.js +532 -0
  361. package/dist/io-C6XifaT4.js +9737 -0
  362. package/dist/io-C8awRnSW.js +28 -0
  363. package/dist/ipv4-d88_Jn2p.js +82 -0
  364. package/dist/irc-DpR6FXjN.js +672 -0
  365. package/dist/json-store-Sr_kk-II.d.ts +14 -0
  366. package/dist/keyed-async-queue-BA3BKukE.d.ts +19 -0
  367. package/dist/library-DOwowAGN.js +107 -0
  368. package/dist/lifecycle-core-BHHBoRTY.js +382 -0
  369. package/dist/line/accounts.d.ts +3 -0
  370. package/dist/line/send.d.ts +2 -0
  371. package/dist/line/send.js +4 -4
  372. package/dist/line/template-messages.d.ts +2 -0
  373. package/dist/line-8rsNbJCP.js +530 -0
  374. package/dist/line-D_cvIf6B.d.ts +75 -0
  375. package/dist/links-BOnvOj1z.d.ts +7 -0
  376. package/dist/llm-slug-generator-D9HjWtJT.js +67 -0
  377. package/dist/llm-slug-generator.d.ts +12 -0
  378. package/dist/llm-slug-generator.js +27 -27
  379. package/dist/logging-BhqLWxTD.js +13 -0
  380. package/dist/logging-DfaiL4OX.js +29 -0
  381. package/dist/login-qr-COBYR52w.js +233 -0
  382. package/dist/login-qr-xK4QIpPc.js +107 -0
  383. package/dist/logs-cli-RSSTw8L_.js +254 -0
  384. package/dist/manager-runtime-DL6JoSj9.js +106 -0
  385. package/dist/manager.runtime-Cbyhg1vB.js +710 -0
  386. package/dist/markdown-to-line-BTlEkOls.d.ts +91 -0
  387. package/dist/matrix-DX-jaB88.js +1490 -0
  388. package/dist/matrix-H6Yyj1QZ.d.ts +68 -0
  389. package/dist/matrix-J8s45tRw.js +1269 -0
  390. package/dist/mattermost-D75n6bRI.d.ts +6 -0
  391. package/dist/mcp-cli-CLc3_yCO.js +86 -0
  392. package/dist/media-understanding.runtime-BI0Lljbl.js +111 -0
  393. package/dist/memory-cli-CTp2cYrf.js +106 -0
  394. package/dist/method-scopes-Du8ODGFW.js +2586 -0
  395. package/dist/model-auth-markers-DEDakSUW.d.ts +20 -0
  396. package/dist/model-picker-CDBs7LJF.js +390 -0
  397. package/dist/model-picker-CRix4Wwv.js +107 -0
  398. package/dist/model-picker.runtime-CITyy3Rn.js +120 -0
  399. package/dist/model-suppression.runtime-Ce7D6QUT.js +111 -0
  400. package/dist/models-BK1eanuP.js +113 -0
  401. package/dist/models-X4Czy3uE.js +2514 -0
  402. package/dist/models-cli-C79Ulviy.js +304 -0
  403. package/dist/models-config-DALlu3S9.js +106 -0
  404. package/dist/models-config.providers.discovery-CSJ1STM1.d.ts +18 -0
  405. package/dist/monitor-B45a_RpX.js +3468 -0
  406. package/dist/monitor-C8KbJ-i0.js +767 -0
  407. package/dist/monitor-CIhrvegZ.js +3076 -0
  408. package/dist/monitor-CQut7klP.js +6823 -0
  409. package/dist/monitor-DZb5IJle.js +777 -0
  410. package/dist/monitor-DaFkdD27.js +108 -0
  411. package/dist/monitor-Do9Tp2Ii.js +110 -0
  412. package/dist/monitor-shared-CMK9cDOb.js +444 -0
  413. package/dist/msteams-A6H_wv5F.js +852 -0
  414. package/dist/net-DpMJgN-o.d.ts +19 -0
  415. package/dist/nextcloud-talk-f1pZ5Bge.d.ts +1 -0
  416. package/dist/node-cli-BXnmsjzL.js +2498 -0
  417. package/dist/node-resolve-CupmrA0Y.js +835 -0
  418. package/dist/nodes-cli-DZVrah_8.js +1375 -0
  419. package/dist/nostr-DMV534Ks.d.ts +7 -0
  420. package/dist/nostr-SAk3tjtR.js +8744 -0
  421. package/dist/npm-resolution-Dr9wssCY.js +60 -0
  422. package/dist/oauth-utils-DnyXdWU9.d.ts +10 -0
  423. package/dist/onboard-BE5pmb1g.js +589 -0
  424. package/dist/onboard-channels-3hNVY0E7.js +1241 -0
  425. package/dist/onboard-channels-vaO3nWLL.js +200 -0
  426. package/dist/onboard-custom-CI5uFyWH.js +571 -0
  427. package/dist/onboard-custom-eIvRswgv.js +109 -0
  428. package/dist/onboard-helpers-ChMWfUnl.js +335 -0
  429. package/dist/onboard-helpers-DRFi9oaD.js +108 -0
  430. package/dist/onboard-remote-BTspTgA4.js +112 -0
  431. package/dist/onboard-remote-so38yXlX.js +181 -0
  432. package/dist/onboard-search-DS0tZS24.js +297 -0
  433. package/dist/onboard-skills-B9DxCCiU.js +133 -0
  434. package/dist/onboard-skills-so0a_BJV.js +112 -0
  435. package/dist/outbound-media-BiJscGlR.js +11 -0
  436. package/dist/outbound-media-DJF-TuJu.d.ts +11 -0
  437. package/dist/pairing-access-CuiJP9xN.d.ts +21 -0
  438. package/dist/pairing-cli-DN0u1Cez.js +212 -0
  439. package/dist/parse-finite-number-B3FJTjyQ.d.ts +5 -0
  440. package/dist/perplexity-Bw1u3CAF.js +24 -0
  441. package/dist/persistent-dedupe-DR5Ka6BX.d.ts +26 -0
  442. package/dist/pi-model-discovery-runtime-iwKNCaYu.js +106 -0
  443. package/dist/pi-tools.before-tool-call.runtime-BM_N-JZe.js +380 -0
  444. package/dist/plugin-install--KVul05Z.js +184 -0
  445. package/dist/plugin-install-DVpPsLkS.js +112 -0
  446. package/dist/plugin-install-plan-Dwc6-coz.js +49 -0
  447. package/dist/plugin-registry-XRswugE9.js +108 -0
  448. package/dist/plugin-registry-jozQafRo.js +49 -0
  449. package/dist/plugin-sdk/account-resolution.js +26 -26
  450. package/dist/plugin-sdk/acp-runtime.js +26 -26
  451. package/dist/plugin-sdk/acpx.js +1 -1
  452. package/dist/plugin-sdk/agent-runtime.js +26 -26
  453. package/dist/plugin-sdk/bluebubbles.js +29 -29
  454. package/dist/plugin-sdk/channel-config-helpers.js +26 -26
  455. package/dist/plugin-sdk/channel-config-schema.js +2 -2
  456. package/dist/plugin-sdk/channel-policy.js +26 -26
  457. package/dist/plugin-sdk/channel-runtime.js +26 -26
  458. package/dist/plugin-sdk/compat.js +27 -27
  459. package/dist/plugin-sdk/config-runtime.js +28 -28
  460. package/dist/plugin-sdk/conversation-runtime.js +26 -26
  461. package/dist/plugin-sdk/discord.js +26 -26
  462. package/dist/plugin-sdk/feishu.js +27 -27
  463. package/dist/plugin-sdk/gateway-runtime.js +8 -8
  464. package/dist/plugin-sdk/googlechat.js +29 -29
  465. package/dist/plugin-sdk/image-generation-runtime.js +26 -26
  466. package/dist/plugin-sdk/image-generation.js +26 -26
  467. package/dist/plugin-sdk/imessage.js +27 -27
  468. package/dist/plugin-sdk/index.js +26 -26
  469. package/dist/plugin-sdk/infra-runtime.js +26 -26
  470. package/dist/plugin-sdk/irc.js +29 -29
  471. package/dist/plugin-sdk/line.js +27 -27
  472. package/dist/plugin-sdk/llm-task.js +26 -26
  473. package/dist/plugin-sdk/matrix.js +29 -29
  474. package/dist/plugin-sdk/mattermost.js +28 -28
  475. package/dist/plugin-sdk/media-runtime.js +26 -26
  476. package/dist/plugin-sdk/media-understanding-runtime.js +26 -26
  477. package/dist/plugin-sdk/media-understanding.js +26 -26
  478. package/dist/plugin-sdk/msteams.js +30 -30
  479. package/dist/plugin-sdk/nextcloud-talk.js +28 -28
  480. package/dist/plugin-sdk/nostr.js +27 -27
  481. package/dist/plugin-sdk/plugin-runtime.js +26 -26
  482. package/dist/plugin-sdk/provider-auth.js +28 -28
  483. package/dist/plugin-sdk/provider-setup.js +27 -27
  484. package/dist/plugin-sdk/provider-web-search.js +1 -1
  485. package/dist/plugin-sdk/qwen-portal-auth.js +26 -26
  486. package/dist/plugin-sdk/reply-history.js +26 -26
  487. package/dist/plugin-sdk/reply-runtime.js +26 -26
  488. package/dist/plugin-sdk/sandbox.js +26 -26
  489. package/dist/plugin-sdk/security-runtime.js +26 -26
  490. package/dist/plugin-sdk/self-hosted-provider-setup.js +27 -27
  491. package/dist/plugin-sdk/setup.js +27 -27
  492. package/dist/plugin-sdk/signal.js +26 -26
  493. package/dist/plugin-sdk/slack.js +26 -26
  494. package/dist/plugin-sdk/speech-runtime.js +26 -26
  495. package/dist/plugin-sdk/speech.js +26 -26
  496. package/dist/plugin-sdk/src/channels/plugins/setup-wizard-helpers.d.ts +3 -0
  497. package/dist/plugin-sdk/src/config/config-lock.d.ts +38 -0
  498. package/dist/plugin-sdk/src/config/config.d.ts +1 -1
  499. package/dist/plugin-sdk/src/config/io.d.ts +39 -0
  500. package/dist/plugin-sdk/src/config/types.gateway.d.ts +12 -0
  501. package/dist/plugin-sdk/src/config/types.secrets.d.ts +10 -0
  502. package/dist/plugin-sdk/src/config/zod-schema.d.ts +2 -0
  503. package/dist/plugin-sdk/src/gateway/credential-planner.d.ts +3 -1
  504. package/dist/plugin-sdk/src/secrets/provider-env-vars.d.ts +61 -0
  505. package/dist/plugin-sdk/src/secrets/sec1-placeholder.d.ts +181 -0
  506. package/dist/plugin-sdk/src/secrets/sec1-utils.d.ts +57 -0
  507. package/dist/plugin-sdk/synology-chat.js +27 -27
  508. package/dist/plugin-sdk/telegram.js +26 -26
  509. package/dist/plugin-sdk/text-runtime.js +4 -4
  510. package/dist/plugin-sdk/tlon.js +27 -27
  511. package/dist/plugin-sdk/twitch.js +26 -26
  512. package/dist/plugin-sdk/voice-call.js +26 -26
  513. package/dist/plugin-sdk/whatsapp.js +26 -26
  514. package/dist/plugin-sdk/zalo.js +30 -30
  515. package/dist/plugin-sdk/zalouser.js +29 -29
  516. package/dist/plugins/runtime/index.d.ts +22 -0
  517. package/dist/plugins/runtime/index.js +26 -26
  518. package/dist/plugins-C4PiDdjc.js +106 -0
  519. package/dist/plugins-cli-zhmliYNU.js +912 -0
  520. package/dist/policy-CcSolumc.js +143 -0
  521. package/dist/preflight-audio.runtime-BAbfqqzW.js +111 -0
  522. package/dist/probe-Bgt5c-cr.js +129 -0
  523. package/dist/probe-CPk5iGcg.js +47 -0
  524. package/dist/probe-DR4KRKXz.js +19 -0
  525. package/dist/probe-DnoCyJ_m.js +1793 -0
  526. package/dist/probe-VsLtK3vQ.js +6328 -0
  527. package/dist/probe-auth-BnsKrQt7.js +38 -0
  528. package/dist/probe-auth-DYdUG8l1.js +48 -0
  529. package/dist/program-8enYYBsc.js +247 -0
  530. package/dist/prompt-select-styled-DxBcUasv.js +2673 -0
  531. package/dist/provider-api-key-auth.runtime-DsLZyt6h.js +116 -0
  532. package/dist/provider-auth-choice-30EvRxqc.js +126 -0
  533. package/dist/provider-auth-choice-preference-DMr1WmRg.js +189 -0
  534. package/dist/provider-auth-choice.runtime-CI98BgQF.js +118 -0
  535. package/dist/provider-auth-guidance-WKDIi_wk.js +34 -0
  536. package/dist/provider-auth-result-Cs8wguSI.d.ts +18 -0
  537. package/dist/provider-models-EOys_Nvi.d.ts +867 -0
  538. package/dist/provider-ollama-setup-D89zlm9C.d.ts +32 -0
  539. package/dist/provider-onboard-BzOpgCLu.d.ts +40 -0
  540. package/dist/provider-runtime.runtime-Cm4as2KG.js +106 -0
  541. package/dist/provider-self-hosted-setup-Bmv_AQmw.d.ts +61 -0
  542. package/dist/provider-self-hosted-setup-CJwFVVB4.js +182 -0
  543. package/dist/provider-usage-CVNyLLDb.js +106 -0
  544. package/dist/provider-usage.types-CdTymHNu.d.ts +16 -0
  545. package/dist/provider-web-search-BJhXD5dH.js +2392 -0
  546. package/dist/provider-wizard-DMMYXjlW.js +152 -0
  547. package/dist/push-apns-BnWTdTEk.js +1038 -0
  548. package/dist/pw-ai-CtK_7Cy2.js +1866 -0
  549. package/dist/qr-cli-CA-BF0--.js +108 -0
  550. package/dist/qr-cli-D18HiUkh.js +369 -0
  551. package/dist/reactions-Df7XG8Uh.js +281 -0
  552. package/dist/read-only-account-inspect.discord.runtime-B-FP0mwb.js +111 -0
  553. package/dist/read-only-account-inspect.slack.runtime-DkWZ2ccW.js +111 -0
  554. package/dist/read-only-account-inspect.telegram.runtime-BnlTkn_e.js +111 -0
  555. package/dist/redact-snapshot-DVdstBvO.js +2661 -0
  556. package/dist/ref-contract-RPkB754Q.js +53 -0
  557. package/dist/register.agent-DVAxXQKW.js +434 -0
  558. package/dist/register.backup-CUuL5KUZ.js +624 -0
  559. package/dist/register.configure-bC0UEwfU.js +247 -0
  560. package/dist/register.maintenance-iIqvl_eT.js +569 -0
  561. package/dist/register.message-CEDd4z07.js +704 -0
  562. package/dist/register.onboard-Cejfnysy.js +187 -0
  563. package/dist/register.setup-DU7uHdYt.js +207 -0
  564. package/dist/register.status-health-sessions-BWphMXNR.js +493 -0
  565. package/dist/register.subclis-DnIweTEG.js +315 -0
  566. package/dist/register.subclis-gJX_Pbub.js +12 -0
  567. package/dist/registry-Dgwc-7eS.js +1183 -0
  568. package/dist/replies-D9PEZ8yn.js +110 -0
  569. package/dist/reply-history-lHgoC4l3.d.ts +1 -0
  570. package/dist/reply-payload-Bd2HuR4g.d.ts +46 -0
  571. package/dist/request-url-BcSJaiiu.d.ts +5 -0
  572. package/dist/resolve-BbsCHGLY.js +660 -0
  573. package/dist/resolve-channels-BtrGC95o.js +262 -0
  574. package/dist/resolve-channels-C1SthO1N.js +226 -0
  575. package/dist/resolve-users-CgSxHrU0.js +143 -0
  576. package/dist/routes-BZtqNrBf.js +7097 -0
  577. package/dist/rpc-D3KMxG4J.js +67 -0
  578. package/dist/run-command-C8b3dCZV.d.ts +16 -0
  579. package/dist/run-main-BlWJVotF.js +423 -0
  580. package/dist/runtime-RWGbO5Qy.d.ts +26 -0
  581. package/dist/runtime-discord-ops.runtime-DUXIYvQr.js +9073 -0
  582. package/dist/runtime-slack-ops.runtime-n1yFfyp1.js +4551 -0
  583. package/dist/runtime-telegram-ops.runtime-PZUWchjT.js +128 -0
  584. package/dist/runtime-whatsapp-login.runtime-xsuNyvGz.js +109 -0
  585. package/dist/runtime-whatsapp-outbound.runtime-5EfEyCsO.js +112 -0
  586. package/dist/sandbox-cli-Dw1nWNmQ.js +530 -0
  587. package/dist/search-manager-BJoRxOaf.js +15 -0
  588. package/dist/search-manager-DxkQvUrW.js +386 -0
  589. package/dist/secret-input-schema-Cp_La9qv.d.ts +19 -0
  590. package/dist/secrets-cli-BPyV2gSq.js +2065 -0
  591. package/dist/security-cli-EK4sSRfG.js +570 -0
  592. package/dist/send-B01Gvh9m.js +629 -0
  593. package/dist/send-B4L4wRJO.js +100 -0
  594. package/dist/send-BDcGrXt0.js +1025 -0
  595. package/dist/send-BRRtHxyR.js +283 -0
  596. package/dist/send-DU6dmMXW.js +631 -0
  597. package/dist/server-CWw5GFEg.js +106 -0
  598. package/dist/server-node-events-92cDVswC.js +501 -0
  599. package/dist/session-key-DbkfhOjM.d.ts +46 -0
  600. package/dist/sessions-B052uHA3.js +218 -0
  601. package/dist/sessions-Cef4dZNP.js +107 -0
  602. package/dist/setup-BlQPyDPy.js +387 -0
  603. package/dist/setup-DcSZ_pTn.d.ts +37 -0
  604. package/dist/setup-core-B9mdZYnU.js +166 -0
  605. package/dist/setup-core-Cj0sLkpP.js +47 -0
  606. package/dist/setup-core-CkZbebOv.js +143 -0
  607. package/dist/setup-core-MRNjnrJl.js +205 -0
  608. package/dist/setup-surface-3ZY0JtWE.js +490 -0
  609. package/dist/setup-wizard-helpers-Dwzb9Dcz.d.ts +203 -0
  610. package/dist/setup.finalize-B5ETm3Ui.js +517 -0
  611. package/dist/setup.gateway-config-C8hdtlbw.js +338 -0
  612. package/dist/setup.secret-input-BZSIeiqy.js +25 -0
  613. package/dist/shared--9_eQ_lc.js +75 -0
  614. package/dist/shared-CxkH3H0U.js +102 -0
  615. package/dist/shared-DTNL0hA9.js +298 -0
  616. package/dist/shared-HSP1OV-Q.js +96 -0
  617. package/dist/shared-UIjWb_3B.js +182 -0
  618. package/dist/signal-CTI6bSmB.js +109 -0
  619. package/dist/skills-4-r1mfJM.js +853 -0
  620. package/dist/skills-RNm54CBO.js +19 -0
  621. package/dist/skills-cli-te7dSs5p.js +291 -0
  622. package/dist/skills-install-Del-Ogv8.js +763 -0
  623. package/dist/skills-status-BZpoMXrR.js +169 -0
  624. package/dist/skills-status-Dq61Sz8U.js +20 -0
  625. package/dist/slack-oc-viUtl.js +109 -0
  626. package/dist/slash-commands.runtime-NdkD2LZV.js +123 -0
  627. package/dist/slash-dispatch.runtime-DQgeaF3J.js +136 -0
  628. package/dist/slash-skill-commands.runtime-DmOl2DnL.js +111 -0
  629. package/dist/src-0wtt7seR.js +1696 -0
  630. package/dist/status-5oR_gqv_.js +121 -0
  631. package/dist/status-BO8LY0hC.js +1599 -0
  632. package/dist/status-D_oHA9yO.js +126 -0
  633. package/dist/status-IrMacJRj.js +606 -0
  634. package/dist/status-Prdeg53E.js +43 -0
  635. package/dist/status-json-Da0hR-1Z.js +286 -0
  636. package/dist/status.link-channel-BgUJEZAz.js +138 -0
  637. package/dist/status.scan.deps.runtime-D9vHTxOW.js +121 -0
  638. package/dist/status.scan.runtime-D-EdD5CW.js +114 -0
  639. package/dist/status.summary--i6xduWH.js +592 -0
  640. package/dist/status.summary.runtime-BqMXjaBc.js +113 -0
  641. package/dist/subagent-orphan-recovery-DiRJcFQc.js +302 -0
  642. package/dist/subagent-registry-runtime-B66EYEYm.js +106 -0
  643. package/dist/synology-chat-BemXqdzG.js +297 -0
  644. package/dist/system-cli-CSuiia4-.js +92 -0
  645. package/dist/telegram/audit.d.ts +2 -0
  646. package/dist/telegram/audit.js +1 -1
  647. package/dist/telegram/token.d.ts +2 -0
  648. package/dist/telegram/token.js +26 -26
  649. package/dist/telegram-DLFcRv5a.js +109 -0
  650. package/dist/testing-DZrulv-n.d.ts +1755 -0
  651. package/dist/text-chunking-BaYBIUoR.d.ts +79 -0
  652. package/dist/text-chunking-C8kmbNfa.js +84 -0
  653. package/dist/thinking-D8aqmr3o.d.ts +13 -0
  654. package/dist/tlon-Bpr4f3yF.js +433 -0
  655. package/dist/tool-send-BHKm5ztm.d.ts +9 -0
  656. package/dist/tui-BY3QRgC1.js +3834 -0
  657. package/dist/tui-cli-CCfZOlV0.js +132 -0
  658. package/dist/types-CKx5nDZB.d.ts +45 -0
  659. package/dist/types-DBhDdMQd.d.ts +22670 -0
  660. package/dist/types.base-B_TkkSS8.d.ts +188 -0
  661. package/dist/types.secrets-Bojc4omL.js +92 -0
  662. package/dist/ui-1UpZZyI3.js +31 -0
  663. package/dist/update-BR4JvFpV.js +1036 -0
  664. package/dist/update-cli-BZv44lFq.js +1498 -0
  665. package/dist/update-offset-store-DGdBotIW.js +107 -0
  666. package/dist/update-runner-D34sooPe.js +1496 -0
  667. package/dist/vllm-defaults-BCGSJ7K0.d.ts +13 -0
  668. package/dist/wait-BU9vJv22.d.ts +4 -0
  669. package/dist/web-CXpU2D41.js +107 -0
  670. package/dist/web-shared-B4sL45ah.d.ts +45 -0
  671. package/dist/webhook-memory-guards-B7oLVseG.d.ts +43 -0
  672. package/dist/webhook-request-guards-CqIH7equ.d.ts +76 -0
  673. package/dist/webhook-targets-CAAGATtk.js +181 -0
  674. package/dist/webhook-targets-oQ0jd4r0.d.ts +106 -0
  675. package/dist/webhooks-cli-B46t2VT5.js +349 -0
  676. package/dist/whatsapp-Dniwd4Rv.js +109 -0
  677. package/dist/whatsapp-actions-fL46PsNs.js +162 -0
  678. package/dist/windows-spawn-DGeE98SH.d.ts +43 -0
  679. package/dist/workspace-dirs-d3Ms_ryk.js +2002 -0
  680. package/dist/zalo-Csulx0XK.d.ts +9 -0
  681. package/dist/zalo-gh0yAWmS.js +415 -0
  682. package/dist/zalouser-CuxRvztM.js +30911 -0
  683. package/dist/zod-schema.agent-runtime-B4MkB-_3.d.ts +10 -0
  684. package/dist/zod-schema.core-D5reNip6.js +541 -0
  685. package/dist/zod-schema.core-DN3RhEUG.d.ts +173 -0
  686. package/docs/SEC1.md +523 -0
  687. package/docs/SEC1_IMPLEMENTATION/CHANNELS_REPORT.md +173 -0
  688. package/docs/SEC1_IMPLEMENTATION/CORE_UTIL_REPORT.md +139 -0
  689. package/docs/SEC1_IMPLEMENTATION/DOCS_REPORT.md +134 -0
  690. package/docs/SEC1_IMPLEMENTATION/ENV_MAP_DRAFT.md +148 -0
  691. package/docs/SEC1_IMPLEMENTATION/INTEGRATION_REPORT.md +170 -0
  692. package/docs/SEC1_IMPLEMENTATION/PROVIDERS_REPORT.md +291 -0
  693. package/docs/SEC1_IMPLEMENTATION/QA_REPORT.md +249 -0
  694. package/docs/SEC1_IMPLEMENTATION/RECURSIVE_QA/wave1-channels.md +317 -0
  695. package/docs/SEC1_IMPLEMENTATION/RECURSIVE_QA/wave1-docs.md +212 -0
  696. package/docs/SEC1_IMPLEMENTATION/RECURSIVE_QA/wave1-security.md +368 -0
  697. package/docs/SEC1_IMPLEMENTATION/RECURSIVE_QA/wave2-critic-consolidated.md +195 -0
  698. package/docs/SEC1_IMPLEMENTATION/RECURSIVE_QA/wave3-fix-report.md +105 -0
  699. package/docs/SEC1_IMPLEMENTATION/STRATEGY.md +451 -0
  700. package/docs/SEC1_IMPLEMENTATION/TEST_REPORT.md +156 -0
  701. package/docs/pipeline-sdk/CLI_SPEC.md +609 -0
  702. package/docs/pipeline-sdk/PIPELINE_SDK_DESIGN.md +1372 -0
  703. package/extensions/kakao-talkchannel/MIGRATION_ARCH_ANALYSIS.md +455 -0
  704. package/extensions/kakao-talkchannel/MIGRATION_CODE_ANALYSIS.md +383 -0
  705. package/extensions/kakao-talkchannel/MIGRATION_STRATEGY.md +115 -0
  706. package/extensions/kakao-talkchannel/README.md +50 -0
  707. package/extensions/kakao-talkchannel/index.ts +20 -0
  708. package/extensions/kakao-talkchannel/moldclaw.plugin.json +98 -0
  709. package/extensions/kakao-talkchannel/package.json +12 -0
  710. package/extensions/kakao-talkchannel/src/adapters/config.ts +132 -0
  711. package/extensions/kakao-talkchannel/src/adapters/gateway.ts +974 -0
  712. package/extensions/kakao-talkchannel/src/adapters/outbound.ts +52 -0
  713. package/extensions/kakao-talkchannel/src/adapters/pairing.ts +35 -0
  714. package/extensions/kakao-talkchannel/src/adapters/security.ts +57 -0
  715. package/extensions/kakao-talkchannel/src/adapters/setup.ts +105 -0
  716. package/extensions/kakao-talkchannel/src/adapters/status.ts +117 -0
  717. package/extensions/kakao-talkchannel/src/channel.ts +58 -0
  718. package/extensions/kakao-talkchannel/src/commands/card.ts +413 -0
  719. package/extensions/kakao-talkchannel/src/config/schema.ts +129 -0
  720. package/extensions/kakao-talkchannel/src/kakao/callback.ts +133 -0
  721. package/extensions/kakao-talkchannel/src/kakao/limits.ts +129 -0
  722. package/extensions/kakao-talkchannel/src/kakao/payload.ts +138 -0
  723. package/extensions/kakao-talkchannel/src/kakao/response.ts +373 -0
  724. package/extensions/kakao-talkchannel/src/relay/client.ts +146 -0
  725. package/extensions/kakao-talkchannel/src/relay/session.ts +137 -0
  726. package/extensions/kakao-talkchannel/src/relay/sse.ts +258 -0
  727. package/extensions/kakao-talkchannel/src/relay/stream.ts +149 -0
  728. package/extensions/kakao-talkchannel/src/runtime.ts +21 -0
  729. package/extensions/kakao-talkchannel/src/types.ts +447 -0
  730. package/extensions/kakao-talkchannel/src/version.ts +3 -0
  731. package/extensions/kakao-talkchannel/tsconfig.json +19 -0
  732. package/package.json +23 -8
  733. package/skills/meshy/SKILL.md +69 -0
  734. package/skills/meshy/scripts/__pycache__/check_status.cpython-312.pyc +0 -0
  735. package/skills/meshy/scripts/__pycache__/image_to_3d.cpython-312.pyc +0 -0
  736. package/skills/meshy/scripts/__pycache__/text_to_3d.cpython-312.pyc +0 -0
  737. package/skills/meshy/scripts/check_status.py +147 -0
  738. package/skills/meshy/scripts/image_to_3d.py +229 -0
  739. package/skills/meshy/scripts/text_to_3d.py +214 -0
  740. package/skills/nano-banana-pro/scripts/generate_image.py +1 -1
  741. package/skills/openai-whisper-api/scripts/transcribe.sh +0 -0
  742. package/skills/tavily-search/SKILL.md +61 -0
  743. package/skills/tavily-search/scripts/__pycache__/search.cpython-312.pyc +0 -0
  744. package/skills/tavily-search/scripts/search.py +238 -0
  745. package/skills/video-frames/scripts/frame.sh +0 -0
  746. package/LICENSE +0 -21
  747. package/dist/accounts-UcSvD34O.js +0 -109
  748. package/dist/acp-cli-BPb8PgHP.js +0 -2088
  749. package/dist/actions.runtime-BL5QRooG.js +0 -114
  750. package/dist/actions.runtime-DSdfSo40.js +0 -128
  751. package/dist/agents-CHeX_5-H.js +0 -217
  752. package/dist/agents-DQRL9XKP.js +0 -853
  753. package/dist/allow-list-Boi79v-U.js +0 -81
  754. package/dist/allowlist-B2eBBeMF.js +0 -142
  755. package/dist/api-CFAtRSYL.js +0 -6953
  756. package/dist/api-D5JNJj8n.js +0 -112
  757. package/dist/audit-BM0GsdzV.js +0 -787
  758. package/dist/audit-BqRK9OSj.js +0 -54
  759. package/dist/audit-channel.collect.runtime-BPvDB8aq.js +0 -600
  760. package/dist/audit-channel.runtime-D3fzHiAo.js +0 -116
  761. package/dist/audit-extra.async-NveNIzX0.js +0 -813
  762. package/dist/audit-membership-runtime-mu470WFO.js +0 -157
  763. package/dist/audit.deep.runtime-RdxvW8Tj.js +0 -24
  764. package/dist/audit.nondeep.runtime-DDu8vA9Z.js +0 -831
  765. package/dist/audit.runtime-Y8C9W7s9.js +0 -113
  766. package/dist/auth-choice-C1CIxRsi.js +0 -268
  767. package/dist/auth-choice-CTvqWiDI.js +0 -117
  768. package/dist/auth-choice-Ddzko1B8.js +0 -502
  769. package/dist/auth-choice-options-BIAmAiCe.js +0 -123
  770. package/dist/auth-choice-prompt-B815kArz.js +0 -110
  771. package/dist/auth-choice-prompt-CGhTNCJx.js +0 -36
  772. package/dist/auth-choice.plugin-providers.runtime-AvAZ6S5W.js +0 -114
  773. package/dist/auth-profiles-BJcHzwPy.js +0 -127650
  774. package/dist/auth-profiles.runtime-CieFilK5.js +0 -111
  775. package/dist/bluebubbles-F8FGE9cH.js +0 -64
  776. package/dist/brave-BG5Yopn8.js +0 -24
  777. package/dist/browser-cli-Co7PJGZF.js +0 -1492
  778. package/dist/call-CoaQYq7c.js +0 -639
  779. package/dist/call-D3eu5Jjh.js +0 -37
  780. package/dist/channel-BftWD6yu.js +0 -1321
  781. package/dist/channel-Bub9U5Xg.js +0 -214
  782. package/dist/channel-C0oDs7TO.js +0 -4681
  783. package/dist/channel-C8CnEdkZ.js +0 -352
  784. package/dist/channel-CI-RC-xf.js +0 -497
  785. package/dist/channel-CY-hZCOJ.js +0 -397
  786. package/dist/channel-CbtGJB2x.js +0 -943
  787. package/dist/channel-CcfK3wP8.js +0 -803
  788. package/dist/channel-DBoDIeVj.js +0 -619
  789. package/dist/channel-DEq6Ecs-.js +0 -920
  790. package/dist/channel-DH4dhW1n.js +0 -226
  791. package/dist/channel-DQ_wdKg_.js +0 -575
  792. package/dist/channel-DT6qD1Ic.js +0 -207
  793. package/dist/channel-DZNAyxwr.js +0 -542
  794. package/dist/channel-DtakwAEe.js +0 -538
  795. package/dist/channel-DuYgH6p1.js +0 -562
  796. package/dist/channel-Hn-AN-d52.js +0 -316
  797. package/dist/channel-_R4hbD5h.js +0 -1598
  798. package/dist/channel-account-context-DXq8dlvI.js +0 -103
  799. package/dist/channel-kQmEVn3I.js +0 -306
  800. package/dist/channel-options-DHfxaklg.js +0 -50
  801. package/dist/channel-summary-DUpnoYhI.js +0 -106
  802. package/dist/channel-t-JxCWk6.js +0 -949
  803. package/dist/channel.runtime--GYriaXU.js +0 -213
  804. package/dist/channel.runtime-BJtn3GOH.js +0 -174
  805. package/dist/channel.runtime-BV7t_oNz.js +0 -166
  806. package/dist/channel.runtime-Bi8a3n9S.js +0 -865
  807. package/dist/channel.runtime-BjsYF0NN.js +0 -122
  808. package/dist/channel.runtime-BnI6YtmI.js +0 -413
  809. package/dist/channel.runtime-CQOftcCd.js +0 -194
  810. package/dist/channel.runtime-CuIAcPjZ.js +0 -4006
  811. package/dist/channel.runtime-DH1Q1G4k.js +0 -399
  812. package/dist/channel.runtime-DYYUPKxr.js +0 -236
  813. package/dist/channel.runtime-U5Gszsr5.js +0 -177
  814. package/dist/channel.setup-BQFHmgki.js +0 -9
  815. package/dist/channel.setup-BVoDwklu.js +0 -8
  816. package/dist/channel.setup-Bf73HsXr.js +0 -57
  817. package/dist/channel.setup-CblD4flM.js +0 -11
  818. package/dist/channel.setup-DgxlrPgz.js +0 -6
  819. package/dist/channel.setup-GLIAEVKL.js +0 -8
  820. package/dist/channel.setup-YTy5R1sz.js +0 -9
  821. package/dist/channels-CTL8iR9J.js +0 -404
  822. package/dist/channels-DBGvnjHY.js +0 -1113
  823. package/dist/channels-cli-BmVO5-sq.js +0 -286
  824. package/dist/channels-status-issues-kDtsWzA-.js +0 -16
  825. package/dist/clawbot-cli-DtcMJHqX.js +0 -113
  826. package/dist/cli-BNGECGVY.js +0 -149
  827. package/dist/command-registry-1SDrWgER.js +0 -13
  828. package/dist/command-registry-DNorYU4w.js +0 -212
  829. package/dist/command-secret-gateway-DqDZparO.js +0 -106
  830. package/dist/compact.runtime-C1ZN8UGb.js +0 -111
  831. package/dist/completion-cli-Q_Jt5Foc.js +0 -16
  832. package/dist/completion-cli-QkTXhuJh.js +0 -445
  833. package/dist/config-BbxrRaLf.js +0 -938
  834. package/dist/config-CkD8DJ7L.js +0 -44
  835. package/dist/config-cli-BoPrlYTp.js +0 -428
  836. package/dist/config-guard-CEhCvr_u.js +0 -117
  837. package/dist/config-schema-GQ6uWjXe.js +0 -31
  838. package/dist/config-validation-woE2_LpC.js +0 -262
  839. package/dist/config-value-Dh8m-CFf.js +0 -132
  840. package/dist/config-y4i5g7s4.js +0 -30
  841. package/dist/configure-DGRzwdFN.js +0 -1100
  842. package/dist/configure-S4AHE3k_.js +0 -238
  843. package/dist/control-ui-shared-kLBp4YlS.js +0 -29
  844. package/dist/credentials-D5uBf_C5.js +0 -265
  845. package/dist/cron-cli-lGupeVCW.js +0 -634
  846. package/dist/daemon-cli-Cs_edi0I.js +0 -339
  847. package/dist/daemon-install-DIFpP_qv.js +0 -175
  848. package/dist/deliver-DYa_DFZU.js +0 -106
  849. package/dist/deliver-runtime-DCW_o2Ot.js +0 -106
  850. package/dist/devices-cli-YsGOW2-w.js +0 -340
  851. package/dist/diagnostic-vMghIesG.js +0 -310
  852. package/dist/directory-cli-DtjMQjU5.js +0 -306
  853. package/dist/directory.static-DBZGvsdF.js +0 -44
  854. package/dist/discord-DYCu19HT.js +0 -109
  855. package/dist/discovery-DZYAoDF_.js +0 -48
  856. package/dist/dns-cli-DqW4pNgW.js +0 -216
  857. package/dist/docs-cli-Bu9TBlDU.js +0 -173
  858. package/dist/doctor-completion-B5hcQD5c.js +0 -90
  859. package/dist/doctor-config-flow-BBB2ZKfT.js +0 -107
  860. package/dist/doctor-config-flow-DDBYUS9f.js +0 -2437
  861. package/dist/enable-Tmsp8QuB.js +0 -24
  862. package/dist/env-overrides-BHxqjYZG.js +0 -434
  863. package/dist/env-overrides.runtime-Cz98bf-l.js +0 -17
  864. package/dist/exec-approvals-cli-wO5cYfMa.js +0 -419
  865. package/dist/gateway-cli-CFvDGhB9.js +0 -26429
  866. package/dist/gateway-install-token-CskJfo_N.js +0 -163
  867. package/dist/gateway-rpc-srYfBID9.js +0 -26
  868. package/dist/gateway-runtime-C76hUmUV.js +0 -69
  869. package/dist/googlechat-Cha5utST.js +0 -307
  870. package/dist/health-DDQYYsJy.js +0 -108
  871. package/dist/health-DXZykGaX.js +0 -570
  872. package/dist/hooks-cli-DfkurPYP.js +0 -995
  873. package/dist/imessage-B26k39pl.js +0 -110
  874. package/dist/imessage-Bp1_6cws.js +0 -31
  875. package/dist/inbound-reply-dispatch-DoIJLztA.js +0 -71
  876. package/dist/install-target-BjOuS4I8.js +0 -574
  877. package/dist/installs-Cz4k0W1Y.js +0 -532
  878. package/dist/io-B0OKifLZ.js +0 -28
  879. package/dist/io-DcoxdH6t.js +0 -9570
  880. package/dist/ipv4-CTQQ4_IW.js +0 -82
  881. package/dist/irc-B8vBDigm.js +0 -672
  882. package/dist/library-VCM_cQY4.js +0 -107
  883. package/dist/lifecycle-core-Ctz36PdQ.js +0 -382
  884. package/dist/line-B_uTLrdI.js +0 -530
  885. package/dist/llm-slug-generator-YWg0g2pj.js +0 -67
  886. package/dist/logging-S-5LPdfQ.js +0 -13
  887. package/dist/logging-ueBMCGMR.js +0 -29
  888. package/dist/login-qr-pcACm2Ng.js +0 -107
  889. package/dist/login-qr-pv-kxMfF.js +0 -233
  890. package/dist/logs-cli-RgADgSMO.js +0 -254
  891. package/dist/manager-runtime-BhTkoKmb.js +0 -106
  892. package/dist/manager.runtime-BjHzikoK.js +0 -710
  893. package/dist/matrix-C4EEu2Qp.js +0 -1490
  894. package/dist/matrix-Dfzcc5nV.js +0 -1269
  895. package/dist/mcp-cli-CJmOm9Oj.js +0 -86
  896. package/dist/media-understanding.runtime-DCETFCw_.js +0 -111
  897. package/dist/memory-cli-DFqd6tYx.js +0 -106
  898. package/dist/method-scopes-D-Q9dvbj.js +0 -2586
  899. package/dist/model-picker-Z-CUcuMr.js +0 -390
  900. package/dist/model-picker-v5mUsZ4J.js +0 -107
  901. package/dist/model-picker.runtime-A_z0dHfS.js +0 -120
  902. package/dist/model-suppression.runtime-QVWVJRr-.js +0 -111
  903. package/dist/models-Bbj0xV4F.js +0 -2514
  904. package/dist/models-D-OIjZqU.js +0 -113
  905. package/dist/models-cli-Bpn-5i4h.js +0 -304
  906. package/dist/models-config-Cwa5cJbC.js +0 -106
  907. package/dist/monitor-BchfCAaU.js +0 -6823
  908. package/dist/monitor-BydV44SP.js +0 -3076
  909. package/dist/monitor-CT8axwfm.js +0 -767
  910. package/dist/monitor-CZGWNOvn.js +0 -777
  911. package/dist/monitor-DN62r69g.js +0 -3468
  912. package/dist/monitor-DZ0fzJku.js +0 -110
  913. package/dist/monitor-DvNjzWFu.js +0 -108
  914. package/dist/monitor-shared-B-DBSlkQ.js +0 -444
  915. package/dist/msteams-Bf-wk2Rp.js +0 -852
  916. package/dist/node-cli-kH16TQI7.js +0 -2498
  917. package/dist/node-resolve-DfOpQmxm.js +0 -835
  918. package/dist/nodes-cli-CkAMXW5u.js +0 -1375
  919. package/dist/nostr-B8UGHclZ.js +0 -8744
  920. package/dist/npm-resolution-DmjlifII.js +0 -60
  921. package/dist/onboard-C883nfyw.js +0 -589
  922. package/dist/onboard-channels-Dc-BxN7p.js +0 -200
  923. package/dist/onboard-channels-j5EENtum.js +0 -1241
  924. package/dist/onboard-custom-0atne0C5.js +0 -571
  925. package/dist/onboard-custom-CWMqwjJx.js +0 -109
  926. package/dist/onboard-helpers-D3wWfH8F.js +0 -335
  927. package/dist/onboard-helpers-DZmRCe8l.js +0 -108
  928. package/dist/onboard-remote-Cn6kW-p0.js +0 -112
  929. package/dist/onboard-remote-Cx4w5VAk.js +0 -181
  930. package/dist/onboard-search-Ck9HRh2M.js +0 -297
  931. package/dist/onboard-skills-BtqrGioT.js +0 -133
  932. package/dist/onboard-skills-Dnw19Os8.js +0 -112
  933. package/dist/outbound-media-C5Nv4o18.js +0 -11
  934. package/dist/pairing-cli-Cwy9QZ_4.js +0 -212
  935. package/dist/perplexity-Brhpb45X.js +0 -24
  936. package/dist/pi-model-discovery-runtime-DIOdo6D8.js +0 -106
  937. package/dist/pi-tools.before-tool-call.runtime-CFM4gsDF.js +0 -380
  938. package/dist/plugin-install-BOV00hia.js +0 -112
  939. package/dist/plugin-install-Bak8fUBv.js +0 -184
  940. package/dist/plugin-install-plan-bKkEefRf.js +0 -49
  941. package/dist/plugin-registry-DxAXQUlZ.js +0 -108
  942. package/dist/plugin-registry-n0p3phem.js +0 -49
  943. package/dist/plugins-Ca3RK8Fi.js +0 -106
  944. package/dist/plugins-cli-BnC51H2R.js +0 -912
  945. package/dist/policy-BJv97w9e.js +0 -143
  946. package/dist/preflight-audio.runtime-BrFcf-6_.js +0 -111
  947. package/dist/probe-063xvvZc.js +0 -19
  948. package/dist/probe-BJEb2wGv.js +0 -1793
  949. package/dist/probe-CJQlxgsl.js +0 -47
  950. package/dist/probe-Caa2HznF.js +0 -6328
  951. package/dist/probe-CfL4tnJ6.js +0 -129
  952. package/dist/probe-auth-DN2Ec83-.js +0 -38
  953. package/dist/probe-auth-D_UKzu4m.js +0 -48
  954. package/dist/program-BOMdC7MC.js +0 -247
  955. package/dist/prompt-select-styled-DDnCfM3j.js +0 -2673
  956. package/dist/provider-api-key-auth.runtime-DUns3fwX.js +0 -116
  957. package/dist/provider-auth-choice-B_j1ctT2.js +0 -126
  958. package/dist/provider-auth-choice-preference-BaOBZ_Xn.js +0 -189
  959. package/dist/provider-auth-choice.runtime-DOako_zV.js +0 -118
  960. package/dist/provider-auth-guidance-CrjxnoNZ.js +0 -34
  961. package/dist/provider-runtime.runtime-BkOkgmTw.js +0 -106
  962. package/dist/provider-self-hosted-setup-BFDU6dRa.js +0 -182
  963. package/dist/provider-usage-CaDE0mqq.js +0 -106
  964. package/dist/provider-web-search-BR7etTjJ.js +0 -2392
  965. package/dist/provider-wizard-DCPdKUvb.js +0 -152
  966. package/dist/push-apns-B_OZjm4v.js +0 -1038
  967. package/dist/pw-ai-dG60P0hQ.js +0 -1866
  968. package/dist/qr-cli-DWfiw79I.js +0 -369
  969. package/dist/qr-cli-DwuKtyZQ.js +0 -108
  970. package/dist/reactions-CIGAPBn8.js +0 -281
  971. package/dist/read-only-account-inspect.discord.runtime-D54mnq8l.js +0 -111
  972. package/dist/read-only-account-inspect.slack.runtime-Bxs9ObMC.js +0 -111
  973. package/dist/read-only-account-inspect.telegram.runtime-UoVuf_Yo.js +0 -111
  974. package/dist/redact-snapshot-DZ3Vq-SC.js +0 -2657
  975. package/dist/ref-contract-D96lSYLs.js +0 -53
  976. package/dist/register.agent-2KmeahEL.js +0 -434
  977. package/dist/register.backup-ECBnWVR7.js +0 -624
  978. package/dist/register.configure-Doz1daCp.js +0 -247
  979. package/dist/register.maintenance-C33cV-WM.js +0 -569
  980. package/dist/register.message-CnL0NiF6.js +0 -704
  981. package/dist/register.onboard-BrYGZeQA.js +0 -187
  982. package/dist/register.setup-Bx6gEg6X.js +0 -207
  983. package/dist/register.status-health-sessions-FLb0CUOO.js +0 -493
  984. package/dist/register.subclis-BuqgaeIf.js +0 -12
  985. package/dist/register.subclis-DwdgfdnT.js +0 -315
  986. package/dist/registry-xhgvU89y.js +0 -1107
  987. package/dist/replies-hB2aipLu.js +0 -110
  988. package/dist/resolve-3ErMOltL.js +0 -660
  989. package/dist/resolve-channels-BV8GXuPe.js +0 -226
  990. package/dist/resolve-channels-CTY_XRIP.js +0 -262
  991. package/dist/resolve-users-DQ4Ne4Zc.js +0 -143
  992. package/dist/routes-BNDsNO_e.js +0 -7097
  993. package/dist/rpc-BLGTBWXq.js +0 -67
  994. package/dist/run-main-COAE4GlI.js +0 -423
  995. package/dist/runtime-discord-ops.runtime-Dxg-nlgd.js +0 -9073
  996. package/dist/runtime-slack-ops.runtime-Di474LJr.js +0 -4551
  997. package/dist/runtime-telegram-ops.runtime-Da8vgf3O.js +0 -128
  998. package/dist/runtime-whatsapp-login.runtime-DcouP4iF.js +0 -109
  999. package/dist/runtime-whatsapp-outbound.runtime-CYamaEJX.js +0 -112
  1000. package/dist/sandbox-cli-U5ZTxhxL.js +0 -530
  1001. package/dist/search-manager-CfizyEMk.js +0 -386
  1002. package/dist/search-manager-DaF2QP4s.js +0 -15
  1003. package/dist/secrets-cli-C0gytFip.js +0 -2065
  1004. package/dist/security-cli-C74EuLUO.js +0 -570
  1005. package/dist/send-BTLVBf_E.js +0 -631
  1006. package/dist/send-BlWWCEZE.js +0 -1025
  1007. package/dist/send-CfypD1B_.js +0 -100
  1008. package/dist/send-Cm9v3uhF.js +0 -283
  1009. package/dist/send-g2odQuYI.js +0 -629
  1010. package/dist/server-C8b5QJ2s.js +0 -106
  1011. package/dist/server-node-events-xqQe5xiu.js +0 -501
  1012. package/dist/sessions-CSSzvgPQ.js +0 -107
  1013. package/dist/sessions-z0GIvdKa.js +0 -218
  1014. package/dist/setup-D9XTmlF8.js +0 -387
  1015. package/dist/setup-core-BDrLOwYO.js +0 -143
  1016. package/dist/setup-core-CM7cY7_i.js +0 -166
  1017. package/dist/setup-core-CnmgANY-.js +0 -205
  1018. package/dist/setup-core-DgcjCKmG.js +0 -47
  1019. package/dist/setup-surface-DzRrVKYj.js +0 -490
  1020. package/dist/setup.finalize-UaPu_adv.js +0 -517
  1021. package/dist/setup.gateway-config-Djc1ceEh.js +0 -338
  1022. package/dist/setup.secret-input-BkczghbR.js +0 -25
  1023. package/dist/shared-BHizGoNk.js +0 -298
  1024. package/dist/shared-CUfYhQkP.js +0 -96
  1025. package/dist/shared-DYYqr9EC.js +0 -75
  1026. package/dist/shared-DthOxMRQ.js +0 -182
  1027. package/dist/shared-On_A5_hW.js +0 -102
  1028. package/dist/signal-D6px9PGZ.js +0 -109
  1029. package/dist/skills-B4h1k-SP.js +0 -853
  1030. package/dist/skills-Bto10BGB.js +0 -19
  1031. package/dist/skills-cli-CXGR3Y5j.js +0 -291
  1032. package/dist/skills-install-B1AlkK8C.js +0 -763
  1033. package/dist/skills-status-BsmJ_iSg.js +0 -20
  1034. package/dist/skills-status-DGdxY3OI.js +0 -169
  1035. package/dist/slack-B7vWFmxP.js +0 -109
  1036. package/dist/slash-commands.runtime-DXdAT84n.js +0 -123
  1037. package/dist/slash-dispatch.runtime-CNf2-9Aj.js +0 -136
  1038. package/dist/slash-skill-commands.runtime-CBjffHRX.js +0 -111
  1039. package/dist/src-Cp7P7T08.js +0 -1696
  1040. package/dist/status-158fWh4A.js +0 -43
  1041. package/dist/status-BJIVLJnb.js +0 -1599
  1042. package/dist/status-BQiBI6N9.js +0 -126
  1043. package/dist/status-CZipXGUu.js +0 -121
  1044. package/dist/status-ZZIVFLI-.js +0 -606
  1045. package/dist/status-json-BNUy5Mem.js +0 -286
  1046. package/dist/status.link-channel-B694y1Xu.js +0 -138
  1047. package/dist/status.scan.deps.runtime-BcoKEzQD.js +0 -121
  1048. package/dist/status.scan.runtime-CqScDt-p.js +0 -114
  1049. package/dist/status.summary-AMek7qvI.js +0 -592
  1050. package/dist/status.summary.runtime-XgkcQ_kr.js +0 -113
  1051. package/dist/subagent-orphan-recovery-CrCYTmFC.js +0 -302
  1052. package/dist/subagent-registry-runtime-Cg-YvLx3.js +0 -106
  1053. package/dist/synology-chat-0G85jIqQ.js +0 -297
  1054. package/dist/system-cli-kZtSxKNm.js +0 -92
  1055. package/dist/telegram-DV0Wy89w.js +0 -109
  1056. package/dist/text-chunking-C2J2Oeul.js +0 -84
  1057. package/dist/tlon-DmK1NUVP.js +0 -433
  1058. package/dist/tui-D3bNPLG7.js +0 -3834
  1059. package/dist/tui-cli-DtMp9k_s.js +0 -132
  1060. package/dist/types.secrets-DuSPmmWB.js +0 -80
  1061. package/dist/ui-CeGztSEL.js +0 -31
  1062. package/dist/update-De7VudzP.js +0 -1036
  1063. package/dist/update-cli-BH8Pb-So.js +0 -1498
  1064. package/dist/update-offset-store-syELkdEW.js +0 -107
  1065. package/dist/update-runner-Cq-Q40T9.js +0 -1496
  1066. package/dist/web-CjMtvfSq.js +0 -107
  1067. package/dist/webhook-targets-_jTR0Bb_.js +0 -181
  1068. package/dist/webhooks-cli-DQ6u2Qau.js +0 -349
  1069. package/dist/whatsapp-CyLk16SZ.js +0 -109
  1070. package/dist/whatsapp-actions-Dzr2Wzqw.js +0 -162
  1071. package/dist/workspace-dirs-L1_QQ9mB.js +0 -2002
  1072. package/dist/zalo-CrehfXvK.js +0 -415
  1073. package/dist/zalouser-D1QD-O-I.js +0 -30911
  1074. package/dist/zod-schema.core-CWxzqcUs.js +0 -541
@@ -0,0 +1,3076 @@
1
+ import { Ah as createScopedPairingAccess, Hg as logAckFailure, Nd as resolveDmGroupAccessWithLists, Od as DM_GROUP_ACCESS_REASON, Oh as issuePairingChallenge, Ug as logInboundDrop, Uw as resolveControlCommandGate, Wg as logTypingFailure, bh as readWebhookBodyOrReject, gT as mapAllowFromEntries, kd as readStoreAllowFromForDmPolicy, nh as resolveChannelMediaMaxBytes, oS as resolveAckReaction, r_ as recordPendingHistoryEntryIfEnabled, sg as createReplyPrefixOptions, t_ as evictOldHistoryKeys, vh as createWebhookInFlightLimiter, wv as stripMarkdown } from "./auth-profiles-9zZdaXJK.js";
2
+ import { c as normalizeResolvedSecretInputString, l as normalizeSecretInputString } from "./types.secrets-Bojc4omL.js";
3
+ import { t as parseFiniteNumber } from "./parse-finite-number-D2N9fUBi.js";
4
+ import { t as resolveRequestUrl } from "./request-url-dk3VZOwj.js";
5
+ import { a as resolveWebhookTargetWithAuthOrRejectSync, c as normalizeWebhookPath, n as registerWebhookTargetWithPluginRoute, s as withResolvedWebhookRequestPipeline } from "./webhook-targets-CAAGATtk.js";
6
+ import { a as isAllowedBlueBubblesSender, b as blueBubblesFetchWithTimeout, d as fetchBlueBubblesServerInfo, f as getCachedBlueBubblesPrivateApiStatus, i as formatBlueBubblesChatTarget, m as isBlueBubblesPrivateApiStatusEnabled, p as isBlueBubblesPrivateApiEnabled, r as extractHandleFromChatGuid, s as normalizeBlueBubblesHandle, u as parseBlueBubblesTarget, v as resolveBlueBubblesAccount, x as buildBlueBubblesApiUrl } from "./monitor-shared-CMK9cDOb.js";
7
+ import { r as warnBlueBubbles, t as getBlueBubblesRuntime } from "./runtime-mPbIHn4t.js";
8
+ import { fileURLToPath } from "node:url";
9
+ import { constants } from "node:fs";
10
+ import path from "node:path";
11
+ import os from "node:os";
12
+ import fs$1 from "node:fs/promises";
13
+ import crypto, { createHash, timingSafeEqual } from "node:crypto";
14
+ //#region extensions/bluebubbles/src/account-resolve.ts
15
+ function resolveBlueBubblesServerAccount(params) {
16
+ const account = resolveBlueBubblesAccount({
17
+ cfg: params.cfg ?? {},
18
+ accountId: params.accountId
19
+ });
20
+ const baseUrl = normalizeResolvedSecretInputString({
21
+ value: params.serverUrl,
22
+ path: "channels.bluebubbles.serverUrl"
23
+ }) || normalizeResolvedSecretInputString({
24
+ value: account.config.serverUrl,
25
+ path: `channels.bluebubbles.accounts.${account.accountId}.serverUrl`
26
+ });
27
+ const password = normalizeResolvedSecretInputString({
28
+ value: params.password,
29
+ path: "channels.bluebubbles.password"
30
+ }) || normalizeResolvedSecretInputString({
31
+ value: account.config.password,
32
+ path: `channels.bluebubbles.accounts.${account.accountId}.password`
33
+ });
34
+ if (!baseUrl) throw new Error("BlueBubbles serverUrl is required");
35
+ if (!password) throw new Error("BlueBubbles password is required");
36
+ return {
37
+ baseUrl,
38
+ password,
39
+ accountId: account.accountId,
40
+ allowPrivateNetwork: account.config.allowPrivateNetwork === true
41
+ };
42
+ }
43
+ //#endregion
44
+ //#region extensions/bluebubbles/src/multipart.ts
45
+ function concatUint8Arrays(parts) {
46
+ const totalLength = parts.reduce((acc, part) => acc + part.length, 0);
47
+ const body = new Uint8Array(totalLength);
48
+ let offset = 0;
49
+ for (const part of parts) {
50
+ body.set(part, offset);
51
+ offset += part.length;
52
+ }
53
+ return body;
54
+ }
55
+ async function postMultipartFormData(params) {
56
+ const body = Buffer.from(concatUint8Arrays(params.parts));
57
+ return await blueBubblesFetchWithTimeout(params.url, {
58
+ method: "POST",
59
+ headers: { "Content-Type": `multipart/form-data; boundary=${params.boundary}` },
60
+ body
61
+ }, params.timeoutMs);
62
+ }
63
+ async function assertMultipartActionOk(response, action) {
64
+ if (response.ok) return;
65
+ const errorText = await response.text().catch(() => "");
66
+ throw new Error(`BlueBubbles ${action} failed (${response.status}): ${errorText || "unknown"}`);
67
+ }
68
+ //#endregion
69
+ //#region extensions/bluebubbles/src/send-helpers.ts
70
+ function resolveBlueBubblesSendTarget(raw) {
71
+ const parsed = parseBlueBubblesTarget(raw);
72
+ if (parsed.kind === "handle") return {
73
+ kind: "handle",
74
+ address: normalizeBlueBubblesHandle(parsed.to),
75
+ service: parsed.service
76
+ };
77
+ if (parsed.kind === "chat_id") return {
78
+ kind: "chat_id",
79
+ chatId: parsed.chatId
80
+ };
81
+ if (parsed.kind === "chat_guid") return {
82
+ kind: "chat_guid",
83
+ chatGuid: parsed.chatGuid
84
+ };
85
+ return {
86
+ kind: "chat_identifier",
87
+ chatIdentifier: parsed.chatIdentifier
88
+ };
89
+ }
90
+ function extractBlueBubblesMessageId(payload) {
91
+ if (!payload || typeof payload !== "object") return "unknown";
92
+ const asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : null;
93
+ const record = payload;
94
+ const roots = [
95
+ record,
96
+ asRecord(record.data),
97
+ asRecord(record.result),
98
+ asRecord(record.payload),
99
+ asRecord(record.message),
100
+ Array.isArray(record.data) ? asRecord(record.data[0]) : null
101
+ ];
102
+ for (const root of roots) {
103
+ if (!root) continue;
104
+ const candidates = [
105
+ root.message_id,
106
+ root.messageId,
107
+ root.messageGuid,
108
+ root.message_guid,
109
+ root.guid,
110
+ root.id,
111
+ root.uuid
112
+ ];
113
+ for (const candidate of candidates) {
114
+ if (typeof candidate === "string" && candidate.trim()) return candidate.trim();
115
+ if (typeof candidate === "number" && Number.isFinite(candidate)) return String(candidate);
116
+ }
117
+ }
118
+ return "unknown";
119
+ }
120
+ //#endregion
121
+ //#region extensions/bluebubbles/src/send.ts
122
+ /** Maps short effect names to full Apple effect IDs */
123
+ const EFFECT_MAP = {
124
+ slam: "com.apple.MobileSMS.expressivesend.impact",
125
+ loud: "com.apple.MobileSMS.expressivesend.loud",
126
+ gentle: "com.apple.MobileSMS.expressivesend.gentle",
127
+ invisible: "com.apple.MobileSMS.expressivesend.invisibleink",
128
+ "invisible-ink": "com.apple.MobileSMS.expressivesend.invisibleink",
129
+ "invisible ink": "com.apple.MobileSMS.expressivesend.invisibleink",
130
+ invisibleink: "com.apple.MobileSMS.expressivesend.invisibleink",
131
+ echo: "com.apple.messages.effect.CKEchoEffect",
132
+ spotlight: "com.apple.messages.effect.CKSpotlightEffect",
133
+ balloons: "com.apple.messages.effect.CKHappyBirthdayEffect",
134
+ confetti: "com.apple.messages.effect.CKConfettiEffect",
135
+ love: "com.apple.messages.effect.CKHeartEffect",
136
+ heart: "com.apple.messages.effect.CKHeartEffect",
137
+ hearts: "com.apple.messages.effect.CKHeartEffect",
138
+ lasers: "com.apple.messages.effect.CKLasersEffect",
139
+ fireworks: "com.apple.messages.effect.CKFireworksEffect",
140
+ celebration: "com.apple.messages.effect.CKSparklesEffect"
141
+ };
142
+ function resolveEffectId(raw) {
143
+ if (!raw) return;
144
+ const trimmed = raw.trim().toLowerCase();
145
+ if (EFFECT_MAP[trimmed]) return EFFECT_MAP[trimmed];
146
+ const normalized = trimmed.replace(/[\s_]+/g, "-");
147
+ if (EFFECT_MAP[normalized]) return EFFECT_MAP[normalized];
148
+ const compact = trimmed.replace(/[\s_-]+/g, "");
149
+ if (EFFECT_MAP[compact]) return EFFECT_MAP[compact];
150
+ return raw;
151
+ }
152
+ function resolvePrivateApiDecision(params) {
153
+ const { privateApiStatus, wantsReplyThread, wantsEffect } = params;
154
+ const needsPrivateApi = wantsReplyThread || wantsEffect;
155
+ const canUsePrivateApi = needsPrivateApi && isBlueBubblesPrivateApiStatusEnabled(privateApiStatus);
156
+ const throwEffectDisabledError = wantsEffect && privateApiStatus === false;
157
+ if (!needsPrivateApi || privateApiStatus !== null) return {
158
+ canUsePrivateApi,
159
+ throwEffectDisabledError
160
+ };
161
+ return {
162
+ canUsePrivateApi,
163
+ throwEffectDisabledError,
164
+ warningMessage: `Private API status unknown; sending without ${[wantsReplyThread ? "reply threading" : null, wantsEffect ? "message effects" : null].filter(Boolean).join(" + ")}. Run a status probe to restore private-api features.`
165
+ };
166
+ }
167
+ async function parseBlueBubblesMessageResponse(res) {
168
+ const body = await res.text();
169
+ if (!body) return { messageId: "ok" };
170
+ try {
171
+ return { messageId: extractBlueBubblesMessageId(JSON.parse(body)) };
172
+ } catch {
173
+ return { messageId: "ok" };
174
+ }
175
+ }
176
+ function extractChatGuid(chat) {
177
+ const candidates = [
178
+ chat.chatGuid,
179
+ chat.guid,
180
+ chat.chat_guid,
181
+ chat.identifier,
182
+ chat.chatIdentifier,
183
+ chat.chat_identifier
184
+ ];
185
+ for (const candidate of candidates) if (typeof candidate === "string" && candidate.trim()) return candidate.trim();
186
+ return null;
187
+ }
188
+ function extractChatId(chat) {
189
+ const candidates = [
190
+ chat.chatId,
191
+ chat.id,
192
+ chat.chat_id
193
+ ];
194
+ for (const candidate of candidates) if (typeof candidate === "number" && Number.isFinite(candidate)) return candidate;
195
+ return null;
196
+ }
197
+ function extractChatIdentifierFromChatGuid$1(chatGuid) {
198
+ const parts = chatGuid.split(";");
199
+ if (parts.length < 3) return null;
200
+ const identifier = parts[2]?.trim();
201
+ return identifier ? identifier : null;
202
+ }
203
+ function extractParticipantAddresses(chat) {
204
+ const raw = (Array.isArray(chat.participants) ? chat.participants : null) ?? (Array.isArray(chat.handles) ? chat.handles : null) ?? (Array.isArray(chat.participantHandles) ? chat.participantHandles : null);
205
+ if (!raw) return [];
206
+ const out = [];
207
+ for (const entry of raw) {
208
+ if (typeof entry === "string") {
209
+ out.push(entry);
210
+ continue;
211
+ }
212
+ if (entry && typeof entry === "object") {
213
+ const record = entry;
214
+ const candidate = typeof record.address === "string" && record.address || typeof record.handle === "string" && record.handle || typeof record.id === "string" && record.id || typeof record.identifier === "string" && record.identifier;
215
+ if (candidate) out.push(candidate);
216
+ }
217
+ }
218
+ return out;
219
+ }
220
+ async function queryChats(params) {
221
+ const res = await blueBubblesFetchWithTimeout(buildBlueBubblesApiUrl({
222
+ baseUrl: params.baseUrl,
223
+ path: "/api/v1/chat/query",
224
+ password: params.password
225
+ }), {
226
+ method: "POST",
227
+ headers: { "Content-Type": "application/json" },
228
+ body: JSON.stringify({
229
+ limit: params.limit,
230
+ offset: params.offset,
231
+ with: ["participants"]
232
+ })
233
+ }, params.timeoutMs);
234
+ if (!res.ok) return [];
235
+ const payload = await res.json().catch(() => null);
236
+ const data = payload && typeof payload.data !== "undefined" ? payload.data : null;
237
+ return Array.isArray(data) ? data : [];
238
+ }
239
+ async function resolveChatGuidForTarget(params) {
240
+ if (params.target.kind === "chat_guid") return params.target.chatGuid;
241
+ const normalizedHandle = params.target.kind === "handle" ? normalizeBlueBubblesHandle(params.target.address) : "";
242
+ const targetChatId = params.target.kind === "chat_id" ? params.target.chatId : null;
243
+ const targetChatIdentifier = params.target.kind === "chat_identifier" ? params.target.chatIdentifier : null;
244
+ const limit = 500;
245
+ let participantMatch = null;
246
+ for (let offset = 0; offset < 5e3; offset += limit) {
247
+ const chats = await queryChats({
248
+ baseUrl: params.baseUrl,
249
+ password: params.password,
250
+ timeoutMs: params.timeoutMs,
251
+ offset,
252
+ limit
253
+ });
254
+ if (chats.length === 0) break;
255
+ for (const chat of chats) {
256
+ if (targetChatId != null) {
257
+ const chatId = extractChatId(chat);
258
+ if (chatId != null && chatId === targetChatId) return extractChatGuid(chat);
259
+ }
260
+ if (targetChatIdentifier) {
261
+ const guid = extractChatGuid(chat);
262
+ if (guid) {
263
+ if (guid === targetChatIdentifier) return guid;
264
+ const guidIdentifier = extractChatIdentifierFromChatGuid$1(guid);
265
+ if (guidIdentifier && guidIdentifier === targetChatIdentifier) return guid;
266
+ }
267
+ const identifier = typeof chat.identifier === "string" ? chat.identifier : typeof chat.chatIdentifier === "string" ? chat.chatIdentifier : typeof chat.chat_identifier === "string" ? chat.chat_identifier : "";
268
+ if (identifier && identifier === targetChatIdentifier) return guid ?? extractChatGuid(chat);
269
+ }
270
+ if (normalizedHandle) {
271
+ const guid = extractChatGuid(chat);
272
+ const directHandle = guid ? extractHandleFromChatGuid(guid) : null;
273
+ if (directHandle && directHandle === normalizedHandle) return guid;
274
+ if (!participantMatch && guid) {
275
+ if (guid.includes(";-;")) {
276
+ if (extractParticipantAddresses(chat).map((entry) => normalizeBlueBubblesHandle(entry)).includes(normalizedHandle)) participantMatch = guid;
277
+ }
278
+ }
279
+ }
280
+ }
281
+ }
282
+ return participantMatch;
283
+ }
284
+ /**
285
+ * Creates a new chat (DM) and optionally sends an initial message.
286
+ * Requires Private API to be enabled in BlueBubbles.
287
+ */
288
+ async function createNewChatWithMessage(params) {
289
+ const url = buildBlueBubblesApiUrl({
290
+ baseUrl: params.baseUrl,
291
+ path: "/api/v1/chat/new",
292
+ password: params.password
293
+ });
294
+ const payload = {
295
+ addresses: [params.address],
296
+ message: params.message,
297
+ tempGuid: `temp-${crypto.randomUUID()}`
298
+ };
299
+ const res = await blueBubblesFetchWithTimeout(url, {
300
+ method: "POST",
301
+ headers: { "Content-Type": "application/json" },
302
+ body: JSON.stringify(payload)
303
+ }, params.timeoutMs);
304
+ if (!res.ok) {
305
+ const errorText = await res.text();
306
+ if (res.status === 400 || res.status === 403 || errorText.toLowerCase().includes("private api")) throw new Error(`BlueBubbles send failed: Cannot create new chat - Private API must be enabled. Original error: ${errorText || res.status}`);
307
+ throw new Error(`BlueBubbles create chat failed (${res.status}): ${errorText || "unknown"}`);
308
+ }
309
+ return parseBlueBubblesMessageResponse(res);
310
+ }
311
+ async function sendMessageBlueBubbles(to, text, opts = {}) {
312
+ const trimmedText = text ?? "";
313
+ if (!trimmedText.trim()) throw new Error("BlueBubbles send requires text");
314
+ const strippedText = stripMarkdown(trimmedText);
315
+ if (!strippedText.trim()) throw new Error("BlueBubbles send requires text (message was empty after markdown removal)");
316
+ const account = resolveBlueBubblesAccount({
317
+ cfg: opts.cfg ?? {},
318
+ accountId: opts.accountId
319
+ });
320
+ const baseUrl = normalizeSecretInputString(opts.serverUrl) || normalizeSecretInputString(account.config.serverUrl);
321
+ const password = normalizeSecretInputString(opts.password) || normalizeSecretInputString(account.config.password);
322
+ if (!baseUrl) throw new Error("BlueBubbles serverUrl is required");
323
+ if (!password) throw new Error("BlueBubbles password is required");
324
+ const privateApiStatus = getCachedBlueBubblesPrivateApiStatus(account.accountId);
325
+ const target = resolveBlueBubblesSendTarget(to);
326
+ const chatGuid = await resolveChatGuidForTarget({
327
+ baseUrl,
328
+ password,
329
+ timeoutMs: opts.timeoutMs,
330
+ target
331
+ });
332
+ if (!chatGuid) {
333
+ if (target.kind === "handle") return createNewChatWithMessage({
334
+ baseUrl,
335
+ password,
336
+ address: target.address,
337
+ message: strippedText,
338
+ timeoutMs: opts.timeoutMs
339
+ });
340
+ throw new Error("BlueBubbles send failed: chatGuid not found for target. Use a chat_guid target or ensure the chat exists.");
341
+ }
342
+ const effectId = resolveEffectId(opts.effectId);
343
+ const wantsReplyThread = Boolean(opts.replyToMessageGuid?.trim());
344
+ const privateApiDecision = resolvePrivateApiDecision({
345
+ privateApiStatus,
346
+ wantsReplyThread,
347
+ wantsEffect: Boolean(effectId)
348
+ });
349
+ if (privateApiDecision.throwEffectDisabledError) throw new Error("BlueBubbles send failed: reply/effect requires Private API, but it is disabled on the BlueBubbles server.");
350
+ if (privateApiDecision.warningMessage) warnBlueBubbles(privateApiDecision.warningMessage);
351
+ const payload = {
352
+ chatGuid,
353
+ tempGuid: crypto.randomUUID(),
354
+ message: strippedText
355
+ };
356
+ if (privateApiDecision.canUsePrivateApi) payload.method = "private-api";
357
+ if (wantsReplyThread && privateApiDecision.canUsePrivateApi) {
358
+ payload.selectedMessageGuid = opts.replyToMessageGuid;
359
+ payload.partIndex = typeof opts.replyToPartIndex === "number" ? opts.replyToPartIndex : 0;
360
+ }
361
+ if (effectId && privateApiDecision.canUsePrivateApi) payload.effectId = effectId;
362
+ const res = await blueBubblesFetchWithTimeout(buildBlueBubblesApiUrl({
363
+ baseUrl,
364
+ path: "/api/v1/message/text",
365
+ password
366
+ }), {
367
+ method: "POST",
368
+ headers: { "Content-Type": "application/json" },
369
+ body: JSON.stringify(payload)
370
+ }, opts.timeoutMs);
371
+ if (!res.ok) {
372
+ const errorText = await res.text();
373
+ throw new Error(`BlueBubbles send failed (${res.status}): ${errorText || "unknown"}`);
374
+ }
375
+ return parseBlueBubblesMessageResponse(res);
376
+ }
377
+ //#endregion
378
+ //#region extensions/bluebubbles/src/attachments.ts
379
+ const DEFAULT_ATTACHMENT_MAX_BYTES = 8 * 1024 * 1024;
380
+ const AUDIO_MIME_MP3 = new Set(["audio/mpeg", "audio/mp3"]);
381
+ const AUDIO_MIME_CAF = new Set(["audio/x-caf", "audio/caf"]);
382
+ function sanitizeFilename(input, fallback) {
383
+ const trimmed = input?.trim() ?? "";
384
+ return ((trimmed ? path.basename(trimmed) : "") || fallback).replace(/[\r\n"\\]/g, "_");
385
+ }
386
+ function ensureExtension(filename, extension, fallbackBase) {
387
+ const currentExt = path.extname(filename);
388
+ if (currentExt.toLowerCase() === extension) return filename;
389
+ return `${(currentExt ? filename.slice(0, -currentExt.length) : filename) || fallbackBase}${extension}`;
390
+ }
391
+ function resolveVoiceInfo(filename, contentType) {
392
+ const normalizedType = contentType?.trim().toLowerCase();
393
+ const extension = path.extname(filename).toLowerCase();
394
+ const isMp3 = extension === ".mp3" || (normalizedType ? AUDIO_MIME_MP3.has(normalizedType) : false);
395
+ const isCaf = extension === ".caf" || (normalizedType ? AUDIO_MIME_CAF.has(normalizedType) : false);
396
+ return {
397
+ isAudio: isMp3 || isCaf || Boolean(normalizedType?.startsWith("audio/")),
398
+ isMp3,
399
+ isCaf
400
+ };
401
+ }
402
+ function resolveAccount$3(params) {
403
+ return resolveBlueBubblesServerAccount(params);
404
+ }
405
+ function safeExtractHostname(url) {
406
+ try {
407
+ return new URL(url).hostname.trim() || void 0;
408
+ } catch {
409
+ return;
410
+ }
411
+ }
412
+ function readMediaFetchErrorCode(error) {
413
+ if (!error || typeof error !== "object") return;
414
+ const code = error.code;
415
+ return code === "max_bytes" || code === "http_error" || code === "fetch_failed" ? code : void 0;
416
+ }
417
+ async function downloadBlueBubblesAttachment(attachment, opts = {}) {
418
+ const guid = attachment.guid?.trim();
419
+ if (!guid) throw new Error("BlueBubbles attachment guid is required");
420
+ const { baseUrl, password, allowPrivateNetwork } = resolveAccount$3(opts);
421
+ const url = buildBlueBubblesApiUrl({
422
+ baseUrl,
423
+ path: `/api/v1/attachment/${encodeURIComponent(guid)}/download`,
424
+ password
425
+ });
426
+ const maxBytes = typeof opts.maxBytes === "number" ? opts.maxBytes : DEFAULT_ATTACHMENT_MAX_BYTES;
427
+ const trustedHostname = safeExtractHostname(baseUrl);
428
+ try {
429
+ const fetched = await getBlueBubblesRuntime().channel.media.fetchRemoteMedia({
430
+ url,
431
+ filePathHint: attachment.transferName ?? attachment.guid ?? "attachment",
432
+ maxBytes,
433
+ ssrfPolicy: allowPrivateNetwork ? { allowPrivateNetwork: true } : trustedHostname ? { allowedHostnames: [trustedHostname] } : void 0,
434
+ fetchImpl: async (input, init) => await blueBubblesFetchWithTimeout(resolveRequestUrl(input), {
435
+ ...init,
436
+ method: init?.method ?? "GET"
437
+ }, opts.timeoutMs)
438
+ });
439
+ return {
440
+ buffer: new Uint8Array(fetched.buffer),
441
+ contentType: fetched.contentType ?? attachment.mimeType ?? void 0
442
+ };
443
+ } catch (error) {
444
+ if (readMediaFetchErrorCode(error) === "max_bytes") throw new Error(`BlueBubbles attachment too large (limit ${maxBytes} bytes)`);
445
+ const text = error instanceof Error ? error.message : String(error);
446
+ throw new Error(`BlueBubbles attachment download failed: ${text}`);
447
+ }
448
+ }
449
+ /**
450
+ * Send an attachment via BlueBubbles API.
451
+ * Supports sending media files (images, videos, audio, documents) to a chat.
452
+ * When asVoice is true, expects MP3/CAF audio and marks it as an iMessage voice memo.
453
+ */
454
+ async function sendBlueBubblesAttachment(params) {
455
+ const { to, caption, replyToMessageGuid, replyToPartIndex, asVoice, opts = {} } = params;
456
+ let { buffer, filename, contentType } = params;
457
+ const wantsVoice = asVoice === true;
458
+ const fallbackName = wantsVoice ? "Audio Message" : "attachment";
459
+ filename = sanitizeFilename(filename, fallbackName);
460
+ contentType = contentType?.trim() || void 0;
461
+ const { baseUrl, password, accountId } = resolveAccount$3(opts);
462
+ const privateApiStatus = getCachedBlueBubblesPrivateApiStatus(accountId);
463
+ const privateApiEnabled = isBlueBubblesPrivateApiStatusEnabled(privateApiStatus);
464
+ const isAudioMessage = wantsVoice;
465
+ if (isAudioMessage) {
466
+ const voiceInfo = resolveVoiceInfo(filename, contentType);
467
+ if (!voiceInfo.isAudio) throw new Error("BlueBubbles voice messages require audio media (mp3 or caf).");
468
+ if (voiceInfo.isMp3) {
469
+ filename = ensureExtension(filename, ".mp3", fallbackName);
470
+ contentType = contentType ?? "audio/mpeg";
471
+ } else if (voiceInfo.isCaf) {
472
+ filename = ensureExtension(filename, ".caf", fallbackName);
473
+ contentType = contentType ?? "audio/x-caf";
474
+ } else throw new Error("BlueBubbles voice messages require mp3 or caf audio (convert before sending).");
475
+ }
476
+ const target = resolveBlueBubblesSendTarget(to);
477
+ const chatGuid = await resolveChatGuidForTarget({
478
+ baseUrl,
479
+ password,
480
+ timeoutMs: opts.timeoutMs,
481
+ target
482
+ });
483
+ if (!chatGuid) throw new Error("BlueBubbles attachment send failed: chatGuid not found for target. Use a chat_guid target or ensure the chat exists.");
484
+ const url = buildBlueBubblesApiUrl({
485
+ baseUrl,
486
+ path: "/api/v1/message/attachment",
487
+ password
488
+ });
489
+ const boundary = `----BlueBubblesFormBoundary${crypto.randomUUID().replace(/-/g, "")}`;
490
+ const parts = [];
491
+ const encoder = new TextEncoder();
492
+ const addField = (name, value) => {
493
+ parts.push(encoder.encode(`--${boundary}\r\n`));
494
+ parts.push(encoder.encode(`Content-Disposition: form-data; name="${name}"\r\n\r\n`));
495
+ parts.push(encoder.encode(`${value}\r\n`));
496
+ };
497
+ const addFile = (name, fileBuffer, fileName, mimeType) => {
498
+ parts.push(encoder.encode(`--${boundary}\r\n`));
499
+ parts.push(encoder.encode(`Content-Disposition: form-data; name="${name}"; filename="${fileName}"\r\n`));
500
+ parts.push(encoder.encode(`Content-Type: ${mimeType ?? "application/octet-stream"}\r\n\r\n`));
501
+ parts.push(fileBuffer);
502
+ parts.push(encoder.encode("\r\n"));
503
+ };
504
+ addFile("attachment", buffer, filename, contentType);
505
+ addField("chatGuid", chatGuid);
506
+ addField("name", filename);
507
+ addField("tempGuid", `temp-${Date.now()}-${crypto.randomUUID().slice(0, 8)}`);
508
+ if (privateApiEnabled) addField("method", "private-api");
509
+ if (isAudioMessage) addField("isAudioMessage", "true");
510
+ const trimmedReplyTo = replyToMessageGuid?.trim();
511
+ if (trimmedReplyTo && privateApiEnabled) {
512
+ addField("selectedMessageGuid", trimmedReplyTo);
513
+ addField("partIndex", typeof replyToPartIndex === "number" ? String(replyToPartIndex) : "0");
514
+ } else if (trimmedReplyTo && privateApiStatus === null) warnBlueBubbles("Private API status unknown; sending attachment without reply threading metadata. Run a status probe to restore private-api reply features.");
515
+ if (caption) {
516
+ addField("message", caption);
517
+ addField("text", caption);
518
+ addField("caption", caption);
519
+ }
520
+ parts.push(encoder.encode(`--${boundary}--\r\n`));
521
+ const res = await postMultipartFormData({
522
+ url,
523
+ boundary,
524
+ parts,
525
+ timeoutMs: opts.timeoutMs ?? 6e4
526
+ });
527
+ await assertMultipartActionOk(res, "attachment send");
528
+ const responseBody = await res.text();
529
+ if (!responseBody) return { messageId: "ok" };
530
+ try {
531
+ return { messageId: extractBlueBubblesMessageId(JSON.parse(responseBody)) };
532
+ } catch {
533
+ return { messageId: "ok" };
534
+ }
535
+ }
536
+ //#endregion
537
+ //#region extensions/bluebubbles/src/chat.ts
538
+ function resolveAccount$2(params) {
539
+ return resolveBlueBubblesServerAccount(params);
540
+ }
541
+ function assertPrivateApiEnabled(accountId, feature) {
542
+ if (getCachedBlueBubblesPrivateApiStatus(accountId) === false) throw new Error(`BlueBubbles ${feature} requires Private API, but it is disabled on the BlueBubbles server.`);
543
+ }
544
+ function resolvePartIndex(partIndex) {
545
+ return typeof partIndex === "number" ? partIndex : 0;
546
+ }
547
+ async function sendBlueBubblesChatEndpointRequest(params) {
548
+ const trimmed = params.chatGuid.trim();
549
+ if (!trimmed) return;
550
+ const { baseUrl, password, accountId } = resolveAccount$2(params.opts);
551
+ if (getCachedBlueBubblesPrivateApiStatus(accountId) === false) return;
552
+ await assertMultipartActionOk(await blueBubblesFetchWithTimeout(buildBlueBubblesApiUrl({
553
+ baseUrl,
554
+ path: `/api/v1/chat/${encodeURIComponent(trimmed)}/${params.endpoint}`,
555
+ password
556
+ }), { method: params.method }, params.opts.timeoutMs), params.action);
557
+ }
558
+ async function sendPrivateApiJsonRequest(params) {
559
+ const { baseUrl, password, accountId } = resolveAccount$2(params.opts);
560
+ assertPrivateApiEnabled(accountId, params.feature);
561
+ const url = buildBlueBubblesApiUrl({
562
+ baseUrl,
563
+ path: params.path,
564
+ password
565
+ });
566
+ const request = { method: params.method };
567
+ if (params.payload !== void 0) {
568
+ request.headers = { "Content-Type": "application/json" };
569
+ request.body = JSON.stringify(params.payload);
570
+ }
571
+ await assertMultipartActionOk(await blueBubblesFetchWithTimeout(url, request, params.opts.timeoutMs), params.action);
572
+ }
573
+ async function markBlueBubblesChatRead(chatGuid, opts = {}) {
574
+ await sendBlueBubblesChatEndpointRequest({
575
+ chatGuid,
576
+ opts,
577
+ endpoint: "read",
578
+ method: "POST",
579
+ action: "read"
580
+ });
581
+ }
582
+ async function sendBlueBubblesTyping(chatGuid, typing, opts = {}) {
583
+ await sendBlueBubblesChatEndpointRequest({
584
+ chatGuid,
585
+ opts,
586
+ endpoint: "typing",
587
+ method: typing ? "POST" : "DELETE",
588
+ action: "typing"
589
+ });
590
+ }
591
+ /**
592
+ * Edit a message via BlueBubbles API.
593
+ * Requires macOS 13 (Ventura) or higher with Private API enabled.
594
+ */
595
+ async function editBlueBubblesMessage(messageGuid, newText, opts = {}) {
596
+ const trimmedGuid = messageGuid.trim();
597
+ if (!trimmedGuid) throw new Error("BlueBubbles edit requires messageGuid");
598
+ const trimmedText = newText.trim();
599
+ if (!trimmedText) throw new Error("BlueBubbles edit requires newText");
600
+ await sendPrivateApiJsonRequest({
601
+ opts,
602
+ feature: "edit",
603
+ action: "edit",
604
+ method: "POST",
605
+ path: `/api/v1/message/${encodeURIComponent(trimmedGuid)}/edit`,
606
+ payload: {
607
+ editedMessage: trimmedText,
608
+ backwardsCompatibilityMessage: opts.backwardsCompatMessage ?? `Edited to: ${trimmedText}`,
609
+ partIndex: resolvePartIndex(opts.partIndex)
610
+ }
611
+ });
612
+ }
613
+ /**
614
+ * Unsend (retract) a message via BlueBubbles API.
615
+ * Requires macOS 13 (Ventura) or higher with Private API enabled.
616
+ */
617
+ async function unsendBlueBubblesMessage(messageGuid, opts = {}) {
618
+ const trimmedGuid = messageGuid.trim();
619
+ if (!trimmedGuid) throw new Error("BlueBubbles unsend requires messageGuid");
620
+ await sendPrivateApiJsonRequest({
621
+ opts,
622
+ feature: "unsend",
623
+ action: "unsend",
624
+ method: "POST",
625
+ path: `/api/v1/message/${encodeURIComponent(trimmedGuid)}/unsend`,
626
+ payload: { partIndex: resolvePartIndex(opts.partIndex) }
627
+ });
628
+ }
629
+ /**
630
+ * Rename a group chat via BlueBubbles API.
631
+ */
632
+ async function renameBlueBubblesChat(chatGuid, displayName, opts = {}) {
633
+ const trimmedGuid = chatGuid.trim();
634
+ if (!trimmedGuid) throw new Error("BlueBubbles rename requires chatGuid");
635
+ await sendPrivateApiJsonRequest({
636
+ opts,
637
+ feature: "renameGroup",
638
+ action: "rename",
639
+ method: "PUT",
640
+ path: `/api/v1/chat/${encodeURIComponent(trimmedGuid)}`,
641
+ payload: { displayName }
642
+ });
643
+ }
644
+ /**
645
+ * Add a participant to a group chat via BlueBubbles API.
646
+ */
647
+ async function addBlueBubblesParticipant(chatGuid, address, opts = {}) {
648
+ const trimmedGuid = chatGuid.trim();
649
+ if (!trimmedGuid) throw new Error("BlueBubbles addParticipant requires chatGuid");
650
+ const trimmedAddress = address.trim();
651
+ if (!trimmedAddress) throw new Error("BlueBubbles addParticipant requires address");
652
+ await sendPrivateApiJsonRequest({
653
+ opts,
654
+ feature: "addParticipant",
655
+ action: "addParticipant",
656
+ method: "POST",
657
+ path: `/api/v1/chat/${encodeURIComponent(trimmedGuid)}/participant`,
658
+ payload: { address: trimmedAddress }
659
+ });
660
+ }
661
+ /**
662
+ * Remove a participant from a group chat via BlueBubbles API.
663
+ */
664
+ async function removeBlueBubblesParticipant(chatGuid, address, opts = {}) {
665
+ const trimmedGuid = chatGuid.trim();
666
+ if (!trimmedGuid) throw new Error("BlueBubbles removeParticipant requires chatGuid");
667
+ const trimmedAddress = address.trim();
668
+ if (!trimmedAddress) throw new Error("BlueBubbles removeParticipant requires address");
669
+ await sendPrivateApiJsonRequest({
670
+ opts,
671
+ feature: "removeParticipant",
672
+ action: "removeParticipant",
673
+ method: "DELETE",
674
+ path: `/api/v1/chat/${encodeURIComponent(trimmedGuid)}/participant`,
675
+ payload: { address: trimmedAddress }
676
+ });
677
+ }
678
+ /**
679
+ * Leave a group chat via BlueBubbles API.
680
+ */
681
+ async function leaveBlueBubblesChat(chatGuid, opts = {}) {
682
+ const trimmedGuid = chatGuid.trim();
683
+ if (!trimmedGuid) throw new Error("BlueBubbles leaveChat requires chatGuid");
684
+ await sendPrivateApiJsonRequest({
685
+ opts,
686
+ feature: "leaveGroup",
687
+ action: "leaveChat",
688
+ method: "POST",
689
+ path: `/api/v1/chat/${encodeURIComponent(trimmedGuid)}/leave`
690
+ });
691
+ }
692
+ /**
693
+ * Set a group chat's icon/photo via BlueBubbles API.
694
+ * Requires Private API to be enabled.
695
+ */
696
+ async function setGroupIconBlueBubbles(chatGuid, buffer, filename, opts = {}) {
697
+ const trimmedGuid = chatGuid.trim();
698
+ if (!trimmedGuid) throw new Error("BlueBubbles setGroupIcon requires chatGuid");
699
+ if (!buffer || buffer.length === 0) throw new Error("BlueBubbles setGroupIcon requires image buffer");
700
+ const { baseUrl, password, accountId } = resolveAccount$2(opts);
701
+ assertPrivateApiEnabled(accountId, "setGroupIcon");
702
+ const url = buildBlueBubblesApiUrl({
703
+ baseUrl,
704
+ path: `/api/v1/chat/${encodeURIComponent(trimmedGuid)}/icon`,
705
+ password
706
+ });
707
+ const boundary = `----BlueBubblesFormBoundary${crypto.randomUUID().replace(/-/g, "")}`;
708
+ const parts = [];
709
+ const encoder = new TextEncoder();
710
+ const safeFilename = path.basename(filename).replace(/[\r\n"\\]/g, "_") || "icon.png";
711
+ parts.push(encoder.encode(`--${boundary}\r\n`));
712
+ parts.push(encoder.encode(`Content-Disposition: form-data; name="icon"; filename="${safeFilename}"\r\n`));
713
+ parts.push(encoder.encode(`Content-Type: ${opts.contentType ?? "application/octet-stream"}\r\n\r\n`));
714
+ parts.push(buffer);
715
+ parts.push(encoder.encode("\r\n"));
716
+ parts.push(encoder.encode(`--${boundary}--\r\n`));
717
+ await assertMultipartActionOk(await postMultipartFormData({
718
+ url,
719
+ boundary,
720
+ parts,
721
+ timeoutMs: opts.timeoutMs ?? 6e4
722
+ }), "setGroupIcon");
723
+ }
724
+ //#endregion
725
+ //#region extensions/bluebubbles/src/monitor-debounce.ts
726
+ /**
727
+ * Default debounce window for inbound message coalescing (ms).
728
+ * This helps combine URL text + link preview balloon messages that BlueBubbles
729
+ * sends as separate webhook events when no explicit inbound debounce config exists.
730
+ */
731
+ const DEFAULT_INBOUND_DEBOUNCE_MS = 500;
732
+ /**
733
+ * Combines multiple debounced messages into a single message for processing.
734
+ * Used when multiple webhook events arrive within the debounce window.
735
+ */
736
+ function combineDebounceEntries(entries) {
737
+ if (entries.length === 0) throw new Error("Cannot combine empty entries");
738
+ if (entries.length === 1) return entries[0].message;
739
+ const first = entries[0].message;
740
+ const seenTexts = /* @__PURE__ */ new Set();
741
+ const textParts = [];
742
+ for (const entry of entries) {
743
+ const text = entry.message.text.trim();
744
+ if (!text) continue;
745
+ const normalizedText = text.toLowerCase();
746
+ if (seenTexts.has(normalizedText)) continue;
747
+ seenTexts.add(normalizedText);
748
+ textParts.push(text);
749
+ }
750
+ const allAttachments = entries.flatMap((e) => e.message.attachments ?? []);
751
+ const timestamps = entries.map((e) => e.message.timestamp).filter((t) => typeof t === "number");
752
+ const latestTimestamp = timestamps.length > 0 ? Math.max(...timestamps) : first.timestamp;
753
+ const messageIds = entries.map((e) => e.message.messageId).filter((id) => Boolean(id));
754
+ const entryWithReply = entries.find((e) => e.message.replyToId);
755
+ return {
756
+ ...first,
757
+ text: textParts.join(" "),
758
+ attachments: allAttachments.length > 0 ? allAttachments : first.attachments,
759
+ timestamp: latestTimestamp,
760
+ messageId: messageIds[0] ?? first.messageId,
761
+ replyToId: entryWithReply?.message.replyToId ?? first.replyToId,
762
+ replyToBody: entryWithReply?.message.replyToBody ?? first.replyToBody,
763
+ replyToSender: entryWithReply?.message.replyToSender ?? first.replyToSender,
764
+ balloonBundleId: void 0
765
+ };
766
+ }
767
+ function resolveBlueBubblesDebounceMs(config, core) {
768
+ const inbound = config.messages?.inbound;
769
+ if (!(typeof inbound?.debounceMs === "number" || typeof inbound?.byChannel?.bluebubbles === "number")) return DEFAULT_INBOUND_DEBOUNCE_MS;
770
+ return core.channel.debounce.resolveInboundDebounceMs({
771
+ cfg: config,
772
+ channel: "bluebubbles"
773
+ });
774
+ }
775
+ function createBlueBubblesDebounceRegistry(params) {
776
+ const targetDebouncers = /* @__PURE__ */ new Map();
777
+ return {
778
+ getOrCreateDebouncer: (target) => {
779
+ const existing = targetDebouncers.get(target);
780
+ if (existing) return existing;
781
+ const { account, config, runtime, core } = target;
782
+ const debouncer = core.channel.debounce.createInboundDebouncer({
783
+ debounceMs: resolveBlueBubblesDebounceMs(config, core),
784
+ buildKey: (entry) => {
785
+ const msg = entry.message;
786
+ const balloonBundleId = msg.balloonBundleId?.trim();
787
+ const associatedMessageGuid = msg.associatedMessageGuid?.trim();
788
+ if (balloonBundleId && associatedMessageGuid) return `bluebubbles:${account.accountId}:balloon:${associatedMessageGuid}`;
789
+ const messageId = msg.messageId?.trim();
790
+ if (messageId) return `bluebubbles:${account.accountId}:msg:${messageId}`;
791
+ const chatKey = msg.chatGuid?.trim() ?? msg.chatIdentifier?.trim() ?? (msg.chatId ? String(msg.chatId) : "dm");
792
+ return `bluebubbles:${account.accountId}:${chatKey}:${msg.senderId}`;
793
+ },
794
+ shouldDebounce: (entry) => {
795
+ const msg = entry.message;
796
+ if (msg.fromMe) return false;
797
+ if (core.channel.text.hasControlCommand(msg.text, config)) return false;
798
+ return true;
799
+ },
800
+ onFlush: async (entries) => {
801
+ if (entries.length === 0) return;
802
+ const flushTarget = entries[0].target;
803
+ if (entries.length === 1) {
804
+ await params.processMessage(entries[0].message, flushTarget);
805
+ return;
806
+ }
807
+ const combined = combineDebounceEntries(entries);
808
+ if (core.logging.shouldLogVerbose()) {
809
+ const count = entries.length;
810
+ const preview = combined.text.slice(0, 50);
811
+ runtime.log?.(`[bluebubbles] coalesced ${count} messages: "${preview}${combined.text.length > 50 ? "..." : ""}"`);
812
+ }
813
+ await params.processMessage(combined, flushTarget);
814
+ },
815
+ onError: (err) => {
816
+ runtime.error?.(`[${account.accountId}] [bluebubbles] debounce flush failed: ${String(err)}`);
817
+ }
818
+ });
819
+ targetDebouncers.set(target, debouncer);
820
+ return debouncer;
821
+ },
822
+ removeDebouncer: (target) => {
823
+ targetDebouncers.delete(target);
824
+ }
825
+ };
826
+ }
827
+ //#endregion
828
+ //#region extensions/bluebubbles/src/monitor-normalize.ts
829
+ function asRecord$1(value) {
830
+ return value && typeof value === "object" && !Array.isArray(value) ? value : null;
831
+ }
832
+ function readString(record, key) {
833
+ if (!record) return;
834
+ const value = record[key];
835
+ return typeof value === "string" ? value : void 0;
836
+ }
837
+ function readNumber(record, key) {
838
+ if (!record) return;
839
+ const value = record[key];
840
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
841
+ }
842
+ function readBoolean(record, key) {
843
+ if (!record) return;
844
+ const value = record[key];
845
+ return typeof value === "boolean" ? value : void 0;
846
+ }
847
+ function readNumberLike(record, key) {
848
+ if (!record) return;
849
+ return parseFiniteNumber(record[key]);
850
+ }
851
+ function extractAttachments(message) {
852
+ const raw = message["attachments"];
853
+ if (!Array.isArray(raw)) return [];
854
+ const out = [];
855
+ for (const entry of raw) {
856
+ const record = asRecord$1(entry);
857
+ if (!record) continue;
858
+ out.push({
859
+ guid: readString(record, "guid"),
860
+ uti: readString(record, "uti"),
861
+ mimeType: readString(record, "mimeType") ?? readString(record, "mime_type"),
862
+ transferName: readString(record, "transferName") ?? readString(record, "transfer_name"),
863
+ totalBytes: readNumberLike(record, "totalBytes") ?? readNumberLike(record, "total_bytes"),
864
+ height: readNumberLike(record, "height"),
865
+ width: readNumberLike(record, "width"),
866
+ originalROWID: readNumberLike(record, "originalROWID") ?? readNumberLike(record, "rowid")
867
+ });
868
+ }
869
+ return out;
870
+ }
871
+ function buildAttachmentPlaceholder(attachments) {
872
+ if (attachments.length === 0) return "";
873
+ const mimeTypes = attachments.map((entry) => entry.mimeType ?? "");
874
+ const allImages = mimeTypes.every((entry) => entry.startsWith("image/"));
875
+ const allVideos = mimeTypes.every((entry) => entry.startsWith("video/"));
876
+ const allAudio = mimeTypes.every((entry) => entry.startsWith("audio/"));
877
+ const tag = allImages ? "<media:image>" : allVideos ? "<media:video>" : allAudio ? "<media:audio>" : "<media:attachment>";
878
+ const label = allImages ? "image" : allVideos ? "video" : allAudio ? "audio" : "file";
879
+ const suffix = attachments.length === 1 ? label : `${label}s`;
880
+ return `${tag} (${attachments.length} ${suffix})`;
881
+ }
882
+ function buildMessagePlaceholder(message) {
883
+ const attachmentPlaceholder = buildAttachmentPlaceholder(message.attachments ?? []);
884
+ if (attachmentPlaceholder) return attachmentPlaceholder;
885
+ if (message.balloonBundleId) return "<media:sticker>";
886
+ return "";
887
+ }
888
+ function formatReplyTag(message) {
889
+ const rawId = message.replyToShortId || message.replyToId;
890
+ if (!rawId) return null;
891
+ return `[[reply_to:${rawId}]]`;
892
+ }
893
+ function extractReplyMetadata(message) {
894
+ const replyRecord = asRecord$1(message["replyTo"] ?? message["reply_to"] ?? message["replyToMessage"] ?? message["reply_to_message"] ?? message["repliedMessage"] ?? message["quotedMessage"] ?? message["associatedMessage"] ?? message["reply"]);
895
+ const replyHandle = asRecord$1(replyRecord?.["handle"]) ?? asRecord$1(replyRecord?.["sender"]) ?? null;
896
+ const replySenderRaw = readString(replyHandle, "address") ?? readString(replyHandle, "handle") ?? readString(replyHandle, "id") ?? readString(replyRecord, "senderId") ?? readString(replyRecord, "sender") ?? readString(replyRecord, "from");
897
+ const normalizedSender = replySenderRaw ? normalizeBlueBubblesHandle(replySenderRaw) || replySenderRaw.trim() : void 0;
898
+ const replyToBody = readString(replyRecord, "text") ?? readString(replyRecord, "body") ?? readString(replyRecord, "message") ?? readString(replyRecord, "subject") ?? void 0;
899
+ const directReplyId = readString(message, "replyToMessageGuid") ?? readString(message, "replyToGuid") ?? readString(message, "replyGuid") ?? readString(message, "selectedMessageGuid") ?? readString(message, "selectedMessageId") ?? readString(message, "replyToMessageId") ?? readString(message, "replyId") ?? readString(replyRecord, "guid") ?? readString(replyRecord, "id") ?? readString(replyRecord, "messageId");
900
+ const associatedType = readNumberLike(message, "associatedMessageType") ?? readNumberLike(message, "associated_message_type");
901
+ const associatedGuid = readString(message, "associatedMessageGuid") ?? readString(message, "associated_message_guid") ?? readString(message, "associatedMessageId");
902
+ const isReactionAssociation = typeof associatedType === "number" && REACTION_TYPE_MAP.has(associatedType);
903
+ const replyToId = directReplyId ?? (!isReactionAssociation ? associatedGuid : void 0);
904
+ const threadOriginatorGuid = readString(message, "threadOriginatorGuid");
905
+ const messageGuid = readString(message, "guid");
906
+ return {
907
+ replyToId: (replyToId ?? (!replyToId && threadOriginatorGuid && threadOriginatorGuid !== messageGuid ? threadOriginatorGuid : void 0))?.trim() || void 0,
908
+ replyToBody: replyToBody?.trim() || void 0,
909
+ replyToSender: normalizedSender || void 0
910
+ };
911
+ }
912
+ function readFirstChatRecord(message) {
913
+ const chats = message["chats"];
914
+ if (!Array.isArray(chats) || chats.length === 0) return null;
915
+ const first = chats[0];
916
+ return asRecord$1(first);
917
+ }
918
+ function extractSenderInfo(message) {
919
+ const handleValue = message.handle ?? message.sender;
920
+ const handle = asRecord$1(handleValue) ?? (typeof handleValue === "string" ? { address: handleValue } : null);
921
+ const senderId = (readString(handle, "address") ?? readString(handle, "handle") ?? readString(handle, "id") ?? readString(message, "senderId") ?? readString(message, "sender") ?? readString(message, "from") ?? "").trim();
922
+ const senderName = readString(handle, "displayName") ?? readString(handle, "name") ?? readString(message, "senderName") ?? void 0;
923
+ return {
924
+ senderId,
925
+ senderIdExplicit: Boolean(senderId),
926
+ senderName
927
+ };
928
+ }
929
+ function extractChatContext(message) {
930
+ const chat = asRecord$1(message.chat) ?? asRecord$1(message.conversation) ?? null;
931
+ const chatFromList = readFirstChatRecord(message);
932
+ const chatGuid = readString(message, "chatGuid") ?? readString(message, "chat_guid") ?? readString(chat, "chatGuid") ?? readString(chat, "chat_guid") ?? readString(chat, "guid") ?? readString(chatFromList, "chatGuid") ?? readString(chatFromList, "chat_guid") ?? readString(chatFromList, "guid");
933
+ const chatIdentifier = readString(message, "chatIdentifier") ?? readString(message, "chat_identifier") ?? readString(chat, "chatIdentifier") ?? readString(chat, "chat_identifier") ?? readString(chat, "identifier") ?? readString(chatFromList, "chatIdentifier") ?? readString(chatFromList, "chat_identifier") ?? readString(chatFromList, "identifier") ?? extractChatIdentifierFromChatGuid(chatGuid);
934
+ const chatId = readNumberLike(message, "chatId") ?? readNumberLike(message, "chat_id") ?? readNumberLike(chat, "chatId") ?? readNumberLike(chat, "chat_id") ?? readNumberLike(chat, "id") ?? readNumberLike(chatFromList, "chatId") ?? readNumberLike(chatFromList, "chat_id") ?? readNumberLike(chatFromList, "id");
935
+ const chatName = readString(message, "chatName") ?? readString(chat, "displayName") ?? readString(chat, "name") ?? readString(chatFromList, "displayName") ?? readString(chatFromList, "name") ?? void 0;
936
+ const chatParticipants = chat ? chat["participants"] : void 0;
937
+ const messageParticipants = message["participants"];
938
+ const chatsParticipants = chatFromList ? chatFromList["participants"] : void 0;
939
+ const participants = Array.isArray(chatParticipants) ? chatParticipants : Array.isArray(messageParticipants) ? messageParticipants : Array.isArray(chatsParticipants) ? chatsParticipants : [];
940
+ const participantsCount = participants.length;
941
+ const groupFromChatGuid = resolveGroupFlagFromChatGuid(chatGuid);
942
+ const explicitIsGroup = readBoolean(message, "isGroup") ?? readBoolean(message, "is_group") ?? readBoolean(chat, "isGroup") ?? readBoolean(message, "group");
943
+ return {
944
+ chatGuid,
945
+ chatIdentifier,
946
+ chatId,
947
+ chatName,
948
+ isGroup: typeof groupFromChatGuid === "boolean" ? groupFromChatGuid : explicitIsGroup ?? participantsCount > 2,
949
+ participants
950
+ };
951
+ }
952
+ function normalizeParticipantEntry(entry) {
953
+ if (typeof entry === "string" || typeof entry === "number") {
954
+ const raw = String(entry).trim();
955
+ if (!raw) return null;
956
+ const normalized = normalizeBlueBubblesHandle(raw) || raw;
957
+ return normalized ? { id: normalized } : null;
958
+ }
959
+ const record = asRecord$1(entry);
960
+ if (!record) return null;
961
+ const nestedHandle = asRecord$1(record["handle"]) ?? asRecord$1(record["sender"]) ?? asRecord$1(record["contact"]) ?? null;
962
+ const idRaw = readString(record, "address") ?? readString(record, "handle") ?? readString(record, "id") ?? readString(record, "phoneNumber") ?? readString(record, "phone_number") ?? readString(record, "email") ?? readString(nestedHandle, "address") ?? readString(nestedHandle, "handle") ?? readString(nestedHandle, "id");
963
+ const nameRaw = readString(record, "displayName") ?? readString(record, "name") ?? readString(record, "title") ?? readString(nestedHandle, "displayName") ?? readString(nestedHandle, "name");
964
+ const normalizedId = idRaw ? normalizeBlueBubblesHandle(idRaw) || idRaw.trim() : "";
965
+ if (!normalizedId) return null;
966
+ return {
967
+ id: normalizedId,
968
+ name: nameRaw?.trim() || void 0
969
+ };
970
+ }
971
+ function normalizeParticipantList(raw) {
972
+ if (!Array.isArray(raw) || raw.length === 0) return [];
973
+ const seen = /* @__PURE__ */ new Set();
974
+ const output = [];
975
+ for (const entry of raw) {
976
+ const normalized = normalizeParticipantEntry(entry);
977
+ if (!normalized?.id) continue;
978
+ const key = normalized.id.toLowerCase();
979
+ if (seen.has(key)) continue;
980
+ seen.add(key);
981
+ output.push(normalized);
982
+ }
983
+ return output;
984
+ }
985
+ function formatGroupMembers(params) {
986
+ const seen = /* @__PURE__ */ new Set();
987
+ const ordered = [];
988
+ for (const entry of params.participants ?? []) {
989
+ if (!entry?.id) continue;
990
+ const key = entry.id.toLowerCase();
991
+ if (seen.has(key)) continue;
992
+ seen.add(key);
993
+ ordered.push(entry);
994
+ }
995
+ if (ordered.length === 0 && params.fallback?.id) ordered.push(params.fallback);
996
+ if (ordered.length === 0) return;
997
+ return ordered.map((entry) => entry.name ? `${entry.name} (${entry.id})` : entry.id).join(", ");
998
+ }
999
+ function resolveGroupFlagFromChatGuid(chatGuid) {
1000
+ const guid = chatGuid?.trim();
1001
+ if (!guid) return;
1002
+ const parts = guid.split(";");
1003
+ if (parts.length >= 3) {
1004
+ if (parts[1] === "+") return true;
1005
+ if (parts[1] === "-") return false;
1006
+ }
1007
+ if (guid.includes(";+;")) return true;
1008
+ if (guid.includes(";-;")) return false;
1009
+ }
1010
+ function extractChatIdentifierFromChatGuid(chatGuid) {
1011
+ const guid = chatGuid?.trim();
1012
+ if (!guid) return;
1013
+ const parts = guid.split(";");
1014
+ if (parts.length < 3) return;
1015
+ return parts[2]?.trim() || void 0;
1016
+ }
1017
+ function formatGroupAllowlistEntry(params) {
1018
+ const guid = params.chatGuid?.trim();
1019
+ if (guid) return `chat_guid:${guid}`;
1020
+ const chatId = params.chatId;
1021
+ if (typeof chatId === "number" && Number.isFinite(chatId)) return `chat_id:${chatId}`;
1022
+ const identifier = params.chatIdentifier?.trim();
1023
+ if (identifier) return `chat_identifier:${identifier}`;
1024
+ return null;
1025
+ }
1026
+ const REACTION_TYPE_MAP = new Map([
1027
+ [2e3, {
1028
+ emoji: "❤️",
1029
+ action: "added"
1030
+ }],
1031
+ [2001, {
1032
+ emoji: "👍",
1033
+ action: "added"
1034
+ }],
1035
+ [2002, {
1036
+ emoji: "👎",
1037
+ action: "added"
1038
+ }],
1039
+ [2003, {
1040
+ emoji: "😂",
1041
+ action: "added"
1042
+ }],
1043
+ [2004, {
1044
+ emoji: "‼️",
1045
+ action: "added"
1046
+ }],
1047
+ [2005, {
1048
+ emoji: "❓",
1049
+ action: "added"
1050
+ }],
1051
+ [3e3, {
1052
+ emoji: "❤️",
1053
+ action: "removed"
1054
+ }],
1055
+ [3001, {
1056
+ emoji: "👍",
1057
+ action: "removed"
1058
+ }],
1059
+ [3002, {
1060
+ emoji: "👎",
1061
+ action: "removed"
1062
+ }],
1063
+ [3003, {
1064
+ emoji: "😂",
1065
+ action: "removed"
1066
+ }],
1067
+ [3004, {
1068
+ emoji: "‼️",
1069
+ action: "removed"
1070
+ }],
1071
+ [3005, {
1072
+ emoji: "❓",
1073
+ action: "removed"
1074
+ }]
1075
+ ]);
1076
+ const TAPBACK_TEXT_MAP = new Map([
1077
+ ["loved", {
1078
+ emoji: "❤️",
1079
+ action: "added"
1080
+ }],
1081
+ ["liked", {
1082
+ emoji: "👍",
1083
+ action: "added"
1084
+ }],
1085
+ ["disliked", {
1086
+ emoji: "👎",
1087
+ action: "added"
1088
+ }],
1089
+ ["laughed at", {
1090
+ emoji: "😂",
1091
+ action: "added"
1092
+ }],
1093
+ ["emphasized", {
1094
+ emoji: "‼️",
1095
+ action: "added"
1096
+ }],
1097
+ ["questioned", {
1098
+ emoji: "❓",
1099
+ action: "added"
1100
+ }],
1101
+ ["removed a heart from", {
1102
+ emoji: "❤️",
1103
+ action: "removed"
1104
+ }],
1105
+ ["removed a like from", {
1106
+ emoji: "👍",
1107
+ action: "removed"
1108
+ }],
1109
+ ["removed a dislike from", {
1110
+ emoji: "👎",
1111
+ action: "removed"
1112
+ }],
1113
+ ["removed a laugh from", {
1114
+ emoji: "😂",
1115
+ action: "removed"
1116
+ }],
1117
+ ["removed an emphasis from", {
1118
+ emoji: "‼️",
1119
+ action: "removed"
1120
+ }],
1121
+ ["removed a question from", {
1122
+ emoji: "❓",
1123
+ action: "removed"
1124
+ }]
1125
+ ]);
1126
+ const TAPBACK_EMOJI_REGEX = /(?:\p{Regional_Indicator}{2})|(?:[0-9#*]\uFE0F?\u20E3)|(?:\p{Extended_Pictographic}(?:\uFE0F|\uFE0E)?(?:\p{Emoji_Modifier})?(?:\u200D\p{Extended_Pictographic}(?:\uFE0F|\uFE0E)?(?:\p{Emoji_Modifier})?)*)/u;
1127
+ function extractFirstEmoji(text) {
1128
+ const match = text.match(TAPBACK_EMOJI_REGEX);
1129
+ return match ? match[0] : null;
1130
+ }
1131
+ function extractQuotedTapbackText(text) {
1132
+ const match = text.match(/[“"]([^”"]+)[”"]/s);
1133
+ return match ? match[1] : null;
1134
+ }
1135
+ function isTapbackAssociatedType(type) {
1136
+ return typeof type === "number" && Number.isFinite(type) && type >= 2e3 && type < 4e3;
1137
+ }
1138
+ function resolveTapbackActionHint(type) {
1139
+ if (typeof type !== "number" || !Number.isFinite(type)) return;
1140
+ if (type >= 3e3 && type < 4e3) return "removed";
1141
+ if (type >= 2e3 && type < 3e3) return "added";
1142
+ }
1143
+ function resolveTapbackContext(message) {
1144
+ const associatedType = message.associatedMessageType;
1145
+ const hasTapbackType = isTapbackAssociatedType(associatedType);
1146
+ const hasTapbackMarker = Boolean(message.associatedMessageEmoji) || Boolean(message.isTapback);
1147
+ if (!hasTapbackType && !hasTapbackMarker) return null;
1148
+ const replyToId = message.associatedMessageGuid?.trim() || message.replyToId?.trim() || void 0;
1149
+ const actionHint = resolveTapbackActionHint(associatedType);
1150
+ return {
1151
+ emojiHint: message.associatedMessageEmoji?.trim() || REACTION_TYPE_MAP.get(associatedType ?? -1)?.emoji,
1152
+ actionHint,
1153
+ replyToId
1154
+ };
1155
+ }
1156
+ function parseTapbackText(params) {
1157
+ const trimmed = params.text.trim();
1158
+ const lower = trimmed.toLowerCase();
1159
+ if (!trimmed) return null;
1160
+ const parseLeadingReactionAction = (prefix, defaultAction) => {
1161
+ if (!lower.startsWith(prefix)) return null;
1162
+ const emoji = extractFirstEmoji(trimmed) ?? params.emojiHint;
1163
+ if (!emoji) return null;
1164
+ const quotedText = extractQuotedTapbackText(trimmed);
1165
+ if (params.requireQuoted && !quotedText) return null;
1166
+ const fallback = trimmed.slice(prefix.length).trim();
1167
+ return {
1168
+ emoji,
1169
+ action: params.actionHint ?? defaultAction,
1170
+ quotedText: quotedText ?? fallback
1171
+ };
1172
+ };
1173
+ for (const [pattern, { emoji, action }] of TAPBACK_TEXT_MAP) if (lower.startsWith(pattern)) {
1174
+ const afterPattern = trimmed.slice(pattern.length).trim();
1175
+ if (params.requireQuoted) {
1176
+ const strictMatch = afterPattern.match(/^[“"](.+)[”"]$/s);
1177
+ if (!strictMatch) return null;
1178
+ return {
1179
+ emoji,
1180
+ action,
1181
+ quotedText: strictMatch[1]
1182
+ };
1183
+ }
1184
+ return {
1185
+ emoji,
1186
+ action,
1187
+ quotedText: extractQuotedTapbackText(afterPattern) ?? extractQuotedTapbackText(trimmed) ?? afterPattern
1188
+ };
1189
+ }
1190
+ const reacted = parseLeadingReactionAction("reacted", "added");
1191
+ if (reacted) return reacted;
1192
+ const removed = parseLeadingReactionAction("removed", "removed");
1193
+ if (removed) return removed;
1194
+ return null;
1195
+ }
1196
+ function extractMessagePayload(payload) {
1197
+ const parseRecord = (value) => {
1198
+ const record = asRecord$1(value);
1199
+ if (record) return record;
1200
+ if (Array.isArray(value)) {
1201
+ for (const entry of value) {
1202
+ const parsedEntry = parseRecord(entry);
1203
+ if (parsedEntry) return parsedEntry;
1204
+ }
1205
+ return null;
1206
+ }
1207
+ if (typeof value !== "string") return null;
1208
+ const trimmed = value.trim();
1209
+ if (!trimmed) return null;
1210
+ try {
1211
+ return parseRecord(JSON.parse(trimmed));
1212
+ } catch {
1213
+ return null;
1214
+ }
1215
+ };
1216
+ const data = parseRecord(payload.data ?? payload.payload ?? payload.event);
1217
+ const message = parseRecord(payload.message ?? data?.message ?? data);
1218
+ if (message) return message;
1219
+ return null;
1220
+ }
1221
+ function normalizeWebhookMessage(payload) {
1222
+ const message = extractMessagePayload(payload);
1223
+ if (!message) return null;
1224
+ const text = readString(message, "text") ?? readString(message, "body") ?? readString(message, "subject") ?? "";
1225
+ const { senderId, senderIdExplicit, senderName } = extractSenderInfo(message);
1226
+ const { chatGuid, chatIdentifier, chatId, chatName, isGroup, participants } = extractChatContext(message);
1227
+ const normalizedParticipants = normalizeParticipantList(participants);
1228
+ const fromMe = readBoolean(message, "isFromMe") ?? readBoolean(message, "is_from_me");
1229
+ const messageId = readString(message, "guid") ?? readString(message, "id") ?? readString(message, "messageId") ?? void 0;
1230
+ const balloonBundleId = readString(message, "balloonBundleId");
1231
+ const associatedMessageGuid = readString(message, "associatedMessageGuid") ?? readString(message, "associated_message_guid") ?? readString(message, "associatedMessageId") ?? void 0;
1232
+ const associatedMessageType = readNumberLike(message, "associatedMessageType") ?? readNumberLike(message, "associated_message_type");
1233
+ const associatedMessageEmoji = readString(message, "associatedMessageEmoji") ?? readString(message, "associated_message_emoji") ?? readString(message, "reactionEmoji") ?? readString(message, "reaction_emoji") ?? void 0;
1234
+ const isTapback = readBoolean(message, "isTapback") ?? readBoolean(message, "is_tapback") ?? readBoolean(message, "tapback") ?? void 0;
1235
+ const timestampRaw = readNumber(message, "date") ?? readNumber(message, "dateCreated") ?? readNumber(message, "timestamp");
1236
+ const timestamp = typeof timestampRaw === "number" ? timestampRaw > 0xe8d4a51000 ? timestampRaw : timestampRaw * 1e3 : void 0;
1237
+ const senderFallbackFromChatGuid = !senderIdExplicit && !isGroup && chatGuid ? extractHandleFromChatGuid(chatGuid) : null;
1238
+ const normalizedSender = normalizeBlueBubblesHandle(senderId || senderFallbackFromChatGuid || "");
1239
+ if (!normalizedSender) return null;
1240
+ const replyMetadata = extractReplyMetadata(message);
1241
+ return {
1242
+ text,
1243
+ senderId: normalizedSender,
1244
+ senderIdExplicit,
1245
+ senderName,
1246
+ messageId,
1247
+ timestamp,
1248
+ isGroup,
1249
+ chatId,
1250
+ chatGuid,
1251
+ chatIdentifier,
1252
+ chatName,
1253
+ fromMe,
1254
+ attachments: extractAttachments(message),
1255
+ balloonBundleId,
1256
+ associatedMessageGuid,
1257
+ associatedMessageType,
1258
+ associatedMessageEmoji,
1259
+ isTapback,
1260
+ participants: normalizedParticipants,
1261
+ replyToId: replyMetadata.replyToId,
1262
+ replyToBody: replyMetadata.replyToBody,
1263
+ replyToSender: replyMetadata.replyToSender
1264
+ };
1265
+ }
1266
+ function normalizeWebhookReaction(payload) {
1267
+ const message = extractMessagePayload(payload);
1268
+ if (!message) return null;
1269
+ const associatedGuid = readString(message, "associatedMessageGuid") ?? readString(message, "associated_message_guid") ?? readString(message, "associatedMessageId");
1270
+ const associatedType = readNumberLike(message, "associatedMessageType") ?? readNumberLike(message, "associated_message_type");
1271
+ if (!associatedGuid || associatedType === void 0) return null;
1272
+ const mapping = REACTION_TYPE_MAP.get(associatedType);
1273
+ const emoji = ((readString(message, "associatedMessageEmoji") ?? readString(message, "associated_message_emoji") ?? readString(message, "reactionEmoji") ?? readString(message, "reaction_emoji"))?.trim() || mapping?.emoji) ?? `reaction:${associatedType}`;
1274
+ const action = mapping?.action ?? resolveTapbackActionHint(associatedType) ?? "added";
1275
+ const { senderId, senderIdExplicit, senderName } = extractSenderInfo(message);
1276
+ const { chatGuid, chatIdentifier, chatId, chatName, isGroup } = extractChatContext(message);
1277
+ const fromMe = readBoolean(message, "isFromMe") ?? readBoolean(message, "is_from_me");
1278
+ const timestampRaw = readNumberLike(message, "date") ?? readNumberLike(message, "dateCreated") ?? readNumberLike(message, "timestamp");
1279
+ const timestamp = typeof timestampRaw === "number" ? timestampRaw > 0xe8d4a51000 ? timestampRaw : timestampRaw * 1e3 : void 0;
1280
+ const senderFallbackFromChatGuid = !senderIdExplicit && !isGroup && chatGuid ? extractHandleFromChatGuid(chatGuid) : null;
1281
+ const normalizedSender = normalizeBlueBubblesHandle(senderId || senderFallbackFromChatGuid || "");
1282
+ if (!normalizedSender) return null;
1283
+ return {
1284
+ action,
1285
+ emoji,
1286
+ senderId: normalizedSender,
1287
+ senderIdExplicit,
1288
+ senderName,
1289
+ messageId: associatedGuid,
1290
+ timestamp,
1291
+ isGroup,
1292
+ chatId,
1293
+ chatGuid,
1294
+ chatIdentifier,
1295
+ chatName,
1296
+ fromMe
1297
+ };
1298
+ }
1299
+ //#endregion
1300
+ //#region extensions/bluebubbles/src/history.ts
1301
+ function resolveAccount$1(params) {
1302
+ return resolveBlueBubblesServerAccount(params);
1303
+ }
1304
+ const MAX_HISTORY_FETCH_LIMIT = 100;
1305
+ const HISTORY_SCAN_MULTIPLIER = 8;
1306
+ const MAX_HISTORY_SCAN_MESSAGES = 500;
1307
+ const MAX_HISTORY_BODY_CHARS = 2e3;
1308
+ function clampHistoryLimit(limit) {
1309
+ if (!Number.isFinite(limit)) return 0;
1310
+ const normalized = Math.floor(limit);
1311
+ if (normalized <= 0) return 0;
1312
+ return Math.min(normalized, MAX_HISTORY_FETCH_LIMIT);
1313
+ }
1314
+ function truncateHistoryBody$1(text) {
1315
+ if (text.length <= MAX_HISTORY_BODY_CHARS) return text;
1316
+ return `${text.slice(0, MAX_HISTORY_BODY_CHARS).trimEnd()}...`;
1317
+ }
1318
+ /**
1319
+ * Fetch message history from BlueBubbles API for a specific chat.
1320
+ * This provides the initial backfill for both group chats and DMs.
1321
+ */
1322
+ async function fetchBlueBubblesHistory(chatIdentifier, limit, opts = {}) {
1323
+ const effectiveLimit = clampHistoryLimit(limit);
1324
+ if (!chatIdentifier.trim() || effectiveLimit <= 0) return {
1325
+ entries: [],
1326
+ resolved: true
1327
+ };
1328
+ let baseUrl;
1329
+ let password;
1330
+ try {
1331
+ ({baseUrl, password} = resolveAccount$1(opts));
1332
+ } catch {
1333
+ return {
1334
+ entries: [],
1335
+ resolved: false
1336
+ };
1337
+ }
1338
+ const possiblePaths = [
1339
+ `/api/v1/chat/${encodeURIComponent(chatIdentifier)}/messages?limit=${effectiveLimit}&sort=DESC`,
1340
+ `/api/v1/messages?chatGuid=${encodeURIComponent(chatIdentifier)}&limit=${effectiveLimit}`,
1341
+ `/api/v1/chat/${encodeURIComponent(chatIdentifier)}/message?limit=${effectiveLimit}`
1342
+ ];
1343
+ for (const path of possiblePaths) try {
1344
+ const res = await blueBubblesFetchWithTimeout(buildBlueBubblesApiUrl({
1345
+ baseUrl,
1346
+ path,
1347
+ password
1348
+ }), { method: "GET" }, opts.timeoutMs ?? 1e4);
1349
+ if (!res.ok) continue;
1350
+ const data = await res.json().catch(() => null);
1351
+ if (!data) continue;
1352
+ let messages = [];
1353
+ if (Array.isArray(data)) messages = data;
1354
+ else if (data.data && Array.isArray(data.data)) messages = data.data;
1355
+ else if (data.messages && Array.isArray(data.messages)) messages = data.messages;
1356
+ else continue;
1357
+ const historyEntries = [];
1358
+ const maxScannedMessages = Math.min(Math.max(effectiveLimit * HISTORY_SCAN_MULTIPLIER, effectiveLimit), MAX_HISTORY_SCAN_MESSAGES);
1359
+ for (let i = 0; i < messages.length && i < maxScannedMessages; i++) {
1360
+ const msg = messages[i];
1361
+ const text = msg.text?.trim();
1362
+ if (!text) continue;
1363
+ const sender = msg.is_from_me ? "me" : msg.sender?.display_name || msg.sender?.address || msg.handle_id || "Unknown";
1364
+ const timestamp = msg.date_created || msg.date_delivered;
1365
+ historyEntries.push({
1366
+ sender,
1367
+ body: truncateHistoryBody$1(text),
1368
+ timestamp,
1369
+ messageId: msg.guid
1370
+ });
1371
+ }
1372
+ historyEntries.sort((a, b) => {
1373
+ return (a.timestamp || 0) - (b.timestamp || 0);
1374
+ });
1375
+ return {
1376
+ entries: historyEntries.slice(0, effectiveLimit),
1377
+ resolved: true
1378
+ };
1379
+ } catch (error) {
1380
+ continue;
1381
+ }
1382
+ return {
1383
+ entries: [],
1384
+ resolved: false
1385
+ };
1386
+ }
1387
+ //#endregion
1388
+ //#region extensions/bluebubbles/src/media-send.ts
1389
+ const HTTP_URL_RE = /^https?:\/\//i;
1390
+ const MB = 1024 * 1024;
1391
+ function assertMediaWithinLimit(sizeBytes, maxBytes) {
1392
+ if (typeof maxBytes !== "number" || maxBytes <= 0) return;
1393
+ if (sizeBytes <= maxBytes) return;
1394
+ const maxLabel = (maxBytes / MB).toFixed(0);
1395
+ const sizeLabel = (sizeBytes / MB).toFixed(2);
1396
+ throw new Error(`Media exceeds ${maxLabel}MB limit (got ${sizeLabel}MB)`);
1397
+ }
1398
+ function resolveLocalMediaPath(source) {
1399
+ if (!source.startsWith("file://")) return source;
1400
+ try {
1401
+ return fileURLToPath(source);
1402
+ } catch {
1403
+ throw new Error(`Invalid file:// URL: ${source}`);
1404
+ }
1405
+ }
1406
+ function expandHomePath(input) {
1407
+ if (input === "~") return os.homedir();
1408
+ if (input.startsWith("~/") || input.startsWith(`~${path.sep}`)) return path.join(os.homedir(), input.slice(2));
1409
+ return input;
1410
+ }
1411
+ function resolveConfiguredPath(input) {
1412
+ const trimmed = input.trim();
1413
+ if (!trimmed) throw new Error("Empty mediaLocalRoots entry is not allowed");
1414
+ if (trimmed.startsWith("file://")) {
1415
+ let parsed;
1416
+ try {
1417
+ parsed = fileURLToPath(trimmed);
1418
+ } catch {
1419
+ throw new Error(`Invalid file:// URL in mediaLocalRoots: ${input}`);
1420
+ }
1421
+ if (!path.isAbsolute(parsed)) throw new Error(`mediaLocalRoots entries must be absolute paths: ${input}`);
1422
+ return parsed;
1423
+ }
1424
+ const resolved = expandHomePath(trimmed);
1425
+ if (!path.isAbsolute(resolved)) throw new Error(`mediaLocalRoots entries must be absolute paths: ${input}`);
1426
+ return resolved;
1427
+ }
1428
+ function isPathInsideRoot(candidate, root) {
1429
+ const normalizedCandidate = path.normalize(candidate);
1430
+ const normalizedRoot = path.normalize(root);
1431
+ const rootWithSep = normalizedRoot.endsWith(path.sep) ? normalizedRoot : normalizedRoot + path.sep;
1432
+ if (process.platform === "win32") {
1433
+ const candidateLower = normalizedCandidate.toLowerCase();
1434
+ const rootLower = normalizedRoot.toLowerCase();
1435
+ const rootWithSepLower = rootWithSep.toLowerCase();
1436
+ return candidateLower === rootLower || candidateLower.startsWith(rootWithSepLower);
1437
+ }
1438
+ return normalizedCandidate === normalizedRoot || normalizedCandidate.startsWith(rootWithSep);
1439
+ }
1440
+ function resolveMediaLocalRoots(params) {
1441
+ return (resolveBlueBubblesAccount({
1442
+ cfg: params.cfg,
1443
+ accountId: params.accountId
1444
+ }).config.mediaLocalRoots ?? []).map((entry) => entry.trim()).filter((entry) => entry.length > 0);
1445
+ }
1446
+ async function assertLocalMediaPathAllowed(params) {
1447
+ if (params.localRoots.length === 0) throw new Error(`Local BlueBubbles media paths are disabled by default. Set channels.bluebubbles.mediaLocalRoots${params.accountId ? ` or channels.bluebubbles.accounts.${params.accountId}.mediaLocalRoots` : ""} to explicitly allow local file directories.`);
1448
+ const resolvedLocalPath = path.resolve(params.localPath);
1449
+ const supportsNoFollow = process.platform !== "win32" && "O_NOFOLLOW" in constants;
1450
+ const openFlags = constants.O_RDONLY | (supportsNoFollow ? constants.O_NOFOLLOW : 0);
1451
+ for (const rootEntry of params.localRoots) {
1452
+ const resolvedRootInput = resolveConfiguredPath(rootEntry);
1453
+ const relativeToRoot = path.relative(resolvedRootInput, resolvedLocalPath);
1454
+ if (relativeToRoot.startsWith("..") || path.isAbsolute(relativeToRoot) || relativeToRoot === "") continue;
1455
+ let rootReal;
1456
+ try {
1457
+ rootReal = await fs$1.realpath(resolvedRootInput);
1458
+ } catch {
1459
+ rootReal = path.resolve(resolvedRootInput);
1460
+ }
1461
+ const candidatePath = path.resolve(rootReal, relativeToRoot);
1462
+ if (!isPathInsideRoot(candidatePath, rootReal)) continue;
1463
+ let handle = null;
1464
+ try {
1465
+ handle = await fs$1.open(candidatePath, openFlags);
1466
+ const realPath = await fs$1.realpath(candidatePath);
1467
+ if (!isPathInsideRoot(realPath, rootReal)) continue;
1468
+ const stat = await handle.stat();
1469
+ if (!stat.isFile()) continue;
1470
+ const realStat = await fs$1.stat(realPath);
1471
+ if (stat.ino !== realStat.ino || stat.dev !== realStat.dev) continue;
1472
+ return {
1473
+ data: await handle.readFile(),
1474
+ realPath,
1475
+ sizeBytes: stat.size
1476
+ };
1477
+ } catch {
1478
+ continue;
1479
+ } finally {
1480
+ if (handle) await handle.close().catch(() => {});
1481
+ }
1482
+ }
1483
+ throw new Error(`Local media path is not under any configured mediaLocalRoots entry: ${params.localPath}`);
1484
+ }
1485
+ function resolveFilenameFromSource(source) {
1486
+ if (!source) return;
1487
+ if (source.startsWith("file://")) try {
1488
+ return path.basename(fileURLToPath(source)) || void 0;
1489
+ } catch {
1490
+ return;
1491
+ }
1492
+ if (HTTP_URL_RE.test(source)) try {
1493
+ return path.basename(new URL(source).pathname) || void 0;
1494
+ } catch {
1495
+ return;
1496
+ }
1497
+ return path.basename(source) || void 0;
1498
+ }
1499
+ async function sendBlueBubblesMedia(params) {
1500
+ const { cfg, to, mediaUrl, mediaPath, mediaBuffer, contentType, filename, caption, replyToId, accountId, asVoice } = params;
1501
+ const core = getBlueBubblesRuntime();
1502
+ const maxBytes = resolveChannelMediaMaxBytes({
1503
+ cfg,
1504
+ resolveChannelLimitMb: ({ cfg, accountId }) => cfg.channels?.bluebubbles?.accounts?.[accountId]?.mediaMaxMb ?? cfg.channels?.bluebubbles?.mediaMaxMb,
1505
+ accountId
1506
+ });
1507
+ const mediaLocalRoots = resolveMediaLocalRoots({
1508
+ cfg,
1509
+ accountId
1510
+ });
1511
+ let buffer;
1512
+ let resolvedContentType = contentType ?? void 0;
1513
+ let resolvedFilename = filename ?? void 0;
1514
+ if (mediaBuffer) {
1515
+ assertMediaWithinLimit(mediaBuffer.byteLength, maxBytes);
1516
+ buffer = mediaBuffer;
1517
+ if (!resolvedContentType) {
1518
+ const hint = mediaPath ?? mediaUrl;
1519
+ resolvedContentType = await core.media.detectMime({
1520
+ buffer: Buffer.isBuffer(mediaBuffer) ? mediaBuffer : Buffer.from(mediaBuffer),
1521
+ filePath: hint
1522
+ }) ?? void 0;
1523
+ }
1524
+ if (!resolvedFilename) resolvedFilename = resolveFilenameFromSource(mediaPath ?? mediaUrl);
1525
+ } else {
1526
+ const source = mediaPath ?? mediaUrl;
1527
+ if (!source) throw new Error("BlueBubbles media delivery requires mediaUrl, mediaPath, or mediaBuffer.");
1528
+ if (HTTP_URL_RE.test(source)) {
1529
+ const fetched = await core.channel.media.fetchRemoteMedia({
1530
+ url: source,
1531
+ maxBytes: typeof maxBytes === "number" && maxBytes > 0 ? maxBytes : void 0
1532
+ });
1533
+ buffer = fetched.buffer;
1534
+ resolvedContentType = resolvedContentType ?? fetched.contentType ?? void 0;
1535
+ resolvedFilename = resolvedFilename ?? fetched.fileName;
1536
+ } else {
1537
+ const localFile = await assertLocalMediaPathAllowed({
1538
+ localPath: expandHomePath(resolveLocalMediaPath(source)),
1539
+ localRoots: mediaLocalRoots,
1540
+ accountId
1541
+ });
1542
+ if (typeof maxBytes === "number" && maxBytes > 0) assertMediaWithinLimit(localFile.sizeBytes, maxBytes);
1543
+ const data = localFile.data;
1544
+ assertMediaWithinLimit(data.byteLength, maxBytes);
1545
+ buffer = new Uint8Array(data);
1546
+ if (!resolvedContentType) resolvedContentType = await core.media.detectMime({
1547
+ buffer: data,
1548
+ filePath: localFile.realPath
1549
+ }) ?? void 0;
1550
+ if (!resolvedFilename) resolvedFilename = resolveFilenameFromSource(localFile.realPath);
1551
+ }
1552
+ }
1553
+ const replyToMessageGuid = replyToId?.trim() ? resolveBlueBubblesMessageId(replyToId.trim(), { requireKnownShortId: true }) : void 0;
1554
+ const attachmentResult = await sendBlueBubblesAttachment({
1555
+ to,
1556
+ buffer,
1557
+ filename: resolvedFilename ?? "attachment",
1558
+ contentType: resolvedContentType ?? void 0,
1559
+ replyToMessageGuid,
1560
+ asVoice,
1561
+ opts: {
1562
+ cfg,
1563
+ accountId
1564
+ }
1565
+ });
1566
+ const trimmedCaption = caption?.trim();
1567
+ if (trimmedCaption) await sendMessageBlueBubbles(to, trimmedCaption, {
1568
+ cfg,
1569
+ accountId,
1570
+ replyToMessageGuid
1571
+ });
1572
+ return attachmentResult;
1573
+ }
1574
+ //#endregion
1575
+ //#region extensions/bluebubbles/src/monitor-reply-cache.ts
1576
+ const REPLY_CACHE_MAX = 2e3;
1577
+ const REPLY_CACHE_TTL_MS = 360 * 60 * 1e3;
1578
+ const blueBubblesReplyCacheByMessageId = /* @__PURE__ */ new Map();
1579
+ const blueBubblesShortIdToUuid = /* @__PURE__ */ new Map();
1580
+ const blueBubblesUuidToShortId = /* @__PURE__ */ new Map();
1581
+ let blueBubblesShortIdCounter = 0;
1582
+ function trimOrUndefined$2(value) {
1583
+ const trimmed = value?.trim();
1584
+ return trimmed ? trimmed : void 0;
1585
+ }
1586
+ function generateShortId() {
1587
+ blueBubblesShortIdCounter += 1;
1588
+ return String(blueBubblesShortIdCounter);
1589
+ }
1590
+ function rememberBlueBubblesReplyCache(entry) {
1591
+ const messageId = entry.messageId.trim();
1592
+ if (!messageId) return {
1593
+ ...entry,
1594
+ shortId: ""
1595
+ };
1596
+ let shortId = blueBubblesUuidToShortId.get(messageId);
1597
+ if (!shortId) {
1598
+ shortId = generateShortId();
1599
+ blueBubblesShortIdToUuid.set(shortId, messageId);
1600
+ blueBubblesUuidToShortId.set(messageId, shortId);
1601
+ }
1602
+ const fullEntry = {
1603
+ ...entry,
1604
+ messageId,
1605
+ shortId
1606
+ };
1607
+ blueBubblesReplyCacheByMessageId.delete(messageId);
1608
+ blueBubblesReplyCacheByMessageId.set(messageId, fullEntry);
1609
+ const cutoff = Date.now() - REPLY_CACHE_TTL_MS;
1610
+ for (const [key, value] of blueBubblesReplyCacheByMessageId) {
1611
+ if (value.timestamp < cutoff) {
1612
+ blueBubblesReplyCacheByMessageId.delete(key);
1613
+ if (value.shortId) {
1614
+ blueBubblesShortIdToUuid.delete(value.shortId);
1615
+ blueBubblesUuidToShortId.delete(key);
1616
+ }
1617
+ continue;
1618
+ }
1619
+ break;
1620
+ }
1621
+ while (blueBubblesReplyCacheByMessageId.size > REPLY_CACHE_MAX) {
1622
+ const oldest = blueBubblesReplyCacheByMessageId.keys().next().value;
1623
+ if (!oldest) break;
1624
+ const oldEntry = blueBubblesReplyCacheByMessageId.get(oldest);
1625
+ blueBubblesReplyCacheByMessageId.delete(oldest);
1626
+ if (oldEntry?.shortId) {
1627
+ blueBubblesShortIdToUuid.delete(oldEntry.shortId);
1628
+ blueBubblesUuidToShortId.delete(oldest);
1629
+ }
1630
+ }
1631
+ return fullEntry;
1632
+ }
1633
+ /**
1634
+ * Resolves a short message ID (e.g., "1", "2") to a full BlueBubbles GUID.
1635
+ * Returns the input unchanged if it's already a GUID or not found in the mapping.
1636
+ */
1637
+ function resolveBlueBubblesMessageId(shortOrUuid, opts) {
1638
+ const trimmed = shortOrUuid.trim();
1639
+ if (!trimmed) return trimmed;
1640
+ if (/^\d+$/.test(trimmed)) {
1641
+ const uuid = blueBubblesShortIdToUuid.get(trimmed);
1642
+ if (uuid) return uuid;
1643
+ if (opts?.requireKnownShortId) throw new Error(`BlueBubbles short message id "${trimmed}" is no longer available. Use MessageSidFull.`);
1644
+ }
1645
+ return trimmed;
1646
+ }
1647
+ /**
1648
+ * Gets the short ID for a message GUID, if one exists.
1649
+ */
1650
+ function getShortIdForUuid(uuid) {
1651
+ return blueBubblesUuidToShortId.get(uuid.trim());
1652
+ }
1653
+ function resolveReplyContextFromCache(params) {
1654
+ const replyToId = params.replyToId.trim();
1655
+ if (!replyToId) return null;
1656
+ const cached = blueBubblesReplyCacheByMessageId.get(replyToId);
1657
+ if (!cached) return null;
1658
+ if (cached.accountId !== params.accountId) return null;
1659
+ const cutoff = Date.now() - REPLY_CACHE_TTL_MS;
1660
+ if (cached.timestamp < cutoff) {
1661
+ blueBubblesReplyCacheByMessageId.delete(replyToId);
1662
+ return null;
1663
+ }
1664
+ const chatGuid = trimOrUndefined$2(params.chatGuid);
1665
+ const chatIdentifier = trimOrUndefined$2(params.chatIdentifier);
1666
+ const cachedChatGuid = trimOrUndefined$2(cached.chatGuid);
1667
+ const cachedChatIdentifier = trimOrUndefined$2(cached.chatIdentifier);
1668
+ const chatId = typeof params.chatId === "number" ? params.chatId : void 0;
1669
+ const cachedChatId = typeof cached.chatId === "number" ? cached.chatId : void 0;
1670
+ if (chatGuid && cachedChatGuid && chatGuid !== cachedChatGuid) return null;
1671
+ if (!chatGuid && chatIdentifier && cachedChatIdentifier && chatIdentifier !== cachedChatIdentifier) return null;
1672
+ if (!chatGuid && !chatIdentifier && chatId && cachedChatId && chatId !== cachedChatId) return null;
1673
+ return cached;
1674
+ }
1675
+ //#endregion
1676
+ //#region extensions/bluebubbles/src/monitor-self-chat-cache.ts
1677
+ const SELF_CHAT_TTL_MS = 1e4;
1678
+ const MAX_SELF_CHAT_CACHE_ENTRIES = 512;
1679
+ const CLEANUP_MIN_INTERVAL_MS = 1e3;
1680
+ const MAX_SELF_CHAT_BODY_CHARS = 32768;
1681
+ const cache = /* @__PURE__ */ new Map();
1682
+ let lastCleanupAt = 0;
1683
+ function normalizeBody(body) {
1684
+ if (!body) return null;
1685
+ const normalized = (body.length > MAX_SELF_CHAT_BODY_CHARS ? body.slice(0, MAX_SELF_CHAT_BODY_CHARS) : body).replace(/\r\n?/g, "\n").trim();
1686
+ return normalized ? normalized : null;
1687
+ }
1688
+ function isUsableTimestamp(timestamp) {
1689
+ return typeof timestamp === "number" && Number.isFinite(timestamp);
1690
+ }
1691
+ function digestText(text) {
1692
+ return createHash("sha256").update(text).digest("base64url");
1693
+ }
1694
+ function trimOrUndefined$1(value) {
1695
+ const trimmed = value?.trim();
1696
+ return trimmed ? trimmed : void 0;
1697
+ }
1698
+ function resolveCanonicalChatTarget(parts) {
1699
+ const handleFromGuid = parts.chatGuid ? extractHandleFromChatGuid(parts.chatGuid) : null;
1700
+ if (handleFromGuid) return handleFromGuid;
1701
+ const normalizedIdentifier = normalizeBlueBubblesHandle(parts.chatIdentifier ?? "");
1702
+ if (normalizedIdentifier) return normalizedIdentifier;
1703
+ return trimOrUndefined$1(parts.chatGuid) ?? trimOrUndefined$1(parts.chatIdentifier) ?? (typeof parts.chatId === "number" ? String(parts.chatId) : null);
1704
+ }
1705
+ function buildScope(parts) {
1706
+ const target = resolveCanonicalChatTarget(parts) ?? parts.senderId;
1707
+ return `${parts.accountId}:${target}`;
1708
+ }
1709
+ function cleanupExpired(now = Date.now()) {
1710
+ if (lastCleanupAt !== 0 && now >= lastCleanupAt && now - lastCleanupAt < CLEANUP_MIN_INTERVAL_MS) return;
1711
+ lastCleanupAt = now;
1712
+ for (const [key, seenAt] of cache.entries()) if (now - seenAt > SELF_CHAT_TTL_MS) cache.delete(key);
1713
+ }
1714
+ function enforceSizeCap() {
1715
+ while (cache.size > MAX_SELF_CHAT_CACHE_ENTRIES) {
1716
+ const oldestKey = cache.keys().next().value;
1717
+ if (typeof oldestKey !== "string") break;
1718
+ cache.delete(oldestKey);
1719
+ }
1720
+ }
1721
+ function buildKey(lookup) {
1722
+ const body = normalizeBody(lookup.body);
1723
+ if (!body || !isUsableTimestamp(lookup.timestamp)) return null;
1724
+ return `${buildScope(lookup)}:${lookup.timestamp}:${digestText(body)}`;
1725
+ }
1726
+ function rememberBlueBubblesSelfChatCopy(lookup) {
1727
+ cleanupExpired();
1728
+ const key = buildKey(lookup);
1729
+ if (!key) return;
1730
+ cache.set(key, Date.now());
1731
+ enforceSizeCap();
1732
+ }
1733
+ function hasBlueBubblesSelfChatCopy(lookup) {
1734
+ cleanupExpired();
1735
+ const key = buildKey(lookup);
1736
+ if (!key) return false;
1737
+ const seenAt = cache.get(key);
1738
+ return typeof seenAt === "number" && Date.now() - seenAt <= SELF_CHAT_TTL_MS;
1739
+ }
1740
+ //#endregion
1741
+ //#region extensions/bluebubbles/src/reactions.ts
1742
+ const REACTION_TYPES = new Set([
1743
+ "love",
1744
+ "like",
1745
+ "dislike",
1746
+ "laugh",
1747
+ "emphasize",
1748
+ "question"
1749
+ ]);
1750
+ const REACTION_ALIASES = new Map([
1751
+ ["heart", "love"],
1752
+ ["love", "love"],
1753
+ ["❤", "love"],
1754
+ ["❤️", "love"],
1755
+ ["red_heart", "love"],
1756
+ ["thumbs_up", "like"],
1757
+ ["thumbsup", "like"],
1758
+ ["thumbs-up", "like"],
1759
+ ["thumbsup", "like"],
1760
+ ["like", "like"],
1761
+ ["thumb", "like"],
1762
+ ["ok", "like"],
1763
+ ["thumbs_down", "dislike"],
1764
+ ["thumbsdown", "dislike"],
1765
+ ["thumbs-down", "dislike"],
1766
+ ["dislike", "dislike"],
1767
+ ["boo", "dislike"],
1768
+ ["no", "dislike"],
1769
+ ["haha", "laugh"],
1770
+ ["lol", "laugh"],
1771
+ ["lmao", "laugh"],
1772
+ ["rofl", "laugh"],
1773
+ ["😂", "laugh"],
1774
+ ["🤣", "laugh"],
1775
+ ["xd", "laugh"],
1776
+ ["laugh", "laugh"],
1777
+ ["emphasis", "emphasize"],
1778
+ ["emphasize", "emphasize"],
1779
+ ["exclaim", "emphasize"],
1780
+ ["!!", "emphasize"],
1781
+ ["‼", "emphasize"],
1782
+ ["‼️", "emphasize"],
1783
+ ["❗", "emphasize"],
1784
+ ["important", "emphasize"],
1785
+ ["bang", "emphasize"],
1786
+ ["question", "question"],
1787
+ ["?", "question"],
1788
+ ["❓", "question"],
1789
+ ["❔", "question"],
1790
+ ["ask", "question"],
1791
+ ["loved", "love"],
1792
+ ["liked", "like"],
1793
+ ["disliked", "dislike"],
1794
+ ["laughed", "laugh"],
1795
+ ["emphasized", "emphasize"],
1796
+ ["questioned", "question"],
1797
+ ["fire", "love"],
1798
+ ["🔥", "love"],
1799
+ ["wow", "emphasize"],
1800
+ ["!", "emphasize"],
1801
+ ["heart_eyes", "love"],
1802
+ ["smile", "laugh"],
1803
+ ["smiley", "laugh"],
1804
+ ["happy", "laugh"],
1805
+ ["joy", "laugh"]
1806
+ ]);
1807
+ const REACTION_EMOJIS = new Map([
1808
+ ["❤️", "love"],
1809
+ ["❤", "love"],
1810
+ ["♥️", "love"],
1811
+ ["♥", "love"],
1812
+ ["😍", "love"],
1813
+ ["💕", "love"],
1814
+ ["👍", "like"],
1815
+ ["👌", "like"],
1816
+ ["👎", "dislike"],
1817
+ ["🙅", "dislike"],
1818
+ ["😂", "laugh"],
1819
+ ["🤣", "laugh"],
1820
+ ["😆", "laugh"],
1821
+ ["😁", "laugh"],
1822
+ ["😹", "laugh"],
1823
+ ["‼️", "emphasize"],
1824
+ ["‼", "emphasize"],
1825
+ ["!!", "emphasize"],
1826
+ ["❗", "emphasize"],
1827
+ ["❕", "emphasize"],
1828
+ ["!", "emphasize"],
1829
+ ["❓", "question"],
1830
+ ["❔", "question"],
1831
+ ["?", "question"]
1832
+ ]);
1833
+ function resolveAccount(params) {
1834
+ return resolveBlueBubblesServerAccount(params);
1835
+ }
1836
+ function normalizeBlueBubblesReactionInput(emoji, remove) {
1837
+ const trimmed = emoji.trim();
1838
+ if (!trimmed) throw new Error("BlueBubbles reaction requires an emoji or name.");
1839
+ let raw = trimmed.toLowerCase();
1840
+ if (raw.startsWith("-")) raw = raw.slice(1);
1841
+ const aliased = REACTION_ALIASES.get(raw) ?? raw;
1842
+ const mapped = REACTION_EMOJIS.get(trimmed) ?? REACTION_EMOJIS.get(raw) ?? aliased;
1843
+ if (!REACTION_TYPES.has(mapped)) throw new Error(`Unsupported BlueBubbles reaction: ${trimmed}`);
1844
+ return remove ? `-${mapped}` : mapped;
1845
+ }
1846
+ async function sendBlueBubblesReaction(params) {
1847
+ const chatGuid = params.chatGuid.trim();
1848
+ const messageGuid = params.messageGuid.trim();
1849
+ if (!chatGuid) throw new Error("BlueBubbles reaction requires chatGuid.");
1850
+ if (!messageGuid) throw new Error("BlueBubbles reaction requires messageGuid.");
1851
+ const reaction = normalizeBlueBubblesReactionInput(params.emoji, params.remove);
1852
+ const { baseUrl, password, accountId } = resolveAccount(params.opts ?? {});
1853
+ if (getCachedBlueBubblesPrivateApiStatus(accountId) === false) throw new Error("BlueBubbles reaction requires Private API, but it is disabled on the BlueBubbles server.");
1854
+ const url = buildBlueBubblesApiUrl({
1855
+ baseUrl,
1856
+ path: "/api/v1/message/react",
1857
+ password
1858
+ });
1859
+ const payload = {
1860
+ chatGuid,
1861
+ selectedMessageGuid: messageGuid,
1862
+ reaction,
1863
+ partIndex: typeof params.partIndex === "number" ? params.partIndex : 0
1864
+ };
1865
+ const res = await blueBubblesFetchWithTimeout(url, {
1866
+ method: "POST",
1867
+ headers: { "Content-Type": "application/json" },
1868
+ body: JSON.stringify(payload)
1869
+ }, params.opts?.timeoutMs);
1870
+ if (!res.ok) {
1871
+ const errorText = await res.text();
1872
+ throw new Error(`BlueBubbles reaction failed (${res.status}): ${errorText || "unknown"}`);
1873
+ }
1874
+ }
1875
+ //#endregion
1876
+ //#region extensions/bluebubbles/src/monitor-processing.ts
1877
+ const DEFAULT_TEXT_LIMIT = 4e3;
1878
+ const invalidAckReactions = /* @__PURE__ */ new Set();
1879
+ const REPLY_DIRECTIVE_TAG_RE = /\[\[\s*(?:reply_to_current|reply_to\s*:\s*[^\]\n]+)\s*\]\]/gi;
1880
+ const PENDING_OUTBOUND_MESSAGE_ID_TTL_MS = 120 * 1e3;
1881
+ const pendingOutboundMessageIds = [];
1882
+ let pendingOutboundMessageIdCounter = 0;
1883
+ function trimOrUndefined(value) {
1884
+ const trimmed = value?.trim();
1885
+ return trimmed ? trimmed : void 0;
1886
+ }
1887
+ function normalizeSnippet(value) {
1888
+ return stripMarkdown(value).replace(/\s+/g, " ").trim().toLowerCase();
1889
+ }
1890
+ function isBlueBubblesSelfChatMessage(message, isGroup) {
1891
+ if (isGroup || !message.senderIdExplicit) return false;
1892
+ const chatHandle = (message.chatGuid ? extractHandleFromChatGuid(message.chatGuid) : null) ?? normalizeBlueBubblesHandle(message.chatIdentifier ?? "");
1893
+ return Boolean(chatHandle) && chatHandle === message.senderId;
1894
+ }
1895
+ function prunePendingOutboundMessageIds(now = Date.now()) {
1896
+ const cutoff = now - PENDING_OUTBOUND_MESSAGE_ID_TTL_MS;
1897
+ for (let i = pendingOutboundMessageIds.length - 1; i >= 0; i--) if (pendingOutboundMessageIds[i].createdAt < cutoff) pendingOutboundMessageIds.splice(i, 1);
1898
+ }
1899
+ function rememberPendingOutboundMessageId(entry) {
1900
+ prunePendingOutboundMessageIds();
1901
+ pendingOutboundMessageIdCounter += 1;
1902
+ const snippetRaw = entry.snippet.trim();
1903
+ const snippetNorm = normalizeSnippet(snippetRaw);
1904
+ pendingOutboundMessageIds.push({
1905
+ id: pendingOutboundMessageIdCounter,
1906
+ accountId: entry.accountId,
1907
+ sessionKey: entry.sessionKey,
1908
+ outboundTarget: entry.outboundTarget,
1909
+ chatGuid: trimOrUndefined(entry.chatGuid),
1910
+ chatIdentifier: trimOrUndefined(entry.chatIdentifier),
1911
+ chatId: typeof entry.chatId === "number" ? entry.chatId : void 0,
1912
+ snippetRaw,
1913
+ snippetNorm,
1914
+ isMediaSnippet: snippetRaw.toLowerCase().startsWith("<media:"),
1915
+ createdAt: Date.now()
1916
+ });
1917
+ return pendingOutboundMessageIdCounter;
1918
+ }
1919
+ function forgetPendingOutboundMessageId(id) {
1920
+ const index = pendingOutboundMessageIds.findIndex((entry) => entry.id === id);
1921
+ if (index >= 0) pendingOutboundMessageIds.splice(index, 1);
1922
+ }
1923
+ function chatsMatch(left, right) {
1924
+ const leftGuid = trimOrUndefined(left.chatGuid);
1925
+ const rightGuid = trimOrUndefined(right.chatGuid);
1926
+ if (leftGuid && rightGuid) return leftGuid === rightGuid;
1927
+ const leftIdentifier = trimOrUndefined(left.chatIdentifier);
1928
+ const rightIdentifier = trimOrUndefined(right.chatIdentifier);
1929
+ if (leftIdentifier && rightIdentifier) return leftIdentifier === rightIdentifier;
1930
+ const leftChatId = typeof left.chatId === "number" ? left.chatId : void 0;
1931
+ const rightChatId = typeof right.chatId === "number" ? right.chatId : void 0;
1932
+ if (leftChatId !== void 0 && rightChatId !== void 0) return leftChatId === rightChatId;
1933
+ return false;
1934
+ }
1935
+ function consumePendingOutboundMessageId(params) {
1936
+ prunePendingOutboundMessageIds();
1937
+ const bodyNorm = normalizeSnippet(params.body);
1938
+ const isMediaBody = params.body.trim().toLowerCase().startsWith("<media:");
1939
+ for (let i = 0; i < pendingOutboundMessageIds.length; i++) {
1940
+ const entry = pendingOutboundMessageIds[i];
1941
+ if (entry.accountId !== params.accountId) continue;
1942
+ if (!chatsMatch(entry, params)) continue;
1943
+ if (entry.snippetNorm && entry.snippetNorm === bodyNorm) {
1944
+ pendingOutboundMessageIds.splice(i, 1);
1945
+ return entry;
1946
+ }
1947
+ if (entry.isMediaSnippet && isMediaBody) {
1948
+ pendingOutboundMessageIds.splice(i, 1);
1949
+ return entry;
1950
+ }
1951
+ }
1952
+ return null;
1953
+ }
1954
+ function logVerbose(core, runtime, message) {
1955
+ if (core.logging.shouldLogVerbose()) runtime.log?.(`[bluebubbles] ${message}`);
1956
+ }
1957
+ function logGroupAllowlistHint(params) {
1958
+ const log = params.runtime.log ?? console.log;
1959
+ const nameHint = params.chatName ? ` (group name: ${params.chatName})` : "";
1960
+ const accountHint = params.accountId ? ` (or channels.bluebubbles.accounts.${params.accountId}.groupAllowFrom)` : "";
1961
+ if (params.entry) {
1962
+ log(`[bluebubbles] group message blocked (${params.reason}). Allow this group by adding "${params.entry}" to channels.bluebubbles.groupAllowFrom${nameHint}.`);
1963
+ log(`[bluebubbles] add to config: channels.bluebubbles.groupAllowFrom=["${params.entry}"]${accountHint}.`);
1964
+ return;
1965
+ }
1966
+ log(`[bluebubbles] group message blocked (${params.reason}). Allow groups by setting channels.bluebubbles.groupPolicy="open" or adding a group id to channels.bluebubbles.groupAllowFrom${accountHint}${nameHint}.`);
1967
+ }
1968
+ function resolveBlueBubblesAckReaction(params) {
1969
+ const raw = resolveAckReaction(params.cfg, params.agentId).trim();
1970
+ if (!raw) return null;
1971
+ try {
1972
+ normalizeBlueBubblesReactionInput(raw);
1973
+ return raw;
1974
+ } catch {
1975
+ const key = raw.toLowerCase();
1976
+ if (!invalidAckReactions.has(key)) {
1977
+ invalidAckReactions.add(key);
1978
+ logVerbose(params.core, params.runtime, `ack reaction skipped (unsupported for BlueBubbles): ${raw}`);
1979
+ }
1980
+ return null;
1981
+ }
1982
+ }
1983
+ /**
1984
+ * In-memory rolling history map keyed by account + chat identifier.
1985
+ * Populated from incoming messages during the session.
1986
+ * API backfill is attempted until one fetch resolves (or retries are exhausted).
1987
+ */
1988
+ const chatHistories = /* @__PURE__ */ new Map();
1989
+ const historyBackfills = /* @__PURE__ */ new Map();
1990
+ const HISTORY_BACKFILL_BASE_DELAY_MS = 5e3;
1991
+ const HISTORY_BACKFILL_MAX_DELAY_MS = 120 * 1e3;
1992
+ const HISTORY_BACKFILL_MAX_ATTEMPTS = 6;
1993
+ const HISTORY_BACKFILL_RETRY_WINDOW_MS = 1800 * 1e3;
1994
+ const MAX_STORED_HISTORY_ENTRY_CHARS = 2e3;
1995
+ const MAX_INBOUND_HISTORY_ENTRY_CHARS = 1200;
1996
+ const MAX_INBOUND_HISTORY_TOTAL_CHARS = 12e3;
1997
+ function buildAccountScopedHistoryKey(accountId, historyIdentifier) {
1998
+ return `${accountId}\u0000${historyIdentifier}`;
1999
+ }
2000
+ function historyDedupKey(entry) {
2001
+ const messageId = entry.messageId?.trim();
2002
+ if (messageId) return `id:${messageId}`;
2003
+ return `fallback:${entry.sender}\u0000${entry.body}\u0000${entry.timestamp ?? ""}`;
2004
+ }
2005
+ function truncateHistoryBody(body, maxChars) {
2006
+ const trimmed = body.trim();
2007
+ if (!trimmed) return "";
2008
+ if (trimmed.length <= maxChars) return trimmed;
2009
+ return `${trimmed.slice(0, maxChars).trimEnd()}...`;
2010
+ }
2011
+ function mergeHistoryEntries(params) {
2012
+ if (params.limit <= 0) return [];
2013
+ const merged = [];
2014
+ const seen = /* @__PURE__ */ new Set();
2015
+ const appendUnique = (entry) => {
2016
+ const key = historyDedupKey(entry);
2017
+ if (seen.has(key)) return;
2018
+ seen.add(key);
2019
+ merged.push(entry);
2020
+ };
2021
+ for (const entry of params.apiEntries) appendUnique(entry);
2022
+ for (const entry of params.currentEntries) appendUnique(entry);
2023
+ if (merged.length <= params.limit) return merged;
2024
+ return merged.slice(merged.length - params.limit);
2025
+ }
2026
+ function pruneHistoryBackfillState() {
2027
+ for (const key of historyBackfills.keys()) if (!chatHistories.has(key)) historyBackfills.delete(key);
2028
+ }
2029
+ function markHistoryBackfillResolved(historyKey) {
2030
+ const state = historyBackfills.get(historyKey);
2031
+ if (state) {
2032
+ state.resolved = true;
2033
+ historyBackfills.set(historyKey, state);
2034
+ return;
2035
+ }
2036
+ historyBackfills.set(historyKey, {
2037
+ attempts: 0,
2038
+ firstAttemptAt: Date.now(),
2039
+ nextAttemptAt: Number.POSITIVE_INFINITY,
2040
+ resolved: true
2041
+ });
2042
+ }
2043
+ function planHistoryBackfillAttempt(historyKey, now) {
2044
+ const existing = historyBackfills.get(historyKey);
2045
+ if (existing?.resolved) return null;
2046
+ if (existing && now - existing.firstAttemptAt > HISTORY_BACKFILL_RETRY_WINDOW_MS) {
2047
+ markHistoryBackfillResolved(historyKey);
2048
+ return null;
2049
+ }
2050
+ if (existing && existing.attempts >= HISTORY_BACKFILL_MAX_ATTEMPTS) {
2051
+ markHistoryBackfillResolved(historyKey);
2052
+ return null;
2053
+ }
2054
+ if (existing && now < existing.nextAttemptAt) return null;
2055
+ const attempts = (existing?.attempts ?? 0) + 1;
2056
+ const state = {
2057
+ attempts,
2058
+ firstAttemptAt: existing?.firstAttemptAt ?? now,
2059
+ nextAttemptAt: now + Math.min(HISTORY_BACKFILL_BASE_DELAY_MS * 2 ** (attempts - 1), HISTORY_BACKFILL_MAX_DELAY_MS),
2060
+ resolved: false
2061
+ };
2062
+ historyBackfills.set(historyKey, state);
2063
+ return state;
2064
+ }
2065
+ function buildInboundHistorySnapshot(params) {
2066
+ if (params.limit <= 0 || params.entries.length === 0) return;
2067
+ const recent = params.entries.slice(-params.limit);
2068
+ const selected = [];
2069
+ let remainingChars = MAX_INBOUND_HISTORY_TOTAL_CHARS;
2070
+ for (let i = recent.length - 1; i >= 0; i--) {
2071
+ const entry = recent[i];
2072
+ const body = truncateHistoryBody(entry.body, MAX_INBOUND_HISTORY_ENTRY_CHARS);
2073
+ if (!body) continue;
2074
+ if (selected.length > 0 && body.length > remainingChars) break;
2075
+ selected.push({
2076
+ sender: entry.sender,
2077
+ body,
2078
+ timestamp: entry.timestamp
2079
+ });
2080
+ remainingChars -= body.length;
2081
+ if (remainingChars <= 0) break;
2082
+ }
2083
+ if (selected.length === 0) return;
2084
+ selected.reverse();
2085
+ return selected;
2086
+ }
2087
+ async function processMessage(message, target) {
2088
+ const { account, config, runtime, core, statusSink } = target;
2089
+ const pairing = createScopedPairingAccess({
2090
+ core,
2091
+ channel: "bluebubbles",
2092
+ accountId: account.accountId
2093
+ });
2094
+ const privateApiEnabled = isBlueBubblesPrivateApiEnabled(account.accountId);
2095
+ const groupFlag = resolveGroupFlagFromChatGuid(message.chatGuid);
2096
+ const isGroup = typeof groupFlag === "boolean" ? groupFlag : message.isGroup;
2097
+ const text = message.text.trim();
2098
+ const attachments = message.attachments ?? [];
2099
+ const placeholder = buildMessagePlaceholder(message);
2100
+ const tapbackContext = resolveTapbackContext(message);
2101
+ const tapbackParsed = parseTapbackText({
2102
+ text,
2103
+ emojiHint: tapbackContext?.emojiHint,
2104
+ actionHint: tapbackContext?.actionHint,
2105
+ requireQuoted: !tapbackContext
2106
+ });
2107
+ const isTapbackMessage = Boolean(tapbackParsed);
2108
+ const rawBody = tapbackParsed ? tapbackParsed.action === "removed" ? `removed ${tapbackParsed.emoji} reaction` : `reacted with ${tapbackParsed.emoji}` : text || placeholder;
2109
+ const isSelfChatMessage = isBlueBubblesSelfChatMessage(message, isGroup);
2110
+ const selfChatLookup = {
2111
+ accountId: account.accountId,
2112
+ chatGuid: message.chatGuid,
2113
+ chatIdentifier: message.chatIdentifier,
2114
+ chatId: message.chatId,
2115
+ senderId: message.senderId,
2116
+ body: rawBody,
2117
+ timestamp: message.timestamp
2118
+ };
2119
+ const cacheMessageId = message.messageId?.trim();
2120
+ const confirmedOutboundCacheEntry = cacheMessageId ? resolveReplyContextFromCache({
2121
+ accountId: account.accountId,
2122
+ replyToId: cacheMessageId,
2123
+ chatGuid: message.chatGuid,
2124
+ chatIdentifier: message.chatIdentifier,
2125
+ chatId: message.chatId
2126
+ }) : null;
2127
+ let messageShortId;
2128
+ const cacheInboundMessage = () => {
2129
+ if (!cacheMessageId) return;
2130
+ messageShortId = rememberBlueBubblesReplyCache({
2131
+ accountId: account.accountId,
2132
+ messageId: cacheMessageId,
2133
+ chatGuid: message.chatGuid,
2134
+ chatIdentifier: message.chatIdentifier,
2135
+ chatId: message.chatId,
2136
+ senderLabel: message.fromMe ? "me" : message.senderId,
2137
+ body: rawBody,
2138
+ timestamp: message.timestamp ?? Date.now()
2139
+ }).shortId;
2140
+ };
2141
+ if (message.fromMe) {
2142
+ cacheInboundMessage();
2143
+ const confirmedAssistantOutbound = confirmedOutboundCacheEntry?.senderLabel === "me" && normalizeSnippet(confirmedOutboundCacheEntry.body ?? "") === normalizeSnippet(rawBody);
2144
+ if (isSelfChatMessage && confirmedAssistantOutbound) rememberBlueBubblesSelfChatCopy(selfChatLookup);
2145
+ if (cacheMessageId) {
2146
+ const pending = consumePendingOutboundMessageId({
2147
+ accountId: account.accountId,
2148
+ chatGuid: message.chatGuid,
2149
+ chatIdentifier: message.chatIdentifier,
2150
+ chatId: message.chatId,
2151
+ body: rawBody
2152
+ });
2153
+ if (pending) {
2154
+ const displayId = getShortIdForUuid(cacheMessageId) || cacheMessageId;
2155
+ const previewSource = pending.snippetRaw || rawBody;
2156
+ const preview = previewSource ? ` "${previewSource.slice(0, 12)}${previewSource.length > 12 ? "…" : ""}"` : "";
2157
+ core.system.enqueueSystemEvent(`Assistant sent${preview} [message_id:${displayId}]`, {
2158
+ sessionKey: pending.sessionKey,
2159
+ contextKey: `bluebubbles:outbound:${pending.outboundTarget}:${cacheMessageId}`
2160
+ });
2161
+ }
2162
+ }
2163
+ return;
2164
+ }
2165
+ if (isSelfChatMessage && hasBlueBubblesSelfChatCopy(selfChatLookup)) {
2166
+ logVerbose(core, runtime, `drop: reflected self-chat duplicate sender=${message.senderId}`);
2167
+ return;
2168
+ }
2169
+ if (!rawBody) {
2170
+ logVerbose(core, runtime, `drop: empty text sender=${message.senderId}`);
2171
+ return;
2172
+ }
2173
+ logVerbose(core, runtime, `msg sender=${message.senderId} group=${isGroup} textLen=${text.length} attachments=${attachments.length} chatGuid=${message.chatGuid ?? ""} chatId=${message.chatId ?? ""}`);
2174
+ const dmPolicy = account.config.dmPolicy ?? "pairing";
2175
+ const groupPolicy = account.config.groupPolicy ?? "allowlist";
2176
+ const configuredAllowFrom = mapAllowFromEntries(account.config.allowFrom);
2177
+ const storeAllowFrom = await readStoreAllowFromForDmPolicy({
2178
+ provider: "bluebubbles",
2179
+ accountId: account.accountId,
2180
+ dmPolicy,
2181
+ readStore: pairing.readStoreForDmPolicy
2182
+ });
2183
+ const accessDecision = resolveDmGroupAccessWithLists({
2184
+ isGroup,
2185
+ dmPolicy,
2186
+ groupPolicy,
2187
+ allowFrom: configuredAllowFrom,
2188
+ groupAllowFrom: account.config.groupAllowFrom,
2189
+ storeAllowFrom,
2190
+ isSenderAllowed: (allowFrom) => isAllowedBlueBubblesSender({
2191
+ allowFrom,
2192
+ sender: message.senderId,
2193
+ chatId: message.chatId ?? void 0,
2194
+ chatGuid: message.chatGuid ?? void 0,
2195
+ chatIdentifier: message.chatIdentifier ?? void 0
2196
+ })
2197
+ });
2198
+ const effectiveAllowFrom = accessDecision.effectiveAllowFrom;
2199
+ const effectiveGroupAllowFrom = accessDecision.effectiveGroupAllowFrom;
2200
+ const groupAllowEntry = formatGroupAllowlistEntry({
2201
+ chatGuid: message.chatGuid,
2202
+ chatId: message.chatId ?? void 0,
2203
+ chatIdentifier: message.chatIdentifier ?? void 0
2204
+ });
2205
+ const groupName = message.chatName?.trim() || void 0;
2206
+ if (accessDecision.decision !== "allow") {
2207
+ if (isGroup) {
2208
+ if (accessDecision.reasonCode === DM_GROUP_ACCESS_REASON.GROUP_POLICY_DISABLED) {
2209
+ logVerbose(core, runtime, "Blocked BlueBubbles group message (groupPolicy=disabled)");
2210
+ logGroupAllowlistHint({
2211
+ runtime,
2212
+ reason: "groupPolicy=disabled",
2213
+ entry: groupAllowEntry,
2214
+ chatName: groupName,
2215
+ accountId: account.accountId
2216
+ });
2217
+ return;
2218
+ }
2219
+ if (accessDecision.reasonCode === DM_GROUP_ACCESS_REASON.GROUP_POLICY_EMPTY_ALLOWLIST) {
2220
+ logVerbose(core, runtime, "Blocked BlueBubbles group message (no allowlist)");
2221
+ logGroupAllowlistHint({
2222
+ runtime,
2223
+ reason: "groupPolicy=allowlist (empty allowlist)",
2224
+ entry: groupAllowEntry,
2225
+ chatName: groupName,
2226
+ accountId: account.accountId
2227
+ });
2228
+ return;
2229
+ }
2230
+ if (accessDecision.reasonCode === DM_GROUP_ACCESS_REASON.GROUP_POLICY_NOT_ALLOWLISTED) {
2231
+ logVerbose(core, runtime, `Blocked BlueBubbles sender ${message.senderId} (not in groupAllowFrom)`);
2232
+ logVerbose(core, runtime, `drop: group sender not allowed sender=${message.senderId} allowFrom=${effectiveGroupAllowFrom.join(",")}`);
2233
+ logGroupAllowlistHint({
2234
+ runtime,
2235
+ reason: "groupPolicy=allowlist (not allowlisted)",
2236
+ entry: groupAllowEntry,
2237
+ chatName: groupName,
2238
+ accountId: account.accountId
2239
+ });
2240
+ return;
2241
+ }
2242
+ return;
2243
+ }
2244
+ if (accessDecision.reasonCode === DM_GROUP_ACCESS_REASON.DM_POLICY_DISABLED) {
2245
+ logVerbose(core, runtime, `Blocked BlueBubbles DM from ${message.senderId}`);
2246
+ logVerbose(core, runtime, `drop: dmPolicy disabled sender=${message.senderId}`);
2247
+ return;
2248
+ }
2249
+ if (accessDecision.decision === "pairing") {
2250
+ await issuePairingChallenge({
2251
+ channel: "bluebubbles",
2252
+ senderId: message.senderId,
2253
+ senderIdLine: `Your BlueBubbles sender id: ${message.senderId}`,
2254
+ meta: { name: message.senderName },
2255
+ upsertPairingRequest: pairing.upsertPairingRequest,
2256
+ onCreated: () => {
2257
+ runtime.log?.(`[bluebubbles] pairing request sender=${message.senderId} created=true`);
2258
+ logVerbose(core, runtime, `bluebubbles pairing request sender=${message.senderId}`);
2259
+ },
2260
+ sendPairingReply: async (text) => {
2261
+ await sendMessageBlueBubbles(message.senderId, text, {
2262
+ cfg: config,
2263
+ accountId: account.accountId
2264
+ });
2265
+ statusSink?.({ lastOutboundAt: Date.now() });
2266
+ },
2267
+ onReplyError: (err) => {
2268
+ logVerbose(core, runtime, `bluebubbles pairing reply failed for ${message.senderId}: ${String(err)}`);
2269
+ runtime.error?.(`[bluebubbles] pairing reply failed sender=${message.senderId}: ${String(err)}`);
2270
+ }
2271
+ });
2272
+ return;
2273
+ }
2274
+ logVerbose(core, runtime, `Blocked unauthorized BlueBubbles sender ${message.senderId} (dmPolicy=${dmPolicy})`);
2275
+ logVerbose(core, runtime, `drop: dm sender not allowed sender=${message.senderId} allowFrom=${effectiveAllowFrom.join(",")}`);
2276
+ return;
2277
+ }
2278
+ const chatId = message.chatId ?? void 0;
2279
+ const chatGuid = message.chatGuid ?? void 0;
2280
+ const chatIdentifier = message.chatIdentifier ?? void 0;
2281
+ const peerId = isGroup ? chatGuid ?? chatIdentifier ?? (chatId ? String(chatId) : "group") : message.senderId;
2282
+ const route = core.channel.routing.resolveAgentRoute({
2283
+ cfg: config,
2284
+ channel: "bluebubbles",
2285
+ accountId: account.accountId,
2286
+ peer: {
2287
+ kind: isGroup ? "group" : "direct",
2288
+ id: peerId
2289
+ }
2290
+ });
2291
+ const messageText = text;
2292
+ const mentionRegexes = core.channel.mentions.buildMentionRegexes(config, route.agentId);
2293
+ const wasMentioned = isGroup ? core.channel.mentions.matchesMentionPatterns(messageText, mentionRegexes) : true;
2294
+ const canDetectMention = mentionRegexes.length > 0;
2295
+ const requireMention = core.channel.groups.resolveRequireMention({
2296
+ cfg: config,
2297
+ channel: "bluebubbles",
2298
+ groupId: peerId,
2299
+ accountId: account.accountId
2300
+ });
2301
+ const useAccessGroups = config.commands?.useAccessGroups !== false;
2302
+ const hasControlCmd = core.channel.text.hasControlCommand(messageText, config);
2303
+ const commandDmAllowFrom = isGroup ? configuredAllowFrom : effectiveAllowFrom;
2304
+ const ownerAllowedForCommands = commandDmAllowFrom.length > 0 ? isAllowedBlueBubblesSender({
2305
+ allowFrom: commandDmAllowFrom,
2306
+ sender: message.senderId,
2307
+ chatId: message.chatId ?? void 0,
2308
+ chatGuid: message.chatGuid ?? void 0,
2309
+ chatIdentifier: message.chatIdentifier ?? void 0
2310
+ }) : false;
2311
+ const groupAllowedForCommands = effectiveGroupAllowFrom.length > 0 ? isAllowedBlueBubblesSender({
2312
+ allowFrom: effectiveGroupAllowFrom,
2313
+ sender: message.senderId,
2314
+ chatId: message.chatId ?? void 0,
2315
+ chatGuid: message.chatGuid ?? void 0,
2316
+ chatIdentifier: message.chatIdentifier ?? void 0
2317
+ }) : false;
2318
+ const commandGate = resolveControlCommandGate({
2319
+ useAccessGroups,
2320
+ authorizers: [{
2321
+ configured: commandDmAllowFrom.length > 0,
2322
+ allowed: ownerAllowedForCommands
2323
+ }, {
2324
+ configured: effectiveGroupAllowFrom.length > 0,
2325
+ allowed: groupAllowedForCommands
2326
+ }],
2327
+ allowTextCommands: true,
2328
+ hasControlCommand: hasControlCmd
2329
+ });
2330
+ const commandAuthorized = commandGate.commandAuthorized;
2331
+ if (isGroup && commandGate.shouldBlock) {
2332
+ logInboundDrop({
2333
+ log: (msg) => logVerbose(core, runtime, msg),
2334
+ channel: "bluebubbles",
2335
+ reason: "control command (unauthorized)",
2336
+ target: message.senderId
2337
+ });
2338
+ return;
2339
+ }
2340
+ const shouldBypassMention = isGroup && requireMention && !wasMentioned && commandAuthorized && hasControlCmd;
2341
+ const effectiveWasMentioned = wasMentioned || shouldBypassMention;
2342
+ if (isGroup && requireMention && canDetectMention && !wasMentioned && !shouldBypassMention) {
2343
+ logVerbose(core, runtime, `bluebubbles: skipping group message (no mention)`);
2344
+ return;
2345
+ }
2346
+ cacheInboundMessage();
2347
+ const baseUrl = normalizeSecretInputString(account.config.serverUrl);
2348
+ const password = normalizeSecretInputString(account.config.password);
2349
+ const maxBytes = account.config.mediaMaxMb && account.config.mediaMaxMb > 0 ? account.config.mediaMaxMb * 1024 * 1024 : 8 * 1024 * 1024;
2350
+ let mediaUrls = [];
2351
+ let mediaPaths = [];
2352
+ let mediaTypes = [];
2353
+ if (attachments.length > 0) if (!baseUrl || !password) logVerbose(core, runtime, "attachment download skipped (missing serverUrl/password)");
2354
+ else for (const attachment of attachments) {
2355
+ if (!attachment.guid) continue;
2356
+ if (attachment.totalBytes && attachment.totalBytes > maxBytes) {
2357
+ logVerbose(core, runtime, `attachment too large guid=${attachment.guid} bytes=${attachment.totalBytes}`);
2358
+ continue;
2359
+ }
2360
+ try {
2361
+ const downloaded = await downloadBlueBubblesAttachment(attachment, {
2362
+ cfg: config,
2363
+ accountId: account.accountId,
2364
+ maxBytes
2365
+ });
2366
+ const saved = await core.channel.media.saveMediaBuffer(Buffer.from(downloaded.buffer), downloaded.contentType, "inbound", maxBytes);
2367
+ mediaPaths.push(saved.path);
2368
+ mediaUrls.push(saved.path);
2369
+ if (saved.contentType) mediaTypes.push(saved.contentType);
2370
+ } catch (err) {
2371
+ logVerbose(core, runtime, `attachment download failed guid=${attachment.guid} err=${String(err)}`);
2372
+ }
2373
+ }
2374
+ let replyToId = message.replyToId;
2375
+ let replyToBody = message.replyToBody;
2376
+ let replyToSender = message.replyToSender;
2377
+ let replyToShortId;
2378
+ if (isTapbackMessage && tapbackContext?.replyToId) replyToId = tapbackContext.replyToId;
2379
+ if (replyToId) {
2380
+ const cached = resolveReplyContextFromCache({
2381
+ accountId: account.accountId,
2382
+ replyToId,
2383
+ chatGuid: message.chatGuid,
2384
+ chatIdentifier: message.chatIdentifier,
2385
+ chatId: message.chatId
2386
+ });
2387
+ if (cached) {
2388
+ if (!replyToBody && cached.body) replyToBody = cached.body;
2389
+ if (!replyToSender && cached.senderLabel) replyToSender = cached.senderLabel;
2390
+ replyToShortId = cached.shortId;
2391
+ if (core.logging.shouldLogVerbose()) {
2392
+ const preview = (cached.body ?? "").replace(/\s+/g, " ").slice(0, 120);
2393
+ logVerbose(core, runtime, `reply-context cache hit replyToId=${replyToId} sender=${replyToSender ?? ""} body="${preview}"`);
2394
+ }
2395
+ }
2396
+ }
2397
+ if (replyToId && !replyToShortId) replyToShortId = getShortIdForUuid(replyToId);
2398
+ const replyTag = formatReplyTag({
2399
+ replyToId,
2400
+ replyToShortId
2401
+ });
2402
+ const baseBody = replyTag ? isTapbackMessage ? `${rawBody} ${replyTag}` : `${replyTag} ${rawBody}` : rawBody;
2403
+ const senderLabel = message.senderName || `user:${message.senderId}`;
2404
+ const fromLabel = isGroup ? `${message.chatName?.trim() || "Group"} id:${peerId}` : senderLabel !== message.senderId ? `${senderLabel} id:${message.senderId}` : senderLabel;
2405
+ const groupSubject = isGroup ? message.chatName?.trim() || void 0 : void 0;
2406
+ const groupMembers = isGroup ? formatGroupMembers({
2407
+ participants: message.participants,
2408
+ fallback: message.senderId ? {
2409
+ id: message.senderId,
2410
+ name: message.senderName
2411
+ } : void 0
2412
+ }) : void 0;
2413
+ const storePath = core.channel.session.resolveStorePath(config.session?.store, { agentId: route.agentId });
2414
+ const envelopeOptions = core.channel.reply.resolveEnvelopeFormatOptions(config);
2415
+ const previousTimestamp = core.channel.session.readSessionUpdatedAt({
2416
+ storePath,
2417
+ sessionKey: route.sessionKey
2418
+ });
2419
+ const body = core.channel.reply.formatInboundEnvelope({
2420
+ channel: "BlueBubbles",
2421
+ from: fromLabel,
2422
+ timestamp: message.timestamp,
2423
+ previousTimestamp,
2424
+ envelope: envelopeOptions,
2425
+ body: baseBody,
2426
+ chatType: isGroup ? "group" : "direct",
2427
+ sender: {
2428
+ name: message.senderName || void 0,
2429
+ id: message.senderId
2430
+ }
2431
+ });
2432
+ let chatGuidForActions = chatGuid;
2433
+ if (!chatGuidForActions && baseUrl && password) {
2434
+ const resolveTarget = isGroup && (chatId || chatIdentifier) ? chatId ? {
2435
+ kind: "chat_id",
2436
+ chatId
2437
+ } : {
2438
+ kind: "chat_identifier",
2439
+ chatIdentifier: chatIdentifier ?? ""
2440
+ } : {
2441
+ kind: "handle",
2442
+ address: message.senderId
2443
+ };
2444
+ if (resolveTarget.kind !== "chat_identifier" || resolveTarget.chatIdentifier) chatGuidForActions = await resolveChatGuidForTarget({
2445
+ baseUrl,
2446
+ password,
2447
+ target: resolveTarget
2448
+ }) ?? void 0;
2449
+ }
2450
+ const ackReactionScope = config.messages?.ackReactionScope ?? "group-mentions";
2451
+ const removeAckAfterReply = config.messages?.removeAckAfterReply ?? false;
2452
+ const ackReactionValue = resolveBlueBubblesAckReaction({
2453
+ cfg: config,
2454
+ agentId: route.agentId,
2455
+ core,
2456
+ runtime
2457
+ });
2458
+ const shouldAckReaction = () => Boolean(ackReactionValue && core.channel.reactions.shouldAckReaction({
2459
+ scope: ackReactionScope,
2460
+ isDirect: !isGroup,
2461
+ isGroup,
2462
+ isMentionableGroup: isGroup,
2463
+ requireMention: Boolean(requireMention),
2464
+ canDetectMention,
2465
+ effectiveWasMentioned,
2466
+ shouldBypassMention
2467
+ }));
2468
+ const ackMessageId = message.messageId?.trim() || "";
2469
+ const ackReactionPromise = shouldAckReaction() && ackMessageId && chatGuidForActions && ackReactionValue ? sendBlueBubblesReaction({
2470
+ chatGuid: chatGuidForActions,
2471
+ messageGuid: ackMessageId,
2472
+ emoji: ackReactionValue,
2473
+ opts: {
2474
+ cfg: config,
2475
+ accountId: account.accountId
2476
+ }
2477
+ }).then(() => true, (err) => {
2478
+ logVerbose(core, runtime, `ack reaction failed chatGuid=${chatGuidForActions} msg=${ackMessageId}: ${String(err)}`);
2479
+ return false;
2480
+ }) : null;
2481
+ const sendReadReceipts = account.config.sendReadReceipts !== false;
2482
+ if (chatGuidForActions && baseUrl && password && sendReadReceipts) try {
2483
+ await markBlueBubblesChatRead(chatGuidForActions, {
2484
+ cfg: config,
2485
+ accountId: account.accountId
2486
+ });
2487
+ logVerbose(core, runtime, `marked read chatGuid=${chatGuidForActions}`);
2488
+ } catch (err) {
2489
+ runtime.error?.(`[bluebubbles] mark read failed: ${String(err)}`);
2490
+ }
2491
+ else if (!sendReadReceipts) logVerbose(core, runtime, "mark read skipped (sendReadReceipts=false)");
2492
+ else logVerbose(core, runtime, "mark read skipped (missing chatGuid or credentials)");
2493
+ const outboundTarget = isGroup ? formatBlueBubblesChatTarget({
2494
+ chatId,
2495
+ chatGuid: chatGuidForActions ?? chatGuid,
2496
+ chatIdentifier
2497
+ }) || peerId : chatGuidForActions ? formatBlueBubblesChatTarget({ chatGuid: chatGuidForActions }) : message.senderId;
2498
+ const maybeEnqueueOutboundMessageId = (messageId, snippet) => {
2499
+ const trimmed = messageId?.trim();
2500
+ if (!trimmed || trimmed === "ok" || trimmed === "unknown") return false;
2501
+ const displayId = rememberBlueBubblesReplyCache({
2502
+ accountId: account.accountId,
2503
+ messageId: trimmed,
2504
+ chatGuid: chatGuidForActions ?? chatGuid,
2505
+ chatIdentifier,
2506
+ chatId,
2507
+ senderLabel: "me",
2508
+ body: snippet ?? "",
2509
+ timestamp: Date.now()
2510
+ }).shortId || trimmed;
2511
+ const preview = snippet ? ` "${snippet.slice(0, 12)}${snippet.length > 12 ? "…" : ""}"` : "";
2512
+ core.system.enqueueSystemEvent(`Assistant sent${preview} [message_id:${displayId}]`, {
2513
+ sessionKey: route.sessionKey,
2514
+ contextKey: `bluebubbles:outbound:${outboundTarget}:${trimmed}`
2515
+ });
2516
+ return true;
2517
+ };
2518
+ const sanitizeReplyDirectiveText = (value) => {
2519
+ if (privateApiEnabled) return value;
2520
+ return value.replace(REPLY_DIRECTIVE_TAG_RE, " ").replace(/[ \t]+/g, " ").trim();
2521
+ };
2522
+ const historyLimit = isGroup ? account.config.historyLimit ?? 0 : account.config.dmHistoryLimit ?? 0;
2523
+ const historyIdentifier = chatGuid || chatIdentifier || (chatId ? String(chatId) : null) || (isGroup ? null : message.senderId) || "";
2524
+ const historyKey = historyIdentifier ? buildAccountScopedHistoryKey(account.accountId, historyIdentifier) : "";
2525
+ if (historyKey && historyLimit > 0) {
2526
+ const nowMs = Date.now();
2527
+ const senderLabel = message.fromMe ? "me" : message.senderName || message.senderId;
2528
+ const normalizedHistoryBody = truncateHistoryBody(text, MAX_STORED_HISTORY_ENTRY_CHARS);
2529
+ const currentEntries = recordPendingHistoryEntryIfEnabled({
2530
+ historyMap: chatHistories,
2531
+ limit: historyLimit,
2532
+ historyKey,
2533
+ entry: normalizedHistoryBody ? {
2534
+ sender: senderLabel,
2535
+ body: normalizedHistoryBody,
2536
+ timestamp: message.timestamp ?? nowMs,
2537
+ messageId: message.messageId ?? void 0
2538
+ } : null
2539
+ });
2540
+ pruneHistoryBackfillState();
2541
+ const backfillAttempt = planHistoryBackfillAttempt(historyKey, nowMs);
2542
+ if (backfillAttempt) try {
2543
+ const backfillResult = await fetchBlueBubblesHistory(historyIdentifier, historyLimit, {
2544
+ cfg: config,
2545
+ accountId: account.accountId
2546
+ });
2547
+ if (backfillResult.resolved) markHistoryBackfillResolved(historyKey);
2548
+ if (backfillResult.entries.length > 0) {
2549
+ const apiEntries = [];
2550
+ for (const entry of backfillResult.entries) {
2551
+ const body = truncateHistoryBody(entry.body, MAX_STORED_HISTORY_ENTRY_CHARS);
2552
+ if (!body) continue;
2553
+ apiEntries.push({
2554
+ sender: entry.sender,
2555
+ body,
2556
+ timestamp: entry.timestamp,
2557
+ messageId: entry.messageId
2558
+ });
2559
+ }
2560
+ const merged = mergeHistoryEntries({
2561
+ apiEntries,
2562
+ currentEntries: currentEntries.length > 0 ? currentEntries : chatHistories.get(historyKey) ?? [],
2563
+ limit: historyLimit
2564
+ });
2565
+ if (chatHistories.has(historyKey)) chatHistories.delete(historyKey);
2566
+ chatHistories.set(historyKey, merged);
2567
+ evictOldHistoryKeys(chatHistories);
2568
+ logVerbose(core, runtime, `backfilled ${backfillResult.entries.length} history messages for ${isGroup ? "group" : "DM"}: ${historyIdentifier}`);
2569
+ } else if (!backfillResult.resolved) {
2570
+ const remainingAttempts = HISTORY_BACKFILL_MAX_ATTEMPTS - backfillAttempt.attempts;
2571
+ const nextBackoffMs = Math.max(backfillAttempt.nextAttemptAt - nowMs, 0);
2572
+ logVerbose(core, runtime, `history backfill unresolved for ${historyIdentifier}; retries left=${Math.max(remainingAttempts, 0)} next_in_ms=${nextBackoffMs}`);
2573
+ }
2574
+ } catch (err) {
2575
+ const remainingAttempts = HISTORY_BACKFILL_MAX_ATTEMPTS - backfillAttempt.attempts;
2576
+ const nextBackoffMs = Math.max(backfillAttempt.nextAttemptAt - nowMs, 0);
2577
+ logVerbose(core, runtime, `history backfill failed for ${historyIdentifier}: ${String(err)} (retries left=${Math.max(remainingAttempts, 0)} next_in_ms=${nextBackoffMs})`);
2578
+ }
2579
+ }
2580
+ let inboundHistory;
2581
+ if (historyKey && historyLimit > 0) {
2582
+ const entries = chatHistories.get(historyKey);
2583
+ if (entries && entries.length > 0) inboundHistory = buildInboundHistorySnapshot({
2584
+ entries,
2585
+ limit: historyLimit
2586
+ });
2587
+ }
2588
+ const commandBody = messageText.trim();
2589
+ const ctxPayload = core.channel.reply.finalizeInboundContext({
2590
+ Body: body,
2591
+ BodyForAgent: rawBody,
2592
+ InboundHistory: inboundHistory,
2593
+ RawBody: rawBody,
2594
+ CommandBody: commandBody,
2595
+ BodyForCommands: commandBody,
2596
+ MediaUrl: mediaUrls[0],
2597
+ MediaUrls: mediaUrls.length > 0 ? mediaUrls : void 0,
2598
+ MediaPath: mediaPaths[0],
2599
+ MediaPaths: mediaPaths.length > 0 ? mediaPaths : void 0,
2600
+ MediaType: mediaTypes[0],
2601
+ MediaTypes: mediaTypes.length > 0 ? mediaTypes : void 0,
2602
+ From: isGroup ? `group:${peerId}` : `bluebubbles:${message.senderId}`,
2603
+ To: `bluebubbles:${outboundTarget}`,
2604
+ SessionKey: route.sessionKey,
2605
+ AccountId: route.accountId,
2606
+ ChatType: isGroup ? "group" : "direct",
2607
+ ConversationLabel: fromLabel,
2608
+ ReplyToId: replyToShortId || replyToId,
2609
+ ReplyToIdFull: replyToId,
2610
+ ReplyToBody: replyToBody,
2611
+ ReplyToSender: replyToSender,
2612
+ GroupSubject: groupSubject,
2613
+ GroupMembers: groupMembers,
2614
+ SenderName: message.senderName || void 0,
2615
+ SenderId: message.senderId,
2616
+ Provider: "bluebubbles",
2617
+ Surface: "bluebubbles",
2618
+ MessageSid: messageShortId || message.messageId,
2619
+ MessageSidFull: message.messageId,
2620
+ Timestamp: message.timestamp,
2621
+ OriginatingChannel: "bluebubbles",
2622
+ OriginatingTo: `bluebubbles:${outboundTarget}`,
2623
+ WasMentioned: effectiveWasMentioned,
2624
+ CommandAuthorized: commandAuthorized
2625
+ });
2626
+ let sentMessage = false;
2627
+ let streamingActive = false;
2628
+ let typingRestartTimer;
2629
+ const typingRestartDelayMs = 150;
2630
+ const clearTypingRestartTimer = () => {
2631
+ if (typingRestartTimer) {
2632
+ clearTimeout(typingRestartTimer);
2633
+ typingRestartTimer = void 0;
2634
+ }
2635
+ };
2636
+ const restartTypingSoon = () => {
2637
+ if (!streamingActive || !chatGuidForActions || !baseUrl || !password) return;
2638
+ clearTypingRestartTimer();
2639
+ typingRestartTimer = setTimeout(() => {
2640
+ typingRestartTimer = void 0;
2641
+ if (!streamingActive) return;
2642
+ sendBlueBubblesTyping(chatGuidForActions, true, {
2643
+ cfg: config,
2644
+ accountId: account.accountId
2645
+ }).catch((err) => {
2646
+ runtime.error?.(`[bluebubbles] typing restart failed: ${String(err)}`);
2647
+ });
2648
+ }, typingRestartDelayMs);
2649
+ };
2650
+ try {
2651
+ const { onModelSelected, ...prefixOptions } = createReplyPrefixOptions({
2652
+ cfg: config,
2653
+ agentId: route.agentId,
2654
+ channel: "bluebubbles",
2655
+ accountId: account.accountId
2656
+ });
2657
+ await core.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
2658
+ ctx: ctxPayload,
2659
+ cfg: config,
2660
+ dispatcherOptions: {
2661
+ ...prefixOptions,
2662
+ deliver: async (payload, info) => {
2663
+ const rawReplyToId = privateApiEnabled && typeof payload.replyToId === "string" ? payload.replyToId.trim() : "";
2664
+ const replyToMessageGuid = rawReplyToId ? resolveBlueBubblesMessageId(rawReplyToId, { requireKnownShortId: true }) : "";
2665
+ const mediaList = payload.mediaUrls?.length ? payload.mediaUrls : payload.mediaUrl ? [payload.mediaUrl] : [];
2666
+ if (mediaList.length > 0) {
2667
+ const tableMode = core.channel.text.resolveMarkdownTableMode({
2668
+ cfg: config,
2669
+ channel: "bluebubbles",
2670
+ accountId: account.accountId
2671
+ });
2672
+ const text = sanitizeReplyDirectiveText(core.channel.text.convertMarkdownTables(payload.text ?? "", tableMode));
2673
+ let first = true;
2674
+ for (const mediaUrl of mediaList) {
2675
+ const caption = first ? text : void 0;
2676
+ first = false;
2677
+ const cachedBody = (caption ?? "").trim() || "<media:attachment>";
2678
+ const pendingId = rememberPendingOutboundMessageId({
2679
+ accountId: account.accountId,
2680
+ sessionKey: route.sessionKey,
2681
+ outboundTarget,
2682
+ chatGuid: chatGuidForActions ?? chatGuid,
2683
+ chatIdentifier,
2684
+ chatId,
2685
+ snippet: cachedBody
2686
+ });
2687
+ let result;
2688
+ try {
2689
+ result = await sendBlueBubblesMedia({
2690
+ cfg: config,
2691
+ to: outboundTarget,
2692
+ mediaUrl,
2693
+ caption: caption ?? void 0,
2694
+ replyToId: replyToMessageGuid || null,
2695
+ accountId: account.accountId
2696
+ });
2697
+ } catch (err) {
2698
+ forgetPendingOutboundMessageId(pendingId);
2699
+ throw err;
2700
+ }
2701
+ if (maybeEnqueueOutboundMessageId(result.messageId, cachedBody)) forgetPendingOutboundMessageId(pendingId);
2702
+ sentMessage = true;
2703
+ statusSink?.({ lastOutboundAt: Date.now() });
2704
+ if (info.kind === "block") restartTypingSoon();
2705
+ }
2706
+ return;
2707
+ }
2708
+ const textLimit = account.config.textChunkLimit && account.config.textChunkLimit > 0 ? account.config.textChunkLimit : DEFAULT_TEXT_LIMIT;
2709
+ const chunkMode = account.config.chunkMode ?? "length";
2710
+ const tableMode = core.channel.text.resolveMarkdownTableMode({
2711
+ cfg: config,
2712
+ channel: "bluebubbles",
2713
+ accountId: account.accountId
2714
+ });
2715
+ const text = sanitizeReplyDirectiveText(core.channel.text.convertMarkdownTables(payload.text ?? "", tableMode));
2716
+ const chunks = chunkMode === "newline" ? core.channel.text.chunkTextWithMode(text, textLimit, chunkMode) : core.channel.text.chunkMarkdownText(text, textLimit);
2717
+ if (!chunks.length && text) chunks.push(text);
2718
+ if (!chunks.length) return;
2719
+ for (const chunk of chunks) {
2720
+ const pendingId = rememberPendingOutboundMessageId({
2721
+ accountId: account.accountId,
2722
+ sessionKey: route.sessionKey,
2723
+ outboundTarget,
2724
+ chatGuid: chatGuidForActions ?? chatGuid,
2725
+ chatIdentifier,
2726
+ chatId,
2727
+ snippet: chunk
2728
+ });
2729
+ let result;
2730
+ try {
2731
+ result = await sendMessageBlueBubbles(outboundTarget, chunk, {
2732
+ cfg: config,
2733
+ accountId: account.accountId,
2734
+ replyToMessageGuid: replyToMessageGuid || void 0
2735
+ });
2736
+ } catch (err) {
2737
+ forgetPendingOutboundMessageId(pendingId);
2738
+ throw err;
2739
+ }
2740
+ if (maybeEnqueueOutboundMessageId(result.messageId, chunk)) forgetPendingOutboundMessageId(pendingId);
2741
+ sentMessage = true;
2742
+ statusSink?.({ lastOutboundAt: Date.now() });
2743
+ if (info.kind === "block") restartTypingSoon();
2744
+ }
2745
+ },
2746
+ onReplyStart: async () => {
2747
+ if (!chatGuidForActions) return;
2748
+ if (!baseUrl || !password) return;
2749
+ streamingActive = true;
2750
+ clearTypingRestartTimer();
2751
+ try {
2752
+ await sendBlueBubblesTyping(chatGuidForActions, true, {
2753
+ cfg: config,
2754
+ accountId: account.accountId
2755
+ });
2756
+ } catch (err) {
2757
+ runtime.error?.(`[bluebubbles] typing start failed: ${String(err)}`);
2758
+ }
2759
+ },
2760
+ onIdle: async () => {
2761
+ if (!chatGuidForActions) return;
2762
+ if (!baseUrl || !password) return;
2763
+ },
2764
+ onError: (err, info) => {
2765
+ runtime.error?.(`BlueBubbles ${info.kind} reply failed: ${String(err)}`);
2766
+ }
2767
+ },
2768
+ replyOptions: {
2769
+ onModelSelected,
2770
+ disableBlockStreaming: typeof account.config.blockStreaming === "boolean" ? !account.config.blockStreaming : void 0
2771
+ }
2772
+ });
2773
+ } finally {
2774
+ const shouldStopTyping = Boolean(chatGuidForActions && baseUrl && password) && (streamingActive || !sentMessage);
2775
+ streamingActive = false;
2776
+ clearTypingRestartTimer();
2777
+ if (sentMessage && chatGuidForActions && ackMessageId) core.channel.reactions.removeAckReactionAfterReply({
2778
+ removeAfterReply: removeAckAfterReply,
2779
+ ackReactionPromise,
2780
+ ackReactionValue: ackReactionValue ?? null,
2781
+ remove: () => sendBlueBubblesReaction({
2782
+ chatGuid: chatGuidForActions,
2783
+ messageGuid: ackMessageId,
2784
+ emoji: ackReactionValue ?? "",
2785
+ remove: true,
2786
+ opts: {
2787
+ cfg: config,
2788
+ accountId: account.accountId
2789
+ }
2790
+ }),
2791
+ onError: (err) => {
2792
+ logAckFailure({
2793
+ log: (msg) => logVerbose(core, runtime, msg),
2794
+ channel: "bluebubbles",
2795
+ target: `${chatGuidForActions}/${ackMessageId}`,
2796
+ error: err
2797
+ });
2798
+ }
2799
+ });
2800
+ if (shouldStopTyping && chatGuidForActions) sendBlueBubblesTyping(chatGuidForActions, false, {
2801
+ cfg: config,
2802
+ accountId: account.accountId
2803
+ }).catch((err) => {
2804
+ logTypingFailure({
2805
+ log: (msg) => logVerbose(core, runtime, msg),
2806
+ channel: "bluebubbles",
2807
+ action: "stop",
2808
+ target: chatGuidForActions,
2809
+ error: err
2810
+ });
2811
+ });
2812
+ }
2813
+ }
2814
+ async function processReaction(reaction, target) {
2815
+ const { account, config, runtime, core } = target;
2816
+ const pairing = createScopedPairingAccess({
2817
+ core,
2818
+ channel: "bluebubbles",
2819
+ accountId: account.accountId
2820
+ });
2821
+ if (reaction.fromMe) return;
2822
+ const dmPolicy = account.config.dmPolicy ?? "pairing";
2823
+ const groupPolicy = account.config.groupPolicy ?? "allowlist";
2824
+ const storeAllowFrom = await readStoreAllowFromForDmPolicy({
2825
+ provider: "bluebubbles",
2826
+ accountId: account.accountId,
2827
+ dmPolicy,
2828
+ readStore: pairing.readStoreForDmPolicy
2829
+ });
2830
+ if (resolveDmGroupAccessWithLists({
2831
+ isGroup: reaction.isGroup,
2832
+ dmPolicy,
2833
+ groupPolicy,
2834
+ allowFrom: account.config.allowFrom,
2835
+ groupAllowFrom: account.config.groupAllowFrom,
2836
+ storeAllowFrom,
2837
+ isSenderAllowed: (allowFrom) => isAllowedBlueBubblesSender({
2838
+ allowFrom,
2839
+ sender: reaction.senderId,
2840
+ chatId: reaction.chatId ?? void 0,
2841
+ chatGuid: reaction.chatGuid ?? void 0,
2842
+ chatIdentifier: reaction.chatIdentifier ?? void 0
2843
+ })
2844
+ }).decision !== "allow") return;
2845
+ const chatId = reaction.chatId ?? void 0;
2846
+ const chatGuid = reaction.chatGuid ?? void 0;
2847
+ const chatIdentifier = reaction.chatIdentifier ?? void 0;
2848
+ const peerId = reaction.isGroup ? chatGuid ?? chatIdentifier ?? (chatId ? String(chatId) : "group") : reaction.senderId;
2849
+ const route = core.channel.routing.resolveAgentRoute({
2850
+ cfg: config,
2851
+ channel: "bluebubbles",
2852
+ accountId: account.accountId,
2853
+ peer: {
2854
+ kind: reaction.isGroup ? "group" : "direct",
2855
+ id: peerId
2856
+ }
2857
+ });
2858
+ const senderLabel = reaction.senderName || reaction.senderId;
2859
+ const chatLabel = reaction.isGroup ? ` in group:${peerId}` : "";
2860
+ const messageDisplayId = getShortIdForUuid(reaction.messageId) || reaction.messageId;
2861
+ const text = reaction.action === "removed" ? `${senderLabel} removed ${reaction.emoji} reaction [[reply_to:${messageDisplayId}]]${chatLabel}` : `${senderLabel} reacted with ${reaction.emoji} [[reply_to:${messageDisplayId}]]${chatLabel}`;
2862
+ core.system.enqueueSystemEvent(text, {
2863
+ sessionKey: route.sessionKey,
2864
+ contextKey: `bluebubbles:reaction:${reaction.action}:${peerId}:${reaction.messageId}:${reaction.senderId}:${reaction.emoji}`
2865
+ });
2866
+ logVerbose(core, runtime, `reaction event enqueued: ${text}`);
2867
+ }
2868
+ //#endregion
2869
+ //#region extensions/bluebubbles/src/monitor.ts
2870
+ const webhookTargets = /* @__PURE__ */ new Map();
2871
+ const webhookInFlightLimiter = createWebhookInFlightLimiter();
2872
+ const debounceRegistry = createBlueBubblesDebounceRegistry({ processMessage });
2873
+ function registerBlueBubblesWebhookTarget(target) {
2874
+ const registered = registerWebhookTargetWithPluginRoute({
2875
+ targetsByPath: webhookTargets,
2876
+ target,
2877
+ route: {
2878
+ auth: "plugin",
2879
+ match: "exact",
2880
+ pluginId: "bluebubbles",
2881
+ source: "bluebubbles-webhook",
2882
+ accountId: target.account.accountId,
2883
+ log: target.runtime.log,
2884
+ handler: async (req, res) => {
2885
+ if (!await handleBlueBubblesWebhookRequest(req, res) && !res.headersSent) {
2886
+ res.statusCode = 404;
2887
+ res.setHeader("Content-Type", "text/plain; charset=utf-8");
2888
+ res.end("Not Found");
2889
+ }
2890
+ }
2891
+ }
2892
+ });
2893
+ return () => {
2894
+ registered.unregister();
2895
+ debounceRegistry.removeDebouncer(registered.target);
2896
+ };
2897
+ }
2898
+ function parseBlueBubblesWebhookPayload(rawBody) {
2899
+ const trimmed = rawBody.trim();
2900
+ if (!trimmed) return {
2901
+ ok: false,
2902
+ error: "empty payload"
2903
+ };
2904
+ try {
2905
+ return {
2906
+ ok: true,
2907
+ value: JSON.parse(trimmed)
2908
+ };
2909
+ } catch {
2910
+ const params = new URLSearchParams(rawBody);
2911
+ const payload = params.get("payload") ?? params.get("data") ?? params.get("message");
2912
+ if (!payload) return {
2913
+ ok: false,
2914
+ error: "invalid json"
2915
+ };
2916
+ try {
2917
+ return {
2918
+ ok: true,
2919
+ value: JSON.parse(payload)
2920
+ };
2921
+ } catch (error) {
2922
+ return {
2923
+ ok: false,
2924
+ error: error instanceof Error ? error.message : String(error)
2925
+ };
2926
+ }
2927
+ }
2928
+ }
2929
+ function asRecord(value) {
2930
+ return value && typeof value === "object" && !Array.isArray(value) ? value : null;
2931
+ }
2932
+ function maskSecret(value) {
2933
+ if (value.length <= 6) return "***";
2934
+ return `${value.slice(0, 2)}***${value.slice(-2)}`;
2935
+ }
2936
+ function normalizeAuthToken(raw) {
2937
+ const value = raw.trim();
2938
+ if (!value) return "";
2939
+ if (value.toLowerCase().startsWith("bearer ")) return value.slice(7).trim();
2940
+ return value;
2941
+ }
2942
+ function safeEqualSecret(aRaw, bRaw) {
2943
+ const a = normalizeAuthToken(aRaw);
2944
+ const b = normalizeAuthToken(bRaw);
2945
+ if (!a || !b) return false;
2946
+ const bufA = Buffer.from(a, "utf8");
2947
+ const bufB = Buffer.from(b, "utf8");
2948
+ if (bufA.length !== bufB.length) return false;
2949
+ return timingSafeEqual(bufA, bufB);
2950
+ }
2951
+ async function handleBlueBubblesWebhookRequest(req, res) {
2952
+ return await withResolvedWebhookRequestPipeline({
2953
+ req,
2954
+ res,
2955
+ targetsByPath: webhookTargets,
2956
+ allowMethods: ["POST"],
2957
+ inFlightLimiter: webhookInFlightLimiter,
2958
+ handle: async ({ path, targets }) => {
2959
+ const url = new URL(req.url ?? "/", "http://localhost");
2960
+ const guidParam = url.searchParams.get("guid") ?? url.searchParams.get("password");
2961
+ const headerToken = req.headers["x-guid"] ?? req.headers["x-password"] ?? req.headers["x-bluebubbles-guid"] ?? req.headers["authorization"];
2962
+ const guid = (Array.isArray(headerToken) ? headerToken[0] : headerToken) ?? guidParam ?? "";
2963
+ const target = resolveWebhookTargetWithAuthOrRejectSync({
2964
+ targets,
2965
+ res,
2966
+ isMatch: (target) => {
2967
+ return safeEqualSecret(guid, target.account.config.password?.trim() ?? "");
2968
+ }
2969
+ });
2970
+ if (!target) {
2971
+ console.warn(`[bluebubbles] webhook rejected: status=${res.statusCode} path=${path} guid=${maskSecret(url.searchParams.get("guid") ?? url.searchParams.get("password") ?? "")}`);
2972
+ return true;
2973
+ }
2974
+ const body = await readWebhookBodyOrReject({
2975
+ req,
2976
+ res,
2977
+ profile: "post-auth",
2978
+ invalidBodyMessage: "invalid payload"
2979
+ });
2980
+ if (!body.ok) {
2981
+ console.warn(`[bluebubbles] webhook rejected: status=${res.statusCode}`);
2982
+ return true;
2983
+ }
2984
+ const parsed = parseBlueBubblesWebhookPayload(body.value);
2985
+ if (!parsed.ok) {
2986
+ res.statusCode = 400;
2987
+ res.end(parsed.error);
2988
+ console.warn(`[bluebubbles] webhook rejected: ${parsed.error}`);
2989
+ return true;
2990
+ }
2991
+ const payload = asRecord(parsed.value) ?? {};
2992
+ const firstTarget = targets[0];
2993
+ if (firstTarget) logVerbose(firstTarget.core, firstTarget.runtime, `webhook received path=${path} keys=${Object.keys(payload).join(",") || "none"}`);
2994
+ const eventTypeRaw = payload.type;
2995
+ const eventType = typeof eventTypeRaw === "string" ? eventTypeRaw.trim() : "";
2996
+ if (eventType && !new Set([
2997
+ "new-message",
2998
+ "updated-message",
2999
+ "message-reaction",
3000
+ "reaction"
3001
+ ]).has(eventType)) {
3002
+ res.statusCode = 200;
3003
+ res.end("ok");
3004
+ if (firstTarget) logVerbose(firstTarget.core, firstTarget.runtime, `webhook ignored type=${eventType}`);
3005
+ return true;
3006
+ }
3007
+ const reaction = normalizeWebhookReaction(payload);
3008
+ if ((eventType === "updated-message" || eventType === "message-reaction" || eventType === "reaction") && !reaction) {
3009
+ res.statusCode = 200;
3010
+ res.end("ok");
3011
+ if (firstTarget) logVerbose(firstTarget.core, firstTarget.runtime, `webhook ignored ${eventType || "event"} without reaction`);
3012
+ return true;
3013
+ }
3014
+ const message = reaction ? null : normalizeWebhookMessage(payload);
3015
+ if (!message && !reaction) {
3016
+ res.statusCode = 400;
3017
+ res.end("invalid payload");
3018
+ console.warn("[bluebubbles] webhook rejected: unable to parse message payload");
3019
+ return true;
3020
+ }
3021
+ target.statusSink?.({ lastInboundAt: Date.now() });
3022
+ if (reaction) processReaction(reaction, target).catch((err) => {
3023
+ target.runtime.error?.(`[${target.account.accountId}] BlueBubbles reaction failed: ${String(err)}`);
3024
+ });
3025
+ else if (message) debounceRegistry.getOrCreateDebouncer(target).enqueue({
3026
+ message,
3027
+ target
3028
+ }).catch((err) => {
3029
+ target.runtime.error?.(`[${target.account.accountId}] BlueBubbles webhook failed: ${String(err)}`);
3030
+ });
3031
+ res.statusCode = 200;
3032
+ res.end("ok");
3033
+ if (reaction) {
3034
+ if (firstTarget) logVerbose(firstTarget.core, firstTarget.runtime, `webhook accepted reaction sender=${reaction.senderId} msg=${reaction.messageId} action=${reaction.action}`);
3035
+ } else if (message) {
3036
+ if (firstTarget) logVerbose(firstTarget.core, firstTarget.runtime, `webhook accepted sender=${message.senderId} group=${message.isGroup} chatGuid=${message.chatGuid ?? ""} chatId=${message.chatId ?? ""}`);
3037
+ }
3038
+ return true;
3039
+ }
3040
+ });
3041
+ }
3042
+ async function monitorBlueBubblesProvider(options) {
3043
+ const { account, config, runtime, abortSignal, statusSink } = options;
3044
+ const core = getBlueBubblesRuntime();
3045
+ const path = options.webhookPath?.trim() || "/bluebubbles-webhook";
3046
+ const serverInfo = await fetchBlueBubblesServerInfo({
3047
+ baseUrl: account.baseUrl,
3048
+ password: account.config.password,
3049
+ accountId: account.accountId,
3050
+ timeoutMs: 5e3
3051
+ }).catch(() => null);
3052
+ if (serverInfo?.os_version) runtime.log?.(`[${account.accountId}] BlueBubbles server macOS ${serverInfo.os_version}`);
3053
+ if (typeof serverInfo?.private_api === "boolean") runtime.log?.(`[${account.accountId}] BlueBubbles Private API ${serverInfo.private_api ? "enabled" : "disabled"}`);
3054
+ const unregister = registerBlueBubblesWebhookTarget({
3055
+ account,
3056
+ config,
3057
+ runtime,
3058
+ core,
3059
+ path,
3060
+ statusSink
3061
+ });
3062
+ return await new Promise((resolve) => {
3063
+ const stop = () => {
3064
+ unregister();
3065
+ resolve();
3066
+ };
3067
+ if (abortSignal?.aborted) {
3068
+ stop();
3069
+ return;
3070
+ }
3071
+ abortSignal?.addEventListener("abort", stop, { once: true });
3072
+ runtime.log?.(`[${account.accountId}] BlueBubbles webhook listening on ${normalizeWebhookPath(path)}`);
3073
+ });
3074
+ }
3075
+ //#endregion
3076
+ export { addBlueBubblesParticipant as a, removeBlueBubblesParticipant as c, unsendBlueBubblesMessage as d, sendBlueBubblesAttachment as f, sendBlueBubblesMedia as i, renameBlueBubblesChat as l, sendMessageBlueBubbles as m, sendBlueBubblesReaction as n, editBlueBubblesMessage as o, resolveChatGuidForTarget as p, resolveBlueBubblesMessageId as r, leaveBlueBubblesChat as s, monitorBlueBubblesProvider as t, setGroupIconBlueBubbles as u };