@larksuite/openclaw-lark 2025.7.15-beta.0

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 (426) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +76 -0
  3. package/bin/openclaw-lark.js +39 -0
  4. package/index.d.ts +36 -0
  5. package/index.js +188 -0
  6. package/openclaw.plugin.json +64 -0
  7. package/package.json +63 -0
  8. package/secret-contract-api.d.ts +15 -0
  9. package/secret-contract-api.js +78 -0
  10. package/skills/feishu-bitable/SKILL.md +248 -0
  11. package/skills/feishu-bitable/references/examples.md +813 -0
  12. package/skills/feishu-bitable/references/field-properties.md +763 -0
  13. package/skills/feishu-bitable/references/record-values.md +911 -0
  14. package/skills/feishu-calendar/SKILL.md +242 -0
  15. package/skills/feishu-channel-rules/SKILL.md +18 -0
  16. package/skills/feishu-channel-rules/references/markdown-syntax.md +138 -0
  17. package/skills/feishu-create-doc/SKILL.md +719 -0
  18. package/skills/feishu-fetch-doc/SKILL.md +93 -0
  19. package/skills/feishu-im-read/SKILL.md +163 -0
  20. package/skills/feishu-task/SKILL.md +340 -0
  21. package/skills/feishu-troubleshoot/SKILL.md +70 -0
  22. package/skills/feishu-update-doc/SKILL.md +285 -0
  23. package/src/card/builder.d.ts +152 -0
  24. package/src/card/builder.js +794 -0
  25. package/src/card/card-error.d.ts +91 -0
  26. package/src/card/card-error.js +206 -0
  27. package/src/card/cardkit.d.ts +90 -0
  28. package/src/card/cardkit.js +203 -0
  29. package/src/card/flush-controller.d.ts +45 -0
  30. package/src/card/flush-controller.js +138 -0
  31. package/src/card/image-resolver.d.ts +45 -0
  32. package/src/card/image-resolver.js +116 -0
  33. package/src/card/markdown-style.d.ts +16 -0
  34. package/src/card/markdown-style.js +106 -0
  35. package/src/card/reasoning-utils.d.ts +14 -0
  36. package/src/card/reasoning-utils.js +64 -0
  37. package/src/card/reply-dispatcher-types.d.ts +132 -0
  38. package/src/card/reply-dispatcher-types.js +61 -0
  39. package/src/card/reply-dispatcher.d.ts +15 -0
  40. package/src/card/reply-dispatcher.js +447 -0
  41. package/src/card/reply-mode.d.ts +41 -0
  42. package/src/card/reply-mode.js +70 -0
  43. package/src/card/streaming-card-controller.d.ts +118 -0
  44. package/src/card/streaming-card-controller.js +1045 -0
  45. package/src/card/tool-use-config.d.ts +26 -0
  46. package/src/card/tool-use-config.js +76 -0
  47. package/src/card/tool-use-display.d.ts +37 -0
  48. package/src/card/tool-use-display.js +476 -0
  49. package/src/card/tool-use-trace-store.d.ts +51 -0
  50. package/src/card/tool-use-trace-store.js +271 -0
  51. package/src/card/unavailable-guard.d.ts +35 -0
  52. package/src/card/unavailable-guard.js +87 -0
  53. package/src/channel/abort-detect.d.ts +47 -0
  54. package/src/channel/abort-detect.js +219 -0
  55. package/src/channel/chat-queue.d.ts +41 -0
  56. package/src/channel/chat-queue.js +68 -0
  57. package/src/channel/config-adapter.d.ts +23 -0
  58. package/src/channel/config-adapter.js +107 -0
  59. package/src/channel/directory.d.ts +57 -0
  60. package/src/channel/directory.js +197 -0
  61. package/src/channel/event-handlers.d.ts +17 -0
  62. package/src/channel/event-handlers.js +380 -0
  63. package/src/channel/interactive-dispatch.d.ts +59 -0
  64. package/src/channel/interactive-dispatch.js +195 -0
  65. package/src/channel/monitor.d.ts +17 -0
  66. package/src/channel/monitor.js +140 -0
  67. package/src/channel/onboarding-config.d.ts +18 -0
  68. package/src/channel/onboarding-config.js +96 -0
  69. package/src/channel/onboarding-migrate.d.ts +25 -0
  70. package/src/channel/onboarding-migrate.js +70 -0
  71. package/src/channel/onboarding.d.ts +12 -0
  72. package/src/channel/onboarding.js +300 -0
  73. package/src/channel/plugin.d.ts +13 -0
  74. package/src/channel/plugin.js +310 -0
  75. package/src/channel/probe.d.ts +14 -0
  76. package/src/channel/probe.js +24 -0
  77. package/src/channel/types.d.ts +37 -0
  78. package/src/channel/types.js +8 -0
  79. package/src/commands/auth.d.ts +21 -0
  80. package/src/commands/auth.js +165 -0
  81. package/src/commands/diagnose.d.ts +69 -0
  82. package/src/commands/diagnose.js +848 -0
  83. package/src/commands/doctor.d.ts +27 -0
  84. package/src/commands/doctor.js +588 -0
  85. package/src/commands/index.d.ts +25 -0
  86. package/src/commands/index.js +219 -0
  87. package/src/commands/locale.d.ts +7 -0
  88. package/src/commands/locale.js +8 -0
  89. package/src/core/accounts.d.ts +51 -0
  90. package/src/core/accounts.js +219 -0
  91. package/src/core/agent-config.d.ts +100 -0
  92. package/src/core/agent-config.js +148 -0
  93. package/src/core/api-error.d.ts +48 -0
  94. package/src/core/api-error.js +117 -0
  95. package/src/core/app-owner-fallback.d.ts +22 -0
  96. package/src/core/app-owner-fallback.js +39 -0
  97. package/src/core/app-scope-checker.d.ts +87 -0
  98. package/src/core/app-scope-checker.js +198 -0
  99. package/src/core/auth-errors.d.ts +144 -0
  100. package/src/core/auth-errors.js +160 -0
  101. package/src/core/card-action-operator.d.ts +33 -0
  102. package/src/core/card-action-operator.js +30 -0
  103. package/src/core/chat-info-cache.d.ts +67 -0
  104. package/src/core/chat-info-cache.js +165 -0
  105. package/src/core/comment-target.d.ts +65 -0
  106. package/src/core/comment-target.js +100 -0
  107. package/src/core/config-schema.d.ts +490 -0
  108. package/src/core/config-schema.js +223 -0
  109. package/src/core/device-flow.d.ts +77 -0
  110. package/src/core/device-flow.js +217 -0
  111. package/src/core/domains.d.ts +18 -0
  112. package/src/core/domains.js +34 -0
  113. package/src/core/feishu-fetch.d.ts +18 -0
  114. package/src/core/feishu-fetch.js +28 -0
  115. package/src/core/footer-config.d.ts +24 -0
  116. package/src/core/footer-config.js +51 -0
  117. package/src/core/lark-client.d.ts +125 -0
  118. package/src/core/lark-client.js +468 -0
  119. package/src/core/lark-logger.d.ts +23 -0
  120. package/src/core/lark-logger.js +160 -0
  121. package/src/core/lark-ticket.d.ts +29 -0
  122. package/src/core/lark-ticket.js +40 -0
  123. package/src/core/message-unavailable.d.ts +53 -0
  124. package/src/core/message-unavailable.js +142 -0
  125. package/src/core/owner-policy.d.ts +32 -0
  126. package/src/core/owner-policy.js +55 -0
  127. package/src/core/permission-url.d.ts +22 -0
  128. package/src/core/permission-url.js +76 -0
  129. package/src/core/raw-request.d.ts +27 -0
  130. package/src/core/raw-request.js +90 -0
  131. package/src/core/runtime-store.d.ts +13 -0
  132. package/src/core/runtime-store.js +29 -0
  133. package/src/core/scope-manager.d.ts +168 -0
  134. package/src/core/scope-manager.js +224 -0
  135. package/src/core/sdk-compat.d.ts +20 -0
  136. package/src/core/sdk-compat.js +28 -0
  137. package/src/core/security-check.d.ts +72 -0
  138. package/src/core/security-check.js +184 -0
  139. package/src/core/shutdown-hooks.d.ts +22 -0
  140. package/src/core/shutdown-hooks.js +61 -0
  141. package/src/core/synthetic-target.d.ts +33 -0
  142. package/src/core/synthetic-target.js +40 -0
  143. package/src/core/targets.d.ts +60 -0
  144. package/src/core/targets.js +173 -0
  145. package/src/core/token-store.d.ts +54 -0
  146. package/src/core/token-store.js +326 -0
  147. package/src/core/tool-client.d.ts +176 -0
  148. package/src/core/tool-client.js +426 -0
  149. package/src/core/tool-scopes.d.ts +156 -0
  150. package/src/core/tool-scopes.js +344 -0
  151. package/src/core/tools-config.d.ts +55 -0
  152. package/src/core/tools-config.js +143 -0
  153. package/src/core/types.d.ts +91 -0
  154. package/src/core/types.js +12 -0
  155. package/src/core/uat-client.d.ts +46 -0
  156. package/src/core/uat-client.js +192 -0
  157. package/src/core/version.d.ts +31 -0
  158. package/src/core/version.js +69 -0
  159. package/src/messaging/converters/audio.d.ts +8 -0
  160. package/src/messaging/converters/audio.js +24 -0
  161. package/src/messaging/converters/calendar.d.ts +13 -0
  162. package/src/messaging/converters/calendar.js +56 -0
  163. package/src/messaging/converters/content-converter-helpers.d.ts +30 -0
  164. package/src/messaging/converters/content-converter-helpers.js +82 -0
  165. package/src/messaging/converters/content-converter.d.ts +24 -0
  166. package/src/messaging/converters/content-converter.js +40 -0
  167. package/src/messaging/converters/file.d.ts +8 -0
  168. package/src/messaging/converters/file.js +24 -0
  169. package/src/messaging/converters/folder.d.ts +8 -0
  170. package/src/messaging/converters/folder.js +24 -0
  171. package/src/messaging/converters/hongbao.d.ts +8 -0
  172. package/src/messaging/converters/hongbao.js +20 -0
  173. package/src/messaging/converters/image.d.ts +8 -0
  174. package/src/messaging/converters/image.js +22 -0
  175. package/src/messaging/converters/index.d.ts +8 -0
  176. package/src/messaging/converters/index.js +53 -0
  177. package/src/messaging/converters/interactive/card-converter.d.ts +76 -0
  178. package/src/messaging/converters/interactive/card-converter.js +1177 -0
  179. package/src/messaging/converters/interactive/card-utils.d.ts +9 -0
  180. package/src/messaging/converters/interactive/card-utils.js +47 -0
  181. package/src/messaging/converters/interactive/index.d.ts +8 -0
  182. package/src/messaging/converters/interactive/index.js +25 -0
  183. package/src/messaging/converters/interactive/legacy.d.ts +11 -0
  184. package/src/messaging/converters/interactive/legacy.js +60 -0
  185. package/src/messaging/converters/interactive/types.d.ts +23 -0
  186. package/src/messaging/converters/interactive/types.js +27 -0
  187. package/src/messaging/converters/location.d.ts +8 -0
  188. package/src/messaging/converters/location.js +23 -0
  189. package/src/messaging/converters/merge-forward.d.ts +32 -0
  190. package/src/messaging/converters/merge-forward.js +235 -0
  191. package/src/messaging/converters/post.d.ts +11 -0
  192. package/src/messaging/converters/post.js +235 -0
  193. package/src/messaging/converters/share.d.ts +9 -0
  194. package/src/messaging/converters/share.js +28 -0
  195. package/src/messaging/converters/sticker.d.ts +8 -0
  196. package/src/messaging/converters/sticker.js +22 -0
  197. package/src/messaging/converters/system.d.ts +12 -0
  198. package/src/messaging/converters/system.js +36 -0
  199. package/src/messaging/converters/text.d.ts +8 -0
  200. package/src/messaging/converters/text.js +18 -0
  201. package/src/messaging/converters/todo.d.ts +8 -0
  202. package/src/messaging/converters/todo.js +45 -0
  203. package/src/messaging/converters/types.d.ts +114 -0
  204. package/src/messaging/converters/types.js +8 -0
  205. package/src/messaging/converters/unknown.d.ts +8 -0
  206. package/src/messaging/converters/unknown.js +20 -0
  207. package/src/messaging/converters/utils.d.ts +22 -0
  208. package/src/messaging/converters/utils.js +57 -0
  209. package/src/messaging/converters/video-chat.d.ts +8 -0
  210. package/src/messaging/converters/video-chat.js +31 -0
  211. package/src/messaging/converters/video.d.ts +8 -0
  212. package/src/messaging/converters/video.js +35 -0
  213. package/src/messaging/converters/vote.d.ts +8 -0
  214. package/src/messaging/converters/vote.js +28 -0
  215. package/src/messaging/inbound/bot-content.d.ts +84 -0
  216. package/src/messaging/inbound/bot-content.js +117 -0
  217. package/src/messaging/inbound/bot-loop-guard.d.ts +48 -0
  218. package/src/messaging/inbound/bot-loop-guard.js +89 -0
  219. package/src/messaging/inbound/comment-context.d.ts +82 -0
  220. package/src/messaging/inbound/comment-context.js +353 -0
  221. package/src/messaging/inbound/comment-handler.d.ts +30 -0
  222. package/src/messaging/inbound/comment-handler.js +269 -0
  223. package/src/messaging/inbound/dedup.d.ts +59 -0
  224. package/src/messaging/inbound/dedup.js +121 -0
  225. package/src/messaging/inbound/dispatch-builders.d.ts +104 -0
  226. package/src/messaging/inbound/dispatch-builders.js +241 -0
  227. package/src/messaging/inbound/dispatch-commands.d.ts +22 -0
  228. package/src/messaging/inbound/dispatch-commands.js +131 -0
  229. package/src/messaging/inbound/dispatch-context.d.ts +67 -0
  230. package/src/messaging/inbound/dispatch-context.js +153 -0
  231. package/src/messaging/inbound/dispatch.d.ts +50 -0
  232. package/src/messaging/inbound/dispatch.js +477 -0
  233. package/src/messaging/inbound/enrich.d.ts +102 -0
  234. package/src/messaging/inbound/enrich.js +236 -0
  235. package/src/messaging/inbound/gate-effects.d.ts +23 -0
  236. package/src/messaging/inbound/gate-effects.js +46 -0
  237. package/src/messaging/inbound/gate.d.ts +91 -0
  238. package/src/messaging/inbound/gate.js +342 -0
  239. package/src/messaging/inbound/handler-registry.d.ts +25 -0
  240. package/src/messaging/inbound/handler-registry.js +23 -0
  241. package/src/messaging/inbound/handler.d.ts +37 -0
  242. package/src/messaging/inbound/handler.js +286 -0
  243. package/src/messaging/inbound/media-resolver.d.ts +32 -0
  244. package/src/messaging/inbound/media-resolver.js +91 -0
  245. package/src/messaging/inbound/mention-registry.d.ts +59 -0
  246. package/src/messaging/inbound/mention-registry.js +115 -0
  247. package/src/messaging/inbound/mention.d.ts +48 -0
  248. package/src/messaging/inbound/mention.js +102 -0
  249. package/src/messaging/inbound/parse-io.d.ts +50 -0
  250. package/src/messaging/inbound/parse-io.js +86 -0
  251. package/src/messaging/inbound/parse.d.ts +28 -0
  252. package/src/messaging/inbound/parse.js +128 -0
  253. package/src/messaging/inbound/permission.d.ts +17 -0
  254. package/src/messaging/inbound/permission.js +44 -0
  255. package/src/messaging/inbound/policy.d.ts +95 -0
  256. package/src/messaging/inbound/policy.js +168 -0
  257. package/src/messaging/inbound/reaction-handler.d.ts +62 -0
  258. package/src/messaging/inbound/reaction-handler.js +259 -0
  259. package/src/messaging/inbound/sentinel-store.d.ts +37 -0
  260. package/src/messaging/inbound/sentinel-store.js +98 -0
  261. package/src/messaging/inbound/synthetic-message.d.ts +26 -0
  262. package/src/messaging/inbound/synthetic-message.js +59 -0
  263. package/src/messaging/inbound/user-name-cache-store.d.ts +62 -0
  264. package/src/messaging/inbound/user-name-cache-store.js +236 -0
  265. package/src/messaging/inbound/user-name-cache.d.ts +78 -0
  266. package/src/messaging/inbound/user-name-cache.js +306 -0
  267. package/src/messaging/inbound/vc-meeting-invited-handler.d.ts +20 -0
  268. package/src/messaging/inbound/vc-meeting-invited-handler.js +236 -0
  269. package/src/messaging/inbound/vc-sender.d.ts +41 -0
  270. package/src/messaging/inbound/vc-sender.js +53 -0
  271. package/src/messaging/outbound/actions.d.ts +16 -0
  272. package/src/messaging/outbound/actions.js +329 -0
  273. package/src/messaging/outbound/bot-peer-context.d.ts +42 -0
  274. package/src/messaging/outbound/bot-peer-context.js +40 -0
  275. package/src/messaging/outbound/chat-manage.d.ts +64 -0
  276. package/src/messaging/outbound/chat-manage.js +117 -0
  277. package/src/messaging/outbound/deliver.d.ts +186 -0
  278. package/src/messaging/outbound/deliver.js +410 -0
  279. package/src/messaging/outbound/fetch.d.ts +12 -0
  280. package/src/messaging/outbound/fetch.js +17 -0
  281. package/src/messaging/outbound/forward.d.ts +26 -0
  282. package/src/messaging/outbound/forward.js +51 -0
  283. package/src/messaging/outbound/media-url-utils.d.ts +29 -0
  284. package/src/messaging/outbound/media-url-utils.js +172 -0
  285. package/src/messaging/outbound/media.d.ts +260 -0
  286. package/src/messaging/outbound/media.js +865 -0
  287. package/src/messaging/outbound/normalize-mentions.d.ts +50 -0
  288. package/src/messaging/outbound/normalize-mentions.js +166 -0
  289. package/src/messaging/outbound/outbound-mention.d.ts +41 -0
  290. package/src/messaging/outbound/outbound-mention.js +112 -0
  291. package/src/messaging/outbound/outbound.d.ts +79 -0
  292. package/src/messaging/outbound/outbound.js +195 -0
  293. package/src/messaging/outbound/reactions.d.ts +124 -0
  294. package/src/messaging/outbound/reactions.js +384 -0
  295. package/src/messaging/outbound/send.d.ts +153 -0
  296. package/src/messaging/outbound/send.js +417 -0
  297. package/src/messaging/outbound/typing.d.ts +60 -0
  298. package/src/messaging/outbound/typing.js +139 -0
  299. package/src/messaging/shared/message-lookup.d.ts +54 -0
  300. package/src/messaging/shared/message-lookup.js +120 -0
  301. package/src/messaging/types.d.ts +316 -0
  302. package/src/messaging/types.js +11 -0
  303. package/src/tools/ask-user-question.d.ts +32 -0
  304. package/src/tools/ask-user-question.js +922 -0
  305. package/src/tools/auto-auth.d.ts +57 -0
  306. package/src/tools/auto-auth.js +904 -0
  307. package/src/tools/helpers.d.ts +264 -0
  308. package/src/tools/helpers.js +389 -0
  309. package/src/tools/mcp/doc/create.d.ts +12 -0
  310. package/src/tools/mcp/doc/create.js +47 -0
  311. package/src/tools/mcp/doc/fetch.d.ts +12 -0
  312. package/src/tools/mcp/doc/fetch.js +39 -0
  313. package/src/tools/mcp/doc/index.d.ts +12 -0
  314. package/src/tools/mcp/doc/index.js +50 -0
  315. package/src/tools/mcp/doc/update.d.ts +12 -0
  316. package/src/tools/mcp/doc/update.js +64 -0
  317. package/src/tools/mcp/shared.d.ts +59 -0
  318. package/src/tools/mcp/shared.js +239 -0
  319. package/src/tools/oapi/bitable/app-table-field.d.ts +16 -0
  320. package/src/tools/oapi/bitable/app-table-field.js +225 -0
  321. package/src/tools/oapi/bitable/app-table-record.d.ts +20 -0
  322. package/src/tools/oapi/bitable/app-table-record.js +439 -0
  323. package/src/tools/oapi/bitable/app-table-view.d.ts +16 -0
  324. package/src/tools/oapi/bitable/app-table-view.js +172 -0
  325. package/src/tools/oapi/bitable/app-table.d.ts +17 -0
  326. package/src/tools/oapi/bitable/app-table.js +195 -0
  327. package/src/tools/oapi/bitable/app.d.ts +18 -0
  328. package/src/tools/oapi/bitable/app.js +189 -0
  329. package/src/tools/oapi/bitable/index.d.ts +9 -0
  330. package/src/tools/oapi/bitable/index.js +17 -0
  331. package/src/tools/oapi/calendar/calendar.d.ts +15 -0
  332. package/src/tools/oapi/calendar/calendar.js +125 -0
  333. package/src/tools/oapi/calendar/event-attendee.d.ts +14 -0
  334. package/src/tools/oapi/calendar/event-attendee.js +161 -0
  335. package/src/tools/oapi/calendar/event.d.ts +16 -0
  336. package/src/tools/oapi/calendar/event.js +712 -0
  337. package/src/tools/oapi/calendar/freebusy.d.ts +13 -0
  338. package/src/tools/oapi/calendar/freebusy.js +114 -0
  339. package/src/tools/oapi/calendar/index.d.ts +8 -0
  340. package/src/tools/oapi/calendar/index.js +15 -0
  341. package/src/tools/oapi/chat/chat.d.ts +16 -0
  342. package/src/tools/oapi/chat/chat.js +127 -0
  343. package/src/tools/oapi/chat/index.d.ts +10 -0
  344. package/src/tools/oapi/chat/index.js +23 -0
  345. package/src/tools/oapi/chat/members.d.ts +11 -0
  346. package/src/tools/oapi/chat/members.js +84 -0
  347. package/src/tools/oapi/common/get-user.d.ts +12 -0
  348. package/src/tools/oapi/common/get-user.js +109 -0
  349. package/src/tools/oapi/common/index.d.ts +6 -0
  350. package/src/tools/oapi/common/index.js +11 -0
  351. package/src/tools/oapi/common/search-user.d.ts +11 -0
  352. package/src/tools/oapi/common/search-user.js +76 -0
  353. package/src/tools/oapi/drive/doc-comments.d.ts +15 -0
  354. package/src/tools/oapi/drive/doc-comments.js +351 -0
  355. package/src/tools/oapi/drive/doc-media.d.ts +19 -0
  356. package/src/tools/oapi/drive/doc-media.js +371 -0
  357. package/src/tools/oapi/drive/file.d.ts +19 -0
  358. package/src/tools/oapi/drive/file.js +519 -0
  359. package/src/tools/oapi/drive/index.d.ts +12 -0
  360. package/src/tools/oapi/drive/index.js +45 -0
  361. package/src/tools/oapi/helpers.d.ts +183 -0
  362. package/src/tools/oapi/helpers.js +385 -0
  363. package/src/tools/oapi/im/format-messages.d.ts +50 -0
  364. package/src/tools/oapi/im/format-messages.js +169 -0
  365. package/src/tools/oapi/im/index.d.ts +10 -0
  366. package/src/tools/oapi/im/index.js +25 -0
  367. package/src/tools/oapi/im/message-read.d.ts +13 -0
  368. package/src/tools/oapi/im/message-read.js +419 -0
  369. package/src/tools/oapi/im/message.d.ts +16 -0
  370. package/src/tools/oapi/im/message.js +152 -0
  371. package/src/tools/oapi/im/resource.d.ts +13 -0
  372. package/src/tools/oapi/im/resource.js +186 -0
  373. package/src/tools/oapi/im/time-utils.d.ts +46 -0
  374. package/src/tools/oapi/im/time-utils.js +212 -0
  375. package/src/tools/oapi/im/user-name-uat.d.ts +26 -0
  376. package/src/tools/oapi/im/user-name-uat.js +143 -0
  377. package/src/tools/oapi/index.d.ts +11 -0
  378. package/src/tools/oapi/index.js +64 -0
  379. package/src/tools/oapi/sdk-types.d.ts +96 -0
  380. package/src/tools/oapi/sdk-types.js +13 -0
  381. package/src/tools/oapi/search/doc-search.d.ts +13 -0
  382. package/src/tools/oapi/search/doc-search.js +194 -0
  383. package/src/tools/oapi/search/index.d.ts +12 -0
  384. package/src/tools/oapi/search/index.js +37 -0
  385. package/src/tools/oapi/sheets/index.d.ts +12 -0
  386. package/src/tools/oapi/sheets/index.js +35 -0
  387. package/src/tools/oapi/sheets/sheet.d.ts +16 -0
  388. package/src/tools/oapi/sheets/sheet.js +688 -0
  389. package/src/tools/oapi/task/attachment.d.ts +18 -0
  390. package/src/tools/oapi/task/attachment.js +107 -0
  391. package/src/tools/oapi/task/comment.d.ts +15 -0
  392. package/src/tools/oapi/task/comment.js +149 -0
  393. package/src/tools/oapi/task/index.d.ts +11 -0
  394. package/src/tools/oapi/task/index.js +21 -0
  395. package/src/tools/oapi/task/section.d.ts +17 -0
  396. package/src/tools/oapi/task/section.js +293 -0
  397. package/src/tools/oapi/task/subtask.d.ts +14 -0
  398. package/src/tools/oapi/task/subtask.js +171 -0
  399. package/src/tools/oapi/task/task.d.ts +19 -0
  400. package/src/tools/oapi/task/task.js +512 -0
  401. package/src/tools/oapi/task/task_agent.d.ts +14 -0
  402. package/src/tools/oapi/task/task_agent.js +108 -0
  403. package/src/tools/oapi/task/tasklist.d.ts +19 -0
  404. package/src/tools/oapi/task/tasklist.js +276 -0
  405. package/src/tools/oapi/wiki/index.d.ts +12 -0
  406. package/src/tools/oapi/wiki/index.js +42 -0
  407. package/src/tools/oapi/wiki/space-node.d.ts +17 -0
  408. package/src/tools/oapi/wiki/space-node.js +233 -0
  409. package/src/tools/oapi/wiki/space.d.ts +15 -0
  410. package/src/tools/oapi/wiki/space.js +133 -0
  411. package/src/tools/oauth-batch-auth.d.ts +11 -0
  412. package/src/tools/oauth-batch-auth.js +150 -0
  413. package/src/tools/oauth-cards.d.ts +39 -0
  414. package/src/tools/oauth-cards.js +324 -0
  415. package/src/tools/oauth.d.ts +47 -0
  416. package/src/tools/oauth.js +592 -0
  417. package/src/tools/onboarding-auth.d.ts +27 -0
  418. package/src/tools/onboarding-auth.js +133 -0
  419. package/src/tools/tat/im/index.d.ts +15 -0
  420. package/src/tools/tat/im/index.js +22 -0
  421. package/src/tools/tat/im/resource.d.ts +15 -0
  422. package/src/tools/tat/im/resource.js +192 -0
  423. package/tsdown.config.d.ts +2 -0
  424. package/tsdown.config.js +25 -0
  425. package/vitest.config.d.ts +2 -0
  426. package/vitest.config.js +12 -0
