@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,713 +0,0 @@
1
- import type * as Lark from "@larksuiteoapi/node-sdk";
2
- import { Type } from "@sinclair/typebox";
3
- import type { FasedAgentPluginApi } from "fased/plugin-sdk";
4
- import { listEnabledFeishuAccounts } from "./accounts.js";
5
- import { createFeishuToolClient } from "./tool-account.js";
6
-
7
- // ============ Helpers ============
8
-
9
- function json(data: unknown) {
10
- return {
11
- content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }],
12
- details: data,
13
- };
14
- }
15
-
16
- /** Field type ID to human-readable name */
17
- const FIELD_TYPE_NAMES: Record<number, string> = {
18
- 1: "Text",
19
- 2: "Number",
20
- 3: "SingleSelect",
21
- 4: "MultiSelect",
22
- 5: "DateTime",
23
- 7: "Checkbox",
24
- 11: "User",
25
- 13: "Phone",
26
- 15: "URL",
27
- 17: "Attachment",
28
- 18: "SingleLink",
29
- 19: "Lookup",
30
- 20: "Formula",
31
- 21: "DuplexLink",
32
- 22: "Location",
33
- 23: "GroupChat",
34
- 1001: "CreatedTime",
35
- 1002: "ModifiedTime",
36
- 1003: "CreatedUser",
37
- 1004: "ModifiedUser",
38
- 1005: "AutoNumber",
39
- };
40
-
41
- // ============ Core Functions ============
42
-
43
- /** Parse bitable URL and extract tokens */
44
- function parseBitableUrl(url: string): { token: string; tableId?: string; isWiki: boolean } | null {
45
- try {
46
- const u = new URL(url);
47
- const tableId = u.searchParams.get("table") ?? undefined;
48
-
49
- // Wiki format: /wiki/XXXXX?table=YYY
50
- const wikiMatch = u.pathname.match(/\/wiki\/([A-Za-z0-9]+)/);
51
- if (wikiMatch) {
52
- return { token: wikiMatch[1], tableId, isWiki: true };
53
- }
54
-
55
- // Base format: /base/XXXXX?table=YYY
56
- const baseMatch = u.pathname.match(/\/base\/([A-Za-z0-9]+)/);
57
- if (baseMatch) {
58
- return { token: baseMatch[1], tableId, isWiki: false };
59
- }
60
-
61
- return null;
62
- } catch {
63
- return null;
64
- }
65
- }
66
-
67
- /** Get app_token from wiki node_token */
68
- async function getAppTokenFromWiki(client: Lark.Client, nodeToken: string): Promise<string> {
69
- const res = await client.wiki.space.getNode({
70
- params: { token: nodeToken },
71
- });
72
- if (res.code !== 0) {
73
- throw new Error(res.msg);
74
- }
75
-
76
- const node = res.data?.node;
77
- if (!node) {
78
- throw new Error("Node not found");
79
- }
80
- if (node.obj_type !== "bitable") {
81
- throw new Error(`Node is not a bitable (type: ${node.obj_type})`);
82
- }
83
-
84
- return node.obj_token!;
85
- }
86
-
87
- /** Get bitable metadata from URL (handles both /base/ and /wiki/ URLs) */
88
- async function getBitableMeta(client: Lark.Client, url: string) {
89
- const parsed = parseBitableUrl(url);
90
- if (!parsed) {
91
- throw new Error("Invalid URL format. Expected /base/XXX or /wiki/XXX URL");
92
- }
93
-
94
- let appToken: string;
95
- if (parsed.isWiki) {
96
- appToken = await getAppTokenFromWiki(client, parsed.token);
97
- } else {
98
- appToken = parsed.token;
99
- }
100
-
101
- // Get bitable app info
102
- const res = await client.bitable.app.get({
103
- path: { app_token: appToken },
104
- });
105
- if (res.code !== 0) {
106
- throw new Error(res.msg);
107
- }
108
-
109
- // List tables if no table_id specified
110
- let tables: { table_id: string; name: string }[] = [];
111
- if (!parsed.tableId) {
112
- const tablesRes = await client.bitable.appTable.list({
113
- path: { app_token: appToken },
114
- });
115
- if (tablesRes.code === 0) {
116
- tables = (tablesRes.data?.items ?? []).map((t) => ({
117
- table_id: t.table_id!,
118
- name: t.name!,
119
- }));
120
- }
121
- }
122
-
123
- return {
124
- app_token: appToken,
125
- table_id: parsed.tableId,
126
- name: res.data?.app?.name,
127
- url_type: parsed.isWiki ? "wiki" : "base",
128
- ...(tables.length > 0 && { tables }),
129
- hint: parsed.tableId
130
- ? `Use app_token="${appToken}" and table_id="${parsed.tableId}" for other bitable tools`
131
- : `Use app_token="${appToken}" for other bitable tools. Select a table_id from the tables list.`,
132
- };
133
- }
134
-
135
- async function listFields(client: Lark.Client, appToken: string, tableId: string) {
136
- const res = await client.bitable.appTableField.list({
137
- path: { app_token: appToken, table_id: tableId },
138
- });
139
- if (res.code !== 0) {
140
- throw new Error(res.msg);
141
- }
142
-
143
- const fields = res.data?.items ?? [];
144
- return {
145
- fields: fields.map((f) => ({
146
- field_id: f.field_id,
147
- field_name: f.field_name,
148
- type: f.type,
149
- type_name: FIELD_TYPE_NAMES[f.type ?? 0] || `type_${f.type}`,
150
- is_primary: f.is_primary,
151
- ...(f.property && { property: f.property }),
152
- })),
153
- total: fields.length,
154
- };
155
- }
156
-
157
- async function listRecords(
158
- client: Lark.Client,
159
- appToken: string,
160
- tableId: string,
161
- pageSize?: number,
162
- pageToken?: string,
163
- ) {
164
- const res = await client.bitable.appTableRecord.list({
165
- path: { app_token: appToken, table_id: tableId },
166
- params: {
167
- page_size: pageSize ?? 100,
168
- ...(pageToken && { page_token: pageToken }),
169
- },
170
- });
171
- if (res.code !== 0) {
172
- throw new Error(res.msg);
173
- }
174
-
175
- return {
176
- records: res.data?.items ?? [],
177
- has_more: res.data?.has_more ?? false,
178
- page_token: res.data?.page_token,
179
- total: res.data?.total,
180
- };
181
- }
182
-
183
- async function getRecord(client: Lark.Client, appToken: string, tableId: string, recordId: string) {
184
- const res = await client.bitable.appTableRecord.get({
185
- path: { app_token: appToken, table_id: tableId, record_id: recordId },
186
- });
187
- if (res.code !== 0) {
188
- throw new Error(res.msg);
189
- }
190
-
191
- return {
192
- record: res.data?.record,
193
- };
194
- }
195
-
196
- async function createRecord(
197
- client: Lark.Client,
198
- appToken: string,
199
- tableId: string,
200
- fields: Record<string, unknown>,
201
- ) {
202
- const res = await client.bitable.appTableRecord.create({
203
- path: { app_token: appToken, table_id: tableId },
204
- // oxlint-disable-next-line typescript/no-explicit-any
205
- data: { fields: fields as any },
206
- });
207
- if (res.code !== 0) {
208
- throw new Error(res.msg);
209
- }
210
-
211
- return {
212
- record: res.data?.record,
213
- };
214
- }
215
-
216
- /** Logger interface for cleanup operations */
217
- type CleanupLogger = {
218
- debug: (msg: string) => void;
219
- warn: (msg: string) => void;
220
- };
221
-
222
- /** Default field types created for new Bitable tables (to be cleaned up) */
223
- const DEFAULT_CLEANUP_FIELD_TYPES = new Set([3, 5, 17]); // SingleSelect, DateTime, Attachment
224
-
225
- /** Clean up default placeholder rows and fields in a newly created Bitable table */
226
- async function cleanupNewBitable(
227
- client: Lark.Client,
228
- appToken: string,
229
- tableId: string,
230
- tableName: string,
231
- logger: CleanupLogger,
232
- ): Promise<{ cleanedRows: number; cleanedFields: number }> {
233
- let cleanedRows = 0;
234
- let cleanedFields = 0;
235
-
236
- // Step 1: Clean up default fields
237
- const fieldsRes = await client.bitable.appTableField.list({
238
- path: { app_token: appToken, table_id: tableId },
239
- });
240
-
241
- if (fieldsRes.code === 0 && fieldsRes.data?.items) {
242
- // Step 1a: Rename primary field to the table name (works for both Feishu and Lark)
243
- const primaryField = fieldsRes.data.items.find((f) => f.is_primary);
244
- if (primaryField?.field_id) {
245
- try {
246
- const newFieldName = tableName.length <= 20 ? tableName : "Name";
247
- await client.bitable.appTableField.update({
248
- path: {
249
- app_token: appToken,
250
- table_id: tableId,
251
- field_id: primaryField.field_id,
252
- },
253
- data: {
254
- field_name: newFieldName,
255
- type: 1,
256
- },
257
- });
258
- cleanedFields++;
259
- } catch (err) {
260
- logger.debug(`Failed to rename primary field: ${err}`);
261
- }
262
- }
263
-
264
- // Step 1b: Delete default placeholder fields by type (works for both Feishu and Lark)
265
- const defaultFieldsToDelete = fieldsRes.data.items.filter(
266
- (f) => !f.is_primary && DEFAULT_CLEANUP_FIELD_TYPES.has(f.type ?? 0),
267
- );
268
-
269
- for (const field of defaultFieldsToDelete) {
270
- if (field.field_id) {
271
- try {
272
- await client.bitable.appTableField.delete({
273
- path: {
274
- app_token: appToken,
275
- table_id: tableId,
276
- field_id: field.field_id,
277
- },
278
- });
279
- cleanedFields++;
280
- } catch (err) {
281
- logger.debug(`Failed to delete default field ${field.field_name}: ${err}`);
282
- }
283
- }
284
- }
285
- }
286
-
287
- // Step 2: Delete empty placeholder rows (batch when possible)
288
- const recordsRes = await client.bitable.appTableRecord.list({
289
- path: { app_token: appToken, table_id: tableId },
290
- params: { page_size: 100 },
291
- });
292
-
293
- if (recordsRes.code === 0 && recordsRes.data?.items) {
294
- const emptyRecordIds = recordsRes.data.items
295
- .filter((r) => !r.fields || Object.keys(r.fields).length === 0)
296
- .map((r) => r.record_id)
297
- .filter((id): id is string => Boolean(id));
298
-
299
- if (emptyRecordIds.length > 0) {
300
- try {
301
- await client.bitable.appTableRecord.batchDelete({
302
- path: { app_token: appToken, table_id: tableId },
303
- data: { records: emptyRecordIds },
304
- });
305
- cleanedRows = emptyRecordIds.length;
306
- } catch {
307
- // Fallback: delete one by one if batch API is unavailable
308
- for (const recordId of emptyRecordIds) {
309
- try {
310
- await client.bitable.appTableRecord.delete({
311
- path: { app_token: appToken, table_id: tableId, record_id: recordId },
312
- });
313
- cleanedRows++;
314
- } catch (err) {
315
- logger.debug(`Failed to delete empty row ${recordId}: ${err}`);
316
- }
317
- }
318
- }
319
- }
320
- }
321
-
322
- return { cleanedRows, cleanedFields };
323
- }
324
-
325
- async function createApp(
326
- client: Lark.Client,
327
- name: string,
328
- folderToken?: string,
329
- logger?: CleanupLogger,
330
- ) {
331
- const res = await client.bitable.app.create({
332
- data: {
333
- name,
334
- ...(folderToken && { folder_token: folderToken }),
335
- },
336
- });
337
- if (res.code !== 0) {
338
- throw new Error(res.msg);
339
- }
340
-
341
- const appToken = res.data?.app?.app_token;
342
- if (!appToken) {
343
- throw new Error("Failed to create Bitable: no app_token returned");
344
- }
345
-
346
- const log: CleanupLogger = logger ?? { debug: () => {}, warn: () => {} };
347
- let tableId: string | undefined;
348
- let cleanedRows = 0;
349
- let cleanedFields = 0;
350
-
351
- try {
352
- const tablesRes = await client.bitable.appTable.list({
353
- path: { app_token: appToken },
354
- });
355
- if (tablesRes.code === 0 && tablesRes.data?.items && tablesRes.data.items.length > 0) {
356
- tableId = tablesRes.data.items[0].table_id ?? undefined;
357
- if (tableId) {
358
- const cleanup = await cleanupNewBitable(client, appToken, tableId, name, log);
359
- cleanedRows = cleanup.cleanedRows;
360
- cleanedFields = cleanup.cleanedFields;
361
- }
362
- }
363
- } catch (err) {
364
- log.debug(`Cleanup failed (non-critical): ${err}`);
365
- }
366
-
367
- return {
368
- app_token: appToken,
369
- table_id: tableId,
370
- name: res.data?.app?.name,
371
- url: res.data?.app?.url,
372
- cleaned_placeholder_rows: cleanedRows,
373
- cleaned_default_fields: cleanedFields,
374
- hint: tableId
375
- ? `Table created. Use app_token="${appToken}" and table_id="${tableId}" for other bitable tools.`
376
- : "Table created. Use feishu_bitable_get_meta to get table_id and field details.",
377
- };
378
- }
379
-
380
- async function createField(
381
- client: Lark.Client,
382
- appToken: string,
383
- tableId: string,
384
- fieldName: string,
385
- fieldType: number,
386
- property?: Record<string, unknown>,
387
- ) {
388
- const res = await client.bitable.appTableField.create({
389
- path: { app_token: appToken, table_id: tableId },
390
- data: {
391
- field_name: fieldName,
392
- type: fieldType,
393
- ...(property && { property }),
394
- },
395
- });
396
- if (res.code !== 0) {
397
- throw new Error(res.msg);
398
- }
399
-
400
- return {
401
- field_id: res.data?.field?.field_id,
402
- field_name: res.data?.field?.field_name,
403
- type: res.data?.field?.type,
404
- type_name: FIELD_TYPE_NAMES[res.data?.field?.type ?? 0] || `type_${res.data?.field?.type}`,
405
- };
406
- }
407
-
408
- async function updateRecord(
409
- client: Lark.Client,
410
- appToken: string,
411
- tableId: string,
412
- recordId: string,
413
- fields: Record<string, unknown>,
414
- ) {
415
- const res = await client.bitable.appTableRecord.update({
416
- path: { app_token: appToken, table_id: tableId, record_id: recordId },
417
- // oxlint-disable-next-line typescript/no-explicit-any
418
- data: { fields: fields as any },
419
- });
420
- if (res.code !== 0) {
421
- throw new Error(res.msg);
422
- }
423
-
424
- return {
425
- record: res.data?.record,
426
- };
427
- }
428
-
429
- // ============ Schemas ============
430
-
431
- const GetMetaSchema = Type.Object({
432
- url: Type.String({
433
- description: "Bitable URL. Supports both formats: /base/XXX?table=YYY or /wiki/XXX?table=YYY",
434
- }),
435
- });
436
-
437
- const ListFieldsSchema = Type.Object({
438
- app_token: Type.String({
439
- description: "Bitable app token (use feishu_bitable_get_meta to get from URL)",
440
- }),
441
- table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
442
- });
443
-
444
- const ListRecordsSchema = Type.Object({
445
- app_token: Type.String({
446
- description: "Bitable app token (use feishu_bitable_get_meta to get from URL)",
447
- }),
448
- table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
449
- page_size: Type.Optional(
450
- Type.Number({
451
- description: "Number of records per page (1-500, default 100)",
452
- minimum: 1,
453
- maximum: 500,
454
- }),
455
- ),
456
- page_token: Type.Optional(
457
- Type.String({ description: "Pagination token from previous response" }),
458
- ),
459
- });
460
-
461
- const GetRecordSchema = Type.Object({
462
- app_token: Type.String({
463
- description: "Bitable app token (use feishu_bitable_get_meta to get from URL)",
464
- }),
465
- table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
466
- record_id: Type.String({ description: "Record ID to retrieve" }),
467
- });
468
-
469
- const CreateRecordSchema = Type.Object({
470
- app_token: Type.String({
471
- description: "Bitable app token (use feishu_bitable_get_meta to get from URL)",
472
- }),
473
- table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
474
- fields: Type.Record(Type.String(), Type.Any(), {
475
- description:
476
- "Field values keyed by field name. Format by type: Text='string', Number=123, SingleSelect='Option', MultiSelect=['A','B'], DateTime=timestamp_ms, User=[{id:'ou_xxx'}], URL={text:'Display',link:'https://...'}",
477
- }),
478
- });
479
-
480
- const CreateAppSchema = Type.Object({
481
- name: Type.String({
482
- description: "Name for the new Bitable application",
483
- }),
484
- folder_token: Type.Optional(
485
- Type.String({
486
- description: "Optional folder token to place the Bitable in a specific folder",
487
- }),
488
- ),
489
- });
490
-
491
- const CreateFieldSchema = Type.Object({
492
- app_token: Type.String({
493
- description:
494
- "Bitable app token (use feishu_bitable_get_meta to get from URL, or feishu_bitable_create_app to create new)",
495
- }),
496
- table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
497
- field_name: Type.String({ description: "Name for the new field" }),
498
- field_type: Type.Number({
499
- description:
500
- "Field type ID: 1=Text, 2=Number, 3=SingleSelect, 4=MultiSelect, 5=DateTime, 7=Checkbox, 11=User, 13=Phone, 15=URL, 17=Attachment, 18=SingleLink, 19=Lookup, 20=Formula, 21=DuplexLink, 22=Location, 23=GroupChat, 1001=CreatedTime, 1002=ModifiedTime, 1003=CreatedUser, 1004=ModifiedUser, 1005=AutoNumber",
501
- minimum: 1,
502
- }),
503
- property: Type.Optional(
504
- Type.Record(Type.String(), Type.Any(), {
505
- description: "Field-specific properties (e.g., options for SingleSelect, format for Number)",
506
- }),
507
- ),
508
- });
509
-
510
- const UpdateRecordSchema = Type.Object({
511
- app_token: Type.String({
512
- description: "Bitable app token (use feishu_bitable_get_meta to get from URL)",
513
- }),
514
- table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
515
- record_id: Type.String({ description: "Record ID to update" }),
516
- fields: Type.Record(Type.String(), Type.Any(), {
517
- description: "Field values to update (same format as create_record)",
518
- }),
519
- });
520
-
521
- // ============ Tool Registration ============
522
-
523
- export function registerFeishuBitableTools(api: FasedAgentPluginApi) {
524
- if (!api.config) {
525
- api.logger.debug?.("feishu_bitable: No config available, skipping bitable tools");
526
- return;
527
- }
528
-
529
- const accounts = listEnabledFeishuAccounts(api.config);
530
- if (accounts.length === 0) {
531
- api.logger.debug?.("feishu_bitable: No Feishu accounts configured, skipping bitable tools");
532
- return;
533
- }
534
-
535
- type AccountAwareParams = { accountId?: string };
536
-
537
- const getClient = (params: AccountAwareParams | undefined, defaultAccountId?: string) =>
538
- createFeishuToolClient({ api, executeParams: params, defaultAccountId });
539
-
540
- const registerBitableTool = <TParams extends AccountAwareParams>(params: {
541
- name: string;
542
- label: string;
543
- description: string;
544
- parameters: unknown;
545
- execute: (args: { params: TParams; defaultAccountId?: string }) => Promise<unknown>;
546
- }) => {
547
- api.registerTool(
548
- (ctx) => ({
549
- name: params.name,
550
- label: params.label,
551
- description: params.description,
552
- parameters: params.parameters,
553
- async execute(_toolCallId, rawParams) {
554
- try {
555
- return json(
556
- await params.execute({
557
- params: rawParams as TParams,
558
- defaultAccountId: ctx.agentAccountId,
559
- }),
560
- );
561
- } catch (err) {
562
- return json({ error: err instanceof Error ? err.message : String(err) });
563
- }
564
- },
565
- }),
566
- { name: params.name },
567
- );
568
- };
569
-
570
- registerBitableTool<{ url: string; accountId?: string }>({
571
- name: "feishu_bitable_get_meta",
572
- label: "Feishu Bitable Get Meta",
573
- description:
574
- "Parse a Bitable URL and get app_token, table_id, and table list. Use this first when given a /wiki/ or /base/ URL.",
575
- parameters: GetMetaSchema,
576
- async execute({ params, defaultAccountId }) {
577
- return getBitableMeta(getClient(params, defaultAccountId), params.url);
578
- },
579
- });
580
-
581
- registerBitableTool<{ app_token: string; table_id: string; accountId?: string }>({
582
- name: "feishu_bitable_list_fields",
583
- label: "Feishu Bitable List Fields",
584
- description: "List all fields (columns) in a Bitable table with their types and properties",
585
- parameters: ListFieldsSchema,
586
- async execute({ params, defaultAccountId }) {
587
- return listFields(getClient(params, defaultAccountId), params.app_token, params.table_id);
588
- },
589
- });
590
-
591
- registerBitableTool<{
592
- app_token: string;
593
- table_id: string;
594
- page_size?: number;
595
- page_token?: string;
596
- accountId?: string;
597
- }>({
598
- name: "feishu_bitable_list_records",
599
- label: "Feishu Bitable List Records",
600
- description: "List records (rows) from a Bitable table with pagination support",
601
- parameters: ListRecordsSchema,
602
- async execute({ params, defaultAccountId }) {
603
- return listRecords(
604
- getClient(params, defaultAccountId),
605
- params.app_token,
606
- params.table_id,
607
- params.page_size,
608
- params.page_token,
609
- );
610
- },
611
- });
612
-
613
- registerBitableTool<{
614
- app_token: string;
615
- table_id: string;
616
- record_id: string;
617
- accountId?: string;
618
- }>({
619
- name: "feishu_bitable_get_record",
620
- label: "Feishu Bitable Get Record",
621
- description: "Get a single record by ID from a Bitable table",
622
- parameters: GetRecordSchema,
623
- async execute({ params, defaultAccountId }) {
624
- return getRecord(
625
- getClient(params, defaultAccountId),
626
- params.app_token,
627
- params.table_id,
628
- params.record_id,
629
- );
630
- },
631
- });
632
-
633
- registerBitableTool<{
634
- app_token: string;
635
- table_id: string;
636
- fields: Record<string, unknown>;
637
- accountId?: string;
638
- }>({
639
- name: "feishu_bitable_create_record",
640
- label: "Feishu Bitable Create Record",
641
- description: "Create a new record (row) in a Bitable table",
642
- parameters: CreateRecordSchema,
643
- async execute({ params, defaultAccountId }) {
644
- return createRecord(
645
- getClient(params, defaultAccountId),
646
- params.app_token,
647
- params.table_id,
648
- params.fields,
649
- );
650
- },
651
- });
652
-
653
- registerBitableTool<{
654
- app_token: string;
655
- table_id: string;
656
- record_id: string;
657
- fields: Record<string, unknown>;
658
- accountId?: string;
659
- }>({
660
- name: "feishu_bitable_update_record",
661
- label: "Feishu Bitable Update Record",
662
- description: "Update an existing record (row) in a Bitable table",
663
- parameters: UpdateRecordSchema,
664
- async execute({ params, defaultAccountId }) {
665
- return updateRecord(
666
- getClient(params, defaultAccountId),
667
- params.app_token,
668
- params.table_id,
669
- params.record_id,
670
- params.fields,
671
- );
672
- },
673
- });
674
-
675
- registerBitableTool<{ name: string; folder_token?: string; accountId?: string }>({
676
- name: "feishu_bitable_create_app",
677
- label: "Feishu Bitable Create App",
678
- description: "Create a new Bitable (multidimensional table) application",
679
- parameters: CreateAppSchema,
680
- async execute({ params, defaultAccountId }) {
681
- return createApp(getClient(params, defaultAccountId), params.name, params.folder_token, {
682
- debug: (msg) => api.logger.debug?.(msg),
683
- warn: (msg) => api.logger.warn?.(msg),
684
- });
685
- },
686
- });
687
-
688
- registerBitableTool<{
689
- app_token: string;
690
- table_id: string;
691
- field_name: string;
692
- field_type: number;
693
- property?: Record<string, unknown>;
694
- accountId?: string;
695
- }>({
696
- name: "feishu_bitable_create_field",
697
- label: "Feishu Bitable Create Field",
698
- description: "Create a new field (column) in a Bitable table",
699
- parameters: CreateFieldSchema,
700
- async execute({ params, defaultAccountId }) {
701
- return createField(
702
- getClient(params, defaultAccountId),
703
- params.app_token,
704
- params.table_id,
705
- params.field_name,
706
- params.field_type,
707
- params.property,
708
- );
709
- },
710
- });
711
-
712
- api.logger.debug?.("feishu_bitable: Registered bitable tools");
713
- }