@fased/fased 0.1.36 → 0.1.37

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 (244) hide show
  1. package/config/capability-catalog.json +241 -0
  2. package/config/dependency-ownership.json +130 -0
  3. package/config/official-channel-catalog.json +39 -0
  4. package/dist/agents/tools/web-fetch-utils.js +2 -1
  5. package/dist/agents/tools/web-fetch-visibility.js +3 -1
  6. package/dist/brand.js +1 -1
  7. package/dist/browser/pw-session.js +2 -1
  8. package/dist/browser/pw-tools-core.state.js +3 -2
  9. package/dist/browser/runtime-dependency.js +27 -0
  10. package/dist/build-info.json +3 -3
  11. package/dist/canvas-host/a2ui/.bundle.hash +1 -1
  12. package/dist/capabilities/catalog.js +228 -0
  13. package/dist/cli/components-cli.js +105 -0
  14. package/dist/cli/hooks-cli.js +1 -1
  15. package/dist/cli/plugins-cli.js +3 -3
  16. package/dist/cli/program/register.subclis.js +9 -0
  17. package/dist/cli/update-cli/update-command.js +1 -1
  18. package/dist/commands/doctor-capabilities.js +26 -0
  19. package/dist/commands/doctor.js +2 -0
  20. package/dist/control-ui/assets/{app-DXYMrRJ9.js → app-JBrTSsNu.js} +1480 -1465
  21. package/dist/control-ui/assets/{index-iGQkJE0l.js → index-H-2DWAnH.js} +3 -3
  22. package/dist/control-ui/index.html +1 -1
  23. package/dist/gateway/method-scopes.js +1 -0
  24. package/dist/gateway/server-methods/plugins-marketplace.js +1 -1
  25. package/dist/gateway/server-methods/services.js +8 -0
  26. package/dist/gateway/server-methods-list.js +1 -0
  27. package/dist/infra/optional-runtime-dependency.js +46 -0
  28. package/dist/media/image-ops.js +6 -1
  29. package/dist/media/input-files.js +11 -2
  30. package/dist/media/mime.js +6 -1
  31. package/dist/memory/sqlite-vec.js +7 -1
  32. package/dist/plugin-sdk/{accounts-VqAX3HJ0.js → accounts-BwkH5bTD.js} +1 -1
  33. package/dist/plugin-sdk/{accounts-COY-15zJ.js → accounts-C5BjfxoO.js} +1 -1
  34. package/dist/plugin-sdk/{accounts-Zgt0NP54.js → accounts-RT6y7n3H.js} +1 -1
  35. package/dist/plugin-sdk/{actions-lB3PCwsz.js → actions-BrU_JMqM.js} +2 -2
  36. package/dist/plugin-sdk/{actions-BI5QViLk.js → actions-CUdVHzeJ.js} +2 -2
  37. package/dist/plugin-sdk/{active-listener-DKZiSaRA.js → active-listener-CE8t5g6l.js} +1 -1
  38. package/dist/plugin-sdk/{active-listener-D6_pdTMC.js → active-listener-Dx1SEGDn.js} +1 -1
  39. package/dist/plugin-sdk/{audio-preflight-Dx8J7XhV.js → audio-preflight-C8SbY4fV.js} +22 -22
  40. package/dist/plugin-sdk/{audio-preflight-CeRstduc.js → audio-preflight-CuABlLDL.js} +22 -22
  41. package/dist/plugin-sdk/{audit-BImNOQvk.js → audit-DxB2Kml5.js} +11 -11
  42. package/dist/plugin-sdk/{audit-CKWkq0Un.js → audit-sSeRDwJb.js} +11 -11
  43. package/dist/plugin-sdk/channel-plugin-common.js +3 -2
  44. package/dist/plugin-sdk/{chunk-skAJZWCT.js → chunk-KCxbJLsV.js} +1 -1
  45. package/dist/plugin-sdk/{chunk-Cjw4712g.js → chunk-M2d7r-Zt.js} +1 -1
  46. package/dist/plugin-sdk/{chunk-items-Df5811D0.js → chunk-items-BGbYyNvO.js} +1 -1
  47. package/dist/plugin-sdk/command-status.js +22 -22
  48. package/dist/plugin-sdk/{commands-registry-5J619bQ2.js → commands-registry-CdT-nl7v.js} +2 -2
  49. package/dist/plugin-sdk/{commands-registry-CoLAT03J.js → commands-registry-DoWdYAJd.js} +2 -2
  50. package/dist/plugin-sdk/{common-CSTxewqY.js → common-Cpw-vuuM.js} +1 -1
  51. package/dist/plugin-sdk/{common-BiF0sTnY.js → common-DJWrErdE.js} +1 -1
  52. package/dist/plugin-sdk/{config-BxVjLTIv.js → config-C0qggNKQ.js} +7 -7
  53. package/dist/plugin-sdk/{config-TFokWwvO.js → config-CgwTaper.js} +45 -2
  54. package/dist/plugin-sdk/{config-DXlISPlx.js → config-DtqAN2L3.js} +45 -2
  55. package/dist/plugin-sdk/{config-DgD5T-Ui.js → config-g1MG9Bet.js} +7 -7
  56. package/dist/plugin-sdk/discord.js +2 -1
  57. package/dist/plugin-sdk/{fetch-guard-DPMynms8.js → fetch-guard-BLdujDnt.js} +1 -1
  58. package/dist/plugin-sdk/{fetch-guard-COLmW2TM.js → fetch-guard-DTKgMN9f.js} +1 -1
  59. package/dist/plugin-sdk/{handle-action-C-UndB8E.js → handle-action-B61D85yo.js} +12 -12
  60. package/dist/plugin-sdk/{handle-action-hhufKxmU.js → handle-action-CjcxGzQD.js} +12 -12
  61. package/dist/plugin-sdk/index.js +22 -22
  62. package/dist/plugin-sdk/{login-DL1oBBfL.js → login-CB_nCjX3.js} +3 -3
  63. package/dist/plugin-sdk/{login-YveoqEvH.js → login-CfRfRNc7.js} +2 -2
  64. package/dist/plugin-sdk/{login-Dnxas1dI.js → login-CzUuDd1v.js} +3 -3
  65. package/dist/plugin-sdk/{login-qr-CVQsGWKq.js → login-qr-D7MEpFza.js} +3 -3
  66. package/dist/plugin-sdk/{login-qr-B343JNXJ.js → login-qr-DgxfBFVN.js} +3 -3
  67. package/dist/plugin-sdk/{manager-BytwRIfK.js → manager-9see0IX5.js} +8 -3
  68. package/dist/plugin-sdk/{manager-BZjd_PCt.js → manager-D2kZ0Cps.js} +8 -3
  69. package/dist/plugin-sdk/{markdown-tables-krKiU4cT.js → markdown-tables-CCSD52rA.js} +1 -1
  70. package/dist/plugin-sdk/{markdown-tables-9rJDQ1X-.js → markdown-tables-DWUNvLrc.js} +1 -1
  71. package/dist/plugin-sdk/{media-D7ZkWU-A.js → media-C7YT4DeU.js} +13 -4
  72. package/dist/plugin-sdk/{media-C6C2c9a4.js → media-Cxw-xLGU.js} +13 -4
  73. package/dist/plugin-sdk/{monitor-CVQNDfhs.js → monitor-9X7wapUN.js} +27 -27
  74. package/dist/plugin-sdk/{monitor-BCxkQBoh.js → monitor-B3IfJzKX.js} +26 -26
  75. package/dist/plugin-sdk/{monitor-BzDW50H6.js → monitor-CTjAST_W.js} +27 -27
  76. package/dist/plugin-sdk/{monitor-BsLMfn3U.js → monitor-tYFfy2u-.js} +26 -26
  77. package/dist/plugin-sdk/{openresponses-http-BB67Z4QM.js → openresponses-http-DEB2fEya.js} +22 -22
  78. package/dist/plugin-sdk/{openresponses-http-NE76GGhj.js → openresponses-http-YgMg1jnp.js} +22 -22
  79. package/dist/plugin-sdk/{ssrf-u0Ul7okY.js → optional-runtime-dependency-szS49voX.js} +46 -2
  80. package/dist/plugin-sdk/{outbound-PGNWU6T-.js → outbound-BCxOxdi-.js} +6 -6
  81. package/dist/plugin-sdk/{outbound-BHWJD9q0.js → outbound-JIwQbpRY.js} +6 -6
  82. package/dist/plugin-sdk/{outbound-attachment-BVzfhqnk.js → outbound-attachment-C-jSFaEB.js} +1 -1
  83. package/dist/plugin-sdk/{outbound-attachment-ClMvNW17.js → outbound-attachment-D6tj5Y5H.js} +1 -1
  84. package/dist/plugin-sdk/{pi-embedded-runner-DQ6UPx6-.js → pi-embedded-runner-CUVk8CIj.js} +72 -60
  85. package/dist/plugin-sdk/{pi-model-discovery-D51L5E9I.js → pi-model-discovery-DadlvsZW.js} +1 -1
  86. package/dist/plugin-sdk/{pi-model-discovery-runtime-DxoFm4Vd.js → pi-model-discovery-runtime-C5ssE6EW.js} +1 -1
  87. package/dist/plugin-sdk/{pi-model-discovery-runtime-DRuh4PNV.js → pi-model-discovery-runtime-DAaOPt64.js} +2 -2
  88. package/dist/plugin-sdk/{pi-model-discovery-runtime-CQOauapl.js → pi-model-discovery-runtime-LB-5lX5L.js} +1 -1
  89. package/dist/plugin-sdk/{pi-model-discovery-runtime-BTWgkx4x.js → pi-model-discovery-runtime-gd77b0UF.js} +2 -2
  90. package/dist/plugin-sdk/{pi-model-discovery-CkH5l9X5.js → pi-model-discovery-yifTIDIn.js} +1 -1
  91. package/dist/plugin-sdk/{pw-ai-DZs6uYRd.js → pw-ai-SNCI9UXT.js} +6 -5
  92. package/dist/plugin-sdk/{pw-ai-Cn-EUPZK.js → pw-ai-sH1Pi-Fh.js} +6 -5
  93. package/dist/plugin-sdk/{registry-B4HvWzob.js → registry-DNkJsNsz.js} +4 -3
  94. package/dist/plugin-sdk/{replies-jDMUBsNO.js → replies-fvzN5wnU.js} +2 -2
  95. package/dist/plugin-sdk/{replies-B_LW9c9f.js → replies-zebgZCHX.js} +2 -2
  96. package/dist/plugin-sdk/{resolve-route-_YZHbS-z.js → resolve-route-CNhTJG_2.js} +1 -1
  97. package/dist/plugin-sdk/{resolve-route-DlHzggnG.js → resolve-route-DO0WR4nB.js} +1 -1
  98. package/dist/plugin-sdk/{resolve-utils-zBhVX3Vx.js → resolve-utils-EFP1DYqG.js} +1 -1
  99. package/dist/plugin-sdk/{retry-policy-DGLs5ebP.js → retry-policy-BLYEgIwP.js} +1 -1
  100. package/dist/plugin-sdk/{retry-policy-DaodShGa.js → retry-policy-sM01QZT2.js} +1 -1
  101. package/dist/plugin-sdk/{runtime-Dd0sswuW.js → runtime-BPyuAmka.js} +4 -3
  102. package/dist/plugin-sdk/{paths-DW-U2r7Y.js → runtime-dependency-B-1u41Ph.js} +27 -3
  103. package/dist/plugin-sdk/{paths-CBCpJ5bu.js → runtime-dependency-Csswyv5r.js} +27 -3
  104. package/dist/plugin-sdk/sat-runtime.js +1 -0
  105. package/dist/plugin-sdk/{send-8remZhsH.js → send-B09HRfHN.js} +6 -6
  106. package/dist/plugin-sdk/{send-DaaAscWj.js → send-BBYcgXA4.js} +5 -5
  107. package/dist/plugin-sdk/{send-DFTB0cnx.js → send-BQXQA81e.js} +6 -6
  108. package/dist/plugin-sdk/{send-CtMVvMJs.js → send-BzFdvD_i.js} +6 -6
  109. package/dist/plugin-sdk/{send-Di9irjS-.js → send-C3u-F_8s.js} +6 -6
  110. package/dist/plugin-sdk/{send-Dl88ZKq2.js → send-D3836_UN.js} +6 -6
  111. package/dist/plugin-sdk/{send-ifgZCHVB.js → send-D7tr-EsH.js} +5 -5
  112. package/dist/plugin-sdk/{send-DvUpYh0d.js → send-DRGzRdI3.js} +6 -6
  113. package/dist/plugin-sdk/{send-D2jlPeKH.js → send-DfkPKz_0.js} +4 -4
  114. package/dist/plugin-sdk/{send-QSt6nbny.js → send-DsxFXrCO.js} +4 -4
  115. package/dist/plugin-sdk/{session-CknrceVU.js → session-DG_bYisw.js} +2 -2
  116. package/dist/plugin-sdk/{session-CyRTcJ8N.js → session-EIStzK0E.js} +2 -2
  117. package/dist/plugin-sdk/{skill-commands-DHxkTA0s.js → skill-commands-CkgGmWBS.js} +2 -2
  118. package/dist/plugin-sdk/{skill-commands-CLXAG5sU.js → skill-commands-hyZA0LE3.js} +2 -2
  119. package/dist/plugin-sdk/{slack-BpJXkwxF.js → slack-C0WZVJPZ.js} +34 -34
  120. package/dist/plugin-sdk/{slack-Br9c6Yzs.js → slack-DtlPw_PN.js} +34 -34
  121. package/dist/plugin-sdk/{slack-actions-8tLGt1Ht.js → slack-actions-BQawWGTJ.js} +11 -11
  122. package/dist/plugin-sdk/{slack-actions-CDSSRo8Y.js → slack-actions-DDMszx56.js} +11 -11
  123. package/dist/plugin-sdk/slack.js +2 -1
  124. package/dist/plugin-sdk/src/brand.d.ts +2 -2
  125. package/dist/plugin-sdk/src/browser/runtime-dependency.d.ts +3 -0
  126. package/dist/plugin-sdk/src/infra/optional-runtime-dependency.d.ts +6 -0
  127. package/dist/plugin-sdk/{ssrf-fG4UHKBw.js → ssrf-Cce6LubA.js} +41 -7
  128. package/dist/plugin-sdk/{status-DoxnzyMC.js → status-CIiBeb9B.js} +72 -60
  129. package/dist/plugin-sdk/{sticker-cache-zmJ39ByC.js → sticker-cache-9houHChV.js} +3 -3
  130. package/dist/plugin-sdk/{sticker-cache-D7WcMYsF.js → sticker-cache-Dwi-XsgB.js} +3 -3
  131. package/dist/plugin-sdk/{tables-CkxblF0u.js → tables-BD7H5ug-.js} +1 -1
  132. package/dist/plugin-sdk/{tables-RBtf8G4P.js → tables-CJE8kB35.js} +1 -1
  133. package/dist/plugin-sdk/{telegram-actions-DAeYXSLk.js → telegram-actions-Bu1edXF2.js} +25 -25
  134. package/dist/plugin-sdk/{telegram-actions-BDeS3ocd.js → telegram-actions-CRXVO8lG.js} +25 -25
  135. package/dist/plugin-sdk/telegram.js +2 -1
  136. package/dist/plugin-sdk/{thread-bindings.lifecycle-DsB94WbE.js → thread-bindings.lifecycle-Djem8FWF.js} +2 -2
  137. package/dist/plugin-sdk/{thread-bindings.lifecycle-DMhV3TsR.js → thread-bindings.lifecycle-gmHv3hc7.js} +2 -2
  138. package/dist/plugin-sdk/{thread-bindings.state-DYWpy7hJ.js → thread-bindings.state-CNT2vxm3.js} +2 -2
  139. package/dist/plugin-sdk/{thread-bindings.state-DG5cBaRn.js → thread-bindings.state-D8kN2X6H.js} +2 -2
  140. package/dist/plugin-sdk/{web-IJ4NoGPJ.js → web-DCrVQr6y.js} +26 -26
  141. package/dist/plugin-sdk/{web-DJwacWQo.js → web-Ds6OWw3C.js} +26 -26
  142. package/dist/plugin-sdk/{whatsapp-actions-DAY8hWpD.js → whatsapp-actions-68Mfs2dJ.js} +12 -12
  143. package/dist/plugin-sdk/{whatsapp-actions-6opfo-oB.js → whatsapp-actions-DRqtzvTO.js} +12 -12
  144. package/dist/plugin-sdk/whatsapp.js +6 -5
  145. package/dist/plugin-sdk/{wsl-B2euLEc2.js → wsl-DcM2PgSS.js} +3 -3
  146. package/dist/plugin-sdk/{wsl-B8eyviuv.js → wsl-PXrdWitE.js} +3 -3
  147. package/dist/plugins/update.js +1 -1
  148. package/dist/tts/tts-core.js +6 -1
  149. package/dist/wizard/onboarding.finalize.js +9 -0
  150. package/extensions/acpx/package.json +1 -1
  151. package/extensions/bluebubbles/package.json +1 -1
  152. package/extensions/copilot-proxy/package.json +1 -1
  153. package/extensions/diagnostics-otel/package.json +1 -1
  154. package/extensions/fased-federation/package.json +1 -1
  155. package/extensions/google-gemini-cli-auth/package.json +1 -1
  156. package/extensions/imessage/package.json +1 -1
  157. package/extensions/irc/package.json +1 -1
  158. package/extensions/line/package.json +1 -1
  159. package/extensions/llm-task/package.json +1 -1
  160. package/extensions/lobster/package.json +1 -1
  161. package/extensions/matrix/CHANGELOG.md +6 -0
  162. package/extensions/matrix/package.json +1 -1
  163. package/extensions/mattermost/package.json +1 -1
  164. package/extensions/memory-core/package.json +2 -2
  165. package/extensions/memory-lancedb/package.json +1 -1
  166. package/extensions/minimax-portal-auth/package.json +1 -1
  167. package/extensions/msteams/CHANGELOG.md +6 -0
  168. package/extensions/msteams/package.json +1 -1
  169. package/extensions/nextcloud-talk/package.json +1 -1
  170. package/extensions/nostr/CHANGELOG.md +6 -0
  171. package/extensions/nostr/package.json +1 -1
  172. package/extensions/open-prose/package.json +1 -1
  173. package/extensions/sat-mining/package.json +1 -1
  174. package/extensions/signal/package.json +1 -1
  175. package/extensions/synology-chat/package.json +1 -1
  176. package/extensions/tlon/package.json +1 -1
  177. package/extensions/twitch/CHANGELOG.md +6 -0
  178. package/extensions/twitch/package.json +1 -1
  179. package/extensions/voice-call/CHANGELOG.md +6 -0
  180. package/extensions/voice-call/package.json +1 -1
  181. package/extensions/zalo/CHANGELOG.md +6 -0
  182. package/extensions/zalo/package.json +1 -1
  183. package/extensions/zalouser/CHANGELOG.md +6 -0
  184. package/extensions/zalouser/package.json +1 -1
  185. package/package.json +22 -15
  186. package/extensions/feishu/fased.plugin.json +0 -10
  187. package/extensions/feishu/index.ts +0 -63
  188. package/extensions/feishu/package.json +0 -33
  189. package/extensions/feishu/skills/feishu-doc/SKILL.md +0 -211
  190. package/extensions/feishu/skills/feishu-doc/references/block-types.md +0 -103
  191. package/extensions/feishu/skills/feishu-drive/SKILL.md +0 -97
  192. package/extensions/feishu/skills/feishu-perm/SKILL.md +0 -119
  193. package/extensions/feishu/skills/feishu-wiki/SKILL.md +0 -111
  194. package/extensions/feishu/src/accounts.ts +0 -159
  195. package/extensions/feishu/src/bitable.ts +0 -713
  196. package/extensions/feishu/src/bot.ts +0 -979
  197. package/extensions/feishu/src/channel.ts +0 -359
  198. package/extensions/feishu/src/client.ts +0 -118
  199. package/extensions/feishu/src/config-schema.ts +0 -226
  200. package/extensions/feishu/src/dedup.ts +0 -54
  201. package/extensions/feishu/src/directory.ts +0 -177
  202. package/extensions/feishu/src/doc-schema.ts +0 -122
  203. package/extensions/feishu/src/docx.ts +0 -998
  204. package/extensions/feishu/src/drive-schema.ts +0 -46
  205. package/extensions/feishu/src/drive.ts +0 -232
  206. package/extensions/feishu/src/dynamic-agent.ts +0 -131
  207. package/extensions/feishu/src/external-keys.ts +0 -19
  208. package/extensions/feishu/src/media.ts +0 -447
  209. package/extensions/feishu/src/mention.ts +0 -133
  210. package/extensions/feishu/src/monitor.ts +0 -434
  211. package/extensions/feishu/src/onboarding.ts +0 -430
  212. package/extensions/feishu/src/outbound.ts +0 -56
  213. package/extensions/feishu/src/perm-schema.ts +0 -52
  214. package/extensions/feishu/src/perm.ts +0 -180
  215. package/extensions/feishu/src/policy.ts +0 -116
  216. package/extensions/feishu/src/probe.ts +0 -44
  217. package/extensions/feishu/src/reactions.ts +0 -160
  218. package/extensions/feishu/src/reply-dispatcher.ts +0 -239
  219. package/extensions/feishu/src/runtime.ts +0 -14
  220. package/extensions/feishu/src/send-result.ts +0 -29
  221. package/extensions/feishu/src/send-target.ts +0 -25
  222. package/extensions/feishu/src/send.ts +0 -313
  223. package/extensions/feishu/src/streaming-card.ts +0 -218
  224. package/extensions/feishu/src/targets.ts +0 -78
  225. package/extensions/feishu/src/tool-account.ts +0 -58
  226. package/extensions/feishu/src/tools-config.ts +0 -21
  227. package/extensions/feishu/src/types.ts +0 -81
  228. package/extensions/feishu/src/typing.ts +0 -80
  229. package/extensions/feishu/src/wiki-schema.ts +0 -55
  230. package/extensions/feishu/src/wiki.ts +0 -237
  231. package/extensions/googlechat/fased.plugin.json +0 -9
  232. package/extensions/googlechat/index.ts +0 -19
  233. package/extensions/googlechat/package.json +0 -37
  234. package/extensions/googlechat/src/accounts.ts +0 -147
  235. package/extensions/googlechat/src/actions.ts +0 -176
  236. package/extensions/googlechat/src/api.ts +0 -282
  237. package/extensions/googlechat/src/auth.ts +0 -137
  238. package/extensions/googlechat/src/channel.ts +0 -591
  239. package/extensions/googlechat/src/monitor.ts +0 -996
  240. package/extensions/googlechat/src/onboarding.ts +0 -344
  241. package/extensions/googlechat/src/runtime.ts +0 -14
  242. package/extensions/googlechat/src/targets.ts +0 -65
  243. package/extensions/googlechat/src/types.config.ts +0 -3
  244. package/extensions/googlechat/src/types.ts +0 -73
