@spacebar_ai/moldclaw-core 2026.3.43 → 2026.3.44

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 (1131) hide show
  1. package/dist/accounts-5qY-dKca.d.ts +103 -0
  2. package/dist/accounts-SqdHz2ZP.js +114 -0
  3. package/dist/acp-cli-E6bcNqiE.js +2093 -0
  4. package/dist/actions.runtime-BU_XMuLk.js +119 -0
  5. package/dist/actions.runtime-CY5h8lqH.js +133 -0
  6. package/dist/agent-scope-lZlwP1At.js +208 -0
  7. package/dist/agents-C4SkadR1.js +853 -0
  8. package/dist/agents-RfwqGCzE.js +222 -0
  9. package/dist/agents.config-CX9CPNfP.js +17 -0
  10. package/dist/agents.config-DF9Zwn9n.js +121 -0
  11. package/dist/allow-list-3WSjz1zl.js +81 -0
  12. package/dist/allowlist-DNbDjFjw.js +142 -0
  13. package/dist/api-BEOpJ7dR.js +117 -0
  14. package/dist/audit-CpJz_eu6.js +787 -0
  15. package/dist/audit-CpfSjvyo.js +54 -0
  16. package/dist/audit-channel.collect.runtime-BeGotloZ.js +605 -0
  17. package/dist/audit-channel.runtime-BJDZ7ETt.js +121 -0
  18. package/dist/audit-extra.async-C2G0mqmk.js +813 -0
  19. package/dist/audit-membership-runtime-B1FqJsPV.js +162 -0
  20. package/dist/audit.deep.runtime-DyL9O_sU.js +25 -0
  21. package/dist/audit.nondeep.runtime-C6jFgJfH.js +832 -0
  22. package/dist/audit.runtime-Dnlsn23e.js +118 -0
  23. package/dist/auth-Ch3Rchm4.js +101 -0
  24. package/dist/auth-choice-CEFSlnLT.js +122 -0
  25. package/dist/auth-choice-CVCef-eU.js +268 -0
  26. package/dist/auth-choice-Cez-pXrg.js +507 -0
  27. package/dist/auth-choice-options-DO78mvPe.js +123 -0
  28. package/dist/auth-choice-prompt-CUkC7Mmb.js +36 -0
  29. package/dist/auth-choice-prompt-DCuQRiVl.js +115 -0
  30. package/dist/auth-choice.apply-helpers-BhbNIV8X.js +66 -0
  31. package/dist/auth-choice.plugin-providers.runtime-4BhqvEw_.js +119 -0
  32. package/dist/auth-profiles-smABVXzp.js +128040 -0
  33. package/dist/auth-profiles.runtime-Cr-ojtTc.js +116 -0
  34. package/dist/banner-CojBHPWr.js +342 -0
  35. package/dist/bluebubbles-BnLsj2Fy.d.ts +6 -0
  36. package/dist/bluebubbles-CVk7M3Bl.js +64 -0
  37. package/dist/bot-DdyrB2z9.d.ts +478 -0
  38. package/dist/brave-w4Fo8WZ3.js +24 -0
  39. package/dist/browser-cli-DWFs3P_i.js +1494 -0
  40. package/dist/build-info.json +3 -3
  41. package/dist/bundled/boot-md/handler.d.ts +1 -1
  42. package/dist/bundled/boot-md/handler.js +35 -35
  43. package/dist/bundled/bootstrap-extra-files/handler.d.ts +1 -1
  44. package/dist/bundled/bootstrap-extra-files/handler.js +1 -1
  45. package/dist/bundled/command-logger/handler.d.ts +1 -1
  46. package/dist/bundled/session-memory/handler.d.ts +1 -1
  47. package/dist/bundled/session-memory/handler.js +36 -36
  48. package/dist/call-Do7wTSr7.js +39 -0
  49. package/dist/call-gdDAt07d.js +640 -0
  50. package/dist/canvas-host/a2ui/.bundle.hash +1 -1
  51. package/dist/channel-B26pkce0.js +214 -0
  52. package/dist/channel-BJHp0AQC.js +352 -0
  53. package/dist/channel-BKFOv51P.js +4681 -0
  54. package/dist/channel-BNgpOY8v.js +538 -0
  55. package/dist/channel-BcQAAo2P.js +226 -0
  56. package/dist/channel-BvNdnhbx.js +1598 -0
  57. package/dist/channel-C1Rda3Jd.js +306 -0
  58. package/dist/channel-C87DG-F7.js +803 -0
  59. package/dist/channel-CIip0kvZ.js +619 -0
  60. package/dist/channel-CTPxoT_E2.js +316 -0
  61. package/dist/channel-CklaCzUG.js +562 -0
  62. package/dist/channel-CoJnAdLs.js +920 -0
  63. package/dist/channel-D3tafL1_.js +949 -0
  64. package/dist/channel-DFMrP2uu.js +542 -0
  65. package/dist/channel-DMd5cJQe.js +397 -0
  66. package/dist/channel-Dm34kxAJ.js +207 -0
  67. package/dist/channel-DmwF9udn.js +1321 -0
  68. package/dist/channel-account-context-Bjur9nlh.js +103 -0
  69. package/dist/channel-bGnST659.js +943 -0
  70. package/dist/channel-hIgbkTZf.js +575 -0
  71. package/dist/channel-m_TGrDKo.js +497 -0
  72. package/dist/channel-options-DoUPBMa8.js +50 -0
  73. package/dist/channel-plugin-ids-TZIY4hFs.js +26 -0
  74. package/dist/channel-summary-qD54bOBO.js +111 -0
  75. package/dist/channel.runtime-B0H04Dkk.js +199 -0
  76. package/dist/channel.runtime-BU1f3NkV.js +418 -0
  77. package/dist/channel.runtime-Bj1sfLep.js +4011 -0
  78. package/dist/channel.runtime-BtPAAJc3.js +870 -0
  79. package/dist/channel.runtime-Bx-10m_j.js +171 -0
  80. package/dist/channel.runtime-CI_TBywQ.js +179 -0
  81. package/dist/channel.runtime-CSLj14-Z.js +182 -0
  82. package/dist/channel.runtime-D-lTSYAd.js +404 -0
  83. package/dist/channel.runtime-DJqIOSji.js +127 -0
  84. package/dist/channel.runtime-Ec8aQ9V2.js +241 -0
  85. package/dist/channel.runtime-ax5a1jBm.js +218 -0
  86. package/dist/channel.setup-B-ncdYLT.js +9 -0
  87. package/dist/channel.setup-BY4bh5dm.js +9 -0
  88. package/dist/channel.setup-BovsdMnL.js +57 -0
  89. package/dist/channel.setup-CXzXA25h.js +6 -0
  90. package/dist/channel.setup-DcZUEufN.js +8 -0
  91. package/dist/channel.setup-E6zceRsE.js +8 -0
  92. package/dist/channel.setup-Pc7nGbdX.js +11 -0
  93. package/dist/channels/plugins/actions/discord.d.ts +2 -2
  94. package/dist/channels/plugins/actions/discord.js +35 -35
  95. package/dist/channels/plugins/actions/signal.d.ts +1 -1
  96. package/dist/channels/plugins/actions/signal.js +35 -35
  97. package/dist/channels/plugins/actions/telegram.d.ts +2 -2
  98. package/dist/channels/plugins/actions/telegram.js +35 -35
  99. package/dist/channels/plugins/agent-tools/whatsapp-login.d.ts +3 -3
  100. package/dist/channels/plugins/agent-tools/whatsapp-login.js +35 -35
  101. package/dist/channels-CPtE5ND6.js +404 -0
  102. package/dist/channels-Cj8ZolHI.js +1118 -0
  103. package/dist/channels-cli-D2sKrntt.js +291 -0
  104. package/dist/channels-status-issues-CzIHODg2.js +16 -0
  105. package/dist/clawbot-cli-BcwEDmUn.js +118 -0
  106. package/dist/cleanup-utils-D0L17RsX.js +96 -0
  107. package/dist/cli/daemon-cli.js +1 -1
  108. package/dist/cli-BvGVPKnD.js +154 -0
  109. package/dist/command-registry-CADQzTAg.js +14 -0
  110. package/dist/command-registry-ktiJNAJd.js +242 -0
  111. package/dist/command-secret-gateway-CXp10RTM.js +111 -0
  112. package/dist/compact.runtime-DyKL-Iar.js +116 -0
  113. package/dist/completion-cli-Bz4STrpt.js +17 -0
  114. package/dist/completion-cli-pVda2OFb.js +445 -0
  115. package/dist/config-BbvDRSYp.js +31 -0
  116. package/dist/config-CwBv71QC.js +44 -0
  117. package/dist/config-cli-Y0uXHbOw.js +678 -0
  118. package/dist/config-guard-BpW5g7JE.js +118 -0
  119. package/dist/config-validation-B-vLIsbo.js +262 -0
  120. package/dist/config-value-DT3-5958.js +132 -0
  121. package/dist/configure-B9U-jCqP.js +1100 -0
  122. package/dist/configure-BJ3Wrs5b.js +243 -0
  123. package/dist/control-ui-assets-C1YDYi82.js +232 -0
  124. package/dist/control-ui-shared-Dm5Dh0Lo.js +29 -0
  125. package/dist/core-BwKq3krw.js +150 -0
  126. package/dist/core-hjBwfDsW.d.ts +87 -0
  127. package/dist/cron-cli-DTDgfoMh.js +639 -0
  128. package/dist/daemon-cli-C-dkAXR1.js +339 -0
  129. package/dist/daemon-install-Oy0Q5pMF.js +180 -0
  130. package/dist/deliver-DNGnDqF9.js +111 -0
  131. package/dist/deliver-runtime-CCNZIhET.js +111 -0
  132. package/dist/device-id-cli-XvwZbIyC.js +52 -0
  133. package/dist/device-identity-IG5DngWM.js +365 -0
  134. package/dist/devices-cli-DIsxj4xp.js +342 -0
  135. package/dist/diagnostic-DTPopFvh.js +310 -0
  136. package/dist/directory-cli-DTSY3Ktr.js +311 -0
  137. package/dist/directory-config-helpers-DpFcAbmo.d.ts +38 -0
  138. package/dist/directory.static-CBRAUwUW.js +44 -0
  139. package/dist/discord-CrgxhEWw.js +114 -0
  140. package/dist/discovery-DrG7wmAR.js +48 -0
  141. package/dist/dm-policy-shared-DKoGdUpY.d.ts +95 -0
  142. package/dist/dns-cli-BJiz6CLK.js +217 -0
  143. package/dist/docs-cli-Dq2Yi5qO.js +174 -0
  144. package/dist/doctor-completion-D3GeVcFP.js +90 -0
  145. package/dist/doctor-config-flow-B1cMjr8h.js +112 -0
  146. package/dist/doctor-config-flow-BUe7JpV3.js +2437 -0
  147. package/dist/enable-Bc8bCuVe.js +24 -0
  148. package/dist/entry.js +4 -4
  149. package/dist/exec-approvals-cli-kLAev6bP.js +421 -0
  150. package/dist/extensions/acpx/index.d.ts +1 -1
  151. package/dist/extensions/amazon-bedrock/index.d.ts +1 -1
  152. package/dist/extensions/amazon-bedrock/index.js +4 -4
  153. package/dist/extensions/anthropic/index.d.ts +1 -1
  154. package/dist/extensions/anthropic/index.js +35 -35
  155. package/dist/extensions/bluebubbles/index.d.ts +1 -1
  156. package/dist/extensions/bluebubbles/index.js +39 -39
  157. package/dist/extensions/bluebubbles/setup-entry.d.ts +2 -2
  158. package/dist/extensions/bluebubbles/setup-entry.js +39 -39
  159. package/dist/extensions/brave/index.d.ts +1 -1
  160. package/dist/extensions/brave/index.js +5 -5
  161. package/dist/extensions/byteplus/index.d.ts +1 -1
  162. package/dist/extensions/byteplus/index.js +35 -35
  163. package/dist/extensions/cloudflare-ai-gateway/index.d.ts +1 -1
  164. package/dist/extensions/cloudflare-ai-gateway/index.js +36 -36
  165. package/dist/extensions/copilot-proxy/index.d.ts +1 -1
  166. package/dist/extensions/copilot-proxy/index.js +4 -4
  167. package/dist/extensions/device-pair/index.d.ts +1 -1
  168. package/dist/extensions/device-pair/index.js +4 -4
  169. package/dist/extensions/diagnostics-otel/index.d.ts +1 -1
  170. package/dist/extensions/diagnostics-otel/index.js +4 -4
  171. package/dist/extensions/diffs/index.d.ts +1 -1
  172. package/dist/extensions/discord/index.d.ts +1 -1
  173. package/dist/extensions/discord/index.js +40 -40
  174. package/dist/extensions/discord/setup-entry.d.ts +1 -1
  175. package/dist/extensions/discord/setup-entry.js +38 -38
  176. package/dist/extensions/elevenlabs/index.d.ts +1 -1
  177. package/dist/extensions/elevenlabs/index.js +35 -35
  178. package/dist/extensions/feishu/index.d.ts +2 -2
  179. package/dist/extensions/feishu/index.js +40 -40
  180. package/dist/extensions/feishu/setup-entry.d.ts +2 -2
  181. package/dist/extensions/feishu/setup-entry.js +37 -37
  182. package/dist/extensions/firecrawl/index.d.ts +1 -1
  183. package/dist/extensions/firecrawl/index.js +35 -35
  184. package/dist/extensions/github-copilot/index.d.ts +1 -1
  185. package/dist/extensions/github-copilot/index.js +35 -35
  186. package/dist/extensions/google/index.d.ts +1 -1
  187. package/dist/extensions/google/index.js +35 -35
  188. package/dist/extensions/googlechat/index.d.ts +1 -1
  189. package/dist/extensions/googlechat/index.js +38 -38
  190. package/dist/extensions/googlechat/setup-entry.d.ts +1 -1
  191. package/dist/extensions/googlechat/setup-entry.js +38 -38
  192. package/dist/extensions/huggingface/index.d.ts +1 -1
  193. package/dist/extensions/huggingface/index.js +35 -35
  194. package/dist/extensions/imessage/index.d.ts +1 -1
  195. package/dist/extensions/imessage/index.js +39 -39
  196. package/dist/extensions/imessage/setup-entry.d.ts +1 -1
  197. package/dist/extensions/imessage/setup-entry.js +39 -39
  198. package/dist/extensions/irc/index.d.ts +1 -1
  199. package/dist/extensions/irc/index.js +38 -38
  200. package/dist/extensions/irc/setup-entry.d.ts +2 -2
  201. package/dist/extensions/irc/setup-entry.js +38 -38
  202. package/dist/extensions/kakao-talkchannel/index.d.ts +1 -1
  203. package/dist/extensions/kakao-talkchannel/index.js +4 -4
  204. package/dist/extensions/kilocode/index.d.ts +1 -1
  205. package/dist/extensions/kilocode/index.js +35 -35
  206. package/dist/extensions/kimi-coding/index.d.ts +1 -1
  207. package/dist/extensions/kimi-coding/index.js +35 -35
  208. package/dist/extensions/line/index.d.ts +1 -1
  209. package/dist/extensions/line/index.js +37 -37
  210. package/dist/extensions/line/setup-entry.d.ts +1 -1
  211. package/dist/extensions/line/setup-entry.js +37 -37
  212. package/dist/extensions/llm-task/index.d.ts +1 -1
  213. package/dist/extensions/llm-task/index.js +35 -35
  214. package/dist/extensions/lobster/index.d.ts +1 -1
  215. package/dist/extensions/lobster/index.js +4 -4
  216. package/dist/extensions/matrix/index.d.ts +1 -1
  217. package/dist/extensions/matrix/index.js +40 -40
  218. package/dist/extensions/matrix/setup-entry.d.ts +2 -2
  219. package/dist/extensions/matrix/setup-entry.js +40 -40
  220. package/dist/extensions/mattermost/index.d.ts +1 -1
  221. package/dist/extensions/mattermost/index.js +37 -37
  222. package/dist/extensions/mattermost/setup-entry.d.ts +2 -2
  223. package/dist/extensions/mattermost/setup-entry.js +37 -37
  224. package/dist/extensions/memory-core/index.d.ts +1 -1
  225. package/dist/extensions/memory-core/index.js +4 -4
  226. package/dist/extensions/memory-lancedb/index.d.ts +1 -1
  227. package/dist/extensions/memory-lancedb/index.js +4 -4
  228. package/dist/extensions/microsoft/index.d.ts +1 -1
  229. package/dist/extensions/microsoft/index.js +35 -35
  230. package/dist/extensions/minimax/index.d.ts +1 -1
  231. package/dist/extensions/minimax/index.js +35 -35
  232. package/dist/extensions/mistral/index.d.ts +1 -1
  233. package/dist/extensions/mistral/index.js +35 -35
  234. package/dist/extensions/modelstudio/index.d.ts +1 -1
  235. package/dist/extensions/modelstudio/index.js +35 -35
  236. package/dist/extensions/moonshot/index.d.ts +1 -1
  237. package/dist/extensions/moonshot/index.js +35 -35
  238. package/dist/extensions/msteams/index.d.ts +1 -1
  239. package/dist/extensions/msteams/index.js +40 -40
  240. package/dist/extensions/msteams/setup-entry.d.ts +1 -1
  241. package/dist/extensions/msteams/setup-entry.js +40 -40
  242. package/dist/extensions/nextcloud-talk/index.d.ts +1 -1
  243. package/dist/extensions/nextcloud-talk/index.js +37 -37
  244. package/dist/extensions/nextcloud-talk/setup-entry.d.ts +2 -2
  245. package/dist/extensions/nextcloud-talk/setup-entry.js +37 -37
  246. package/dist/extensions/nostr/index.d.ts +1 -1
  247. package/dist/extensions/nostr/index.js +37 -37
  248. package/dist/extensions/nostr/setup-entry.d.ts +1 -1
  249. package/dist/extensions/nostr/setup-entry.js +37 -37
  250. package/dist/extensions/nvidia/index.d.ts +1 -1
  251. package/dist/extensions/nvidia/index.js +4 -4
  252. package/dist/extensions/ollama/index.d.ts +1 -1
  253. package/dist/extensions/ollama/index.js +7 -7
  254. package/dist/extensions/open-prose/index.d.ts +1 -1
  255. package/dist/extensions/open-prose/index.js +4 -4
  256. package/dist/extensions/openai/index.d.ts +1 -1
  257. package/dist/extensions/openai/index.js +35 -35
  258. package/dist/extensions/opencode/index.d.ts +1 -1
  259. package/dist/extensions/opencode/index.js +35 -35
  260. package/dist/extensions/opencode-go/index.d.ts +1 -1
  261. package/dist/extensions/opencode-go/index.js +35 -35
  262. package/dist/extensions/openrouter/index.d.ts +1 -1
  263. package/dist/extensions/openrouter/index.js +35 -35
  264. package/dist/extensions/openshell/index.d.ts +1 -1
  265. package/dist/extensions/openshell/index.js +35 -35
  266. package/dist/extensions/perplexity/index.d.ts +1 -1
  267. package/dist/extensions/perplexity/index.js +5 -5
  268. package/dist/extensions/phone-control/index.d.ts +1 -1
  269. package/dist/extensions/phone-control/index.js +4 -4
  270. package/dist/extensions/qianfan/index.d.ts +1 -1
  271. package/dist/extensions/qianfan/index.js +35 -35
  272. package/dist/extensions/qwen-portal-auth/index.d.ts +1 -1
  273. package/dist/extensions/qwen-portal-auth/index.js +35 -35
  274. package/dist/extensions/sglang/index.d.ts +1 -1
  275. package/dist/extensions/sglang/index.js +35 -35
  276. package/dist/extensions/signal/index.d.ts +1 -1
  277. package/dist/extensions/signal/index.js +38 -38
  278. package/dist/extensions/signal/setup-entry.d.ts +1 -1
  279. package/dist/extensions/signal/setup-entry.js +38 -38
  280. package/dist/extensions/slack/index.d.ts +1 -1
  281. package/dist/extensions/slack/index.js +39 -39
  282. package/dist/extensions/slack/setup-entry.d.ts +1 -1
  283. package/dist/extensions/slack/setup-entry.js +38 -38
  284. package/dist/extensions/synology-chat/index.d.ts +1 -1
  285. package/dist/extensions/synology-chat/index.js +37 -37
  286. package/dist/extensions/synology-chat/setup-entry.d.ts +1 -1
  287. package/dist/extensions/synology-chat/setup-entry.js +37 -37
  288. package/dist/extensions/synthetic/index.d.ts +1 -1
  289. package/dist/extensions/synthetic/index.js +35 -35
  290. package/dist/extensions/talk-voice/index.d.ts +1 -1
  291. package/dist/extensions/talk-voice/index.js +35 -35
  292. package/dist/extensions/telegram/index.d.ts +1 -1
  293. package/dist/extensions/telegram/index.js +38 -38
  294. package/dist/extensions/telegram/setup-entry.d.ts +1 -1
  295. package/dist/extensions/telegram/setup-entry.js +37 -37
  296. package/dist/extensions/thread-ownership/index.d.ts +1 -1
  297. package/dist/extensions/thread-ownership/index.js +4 -4
  298. package/dist/extensions/tlon/index.d.ts +1 -1
  299. package/dist/extensions/tlon/index.js +37 -37
  300. package/dist/extensions/tlon/setup-entry.d.ts +1 -1
  301. package/dist/extensions/tlon/setup-entry.js +37 -37
  302. package/dist/extensions/together/index.d.ts +1 -1
  303. package/dist/extensions/together/index.js +35 -35
  304. package/dist/extensions/twitch/index.d.ts +2 -2
  305. package/dist/extensions/twitch/index.js +37 -37
  306. package/dist/extensions/venice/index.d.ts +1 -1
  307. package/dist/extensions/venice/index.js +35 -35
  308. package/dist/extensions/vercel-ai-gateway/index.d.ts +1 -1
  309. package/dist/extensions/vercel-ai-gateway/index.js +36 -36
  310. package/dist/extensions/vllm/index.d.ts +1 -1
  311. package/dist/extensions/vllm/index.js +35 -35
  312. package/dist/extensions/voice-call/index.d.ts +1 -1
  313. package/dist/extensions/voice-call/index.js +35 -35
  314. package/dist/extensions/volcengine/index.d.ts +1 -1
  315. package/dist/extensions/volcengine/index.js +35 -35
  316. package/dist/extensions/whatsapp/index.d.ts +1 -1
  317. package/dist/extensions/whatsapp/index.js +38 -38
  318. package/dist/extensions/whatsapp/setup-entry.d.ts +1 -1
  319. package/dist/extensions/whatsapp/setup-entry.js +38 -38
  320. package/dist/extensions/xai/index.d.ts +1 -1
  321. package/dist/extensions/xai/index.js +35 -35
  322. package/dist/extensions/xiaomi/index.d.ts +1 -1
  323. package/dist/extensions/xiaomi/index.js +35 -35
  324. package/dist/extensions/zai/index.d.ts +1 -1
  325. package/dist/extensions/zai/index.js +35 -35
  326. package/dist/extensions/zalo/index.d.ts +1 -1
  327. package/dist/extensions/zalo/index.js +39 -39
  328. package/dist/extensions/zalo/setup-entry.d.ts +1 -1
  329. package/dist/extensions/zalo/setup-entry.js +39 -39
  330. package/dist/extensions/zalouser/index.d.ts +1 -1
  331. package/dist/extensions/zalouser/index.js +40 -40
  332. package/dist/extensions/zalouser/setup-entry.d.ts +1 -1
  333. package/dist/extensions/zalouser/setup-entry.js +40 -40
  334. package/dist/feishu-fIcnHDTd.d.ts +36 -0
  335. package/dist/gateway-cli-0c-8h93_.js +26437 -0
  336. package/dist/gateway-install-token-1PwJvrBY.js +163 -0
  337. package/dist/gateway-rpc-C0Vk51W7.js +26 -0
  338. package/dist/gateway-runtime-CBm3CCoA.js +69 -0
  339. package/dist/git-commit-BTWXFY41.js +177 -0
  340. package/dist/git-commit-D6GTN5Yt.js +2 -0
  341. package/dist/googlechat-BQr4xgoZ.js +307 -0
  342. package/dist/googlechat-BvwsCVKl.d.ts +12 -0
  343. package/dist/group-access-DpiQnd-G.d.ts +61 -0
  344. package/dist/health-6yZQGADY.js +113 -0
  345. package/dist/health-C9DYGyRe.js +570 -0
  346. package/dist/heartbeat-summary-Dct2lqJj.js +57 -0
  347. package/dist/help-CtwSApfq.js +81 -0
  348. package/dist/hooks-9gokOxZ5.d.ts +6 -0
  349. package/dist/hooks-cli-BegKzHZT.js +1000 -0
  350. package/dist/hooks-status-Bm_pGORf.js +78 -0
  351. package/dist/http-registry-D-S6a1Na.d.ts +20 -0
  352. package/dist/identity-file-Diub2a0t.js +60 -0
  353. package/dist/image-generation-CbIVzmAR.d.ts +9 -0
  354. package/dist/imessage-Bgok9kfl.js +31 -0
  355. package/dist/imessage-VIHePprL.js +115 -0
  356. package/dist/inbound-reply-dispatch-B53GAGWq.js +71 -0
  357. package/dist/inbound-reply-dispatch-n7U3qg15.d.ts +72 -0
  358. package/dist/index.js +2 -2
  359. package/dist/install-target-oz1pjfHH.js +574 -0
  360. package/dist/installs-CUFm5V8a.js +532 -0
  361. package/dist/io-BaBxjB1v.js +9739 -0
  362. package/dist/io-CgHb1Jld.js +29 -0
  363. package/dist/irc-CaRKzGvW.js +672 -0
  364. package/dist/library-C5SNBCMb.js +112 -0
  365. package/dist/lifecycle-core-Dn8PK6nk.js +382 -0
  366. package/dist/line/accounts.d.ts +2 -2
  367. package/dist/line/send.d.ts +1 -1
  368. package/dist/line/send.js +7 -7
  369. package/dist/line/template-messages.d.ts +1 -1
  370. package/dist/line-B5QFpgN_.d.ts +75 -0
  371. package/dist/line-fePrrQOD.js +530 -0
  372. package/dist/llm-slug-generator-hKae3XDA.js +67 -0
  373. package/dist/llm-slug-generator.d.ts +1 -1
  374. package/dist/llm-slug-generator.js +36 -36
  375. package/dist/logging-CdisccbY.js +13 -0
  376. package/dist/logging-LKQSgX1d.js +30 -0
  377. package/dist/login-qr-C1YWh4nE.js +233 -0
  378. package/dist/login-qr-WFluMDMb.js +112 -0
  379. package/dist/logs-cli-CNzOvZ2d.js +256 -0
  380. package/dist/manager-runtime-DgMhLTkR.js +111 -0
  381. package/dist/manager.runtime-hUWgpPt2.js +715 -0
  382. package/dist/manifest-registry-CS_p1OBQ.js +1329 -0
  383. package/dist/matrix-43_RGLZN.d.ts +68 -0
  384. package/dist/matrix-CCFxHfxa.js +1269 -0
  385. package/dist/matrix-DWs_qIkJ.js +1495 -0
  386. package/dist/mcp-cli-Ci2jvv3s.js +87 -0
  387. package/dist/media-understanding.runtime-Cdr6iTW6.js +116 -0
  388. package/dist/memory-cli-LZbyF0Iu.js +111 -0
  389. package/dist/memory-search-BHhETk6u.js +17 -0
  390. package/dist/memory-search-tTD5o_rU.js +204 -0
  391. package/dist/method-scopes-B2ZKSsxQ.js +2452 -0
  392. package/dist/model-auth-markers-LqZ4qhrZ.d.ts +20 -0
  393. package/dist/model-picker-CTR5mo4v.js +112 -0
  394. package/dist/model-picker-DG4z_dBs.js +390 -0
  395. package/dist/model-picker.runtime-DMQ9Pj9_.js +125 -0
  396. package/dist/model-selection-bBBxfXdb.js +653 -0
  397. package/dist/model-suppression.runtime-BVG75tZ7.js +116 -0
  398. package/dist/models-BjkVLfgw.js +2514 -0
  399. package/dist/models-ZO01Q4cx.js +118 -0
  400. package/dist/models-cli-DemdF-bm.js +309 -0
  401. package/dist/models-config-B2Jja8ua.js +111 -0
  402. package/dist/models-config.providers.discovery-puxTsH39.d.ts +18 -0
  403. package/dist/moldclaw-root-Cb6HRlUO.js +92 -0
  404. package/dist/monitor-BP4idxJD.js +782 -0
  405. package/dist/monitor-B_eP8Eim.js +772 -0
  406. package/dist/monitor-CRHYNl5J.js +3468 -0
  407. package/dist/monitor-Ci1Xg4g3.js +113 -0
  408. package/dist/monitor-DEodDl3z.js +6823 -0
  409. package/dist/monitor-DJlNKuMz.js +115 -0
  410. package/dist/monitor-DvFwDS9w.js +3076 -0
  411. package/dist/monitor-shared--cEjSf8s.js +444 -0
  412. package/dist/msteams-CV2a8uE8.js +852 -0
  413. package/dist/node-cli-Of2g7DSd.js +2503 -0
  414. package/dist/node-resolve-BYC2FbO2.js +835 -0
  415. package/dist/nodes-cli-CPHM6Upj.js +1380 -0
  416. package/dist/nostr-BFKRoOlz.d.ts +7 -0
  417. package/dist/nostr-lHpcBzz4.js +8744 -0
  418. package/dist/npm-resolution-kqHN85wB.js +60 -0
  419. package/dist/oauth-env-CLG8KOrz.js +10 -0
  420. package/dist/onboard-BON0C360.js +48 -0
  421. package/dist/onboard-CRkIBgOI.js +589 -0
  422. package/dist/onboard-DsKI17iq.js +25 -0
  423. package/dist/onboard-channels-BY3IbBBf.js +1241 -0
  424. package/dist/onboard-channels-CLKdRxvW.js +205 -0
  425. package/dist/onboard-custom-BjPrMo_R.js +571 -0
  426. package/dist/onboard-custom-DqcPiZBN.js +114 -0
  427. package/dist/onboard-helpers-BkrOY5OE.js +113 -0
  428. package/dist/onboard-helpers-DiSRTpZC.js +335 -0
  429. package/dist/onboard-hooks-pzEPZAvl.js +72 -0
  430. package/dist/onboard-remote-ChyLC6Dk.js +181 -0
  431. package/dist/onboard-remote-DHmK9ntl.js +117 -0
  432. package/dist/onboard-search-BgA3jEMW.js +302 -0
  433. package/dist/onboard-skills-BMo_NvnW.js +133 -0
  434. package/dist/onboard-skills-Bba-Z2p8.js +117 -0
  435. package/dist/outbound-media-BHD4aJEX.d.ts +11 -0
  436. package/dist/outbound-media-DSno0N82.js +11 -0
  437. package/dist/pairing-access-CzHpaM0R.d.ts +21 -0
  438. package/dist/pairing-cli-CmklqK0q.js +217 -0
  439. package/dist/perplexity-CXwMDD3u.js +24 -0
  440. package/dist/persistent-dedupe-B9vrAf8t.d.ts +26 -0
  441. package/dist/pi-model-discovery-runtime-BrK7tcaO.js +111 -0
  442. package/dist/pi-tools.before-tool-call.runtime-C5yLUogH.js +381 -0
  443. package/dist/plugin-install-C4AWJIFP.js +117 -0
  444. package/dist/plugin-install-CB3J1hfV.js +184 -0
  445. package/dist/plugin-install-plan-7itZiegi.js +49 -0
  446. package/dist/plugin-registry-DX_GFoiz.js +113 -0
  447. package/dist/plugin-registry-e3cxTtvb.js +49 -0
  448. package/dist/plugin-sdk/account-resolution.js +35 -35
  449. package/dist/plugin-sdk/acp-runtime.js +35 -35
  450. package/dist/plugin-sdk/agent-runtime.js +35 -35
  451. package/dist/plugin-sdk/bluebubbles.js +37 -37
  452. package/dist/plugin-sdk/channel-config-helpers.js +35 -35
  453. package/dist/plugin-sdk/channel-policy.js +35 -35
  454. package/dist/plugin-sdk/channel-runtime.js +35 -35
  455. package/dist/plugin-sdk/compat.js +36 -36
  456. package/dist/plugin-sdk/config-runtime.js +35 -35
  457. package/dist/plugin-sdk/conversation-runtime.js +35 -35
  458. package/dist/plugin-sdk/copilot-proxy.js +4 -4
  459. package/dist/plugin-sdk/core.js +4 -4
  460. package/dist/plugin-sdk/device-pair.js +4 -4
  461. package/dist/plugin-sdk/discord.js +35 -35
  462. package/dist/plugin-sdk/feishu.js +35 -35
  463. package/dist/plugin-sdk/gateway-runtime.js +10 -10
  464. package/dist/plugin-sdk/googlechat.js +37 -37
  465. package/dist/plugin-sdk/image-generation-runtime.js +35 -35
  466. package/dist/plugin-sdk/image-generation.js +35 -35
  467. package/dist/plugin-sdk/imessage.js +36 -36
  468. package/dist/plugin-sdk/index.js +35 -35
  469. package/dist/plugin-sdk/infra-runtime.js +35 -35
  470. package/dist/plugin-sdk/irc.js +37 -37
  471. package/dist/plugin-sdk/line.js +36 -36
  472. package/dist/plugin-sdk/llm-task.js +35 -35
  473. package/dist/plugin-sdk/lobster.js +4 -4
  474. package/dist/plugin-sdk/matrix.js +37 -37
  475. package/dist/plugin-sdk/mattermost.js +36 -36
  476. package/dist/plugin-sdk/media-runtime.js +35 -35
  477. package/dist/plugin-sdk/media-understanding-runtime.js +35 -35
  478. package/dist/plugin-sdk/media-understanding.js +35 -35
  479. package/dist/plugin-sdk/memory-lancedb.js +4 -4
  480. package/dist/plugin-sdk/minimax-portal-auth.js +4 -4
  481. package/dist/plugin-sdk/msteams.js +38 -38
  482. package/dist/plugin-sdk/nextcloud-talk.js +36 -36
  483. package/dist/plugin-sdk/nostr.js +36 -36
  484. package/dist/plugin-sdk/ollama-setup.js +9 -9
  485. package/dist/plugin-sdk/open-prose.js +4 -4
  486. package/dist/plugin-sdk/phone-control.js +4 -4
  487. package/dist/plugin-sdk/plugin-runtime.js +35 -35
  488. package/dist/plugin-sdk/provider-auth.js +35 -35
  489. package/dist/plugin-sdk/provider-models.js +5 -5
  490. package/dist/plugin-sdk/provider-onboard.js +4 -4
  491. package/dist/plugin-sdk/provider-setup.js +39 -39
  492. package/dist/plugin-sdk/provider-stream.js +4 -4
  493. package/dist/plugin-sdk/provider-usage.js +4 -4
  494. package/dist/plugin-sdk/qwen-portal-auth.js +35 -35
  495. package/dist/plugin-sdk/reply-history.js +35 -35
  496. package/dist/plugin-sdk/reply-runtime.js +35 -35
  497. package/dist/plugin-sdk/routing.js +3 -3
  498. package/dist/plugin-sdk/sandbox.js +35 -35
  499. package/dist/plugin-sdk/security-runtime.js +35 -35
  500. package/dist/plugin-sdk/self-hosted-provider-setup.js +37 -37
  501. package/dist/plugin-sdk/setup.js +35 -35
  502. package/dist/plugin-sdk/signal.js +35 -35
  503. package/dist/plugin-sdk/slack.js +35 -35
  504. package/dist/plugin-sdk/speech-runtime.js +35 -35
  505. package/dist/plugin-sdk/speech.js +35 -35
  506. package/dist/plugin-sdk/src/secrets/secure-file-store.d.ts +26 -0
  507. package/dist/plugin-sdk/src/subscription/provider.d.ts +5 -3
  508. package/dist/plugin-sdk/synology-chat.js +36 -36
  509. package/dist/plugin-sdk/talk-voice.js +4 -4
  510. package/dist/plugin-sdk/telegram.js +35 -35
  511. package/dist/plugin-sdk/text-runtime.js +7 -7
  512. package/dist/plugin-sdk/thread-ownership.js +4 -4
  513. package/dist/plugin-sdk/tlon.js +36 -36
  514. package/dist/plugin-sdk/twitch.js +35 -35
  515. package/dist/plugin-sdk/voice-call.js +35 -35
  516. package/dist/plugin-sdk/whatsapp.js +35 -35
  517. package/dist/plugin-sdk/zalo.js +38 -38
  518. package/dist/plugin-sdk/zalouser.js +38 -38
  519. package/dist/plugins/runtime/index.d.ts +1 -1
  520. package/dist/plugins/runtime/index.js +35 -35
  521. package/dist/plugins-DF5FaTO0.js +111 -0
  522. package/dist/plugins-cli-CvTJemqC.js +917 -0
  523. package/dist/policy-CNXISK_a.js +143 -0
  524. package/dist/preflight-audio.runtime-RP000oxo.js +116 -0
  525. package/dist/probe-BkM5pykD.js +21 -0
  526. package/dist/probe-DKbRTJv5.js +1793 -0
  527. package/dist/probe-DkrfRsjU.js +47 -0
  528. package/dist/probe-DpcJ0WeP.js +129 -0
  529. package/dist/probe-auth-BcNjX8hy.js +40 -0
  530. package/dist/probe-auth-DhuAb8ls.js +48 -0
  531. package/dist/probe-wciBj-aL.js +6329 -0
  532. package/dist/program-C8-p0mW5.js +253 -0
  533. package/dist/prompt-select-styled-DH0pVoc0.js +2673 -0
  534. package/dist/provider-api-key-auth.runtime-CAFeIQ1u.js +121 -0
  535. package/dist/provider-auth-choice-CB_HzdTl.js +126 -0
  536. package/dist/provider-auth-choice-helpers-hzDkh3f1.js +48 -0
  537. package/dist/provider-auth-choice-preference-BHCXvNSE.js +189 -0
  538. package/dist/provider-auth-choice.runtime-Dx4ms2C5.js +123 -0
  539. package/dist/provider-auth-choices-0KaDNPBQ.js +57 -0
  540. package/dist/provider-auth-guidance-BaAUiNr_.js +34 -0
  541. package/dist/provider-auth-result-Bto1bYtS.d.ts +18 -0
  542. package/dist/provider-models-DxOmeToO.d.ts +867 -0
  543. package/dist/provider-models-xnyxy6mO.js +2113 -0
  544. package/dist/provider-ollama-setup-DBYK__ov.d.ts +32 -0
  545. package/dist/provider-ollama-setup-QzgCxj44.js +314 -0
  546. package/dist/provider-onboard-B9ionepI.js +139 -0
  547. package/dist/provider-onboard-CURxJ_UX.d.ts +40 -0
  548. package/dist/provider-runtime.runtime-4xwmsl5L.js +111 -0
  549. package/dist/provider-self-hosted-setup-BHd24EDG.js +182 -0
  550. package/dist/provider-self-hosted-setup-qeY8BYSy.d.ts +61 -0
  551. package/dist/provider-stream-Chz_EFw3.js +512 -0
  552. package/dist/provider-usage-C11Q7UwS.js +111 -0
  553. package/dist/provider-usage-kxemdMp2.js +633 -0
  554. package/dist/provider-wizard-CanJoxNC.js +152 -0
  555. package/dist/push-apns-Dsajnm8C.js +1038 -0
  556. package/dist/pw-ai-DUe4BbH2.js +1867 -0
  557. package/dist/qmd-manager-CAAFp7qK.js +1570 -0
  558. package/dist/qr-cli-Bu2jqTPY.js +113 -0
  559. package/dist/qr-cli-Bu9Z-X48.js +369 -0
  560. package/dist/reactions-Cpfum4iU.js +281 -0
  561. package/dist/read-only-account-inspect.discord.runtime-BK0LaMgC.js +116 -0
  562. package/dist/read-only-account-inspect.slack.runtime-DgKiC5wT.js +116 -0
  563. package/dist/read-only-account-inspect.telegram.runtime-mxfgFVOU.js +116 -0
  564. package/dist/redact-snapshot-DD8A4tdd.js +2663 -0
  565. package/dist/register.agent-DU4FtrU2.js +439 -0
  566. package/dist/register.backup-8nOYtJqg.js +625 -0
  567. package/dist/register.configure-DmtecqIH.js +252 -0
  568. package/dist/register.maintenance-Dir3ulKP.js +574 -0
  569. package/dist/register.message-Cfl-f3Ju.js +709 -0
  570. package/dist/register.onboard-Bv7WVzEi.js +192 -0
  571. package/dist/register.setup-BIyeI8RY.js +212 -0
  572. package/dist/register.status-health-sessions-C69WQcF4.js +498 -0
  573. package/dist/register.subclis-B_4KCgTd.js +315 -0
  574. package/dist/register.subclis-BeXsmgBL.js +13 -0
  575. package/dist/replies-DdcFUmki.js +110 -0
  576. package/dist/resolve-channels-DRZqPV5o.js +226 -0
  577. package/dist/resolve-channels-DxW1kqxA.js +262 -0
  578. package/dist/resolve-route-DdX-HBVt.js +538 -0
  579. package/dist/resolve-users-rgCQvkLs.js +143 -0
  580. package/dist/root-help-QAkoA7GD.js +32 -0
  581. package/dist/routes-CcJNnwTF.js +7097 -0
  582. package/dist/rpc-DDUAlBbH.js +67 -0
  583. package/dist/run-main-D9ci5pn7.js +424 -0
  584. package/dist/runtime-Bitmi8Er.d.ts +26 -0
  585. package/dist/runtime-discord-ops.runtime-T4sf7aRB.js +9078 -0
  586. package/dist/runtime-slack-ops.runtime-BQpP48mC.js +4556 -0
  587. package/dist/runtime-telegram-ops.runtime-cVO5dqOp.js +133 -0
  588. package/dist/runtime-whatsapp-login.runtime-DtNx0dSY.js +114 -0
  589. package/dist/runtime-whatsapp-outbound.runtime-Bw47QbFK.js +117 -0
  590. package/dist/sandbox-cli-DsFwjbjC.js +535 -0
  591. package/dist/search-manager-BRAK8fEe.js +16 -0
  592. package/dist/search-manager-BS5Db0A6.js +386 -0
  593. package/dist/secrets-cli-D3J46TJp.js +2070 -0
  594. package/dist/security-cli-B866M9cB.js +575 -0
  595. package/dist/send-B1pX9_Oc.js +283 -0
  596. package/dist/send-B2RrLg83.js +100 -0
  597. package/dist/send-DFnV__Aq.js +1025 -0
  598. package/dist/send-DZIH6CJt.js +629 -0
  599. package/dist/send-sl9WnKbW.js +631 -0
  600. package/dist/server-node-events-BT6egg20.js +506 -0
  601. package/dist/server-zI_K-D05.js +107 -0
  602. package/dist/sessions-C8kiAcoJ.js +112 -0
  603. package/dist/sessions-DLBpp52_.js +218 -0
  604. package/dist/setup-C7eOzMiC.js +387 -0
  605. package/dist/setup-CFIMq-Pz.d.ts +37 -0
  606. package/dist/setup-binary-CcAv8NXz.js +406 -0
  607. package/dist/setup-browser-C4eRV3h6.js +70 -0
  608. package/dist/setup-core-BnR486P-.js +143 -0
  609. package/dist/setup-core-CIswIiu5.js +166 -0
  610. package/dist/setup-core-CcbcrXXg.js +47 -0
  611. package/dist/setup-core-nZSw5BSv.js +205 -0
  612. package/dist/setup-surface-C5iSpT4M.js +490 -0
  613. package/dist/setup-wizard-helpers-r0J6l8ST.d.ts +203 -0
  614. package/dist/setup.finalize-adiRfo0U.js +522 -0
  615. package/dist/setup.gateway-config-BwFWKDfT.js +343 -0
  616. package/dist/shared-12TimyeF.js +182 -0
  617. package/dist/shared-9EWO34-k.js +298 -0
  618. package/dist/shared-B4vUbaRR.js +75 -0
  619. package/dist/shared-bNWpW3Dd.js +96 -0
  620. package/dist/shared-lU1y5dvS.js +102 -0
  621. package/dist/signal-DBlETRu9.js +114 -0
  622. package/dist/skills-Bio8GwTE.js +20 -0
  623. package/dist/skills-DE_MXFSN.js +853 -0
  624. package/dist/skills-cli-BGuW-tKw.js +292 -0
  625. package/dist/skills-install--rnorIoJ.js +763 -0
  626. package/dist/skills-status-B08PtBc_.js +21 -0
  627. package/dist/skills-status-CzM008aB.js +169 -0
  628. package/dist/slack-C4T53Nc-.js +114 -0
  629. package/dist/slash-commands.runtime-B7fsD8Be.js +128 -0
  630. package/dist/slash-dispatch.runtime-t0PAX4vQ.js +141 -0
  631. package/dist/slash-skill-commands.runtime-DIhPnEfR.js +116 -0
  632. package/dist/src-DrDirlvw.js +1701 -0
  633. package/dist/status-Bld14WSA.js +131 -0
  634. package/dist/status-CgeO4RuH.js +43 -0
  635. package/dist/status-HlvixAOq.js +606 -0
  636. package/dist/status-Rom_Lf3c.js +1599 -0
  637. package/dist/status-TwbMH6Am.js +126 -0
  638. package/dist/status-json-DMW7cmuK.js +288 -0
  639. package/dist/status.link-channel-V4LkB6Gq.js +143 -0
  640. package/dist/status.scan.deps.runtime-BE3X-dcP.js +126 -0
  641. package/dist/status.scan.runtime-BxVY4mty.js +119 -0
  642. package/dist/status.summary-CzLM0vVr.js +592 -0
  643. package/dist/status.summary.runtime-BSBnHZ1Q.js +118 -0
  644. package/dist/status.update-BxblMS7P.js +77 -0
  645. package/dist/subagent-orphan-recovery-BpRPryEj.js +307 -0
  646. package/dist/subagent-registry-runtime-DYYU5p3X.js +111 -0
  647. package/dist/subscription-CpFdxuFS.js +33 -0
  648. package/dist/subscription-DaA1urx-.js +102 -0
  649. package/dist/subscription-cli-Bvto9EmO.js +134 -0
  650. package/dist/synology-chat-3nwk-Nj0.js +297 -0
  651. package/dist/system-cli-BvNps8sl.js +94 -0
  652. package/dist/telegram/audit.d.ts +1 -1
  653. package/dist/telegram/audit.js +1 -1
  654. package/dist/telegram/token.d.ts +1 -1
  655. package/dist/telegram/token.js +35 -35
  656. package/dist/telegram-RtKXoEsF.js +114 -0
  657. package/dist/text-chunking-BD5mQe2R.js +84 -0
  658. package/dist/text-chunking-DDUU_vAF.d.ts +79 -0
  659. package/dist/tlon-z-kYmJE-.js +433 -0
  660. package/dist/tui-cli-CzSK08Rh.js +137 -0
  661. package/dist/tui-wV7R1Tlc.js +3834 -0
  662. package/dist/types-2H_e7eWT.d.ts +45 -0
  663. package/dist/types-ZKnGUchG.d.ts +22692 -0
  664. package/dist/types.base-BFiQZ4J9.d.ts +188 -0
  665. package/dist/ui-BWVHreeR.js +31 -0
  666. package/dist/update-D1Wgh1Tj.js +1036 -0
  667. package/dist/update-cli-CZh99uyY.js +1503 -0
  668. package/dist/update-offset-store-D5xTdUr0.js +112 -0
  669. package/dist/update-runner-GbKfoCHs.js +1496 -0
  670. package/dist/upsert-with-lock-BZU7Le8n.js +33 -0
  671. package/dist/usage-Czgwvg0h.js +115 -0
  672. package/dist/web-CMczmL90.js +112 -0
  673. package/dist/web-shared-B5Q0mIJq.d.ts +45 -0
  674. package/dist/webhook-request-guards-CsKDhZJr.d.ts +76 -0
  675. package/dist/webhook-targets-BSmFtesN.js +181 -0
  676. package/dist/webhook-targets-CjxuEE9C.d.ts +106 -0
  677. package/dist/webhooks-cli-Wl9y6AWW.js +350 -0
  678. package/dist/whatsapp-VzRW8MdR.js +114 -0
  679. package/dist/whatsapp-actions-Cg1Wxv8W.js +167 -0
  680. package/dist/workspace-DJ_S272u.js +484 -0
  681. package/dist/workspace-DbZSqjw0.js +289 -0
  682. package/dist/workspace-cli-D93DLmAh.js +154 -0
  683. package/dist/workspace-dirs-CGeIPpGN.js +2003 -0
  684. package/dist/zalo-CK2dlGmu.d.ts +9 -0
  685. package/dist/zalo-Db7s2boL.js +415 -0
  686. package/dist/zalouser-Jh5YTJX3.js +30911 -0
  687. package/extensions/discord/src/monitor/allow-list.ts +8 -1
  688. package/extensions/discord/src/monitor/message-handler.preflight.ts +4 -1
  689. package/package.json +1 -1
  690. package/dist/accounts-CS8U4v8C.js +0 -114
  691. package/dist/accounts-gLr-Udmt.d.ts +0 -103
  692. package/dist/acp-cli-BGT0jXcC.js +0 -2093
  693. package/dist/actions.runtime-BfckTw6c.js +0 -119
  694. package/dist/actions.runtime-Cl9mBfqH.js +0 -133
  695. package/dist/agent-scope-C-YmLnnb.js +0 -208
  696. package/dist/agents-CydD54p8.js +0 -222
  697. package/dist/agents-DpQsZO6O.js +0 -853
  698. package/dist/agents.config-XU7IsYE-.js +0 -121
  699. package/dist/agents.config-ssoQXuvF.js +0 -17
  700. package/dist/allow-list-Cfn6lmMK.js +0 -81
  701. package/dist/allowlist-CCYXVpM9.js +0 -142
  702. package/dist/api-BoXoFKxy.js +0 -117
  703. package/dist/audit-Bv05N5o9.js +0 -787
  704. package/dist/audit-CIWW1Aqm.js +0 -54
  705. package/dist/audit-channel.collect.runtime-Bi7yrdcO.js +0 -605
  706. package/dist/audit-channel.runtime-C_NDweiW.js +0 -121
  707. package/dist/audit-extra.async-Dp7OKSXg.js +0 -813
  708. package/dist/audit-membership-runtime-B8FQ6VtN.js +0 -162
  709. package/dist/audit.deep.runtime-CXhobL6b.js +0 -25
  710. package/dist/audit.nondeep.runtime-CrEm3T16.js +0 -832
  711. package/dist/audit.runtime-CJPKj1Zg.js +0 -118
  712. package/dist/auth-Byfp0flq.js +0 -101
  713. package/dist/auth-choice-BgOjdeXN.js +0 -507
  714. package/dist/auth-choice-CD1Heq0M.js +0 -122
  715. package/dist/auth-choice-ePNfg0iQ.js +0 -268
  716. package/dist/auth-choice-options-BlewQWI0.js +0 -123
  717. package/dist/auth-choice-prompt-BP2b6aXz.js +0 -36
  718. package/dist/auth-choice-prompt-Cmwl4n97.js +0 -115
  719. package/dist/auth-choice.apply-helpers-Dq-nxuuX.js +0 -66
  720. package/dist/auth-choice.plugin-providers.runtime-B23kOUzQ.js +0 -119
  721. package/dist/auth-profiles-1kPLbBwI.js +0 -127823
  722. package/dist/auth-profiles.runtime-DAfSjku1.js +0 -116
  723. package/dist/banner-DeOsobLO.js +0 -342
  724. package/dist/bluebubbles-BsLGedBM.js +0 -64
  725. package/dist/bluebubbles-U2sAfO4_.d.ts +0 -6
  726. package/dist/bot-DW12K3bO.d.ts +0 -478
  727. package/dist/brave-BoWimrLe.js +0 -24
  728. package/dist/browser-cli-D_S3wEYE.js +0 -1494
  729. package/dist/call-ByEzDJ1_.js +0 -640
  730. package/dist/call-CHCWVg-O.js +0 -39
  731. package/dist/channel-3VC0oOMu.js +0 -214
  732. package/dist/channel-B9fCBPiS.js +0 -207
  733. package/dist/channel-B9q775cM.js +0 -562
  734. package/dist/channel-BG3UK54j.js +0 -803
  735. package/dist/channel-BRQAdMML.js +0 -352
  736. package/dist/channel-BmlLp933.js +0 -1321
  737. package/dist/channel-By6KvdTG.js +0 -920
  738. package/dist/channel-C8rRsdf6.js +0 -226
  739. package/dist/channel-CLEDBbXE.js +0 -943
  740. package/dist/channel-CMvBAG7o.js +0 -306
  741. package/dist/channel-CmlxxjHY.js +0 -1598
  742. package/dist/channel-CqG6_xN0.js +0 -949
  743. package/dist/channel-DNueHKs92.js +0 -316
  744. package/dist/channel-DUtyN7BX.js +0 -4681
  745. package/dist/channel-DWD6GrfZ.js +0 -538
  746. package/dist/channel-DaRYMYzj.js +0 -619
  747. package/dist/channel-Dj6BgLp8.js +0 -575
  748. package/dist/channel-account-context-Ba3u5D21.js +0 -103
  749. package/dist/channel-crabk6Em.js +0 -542
  750. package/dist/channel-i8uqQaK2.js +0 -497
  751. package/dist/channel-options-xljvwHS2.js +0 -50
  752. package/dist/channel-plugin-ids-DAgknSG4.js +0 -26
  753. package/dist/channel-summary-dHTMCG75.js +0 -111
  754. package/dist/channel-xVWQ96Ni.js +0 -397
  755. package/dist/channel.runtime-B6PoZ4BV.js +0 -182
  756. package/dist/channel.runtime-BPZmo57e.js +0 -404
  757. package/dist/channel.runtime-B_1uGR-U.js +0 -199
  758. package/dist/channel.runtime-BiXnPU0d.js +0 -218
  759. package/dist/channel.runtime-BpvDc9sv.js +0 -870
  760. package/dist/channel.runtime-CUua3W80.js +0 -418
  761. package/dist/channel.runtime-CaCBTd0A.js +0 -179
  762. package/dist/channel.runtime-D0FfYvUj.js +0 -4011
  763. package/dist/channel.runtime-DhoJtpvJ.js +0 -241
  764. package/dist/channel.runtime-Kj9EXNE0.js +0 -127
  765. package/dist/channel.runtime-r4tPuPyh.js +0 -171
  766. package/dist/channel.setup-B7d_grfe.js +0 -6
  767. package/dist/channel.setup-C0vu1fhi.js +0 -9
  768. package/dist/channel.setup-CAI0FNHj.js +0 -11
  769. package/dist/channel.setup-CkDVwv5R.js +0 -57
  770. package/dist/channel.setup-Cpd00YqQ.js +0 -8
  771. package/dist/channel.setup-DbBz1-WT.js +0 -9
  772. package/dist/channel.setup-GZnAvD9g.js +0 -8
  773. package/dist/channels-5H484RSw.js +0 -1118
  774. package/dist/channels-BnPudfyx.js +0 -404
  775. package/dist/channels-cli-WIC-QeH_.js +0 -291
  776. package/dist/channels-status-issues-RDmzovJU.js +0 -16
  777. package/dist/clawbot-cli-BgutNwf8.js +0 -118
  778. package/dist/cleanup-utils-DBl1Aij1.js +0 -96
  779. package/dist/cli-1P7u6zqu.js +0 -154
  780. package/dist/command-registry-B8jovrws.js +0 -232
  781. package/dist/command-registry-DtDl1FVm.js +0 -14
  782. package/dist/command-secret-gateway-BgUo3FxJ.js +0 -111
  783. package/dist/compact.runtime-CXbXM0AU.js +0 -116
  784. package/dist/completion-cli-Cik_owAE.js +0 -17
  785. package/dist/completion-cli-RU3P2RSl.js +0 -445
  786. package/dist/config-5HUpB1L1.js +0 -31
  787. package/dist/config-cli-QHaUHoZI.js +0 -433
  788. package/dist/config-guard-C9Sn3pE-.js +0 -118
  789. package/dist/config-sW57gztj.js +0 -44
  790. package/dist/config-validation-5LkjIKNt.js +0 -262
  791. package/dist/config-value-CtTWALxG.js +0 -132
  792. package/dist/configure-BmR2TPLf.js +0 -243
  793. package/dist/configure-DaLN-5xM.js +0 -1100
  794. package/dist/control-ui-assets-CH3MYmAo.js +0 -232
  795. package/dist/control-ui-shared-CA77PTml.js +0 -29
  796. package/dist/core-CvDzLs7B.js +0 -150
  797. package/dist/core-dPA4nFkn.d.ts +0 -87
  798. package/dist/cron-cli-tguLpzyq.js +0 -639
  799. package/dist/daemon-cli-ptosOkL8.js +0 -339
  800. package/dist/daemon-install-DzU4EnVa.js +0 -180
  801. package/dist/deliver-DwxFoHM3.js +0 -111
  802. package/dist/deliver-runtime-DOdDyaPI.js +0 -111
  803. package/dist/device-id-cli-GopvlxxZ.js +0 -52
  804. package/dist/device-identity-CRfhC3_s.js +0 -365
  805. package/dist/devices-cli-ain7ESqU.js +0 -342
  806. package/dist/diagnostic-D96Xaqrj.js +0 -310
  807. package/dist/directory-cli-fh1UxGgY.js +0 -311
  808. package/dist/directory-config-helpers-CpU1oflo.d.ts +0 -38
  809. package/dist/directory.static-CKjJUNGl.js +0 -44
  810. package/dist/discord-CflhwDEM.js +0 -114
  811. package/dist/discovery-x0ZqY4AB.js +0 -48
  812. package/dist/dm-policy-shared-73A52W6E.d.ts +0 -95
  813. package/dist/dns-cli-DCHyKjGf.js +0 -217
  814. package/dist/docs-cli-D3OoqYSP.js +0 -174
  815. package/dist/doctor-completion-Bq2eP87s.js +0 -90
  816. package/dist/doctor-config-flow-D8XRG9Ku.js +0 -2437
  817. package/dist/doctor-config-flow-DGiF1HGc.js +0 -112
  818. package/dist/enable-0QSF4YGH.js +0 -24
  819. package/dist/exec-approvals-cli-Bncym0Gd.js +0 -421
  820. package/dist/feishu-B5JDcyF9.d.ts +0 -36
  821. package/dist/gateway-cli-DYscsmA-.js +0 -26437
  822. package/dist/gateway-install-token-CNv17ac9.js +0 -163
  823. package/dist/gateway-rpc-BGC1Rxvg.js +0 -26
  824. package/dist/gateway-runtime-D89mSQPB.js +0 -69
  825. package/dist/git-commit-CeLH5Ozm.js +0 -2
  826. package/dist/git-commit-DUKRiCP-.js +0 -177
  827. package/dist/googlechat-BgXeXjd1.js +0 -307
  828. package/dist/googlechat-De-T7C31.d.ts +0 -12
  829. package/dist/group-access-Deh1tVNr.d.ts +0 -61
  830. package/dist/health-BEjzWwaB.js +0 -570
  831. package/dist/health-FjqrWQL6.js +0 -113
  832. package/dist/heartbeat-summary-CfdSA9M1.js +0 -57
  833. package/dist/help-BZeVprq1.js +0 -81
  834. package/dist/hooks-B5pYs_d7.d.ts +0 -6
  835. package/dist/hooks-cli-B7uGJs2O.js +0 -1000
  836. package/dist/hooks-status-CfceaUSg.js +0 -78
  837. package/dist/http-registry-C-KXqwnj.d.ts +0 -20
  838. package/dist/identity-file-sshkKKIr.js +0 -60
  839. package/dist/image-generation-CafM5hZh.d.ts +0 -9
  840. package/dist/imessage-BcV3WGx_.js +0 -31
  841. package/dist/imessage-Dhje7Ty-.js +0 -115
  842. package/dist/inbound-reply-dispatch-C73_7SOl.js +0 -71
  843. package/dist/inbound-reply-dispatch-DmL0KWLe.d.ts +0 -72
  844. package/dist/install-target-D7NRhfzc.js +0 -574
  845. package/dist/installs-Bj6jblqc.js +0 -532
  846. package/dist/io-CMfWWPXQ.js +0 -9738
  847. package/dist/io-CV844hAM.js +0 -29
  848. package/dist/irc-DKi1fDYI.js +0 -672
  849. package/dist/library-rygTG3oA.js +0 -112
  850. package/dist/lifecycle-core-BPlvShWY.js +0 -382
  851. package/dist/line-CGsemKWJ.js +0 -530
  852. package/dist/line-CKU3ER-n.d.ts +0 -75
  853. package/dist/llm-slug-generator-DlhVyMqT.js +0 -67
  854. package/dist/logging-5wu9k6w4.js +0 -30
  855. package/dist/logging-CxP9suT8.js +0 -13
  856. package/dist/login-qr-BcDsiwHs.js +0 -233
  857. package/dist/login-qr-Y8pJ5yV4.js +0 -112
  858. package/dist/logs-cli-XI9oVXpH.js +0 -256
  859. package/dist/manager-runtime-DkIlXBhD.js +0 -111
  860. package/dist/manager.runtime-Q0q2rJCC.js +0 -715
  861. package/dist/manifest-registry-DAd0SRAP.js +0 -1329
  862. package/dist/matrix-BI0DBBrG.js +0 -1495
  863. package/dist/matrix-DiABGjJR.js +0 -1269
  864. package/dist/matrix-fC6NrFM5.d.ts +0 -68
  865. package/dist/mcp-cli-BOyn_DLL.js +0 -87
  866. package/dist/media-understanding.runtime-DjUa7Dka.js +0 -116
  867. package/dist/memory-cli-CJd_vl-Y.js +0 -111
  868. package/dist/memory-search-CEEItIFR.js +0 -17
  869. package/dist/memory-search-Cv1SBrn7.js +0 -204
  870. package/dist/method-scopes-CQE7-bZ-.js +0 -2452
  871. package/dist/model-auth-markers-B1bbs9Qd.d.ts +0 -20
  872. package/dist/model-picker-D6_89XHg.js +0 -112
  873. package/dist/model-picker-Svaw-APs.js +0 -390
  874. package/dist/model-picker.runtime-Chi9nV7A.js +0 -125
  875. package/dist/model-selection-hL8i1Jbs.js +0 -653
  876. package/dist/model-suppression.runtime-DjWJZ0X-.js +0 -116
  877. package/dist/models-7qj1dG_W.js +0 -118
  878. package/dist/models-BPOB_xJF.js +0 -2514
  879. package/dist/models-cli-DdlOVUjS.js +0 -309
  880. package/dist/models-config-CBqUS-jX.js +0 -111
  881. package/dist/models-config.providers.discovery-BKB5JH9M.d.ts +0 -18
  882. package/dist/moldclaw-root-D6PbhbZk.js +0 -88
  883. package/dist/monitor-BPYhkEqF.js +0 -782
  884. package/dist/monitor-BuTcQ24j.js +0 -3468
  885. package/dist/monitor-CuXvNhFh.js +0 -113
  886. package/dist/monitor-D-TqSIHF.js +0 -6823
  887. package/dist/monitor-DRSgo9u2.js +0 -3076
  888. package/dist/monitor-DcHch39z.js +0 -772
  889. package/dist/monitor-DsHBMrXp.js +0 -115
  890. package/dist/monitor-shared-CL8T4gt1.js +0 -444
  891. package/dist/msteams-7FMwTvQG.js +0 -852
  892. package/dist/node-cli-BCjaSCZM.js +0 -2503
  893. package/dist/node-resolve-D5Hvcgyx.js +0 -835
  894. package/dist/nodes-cli-Dd_SNbkt.js +0 -1380
  895. package/dist/nostr-D8scBiYq.d.ts +0 -7
  896. package/dist/nostr-DBTFTxKs.js +0 -8744
  897. package/dist/npm-resolution-CYfb3MHG.js +0 -60
  898. package/dist/oauth-env-zPt5RywA.js +0 -10
  899. package/dist/onboard-BEFQQeig.js +0 -25
  900. package/dist/onboard-CJHNyxJh.js +0 -48
  901. package/dist/onboard-D_3UeLEN.js +0 -589
  902. package/dist/onboard-channels-B_JL0Djc.js +0 -1241
  903. package/dist/onboard-channels-CqZzHt2C.js +0 -205
  904. package/dist/onboard-custom-CER3Ggbq.js +0 -571
  905. package/dist/onboard-custom-bNRdGECb.js +0 -114
  906. package/dist/onboard-helpers-BK0Hsb7Y.js +0 -335
  907. package/dist/onboard-helpers-CXZ5RPoR.js +0 -113
  908. package/dist/onboard-hooks-1NsxEDjH.js +0 -72
  909. package/dist/onboard-remote-DuKhC_7W.js +0 -117
  910. package/dist/onboard-remote-OwRcDuB3.js +0 -181
  911. package/dist/onboard-search-Cy8dOq2W.js +0 -302
  912. package/dist/onboard-skills-D5phRa6r.js +0 -117
  913. package/dist/onboard-skills-c9qWCNe9.js +0 -133
  914. package/dist/outbound-media-CgNYEQWb.d.ts +0 -11
  915. package/dist/outbound-media-DYRO2vTD.js +0 -11
  916. package/dist/pairing-access-Dsiu5Mvl.d.ts +0 -21
  917. package/dist/pairing-cli-BOnv0TYn.js +0 -217
  918. package/dist/perplexity-EZwC3y2b.js +0 -24
  919. package/dist/persistent-dedupe-DMLOqJ23.d.ts +0 -26
  920. package/dist/pi-model-discovery-runtime-BToY3A6K.js +0 -111
  921. package/dist/pi-tools.before-tool-call.runtime-D_acPtld.js +0 -381
  922. package/dist/plugin-install-CgJpSjYd.js +0 -184
  923. package/dist/plugin-install-Cl1A4EF6.js +0 -117
  924. package/dist/plugin-install-plan-Dc2Z4DeU.js +0 -49
  925. package/dist/plugin-registry-B1UaWrQD.js +0 -49
  926. package/dist/plugin-registry-Cy8biwnn.js +0 -113
  927. package/dist/plugins-CXwvg50F.js +0 -111
  928. package/dist/plugins-cli-Uvzp2aYV.js +0 -917
  929. package/dist/policy-DsMBbEe7.js +0 -143
  930. package/dist/preflight-audio.runtime-hWsZIYvc.js +0 -116
  931. package/dist/probe-CNsSf1Uf.js +0 -6329
  932. package/dist/probe-CqOIrPhb.js +0 -47
  933. package/dist/probe-DH6gDw-h.js +0 -129
  934. package/dist/probe-DM16PLf4.js +0 -21
  935. package/dist/probe-DvAEEWYr.js +0 -1793
  936. package/dist/probe-auth-COfgCble.js +0 -48
  937. package/dist/probe-auth-I_5TX1Eh.js +0 -40
  938. package/dist/program-Dz80sgTU.js +0 -253
  939. package/dist/prompt-select-styled-wQehwFxK.js +0 -2673
  940. package/dist/provider-api-key-auth.runtime-BR9GU4ya.js +0 -121
  941. package/dist/provider-auth-choice-CdhA84kr.js +0 -126
  942. package/dist/provider-auth-choice-helpers-kabp_0zA.js +0 -48
  943. package/dist/provider-auth-choice-preference-se3zAM_2.js +0 -189
  944. package/dist/provider-auth-choice.runtime-BMc8-xNQ.js +0 -123
  945. package/dist/provider-auth-choices-CYsCViGi.js +0 -57
  946. package/dist/provider-auth-guidance-CMjUWlNf.js +0 -34
  947. package/dist/provider-auth-result-Cw6qIhO-.d.ts +0 -18
  948. package/dist/provider-models-BCId_Lfu.js +0 -2113
  949. package/dist/provider-models-Ok-DrSiY.d.ts +0 -867
  950. package/dist/provider-ollama-setup-B6XJZ0So.js +0 -314
  951. package/dist/provider-ollama-setup-lGDdTl0b.d.ts +0 -32
  952. package/dist/provider-onboard-CSPi7jOK.d.ts +0 -40
  953. package/dist/provider-onboard-Ca0TaNud.js +0 -139
  954. package/dist/provider-runtime.runtime-DwwkHw_7.js +0 -111
  955. package/dist/provider-self-hosted-setup-BEKLVGpj.js +0 -182
  956. package/dist/provider-self-hosted-setup-Df91By-J.d.ts +0 -61
  957. package/dist/provider-stream-DrUD69ai.js +0 -512
  958. package/dist/provider-usage-BgKHCnjr.js +0 -111
  959. package/dist/provider-usage-D8EZpFz9.js +0 -633
  960. package/dist/provider-wizard-DMdb-zj_.js +0 -152
  961. package/dist/push-apns-BPH6d4VV.js +0 -1038
  962. package/dist/pw-ai-DttfldtL.js +0 -1867
  963. package/dist/qmd-manager-CybcDUfk.js +0 -1570
  964. package/dist/qr-cli-8NcmJ8Ft.js +0 -369
  965. package/dist/qr-cli-DWe0Our3.js +0 -113
  966. package/dist/reactions-D6N0LR16.js +0 -281
  967. package/dist/read-only-account-inspect.discord.runtime-CqUWTRfl.js +0 -116
  968. package/dist/read-only-account-inspect.slack.runtime-9-jpln3q.js +0 -116
  969. package/dist/read-only-account-inspect.telegram.runtime-EKPI1D7n.js +0 -116
  970. package/dist/redact-snapshot-DwJEIVk9.js +0 -2663
  971. package/dist/register.agent-D3YdDirP.js +0 -439
  972. package/dist/register.backup-dR27qCuo.js +0 -625
  973. package/dist/register.configure-BjFhkkka.js +0 -252
  974. package/dist/register.maintenance-DiMQJIOa.js +0 -574
  975. package/dist/register.message-CdZsKYH1.js +0 -709
  976. package/dist/register.onboard-B0rV1eaO.js +0 -192
  977. package/dist/register.setup-wKMvohzo.js +0 -212
  978. package/dist/register.status-health-sessions-BJ68m6pt.js +0 -498
  979. package/dist/register.subclis-CnnrWt2a.js +0 -315
  980. package/dist/register.subclis-lSvTkC6z.js +0 -13
  981. package/dist/replies-BABt9b48.js +0 -110
  982. package/dist/resolve-channels-BqZFl2Ux.js +0 -262
  983. package/dist/resolve-channels-DjQLXb7B.js +0 -226
  984. package/dist/resolve-route-CSHDsa_m.js +0 -538
  985. package/dist/resolve-users-BG6HaSR5.js +0 -143
  986. package/dist/root-help-ohmaCyC_.js +0 -32
  987. package/dist/routes-4k2kpvoT.js +0 -7097
  988. package/dist/rpc-Cnwn4Q6L.js +0 -67
  989. package/dist/run-main-VYlacKA0.js +0 -424
  990. package/dist/runtime-D61jzMiI.d.ts +0 -26
  991. package/dist/runtime-discord-ops.runtime-DafrU-rI.js +0 -9078
  992. package/dist/runtime-slack-ops.runtime-CdXBKXwd.js +0 -4556
  993. package/dist/runtime-telegram-ops.runtime-B12sF7gE.js +0 -133
  994. package/dist/runtime-whatsapp-login.runtime-CqEudH37.js +0 -114
  995. package/dist/runtime-whatsapp-outbound.runtime-D5m2qyn-.js +0 -117
  996. package/dist/sandbox-cli-CHJiEWXB.js +0 -535
  997. package/dist/search-manager-BtNC3-i_.js +0 -16
  998. package/dist/search-manager-C7J7B3_a.js +0 -386
  999. package/dist/secrets-cli-C6yIWBbN.js +0 -2070
  1000. package/dist/security-cli-BVu9BkjD.js +0 -575
  1001. package/dist/send-BSreC7rr.js +0 -631
  1002. package/dist/send-BsLHQG_B.js +0 -1025
  1003. package/dist/send-BuNhp8PH.js +0 -283
  1004. package/dist/send-DOCswVar.js +0 -100
  1005. package/dist/send-Dl0LLErk.js +0 -629
  1006. package/dist/server-node-events-Bq2067EG.js +0 -506
  1007. package/dist/server-y38L7N5H.js +0 -107
  1008. package/dist/sessions-BV8gXURR.js +0 -112
  1009. package/dist/sessions-dl1Kc-Ci.js +0 -218
  1010. package/dist/setup-BSPXdMuK.d.ts +0 -37
  1011. package/dist/setup-DGszQH0_.js +0 -387
  1012. package/dist/setup-binary-C17YnmA8.js +0 -406
  1013. package/dist/setup-browser-CPx-nEsr.js +0 -70
  1014. package/dist/setup-core-BByHN1ME.js +0 -143
  1015. package/dist/setup-core-C0KPlBmL.js +0 -47
  1016. package/dist/setup-core-Cq37G6of.js +0 -166
  1017. package/dist/setup-core-uO84_Y75.js +0 -205
  1018. package/dist/setup-surface-BEMi7Rmb.js +0 -490
  1019. package/dist/setup-wizard-helpers-Ck9wDR0b.d.ts +0 -203
  1020. package/dist/setup.finalize-BzPBa8zW.js +0 -522
  1021. package/dist/setup.gateway-config-DdwkF-8e.js +0 -343
  1022. package/dist/shared-BCw4SKjB.js +0 -96
  1023. package/dist/shared-CjNzsULP.js +0 -75
  1024. package/dist/shared-Cu1BE7ZE.js +0 -298
  1025. package/dist/shared-DSClmyUn.js +0 -182
  1026. package/dist/shared-DyJdGH6y.js +0 -102
  1027. package/dist/signal-Dyv4NZsB.js +0 -114
  1028. package/dist/skills-CbB5b27M.js +0 -853
  1029. package/dist/skills-CnfI7Szw.js +0 -20
  1030. package/dist/skills-cli-CavB1f_3.js +0 -292
  1031. package/dist/skills-install-B1OBdgd0.js +0 -763
  1032. package/dist/skills-status-B3gAmIbW.js +0 -169
  1033. package/dist/skills-status-DrHhFgU9.js +0 -21
  1034. package/dist/slack-BRzqnoAz.js +0 -114
  1035. package/dist/slash-commands.runtime-BK88kgds.js +0 -128
  1036. package/dist/slash-dispatch.runtime-COGywwJE.js +0 -141
  1037. package/dist/slash-skill-commands.runtime-Ti4brxgh.js +0 -116
  1038. package/dist/src-DUR6OQxI.js +0 -1701
  1039. package/dist/status-C6dgQY9a.js +0 -131
  1040. package/dist/status-CNK0Q7QH.js +0 -606
  1041. package/dist/status-DBcX0DSC.js +0 -43
  1042. package/dist/status-DKgFgbwv.js +0 -1599
  1043. package/dist/status-Wn5lhNAc.js +0 -126
  1044. package/dist/status-json-D2EkWqAl.js +0 -288
  1045. package/dist/status.link-channel-D3ULIdEa.js +0 -143
  1046. package/dist/status.scan.deps.runtime-BsjWTAm4.js +0 -126
  1047. package/dist/status.scan.runtime-D4HbzROD.js +0 -119
  1048. package/dist/status.summary-C3YxPrDK.js +0 -592
  1049. package/dist/status.summary.runtime-DAkXPSaK.js +0 -118
  1050. package/dist/status.update-B4NnN9P1.js +0 -77
  1051. package/dist/subagent-orphan-recovery-QiQEBv36.js +0 -307
  1052. package/dist/subagent-registry-runtime-BJatPQFK.js +0 -111
  1053. package/dist/subscription-BhZORXN9.js +0 -100
  1054. package/dist/subscription-QEUjQRMv.js +0 -33
  1055. package/dist/subscription-cli-HrULlAgc.js +0 -134
  1056. package/dist/synology-chat-DB76GWMN.js +0 -297
  1057. package/dist/system-cli-D8jDwWuL.js +0 -94
  1058. package/dist/telegram-BHiiqKkQ.js +0 -114
  1059. package/dist/text-chunking-Baonm9Lu.js +0 -84
  1060. package/dist/text-chunking-DzB11ONk.d.ts +0 -79
  1061. package/dist/tlon-DLESxNgD.js +0 -433
  1062. package/dist/tui-C75zi2Cl.js +0 -3834
  1063. package/dist/tui-cli-DFwx5e6i.js +0 -137
  1064. package/dist/types-BKldC9YN.d.ts +0 -22692
  1065. package/dist/types-MeyueBE0.d.ts +0 -45
  1066. package/dist/types.base-Cw0-zIvE.d.ts +0 -188
  1067. package/dist/ui-B55NOIB6.js +0 -31
  1068. package/dist/update--ojavYQ4.js +0 -1036
  1069. package/dist/update-cli-Cvj5aWYM.js +0 -1503
  1070. package/dist/update-offset-store-upatuWwX.js +0 -112
  1071. package/dist/update-runner-DHkY_-76.js +0 -1496
  1072. package/dist/upsert-with-lock-C171GLaR.js +0 -33
  1073. package/dist/usage-N3bxnbmt.js +0 -115
  1074. package/dist/web-RdvT7gKa.js +0 -112
  1075. package/dist/web-shared-C2qHVxw1.d.ts +0 -45
  1076. package/dist/webhook-request-guards-CosLyl01.d.ts +0 -76
  1077. package/dist/webhook-targets-Bfnag-du.js +0 -181
  1078. package/dist/webhook-targets-DP_EkQa4.d.ts +0 -106
  1079. package/dist/webhooks-cli-ZpnXrq7G.js +0 -350
  1080. package/dist/whatsapp-DNTAyZHt.js +0 -114
  1081. package/dist/whatsapp-actions-o1zKQzKZ.js +0 -167
  1082. package/dist/workspace-CpWi5wPr.js +0 -479
  1083. package/dist/workspace-Ii7aRS7c.js +0 -289
  1084. package/dist/workspace-dirs-x10McA9t.js +0 -2003
  1085. package/dist/zalo-C9OQRYRw.d.ts +0 -9
  1086. package/dist/zalo-zm_bYCKg.js +0 -415
  1087. package/dist/zalouser-CvVEUvc5.js +0 -30911
  1088. /package/dist/{account-id-B3YSn4hl.d.ts → account-id-B8ce6G_4.d.ts} +0 -0
  1089. /package/dist/{acpx-CnNv70m2.d.ts → acpx-Ci50I9T2.d.ts} +0 -0
  1090. /package/dist/{agent-media-payload-DE2pEcsz.d.ts → agent-media-payload-en-gS5p6.d.ts} +0 -0
  1091. /package/dist/{allow-from-DPpHnT2A.d.ts → allow-from-cMeQ47Ot.d.ts} +0 -0
  1092. /package/dist/{allowlist-resolution-CLFiZ6nE.d.ts → allowlist-resolution-DoAWbfXV.d.ts} +0 -0
  1093. /package/dist/{bluebubbles-Duhu-Jer.d.ts → bluebubbles-C6yYmUl0.d.ts} +0 -0
  1094. /package/dist/{boolean-param-BhFjB3gp.d.ts → boolean-param-CdO2TFTk.d.ts} +0 -0
  1095. /package/dist/{channel-config-schema-DnnVMdjR.d.ts → channel-config-schema-Chp38wel.d.ts} +0 -0
  1096. /package/dist/{channel-policy-Baq-Z06b.d.ts → channel-policy-g2h6AbYQ.d.ts} +0 -0
  1097. /package/dist/{chat-type-DpiBgwuG.d.ts → chat-type-BLt59pPT.d.ts} +0 -0
  1098. /package/dist/{command-format-vi4xq8e8.d.ts → command-format-BDJC05Jp.d.ts} +0 -0
  1099. /package/dist/{diffs-DK7fVSDo.d.ts → diffs-D_iNKCyn.d.ts} +0 -0
  1100. /package/dist/{directory-runtime-BTLPaysA.d.ts → directory-runtime-DhMex6HY.d.ts} +0 -0
  1101. /package/dist/{exec-C01wtBHu.d.ts → exec-pjfUY4KM.d.ts} +0 -0
  1102. /package/dist/{gaxios-fetch-compat-wZ38b3w3.js → gaxios-fetch-compat-B_vtINdV.js} +0 -0
  1103. /package/dist/{history-CwXuP2TW.d.ts → history-aqSS5VGQ.d.ts} +0 -0
  1104. /package/dist/{inbound-envelope-SggrBs9m.d.ts → inbound-envelope-C5hWuZod.d.ts} +0 -0
  1105. /package/dist/{index-apAZHsDo.d.ts → index-DXVQFYGX.d.ts} +0 -0
  1106. /package/dist/{json-store-r75IZGk9.d.ts → json-store-UnqQ5aV3.d.ts} +0 -0
  1107. /package/dist/{keyed-async-queue-DHIr7yNe.d.ts → keyed-async-queue-guucpLw3.d.ts} +0 -0
  1108. /package/dist/{links-HeQ3r_L0.d.ts → links-Bar0meEK.d.ts} +0 -0
  1109. /package/dist/{markdown-to-line-CDb4Jy3V.d.ts → markdown-to-line-D8uH_KOj.d.ts} +0 -0
  1110. /package/dist/{mattermost-DtCsxpgg.d.ts → mattermost-xl7jAFJL.d.ts} +0 -0
  1111. /package/dist/{net-BATPDwdQ.d.ts → net-rGOKGds6.d.ts} +0 -0
  1112. /package/dist/{nextcloud-talk-Bb2wHOwp.d.ts → nextcloud-talk-De2CZ9dV.d.ts} +0 -0
  1113. /package/dist/{oauth-utils-u567CLT0.d.ts → oauth-utils-DzN1AlEH.d.ts} +0 -0
  1114. /package/dist/{parse-finite-number-l3tNlrZh.d.ts → parse-finite-number-odgyqhi0.d.ts} +0 -0
  1115. /package/dist/{provider-usage.types-C6061OVN.d.ts → provider-usage.types-EDE9o-H_.d.ts} +0 -0
  1116. /package/dist/{reply-history-BDsFnZFl.d.ts → reply-history-CVuU31xe.d.ts} +0 -0
  1117. /package/dist/{reply-payload-CCvM4W9u.d.ts → reply-payload-CHkpBYwL.d.ts} +0 -0
  1118. /package/dist/{request-url-C54l4-xC.d.ts → request-url-DHisbiHY.d.ts} +0 -0
  1119. /package/dist/{run-command-D3RqWcHu.d.ts → run-command-y0Cndsb1.d.ts} +0 -0
  1120. /package/dist/{secret-input-schema-BLBt-NAP.d.ts → secret-input-schema-b1vpYDQN.d.ts} +0 -0
  1121. /package/dist/{session-key-BQ2-bR-9.d.ts → session-key-DTHQl57f.d.ts} +0 -0
  1122. /package/dist/{ssh-config-C4mcH9Ly.js → ssh-config-hEHBfU2_.js} +0 -0
  1123. /package/dist/{testing-DLkhGsoz.d.ts → testing-DszuZXgK.d.ts} +0 -0
  1124. /package/dist/{thinking-DRkjX18p.d.ts → thinking-IwXTGSeT.d.ts} +0 -0
  1125. /package/dist/{tool-send-CMMD1uDu.d.ts → tool-send-DWHRmKpz.d.ts} +0 -0
  1126. /package/dist/{vllm-defaults-CcGuf4hL.d.ts → vllm-defaults-CrxZgE6-.d.ts} +0 -0
  1127. /package/dist/{wait-Daog8bxM.d.ts → wait-wDWw_MTI.d.ts} +0 -0
  1128. /package/dist/{webhook-memory-guards-C5MrExwT.d.ts → webhook-memory-guards-DreORuJy.d.ts} +0 -0
  1129. /package/dist/{windows-spawn-j2l-dqu8.d.ts → windows-spawn-BIzH92x2.d.ts} +0 -0
  1130. /package/dist/{zod-schema.agent-runtime-krMrBnIn.d.ts → zod-schema.agent-runtime-CP2rmis3.d.ts} +0 -0
  1131. /package/dist/{zod-schema.core-BNDieZDZ.d.ts → zod-schema.core-Foi1tYwi.d.ts} +0 -0