@@ -0,0 +1,519 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * feishu_drive_file tool -- Manage Feishu Drive files.
7
+ *
8
+ * Actions: list, get_meta, copy, move, delete, upload, download
9
+ *
10
+ * Uses the Feishu Drive API:
11
+ * - list: GET /open-apis/drive/v1/files
12
+ * - get_meta: POST /open-apis/drive/v1/metas/batch_query
13
+ * - copy: POST /open-apis/drive/v1/files/:file_token/copy
14
+ * - move: POST /open-apis/drive/v1/files/:file_token/move
15
+ * - delete: DELETE /open-apis/drive/v1/files/:file_token
16
+ * - upload: POST /open-apis/drive/v1/files/upload_all
17
+ * - download: GET /open-apis/drive/v1/files/:file_token/download
18
+ */
19
+ /* eslint-disable @typescript-eslint/no-explicit-any */
20
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ var desc = Object.getOwnPropertyDescriptor(m, k);
23
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
24
+ desc = { enumerable: true, get: function() { return m[k]; } };
25
+ }
26
+ Object.defineProperty(o, k2, desc);
27
+ }) : (function(o, m, k, k2) {
28
+ if (k2 === undefined) k2 = k;
29
+ o[k2] = m[k];
30
+ }));
31
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
32
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
33
+ }) : function(o, v) {
34
+ o["default"] = v;
35
+ });
36
+ var __importStar = (this && this.__importStar) || (function () {
37
+ var ownKeys = function(o) {
38
+ ownKeys = Object.getOwnPropertyNames || function (o) {
39
+ var ar = [];
40
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
41
+ return ar;
42
+ };
43
+ return ownKeys(o);
44
+ };
45
+ return function (mod) {
46
+ if (mod && mod.__esModule) return mod;
47
+ var result = {};
48
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
49
+ __setModuleDefault(result, mod);
50
+ return result;
51
+ };
52
+ })();
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.registerFeishuDriveFileTool = registerFeishuDriveFileTool;
55
+ const fs = __importStar(require("node:fs/promises"));
56
+ const path = __importStar(require("node:path"));
57
+ const typebox_1 = require("@sinclair/typebox");
58
+ const helpers_1 = require("../helpers.js");
59
+ // 分片上传配置
60
+ const SMALL_FILE_THRESHOLD = 15 * 1024 * 1024; // 15MB,小于此大小使用一次上传
61
+ // ---------------------------------------------------------------------------
62
+ // Schema
63
+ // ---------------------------------------------------------------------------
64
+ const FeishuDriveFileSchema = typebox_1.Type.Union([
65
+ // LIST FILES
66
+ typebox_1.Type.Object({
67
+ action: typebox_1.Type.Literal('list'),
68
+ folder_token: typebox_1.Type.Optional(typebox_1.Type.String({
69
+ description: '文件夹 token(可选)。不填写或填空字符串时,获取用户云空间根目录下的清单(注意:根目录模式不支持分页和返回快捷方式)',
70
+ })),
71
+ page_size: typebox_1.Type.Optional(typebox_1.Type.Integer({
72
+ description: '分页大小(默认 200,最大 200)',
73
+ minimum: 1,
74
+ maximum: 200,
75
+ })),
76
+ page_token: typebox_1.Type.Optional(typebox_1.Type.String({
77
+ description: '分页标记。首次请求无需填写',
78
+ })),
79
+ order_by: typebox_1.Type.Optional((0, helpers_1.StringEnum)(['EditedTime', 'CreatedTime'], {
80
+ description: '排序方式:EditedTime(编辑时间)、CreatedTime(创建时间)',
81
+ })),
82
+ direction: typebox_1.Type.Optional((0, helpers_1.StringEnum)(['ASC', 'DESC'], {
83
+ description: '排序方向:ASC(升序)、DESC(降序)',
84
+ })),
85
+ }),
86
+ // GET META
87
+ typebox_1.Type.Object({
88
+ action: typebox_1.Type.Literal('get_meta'),
89
+ request_docs: typebox_1.Type.Array(typebox_1.Type.Object({
90
+ doc_token: typebox_1.Type.String({
91
+ description: '文档 token(从浏览器 URL 中获取,如 spreadsheet_token、doc_token 等)',
92
+ }),
93
+ doc_type: typebox_1.Type.Union([
94
+ typebox_1.Type.Literal('doc'),
95
+ typebox_1.Type.Literal('sheet'),
96
+ typebox_1.Type.Literal('file'),
97
+ typebox_1.Type.Literal('bitable'),
98
+ typebox_1.Type.Literal('docx'),
99
+ typebox_1.Type.Literal('folder'),
100
+ typebox_1.Type.Literal('mindnote'),
101
+ typebox_1.Type.Literal('slides'),
102
+ ], {
103
+ description: '文档类型:doc、sheet、file、bitable、docx、folder、mindnote、slides',
104
+ }),
105
+ }), {
106
+ description: "要查询的文档列表(批量查询,最多 50 个)。示例:[{doc_token: 'Z1FjxxxxxxxxxxxxxxxxxxxtnAc', doc_type: 'sheet'}]",
107
+ minItems: 1,
108
+ maxItems: 50,
109
+ }),
110
+ }),
111
+ // COPY FILE
112
+ typebox_1.Type.Object({
113
+ action: typebox_1.Type.Literal('copy'),
114
+ file_token: typebox_1.Type.String({
115
+ description: '文件 token(必填)',
116
+ }),
117
+ name: typebox_1.Type.String({
118
+ description: '目标文件名(必填)',
119
+ }),
120
+ type: typebox_1.Type.Union([
121
+ typebox_1.Type.Literal('doc'),
122
+ typebox_1.Type.Literal('sheet'),
123
+ typebox_1.Type.Literal('file'),
124
+ typebox_1.Type.Literal('bitable'),
125
+ typebox_1.Type.Literal('docx'),
126
+ typebox_1.Type.Literal('folder'),
127
+ typebox_1.Type.Literal('mindnote'),
128
+ typebox_1.Type.Literal('slides'),
129
+ ], {
130
+ description: '文档类型(必填)',
131
+ }),
132
+ folder_token: typebox_1.Type.Optional(typebox_1.Type.String({
133
+ description: '目标文件夹 token。不传则复制到「我的空间」根目录',
134
+ })),
135
+ parent_node: typebox_1.Type.Optional(typebox_1.Type.String({
136
+ description: '【folder_token 的别名】目标文件夹 token(为兼容性保留,建议使用 folder_token)',
137
+ })),
138
+ }),
139
+ // MOVE FILE
140
+ typebox_1.Type.Object({
141
+ action: typebox_1.Type.Literal('move'),
142
+ file_token: typebox_1.Type.String({
143
+ description: '文件 token(必填)',
144
+ }),
145
+ type: typebox_1.Type.Union([
146
+ typebox_1.Type.Literal('doc'),
147
+ typebox_1.Type.Literal('sheet'),
148
+ typebox_1.Type.Literal('file'),
149
+ typebox_1.Type.Literal('bitable'),
150
+ typebox_1.Type.Literal('docx'),
151
+ typebox_1.Type.Literal('folder'),
152
+ typebox_1.Type.Literal('mindnote'),
153
+ typebox_1.Type.Literal('slides'),
154
+ ], {
155
+ description: '文档类型(必填)',
156
+ }),
157
+ folder_token: typebox_1.Type.String({
158
+ description: '目标文件夹 token(必填)',
159
+ }),
160
+ }),
161
+ // DELETE FILE
162
+ typebox_1.Type.Object({
163
+ action: typebox_1.Type.Literal('delete'),
164
+ file_token: typebox_1.Type.String({
165
+ description: '文件 token(必填)',
166
+ }),
167
+ type: typebox_1.Type.Union([
168
+ typebox_1.Type.Literal('doc'),
169
+ typebox_1.Type.Literal('sheet'),
170
+ typebox_1.Type.Literal('file'),
171
+ typebox_1.Type.Literal('bitable'),
172
+ typebox_1.Type.Literal('docx'),
173
+ typebox_1.Type.Literal('folder'),
174
+ typebox_1.Type.Literal('mindnote'),
175
+ typebox_1.Type.Literal('slides'),
176
+ ], {
177
+ description: '文档类型(必填)',
178
+ }),
179
+ }),
180
+ // UPLOAD FILE
181
+ typebox_1.Type.Object({
182
+ action: typebox_1.Type.Literal('upload'),
183
+ parent_node: typebox_1.Type.Optional(typebox_1.Type.String({
184
+ description: '父节点 token(可选)。explorer 类型填文件夹 token,bitable 类型填 app_token。不填写或填空字符串时,上传到云空间根目录',
185
+ })),
186
+ file_path: typebox_1.Type.Optional(typebox_1.Type.String({
187
+ description: '本地文件路径(与 file_content_base64 二选一)。优先使用此参数,会自动读取文件内容、计算大小、提取文件名。',
188
+ })),
189
+ file_content_base64: typebox_1.Type.Optional(typebox_1.Type.String({
190
+ description: '文件内容的 Base64 编码(与 file_path 二选一)。当不提供 file_path 时使用。',
191
+ })),
192
+ file_name: typebox_1.Type.Optional(typebox_1.Type.String({
193
+ description: '文件名(可选)。如果提供了 file_path,会自动从路径中提取文件名;如果使用 file_content_base64,则必须提供此参数。',
194
+ })),
195
+ size: typebox_1.Type.Optional(typebox_1.Type.Integer({
196
+ description: '文件大小(字节,可选)。如果提供了 file_path,会自动计算;如果使用 file_content_base64,则必须提供此参数。',
197
+ })),
198
+ }),
199
+ // DOWNLOAD FILE
200
+ typebox_1.Type.Object({
201
+ action: typebox_1.Type.Literal('download'),
202
+ file_token: typebox_1.Type.String({
203
+ description: '文件 token(必填)',
204
+ }),
205
+ output_path: typebox_1.Type.Optional(typebox_1.Type.String({
206
+ description: "本地保存的完整文件路径(可选)。必须包含文件名和扩展名,例如 '/tmp/file.pdf'。如果不提供,则返回 Base64 编码的文件内容。",
207
+ })),
208
+ }),
209
+ ]);
210
+ // ---------------------------------------------------------------------------
211
+ // Registration
212
+ // ---------------------------------------------------------------------------
213
+ function registerFeishuDriveFileTool(api) {
214
+ if (!api.config)
215
+ return false;
216
+ const cfg = api.config;
217
+ const { toolClient, log } = (0, helpers_1.createToolContext)(api, 'feishu_drive_file');
218
+ return (0, helpers_1.registerTool)(api, {
219
+ name: 'feishu_drive_file',
220
+ label: 'Feishu Drive Files',
221
+ description: '【以用户身份】飞书云空间文件管理工具。当用户要求查看云空间(云盘)中的文件列表、获取文件信息、复制/移动/删除文件、上传/下载文件时使用。消息中的文件读写**禁止**使用该工具!' +
222
+ '\n\nActions:' +
223
+ '\n- list(列出文件):列出文件夹下的文件。不提供 folder_token 时获取根目录清单' +
224
+ "\n- get_meta(批量获取元数据):批量查询文档元信息,使用 request_docs 数组参数,格式:[{doc_token: '...', doc_type: 'sheet'}]" +
225
+ '\n- copy(复制文件):复制文件到指定位置' +
226
+ '\n- move(移动文件):移动文件到指定文件夹' +
227
+ '\n- delete(删除文件):删除文件' +
228
+ '\n- upload(上传文件):上传本地文件到云空间。提供 file_path(本地文件路径)或 file_content_base64(Base64 编码)' +
229
+ '\n- download(下载文件):下载文件到本地。提供 output_path(本地保存路径)则保存到本地,否则返回 Base64 编码' +
230
+ '\n\n【重要】copy/move/delete 操作需要 file_token 和 type 参数。get_meta 使用 request_docs 数组参数。' +
231
+ '\n【重要】upload 优先使用 file_path(自动读取文件、提取文件名和大小),也支持 file_content_base64(需手动提供 file_name 和 size)。' +
232
+ '\n【重要】download 提供 output_path 时保存到本地(可以是文件路径或文件夹路径+file_name),不提供则返回 Base64。',
233
+ parameters: FeishuDriveFileSchema,
234
+ async execute(_toolCallId, params) {
235
+ const p = params;
236
+ try {
237
+ const client = toolClient();
238
+ switch (p.action) {
239
+ // -----------------------------------------------------------------
240
+ // LIST FILES
241
+ // -----------------------------------------------------------------
242
+ case 'list': {
243
+ log.info(`list: folder_token=${p.folder_token || '(root)'}, page_size=${p.page_size ?? 200}`);
244
+ const res = await client.invoke('feishu_drive_file.list', (sdk, opts) => sdk.drive.file.list({
245
+ params: {
246
+ folder_token: p.folder_token,
247
+ page_size: p.page_size,
248
+ page_token: p.page_token,
249
+ order_by: p.order_by,
250
+ direction: p.direction,
251
+ },
252
+ }, opts), { as: 'user' });
253
+ (0, helpers_1.assertLarkOk)(res);
254
+ log.info(`list: returned ${res.data?.files?.length ?? 0} files`);
255
+ const data = res.data;
256
+ return (0, helpers_1.json)({
257
+ files: data?.files,
258
+ has_more: data?.has_more,
259
+ page_token: data?.next_page_token,
260
+ });
261
+ }
262
+ // -----------------------------------------------------------------
263
+ // GET META
264
+ // -----------------------------------------------------------------
265
+ case 'get_meta': {
266
+ if (!p.request_docs || !Array.isArray(p.request_docs) || p.request_docs.length === 0) {
267
+ return (0, helpers_1.json)({
268
+ error: "request_docs must be a non-empty array. Correct format: {action: 'get_meta', request_docs: [{doc_token: '...', doc_type: 'sheet'}]}",
269
+ });
270
+ }
271
+ log.info(`get_meta: querying ${p.request_docs.length} documents`);
272
+ const res = await client.invoke('feishu_drive_file.get_meta', (sdk, opts) => sdk.drive.meta.batchQuery({
273
+ data: {
274
+ request_docs: p.request_docs,
275
+ },
276
+ }, opts), { as: 'user' });
277
+ (0, helpers_1.assertLarkOk)(res);
278
+ log.info(`get_meta: returned ${res.data?.metas?.length ?? 0} metas`);
279
+ return (0, helpers_1.json)({
280
+ metas: res.data?.metas ?? [],
281
+ });
282
+ }
283
+ // -----------------------------------------------------------------
284
+ // COPY FILE
285
+ // -----------------------------------------------------------------
286
+ case 'copy': {
287
+ // 兼容处理:parent_node 作为 folder_token 的别名
288
+ const targetFolderToken = p.folder_token || p.parent_node;
289
+ log.info(`copy: file_token=${p.file_token}, name=${p.name}, type=${p.type}, folder_token=${targetFolderToken ?? '(root)'}`);
290
+ const res = await client.invoke('feishu_drive_file.copy', (sdk, opts) => sdk.drive.file.copy({
291
+ path: { file_token: p.file_token },
292
+ data: {
293
+ name: p.name,
294
+ type: p.type,
295
+ folder_token: targetFolderToken,
296
+ },
297
+ }, opts), { as: 'user' });
298
+ (0, helpers_1.assertLarkOk)(res);
299
+ const data = res.data;
300
+ log.info(`copy: new file_token=${data?.file?.token ?? 'unknown'}`);
301
+ return (0, helpers_1.json)({
302
+ file: data?.file,
303
+ });
304
+ }
305
+ // -----------------------------------------------------------------
306
+ // MOVE FILE
307
+ // -----------------------------------------------------------------
308
+ case 'move': {
309
+ log.info(`move: file_token=${p.file_token}, type=${p.type}, folder_token=${p.folder_token}`);
310
+ const res = await client.invoke('feishu_drive_file.move', (sdk, opts) => sdk.drive.file.move({
311
+ path: { file_token: p.file_token },
312
+ data: {
313
+ type: p.type,
314
+ folder_token: p.folder_token,
315
+ },
316
+ }, opts), { as: 'user' });
317
+ (0, helpers_1.assertLarkOk)(res);
318
+ const data = res.data;
319
+ log.info(`move: success${data?.task_id ? `, task_id=${data.task_id}` : ''}`);
320
+ return (0, helpers_1.json)({
321
+ success: true,
322
+ ...(data?.task_id ? { task_id: data.task_id } : {}),
323
+ file_token: p.file_token,
324
+ target_folder_token: p.folder_token,
325
+ });
326
+ }
327
+ // -----------------------------------------------------------------
328
+ // DELETE FILE
329
+ // -----------------------------------------------------------------
330
+ case 'delete': {
331
+ log.info(`delete: file_token=${p.file_token}, type=${p.type}`);
332
+ const res = await client.invoke('feishu_drive_file.delete', (sdk, opts) => sdk.drive.file.delete({
333
+ path: { file_token: p.file_token },
334
+ params: {
335
+ type: p.type,
336
+ },
337
+ }, opts), { as: 'user' });
338
+ (0, helpers_1.assertLarkOk)(res);
339
+ const data = res.data;
340
+ log.info(`delete: success${data?.task_id ? `, task_id=${data.task_id}` : ''}`);
341
+ return (0, helpers_1.json)({
342
+ success: true,
343
+ ...(data?.task_id ? { task_id: data.task_id } : {}),
344
+ file_token: p.file_token,
345
+ });
346
+ }
347
+ // -----------------------------------------------------------------
348
+ // UPLOAD FILE
349
+ // -----------------------------------------------------------------
350
+ case 'upload': {
351
+ let fileBuffer;
352
+ let fileName;
353
+ let fileSize;
354
+ // 优先使用 file_path
355
+ if (p.file_path) {
356
+ log.info(`upload: reading from local file: ${p.file_path}`);
357
+ try {
358
+ // 读取文件内容
359
+ fileBuffer = await fs.readFile(p.file_path);
360
+ // 提取文件名(如果未提供)
361
+ fileName = p.file_name || path.basename(p.file_path);
362
+ // 计算文件大小(如果未提供)
363
+ fileSize = p.size || fileBuffer.length;
364
+ log.info(`upload: file_name=${fileName}, size=${fileSize}, parent=${p.parent_node || '(root)'}`);
365
+ }
366
+ catch (err) {
367
+ return (0, helpers_1.json)({
368
+ error: `failed to read local file: ${err instanceof Error ? err.message : String(err)}`,
369
+ });
370
+ }
371
+ }
372
+ else if (p.file_content_base64) {
373
+ // 使用 base64 内容
374
+ if (!p.file_name || !p.size) {
375
+ return (0, helpers_1.json)({
376
+ error: 'file_name and size are required when using file_content_base64',
377
+ });
378
+ }
379
+ log.info(`upload: using base64 content, file_name=${p.file_name}, size=${p.size}, parent=${p.parent_node}`);
380
+ // Decode base64 to buffer
381
+ fileBuffer = Buffer.from(p.file_content_base64, 'base64');
382
+ fileName = p.file_name;
383
+ fileSize = p.size;
384
+ }
385
+ else {
386
+ return (0, helpers_1.json)({
387
+ error: 'either file_path or file_content_base64 is required',
388
+ });
389
+ }
390
+ // 根据文件大小选择上传方式
391
+ if (fileSize <= SMALL_FILE_THRESHOLD) {
392
+ // 小文件:使用一次上传
393
+ log.info(`upload: using upload_all (file size ${fileSize} <= 15MB)`);
394
+ const res = await client.invoke('feishu_drive_file.upload', (sdk, opts) => sdk.drive.file.uploadAll({
395
+ data: {
396
+ file_name: fileName,
397
+ parent_type: 'explorer',
398
+ parent_node: p.parent_node || '',
399
+ size: fileSize,
400
+ file: fileBuffer,
401
+ },
402
+ }, opts), { as: 'user' });
403
+ (0, helpers_1.assertLarkOk)(res);
404
+ log.info(`upload: file_token=${res.data?.file_token}`);
405
+ return (0, helpers_1.json)({
406
+ file_token: res.data?.file_token,
407
+ file_name: fileName,
408
+ size: fileSize,
409
+ });
410
+ }
411
+ else {
412
+ // 大文件:使用分片上传
413
+ log.info(`upload: using chunked upload (file size ${fileSize} > 15MB)`);
414
+ // 1. 预上传
415
+ log.info(`upload: step 1 - prepare upload`);
416
+ const prepareRes = await client.invoke('feishu_drive_file.upload', (sdk, opts) => sdk.drive.file.uploadPrepare({
417
+ data: {
418
+ file_name: fileName,
419
+ parent_type: 'explorer',
420
+ parent_node: p.parent_node || '',
421
+ size: fileSize,
422
+ },
423
+ }, opts), { as: 'user' });
424
+ log.info(`upload: prepareRes = ${JSON.stringify(prepareRes)}`);
425
+ if (!prepareRes) {
426
+ return (0, helpers_1.json)({ error: 'pre-upload failed: empty response' });
427
+ }
428
+ (0, helpers_1.assertLarkOk)(prepareRes);
429
+ const { upload_id, block_size, block_num } = prepareRes.data;
430
+ log.info(`upload: got upload_id=${upload_id}, block_num=${block_num}, block_size=${block_size}`);
431
+ // 2. 上传分片
432
+ log.info(`upload: step 2 - uploading ${block_num} chunks`);
433
+ for (let seq = 0; seq < block_num; seq++) {
434
+ const start = seq * block_size;
435
+ const end = Math.min(start + block_size, fileSize);
436
+ const chunkBuffer = fileBuffer.subarray(start, end);
437
+ log.info(`upload: uploading chunk ${seq + 1}/${block_num} (${chunkBuffer.length} bytes)`);
438
+ await client.invoke('feishu_drive_file.upload', (sdk, opts) => sdk.drive.file.uploadPart({
439
+ data: {
440
+ upload_id: String(upload_id),
441
+ seq: Number(seq),
442
+ size: Number(chunkBuffer.length),
443
+ file: chunkBuffer,
444
+ },
445
+ }, opts), { as: 'user' });
446
+ log.info(`upload: chunk ${seq + 1}/${block_num} uploaded successfully`);
447
+ }
448
+ // 3. 完成上传
449
+ log.info(`upload: step 3 - finish upload`);
450
+ const finishRes = await client.invoke('feishu_drive_file.upload', (sdk, opts) => sdk.drive.file.uploadFinish({
451
+ data: {
452
+ upload_id,
453
+ block_num,
454
+ },
455
+ }, opts), { as: 'user' });
456
+ (0, helpers_1.assertLarkOk)(finishRes);
457
+ log.info(`upload: file_token=${finishRes.data?.file_token}`);
458
+ return (0, helpers_1.json)({
459
+ file_token: finishRes.data?.file_token,
460
+ file_name: fileName,
461
+ size: fileSize,
462
+ upload_method: 'chunked',
463
+ chunks_uploaded: block_num,
464
+ });
465
+ }
466
+ }
467
+ // -----------------------------------------------------------------
468
+ // DOWNLOAD FILE
469
+ // -----------------------------------------------------------------
470
+ case 'download': {
471
+ log.info(`download: file_token=${p.file_token}`);
472
+ const res = await client.invoke('feishu_drive_file.download', (sdk, opts) => sdk.drive.file.download({
473
+ path: { file_token: p.file_token },
474
+ }, opts), { as: 'user' });
475
+ // File download returns Buffer through getReadableStream
476
+ const stream = res.getReadableStream();
477
+ const chunks = [];
478
+ for await (const chunk of stream) {
479
+ chunks.push(chunk);
480
+ }
481
+ const fileBuffer = Buffer.concat(chunks);
482
+ log.info(`download: file size=${fileBuffer.length} bytes`);
483
+ // 如果提供了 output_path,保存到本地文件
484
+ if (p.output_path) {
485
+ try {
486
+ // output_path 必须是完整文件路径
487
+ // 确保父目录存在
488
+ await fs.mkdir(path.dirname(p.output_path), { recursive: true });
489
+ // 写入文件
490
+ await fs.writeFile(p.output_path, fileBuffer);
491
+ log.info(`download: saved to ${p.output_path}`);
492
+ return (0, helpers_1.json)({
493
+ saved_path: p.output_path,
494
+ size: fileBuffer.length,
495
+ });
496
+ }
497
+ catch (err) {
498
+ return (0, helpers_1.json)({
499
+ error: `failed to save file: ${err instanceof Error ? err.message : String(err)}`,
500
+ });
501
+ }
502
+ }
503
+ else {
504
+ // 没有提供 output_path,返回 base64
505
+ const base64Content = fileBuffer.toString('base64');
506
+ return (0, helpers_1.json)({
507
+ file_content_base64: base64Content,
508
+ size: fileBuffer.length,
509
+ });
510
+ }
511
+ }
512
+ }
513
+ }
514
+ catch (err) {
515
+ return await (0, helpers_1.handleInvokeErrorWithAutoAuth)(err, cfg);
516
+ }
517
+ },
518
+ }, { name: 'feishu_drive_file' });
519
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ *
5
+ * Drive 工具集
6
+ * 统一导出所有云空间相关工具的注册函数
7
+ */
8
+ import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
9
+ /**
10
+ * 注册所有 Drive 工具
11
+ */
12
+ export declare function registerFeishuDriveTools(api: OpenClawPluginApi): void;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * Drive 工具集
7
+ * 统一导出所有云空间相关工具的注册函数
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.registerFeishuDriveTools = registerFeishuDriveTools;
11
+ const accounts_1 = require("../../../core/accounts.js");
12
+ const tools_config_1 = require("../../../core/tools-config.js");
13
+ const file_1 = require("./file.js");
14
+ const doc_comments_1 = require("./doc-comments.js");
15
+ const doc_media_1 = require("./doc-media.js");
16
+ /**
17
+ * 注册所有 Drive 工具
18
+ */
19
+ function registerFeishuDriveTools(api) {
20
+ if (!api.config) {
21
+ api.logger.debug?.('feishu_drive: No config available, skipping');
22
+ return;
23
+ }
24
+ const accounts = (0, accounts_1.getEnabledLarkAccounts)(api.config);
25
+ if (accounts.length === 0) {
26
+ api.logger.debug?.('feishu_drive: No Feishu accounts configured, skipping');
27
+ return;
28
+ }
29
+ const toolsCfg = (0, tools_config_1.resolveAnyEnabledToolsConfig)(accounts);
30
+ if (!toolsCfg.drive) {
31
+ api.logger.debug?.('feishu_drive: drive tool disabled in all accounts');
32
+ return;
33
+ }
34
+ // 注册所有工具
35
+ const registered = [];
36
+ if ((0, file_1.registerFeishuDriveFileTool)(api))
37
+ registered.push('feishu_drive_file');
38
+ if ((0, doc_comments_1.registerDocCommentsTool)(api))
39
+ registered.push('feishu_doc_comments');
40
+ if ((0, doc_media_1.registerDocMediaTool)(api))
41
+ registered.push('feishu_doc_media');
42
+ if (registered.length > 0) {
43
+ api.logger.debug?.(`feishu_drive: Registered ${registered.join(', ')}`);
44
+ }
45
+ }