@@ -1,447 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { Readable } from "stream";
4
- import { withTempDownloadPath, type FasedAgentConfig } from "fased/plugin-sdk";
5
- import { resolveFeishuAccount } from "./accounts.js";
6
- import { createFeishuClient } from "./client.js";
7
- import { normalizeFeishuExternalKey } from "./external-keys.js";
8
- import { getFeishuRuntime } from "./runtime.js";
9
- import { assertFeishuMessageApiSuccess, toFeishuSendResult } from "./send-result.js";
10
- import { resolveFeishuSendTarget } from "./send-target.js";
11
-
12
- export type DownloadImageResult = {
13
- buffer: Buffer;
14
- contentType?: string;
15
- };
16
-
17
- export type DownloadMessageResourceResult = {
18
- buffer: Buffer;
19
- contentType?: string;
20
- fileName?: string;
21
- };
22
-
23
- async function readFeishuResponseBuffer(params: {
24
- response: unknown;
25
- tmpDirPrefix: string;
26
- errorPrefix: string;
27
- }): Promise<Buffer> {
28
- const { response } = params;
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- SDK response type
30
- const responseAny = response as any;
31
- if (responseAny.code !== undefined && responseAny.code !== 0) {
32
- throw new Error(`${params.errorPrefix}: ${responseAny.msg || `code ${responseAny.code}`}`);
33
- }
34
-
35
- if (Buffer.isBuffer(response)) {
36
- return response;
37
- }
38
- if (response instanceof ArrayBuffer) {
39
- return Buffer.from(response);
40
- }
41
- if (responseAny.data && Buffer.isBuffer(responseAny.data)) {
42
- return responseAny.data;
43
- }
44
- if (responseAny.data instanceof ArrayBuffer) {
45
- return Buffer.from(responseAny.data);
46
- }
47
- if (typeof responseAny.getReadableStream === "function") {
48
- const stream = responseAny.getReadableStream();
49
- const chunks: Buffer[] = [];
50
- for await (const chunk of stream) {
51
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
52
- }
53
- return Buffer.concat(chunks);
54
- }
55
- if (typeof responseAny.writeFile === "function") {
56
- return await withTempDownloadPath({ prefix: params.tmpDirPrefix }, async (tmpPath) => {
57
- await responseAny.writeFile(tmpPath);
58
- return await fs.promises.readFile(tmpPath);
59
- });
60
- }
61
- if (typeof responseAny[Symbol.asyncIterator] === "function") {
62
- const chunks: Buffer[] = [];
63
- for await (const chunk of responseAny) {
64
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
65
- }
66
- return Buffer.concat(chunks);
67
- }
68
- if (typeof responseAny.read === "function") {
69
- const chunks: Buffer[] = [];
70
- for await (const chunk of responseAny as Readable) {
71
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
72
- }
73
- return Buffer.concat(chunks);
74
- }
75
-
76
- const keys = Object.keys(responseAny);
77
- const types = keys.map((k) => `${k}: ${typeof responseAny[k]}`).join(", ");
78
- throw new Error(`${params.errorPrefix}: unexpected response format. Keys: [${types}]`);
79
- }
80
-
81
- /**
82
- * Download an image from Feishu using image_key.
83
- * Used for downloading images sent in messages.
84
- */
85
- export async function downloadImageFeishu(params: {
86
- cfg: FasedAgentConfig;
87
- imageKey: string;
88
- accountId?: string;
89
- }): Promise<DownloadImageResult> {
90
- const { cfg, imageKey, accountId } = params;
91
- const normalizedImageKey = normalizeFeishuExternalKey(imageKey);
92
- if (!normalizedImageKey) {
93
- throw new Error("Feishu image download failed: invalid image_key");
94
- }
95
- const account = resolveFeishuAccount({ cfg, accountId });
96
- if (!account.configured) {
97
- throw new Error(`Feishu account "${account.accountId}" not configured`);
98
- }
99
-
100
- const client = createFeishuClient(account);
101
-
102
- const response = await client.im.image.get({
103
- path: { image_key: normalizedImageKey },
104
- });
105
-
106
- const buffer = await readFeishuResponseBuffer({
107
- response,
108
- tmpDirPrefix: "fased-feishu-img-",
109
- errorPrefix: "Feishu image download failed",
110
- });
111
- return { buffer };
112
- }
113
-
114
- /**
115
- * Download a message resource (file/image/audio/video) from Feishu.
116
- * Used for downloading files, audio, and video from messages.
117
- */
118
- export async function downloadMessageResourceFeishu(params: {
119
- cfg: FasedAgentConfig;
120
- messageId: string;
121
- fileKey: string;
122
- type: "image" | "file";
123
- accountId?: string;
124
- }): Promise<DownloadMessageResourceResult> {
125
- const { cfg, messageId, fileKey, type, accountId } = params;
126
- const normalizedFileKey = normalizeFeishuExternalKey(fileKey);
127
- if (!normalizedFileKey) {
128
- throw new Error("Feishu message resource download failed: invalid file_key");
129
- }
130
- const account = resolveFeishuAccount({ cfg, accountId });
131
- if (!account.configured) {
132
- throw new Error(`Feishu account "${account.accountId}" not configured`);
133
- }
134
-
135
- const client = createFeishuClient(account);
136
-
137
- const response = await client.im.messageResource.get({
138
- path: { message_id: messageId, file_key: normalizedFileKey },
139
- params: { type },
140
- });
141
-
142
- const buffer = await readFeishuResponseBuffer({
143
- response,
144
- tmpDirPrefix: "fased-feishu-resource-",
145
- errorPrefix: "Feishu message resource download failed",
146
- });
147
- return { buffer };
148
- }
149
-
150
- export type UploadImageResult = {
151
- imageKey: string;
152
- };
153
-
154
- export type UploadFileResult = {
155
- fileKey: string;
156
- };
157
-
158
- export type SendMediaResult = {
159
- messageId: string;
160
- chatId: string;
161
- };
162
-
163
- /**
164
- * Upload an image to Feishu and get an image_key for sending.
165
- * Supports: JPEG, PNG, WEBP, GIF, TIFF, BMP, ICO
166
- */
167
- export async function uploadImageFeishu(params: {
168
- cfg: FasedAgentConfig;
169
- image: Buffer | string; // Buffer or file path
170
- imageType?: "message" | "avatar";
171
- accountId?: string;
172
- }): Promise<UploadImageResult> {
173
- const { cfg, image, imageType = "message", accountId } = params;
174
- const account = resolveFeishuAccount({ cfg, accountId });
175
- if (!account.configured) {
176
- throw new Error(`Feishu account "${account.accountId}" not configured`);
177
- }
178
-
179
- const client = createFeishuClient(account);
180
-
181
- // SDK accepts Buffer directly or fs.ReadStream for file paths
182
- // Using Readable.from(buffer) causes issues with form-data library
183
- // See: https://github.com/larksuite/node-sdk/issues/121
184
- const imageData = typeof image === "string" ? fs.createReadStream(image) : image;
185
-
186
- const response = await client.im.image.create({
187
- data: {
188
- image_type: imageType,
189
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- SDK accepts Buffer or ReadStream
190
- image: imageData as any,
191
- },
192
- });
193
-
194
- // SDK v1.30+ returns data directly without code wrapper on success
195
- // On error, it throws or returns { code, msg }
196
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- SDK response type
197
- const responseAny = response as any;
198
- if (responseAny.code !== undefined && responseAny.code !== 0) {
199
- throw new Error(`Feishu image upload failed: ${responseAny.msg || `code ${responseAny.code}`}`);
200
- }
201
-
202
- const imageKey = responseAny.image_key ?? responseAny.data?.image_key;
203
- if (!imageKey) {
204
- throw new Error("Feishu image upload failed: no image_key returned");
205
- }
206
-
207
- return { imageKey };
208
- }
209
-
210
- /**
211
- * Upload a file to Feishu and get a file_key for sending.
212
- * Max file size: 30MB
213
- */
214
- export async function uploadFileFeishu(params: {
215
- cfg: FasedAgentConfig;
216
- file: Buffer | string; // Buffer or file path
217
- fileName: string;
218
- fileType: "opus" | "mp4" | "pdf" | "doc" | "xls" | "ppt" | "stream";
219
- duration?: number; // Required for audio/video files, in milliseconds
220
- accountId?: string;
221
- }): Promise<UploadFileResult> {
222
- const { cfg, file, fileName, fileType, duration, accountId } = params;
223
- const account = resolveFeishuAccount({ cfg, accountId });
224
- if (!account.configured) {
225
- throw new Error(`Feishu account "${account.accountId}" not configured`);
226
- }
227
-
228
- const client = createFeishuClient(account);
229
-
230
- // SDK accepts Buffer directly or fs.ReadStream for file paths
231
- // Using Readable.from(buffer) causes issues with form-data library
232
- // See: https://github.com/larksuite/node-sdk/issues/121
233
- const fileData = typeof file === "string" ? fs.createReadStream(file) : file;
234
-
235
- const response = await client.im.file.create({
236
- data: {
237
- file_type: fileType,
238
- file_name: fileName,
239
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- SDK accepts Buffer or ReadStream
240
- file: fileData as any,
241
- ...(duration !== undefined && { duration }),
242
- },
243
- });
244
-
245
- // SDK v1.30+ returns data directly without code wrapper on success
246
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- SDK response type
247
- const responseAny = response as any;
248
- if (responseAny.code !== undefined && responseAny.code !== 0) {
249
- throw new Error(`Feishu file upload failed: ${responseAny.msg || `code ${responseAny.code}`}`);
250
- }
251
-
252
- const fileKey = responseAny.file_key ?? responseAny.data?.file_key;
253
- if (!fileKey) {
254
- throw new Error("Feishu file upload failed: no file_key returned");
255
- }
256
-
257
- return { fileKey };
258
- }
259
-
260
- /**
261
- * Send an image message using an image_key
262
- */
263
- export async function sendImageFeishu(params: {
264
- cfg: FasedAgentConfig;
265
- to: string;
266
- imageKey: string;
267
- replyToMessageId?: string;
268
- accountId?: string;
269
- }): Promise<SendMediaResult> {
270
- const { cfg, to, imageKey, replyToMessageId, accountId } = params;
271
- const { client, receiveId, receiveIdType } = resolveFeishuSendTarget({
272
- cfg,
273
- to,
274
- accountId,
275
- });
276
- const content = JSON.stringify({ image_key: imageKey });
277
-
278
- if (replyToMessageId) {
279
- const response = await client.im.message.reply({
280
- path: { message_id: replyToMessageId },
281
- data: {
282
- content,
283
- msg_type: "image",
284
- },
285
- });
286
- assertFeishuMessageApiSuccess(response, "Feishu image reply failed");
287
- return toFeishuSendResult(response, receiveId);
288
- }
289
-
290
- const response = await client.im.message.create({
291
- params: { receive_id_type: receiveIdType },
292
- data: {
293
- receive_id: receiveId,
294
- content,
295
- msg_type: "image",
296
- },
297
- });
298
- assertFeishuMessageApiSuccess(response, "Feishu image send failed");
299
- return toFeishuSendResult(response, receiveId);
300
- }
301
-
302
- /**
303
- * Send a file message using a file_key
304
- */
305
- export async function sendFileFeishu(params: {
306
- cfg: FasedAgentConfig;
307
- to: string;
308
- fileKey: string;
309
- /** Use "media" for audio/video files, "file" for documents */
310
- msgType?: "file" | "media";
311
- replyToMessageId?: string;
312
- accountId?: string;
313
- }): Promise<SendMediaResult> {
314
- const { cfg, to, fileKey, replyToMessageId, accountId } = params;
315
- const msgType = params.msgType ?? "file";
316
- const { client, receiveId, receiveIdType } = resolveFeishuSendTarget({
317
- cfg,
318
- to,
319
- accountId,
320
- });
321
- const content = JSON.stringify({ file_key: fileKey });
322
-
323
- if (replyToMessageId) {
324
- const response = await client.im.message.reply({
325
- path: { message_id: replyToMessageId },
326
- data: {
327
- content,
328
- msg_type: msgType,
329
- },
330
- });
331
- assertFeishuMessageApiSuccess(response, "Feishu file reply failed");
332
- return toFeishuSendResult(response, receiveId);
333
- }
334
-
335
- const response = await client.im.message.create({
336
- params: { receive_id_type: receiveIdType },
337
- data: {
338
- receive_id: receiveId,
339
- content,
340
- msg_type: msgType,
341
- },
342
- });
343
- assertFeishuMessageApiSuccess(response, "Feishu file send failed");
344
- return toFeishuSendResult(response, receiveId);
345
- }
346
-
347
- /**
348
- * Helper to detect file type from extension
349
- */
350
- export function detectFileType(
351
- fileName: string,
352
- ): "opus" | "mp4" | "pdf" | "doc" | "xls" | "ppt" | "stream" {
353
- const ext = path.extname(fileName).toLowerCase();
354
- switch (ext) {
355
- case ".opus":
356
- case ".ogg":
357
- return "opus";
358
- case ".mp4":
359
- case ".mov":
360
- case ".avi":
361
- return "mp4";
362
- case ".pdf":
363
- return "pdf";
364
- case ".doc":
365
- case ".docx":
366
- return "doc";
367
- case ".xls":
368
- case ".xlsx":
369
- return "xls";
370
- case ".ppt":
371
- case ".pptx":
372
- return "ppt";
373
- default:
374
- return "stream";
375
- }
376
- }
377
-
378
- /**
379
- * Upload and send media (image or file) from URL, local path, or buffer.
380
- * When mediaUrl is a local path, mediaLocalRoots (from core outbound context)
381
- * must be passed so loadWebMedia allows the path (post CVE-2026-26321).
382
- */
383
- export async function sendMediaFeishu(params: {
384
- cfg: FasedAgentConfig;
385
- to: string;
386
- mediaUrl?: string;
387
- mediaBuffer?: Buffer;
388
- fileName?: string;
389
- replyToMessageId?: string;
390
- accountId?: string;
391
- /** Allowed roots for local path reads; required for local filePath to work. */
392
- mediaLocalRoots?: readonly string[];
393
- }): Promise<SendMediaResult> {
394
- const { cfg, to, mediaUrl, mediaBuffer, fileName, replyToMessageId, accountId, mediaLocalRoots } =
395
- params;
396
- const account = resolveFeishuAccount({ cfg, accountId });
397
- if (!account.configured) {
398
- throw new Error(`Feishu account "${account.accountId}" not configured`);
399
- }
400
- const mediaMaxBytes = (account.config?.mediaMaxMb ?? 30) * 1024 * 1024;
401
-
402
- let buffer: Buffer;
403
- let name: string;
404
-
405
- if (mediaBuffer) {
406
- buffer = mediaBuffer;
407
- name = fileName ?? "file";
408
- } else if (mediaUrl) {
409
- const loaded = await getFeishuRuntime().media.loadWebMedia(mediaUrl, {
410
- maxBytes: mediaMaxBytes,
411
- optimizeImages: false,
412
- localRoots: mediaLocalRoots?.length ? mediaLocalRoots : undefined,
413
- });
414
- buffer = loaded.buffer;
415
- name = fileName ?? loaded.fileName ?? "file";
416
- } else {
417
- throw new Error("Either mediaUrl or mediaBuffer must be provided");
418
- }
419
-
420
- // Determine if it's an image based on extension
421
- const ext = path.extname(name).toLowerCase();
422
- const isImage = [".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp", ".ico", ".tiff"].includes(ext);
423
-
424
- if (isImage) {
425
- const { imageKey } = await uploadImageFeishu({ cfg, image: buffer, accountId });
426
- return sendImageFeishu({ cfg, to, imageKey, replyToMessageId, accountId });
427
- } else {
428
- const fileType = detectFileType(name);
429
- const { fileKey } = await uploadFileFeishu({
430
- cfg,
431
- file: buffer,
432
- fileName: name,
433
- fileType,
434
- accountId,
435
- });
436
- // Feishu requires msg_type "media" for audio/video, "file" for documents
437
- const isMedia = fileType === "mp4" || fileType === "opus";
438
- return sendFileFeishu({
439
- cfg,
440
- to,
441
- fileKey,
442
- msgType: isMedia ? "media" : "file",
443
- replyToMessageId,
444
- accountId,
445
- });
446
- }
447
- }
@@ -1,133 +0,0 @@
1
- import type { FeishuMessageEvent } from "./bot.js";
2
-
3
- /**
4
- * Escape regex metacharacters so user-controlled mention fields are treated literally.
5
- */
6
- export function escapeRegExp(input: string): string {
7
- return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
8
- }
9
-
10
- /**
11
- * Mention target user info
12
- */
13
- export type MentionTarget = {
14
- openId: string;
15
- name: string;
16
- key: string; // Placeholder in original message, e.g. @_user_1
17
- };
18
-
19
- /**
20
- * Extract mention targets from message event (excluding the bot itself)
21
- */
22
- export function extractMentionTargets(
23
- event: FeishuMessageEvent,
24
- botOpenId?: string,
25
- ): MentionTarget[] {
26
- const mentions = event.message.mentions ?? [];
27
-
28
- return mentions
29
- .filter((m) => {
30
- // Exclude the bot itself
31
- if (botOpenId && m.id.open_id === botOpenId) {
32
- return false;
33
- }
34
- // Must have open_id
35
- return !!m.id.open_id;
36
- })
37
- .map((m) => ({
38
- openId: m.id.open_id!,
39
- name: m.name,
40
- key: m.key,
41
- }));
42
- }
43
-
44
- /**
45
- * Check if message is a mention forward request
46
- * Rules:
47
- * - Group: message mentions bot + at least one other user
48
- * - DM: message mentions any user (no need to mention bot)
49
- */
50
- export function isMentionForwardRequest(event: FeishuMessageEvent, botOpenId?: string): boolean {
51
- const mentions = event.message.mentions ?? [];
52
- if (mentions.length === 0) {
53
- return false;
54
- }
55
-
56
- const isDirectMessage = event.message.chat_type === "p2p";
57
- const hasOtherMention = mentions.some((m) => m.id.open_id !== botOpenId);
58
-
59
- if (isDirectMessage) {
60
- // DM: trigger if any non-bot user is mentioned
61
- return hasOtherMention;
62
- } else {
63
- // Group: need to mention both bot and other users
64
- const hasBotMention = mentions.some((m) => m.id.open_id === botOpenId);
65
- return hasBotMention && hasOtherMention;
66
- }
67
- }
68
-
69
- /**
70
- * Extract message body from text (remove @ placeholders)
71
- */
72
- export function extractMessageBody(text: string, allMentionKeys: string[]): string {
73
- let result = text;
74
-
75
- // Remove all @ placeholders
76
- for (const key of allMentionKeys) {
77
- result = result.replace(new RegExp(escapeRegExp(key), "g"), "");
78
- }
79
-
80
- return result.replace(/\s+/g, " ").trim();
81
- }
82
-
83
- /**
84
- * Format @mention for text message
85
- */
86
- export function formatMentionForText(target: MentionTarget): string {
87
- return `<at user_id="${target.openId}">${target.name}</at>`;
88
- }
89
-
90
- /**
91
- * Format @everyone for text message
92
- */
93
- export function formatMentionAllForText(): string {
94
- return `<at user_id="all">Everyone</at>`;
95
- }
96
-
97
- /**
98
- * Format @mention for card message (lark_md)
99
- */
100
- export function formatMentionForCard(target: MentionTarget): string {
101
- return `<at id=${target.openId}></at>`;
102
- }
103
-
104
- /**
105
- * Format @everyone for card message
106
- */
107
- export function formatMentionAllForCard(): string {
108
- return `<at id=all></at>`;
109
- }
110
-
111
- /**
112
- * Build complete message with @mentions (text format)
113
- */
114
- export function buildMentionedMessage(targets: MentionTarget[], message: string): string {
115
- if (targets.length === 0) {
116
- return message;
117
- }
118
-
119
- const mentionParts = targets.map((t) => formatMentionForText(t));
120
- return `${mentionParts.join(" ")} ${message}`;
121
- }
122
-
123
- /**
124
- * Build card content with @mentions (Markdown format)
125
- */
126
- export function buildMentionedCardContent(targets: MentionTarget[], message: string): string {
127
- if (targets.length === 0) {
128
- return message;
129
- }
130
-
131
- const mentionParts = targets.map((t) => formatMentionForCard(t));
132
- return `${mentionParts.join(" ")} ${message}`;
133
- }