@@ -1,3468 +0,0 @@
1
- import { $v as registerSessionBindingAdapter, Ah as createScopedPairingAccess, Ch as createFixedWindowRateLimiter, Dh as createPersistentDedupe, Fh as createEventDispatcher, Hh as resolveFeishuAccount, Ih as createFeishuClient, Lh as createFeishuWSClient, Oh as issuePairingChallenge, Ph as probeFeishu, Pt as resolveThreadBindingConversationIdFromBindingId, Qg as buildPendingHistoryContextFromMap, Rh as raceWithTimeoutAndAbort, Sh as WEBHOOK_RATE_LIMIT_DEFAULTS, Th as buildFeishuConversationId, WS as createDedupeCache, Wg as logTypingFailure, Zv as getSessionBindingService, _S as installRequestBodyLimitGuard, __ as resolveThreadBindingMaxAgeMsForChannel, ag as createTypingCallbacks, e_ as clearHistoryEntriesIfEnabled, ey as unregisterSessionBindingAdapter, fm as ensureConfiguredAcpRouteReady, gh as applyBasicWebhookRequestGuards, h_ as resolveThreadBindingIdleTimeoutMsForChannel, iS as resolveAgentOutboundIdentity, jh as buildAgentMediaPayload, og as createReplyPrefixContext, pm as resolveConfiguredAcpRoute, r_ as recordPendingHistoryEntryIfEnabled, wh as createWebhookAnomalyTracker, xh as WEBHOOK_ANOMALY_COUNTER_DEFAULTS, yS as readJsonBodyWithLimit, zh as listEnabledFeishuAccounts } from "./auth-profiles-1kPLbBwI.js";
2
- import { c as normalizeAgentId, u as resolveAgentIdFromSessionKey } from "./session-key-UoG7Kfw5.js";
3
- import { n as normalizeAccountId } from "./account-id-BuyZMNja.js";
4
- import { J as fetchWithSsrFGuard } from "./provider-web-search-CcUC9ktE.js";
5
- import { o as resolveGlobalSingleton } from "./text-runtime-Cfq-Uyx0.js";
6
- import { n as deriveLastRoutePolicy } from "./resolve-route-CSHDsa_m.js";
7
- import { f as warnMissingProviderGroupPolicyFallbackOnce, l as resolveDefaultGroupPolicy, u as resolveOpenProviderRuntimeGroupPolicy } from "./group-access-UAqUyJod.js";
8
- import { t as readJsonFileWithFallback } from "./json-store--7cBPxTG.js";
9
- import { a as resolveReceiveIdType, t as getFeishuRuntime } from "./runtime-BKcd1buT.js";
10
- import { a as resolveFeishuReplyPolicy, n as resolveFeishuAllowlistMatch, r as resolveFeishuGroupConfig, t as isFeishuGroupAllowed } from "./policy-8e8pPYkk.js";
11
- import { C as sendMediaFeishu, E as normalizeFeishuExternalKey, a as sendCardFeishu, b as downloadMessageResourceFeishu, c as sendStructuredCardFeishu, d as buildMentionedCardContent, i as resolveFeishuCardTemplate, n as getMessageFeishu, o as sendMarkdownCardFeishu, p as extractMentionTargets, r as listFeishuThreadMessages, s as sendMessageFeishu, u as parsePostContent, y as isMentionForwardRequest } from "./send-BsLHQG_B.js";
12
- import fs from "node:fs";
13
- import path from "node:path";
14
- import os from "node:os";
15
- import crypto from "node:crypto";
16
- import * as Lark from "@larksuiteoapi/node-sdk";
17
- import * as crypto$2 from "crypto";
18
- import * as http from "http";
19
- //#region extensions/feishu/src/thread-bindings.ts
20
- const state = resolveGlobalSingleton(Symbol.for("moldclaw.feishuThreadBindingsState"), () => ({
21
- managersByAccountId: /* @__PURE__ */ new Map(),
22
- bindingsByAccountConversation: /* @__PURE__ */ new Map()
23
- }));
24
- const MANAGERS_BY_ACCOUNT_ID = state.managersByAccountId;
25
- const BINDINGS_BY_ACCOUNT_CONVERSATION = state.bindingsByAccountConversation;
26
- function resolveBindingKey(params) {
27
- return `${params.accountId}:${params.conversationId}`;
28
- }
29
- function toSessionBindingTargetKind(raw) {
30
- return raw === "subagent" ? "subagent" : "session";
31
- }
32
- function toFeishuTargetKind(raw) {
33
- return raw === "subagent" ? "subagent" : "acp";
34
- }
35
- function toSessionBindingRecord(record, defaults) {
36
- const idleExpiresAt = defaults.idleTimeoutMs > 0 ? record.lastActivityAt + defaults.idleTimeoutMs : void 0;
37
- const maxAgeExpiresAt = defaults.maxAgeMs > 0 ? record.boundAt + defaults.maxAgeMs : void 0;
38
- const expiresAt = idleExpiresAt != null && maxAgeExpiresAt != null ? Math.min(idleExpiresAt, maxAgeExpiresAt) : idleExpiresAt ?? maxAgeExpiresAt;
39
- return {
40
- bindingId: resolveBindingKey({
41
- accountId: record.accountId,
42
- conversationId: record.conversationId
43
- }),
44
- targetSessionKey: record.targetSessionKey,
45
- targetKind: toSessionBindingTargetKind(record.targetKind),
46
- conversation: {
47
- channel: "feishu",
48
- accountId: record.accountId,
49
- conversationId: record.conversationId,
50
- parentConversationId: record.parentConversationId
51
- },
52
- status: "active",
53
- boundAt: record.boundAt,
54
- expiresAt,
55
- metadata: {
56
- agentId: record.agentId,
57
- label: record.label,
58
- boundBy: record.boundBy,
59
- deliveryTo: record.deliveryTo,
60
- deliveryThreadId: record.deliveryThreadId,
61
- lastActivityAt: record.lastActivityAt,
62
- idleTimeoutMs: defaults.idleTimeoutMs,
63
- maxAgeMs: defaults.maxAgeMs
64
- }
65
- };
66
- }
67
- function createFeishuThreadBindingManager(params) {
68
- const accountId = normalizeAccountId(params.accountId);
69
- const existing = MANAGERS_BY_ACCOUNT_ID.get(accountId);
70
- if (existing) return existing;
71
- const idleTimeoutMs = resolveThreadBindingIdleTimeoutMsForChannel({
72
- cfg: params.cfg,
73
- channel: "feishu",
74
- accountId
75
- });
76
- const maxAgeMs = resolveThreadBindingMaxAgeMsForChannel({
77
- cfg: params.cfg,
78
- channel: "feishu",
79
- accountId
80
- });
81
- const manager = {
82
- accountId,
83
- getByConversationId: (conversationId) => BINDINGS_BY_ACCOUNT_CONVERSATION.get(resolveBindingKey({
84
- accountId,
85
- conversationId
86
- })),
87
- listBySessionKey: (targetSessionKey) => [...BINDINGS_BY_ACCOUNT_CONVERSATION.values()].filter((record) => record.accountId === accountId && record.targetSessionKey === targetSessionKey),
88
- bindConversation: ({ conversationId, parentConversationId, targetKind, targetSessionKey, metadata }) => {
89
- const normalizedConversationId = conversationId.trim();
90
- if (!normalizedConversationId || !targetSessionKey.trim()) return null;
91
- const now = Date.now();
92
- const record = {
93
- accountId,
94
- conversationId: normalizedConversationId,
95
- parentConversationId: parentConversationId?.trim() || void 0,
96
- deliveryTo: typeof metadata?.deliveryTo === "string" && metadata.deliveryTo.trim() ? metadata.deliveryTo.trim() : void 0,
97
- deliveryThreadId: typeof metadata?.deliveryThreadId === "string" && metadata.deliveryThreadId.trim() ? metadata.deliveryThreadId.trim() : void 0,
98
- targetKind: toFeishuTargetKind(targetKind),
99
- targetSessionKey: targetSessionKey.trim(),
100
- agentId: typeof metadata?.agentId === "string" && metadata.agentId.trim() ? metadata.agentId.trim() : resolveAgentIdFromSessionKey(targetSessionKey),
101
- label: typeof metadata?.label === "string" && metadata.label.trim() ? metadata.label.trim() : void 0,
102
- boundBy: typeof metadata?.boundBy === "string" && metadata.boundBy.trim() ? metadata.boundBy.trim() : void 0,
103
- boundAt: now,
104
- lastActivityAt: now
105
- };
106
- BINDINGS_BY_ACCOUNT_CONVERSATION.set(resolveBindingKey({
107
- accountId,
108
- conversationId: normalizedConversationId
109
- }), record);
110
- return record;
111
- },
112
- touchConversation: (conversationId, at = Date.now()) => {
113
- const key = resolveBindingKey({
114
- accountId,
115
- conversationId
116
- });
117
- const existingRecord = BINDINGS_BY_ACCOUNT_CONVERSATION.get(key);
118
- if (!existingRecord) return null;
119
- const updated = {
120
- ...existingRecord,
121
- lastActivityAt: at
122
- };
123
- BINDINGS_BY_ACCOUNT_CONVERSATION.set(key, updated);
124
- return updated;
125
- },
126
- unbindConversation: (conversationId) => {
127
- const key = resolveBindingKey({
128
- accountId,
129
- conversationId
130
- });
131
- const existingRecord = BINDINGS_BY_ACCOUNT_CONVERSATION.get(key);
132
- if (!existingRecord) return null;
133
- BINDINGS_BY_ACCOUNT_CONVERSATION.delete(key);
134
- return existingRecord;
135
- },
136
- unbindBySessionKey: (targetSessionKey) => {
137
- const removed = [];
138
- for (const record of [...BINDINGS_BY_ACCOUNT_CONVERSATION.values()]) {
139
- if (record.accountId !== accountId || record.targetSessionKey !== targetSessionKey) continue;
140
- BINDINGS_BY_ACCOUNT_CONVERSATION.delete(resolveBindingKey({
141
- accountId,
142
- conversationId: record.conversationId
143
- }));
144
- removed.push(record);
145
- }
146
- return removed;
147
- },
148
- stop: () => {
149
- for (const key of [...BINDINGS_BY_ACCOUNT_CONVERSATION.keys()]) if (key.startsWith(`${accountId}:`)) BINDINGS_BY_ACCOUNT_CONVERSATION.delete(key);
150
- MANAGERS_BY_ACCOUNT_ID.delete(accountId);
151
- unregisterSessionBindingAdapter({
152
- channel: "feishu",
153
- accountId
154
- });
155
- }
156
- };
157
- registerSessionBindingAdapter({
158
- channel: "feishu",
159
- accountId,
160
- capabilities: { placements: ["current"] },
161
- bind: async (input) => {
162
- if (input.conversation.channel !== "feishu" || input.placement === "child") return null;
163
- const bound = manager.bindConversation({
164
- conversationId: input.conversation.conversationId,
165
- parentConversationId: input.conversation.parentConversationId,
166
- targetKind: input.targetKind,
167
- targetSessionKey: input.targetSessionKey,
168
- metadata: input.metadata
169
- });
170
- return bound ? toSessionBindingRecord(bound, {
171
- idleTimeoutMs,
172
- maxAgeMs
173
- }) : null;
174
- },
175
- listBySession: (targetSessionKey) => manager.listBySessionKey(targetSessionKey).map((entry) => toSessionBindingRecord(entry, {
176
- idleTimeoutMs,
177
- maxAgeMs
178
- })),
179
- resolveByConversation: (ref) => {
180
- if (ref.channel !== "feishu") return null;
181
- const found = manager.getByConversationId(ref.conversationId);
182
- return found ? toSessionBindingRecord(found, {
183
- idleTimeoutMs,
184
- maxAgeMs
185
- }) : null;
186
- },
187
- touch: (bindingId, at) => {
188
- const conversationId = resolveThreadBindingConversationIdFromBindingId({
189
- accountId,
190
- bindingId
191
- });
192
- if (conversationId) manager.touchConversation(conversationId, at);
193
- },
194
- unbind: async (input) => {
195
- if (input.targetSessionKey?.trim()) return manager.unbindBySessionKey(input.targetSessionKey.trim()).map((entry) => toSessionBindingRecord(entry, {
196
- idleTimeoutMs,
197
- maxAgeMs
198
- }));
199
- const conversationId = resolveThreadBindingConversationIdFromBindingId({
200
- accountId,
201
- bindingId: input.bindingId
202
- });
203
- if (!conversationId) return [];
204
- const removed = manager.unbindConversation(conversationId);
205
- return removed ? [toSessionBindingRecord(removed, {
206
- idleTimeoutMs,
207
- maxAgeMs
208
- })] : [];
209
- }
210
- });
211
- MANAGERS_BY_ACCOUNT_ID.set(accountId, manager);
212
- return manager;
213
- }
214
- function getFeishuThreadBindingManager(accountId) {
215
- return MANAGERS_BY_ACCOUNT_ID.get(normalizeAccountId(accountId)) ?? null;
216
- }
217
- //#endregion
218
- //#region extensions/feishu/src/dedup.ts
219
- const DEDUP_TTL_MS = 1440 * 60 * 1e3;
220
- const MEMORY_MAX_SIZE = 1e3;
221
- const FILE_MAX_ENTRIES = 1e4;
222
- const EVENT_DEDUP_TTL_MS = 300 * 1e3;
223
- const EVENT_MEMORY_MAX_SIZE = 2e3;
224
- const memoryDedupe = createDedupeCache({
225
- ttlMs: DEDUP_TTL_MS,
226
- maxSize: MEMORY_MAX_SIZE
227
- });
228
- const processingClaims = createDedupeCache({
229
- ttlMs: EVENT_DEDUP_TTL_MS,
230
- maxSize: EVENT_MEMORY_MAX_SIZE
231
- });
232
- function resolveStateDirFromEnv(env = process.env) {
233
- const stateOverride = env.MOLDCLAW_STATE_DIR?.trim() || env.CLAWDBOT_STATE_DIR?.trim();
234
- if (stateOverride) return stateOverride;
235
- if (env.VITEST || env.NODE_ENV === "test") return path.join(os.tmpdir(), ["moldclaw-vitest", String(process.pid)].join("-"));
236
- return path.join(os.homedir(), ".moldclaw");
237
- }
238
- function resolveNamespaceFilePath(namespace) {
239
- const safe = namespace.replace(/[^a-zA-Z0-9_-]/g, "_");
240
- return path.join(resolveStateDirFromEnv(), "feishu", "dedup", `${safe}.json`);
241
- }
242
- const persistentDedupe = createPersistentDedupe({
243
- ttlMs: DEDUP_TTL_MS,
244
- memoryMaxSize: MEMORY_MAX_SIZE,
245
- fileMaxEntries: FILE_MAX_ENTRIES,
246
- resolveFilePath: resolveNamespaceFilePath
247
- });
248
- function resolveEventDedupeKey(namespace, messageId) {
249
- const trimmed = messageId?.trim();
250
- if (!trimmed) return null;
251
- return `${namespace}:${trimmed}`;
252
- }
253
- function normalizeMessageId(messageId) {
254
- const trimmed = messageId?.trim();
255
- return trimmed ? trimmed : null;
256
- }
257
- function resolveMemoryDedupeKey(namespace, messageId) {
258
- const trimmed = normalizeMessageId(messageId);
259
- if (!trimmed) return null;
260
- return `${namespace}:${trimmed}`;
261
- }
262
- function tryBeginFeishuMessageProcessing(messageId, namespace = "global") {
263
- return !processingClaims.check(resolveEventDedupeKey(namespace, messageId));
264
- }
265
- function releaseFeishuMessageProcessing(messageId, namespace = "global") {
266
- processingClaims.delete(resolveEventDedupeKey(namespace, messageId));
267
- }
268
- async function finalizeFeishuMessageProcessing(params) {
269
- const { messageId, namespace = "global", log, claimHeld = false } = params;
270
- const normalizedMessageId = normalizeMessageId(messageId);
271
- const memoryKey = resolveMemoryDedupeKey(namespace, messageId);
272
- if (!memoryKey || !normalizedMessageId) return false;
273
- if (!claimHeld && !tryBeginFeishuMessageProcessing(normalizedMessageId, namespace)) return false;
274
- if (!tryRecordMessage(memoryKey)) {
275
- releaseFeishuMessageProcessing(normalizedMessageId, namespace);
276
- return false;
277
- }
278
- if (!await tryRecordMessagePersistent(normalizedMessageId, namespace, log)) {
279
- releaseFeishuMessageProcessing(normalizedMessageId, namespace);
280
- return false;
281
- }
282
- return true;
283
- }
284
- async function recordProcessedFeishuMessage(messageId, namespace = "global", log) {
285
- const normalizedMessageId = normalizeMessageId(messageId);
286
- const memoryKey = resolveMemoryDedupeKey(namespace, messageId);
287
- if (!memoryKey || !normalizedMessageId) return false;
288
- tryRecordMessage(memoryKey);
289
- return await tryRecordMessagePersistent(normalizedMessageId, namespace, log);
290
- }
291
- async function hasProcessedFeishuMessage(messageId, namespace = "global", log) {
292
- const normalizedMessageId = normalizeMessageId(messageId);
293
- const memoryKey = resolveMemoryDedupeKey(namespace, messageId);
294
- if (!memoryKey || !normalizedMessageId) return false;
295
- if (hasRecordedMessage(memoryKey)) return true;
296
- return hasRecordedMessagePersistent(normalizedMessageId, namespace, log);
297
- }
298
- /**
299
- * Synchronous dedup — memory only.
300
- * Kept for backward compatibility; prefer {@link tryRecordMessagePersistent}.
301
- */
302
- function tryRecordMessage(messageId) {
303
- return !memoryDedupe.check(messageId);
304
- }
305
- function hasRecordedMessage(messageId) {
306
- const trimmed = messageId.trim();
307
- if (!trimmed) return false;
308
- return memoryDedupe.peek(trimmed);
309
- }
310
- async function tryRecordMessagePersistent(messageId, namespace = "global", log) {
311
- return persistentDedupe.checkAndRecord(messageId, {
312
- namespace,
313
- onDiskError: (error) => {
314
- log?.(`feishu-dedup: disk error, falling back to memory: ${String(error)}`);
315
- }
316
- });
317
- }
318
- async function hasRecordedMessagePersistent(messageId, namespace = "global", log) {
319
- const trimmed = messageId.trim();
320
- if (!trimmed) return false;
321
- const now = Date.now();
322
- const filePath = resolveNamespaceFilePath(namespace);
323
- try {
324
- const { value } = await readJsonFileWithFallback(filePath, {});
325
- const seenAt = value[trimmed];
326
- if (typeof seenAt !== "number" || !Number.isFinite(seenAt)) return false;
327
- return DEDUP_TTL_MS <= 0 || now - seenAt < DEDUP_TTL_MS;
328
- } catch (error) {
329
- log?.(`feishu-dedup: persistent peek failed: ${String(error)}`);
330
- return false;
331
- }
332
- }
333
- async function warmupDedupFromDisk(namespace, log) {
334
- return persistentDedupe.warmup(namespace, (error) => {
335
- log?.(`feishu-dedup: warmup disk error: ${String(error)}`);
336
- });
337
- }
338
- //#endregion
339
- //#region extensions/feishu/src/dynamic-agent.ts
340
- /**
341
- * Check if a dynamic agent should be created for a DM user and create it if needed.
342
- * This creates a unique agent instance with its own workspace for each DM user.
343
- */
344
- async function maybeCreateDynamicAgent(params) {
345
- const { cfg, runtime, senderOpenId, dynamicCfg, log } = params;
346
- const existingBindings = cfg.bindings ?? [];
347
- if (existingBindings.some((b) => b.match?.channel === "feishu" && b.match?.peer?.kind === "direct" && b.match?.peer?.id === senderOpenId)) return {
348
- created: false,
349
- updatedCfg: cfg
350
- };
351
- if (dynamicCfg.maxAgents !== void 0) {
352
- if ((cfg.agents?.list ?? []).filter((a) => a.id.startsWith("feishu-")).length >= dynamicCfg.maxAgents) {
353
- log(`feishu: maxAgents limit (${dynamicCfg.maxAgents}) reached, not creating agent for ${senderOpenId}`);
354
- return {
355
- created: false,
356
- updatedCfg: cfg
357
- };
358
- }
359
- }
360
- const agentId = `feishu-${senderOpenId}`;
361
- if ((cfg.agents?.list ?? []).find((a) => a.id === agentId)) {
362
- log(`feishu: agent "${agentId}" exists, adding missing binding for ${senderOpenId}`);
363
- const updatedCfg = {
364
- ...cfg,
365
- bindings: [...existingBindings, {
366
- agentId,
367
- match: {
368
- channel: "feishu",
369
- peer: {
370
- kind: "direct",
371
- id: senderOpenId
372
- }
373
- }
374
- }]
375
- };
376
- await runtime.config.writeConfigFile(updatedCfg);
377
- return {
378
- created: true,
379
- updatedCfg,
380
- agentId
381
- };
382
- }
383
- const workspaceTemplate = dynamicCfg.workspaceTemplate ?? "~/.moldclaw/workspace-{agentId}";
384
- const agentDirTemplate = dynamicCfg.agentDirTemplate ?? "~/.moldclaw/agents/{agentId}/agent";
385
- const workspace = resolveUserPath(workspaceTemplate.replace("{userId}", senderOpenId).replace("{agentId}", agentId));
386
- const agentDir = resolveUserPath(agentDirTemplate.replace("{userId}", senderOpenId).replace("{agentId}", agentId));
387
- log(`feishu: creating dynamic agent "${agentId}" for user ${senderOpenId}`);
388
- log(` workspace: ${workspace}`);
389
- log(` agentDir: ${agentDir}`);
390
- await fs.promises.mkdir(workspace, { recursive: true });
391
- await fs.promises.mkdir(agentDir, { recursive: true });
392
- const updatedCfg = {
393
- ...cfg,
394
- agents: {
395
- ...cfg.agents,
396
- list: [...cfg.agents?.list ?? [], {
397
- id: agentId,
398
- workspace,
399
- agentDir
400
- }]
401
- },
402
- bindings: [...existingBindings, {
403
- agentId,
404
- match: {
405
- channel: "feishu",
406
- peer: {
407
- kind: "direct",
408
- id: senderOpenId
409
- }
410
- }
411
- }]
412
- };
413
- await runtime.config.writeConfigFile(updatedCfg);
414
- return {
415
- created: true,
416
- updatedCfg,
417
- agentId
418
- };
419
- }
420
- /**
421
- * Resolve a path that may start with ~ to the user's home directory.
422
- */
423
- function resolveUserPath(p) {
424
- if (p.startsWith("~/")) return path.join(os.homedir(), p.slice(2));
425
- return p;
426
- }
427
- //#endregion
428
- //#region extensions/feishu/src/streaming-card.ts
429
- const tokenCache = /* @__PURE__ */ new Map();
430
- function resolveApiBase(domain) {
431
- if (domain === "lark") return "https://open.larksuite.com/open-apis";
432
- if (domain && domain !== "feishu" && domain.startsWith("http")) return `${domain.replace(/\/+$/, "")}/open-apis`;
433
- return "https://open.feishu.cn/open-apis";
434
- }
435
- function resolveAllowedHostnames(domain) {
436
- if (domain === "lark") return ["open.larksuite.com"];
437
- if (domain && domain !== "feishu" && domain.startsWith("http")) try {
438
- return [new URL(domain).hostname];
439
- } catch {
440
- return [];
441
- }
442
- return ["open.feishu.cn"];
443
- }
444
- async function getToken(creds) {
445
- const key = `${creds.domain ?? "feishu"}|${creds.appId}`;
446
- const cached = tokenCache.get(key);
447
- if (cached && cached.expiresAt > Date.now() + 6e4) return cached.token;
448
- const { response, release } = await fetchWithSsrFGuard({
449
- url: `${resolveApiBase(creds.domain)}/auth/v3/tenant_access_token/internal`,
450
- init: {
451
- method: "POST",
452
- headers: { "Content-Type": "application/json" },
453
- body: JSON.stringify({
454
- app_id: creds.appId,
455
- app_secret: creds.appSecret
456
- })
457
- },
458
- policy: { allowedHostnames: resolveAllowedHostnames(creds.domain) },
459
- auditContext: "feishu.streaming-card.token"
460
- });
461
- if (!response.ok) {
462
- await release();
463
- throw new Error(`Token request failed with HTTP ${response.status}`);
464
- }
465
- const data = await response.json();
466
- await release();
467
- if (data.code !== 0 || !data.tenant_access_token) throw new Error(`Token error: ${data.msg}`);
468
- tokenCache.set(key, {
469
- token: data.tenant_access_token,
470
- expiresAt: Date.now() + (data.expire ?? 7200) * 1e3
471
- });
472
- return data.tenant_access_token;
473
- }
474
- function truncateSummary(text, max = 50) {
475
- if (!text) return "";
476
- const clean = text.replace(/\n/g, " ").trim();
477
- return clean.length <= max ? clean : clean.slice(0, max - 3) + "...";
478
- }
479
- function mergeStreamingText(previousText, nextText) {
480
- const previous = typeof previousText === "string" ? previousText : "";
481
- const next = typeof nextText === "string" ? nextText : "";
482
- if (!next) return previous;
483
- if (!previous || next === previous) return next;
484
- if (next.startsWith(previous)) return next;
485
- if (previous.startsWith(next)) return previous;
486
- if (next.includes(previous)) return next;
487
- if (previous.includes(next)) return previous;
488
- const maxOverlap = Math.min(previous.length, next.length);
489
- for (let overlap = maxOverlap; overlap > 0; overlap -= 1) if (previous.slice(-overlap) === next.slice(0, overlap)) return `${previous}${next.slice(overlap)}`;
490
- return `${previous}${next}`;
491
- }
492
- function resolveStreamingCardSendMode(options) {
493
- if (options?.replyToMessageId) return "reply";
494
- if (options?.rootId) return "root_create";
495
- return "create";
496
- }
497
- /** Streaming card session manager */
498
- var FeishuStreamingSession = class {
499
- constructor(client, creds, log) {
500
- this.state = null;
501
- this.queue = Promise.resolve();
502
- this.closed = false;
503
- this.lastUpdateTime = 0;
504
- this.pendingText = null;
505
- this.flushTimer = null;
506
- this.updateThrottleMs = 100;
507
- this.client = client;
508
- this.creds = creds;
509
- this.log = log;
510
- }
511
- async start(receiveId, receiveIdType = "chat_id", options) {
512
- if (this.state) return;
513
- const apiBase = resolveApiBase(this.creds.domain);
514
- const elements = [{
515
- tag: "markdown",
516
- content: "⏳ Thinking...",
517
- element_id: "content"
518
- }];
519
- if (options?.note) {
520
- elements.push({ tag: "hr" });
521
- elements.push({
522
- tag: "markdown",
523
- content: `<font color='grey'>${options.note}</font>`,
524
- element_id: "note"
525
- });
526
- }
527
- const cardJson = {
528
- schema: "2.0",
529
- config: {
530
- streaming_mode: true,
531
- summary: { content: "[Generating...]" },
532
- streaming_config: {
533
- print_frequency_ms: { default: 50 },
534
- print_step: { default: 1 }
535
- }
536
- },
537
- body: { elements }
538
- };
539
- if (options?.header) cardJson.header = {
540
- title: {
541
- tag: "plain_text",
542
- content: options.header.title
543
- },
544
- template: resolveFeishuCardTemplate(options.header.template) ?? "blue"
545
- };
546
- const { response: createRes, release: releaseCreate } = await fetchWithSsrFGuard({
547
- url: `${apiBase}/cardkit/v1/cards`,
548
- init: {
549
- method: "POST",
550
- headers: {
551
- Authorization: `Bearer ${await getToken(this.creds)}`,
552
- "Content-Type": "application/json"
553
- },
554
- body: JSON.stringify({
555
- type: "card_json",
556
- data: JSON.stringify(cardJson)
557
- })
558
- },
559
- policy: { allowedHostnames: resolveAllowedHostnames(this.creds.domain) },
560
- auditContext: "feishu.streaming-card.create"
561
- });
562
- if (!createRes.ok) {
563
- await releaseCreate();
564
- throw new Error(`Create card request failed with HTTP ${createRes.status}`);
565
- }
566
- const createData = await createRes.json();
567
- await releaseCreate();
568
- if (createData.code !== 0 || !createData.data?.card_id) throw new Error(`Create card failed: ${createData.msg}`);
569
- const cardId = createData.data.card_id;
570
- const cardContent = JSON.stringify({
571
- type: "card",
572
- data: { card_id: cardId }
573
- });
574
- let sendRes;
575
- const sendOptions = options ?? {};
576
- const sendMode = resolveStreamingCardSendMode(sendOptions);
577
- if (sendMode === "reply") sendRes = await this.client.im.message.reply({
578
- path: { message_id: sendOptions.replyToMessageId },
579
- data: {
580
- msg_type: "interactive",
581
- content: cardContent,
582
- ...sendOptions.replyInThread ? { reply_in_thread: true } : {}
583
- }
584
- });
585
- else if (sendMode === "root_create") sendRes = await this.client.im.message.create({
586
- params: { receive_id_type: receiveIdType },
587
- data: Object.assign({
588
- receive_id: receiveId,
589
- msg_type: "interactive",
590
- content: cardContent
591
- }, { root_id: sendOptions.rootId })
592
- });
593
- else sendRes = await this.client.im.message.create({
594
- params: { receive_id_type: receiveIdType },
595
- data: {
596
- receive_id: receiveId,
597
- msg_type: "interactive",
598
- content: cardContent
599
- }
600
- });
601
- if (sendRes.code !== 0 || !sendRes.data?.message_id) throw new Error(`Send card failed: ${sendRes.msg}`);
602
- this.state = {
603
- cardId,
604
- messageId: sendRes.data.message_id,
605
- sequence: 1,
606
- currentText: "",
607
- hasNote: !!options?.note
608
- };
609
- this.log?.(`Started streaming: cardId=${cardId}, messageId=${sendRes.data.message_id}`);
610
- }
611
- async updateCardContent(text, onError) {
612
- if (!this.state) return;
613
- const apiBase = resolveApiBase(this.creds.domain);
614
- this.state.sequence += 1;
615
- await fetchWithSsrFGuard({
616
- url: `${apiBase}/cardkit/v1/cards/${this.state.cardId}/elements/content/content`,
617
- init: {
618
- method: "PUT",
619
- headers: {
620
- Authorization: `Bearer ${await getToken(this.creds)}`,
621
- "Content-Type": "application/json"
622
- },
623
- body: JSON.stringify({
624
- content: text,
625
- sequence: this.state.sequence,
626
- uuid: `s_${this.state.cardId}_${this.state.sequence}`
627
- })
628
- },
629
- policy: { allowedHostnames: resolveAllowedHostnames(this.creds.domain) },
630
- auditContext: "feishu.streaming-card.update"
631
- }).then(async ({ release }) => {
632
- await release();
633
- }).catch((error) => onError?.(error));
634
- }
635
- async update(text) {
636
- if (!this.state || this.closed) return;
637
- const mergedInput = mergeStreamingText(this.pendingText ?? this.state.currentText, text);
638
- if (!mergedInput || mergedInput === this.state.currentText) return;
639
- const now = Date.now();
640
- if (now - this.lastUpdateTime < this.updateThrottleMs) {
641
- this.pendingText = mergedInput;
642
- return;
643
- }
644
- this.pendingText = null;
645
- this.lastUpdateTime = now;
646
- if (this.flushTimer) {
647
- clearTimeout(this.flushTimer);
648
- this.flushTimer = null;
649
- }
650
- this.queue = this.queue.then(async () => {
651
- if (!this.state || this.closed) return;
652
- const mergedText = mergeStreamingText(this.state.currentText, mergedInput);
653
- if (!mergedText || mergedText === this.state.currentText) return;
654
- this.state.currentText = mergedText;
655
- await this.updateCardContent(mergedText, (e) => this.log?.(`Update failed: ${String(e)}`));
656
- });
657
- await this.queue;
658
- }
659
- async updateNoteContent(note) {
660
- if (!this.state || !this.state.hasNote) return;
661
- const apiBase = resolveApiBase(this.creds.domain);
662
- this.state.sequence += 1;
663
- await fetchWithSsrFGuard({
664
- url: `${apiBase}/cardkit/v1/cards/${this.state.cardId}/elements/note/content`,
665
- init: {
666
- method: "PUT",
667
- headers: {
668
- Authorization: `Bearer ${await getToken(this.creds)}`,
669
- "Content-Type": "application/json"
670
- },
671
- body: JSON.stringify({
672
- content: `<font color='grey'>${note}</font>`,
673
- sequence: this.state.sequence,
674
- uuid: `n_${this.state.cardId}_${this.state.sequence}`
675
- })
676
- },
677
- policy: { allowedHostnames: resolveAllowedHostnames(this.creds.domain) },
678
- auditContext: "feishu.streaming-card.note-update"
679
- }).then(async ({ release }) => {
680
- await release();
681
- }).catch((e) => this.log?.(`Note update failed: ${String(e)}`));
682
- }
683
- async close(finalText, options) {
684
- if (!this.state || this.closed) return;
685
- this.closed = true;
686
- if (this.flushTimer) {
687
- clearTimeout(this.flushTimer);
688
- this.flushTimer = null;
689
- }
690
- await this.queue;
691
- const pendingMerged = mergeStreamingText(this.state.currentText, this.pendingText ?? void 0);
692
- const text = finalText ? mergeStreamingText(pendingMerged, finalText) : pendingMerged;
693
- const apiBase = resolveApiBase(this.creds.domain);
694
- if (text && text !== this.state.currentText) {
695
- await this.updateCardContent(text);
696
- this.state.currentText = text;
697
- }
698
- if (options?.note) await this.updateNoteContent(options.note);
699
- this.state.sequence += 1;
700
- await fetchWithSsrFGuard({
701
- url: `${apiBase}/cardkit/v1/cards/${this.state.cardId}/settings`,
702
- init: {
703
- method: "PATCH",
704
- headers: {
705
- Authorization: `Bearer ${await getToken(this.creds)}`,
706
- "Content-Type": "application/json; charset=utf-8"
707
- },
708
- body: JSON.stringify({
709
- settings: JSON.stringify({ config: {
710
- streaming_mode: false,
711
- summary: { content: truncateSummary(text) }
712
- } }),
713
- sequence: this.state.sequence,
714
- uuid: `c_${this.state.cardId}_${this.state.sequence}`
715
- })
716
- },
717
- policy: { allowedHostnames: resolveAllowedHostnames(this.creds.domain) },
718
- auditContext: "feishu.streaming-card.close"
719
- }).then(async ({ release }) => {
720
- await release();
721
- }).catch((e) => this.log?.(`Close failed: ${String(e)}`));
722
- const finalState = this.state;
723
- this.state = null;
724
- this.pendingText = null;
725
- this.log?.(`Closed streaming: cardId=${finalState.cardId}`);
726
- }
727
- isActive() {
728
- return this.state !== null && !this.closed;
729
- }
730
- };
731
- //#endregion
732
- //#region extensions/feishu/src/typing.ts
733
- const TYPING_EMOJI = "Typing";
734
- /**
735
- * Feishu API error codes that indicate the caller should back off.
736
- * These must propagate to the typing circuit breaker so the keepalive loop
737
- * can trip and stop retrying.
738
- *
739
- * - 99991400: Rate limit (too many requests per second)
740
- * - 99991403: Monthly API call quota exceeded
741
- * - 429: Standard HTTP 429 returned as a Feishu SDK error code
742
- *
743
- * @see https://open.feishu.cn/document/server-docs/api-call-guide/generic-error-code
744
- */
745
- const FEISHU_BACKOFF_CODES = new Set([
746
- 99991400,
747
- 99991403,
748
- 429
749
- ]);
750
- /**
751
- * Custom error class for Feishu backoff conditions detected from non-throwing
752
- * SDK responses. Carries a numeric `.code` so that `isFeishuBackoffError()`
753
- * recognises it when the error is caught downstream.
754
- */
755
- var FeishuBackoffError = class extends Error {
756
- constructor(code) {
757
- super(`Feishu API backoff: code ${code}`);
758
- this.name = "FeishuBackoffError";
759
- this.code = code;
760
- }
761
- };
762
- /**
763
- * Check whether an error represents a rate-limit or quota-exceeded condition
764
- * from the Feishu API that should stop the typing keepalive loop.
765
- *
766
- * Handles two shapes:
767
- * 1. AxiosError with `response.status` and `response.data.code`
768
- * 2. Feishu SDK error with a top-level `code` property
769
- */
770
- function isFeishuBackoffError(err) {
771
- if (typeof err !== "object" || err === null) return false;
772
- const response = err.response;
773
- if (response) {
774
- if (response.status === 429) return true;
775
- if (typeof response.data?.code === "number" && FEISHU_BACKOFF_CODES.has(response.data.code)) return true;
776
- }
777
- const code = err.code;
778
- if (typeof code === "number" && FEISHU_BACKOFF_CODES.has(code)) return true;
779
- return false;
780
- }
781
- /**
782
- * Check whether a Feishu SDK response object contains a backoff error code.
783
- *
784
- * The Feishu SDK sometimes returns a normal response (no throw) with an
785
- * API-level error code in the response body. This must be detected so the
786
- * circuit breaker can trip. See codex review on #28157.
787
- */
788
- function getBackoffCodeFromResponse(response) {
789
- if (typeof response !== "object" || response === null) return;
790
- const code = response.code;
791
- if (typeof code === "number" && FEISHU_BACKOFF_CODES.has(code)) return code;
792
- }
793
- /**
794
- * Add a typing indicator (reaction) to a message.
795
- *
796
- * Rate-limit and quota errors are re-thrown so the circuit breaker in
797
- * `createTypingCallbacks` (typing-start-guard) can trip and stop the
798
- * keepalive loop. See #28062.
799
- *
800
- * Also checks for backoff codes in non-throwing SDK responses (#28157).
801
- */
802
- async function addTypingIndicator(params) {
803
- const { cfg, messageId, accountId, runtime } = params;
804
- const account = resolveFeishuAccount({
805
- cfg,
806
- accountId
807
- });
808
- if (!account.configured) return {
809
- messageId,
810
- reactionId: null
811
- };
812
- const client = createFeishuClient(account);
813
- try {
814
- const response = await client.im.messageReaction.create({
815
- path: { message_id: messageId },
816
- data: { reaction_type: { emoji_type: TYPING_EMOJI } }
817
- });
818
- const backoffCode = getBackoffCodeFromResponse(response);
819
- if (backoffCode !== void 0) {
820
- if (getFeishuRuntime().logging.shouldLogVerbose()) runtime?.log?.(`[feishu] typing indicator response contains backoff code ${backoffCode}, stopping keepalive`);
821
- throw new FeishuBackoffError(backoffCode);
822
- }
823
- return {
824
- messageId,
825
- reactionId: response?.data?.reaction_id ?? null
826
- };
827
- } catch (err) {
828
- if (isFeishuBackoffError(err)) {
829
- if (getFeishuRuntime().logging.shouldLogVerbose()) runtime?.log?.("[feishu] typing indicator hit rate-limit/quota, stopping keepalive");
830
- throw err;
831
- }
832
- if (getFeishuRuntime().logging.shouldLogVerbose()) runtime?.log?.(`[feishu] failed to add typing indicator: ${String(err)}`);
833
- return {
834
- messageId,
835
- reactionId: null
836
- };
837
- }
838
- }
839
- /**
840
- * Remove a typing indicator (reaction) from a message.
841
- *
842
- * Rate-limit and quota errors are re-thrown for the same reason as above.
843
- */
844
- async function removeTypingIndicator(params) {
845
- const { cfg, state, accountId, runtime } = params;
846
- if (!state.reactionId) return;
847
- const account = resolveFeishuAccount({
848
- cfg,
849
- accountId
850
- });
851
- if (!account.configured) return;
852
- const client = createFeishuClient(account);
853
- try {
854
- const backoffCode = getBackoffCodeFromResponse(await client.im.messageReaction.delete({ path: {
855
- message_id: state.messageId,
856
- reaction_id: state.reactionId
857
- } }));
858
- if (backoffCode !== void 0) {
859
- if (getFeishuRuntime().logging.shouldLogVerbose()) runtime?.log?.(`[feishu] typing indicator removal response contains backoff code ${backoffCode}, stopping keepalive`);
860
- throw new FeishuBackoffError(backoffCode);
861
- }
862
- } catch (err) {
863
- if (isFeishuBackoffError(err)) {
864
- if (getFeishuRuntime().logging.shouldLogVerbose()) runtime?.log?.("[feishu] typing indicator removal hit rate-limit/quota, stopping keepalive");
865
- throw err;
866
- }
867
- if (getFeishuRuntime().logging.shouldLogVerbose()) runtime?.log?.(`[feishu] failed to remove typing indicator: ${String(err)}`);
868
- }
869
- }
870
- //#endregion
871
- //#region extensions/feishu/src/reply-dispatcher.ts
872
- /** Detect if text contains markdown elements that benefit from card rendering */
873
- function shouldUseCard(text) {
874
- return /```[\s\S]*?```/.test(text) || /\|.+\|[\r\n]+\|[-:| ]+\|/.test(text);
875
- }
876
- /** Maximum age (ms) for a message to receive a typing indicator reaction.
877
- * Messages older than this are likely replays after context compaction (#30418). */
878
- const TYPING_INDICATOR_MAX_AGE_MS = 2 * 6e4;
879
- const MS_EPOCH_MIN = 0xe8d4a51000;
880
- function normalizeEpochMs(timestamp) {
881
- if (!Number.isFinite(timestamp) || timestamp === void 0 || timestamp <= 0) return;
882
- return timestamp < MS_EPOCH_MIN ? timestamp * 1e3 : timestamp;
883
- }
884
- /** Build a card header from agent identity config. */
885
- function resolveCardHeader(agentId, identity) {
886
- const name = identity?.name?.trim() || agentId;
887
- const emoji = identity?.emoji?.trim();
888
- return {
889
- title: emoji ? `${emoji} ${name}` : name,
890
- template: identity?.theme ?? "blue"
891
- };
892
- }
893
- /** Build a card note footer from agent identity and model context. */
894
- function resolveCardNote(agentId, identity, prefixCtx) {
895
- const parts = [`Agent: ${identity?.name?.trim() || agentId}`];
896
- if (prefixCtx.model) parts.push(`Model: ${prefixCtx.model}`);
897
- if (prefixCtx.provider) parts.push(`Provider: ${prefixCtx.provider}`);
898
- return parts.join(" | ");
899
- }
900
- function createFeishuReplyDispatcher(params) {
901
- const core = getFeishuRuntime();
902
- const { cfg, agentId, chatId, replyToMessageId, skipReplyToInMessages, replyInThread, threadReply, rootId, mentionTargets, accountId, identity } = params;
903
- const sendReplyToMessageId = skipReplyToInMessages ? void 0 : replyToMessageId;
904
- const threadReplyMode = threadReply === true;
905
- const effectiveReplyInThread = threadReplyMode ? true : replyInThread;
906
- const account = resolveFeishuAccount({
907
- cfg,
908
- accountId
909
- });
910
- const prefixContext = createReplyPrefixContext({
911
- cfg,
912
- agentId
913
- });
914
- let typingState = null;
915
- const typingCallbacks = createTypingCallbacks({
916
- start: async () => {
917
- if (!(account.config.typingIndicator ?? true)) return;
918
- if (!replyToMessageId) return;
919
- const messageCreateTimeMs = normalizeEpochMs(params.messageCreateTimeMs);
920
- if (messageCreateTimeMs !== void 0 && Date.now() - messageCreateTimeMs > TYPING_INDICATOR_MAX_AGE_MS) return;
921
- if (typingState?.reactionId) return;
922
- typingState = await addTypingIndicator({
923
- cfg,
924
- messageId: replyToMessageId,
925
- accountId,
926
- runtime: params.runtime
927
- });
928
- },
929
- stop: async () => {
930
- if (!typingState) return;
931
- await removeTypingIndicator({
932
- cfg,
933
- state: typingState,
934
- accountId,
935
- runtime: params.runtime
936
- });
937
- typingState = null;
938
- },
939
- onStartError: (err) => logTypingFailure({
940
- log: (message) => params.runtime.log?.(message),
941
- channel: "feishu",
942
- action: "start",
943
- error: err
944
- }),
945
- onStopError: (err) => logTypingFailure({
946
- log: (message) => params.runtime.log?.(message),
947
- channel: "feishu",
948
- action: "stop",
949
- error: err
950
- })
951
- });
952
- const textChunkLimit = core.channel.text.resolveTextChunkLimit(cfg, "feishu", accountId, { fallbackLimit: 4e3 });
953
- const chunkMode = core.channel.text.resolveChunkMode(cfg, "feishu");
954
- const tableMode = core.channel.text.resolveMarkdownTableMode({
955
- cfg,
956
- channel: "feishu"
957
- });
958
- const renderMode = account.config?.renderMode ?? "auto";
959
- const streamingEnabled = !threadReplyMode && account.config?.streaming !== false && renderMode !== "raw";
960
- let streaming = null;
961
- let streamText = "";
962
- let lastPartial = "";
963
- let reasoningText = "";
964
- const deliveredFinalTexts = /* @__PURE__ */ new Set();
965
- let partialUpdateQueue = Promise.resolve();
966
- let streamingStartPromise = null;
967
- const formatReasoningPrefix = (thinking) => {
968
- if (!thinking) return "";
969
- return `> 💭 **Thinking**\n${thinking.replace(/^Reasoning:\n/, "").replace(/^_(.*)_$/gm, "$1").split("\n").map((line) => `> ${line}`).join("\n")}`;
970
- };
971
- const buildCombinedStreamText = (thinking, answer) => {
972
- const parts = [];
973
- if (thinking) parts.push(formatReasoningPrefix(thinking));
974
- if (thinking && answer) parts.push("\n\n---\n\n");
975
- if (answer) parts.push(answer);
976
- return parts.join("");
977
- };
978
- const flushStreamingCardUpdate = (combined) => {
979
- partialUpdateQueue = partialUpdateQueue.then(async () => {
980
- if (streamingStartPromise) await streamingStartPromise;
981
- if (streaming?.isActive()) await streaming.update(combined);
982
- });
983
- };
984
- const queueStreamingUpdate = (nextText, options) => {
985
- if (!nextText) return;
986
- if (options?.dedupeWithLastPartial && nextText === lastPartial) return;
987
- if (options?.dedupeWithLastPartial) lastPartial = nextText;
988
- streamText = (options?.mode ?? "snapshot") === "delta" ? `${streamText}${nextText}` : mergeStreamingText(streamText, nextText);
989
- flushStreamingCardUpdate(buildCombinedStreamText(reasoningText, streamText));
990
- };
991
- const queueReasoningUpdate = (nextThinking) => {
992
- if (!nextThinking) return;
993
- reasoningText = nextThinking;
994
- flushStreamingCardUpdate(buildCombinedStreamText(reasoningText, streamText));
995
- };
996
- const startStreaming = () => {
997
- if (!streamingEnabled || streamingStartPromise || streaming) return;
998
- streamingStartPromise = (async () => {
999
- const creds = account.appId && account.appSecret ? {
1000
- appId: account.appId,
1001
- appSecret: account.appSecret,
1002
- domain: account.domain
1003
- } : null;
1004
- if (!creds) return;
1005
- streaming = new FeishuStreamingSession(createFeishuClient(account), creds, (message) => params.runtime.log?.(`feishu[${account.accountId}] ${message}`));
1006
- try {
1007
- const cardHeader = resolveCardHeader(agentId, identity);
1008
- const cardNote = resolveCardNote(agentId, identity, prefixContext.prefixContext);
1009
- await streaming.start(chatId, resolveReceiveIdType(chatId), {
1010
- replyToMessageId,
1011
- replyInThread: effectiveReplyInThread,
1012
- rootId,
1013
- header: cardHeader,
1014
- note: cardNote
1015
- });
1016
- } catch (error) {
1017
- params.runtime.error?.(`feishu: streaming start failed: ${String(error)}`);
1018
- streaming = null;
1019
- streamingStartPromise = null;
1020
- }
1021
- })();
1022
- };
1023
- const closeStreaming = async () => {
1024
- if (streamingStartPromise) await streamingStartPromise;
1025
- await partialUpdateQueue;
1026
- if (streaming?.isActive()) {
1027
- let text = buildCombinedStreamText(reasoningText, streamText);
1028
- if (mentionTargets?.length) text = buildMentionedCardContent(mentionTargets, text);
1029
- const finalNote = resolveCardNote(agentId, identity, prefixContext.prefixContext);
1030
- await streaming.close(text, { note: finalNote });
1031
- }
1032
- streaming = null;
1033
- streamingStartPromise = null;
1034
- streamText = "";
1035
- lastPartial = "";
1036
- reasoningText = "";
1037
- };
1038
- const sendChunkedTextReply = async (params) => {
1039
- let first = true;
1040
- const chunkSource = params.useCard ? params.text : core.channel.text.convertMarkdownTables(params.text, tableMode);
1041
- for (const chunk of core.channel.text.chunkTextWithMode(chunkSource, textChunkLimit, chunkMode)) {
1042
- const message = {
1043
- cfg,
1044
- to: chatId,
1045
- text: chunk,
1046
- replyToMessageId: sendReplyToMessageId,
1047
- replyInThread: effectiveReplyInThread,
1048
- mentions: first ? mentionTargets : void 0,
1049
- accountId
1050
- };
1051
- if (params.useCard) await sendMarkdownCardFeishu(message);
1052
- else await sendMessageFeishu(message);
1053
- first = false;
1054
- }
1055
- if (params.infoKind === "final") deliveredFinalTexts.add(params.text);
1056
- };
1057
- const { dispatcher, replyOptions, markDispatchIdle } = core.channel.reply.createReplyDispatcherWithTyping({
1058
- responsePrefix: prefixContext.responsePrefix,
1059
- responsePrefixContextProvider: prefixContext.responsePrefixContextProvider,
1060
- humanDelay: core.channel.reply.resolveHumanDelayConfig(cfg, agentId),
1061
- onReplyStart: () => {
1062
- deliveredFinalTexts.clear();
1063
- if (streamingEnabled && renderMode === "card") startStreaming();
1064
- typingCallbacks.onReplyStart?.();
1065
- },
1066
- deliver: async (payload, info) => {
1067
- const text = payload.text ?? "";
1068
- const mediaList = payload.mediaUrls && payload.mediaUrls.length > 0 ? payload.mediaUrls : payload.mediaUrl ? [payload.mediaUrl] : [];
1069
- const hasText = Boolean(text.trim());
1070
- const hasMedia = mediaList.length > 0;
1071
- const skipTextForDuplicateFinal = info?.kind === "final" && hasText && deliveredFinalTexts.has(text);
1072
- const shouldDeliverText = hasText && !skipTextForDuplicateFinal;
1073
- if (!shouldDeliverText && !hasMedia) return;
1074
- if (shouldDeliverText) {
1075
- const useCard = renderMode === "card" || renderMode === "auto" && shouldUseCard(text);
1076
- let first = true;
1077
- if (info?.kind === "block") {
1078
- if (!(streamingEnabled && useCard)) return;
1079
- startStreaming();
1080
- if (streamingStartPromise) await streamingStartPromise;
1081
- }
1082
- if (info?.kind === "final" && streamingEnabled && useCard) {
1083
- startStreaming();
1084
- if (streamingStartPromise) await streamingStartPromise;
1085
- }
1086
- if (streaming?.isActive()) {
1087
- if (info?.kind === "block") queueStreamingUpdate(text, { mode: "delta" });
1088
- if (info?.kind === "final") {
1089
- streamText = mergeStreamingText(streamText, text);
1090
- await closeStreaming();
1091
- deliveredFinalTexts.add(text);
1092
- }
1093
- if (hasMedia) for (const mediaUrl of mediaList) await sendMediaFeishu({
1094
- cfg,
1095
- to: chatId,
1096
- mediaUrl,
1097
- replyToMessageId: sendReplyToMessageId,
1098
- replyInThread: effectiveReplyInThread,
1099
- accountId
1100
- });
1101
- return;
1102
- }
1103
- if (useCard) {
1104
- const cardHeader = resolveCardHeader(agentId, identity);
1105
- const cardNote = resolveCardNote(agentId, identity, prefixContext.prefixContext);
1106
- for (const chunk of core.channel.text.chunkTextWithMode(text, textChunkLimit, chunkMode)) {
1107
- await sendStructuredCardFeishu({
1108
- cfg,
1109
- to: chatId,
1110
- text: chunk,
1111
- replyToMessageId: sendReplyToMessageId,
1112
- replyInThread: effectiveReplyInThread,
1113
- mentions: first ? mentionTargets : void 0,
1114
- accountId,
1115
- header: cardHeader,
1116
- note: cardNote
1117
- });
1118
- first = false;
1119
- }
1120
- if (info?.kind === "final") deliveredFinalTexts.add(text);
1121
- } else await sendChunkedTextReply({
1122
- text,
1123
- useCard: false,
1124
- infoKind: info?.kind
1125
- });
1126
- }
1127
- if (hasMedia) for (const mediaUrl of mediaList) await sendMediaFeishu({
1128
- cfg,
1129
- to: chatId,
1130
- mediaUrl,
1131
- replyToMessageId: sendReplyToMessageId,
1132
- replyInThread: effectiveReplyInThread,
1133
- accountId
1134
- });
1135
- },
1136
- onError: async (error, info) => {
1137
- params.runtime.error?.(`feishu[${account.accountId}] ${info.kind} reply failed: ${String(error)}`);
1138
- await closeStreaming();
1139
- typingCallbacks.onIdle?.();
1140
- },
1141
- onIdle: async () => {
1142
- await closeStreaming();
1143
- typingCallbacks.onIdle?.();
1144
- },
1145
- onCleanup: () => {
1146
- typingCallbacks.onCleanup?.();
1147
- }
1148
- });
1149
- return {
1150
- dispatcher,
1151
- replyOptions: {
1152
- ...replyOptions,
1153
- onModelSelected: prefixContext.onModelSelected,
1154
- disableBlockStreaming: true,
1155
- onPartialReply: streamingEnabled ? (payload) => {
1156
- if (!payload.text) return;
1157
- queueStreamingUpdate(payload.text, {
1158
- dedupeWithLastPartial: true,
1159
- mode: "snapshot"
1160
- });
1161
- } : void 0,
1162
- onReasoningStream: streamingEnabled ? (payload) => {
1163
- if (!payload.text) return;
1164
- startStreaming();
1165
- queueReasoningUpdate(payload.text);
1166
- } : void 0,
1167
- onReasoningEnd: streamingEnabled ? () => {} : void 0
1168
- },
1169
- markDispatchIdle
1170
- };
1171
- }
1172
- //#endregion
1173
- //#region extensions/feishu/src/bot.ts
1174
- const IGNORED_PERMISSION_SCOPE_TOKENS = ["contact:contact.base:readonly"];
1175
- const FEISHU_SCOPE_CORRECTIONS = { "contact:contact.base:readonly": "contact:user.base:readonly" };
1176
- function correctFeishuScopeInUrl(url) {
1177
- let corrected = url;
1178
- for (const [wrong, right] of Object.entries(FEISHU_SCOPE_CORRECTIONS)) {
1179
- corrected = corrected.replaceAll(encodeURIComponent(wrong), encodeURIComponent(right));
1180
- corrected = corrected.replaceAll(wrong, right);
1181
- }
1182
- return corrected;
1183
- }
1184
- function shouldSuppressPermissionErrorNotice(permissionError) {
1185
- const message = permissionError.message.toLowerCase();
1186
- return IGNORED_PERMISSION_SCOPE_TOKENS.some((token) => message.includes(token));
1187
- }
1188
- function extractPermissionError(err) {
1189
- if (!err || typeof err !== "object") return null;
1190
- const data = err.response?.data;
1191
- if (!data || typeof data !== "object") return null;
1192
- const feishuErr = data;
1193
- if (feishuErr.code !== 99991672) return null;
1194
- const msg = feishuErr.msg ?? "";
1195
- const urlMatch = msg.match(/https:\/\/[^\s,]+\/app\/[^\s,]+/);
1196
- const grantUrl = urlMatch?.[0] ? correctFeishuScopeInUrl(urlMatch[0]) : void 0;
1197
- return {
1198
- code: feishuErr.code,
1199
- message: msg,
1200
- grantUrl
1201
- };
1202
- }
1203
- const SENDER_NAME_TTL_MS = 600 * 1e3;
1204
- const senderNameCache = /* @__PURE__ */ new Map();
1205
- const permissionErrorNotifiedAt = /* @__PURE__ */ new Map();
1206
- const PERMISSION_ERROR_COOLDOWN_MS = 300 * 1e3;
1207
- function resolveSenderLookupIdType(senderId) {
1208
- const trimmed = senderId.trim();
1209
- if (trimmed.startsWith("ou_")) return "open_id";
1210
- if (trimmed.startsWith("on_")) return "union_id";
1211
- return "user_id";
1212
- }
1213
- async function resolveFeishuSenderName(params) {
1214
- const { account, senderId, log } = params;
1215
- if (!account.configured) return {};
1216
- const normalizedSenderId = senderId.trim();
1217
- if (!normalizedSenderId) return {};
1218
- const cached = senderNameCache.get(normalizedSenderId);
1219
- const now = Date.now();
1220
- if (cached && cached.expireAt > now) return { name: cached.name };
1221
- try {
1222
- const client = createFeishuClient(account);
1223
- const userIdType = resolveSenderLookupIdType(normalizedSenderId);
1224
- const res = await client.contact.user.get({
1225
- path: { user_id: normalizedSenderId },
1226
- params: { user_id_type: userIdType }
1227
- });
1228
- const name = res?.data?.user?.name || res?.data?.user?.display_name || res?.data?.user?.nickname || res?.data?.user?.en_name;
1229
- if (name && typeof name === "string") {
1230
- senderNameCache.set(normalizedSenderId, {
1231
- name,
1232
- expireAt: now + SENDER_NAME_TTL_MS
1233
- });
1234
- return { name };
1235
- }
1236
- return {};
1237
- } catch (err) {
1238
- const permErr = extractPermissionError(err);
1239
- if (permErr) {
1240
- if (shouldSuppressPermissionErrorNotice(permErr)) {
1241
- log(`feishu: ignoring stale permission scope error: ${permErr.message}`);
1242
- return {};
1243
- }
1244
- log(`feishu: permission error resolving sender name: code=${permErr.code}`);
1245
- return { permissionError: permErr };
1246
- }
1247
- log(`feishu: failed to resolve sender name for ${normalizedSenderId}: ${String(err)}`);
1248
- return {};
1249
- }
1250
- }
1251
- function resolveFeishuGroupSession(params) {
1252
- const { chatId, senderOpenId, messageId, rootId, threadId, groupConfig, feishuCfg } = params;
1253
- const normalizedThreadId = threadId?.trim();
1254
- const normalizedRootId = rootId?.trim();
1255
- const threadReply = Boolean(normalizedThreadId || normalizedRootId);
1256
- const replyInThread = (groupConfig?.replyInThread ?? feishuCfg?.replyInThread ?? "disabled") === "enabled" || threadReply;
1257
- const legacyTopicSessionMode = groupConfig?.topicSessionMode ?? feishuCfg?.topicSessionMode ?? "disabled";
1258
- const groupSessionScope = groupConfig?.groupSessionScope ?? feishuCfg?.groupSessionScope ?? (legacyTopicSessionMode === "enabled" ? "group_topic" : "group");
1259
- const topicScope = groupSessionScope === "group_topic" || groupSessionScope === "group_topic_sender" ? normalizedRootId ?? normalizedThreadId ?? (replyInThread ? messageId : null) : null;
1260
- let peerId = chatId;
1261
- switch (groupSessionScope) {
1262
- case "group_sender":
1263
- peerId = buildFeishuConversationId({
1264
- chatId,
1265
- scope: "group_sender",
1266
- senderOpenId
1267
- });
1268
- break;
1269
- case "group_topic":
1270
- peerId = topicScope ? buildFeishuConversationId({
1271
- chatId,
1272
- scope: "group_topic",
1273
- topicId: topicScope
1274
- }) : chatId;
1275
- break;
1276
- case "group_topic_sender":
1277
- peerId = topicScope ? buildFeishuConversationId({
1278
- chatId,
1279
- scope: "group_topic_sender",
1280
- topicId: topicScope,
1281
- senderOpenId
1282
- }) : buildFeishuConversationId({
1283
- chatId,
1284
- scope: "group_sender",
1285
- senderOpenId
1286
- });
1287
- break;
1288
- default:
1289
- peerId = chatId;
1290
- break;
1291
- }
1292
- return {
1293
- peerId,
1294
- parentPeer: topicScope && (groupSessionScope === "group_topic" || groupSessionScope === "group_topic_sender") ? {
1295
- kind: "group",
1296
- id: chatId
1297
- } : null,
1298
- groupSessionScope,
1299
- replyInThread,
1300
- threadReply
1301
- };
1302
- }
1303
- function parseMessageContent(content, messageType) {
1304
- if (messageType === "post") {
1305
- const { textContent } = parsePostContent(content);
1306
- return textContent;
1307
- }
1308
- try {
1309
- const parsed = JSON.parse(content);
1310
- if (messageType === "text") return parsed.text || "";
1311
- if (messageType === "share_chat") {
1312
- if (parsed && typeof parsed === "object") {
1313
- const share = parsed;
1314
- if (typeof share.body === "string" && share.body.trim().length > 0) return share.body.trim();
1315
- if (typeof share.summary === "string" && share.summary.trim().length > 0) return share.summary.trim();
1316
- if (typeof share.share_chat_id === "string" && share.share_chat_id.trim().length > 0) return `[Forwarded message: ${share.share_chat_id.trim()}]`;
1317
- }
1318
- return "[Forwarded message]";
1319
- }
1320
- if (messageType === "merge_forward") return "[Merged and Forwarded Message - loading...]";
1321
- return content;
1322
- } catch {
1323
- return content;
1324
- }
1325
- }
1326
- /**
1327
- * Parse merge_forward message content and fetch sub-messages.
1328
- * Returns formatted text content of all sub-messages.
1329
- */
1330
- function parseMergeForwardContent(params) {
1331
- const { content, log } = params;
1332
- const maxMessages = 50;
1333
- log?.(`feishu: parsing merge_forward sub-messages from API response`);
1334
- let items;
1335
- try {
1336
- items = JSON.parse(content);
1337
- } catch {
1338
- log?.(`feishu: merge_forward items parse failed`);
1339
- return "[Merged and Forwarded Message - parse error]";
1340
- }
1341
- if (!Array.isArray(items) || items.length === 0) return "[Merged and Forwarded Message - no sub-messages]";
1342
- const subMessages = items.filter((item) => item.upper_message_id);
1343
- if (subMessages.length === 0) return "[Merged and Forwarded Message - no sub-messages found]";
1344
- log?.(`feishu: merge_forward contains ${subMessages.length} sub-messages`);
1345
- subMessages.sort((a, b) => {
1346
- return parseInt(a.create_time || "0", 10) - parseInt(b.create_time || "0", 10);
1347
- });
1348
- const lines = ["[Merged and Forwarded Messages]"];
1349
- const limitedMessages = subMessages.slice(0, maxMessages);
1350
- for (const item of limitedMessages) {
1351
- const formatted = formatSubMessageContent(item.body?.content || "", item.msg_type || "text");
1352
- lines.push(`- ${formatted}`);
1353
- }
1354
- if (subMessages.length > maxMessages) lines.push(`... and ${subMessages.length - maxMessages} more messages`);
1355
- return lines.join("\n");
1356
- }
1357
- /**
1358
- * Format sub-message content based on message type.
1359
- */
1360
- function formatSubMessageContent(content, contentType) {
1361
- try {
1362
- const parsed = JSON.parse(content);
1363
- switch (contentType) {
1364
- case "text": return parsed.text || content;
1365
- case "post": {
1366
- const { textContent } = parsePostContent(content);
1367
- return textContent;
1368
- }
1369
- case "image": return "[Image]";
1370
- case "file": return `[File: ${parsed.file_name || "unknown"}]`;
1371
- case "audio": return "[Audio]";
1372
- case "video": return "[Video]";
1373
- case "sticker": return "[Sticker]";
1374
- case "merge_forward": return "[Nested Merged Forward]";
1375
- default: return `[${contentType}]`;
1376
- }
1377
- } catch {
1378
- return content;
1379
- }
1380
- }
1381
- function checkBotMentioned(event, botOpenId) {
1382
- if (!botOpenId) return false;
1383
- if ((event.message.content ?? "").includes("@_all")) return true;
1384
- const mentions = event.message.mentions ?? [];
1385
- if (mentions.length > 0) return mentions.some((m) => m.id.open_id === botOpenId);
1386
- if (event.message.message_type === "post") {
1387
- const { mentionedOpenIds } = parsePostContent(event.message.content);
1388
- return mentionedOpenIds.some((id) => id === botOpenId);
1389
- }
1390
- return false;
1391
- }
1392
- function normalizeMentions(text, mentions, botStripId) {
1393
- if (!mentions || mentions.length === 0) return text;
1394
- const escaped = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1395
- const escapeName = (value) => value.replace(/</g, "&lt;").replace(/>/g, "&gt;");
1396
- let result = text;
1397
- for (const mention of mentions) {
1398
- const mentionId = mention.id.open_id;
1399
- const replacement = botStripId && mentionId === botStripId ? "" : mentionId ? `<at user_id="${mentionId}">${escapeName(mention.name)}</at>` : `@${mention.name}`;
1400
- result = result.replace(new RegExp(escaped(mention.key), "g"), () => replacement).trim();
1401
- }
1402
- return result;
1403
- }
1404
- function normalizeFeishuCommandProbeBody(text) {
1405
- if (!text) return "";
1406
- return text.replace(/<at\b[^>]*>[^<]*<\/at>/giu, " ").replace(/(^|\s)@[^/\s]+(?=\s|$|\/)/gu, "$1").replace(/\s+/g, " ").trim();
1407
- }
1408
- /**
1409
- * Parse media keys from message content based on message type.
1410
- */
1411
- function parseMediaKeys(content, messageType) {
1412
- try {
1413
- const parsed = JSON.parse(content);
1414
- const imageKey = normalizeFeishuExternalKey(parsed.image_key);
1415
- const fileKey = normalizeFeishuExternalKey(parsed.file_key);
1416
- switch (messageType) {
1417
- case "image": return {
1418
- imageKey,
1419
- fileName: parsed.file_name
1420
- };
1421
- case "file": return {
1422
- fileKey,
1423
- fileName: parsed.file_name
1424
- };
1425
- case "audio": return {
1426
- fileKey,
1427
- fileName: parsed.file_name
1428
- };
1429
- case "video":
1430
- case "media": return {
1431
- fileKey,
1432
- imageKey,
1433
- fileName: parsed.file_name
1434
- };
1435
- case "sticker": return {
1436
- fileKey,
1437
- fileName: parsed.file_name
1438
- };
1439
- default: return {};
1440
- }
1441
- } catch {
1442
- return {};
1443
- }
1444
- }
1445
- /**
1446
- * Map Feishu message type to messageResource.get resource type.
1447
- * Feishu messageResource API supports only: image | file.
1448
- */
1449
- function toMessageResourceType(messageType) {
1450
- return messageType === "image" ? "image" : "file";
1451
- }
1452
- /**
1453
- * Infer placeholder text based on message type.
1454
- */
1455
- function inferPlaceholder(messageType) {
1456
- switch (messageType) {
1457
- case "image": return "<media:image>";
1458
- case "file": return "<media:document>";
1459
- case "audio": return "<media:audio>";
1460
- case "video":
1461
- case "media": return "<media:video>";
1462
- case "sticker": return "<media:sticker>";
1463
- default: return "<media:document>";
1464
- }
1465
- }
1466
- /**
1467
- * Resolve media from a Feishu message, downloading and saving to disk.
1468
- * Similar to Discord's resolveMediaList().
1469
- */
1470
- async function resolveFeishuMediaList(params) {
1471
- const { cfg, messageId, messageType, content, maxBytes, log, accountId } = params;
1472
- if (![
1473
- "image",
1474
- "file",
1475
- "audio",
1476
- "video",
1477
- "media",
1478
- "sticker",
1479
- "post"
1480
- ].includes(messageType)) return [];
1481
- const out = [];
1482
- const core = getFeishuRuntime();
1483
- if (messageType === "post") {
1484
- const { imageKeys, mediaKeys: postMediaKeys } = parsePostContent(content);
1485
- if (imageKeys.length === 0 && postMediaKeys.length === 0) return [];
1486
- if (imageKeys.length > 0) log?.(`feishu: post message contains ${imageKeys.length} embedded image(s)`);
1487
- if (postMediaKeys.length > 0) log?.(`feishu: post message contains ${postMediaKeys.length} embedded media file(s)`);
1488
- for (const imageKey of imageKeys) try {
1489
- const result = await downloadMessageResourceFeishu({
1490
- cfg,
1491
- messageId,
1492
- fileKey: imageKey,
1493
- type: "image",
1494
- accountId
1495
- });
1496
- let contentType = result.contentType;
1497
- if (!contentType) contentType = await core.media.detectMime({ buffer: result.buffer });
1498
- const saved = await core.channel.media.saveMediaBuffer(result.buffer, contentType, "inbound", maxBytes);
1499
- out.push({
1500
- path: saved.path,
1501
- contentType: saved.contentType,
1502
- placeholder: "<media:image>"
1503
- });
1504
- log?.(`feishu: downloaded embedded image ${imageKey}, saved to ${saved.path}`);
1505
- } catch (err) {
1506
- log?.(`feishu: failed to download embedded image ${imageKey}: ${String(err)}`);
1507
- }
1508
- for (const media of postMediaKeys) try {
1509
- const result = await downloadMessageResourceFeishu({
1510
- cfg,
1511
- messageId,
1512
- fileKey: media.fileKey,
1513
- type: "file",
1514
- accountId
1515
- });
1516
- let contentType = result.contentType;
1517
- if (!contentType) contentType = await core.media.detectMime({ buffer: result.buffer });
1518
- const saved = await core.channel.media.saveMediaBuffer(result.buffer, contentType, "inbound", maxBytes);
1519
- out.push({
1520
- path: saved.path,
1521
- contentType: saved.contentType,
1522
- placeholder: "<media:video>"
1523
- });
1524
- log?.(`feishu: downloaded embedded media ${media.fileKey}, saved to ${saved.path}`);
1525
- } catch (err) {
1526
- log?.(`feishu: failed to download embedded media ${media.fileKey}: ${String(err)}`);
1527
- }
1528
- return out;
1529
- }
1530
- const mediaKeys = parseMediaKeys(content, messageType);
1531
- if (!mediaKeys.imageKey && !mediaKeys.fileKey) return [];
1532
- try {
1533
- let buffer;
1534
- let contentType;
1535
- let fileName;
1536
- const fileKey = mediaKeys.fileKey || mediaKeys.imageKey;
1537
- if (!fileKey) return [];
1538
- const result = await downloadMessageResourceFeishu({
1539
- cfg,
1540
- messageId,
1541
- fileKey,
1542
- type: toMessageResourceType(messageType),
1543
- accountId
1544
- });
1545
- buffer = result.buffer;
1546
- contentType = result.contentType;
1547
- fileName = result.fileName || mediaKeys.fileName;
1548
- if (!contentType) contentType = await core.media.detectMime({ buffer });
1549
- const saved = await core.channel.media.saveMediaBuffer(buffer, contentType, "inbound", maxBytes, fileName);
1550
- out.push({
1551
- path: saved.path,
1552
- contentType: saved.contentType,
1553
- placeholder: inferPlaceholder(messageType)
1554
- });
1555
- log?.(`feishu: downloaded ${messageType} media, saved to ${saved.path}`);
1556
- } catch (err) {
1557
- log?.(`feishu: failed to download ${messageType} media: ${String(err)}`);
1558
- }
1559
- return out;
1560
- }
1561
- function resolveBroadcastAgents(cfg, peerId) {
1562
- const broadcast = cfg.broadcast;
1563
- if (!broadcast || typeof broadcast !== "object") return null;
1564
- const agents = broadcast[peerId];
1565
- if (!Array.isArray(agents) || agents.length === 0) return null;
1566
- return agents;
1567
- }
1568
- function buildBroadcastSessionKey(baseSessionKey, originalAgentId, targetAgentId) {
1569
- const prefix = `agent:${originalAgentId}:`;
1570
- if (baseSessionKey.startsWith(prefix)) return `agent:${targetAgentId}:${baseSessionKey.slice(prefix.length)}`;
1571
- return baseSessionKey;
1572
- }
1573
- /**
1574
- * Build media payload for inbound context.
1575
- * Similar to Discord's buildDiscordMediaPayload().
1576
- */
1577
- function parseFeishuMessageEvent(event, botOpenId, _botName) {
1578
- const rawContent = parseMessageContent(event.message.content, event.message.message_type);
1579
- const mentionedBot = checkBotMentioned(event, botOpenId);
1580
- const hasAnyMention = (event.message.mentions?.length ?? 0) > 0;
1581
- const content = normalizeMentions(rawContent, event.message.mentions, botOpenId);
1582
- const senderOpenId = event.sender.sender_id.open_id?.trim();
1583
- const senderUserId = event.sender.sender_id.user_id?.trim();
1584
- const senderFallbackId = senderOpenId || senderUserId || "";
1585
- const ctx = {
1586
- chatId: event.message.chat_id,
1587
- messageId: event.message.message_id,
1588
- senderId: senderUserId || senderOpenId || "",
1589
- senderOpenId: senderFallbackId,
1590
- chatType: event.message.chat_type,
1591
- mentionedBot,
1592
- hasAnyMention,
1593
- rootId: event.message.root_id || void 0,
1594
- parentId: event.message.parent_id || void 0,
1595
- threadId: event.message.thread_id || void 0,
1596
- content,
1597
- contentType: event.message.message_type
1598
- };
1599
- if (isMentionForwardRequest(event, botOpenId)) {
1600
- const mentionTargets = extractMentionTargets(event, botOpenId);
1601
- if (mentionTargets.length > 0) ctx.mentionTargets = mentionTargets;
1602
- }
1603
- return ctx;
1604
- }
1605
- function buildFeishuAgentBody(params) {
1606
- const { ctx, quotedContent, permissionErrorForAgent, botOpenId } = params;
1607
- let messageBody = ctx.content;
1608
- if (quotedContent) messageBody = `[Replying to: "${quotedContent}"]\n\n${ctx.content}`;
1609
- messageBody = `${ctx.senderName ?? ctx.senderOpenId}: ${messageBody}`;
1610
- if (ctx.hasAnyMention) {
1611
- const botIdHint = botOpenId?.trim();
1612
- messageBody += "\n\n[System: The content may include mention tags in the form <at user_id=\"...\">name</at>. Treat these as real mentions of Feishu entities (users or bots).]";
1613
- if (botIdHint) messageBody += `\n[System: If user_id is "${botIdHint}", that mention refers to you.]`;
1614
- }
1615
- if (ctx.mentionTargets && ctx.mentionTargets.length > 0) {
1616
- const targetNames = ctx.mentionTargets.map((t) => t.name).join(", ");
1617
- messageBody += `\n\n[System: Your reply will automatically @mention: ${targetNames}. Do not write @xxx yourself.]`;
1618
- }
1619
- messageBody = `[message_id: ${ctx.messageId}]\n${messageBody}`;
1620
- if (permissionErrorForAgent) {
1621
- const grantUrl = permissionErrorForAgent.grantUrl ?? "";
1622
- messageBody += `\n\n[System: The bot encountered a Feishu API permission error. Please inform the user about this issue and provide the permission grant URL for the admin to authorize. Permission grant URL: ${grantUrl}]`;
1623
- }
1624
- return messageBody;
1625
- }
1626
- async function handleFeishuMessage(params) {
1627
- const { cfg, event, botOpenId, botName, runtime, chatHistories, accountId, processingClaimHeld = false } = params;
1628
- const account = resolveFeishuAccount({
1629
- cfg,
1630
- accountId
1631
- });
1632
- const feishuCfg = account.config;
1633
- const log = runtime?.log ?? console.log;
1634
- const error = runtime?.error ?? console.error;
1635
- const messageId = event.message.message_id;
1636
- if (!await finalizeFeishuMessageProcessing({
1637
- messageId,
1638
- namespace: account.accountId,
1639
- log,
1640
- claimHeld: processingClaimHeld
1641
- })) {
1642
- log(`feishu: skipping duplicate message ${messageId}`);
1643
- return;
1644
- }
1645
- let ctx = parseFeishuMessageEvent(event, botOpenId, botName);
1646
- const isGroup = ctx.chatType === "group";
1647
- const isDirect = !isGroup;
1648
- const senderUserId = event.sender.sender_id.user_id?.trim() || void 0;
1649
- if (event.message.message_type === "merge_forward") {
1650
- log(`feishu[${account.accountId}]: processing merge_forward message, fetching full content via API`);
1651
- try {
1652
- const response = await createFeishuClient(account).im.message.get({ path: { message_id: event.message.message_id } });
1653
- if (response.code === 0 && response.data?.items && response.data.items.length > 0) {
1654
- log(`feishu[${account.accountId}]: merge_forward API returned ${response.data.items.length} items`);
1655
- const expandedContent = parseMergeForwardContent({
1656
- content: JSON.stringify(response.data.items),
1657
- log
1658
- });
1659
- ctx = {
1660
- ...ctx,
1661
- content: expandedContent
1662
- };
1663
- } else {
1664
- log(`feishu[${account.accountId}]: merge_forward API returned no items`);
1665
- ctx = {
1666
- ...ctx,
1667
- content: "[Merged and Forwarded Message - could not fetch]"
1668
- };
1669
- }
1670
- } catch (err) {
1671
- log(`feishu[${account.accountId}]: merge_forward fetch failed: ${String(err)}`);
1672
- ctx = {
1673
- ...ctx,
1674
- content: "[Merged and Forwarded Message - fetch error]"
1675
- };
1676
- }
1677
- }
1678
- let permissionErrorForAgent;
1679
- if (feishuCfg?.resolveSenderNames ?? true) {
1680
- const senderResult = await resolveFeishuSenderName({
1681
- account,
1682
- senderId: ctx.senderOpenId,
1683
- log
1684
- });
1685
- if (senderResult.name) ctx = {
1686
- ...ctx,
1687
- senderName: senderResult.name
1688
- };
1689
- if (senderResult.permissionError) {
1690
- const appKey = account.appId ?? "default";
1691
- const now = Date.now();
1692
- if (now - (permissionErrorNotifiedAt.get(appKey) ?? 0) > PERMISSION_ERROR_COOLDOWN_MS) {
1693
- permissionErrorNotifiedAt.set(appKey, now);
1694
- permissionErrorForAgent = senderResult.permissionError;
1695
- }
1696
- }
1697
- }
1698
- log(`feishu[${account.accountId}]: received message from ${ctx.senderOpenId} in ${ctx.chatId} (${ctx.chatType})`);
1699
- if (ctx.mentionTargets && ctx.mentionTargets.length > 0) {
1700
- const names = ctx.mentionTargets.map((t) => t.name).join(", ");
1701
- log(`feishu[${account.accountId}]: detected @ forward request, targets: [${names}]`);
1702
- }
1703
- const historyLimit = Math.max(0, feishuCfg?.historyLimit ?? cfg.messages?.groupChat?.historyLimit ?? 50);
1704
- const groupConfig = isGroup ? resolveFeishuGroupConfig({
1705
- cfg: feishuCfg,
1706
- groupId: ctx.chatId
1707
- }) : void 0;
1708
- const groupSession = isGroup ? resolveFeishuGroupSession({
1709
- chatId: ctx.chatId,
1710
- senderOpenId: ctx.senderOpenId,
1711
- messageId: ctx.messageId,
1712
- rootId: ctx.rootId,
1713
- threadId: ctx.threadId,
1714
- groupConfig,
1715
- feishuCfg
1716
- }) : null;
1717
- const groupHistoryKey = isGroup ? groupSession?.peerId ?? ctx.chatId : void 0;
1718
- const dmPolicy = feishuCfg?.dmPolicy ?? "pairing";
1719
- const configAllowFrom = feishuCfg?.allowFrom ?? [];
1720
- const useAccessGroups = cfg.commands?.useAccessGroups !== false;
1721
- const rawBroadcastAgents = isGroup ? resolveBroadcastAgents(cfg, ctx.chatId) : null;
1722
- const broadcastAgents = rawBroadcastAgents ? [...new Set(rawBroadcastAgents.map((id) => normalizeAgentId(id)))] : null;
1723
- let requireMention = false;
1724
- if (isGroup) {
1725
- if (groupConfig?.enabled === false) {
1726
- log(`feishu[${account.accountId}]: group ${ctx.chatId} is disabled`);
1727
- return;
1728
- }
1729
- const defaultGroupPolicy = resolveDefaultGroupPolicy(cfg);
1730
- const { groupPolicy, providerMissingFallbackApplied } = resolveOpenProviderRuntimeGroupPolicy({
1731
- providerConfigPresent: cfg.channels?.feishu !== void 0,
1732
- groupPolicy: feishuCfg?.groupPolicy,
1733
- defaultGroupPolicy
1734
- });
1735
- warnMissingProviderGroupPolicyFallbackOnce({
1736
- providerMissingFallbackApplied,
1737
- providerKey: "feishu",
1738
- accountId: account.accountId,
1739
- log
1740
- });
1741
- if (!isFeishuGroupAllowed({
1742
- groupPolicy,
1743
- allowFrom: feishuCfg?.groupAllowFrom ?? [],
1744
- senderId: ctx.chatId,
1745
- senderName: void 0
1746
- })) {
1747
- log(`feishu[${account.accountId}]: group ${ctx.chatId} not in groupAllowFrom (groupPolicy=${groupPolicy})`);
1748
- return;
1749
- }
1750
- const perGroupSenderAllowFrom = groupConfig?.allowFrom ?? [];
1751
- const globalSenderAllowFrom = feishuCfg?.groupSenderAllowFrom ?? [];
1752
- const effectiveSenderAllowFrom = perGroupSenderAllowFrom.length > 0 ? perGroupSenderAllowFrom : globalSenderAllowFrom;
1753
- if (effectiveSenderAllowFrom.length > 0) {
1754
- if (!isFeishuGroupAllowed({
1755
- groupPolicy: "allowlist",
1756
- allowFrom: effectiveSenderAllowFrom,
1757
- senderId: ctx.senderOpenId,
1758
- senderIds: [senderUserId],
1759
- senderName: ctx.senderName
1760
- })) {
1761
- log(`feishu: sender ${ctx.senderOpenId} not in group ${ctx.chatId} sender allowlist`);
1762
- return;
1763
- }
1764
- }
1765
- ({requireMention} = resolveFeishuReplyPolicy({
1766
- isDirectMessage: false,
1767
- globalConfig: feishuCfg,
1768
- groupConfig
1769
- }));
1770
- if (requireMention && !ctx.mentionedBot) {
1771
- log(`feishu[${account.accountId}]: message in group ${ctx.chatId} did not mention bot`);
1772
- if (!broadcastAgents && chatHistories && groupHistoryKey) recordPendingHistoryEntryIfEnabled({
1773
- historyMap: chatHistories,
1774
- historyKey: groupHistoryKey,
1775
- limit: historyLimit,
1776
- entry: {
1777
- sender: ctx.senderOpenId,
1778
- body: `${ctx.senderName ?? ctx.senderOpenId}: ${ctx.content}`,
1779
- timestamp: Date.now(),
1780
- messageId: ctx.messageId
1781
- }
1782
- });
1783
- return;
1784
- }
1785
- }
1786
- try {
1787
- const core = getFeishuRuntime();
1788
- const pairing = createScopedPairingAccess({
1789
- core,
1790
- channel: "feishu",
1791
- accountId: account.accountId
1792
- });
1793
- const commandProbeBody = isGroup ? normalizeFeishuCommandProbeBody(ctx.content) : ctx.content;
1794
- const shouldComputeCommandAuthorized = core.channel.commands.shouldComputeCommandAuthorized(commandProbeBody, cfg);
1795
- const storeAllowFrom = !isGroup && dmPolicy !== "allowlist" && (dmPolicy !== "open" || shouldComputeCommandAuthorized) ? await pairing.readAllowFromStore().catch(() => []) : [];
1796
- const effectiveDmAllowFrom = [...configAllowFrom, ...storeAllowFrom];
1797
- const dmAllowed = resolveFeishuAllowlistMatch({
1798
- allowFrom: effectiveDmAllowFrom,
1799
- senderId: ctx.senderOpenId,
1800
- senderIds: [senderUserId],
1801
- senderName: ctx.senderName
1802
- }).allowed;
1803
- if (isDirect && dmPolicy !== "open" && !dmAllowed) {
1804
- if (dmPolicy === "pairing") await issuePairingChallenge({
1805
- channel: "feishu",
1806
- senderId: ctx.senderOpenId,
1807
- senderIdLine: `Your Feishu user id: ${ctx.senderOpenId}`,
1808
- meta: { name: ctx.senderName },
1809
- upsertPairingRequest: pairing.upsertPairingRequest,
1810
- onCreated: () => {
1811
- log(`feishu[${account.accountId}]: pairing request sender=${ctx.senderOpenId}`);
1812
- },
1813
- sendPairingReply: async (text) => {
1814
- await sendMessageFeishu({
1815
- cfg,
1816
- to: `chat:${ctx.chatId}`,
1817
- text,
1818
- accountId: account.accountId
1819
- });
1820
- },
1821
- onReplyError: (err) => {
1822
- log(`feishu[${account.accountId}]: pairing reply failed for ${ctx.senderOpenId}: ${String(err)}`);
1823
- }
1824
- });
1825
- else log(`feishu[${account.accountId}]: blocked unauthorized sender ${ctx.senderOpenId} (dmPolicy=${dmPolicy})`);
1826
- return;
1827
- }
1828
- const commandAllowFrom = isGroup ? groupConfig?.allowFrom ?? configAllowFrom : effectiveDmAllowFrom;
1829
- const senderAllowedForCommands = resolveFeishuAllowlistMatch({
1830
- allowFrom: commandAllowFrom,
1831
- senderId: ctx.senderOpenId,
1832
- senderIds: [senderUserId],
1833
- senderName: ctx.senderName
1834
- }).allowed;
1835
- const commandAuthorized = shouldComputeCommandAuthorized ? core.channel.commands.resolveCommandAuthorizedFromAuthorizers({
1836
- useAccessGroups,
1837
- authorizers: [{
1838
- configured: commandAllowFrom.length > 0,
1839
- allowed: senderAllowedForCommands
1840
- }]
1841
- }) : void 0;
1842
- const feishuFrom = `feishu:${ctx.senderOpenId}`;
1843
- const feishuTo = isGroup ? `chat:${ctx.chatId}` : `user:${ctx.senderOpenId}`;
1844
- const peerId = isGroup ? groupSession?.peerId ?? ctx.chatId : ctx.senderOpenId;
1845
- const parentPeer = isGroup ? groupSession?.parentPeer ?? null : null;
1846
- const replyInThread = isGroup ? groupSession?.replyInThread ?? false : false;
1847
- const feishuAcpConversationSupported = !isGroup || groupSession?.groupSessionScope === "group_topic" || groupSession?.groupSessionScope === "group_topic_sender";
1848
- if (isGroup && groupSession) log(`feishu[${account.accountId}]: group session scope=${groupSession.groupSessionScope}, peer=${peerId}`);
1849
- let route = core.channel.routing.resolveAgentRoute({
1850
- cfg,
1851
- channel: "feishu",
1852
- accountId: account.accountId,
1853
- peer: {
1854
- kind: isGroup ? "group" : "direct",
1855
- id: peerId
1856
- },
1857
- parentPeer
1858
- });
1859
- let effectiveCfg = cfg;
1860
- if (!isGroup && route.matchedBy === "default") {
1861
- const dynamicCfg = feishuCfg?.dynamicAgentCreation;
1862
- if (dynamicCfg?.enabled) {
1863
- const result = await maybeCreateDynamicAgent({
1864
- cfg,
1865
- runtime: getFeishuRuntime(),
1866
- senderOpenId: ctx.senderOpenId,
1867
- dynamicCfg,
1868
- log: (msg) => log(msg)
1869
- });
1870
- if (result.created) {
1871
- effectiveCfg = result.updatedCfg;
1872
- route = core.channel.routing.resolveAgentRoute({
1873
- cfg: result.updatedCfg,
1874
- channel: "feishu",
1875
- accountId: account.accountId,
1876
- peer: {
1877
- kind: "direct",
1878
- id: ctx.senderOpenId
1879
- }
1880
- });
1881
- log(`feishu[${account.accountId}]: dynamic agent created, new route: ${route.sessionKey}`);
1882
- }
1883
- }
1884
- }
1885
- const currentConversationId = peerId;
1886
- const parentConversationId = isGroup ? parentPeer?.id ?? ctx.chatId : void 0;
1887
- let configuredBinding = null;
1888
- if (feishuAcpConversationSupported) {
1889
- const configuredRoute = resolveConfiguredAcpRoute({
1890
- cfg: effectiveCfg,
1891
- route,
1892
- channel: "feishu",
1893
- accountId: account.accountId,
1894
- conversationId: currentConversationId,
1895
- parentConversationId
1896
- });
1897
- configuredBinding = configuredRoute.configuredBinding;
1898
- route = configuredRoute.route;
1899
- const threadBinding = getSessionBindingService().resolveByConversation({
1900
- channel: "feishu",
1901
- accountId: account.accountId,
1902
- conversationId: currentConversationId,
1903
- ...parentConversationId ? { parentConversationId } : {}
1904
- });
1905
- const boundSessionKey = threadBinding?.targetSessionKey?.trim();
1906
- if (threadBinding && boundSessionKey) {
1907
- route = {
1908
- ...route,
1909
- sessionKey: boundSessionKey,
1910
- agentId: resolveAgentIdFromSessionKey(boundSessionKey) || route.agentId,
1911
- lastRoutePolicy: deriveLastRoutePolicy({
1912
- sessionKey: boundSessionKey,
1913
- mainSessionKey: route.mainSessionKey
1914
- }),
1915
- matchedBy: "binding.channel"
1916
- };
1917
- configuredBinding = null;
1918
- getSessionBindingService().touch(threadBinding.bindingId);
1919
- log(`feishu[${account.accountId}]: routed via bound conversation ${currentConversationId} -> ${boundSessionKey}`);
1920
- }
1921
- }
1922
- if (configuredBinding) {
1923
- const ensured = await ensureConfiguredAcpRouteReady({
1924
- cfg: effectiveCfg,
1925
- configuredBinding
1926
- });
1927
- if (!ensured.ok) {
1928
- const replyTargetMessageId = isGroup && (groupSession?.groupSessionScope === "group_topic" || groupSession?.groupSessionScope === "group_topic_sender") ? ctx.rootId ?? ctx.messageId : ctx.messageId;
1929
- await sendMessageFeishu({
1930
- cfg: effectiveCfg,
1931
- to: `chat:${ctx.chatId}`,
1932
- text: `⚠️ Failed to initialize the configured ACP session for this Feishu conversation: ${ensured.error}`,
1933
- replyToMessageId: replyTargetMessageId,
1934
- replyInThread: isGroup ? groupSession?.replyInThread ?? false : false,
1935
- accountId: account.accountId
1936
- }).catch((err) => {
1937
- log(`feishu[${account.accountId}]: failed to send ACP init error reply: ${String(err)}`);
1938
- });
1939
- return;
1940
- }
1941
- }
1942
- const preview = ctx.content.replace(/\s+/g, " ").slice(0, 160);
1943
- const inboundLabel = isGroup ? `Feishu[${account.accountId}] message in group ${ctx.chatId}` : `Feishu[${account.accountId}] DM from ${ctx.senderOpenId}`;
1944
- log(`feishu[${account.accountId}]: ${inboundLabel}: ${preview}`);
1945
- const mediaMaxBytes = (feishuCfg?.mediaMaxMb ?? 30) * 1024 * 1024;
1946
- const mediaPayload = buildAgentMediaPayload(await resolveFeishuMediaList({
1947
- cfg,
1948
- messageId: ctx.messageId,
1949
- messageType: event.message.message_type,
1950
- content: event.message.content,
1951
- maxBytes: mediaMaxBytes,
1952
- log,
1953
- accountId: account.accountId
1954
- }));
1955
- let quotedMessageInfo = null;
1956
- let quotedContent;
1957
- if (ctx.parentId) try {
1958
- quotedMessageInfo = await getMessageFeishu({
1959
- cfg,
1960
- messageId: ctx.parentId,
1961
- accountId: account.accountId
1962
- });
1963
- if (quotedMessageInfo) {
1964
- quotedContent = quotedMessageInfo.content;
1965
- log(`feishu[${account.accountId}]: fetched quoted message: ${quotedContent?.slice(0, 100)}`);
1966
- }
1967
- } catch (err) {
1968
- log(`feishu[${account.accountId}]: failed to fetch quoted message: ${String(err)}`);
1969
- }
1970
- const isTopicSessionForThread = isGroup && (groupSession?.groupSessionScope === "group_topic" || groupSession?.groupSessionScope === "group_topic_sender");
1971
- const envelopeOptions = core.channel.reply.resolveEnvelopeFormatOptions(cfg);
1972
- const messageBody = buildFeishuAgentBody({
1973
- ctx,
1974
- quotedContent,
1975
- permissionErrorForAgent,
1976
- botOpenId
1977
- });
1978
- const envelopeFrom = isGroup ? `${ctx.chatId}:${ctx.senderOpenId}` : ctx.senderOpenId;
1979
- if (permissionErrorForAgent) log(`feishu[${account.accountId}]: appending permission error notice to message body`);
1980
- let combinedBody = core.channel.reply.formatAgentEnvelope({
1981
- channel: "Feishu",
1982
- from: envelopeFrom,
1983
- timestamp: /* @__PURE__ */ new Date(),
1984
- envelope: envelopeOptions,
1985
- body: messageBody
1986
- });
1987
- const historyKey = groupHistoryKey;
1988
- if (isGroup && historyKey && chatHistories) combinedBody = buildPendingHistoryContextFromMap({
1989
- historyMap: chatHistories,
1990
- historyKey,
1991
- limit: historyLimit,
1992
- currentMessage: combinedBody,
1993
- formatEntry: (entry) => core.channel.reply.formatAgentEnvelope({
1994
- channel: "Feishu",
1995
- from: `${ctx.chatId}:${entry.sender}`,
1996
- timestamp: entry.timestamp,
1997
- body: entry.body,
1998
- envelope: envelopeOptions
1999
- })
2000
- });
2001
- const inboundHistory = isGroup && historyKey && historyLimit > 0 && chatHistories ? (chatHistories.get(historyKey) ?? []).map((entry) => ({
2002
- sender: entry.sender,
2003
- body: entry.body,
2004
- timestamp: entry.timestamp
2005
- })) : void 0;
2006
- const threadContextBySessionKey = /* @__PURE__ */ new Map();
2007
- let rootMessageInfo;
2008
- let rootMessageFetched = false;
2009
- const getRootMessageInfo = async () => {
2010
- if (!ctx.rootId) return null;
2011
- if (!rootMessageFetched) {
2012
- rootMessageFetched = true;
2013
- if (ctx.rootId === ctx.parentId && quotedMessageInfo) rootMessageInfo = quotedMessageInfo;
2014
- else try {
2015
- rootMessageInfo = await getMessageFeishu({
2016
- cfg,
2017
- messageId: ctx.rootId,
2018
- accountId: account.accountId
2019
- });
2020
- } catch (err) {
2021
- log(`feishu[${account.accountId}]: failed to fetch root message: ${String(err)}`);
2022
- rootMessageInfo = null;
2023
- }
2024
- }
2025
- return rootMessageInfo ?? null;
2026
- };
2027
- const resolveThreadContextForAgent = async (agentId, agentSessionKey) => {
2028
- const cached = threadContextBySessionKey.get(agentSessionKey);
2029
- if (cached) return cached;
2030
- const threadContext = { threadLabel: (ctx.rootId || ctx.threadId) && isTopicSessionForThread ? `Feishu thread in ${ctx.chatId}` : void 0 };
2031
- if (!(ctx.rootId || ctx.threadId) || !isTopicSessionForThread) {
2032
- threadContextBySessionKey.set(agentSessionKey, threadContext);
2033
- return threadContext;
2034
- }
2035
- const storePath = core.channel.session.resolveStorePath(cfg.session?.store, { agentId });
2036
- if (core.channel.session.readSessionUpdatedAt({
2037
- storePath,
2038
- sessionKey: agentSessionKey
2039
- })) {
2040
- log(`feishu[${account.accountId}]: skipping thread bootstrap for existing session ${agentSessionKey}`);
2041
- threadContextBySessionKey.set(agentSessionKey, threadContext);
2042
- return threadContext;
2043
- }
2044
- const rootMsg = await getRootMessageInfo();
2045
- let feishuThreadId = ctx.threadId ?? rootMsg?.threadId;
2046
- if (feishuThreadId) log(`feishu[${account.accountId}]: resolved thread ID: ${feishuThreadId}`);
2047
- if (!feishuThreadId) {
2048
- log(`feishu[${account.accountId}]: no threadId found for root message ${ctx.rootId ?? "none"}, skipping thread history`);
2049
- threadContextBySessionKey.set(agentSessionKey, threadContext);
2050
- return threadContext;
2051
- }
2052
- try {
2053
- const threadMessages = await listFeishuThreadMessages({
2054
- cfg,
2055
- threadId: feishuThreadId,
2056
- currentMessageId: ctx.messageId,
2057
- rootMessageId: ctx.rootId,
2058
- limit: 20,
2059
- accountId: account.accountId
2060
- });
2061
- const senderScoped = groupSession?.groupSessionScope === "group_topic_sender";
2062
- const senderIds = new Set([ctx.senderOpenId, senderUserId].map((id) => id?.trim()).filter((id) => id !== void 0 && id.length > 0));
2063
- const relevantMessages = (senderScoped ? threadMessages.filter((msg) => msg.senderType === "app" || msg.senderId !== void 0 && senderIds.has(msg.senderId.trim())) : threadMessages) ?? [];
2064
- const threadStarterBody = rootMsg?.content ?? relevantMessages[0]?.content;
2065
- const historyMessages = Boolean(rootMsg?.content || ctx.rootId) ? relevantMessages : relevantMessages.slice(1);
2066
- const historyParts = historyMessages.map((msg) => {
2067
- const role = msg.senderType === "app" ? "assistant" : "user";
2068
- return core.channel.reply.formatAgentEnvelope({
2069
- channel: "Feishu",
2070
- from: `${msg.senderId ?? "Unknown"} (${role})`,
2071
- timestamp: msg.createTime,
2072
- body: msg.content,
2073
- envelope: envelopeOptions
2074
- });
2075
- });
2076
- threadContext.threadStarterBody = threadStarterBody;
2077
- threadContext.threadHistoryBody = historyParts.length > 0 ? historyParts.join("\n\n") : void 0;
2078
- log(`feishu[${account.accountId}]: populated thread bootstrap with starter=${threadStarterBody ? "yes" : "no"} history=${historyMessages.length}`);
2079
- } catch (err) {
2080
- log(`feishu[${account.accountId}]: failed to fetch thread history: ${String(err)}`);
2081
- }
2082
- threadContextBySessionKey.set(agentSessionKey, threadContext);
2083
- return threadContext;
2084
- };
2085
- const buildCtxPayloadForAgent = async (agentId, agentSessionKey, agentAccountId, wasMentioned) => {
2086
- const threadContext = await resolveThreadContextForAgent(agentId, agentSessionKey);
2087
- return core.channel.reply.finalizeInboundContext({
2088
- Body: combinedBody,
2089
- BodyForAgent: messageBody,
2090
- InboundHistory: inboundHistory,
2091
- ReplyToId: ctx.parentId,
2092
- RootMessageId: ctx.rootId,
2093
- RawBody: ctx.content,
2094
- CommandBody: ctx.content,
2095
- From: feishuFrom,
2096
- To: feishuTo,
2097
- SessionKey: agentSessionKey,
2098
- AccountId: agentAccountId,
2099
- ChatType: isGroup ? "group" : "direct",
2100
- GroupSubject: isGroup ? ctx.chatId : void 0,
2101
- SenderName: ctx.senderName ?? ctx.senderOpenId,
2102
- SenderId: ctx.senderOpenId,
2103
- Provider: "feishu",
2104
- Surface: "feishu",
2105
- MessageSid: ctx.messageId,
2106
- ReplyToBody: quotedContent ?? void 0,
2107
- ThreadStarterBody: threadContext.threadStarterBody,
2108
- ThreadHistoryBody: threadContext.threadHistoryBody,
2109
- ThreadLabel: threadContext.threadLabel,
2110
- MessageThreadId: ctx.rootId && isTopicSessionForThread ? ctx.rootId : void 0,
2111
- Timestamp: Date.now(),
2112
- WasMentioned: wasMentioned,
2113
- CommandAuthorized: commandAuthorized,
2114
- OriginatingChannel: "feishu",
2115
- OriginatingTo: feishuTo,
2116
- GroupSystemPrompt: isGroup ? groupConfig?.systemPrompt?.trim() || void 0 : void 0,
2117
- ...mediaPayload
2118
- });
2119
- };
2120
- const messageCreateTimeMs = event.message.create_time ? parseInt(event.message.create_time, 10) : void 0;
2121
- const isTopicSession = isGroup && (groupSession?.groupSessionScope === "group_topic" || groupSession?.groupSessionScope === "group_topic_sender");
2122
- const configReplyInThread = isGroup && (groupConfig?.replyInThread ?? feishuCfg?.replyInThread ?? "disabled") === "enabled";
2123
- const replyTargetMessageId = isTopicSession || configReplyInThread ? ctx.rootId ?? ctx.messageId : ctx.messageId;
2124
- const threadReply = isGroup ? groupSession?.threadReply ?? false : false;
2125
- if (broadcastAgents) {
2126
- if (!await tryRecordMessagePersistent(ctx.messageId, "broadcast", log)) {
2127
- log(`feishu[${account.accountId}]: broadcast already claimed by another account for message ${ctx.messageId}; skipping`);
2128
- return;
2129
- }
2130
- const strategy = cfg.broadcast?.strategy || "parallel";
2131
- const activeAgentId = ctx.mentionedBot || !requireMention ? normalizeAgentId(route.agentId) : null;
2132
- const agentIds = (cfg.agents?.list ?? []).map((a) => normalizeAgentId(a.id));
2133
- const hasKnownAgents = agentIds.length > 0;
2134
- log(`feishu[${account.accountId}]: broadcasting to ${broadcastAgents.length} agents (strategy=${strategy}, active=${activeAgentId ?? "none"})`);
2135
- const dispatchForAgent = async (agentId) => {
2136
- if (hasKnownAgents && !agentIds.includes(normalizeAgentId(agentId))) {
2137
- log(`feishu[${account.accountId}]: broadcast agent ${agentId} not found in agents.list; skipping`);
2138
- return;
2139
- }
2140
- const agentSessionKey = buildBroadcastSessionKey(route.sessionKey, route.agentId, agentId);
2141
- const agentCtx = await buildCtxPayloadForAgent(agentId, agentSessionKey, route.accountId, ctx.mentionedBot && agentId === activeAgentId);
2142
- if (agentId === activeAgentId) {
2143
- const identity = resolveAgentOutboundIdentity(cfg, agentId);
2144
- const { dispatcher, replyOptions, markDispatchIdle } = createFeishuReplyDispatcher({
2145
- cfg,
2146
- agentId,
2147
- runtime,
2148
- chatId: ctx.chatId,
2149
- replyToMessageId: replyTargetMessageId,
2150
- skipReplyToInMessages: !isGroup,
2151
- replyInThread,
2152
- rootId: ctx.rootId,
2153
- threadReply,
2154
- mentionTargets: ctx.mentionTargets,
2155
- accountId: account.accountId,
2156
- identity,
2157
- messageCreateTimeMs
2158
- });
2159
- log(`feishu[${account.accountId}]: broadcast active dispatch agent=${agentId} (session=${agentSessionKey})`);
2160
- await core.channel.reply.withReplyDispatcher({
2161
- dispatcher,
2162
- onSettled: () => markDispatchIdle(),
2163
- run: () => core.channel.reply.dispatchReplyFromConfig({
2164
- ctx: agentCtx,
2165
- cfg,
2166
- dispatcher,
2167
- replyOptions
2168
- })
2169
- });
2170
- } else {
2171
- delete agentCtx.CommandAuthorized;
2172
- const noopDispatcher = {
2173
- sendToolResult: () => false,
2174
- sendBlockReply: () => false,
2175
- sendFinalReply: () => false,
2176
- waitForIdle: async () => {},
2177
- getQueuedCounts: () => ({
2178
- tool: 0,
2179
- block: 0,
2180
- final: 0
2181
- }),
2182
- markComplete: () => {}
2183
- };
2184
- log(`feishu[${account.accountId}]: broadcast observer dispatch agent=${agentId} (session=${agentSessionKey})`);
2185
- await core.channel.reply.withReplyDispatcher({
2186
- dispatcher: noopDispatcher,
2187
- run: () => core.channel.reply.dispatchReplyFromConfig({
2188
- ctx: agentCtx,
2189
- cfg,
2190
- dispatcher: noopDispatcher
2191
- })
2192
- });
2193
- }
2194
- };
2195
- if (strategy === "sequential") for (const agentId of broadcastAgents) try {
2196
- await dispatchForAgent(agentId);
2197
- } catch (err) {
2198
- log(`feishu[${account.accountId}]: broadcast dispatch failed for agent=${agentId}: ${String(err)}`);
2199
- }
2200
- else {
2201
- const results = await Promise.allSettled(broadcastAgents.map(dispatchForAgent));
2202
- for (let i = 0; i < results.length; i++) if (results[i].status === "rejected") log(`feishu[${account.accountId}]: broadcast dispatch failed for agent=${broadcastAgents[i]}: ${String(results[i].reason)}`);
2203
- }
2204
- if (isGroup && historyKey && chatHistories) clearHistoryEntriesIfEnabled({
2205
- historyMap: chatHistories,
2206
- historyKey,
2207
- limit: historyLimit
2208
- });
2209
- log(`feishu[${account.accountId}]: broadcast dispatch complete for ${broadcastAgents.length} agents`);
2210
- } else {
2211
- const ctxPayload = await buildCtxPayloadForAgent(route.agentId, route.sessionKey, route.accountId, ctx.mentionedBot);
2212
- const identity = resolveAgentOutboundIdentity(cfg, route.agentId);
2213
- const { dispatcher, replyOptions, markDispatchIdle } = createFeishuReplyDispatcher({
2214
- cfg,
2215
- agentId: route.agentId,
2216
- runtime,
2217
- chatId: ctx.chatId,
2218
- replyToMessageId: replyTargetMessageId,
2219
- skipReplyToInMessages: !isGroup,
2220
- replyInThread,
2221
- rootId: ctx.rootId,
2222
- threadReply,
2223
- mentionTargets: ctx.mentionTargets,
2224
- accountId: account.accountId,
2225
- identity,
2226
- messageCreateTimeMs
2227
- });
2228
- log(`feishu[${account.accountId}]: dispatching to agent (session=${route.sessionKey})`);
2229
- const { queuedFinal, counts } = await core.channel.reply.withReplyDispatcher({
2230
- dispatcher,
2231
- onSettled: () => {
2232
- markDispatchIdle();
2233
- },
2234
- run: () => core.channel.reply.dispatchReplyFromConfig({
2235
- ctx: ctxPayload,
2236
- cfg,
2237
- dispatcher,
2238
- replyOptions
2239
- })
2240
- });
2241
- if (isGroup && historyKey && chatHistories) clearHistoryEntriesIfEnabled({
2242
- historyMap: chatHistories,
2243
- historyKey,
2244
- limit: historyLimit
2245
- });
2246
- log(`feishu[${account.accountId}]: dispatch complete (queuedFinal=${queuedFinal}, replies=${counts.final})`);
2247
- }
2248
- } catch (err) {
2249
- error(`feishu[${account.accountId}]: failed to dispatch message: ${String(err)}`);
2250
- }
2251
- }
2252
- //#endregion
2253
- //#region extensions/feishu/src/card-interaction.ts
2254
- const FEISHU_CARD_INTERACTION_VERSION = "ocf1";
2255
- function isRecord(value) {
2256
- return typeof value === "object" && value !== null;
2257
- }
2258
- function isInteractionKind(value) {
2259
- return value === "button" || value === "quick" || value === "meta";
2260
- }
2261
- function isMetadataValue(value) {
2262
- return value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
2263
- }
2264
- function createFeishuCardInteractionEnvelope(envelope) {
2265
- return {
2266
- oc: FEISHU_CARD_INTERACTION_VERSION,
2267
- ...envelope
2268
- };
2269
- }
2270
- function buildFeishuCardActionTextFallback(event) {
2271
- const actionValue = event.action.value;
2272
- if (isRecord(actionValue)) {
2273
- if (typeof actionValue.text === "string") return actionValue.text;
2274
- if (typeof actionValue.command === "string") return actionValue.command;
2275
- return JSON.stringify(actionValue);
2276
- }
2277
- return String(actionValue);
2278
- }
2279
- function decodeFeishuCardAction(params) {
2280
- const { event, now = Date.now() } = params;
2281
- const actionValue = event.action.value;
2282
- if (!isRecord(actionValue) || actionValue.oc !== "ocf1") return {
2283
- kind: "legacy",
2284
- text: buildFeishuCardActionTextFallback(event)
2285
- };
2286
- if (!isInteractionKind(actionValue.k) || typeof actionValue.a !== "string" || !actionValue.a) return {
2287
- kind: "invalid",
2288
- reason: "malformed"
2289
- };
2290
- if (actionValue.q !== void 0 && typeof actionValue.q !== "string") return {
2291
- kind: "invalid",
2292
- reason: "malformed"
2293
- };
2294
- if (actionValue.m !== void 0) {
2295
- if (!isRecord(actionValue.m)) return {
2296
- kind: "invalid",
2297
- reason: "malformed"
2298
- };
2299
- for (const value of Object.values(actionValue.m)) if (!isMetadataValue(value)) return {
2300
- kind: "invalid",
2301
- reason: "malformed"
2302
- };
2303
- }
2304
- if (actionValue.c !== void 0) {
2305
- if (!isRecord(actionValue.c)) return {
2306
- kind: "invalid",
2307
- reason: "malformed"
2308
- };
2309
- if (actionValue.c.u !== void 0 && typeof actionValue.c.u !== "string") return {
2310
- kind: "invalid",
2311
- reason: "malformed"
2312
- };
2313
- if (actionValue.c.h !== void 0 && typeof actionValue.c.h !== "string") return {
2314
- kind: "invalid",
2315
- reason: "malformed"
2316
- };
2317
- if (actionValue.c.s !== void 0 && typeof actionValue.c.s !== "string") return {
2318
- kind: "invalid",
2319
- reason: "malformed"
2320
- };
2321
- if (actionValue.c.e !== void 0 && !Number.isFinite(actionValue.c.e)) return {
2322
- kind: "invalid",
2323
- reason: "malformed"
2324
- };
2325
- if (actionValue.c.t !== void 0 && actionValue.c.t !== "p2p" && actionValue.c.t !== "group") return {
2326
- kind: "invalid",
2327
- reason: "malformed"
2328
- };
2329
- if (typeof actionValue.c.e === "number" && actionValue.c.e < now) return {
2330
- kind: "invalid",
2331
- reason: "stale"
2332
- };
2333
- const expectedUser = actionValue.c.u?.trim();
2334
- if (expectedUser && expectedUser !== (event.operator.open_id ?? "").trim()) return {
2335
- kind: "invalid",
2336
- reason: "wrong_user"
2337
- };
2338
- const expectedChat = actionValue.c.h?.trim();
2339
- if (expectedChat && expectedChat !== (event.context.chat_id ?? "").trim()) return {
2340
- kind: "invalid",
2341
- reason: "wrong_conversation"
2342
- };
2343
- }
2344
- return {
2345
- kind: "structured",
2346
- envelope: actionValue
2347
- };
2348
- }
2349
- //#endregion
2350
- //#region extensions/feishu/src/card-ux-shared.ts
2351
- function buildFeishuCardButton(params) {
2352
- return {
2353
- tag: "button",
2354
- text: {
2355
- tag: "plain_text",
2356
- content: params.label
2357
- },
2358
- type: params.type ?? "default",
2359
- value: params.value
2360
- };
2361
- }
2362
- function buildFeishuCardInteractionContext(params) {
2363
- return {
2364
- u: params.operatorOpenId,
2365
- ...params.chatId ? { h: params.chatId } : {},
2366
- ...params.sessionKey ? { s: params.sessionKey } : {},
2367
- e: params.expiresAt,
2368
- ...params.chatType ? { t: params.chatType } : {}
2369
- };
2370
- }
2371
- //#endregion
2372
- //#region extensions/feishu/src/card-ux-approval.ts
2373
- const FEISHU_APPROVAL_REQUEST_ACTION = "feishu.quick_actions.request_approval";
2374
- const FEISHU_APPROVAL_CONFIRM_ACTION = "feishu.approval.confirm";
2375
- const FEISHU_APPROVAL_CANCEL_ACTION = "feishu.approval.cancel";
2376
- function createApprovalCard(params) {
2377
- const context = buildFeishuCardInteractionContext(params);
2378
- return {
2379
- schema: "2.0",
2380
- config: { wide_screen_mode: true },
2381
- header: {
2382
- title: {
2383
- tag: "plain_text",
2384
- content: "Confirm action"
2385
- },
2386
- template: "orange"
2387
- },
2388
- body: { elements: [{
2389
- tag: "markdown",
2390
- content: params.prompt
2391
- }, {
2392
- tag: "action",
2393
- actions: [buildFeishuCardButton({
2394
- label: params.confirmLabel ?? "Confirm",
2395
- type: "primary",
2396
- value: createFeishuCardInteractionEnvelope({
2397
- k: "quick",
2398
- a: FEISHU_APPROVAL_CONFIRM_ACTION,
2399
- q: params.command,
2400
- c: context
2401
- })
2402
- }), buildFeishuCardButton({
2403
- label: params.cancelLabel ?? "Cancel",
2404
- value: createFeishuCardInteractionEnvelope({
2405
- k: "button",
2406
- a: FEISHU_APPROVAL_CANCEL_ACTION,
2407
- c: context
2408
- })
2409
- })]
2410
- }] }
2411
- };
2412
- }
2413
- //#endregion
2414
- //#region extensions/feishu/src/card-action.ts
2415
- const FEISHU_APPROVAL_CARD_TTL_MS = 5 * 6e4;
2416
- const FEISHU_CARD_ACTION_TOKEN_TTL_MS = 15 * 6e4;
2417
- const processedCardActionTokens = /* @__PURE__ */ new Map();
2418
- function pruneProcessedCardActionTokens(now) {
2419
- for (const [key, entry] of processedCardActionTokens.entries()) if (entry.expiresAt <= now) processedCardActionTokens.delete(key);
2420
- }
2421
- function beginFeishuCardActionToken(params) {
2422
- const now = params.now ?? Date.now();
2423
- pruneProcessedCardActionTokens(now);
2424
- const normalizedToken = params.token.trim();
2425
- if (!normalizedToken) return true;
2426
- const key = `${params.accountId}:${normalizedToken}`;
2427
- const existing = processedCardActionTokens.get(key);
2428
- if (existing && existing.expiresAt > now) return false;
2429
- processedCardActionTokens.set(key, {
2430
- status: "inflight",
2431
- expiresAt: now + FEISHU_CARD_ACTION_TOKEN_TTL_MS
2432
- });
2433
- return true;
2434
- }
2435
- function completeFeishuCardActionToken(params) {
2436
- const now = params.now ?? Date.now();
2437
- const normalizedToken = params.token.trim();
2438
- if (!normalizedToken) return;
2439
- processedCardActionTokens.set(`${params.accountId}:${normalizedToken}`, {
2440
- status: "completed",
2441
- expiresAt: now + FEISHU_CARD_ACTION_TOKEN_TTL_MS
2442
- });
2443
- }
2444
- function releaseFeishuCardActionToken(params) {
2445
- const normalizedToken = params.token.trim();
2446
- if (!normalizedToken) return;
2447
- processedCardActionTokens.delete(`${params.accountId}:${normalizedToken}`);
2448
- }
2449
- function buildSyntheticMessageEvent(event, content, chatType) {
2450
- return {
2451
- sender: { sender_id: {
2452
- open_id: event.operator.open_id,
2453
- user_id: event.operator.user_id,
2454
- union_id: event.operator.union_id
2455
- } },
2456
- message: {
2457
- message_id: `card-action-${event.token}`,
2458
- chat_id: event.context.chat_id || event.operator.open_id,
2459
- chat_type: chatType ?? (event.context.chat_id ? "group" : "p2p"),
2460
- message_type: "text",
2461
- content: JSON.stringify({ text: content })
2462
- }
2463
- };
2464
- }
2465
- function resolveCallbackTarget(event) {
2466
- const chatId = event.context.chat_id?.trim();
2467
- if (chatId) return `chat:${chatId}`;
2468
- return `user:${event.operator.open_id}`;
2469
- }
2470
- async function dispatchSyntheticCommand(params) {
2471
- await handleFeishuMessage({
2472
- cfg: params.cfg,
2473
- event: buildSyntheticMessageEvent(params.event, params.command, params.chatType),
2474
- botOpenId: params.botOpenId,
2475
- runtime: params.runtime,
2476
- accountId: params.accountId
2477
- });
2478
- }
2479
- async function sendInvalidInteractionNotice(params) {
2480
- const reasonText = params.reason === "stale" ? "This card action has expired. Open a fresh launcher card and try again." : params.reason === "wrong_user" ? "This card action belongs to a different user." : params.reason === "wrong_conversation" ? "This card action belongs to a different conversation." : "This card action payload is invalid.";
2481
- await sendMessageFeishu({
2482
- cfg: params.cfg,
2483
- to: resolveCallbackTarget(params.event),
2484
- text: `⚠️ ${reasonText}`,
2485
- accountId: params.accountId
2486
- });
2487
- }
2488
- async function handleFeishuCardAction(params) {
2489
- const { cfg, event, runtime, accountId } = params;
2490
- const account = resolveFeishuAccount({
2491
- cfg,
2492
- accountId
2493
- });
2494
- const log = runtime?.log ?? console.log;
2495
- const decoded = decodeFeishuCardAction({ event });
2496
- if (!beginFeishuCardActionToken({
2497
- token: event.token,
2498
- accountId: account.accountId
2499
- })) {
2500
- log(`feishu[${account.accountId}]: skipping duplicate card action token ${event.token}`);
2501
- return;
2502
- }
2503
- try {
2504
- if (decoded.kind === "invalid") {
2505
- log(`feishu[${account.accountId}]: rejected card action from ${event.operator.open_id}: ${decoded.reason}`);
2506
- await sendInvalidInteractionNotice({
2507
- cfg,
2508
- event,
2509
- reason: decoded.reason,
2510
- accountId
2511
- });
2512
- completeFeishuCardActionToken({
2513
- token: event.token,
2514
- accountId: account.accountId
2515
- });
2516
- return;
2517
- }
2518
- if (decoded.kind === "structured") {
2519
- const { envelope } = decoded;
2520
- log(`feishu[${account.accountId}]: handling structured card action ${envelope.a} from ${event.operator.open_id}`);
2521
- if (envelope.a === "feishu.quick_actions.request_approval") {
2522
- const command = typeof envelope.m?.command === "string" ? envelope.m.command.trim() : "";
2523
- if (!command) {
2524
- await sendInvalidInteractionNotice({
2525
- cfg,
2526
- event,
2527
- reason: "malformed",
2528
- accountId
2529
- });
2530
- completeFeishuCardActionToken({
2531
- token: event.token,
2532
- accountId: account.accountId
2533
- });
2534
- return;
2535
- }
2536
- const prompt = typeof envelope.m?.prompt === "string" && envelope.m.prompt.trim() ? envelope.m.prompt : `Run \`${command}\` in this Feishu conversation?`;
2537
- await sendCardFeishu({
2538
- cfg,
2539
- to: resolveCallbackTarget(event),
2540
- card: createApprovalCard({
2541
- operatorOpenId: event.operator.open_id,
2542
- chatId: event.context.chat_id || void 0,
2543
- command,
2544
- prompt,
2545
- sessionKey: envelope.c?.s,
2546
- expiresAt: Date.now() + FEISHU_APPROVAL_CARD_TTL_MS,
2547
- chatType: envelope.c?.t ?? (event.context.chat_id ? "group" : "p2p"),
2548
- confirmLabel: command === "/reset" ? "Reset" : "Confirm"
2549
- }),
2550
- accountId
2551
- });
2552
- completeFeishuCardActionToken({
2553
- token: event.token,
2554
- accountId: account.accountId
2555
- });
2556
- return;
2557
- }
2558
- if (envelope.a === "feishu.approval.cancel") {
2559
- await sendMessageFeishu({
2560
- cfg,
2561
- to: resolveCallbackTarget(event),
2562
- text: "Cancelled.",
2563
- accountId
2564
- });
2565
- completeFeishuCardActionToken({
2566
- token: event.token,
2567
- accountId: account.accountId
2568
- });
2569
- return;
2570
- }
2571
- if (envelope.a === "feishu.approval.confirm" || envelope.k === "quick") {
2572
- const command = envelope.q?.trim();
2573
- if (!command) {
2574
- await sendInvalidInteractionNotice({
2575
- cfg,
2576
- event,
2577
- reason: "malformed",
2578
- accountId
2579
- });
2580
- completeFeishuCardActionToken({
2581
- token: event.token,
2582
- accountId: account.accountId
2583
- });
2584
- return;
2585
- }
2586
- await dispatchSyntheticCommand({
2587
- cfg,
2588
- event,
2589
- command,
2590
- botOpenId: params.botOpenId,
2591
- runtime,
2592
- accountId,
2593
- chatType: envelope.c?.t ?? (event.context.chat_id ? "group" : "p2p")
2594
- });
2595
- completeFeishuCardActionToken({
2596
- token: event.token,
2597
- accountId: account.accountId
2598
- });
2599
- return;
2600
- }
2601
- await sendInvalidInteractionNotice({
2602
- cfg,
2603
- event,
2604
- reason: "malformed",
2605
- accountId
2606
- });
2607
- completeFeishuCardActionToken({
2608
- token: event.token,
2609
- accountId: account.accountId
2610
- });
2611
- return;
2612
- }
2613
- const content = buildFeishuCardActionTextFallback(event);
2614
- log(`feishu[${account.accountId}]: handling card action from ${event.operator.open_id}: ${content}`);
2615
- await dispatchSyntheticCommand({
2616
- cfg,
2617
- event,
2618
- command: content,
2619
- botOpenId: params.botOpenId,
2620
- runtime,
2621
- accountId
2622
- });
2623
- completeFeishuCardActionToken({
2624
- token: event.token,
2625
- accountId: account.accountId
2626
- });
2627
- } catch (err) {
2628
- releaseFeishuCardActionToken({
2629
- token: event.token,
2630
- accountId: account.accountId
2631
- });
2632
- throw err;
2633
- }
2634
- }
2635
- //#endregion
2636
- //#region extensions/feishu/src/card-ux-launcher.ts
2637
- const FEISHU_QUICK_ACTION_CARD_TTL_MS = 10 * 6e4;
2638
- const QUICK_ACTION_MENU_KEYS = new Set([
2639
- "quick-actions",
2640
- "quick_actions",
2641
- "launcher"
2642
- ]);
2643
- function isFeishuQuickActionMenuEventKey(eventKey) {
2644
- return QUICK_ACTION_MENU_KEYS.has(eventKey.trim().toLowerCase());
2645
- }
2646
- function createQuickActionLauncherCard(params) {
2647
- const context = buildFeishuCardInteractionContext(params);
2648
- return {
2649
- schema: "2.0",
2650
- config: { wide_screen_mode: true },
2651
- header: {
2652
- title: {
2653
- tag: "plain_text",
2654
- content: "Quick actions"
2655
- },
2656
- template: "indigo"
2657
- },
2658
- body: { elements: [{
2659
- tag: "markdown",
2660
- content: "Run common actions without typing raw commands."
2661
- }, {
2662
- tag: "action",
2663
- actions: [
2664
- buildFeishuCardButton({
2665
- label: "Help",
2666
- value: createFeishuCardInteractionEnvelope({
2667
- k: "quick",
2668
- a: "feishu.quick_actions.help",
2669
- q: "/help",
2670
- c: context
2671
- })
2672
- }),
2673
- buildFeishuCardButton({
2674
- label: "New session",
2675
- type: "primary",
2676
- value: createFeishuCardInteractionEnvelope({
2677
- k: "meta",
2678
- a: FEISHU_APPROVAL_REQUEST_ACTION,
2679
- m: {
2680
- command: "/new",
2681
- prompt: "Start a fresh session? This will reset the current chat context."
2682
- },
2683
- c: context
2684
- })
2685
- }),
2686
- buildFeishuCardButton({
2687
- label: "Reset",
2688
- type: "danger",
2689
- value: createFeishuCardInteractionEnvelope({
2690
- k: "meta",
2691
- a: FEISHU_APPROVAL_REQUEST_ACTION,
2692
- m: {
2693
- command: "/reset",
2694
- prompt: "Reset this session now? Any active conversation state will be cleared."
2695
- },
2696
- c: context
2697
- })
2698
- })
2699
- ]
2700
- }] }
2701
- };
2702
- }
2703
- async function maybeHandleFeishuQuickActionMenu(params) {
2704
- if (!isFeishuQuickActionMenuEventKey(params.eventKey)) return false;
2705
- const expiresAt = (params.now ?? Date.now()) + FEISHU_QUICK_ACTION_CARD_TTL_MS;
2706
- try {
2707
- await sendCardFeishu({
2708
- cfg: params.cfg,
2709
- to: `user:${params.operatorOpenId}`,
2710
- card: createQuickActionLauncherCard({
2711
- operatorOpenId: params.operatorOpenId,
2712
- expiresAt,
2713
- chatType: "p2p"
2714
- }),
2715
- accountId: params.accountId
2716
- });
2717
- } catch (err) {
2718
- params.runtime?.log?.(`feishu[${params.accountId ?? "default"}]: failed to open quick-action launcher for ${params.operatorOpenId}: ${String(err)}`);
2719
- return false;
2720
- }
2721
- params.runtime?.log?.(`feishu[${params.accountId ?? "default"}]: opened quick-action launcher for ${params.operatorOpenId}`);
2722
- return true;
2723
- }
2724
- function isTimeoutErrorMessage(message) {
2725
- return message?.toLowerCase().includes("timeout") || message?.toLowerCase().includes("timed out") ? true : false;
2726
- }
2727
- function isAbortErrorMessage(message) {
2728
- return message?.toLowerCase().includes("aborted") ?? false;
2729
- }
2730
- async function fetchBotIdentityForMonitor(account, options = {}) {
2731
- if (options.abortSignal?.aborted) return {};
2732
- const timeoutMs = options.timeoutMs ?? 1e4;
2733
- const result = await probeFeishu(account, {
2734
- timeoutMs,
2735
- abortSignal: options.abortSignal
2736
- });
2737
- if (result.ok) return {
2738
- botOpenId: result.botOpenId,
2739
- botName: result.botName
2740
- };
2741
- if (options.abortSignal?.aborted || isAbortErrorMessage(result.error)) return {};
2742
- if (isTimeoutErrorMessage(result.error)) (options.runtime?.error ?? console.error)(`feishu[${account.accountId}]: bot info probe timed out after ${timeoutMs}ms; continuing startup`);
2743
- return {};
2744
- }
2745
- //#endregion
2746
- //#region extensions/feishu/src/monitor.state.ts
2747
- const wsClients = /* @__PURE__ */ new Map();
2748
- const httpServers = /* @__PURE__ */ new Map();
2749
- const botOpenIds = /* @__PURE__ */ new Map();
2750
- const botNames = /* @__PURE__ */ new Map();
2751
- const FEISHU_WEBHOOK_MAX_BODY_BYTES = 1024 * 1024;
2752
- const FEISHU_WEBHOOK_BODY_TIMEOUT_MS = 3e4;
2753
- const FEISHU_WEBHOOK_RATE_LIMIT_FALLBACK_DEFAULTS = {
2754
- windowMs: 6e4,
2755
- maxRequests: 120,
2756
- maxTrackedKeys: 4096
2757
- };
2758
- const FEISHU_WEBHOOK_ANOMALY_FALLBACK_DEFAULTS = {
2759
- maxTrackedKeys: 4096,
2760
- ttlMs: 360 * 6e4,
2761
- logEvery: 25
2762
- };
2763
- function coercePositiveInt(value, fallback) {
2764
- if (typeof value !== "number" || !Number.isFinite(value)) return fallback;
2765
- const normalized = Math.floor(value);
2766
- return normalized > 0 ? normalized : fallback;
2767
- }
2768
- function resolveFeishuWebhookRateLimitDefaultsForTest(defaults) {
2769
- const resolved = defaults;
2770
- return {
2771
- windowMs: coercePositiveInt(resolved?.windowMs, FEISHU_WEBHOOK_RATE_LIMIT_FALLBACK_DEFAULTS.windowMs),
2772
- maxRequests: coercePositiveInt(resolved?.maxRequests, FEISHU_WEBHOOK_RATE_LIMIT_FALLBACK_DEFAULTS.maxRequests),
2773
- maxTrackedKeys: coercePositiveInt(resolved?.maxTrackedKeys, FEISHU_WEBHOOK_RATE_LIMIT_FALLBACK_DEFAULTS.maxTrackedKeys)
2774
- };
2775
- }
2776
- function resolveFeishuWebhookAnomalyDefaultsForTest(defaults) {
2777
- const resolved = defaults;
2778
- return {
2779
- maxTrackedKeys: coercePositiveInt(resolved?.maxTrackedKeys, FEISHU_WEBHOOK_ANOMALY_FALLBACK_DEFAULTS.maxTrackedKeys),
2780
- ttlMs: coercePositiveInt(resolved?.ttlMs, FEISHU_WEBHOOK_ANOMALY_FALLBACK_DEFAULTS.ttlMs),
2781
- logEvery: coercePositiveInt(resolved?.logEvery, FEISHU_WEBHOOK_ANOMALY_FALLBACK_DEFAULTS.logEvery)
2782
- };
2783
- }
2784
- const feishuWebhookRateLimitDefaults = resolveFeishuWebhookRateLimitDefaultsForTest(WEBHOOK_RATE_LIMIT_DEFAULTS);
2785
- const feishuWebhookAnomalyDefaults = resolveFeishuWebhookAnomalyDefaultsForTest(WEBHOOK_ANOMALY_COUNTER_DEFAULTS);
2786
- const feishuWebhookRateLimiter = createFixedWindowRateLimiter({
2787
- windowMs: feishuWebhookRateLimitDefaults.windowMs,
2788
- maxRequests: feishuWebhookRateLimitDefaults.maxRequests,
2789
- maxTrackedKeys: feishuWebhookRateLimitDefaults.maxTrackedKeys
2790
- });
2791
- const feishuWebhookAnomalyTracker = createWebhookAnomalyTracker({
2792
- maxTrackedKeys: feishuWebhookAnomalyDefaults.maxTrackedKeys,
2793
- ttlMs: feishuWebhookAnomalyDefaults.ttlMs,
2794
- logEvery: feishuWebhookAnomalyDefaults.logEvery
2795
- });
2796
- function recordWebhookStatus(runtime, accountId, path, statusCode) {
2797
- feishuWebhookAnomalyTracker.record({
2798
- key: `${accountId}:${path}:${statusCode}`,
2799
- statusCode,
2800
- log: runtime?.log ?? console.log,
2801
- message: (count) => `feishu[${accountId}]: webhook anomaly path=${path} status=${statusCode} count=${count}`
2802
- });
2803
- }
2804
- //#endregion
2805
- //#region extensions/feishu/src/monitor.transport.ts
2806
- function isFeishuWebhookPayload(value) {
2807
- return !!value && typeof value === "object" && !Array.isArray(value);
2808
- }
2809
- function timingSafeEqualString(left, right) {
2810
- const leftBuffer = Buffer.from(left, "utf8");
2811
- const rightBuffer = Buffer.from(right, "utf8");
2812
- if (leftBuffer.length !== rightBuffer.length) return false;
2813
- return crypto.timingSafeEqual(leftBuffer, rightBuffer);
2814
- }
2815
- function buildFeishuWebhookEnvelope(req, payload) {
2816
- return Object.assign(Object.create({ headers: req.headers }), payload);
2817
- }
2818
- function isFeishuWebhookSignatureValid(params) {
2819
- const encryptKey = params.encryptKey?.trim();
2820
- if (!encryptKey) return true;
2821
- const timestampHeader = params.headers["x-lark-request-timestamp"];
2822
- const nonceHeader = params.headers["x-lark-request-nonce"];
2823
- const signatureHeader = params.headers["x-lark-signature"];
2824
- const timestamp = Array.isArray(timestampHeader) ? timestampHeader[0] : timestampHeader;
2825
- const nonce = Array.isArray(nonceHeader) ? nonceHeader[0] : nonceHeader;
2826
- const signature = Array.isArray(signatureHeader) ? signatureHeader[0] : signatureHeader;
2827
- if (!timestamp || !nonce || !signature) return false;
2828
- return timingSafeEqualString(crypto.createHash("sha256").update(timestamp + nonce + encryptKey + JSON.stringify(params.payload)).digest("hex"), signature);
2829
- }
2830
- function respondText(res, statusCode, body) {
2831
- res.statusCode = statusCode;
2832
- res.setHeader("Content-Type", "text/plain; charset=utf-8");
2833
- res.end(body);
2834
- }
2835
- async function monitorWebSocket({ account, accountId, runtime, abortSignal, eventDispatcher }) {
2836
- const log = runtime?.log ?? console.log;
2837
- log(`feishu[${accountId}]: starting WebSocket connection...`);
2838
- const wsClient = createFeishuWSClient(account);
2839
- wsClients.set(accountId, wsClient);
2840
- return new Promise((resolve, reject) => {
2841
- const cleanup = () => {
2842
- wsClients.delete(accountId);
2843
- botOpenIds.delete(accountId);
2844
- botNames.delete(accountId);
2845
- };
2846
- const handleAbort = () => {
2847
- log(`feishu[${accountId}]: abort signal received, stopping`);
2848
- cleanup();
2849
- resolve();
2850
- };
2851
- if (abortSignal?.aborted) {
2852
- cleanup();
2853
- resolve();
2854
- return;
2855
- }
2856
- abortSignal?.addEventListener("abort", handleAbort, { once: true });
2857
- try {
2858
- wsClient.start({ eventDispatcher });
2859
- log(`feishu[${accountId}]: WebSocket client started`);
2860
- } catch (err) {
2861
- cleanup();
2862
- abortSignal?.removeEventListener("abort", handleAbort);
2863
- reject(err);
2864
- }
2865
- });
2866
- }
2867
- async function monitorWebhook({ account, accountId, runtime, abortSignal, eventDispatcher }) {
2868
- const log = runtime?.log ?? console.log;
2869
- const error = runtime?.error ?? console.error;
2870
- const port = account.config.webhookPort ?? 3e3;
2871
- const path = account.config.webhookPath ?? "/feishu/events";
2872
- const host = account.config.webhookHost ?? "127.0.0.1";
2873
- log(`feishu[${accountId}]: starting Webhook server on ${host}:${port}, path ${path}...`);
2874
- const server = http.createServer();
2875
- server.on("request", (req, res) => {
2876
- res.on("finish", () => {
2877
- recordWebhookStatus(runtime, accountId, path, res.statusCode);
2878
- });
2879
- if (!applyBasicWebhookRequestGuards({
2880
- req,
2881
- res,
2882
- rateLimiter: feishuWebhookRateLimiter,
2883
- rateLimitKey: `${accountId}:${path}:${req.socket.remoteAddress ?? "unknown"}`,
2884
- nowMs: Date.now(),
2885
- requireJsonContentType: true
2886
- })) return;
2887
- const guard = installRequestBodyLimitGuard(req, res, {
2888
- maxBytes: FEISHU_WEBHOOK_MAX_BODY_BYTES,
2889
- timeoutMs: FEISHU_WEBHOOK_BODY_TIMEOUT_MS,
2890
- responseFormat: "text"
2891
- });
2892
- if (guard.isTripped()) return;
2893
- (async () => {
2894
- try {
2895
- const bodyResult = await readJsonBodyWithLimit(req, {
2896
- maxBytes: FEISHU_WEBHOOK_MAX_BODY_BYTES,
2897
- timeoutMs: FEISHU_WEBHOOK_BODY_TIMEOUT_MS
2898
- });
2899
- if (guard.isTripped() || res.writableEnded) return;
2900
- if (!bodyResult.ok) {
2901
- if (bodyResult.code === "INVALID_JSON") respondText(res, 400, "Invalid JSON");
2902
- return;
2903
- }
2904
- if (!isFeishuWebhookPayload(bodyResult.value)) {
2905
- respondText(res, 400, "Invalid JSON");
2906
- return;
2907
- }
2908
- if (!isFeishuWebhookSignatureValid({
2909
- headers: req.headers,
2910
- payload: bodyResult.value,
2911
- encryptKey: account.encryptKey
2912
- })) {
2913
- respondText(res, 401, "Invalid signature");
2914
- return;
2915
- }
2916
- const { isChallenge, challenge } = Lark.generateChallenge(bodyResult.value, { encryptKey: account.encryptKey ?? "" });
2917
- if (isChallenge) {
2918
- res.statusCode = 200;
2919
- res.setHeader("Content-Type", "application/json; charset=utf-8");
2920
- res.end(JSON.stringify(challenge));
2921
- return;
2922
- }
2923
- const value = await eventDispatcher.invoke(buildFeishuWebhookEnvelope(req, bodyResult.value), { needCheck: false });
2924
- if (!res.headersSent) {
2925
- res.statusCode = 200;
2926
- res.setHeader("Content-Type", "application/json; charset=utf-8");
2927
- res.end(JSON.stringify(value));
2928
- }
2929
- } catch (err) {
2930
- if (!guard.isTripped()) {
2931
- error(`feishu[${accountId}]: webhook handler error: ${String(err)}`);
2932
- if (!res.headersSent) respondText(res, 500, "Internal Server Error");
2933
- }
2934
- } finally {
2935
- guard.dispose();
2936
- }
2937
- })();
2938
- });
2939
- httpServers.set(accountId, server);
2940
- return new Promise((resolve, reject) => {
2941
- const cleanup = () => {
2942
- server.close();
2943
- httpServers.delete(accountId);
2944
- botOpenIds.delete(accountId);
2945
- botNames.delete(accountId);
2946
- };
2947
- const handleAbort = () => {
2948
- log(`feishu[${accountId}]: abort signal received, stopping Webhook server`);
2949
- cleanup();
2950
- resolve();
2951
- };
2952
- if (abortSignal?.aborted) {
2953
- cleanup();
2954
- resolve();
2955
- return;
2956
- }
2957
- abortSignal?.addEventListener("abort", handleAbort, { once: true });
2958
- server.listen(port, host, () => {
2959
- log(`feishu[${accountId}]: Webhook server listening on ${host}:${port}`);
2960
- });
2961
- server.on("error", (err) => {
2962
- error(`feishu[${accountId}]: Webhook server error: ${err}`);
2963
- abortSignal?.removeEventListener("abort", handleAbort);
2964
- reject(err);
2965
- });
2966
- });
2967
- }
2968
- //#endregion
2969
- //#region extensions/feishu/src/monitor.account.ts
2970
- const FEISHU_REACTION_VERIFY_TIMEOUT_MS = 1500;
2971
- async function resolveReactionSyntheticEvent(params) {
2972
- const { cfg, accountId, event, botOpenId, fetchMessage = getMessageFeishu, verificationTimeoutMs = FEISHU_REACTION_VERIFY_TIMEOUT_MS, logger, uuid = () => crypto$2.randomUUID(), action = "created" } = params;
2973
- const emoji = event.reaction_type?.emoji_type;
2974
- const messageId = event.message_id;
2975
- const senderId = event.user_id?.open_id;
2976
- if (!emoji || !messageId || !senderId) return null;
2977
- const reactionNotifications = resolveFeishuAccount({
2978
- cfg,
2979
- accountId
2980
- }).config.reactionNotifications ?? "own";
2981
- if (reactionNotifications === "off") return null;
2982
- if (event.operator_type === "app" || senderId === botOpenId) return null;
2983
- if (emoji === "Typing") return null;
2984
- if (reactionNotifications === "own" && !botOpenId) {
2985
- logger?.(`feishu[${accountId}]: bot open_id unavailable, skipping reaction ${emoji} on ${messageId}`);
2986
- return null;
2987
- }
2988
- const reactedMsg = await raceWithTimeoutAndAbort(fetchMessage({
2989
- cfg,
2990
- messageId,
2991
- accountId
2992
- }), { timeoutMs: verificationTimeoutMs }).then((result) => result.status === "resolved" ? result.value : null).catch(() => null);
2993
- const isBotMessage = reactedMsg?.senderType === "app" || reactedMsg?.senderOpenId === botOpenId;
2994
- if (!reactedMsg || reactionNotifications === "own" && !isBotMessage) {
2995
- logger?.(`feishu[${accountId}]: ignoring reaction on non-bot/unverified message ${messageId} (sender: ${reactedMsg?.senderOpenId ?? "unknown"})`);
2996
- return null;
2997
- }
2998
- const fallbackChatType = reactedMsg.chatType;
2999
- const resolvedChatType = normalizeFeishuChatType(event.chat_type) ?? fallbackChatType;
3000
- if (!resolvedChatType) {
3001
- logger?.(`feishu[${accountId}]: skipping reaction ${emoji} on ${messageId} without chat type context`);
3002
- return null;
3003
- }
3004
- const syntheticChatIdRaw = event.chat_id ?? reactedMsg.chatId;
3005
- const syntheticChatId = syntheticChatIdRaw?.trim() ? syntheticChatIdRaw : `p2p:${senderId}`;
3006
- const syntheticChatType = resolvedChatType;
3007
- return {
3008
- sender: {
3009
- sender_id: { open_id: senderId },
3010
- sender_type: "user"
3011
- },
3012
- message: {
3013
- message_id: `${messageId}:reaction:${emoji}:${uuid()}`,
3014
- chat_id: syntheticChatId,
3015
- chat_type: syntheticChatType,
3016
- message_type: "text",
3017
- content: JSON.stringify({ text: action === "deleted" ? `[removed reaction ${emoji} from message ${messageId}]` : `[reacted with ${emoji} to message ${messageId}]` })
3018
- }
3019
- };
3020
- }
3021
- function normalizeFeishuChatType(value) {
3022
- return value === "group" || value === "private" || value === "p2p" ? value : void 0;
3023
- }
3024
- /**
3025
- * Per-chat serial queue that ensures messages from the same chat are processed
3026
- * in arrival order while allowing different chats to run concurrently.
3027
- */
3028
- function createChatQueue() {
3029
- const queues = /* @__PURE__ */ new Map();
3030
- return (chatId, task) => {
3031
- const next = (queues.get(chatId) ?? Promise.resolve()).then(task, task);
3032
- queues.set(chatId, next);
3033
- next.finally(() => {
3034
- if (queues.get(chatId) === next) queues.delete(chatId);
3035
- });
3036
- return next;
3037
- };
3038
- }
3039
- function mergeFeishuDebounceMentions(entries) {
3040
- const merged = /* @__PURE__ */ new Map();
3041
- for (const entry of entries) for (const mention of entry.message.mentions ?? []) {
3042
- const stableId = mention.id.open_id?.trim() || mention.id.user_id?.trim() || mention.id.union_id?.trim();
3043
- const mentionName = mention.name?.trim();
3044
- const mentionKey = mention.key?.trim();
3045
- const fallback = mentionName && mentionKey ? `${mentionName}|${mentionKey}` : mentionName || mentionKey;
3046
- const key = stableId || fallback;
3047
- if (!key || merged.has(key)) continue;
3048
- merged.set(key, mention);
3049
- }
3050
- if (merged.size === 0) return;
3051
- return Array.from(merged.values());
3052
- }
3053
- function dedupeFeishuDebounceEntriesByMessageId(entries) {
3054
- const seen = /* @__PURE__ */ new Set();
3055
- const deduped = [];
3056
- for (const entry of entries) {
3057
- const messageId = entry.message.message_id?.trim();
3058
- if (!messageId) {
3059
- deduped.push(entry);
3060
- continue;
3061
- }
3062
- if (seen.has(messageId)) continue;
3063
- seen.add(messageId);
3064
- deduped.push(entry);
3065
- }
3066
- return deduped;
3067
- }
3068
- function resolveFeishuDebounceMentions(params) {
3069
- const { entries, botOpenId } = params;
3070
- if (entries.length === 0) return;
3071
- for (let index = entries.length - 1; index >= 0; index -= 1) {
3072
- const entry = entries[index];
3073
- if (isMentionForwardRequest(entry, botOpenId)) return mergeFeishuDebounceMentions([entry]);
3074
- }
3075
- const merged = mergeFeishuDebounceMentions(entries);
3076
- if (!merged) return;
3077
- const normalizedBotOpenId = botOpenId?.trim();
3078
- if (!normalizedBotOpenId) return;
3079
- const botMentions = merged.filter((mention) => mention.id.open_id?.trim() === normalizedBotOpenId);
3080
- return botMentions.length > 0 ? botMentions : void 0;
3081
- }
3082
- function registerEventHandlers(eventDispatcher, context) {
3083
- const { cfg, accountId, runtime, chatHistories, fireAndForget } = context;
3084
- const core = getFeishuRuntime();
3085
- const inboundDebounceMs = core.channel.debounce.resolveInboundDebounceMs({
3086
- cfg,
3087
- channel: "feishu"
3088
- });
3089
- const log = runtime?.log ?? console.log;
3090
- const error = runtime?.error ?? console.error;
3091
- const enqueue = createChatQueue();
3092
- const runFeishuHandler = async (params) => {
3093
- if (fireAndForget) {
3094
- params.task().catch((err) => {
3095
- error(`${params.errorMessage}: ${String(err)}`);
3096
- });
3097
- return;
3098
- }
3099
- try {
3100
- await params.task();
3101
- } catch (err) {
3102
- error(`${params.errorMessage}: ${String(err)}`);
3103
- }
3104
- };
3105
- const dispatchFeishuMessage = async (event) => {
3106
- const chatId = event.message.chat_id?.trim() || "unknown";
3107
- const task = () => handleFeishuMessage({
3108
- cfg,
3109
- event,
3110
- botOpenId: botOpenIds.get(accountId),
3111
- botName: botNames.get(accountId),
3112
- runtime,
3113
- chatHistories,
3114
- accountId,
3115
- processingClaimHeld: true
3116
- });
3117
- await enqueue(chatId, task);
3118
- };
3119
- const resolveSenderDebounceId = (event) => {
3120
- return event.sender.sender_id.open_id?.trim() || event.sender.sender_id.user_id?.trim() || void 0;
3121
- };
3122
- const resolveDebounceText = (event) => {
3123
- return parseFeishuMessageEvent(event, botOpenIds.get(accountId), botNames.get(accountId)).content.trim();
3124
- };
3125
- const recordSuppressedMessageIds = async (entries, dispatchMessageId) => {
3126
- const keepMessageId = dispatchMessageId?.trim();
3127
- const suppressedIds = new Set(entries.map((entry) => entry.message.message_id?.trim()).filter((id) => Boolean(id) && (!keepMessageId || id !== keepMessageId)));
3128
- if (suppressedIds.size === 0) return;
3129
- for (const messageId of suppressedIds) try {
3130
- await recordProcessedFeishuMessage(messageId, accountId, log);
3131
- } catch (err) {
3132
- error(`feishu[${accountId}]: failed to record merged dedupe id ${messageId}: ${String(err)}`);
3133
- }
3134
- };
3135
- const isMessageAlreadyProcessed = async (entry) => {
3136
- return await hasProcessedFeishuMessage(entry.message.message_id, accountId, log);
3137
- };
3138
- const inboundDebouncer = core.channel.debounce.createInboundDebouncer({
3139
- debounceMs: inboundDebounceMs,
3140
- buildKey: (event) => {
3141
- const chatId = event.message.chat_id?.trim();
3142
- const senderId = resolveSenderDebounceId(event);
3143
- if (!chatId || !senderId) return null;
3144
- const rootId = event.message.root_id?.trim();
3145
- return `feishu:${accountId}:${chatId}:${rootId ? `thread:${rootId}` : "chat"}:${senderId}`;
3146
- },
3147
- shouldDebounce: (event) => {
3148
- if (event.message.message_type !== "text") return false;
3149
- const text = resolveDebounceText(event);
3150
- if (!text) return false;
3151
- return !core.channel.text.hasControlCommand(text, cfg);
3152
- },
3153
- onFlush: async (entries) => {
3154
- const last = entries.at(-1);
3155
- if (!last) return;
3156
- if (entries.length === 1) {
3157
- await dispatchFeishuMessage(last);
3158
- return;
3159
- }
3160
- const dedupedEntries = dedupeFeishuDebounceEntriesByMessageId(entries);
3161
- const freshEntries = [];
3162
- for (const entry of dedupedEntries) if (!await isMessageAlreadyProcessed(entry)) freshEntries.push(entry);
3163
- const dispatchEntry = freshEntries.at(-1);
3164
- if (!dispatchEntry) return;
3165
- await recordSuppressedMessageIds(dedupedEntries, dispatchEntry.message.message_id);
3166
- const combinedText = freshEntries.map((entry) => resolveDebounceText(entry)).filter(Boolean).join("\n");
3167
- const mergedMentions = resolveFeishuDebounceMentions({
3168
- entries: freshEntries,
3169
- botOpenId: botOpenIds.get(accountId)
3170
- });
3171
- if (!combinedText.trim()) {
3172
- await dispatchFeishuMessage({
3173
- ...dispatchEntry,
3174
- message: {
3175
- ...dispatchEntry.message,
3176
- mentions: mergedMentions ?? dispatchEntry.message.mentions
3177
- }
3178
- });
3179
- return;
3180
- }
3181
- await dispatchFeishuMessage({
3182
- ...dispatchEntry,
3183
- message: {
3184
- ...dispatchEntry.message,
3185
- message_type: "text",
3186
- content: JSON.stringify({ text: combinedText }),
3187
- mentions: mergedMentions ?? dispatchEntry.message.mentions
3188
- }
3189
- });
3190
- },
3191
- onError: (err, entries) => {
3192
- for (const entry of entries) releaseFeishuMessageProcessing(entry.message.message_id, accountId);
3193
- error(`feishu[${accountId}]: inbound debounce flush failed: ${String(err)}`);
3194
- }
3195
- });
3196
- eventDispatcher.register({
3197
- "im.message.receive_v1": async (data) => {
3198
- const event = data;
3199
- const messageId = event.message?.message_id?.trim();
3200
- if (!tryBeginFeishuMessageProcessing(messageId, accountId)) {
3201
- log(`feishu[${accountId}]: dropping duplicate event for message ${messageId}`);
3202
- return;
3203
- }
3204
- const processMessage = async () => {
3205
- await inboundDebouncer.enqueue(event);
3206
- };
3207
- if (fireAndForget) {
3208
- processMessage().catch((err) => {
3209
- releaseFeishuMessageProcessing(messageId, accountId);
3210
- error(`feishu[${accountId}]: error handling message: ${String(err)}`);
3211
- });
3212
- return;
3213
- }
3214
- try {
3215
- await processMessage();
3216
- } catch (err) {
3217
- releaseFeishuMessageProcessing(messageId, accountId);
3218
- error(`feishu[${accountId}]: error handling message: ${String(err)}`);
3219
- }
3220
- },
3221
- "im.message.message_read_v1": async () => {},
3222
- "im.chat.member.bot.added_v1": async (data) => {
3223
- try {
3224
- log(`feishu[${accountId}]: bot added to chat ${data.chat_id}`);
3225
- } catch (err) {
3226
- error(`feishu[${accountId}]: error handling bot added event: ${String(err)}`);
3227
- }
3228
- },
3229
- "im.chat.member.bot.deleted_v1": async (data) => {
3230
- try {
3231
- log(`feishu[${accountId}]: bot removed from chat ${data.chat_id}`);
3232
- } catch (err) {
3233
- error(`feishu[${accountId}]: error handling bot removed event: ${String(err)}`);
3234
- }
3235
- },
3236
- "im.message.reaction.created_v1": async (data) => {
3237
- await runFeishuHandler({
3238
- errorMessage: `feishu[${accountId}]: error handling reaction event`,
3239
- task: async () => {
3240
- const event = data;
3241
- const myBotId = botOpenIds.get(accountId);
3242
- const syntheticEvent = await resolveReactionSyntheticEvent({
3243
- cfg,
3244
- accountId,
3245
- event,
3246
- botOpenId: myBotId,
3247
- logger: log
3248
- });
3249
- if (!syntheticEvent) return;
3250
- await handleFeishuMessage({
3251
- cfg,
3252
- event: syntheticEvent,
3253
- botOpenId: myBotId,
3254
- botName: botNames.get(accountId),
3255
- runtime,
3256
- chatHistories,
3257
- accountId
3258
- });
3259
- }
3260
- });
3261
- },
3262
- "im.message.reaction.deleted_v1": async (data) => {
3263
- await runFeishuHandler({
3264
- errorMessage: `feishu[${accountId}]: error handling reaction removal event`,
3265
- task: async () => {
3266
- const event = data;
3267
- const myBotId = botOpenIds.get(accountId);
3268
- const syntheticEvent = await resolveReactionSyntheticEvent({
3269
- cfg,
3270
- accountId,
3271
- event,
3272
- botOpenId: myBotId,
3273
- logger: log,
3274
- action: "deleted"
3275
- });
3276
- if (!syntheticEvent) return;
3277
- await handleFeishuMessage({
3278
- cfg,
3279
- event: syntheticEvent,
3280
- botOpenId: myBotId,
3281
- botName: botNames.get(accountId),
3282
- runtime,
3283
- chatHistories,
3284
- accountId
3285
- });
3286
- }
3287
- });
3288
- },
3289
- "application.bot.menu_v6": async (data) => {
3290
- try {
3291
- const event = data;
3292
- const operatorOpenId = event.operator?.operator_id?.open_id?.trim();
3293
- const eventKey = event.event_key?.trim();
3294
- if (!operatorOpenId || !eventKey) return;
3295
- const syntheticEvent = {
3296
- sender: {
3297
- sender_id: {
3298
- open_id: operatorOpenId,
3299
- user_id: event.operator?.operator_id?.user_id,
3300
- union_id: event.operator?.operator_id?.union_id
3301
- },
3302
- sender_type: "user"
3303
- },
3304
- message: {
3305
- message_id: `bot-menu:${eventKey}:${event.timestamp ?? Date.now()}`,
3306
- chat_id: `p2p:${operatorOpenId}`,
3307
- chat_type: "p2p",
3308
- message_type: "text",
3309
- content: JSON.stringify({ text: `/menu ${eventKey}` })
3310
- }
3311
- };
3312
- const handleLegacyMenu = () => handleFeishuMessage({
3313
- cfg,
3314
- event: syntheticEvent,
3315
- botOpenId: botOpenIds.get(accountId),
3316
- botName: botNames.get(accountId),
3317
- runtime,
3318
- chatHistories,
3319
- accountId
3320
- });
3321
- const promise = maybeHandleFeishuQuickActionMenu({
3322
- cfg,
3323
- eventKey,
3324
- operatorOpenId,
3325
- runtime,
3326
- accountId
3327
- }).then((handledMenu) => {
3328
- if (handledMenu) return;
3329
- return handleLegacyMenu();
3330
- });
3331
- if (fireAndForget) {
3332
- promise.catch((err) => {
3333
- error(`feishu[${accountId}]: error handling bot menu event: ${String(err)}`);
3334
- });
3335
- return;
3336
- }
3337
- await promise;
3338
- } catch (err) {
3339
- error(`feishu[${accountId}]: error handling bot menu event: ${String(err)}`);
3340
- }
3341
- },
3342
- "card.action.trigger": async (data) => {
3343
- try {
3344
- const promise = handleFeishuCardAction({
3345
- cfg,
3346
- event: data,
3347
- botOpenId: botOpenIds.get(accountId),
3348
- runtime,
3349
- accountId
3350
- });
3351
- if (fireAndForget) promise.catch((err) => {
3352
- error(`feishu[${accountId}]: error handling card action: ${String(err)}`);
3353
- });
3354
- else await promise;
3355
- } catch (err) {
3356
- error(`feishu[${accountId}]: error handling card action: ${String(err)}`);
3357
- }
3358
- }
3359
- });
3360
- }
3361
- async function monitorSingleAccount(params) {
3362
- const { cfg, account, runtime, abortSignal } = params;
3363
- const { accountId } = account;
3364
- const log = runtime?.log ?? console.log;
3365
- const botOpenIdSource = params.botOpenIdSource ?? { kind: "fetch" };
3366
- const botIdentity = botOpenIdSource.kind === "prefetched" ? {
3367
- botOpenId: botOpenIdSource.botOpenId,
3368
- botName: botOpenIdSource.botName
3369
- } : await fetchBotIdentityForMonitor(account, {
3370
- runtime,
3371
- abortSignal
3372
- });
3373
- const botOpenId = botIdentity.botOpenId;
3374
- const botName = botIdentity.botName?.trim();
3375
- botOpenIds.set(accountId, botOpenId ?? "");
3376
- if (botName) botNames.set(accountId, botName);
3377
- else botNames.delete(accountId);
3378
- log(`feishu[${accountId}]: bot open_id resolved: ${botOpenId ?? "unknown"}`);
3379
- const connectionMode = account.config.connectionMode ?? "websocket";
3380
- if (connectionMode === "webhook" && !account.verificationToken?.trim()) throw new Error(`Feishu account "${accountId}" webhook mode requires verificationToken`);
3381
- if (connectionMode === "webhook" && !account.encryptKey?.trim()) throw new Error(`Feishu account "${accountId}" webhook mode requires encryptKey`);
3382
- const warmupCount = await warmupDedupFromDisk(accountId, log);
3383
- if (warmupCount > 0) log(`feishu[${accountId}]: dedup warmup loaded ${warmupCount} entries from disk`);
3384
- let threadBindingManager = null;
3385
- try {
3386
- const eventDispatcher = createEventDispatcher(account);
3387
- const chatHistories = /* @__PURE__ */ new Map();
3388
- threadBindingManager = createFeishuThreadBindingManager({
3389
- accountId,
3390
- cfg
3391
- });
3392
- registerEventHandlers(eventDispatcher, {
3393
- cfg,
3394
- accountId,
3395
- runtime,
3396
- chatHistories,
3397
- fireAndForget: true
3398
- });
3399
- if (connectionMode === "webhook") return await monitorWebhook({
3400
- account,
3401
- accountId,
3402
- runtime,
3403
- abortSignal,
3404
- eventDispatcher
3405
- });
3406
- return await monitorWebSocket({
3407
- account,
3408
- accountId,
3409
- runtime,
3410
- abortSignal,
3411
- eventDispatcher
3412
- });
3413
- } finally {
3414
- threadBindingManager?.stop();
3415
- }
3416
- }
3417
- //#endregion
3418
- //#region extensions/feishu/src/monitor.ts
3419
- async function monitorFeishuProvider(opts = {}) {
3420
- const cfg = opts.config;
3421
- if (!cfg) throw new Error("Config is required for Feishu monitor");
3422
- const log = opts.runtime?.log ?? console.log;
3423
- if (opts.accountId) {
3424
- const account = resolveFeishuAccount({
3425
- cfg,
3426
- accountId: opts.accountId
3427
- });
3428
- if (!account.enabled || !account.configured) throw new Error(`Feishu account "${opts.accountId}" not configured or disabled`);
3429
- return monitorSingleAccount({
3430
- cfg,
3431
- account,
3432
- runtime: opts.runtime,
3433
- abortSignal: opts.abortSignal
3434
- });
3435
- }
3436
- const accounts = listEnabledFeishuAccounts(cfg);
3437
- if (accounts.length === 0) throw new Error("No enabled Feishu accounts configured");
3438
- log(`feishu: starting ${accounts.length} account(s): ${accounts.map((a) => a.accountId).join(", ")}`);
3439
- const monitorPromises = [];
3440
- for (const account of accounts) {
3441
- if (opts.abortSignal?.aborted) {
3442
- log("feishu: abort signal received during startup preflight; stopping startup");
3443
- break;
3444
- }
3445
- const { botOpenId, botName } = await fetchBotIdentityForMonitor(account, {
3446
- runtime: opts.runtime,
3447
- abortSignal: opts.abortSignal
3448
- });
3449
- if (opts.abortSignal?.aborted) {
3450
- log("feishu: abort signal received during startup preflight; stopping startup");
3451
- break;
3452
- }
3453
- monitorPromises.push(monitorSingleAccount({
3454
- cfg,
3455
- account,
3456
- runtime: opts.runtime,
3457
- abortSignal: opts.abortSignal,
3458
- botOpenIdSource: {
3459
- kind: "prefetched",
3460
- botOpenId,
3461
- botName
3462
- }
3463
- }));
3464
- }
3465
- await Promise.all(monitorPromises);
3466
- }
3467
- //#endregion
3468
- export { resolveReactionSyntheticEvent as n, getFeishuThreadBindingManager as r, monitorFeishuProvider as t };