@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,717 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* Streaming card controller for the Feishu/Lark channel plugin.
|
|
6
|
+
*
|
|
7
|
+
* Manages the full lifecycle of a streaming CardKit card:
|
|
8
|
+
* idle → creating → streaming → completed / aborted / terminated.
|
|
9
|
+
*
|
|
10
|
+
* Delegates throttling to FlushController and message-unavailable
|
|
11
|
+
* detection to UnavailableGuard.
|
|
12
|
+
*/
|
|
13
|
+
import { SILENT_REPLY_TOKEN } from 'openclaw/plugin-sdk';
|
|
14
|
+
import { extractLarkApiCode } from '../core/api-error';
|
|
15
|
+
import { larkLogger } from '../core/lark-logger';
|
|
16
|
+
import { sendCardFeishu, updateCardFeishu } from '../messaging/outbound/send';
|
|
17
|
+
import { createCardEntity, sendCardByCardId, streamCardContent, updateCardKitCard, setCardStreamingMode, } from './cardkit';
|
|
18
|
+
import { buildCardContent, splitReasoningText, stripReasoningTags, STREAMING_ELEMENT_ID, toCardKit2 } from './builder';
|
|
19
|
+
import { optimizeMarkdownStyle } from './markdown-style';
|
|
20
|
+
import { registerShutdownHook } from '../core/shutdown-hooks';
|
|
21
|
+
import { FlushController } from './flush-controller';
|
|
22
|
+
import { UnavailableGuard } from './unavailable-guard';
|
|
23
|
+
import { TERMINAL_PHASES, PHASE_TRANSITIONS, THROTTLE_CONSTANTS, EMPTY_REPLY_FALLBACK_TEXT, } from './reply-dispatcher-types';
|
|
24
|
+
const log = larkLogger('card/streaming');
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// CardKit 2.0 initial streaming payload
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
const STREAMING_THINKING_CARD = {
|
|
29
|
+
schema: '2.0',
|
|
30
|
+
config: {
|
|
31
|
+
streaming_mode: true,
|
|
32
|
+
summary: { content: '思考中...' },
|
|
33
|
+
},
|
|
34
|
+
body: {
|
|
35
|
+
elements: [
|
|
36
|
+
{
|
|
37
|
+
tag: 'markdown',
|
|
38
|
+
content: '',
|
|
39
|
+
text_align: 'left',
|
|
40
|
+
text_size: 'normal_v2',
|
|
41
|
+
margin: '0px 0px 0px 0px',
|
|
42
|
+
element_id: STREAMING_ELEMENT_ID,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
tag: 'markdown',
|
|
46
|
+
content: ' ',
|
|
47
|
+
icon: {
|
|
48
|
+
tag: 'custom_icon',
|
|
49
|
+
img_key: 'img_v3_02vb_496bec09-4b43-4773-ad6b-0cdd103cd2bg',
|
|
50
|
+
size: '16px 16px',
|
|
51
|
+
},
|
|
52
|
+
element_id: 'loading_icon',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// StreamingCardController
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
export class StreamingCardController {
|
|
61
|
+
// ---- Explicit state machine ----
|
|
62
|
+
phase = 'idle';
|
|
63
|
+
// ---- Structured state ----
|
|
64
|
+
cardKit = {
|
|
65
|
+
cardKitCardId: null,
|
|
66
|
+
originalCardKitCardId: null,
|
|
67
|
+
cardKitSequence: 0,
|
|
68
|
+
cardMessageId: null,
|
|
69
|
+
};
|
|
70
|
+
text = {
|
|
71
|
+
accumulatedText: '',
|
|
72
|
+
completedText: '',
|
|
73
|
+
streamingPrefix: '',
|
|
74
|
+
lastPartialText: '',
|
|
75
|
+
};
|
|
76
|
+
reasoning = {
|
|
77
|
+
accumulatedReasoningText: '',
|
|
78
|
+
reasoningStartTime: null,
|
|
79
|
+
reasoningElapsedMs: 0,
|
|
80
|
+
isReasoningPhase: false,
|
|
81
|
+
};
|
|
82
|
+
// ---- Sub-controllers ----
|
|
83
|
+
flush;
|
|
84
|
+
guard;
|
|
85
|
+
// ---- Lifecycle ----
|
|
86
|
+
createEpoch = 0;
|
|
87
|
+
_terminalReason = null;
|
|
88
|
+
dispatchFullyComplete = false;
|
|
89
|
+
cardCreationPromise = null;
|
|
90
|
+
disposeShutdownHook = null;
|
|
91
|
+
dispatchStartTime = Date.now();
|
|
92
|
+
// ---- Injected dependencies ----
|
|
93
|
+
deps;
|
|
94
|
+
elapsed() {
|
|
95
|
+
return Date.now() - this.dispatchStartTime;
|
|
96
|
+
}
|
|
97
|
+
constructor(deps) {
|
|
98
|
+
this.deps = deps;
|
|
99
|
+
this.guard = new UnavailableGuard({
|
|
100
|
+
replyToMessageId: deps.replyToMessageId,
|
|
101
|
+
getCardMessageId: () => this.cardKit.cardMessageId,
|
|
102
|
+
onTerminate: () => {
|
|
103
|
+
this.transition('terminated', 'UnavailableGuard', 'unavailable');
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
this.flush = new FlushController(() => this.performFlush());
|
|
107
|
+
}
|
|
108
|
+
// ------------------------------------------------------------------
|
|
109
|
+
// Public accessors
|
|
110
|
+
// ------------------------------------------------------------------
|
|
111
|
+
get cardMessageId() {
|
|
112
|
+
return this.cardKit.cardMessageId;
|
|
113
|
+
}
|
|
114
|
+
get isTerminalPhase() {
|
|
115
|
+
return TERMINAL_PHASES.has(this.phase);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Whether the card has been explicitly aborted (via abortCard()).
|
|
119
|
+
*
|
|
120
|
+
* Distinct from isTerminalPhase — creation_failed is NOT an abort;
|
|
121
|
+
* it should allow fallthrough to static delivery in the factory.
|
|
122
|
+
*/
|
|
123
|
+
get isAborted() {
|
|
124
|
+
return this.phase === 'aborted';
|
|
125
|
+
}
|
|
126
|
+
/** Whether the reply pipeline was terminated due to an unavailable message. */
|
|
127
|
+
get isTerminated() {
|
|
128
|
+
return this.guard.isTerminated;
|
|
129
|
+
}
|
|
130
|
+
/** Check if the pipeline should skip further operations for this source. */
|
|
131
|
+
shouldSkipForUnavailable(source) {
|
|
132
|
+
return this.guard.shouldSkip(source);
|
|
133
|
+
}
|
|
134
|
+
/** Attempt to terminate the pipeline due to an unavailable message error. */
|
|
135
|
+
terminateIfUnavailable(source, err) {
|
|
136
|
+
return this.guard.terminate(source, err);
|
|
137
|
+
}
|
|
138
|
+
/** Why the controller entered a terminal phase, or null if still active. */
|
|
139
|
+
get terminalReason() {
|
|
140
|
+
return this._terminalReason;
|
|
141
|
+
}
|
|
142
|
+
/** @internal — exposed for test assertions only. */
|
|
143
|
+
get currentPhase() {
|
|
144
|
+
return this.phase;
|
|
145
|
+
}
|
|
146
|
+
// ------------------------------------------------------------------
|
|
147
|
+
// Unified callback guard
|
|
148
|
+
// ------------------------------------------------------------------
|
|
149
|
+
/**
|
|
150
|
+
* Unified callback guard — returns true if the pipeline is active
|
|
151
|
+
* and the callback should proceed.
|
|
152
|
+
*
|
|
153
|
+
* Combines three checks:
|
|
154
|
+
* 1. guard.isTerminated — message recalled/deleted
|
|
155
|
+
* 2. guard.shouldSkip(source) — eagerly detect unavailable messages
|
|
156
|
+
* 3. isTerminalPhase — completed/aborted/terminated/creation_failed
|
|
157
|
+
*/
|
|
158
|
+
shouldProceed(source) {
|
|
159
|
+
if (this.guard.isTerminated || this.guard.shouldSkip(source))
|
|
160
|
+
return false;
|
|
161
|
+
return !this.isTerminalPhase;
|
|
162
|
+
}
|
|
163
|
+
// ------------------------------------------------------------------
|
|
164
|
+
// State machine
|
|
165
|
+
// ------------------------------------------------------------------
|
|
166
|
+
isStaleCreate(epoch) {
|
|
167
|
+
return epoch !== this.createEpoch;
|
|
168
|
+
}
|
|
169
|
+
transition(to, source, reason) {
|
|
170
|
+
const from = this.phase;
|
|
171
|
+
if (from === to)
|
|
172
|
+
return false;
|
|
173
|
+
if (!PHASE_TRANSITIONS[from].has(to)) {
|
|
174
|
+
log.warn('phase transition rejected', { from, to, source });
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
this.phase = to;
|
|
178
|
+
log.info('phase transition', { from, to, source, reason });
|
|
179
|
+
if (TERMINAL_PHASES.has(to)) {
|
|
180
|
+
this._terminalReason = reason ?? null;
|
|
181
|
+
this.onEnterTerminalPhase();
|
|
182
|
+
}
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
onEnterTerminalPhase() {
|
|
186
|
+
this.createEpoch += 1;
|
|
187
|
+
this.flush.cancelPendingFlush();
|
|
188
|
+
this.flush.complete();
|
|
189
|
+
this.disposeShutdownHook?.();
|
|
190
|
+
this.disposeShutdownHook = null;
|
|
191
|
+
}
|
|
192
|
+
// ------------------------------------------------------------------
|
|
193
|
+
// SDK callback bindings
|
|
194
|
+
// ------------------------------------------------------------------
|
|
195
|
+
/**
|
|
196
|
+
* Handle a deliver() call in streaming card mode.
|
|
197
|
+
*
|
|
198
|
+
* Accumulates text from the SDK's deliver callbacks to build the
|
|
199
|
+
* authoritative "completedText" for the final card.
|
|
200
|
+
*/
|
|
201
|
+
async onDeliver(payload) {
|
|
202
|
+
if (!this.shouldProceed('onDeliver'))
|
|
203
|
+
return;
|
|
204
|
+
const text = payload.text ?? '';
|
|
205
|
+
if (!text.trim())
|
|
206
|
+
return;
|
|
207
|
+
await this.ensureCardCreated();
|
|
208
|
+
if (!this.shouldProceed('onDeliver.postCreate'))
|
|
209
|
+
return;
|
|
210
|
+
if (!this.cardKit.cardMessageId)
|
|
211
|
+
return;
|
|
212
|
+
const split = splitReasoningText(text);
|
|
213
|
+
if (split.reasoningText && !split.answerText) {
|
|
214
|
+
// Pure reasoning payload
|
|
215
|
+
this.reasoning.reasoningElapsedMs = this.reasoning.reasoningStartTime
|
|
216
|
+
? Date.now() - this.reasoning.reasoningStartTime
|
|
217
|
+
: 0;
|
|
218
|
+
this.reasoning.accumulatedReasoningText = split.reasoningText;
|
|
219
|
+
this.reasoning.isReasoningPhase = true;
|
|
220
|
+
await this.throttledCardUpdate();
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
// Answer payload (may also contain inline reasoning from tags)
|
|
224
|
+
this.reasoning.isReasoningPhase = false;
|
|
225
|
+
if (split.reasoningText) {
|
|
226
|
+
this.reasoning.accumulatedReasoningText = split.reasoningText;
|
|
227
|
+
}
|
|
228
|
+
const answerText = split.answerText ?? text;
|
|
229
|
+
// 累积 deliver 文本用于最终卡片
|
|
230
|
+
this.text.completedText += (this.text.completedText ? '\n\n' : '') + answerText;
|
|
231
|
+
// 没有流式数据时,用 deliver 文本显示在卡片上
|
|
232
|
+
if (!this.text.lastPartialText && !this.text.streamingPrefix) {
|
|
233
|
+
this.text.accumulatedText += (this.text.accumulatedText ? '\n\n' : '') + answerText;
|
|
234
|
+
this.text.streamingPrefix = this.text.accumulatedText;
|
|
235
|
+
await this.throttledCardUpdate();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async onReasoningStream(payload) {
|
|
239
|
+
if (!this.shouldProceed('onReasoningStream'))
|
|
240
|
+
return;
|
|
241
|
+
await this.ensureCardCreated();
|
|
242
|
+
if (!this.shouldProceed('onReasoningStream.postCreate'))
|
|
243
|
+
return;
|
|
244
|
+
if (!this.cardKit.cardMessageId)
|
|
245
|
+
return;
|
|
246
|
+
const rawText = payload.text ?? '';
|
|
247
|
+
if (!rawText)
|
|
248
|
+
return;
|
|
249
|
+
if (!this.reasoning.reasoningStartTime) {
|
|
250
|
+
this.reasoning.reasoningStartTime = Date.now();
|
|
251
|
+
}
|
|
252
|
+
this.reasoning.isReasoningPhase = true;
|
|
253
|
+
const split = splitReasoningText(rawText);
|
|
254
|
+
this.reasoning.accumulatedReasoningText = split.reasoningText ?? rawText;
|
|
255
|
+
await this.throttledCardUpdate();
|
|
256
|
+
}
|
|
257
|
+
async onPartialReply(payload) {
|
|
258
|
+
if (!this.shouldProceed('onPartialReply'))
|
|
259
|
+
return;
|
|
260
|
+
const text = stripReasoningTags(payload.text ?? '');
|
|
261
|
+
log.debug('onPartialReply', { len: text.length });
|
|
262
|
+
if (!text)
|
|
263
|
+
return;
|
|
264
|
+
if (!this.reasoning.reasoningStartTime) {
|
|
265
|
+
this.reasoning.reasoningStartTime = Date.now();
|
|
266
|
+
}
|
|
267
|
+
if (this.reasoning.isReasoningPhase) {
|
|
268
|
+
this.reasoning.isReasoningPhase = false;
|
|
269
|
+
this.reasoning.reasoningElapsedMs = this.reasoning.reasoningStartTime
|
|
270
|
+
? Date.now() - this.reasoning.reasoningStartTime
|
|
271
|
+
: 0;
|
|
272
|
+
}
|
|
273
|
+
// 检测回复边界:文本长度缩短 → 新回复开始
|
|
274
|
+
if (this.text.lastPartialText && text.length < this.text.lastPartialText.length) {
|
|
275
|
+
this.text.streamingPrefix += (this.text.streamingPrefix ? '\n\n' : '') + this.text.lastPartialText;
|
|
276
|
+
}
|
|
277
|
+
this.text.lastPartialText = text;
|
|
278
|
+
this.text.accumulatedText = this.text.streamingPrefix ? this.text.streamingPrefix + '\n\n' + text : text;
|
|
279
|
+
// NO_REPLY 缓冲
|
|
280
|
+
if (!this.text.streamingPrefix && SILENT_REPLY_TOKEN.startsWith(this.text.accumulatedText.trim())) {
|
|
281
|
+
log.debug('onPartialReply: buffering NO_REPLY prefix');
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
await this.ensureCardCreated();
|
|
285
|
+
if (!this.shouldProceed('onPartialReply.postCreate'))
|
|
286
|
+
return;
|
|
287
|
+
if (!this.cardKit.cardMessageId)
|
|
288
|
+
return;
|
|
289
|
+
await this.throttledCardUpdate();
|
|
290
|
+
}
|
|
291
|
+
async onError(err, info) {
|
|
292
|
+
if (this.guard.terminate('onError', err))
|
|
293
|
+
return;
|
|
294
|
+
log.error(`${info.kind} reply failed`, { error: String(err) });
|
|
295
|
+
this.finalizeCard('onError', 'error');
|
|
296
|
+
await this.flush.waitForFlush();
|
|
297
|
+
if (this.cardCreationPromise)
|
|
298
|
+
await this.cardCreationPromise;
|
|
299
|
+
const errorEffectiveCardId = this.cardKit.cardKitCardId ?? this.cardKit.originalCardKitCardId;
|
|
300
|
+
if (this.cardKit.cardMessageId) {
|
|
301
|
+
try {
|
|
302
|
+
const errorText = this.text.accumulatedText
|
|
303
|
+
? `${this.text.accumulatedText}\n\n---\n**Error**: An error occurred while generating the response.`
|
|
304
|
+
: '**Error**: An error occurred while generating the response.';
|
|
305
|
+
const errorCard = buildCardContent('complete', {
|
|
306
|
+
text: errorText,
|
|
307
|
+
reasoningText: this.reasoning.accumulatedReasoningText || undefined,
|
|
308
|
+
reasoningElapsedMs: this.reasoning.reasoningElapsedMs || undefined,
|
|
309
|
+
elapsedMs: this.elapsed(),
|
|
310
|
+
isError: true,
|
|
311
|
+
footer: this.deps.resolvedFooter,
|
|
312
|
+
});
|
|
313
|
+
if (errorEffectiveCardId) {
|
|
314
|
+
await this.closeStreamingAndUpdate(errorEffectiveCardId, errorCard, 'onError');
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
await updateCardFeishu({
|
|
318
|
+
cfg: this.deps.cfg,
|
|
319
|
+
messageId: this.cardKit.cardMessageId,
|
|
320
|
+
card: errorCard,
|
|
321
|
+
accountId: this.deps.accountId,
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
catch {
|
|
326
|
+
// Ignore update failures during error handling
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
async onIdle() {
|
|
331
|
+
if (this.guard.isTerminated || this.guard.shouldSkip('onIdle'))
|
|
332
|
+
return;
|
|
333
|
+
if (!this.dispatchFullyComplete)
|
|
334
|
+
return;
|
|
335
|
+
if (this.isTerminalPhase)
|
|
336
|
+
return;
|
|
337
|
+
this.finalizeCard('onIdle', 'normal');
|
|
338
|
+
await this.flush.waitForFlush();
|
|
339
|
+
if (this.cardCreationPromise) {
|
|
340
|
+
await this.cardCreationPromise;
|
|
341
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
342
|
+
await this.flush.waitForFlush();
|
|
343
|
+
}
|
|
344
|
+
const idleEffectiveCardId = this.cardKit.cardKitCardId ?? this.cardKit.originalCardKitCardId;
|
|
345
|
+
if (this.cardKit.cardMessageId) {
|
|
346
|
+
try {
|
|
347
|
+
if (idleEffectiveCardId) {
|
|
348
|
+
const seqBeforeClose = this.cardKit.cardKitSequence;
|
|
349
|
+
this.cardKit.cardKitSequence += 1;
|
|
350
|
+
log.info('onIdle: closing streaming mode', {
|
|
351
|
+
seqBefore: seqBeforeClose,
|
|
352
|
+
seqAfter: this.cardKit.cardKitSequence,
|
|
353
|
+
});
|
|
354
|
+
await setCardStreamingMode({
|
|
355
|
+
cfg: this.deps.cfg,
|
|
356
|
+
cardId: idleEffectiveCardId,
|
|
357
|
+
streamingMode: false,
|
|
358
|
+
sequence: this.cardKit.cardKitSequence,
|
|
359
|
+
accountId: this.deps.accountId,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
const isNoReplyLeak = !this.text.completedText && SILENT_REPLY_TOKEN.startsWith(this.text.accumulatedText.trim());
|
|
363
|
+
const displayText = this.text.completedText || (isNoReplyLeak ? '' : this.text.accumulatedText) || EMPTY_REPLY_FALLBACK_TEXT;
|
|
364
|
+
if (!this.text.completedText && !this.text.accumulatedText) {
|
|
365
|
+
log.warn('reply completed without visible text, using empty-reply fallback');
|
|
366
|
+
}
|
|
367
|
+
const completeCard = buildCardContent('complete', {
|
|
368
|
+
text: displayText,
|
|
369
|
+
reasoningText: this.reasoning.accumulatedReasoningText || undefined,
|
|
370
|
+
reasoningElapsedMs: this.reasoning.reasoningElapsedMs || undefined,
|
|
371
|
+
elapsedMs: this.elapsed(),
|
|
372
|
+
footer: this.deps.resolvedFooter,
|
|
373
|
+
});
|
|
374
|
+
if (idleEffectiveCardId) {
|
|
375
|
+
const seqBeforeUpdate = this.cardKit.cardKitSequence;
|
|
376
|
+
this.cardKit.cardKitSequence += 1;
|
|
377
|
+
log.info('onIdle: updating final card', {
|
|
378
|
+
seqBefore: seqBeforeUpdate,
|
|
379
|
+
seqAfter: this.cardKit.cardKitSequence,
|
|
380
|
+
});
|
|
381
|
+
await updateCardKitCard({
|
|
382
|
+
cfg: this.deps.cfg,
|
|
383
|
+
cardId: idleEffectiveCardId,
|
|
384
|
+
card: toCardKit2(completeCard),
|
|
385
|
+
sequence: this.cardKit.cardKitSequence,
|
|
386
|
+
accountId: this.deps.accountId,
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
await updateCardFeishu({
|
|
391
|
+
cfg: this.deps.cfg,
|
|
392
|
+
messageId: this.cardKit.cardMessageId,
|
|
393
|
+
card: completeCard,
|
|
394
|
+
accountId: this.deps.accountId,
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
log.info('reply completed, card finalized', {
|
|
398
|
+
elapsedMs: this.elapsed(),
|
|
399
|
+
isCardKit: !!idleEffectiveCardId,
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
catch (err) {
|
|
403
|
+
log.warn('final card update failed', { error: String(err) });
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
// ------------------------------------------------------------------
|
|
408
|
+
// External control
|
|
409
|
+
// ------------------------------------------------------------------
|
|
410
|
+
markFullyComplete() {
|
|
411
|
+
log.debug('markFullyComplete', {
|
|
412
|
+
completedTextLen: this.text.completedText.length,
|
|
413
|
+
accumulatedTextLen: this.text.accumulatedText.length,
|
|
414
|
+
});
|
|
415
|
+
this.dispatchFullyComplete = true;
|
|
416
|
+
}
|
|
417
|
+
async abortCard() {
|
|
418
|
+
try {
|
|
419
|
+
if (!this.transition('aborted', 'abortCard', 'abort'))
|
|
420
|
+
return;
|
|
421
|
+
// transition() already executed onEnterTerminalPhase (cancel + complete + dispose hook)
|
|
422
|
+
// Only need to wait for any in-flight flush to finish
|
|
423
|
+
await this.flush.waitForFlush();
|
|
424
|
+
if (this.cardCreationPromise)
|
|
425
|
+
await this.cardCreationPromise;
|
|
426
|
+
const effectiveCardId = this.cardKit.cardKitCardId ?? this.cardKit.originalCardKitCardId;
|
|
427
|
+
if (effectiveCardId) {
|
|
428
|
+
const elapsedMs = Date.now() - this.dispatchStartTime;
|
|
429
|
+
const abortText = this.text.accumulatedText || 'Aborted.';
|
|
430
|
+
const abortCardContent = buildCardContent('complete', {
|
|
431
|
+
text: abortText,
|
|
432
|
+
reasoningText: this.reasoning.accumulatedReasoningText || undefined,
|
|
433
|
+
reasoningElapsedMs: this.reasoning.reasoningElapsedMs || undefined,
|
|
434
|
+
elapsedMs,
|
|
435
|
+
isAborted: true,
|
|
436
|
+
footer: this.deps.resolvedFooter,
|
|
437
|
+
});
|
|
438
|
+
await this.closeStreamingAndUpdate(effectiveCardId, abortCardContent, 'abortCard');
|
|
439
|
+
log.info('abortCard completed', { effectiveCardId });
|
|
440
|
+
}
|
|
441
|
+
else if (this.cardKit.cardMessageId) {
|
|
442
|
+
// IM fallback: 卡片不是通过 CardKit 发的,用 im.message.patch 更新
|
|
443
|
+
const elapsedMs = Date.now() - this.dispatchStartTime;
|
|
444
|
+
const abortText = this.text.accumulatedText || 'Aborted.';
|
|
445
|
+
const abortCard = buildCardContent('complete', {
|
|
446
|
+
text: abortText,
|
|
447
|
+
reasoningText: this.reasoning.accumulatedReasoningText || undefined,
|
|
448
|
+
reasoningElapsedMs: this.reasoning.reasoningElapsedMs || undefined,
|
|
449
|
+
elapsedMs,
|
|
450
|
+
isAborted: true,
|
|
451
|
+
footer: this.deps.resolvedFooter,
|
|
452
|
+
});
|
|
453
|
+
await updateCardFeishu({
|
|
454
|
+
cfg: this.deps.cfg,
|
|
455
|
+
messageId: this.cardKit.cardMessageId,
|
|
456
|
+
card: abortCard,
|
|
457
|
+
accountId: this.deps.accountId,
|
|
458
|
+
});
|
|
459
|
+
log.info('abortCard completed (IM fallback)', { messageId: this.cardKit.cardMessageId });
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
catch (err) {
|
|
463
|
+
log.warn('abortCard failed', { error: String(err) });
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
// ------------------------------------------------------------------
|
|
467
|
+
// Internal: card creation
|
|
468
|
+
// ------------------------------------------------------------------
|
|
469
|
+
async ensureCardCreated() {
|
|
470
|
+
if (this.guard.shouldSkip('ensureCardCreated.precheck'))
|
|
471
|
+
return;
|
|
472
|
+
if (this.cardKit.cardMessageId || this.phase === 'creation_failed' || this.isTerminalPhase) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
if (this.cardCreationPromise) {
|
|
476
|
+
await this.cardCreationPromise;
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
if (!this.transition('creating', 'ensureCardCreated'))
|
|
480
|
+
return;
|
|
481
|
+
this.createEpoch += 1;
|
|
482
|
+
const epoch = this.createEpoch;
|
|
483
|
+
this.cardCreationPromise = (async () => {
|
|
484
|
+
try {
|
|
485
|
+
try {
|
|
486
|
+
// Step 1: Create card entity
|
|
487
|
+
const cId = await createCardEntity({
|
|
488
|
+
cfg: this.deps.cfg,
|
|
489
|
+
card: STREAMING_THINKING_CARD,
|
|
490
|
+
accountId: this.deps.accountId,
|
|
491
|
+
});
|
|
492
|
+
if (this.isStaleCreate(epoch)) {
|
|
493
|
+
log.info('ensureCardCreated: stale epoch after createCardEntity, bailing out', {
|
|
494
|
+
epoch,
|
|
495
|
+
phase: this.phase,
|
|
496
|
+
});
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
if (cId) {
|
|
500
|
+
this.cardKit.cardKitCardId = cId;
|
|
501
|
+
this.cardKit.originalCardKitCardId = cId;
|
|
502
|
+
this.cardKit.cardKitSequence = 1;
|
|
503
|
+
this.disposeShutdownHook = registerShutdownHook(`streaming-card:${cId}`, () => this.abortCard());
|
|
504
|
+
log.info('created CardKit entity', {
|
|
505
|
+
cardId: cId,
|
|
506
|
+
initialSequence: this.cardKit.cardKitSequence,
|
|
507
|
+
});
|
|
508
|
+
// Step 2: Send IM message referencing card_id
|
|
509
|
+
const result = await sendCardByCardId({
|
|
510
|
+
cfg: this.deps.cfg,
|
|
511
|
+
to: this.deps.chatId,
|
|
512
|
+
cardId: cId,
|
|
513
|
+
replyToMessageId: this.deps.replyToMessageId,
|
|
514
|
+
replyInThread: this.deps.replyInThread,
|
|
515
|
+
accountId: this.deps.accountId,
|
|
516
|
+
});
|
|
517
|
+
if (this.isStaleCreate(epoch)) {
|
|
518
|
+
log.info('ensureCardCreated: stale epoch after sendCardByCardId, bailing out', {
|
|
519
|
+
epoch,
|
|
520
|
+
phase: this.phase,
|
|
521
|
+
});
|
|
522
|
+
this.disposeShutdownHook?.();
|
|
523
|
+
this.disposeShutdownHook = null;
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
this.cardKit.cardMessageId = result.messageId;
|
|
527
|
+
this.flush.setCardMessageReady(true);
|
|
528
|
+
if (!this.transition('streaming', 'ensureCardCreated.cardkit')) {
|
|
529
|
+
this.disposeShutdownHook?.();
|
|
530
|
+
this.disposeShutdownHook = null;
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
log.info('sent CardKit card', { messageId: result.messageId });
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
throw new Error('card.create returned empty card_id');
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
catch (cardKitErr) {
|
|
540
|
+
if (this.isStaleCreate(epoch))
|
|
541
|
+
return;
|
|
542
|
+
if (this.guard.terminate('ensureCardCreated.cardkitFlow', cardKitErr)) {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
// CardKit flow failed — fall back to regular IM card
|
|
546
|
+
const apiDetail = extractApiDetail(cardKitErr);
|
|
547
|
+
log.warn('CardKit flow failed, falling back to IM', { apiDetail });
|
|
548
|
+
this.cardKit.cardKitCardId = null;
|
|
549
|
+
this.cardKit.originalCardKitCardId = null;
|
|
550
|
+
const fallbackCard = buildCardContent('thinking');
|
|
551
|
+
const result = await sendCardFeishu({
|
|
552
|
+
cfg: this.deps.cfg,
|
|
553
|
+
to: this.deps.chatId,
|
|
554
|
+
card: fallbackCard,
|
|
555
|
+
replyToMessageId: this.deps.replyToMessageId,
|
|
556
|
+
replyInThread: this.deps.replyInThread,
|
|
557
|
+
accountId: this.deps.accountId,
|
|
558
|
+
});
|
|
559
|
+
if (this.isStaleCreate(epoch)) {
|
|
560
|
+
log.info('ensureCardCreated: stale epoch after IM fallback send, bailing out', {
|
|
561
|
+
epoch,
|
|
562
|
+
phase: this.phase,
|
|
563
|
+
});
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
this.cardKit.cardMessageId = result.messageId;
|
|
567
|
+
this.flush.setCardMessageReady(true);
|
|
568
|
+
if (!this.transition('streaming', 'ensureCardCreated.imFallback')) {
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
log.info('sent fallback IM card', { messageId: result.messageId });
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
catch (err) {
|
|
575
|
+
if (this.isStaleCreate(epoch))
|
|
576
|
+
return;
|
|
577
|
+
if (this.guard.terminate('ensureCardCreated.outer', err)) {
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
log.warn('thinking card failed, falling back to static', { error: String(err) });
|
|
581
|
+
this.transition('creation_failed', 'ensureCardCreated.outer', 'creation_failed');
|
|
582
|
+
}
|
|
583
|
+
})();
|
|
584
|
+
await this.cardCreationPromise;
|
|
585
|
+
}
|
|
586
|
+
// ------------------------------------------------------------------
|
|
587
|
+
// Internal: flush
|
|
588
|
+
// ------------------------------------------------------------------
|
|
589
|
+
async performFlush() {
|
|
590
|
+
if (!this.cardKit.cardMessageId || this.isTerminalPhase)
|
|
591
|
+
return;
|
|
592
|
+
// v2 CardKit 卡片不能走 IM patch,如果流式 CardKit 已禁用但 originalCardKitCardId
|
|
593
|
+
// 仍在,说明卡片是通过 CardKit 发的——跳过中间态更新,等终态用 originalCardKitCardId 收尾
|
|
594
|
+
if (!this.cardKit.cardKitCardId && this.cardKit.originalCardKitCardId) {
|
|
595
|
+
log.debug('performFlush: skipping (CardKit streaming disabled, awaiting final update)');
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
log.debug('flushCardUpdate: enter', {
|
|
599
|
+
seq: this.cardKit.cardKitSequence,
|
|
600
|
+
isCardKit: !!this.cardKit.cardKitCardId,
|
|
601
|
+
});
|
|
602
|
+
try {
|
|
603
|
+
const displayText = this.buildDisplayText();
|
|
604
|
+
if (this.cardKit.cardKitCardId) {
|
|
605
|
+
// CardKit streaming — typewriter effect
|
|
606
|
+
const prevSeq = this.cardKit.cardKitSequence;
|
|
607
|
+
this.cardKit.cardKitSequence += 1;
|
|
608
|
+
log.debug('flushCardUpdate: seq bump', {
|
|
609
|
+
seqBefore: prevSeq,
|
|
610
|
+
seqAfter: this.cardKit.cardKitSequence,
|
|
611
|
+
});
|
|
612
|
+
await streamCardContent({
|
|
613
|
+
cfg: this.deps.cfg,
|
|
614
|
+
cardId: this.cardKit.cardKitCardId,
|
|
615
|
+
elementId: STREAMING_ELEMENT_ID,
|
|
616
|
+
content: optimizeMarkdownStyle(displayText),
|
|
617
|
+
sequence: this.cardKit.cardKitSequence,
|
|
618
|
+
accountId: this.deps.accountId,
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
else {
|
|
622
|
+
log.debug('flushCardUpdate: IM patch fallback');
|
|
623
|
+
const card = buildCardContent('streaming', {
|
|
624
|
+
text: this.reasoning.isReasoningPhase ? '' : displayText,
|
|
625
|
+
reasoningText: this.reasoning.isReasoningPhase ? this.reasoning.accumulatedReasoningText : undefined,
|
|
626
|
+
});
|
|
627
|
+
await updateCardFeishu({
|
|
628
|
+
cfg: this.deps.cfg,
|
|
629
|
+
messageId: this.cardKit.cardMessageId,
|
|
630
|
+
card: card,
|
|
631
|
+
accountId: this.deps.accountId,
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
catch (err) {
|
|
636
|
+
if (this.guard.terminate('flushCardUpdate', err))
|
|
637
|
+
return;
|
|
638
|
+
const apiCode = extractLarkApiCode(err);
|
|
639
|
+
if (apiCode === 230020) {
|
|
640
|
+
log.info('flushCardUpdate: rate limited (230020), skipping', {
|
|
641
|
+
seq: this.cardKit.cardKitSequence,
|
|
642
|
+
});
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
const apiDetail = extractApiDetail(err);
|
|
646
|
+
log.error('card stream update failed', {
|
|
647
|
+
apiCode,
|
|
648
|
+
seq: this.cardKit.cardKitSequence,
|
|
649
|
+
apiDetail,
|
|
650
|
+
});
|
|
651
|
+
if (this.cardKit.cardKitCardId) {
|
|
652
|
+
log.warn('disabling CardKit streaming, falling back to im.message.patch');
|
|
653
|
+
this.cardKit.cardKitCardId = null;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
buildDisplayText() {
|
|
658
|
+
if (this.reasoning.isReasoningPhase && this.reasoning.accumulatedReasoningText) {
|
|
659
|
+
const reasoningDisplay = `💭 **Thinking...**\n\n${this.reasoning.accumulatedReasoningText}`;
|
|
660
|
+
return this.text.accumulatedText ? this.text.accumulatedText + '\n\n' + reasoningDisplay : reasoningDisplay;
|
|
661
|
+
}
|
|
662
|
+
return this.text.accumulatedText;
|
|
663
|
+
}
|
|
664
|
+
async throttledCardUpdate() {
|
|
665
|
+
if (this.guard.shouldSkip('throttledCardUpdate'))
|
|
666
|
+
return;
|
|
667
|
+
const throttleMs = this.cardKit.cardKitCardId ? THROTTLE_CONSTANTS.CARDKIT_MS : THROTTLE_CONSTANTS.PATCH_MS;
|
|
668
|
+
await this.flush.throttledUpdate(throttleMs);
|
|
669
|
+
}
|
|
670
|
+
// ------------------------------------------------------------------
|
|
671
|
+
// Internal: lifecycle helpers
|
|
672
|
+
// ------------------------------------------------------------------
|
|
673
|
+
finalizeCard(source, reason) {
|
|
674
|
+
this.transition('completed', source, reason);
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Close streaming mode then update card content (shared by onError and abortCard).
|
|
678
|
+
*/
|
|
679
|
+
async closeStreamingAndUpdate(cardId, card, label) {
|
|
680
|
+
const seqBeforeClose = this.cardKit.cardKitSequence;
|
|
681
|
+
this.cardKit.cardKitSequence += 1;
|
|
682
|
+
log.info(`${label}: closing streaming mode`, {
|
|
683
|
+
seqBefore: seqBeforeClose,
|
|
684
|
+
seqAfter: this.cardKit.cardKitSequence,
|
|
685
|
+
});
|
|
686
|
+
await setCardStreamingMode({
|
|
687
|
+
cfg: this.deps.cfg,
|
|
688
|
+
cardId,
|
|
689
|
+
streamingMode: false,
|
|
690
|
+
sequence: this.cardKit.cardKitSequence,
|
|
691
|
+
accountId: this.deps.accountId,
|
|
692
|
+
});
|
|
693
|
+
const seqBeforeUpdate = this.cardKit.cardKitSequence;
|
|
694
|
+
this.cardKit.cardKitSequence += 1;
|
|
695
|
+
log.info(`${label}: updating card`, {
|
|
696
|
+
seqBefore: seqBeforeUpdate,
|
|
697
|
+
seqAfter: this.cardKit.cardKitSequence,
|
|
698
|
+
});
|
|
699
|
+
await updateCardKitCard({
|
|
700
|
+
cfg: this.deps.cfg,
|
|
701
|
+
cardId,
|
|
702
|
+
card: toCardKit2(card),
|
|
703
|
+
sequence: this.cardKit.cardKitSequence,
|
|
704
|
+
accountId: this.deps.accountId,
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
// ---------------------------------------------------------------------------
|
|
709
|
+
// Error detail extraction helpers (replacing `any` casts)
|
|
710
|
+
// ---------------------------------------------------------------------------
|
|
711
|
+
function extractApiDetail(err) {
|
|
712
|
+
if (!err || typeof err !== 'object')
|
|
713
|
+
return String(err);
|
|
714
|
+
const e = err;
|
|
715
|
+
return e.response?.data ? JSON.stringify(e.response.data) : String(err);
|
|
716
|
+
}
|
|
717
|
+
//# sourceMappingURL=streaming-card-controller.js.map
|