@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,91 @@
1
+ /**
2
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ *
5
+ * Unified card API error handling.
6
+ *
7
+ * Provides structured error class for CardKit API responses, sub-error
8
+ * parsing for the generic 230099 code, and helper predicates used by
9
+ * reply-dispatcher and streaming-card-controller.
10
+ */
11
+ /** 卡片 API 级别错误码。 */
12
+ export declare const CARD_ERROR: {
13
+ /** 发送频率限制 */
14
+ readonly RATE_LIMITED: 230020;
15
+ /** 卡片内容创建失败(通用码,需检查子错误) */
16
+ readonly CARD_CONTENT_FAILED: 230099;
17
+ };
18
+ /** 230099 子错误码,嵌套在 msg 的 ErrCode 字段中。 */
19
+ export declare const CARD_CONTENT_SUB_ERROR: {
20
+ /** 卡片元素(表格等)数量超限 */
21
+ readonly ELEMENT_LIMIT: 11310;
22
+ };
23
+ export declare const FEISHU_CARD_TABLE_LIMIT = 3;
24
+ export interface MarkdownTableMatch {
25
+ index: number;
26
+ length: number;
27
+ raw: string;
28
+ }
29
+ /** CardKit API 返回非零 code 时的结构化错误。 */
30
+ export declare class CardKitApiError extends Error {
31
+ readonly code: number;
32
+ readonly msg: string;
33
+ constructor(params: {
34
+ api: string;
35
+ code: number;
36
+ msg: string;
37
+ context: string;
38
+ });
39
+ }
40
+ /**
41
+ * 从 msg 字符串中提取子错误码。
42
+ *
43
+ * 示例输入: "Failed to create card content, ext=ErrCode: 11310; ErrMsg: element exceeds the limit; code:230099"
44
+ * 返回 11310 或 null。
45
+ */
46
+ export declare function extractSubCode(msg: string): number | null;
47
+ /**
48
+ * 从任意抛错对象中解析卡片 API 错误结构。
49
+ *
50
+ * 返回 { code, subCode, errMsg },如果无法提取 code 则返回 null。
51
+ */
52
+ export declare function parseCardApiError(err: unknown): {
53
+ code: number;
54
+ subCode: number | null;
55
+ errMsg: string;
56
+ } | null;
57
+ /**
58
+ * 判断错误是否为卡片表格数量超限。
59
+ *
60
+ * 匹配条件:code 230099 + subCode 11310 + errMsg 含 "table number over limit"。
61
+ * 11310 是通用的元素超限码(也覆盖模板可见性、组件上限等),
62
+ * 必须同时检查 errMsg 确认是表格数量导致的。
63
+ *
64
+ * 实际错误格式(生产日志 2026-03-13):
65
+ * "Failed to create card content, ext=ErrCode: 11310; ErrMsg: card table number over limit; ErrorValue: table; "
66
+ */
67
+ export declare function isCardTableLimitError(err: unknown): boolean;
68
+ /** 判断错误是否为卡片发送频率限制(230020)。 */
69
+ export declare function isCardRateLimitError(err: unknown): boolean;
70
+ /**
71
+ * 收集正文里可被飞书卡片实际渲染的 markdown 表格。
72
+ *
73
+ * 代码块里的示例表格不会被飞书解析成卡片表格元素,因此这里要先排除,
74
+ * 让 shouldUseCard() 预检和 sanitizeTextForCard() 降级逻辑使用同一份结果。
75
+ */
76
+ export declare function findMarkdownTablesOutsideCodeBlocks(text: string): MarkdownTableMatch[];
77
+ /**
78
+ * 对多段 markdown 文本共享一个表格预算。
79
+ *
80
+ * 段落按数组顺序消耗额度,适合处理“reasoning + 正文”这类会被飞书
81
+ * 作为同一张卡片渲染的多块文本。
82
+ */
83
+ export declare function sanitizeTextSegmentsForCard(texts: readonly string[], tableLimit?: number): string[];
84
+ /**
85
+ * 对正文中超出 tableLimit 的 markdown 表格降级为 code block,
86
+ * 避免飞书卡片因表格数超限触发 230099/11310。
87
+ *
88
+ * 前 tableLimit 张表格保持原样(可正常卡片渲染);
89
+ * 超出部分用反引号包裹,阻止飞书将其解析为卡片表格元素。
90
+ */
91
+ export declare function sanitizeTextForCard(text: string, tableLimit?: number): string;
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * Unified card API error handling.
7
+ *
8
+ * Provides structured error class for CardKit API responses, sub-error
9
+ * parsing for the generic 230099 code, and helper predicates used by
10
+ * reply-dispatcher and streaming-card-controller.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.CardKitApiError = exports.FEISHU_CARD_TABLE_LIMIT = exports.CARD_CONTENT_SUB_ERROR = exports.CARD_ERROR = void 0;
14
+ exports.extractSubCode = extractSubCode;
15
+ exports.parseCardApiError = parseCardApiError;
16
+ exports.isCardTableLimitError = isCardTableLimitError;
17
+ exports.isCardRateLimitError = isCardRateLimitError;
18
+ exports.findMarkdownTablesOutsideCodeBlocks = findMarkdownTablesOutsideCodeBlocks;
19
+ exports.sanitizeTextSegmentsForCard = sanitizeTextSegmentsForCard;
20
+ exports.sanitizeTextForCard = sanitizeTextForCard;
21
+ const api_error_1 = require("../core/api-error.js");
22
+ // ---------------------------------------------------------------------------
23
+ // Error code constants
24
+ // ---------------------------------------------------------------------------
25
+ /** 卡片 API 级别错误码。 */
26
+ exports.CARD_ERROR = {
27
+ /** 发送频率限制 */
28
+ RATE_LIMITED: 230020,
29
+ /** 卡片内容创建失败(通用码,需检查子错误) */
30
+ CARD_CONTENT_FAILED: 230099,
31
+ };
32
+ /** 230099 子错误码,嵌套在 msg 的 ErrCode 字段中。 */
33
+ exports.CARD_CONTENT_SUB_ERROR = {
34
+ /** 卡片元素(表格等)数量超限 */
35
+ ELEMENT_LIMIT: 11310,
36
+ };
37
+ // 经验性的飞书卡片表格上限 -- 4+ 张触发 230099/11310(2026-03 实测)。
38
+ exports.FEISHU_CARD_TABLE_LIMIT = 3;
39
+ // ---------------------------------------------------------------------------
40
+ // Error class
41
+ // ---------------------------------------------------------------------------
42
+ /** CardKit API 返回非零 code 时的结构化错误。 */
43
+ class CardKitApiError extends Error {
44
+ code;
45
+ msg;
46
+ constructor(params) {
47
+ const { api, code, msg, context } = params;
48
+ super(`cardkit ${api} FAILED: code=${code}, msg=${msg}, ${context}`);
49
+ this.name = 'CardKitApiError';
50
+ this.code = code;
51
+ this.msg = msg;
52
+ }
53
+ }
54
+ exports.CardKitApiError = CardKitApiError;
55
+ // ---------------------------------------------------------------------------
56
+ // Sub-error extraction
57
+ // ---------------------------------------------------------------------------
58
+ /**
59
+ * 从 msg 字符串中提取子错误码。
60
+ *
61
+ * 示例输入: "Failed to create card content, ext=ErrCode: 11310; ErrMsg: element exceeds the limit; code:230099"
62
+ * 返回 11310 或 null。
63
+ */
64
+ function extractSubCode(msg) {
65
+ const match = /ErrCode:\s*(\d+)/.exec(msg);
66
+ if (!match)
67
+ return null;
68
+ const code = Number(match[1]);
69
+ return Number.isFinite(code) ? code : null;
70
+ }
71
+ // ---------------------------------------------------------------------------
72
+ // Structured error parsing
73
+ // ---------------------------------------------------------------------------
74
+ /**
75
+ * 从任意抛错对象中解析卡片 API 错误结构。
76
+ *
77
+ * 返回 { code, subCode, errMsg },如果无法提取 code 则返回 null。
78
+ */
79
+ function parseCardApiError(err) {
80
+ const code = (0, api_error_1.extractLarkApiCode)(err);
81
+ if (code === undefined)
82
+ return null;
83
+ // 按优先级提取 msg 文本
84
+ let errMsg = '';
85
+ if (err && typeof err === 'object') {
86
+ const e = err;
87
+ if (typeof e.msg === 'string') {
88
+ errMsg = e.msg;
89
+ }
90
+ else if (typeof e.response?.data?.msg === 'string') {
91
+ // Axios errors: response.data.msg carries the Feishu detail with ErrCode
92
+ errMsg = e.response.data.msg;
93
+ }
94
+ else if (typeof e.message === 'string') {
95
+ // Fallback to generic Error.message (e.g. CardKitApiError)
96
+ errMsg = e.message;
97
+ }
98
+ }
99
+ const subCode = extractSubCode(errMsg);
100
+ return { code, subCode, errMsg };
101
+ }
102
+ // ---------------------------------------------------------------------------
103
+ // Helper predicates
104
+ // ---------------------------------------------------------------------------
105
+ /**
106
+ * 判断错误是否为卡片表格数量超限。
107
+ *
108
+ * 匹配条件:code 230099 + subCode 11310 + errMsg 含 "table number over limit"。
109
+ * 11310 是通用的元素超限码(也覆盖模板可见性、组件上限等),
110
+ * 必须同时检查 errMsg 确认是表格数量导致的。
111
+ *
112
+ * 实际错误格式(生产日志 2026-03-13):
113
+ * "Failed to create card content, ext=ErrCode: 11310; ErrMsg: card table number over limit; ErrorValue: table; "
114
+ */
115
+ function isCardTableLimitError(err) {
116
+ const parsed = parseCardApiError(err);
117
+ if (!parsed)
118
+ return false;
119
+ return (parsed.code === exports.CARD_ERROR.CARD_CONTENT_FAILED &&
120
+ parsed.subCode === exports.CARD_CONTENT_SUB_ERROR.ELEMENT_LIMIT &&
121
+ /table number over limit/i.test(parsed.errMsg));
122
+ }
123
+ /** 判断错误是否为卡片发送频率限制(230020)。 */
124
+ function isCardRateLimitError(err) {
125
+ const parsed = parseCardApiError(err);
126
+ if (!parsed)
127
+ return false;
128
+ return parsed.code === exports.CARD_ERROR.RATE_LIMITED;
129
+ }
130
+ // ---------------------------------------------------------------------------
131
+ // Text sanitization
132
+ // ---------------------------------------------------------------------------
133
+ /**
134
+ * 收集正文里可被飞书卡片实际渲染的 markdown 表格。
135
+ *
136
+ * 代码块里的示例表格不会被飞书解析成卡片表格元素,因此这里要先排除,
137
+ * 让 shouldUseCard() 预检和 sanitizeTextForCard() 降级逻辑使用同一份结果。
138
+ */
139
+ function findMarkdownTablesOutsideCodeBlocks(text) {
140
+ const codeBlockRanges = [];
141
+ const codeBlockRegex = /```[\s\S]*?```/g;
142
+ let codeBlockMatch = codeBlockRegex.exec(text);
143
+ while (codeBlockMatch != null) {
144
+ codeBlockRanges.push({
145
+ start: codeBlockMatch.index,
146
+ end: codeBlockMatch.index + codeBlockMatch[0].length,
147
+ });
148
+ codeBlockMatch = codeBlockRegex.exec(text);
149
+ }
150
+ const isInsideCodeBlock = (idx) => codeBlockRanges.some((range) => idx >= range.start && idx < range.end);
151
+ const tableRegex = /\|.+\|[\r\n]+\|[-:| ]+\|[\s\S]*?(?=\n\n|\n(?!\|)|$)/g;
152
+ const matches = [];
153
+ let tableMatch = tableRegex.exec(text);
154
+ while (tableMatch != null) {
155
+ if (!isInsideCodeBlock(tableMatch.index)) {
156
+ matches.push({
157
+ index: tableMatch.index,
158
+ length: tableMatch[0].length,
159
+ raw: tableMatch[0],
160
+ });
161
+ }
162
+ tableMatch = tableRegex.exec(text);
163
+ }
164
+ return matches;
165
+ }
166
+ /**
167
+ * 对多段 markdown 文本共享一个表格预算。
168
+ *
169
+ * 段落按数组顺序消耗额度,适合处理“reasoning + 正文”这类会被飞书
170
+ * 作为同一张卡片渲染的多块文本。
171
+ */
172
+ function sanitizeTextSegmentsForCard(texts, tableLimit = exports.FEISHU_CARD_TABLE_LIMIT) {
173
+ let remainingTableBudget = tableLimit;
174
+ return texts.map((text) => {
175
+ const matches = findMarkdownTablesOutsideCodeBlocks(text);
176
+ if (matches.length <= remainingTableBudget) {
177
+ remainingTableBudget -= matches.length;
178
+ return text;
179
+ }
180
+ const sanitizedText = wrapTablesBeyondLimit(text, matches, Math.max(remainingTableBudget, 0));
181
+ remainingTableBudget = 0;
182
+ return sanitizedText;
183
+ });
184
+ }
185
+ /**
186
+ * 对正文中超出 tableLimit 的 markdown 表格降级为 code block,
187
+ * 避免飞书卡片因表格数超限触发 230099/11310。
188
+ *
189
+ * 前 tableLimit 张表格保持原样(可正常卡片渲染);
190
+ * 超出部分用反引号包裹,阻止飞书将其解析为卡片表格元素。
191
+ */
192
+ function sanitizeTextForCard(text, tableLimit = exports.FEISHU_CARD_TABLE_LIMIT) {
193
+ return sanitizeTextSegmentsForCard([text], tableLimit)[0];
194
+ }
195
+ function wrapTablesBeyondLimit(text, matches, keepCount) {
196
+ if (matches.length <= keepCount)
197
+ return text;
198
+ // Back-to-front replacement keeps the original indices stable.
199
+ let result = text;
200
+ for (let i = matches.length - 1; i >= keepCount; i--) {
201
+ const { index, length, raw } = matches[i];
202
+ const replacement = `\`\`\`\n${raw}\n\`\`\``;
203
+ result = result.slice(0, index) + replacement + result.slice(index + length);
204
+ }
205
+ return result;
206
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ *
5
+ * CardKit streaming APIs for Lark/Feishu.
6
+ */
7
+ import type { ClawdbotConfig } from 'openclaw/plugin-sdk';
8
+ import type { FeishuSendResult } from '../messaging/types';
9
+ /**
10
+ * Create a card entity via the CardKit API.
11
+ *
12
+ * Returns the card_id directly, bypassing the idConvert step.
13
+ * The card can then be sent via IM API and streamed via CardKit.
14
+ */
15
+ export declare function createCardEntity(params: {
16
+ cfg: ClawdbotConfig;
17
+ card: Record<string, unknown>;
18
+ accountId?: string;
19
+ }): Promise<string | null>;
20
+ /**
21
+ * Stream text content to a specific card element using the CardKit API.
22
+ *
23
+ * The card automatically diffs the new content against the previous
24
+ * content and renders incremental changes with a typewriter animation.
25
+ *
26
+ * @param params.cardId - CardKit card ID (from `convertMessageToCardId`).
27
+ * @param params.elementId - The element ID to update (e.g. `STREAMING_ELEMENT_ID`).
28
+ * @param params.content - The full cumulative text (not a delta).
29
+ * @param params.sequence - Monotonically increasing sequence number.
30
+ */
31
+ export declare function streamCardContent(params: {
32
+ cfg: ClawdbotConfig;
33
+ cardId: string;
34
+ elementId: string;
35
+ content: string;
36
+ sequence: number;
37
+ accountId?: string;
38
+ }): Promise<void>;
39
+ /**
40
+ * Fully replace a card using the CardKit API.
41
+ *
42
+ * Used for the final "complete" state update (with action buttons, green
43
+ * header, etc.) after streaming finishes.
44
+ *
45
+ * @param params.cardId - CardKit card ID.
46
+ * @param params.card - The new card JSON content.
47
+ * @param params.sequence - Monotonically increasing sequence number.
48
+ */
49
+ export declare function updateCardKitCard(params: {
50
+ cfg: ClawdbotConfig;
51
+ cardId: string;
52
+ card: Record<string, unknown>;
53
+ sequence: number;
54
+ accountId?: string;
55
+ }): Promise<void>;
56
+ export declare function updateCardKitCardForAuth(params: {
57
+ cfg: ClawdbotConfig;
58
+ cardId: string;
59
+ card: Record<string, unknown>;
60
+ sequence: number;
61
+ accountId?: string;
62
+ }): Promise<void>;
63
+ /**
64
+ * Send an interactive card message by referencing a CardKit card_id.
65
+ *
66
+ * The content format is: {"type":"card","data":{"card_id":"xxx"}}
67
+ * This links the IM message to the CardKit card entity, enabling
68
+ * streaming updates via cardElement.content().
69
+ */
70
+ export declare function sendCardByCardId(params: {
71
+ cfg: ClawdbotConfig;
72
+ to: string;
73
+ cardId: string;
74
+ replyToMessageId?: string;
75
+ replyInThread?: boolean;
76
+ accountId?: string;
77
+ }): Promise<FeishuSendResult>;
78
+ /**
79
+ * Close (or open) the streaming mode on a CardKit card.
80
+ *
81
+ * Must be called after streaming is complete to restore normal card
82
+ * behaviour (forwarding, interaction callbacks, etc.).
83
+ */
84
+ export declare function setCardStreamingMode(params: {
85
+ cfg: ClawdbotConfig;
86
+ cardId: string;
87
+ streamingMode: boolean;
88
+ sequence: number;
89
+ accountId?: string;
90
+ }): Promise<void>;
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * CardKit streaming APIs for Lark/Feishu.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createCardEntity = createCardEntity;
10
+ exports.streamCardContent = streamCardContent;
11
+ exports.updateCardKitCard = updateCardKitCard;
12
+ exports.updateCardKitCardForAuth = updateCardKitCardForAuth;
13
+ exports.sendCardByCardId = sendCardByCardId;
14
+ exports.setCardStreamingMode = setCardStreamingMode;
15
+ const lark_client_1 = require("../core/lark-client.js");
16
+ const lark_logger_1 = require("../core/lark-logger.js");
17
+ const message_unavailable_1 = require("../core/message-unavailable.js");
18
+ const targets_1 = require("../core/targets.js");
19
+ const card_error_1 = require("./card-error.js");
20
+ const log = (0, lark_logger_1.larkLogger)('card/cardkit');
21
+ // ---------------------------------------------------------------------------
22
+ // Helpers
23
+ // ---------------------------------------------------------------------------
24
+ /**
25
+ * 记录 CardKit API 响应日志,检测错误码并抛出异常。
26
+ *
27
+ * 默认 fail-fast:body-level 非零 code 视为业务错误,立即抛出,
28
+ * 由调用方(streaming-card-controller 等)统一走 catch → guard 处理。
29
+ */
30
+ function logCardKitResponse(params) {
31
+ const { resp, api, context } = params;
32
+ const { code, msg } = resp;
33
+ log.info(`cardkit ${api} response`, { code, msg, context });
34
+ if (code && code !== 0) {
35
+ log.warn(`cardkit ${api} FAILED`, {
36
+ code,
37
+ msg,
38
+ context,
39
+ fullResponse: resp,
40
+ });
41
+ throw new card_error_1.CardKitApiError({ api, code, msg: msg ?? '', context });
42
+ }
43
+ }
44
+ // ---------------------------------------------------------------------------
45
+ // CardKit streaming APIs
46
+ // ---------------------------------------------------------------------------
47
+ /**
48
+ * Create a card entity via the CardKit API.
49
+ *
50
+ * Returns the card_id directly, bypassing the idConvert step.
51
+ * The card can then be sent via IM API and streamed via CardKit.
52
+ */
53
+ async function createCardEntity(params) {
54
+ const { cfg, card, accountId } = params;
55
+ const client = lark_client_1.LarkClient.fromCfg(cfg, accountId).sdk;
56
+ // SDK 返回类型不完整,运行时包含 code/msg/data 字段
57
+ const response = (await client.cardkit.v1.card.create({
58
+ data: {
59
+ type: 'card_json',
60
+ data: JSON.stringify(card),
61
+ },
62
+ }));
63
+ // 兼容不同 SDK 包装层:优先 data.card_id,回退顶层 card_id
64
+ const cardId = (response.data?.card_id ?? response.card_id) ?? null;
65
+ logCardKitResponse({
66
+ resp: response,
67
+ api: 'card.create',
68
+ context: `cardId=${cardId}`,
69
+ });
70
+ return cardId;
71
+ }
72
+ /**
73
+ * Stream text content to a specific card element using the CardKit API.
74
+ *
75
+ * The card automatically diffs the new content against the previous
76
+ * content and renders incremental changes with a typewriter animation.
77
+ *
78
+ * @param params.cardId - CardKit card ID (from `convertMessageToCardId`).
79
+ * @param params.elementId - The element ID to update (e.g. `STREAMING_ELEMENT_ID`).
80
+ * @param params.content - The full cumulative text (not a delta).
81
+ * @param params.sequence - Monotonically increasing sequence number.
82
+ */
83
+ async function streamCardContent(params) {
84
+ const { cfg, cardId, elementId, content, sequence, accountId } = params;
85
+ const client = lark_client_1.LarkClient.fromCfg(cfg, accountId).sdk;
86
+ // SDK 返回类型不完整,运行时包含 code/msg 字段
87
+ const resp = (await client.cardkit.v1.cardElement.content({
88
+ data: { content, sequence },
89
+ path: { card_id: cardId, element_id: elementId },
90
+ }));
91
+ logCardKitResponse({
92
+ resp,
93
+ api: 'cardElement.content',
94
+ context: `seq=${sequence}, contentLen=${content.length}`,
95
+ });
96
+ }
97
+ /**
98
+ * Fully replace a card using the CardKit API.
99
+ *
100
+ * Used for the final "complete" state update (with action buttons, green
101
+ * header, etc.) after streaming finishes.
102
+ *
103
+ * @param params.cardId - CardKit card ID.
104
+ * @param params.card - The new card JSON content.
105
+ * @param params.sequence - Monotonically increasing sequence number.
106
+ */
107
+ async function updateCardKitCard(params) {
108
+ const { cfg, cardId, card, sequence, accountId } = params;
109
+ const client = lark_client_1.LarkClient.fromCfg(cfg, accountId).sdk;
110
+ // SDK 返回类型不完整,运行时包含 code/msg 字段
111
+ const resp = (await client.cardkit.v1.card.update({
112
+ data: {
113
+ card: { type: 'card_json', data: JSON.stringify(card) },
114
+ sequence,
115
+ },
116
+ path: { card_id: cardId },
117
+ }));
118
+ logCardKitResponse({
119
+ resp,
120
+ api: 'card.update',
121
+ context: `seq=${sequence}, cardId=${cardId}`,
122
+ });
123
+ }
124
+ async function updateCardKitCardForAuth(params) {
125
+ return updateCardKitCard(params);
126
+ }
127
+ /**
128
+ * Send an interactive card message by referencing a CardKit card_id.
129
+ *
130
+ * The content format is: {"type":"card","data":{"card_id":"xxx"}}
131
+ * This links the IM message to the CardKit card entity, enabling
132
+ * streaming updates via cardElement.content().
133
+ */
134
+ async function sendCardByCardId(params) {
135
+ const { cfg, to, cardId, replyToMessageId, replyInThread, accountId } = params;
136
+ const client = lark_client_1.LarkClient.fromCfg(cfg, accountId).sdk;
137
+ const contentPayload = JSON.stringify({
138
+ type: 'card',
139
+ data: { card_id: cardId },
140
+ });
141
+ if (replyToMessageId) {
142
+ // 规范化 message_id,处理合成 ID(如 "om_xxx:auth-complete")
143
+ const normalizedId = (0, targets_1.normalizeMessageId)(replyToMessageId);
144
+ const response = await (0, message_unavailable_1.runWithMessageUnavailableGuard)({
145
+ messageId: normalizedId,
146
+ operation: 'im.message.reply(interactive.cardkit)',
147
+ fn: () => client.im.message.reply({
148
+ path: { message_id: normalizedId },
149
+ data: {
150
+ content: contentPayload,
151
+ msg_type: 'interactive',
152
+ reply_in_thread: replyInThread,
153
+ },
154
+ }),
155
+ });
156
+ return {
157
+ messageId: response?.data?.message_id ?? '',
158
+ chatId: response?.data?.chat_id ?? '',
159
+ };
160
+ }
161
+ const target = (0, targets_1.normalizeFeishuTarget)(to);
162
+ if (!target) {
163
+ throw new Error(`[feishu-send] Invalid target: "${to}"`);
164
+ }
165
+ const receiveIdType = (0, targets_1.resolveReceiveIdType)(target);
166
+ const response = await client.im.message.create({
167
+ // SDK 类型将 receive_id_type 限定为字面量联合,但运行时接受动态值
168
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
169
+ params: { receive_id_type: receiveIdType },
170
+ data: {
171
+ receive_id: target,
172
+ msg_type: 'interactive',
173
+ content: contentPayload,
174
+ },
175
+ });
176
+ return {
177
+ messageId: response?.data?.message_id ?? '',
178
+ chatId: response?.data?.chat_id ?? '',
179
+ };
180
+ }
181
+ /**
182
+ * Close (or open) the streaming mode on a CardKit card.
183
+ *
184
+ * Must be called after streaming is complete to restore normal card
185
+ * behaviour (forwarding, interaction callbacks, etc.).
186
+ */
187
+ async function setCardStreamingMode(params) {
188
+ const { cfg, cardId, streamingMode, sequence, accountId } = params;
189
+ const client = lark_client_1.LarkClient.fromCfg(cfg, accountId).sdk;
190
+ // SDK 返回类型不完整,运行时包含 code/msg 字段
191
+ const resp = (await client.cardkit.v1.card.settings({
192
+ data: {
193
+ settings: JSON.stringify({ streaming_mode: streamingMode }),
194
+ sequence,
195
+ },
196
+ path: { card_id: cardId },
197
+ }));
198
+ logCardKitResponse({
199
+ resp,
200
+ api: 'card.settings',
201
+ context: `seq=${sequence}, streaming_mode=${streamingMode}`,
202
+ });
203
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ *
5
+ * Generic throttled flush controller.
6
+ *
7
+ * A pure scheduling primitive that manages timer-based throttling,
8
+ * mutex-guarded flushing, and reflush-on-conflict. Contains no
9
+ * business logic — the actual flush work is provided via a callback.
10
+ */
11
+ export declare class FlushController {
12
+ private readonly doFlush;
13
+ private flushInProgress;
14
+ private flushResolvers;
15
+ private needsReflush;
16
+ private pendingFlushTimer;
17
+ private lastUpdateTime;
18
+ private isCompleted;
19
+ constructor(doFlush: () => Promise<void>);
20
+ /** Mark the controller as completed — no more flushes after current one. */
21
+ complete(): void;
22
+ /** Cancel any pending deferred flush timer. */
23
+ cancelPendingFlush(): void;
24
+ /** Wait for any in-progress flush to finish. */
25
+ waitForFlush(): Promise<void>;
26
+ /**
27
+ * Execute a flush (mutex-guarded, with reflush on conflict).
28
+ *
29
+ * If a flush is already in progress, marks needsReflush so a
30
+ * follow-up flush fires immediately after the current one completes.
31
+ */
32
+ flush(): Promise<void>;
33
+ /**
34
+ * Throttled update entry point.
35
+ *
36
+ * @param throttleMs - Minimum interval between flushes (varies by
37
+ * CardKit vs IM patch mode). Passed in by the caller so this
38
+ * controller remains business-logic-free.
39
+ */
40
+ throttledUpdate(throttleMs: number): Promise<void>;
41
+ /** Overridable gate: subclasses / consumers can set via setCardMessageReady. */
42
+ private _cardMessageReady;
43
+ cardMessageReady(): boolean;
44
+ setCardMessageReady(ready: boolean): void;
45
+ }