@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,152 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * feishu_im_user_message tool -- 以用户身份发送/回复 IM 消息
7
+ *
8
+ * Actions: send, reply
9
+ *
10
+ * Uses the Feishu IM API:
11
+ * - send: POST /open-apis/im/v1/messages?receive_id_type=...
12
+ * - reply: POST /open-apis/im/v1/messages/:message_id/reply
13
+ *
14
+ * 全部以用户身份(user_access_token)调用,scope 来自 real-scope.json。
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.registerFeishuImUserMessageTool = registerFeishuImUserMessageTool;
18
+ const typebox_1 = require("@sinclair/typebox");
19
+ const helpers_1 = require("../helpers.js");
20
+ // ---------------------------------------------------------------------------
21
+ // Schema
22
+ // ---------------------------------------------------------------------------
23
+ const FeishuImMessageSchema = typebox_1.Type.Union([
24
+ // SEND
25
+ typebox_1.Type.Object({
26
+ action: typebox_1.Type.Literal('send'),
27
+ receive_id_type: (0, helpers_1.StringEnum)(['open_id', 'chat_id'], {
28
+ description: '接收者 ID 类型:open_id(私聊,ou_xxx)、chat_id(群聊,oc_xxx)',
29
+ }),
30
+ receive_id: typebox_1.Type.String({
31
+ description: "接收者 ID,与 receive_id_type 对应。open_id 填 'ou_xxx',chat_id 填 'oc_xxx'",
32
+ }),
33
+ msg_type: (0, helpers_1.StringEnum)(['text', 'post', 'image', 'file', 'audio', 'media', 'interactive', 'share_chat', 'share_user'], {
34
+ description: '消息类型:text(纯文本)、post(富文本)、image(图片)、file(文件)、interactive(消息卡片)、share_chat(群名片)、share_user(个人名片)等',
35
+ }),
36
+ content: typebox_1.Type.String({
37
+ description: '消息内容(JSON 字符串),格式取决于 msg_type。' +
38
+ '示例:text → \'{"text":"你好"}\',' +
39
+ 'image → \'{"image_key":"img_xxx"}\',' +
40
+ 'share_chat → \'{"chat_id":"oc_xxx"}\',' +
41
+ 'post → \'{"zh_cn":{"title":"标题","content":[[{"tag":"text","text":"正文"}]]}}\'',
42
+ }),
43
+ uuid: typebox_1.Type.Optional(typebox_1.Type.String({
44
+ description: '幂等唯一标识。同一 uuid 在 1 小时内只会发送一条消息,用于去重',
45
+ })),
46
+ }),
47
+ // REPLY
48
+ typebox_1.Type.Object({
49
+ action: typebox_1.Type.Literal('reply'),
50
+ message_id: typebox_1.Type.String({
51
+ description: '被回复消息的 ID(om_xxx 格式)',
52
+ }),
53
+ msg_type: (0, helpers_1.StringEnum)(['text', 'post', 'image', 'file', 'audio', 'media', 'interactive', 'share_chat', 'share_user'], {
54
+ description: '消息类型:text(纯文本)、post(富文本)、image(图片)、interactive(消息卡片)等',
55
+ }),
56
+ content: typebox_1.Type.String({
57
+ description: '回复消息内容(JSON 字符串),格式同 send 的 content',
58
+ }),
59
+ reply_in_thread: typebox_1.Type.Optional(typebox_1.Type.Boolean({
60
+ description: '是否以话题形式回复。true 则消息出现在该消息的话题中,false(默认)则出现在聊天主流',
61
+ })),
62
+ uuid: typebox_1.Type.Optional(typebox_1.Type.String({
63
+ description: '幂等唯一标识',
64
+ })),
65
+ }),
66
+ ]);
67
+ // ---------------------------------------------------------------------------
68
+ // Registration
69
+ // ---------------------------------------------------------------------------
70
+ function registerFeishuImUserMessageTool(api) {
71
+ if (!api.config)
72
+ return false;
73
+ const cfg = api.config;
74
+ const { toolClient, log } = (0, helpers_1.createToolContext)(api, 'feishu_im_user_message');
75
+ return (0, helpers_1.registerTool)(api, {
76
+ name: 'feishu_im_user_message',
77
+ label: 'Feishu: IM User Message',
78
+ description: '飞书用户身份 IM 消息工具。**有且仅当用户明确要求以自己身份发消息、回复消息时使用,当没有明确要求时优先使用message系统工具**。' +
79
+ '\n\nActions:' +
80
+ '\n- send(发送消息):发送消息到私聊或群聊。私聊用 receive_id_type=open_id,群聊用 receive_id_type=chat_id' +
81
+ '\n- reply(回复消息):回复指定 message_id 的消息,支持话题回复(reply_in_thread=true)' +
82
+ '\n\n【重要】content 必须是合法 JSON 字符串,格式取决于 msg_type。' +
83
+ '最常用:text 类型 content 为 \'{"text":"消息内容"}\'。' +
84
+ '\n\n【安全约束】此工具以用户身份发送消息,发出后对方看到的发送者是用户本人。' +
85
+ '调用前必须先向用户确认:1) 发送对象(哪个人或哪个群)2) 消息内容。' +
86
+ '禁止在用户未明确同意的情况下自行发送消息。',
87
+ parameters: FeishuImMessageSchema,
88
+ async execute(_toolCallId, params) {
89
+ const p = params;
90
+ try {
91
+ const client = toolClient();
92
+ switch (p.action) {
93
+ // -----------------------------------------------------------------
94
+ // SEND MESSAGE
95
+ // -----------------------------------------------------------------
96
+ case 'send': {
97
+ log.info(`send: receive_id_type=${p.receive_id_type}, receive_id=${p.receive_id}, msg_type=${p.msg_type}`);
98
+ const res = await client.invoke('feishu_im_user_message.send', (sdk, opts) => sdk.im.v1.message.create({
99
+ params: { receive_id_type: p.receive_id_type },
100
+ data: {
101
+ receive_id: p.receive_id,
102
+ msg_type: p.msg_type,
103
+ content: p.content,
104
+ uuid: p.uuid,
105
+ },
106
+ }, opts), {
107
+ as: 'user',
108
+ });
109
+ (0, helpers_1.assertLarkOk)(res);
110
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
+ const data = res.data;
112
+ log.info(`send: message sent, message_id=${data?.message_id}`);
113
+ return (0, helpers_1.json)({
114
+ message_id: data?.message_id,
115
+ chat_id: data?.chat_id,
116
+ create_time: data?.create_time,
117
+ });
118
+ }
119
+ // -----------------------------------------------------------------
120
+ // REPLY MESSAGE
121
+ // -----------------------------------------------------------------
122
+ case 'reply': {
123
+ log.info(`reply: message_id=${p.message_id}, msg_type=${p.msg_type}, reply_in_thread=${p.reply_in_thread ?? false}`);
124
+ const res = await client.invoke('feishu_im_user_message.reply', (sdk, opts) => sdk.im.v1.message.reply({
125
+ path: { message_id: p.message_id },
126
+ data: {
127
+ content: p.content,
128
+ msg_type: p.msg_type,
129
+ reply_in_thread: p.reply_in_thread,
130
+ uuid: p.uuid,
131
+ },
132
+ }, opts), {
133
+ as: 'user',
134
+ });
135
+ (0, helpers_1.assertLarkOk)(res);
136
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
137
+ const data = res.data;
138
+ log.info(`reply: message sent, message_id=${data?.message_id}`);
139
+ return (0, helpers_1.json)({
140
+ message_id: data?.message_id,
141
+ chat_id: data?.chat_id,
142
+ create_time: data?.create_time,
143
+ });
144
+ }
145
+ }
146
+ }
147
+ catch (err) {
148
+ return await (0, helpers_1.handleInvokeErrorWithAutoAuth)(err, cfg);
149
+ }
150
+ },
151
+ }, { name: 'feishu_im_user_message' });
152
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ *
5
+ * feishu_im_user_fetch_resource tool -- 以用户身份下载 IM 消息中的文件/图片资源
6
+ *
7
+ * 使用飞书 API:
8
+ * - im.v1.messageResource.get: GET /open-apis/im/v1/messages/:message_id/resources/:file_key
9
+ *
10
+ * 全部以用户身份(user_access_token)调用,scope 来自 real-scope.json。
11
+ */
12
+ import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
13
+ export declare function registerFeishuImUserFetchResourceTool(api: OpenClawPluginApi): boolean;
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * feishu_im_user_fetch_resource tool -- 以用户身份下载 IM 消息中的文件/图片资源
7
+ *
8
+ * 使用飞书 API:
9
+ * - im.v1.messageResource.get: GET /open-apis/im/v1/messages/:message_id/resources/:file_key
10
+ *
11
+ * 全部以用户身份(user_access_token)调用,scope 来自 real-scope.json。
12
+ */
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || (function () {
30
+ var ownKeys = function(o) {
31
+ ownKeys = Object.getOwnPropertyNames || function (o) {
32
+ var ar = [];
33
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
+ return ar;
35
+ };
36
+ return ownKeys(o);
37
+ };
38
+ return function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ })();
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.registerFeishuImUserFetchResourceTool = registerFeishuImUserFetchResourceTool;
48
+ const fs = __importStar(require("node:fs/promises"));
49
+ const path = __importStar(require("node:path"));
50
+ const temp_path_1 = require("openclaw/plugin-sdk/temp-path");
51
+ const typebox_1 = require("@sinclair/typebox");
52
+ const helpers_1 = require("../helpers.js");
53
+ // ---------------------------------------------------------------------------
54
+ // Helper: MIME type to extension mapping
55
+ // ---------------------------------------------------------------------------
56
+ const MIME_TO_EXT = {
57
+ // Images
58
+ 'image/png': '.png',
59
+ 'image/jpeg': '.jpg',
60
+ 'image/jpg': '.jpg',
61
+ 'image/gif': '.gif',
62
+ 'image/webp': '.webp',
63
+ 'image/svg+xml': '.svg',
64
+ 'image/bmp': '.bmp',
65
+ 'image/tiff': '.tiff',
66
+ // Videos
67
+ 'video/mp4': '.mp4',
68
+ 'video/mpeg': '.mpeg',
69
+ 'video/quicktime': '.mov',
70
+ 'video/x-msvideo': '.avi',
71
+ 'video/webm': '.webm',
72
+ // Audio
73
+ 'audio/mpeg': '.mp3',
74
+ 'audio/wav': '.wav',
75
+ 'audio/ogg': '.ogg',
76
+ 'audio/mp4': '.m4a',
77
+ // Documents
78
+ 'application/pdf': '.pdf',
79
+ 'application/msword': '.doc',
80
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': '.docx',
81
+ 'application/vnd.ms-excel': '.xls',
82
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': '.xlsx',
83
+ 'application/vnd.ms-powerpoint': '.ppt',
84
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation': '.pptx',
85
+ // Others
86
+ 'application/zip': '.zip',
87
+ 'application/x-rar-compressed': '.rar',
88
+ 'text/plain': '.txt',
89
+ 'application/json': '.json',
90
+ };
91
+ // ---------------------------------------------------------------------------
92
+ // Schema
93
+ // ---------------------------------------------------------------------------
94
+ const FetchResourceSchema = typebox_1.Type.Object({
95
+ message_id: typebox_1.Type.String({
96
+ description: '消息 ID(om_xxx 格式),从消息事件或消息列表中获取',
97
+ }),
98
+ file_key: typebox_1.Type.String({
99
+ description: '资源 Key,从消息体中获取。图片消息的 image_key(img_xxx)或文件消息的 file_key(file_xxx)',
100
+ }),
101
+ type: (0, helpers_1.StringEnum)(['image', 'file'], {
102
+ description: '资源类型:image(图片消息中的图片)、file(文件/音频/视频消息中的文件)',
103
+ }),
104
+ });
105
+ // ---------------------------------------------------------------------------
106
+ // Registration
107
+ // ---------------------------------------------------------------------------
108
+ function registerFeishuImUserFetchResourceTool(api) {
109
+ if (!api.config)
110
+ return false;
111
+ const cfg = api.config;
112
+ const { toolClient, log } = (0, helpers_1.createToolContext)(api, 'feishu_im_user_fetch_resource');
113
+ return (0, helpers_1.registerTool)(api, {
114
+ name: 'feishu_im_user_fetch_resource',
115
+ label: 'Feishu: IM Fetch Resource',
116
+ description: '【以用户身份】下载飞书 IM 消息中的文件或图片资源到本地文件。需要用户 OAuth 授权。' +
117
+ '\n\n适用场景:当你以用户身份调用了消息列表/搜索等 API 获取到 message_id 和 file_key 时,' +
118
+ '应使用本工具以同样的用户身份下载资源。' +
119
+ '\n注意:如果 message_id 来自当前对话上下文(用户发给机器人的消息、引用的消息),' +
120
+ '请使用 feishu_im_bot_image 工具以机器人身份下载,无需用户授权。' +
121
+ '\n\n参数说明:' +
122
+ '\n- message_id:消息 ID(om_xxx),从消息事件或消息列表中获取' +
123
+ '\n- file_key:资源 Key,从消息体中获取。图片用 image_key(img_xxx),文件用 file_key(file_xxx)' +
124
+ '\n- type:图片用 image,文件/音频/视频用 file' +
125
+ '\n\n文件自动保存到 /tmp/openclaw/ 下,返回值中的 saved_path 为实际保存路径。' +
126
+ '\n限制:文件大小不超过 100MB。不支持下载表情包、合并转发消息、卡片中的资源。',
127
+ parameters: FetchResourceSchema,
128
+ async execute(_toolCallId, params) {
129
+ const p = params;
130
+ try {
131
+ const client = toolClient();
132
+ log.info(`fetch_resource: message_id="${p.message_id}", file_key="${p.file_key}", type="${p.type}"`);
133
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
134
+ const res = await client.invoke('feishu_im_user_fetch_resource.default', (sdk, opts) => sdk.im.v1.messageResource.get({
135
+ params: { type: p.type },
136
+ path: { message_id: p.message_id, file_key: p.file_key },
137
+ }, opts), {
138
+ as: 'user',
139
+ });
140
+ // 响应是二进制流,使用 getReadableStream() 读取
141
+ const stream = res.getReadableStream();
142
+ const chunks = [];
143
+ for await (const chunk of stream) {
144
+ chunks.push(chunk);
145
+ }
146
+ const buffer = Buffer.concat(chunks);
147
+ log.info(`fetch_resource: downloaded ${buffer.length} bytes`);
148
+ // 从响应头获取 Content-Type,并确定文件扩展名
149
+ const contentType = res.headers?.['content-type'] || '';
150
+ log.info(`fetch_resource: content-type=${contentType}`);
151
+ // 从 Content-Type 推断扩展名,自动生成保存路径
152
+ const mimeType = contentType ? contentType.split(';')[0].trim() : '';
153
+ const mimeExt = mimeType ? MIME_TO_EXT[mimeType] : undefined;
154
+ const finalPath = (0, temp_path_1.buildRandomTempFilePath)({
155
+ prefix: 'im-resource',
156
+ extension: mimeExt,
157
+ });
158
+ log.info(`fetch_resource: saving to ${finalPath}`);
159
+ // 确保父目录存在
160
+ await fs.mkdir(path.dirname(finalPath), { recursive: true });
161
+ // 保存文件
162
+ try {
163
+ await fs.writeFile(finalPath, buffer);
164
+ log.info(`fetch_resource: saved to ${finalPath}`);
165
+ return (0, helpers_1.json)({
166
+ message_id: p.message_id,
167
+ file_key: p.file_key,
168
+ type: p.type,
169
+ size_bytes: buffer.length,
170
+ content_type: contentType,
171
+ saved_path: finalPath,
172
+ });
173
+ }
174
+ catch (err) {
175
+ log.error(`fetch_resource: failed to save file: ${err}`);
176
+ return (0, helpers_1.json)({
177
+ error: `保存文件失败: ${err instanceof Error ? err.message : String(err)}`,
178
+ });
179
+ }
180
+ }
181
+ catch (err) {
182
+ return await (0, helpers_1.handleInvokeErrorWithAutoAuth)(err, cfg);
183
+ }
184
+ },
185
+ }, { name: 'feishu_im_user_fetch_resource' });
186
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ *
5
+ * 时间工具函数 — 对齐 Go 实现 (time.go + timerange.go)
6
+ *
7
+ * 以 ISO 8601 (RFC 3339) 作为标准时间交换格式,
8
+ * 提供 ISO 8601 ↔ Unix 转换工具及时间范围解析。
9
+ */
10
+ /** Unix 秒(数字)→ ISO 8601 北京时间 */
11
+ export declare function secondsToDateTime(seconds: number): string;
12
+ /** Unix 秒(字符串)→ ISO 8601 北京时间 */
13
+ export declare function secondsStringToDateTime(seconds: string): string;
14
+ /** Unix 毫秒(数字)→ ISO 8601 北京时间 */
15
+ export declare function millisToDateTime(millis: number): string;
16
+ /** Unix 毫秒(字符串)→ ISO 8601 北京时间 */
17
+ export declare function millisStringToDateTime(millis: string): string;
18
+ /** ISO 8601 → Unix 秒(数字) */
19
+ export declare function dateTimeToSeconds(datetime: string): number;
20
+ /** ISO 8601 → Unix 秒(字符串) */
21
+ export declare function dateTimeToSecondsString(datetime: string): string;
22
+ /** ISO 8601 → Unix 毫秒(数字) */
23
+ export declare function dateTimeToMillis(datetime: string): number;
24
+ /** ISO 8601 时间范围 */
25
+ export interface TimeRange {
26
+ start: string;
27
+ end: string;
28
+ }
29
+ /**
30
+ * 解析时间范围标识,返回 ISO 8601 字符串对。
31
+ *
32
+ * 支持的格式:
33
+ * - `today` / `yesterday` / `day_before_yesterday`
34
+ * - `this_week` / `last_week` / `this_month` / `last_month`
35
+ * - `last_{N}_{unit}` — unit: minutes / hours / days
36
+ *
37
+ * 所有计算基于北京时间 (UTC+8)。
38
+ */
39
+ export declare function parseTimeRange(input: string): TimeRange;
40
+ /**
41
+ * 解析时间范围标识,返回 Unix 秒字符串对(供 SDK 调用)。
42
+ */
43
+ export declare function parseTimeRangeToSeconds(input: string): {
44
+ start: string;
45
+ end: string;
46
+ };
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * 时间工具函数 — 对齐 Go 实现 (time.go + timerange.go)
7
+ *
8
+ * 以 ISO 8601 (RFC 3339) 作为标准时间交换格式,
9
+ * 提供 ISO 8601 ↔ Unix 转换工具及时间范围解析。
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.secondsToDateTime = secondsToDateTime;
13
+ exports.secondsStringToDateTime = secondsStringToDateTime;
14
+ exports.millisToDateTime = millisToDateTime;
15
+ exports.millisStringToDateTime = millisStringToDateTime;
16
+ exports.dateTimeToSeconds = dateTimeToSeconds;
17
+ exports.dateTimeToSecondsString = dateTimeToSecondsString;
18
+ exports.dateTimeToMillis = dateTimeToMillis;
19
+ exports.parseTimeRange = parseTimeRange;
20
+ exports.parseTimeRangeToSeconds = parseTimeRangeToSeconds;
21
+ const BJ_OFFSET_MS = 8 * 60 * 60 * 1000;
22
+ // ===========================================================================
23
+ // ISO 8601 ↔ Unix 转换工具(对齐 time.go)
24
+ // ===========================================================================
25
+ /** 将 Date 格式化为北京时间 ISO 8601 字符串 */
26
+ function formatBeijingISO(d) {
27
+ const bj = new Date(d.getTime() + BJ_OFFSET_MS);
28
+ const y = bj.getUTCFullYear();
29
+ const mo = String(bj.getUTCMonth() + 1).padStart(2, '0');
30
+ const da = String(bj.getUTCDate()).padStart(2, '0');
31
+ const h = String(bj.getUTCHours()).padStart(2, '0');
32
+ const mi = String(bj.getUTCMinutes()).padStart(2, '0');
33
+ const s = String(bj.getUTCSeconds()).padStart(2, '0');
34
+ return `${y}-${mo}-${da}T${h}:${mi}:${s}+08:00`;
35
+ }
36
+ // ---------------------------------------------------------------------------
37
+ // Unix 秒 → ISO 8601
38
+ // ---------------------------------------------------------------------------
39
+ /** Unix 秒(数字)→ ISO 8601 北京时间 */
40
+ function secondsToDateTime(seconds) {
41
+ return formatBeijingISO(new Date(seconds * 1000));
42
+ }
43
+ /** Unix 秒(字符串)→ ISO 8601 北京时间 */
44
+ function secondsStringToDateTime(seconds) {
45
+ return secondsToDateTime(parseInt(seconds, 10));
46
+ }
47
+ // ---------------------------------------------------------------------------
48
+ // Unix 毫秒 → ISO 8601
49
+ // ---------------------------------------------------------------------------
50
+ /** Unix 毫秒(数字)→ ISO 8601 北京时间 */
51
+ function millisToDateTime(millis) {
52
+ return formatBeijingISO(new Date(millis));
53
+ }
54
+ /** Unix 毫秒(字符串)→ ISO 8601 北京时间 */
55
+ function millisStringToDateTime(millis) {
56
+ return millisToDateTime(parseInt(millis, 10));
57
+ }
58
+ // ---------------------------------------------------------------------------
59
+ // ISO 8601 → Unix
60
+ // ---------------------------------------------------------------------------
61
+ /** ISO 8601 → Unix 秒(数字) */
62
+ function dateTimeToSeconds(datetime) {
63
+ const d = new Date(datetime);
64
+ if (isNaN(d.getTime())) {
65
+ throw new Error(`无法解析 ISO 8601 时间: "${datetime}"。格式示例: 2026-02-27T14:30:00+08:00`);
66
+ }
67
+ return Math.floor(d.getTime() / 1000);
68
+ }
69
+ /** ISO 8601 → Unix 秒(字符串) */
70
+ function dateTimeToSecondsString(datetime) {
71
+ return dateTimeToSeconds(datetime).toString();
72
+ }
73
+ /** ISO 8601 → Unix 毫秒(数字) */
74
+ function dateTimeToMillis(datetime) {
75
+ const d = new Date(datetime);
76
+ if (isNaN(d.getTime())) {
77
+ throw new Error(`无法解析 ISO 8601 时间: "${datetime}"。格式示例: 2026-02-27T14:30:00+08:00`);
78
+ }
79
+ return d.getTime();
80
+ }
81
+ /**
82
+ * 解析时间范围标识,返回 ISO 8601 字符串对。
83
+ *
84
+ * 支持的格式:
85
+ * - `today` / `yesterday` / `day_before_yesterday`
86
+ * - `this_week` / `last_week` / `this_month` / `last_month`
87
+ * - `last_{N}_{unit}` — unit: minutes / hours / days
88
+ *
89
+ * 所有计算基于北京时间 (UTC+8)。
90
+ */
91
+ function parseTimeRange(input) {
92
+ const now = new Date();
93
+ const bjNow = toBeijingDate(now);
94
+ let start;
95
+ let end;
96
+ switch (input) {
97
+ case 'today':
98
+ start = beijingStartOfDay(bjNow);
99
+ end = now;
100
+ break;
101
+ case 'yesterday': {
102
+ const d = new Date(bjNow);
103
+ d.setUTCDate(d.getUTCDate() - 1);
104
+ start = beijingStartOfDay(d);
105
+ end = beijingEndOfDay(d);
106
+ break;
107
+ }
108
+ case 'day_before_yesterday': {
109
+ const d = new Date(bjNow);
110
+ d.setUTCDate(d.getUTCDate() - 2);
111
+ start = beijingStartOfDay(d);
112
+ end = beijingEndOfDay(d);
113
+ break;
114
+ }
115
+ case 'this_week': {
116
+ const day = bjNow.getUTCDay(); // 0=Sun .. 6=Sat
117
+ const diffToMon = day === 0 ? 6 : day - 1;
118
+ const monday = new Date(bjNow);
119
+ monday.setUTCDate(monday.getUTCDate() - diffToMon);
120
+ start = beijingStartOfDay(monday);
121
+ end = now;
122
+ break;
123
+ }
124
+ case 'last_week': {
125
+ const day = bjNow.getUTCDay();
126
+ const diffToMon = day === 0 ? 6 : day - 1;
127
+ const thisMonday = new Date(bjNow);
128
+ thisMonday.setUTCDate(thisMonday.getUTCDate() - diffToMon);
129
+ const lastMonday = new Date(thisMonday);
130
+ lastMonday.setUTCDate(lastMonday.getUTCDate() - 7);
131
+ const lastSunday = new Date(thisMonday);
132
+ lastSunday.setUTCDate(lastSunday.getUTCDate() - 1);
133
+ start = beijingStartOfDay(lastMonday);
134
+ end = beijingEndOfDay(lastSunday);
135
+ break;
136
+ }
137
+ case 'this_month': {
138
+ const firstDay = new Date(Date.UTC(bjNow.getUTCFullYear(), bjNow.getUTCMonth(), 1));
139
+ start = beijingStartOfDay(firstDay);
140
+ end = now;
141
+ break;
142
+ }
143
+ case 'last_month': {
144
+ const firstDayThisMonth = new Date(Date.UTC(bjNow.getUTCFullYear(), bjNow.getUTCMonth(), 1));
145
+ const lastDayPrevMonth = new Date(firstDayThisMonth);
146
+ lastDayPrevMonth.setUTCDate(lastDayPrevMonth.getUTCDate() - 1);
147
+ const firstDayPrevMonth = new Date(Date.UTC(lastDayPrevMonth.getUTCFullYear(), lastDayPrevMonth.getUTCMonth(), 1));
148
+ start = beijingStartOfDay(firstDayPrevMonth);
149
+ end = beijingEndOfDay(lastDayPrevMonth);
150
+ break;
151
+ }
152
+ default: {
153
+ // last_{N}_{unit} — 只支持 minutes / hours / days(对齐 Go)
154
+ const match = input.match(/^last_(\d+)_(minutes?|hours?|days?)$/);
155
+ if (!match) {
156
+ throw new Error(`不支持的 relative_time 格式: "${input}"。` +
157
+ '支持: today, yesterday, day_before_yesterday, this_week, last_week, this_month, last_month, last_{N}_{unit}(unit: minutes/hours/days)');
158
+ }
159
+ const n = parseInt(match[1], 10);
160
+ const unit = match[2].replace(/s$/, ''); // normalize plural
161
+ start = subtractFromNow(now, n, unit);
162
+ end = now;
163
+ break;
164
+ }
165
+ }
166
+ return {
167
+ start: formatBeijingISO(start),
168
+ end: formatBeijingISO(end),
169
+ };
170
+ }
171
+ /**
172
+ * 解析时间范围标识,返回 Unix 秒字符串对(供 SDK 调用)。
173
+ */
174
+ function parseTimeRangeToSeconds(input) {
175
+ const range = parseTimeRange(input);
176
+ return {
177
+ start: dateTimeToSecondsString(range.start),
178
+ end: dateTimeToSecondsString(range.end),
179
+ };
180
+ }
181
+ // ===========================================================================
182
+ // Internal helpers
183
+ // ===========================================================================
184
+ /** 将 UTC Date 转为「北京时间各部分存在 UTC 字段上」的 Date */
185
+ function toBeijingDate(d) {
186
+ return new Date(d.getTime() + BJ_OFFSET_MS);
187
+ }
188
+ /** 北京时间当天 00:00:00 对应的真实 UTC Date */
189
+ function beijingStartOfDay(bjDate) {
190
+ return new Date(Date.UTC(bjDate.getUTCFullYear(), bjDate.getUTCMonth(), bjDate.getUTCDate()) - BJ_OFFSET_MS);
191
+ }
192
+ /** 北京时间当天 23:59:59 对应的真实 UTC Date */
193
+ function beijingEndOfDay(bjDate) {
194
+ return new Date(Date.UTC(bjDate.getUTCFullYear(), bjDate.getUTCMonth(), bjDate.getUTCDate(), 23, 59, 59) - BJ_OFFSET_MS);
195
+ }
196
+ function subtractFromNow(now, n, unit) {
197
+ const d = new Date(now);
198
+ switch (unit) {
199
+ case 'minute':
200
+ d.setMinutes(d.getMinutes() - n);
201
+ break;
202
+ case 'hour':
203
+ d.setHours(d.getHours() - n);
204
+ break;
205
+ case 'day':
206
+ d.setDate(d.getDate() - n);
207
+ break;
208
+ default:
209
+ throw new Error(`不支持的时间单位: ${unit}`);
210
+ }
211
+ return d;
212
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ *
5
+ * UAT 用户名解析模块
6
+ *
7
+ * 独立于 messaging/inbound 层的 TAT UserNameCache,
8
+ * 用于工具层以用户身份(UAT)批量解析用户显示名。
9
+ *
10
+ * 设计动机:TAT 调用 contact/v3/users/batch 缺少权限导致返回的用户
11
+ * 条目不含 name 字段,而工具层搜索消息等场景运行在 UAT 上下文中,
12
+ * 用户 token 可以读取其他用户的名称。
13
+ *
14
+ * 底层使用 contact/v3/users/basic_batch 接口(scope: contact:user.basic_profile:readonly),
15
+ * 每次最多查询 10 个用户。
16
+ */
17
+ import type { ToolClient } from '../../../core/tool-client';
18
+ /** 从 UAT 缓存中获取用户名 */
19
+ export declare function getUATUserName(accountId: string, openId: string): string | undefined;
20
+ /** 批量写入 UAT 缓存 */
21
+ export declare function setUATUserNames(accountId: string, entries: Map<string, string>): void;
22
+ export declare function batchResolveUserNamesAsUser(params: {
23
+ client: ToolClient;
24
+ openIds: string[];
25
+ log: (...args: unknown[]) => void;
26
+ }): Promise<Map<string, string>>;