@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,310 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * ChannelPlugin interface implementation for the Lark/Feishu channel.
7
+ *
8
+ * This is the top-level entry point that the OpenClaw plugin system uses to
9
+ * discover capabilities, resolve accounts, obtain outbound adapters, and
10
+ * start the inbound event gateway.
11
+ */
12
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
25
+ }) : function(o, v) {
26
+ o["default"] = v;
27
+ });
28
+ var __importStar = (this && this.__importStar) || (function () {
29
+ var ownKeys = function(o) {
30
+ ownKeys = Object.getOwnPropertyNames || function (o) {
31
+ var ar = [];
32
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
33
+ return ar;
34
+ };
35
+ return ownKeys(o);
36
+ };
37
+ return function (mod) {
38
+ if (mod && mod.__esModule) return mod;
39
+ var result = {};
40
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
41
+ __setModuleDefault(result, mod);
42
+ return result;
43
+ };
44
+ })();
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.feishuPlugin = void 0;
47
+ const account_id_1 = require("openclaw/plugin-sdk/account-id");
48
+ const channel_status_1 = require("openclaw/plugin-sdk/channel-status");
49
+ const accounts_1 = require("../core/accounts.js");
50
+ const outbound_1 = require("../messaging/outbound/outbound.js");
51
+ const actions_1 = require("../messaging/outbound/actions.js");
52
+ const policy_1 = require("../messaging/inbound/policy.js");
53
+ const lark_client_1 = require("../core/lark-client.js");
54
+ const send_1 = require("../messaging/outbound/send.js");
55
+ const targets_1 = require("../core/targets.js");
56
+ const onboarding_auth_1 = require("../tools/onboarding-auth.js");
57
+ const lark_logger_1 = require("../core/lark-logger.js");
58
+ const config_schema_1 = require("../core/config-schema.js");
59
+ const config_adapter_1 = require("./config-adapter.js");
60
+ const directory_1 = require("./directory.js");
61
+ const pluginLog = (0, lark_logger_1.larkLogger)('channel/plugin');
62
+ /** 状态轮询的探针结果缓存时长(5 分钟)。 */
63
+ const PROBE_CACHE_TTL_MS = 5 * 60 * 1000;
64
+ // ---------------------------------------------------------------------------
65
+ // Helpers
66
+ // ---------------------------------------------------------------------------
67
+ /** Convert nullable SDK params to optional params for directory functions. */
68
+ function adaptDirectoryParams(params) {
69
+ return {
70
+ cfg: params.cfg,
71
+ query: params.query ?? undefined,
72
+ limit: params.limit ?? undefined,
73
+ accountId: params.accountId ?? undefined,
74
+ };
75
+ }
76
+ // ---------------------------------------------------------------------------
77
+ // Meta
78
+ // ---------------------------------------------------------------------------
79
+ const meta = {
80
+ id: 'feishu',
81
+ label: 'Feishu',
82
+ selectionLabel: 'Lark/Feishu (\u98DE\u4E66)',
83
+ docsPath: '/channels/feishu',
84
+ docsLabel: 'feishu',
85
+ blurb: '\u98DE\u4E66/Lark enterprise messaging.',
86
+ aliases: ['lark'],
87
+ order: 70,
88
+ };
89
+ // ---------------------------------------------------------------------------
90
+ // Channel plugin definition
91
+ // ---------------------------------------------------------------------------
92
+ exports.feishuPlugin = {
93
+ id: 'feishu',
94
+ meta: {
95
+ ...meta,
96
+ },
97
+ // -------------------------------------------------------------------------
98
+ // Pairing
99
+ // -------------------------------------------------------------------------
100
+ pairing: {
101
+ idLabel: 'feishuUserId',
102
+ normalizeAllowEntry: (entry) => entry.replace(/^(feishu|user|open_id):/i, ''),
103
+ notifyApproval: async ({ cfg, id }) => {
104
+ const accountId = (0, accounts_1.getDefaultLarkAccountId)(cfg);
105
+ pluginLog.info('notifyApproval called', { id, accountId });
106
+ // 1. 发送配对成功消息(保持现有行为)
107
+ await (0, send_1.sendMessageFeishu)({
108
+ cfg,
109
+ to: id,
110
+ text: channel_status_1.PAIRING_APPROVED_MESSAGE,
111
+ accountId,
112
+ });
113
+ // 2. 触发 onboarding
114
+ try {
115
+ await (0, onboarding_auth_1.triggerOnboarding)({ cfg, userOpenId: id, accountId });
116
+ pluginLog.info('onboarding completed', { id });
117
+ }
118
+ catch (err) {
119
+ pluginLog.warn('onboarding failed', { id, error: String(err) });
120
+ }
121
+ },
122
+ },
123
+ // -------------------------------------------------------------------------
124
+ // Capabilities
125
+ // -------------------------------------------------------------------------
126
+ capabilities: {
127
+ chatTypes: ['direct', 'group'],
128
+ media: true,
129
+ reactions: true,
130
+ threads: true,
131
+ polls: false,
132
+ nativeCommands: true,
133
+ blockStreaming: true,
134
+ },
135
+ // -------------------------------------------------------------------------
136
+ // Agent prompt
137
+ // -------------------------------------------------------------------------
138
+ agentPrompt: {
139
+ messageToolHints: () => [
140
+ '- Feishu targeting: omit `target` to reply to the current conversation (auto-inferred). Explicit targets: `user:open_id` or `chat:chat_id`.',
141
+ '- Feishu supports interactive cards for rich messages.',
142
+ '- Feishu reactions use UPPERCASE emoji type names (e.g. `OK`,`THUMBSUP`,`THANKS`,`MUSCLE`,`FINGERHEART`,`APPLAUSE`,`FISTBUMP`,`JIAYI`,`DONE`,`SMILE`,`BLUSH` ), not Unicode emoji characters.',
143
+ "- Feishu `action=delete`/`action=unsend` only deletes messages sent by the bot. When the user quotes a message and says 'delete this', use the **quoted message's** message_id, not the user's own message_id.",
144
+ ],
145
+ },
146
+ // -------------------------------------------------------------------------
147
+ // Groups
148
+ // -------------------------------------------------------------------------
149
+ groups: {
150
+ resolveToolPolicy: policy_1.resolveFeishuGroupToolPolicy,
151
+ },
152
+ // -------------------------------------------------------------------------
153
+ // Reload
154
+ // -------------------------------------------------------------------------
155
+ reload: { configPrefixes: ['channels.feishu'] },
156
+ // -------------------------------------------------------------------------
157
+ // Config schema (JSON Schema)
158
+ // -------------------------------------------------------------------------
159
+ configSchema: {
160
+ schema: config_schema_1.FEISHU_CONFIG_JSON_SCHEMA,
161
+ },
162
+ // -------------------------------------------------------------------------
163
+ // Config adapter
164
+ // -------------------------------------------------------------------------
165
+ config: {
166
+ listAccountIds: (cfg) => (0, accounts_1.getLarkAccountIds)(cfg),
167
+ resolveAccount: (cfg, accountId) => (0, accounts_1.getLarkAccount)(cfg, accountId),
168
+ defaultAccountId: (cfg) => (0, accounts_1.getDefaultLarkAccountId)(cfg),
169
+ setAccountEnabled: ({ cfg, accountId, enabled }) => {
170
+ return (0, config_adapter_1.setAccountEnabled)(cfg, accountId, enabled);
171
+ },
172
+ deleteAccount: ({ cfg, accountId }) => {
173
+ return (0, config_adapter_1.deleteAccount)(cfg, accountId);
174
+ },
175
+ isConfigured: (account) => account.configured,
176
+ describeAccount: (account) => ({
177
+ accountId: account.accountId,
178
+ enabled: account.enabled,
179
+ configured: account.configured,
180
+ name: account.name,
181
+ appId: account.appId,
182
+ brand: account.brand,
183
+ }),
184
+ resolveAllowFrom: ({ cfg, accountId }) => {
185
+ const account = (0, accounts_1.getLarkAccount)(cfg, accountId);
186
+ return (account.config?.allowFrom ?? []).map((entry) => String(entry));
187
+ },
188
+ formatAllowFrom: ({ allowFrom }) => allowFrom
189
+ .map((entry) => String(entry).trim())
190
+ .filter(Boolean)
191
+ .map((entry) => entry.toLowerCase()),
192
+ },
193
+ // -------------------------------------------------------------------------
194
+ // Security
195
+ // -------------------------------------------------------------------------
196
+ security: {
197
+ collectWarnings: ({ cfg, accountId }) => (0, config_adapter_1.collectFeishuSecurityWarnings)({ cfg, accountId: accountId ?? account_id_1.DEFAULT_ACCOUNT_ID }),
198
+ },
199
+ // -------------------------------------------------------------------------
200
+ // Setup
201
+ // -------------------------------------------------------------------------
202
+ setup: {
203
+ resolveAccountId: () => account_id_1.DEFAULT_ACCOUNT_ID,
204
+ applyAccountConfig: ({ cfg, accountId }) => {
205
+ return (0, config_adapter_1.applyAccountConfig)(cfg, accountId, { enabled: true });
206
+ },
207
+ },
208
+ // -------------------------------------------------------------------------
209
+ // Messaging
210
+ // -------------------------------------------------------------------------
211
+ messaging: {
212
+ normalizeTarget: (raw) => (0, targets_1.normalizeFeishuTarget)(raw) ?? undefined,
213
+ targetResolver: {
214
+ looksLikeId: targets_1.looksLikeFeishuId,
215
+ hint: '<chatId|user:openId|chat:chatId>',
216
+ },
217
+ },
218
+ // -------------------------------------------------------------------------
219
+ // Directory
220
+ // -------------------------------------------------------------------------
221
+ directory: {
222
+ self: async () => null,
223
+ listPeers: async (p) => (0, directory_1.listFeishuDirectoryPeers)(adaptDirectoryParams(p)),
224
+ listGroups: async (p) => (0, directory_1.listFeishuDirectoryGroups)(adaptDirectoryParams(p)),
225
+ listPeersLive: async (p) => (0, directory_1.listFeishuDirectoryPeersLive)(adaptDirectoryParams(p)),
226
+ listGroupsLive: async (p) => (0, directory_1.listFeishuDirectoryGroupsLive)(adaptDirectoryParams(p)),
227
+ },
228
+ // -------------------------------------------------------------------------
229
+ // Outbound
230
+ // -------------------------------------------------------------------------
231
+ outbound: outbound_1.feishuOutbound,
232
+ // -------------------------------------------------------------------------
233
+ // Threading
234
+ // -------------------------------------------------------------------------
235
+ threading: {
236
+ buildToolContext: ({ context, hasRepliedRef }) => ({
237
+ currentChannelId: (0, targets_1.normalizeFeishuTarget)(context.To ?? '') ?? undefined,
238
+ currentThreadTs: context.MessageThreadId != null ? String(context.MessageThreadId) : undefined,
239
+ currentMessageId: context.CurrentMessageId,
240
+ hasRepliedRef,
241
+ }),
242
+ },
243
+ // -------------------------------------------------------------------------
244
+ // Actions
245
+ // -------------------------------------------------------------------------
246
+ actions: actions_1.feishuMessageActions,
247
+ // -------------------------------------------------------------------------
248
+ // Status
249
+ // -------------------------------------------------------------------------
250
+ status: {
251
+ defaultRuntime: {
252
+ accountId: account_id_1.DEFAULT_ACCOUNT_ID,
253
+ running: false,
254
+ lastStartAt: null,
255
+ lastStopAt: null,
256
+ lastError: null,
257
+ port: null,
258
+ },
259
+ buildChannelSummary: ({ snapshot }) => ({
260
+ configured: snapshot.configured ?? false,
261
+ running: snapshot.running ?? false,
262
+ lastStartAt: snapshot.lastStartAt ?? null,
263
+ lastStopAt: snapshot.lastStopAt ?? null,
264
+ lastError: snapshot.lastError ?? null,
265
+ port: snapshot.port ?? null,
266
+ probe: snapshot.probe,
267
+ lastProbeAt: snapshot.lastProbeAt ?? null,
268
+ }),
269
+ probeAccount: async ({ account }) => {
270
+ return await lark_client_1.LarkClient.fromAccount(account).probe({ maxAgeMs: PROBE_CACHE_TTL_MS });
271
+ },
272
+ buildAccountSnapshot: ({ account, runtime, probe }) => ({
273
+ accountId: account.accountId,
274
+ enabled: account.enabled,
275
+ configured: account.configured,
276
+ name: account.name,
277
+ appId: account.appId,
278
+ brand: account.brand,
279
+ running: runtime?.running ?? false,
280
+ lastStartAt: runtime?.lastStartAt ?? null,
281
+ lastStopAt: runtime?.lastStopAt ?? null,
282
+ lastError: runtime?.lastError ?? null,
283
+ port: runtime?.port ?? null,
284
+ probe,
285
+ }),
286
+ },
287
+ // -------------------------------------------------------------------------
288
+ // Gateway
289
+ // -------------------------------------------------------------------------
290
+ gateway: {
291
+ startAccount: async (ctx) => {
292
+ const { monitorFeishuProvider } = await Promise.resolve().then(() => __importStar(require('./monitor.js')));
293
+ const account = (0, accounts_1.getLarkAccount)(ctx.cfg, ctx.accountId);
294
+ const port = account.config?.webhookPort ?? null;
295
+ ctx.setStatus({ accountId: ctx.accountId, port });
296
+ ctx.log?.info(`starting feishu[${ctx.accountId}] (mode: ${account.config?.connectionMode ?? 'websocket'})`);
297
+ return monitorFeishuProvider({
298
+ config: ctx.cfg,
299
+ runtime: ctx.runtime,
300
+ abortSignal: ctx.abortSignal,
301
+ accountId: ctx.accountId,
302
+ });
303
+ },
304
+ stopAccount: async (ctx) => {
305
+ ctx.log?.info(`stopping feishu[${ctx.accountId}]`);
306
+ await lark_client_1.LarkClient.clearCache(ctx.accountId);
307
+ ctx.log?.info(`stopped feishu[${ctx.accountId}]`);
308
+ },
309
+ },
310
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+ import { type LarkClientCredentials } from '../core/lark-client';
6
+ import type { FeishuProbeResult } from './types';
7
+ /**
8
+ * Probe the Feishu bot connection by calling the bot/v3/info API.
9
+ *
10
+ * Returns a result indicating whether the bot is reachable and its
11
+ * basic identity (name, open_id). Used by onboarding and status
12
+ * checks to verify credentials before committing them to config.
13
+ */
14
+ export declare function probeFeishu(credentials?: LarkClientCredentials): Promise<FeishuProbeResult>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.probeFeishu = probeFeishu;
8
+ const lark_client_1 = require("../core/lark-client.js");
9
+ /**
10
+ * Probe the Feishu bot connection by calling the bot/v3/info API.
11
+ *
12
+ * Returns a result indicating whether the bot is reachable and its
13
+ * basic identity (name, open_id). Used by onboarding and status
14
+ * checks to verify credentials before committing them to config.
15
+ */
16
+ async function probeFeishu(credentials) {
17
+ if (!credentials?.appId || !credentials?.appSecret) {
18
+ return {
19
+ ok: false,
20
+ error: 'missing credentials (appId, appSecret)',
21
+ };
22
+ }
23
+ return lark_client_1.LarkClient.fromCredentials(credentials).probe();
24
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ *
5
+ * Channel type definitions for the Lark/Feishu channel plugin.
6
+ */
7
+ import type { ClawdbotConfig, RuntimeEnv } from 'openclaw/plugin-sdk';
8
+ import type { HistoryEntry } from 'openclaw/plugin-sdk/reply-history';
9
+ import type { LarkClient } from '../core/lark-client';
10
+ import type { MessageDedup } from '../messaging/inbound/dedup';
11
+ export type { FeishuProbeResult } from '../core/types';
12
+ export interface MonitorFeishuOpts {
13
+ config?: ClawdbotConfig;
14
+ runtime?: RuntimeEnv;
15
+ abortSignal?: AbortSignal;
16
+ accountId?: string;
17
+ }
18
+ export interface FeishuDirectoryPeer {
19
+ kind: 'user';
20
+ id: string;
21
+ name?: string;
22
+ }
23
+ export interface FeishuDirectoryGroup {
24
+ kind: 'group';
25
+ id: string;
26
+ name?: string;
27
+ }
28
+ export interface MonitorContext {
29
+ cfg: ClawdbotConfig;
30
+ lark: LarkClient;
31
+ accountId: string;
32
+ chatHistories: Map<string, HistoryEntry[]>;
33
+ messageDedup: MessageDedup;
34
+ runtime?: RuntimeEnv;
35
+ log: (...args: unknown[]) => void;
36
+ error: (...args: unknown[]) => void;
37
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * Channel type definitions for the Lark/Feishu channel plugin.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ *
5
+ * feishu_auth command — 飞书用户权限批量授权命令实现
6
+ *
7
+ * 直接复用 onboarding-auth.ts 的 triggerOnboarding() 函数。
8
+ * 注意:此命令仅限应用 owner 执行(与 onboarding 逻辑一致)
9
+ */
10
+ import type { OpenClawConfig } from 'openclaw/plugin-sdk';
11
+ import type { FeishuLocale } from './locale';
12
+ /**
13
+ * 执行飞书用户权限批量授权命令
14
+ * 直接调用 triggerOnboarding(),包含 owner 检查
15
+ */
16
+ export declare function runFeishuAuth(config: OpenClawConfig, locale?: FeishuLocale): Promise<string>;
17
+ /**
18
+ * 运行飞书授权命令,同时生成中英双语结果。
19
+ * 副作用(triggerOnboarding)只执行一次,结果格式化为双语文本。
20
+ */
21
+ export declare function runFeishuAuthI18n(config: OpenClawConfig): Promise<Record<FeishuLocale, string>>;
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * feishu_auth command — 飞书用户权限批量授权命令实现
7
+ *
8
+ * 直接复用 onboarding-auth.ts 的 triggerOnboarding() 函数。
9
+ * 注意:此命令仅限应用 owner 执行(与 onboarding 逻辑一致)
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.runFeishuAuth = runFeishuAuth;
13
+ exports.runFeishuAuthI18n = runFeishuAuthI18n;
14
+ const onboarding_auth_1 = require("../tools/onboarding-auth.js");
15
+ const lark_ticket_1 = require("../core/lark-ticket.js");
16
+ const accounts_1 = require("../core/accounts.js");
17
+ const lark_client_1 = require("../core/lark-client.js");
18
+ const app_scope_checker_1 = require("../core/app-scope-checker.js");
19
+ const token_store_1 = require("../core/token-store.js");
20
+ const tool_scopes_1 = require("../core/tool-scopes.js");
21
+ const owner_policy_1 = require("../core/owner-policy.js");
22
+ const domains_1 = require("../core/domains.js");
23
+ // ---------------------------------------------------------------------------
24
+ // I18n text map
25
+ // ---------------------------------------------------------------------------
26
+ const T = {
27
+ zh_cn: {
28
+ noIdentity: '❌ 无法获取用户身份,请在飞书对话中使用此命令',
29
+ accountIncomplete: (accountId) => `❌ 账号 ${accountId} 配置不完整`,
30
+ missingSelfManage: (link) => `❌ 应用缺少核心权限 application:application:self_manage,无法查询可授权 scope 列表。\n\n请管理员在飞书开放平台开通此权限后重试:[申请权限](${link})`,
31
+ ownerOnly: '❌ 此命令仅限应用 owner 执行\n\n如需授权,请联系应用管理员。',
32
+ missingOfflineAccess: (link) => `❌ 应用缺少核心权限 offline_access,无法查询可授权 scope 列表。\n\n请管理员在飞书开放平台开通此权限后重试:[申请权限](${link})`,
33
+ noUserScopes: '当前应用未开通任何用户级权限,无需授权。',
34
+ allAuthorized: (count) => `✅ 您已授权所有可用权限(共 ${count} 个),无需重复授权。`,
35
+ authSent: '✅ 已发送授权请求',
36
+ },
37
+ en_us: {
38
+ noIdentity: '❌ Unable to identify user. Please use this command in a Feishu conversation.',
39
+ accountIncomplete: (accountId) => `❌ Account ${accountId} configuration is incomplete`,
40
+ missingSelfManage: (link) => `❌ App is missing the core permission application:application:self_manage and cannot query available scopes.\n\nPlease ask an admin to grant this permission on the Feishu Open Platform: [Apply](${link})`,
41
+ ownerOnly: '❌ This command is restricted to the app owner.\n\nPlease contact the app admin for authorization.',
42
+ missingOfflineAccess: (link) => `❌ App is missing the core permission offline_access and cannot query available scopes.\n\nPlease ask an admin to grant this permission on the Feishu Open Platform: [Apply](${link})`,
43
+ noUserScopes: 'No user-level permissions are enabled for this app. Authorization is not needed.',
44
+ allAuthorized: (count) => `✅ You have authorized all available permissions (${count} total). No re-authorization needed.`,
45
+ authSent: '✅ Authorization request sent',
46
+ },
47
+ };
48
+ /**
49
+ * Format an AuthResult into a locale-specific message string.
50
+ */
51
+ function formatAuthResult(result, locale) {
52
+ const t = T[locale];
53
+ switch (result.kind) {
54
+ case 'no_identity':
55
+ return t.noIdentity;
56
+ case 'account_incomplete':
57
+ return t.accountIncomplete(result.accountId);
58
+ case 'missing_self_manage':
59
+ return t.missingSelfManage(result.link);
60
+ case 'owner_only':
61
+ return t.ownerOnly;
62
+ case 'missing_offline_access':
63
+ return t.missingOfflineAccess(result.link);
64
+ case 'no_user_scopes':
65
+ return t.noUserScopes;
66
+ case 'all_authorized':
67
+ return t.allAuthorized(result.count);
68
+ case 'auth_sent':
69
+ return t.authSent;
70
+ }
71
+ }
72
+ // ---------------------------------------------------------------------------
73
+ // Core logic (executes side-effects exactly once)
74
+ // ---------------------------------------------------------------------------
75
+ /**
76
+ * Execute the auth command logic, including side-effects (triggerOnboarding).
77
+ * Returns a discriminated result that can be formatted into any locale.
78
+ */
79
+ async function executeFeishuAuth(config) {
80
+ const ticket = (0, lark_ticket_1.getTicket)();
81
+ const senderOpenId = ticket?.senderOpenId;
82
+ if (!senderOpenId) {
83
+ return { kind: 'no_identity' };
84
+ }
85
+ // 提前检查 owner 身份,给出明确提示
86
+ const acct = (0, accounts_1.getLarkAccount)(config, ticket.accountId);
87
+ if (!acct.configured) {
88
+ return { kind: 'account_incomplete', accountId: ticket.accountId };
89
+ }
90
+ const sdk = lark_client_1.LarkClient.fromAccount(acct).sdk;
91
+ const { appId } = acct;
92
+ const openDomain = (0, domains_1.openPlatformDomain)(acct.brand);
93
+ try {
94
+ await (0, app_scope_checker_1.getAppInfo)(sdk, appId);
95
+ }
96
+ catch {
97
+ const link = `${openDomain}/app/${appId}/auth?q=application:application:self_manage&op_from=feishu-openclaw&token_type=tenant`;
98
+ return { kind: 'missing_self_manage', link };
99
+ }
100
+ // Owner 检查(fail-close: 授权命令安全优先)
101
+ try {
102
+ await (0, owner_policy_1.assertOwnerAccessStrict)(acct, sdk, senderOpenId);
103
+ }
104
+ catch (err) {
105
+ if (err instanceof owner_policy_1.OwnerAccessDeniedError) {
106
+ return { kind: 'owner_only' };
107
+ }
108
+ throw err;
109
+ }
110
+ // 预检:是否还有未授权的 scope
111
+ let appScopes;
112
+ try {
113
+ appScopes = await (0, app_scope_checker_1.getAppGrantedScopes)(sdk, appId, 'user');
114
+ }
115
+ catch {
116
+ const link = `${openDomain}/app/${appId}/auth?q=application:application:self_manage&op_from=feishu-openclaw&token_type=tenant`;
117
+ return { kind: 'missing_self_manage', link };
118
+ }
119
+ // offline_access 预检 — OAuth 必须的前提权限
120
+ const allScopes = await (0, app_scope_checker_1.getAppGrantedScopes)(sdk, appId);
121
+ if (allScopes.length > 0 && !allScopes.includes('offline_access')) {
122
+ const link = `${openDomain}/app/${appId}/auth?q=offline_access&op_from=feishu-openclaw&token_type=user`;
123
+ return { kind: 'missing_offline_access', link };
124
+ }
125
+ appScopes = (0, tool_scopes_1.filterSensitiveScopes)(appScopes);
126
+ if (appScopes.length === 0) {
127
+ return { kind: 'no_user_scopes' };
128
+ }
129
+ const existing = await (0, token_store_1.getStoredToken)(appId, senderOpenId);
130
+ const tokenValid = existing && (0, token_store_1.tokenStatus)(existing) !== 'expired';
131
+ const grantedScopes = new Set(tokenValid ? (existing.scope?.split(/\s+/).filter(Boolean) ?? []) : []);
132
+ const missingScopes = appScopes.filter((s) => !grantedScopes.has(s));
133
+ if (missingScopes.length === 0) {
134
+ return { kind: 'all_authorized', count: appScopes.length };
135
+ }
136
+ // 调用 triggerOnboarding 执行批量授权(副作用,只执行一次)
137
+ await (0, onboarding_auth_1.triggerOnboarding)({
138
+ cfg: config,
139
+ userOpenId: senderOpenId,
140
+ accountId: ticket.accountId,
141
+ });
142
+ return { kind: 'auth_sent' };
143
+ }
144
+ // ---------------------------------------------------------------------------
145
+ // Public API
146
+ // ---------------------------------------------------------------------------
147
+ /**
148
+ * 执行飞书用户权限批量授权命令
149
+ * 直接调用 triggerOnboarding(),包含 owner 检查
150
+ */
151
+ async function runFeishuAuth(config, locale = 'zh_cn') {
152
+ const result = await executeFeishuAuth(config);
153
+ return formatAuthResult(result, locale);
154
+ }
155
+ /**
156
+ * 运行飞书授权命令,同时生成中英双语结果。
157
+ * 副作用(triggerOnboarding)只执行一次,结果格式化为双语文本。
158
+ */
159
+ async function runFeishuAuthI18n(config) {
160
+ const result = await executeFeishuAuth(config);
161
+ return {
162
+ zh_cn: formatAuthResult(result, 'zh_cn'),
163
+ en_us: formatAuthResult(result, 'en_us'),
164
+ };
165
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ *
5
+ * Diagnostic module for the Lark/Feishu plugin.
6
+ *
7
+ * Collects environment info, account configuration, API connectivity,
8
+ * app permissions, tool registration state, and recent error logs into
9
+ * a structured report that users can share with developers for
10
+ * remote troubleshooting.
11
+ */
12
+ import type { OpenClawConfig } from 'openclaw/plugin-sdk';
13
+ interface DiagLogger {
14
+ info: (message: string) => void;
15
+ warn: (message: string) => void;
16
+ error: (message: string) => void;
17
+ }
18
+ type CheckStatus = 'pass' | 'warn' | 'fail' | 'skip';
19
+ interface DiagCheckResult {
20
+ name: string;
21
+ status: CheckStatus;
22
+ message: string;
23
+ details?: string;
24
+ }
25
+ interface AccountDiagResult {
26
+ accountId: string;
27
+ name?: string;
28
+ enabled: boolean;
29
+ configured: boolean;
30
+ appId?: string;
31
+ brand: string;
32
+ checks: DiagCheckResult[];
33
+ }
34
+ interface DiagReport {
35
+ timestamp: string;
36
+ environment: {
37
+ nodeVersion: string;
38
+ platform: string;
39
+ arch: string;
40
+ pluginVersion: string;
41
+ };
42
+ accounts: AccountDiagResult[];
43
+ toolsRegistered: string[];
44
+ recentErrors: string[];
45
+ overallStatus: 'healthy' | 'degraded' | 'unhealthy';
46
+ checks: DiagCheckResult[];
47
+ }
48
+ export declare function runDiagnosis(params: {
49
+ config: OpenClawConfig;
50
+ logger?: DiagLogger;
51
+ }): Promise<DiagReport>;
52
+ export declare function formatDiagReportText(report: DiagReport): string;
53
+ /**
54
+ * Extract all log lines tagged with a specific message_id from gateway.log.
55
+ *
56
+ * Scans the last 1MB of the log file for lines containing `[msg:{messageId}]`.
57
+ * Returns matching lines in chronological order.
58
+ */
59
+ export declare function traceByMessageId(messageId: string): Promise<string[]>;
60
+ /**
61
+ * Format trace output for CLI display.
62
+ */
63
+ export declare function formatTraceOutput(lines: string[], messageId: string): string;
64
+ /**
65
+ * Analyze trace log lines and produce a structured CLI report.
66
+ */
67
+ export declare function analyzeTrace(lines: string[], _messageId: string): string;
68
+ export declare function formatDiagReportCli(report: DiagReport): string;
69
+ export {};