@lark-project/openclaw-lark-project 2026.3.131

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 (368) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +80 -0
  3. package/README.zh.md +80 -0
  4. package/dist/index.js +172 -0
  5. package/dist/index.js.map +7 -0
  6. package/dist/skills/feishu-bitable/SKILL.md +248 -0
  7. package/dist/skills/feishu-bitable/references/examples.md +813 -0
  8. package/dist/skills/feishu-bitable/references/field-properties.md +763 -0
  9. package/dist/skills/feishu-bitable/references/record-values.md +911 -0
  10. package/dist/skills/feishu-calendar/SKILL.md +244 -0
  11. package/dist/skills/feishu-channel-rules/SKILL.md +18 -0
  12. package/dist/skills/feishu-channel-rules/references/markdown-syntax.md +138 -0
  13. package/dist/skills/feishu-create-doc/SKILL.md +719 -0
  14. package/dist/skills/feishu-fetch-doc/SKILL.md +93 -0
  15. package/dist/skills/feishu-im-read/SKILL.md +163 -0
  16. package/dist/skills/feishu-project/SKILL.md +122 -0
  17. package/dist/skills/feishu-task/SKILL.md +293 -0
  18. package/dist/skills/feishu-troubleshoot/SKILL.md +70 -0
  19. package/dist/skills/feishu-update-doc/SKILL.md +285 -0
  20. package/dist/src/card/builder.js +293 -0
  21. package/dist/src/card/builder.js.map +7 -0
  22. package/dist/src/card/cardkit.js +126 -0
  23. package/dist/src/card/cardkit.js.map +7 -0
  24. package/dist/src/card/flush-controller.js +107 -0
  25. package/dist/src/card/flush-controller.js.map +7 -0
  26. package/dist/src/card/markdown-style.js +57 -0
  27. package/dist/src/card/markdown-style.js.map +7 -0
  28. package/dist/src/card/reply-dispatcher-types.js +39 -0
  29. package/dist/src/card/reply-dispatcher-types.js.map +7 -0
  30. package/dist/src/card/reply-dispatcher.js +245 -0
  31. package/dist/src/card/reply-dispatcher.js.map +7 -0
  32. package/dist/src/card/reply-mode.js +29 -0
  33. package/dist/src/card/reply-mode.js.map +7 -0
  34. package/dist/src/card/streaming-card-controller.js +653 -0
  35. package/dist/src/card/streaming-card-controller.js.map +7 -0
  36. package/dist/src/card/unavailable-guard.js +76 -0
  37. package/dist/src/card/unavailable-guard.js.map +7 -0
  38. package/dist/src/channel/abort-detect.js +79 -0
  39. package/dist/src/channel/abort-detect.js.map +7 -0
  40. package/dist/src/channel/chat-queue.js +50 -0
  41. package/dist/src/channel/chat-queue.js.map +7 -0
  42. package/dist/src/channel/config-adapter.js +89 -0
  43. package/dist/src/channel/config-adapter.js.map +7 -0
  44. package/dist/src/channel/directory.js +133 -0
  45. package/dist/src/channel/directory.js.map +7 -0
  46. package/dist/src/channel/event-handlers.js +175 -0
  47. package/dist/src/channel/event-handlers.js.map +7 -0
  48. package/dist/src/channel/monitor.js +108 -0
  49. package/dist/src/channel/monitor.js.map +7 -0
  50. package/dist/src/channel/onboarding-config.js +76 -0
  51. package/dist/src/channel/onboarding-config.js.map +7 -0
  52. package/dist/src/channel/onboarding-migrate.js +55 -0
  53. package/dist/src/channel/onboarding-migrate.js.map +7 -0
  54. package/dist/src/channel/onboarding.js +285 -0
  55. package/dist/src/channel/onboarding.js.map +7 -0
  56. package/dist/src/channel/plugin.js +260 -0
  57. package/dist/src/channel/plugin.js.map +7 -0
  58. package/dist/src/channel/probe.js +14 -0
  59. package/dist/src/channel/probe.js.map +7 -0
  60. package/dist/src/channel/types.js +1 -0
  61. package/dist/src/channel/types.js.map +7 -0
  62. package/dist/src/commands/auth.js +73 -0
  63. package/dist/src/commands/auth.js.map +7 -0
  64. package/dist/src/commands/diagnose.js +658 -0
  65. package/dist/src/commands/diagnose.js.map +7 -0
  66. package/dist/src/commands/doctor.js +327 -0
  67. package/dist/src/commands/doctor.js.map +7 -0
  68. package/dist/src/commands/index.js +124 -0
  69. package/dist/src/commands/index.js.map +7 -0
  70. package/dist/src/core/accounts.js +129 -0
  71. package/dist/src/core/accounts.js.map +7 -0
  72. package/dist/src/core/agent-config.js +60 -0
  73. package/dist/src/core/agent-config.js.map +7 -0
  74. package/dist/src/core/api-error.js +55 -0
  75. package/dist/src/core/api-error.js.map +7 -0
  76. package/dist/src/core/app-owner-fallback.js +17 -0
  77. package/dist/src/core/app-owner-fallback.js.map +7 -0
  78. package/dist/src/core/app-scope-checker.js +95 -0
  79. package/dist/src/core/app-scope-checker.js.map +7 -0
  80. package/dist/src/core/auth-errors.js +120 -0
  81. package/dist/src/core/auth-errors.js.map +7 -0
  82. package/dist/src/core/chat-info-cache.js +102 -0
  83. package/dist/src/core/chat-info-cache.js.map +7 -0
  84. package/dist/src/core/config-schema.js +150 -0
  85. package/dist/src/core/config-schema.js.map +7 -0
  86. package/dist/src/core/device-flow.js +174 -0
  87. package/dist/src/core/device-flow.js.map +7 -0
  88. package/dist/src/core/feishu-fetch.js +12 -0
  89. package/dist/src/core/feishu-fetch.js.map +7 -0
  90. package/dist/src/core/footer-config.js +16 -0
  91. package/dist/src/core/footer-config.js.map +7 -0
  92. package/dist/src/core/lark-client.js +322 -0
  93. package/dist/src/core/lark-client.js.map +7 -0
  94. package/dist/src/core/lark-logger.js +92 -0
  95. package/dist/src/core/lark-logger.js.map +7 -0
  96. package/dist/src/core/lark-ticket.js +18 -0
  97. package/dist/src/core/lark-ticket.js.map +7 -0
  98. package/dist/src/core/message-unavailable.js +119 -0
  99. package/dist/src/core/message-unavailable.js.map +7 -0
  100. package/dist/src/core/owner-policy.js +25 -0
  101. package/dist/src/core/owner-policy.js.map +7 -0
  102. package/dist/src/core/permission-url.js +37 -0
  103. package/dist/src/core/permission-url.js.map +7 -0
  104. package/dist/src/core/project-auth.js +177 -0
  105. package/dist/src/core/project-auth.js.map +7 -0
  106. package/dist/src/core/project-oauth-flow.js +124 -0
  107. package/dist/src/core/project-oauth-flow.js.map +7 -0
  108. package/dist/src/core/project-token-store.js +172 -0
  109. package/dist/src/core/project-token-store.js.map +7 -0
  110. package/dist/src/core/raw-request.js +45 -0
  111. package/dist/src/core/raw-request.js.map +7 -0
  112. package/dist/src/core/scope-manager.js +62 -0
  113. package/dist/src/core/scope-manager.js.map +7 -0
  114. package/dist/src/core/security-check.js +118 -0
  115. package/dist/src/core/security-check.js.map +7 -0
  116. package/dist/src/core/shutdown-hooks.js +37 -0
  117. package/dist/src/core/shutdown-hooks.js.map +7 -0
  118. package/dist/src/core/targets.js +55 -0
  119. package/dist/src/core/targets.js.map +7 -0
  120. package/dist/src/core/token-store.js +215 -0
  121. package/dist/src/core/token-store.js.map +7 -0
  122. package/dist/src/core/tool-client.js +335 -0
  123. package/dist/src/core/tool-client.js.map +7 -0
  124. package/dist/src/core/tool-scopes.js +207 -0
  125. package/dist/src/core/tool-scopes.js.map +7 -0
  126. package/dist/src/core/tools-config.js +57 -0
  127. package/dist/src/core/tools-config.js.map +7 -0
  128. package/dist/src/core/types.js +1 -0
  129. package/dist/src/core/types.js.map +7 -0
  130. package/dist/src/core/uat-client.js +124 -0
  131. package/dist/src/core/uat-client.js.map +7 -0
  132. package/dist/src/core/version.js +27 -0
  133. package/dist/src/core/version.js.map +7 -0
  134. package/dist/src/messaging/converters/audio.js +19 -0
  135. package/dist/src/messaging/converters/audio.js.map +7 -0
  136. package/dist/src/messaging/converters/calendar.js +46 -0
  137. package/dist/src/messaging/converters/calendar.js.map +7 -0
  138. package/dist/src/messaging/converters/content-converter.js +61 -0
  139. package/dist/src/messaging/converters/content-converter.js.map +7 -0
  140. package/dist/src/messaging/converters/file.js +18 -0
  141. package/dist/src/messaging/converters/file.js.map +7 -0
  142. package/dist/src/messaging/converters/folder.js +18 -0
  143. package/dist/src/messaging/converters/folder.js.map +7 -0
  144. package/dist/src/messaging/converters/hongbao.js +14 -0
  145. package/dist/src/messaging/converters/hongbao.js.map +7 -0
  146. package/dist/src/messaging/converters/image.js +16 -0
  147. package/dist/src/messaging/converters/image.js.map +7 -0
  148. package/dist/src/messaging/converters/index.js +48 -0
  149. package/dist/src/messaging/converters/index.js.map +7 -0
  150. package/dist/src/messaging/converters/interactive/card-converter.js +1040 -0
  151. package/dist/src/messaging/converters/interactive/card-converter.js.map +7 -0
  152. package/dist/src/messaging/converters/interactive/card-utils.js +36 -0
  153. package/dist/src/messaging/converters/interactive/card-utils.js.map +7 -0
  154. package/dist/src/messaging/converters/interactive/index.js +19 -0
  155. package/dist/src/messaging/converters/interactive/index.js.map +7 -0
  156. package/dist/src/messaging/converters/interactive/legacy.js +53 -0
  157. package/dist/src/messaging/converters/interactive/legacy.js.map +7 -0
  158. package/dist/src/messaging/converters/interactive/types.js +23 -0
  159. package/dist/src/messaging/converters/interactive/types.js.map +7 -0
  160. package/dist/src/messaging/converters/location.js +17 -0
  161. package/dist/src/messaging/converters/location.js.map +7 -0
  162. package/dist/src/messaging/converters/merge-forward.js +143 -0
  163. package/dist/src/messaging/converters/merge-forward.js.map +7 -0
  164. package/dist/src/messaging/converters/post.js +113 -0
  165. package/dist/src/messaging/converters/post.js.map +7 -0
  166. package/dist/src/messaging/converters/share.js +22 -0
  167. package/dist/src/messaging/converters/share.js.map +7 -0
  168. package/dist/src/messaging/converters/sticker.js +16 -0
  169. package/dist/src/messaging/converters/sticker.js.map +7 -0
  170. package/dist/src/messaging/converters/system.js +25 -0
  171. package/dist/src/messaging/converters/system.js.map +7 -0
  172. package/dist/src/messaging/converters/text.js +12 -0
  173. package/dist/src/messaging/converters/text.js.map +7 -0
  174. package/dist/src/messaging/converters/todo.js +37 -0
  175. package/dist/src/messaging/converters/todo.js.map +7 -0
  176. package/dist/src/messaging/converters/types.js +1 -0
  177. package/dist/src/messaging/converters/types.js.map +7 -0
  178. package/dist/src/messaging/converters/unknown.js +13 -0
  179. package/dist/src/messaging/converters/unknown.js.map +7 -0
  180. package/dist/src/messaging/converters/utils.js +35 -0
  181. package/dist/src/messaging/converters/utils.js.map +7 -0
  182. package/dist/src/messaging/converters/video-chat.js +21 -0
  183. package/dist/src/messaging/converters/video-chat.js.map +7 -0
  184. package/dist/src/messaging/converters/video.js +30 -0
  185. package/dist/src/messaging/converters/video.js.map +7 -0
  186. package/dist/src/messaging/converters/vote.js +24 -0
  187. package/dist/src/messaging/converters/vote.js.map +7 -0
  188. package/dist/src/messaging/inbound/dedup.js +82 -0
  189. package/dist/src/messaging/inbound/dedup.js.map +7 -0
  190. package/dist/src/messaging/inbound/dispatch-builders.js +98 -0
  191. package/dist/src/messaging/inbound/dispatch-builders.js.map +7 -0
  192. package/dist/src/messaging/inbound/dispatch-commands.js +94 -0
  193. package/dist/src/messaging/inbound/dispatch-commands.js.map +7 -0
  194. package/dist/src/messaging/inbound/dispatch-context.js +96 -0
  195. package/dist/src/messaging/inbound/dispatch-context.js.map +7 -0
  196. package/dist/src/messaging/inbound/dispatch.js +150 -0
  197. package/dist/src/messaging/inbound/dispatch.js.map +7 -0
  198. package/dist/src/messaging/inbound/enrich.js +137 -0
  199. package/dist/src/messaging/inbound/enrich.js.map +7 -0
  200. package/dist/src/messaging/inbound/gate-effects.js +28 -0
  201. package/dist/src/messaging/inbound/gate-effects.js.map +7 -0
  202. package/dist/src/messaging/inbound/gate.js +163 -0
  203. package/dist/src/messaging/inbound/gate.js.map +7 -0
  204. package/dist/src/messaging/inbound/handler.js +132 -0
  205. package/dist/src/messaging/inbound/handler.js.map +7 -0
  206. package/dist/src/messaging/inbound/media-resolver.js +70 -0
  207. package/dist/src/messaging/inbound/media-resolver.js.map +7 -0
  208. package/dist/src/messaging/inbound/mention.js +50 -0
  209. package/dist/src/messaging/inbound/mention.js.map +7 -0
  210. package/dist/src/messaging/inbound/parse-io.js +41 -0
  211. package/dist/src/messaging/inbound/parse-io.js.map +7 -0
  212. package/dist/src/messaging/inbound/parse.js +79 -0
  213. package/dist/src/messaging/inbound/parse.js.map +7 -0
  214. package/dist/src/messaging/inbound/permission.js +30 -0
  215. package/dist/src/messaging/inbound/permission.js.map +7 -0
  216. package/dist/src/messaging/inbound/policy.js +83 -0
  217. package/dist/src/messaging/inbound/policy.js.map +7 -0
  218. package/dist/src/messaging/inbound/reaction-handler.js +162 -0
  219. package/dist/src/messaging/inbound/reaction-handler.js.map +7 -0
  220. package/dist/src/messaging/inbound/user-name-cache.js +172 -0
  221. package/dist/src/messaging/inbound/user-name-cache.js.map +7 -0
  222. package/dist/src/messaging/outbound/actions.js +239 -0
  223. package/dist/src/messaging/outbound/actions.js.map +7 -0
  224. package/dist/src/messaging/outbound/chat-manage.js +74 -0
  225. package/dist/src/messaging/outbound/chat-manage.js.map +7 -0
  226. package/dist/src/messaging/outbound/deliver.js +162 -0
  227. package/dist/src/messaging/outbound/deliver.js.map +7 -0
  228. package/dist/src/messaging/outbound/fetch.js +7 -0
  229. package/dist/src/messaging/outbound/fetch.js.map +7 -0
  230. package/dist/src/messaging/outbound/forward.js +31 -0
  231. package/dist/src/messaging/outbound/forward.js.map +7 -0
  232. package/dist/src/messaging/outbound/media-url-utils.js +101 -0
  233. package/dist/src/messaging/outbound/media-url-utils.js.map +7 -0
  234. package/dist/src/messaging/outbound/media.js +463 -0
  235. package/dist/src/messaging/outbound/media.js.map +7 -0
  236. package/dist/src/messaging/outbound/outbound.js +95 -0
  237. package/dist/src/messaging/outbound/outbound.js.map +7 -0
  238. package/dist/src/messaging/outbound/reactions.js +312 -0
  239. package/dist/src/messaging/outbound/reactions.js.map +7 -0
  240. package/dist/src/messaging/outbound/send.js +194 -0
  241. package/dist/src/messaging/outbound/send.js.map +7 -0
  242. package/dist/src/messaging/outbound/typing.js +77 -0
  243. package/dist/src/messaging/outbound/typing.js.map +7 -0
  244. package/dist/src/messaging/shared/message-lookup.js +84 -0
  245. package/dist/src/messaging/shared/message-lookup.js.map +7 -0
  246. package/dist/src/messaging/types.js +1 -0
  247. package/dist/src/messaging/types.js.map +7 -0
  248. package/dist/src/tools/auto-auth.js +714 -0
  249. package/dist/src/tools/auto-auth.js.map +7 -0
  250. package/dist/src/tools/helpers.js +133 -0
  251. package/dist/src/tools/helpers.js.map +7 -0
  252. package/dist/src/tools/mcp/doc/create.js +35 -0
  253. package/dist/src/tools/mcp/doc/create.js.map +7 -0
  254. package/dist/src/tools/mcp/doc/fetch.js +33 -0
  255. package/dist/src/tools/mcp/doc/fetch.js.map +7 -0
  256. package/dist/src/tools/mcp/doc/index.js +32 -0
  257. package/dist/src/tools/mcp/doc/index.js.map +7 -0
  258. package/dist/src/tools/mcp/doc/update.js +61 -0
  259. package/dist/src/tools/mcp/doc/update.js.map +7 -0
  260. package/dist/src/tools/mcp/project/endpoint.js +25 -0
  261. package/dist/src/tools/mcp/project/endpoint.js.map +7 -0
  262. package/dist/src/tools/mcp/project/index.js +27 -0
  263. package/dist/src/tools/mcp/project/index.js.map +7 -0
  264. package/dist/src/tools/mcp/project/tools.js +579 -0
  265. package/dist/src/tools/mcp/project/tools.js.map +7 -0
  266. package/dist/src/tools/mcp/shared.js +170 -0
  267. package/dist/src/tools/mcp/shared.js.map +7 -0
  268. package/dist/src/tools/oapi/bitable/app-table-field.js +244 -0
  269. package/dist/src/tools/oapi/bitable/app-table-field.js.map +7 -0
  270. package/dist/src/tools/oapi/bitable/app-table-record.js +501 -0
  271. package/dist/src/tools/oapi/bitable/app-table-record.js.map +7 -0
  272. package/dist/src/tools/oapi/bitable/app-table-view.js +226 -0
  273. package/dist/src/tools/oapi/bitable/app-table-view.js.map +7 -0
  274. package/dist/src/tools/oapi/bitable/app-table.js +278 -0
  275. package/dist/src/tools/oapi/bitable/app-table.js.map +7 -0
  276. package/dist/src/tools/oapi/bitable/app.js +200 -0
  277. package/dist/src/tools/oapi/bitable/app.js.map +7 -0
  278. package/dist/src/tools/oapi/bitable/index.js +13 -0
  279. package/dist/src/tools/oapi/bitable/index.js.map +7 -0
  280. package/dist/src/tools/oapi/calendar/calendar.js +131 -0
  281. package/dist/src/tools/oapi/calendar/calendar.js.map +7 -0
  282. package/dist/src/tools/oapi/calendar/event-attendee.js +301 -0
  283. package/dist/src/tools/oapi/calendar/event-attendee.js.map +7 -0
  284. package/dist/src/tools/oapi/calendar/event.js +834 -0
  285. package/dist/src/tools/oapi/calendar/event.js.map +7 -0
  286. package/dist/src/tools/oapi/calendar/freebusy.js +111 -0
  287. package/dist/src/tools/oapi/calendar/freebusy.js.map +7 -0
  288. package/dist/src/tools/oapi/calendar/index.js +11 -0
  289. package/dist/src/tools/oapi/calendar/index.js.map +7 -0
  290. package/dist/src/tools/oapi/chat/chat.js +132 -0
  291. package/dist/src/tools/oapi/chat/chat.js.map +7 -0
  292. package/dist/src/tools/oapi/chat/index.js +11 -0
  293. package/dist/src/tools/oapi/chat/index.js.map +7 -0
  294. package/dist/src/tools/oapi/chat/members.js +83 -0
  295. package/dist/src/tools/oapi/chat/members.js.map +7 -0
  296. package/dist/src/tools/oapi/common/get-user.js +95 -0
  297. package/dist/src/tools/oapi/common/get-user.js.map +7 -0
  298. package/dist/src/tools/oapi/common/index.js +7 -0
  299. package/dist/src/tools/oapi/common/index.js.map +7 -0
  300. package/dist/src/tools/oapi/common/search-user.js +67 -0
  301. package/dist/src/tools/oapi/common/search-user.js.map +7 -0
  302. package/dist/src/tools/oapi/drive/doc-comments.js +310 -0
  303. package/dist/src/tools/oapi/drive/doc-comments.js.map +7 -0
  304. package/dist/src/tools/oapi/drive/doc-media.js +314 -0
  305. package/dist/src/tools/oapi/drive/doc-media.js.map +7 -0
  306. package/dist/src/tools/oapi/drive/file.js +548 -0
  307. package/dist/src/tools/oapi/drive/file.js.map +7 -0
  308. package/dist/src/tools/oapi/drive/index.js +29 -0
  309. package/dist/src/tools/oapi/drive/index.js.map +7 -0
  310. package/dist/src/tools/oapi/helpers.js +199 -0
  311. package/dist/src/tools/oapi/helpers.js.map +7 -0
  312. package/dist/src/tools/oapi/im/format-messages.js +128 -0
  313. package/dist/src/tools/oapi/im/format-messages.js.map +7 -0
  314. package/dist/src/tools/oapi/im/index.js +15 -0
  315. package/dist/src/tools/oapi/im/index.js.map +7 -0
  316. package/dist/src/tools/oapi/im/message-read.js +404 -0
  317. package/dist/src/tools/oapi/im/message-read.js.map +7 -0
  318. package/dist/src/tools/oapi/im/message.js +179 -0
  319. package/dist/src/tools/oapi/im/message.js.map +7 -0
  320. package/dist/src/tools/oapi/im/resource.js +126 -0
  321. package/dist/src/tools/oapi/im/resource.js.map +7 -0
  322. package/dist/src/tools/oapi/im/time-utils.js +169 -0
  323. package/dist/src/tools/oapi/im/time-utils.js.map +7 -0
  324. package/dist/src/tools/oapi/im/user-name-uat.js +103 -0
  325. package/dist/src/tools/oapi/im/user-name-uat.js.map +7 -0
  326. package/dist/src/tools/oapi/index.js +56 -0
  327. package/dist/src/tools/oapi/index.js.map +7 -0
  328. package/dist/src/tools/oapi/sdk-types.js +1 -0
  329. package/dist/src/tools/oapi/sdk-types.js.map +7 -0
  330. package/dist/src/tools/oapi/search/doc-search.js +215 -0
  331. package/dist/src/tools/oapi/search/doc-search.js.map +7 -0
  332. package/dist/src/tools/oapi/search/index.js +25 -0
  333. package/dist/src/tools/oapi/search/index.js.map +7 -0
  334. package/dist/src/tools/oapi/sheets/index.js +25 -0
  335. package/dist/src/tools/oapi/sheets/index.js.map +7 -0
  336. package/dist/src/tools/oapi/sheets/sheet.js +652 -0
  337. package/dist/src/tools/oapi/sheets/sheet.js.map +7 -0
  338. package/dist/src/tools/oapi/task/comment.js +151 -0
  339. package/dist/src/tools/oapi/task/comment.js.map +7 -0
  340. package/dist/src/tools/oapi/task/index.js +11 -0
  341. package/dist/src/tools/oapi/task/index.js.map +7 -0
  342. package/dist/src/tools/oapi/task/subtask.js +175 -0
  343. package/dist/src/tools/oapi/task/subtask.js.map +7 -0
  344. package/dist/src/tools/oapi/task/task.js +405 -0
  345. package/dist/src/tools/oapi/task/task.js.map +7 -0
  346. package/dist/src/tools/oapi/task/tasklist.js +366 -0
  347. package/dist/src/tools/oapi/task/tasklist.js.map +7 -0
  348. package/dist/src/tools/oapi/wiki/index.js +27 -0
  349. package/dist/src/tools/oapi/wiki/index.js.map +7 -0
  350. package/dist/src/tools/oapi/wiki/space-node.js +311 -0
  351. package/dist/src/tools/oapi/wiki/space-node.js.map +7 -0
  352. package/dist/src/tools/oapi/wiki/space.js +148 -0
  353. package/dist/src/tools/oapi/wiki/space.js.map +7 -0
  354. package/dist/src/tools/oauth-batch-auth.js +125 -0
  355. package/dist/src/tools/oauth-batch-auth.js.map +7 -0
  356. package/dist/src/tools/oauth-cards.js +269 -0
  357. package/dist/src/tools/oauth-cards.js.map +7 -0
  358. package/dist/src/tools/oauth.js +538 -0
  359. package/dist/src/tools/oauth.js.map +7 -0
  360. package/dist/src/tools/onboarding-auth.js +101 -0
  361. package/dist/src/tools/onboarding-auth.js.map +7 -0
  362. package/dist/src/tools/project-oauth.js +305 -0
  363. package/dist/src/tools/project-oauth.js.map +7 -0
  364. package/dist/src/tools/tat/im/index.js +9 -0
  365. package/dist/src/tools/tat/im/index.js.map +7 -0
  366. package/dist/src/tools/tat/im/resource.js +123 -0
  367. package/dist/src/tools/tat/im/resource.js.map +7 -0
  368. package/package.json +64 -0
