@larksuite/openclaw-lark 2026.3.9
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.
- package/LICENSE +10 -0
- package/README.md +283 -0
- package/index.d.ts +37 -0
- package/index.d.ts.map +1 -0
- package/index.js +119 -0
- package/index.js.map +1 -0
- package/openclaw.plugin.json +10 -0
- package/package.json +47 -0
- package/skills/feishu-bitable/SKILL.md +248 -0
- package/skills/feishu-bitable/references/examples.md +813 -0
- package/skills/feishu-bitable/references/field-properties.md +763 -0
- package/skills/feishu-bitable/references/record-values.md +911 -0
- package/skills/feishu-calendar/SKILL.md +244 -0
- package/skills/feishu-channel-rules/SKILL.md +18 -0
- package/skills/feishu-channel-rules/references/markdown-syntax.md +138 -0
- package/skills/feishu-create-doc/SKILL.md +719 -0
- package/skills/feishu-fetch-doc/SKILL.md +93 -0
- package/skills/feishu-im-read/SKILL.md +163 -0
- package/skills/feishu-task/SKILL.md +293 -0
- package/skills/feishu-troubleshoot/SKILL.md +70 -0
- package/skills/feishu-update-doc/SKILL.md +285 -0
- package/src/card/builder.d.ts +100 -0
- package/src/card/builder.d.ts.map +1 -0
- package/src/card/builder.js +381 -0
- package/src/card/builder.js.map +1 -0
- package/src/card/cardkit.d.ts +91 -0
- package/src/card/cardkit.d.ts.map +1 -0
- package/src/card/cardkit.js +182 -0
- package/src/card/cardkit.js.map +1 -0
- package/src/card/flush-controller.d.ts +46 -0
- package/src/card/flush-controller.d.ts.map +1 -0
- package/src/card/flush-controller.js +135 -0
- package/src/card/flush-controller.js.map +1 -0
- package/src/card/markdown-style.d.ts +17 -0
- package/src/card/markdown-style.d.ts.map +1 -0
- package/src/card/markdown-style.js +98 -0
- package/src/card/markdown-style.js.map +1 -0
- package/src/card/reply-dispatcher-types.d.ts +121 -0
- package/src/card/reply-dispatcher-types.d.ts.map +1 -0
- package/src/card/reply-dispatcher-types.js +58 -0
- package/src/card/reply-dispatcher-types.js.map +1 -0
- package/src/card/reply-dispatcher.d.ts +16 -0
- package/src/card/reply-dispatcher.d.ts.map +1 -0
- package/src/card/reply-dispatcher.js +293 -0
- package/src/card/reply-dispatcher.js.map +1 -0
- package/src/card/reply-mode.d.ts +39 -0
- package/src/card/reply-mode.d.ts.map +1 -0
- package/src/card/reply-mode.js +66 -0
- package/src/card/reply-mode.js.map +1 -0
- package/src/card/streaming-card-controller.d.ts +88 -0
- package/src/card/streaming-card-controller.d.ts.map +1 -0
- package/src/card/streaming-card-controller.js +717 -0
- package/src/card/streaming-card-controller.js.map +1 -0
- package/src/card/unavailable-guard.d.ts +36 -0
- package/src/card/unavailable-guard.d.ts.map +1 -0
- package/src/card/unavailable-guard.js +84 -0
- package/src/card/unavailable-guard.js.map +1 -0
- package/src/channel/abort-detect.d.ts +35 -0
- package/src/channel/abort-detect.d.ts.map +1 -0
- package/src/channel/abort-detect.js +125 -0
- package/src/channel/abort-detect.js.map +1 -0
- package/src/channel/chat-queue.d.ts +42 -0
- package/src/channel/chat-queue.d.ts.map +1 -0
- package/src/channel/chat-queue.js +59 -0
- package/src/channel/chat-queue.js.map +1 -0
- package/src/channel/config-adapter.d.ts +24 -0
- package/src/channel/config-adapter.d.ts.map +1 -0
- package/src/channel/config-adapter.js +102 -0
- package/src/channel/config-adapter.js.map +1 -0
- package/src/channel/directory.d.ts +58 -0
- package/src/channel/directory.d.ts.map +1 -0
- package/src/channel/directory.js +192 -0
- package/src/channel/directory.js.map +1 -0
- package/src/channel/event-handlers.d.ts +16 -0
- package/src/channel/event-handlers.d.ts.map +1 -0
- package/src/channel/event-handlers.js +222 -0
- package/src/channel/event-handlers.js.map +1 -0
- package/src/channel/monitor.d.ts +18 -0
- package/src/channel/monitor.d.ts.map +1 -0
- package/src/channel/monitor.js +128 -0
- package/src/channel/monitor.js.map +1 -0
- package/src/channel/onboarding-config.d.ts +18 -0
- package/src/channel/onboarding-config.d.ts.map +1 -0
- package/src/channel/onboarding-config.js +89 -0
- package/src/channel/onboarding-config.js.map +1 -0
- package/src/channel/onboarding-migrate.d.ts +26 -0
- package/src/channel/onboarding-migrate.d.ts.map +1 -0
- package/src/channel/onboarding-migrate.js +68 -0
- package/src/channel/onboarding-migrate.js.map +1 -0
- package/src/channel/onboarding.d.ts +13 -0
- package/src/channel/onboarding.d.ts.map +1 -0
- package/src/channel/onboarding.js +297 -0
- package/src/channel/onboarding.js.map +1 -0
- package/src/channel/plugin.d.ts +14 -0
- package/src/channel/plugin.d.ts.map +1 -0
- package/src/channel/plugin.js +279 -0
- package/src/channel/plugin.js.map +1 -0
- package/src/channel/probe.d.ts +15 -0
- package/src/channel/probe.d.ts.map +1 -0
- package/src/channel/probe.js +22 -0
- package/src/channel/probe.js.map +1 -0
- package/src/channel/types.d.ts +37 -0
- package/src/channel/types.d.ts.map +1 -0
- package/src/channel/types.js +8 -0
- package/src/channel/types.js.map +1 -0
- package/src/commands/auth.d.ts +16 -0
- package/src/commands/auth.d.ts.map +1 -0
- package/src/commands/auth.js +85 -0
- package/src/commands/auth.js.map +1 -0
- package/src/commands/diagnose.d.ts +70 -0
- package/src/commands/diagnose.d.ts.map +1 -0
- package/src/commands/diagnose.js +808 -0
- package/src/commands/diagnose.js.map +1 -0
- package/src/commands/doctor.d.ts +18 -0
- package/src/commands/doctor.d.ts.map +1 -0
- package/src/commands/doctor.js +439 -0
- package/src/commands/doctor.js.map +1 -0
- package/src/commands/index.d.ts +9 -0
- package/src/commands/index.d.ts.map +1 -0
- package/src/commands/index.js +208 -0
- package/src/commands/index.js.map +1 -0
- package/src/core/accounts.d.ts +38 -0
- package/src/core/accounts.d.ts.map +1 -0
- package/src/core/accounts.js +179 -0
- package/src/core/accounts.js.map +1 -0
- package/src/core/agent-config.d.ts +101 -0
- package/src/core/agent-config.d.ts.map +1 -0
- package/src/core/agent-config.js +140 -0
- package/src/core/agent-config.js.map +1 -0
- package/src/core/api-error.d.ts +49 -0
- package/src/core/api-error.d.ts.map +1 -0
- package/src/core/api-error.js +113 -0
- package/src/core/api-error.js.map +1 -0
- package/src/core/app-owner-fallback.d.ts +22 -0
- package/src/core/app-owner-fallback.d.ts.map +1 -0
- package/src/core/app-owner-fallback.js +39 -0
- package/src/core/app-owner-fallback.js.map +1 -0
- package/src/core/app-scope-checker.d.ts +88 -0
- package/src/core/app-scope-checker.d.ts.map +1 -0
- package/src/core/app-scope-checker.js +191 -0
- package/src/core/app-scope-checker.js.map +1 -0
- package/src/core/auth-errors.d.ts +143 -0
- package/src/core/auth-errors.d.ts.map +1 -0
- package/src/core/auth-errors.js +156 -0
- package/src/core/auth-errors.js.map +1 -0
- package/src/core/chat-info-cache.d.ts +58 -0
- package/src/core/chat-info-cache.d.ts.map +1 -0
- package/src/core/chat-info-cache.js +153 -0
- package/src/core/chat-info-cache.js.map +1 -0
- package/src/core/config-schema.d.ts +449 -0
- package/src/core/config-schema.d.ts.map +1 -0
- package/src/core/config-schema.js +201 -0
- package/src/core/config-schema.js.map +1 -0
- package/src/core/device-flow.d.ts +78 -0
- package/src/core/device-flow.d.ts.map +1 -0
- package/src/core/device-flow.js +213 -0
- package/src/core/device-flow.js.map +1 -0
- package/src/core/feishu-fetch.d.ts +19 -0
- package/src/core/feishu-fetch.d.ts.map +1 -0
- package/src/core/feishu-fetch.js +26 -0
- package/src/core/feishu-fetch.js.map +1 -0
- package/src/core/footer-config.d.ts +25 -0
- package/src/core/footer-config.d.ts.map +1 -0
- package/src/core/footer-config.js +40 -0
- package/src/core/footer-config.js.map +1 -0
- package/src/core/lark-client.d.ts +109 -0
- package/src/core/lark-client.d.ts.map +1 -0
- package/src/core/lark-client.js +354 -0
- package/src/core/lark-client.js.map +1 -0
- package/src/core/lark-logger.d.ts +24 -0
- package/src/core/lark-logger.d.ts.map +1 -0
- package/src/core/lark-logger.js +155 -0
- package/src/core/lark-logger.js.map +1 -0
- package/src/core/lark-ticket.d.ts +30 -0
- package/src/core/lark-ticket.d.ts.map +1 -0
- package/src/core/lark-ticket.js +36 -0
- package/src/core/lark-ticket.js.map +1 -0
- package/src/core/message-unavailable.d.ts +54 -0
- package/src/core/message-unavailable.d.ts.map +1 -0
- package/src/core/message-unavailable.js +131 -0
- package/src/core/message-unavailable.js.map +1 -0
- package/src/core/owner-policy.d.ts +32 -0
- package/src/core/owner-policy.d.ts.map +1 -0
- package/src/core/owner-policy.js +53 -0
- package/src/core/owner-policy.js.map +1 -0
- package/src/core/permission-url.d.ts +23 -0
- package/src/core/permission-url.d.ts.map +1 -0
- package/src/core/permission-url.js +73 -0
- package/src/core/permission-url.js.map +1 -0
- package/src/core/raw-request.d.ts +28 -0
- package/src/core/raw-request.d.ts.map +1 -0
- package/src/core/raw-request.js +63 -0
- package/src/core/raw-request.js.map +1 -0
- package/src/core/scope-manager.d.ts +169 -0
- package/src/core/scope-manager.d.ts.map +1 -0
- package/src/core/scope-manager.js +214 -0
- package/src/core/scope-manager.js.map +1 -0
- package/src/core/security-check.d.ts +73 -0
- package/src/core/security-check.d.ts.map +1 -0
- package/src/core/security-check.js +175 -0
- package/src/core/security-check.js.map +1 -0
- package/src/core/shutdown-hooks.d.ts +23 -0
- package/src/core/shutdown-hooks.d.ts.map +1 -0
- package/src/core/shutdown-hooks.js +57 -0
- package/src/core/shutdown-hooks.js.map +1 -0
- package/src/core/targets.d.ts +50 -0
- package/src/core/targets.d.ts.map +1 -0
- package/src/core/targets.js +128 -0
- package/src/core/targets.js.map +1 -0
- package/src/core/token-store.d.ts +55 -0
- package/src/core/token-store.d.ts.map +1 -0
- package/src/core/token-store.js +315 -0
- package/src/core/token-store.js.map +1 -0
- package/src/core/tool-client.d.ts +177 -0
- package/src/core/tool-client.d.ts.map +1 -0
- package/src/core/tool-client.js +381 -0
- package/src/core/tool-client.js.map +1 -0
- package/src/core/tool-scopes.d.ts +154 -0
- package/src/core/tool-scopes.d.ts.map +1 -0
- package/src/core/tool-scopes.js +326 -0
- package/src/core/tool-scopes.js.map +1 -0
- package/src/core/tools-config.d.ts +35 -0
- package/src/core/tools-config.d.ts.map +1 -0
- package/src/core/tools-config.js +88 -0
- package/src/core/tools-config.js.map +1 -0
- package/src/core/types.d.ts +88 -0
- package/src/core/types.d.ts.map +1 -0
- package/src/core/types.js +12 -0
- package/src/core/types.js.map +1 -0
- package/src/core/uat-client.d.ts +47 -0
- package/src/core/uat-client.d.ts.map +1 -0
- package/src/core/uat-client.js +173 -0
- package/src/core/uat-client.js.map +1 -0
- package/src/core/version.d.ts +26 -0
- package/src/core/version.d.ts.map +1 -0
- package/src/core/version.js +50 -0
- package/src/core/version.js.map +1 -0
- package/src/messaging/converters/audio.d.ts +9 -0
- package/src/messaging/converters/audio.d.ts.map +1 -0
- package/src/messaging/converters/audio.js +22 -0
- package/src/messaging/converters/audio.js.map +1 -0
- package/src/messaging/converters/calendar.d.ts +14 -0
- package/src/messaging/converters/calendar.d.ts.map +1 -0
- package/src/messaging/converters/calendar.js +51 -0
- package/src/messaging/converters/calendar.js.map +1 -0
- package/src/messaging/converters/content-converter.d.ts +42 -0
- package/src/messaging/converters/content-converter.d.ts.map +1 -0
- package/src/messaging/converters/content-converter.js +107 -0
- package/src/messaging/converters/content-converter.js.map +1 -0
- package/src/messaging/converters/file.d.ts +9 -0
- package/src/messaging/converters/file.d.ts.map +1 -0
- package/src/messaging/converters/file.js +21 -0
- package/src/messaging/converters/file.js.map +1 -0
- package/src/messaging/converters/folder.d.ts +9 -0
- package/src/messaging/converters/folder.d.ts.map +1 -0
- package/src/messaging/converters/folder.js +21 -0
- package/src/messaging/converters/folder.js.map +1 -0
- package/src/messaging/converters/hongbao.d.ts +9 -0
- package/src/messaging/converters/hongbao.d.ts.map +1 -0
- package/src/messaging/converters/hongbao.js +17 -0
- package/src/messaging/converters/hongbao.js.map +1 -0
- package/src/messaging/converters/image.d.ts +9 -0
- package/src/messaging/converters/image.d.ts.map +1 -0
- package/src/messaging/converters/image.js +19 -0
- package/src/messaging/converters/image.js.map +1 -0
- package/src/messaging/converters/index.d.ts +9 -0
- package/src/messaging/converters/index.d.ts.map +1 -0
- package/src/messaging/converters/index.js +51 -0
- package/src/messaging/converters/index.js.map +1 -0
- package/src/messaging/converters/interactive/card-converter.d.ts +77 -0
- package/src/messaging/converters/interactive/card-converter.d.ts.map +1 -0
- package/src/messaging/converters/interactive/card-converter.js +1174 -0
- package/src/messaging/converters/interactive/card-converter.js.map +1 -0
- package/src/messaging/converters/interactive/card-utils.d.ts +10 -0
- package/src/messaging/converters/interactive/card-utils.d.ts.map +1 -0
- package/src/messaging/converters/interactive/card-utils.js +43 -0
- package/src/messaging/converters/interactive/card-utils.js.map +1 -0
- package/src/messaging/converters/interactive/index.d.ts +9 -0
- package/src/messaging/converters/interactive/index.d.ts.map +1 -0
- package/src/messaging/converters/interactive/index.js +22 -0
- package/src/messaging/converters/interactive/index.js.map +1 -0
- package/src/messaging/converters/interactive/legacy.d.ts +12 -0
- package/src/messaging/converters/interactive/legacy.d.ts.map +1 -0
- package/src/messaging/converters/interactive/legacy.js +58 -0
- package/src/messaging/converters/interactive/legacy.js.map +1 -0
- package/src/messaging/converters/interactive/types.d.ts +24 -0
- package/src/messaging/converters/interactive/types.d.ts.map +1 -0
- package/src/messaging/converters/interactive/types.js +25 -0
- package/src/messaging/converters/interactive/types.js.map +1 -0
- package/src/messaging/converters/location.d.ts +9 -0
- package/src/messaging/converters/location.d.ts.map +1 -0
- package/src/messaging/converters/location.js +20 -0
- package/src/messaging/converters/location.js.map +1 -0
- package/src/messaging/converters/merge-forward.d.ts +33 -0
- package/src/messaging/converters/merge-forward.d.ts.map +1 -0
- package/src/messaging/converters/merge-forward.js +226 -0
- package/src/messaging/converters/merge-forward.js.map +1 -0
- package/src/messaging/converters/post.d.ts +12 -0
- package/src/messaging/converters/post.d.ts.map +1 -0
- package/src/messaging/converters/post.js +136 -0
- package/src/messaging/converters/post.js.map +1 -0
- package/src/messaging/converters/share.d.ts +10 -0
- package/src/messaging/converters/share.d.ts.map +1 -0
- package/src/messaging/converters/share.js +24 -0
- package/src/messaging/converters/share.js.map +1 -0
- package/src/messaging/converters/sticker.d.ts +9 -0
- package/src/messaging/converters/sticker.d.ts.map +1 -0
- package/src/messaging/converters/sticker.js +19 -0
- package/src/messaging/converters/sticker.js.map +1 -0
- package/src/messaging/converters/system.d.ts +13 -0
- package/src/messaging/converters/system.d.ts.map +1 -0
- package/src/messaging/converters/system.js +33 -0
- package/src/messaging/converters/system.js.map +1 -0
- package/src/messaging/converters/text.d.ts +9 -0
- package/src/messaging/converters/text.d.ts.map +1 -0
- package/src/messaging/converters/text.js +15 -0
- package/src/messaging/converters/text.js.map +1 -0
- package/src/messaging/converters/todo.d.ts +9 -0
- package/src/messaging/converters/todo.d.ts.map +1 -0
- package/src/messaging/converters/todo.js +42 -0
- package/src/messaging/converters/todo.js.map +1 -0
- package/src/messaging/converters/types.d.ts +108 -0
- package/src/messaging/converters/types.d.ts.map +1 -0
- package/src/messaging/converters/types.js +8 -0
- package/src/messaging/converters/types.js.map +1 -0
- package/src/messaging/converters/unknown.d.ts +9 -0
- package/src/messaging/converters/unknown.d.ts.map +1 -0
- package/src/messaging/converters/unknown.js +17 -0
- package/src/messaging/converters/unknown.js.map +1 -0
- package/src/messaging/converters/utils.d.ts +23 -0
- package/src/messaging/converters/utils.d.ts.map +1 -0
- package/src/messaging/converters/utils.js +52 -0
- package/src/messaging/converters/utils.js.map +1 -0
- package/src/messaging/converters/video-chat.d.ts +9 -0
- package/src/messaging/converters/video-chat.d.ts.map +1 -0
- package/src/messaging/converters/video-chat.js +24 -0
- package/src/messaging/converters/video-chat.js.map +1 -0
- package/src/messaging/converters/video.d.ts +9 -0
- package/src/messaging/converters/video.d.ts.map +1 -0
- package/src/messaging/converters/video.js +33 -0
- package/src/messaging/converters/video.js.map +1 -0
- package/src/messaging/converters/vote.d.ts +9 -0
- package/src/messaging/converters/vote.d.ts.map +1 -0
- package/src/messaging/converters/vote.js +25 -0
- package/src/messaging/converters/vote.js.map +1 -0
- package/src/messaging/inbound/dedup.d.ts +60 -0
- package/src/messaging/inbound/dedup.d.ts.map +1 -0
- package/src/messaging/inbound/dedup.js +117 -0
- package/src/messaging/inbound/dedup.js.map +1 -0
- package/src/messaging/inbound/dispatch-builders.d.ts +84 -0
- package/src/messaging/inbound/dispatch-builders.d.ts.map +1 -0
- package/src/messaging/inbound/dispatch-builders.js +153 -0
- package/src/messaging/inbound/dispatch-builders.js.map +1 -0
- package/src/messaging/inbound/dispatch-commands.d.ts +28 -0
- package/src/messaging/inbound/dispatch-commands.d.ts.map +1 -0
- package/src/messaging/inbound/dispatch-commands.js +113 -0
- package/src/messaging/inbound/dispatch-commands.js.map +1 -0
- package/src/messaging/inbound/dispatch-context.d.ts +68 -0
- package/src/messaging/inbound/dispatch-context.d.ts.map +1 -0
- package/src/messaging/inbound/dispatch-context.js +137 -0
- package/src/messaging/inbound/dispatch-context.js.map +1 -0
- package/src/messaging/inbound/dispatch.d.ts +48 -0
- package/src/messaging/inbound/dispatch.d.ts.map +1 -0
- package/src/messaging/inbound/dispatch.js +193 -0
- package/src/messaging/inbound/dispatch.js.map +1 -0
- package/src/messaging/inbound/enrich.d.ts +103 -0
- package/src/messaging/inbound/enrich.d.ts.map +1 -0
- package/src/messaging/inbound/enrich.js +228 -0
- package/src/messaging/inbound/enrich.js.map +1 -0
- package/src/messaging/inbound/gate-effects.d.ts +24 -0
- package/src/messaging/inbound/gate-effects.d.ts.map +1 -0
- package/src/messaging/inbound/gate-effects.js +44 -0
- package/src/messaging/inbound/gate-effects.js.map +1 -0
- package/src/messaging/inbound/gate.d.ts +61 -0
- package/src/messaging/inbound/gate.d.ts.map +1 -0
- package/src/messaging/inbound/gate.js +234 -0
- package/src/messaging/inbound/gate.js.map +1 -0
- package/src/messaging/inbound/handler.d.ts +36 -0
- package/src/messaging/inbound/handler.d.ts.map +1 -0
- package/src/messaging/inbound/handler.js +174 -0
- package/src/messaging/inbound/handler.js.map +1 -0
- package/src/messaging/inbound/media-resolver.d.ts +33 -0
- package/src/messaging/inbound/media-resolver.d.ts.map +1 -0
- package/src/messaging/inbound/media-resolver.js +88 -0
- package/src/messaging/inbound/media-resolver.js.map +1 -0
- package/src/messaging/inbound/mention.d.ts +40 -0
- package/src/messaging/inbound/mention.d.ts.map +1 -0
- package/src/messaging/inbound/mention.js +82 -0
- package/src/messaging/inbound/mention.js.map +1 -0
- package/src/messaging/inbound/parse-io.d.ts +51 -0
- package/src/messaging/inbound/parse-io.d.ts.map +1 -0
- package/src/messaging/inbound/parse-io.js +82 -0
- package/src/messaging/inbound/parse-io.js.map +1 -0
- package/src/messaging/inbound/parse.d.ts +29 -0
- package/src/messaging/inbound/parse.d.ts.map +1 -0
- package/src/messaging/inbound/parse.js +107 -0
- package/src/messaging/inbound/parse.js.map +1 -0
- package/src/messaging/inbound/permission.d.ts +18 -0
- package/src/messaging/inbound/permission.d.ts.map +1 -0
- package/src/messaging/inbound/permission.js +41 -0
- package/src/messaging/inbound/permission.js.map +1 -0
- package/src/messaging/inbound/policy.d.ts +95 -0
- package/src/messaging/inbound/policy.d.ts.map +1 -0
- package/src/messaging/inbound/policy.js +161 -0
- package/src/messaging/inbound/policy.js.map +1 -0
- package/src/messaging/inbound/reaction-handler.d.ts +62 -0
- package/src/messaging/inbound/reaction-handler.d.ts.map +1 -0
- package/src/messaging/inbound/reaction-handler.js +221 -0
- package/src/messaging/inbound/reaction-handler.js.map +1 -0
- package/src/messaging/inbound/user-name-cache.d.ts +83 -0
- package/src/messaging/inbound/user-name-cache.d.ts.map +1 -0
- package/src/messaging/inbound/user-name-cache.js +242 -0
- package/src/messaging/inbound/user-name-cache.js.map +1 -0
- package/src/messaging/outbound/actions.d.ts +17 -0
- package/src/messaging/outbound/actions.d.ts.map +1 -0
- package/src/messaging/outbound/actions.js +310 -0
- package/src/messaging/outbound/actions.js.map +1 -0
- package/src/messaging/outbound/chat-manage.d.ts +65 -0
- package/src/messaging/outbound/chat-manage.d.ts.map +1 -0
- package/src/messaging/outbound/chat-manage.js +112 -0
- package/src/messaging/outbound/chat-manage.js.map +1 -0
- package/src/messaging/outbound/deliver.d.ts +156 -0
- package/src/messaging/outbound/deliver.d.ts.map +1 -0
- package/src/messaging/outbound/deliver.js +299 -0
- package/src/messaging/outbound/deliver.js.map +1 -0
- package/src/messaging/outbound/fetch.d.ts +13 -0
- package/src/messaging/outbound/fetch.d.ts.map +1 -0
- package/src/messaging/outbound/fetch.js +13 -0
- package/src/messaging/outbound/fetch.js.map +1 -0
- package/src/messaging/outbound/forward.d.ts +27 -0
- package/src/messaging/outbound/forward.d.ts.map +1 -0
- package/src/messaging/outbound/forward.js +49 -0
- package/src/messaging/outbound/forward.js.map +1 -0
- package/src/messaging/outbound/media-url-utils.d.ts +30 -0
- package/src/messaging/outbound/media-url-utils.d.ts.map +1 -0
- package/src/messaging/outbound/media-url-utils.js +131 -0
- package/src/messaging/outbound/media-url-utils.js.map +1 -0
- package/src/messaging/outbound/media.d.ts +256 -0
- package/src/messaging/outbound/media.d.ts.map +1 -0
- package/src/messaging/outbound/media.js +749 -0
- package/src/messaging/outbound/media.js.map +1 -0
- package/src/messaging/outbound/outbound.d.ts +90 -0
- package/src/messaging/outbound/outbound.d.ts.map +1 -0
- package/src/messaging/outbound/outbound.js +112 -0
- package/src/messaging/outbound/outbound.js.map +1 -0
- package/src/messaging/outbound/reactions.d.ts +125 -0
- package/src/messaging/outbound/reactions.d.ts.map +1 -0
- package/src/messaging/outbound/reactions.js +379 -0
- package/src/messaging/outbound/reactions.js.map +1 -0
- package/src/messaging/outbound/send.d.ts +136 -0
- package/src/messaging/outbound/send.d.ts.map +1 -0
- package/src/messaging/outbound/send.js +289 -0
- package/src/messaging/outbound/send.js.map +1 -0
- package/src/messaging/outbound/typing.d.ts +61 -0
- package/src/messaging/outbound/typing.d.ts.map +1 -0
- package/src/messaging/outbound/typing.js +136 -0
- package/src/messaging/outbound/typing.js.map +1 -0
- package/src/messaging/shared/message-lookup.d.ts +55 -0
- package/src/messaging/shared/message-lookup.d.ts.map +1 -0
- package/src/messaging/shared/message-lookup.js +118 -0
- package/src/messaging/shared/message-lookup.js.map +1 -0
- package/src/messaging/types.d.ts +177 -0
- package/src/messaging/types.d.ts.map +1 -0
- package/src/messaging/types.js +11 -0
- package/src/messaging/types.js.map +1 -0
- package/src/tools/auto-auth.d.ts +57 -0
- package/src/tools/auto-auth.d.ts.map +1 -0
- package/src/tools/auto-auth.js +925 -0
- package/src/tools/auto-auth.js.map +1 -0
- package/src/tools/helpers.d.ts +220 -0
- package/src/tools/helpers.d.ts.map +1 -0
- package/src/tools/helpers.js +298 -0
- package/src/tools/helpers.js.map +1 -0
- package/src/tools/mcp/doc/create.d.ts +13 -0
- package/src/tools/mcp/doc/create.d.ts.map +1 -0
- package/src/tools/mcp/doc/create.js +45 -0
- package/src/tools/mcp/doc/create.js.map +1 -0
- package/src/tools/mcp/doc/fetch.d.ts +13 -0
- package/src/tools/mcp/doc/fetch.d.ts.map +1 -0
- package/src/tools/mcp/doc/fetch.js +37 -0
- package/src/tools/mcp/doc/fetch.js.map +1 -0
- package/src/tools/mcp/doc/index.d.ts +13 -0
- package/src/tools/mcp/doc/index.d.ts.map +1 -0
- package/src/tools/mcp/doc/index.js +42 -0
- package/src/tools/mcp/doc/index.js.map +1 -0
- package/src/tools/mcp/doc/update.d.ts +13 -0
- package/src/tools/mcp/doc/update.d.ts.map +1 -0
- package/src/tools/mcp/doc/update.js +62 -0
- package/src/tools/mcp/doc/update.js.map +1 -0
- package/src/tools/mcp/shared.d.ts +58 -0
- package/src/tools/mcp/shared.d.ts.map +1 -0
- package/src/tools/mcp/shared.js +224 -0
- package/src/tools/mcp/shared.js.map +1 -0
- package/src/tools/oapi/bitable/app-table-field.d.ts +17 -0
- package/src/tools/oapi/bitable/app-table-field.d.ts.map +1 -0
- package/src/tools/oapi/bitable/app-table-field.js +224 -0
- package/src/tools/oapi/bitable/app-table-field.js.map +1 -0
- package/src/tools/oapi/bitable/app-table-record.d.ts +21 -0
- package/src/tools/oapi/bitable/app-table-record.d.ts.map +1 -0
- package/src/tools/oapi/bitable/app-table-record.js +449 -0
- package/src/tools/oapi/bitable/app-table-record.js.map +1 -0
- package/src/tools/oapi/bitable/app-table-view.d.ts +18 -0
- package/src/tools/oapi/bitable/app-table-view.d.ts.map +1 -0
- package/src/tools/oapi/bitable/app-table-view.js +197 -0
- package/src/tools/oapi/bitable/app-table-view.js.map +1 -0
- package/src/tools/oapi/bitable/app-table.d.ts +20 -0
- package/src/tools/oapi/bitable/app-table.d.ts.map +1 -0
- package/src/tools/oapi/bitable/app-table.js +249 -0
- package/src/tools/oapi/bitable/app-table.js.map +1 -0
- package/src/tools/oapi/bitable/app.d.ts +19 -0
- package/src/tools/oapi/bitable/app.d.ts.map +1 -0
- package/src/tools/oapi/bitable/app.js +188 -0
- package/src/tools/oapi/bitable/app.js.map +1 -0
- package/src/tools/oapi/bitable/index.d.ts +10 -0
- package/src/tools/oapi/bitable/index.d.ts.map +1 -0
- package/src/tools/oapi/bitable/index.js +10 -0
- package/src/tools/oapi/bitable/index.js.map +1 -0
- package/src/tools/oapi/calendar/calendar.d.ts +16 -0
- package/src/tools/oapi/calendar/calendar.d.ts.map +1 -0
- package/src/tools/oapi/calendar/calendar.js +124 -0
- package/src/tools/oapi/calendar/calendar.js.map +1 -0
- package/src/tools/oapi/calendar/event-attendee.d.ts +17 -0
- package/src/tools/oapi/calendar/event-attendee.d.ts.map +1 -0
- package/src/tools/oapi/calendar/event-attendee.js +275 -0
- package/src/tools/oapi/calendar/event-attendee.js.map +1 -0
- package/src/tools/oapi/calendar/event.d.ts +17 -0
- package/src/tools/oapi/calendar/event.d.ts.map +1 -0
- package/src/tools/oapi/calendar/event.js +721 -0
- package/src/tools/oapi/calendar/event.js.map +1 -0
- package/src/tools/oapi/calendar/freebusy.d.ts +14 -0
- package/src/tools/oapi/calendar/freebusy.d.ts.map +1 -0
- package/src/tools/oapi/calendar/freebusy.js +113 -0
- package/src/tools/oapi/calendar/freebusy.js.map +1 -0
- package/src/tools/oapi/calendar/index.d.ts +9 -0
- package/src/tools/oapi/calendar/index.d.ts.map +1 -0
- package/src/tools/oapi/calendar/index.js +9 -0
- package/src/tools/oapi/calendar/index.js.map +1 -0
- package/src/tools/oapi/chat/chat.d.ts +17 -0
- package/src/tools/oapi/chat/chat.d.ts.map +1 -0
- package/src/tools/oapi/chat/chat.js +126 -0
- package/src/tools/oapi/chat/chat.js.map +1 -0
- package/src/tools/oapi/chat/index.d.ts +11 -0
- package/src/tools/oapi/chat/index.d.ts.map +1 -0
- package/src/tools/oapi/chat/index.js +16 -0
- package/src/tools/oapi/chat/index.js.map +1 -0
- package/src/tools/oapi/chat/members.d.ts +12 -0
- package/src/tools/oapi/chat/members.d.ts.map +1 -0
- package/src/tools/oapi/chat/members.js +83 -0
- package/src/tools/oapi/chat/members.js.map +1 -0
- package/src/tools/oapi/common/get-user.d.ts +13 -0
- package/src/tools/oapi/common/get-user.d.ts.map +1 -0
- package/src/tools/oapi/common/get-user.js +108 -0
- package/src/tools/oapi/common/get-user.js.map +1 -0
- package/src/tools/oapi/common/index.d.ts +7 -0
- package/src/tools/oapi/common/index.d.ts.map +1 -0
- package/src/tools/oapi/common/index.js +7 -0
- package/src/tools/oapi/common/index.js.map +1 -0
- package/src/tools/oapi/common/search-user.d.ts +12 -0
- package/src/tools/oapi/common/search-user.d.ts.map +1 -0
- package/src/tools/oapi/common/search-user.js +75 -0
- package/src/tools/oapi/common/search-user.js.map +1 -0
- package/src/tools/oapi/drive/doc-comments.d.ts +16 -0
- package/src/tools/oapi/drive/doc-comments.d.ts.map +1 -0
- package/src/tools/oapi/drive/doc-comments.js +288 -0
- package/src/tools/oapi/drive/doc-comments.js.map +1 -0
- package/src/tools/oapi/drive/doc-media.d.ts +20 -0
- package/src/tools/oapi/drive/doc-media.d.ts.map +1 -0
- package/src/tools/oapi/drive/doc-media.js +337 -0
- package/src/tools/oapi/drive/doc-media.js.map +1 -0
- package/src/tools/oapi/drive/file.d.ts +20 -0
- package/src/tools/oapi/drive/file.d.ts.map +1 -0
- package/src/tools/oapi/drive/file.js +485 -0
- package/src/tools/oapi/drive/file.js.map +1 -0
- package/src/tools/oapi/drive/index.d.ts +13 -0
- package/src/tools/oapi/drive/index.d.ts.map +1 -0
- package/src/tools/oapi/drive/index.js +37 -0
- package/src/tools/oapi/drive/index.js.map +1 -0
- package/src/tools/oapi/helpers.d.ts +174 -0
- package/src/tools/oapi/helpers.d.ts.map +1 -0
- package/src/tools/oapi/helpers.js +341 -0
- package/src/tools/oapi/helpers.js.map +1 -0
- package/src/tools/oapi/im/format-messages.d.ts +51 -0
- package/src/tools/oapi/im/format-messages.d.ts.map +1 -0
- package/src/tools/oapi/im/format-messages.js +166 -0
- package/src/tools/oapi/im/format-messages.js.map +1 -0
- package/src/tools/oapi/im/index.d.ts +11 -0
- package/src/tools/oapi/im/index.d.ts.map +1 -0
- package/src/tools/oapi/im/index.js +18 -0
- package/src/tools/oapi/im/index.js.map +1 -0
- package/src/tools/oapi/im/message-read.d.ts +14 -0
- package/src/tools/oapi/im/message-read.d.ts.map +1 -0
- package/src/tools/oapi/im/message-read.js +412 -0
- package/src/tools/oapi/im/message-read.js.map +1 -0
- package/src/tools/oapi/im/message.d.ts +17 -0
- package/src/tools/oapi/im/message.d.ts.map +1 -0
- package/src/tools/oapi/im/message.js +171 -0
- package/src/tools/oapi/im/message.js.map +1 -0
- package/src/tools/oapi/im/resource.d.ts +14 -0
- package/src/tools/oapi/im/resource.d.ts.map +1 -0
- package/src/tools/oapi/im/resource.js +152 -0
- package/src/tools/oapi/im/resource.js.map +1 -0
- package/src/tools/oapi/im/time-utils.d.ts +47 -0
- package/src/tools/oapi/im/time-utils.d.ts.map +1 -0
- package/src/tools/oapi/im/time-utils.js +202 -0
- package/src/tools/oapi/im/time-utils.js.map +1 -0
- package/src/tools/oapi/im/user-name-uat.d.ts +24 -0
- package/src/tools/oapi/im/user-name-uat.d.ts.map +1 -0
- package/src/tools/oapi/im/user-name-uat.js +128 -0
- package/src/tools/oapi/im/user-name-uat.js.map +1 -0
- package/src/tools/oapi/index.d.ts +12 -0
- package/src/tools/oapi/index.d.ts.map +1 -0
- package/src/tools/oapi/index.js +59 -0
- package/src/tools/oapi/index.js.map +1 -0
- package/src/tools/oapi/sdk-types.d.ts +97 -0
- package/src/tools/oapi/sdk-types.d.ts.map +1 -0
- package/src/tools/oapi/sdk-types.js +13 -0
- package/src/tools/oapi/sdk-types.js.map +1 -0
- package/src/tools/oapi/search/doc-search.d.ts +14 -0
- package/src/tools/oapi/search/doc-search.d.ts.map +1 -0
- package/src/tools/oapi/search/doc-search.js +203 -0
- package/src/tools/oapi/search/doc-search.js.map +1 -0
- package/src/tools/oapi/search/index.d.ts +13 -0
- package/src/tools/oapi/search/index.d.ts.map +1 -0
- package/src/tools/oapi/search/index.js +34 -0
- package/src/tools/oapi/search/index.js.map +1 -0
- package/src/tools/oapi/sheets/index.d.ts +13 -0
- package/src/tools/oapi/sheets/index.d.ts.map +1 -0
- package/src/tools/oapi/sheets/index.js +32 -0
- package/src/tools/oapi/sheets/index.js.map +1 -0
- package/src/tools/oapi/sheets/sheet.d.ts +17 -0
- package/src/tools/oapi/sheets/sheet.d.ts.map +1 -0
- package/src/tools/oapi/sheets/sheet.js +652 -0
- package/src/tools/oapi/sheets/sheet.js.map +1 -0
- package/src/tools/oapi/task/comment.d.ts +16 -0
- package/src/tools/oapi/task/comment.d.ts.map +1 -0
- package/src/tools/oapi/task/comment.js +142 -0
- package/src/tools/oapi/task/comment.js.map +1 -0
- package/src/tools/oapi/task/index.d.ts +9 -0
- package/src/tools/oapi/task/index.d.ts.map +1 -0
- package/src/tools/oapi/task/index.js +9 -0
- package/src/tools/oapi/task/index.js.map +1 -0
- package/src/tools/oapi/task/subtask.d.ts +15 -0
- package/src/tools/oapi/task/subtask.d.ts.map +1 -0
- package/src/tools/oapi/task/subtask.js +164 -0
- package/src/tools/oapi/task/subtask.js.map +1 -0
- package/src/tools/oapi/task/task.d.ts +17 -0
- package/src/tools/oapi/task/task.d.ts.map +1 -0
- package/src/tools/oapi/task/task.js +346 -0
- package/src/tools/oapi/task/task.js.map +1 -0
- package/src/tools/oapi/task/tasklist.d.ts +22 -0
- package/src/tools/oapi/task/tasklist.d.ts.map +1 -0
- package/src/tools/oapi/task/tasklist.js +323 -0
- package/src/tools/oapi/task/tasklist.js.map +1 -0
- package/src/tools/oapi/wiki/index.d.ts +13 -0
- package/src/tools/oapi/wiki/index.d.ts.map +1 -0
- package/src/tools/oapi/wiki/index.js +35 -0
- package/src/tools/oapi/wiki/index.js.map +1 -0
- package/src/tools/oapi/wiki/space-node.d.ts +18 -0
- package/src/tools/oapi/wiki/space-node.d.ts.map +1 -0
- package/src/tools/oapi/wiki/space-node.js +253 -0
- package/src/tools/oapi/wiki/space-node.js.map +1 -0
- package/src/tools/oapi/wiki/space.d.ts +16 -0
- package/src/tools/oapi/wiki/space.d.ts.map +1 -0
- package/src/tools/oapi/wiki/space.js +132 -0
- package/src/tools/oapi/wiki/space.js.map +1 -0
- package/src/tools/oauth-batch-auth.d.ts +12 -0
- package/src/tools/oauth-batch-auth.d.ts.map +1 -0
- package/src/tools/oauth-batch-auth.js +142 -0
- package/src/tools/oauth-batch-auth.js.map +1 -0
- package/src/tools/oauth-cards.d.ts +27 -0
- package/src/tools/oauth-cards.d.ts.map +1 -0
- package/src/tools/oauth-cards.js +251 -0
- package/src/tools/oauth-cards.js.map +1 -0
- package/src/tools/oauth.d.ts +48 -0
- package/src/tools/oauth.d.ts.map +1 -0
- package/src/tools/oauth.js +619 -0
- package/src/tools/oauth.js.map +1 -0
- package/src/tools/onboarding-auth.d.ts +28 -0
- package/src/tools/onboarding-auth.d.ts.map +1 -0
- package/src/tools/onboarding-auth.js +131 -0
- package/src/tools/onboarding-auth.js.map +1 -0
- package/src/tools/tat/im/index.d.ts +16 -0
- package/src/tools/tat/im/index.d.ts.map +1 -0
- package/src/tools/tat/im/index.js +19 -0
- package/src/tools/tat/im/index.js.map +1 -0
- package/src/tools/tat/im/resource.d.ts +16 -0
- package/src/tools/tat/im/resource.d.ts.map +1 -0
- package/src/tools/tat/im/resource.js +158 -0
- package/src/tools/tat/im/resource.js.map +1 -0
|
@@ -0,0 +1,808 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* Diagnostic module for the Feishu/Lark plugin.
|
|
6
|
+
*
|
|
7
|
+
* Collects environment info, account configuration, API connectivity,
|
|
8
|
+
* app permissions, tool registration state, and recent error logs into
|
|
9
|
+
* a structured report that users can share with developers for
|
|
10
|
+
* remote troubleshooting.
|
|
11
|
+
*/
|
|
12
|
+
import * as fs from 'node:fs/promises';
|
|
13
|
+
import * as path from 'node:path';
|
|
14
|
+
import * as os from 'node:os';
|
|
15
|
+
import { probeFeishu } from '../channel/probe';
|
|
16
|
+
import { getLarkAccountIds, getLarkAccount, getEnabledLarkAccounts } from '../core/accounts';
|
|
17
|
+
import { LarkClient } from '../core/lark-client';
|
|
18
|
+
/**
|
|
19
|
+
* Resolve the global config for cross-account operations.
|
|
20
|
+
* See doctor.ts for rationale.
|
|
21
|
+
*/
|
|
22
|
+
function resolveGlobalConfig(config) {
|
|
23
|
+
return LarkClient.globalConfig ?? config;
|
|
24
|
+
}
|
|
25
|
+
import { assertLarkOk, formatLarkError } from '../core/api-error';
|
|
26
|
+
import { resolveAnyEnabledToolsConfig } from '../core/tools-config';
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Constants
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
const PLUGIN_VERSION = '2026.2.10';
|
|
31
|
+
const LOG_READ_BYTES = 256 * 1024; // read last 256KB of log
|
|
32
|
+
const MAX_ERROR_LINES = 20;
|
|
33
|
+
/** Matches a timestamped log line: 2026-02-13T09:23:35.038Z [level]: ... */
|
|
34
|
+
const TIMESTAMPED_LINE_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/;
|
|
35
|
+
const ERROR_LEVEL_RE = /\[error\]|\[warn\]/i;
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
// Helpers
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
function maskSecret(secret) {
|
|
40
|
+
if (!secret)
|
|
41
|
+
return '(未设置)';
|
|
42
|
+
if (secret.length <= 4)
|
|
43
|
+
return '****';
|
|
44
|
+
return secret.slice(0, 4) + '****';
|
|
45
|
+
}
|
|
46
|
+
async function extractRecentErrors(logPath) {
|
|
47
|
+
try {
|
|
48
|
+
await fs.access(logPath);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const stat = await fs.stat(logPath);
|
|
55
|
+
const readSize = Math.min(stat.size, LOG_READ_BYTES);
|
|
56
|
+
const fd = await fs.open(logPath, 'r');
|
|
57
|
+
try {
|
|
58
|
+
const buffer = Buffer.alloc(readSize);
|
|
59
|
+
await fd.read(buffer, 0, readSize, Math.max(0, stat.size - readSize));
|
|
60
|
+
const content = buffer.toString('utf-8');
|
|
61
|
+
const lines = content.split('\n').filter(Boolean);
|
|
62
|
+
// Only pick timestamped log entries at error/warn level,
|
|
63
|
+
// ignoring stack trace fragments and other noise.
|
|
64
|
+
const errorLines = lines.filter((line) => TIMESTAMPED_LINE_RE.test(line) && ERROR_LEVEL_RE.test(line));
|
|
65
|
+
return errorLines.slice(-MAX_ERROR_LINES);
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
await fd.close();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function checkAppScopes(client) {
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
|
+
const res = await client.application.scope.list({});
|
|
78
|
+
assertLarkOk(res);
|
|
79
|
+
const scopes = res.data?.scopes ?? [];
|
|
80
|
+
const granted = scopes.filter((s) => s.grant_status === 1);
|
|
81
|
+
const pending = scopes.filter((s) => s.grant_status !== 1);
|
|
82
|
+
return {
|
|
83
|
+
granted: granted.length,
|
|
84
|
+
pending: pending.length,
|
|
85
|
+
summary: `${granted.length} 已授权, ${pending.length} 待授权`,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function detectRegisteredTools(config) {
|
|
89
|
+
const accounts = getEnabledLarkAccounts(config);
|
|
90
|
+
if (accounts.length === 0)
|
|
91
|
+
return [];
|
|
92
|
+
const toolsCfg = resolveAnyEnabledToolsConfig(accounts);
|
|
93
|
+
const tools = [];
|
|
94
|
+
if (toolsCfg.doc)
|
|
95
|
+
tools.push('feishu_doc');
|
|
96
|
+
if (toolsCfg.scopes)
|
|
97
|
+
tools.push('feishu_app_scopes');
|
|
98
|
+
if (toolsCfg.wiki)
|
|
99
|
+
tools.push('feishu_wiki');
|
|
100
|
+
if (toolsCfg.drive)
|
|
101
|
+
tools.push('feishu_drive');
|
|
102
|
+
if (toolsCfg.perm)
|
|
103
|
+
tools.push('feishu_perm');
|
|
104
|
+
tools.push('feishu_bitable_get_meta', 'feishu_bitable_list_fields', 'feishu_bitable_list_records', 'feishu_bitable_get_record', 'feishu_bitable_create_record', 'feishu_bitable_update_record');
|
|
105
|
+
tools.push('feishu_task');
|
|
106
|
+
tools.push('feishu_calendar');
|
|
107
|
+
return tools;
|
|
108
|
+
}
|
|
109
|
+
async function diagnoseAccount(account) {
|
|
110
|
+
const checks = [];
|
|
111
|
+
const result = {
|
|
112
|
+
accountId: account.accountId,
|
|
113
|
+
name: account.name,
|
|
114
|
+
enabled: account.enabled,
|
|
115
|
+
configured: account.configured,
|
|
116
|
+
appId: account.appId ?? '(未设置)',
|
|
117
|
+
brand: account.brand,
|
|
118
|
+
checks,
|
|
119
|
+
};
|
|
120
|
+
// A1: Credentials
|
|
121
|
+
checks.push({
|
|
122
|
+
name: '凭证完整性',
|
|
123
|
+
status: account.configured ? 'pass' : 'fail',
|
|
124
|
+
message: account.configured
|
|
125
|
+
? `appId: ${account.appId}, appSecret: ${maskSecret(account.appSecret)}`
|
|
126
|
+
: '缺少 appId 或 appSecret',
|
|
127
|
+
});
|
|
128
|
+
// A2: Enabled
|
|
129
|
+
checks.push({
|
|
130
|
+
name: '账户启用',
|
|
131
|
+
status: account.enabled ? 'pass' : 'warn',
|
|
132
|
+
message: account.enabled ? '已启用' : '已禁用',
|
|
133
|
+
});
|
|
134
|
+
if (!account.configured || !account.appId || !account.appSecret) {
|
|
135
|
+
checks.push({
|
|
136
|
+
name: 'API 连通性',
|
|
137
|
+
status: 'skip',
|
|
138
|
+
message: '凭证未配置,跳过',
|
|
139
|
+
});
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
// A3: API connectivity via probe
|
|
143
|
+
try {
|
|
144
|
+
const probeResult = await probeFeishu({
|
|
145
|
+
accountId: account.accountId,
|
|
146
|
+
appId: account.appId,
|
|
147
|
+
appSecret: account.appSecret,
|
|
148
|
+
brand: account.brand,
|
|
149
|
+
});
|
|
150
|
+
checks.push({
|
|
151
|
+
name: 'API 连通性',
|
|
152
|
+
status: probeResult.ok ? 'pass' : 'fail',
|
|
153
|
+
message: probeResult.ok ? `连接成功` : `连接失败: ${probeResult.error}`,
|
|
154
|
+
});
|
|
155
|
+
// A4: Bot info
|
|
156
|
+
if (probeResult.ok) {
|
|
157
|
+
checks.push({
|
|
158
|
+
name: 'Bot 信息',
|
|
159
|
+
status: probeResult.botName ? 'pass' : 'warn',
|
|
160
|
+
message: probeResult.botName ? `${probeResult.botName} (${probeResult.botOpenId})` : '未获取到 Bot 名称',
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
checks.push({
|
|
166
|
+
name: 'API 连通性',
|
|
167
|
+
status: 'fail',
|
|
168
|
+
message: `探测异常: ${err instanceof Error ? err.message : String(err)}`,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
// A5: App scopes
|
|
172
|
+
try {
|
|
173
|
+
const client = LarkClient.fromAccount(account).sdk;
|
|
174
|
+
const scopesResult = await checkAppScopes(client);
|
|
175
|
+
checks.push({
|
|
176
|
+
name: '应用权限',
|
|
177
|
+
status: scopesResult.pending > 0 ? 'warn' : 'pass',
|
|
178
|
+
message: scopesResult.summary,
|
|
179
|
+
details: scopesResult.pending > 0 ? '存在未授权的权限,可能影响部分功能' : undefined,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
checks.push({
|
|
184
|
+
name: '应用权限',
|
|
185
|
+
status: 'warn',
|
|
186
|
+
message: `权限检查失败: ${formatLarkError(err)}`,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
// A6: Brand
|
|
190
|
+
checks.push({
|
|
191
|
+
name: '品牌配置',
|
|
192
|
+
status: 'pass',
|
|
193
|
+
message: `brand: ${account.brand}`,
|
|
194
|
+
});
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
// ---------------------------------------------------------------------------
|
|
198
|
+
// Core
|
|
199
|
+
// ---------------------------------------------------------------------------
|
|
200
|
+
export async function runDiagnosis(params) {
|
|
201
|
+
const { config } = params;
|
|
202
|
+
// Use the global config to enumerate all accounts — the passed-in
|
|
203
|
+
// config may be account-scoped (accounts map stripped).
|
|
204
|
+
const globalCfg = resolveGlobalConfig(config);
|
|
205
|
+
const globalChecks = [];
|
|
206
|
+
// -- Environment --
|
|
207
|
+
const nodeVer = parseInt(process.version.slice(1), 10);
|
|
208
|
+
globalChecks.push({
|
|
209
|
+
name: 'Node.js 版本',
|
|
210
|
+
status: nodeVer >= 18 ? 'pass' : 'warn',
|
|
211
|
+
message: process.version,
|
|
212
|
+
details: nodeVer < 18 ? '建议升级到 Node.js 18+' : undefined,
|
|
213
|
+
});
|
|
214
|
+
// -- Account count --
|
|
215
|
+
const accountIds = getLarkAccountIds(globalCfg);
|
|
216
|
+
globalChecks.push({
|
|
217
|
+
name: '飞书账户数量',
|
|
218
|
+
status: accountIds.length > 0 ? 'pass' : 'fail',
|
|
219
|
+
message: `${accountIds.length} 个账户`,
|
|
220
|
+
});
|
|
221
|
+
// -- Log file --
|
|
222
|
+
const logPath = path.join(os.homedir(), '.openclaw', 'logs', 'gateway.log');
|
|
223
|
+
let logExists = false;
|
|
224
|
+
try {
|
|
225
|
+
await fs.access(logPath);
|
|
226
|
+
logExists = true;
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
// noop
|
|
230
|
+
}
|
|
231
|
+
globalChecks.push({
|
|
232
|
+
name: '日志文件',
|
|
233
|
+
status: logExists ? 'pass' : 'warn',
|
|
234
|
+
message: logExists ? logPath : `未找到: ${logPath}`,
|
|
235
|
+
});
|
|
236
|
+
// -- Per-account diagnosis (sequential to avoid rate limits) --
|
|
237
|
+
const accountResults = [];
|
|
238
|
+
for (const id of accountIds) {
|
|
239
|
+
const account = getLarkAccount(globalCfg, id);
|
|
240
|
+
const result = await diagnoseAccount(account);
|
|
241
|
+
accountResults.push(result);
|
|
242
|
+
}
|
|
243
|
+
// -- Tools --
|
|
244
|
+
const tools = detectRegisteredTools(globalCfg);
|
|
245
|
+
// -- Recent errors --
|
|
246
|
+
const recentErrors = await extractRecentErrors(logPath);
|
|
247
|
+
globalChecks.push({
|
|
248
|
+
name: '最近错误日志',
|
|
249
|
+
status: recentErrors.length > 0 ? 'warn' : 'pass',
|
|
250
|
+
message: recentErrors.length > 0 ? `发现 ${recentErrors.length} 条错误` : '无最近错误',
|
|
251
|
+
});
|
|
252
|
+
// -- Overall status --
|
|
253
|
+
const allChecks = [...globalChecks, ...accountResults.flatMap((a) => a.checks)];
|
|
254
|
+
const hasFail = allChecks.some((c) => c.status === 'fail');
|
|
255
|
+
const hasWarn = allChecks.some((c) => c.status === 'warn');
|
|
256
|
+
return {
|
|
257
|
+
timestamp: new Date().toISOString(),
|
|
258
|
+
environment: {
|
|
259
|
+
nodeVersion: process.version,
|
|
260
|
+
platform: process.platform,
|
|
261
|
+
arch: process.arch,
|
|
262
|
+
pluginVersion: PLUGIN_VERSION,
|
|
263
|
+
},
|
|
264
|
+
accounts: accountResults,
|
|
265
|
+
toolsRegistered: tools,
|
|
266
|
+
recentErrors,
|
|
267
|
+
overallStatus: hasFail ? 'unhealthy' : hasWarn ? 'degraded' : 'healthy',
|
|
268
|
+
checks: globalChecks,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
// ---------------------------------------------------------------------------
|
|
272
|
+
// Formatting — plain text (chat command)
|
|
273
|
+
// ---------------------------------------------------------------------------
|
|
274
|
+
const STATUS_LABEL = {
|
|
275
|
+
pass: '[PASS]',
|
|
276
|
+
warn: '[WARN]',
|
|
277
|
+
fail: '[FAIL]',
|
|
278
|
+
skip: '[SKIP]',
|
|
279
|
+
};
|
|
280
|
+
function formatCheck(c) {
|
|
281
|
+
let line = ` ${STATUS_LABEL[c.status]} ${c.name}: ${c.message}`;
|
|
282
|
+
if (c.details) {
|
|
283
|
+
line += `\n ${c.details}`;
|
|
284
|
+
}
|
|
285
|
+
return line;
|
|
286
|
+
}
|
|
287
|
+
export function formatDiagReportText(report) {
|
|
288
|
+
const lines = [];
|
|
289
|
+
const sep = '====================================';
|
|
290
|
+
lines.push(sep);
|
|
291
|
+
lines.push(' 飞书插件诊断报告');
|
|
292
|
+
lines.push(` ${report.timestamp}`);
|
|
293
|
+
lines.push(sep);
|
|
294
|
+
lines.push('');
|
|
295
|
+
// Environment
|
|
296
|
+
lines.push('【环境信息】');
|
|
297
|
+
lines.push(` Node.js: ${report.environment.nodeVersion}`);
|
|
298
|
+
lines.push(` 插件版本: ${report.environment.pluginVersion}`);
|
|
299
|
+
lines.push(` 系统: ${report.environment.platform} ${report.environment.arch}`);
|
|
300
|
+
lines.push('');
|
|
301
|
+
// Global checks
|
|
302
|
+
lines.push('【全局检查】');
|
|
303
|
+
for (const c of report.checks) {
|
|
304
|
+
lines.push(formatCheck(c));
|
|
305
|
+
}
|
|
306
|
+
lines.push('');
|
|
307
|
+
// Per-account
|
|
308
|
+
for (const acct of report.accounts) {
|
|
309
|
+
lines.push(`【账户: ${acct.accountId}】`);
|
|
310
|
+
if (acct.name)
|
|
311
|
+
lines.push(` 名称: ${acct.name}`);
|
|
312
|
+
lines.push(` App ID: ${acct.appId}`);
|
|
313
|
+
lines.push(` 品牌: ${acct.brand}`);
|
|
314
|
+
lines.push('');
|
|
315
|
+
for (const c of acct.checks) {
|
|
316
|
+
lines.push(formatCheck(c));
|
|
317
|
+
}
|
|
318
|
+
lines.push('');
|
|
319
|
+
}
|
|
320
|
+
// Tools
|
|
321
|
+
lines.push('【工具注册】');
|
|
322
|
+
if (report.toolsRegistered.length > 0) {
|
|
323
|
+
lines.push(` ${report.toolsRegistered.join(', ')}`);
|
|
324
|
+
lines.push(` 共 ${report.toolsRegistered.length} 个`);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
lines.push(' 无工具注册(未找到已配置的账户)');
|
|
328
|
+
}
|
|
329
|
+
lines.push('');
|
|
330
|
+
// Recent errors
|
|
331
|
+
if (report.recentErrors.length > 0) {
|
|
332
|
+
lines.push(`【最近错误】(${report.recentErrors.length} 条)`);
|
|
333
|
+
for (let i = 0; i < report.recentErrors.length; i++) {
|
|
334
|
+
lines.push(` ${i + 1}. ${report.recentErrors[i]}`);
|
|
335
|
+
}
|
|
336
|
+
lines.push('');
|
|
337
|
+
}
|
|
338
|
+
// Overall
|
|
339
|
+
const statusMap = {
|
|
340
|
+
healthy: 'HEALTHY',
|
|
341
|
+
degraded: 'DEGRADED (存在警告)',
|
|
342
|
+
unhealthy: 'UNHEALTHY (存在失败项)',
|
|
343
|
+
};
|
|
344
|
+
lines.push(sep);
|
|
345
|
+
lines.push(` 总体状态: ${statusMap[report.overallStatus]}`);
|
|
346
|
+
lines.push(sep);
|
|
347
|
+
return lines.join('\n');
|
|
348
|
+
}
|
|
349
|
+
// ---------------------------------------------------------------------------
|
|
350
|
+
// Formatting — ANSI colored (CLI)
|
|
351
|
+
// ---------------------------------------------------------------------------
|
|
352
|
+
const ANSI = {
|
|
353
|
+
reset: '\x1b[0m',
|
|
354
|
+
bold: '\x1b[1m',
|
|
355
|
+
green: '\x1b[32m',
|
|
356
|
+
yellow: '\x1b[33m',
|
|
357
|
+
red: '\x1b[31m',
|
|
358
|
+
gray: '\x1b[90m',
|
|
359
|
+
};
|
|
360
|
+
const STATUS_LABEL_CLI = {
|
|
361
|
+
pass: `${ANSI.green}[PASS]${ANSI.reset}`,
|
|
362
|
+
warn: `${ANSI.yellow}[WARN]${ANSI.reset}`,
|
|
363
|
+
fail: `${ANSI.red}[FAIL]${ANSI.reset}`,
|
|
364
|
+
skip: `${ANSI.gray}[SKIP]${ANSI.reset}`,
|
|
365
|
+
};
|
|
366
|
+
function formatCheckCli(c) {
|
|
367
|
+
let line = ` ${STATUS_LABEL_CLI[c.status]} ${c.name}: ${c.message}`;
|
|
368
|
+
if (c.details) {
|
|
369
|
+
line += `\n ${ANSI.gray}${c.details}${ANSI.reset}`;
|
|
370
|
+
}
|
|
371
|
+
return line;
|
|
372
|
+
}
|
|
373
|
+
// ---------------------------------------------------------------------------
|
|
374
|
+
// Trace by message_id
|
|
375
|
+
// ---------------------------------------------------------------------------
|
|
376
|
+
/**
|
|
377
|
+
* Extract all log lines tagged with a specific message_id from gateway.log.
|
|
378
|
+
*
|
|
379
|
+
* Scans the last 1MB of the log file for lines containing `[msg:{messageId}]`.
|
|
380
|
+
* Returns matching lines in chronological order.
|
|
381
|
+
*/
|
|
382
|
+
export async function traceByMessageId(messageId) {
|
|
383
|
+
const logPath = path.join(os.homedir(), '.openclaw', 'logs', 'gateway.log');
|
|
384
|
+
try {
|
|
385
|
+
await fs.access(logPath);
|
|
386
|
+
}
|
|
387
|
+
catch {
|
|
388
|
+
return [];
|
|
389
|
+
}
|
|
390
|
+
const TRACE_READ_BYTES = 1024 * 1024; // 1MB — more than extractRecentErrors
|
|
391
|
+
try {
|
|
392
|
+
const stat = await fs.stat(logPath);
|
|
393
|
+
const readSize = Math.min(stat.size, TRACE_READ_BYTES);
|
|
394
|
+
const fd = await fs.open(logPath, 'r');
|
|
395
|
+
try {
|
|
396
|
+
const buffer = Buffer.alloc(readSize);
|
|
397
|
+
await fd.read(buffer, 0, readSize, Math.max(0, stat.size - readSize));
|
|
398
|
+
const content = buffer.toString('utf-8');
|
|
399
|
+
const needle = `[msg:${messageId}]`;
|
|
400
|
+
return content.split('\n').filter((line) => line.includes(needle));
|
|
401
|
+
}
|
|
402
|
+
finally {
|
|
403
|
+
await fd.close();
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
catch {
|
|
407
|
+
return [];
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Format trace output for CLI display.
|
|
412
|
+
*/
|
|
413
|
+
export function formatTraceOutput(lines, messageId) {
|
|
414
|
+
const sep = '────────────────────────────────';
|
|
415
|
+
if (lines.length === 0) {
|
|
416
|
+
return [
|
|
417
|
+
sep,
|
|
418
|
+
` 未找到 ${messageId} 的追踪日志`,
|
|
419
|
+
'',
|
|
420
|
+
' 可能原因:',
|
|
421
|
+
' 1. 该消息尚未被处理',
|
|
422
|
+
' 2. 日志已被轮转',
|
|
423
|
+
' 3. 追踪功能未启用(需要更新插件版本)',
|
|
424
|
+
sep,
|
|
425
|
+
].join('\n');
|
|
426
|
+
}
|
|
427
|
+
const header = `追踪 ${messageId} 的处理链路 (${lines.length} 条日志):`;
|
|
428
|
+
const output = [header, sep];
|
|
429
|
+
for (const line of lines) {
|
|
430
|
+
output.push(line);
|
|
431
|
+
}
|
|
432
|
+
output.push(sep);
|
|
433
|
+
return output.join('\n');
|
|
434
|
+
}
|
|
435
|
+
function classifyEvent(body) {
|
|
436
|
+
if (body.startsWith('received from'))
|
|
437
|
+
return 'received';
|
|
438
|
+
if (body.startsWith('sender resolved'))
|
|
439
|
+
return 'sender_resolved';
|
|
440
|
+
if (body.startsWith('rejected:'))
|
|
441
|
+
return 'rejected';
|
|
442
|
+
if (body.startsWith('dispatching to agent'))
|
|
443
|
+
return 'dispatching';
|
|
444
|
+
if (body.startsWith('dispatch complete'))
|
|
445
|
+
return 'dispatch_complete';
|
|
446
|
+
if (body.startsWith('card entity created'))
|
|
447
|
+
return 'card_created';
|
|
448
|
+
if (body.startsWith('card message sent'))
|
|
449
|
+
return 'card_sent';
|
|
450
|
+
if (body.startsWith('cardkit cardElement.content:'))
|
|
451
|
+
return 'card_stream';
|
|
452
|
+
if (body.startsWith('card stream update failed'))
|
|
453
|
+
return 'card_stream_fail';
|
|
454
|
+
if (body.startsWith('cardkit card.settings:'))
|
|
455
|
+
return 'card_settings';
|
|
456
|
+
if (body.startsWith('cardkit card.update:'))
|
|
457
|
+
return 'card_update';
|
|
458
|
+
if (body.startsWith('card creation failed'))
|
|
459
|
+
return 'card_fallback';
|
|
460
|
+
if (body.startsWith('reply completed'))
|
|
461
|
+
return 'reply_completed';
|
|
462
|
+
if (body.startsWith('reply error'))
|
|
463
|
+
return 'reply_error';
|
|
464
|
+
if (body.startsWith('tool call:'))
|
|
465
|
+
return 'tool_call';
|
|
466
|
+
if (body.startsWith('tool done:'))
|
|
467
|
+
return 'tool_done';
|
|
468
|
+
if (body.startsWith('tool fail:'))
|
|
469
|
+
return 'tool_fail';
|
|
470
|
+
return 'other';
|
|
471
|
+
}
|
|
472
|
+
const EVENT_LABEL = {
|
|
473
|
+
received: '消息接收',
|
|
474
|
+
sender_resolved: 'Sender 解析',
|
|
475
|
+
rejected: '消息拒绝',
|
|
476
|
+
dispatching: '分发到 Agent',
|
|
477
|
+
dispatch_complete: 'Agent 处理完成',
|
|
478
|
+
card_created: '卡片创建',
|
|
479
|
+
card_sent: '卡片消息发送',
|
|
480
|
+
card_stream: '流式更新',
|
|
481
|
+
card_stream_fail: '流式更新失败',
|
|
482
|
+
card_settings: '卡片设置',
|
|
483
|
+
card_update: '卡片最终更新',
|
|
484
|
+
card_fallback: '卡片降级',
|
|
485
|
+
reply_completed: '回复完成',
|
|
486
|
+
reply_error: '回复错误',
|
|
487
|
+
tool_call: '工具调用',
|
|
488
|
+
tool_done: '工具完成',
|
|
489
|
+
tool_fail: '工具失败',
|
|
490
|
+
};
|
|
491
|
+
/** Expected stages in a normal message processing flow. */
|
|
492
|
+
const EXPECTED_STAGES = [
|
|
493
|
+
{ kind: 'received', label: '消息接收 (received from)' },
|
|
494
|
+
{ kind: 'dispatching', label: '分发到 Agent (dispatching to agent)' },
|
|
495
|
+
{ kind: 'card_created', label: '卡片创建 (card entity created)' },
|
|
496
|
+
{ kind: 'card_sent', label: '卡片消息发送 (card message sent)' },
|
|
497
|
+
{ kind: 'card_stream', label: '流式输出 (cardElement.content)' },
|
|
498
|
+
{ kind: 'dispatch_complete', label: '处理完成 (dispatch complete)' },
|
|
499
|
+
{ kind: 'reply_completed', label: '回复收尾 (reply completed)' },
|
|
500
|
+
];
|
|
501
|
+
/** Time gap thresholds (ms) for performance warnings. */
|
|
502
|
+
const PERF_THRESHOLDS = [
|
|
503
|
+
{ from: 'received', to: 'dispatching', warnMs: 500, label: '消息接收 → 分发' },
|
|
504
|
+
{ from: 'dispatching', to: 'card_created', warnMs: 5000, label: '分发 → 卡片创建' },
|
|
505
|
+
{ from: 'card_created', to: 'card_stream', warnMs: 30000, label: '卡片创建 → 首次流式输出' },
|
|
506
|
+
];
|
|
507
|
+
function parseTraceLines(lines) {
|
|
508
|
+
const events = [];
|
|
509
|
+
// Match: 2026-02-13T12:42:04.682Z [feishu] feishu[...][msg:...]: <body>
|
|
510
|
+
const re = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z)\s.*?\]:\s(.+)$/;
|
|
511
|
+
for (const line of lines) {
|
|
512
|
+
const m = line.match(re);
|
|
513
|
+
if (m) {
|
|
514
|
+
events.push({ timestamp: new Date(m[1]), raw: line, body: m[2] });
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return events;
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Analyze trace log lines and produce a structured CLI report.
|
|
521
|
+
*/
|
|
522
|
+
export function analyzeTrace(lines, _messageId) {
|
|
523
|
+
const events = parseTraceLines(lines);
|
|
524
|
+
if (events.length === 0) {
|
|
525
|
+
return `无法解析日志行,请确认日志格式正确。`;
|
|
526
|
+
}
|
|
527
|
+
const out = [];
|
|
528
|
+
const sep = '────────────────────────────────';
|
|
529
|
+
const startTime = events[0].timestamp.getTime();
|
|
530
|
+
const totalMs = events[events.length - 1].timestamp.getTime() - startTime;
|
|
531
|
+
// ── Section 1: Timeline ──
|
|
532
|
+
out.push('');
|
|
533
|
+
out.push(`${ANSI.bold}【时间线】${ANSI.reset} (${events.length} 条日志,跨度 ${(totalMs / 1000).toFixed(1)}s)`);
|
|
534
|
+
out.push(sep);
|
|
535
|
+
let prevMs = startTime;
|
|
536
|
+
// Collapse consecutive card_stream events
|
|
537
|
+
let streamCount = 0;
|
|
538
|
+
let streamFirstSeq = '';
|
|
539
|
+
let streamLastSeq = '';
|
|
540
|
+
function flushStream() {
|
|
541
|
+
if (streamCount > 0) {
|
|
542
|
+
const label = streamCount === 1
|
|
543
|
+
? ` ${ANSI.gray}...${ANSI.reset} 流式更新 seq=${streamFirstSeq}`
|
|
544
|
+
: ` ${ANSI.gray}...${ANSI.reset} 流式更新 x${streamCount} (seq=${streamFirstSeq}~${streamLastSeq})`;
|
|
545
|
+
out.push(label);
|
|
546
|
+
streamCount = 0;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
for (const ev of events) {
|
|
550
|
+
const kind = classifyEvent(ev.body);
|
|
551
|
+
const deltaMs = ev.timestamp.getTime() - prevMs;
|
|
552
|
+
prevMs = ev.timestamp.getTime();
|
|
553
|
+
const offsetMs = ev.timestamp.getTime() - startTime;
|
|
554
|
+
const offsetStr = `+${offsetMs}ms`.padStart(10);
|
|
555
|
+
// Collapse card_stream
|
|
556
|
+
if (kind === 'card_stream') {
|
|
557
|
+
const seqMatch = ev.body.match(/seq=(\d+)/);
|
|
558
|
+
const seq = seqMatch ? seqMatch[1] : '?';
|
|
559
|
+
if (streamCount === 0)
|
|
560
|
+
streamFirstSeq = seq;
|
|
561
|
+
streamLastSeq = seq;
|
|
562
|
+
streamCount++;
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
flushStream();
|
|
566
|
+
const label = EVENT_LABEL[kind] ?? kind;
|
|
567
|
+
const gapWarn = deltaMs > 5000 ? ` ${ANSI.yellow}⚠ ${(deltaMs / 1000).toFixed(1)}s${ANSI.reset}` : '';
|
|
568
|
+
// Marker for errors
|
|
569
|
+
let marker = ' ';
|
|
570
|
+
if (kind === 'rejected' ||
|
|
571
|
+
kind === 'reply_error' ||
|
|
572
|
+
kind === 'tool_fail' ||
|
|
573
|
+
kind === 'card_stream_fail' ||
|
|
574
|
+
kind === 'card_fallback') {
|
|
575
|
+
marker = `${ANSI.red}✘ ${ANSI.reset}`;
|
|
576
|
+
}
|
|
577
|
+
else if (kind === 'tool_call') {
|
|
578
|
+
marker = '→ ';
|
|
579
|
+
}
|
|
580
|
+
// Extract key detail from body
|
|
581
|
+
let detail = '';
|
|
582
|
+
if (kind === 'received') {
|
|
583
|
+
const m = ev.body.match(/from (\S+) in (\S+) \((\w+)\)/);
|
|
584
|
+
if (m)
|
|
585
|
+
detail = `sender=${m[1]}, chat=${m[2]} (${m[3]})`;
|
|
586
|
+
}
|
|
587
|
+
else if (kind === 'dispatching') {
|
|
588
|
+
const m = ev.body.match(/session=(\S+)\)/);
|
|
589
|
+
if (m)
|
|
590
|
+
detail = `session=${m[1]}`;
|
|
591
|
+
}
|
|
592
|
+
else if (kind === 'dispatch_complete') {
|
|
593
|
+
const m = ev.body.match(/replies=(\d+), elapsed=(\d+)ms/);
|
|
594
|
+
if (m)
|
|
595
|
+
detail = `replies=${m[1]}, elapsed=${m[2]}ms`;
|
|
596
|
+
}
|
|
597
|
+
else if (kind === 'tool_call') {
|
|
598
|
+
const m = ev.body.match(/tool call: (\S+)/);
|
|
599
|
+
if (m)
|
|
600
|
+
detail = m[1];
|
|
601
|
+
}
|
|
602
|
+
else if (kind === 'tool_fail') {
|
|
603
|
+
detail = ev.body.replace('tool fail: ', '');
|
|
604
|
+
}
|
|
605
|
+
else if (kind === 'card_created') {
|
|
606
|
+
const m = ev.body.match(/card_id=(\S+)\)/);
|
|
607
|
+
if (m)
|
|
608
|
+
detail = `card_id=${m[1]}`;
|
|
609
|
+
}
|
|
610
|
+
else if (kind === 'reply_completed') {
|
|
611
|
+
const m = ev.body.match(/elapsed=(\d+)ms/);
|
|
612
|
+
if (m)
|
|
613
|
+
detail = `elapsed=${m[1]}ms`;
|
|
614
|
+
}
|
|
615
|
+
else if (kind === 'rejected') {
|
|
616
|
+
detail = ev.body.replace('rejected: ', '');
|
|
617
|
+
}
|
|
618
|
+
out.push(`${ANSI.gray}[${offsetStr}]${ANSI.reset} ${marker}${label}${detail ? ` — ${detail}` : ''}${gapWarn}`);
|
|
619
|
+
}
|
|
620
|
+
flushStream();
|
|
621
|
+
out.push('');
|
|
622
|
+
// ── Section 2: Anomaly detection ──
|
|
623
|
+
const issues = [];
|
|
624
|
+
const kindSet = new Set(events.map((e) => classifyEvent(e.body)));
|
|
625
|
+
// 2.1 Missing stages
|
|
626
|
+
for (const stage of EXPECTED_STAGES) {
|
|
627
|
+
if (!kindSet.has(stage.kind)) {
|
|
628
|
+
// dispatch_complete 和 reply_completed 缺失仅在有 dispatching 时才告警
|
|
629
|
+
if ((stage.kind === 'dispatch_complete' || stage.kind === 'reply_completed') && !kindSet.has('dispatching'))
|
|
630
|
+
continue;
|
|
631
|
+
// card 相关阶段在有 rejected 时不告警
|
|
632
|
+
if ((stage.kind === 'card_created' || stage.kind === 'card_sent' || stage.kind === 'card_stream') &&
|
|
633
|
+
kindSet.has('rejected'))
|
|
634
|
+
continue;
|
|
635
|
+
issues.push(`缺失阶段: ${stage.label}`);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
// 2.2 Errors
|
|
639
|
+
for (const ev of events) {
|
|
640
|
+
const kind = classifyEvent(ev.body);
|
|
641
|
+
if (kind === 'rejected')
|
|
642
|
+
issues.push(`消息被拒绝: ${ev.body.replace('rejected: ', '')}`);
|
|
643
|
+
if (kind === 'reply_error')
|
|
644
|
+
issues.push(`回复错误: ${ev.body}`);
|
|
645
|
+
if (kind === 'tool_fail')
|
|
646
|
+
issues.push(`工具失败: ${ev.body}`);
|
|
647
|
+
if (kind === 'card_stream_fail')
|
|
648
|
+
issues.push(`流式更新失败: ${ev.body}`);
|
|
649
|
+
if (kind === 'card_fallback')
|
|
650
|
+
issues.push(`卡片降级: ${ev.body}`);
|
|
651
|
+
// CardKit non-zero code
|
|
652
|
+
if (kind === 'card_stream' || kind === 'card_update' || kind === 'card_settings' || kind === 'card_created') {
|
|
653
|
+
const codeMatch = ev.body.match(/code=(\d+)/);
|
|
654
|
+
if (codeMatch && codeMatch[1] !== '0') {
|
|
655
|
+
issues.push(`API 返回错误码: code=${codeMatch[1]} — ${ev.body}`);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
// 2.3 Performance thresholds
|
|
660
|
+
const firstByKind = new Map();
|
|
661
|
+
for (const ev of events) {
|
|
662
|
+
const kind = classifyEvent(ev.body);
|
|
663
|
+
if (!firstByKind.has(kind))
|
|
664
|
+
firstByKind.set(kind, ev);
|
|
665
|
+
}
|
|
666
|
+
for (const rule of PERF_THRESHOLDS) {
|
|
667
|
+
const from = firstByKind.get(rule.from);
|
|
668
|
+
const to = firstByKind.get(rule.to);
|
|
669
|
+
if (from && to) {
|
|
670
|
+
const gap = to.timestamp.getTime() - from.timestamp.getTime();
|
|
671
|
+
if (gap > rule.warnMs) {
|
|
672
|
+
issues.push(`性能警告: ${rule.label} 耗时 ${(gap / 1000).toFixed(1)}s(阈值 ${(rule.warnMs / 1000).toFixed(0)}s)`);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
// 2.4 Duplicate delivery
|
|
677
|
+
const receivedCount = events.filter((e) => classifyEvent(e.body) === 'received').length;
|
|
678
|
+
if (receivedCount > 1) {
|
|
679
|
+
issues.push(`重复投递: 同一消息被接收 ${receivedCount} 次(WebSocket 重投递)`);
|
|
680
|
+
}
|
|
681
|
+
// 2.5 Card stream continuity
|
|
682
|
+
const streamSeqs = [];
|
|
683
|
+
for (const ev of events) {
|
|
684
|
+
if (classifyEvent(ev.body) === 'card_stream') {
|
|
685
|
+
const m = ev.body.match(/seq=(\d+)/);
|
|
686
|
+
if (m)
|
|
687
|
+
streamSeqs.push(parseInt(m[1], 10));
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
if (streamSeqs.length > 1) {
|
|
691
|
+
for (let i = 1; i < streamSeqs.length; i++) {
|
|
692
|
+
if (streamSeqs[i] !== streamSeqs[i - 1] + 1) {
|
|
693
|
+
issues.push(`流式 seq 不连续: seq=${streamSeqs[i - 1]} → seq=${streamSeqs[i]}(跳过了 ${streamSeqs[i] - streamSeqs[i - 1] - 1} 个)`);
|
|
694
|
+
break;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
out.push(`${ANSI.bold}【异常检测】${ANSI.reset}`);
|
|
699
|
+
out.push(sep);
|
|
700
|
+
if (issues.length === 0) {
|
|
701
|
+
out.push(` ${ANSI.green}未发现异常${ANSI.reset}`);
|
|
702
|
+
}
|
|
703
|
+
else {
|
|
704
|
+
for (let i = 0; i < issues.length; i++) {
|
|
705
|
+
const isError = issues[i].startsWith('工具失败') ||
|
|
706
|
+
issues[i].startsWith('回复错误') ||
|
|
707
|
+
issues[i].startsWith('API 返回错误码') ||
|
|
708
|
+
issues[i].startsWith('流式更新失败');
|
|
709
|
+
const color = isError ? ANSI.red : ANSI.yellow;
|
|
710
|
+
out.push(` ${color}${i + 1}. ${issues[i]}${ANSI.reset}`);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
out.push('');
|
|
714
|
+
// ── Section 3: Diagnosis ──
|
|
715
|
+
out.push(`${ANSI.bold}【诊断总结】${ANSI.reset}`);
|
|
716
|
+
out.push(sep);
|
|
717
|
+
const hasError = issues.some((i) => i.startsWith('工具失败') ||
|
|
718
|
+
i.startsWith('回复错误') ||
|
|
719
|
+
i.startsWith('API 返回错误码') ||
|
|
720
|
+
i.startsWith('流式更新失败') ||
|
|
721
|
+
i.startsWith('缺失阶段'));
|
|
722
|
+
const hasWarn = issues.length > 0;
|
|
723
|
+
if (!hasWarn) {
|
|
724
|
+
out.push(` 状态: ${ANSI.green}✓ 正常${ANSI.reset}`);
|
|
725
|
+
out.push(` 消息处理链路完整,全程耗时 ${(totalMs / 1000).toFixed(1)}s。`);
|
|
726
|
+
// Break down time
|
|
727
|
+
const dispatchComplete = events.find((e) => classifyEvent(e.body) === 'dispatch_complete' && e.body.includes('replies=') && !e.body.includes('replies=0'));
|
|
728
|
+
if (dispatchComplete) {
|
|
729
|
+
const m = dispatchComplete.body.match(/elapsed=(\d+)ms/);
|
|
730
|
+
if (m) {
|
|
731
|
+
out.push(` 其中 Agent 处理耗时 ${(parseInt(m[1], 10) / 1000).toFixed(1)}s(含 AI 推理 + 工具调用)。`);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
else if (hasError) {
|
|
736
|
+
out.push(` 状态: ${ANSI.red}✘ 异常${ANSI.reset}`);
|
|
737
|
+
out.push(` 发现 ${issues.length} 个问题,需要排查。`);
|
|
738
|
+
}
|
|
739
|
+
else {
|
|
740
|
+
out.push(` 状态: ${ANSI.yellow}⚠ 有警告${ANSI.reset}`);
|
|
741
|
+
out.push(` 发现 ${issues.length} 个警告,功能可用但需关注。`);
|
|
742
|
+
}
|
|
743
|
+
out.push('');
|
|
744
|
+
return out.join('\n');
|
|
745
|
+
}
|
|
746
|
+
export function formatDiagReportCli(report) {
|
|
747
|
+
const lines = [];
|
|
748
|
+
const sep = '====================================';
|
|
749
|
+
lines.push(sep);
|
|
750
|
+
lines.push(` ${ANSI.bold}飞书插件诊断报告${ANSI.reset}`);
|
|
751
|
+
lines.push(` ${report.timestamp}`);
|
|
752
|
+
lines.push(sep);
|
|
753
|
+
lines.push('');
|
|
754
|
+
// Environment
|
|
755
|
+
lines.push(`${ANSI.bold}【环境信息】${ANSI.reset}`);
|
|
756
|
+
lines.push(` Node.js: ${report.environment.nodeVersion}`);
|
|
757
|
+
lines.push(` 插件版本: ${report.environment.pluginVersion}`);
|
|
758
|
+
lines.push(` 系统: ${report.environment.platform} ${report.environment.arch}`);
|
|
759
|
+
lines.push('');
|
|
760
|
+
// Global checks
|
|
761
|
+
lines.push(`${ANSI.bold}【全局检查】${ANSI.reset}`);
|
|
762
|
+
for (const c of report.checks) {
|
|
763
|
+
lines.push(formatCheckCli(c));
|
|
764
|
+
}
|
|
765
|
+
lines.push('');
|
|
766
|
+
// Per-account
|
|
767
|
+
for (const acct of report.accounts) {
|
|
768
|
+
lines.push(`${ANSI.bold}【账户: ${acct.accountId}】${ANSI.reset}`);
|
|
769
|
+
if (acct.name)
|
|
770
|
+
lines.push(` 名称: ${acct.name}`);
|
|
771
|
+
lines.push(` App ID: ${acct.appId}`);
|
|
772
|
+
lines.push(` 品牌: ${acct.brand}`);
|
|
773
|
+
lines.push('');
|
|
774
|
+
for (const c of acct.checks) {
|
|
775
|
+
lines.push(formatCheckCli(c));
|
|
776
|
+
}
|
|
777
|
+
lines.push('');
|
|
778
|
+
}
|
|
779
|
+
// Tools
|
|
780
|
+
lines.push(`${ANSI.bold}【工具注册】${ANSI.reset}`);
|
|
781
|
+
if (report.toolsRegistered.length > 0) {
|
|
782
|
+
lines.push(` ${report.toolsRegistered.join(', ')}`);
|
|
783
|
+
lines.push(` 共 ${report.toolsRegistered.length} 个`);
|
|
784
|
+
}
|
|
785
|
+
else {
|
|
786
|
+
lines.push(' 无工具注册(未找到已配置的账户)');
|
|
787
|
+
}
|
|
788
|
+
lines.push('');
|
|
789
|
+
// Recent errors
|
|
790
|
+
if (report.recentErrors.length > 0) {
|
|
791
|
+
lines.push(`${ANSI.bold}【最近错误】${ANSI.reset}(${report.recentErrors.length} 条)`);
|
|
792
|
+
for (let i = 0; i < report.recentErrors.length; i++) {
|
|
793
|
+
lines.push(` ${ANSI.gray}${i + 1}. ${report.recentErrors[i]}${ANSI.reset}`);
|
|
794
|
+
}
|
|
795
|
+
lines.push('');
|
|
796
|
+
}
|
|
797
|
+
// Overall
|
|
798
|
+
const statusColorMap = {
|
|
799
|
+
healthy: `${ANSI.green}HEALTHY${ANSI.reset}`,
|
|
800
|
+
degraded: `${ANSI.yellow}DEGRADED (存在警告)${ANSI.reset}`,
|
|
801
|
+
unhealthy: `${ANSI.red}UNHEALTHY (存在失败项)${ANSI.reset}`,
|
|
802
|
+
};
|
|
803
|
+
lines.push(sep);
|
|
804
|
+
lines.push(` 总体状态: ${statusColorMap[report.overallStatus]}`);
|
|
805
|
+
lines.push(sep);
|
|
806
|
+
return lines.join('\n');
|
|
807
|
+
}
|
|
808
|
+
//# sourceMappingURL=diagnose.js.map
|