@@ -0,0 +1,658 @@
1
+ import * as fs from "node:fs/promises";
2
+ import * as path from "node:path";
3
+ import * as os from "node:os";
4
+ import { probeFeishu } from "../channel/probe";
5
+ import { getLarkAccountIds, getLarkAccount, getEnabledLarkAccounts } from "../core/accounts";
6
+ import { LarkClient } from "../core/lark-client";
7
+ function resolveGlobalConfig(config) {
8
+ return LarkClient.globalConfig ?? config;
9
+ }
10
+ import { assertLarkOk, formatLarkError } from "../core/api-error";
11
+ import { resolveAnyEnabledToolsConfig } from "../core/tools-config";
12
+ const PLUGIN_VERSION = "2026.2.10";
13
+ const LOG_READ_BYTES = 256 * 1024;
14
+ const MAX_ERROR_LINES = 20;
15
+ const TIMESTAMPED_LINE_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/;
16
+ const ERROR_LEVEL_RE = /\[error\]|\[warn\]/i;
17
+ function maskSecret(secret) {
18
+ if (!secret) return "(\u672A\u8BBE\u7F6E)";
19
+ if (secret.length <= 4) return "****";
20
+ return secret.slice(0, 4) + "****";
21
+ }
22
+ async function extractRecentErrors(logPath) {
23
+ try {
24
+ await fs.access(logPath);
25
+ } catch {
26
+ return [];
27
+ }
28
+ try {
29
+ const stat = await fs.stat(logPath);
30
+ const readSize = Math.min(stat.size, LOG_READ_BYTES);
31
+ const fd = await fs.open(logPath, "r");
32
+ try {
33
+ const buffer = Buffer.alloc(readSize);
34
+ await fd.read(buffer, 0, readSize, Math.max(0, stat.size - readSize));
35
+ const content = buffer.toString("utf-8");
36
+ const lines = content.split("\n").filter(Boolean);
37
+ const errorLines = lines.filter((line) => TIMESTAMPED_LINE_RE.test(line) && ERROR_LEVEL_RE.test(line));
38
+ return errorLines.slice(-MAX_ERROR_LINES);
39
+ } finally {
40
+ await fd.close();
41
+ }
42
+ } catch {
43
+ return [];
44
+ }
45
+ }
46
+ async function checkAppScopes(client) {
47
+ const res = await client.application.scope.list({});
48
+ assertLarkOk(res);
49
+ const scopes = res.data?.scopes ?? [];
50
+ const granted = scopes.filter((s) => s.grant_status === 1);
51
+ const pending = scopes.filter((s) => s.grant_status !== 1);
52
+ return {
53
+ granted: granted.length,
54
+ pending: pending.length,
55
+ summary: `${granted.length} \u5DF2\u6388\u6743, ${pending.length} \u5F85\u6388\u6743`
56
+ };
57
+ }
58
+ function detectRegisteredTools(config) {
59
+ const accounts = getEnabledLarkAccounts(config);
60
+ if (accounts.length === 0) return [];
61
+ const toolsCfg = resolveAnyEnabledToolsConfig(accounts);
62
+ const tools = [];
63
+ if (toolsCfg.doc) tools.push("feishu_doc");
64
+ if (toolsCfg.scopes) tools.push("feishu_app_scopes");
65
+ if (toolsCfg.wiki) tools.push("feishu_wiki");
66
+ if (toolsCfg.drive) tools.push("feishu_drive");
67
+ if (toolsCfg.perm) tools.push("feishu_perm");
68
+ tools.push(
69
+ "feishu_bitable_get_meta",
70
+ "feishu_bitable_list_fields",
71
+ "feishu_bitable_list_records",
72
+ "feishu_bitable_get_record",
73
+ "feishu_bitable_create_record",
74
+ "feishu_bitable_update_record"
75
+ );
76
+ tools.push("feishu_task");
77
+ tools.push("feishu_calendar");
78
+ return tools;
79
+ }
80
+ async function diagnoseAccount(account) {
81
+ const checks = [];
82
+ const result = {
83
+ accountId: account.accountId,
84
+ name: account.name,
85
+ enabled: account.enabled,
86
+ configured: account.configured,
87
+ appId: account.appId ?? "(\u672A\u8BBE\u7F6E)",
88
+ brand: account.brand,
89
+ checks
90
+ };
91
+ checks.push({
92
+ name: "\u51ED\u8BC1\u5B8C\u6574\u6027",
93
+ status: account.configured ? "pass" : "fail",
94
+ message: account.configured ? `appId: ${account.appId}, appSecret: ${maskSecret(account.appSecret)}` : "\u7F3A\u5C11 appId \u6216 appSecret"
95
+ });
96
+ checks.push({
97
+ name: "\u8D26\u6237\u542F\u7528",
98
+ status: account.enabled ? "pass" : "warn",
99
+ message: account.enabled ? "\u5DF2\u542F\u7528" : "\u5DF2\u7981\u7528"
100
+ });
101
+ if (!account.configured || !account.appId || !account.appSecret) {
102
+ checks.push({
103
+ name: "API \u8FDE\u901A\u6027",
104
+ status: "skip",
105
+ message: "\u51ED\u8BC1\u672A\u914D\u7F6E\uFF0C\u8DF3\u8FC7"
106
+ });
107
+ return result;
108
+ }
109
+ try {
110
+ const probeResult = await probeFeishu({
111
+ accountId: account.accountId,
112
+ appId: account.appId,
113
+ appSecret: account.appSecret,
114
+ brand: account.brand
115
+ });
116
+ checks.push({
117
+ name: "API \u8FDE\u901A\u6027",
118
+ status: probeResult.ok ? "pass" : "fail",
119
+ message: probeResult.ok ? `\u8FDE\u63A5\u6210\u529F` : `\u8FDE\u63A5\u5931\u8D25: ${probeResult.error}`
120
+ });
121
+ if (probeResult.ok) {
122
+ checks.push({
123
+ name: "Bot \u4FE1\u606F",
124
+ status: probeResult.botName ? "pass" : "warn",
125
+ message: probeResult.botName ? `${probeResult.botName} (${probeResult.botOpenId})` : "\u672A\u83B7\u53D6\u5230 Bot \u540D\u79F0"
126
+ });
127
+ }
128
+ } catch (err) {
129
+ checks.push({
130
+ name: "API \u8FDE\u901A\u6027",
131
+ status: "fail",
132
+ message: `\u63A2\u6D4B\u5F02\u5E38: ${err instanceof Error ? err.message : String(err)}`
133
+ });
134
+ }
135
+ try {
136
+ const client = LarkClient.fromAccount(account).sdk;
137
+ const scopesResult = await checkAppScopes(client);
138
+ checks.push({
139
+ name: "\u5E94\u7528\u6743\u9650",
140
+ status: scopesResult.pending > 0 ? "warn" : "pass",
141
+ message: scopesResult.summary,
142
+ details: scopesResult.pending > 0 ? "\u5B58\u5728\u672A\u6388\u6743\u7684\u6743\u9650\uFF0C\u53EF\u80FD\u5F71\u54CD\u90E8\u5206\u529F\u80FD" : void 0
143
+ });
144
+ } catch (err) {
145
+ checks.push({
146
+ name: "\u5E94\u7528\u6743\u9650",
147
+ status: "warn",
148
+ message: `\u6743\u9650\u68C0\u67E5\u5931\u8D25: ${formatLarkError(err)}`
149
+ });
150
+ }
151
+ checks.push({
152
+ name: "\u54C1\u724C\u914D\u7F6E",
153
+ status: "pass",
154
+ message: `brand: ${account.brand}`
155
+ });
156
+ return result;
157
+ }
158
+ async function runDiagnosis(params) {
159
+ const { config } = params;
160
+ const globalCfg = resolveGlobalConfig(config);
161
+ const globalChecks = [];
162
+ const nodeVer = parseInt(process.version.slice(1), 10);
163
+ globalChecks.push({
164
+ name: "Node.js \u7248\u672C",
165
+ status: nodeVer >= 18 ? "pass" : "warn",
166
+ message: process.version,
167
+ details: nodeVer < 18 ? "\u5EFA\u8BAE\u5347\u7EA7\u5230 Node.js 18+" : void 0
168
+ });
169
+ const accountIds = getLarkAccountIds(globalCfg);
170
+ globalChecks.push({
171
+ name: "\u98DE\u4E66\u8D26\u6237\u6570\u91CF",
172
+ status: accountIds.length > 0 ? "pass" : "fail",
173
+ message: `${accountIds.length} \u4E2A\u8D26\u6237`
174
+ });
175
+ const logPath = path.join(os.homedir(), ".openclaw", "logs", "gateway.log");
176
+ let logExists = false;
177
+ try {
178
+ await fs.access(logPath);
179
+ logExists = true;
180
+ } catch {
181
+ }
182
+ globalChecks.push({
183
+ name: "\u65E5\u5FD7\u6587\u4EF6",
184
+ status: logExists ? "pass" : "warn",
185
+ message: logExists ? logPath : `\u672A\u627E\u5230: ${logPath}`
186
+ });
187
+ const accountResults = [];
188
+ for (const id of accountIds) {
189
+ const account = getLarkAccount(globalCfg, id);
190
+ const result = await diagnoseAccount(account);
191
+ accountResults.push(result);
192
+ }
193
+ const tools = detectRegisteredTools(globalCfg);
194
+ const recentErrors = await extractRecentErrors(logPath);
195
+ globalChecks.push({
196
+ name: "\u6700\u8FD1\u9519\u8BEF\u65E5\u5FD7",
197
+ status: recentErrors.length > 0 ? "warn" : "pass",
198
+ message: recentErrors.length > 0 ? `\u53D1\u73B0 ${recentErrors.length} \u6761\u9519\u8BEF` : "\u65E0\u6700\u8FD1\u9519\u8BEF"
199
+ });
200
+ const allChecks = [...globalChecks, ...accountResults.flatMap((a) => a.checks)];
201
+ const hasFail = allChecks.some((c) => c.status === "fail");
202
+ const hasWarn = allChecks.some((c) => c.status === "warn");
203
+ return {
204
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
205
+ environment: {
206
+ nodeVersion: process.version,
207
+ platform: process.platform,
208
+ arch: process.arch,
209
+ pluginVersion: PLUGIN_VERSION
210
+ },
211
+ accounts: accountResults,
212
+ toolsRegistered: tools,
213
+ recentErrors,
214
+ overallStatus: hasFail ? "unhealthy" : hasWarn ? "degraded" : "healthy",
215
+ checks: globalChecks
216
+ };
217
+ }
218
+ const STATUS_LABEL = {
219
+ pass: "[PASS]",
220
+ warn: "[WARN]",
221
+ fail: "[FAIL]",
222
+ skip: "[SKIP]"
223
+ };
224
+ function formatCheck(c) {
225
+ let line = ` ${STATUS_LABEL[c.status]} ${c.name}: ${c.message}`;
226
+ if (c.details) {
227
+ line += `
228
+ ${c.details}`;
229
+ }
230
+ return line;
231
+ }
232
+ function formatDiagReportText(report) {
233
+ const lines = [];
234
+ const sep = "====================================";
235
+ lines.push(sep);
236
+ lines.push(" \u98DE\u4E66\u63D2\u4EF6\u8BCA\u65AD\u62A5\u544A");
237
+ lines.push(` ${report.timestamp}`);
238
+ lines.push(sep);
239
+ lines.push("");
240
+ lines.push("\u3010\u73AF\u5883\u4FE1\u606F\u3011");
241
+ lines.push(` Node.js: ${report.environment.nodeVersion}`);
242
+ lines.push(` \u63D2\u4EF6\u7248\u672C: ${report.environment.pluginVersion}`);
243
+ lines.push(` \u7CFB\u7EDF: ${report.environment.platform} ${report.environment.arch}`);
244
+ lines.push("");
245
+ lines.push("\u3010\u5168\u5C40\u68C0\u67E5\u3011");
246
+ for (const c of report.checks) {
247
+ lines.push(formatCheck(c));
248
+ }
249
+ lines.push("");
250
+ for (const acct of report.accounts) {
251
+ lines.push(`\u3010\u8D26\u6237: ${acct.accountId}\u3011`);
252
+ if (acct.name) lines.push(` \u540D\u79F0: ${acct.name}`);
253
+ lines.push(` App ID: ${acct.appId}`);
254
+ lines.push(` \u54C1\u724C: ${acct.brand}`);
255
+ lines.push("");
256
+ for (const c of acct.checks) {
257
+ lines.push(formatCheck(c));
258
+ }
259
+ lines.push("");
260
+ }
261
+ lines.push("\u3010\u5DE5\u5177\u6CE8\u518C\u3011");
262
+ if (report.toolsRegistered.length > 0) {
263
+ lines.push(` ${report.toolsRegistered.join(", ")}`);
264
+ lines.push(` \u5171 ${report.toolsRegistered.length} \u4E2A`);
265
+ } else {
266
+ lines.push(" \u65E0\u5DE5\u5177\u6CE8\u518C\uFF08\u672A\u627E\u5230\u5DF2\u914D\u7F6E\u7684\u8D26\u6237\uFF09");
267
+ }
268
+ lines.push("");
269
+ if (report.recentErrors.length > 0) {
270
+ lines.push(`\u3010\u6700\u8FD1\u9519\u8BEF\u3011(${report.recentErrors.length} \u6761)`);
271
+ for (let i = 0; i < report.recentErrors.length; i++) {
272
+ lines.push(` ${i + 1}. ${report.recentErrors[i]}`);
273
+ }
274
+ lines.push("");
275
+ }
276
+ const statusMap = {
277
+ healthy: "HEALTHY",
278
+ degraded: "DEGRADED (\u5B58\u5728\u8B66\u544A)",
279
+ unhealthy: "UNHEALTHY (\u5B58\u5728\u5931\u8D25\u9879)"
280
+ };
281
+ lines.push(sep);
282
+ lines.push(` \u603B\u4F53\u72B6\u6001: ${statusMap[report.overallStatus]}`);
283
+ lines.push(sep);
284
+ return lines.join("\n");
285
+ }
286
+ const ANSI = {
287
+ reset: "\x1B[0m",
288
+ bold: "\x1B[1m",
289
+ green: "\x1B[32m",
290
+ yellow: "\x1B[33m",
291
+ red: "\x1B[31m",
292
+ gray: "\x1B[90m"
293
+ };
294
+ const STATUS_LABEL_CLI = {
295
+ pass: `${ANSI.green}[PASS]${ANSI.reset}`,
296
+ warn: `${ANSI.yellow}[WARN]${ANSI.reset}`,
297
+ fail: `${ANSI.red}[FAIL]${ANSI.reset}`,
298
+ skip: `${ANSI.gray}[SKIP]${ANSI.reset}`
299
+ };
300
+ function formatCheckCli(c) {
301
+ let line = ` ${STATUS_LABEL_CLI[c.status]} ${c.name}: ${c.message}`;
302
+ if (c.details) {
303
+ line += `
304
+ ${ANSI.gray}${c.details}${ANSI.reset}`;
305
+ }
306
+ return line;
307
+ }
308
+ async function traceByMessageId(messageId) {
309
+ const logPath = path.join(os.homedir(), ".openclaw", "logs", "gateway.log");
310
+ try {
311
+ await fs.access(logPath);
312
+ } catch {
313
+ return [];
314
+ }
315
+ const TRACE_READ_BYTES = 1024 * 1024;
316
+ try {
317
+ const stat = await fs.stat(logPath);
318
+ const readSize = Math.min(stat.size, TRACE_READ_BYTES);
319
+ const fd = await fs.open(logPath, "r");
320
+ try {
321
+ const buffer = Buffer.alloc(readSize);
322
+ await fd.read(buffer, 0, readSize, Math.max(0, stat.size - readSize));
323
+ const content = buffer.toString("utf-8");
324
+ const needle = `[msg:${messageId}]`;
325
+ return content.split("\n").filter((line) => line.includes(needle));
326
+ } finally {
327
+ await fd.close();
328
+ }
329
+ } catch {
330
+ return [];
331
+ }
332
+ }
333
+ function formatTraceOutput(lines, messageId) {
334
+ const sep = "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500";
335
+ if (lines.length === 0) {
336
+ return [
337
+ sep,
338
+ ` \u672A\u627E\u5230 ${messageId} \u7684\u8FFD\u8E2A\u65E5\u5FD7`,
339
+ "",
340
+ " \u53EF\u80FD\u539F\u56E0:",
341
+ " 1. \u8BE5\u6D88\u606F\u5C1A\u672A\u88AB\u5904\u7406",
342
+ " 2. \u65E5\u5FD7\u5DF2\u88AB\u8F6E\u8F6C",
343
+ " 3. \u8FFD\u8E2A\u529F\u80FD\u672A\u542F\u7528\uFF08\u9700\u8981\u66F4\u65B0\u63D2\u4EF6\u7248\u672C\uFF09",
344
+ sep
345
+ ].join("\n");
346
+ }
347
+ const header = `\u8FFD\u8E2A ${messageId} \u7684\u5904\u7406\u94FE\u8DEF (${lines.length} \u6761\u65E5\u5FD7):`;
348
+ const output = [header, sep];
349
+ for (const line of lines) {
350
+ output.push(line);
351
+ }
352
+ output.push(sep);
353
+ return output.join("\n");
354
+ }
355
+ function classifyEvent(body) {
356
+ if (body.startsWith("received from")) return "received";
357
+ if (body.startsWith("sender resolved")) return "sender_resolved";
358
+ if (body.startsWith("rejected:")) return "rejected";
359
+ if (body.startsWith("dispatching to agent")) return "dispatching";
360
+ if (body.startsWith("dispatch complete")) return "dispatch_complete";
361
+ if (body.startsWith("card entity created")) return "card_created";
362
+ if (body.startsWith("card message sent")) return "card_sent";
363
+ if (body.startsWith("cardkit cardElement.content:")) return "card_stream";
364
+ if (body.startsWith("card stream update failed")) return "card_stream_fail";
365
+ if (body.startsWith("cardkit card.settings:")) return "card_settings";
366
+ if (body.startsWith("cardkit card.update:")) return "card_update";
367
+ if (body.startsWith("card creation failed")) return "card_fallback";
368
+ if (body.startsWith("reply completed")) return "reply_completed";
369
+ if (body.startsWith("reply error")) return "reply_error";
370
+ if (body.startsWith("tool call:")) return "tool_call";
371
+ if (body.startsWith("tool done:")) return "tool_done";
372
+ if (body.startsWith("tool fail:")) return "tool_fail";
373
+ return "other";
374
+ }
375
+ const EVENT_LABEL = {
376
+ received: "\u6D88\u606F\u63A5\u6536",
377
+ sender_resolved: "Sender \u89E3\u6790",
378
+ rejected: "\u6D88\u606F\u62D2\u7EDD",
379
+ dispatching: "\u5206\u53D1\u5230 Agent",
380
+ dispatch_complete: "Agent \u5904\u7406\u5B8C\u6210",
381
+ card_created: "\u5361\u7247\u521B\u5EFA",
382
+ card_sent: "\u5361\u7247\u6D88\u606F\u53D1\u9001",
383
+ card_stream: "\u6D41\u5F0F\u66F4\u65B0",
384
+ card_stream_fail: "\u6D41\u5F0F\u66F4\u65B0\u5931\u8D25",
385
+ card_settings: "\u5361\u7247\u8BBE\u7F6E",
386
+ card_update: "\u5361\u7247\u6700\u7EC8\u66F4\u65B0",
387
+ card_fallback: "\u5361\u7247\u964D\u7EA7",
388
+ reply_completed: "\u56DE\u590D\u5B8C\u6210",
389
+ reply_error: "\u56DE\u590D\u9519\u8BEF",
390
+ tool_call: "\u5DE5\u5177\u8C03\u7528",
391
+ tool_done: "\u5DE5\u5177\u5B8C\u6210",
392
+ tool_fail: "\u5DE5\u5177\u5931\u8D25"
393
+ };
394
+ const EXPECTED_STAGES = [
395
+ { kind: "received", label: "\u6D88\u606F\u63A5\u6536 (received from)" },
396
+ { kind: "dispatching", label: "\u5206\u53D1\u5230 Agent (dispatching to agent)" },
397
+ { kind: "card_created", label: "\u5361\u7247\u521B\u5EFA (card entity created)" },
398
+ { kind: "card_sent", label: "\u5361\u7247\u6D88\u606F\u53D1\u9001 (card message sent)" },
399
+ { kind: "card_stream", label: "\u6D41\u5F0F\u8F93\u51FA (cardElement.content)" },
400
+ { kind: "dispatch_complete", label: "\u5904\u7406\u5B8C\u6210 (dispatch complete)" },
401
+ { kind: "reply_completed", label: "\u56DE\u590D\u6536\u5C3E (reply completed)" }
402
+ ];
403
+ const PERF_THRESHOLDS = [
404
+ { from: "received", to: "dispatching", warnMs: 500, label: "\u6D88\u606F\u63A5\u6536 \u2192 \u5206\u53D1" },
405
+ { from: "dispatching", to: "card_created", warnMs: 5e3, label: "\u5206\u53D1 \u2192 \u5361\u7247\u521B\u5EFA" },
406
+ { from: "card_created", to: "card_stream", warnMs: 3e4, label: "\u5361\u7247\u521B\u5EFA \u2192 \u9996\u6B21\u6D41\u5F0F\u8F93\u51FA" }
407
+ ];
408
+ function parseTraceLines(lines) {
409
+ const events = [];
410
+ const re = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z)\s.*?\]:\s(.+)$/;
411
+ for (const line of lines) {
412
+ const m = line.match(re);
413
+ if (m) {
414
+ events.push({ timestamp: new Date(m[1]), raw: line, body: m[2] });
415
+ }
416
+ }
417
+ return events;
418
+ }
419
+ function analyzeTrace(lines, _messageId) {
420
+ const events = parseTraceLines(lines);
421
+ if (events.length === 0) {
422
+ return `\u65E0\u6CD5\u89E3\u6790\u65E5\u5FD7\u884C\uFF0C\u8BF7\u786E\u8BA4\u65E5\u5FD7\u683C\u5F0F\u6B63\u786E\u3002`;
423
+ }
424
+ const out = [];
425
+ const sep = "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500";
426
+ const startTime = events[0].timestamp.getTime();
427
+ const totalMs = events[events.length - 1].timestamp.getTime() - startTime;
428
+ out.push("");
429
+ out.push(`${ANSI.bold}\u3010\u65F6\u95F4\u7EBF\u3011${ANSI.reset} (${events.length} \u6761\u65E5\u5FD7\uFF0C\u8DE8\u5EA6 ${(totalMs / 1e3).toFixed(1)}s)`);
430
+ out.push(sep);
431
+ let prevMs = startTime;
432
+ let streamCount = 0;
433
+ let streamFirstSeq = "";
434
+ let streamLastSeq = "";
435
+ function flushStream() {
436
+ if (streamCount > 0) {
437
+ const label = streamCount === 1 ? ` ${ANSI.gray}...${ANSI.reset} \u6D41\u5F0F\u66F4\u65B0 seq=${streamFirstSeq}` : ` ${ANSI.gray}...${ANSI.reset} \u6D41\u5F0F\u66F4\u65B0 x${streamCount} (seq=${streamFirstSeq}~${streamLastSeq})`;
438
+ out.push(label);
439
+ streamCount = 0;
440
+ }
441
+ }
442
+ for (const ev of events) {
443
+ const kind = classifyEvent(ev.body);
444
+ const deltaMs = ev.timestamp.getTime() - prevMs;
445
+ prevMs = ev.timestamp.getTime();
446
+ const offsetMs = ev.timestamp.getTime() - startTime;
447
+ const offsetStr = `+${offsetMs}ms`.padStart(10);
448
+ if (kind === "card_stream") {
449
+ const seqMatch = ev.body.match(/seq=(\d+)/);
450
+ const seq = seqMatch ? seqMatch[1] : "?";
451
+ if (streamCount === 0) streamFirstSeq = seq;
452
+ streamLastSeq = seq;
453
+ streamCount++;
454
+ continue;
455
+ }
456
+ flushStream();
457
+ const label = EVENT_LABEL[kind] ?? kind;
458
+ const gapWarn = deltaMs > 5e3 ? ` ${ANSI.yellow}\u26A0 ${(deltaMs / 1e3).toFixed(1)}s${ANSI.reset}` : "";
459
+ let marker = " ";
460
+ if (kind === "rejected" || kind === "reply_error" || kind === "tool_fail" || kind === "card_stream_fail" || kind === "card_fallback") {
461
+ marker = `${ANSI.red}\u2718 ${ANSI.reset}`;
462
+ } else if (kind === "tool_call") {
463
+ marker = "\u2192 ";
464
+ }
465
+ let detail = "";
466
+ if (kind === "received") {
467
+ const m = ev.body.match(/from (\S+) in (\S+) \((\w+)\)/);
468
+ if (m) detail = `sender=${m[1]}, chat=${m[2]} (${m[3]})`;
469
+ } else if (kind === "dispatching") {
470
+ const m = ev.body.match(/session=(\S+)\)/);
471
+ if (m) detail = `session=${m[1]}`;
472
+ } else if (kind === "dispatch_complete") {
473
+ const m = ev.body.match(/replies=(\d+), elapsed=(\d+)ms/);
474
+ if (m) detail = `replies=${m[1]}, elapsed=${m[2]}ms`;
475
+ } else if (kind === "tool_call") {
476
+ const m = ev.body.match(/tool call: (\S+)/);
477
+ if (m) detail = m[1];
478
+ } else if (kind === "tool_fail") {
479
+ detail = ev.body.replace("tool fail: ", "");
480
+ } else if (kind === "card_created") {
481
+ const m = ev.body.match(/card_id=(\S+)\)/);
482
+ if (m) detail = `card_id=${m[1]}`;
483
+ } else if (kind === "reply_completed") {
484
+ const m = ev.body.match(/elapsed=(\d+)ms/);
485
+ if (m) detail = `elapsed=${m[1]}ms`;
486
+ } else if (kind === "rejected") {
487
+ detail = ev.body.replace("rejected: ", "");
488
+ }
489
+ out.push(`${ANSI.gray}[${offsetStr}]${ANSI.reset} ${marker}${label}${detail ? ` \u2014 ${detail}` : ""}${gapWarn}`);
490
+ }
491
+ flushStream();
492
+ out.push("");
493
+ const issues = [];
494
+ const kindSet = new Set(events.map((e) => classifyEvent(e.body)));
495
+ for (const stage of EXPECTED_STAGES) {
496
+ if (!kindSet.has(stage.kind)) {
497
+ if ((stage.kind === "dispatch_complete" || stage.kind === "reply_completed") && !kindSet.has("dispatching"))
498
+ continue;
499
+ if ((stage.kind === "card_created" || stage.kind === "card_sent" || stage.kind === "card_stream") && kindSet.has("rejected"))
500
+ continue;
501
+ issues.push(`\u7F3A\u5931\u9636\u6BB5: ${stage.label}`);
502
+ }
503
+ }
504
+ for (const ev of events) {
505
+ const kind = classifyEvent(ev.body);
506
+ if (kind === "rejected") issues.push(`\u6D88\u606F\u88AB\u62D2\u7EDD: ${ev.body.replace("rejected: ", "")}`);
507
+ if (kind === "reply_error") issues.push(`\u56DE\u590D\u9519\u8BEF: ${ev.body}`);
508
+ if (kind === "tool_fail") issues.push(`\u5DE5\u5177\u5931\u8D25: ${ev.body}`);
509
+ if (kind === "card_stream_fail") issues.push(`\u6D41\u5F0F\u66F4\u65B0\u5931\u8D25: ${ev.body}`);
510
+ if (kind === "card_fallback") issues.push(`\u5361\u7247\u964D\u7EA7: ${ev.body}`);
511
+ if (kind === "card_stream" || kind === "card_update" || kind === "card_settings" || kind === "card_created") {
512
+ const codeMatch = ev.body.match(/code=(\d+)/);
513
+ if (codeMatch && codeMatch[1] !== "0") {
514
+ issues.push(`API \u8FD4\u56DE\u9519\u8BEF\u7801: code=${codeMatch[1]} \u2014 ${ev.body}`);
515
+ }
516
+ }
517
+ }
518
+ const firstByKind = /* @__PURE__ */ new Map();
519
+ for (const ev of events) {
520
+ const kind = classifyEvent(ev.body);
521
+ if (!firstByKind.has(kind)) firstByKind.set(kind, ev);
522
+ }
523
+ for (const rule of PERF_THRESHOLDS) {
524
+ const from = firstByKind.get(rule.from);
525
+ const to = firstByKind.get(rule.to);
526
+ if (from && to) {
527
+ const gap = to.timestamp.getTime() - from.timestamp.getTime();
528
+ if (gap > rule.warnMs) {
529
+ issues.push(
530
+ `\u6027\u80FD\u8B66\u544A: ${rule.label} \u8017\u65F6 ${(gap / 1e3).toFixed(1)}s\uFF08\u9608\u503C ${(rule.warnMs / 1e3).toFixed(0)}s\uFF09`
531
+ );
532
+ }
533
+ }
534
+ }
535
+ const receivedCount = events.filter((e) => classifyEvent(e.body) === "received").length;
536
+ if (receivedCount > 1) {
537
+ issues.push(`\u91CD\u590D\u6295\u9012: \u540C\u4E00\u6D88\u606F\u88AB\u63A5\u6536 ${receivedCount} \u6B21\uFF08WebSocket \u91CD\u6295\u9012\uFF09`);
538
+ }
539
+ const streamSeqs = [];
540
+ for (const ev of events) {
541
+ if (classifyEvent(ev.body) === "card_stream") {
542
+ const m = ev.body.match(/seq=(\d+)/);
543
+ if (m) streamSeqs.push(parseInt(m[1], 10));
544
+ }
545
+ }
546
+ if (streamSeqs.length > 1) {
547
+ for (let i = 1; i < streamSeqs.length; i++) {
548
+ if (streamSeqs[i] !== streamSeqs[i - 1] + 1) {
549
+ issues.push(
550
+ `\u6D41\u5F0F seq \u4E0D\u8FDE\u7EED: seq=${streamSeqs[i - 1]} \u2192 seq=${streamSeqs[i]}\uFF08\u8DF3\u8FC7\u4E86 ${streamSeqs[i] - streamSeqs[i - 1] - 1} \u4E2A\uFF09`
551
+ );
552
+ break;
553
+ }
554
+ }
555
+ }
556
+ out.push(`${ANSI.bold}\u3010\u5F02\u5E38\u68C0\u6D4B\u3011${ANSI.reset}`);
557
+ out.push(sep);
558
+ if (issues.length === 0) {
559
+ out.push(` ${ANSI.green}\u672A\u53D1\u73B0\u5F02\u5E38${ANSI.reset}`);
560
+ } else {
561
+ for (let i = 0; i < issues.length; i++) {
562
+ const isError = issues[i].startsWith("\u5DE5\u5177\u5931\u8D25") || issues[i].startsWith("\u56DE\u590D\u9519\u8BEF") || issues[i].startsWith("API \u8FD4\u56DE\u9519\u8BEF\u7801") || issues[i].startsWith("\u6D41\u5F0F\u66F4\u65B0\u5931\u8D25");
563
+ const color = isError ? ANSI.red : ANSI.yellow;
564
+ out.push(` ${color}${i + 1}. ${issues[i]}${ANSI.reset}`);
565
+ }
566
+ }
567
+ out.push("");
568
+ out.push(`${ANSI.bold}\u3010\u8BCA\u65AD\u603B\u7ED3\u3011${ANSI.reset}`);
569
+ out.push(sep);
570
+ const hasError = issues.some(
571
+ (i) => i.startsWith("\u5DE5\u5177\u5931\u8D25") || i.startsWith("\u56DE\u590D\u9519\u8BEF") || i.startsWith("API \u8FD4\u56DE\u9519\u8BEF\u7801") || i.startsWith("\u6D41\u5F0F\u66F4\u65B0\u5931\u8D25") || i.startsWith("\u7F3A\u5931\u9636\u6BB5")
572
+ );
573
+ const hasWarn = issues.length > 0;
574
+ if (!hasWarn) {
575
+ out.push(` \u72B6\u6001: ${ANSI.green}\u2713 \u6B63\u5E38${ANSI.reset}`);
576
+ out.push(` \u6D88\u606F\u5904\u7406\u94FE\u8DEF\u5B8C\u6574\uFF0C\u5168\u7A0B\u8017\u65F6 ${(totalMs / 1e3).toFixed(1)}s\u3002`);
577
+ const dispatchComplete = events.find(
578
+ (e) => classifyEvent(e.body) === "dispatch_complete" && e.body.includes("replies=") && !e.body.includes("replies=0")
579
+ );
580
+ if (dispatchComplete) {
581
+ const m = dispatchComplete.body.match(/elapsed=(\d+)ms/);
582
+ if (m) {
583
+ out.push(` \u5176\u4E2D Agent \u5904\u7406\u8017\u65F6 ${(parseInt(m[1], 10) / 1e3).toFixed(1)}s\uFF08\u542B AI \u63A8\u7406 + \u5DE5\u5177\u8C03\u7528\uFF09\u3002`);
584
+ }
585
+ }
586
+ } else if (hasError) {
587
+ out.push(` \u72B6\u6001: ${ANSI.red}\u2718 \u5F02\u5E38${ANSI.reset}`);
588
+ out.push(` \u53D1\u73B0 ${issues.length} \u4E2A\u95EE\u9898\uFF0C\u9700\u8981\u6392\u67E5\u3002`);
589
+ } else {
590
+ out.push(` \u72B6\u6001: ${ANSI.yellow}\u26A0 \u6709\u8B66\u544A${ANSI.reset}`);
591
+ out.push(` \u53D1\u73B0 ${issues.length} \u4E2A\u8B66\u544A\uFF0C\u529F\u80FD\u53EF\u7528\u4F46\u9700\u5173\u6CE8\u3002`);
592
+ }
593
+ out.push("");
594
+ return out.join("\n");
595
+ }
596
+ function formatDiagReportCli(report) {
597
+ const lines = [];
598
+ const sep = "====================================";
599
+ lines.push(sep);
600
+ lines.push(` ${ANSI.bold}\u98DE\u4E66\u63D2\u4EF6\u8BCA\u65AD\u62A5\u544A${ANSI.reset}`);
601
+ lines.push(` ${report.timestamp}`);
602
+ lines.push(sep);
603
+ lines.push("");
604
+ lines.push(`${ANSI.bold}\u3010\u73AF\u5883\u4FE1\u606F\u3011${ANSI.reset}`);
605
+ lines.push(` Node.js: ${report.environment.nodeVersion}`);
606
+ lines.push(` \u63D2\u4EF6\u7248\u672C: ${report.environment.pluginVersion}`);
607
+ lines.push(` \u7CFB\u7EDF: ${report.environment.platform} ${report.environment.arch}`);
608
+ lines.push("");
609
+ lines.push(`${ANSI.bold}\u3010\u5168\u5C40\u68C0\u67E5\u3011${ANSI.reset}`);
610
+ for (const c of report.checks) {
611
+ lines.push(formatCheckCli(c));
612
+ }
613
+ lines.push("");
614
+ for (const acct of report.accounts) {
615
+ lines.push(`${ANSI.bold}\u3010\u8D26\u6237: ${acct.accountId}\u3011${ANSI.reset}`);
616
+ if (acct.name) lines.push(` \u540D\u79F0: ${acct.name}`);
617
+ lines.push(` App ID: ${acct.appId}`);
618
+ lines.push(` \u54C1\u724C: ${acct.brand}`);
619
+ lines.push("");
620
+ for (const c of acct.checks) {
621
+ lines.push(formatCheckCli(c));
622
+ }
623
+ lines.push("");
624
+ }
625
+ lines.push(`${ANSI.bold}\u3010\u5DE5\u5177\u6CE8\u518C\u3011${ANSI.reset}`);
626
+ if (report.toolsRegistered.length > 0) {
627
+ lines.push(` ${report.toolsRegistered.join(", ")}`);
628
+ lines.push(` \u5171 ${report.toolsRegistered.length} \u4E2A`);
629
+ } else {
630
+ lines.push(" \u65E0\u5DE5\u5177\u6CE8\u518C\uFF08\u672A\u627E\u5230\u5DF2\u914D\u7F6E\u7684\u8D26\u6237\uFF09");
631
+ }
632
+ lines.push("");
633
+ if (report.recentErrors.length > 0) {
634
+ lines.push(`${ANSI.bold}\u3010\u6700\u8FD1\u9519\u8BEF\u3011${ANSI.reset}(${report.recentErrors.length} \u6761)`);
635
+ for (let i = 0; i < report.recentErrors.length; i++) {
636
+ lines.push(` ${ANSI.gray}${i + 1}. ${report.recentErrors[i]}${ANSI.reset}`);
637
+ }
638
+ lines.push("");
639
+ }
640
+ const statusColorMap = {
641
+ healthy: `${ANSI.green}HEALTHY${ANSI.reset}`,
642
+ degraded: `${ANSI.yellow}DEGRADED (\u5B58\u5728\u8B66\u544A)${ANSI.reset}`,
643
+ unhealthy: `${ANSI.red}UNHEALTHY (\u5B58\u5728\u5931\u8D25\u9879)${ANSI.reset}`
644
+ };
645
+ lines.push(sep);
646
+ lines.push(` \u603B\u4F53\u72B6\u6001: ${statusColorMap[report.overallStatus]}`);
647
+ lines.push(sep);
648
+ return lines.join("\n");
649
+ }
650
+ export {
651
+ analyzeTrace,
652
+ formatDiagReportCli,
653
+ formatDiagReportText,
654
+ formatTraceOutput,
655
+ runDiagnosis,
656
+ traceByMessageId
657
+ };
658
+ //# sourceMappingURL=diagnose.js.map