@graychennpm/codebridge 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +217 -2
- package/README.zh-CN.md +222 -0
- package/apps/web/public/brand/agent-logo-carbon.svg +1 -0
- package/apps/web/public/brand/agent-logo.svg +1 -0
- package/docs/zh-CN/npm-release.md +77 -0
- package/node_modules/@codebridge/agent-registry/dist/index.d.ts +32 -0
- package/node_modules/@codebridge/agent-registry/dist/index.js +177 -0
- package/node_modules/@codebridge/agent-registry/dist/setup.d.ts +9 -0
- package/node_modules/@codebridge/agent-registry/dist/setup.js +115 -0
- package/node_modules/@codebridge/agent-registry/package.json +17 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-active-session.d.ts +12 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-active-session.js +57 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-claude-activity.d.ts +9 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-claude-activity.js +49 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-config-options.d.ts +46 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-config-options.js +220 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-doctor.d.ts +3 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-doctor.js +18 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-event-mapper.d.ts +5 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-event-mapper.js +136 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-kill.d.ts +10 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-kill.js +24 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-race.d.ts +6 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-race.js +29 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-session-list.d.ts +32 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-session-list.js +218 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-session-pool.d.ts +85 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-session-pool.js +165 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-session-runner.d.ts +78 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-session-runner.js +550 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-spawn-profiles.d.ts +9 -0
- package/node_modules/@codebridge/backends/dist/acp/acp-spawn-profiles.js +28 -0
- package/node_modules/@codebridge/backends/dist/acp/headless-client.d.ts +19 -0
- package/node_modules/@codebridge/backends/dist/acp/headless-client.js +47 -0
- package/node_modules/@codebridge/backends/dist/acp/index.d.ts +9 -0
- package/node_modules/@codebridge/backends/dist/acp/index.js +9 -0
- package/node_modules/@codebridge/backends/dist/agent-setup.d.ts +60 -0
- package/node_modules/@codebridge/backends/dist/agent-setup.js +504 -0
- package/node_modules/@codebridge/backends/dist/attachment-prompt.d.ts +8 -0
- package/node_modules/@codebridge/backends/dist/attachment-prompt.js +28 -0
- package/node_modules/@codebridge/backends/dist/auth-error-hints.d.ts +8 -0
- package/node_modules/@codebridge/backends/dist/auth-error-hints.js +33 -0
- package/node_modules/@codebridge/backends/dist/codex-skill-commands.d.ts +3 -0
- package/node_modules/@codebridge/backends/dist/codex-skill-commands.js +88 -0
- package/node_modules/@codebridge/backends/dist/index.d.ts +18 -0
- package/node_modules/@codebridge/backends/dist/index.js +34 -0
- package/node_modules/@codebridge/backends/dist/pi-providers.d.ts +45 -0
- package/node_modules/@codebridge/backends/dist/pi-providers.js +148 -0
- package/node_modules/@codebridge/backends/dist/pi-session-runner.d.ts +85 -0
- package/node_modules/@codebridge/backends/dist/pi-session-runner.js +460 -0
- package/node_modules/@codebridge/backends/dist/provider-connection.d.ts +17 -0
- package/node_modules/@codebridge/backends/dist/provider-connection.js +99 -0
- package/node_modules/@codebridge/backends/dist/session-discovery.d.ts +23 -0
- package/node_modules/@codebridge/backends/dist/session-discovery.js +340 -0
- package/node_modules/@codebridge/backends/dist/skill-control-plane.d.ts +147 -0
- package/node_modules/@codebridge/backends/dist/skill-control-plane.js +832 -0
- package/node_modules/@codebridge/backends/package.json +22 -0
- package/node_modules/@codebridge/bridge/dist/alert-notification-rules.d.ts +14 -0
- package/node_modules/@codebridge/bridge/dist/alert-notification-rules.js +37 -0
- package/node_modules/@codebridge/bridge/dist/channel-config.d.ts +4 -0
- package/node_modules/@codebridge/bridge/dist/channel-config.js +9 -0
- package/node_modules/@codebridge/bridge/dist/channel-ingress.d.ts +5 -0
- package/node_modules/@codebridge/bridge/dist/channel-ingress.js +403 -0
- package/node_modules/@codebridge/bridge/dist/cli.d.ts +3 -0
- package/node_modules/@codebridge/bridge/dist/cli.js +581 -0
- package/node_modules/@codebridge/bridge/dist/deployment.d.ts +46 -0
- package/node_modules/@codebridge/bridge/dist/deployment.js +174 -0
- package/node_modules/@codebridge/bridge/dist/event-loop-lag.d.ts +19 -0
- package/node_modules/@codebridge/bridge/dist/event-loop-lag.js +33 -0
- package/node_modules/@codebridge/bridge/dist/feishu-alert-monitor.d.ts +70 -0
- package/node_modules/@codebridge/bridge/dist/feishu-alert-monitor.js +591 -0
- package/node_modules/@codebridge/bridge/dist/init-wizard.d.ts +52 -0
- package/node_modules/@codebridge/bridge/dist/init-wizard.js +571 -0
- package/node_modules/@codebridge/bridge/dist/mcp-api.d.ts +4 -0
- package/node_modules/@codebridge/bridge/dist/mcp-api.js +100 -0
- package/node_modules/@codebridge/bridge/dist/outbound-api.d.ts +31 -0
- package/node_modules/@codebridge/bridge/dist/outbound-api.js +184 -0
- package/node_modules/@codebridge/bridge/dist/outbound-publishers.d.ts +54 -0
- package/node_modules/@codebridge/bridge/dist/outbound-publishers.js +213 -0
- package/node_modules/@codebridge/bridge/dist/project-api.d.ts +4 -0
- package/node_modules/@codebridge/bridge/dist/project-api.js +161 -0
- package/node_modules/@codebridge/bridge/dist/secrets-command.d.ts +13 -0
- package/node_modules/@codebridge/bridge/dist/secrets-command.js +34 -0
- package/node_modules/@codebridge/bridge/dist/session-api.d.ts +26 -0
- package/node_modules/@codebridge/bridge/dist/session-api.js +1378 -0
- package/node_modules/@codebridge/bridge/dist/session-history-import.d.ts +24 -0
- package/node_modules/@codebridge/bridge/dist/session-history-import.js +82 -0
- package/node_modules/@codebridge/bridge/dist/session-runtime-api.d.ts +19 -0
- package/node_modules/@codebridge/bridge/dist/session-runtime-api.js +453 -0
- package/node_modules/@codebridge/bridge/dist/session-runtime-migration.d.ts +21 -0
- package/node_modules/@codebridge/bridge/dist/session-runtime-migration.js +43 -0
- package/node_modules/@codebridge/bridge/dist/session-runtime-types.d.ts +85 -0
- package/node_modules/@codebridge/bridge/dist/session-runtime-types.js +98 -0
- package/node_modules/@codebridge/bridge/dist/skill-api.d.ts +28 -0
- package/node_modules/@codebridge/bridge/dist/skill-api.js +129 -0
- package/node_modules/@codebridge/bridge/dist/startup-surfaces.d.ts +15 -0
- package/node_modules/@codebridge/bridge/dist/startup-surfaces.js +13 -0
- package/node_modules/@codebridge/bridge/dist/web-frontend.d.ts +8 -0
- package/node_modules/@codebridge/bridge/dist/web-frontend.js +76 -0
- package/node_modules/@codebridge/bridge/dist/work-item-api.d.ts +6 -0
- package/node_modules/@codebridge/bridge/dist/work-item-api.js +414 -0
- package/node_modules/@codebridge/bridge/package.json +28 -0
- package/node_modules/@codebridge/channel-feishu/dist/alert-reactions.d.ts +6 -0
- package/node_modules/@codebridge/channel-feishu/dist/alert-reactions.js +58 -0
- package/node_modules/@codebridge/channel-feishu/dist/alert-types.d.ts +35 -0
- package/node_modules/@codebridge/channel-feishu/dist/alert-types.js +2 -0
- package/node_modules/@codebridge/channel-feishu/dist/bridge.d.ts +130 -0
- package/node_modules/@codebridge/channel-feishu/dist/bridge.js +1231 -0
- package/node_modules/@codebridge/channel-feishu/dist/cardkit-writer.d.ts +48 -0
- package/node_modules/@codebridge/channel-feishu/dist/cardkit-writer.js +153 -0
- package/node_modules/@codebridge/channel-feishu/dist/chain-topics.d.ts +20 -0
- package/node_modules/@codebridge/channel-feishu/dist/chain-topics.js +35 -0
- package/node_modules/@codebridge/channel-feishu/dist/coalescing-card-writer.d.ts +12 -0
- package/node_modules/@codebridge/channel-feishu/dist/coalescing-card-writer.js +53 -0
- package/node_modules/@codebridge/channel-feishu/dist/delivery-reconciler.d.ts +19 -0
- package/node_modules/@codebridge/channel-feishu/dist/delivery-reconciler.js +53 -0
- package/node_modules/@codebridge/channel-feishu/dist/durable-markdown-card.d.ts +19 -0
- package/node_modules/@codebridge/channel-feishu/dist/durable-markdown-card.js +77 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-extra-events.d.ts +27 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-extra-events.js +24 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-http.d.ts +4 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-http.js +25 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-inbound-context.d.ts +13 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-inbound-context.js +45 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-inbound-media.d.ts +22 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-inbound-media.js +273 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-mention-gate.d.ts +13 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-mention-gate.js +22 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-outbound-file.d.ts +12 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-outbound-file.js +38 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-quoted-message.d.ts +30 -0
- package/node_modules/@codebridge/channel-feishu/dist/feishu-quoted-message.js +183 -0
- package/node_modules/@codebridge/channel-feishu/dist/index.d.ts +7 -0
- package/node_modules/@codebridge/channel-feishu/dist/index.js +3 -0
- package/node_modules/@codebridge/channel-feishu/dist/redacting-logger.d.ts +17 -0
- package/node_modules/@codebridge/channel-feishu/dist/redacting-logger.js +41 -0
- package/node_modules/@codebridge/channel-feishu/dist/run-status.d.ts +39 -0
- package/node_modules/@codebridge/channel-feishu/dist/run-status.js +166 -0
- package/node_modules/@codebridge/channel-feishu/dist/session-watcher.d.ts +98 -0
- package/node_modules/@codebridge/channel-feishu/dist/session-watcher.js +655 -0
- package/node_modules/@codebridge/channel-feishu/package.json +19 -0
- package/node_modules/@codebridge/channel-telegram/dist/coalescing-message-writer.d.ts +14 -0
- package/node_modules/@codebridge/channel-telegram/dist/coalescing-message-writer.js +56 -0
- package/node_modules/@codebridge/channel-telegram/dist/index.d.ts +3 -0
- package/node_modules/@codebridge/channel-telegram/dist/index.js +3 -0
- package/node_modules/@codebridge/channel-telegram/dist/telegram-api.d.ts +62 -0
- package/node_modules/@codebridge/channel-telegram/dist/telegram-api.js +72 -0
- package/node_modules/@codebridge/channel-telegram/dist/telegram-bridge.d.ts +64 -0
- package/node_modules/@codebridge/channel-telegram/dist/telegram-bridge.js +469 -0
- package/node_modules/@codebridge/channel-telegram/dist/telegram-session-watcher.d.ts +41 -0
- package/node_modules/@codebridge/channel-telegram/dist/telegram-session-watcher.js +184 -0
- package/node_modules/@codebridge/channel-telegram/package.json +18 -0
- package/node_modules/@codebridge/core/dist/config-schema.d.ts +1195 -0
- package/node_modules/@codebridge/core/dist/config-schema.js +293 -0
- package/node_modules/@codebridge/core/dist/config-store.d.ts +48 -0
- package/node_modules/@codebridge/core/dist/config-store.js +207 -0
- package/node_modules/@codebridge/core/dist/index.d.ts +11 -0
- package/node_modules/@codebridge/core/dist/index.js +10 -0
- package/node_modules/@codebridge/core/dist/json-file-store.d.ts +16 -0
- package/node_modules/@codebridge/core/dist/json-file-store.js +46 -0
- package/node_modules/@codebridge/core/dist/mcp-types.d.ts +7 -0
- package/node_modules/@codebridge/core/dist/mcp-types.js +2 -0
- package/node_modules/@codebridge/core/dist/mentions.d.ts +36 -0
- package/node_modules/@codebridge/core/dist/mentions.js +138 -0
- package/node_modules/@codebridge/core/dist/secret-migration.d.ts +14 -0
- package/node_modules/@codebridge/core/dist/secret-migration.js +55 -0
- package/node_modules/@codebridge/core/dist/secret-refs.d.ts +34 -0
- package/node_modules/@codebridge/core/dist/secret-refs.js +142 -0
- package/node_modules/@codebridge/core/dist/session-event-wire.d.ts +17 -0
- package/node_modules/@codebridge/core/dist/session-event-wire.js +28 -0
- package/node_modules/@codebridge/core/dist/types.d.ts +363 -0
- package/node_modules/@codebridge/core/dist/types.js +22 -0
- package/node_modules/@codebridge/core/dist/workspace-key.d.ts +11 -0
- package/node_modules/@codebridge/core/dist/workspace-key.js +25 -0
- package/node_modules/@codebridge/core/package.json +22 -0
- package/node_modules/@codebridge/mcp-runtime/dist/.tsbuildinfo +1 -0
- package/node_modules/@codebridge/mcp-runtime/dist/index.d.ts +92 -0
- package/node_modules/@codebridge/mcp-runtime/dist/index.js +377 -0
- package/node_modules/@codebridge/mcp-runtime/package.json +19 -0
- package/node_modules/@codebridge/policy/dist/capability-runtime.d.ts +123 -0
- package/node_modules/@codebridge/policy/dist/capability-runtime.js +195 -0
- package/node_modules/@codebridge/policy/dist/demo-capabilities.d.ts +4 -0
- package/node_modules/@codebridge/policy/dist/demo-capabilities.js +134 -0
- package/node_modules/@codebridge/policy/dist/equity-capabilities.d.ts +8 -0
- package/node_modules/@codebridge/policy/dist/equity-capabilities.js +35 -0
- package/node_modules/@codebridge/policy/dist/index.d.ts +107 -0
- package/node_modules/@codebridge/policy/dist/index.js +317 -0
- package/node_modules/@codebridge/policy/package.json +17 -0
- package/node_modules/@codebridge/project-catalog/dist/index.d.ts +145 -0
- package/node_modules/@codebridge/project-catalog/dist/index.js +699 -0
- package/node_modules/@codebridge/project-catalog/package.json +18 -0
- package/node_modules/@codebridge/router/dist/channel-stream-projector.d.ts +19 -0
- package/node_modules/@codebridge/router/dist/channel-stream-projector.js +68 -0
- package/node_modules/@codebridge/router/dist/command-help.d.ts +14 -0
- package/node_modules/@codebridge/router/dist/command-help.js +151 -0
- package/node_modules/@codebridge/router/dist/feishu-stream-presenter.d.ts +18 -0
- package/node_modules/@codebridge/router/dist/feishu-stream-presenter.js +193 -0
- package/node_modules/@codebridge/router/dist/index.d.ts +9 -0
- package/node_modules/@codebridge/router/dist/index.js +9 -0
- package/node_modules/@codebridge/router/dist/model-effort.d.ts +5 -0
- package/node_modules/@codebridge/router/dist/model-effort.js +33 -0
- package/node_modules/@codebridge/router/dist/orchestrator.d.ts +56 -0
- package/node_modules/@codebridge/router/dist/orchestrator.js +290 -0
- package/node_modules/@codebridge/router/dist/session-list-format.d.ts +19 -0
- package/node_modules/@codebridge/router/dist/session-list-format.js +97 -0
- package/node_modules/@codebridge/router/dist/session-rotation.d.ts +9 -0
- package/node_modules/@codebridge/router/dist/session-rotation.js +31 -0
- package/node_modules/@codebridge/router/dist/session-router.d.ts +59 -0
- package/node_modules/@codebridge/router/dist/session-router.js +182 -0
- package/node_modules/@codebridge/router/dist/slash-commands.d.ts +78 -0
- package/node_modules/@codebridge/router/dist/slash-commands.js +874 -0
- package/node_modules/@codebridge/router/package.json +18 -0
- package/node_modules/@codebridge/run-executor/dist/agent-event-aggregator.d.ts +18 -0
- package/node_modules/@codebridge/run-executor/dist/agent-event-aggregator.js +88 -0
- package/node_modules/@codebridge/run-executor/dist/index.d.ts +55 -0
- package/node_modules/@codebridge/run-executor/dist/index.js +754 -0
- package/node_modules/@codebridge/run-executor/dist/run-heartbeat.d.ts +14 -0
- package/node_modules/@codebridge/run-executor/dist/run-heartbeat.js +24 -0
- package/node_modules/@codebridge/run-executor/package.json +20 -0
- package/node_modules/@codebridge/runner-client/dist/index.d.ts +142 -0
- package/node_modules/@codebridge/runner-client/dist/index.js +439 -0
- package/node_modules/@codebridge/runner-client/package.json +18 -0
- package/node_modules/@codebridge/runner-host/dist/cli.d.ts +3 -0
- package/node_modules/@codebridge/runner-host/dist/cli.js +58 -0
- package/node_modules/@codebridge/runner-host/dist/codex-session-ownership.d.ts +13 -0
- package/node_modules/@codebridge/runner-host/dist/codex-session-ownership.js +79 -0
- package/node_modules/@codebridge/runner-host/dist/deployment-mcp-server.d.ts +10 -0
- package/node_modules/@codebridge/runner-host/dist/deployment-mcp-server.js +54 -0
- package/node_modules/@codebridge/runner-host/dist/fcb-script.d.ts +3 -0
- package/node_modules/@codebridge/runner-host/dist/fcb-script.js +99 -0
- package/node_modules/@codebridge/runner-host/dist/index.d.ts +3 -0
- package/node_modules/@codebridge/runner-host/dist/index.js +2 -0
- package/node_modules/@codebridge/runner-host/dist/materialize-attachments.d.ts +4 -0
- package/node_modules/@codebridge/runner-host/dist/materialize-attachments.js +62 -0
- package/node_modules/@codebridge/runner-host/dist/server.d.ts +150 -0
- package/node_modules/@codebridge/runner-host/dist/server.js +1295 -0
- package/node_modules/@codebridge/runner-host/dist/session-lease.d.ts +12 -0
- package/node_modules/@codebridge/runner-host/dist/session-lease.js +146 -0
- package/node_modules/@codebridge/runner-host/package.json +26 -0
- package/node_modules/@codebridge/session-catalog/dist/index.d.ts +124 -0
- package/node_modules/@codebridge/session-catalog/dist/index.js +411 -0
- package/node_modules/@codebridge/session-catalog/package.json +17 -0
- package/node_modules/@codebridge/session-coordinator/dist/coordinator.d.ts +111 -0
- package/node_modules/@codebridge/session-coordinator/dist/coordinator.js +364 -0
- package/node_modules/@codebridge/session-coordinator/dist/index.d.ts +5 -0
- package/node_modules/@codebridge/session-coordinator/dist/index.js +5 -0
- package/node_modules/@codebridge/session-coordinator/dist/lease.d.ts +14 -0
- package/node_modules/@codebridge/session-coordinator/dist/lease.js +26 -0
- package/node_modules/@codebridge/session-coordinator/dist/queued-claim.d.ts +20 -0
- package/node_modules/@codebridge/session-coordinator/dist/queued-claim.js +45 -0
- package/node_modules/@codebridge/session-coordinator/dist/recovery.d.ts +31 -0
- package/node_modules/@codebridge/session-coordinator/dist/recovery.js +114 -0
- package/node_modules/@codebridge/session-coordinator/package.json +17 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/node_modules/@codebridge/web/dist/assets/abnfDiagram-N423BO3Z-C-JdFv0U.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/arc-DsNROjzU.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/architecture-TIHT7OUA-ZEBHG2JZ.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/architectureDiagram-T3A2C74G-OsrxcwPM.js +36 -0
- package/node_modules/@codebridge/web/dist/assets/array-BifhSqXX.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/blockDiagram-VBNYF7ZC-DRgfNeNW.js +132 -0
- package/node_modules/@codebridge/web/dist/assets/c4Diagram-5PPSVZJV-BtOGKTh8.js +10 -0
- package/node_modules/@codebridge/web/dist/assets/channel-MhXyjxUS.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-2GRJ4B5K-Dy1gJ7sY.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-4I5QYGJK-1pOLR_SG.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-5RXB4S5H-CP43rgsO.js +231 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-6Q2QTUOP-Bi3Xrp6W.js +88 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-7BUUIJ7U-Bb538aSH.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-7Z6QIM7H-CILAW2Nk.js +10 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-GF5L2VYU-CAp09yhq.js +206 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-I66GZJ75-B_rJXmNu.js +128 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-JQJVKLGR-OVeOJFCx.js +156 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-JWPE2WC7-DVXcaiue.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-KBJHAD2P-uaupp0k5.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-KEIR6QF5-BICK3FdT.js +161 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-NSK5VX7P-fIHF5wwn.js +2 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-QR6OTTB3-DxkJuF2b.js +62 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-RYQCIY6F-CC5j3u-X.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-UBXNYLIW-DB35O-6R.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-W5SLKNZC-bkRBsbq-.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-WRU74C26-DwvEoD-1.js +70 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-XXDRQBXY-DRyYA-HY.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/classDiagram-JCYQIIEL-B8r7z8ii.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/classDiagram-v2-OCEON4UE-B8r7z8ii.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/cose-bilkent-JH36ORCC-CLkwlrX7.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/cynefin-VYW2F7L2-C3_Llw02.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/cynefinDiagram-MW4NZA55-D5v7UnJy.js +62 -0
- package/node_modules/@codebridge/web/dist/assets/cytoscape.esm-B-NFISlW.js +321 -0
- package/node_modules/@codebridge/web/dist/assets/dagre-Buvkdvvj.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/dagre-VZM6K2ZE-Cr0IibwW.js +4 -0
- package/node_modules/@codebridge/web/dist/assets/defaultLocale-BFoDCU3G.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/diagram-7IWD3JNH-CpQXDIzA.js +30 -0
- package/node_modules/@codebridge/web/dist/assets/diagram-B4RE2ZJO-VaOkH0Ya.js +3 -0
- package/node_modules/@codebridge/web/dist/assets/diagram-LBJQPF4R-D0iXyNks.js +24 -0
- package/node_modules/@codebridge/web/dist/assets/diagram-Q27KOJAE-CtqYk01P.js +24 -0
- package/node_modules/@codebridge/web/dist/assets/diagram-UB23O5K3-CFnd3H1_.js +41 -0
- package/node_modules/@codebridge/web/dist/assets/dist-D2L7nRdk.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/ebnfDiagram-BXEA7PRR-B0GIbJYt.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/erDiagram-JOGREHBK-BApaLGVA.js +85 -0
- package/node_modules/@codebridge/web/dist/assets/eventmodeling-45OFAUF4-DqGGjcld.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/flowDiagram-UKHOOZJN-I_qlizLH.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/ganttDiagram-PKOTCBZU-B-QZ-J82.js +292 -0
- package/node_modules/@codebridge/web/dist/assets/gitGraph-TEB2WS4Q-DK2SJ2Ne.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/gitGraphDiagram-DS77QQ5N-B6Z-pu0D.js +106 -0
- package/node_modules/@codebridge/web/dist/assets/graphlib-DS17s2tU.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/index-8BzpyygS.js +559 -0
- package/node_modules/@codebridge/web/dist/assets/index-Bzaz89LE.css +1 -0
- package/node_modules/@codebridge/web/dist/assets/info-DKCQHKI2-CGWxt_Py.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/infoDiagram-6WML65LV-77XjrPZs.js +2 -0
- package/node_modules/@codebridge/web/dist/assets/init-C-OQMol4.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/ishikawaDiagram-WSZJBQD7-P1bZAz2x.js +70 -0
- package/node_modules/@codebridge/web/dist/assets/journeyDiagram-NVQOT4AX-C4rwMcBY.js +139 -0
- package/node_modules/@codebridge/web/dist/assets/kanban-definition-27J2QSJJ-mtw4a9bc.js +89 -0
- package/node_modules/@codebridge/web/dist/assets/line-DP4RkYqm.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/linear-DMg3PPio.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/map-BaFkSB1l.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/mermaid-parser.core-HY84kHw1.js +7 -0
- package/node_modules/@codebridge/web/dist/assets/mermaid.core-DdgCdsnM.js +42 -0
- package/node_modules/@codebridge/web/dist/assets/mindmap-definition-FAOFIHXS-Cw1EnbhZ.js +96 -0
- package/node_modules/@codebridge/web/dist/assets/ordinal-BDEzSJ7C.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/packet-7NZHBO7P-CEbrbJH3.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/path-fybaL0A-.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/pegDiagram-VL7TDLO6-CEc1Gedb.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/pie-RZYD4A2V-DPXVs-IW.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/pieDiagram-7S7Q4E2Y-hoQeGMFH.js +39 -0
- package/node_modules/@codebridge/web/dist/assets/quadrantDiagram-CIZ2JOQS-C-Nmxx0f.js +7 -0
- package/node_modules/@codebridge/web/dist/assets/radar-I7S5WNFK-BVd3X3Pd.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/railroad-3IZDKUUU-CxLxzr_v.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/railroad-abnf-AHOZXSZD-MA1zPI84.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/railroad-ebnf-EBAXGLYW-Bqug_umD.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/railroad-peg-LSFZ7HO6-DRcRFwpq.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/railroadDiagram-AXF67PYL-B007ZkL9.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/requirementDiagram-LRYGKXZP-LrTCcEi5.js +84 -0
- package/node_modules/@codebridge/web/dist/assets/rough.esm-Dy-Kn_BL.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/sankeyDiagram-W5VNT64P-Ch4mzHck.js +40 -0
- package/node_modules/@codebridge/web/dist/assets/sequenceDiagram-SI44F4Z6-CHg4OzLX.js +162 -0
- package/node_modules/@codebridge/web/dist/assets/sizeCapture-X5ZJPWSS-B0uUizjq.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/src-BrO6_odD.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/stateDiagram-OKZ733FA-7cVkr5nR.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/stateDiagram-v2-UEYNNEHI-CTy_mAXb.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/swimlanes-SLNWSIFB-BwSVF5qy.js +2 -0
- package/node_modules/@codebridge/web/dist/assets/swimlanesDiagram-ULZ7WXOC-BBQnfZ1j.js +8 -0
- package/node_modules/@codebridge/web/dist/assets/timeline-definition-Z64GVDOM-BaHEkVDV.js +120 -0
- package/node_modules/@codebridge/web/dist/assets/treeView-QDETBFTQ-CF0kLN62.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/treemap-6X3UGDF4-BB8A8uux.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/vennDiagram-T6HMQDX7-BFK12Iro.js +34 -0
- package/node_modules/@codebridge/web/dist/assets/wardley-OPB4EBWU-C_3y61zk.js +1 -0
- package/node_modules/@codebridge/web/dist/assets/wardleyDiagram-T6FBY63Y-W2oGu4WK.js +78 -0
- package/node_modules/@codebridge/web/dist/assets/xychartDiagram-ELKLHX3M-BiVRnbvz.js +7 -0
- package/node_modules/@codebridge/web/dist/brand/agent-logo-carbon.svg +1 -0
- package/node_modules/@codebridge/web/dist/brand/agent-logo.svg +1 -0
- package/node_modules/@codebridge/web/dist/brand/agnet-logo-carbon.svg +1 -0
- package/node_modules/@codebridge/web/dist/brand/agnet-logo.svg +1 -0
- package/node_modules/@codebridge/web/dist/brand/agnet-mark-carbon.svg +1 -0
- package/node_modules/@codebridge/web/dist/brand/agnet-mark.svg +1 -0
- package/node_modules/@codebridge/web/dist/fonts/CommitMono-400-Regular.otf +0 -0
- package/node_modules/@codebridge/web/dist/fonts/CommitMono-700-Regular.otf +0 -0
- package/node_modules/@codebridge/web/dist/fonts/CommitMono-OFL.txt +21 -0
- package/node_modules/@codebridge/web/dist/fonts/DepartureMono-OFL.txt +21 -0
- package/node_modules/@codebridge/web/dist/fonts/DepartureMono-Regular.woff2 +0 -0
- package/node_modules/@codebridge/web/dist/index.html +25 -0
- package/node_modules/@codebridge/web/package.json +7 -0
- package/node_modules/@codebridge/work-items/dist/index.d.ts +371 -0
- package/node_modules/@codebridge/work-items/dist/index.js +1784 -0
- package/node_modules/@codebridge/work-items/dist/session-projector.d.ts +4 -0
- package/node_modules/@codebridge/work-items/dist/session-projector.js +506 -0
- package/node_modules/@codebridge/work-items/dist/session-runtime.d.ts +274 -0
- package/node_modules/@codebridge/work-items/dist/session-runtime.js +1103 -0
- package/node_modules/@codebridge/work-items/dist/session-schema.d.ts +9 -0
- package/node_modules/@codebridge/work-items/dist/session-schema.js +292 -0
- package/node_modules/@codebridge/work-items/package.json +20 -0
- package/package.json +75 -4
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
import { createChannelStreamProjector } from "@codebridge/router";
|
|
2
|
+
import { runCardJson } from "./cardkit-writer.js";
|
|
3
|
+
import { CoalescingCardWriter } from "./coalescing-card-writer.js";
|
|
4
|
+
import { applyRunSnapshot, createFeishuRunStatus, finishFeishuRunStatus, recordFeishuRunActivity, recordRunVerificationFailure, renderFeishuRunStatus, setCoreEventStream, setHttpWrite, setInboundWebSocket, } from "./run-status.js";
|
|
5
|
+
export const FEISHU_LIVE_STATUS_TICK_MS = 15_000;
|
|
6
|
+
export { FEISHU_LIVE_STATUS_QUIET_MS } from "./run-status.js";
|
|
7
|
+
const FEISHU_LIVE_PROGRESS_CHARS = 1200;
|
|
8
|
+
export function classifyFeishuCardWriteError(error) {
|
|
9
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
10
|
+
return /\b(?:11310|200740|200750|300311)\b|card\s*id\s*invalid|cardid\s*invalid/i.test(text)
|
|
11
|
+
? "permanent"
|
|
12
|
+
: "transient";
|
|
13
|
+
}
|
|
14
|
+
function terminalStateForEvent(type) {
|
|
15
|
+
switch (type) {
|
|
16
|
+
case "RUN_SUCCEEDED":
|
|
17
|
+
return "succeeded";
|
|
18
|
+
case "RUN_FAILED":
|
|
19
|
+
return "failed";
|
|
20
|
+
case "RUN_CANCELLED":
|
|
21
|
+
return "cancelled";
|
|
22
|
+
case "RUN_INTERRUPTED":
|
|
23
|
+
return "interrupted";
|
|
24
|
+
default:
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** 一个 Run 的飞书流式卡片。开卡后由 watcher 喂 AgentEvent,终态时 finalize。 */
|
|
29
|
+
export class FeishuRunCard {
|
|
30
|
+
host;
|
|
31
|
+
chatId;
|
|
32
|
+
sourceMessageId;
|
|
33
|
+
runId;
|
|
34
|
+
projector;
|
|
35
|
+
runStatus;
|
|
36
|
+
abortController;
|
|
37
|
+
cardDone;
|
|
38
|
+
cardDoneResolve;
|
|
39
|
+
readyResolve;
|
|
40
|
+
ready = new Promise((resolve) => { this.readyResolve = resolve; });
|
|
41
|
+
writer;
|
|
42
|
+
lastWriteError;
|
|
43
|
+
streamMessageId;
|
|
44
|
+
streamCardId;
|
|
45
|
+
queueRender = () => { };
|
|
46
|
+
done = false;
|
|
47
|
+
constructor(host, chatId, sourceMessageId, runId, showThinking) {
|
|
48
|
+
this.host = host;
|
|
49
|
+
this.chatId = chatId;
|
|
50
|
+
this.sourceMessageId = sourceMessageId;
|
|
51
|
+
this.runId = runId;
|
|
52
|
+
this.projector = createChannelStreamProjector({
|
|
53
|
+
showThinking,
|
|
54
|
+
maxProgressChars: FEISHU_LIVE_PROGRESS_CHARS,
|
|
55
|
+
});
|
|
56
|
+
this.runStatus = createFeishuRunStatus();
|
|
57
|
+
this.abortController = new AbortController();
|
|
58
|
+
this.cardDone = new Promise((resolve) => { this.cardDoneResolve = resolve; });
|
|
59
|
+
}
|
|
60
|
+
get signal() {
|
|
61
|
+
return this.abortController.signal;
|
|
62
|
+
}
|
|
63
|
+
get cardMessageId() {
|
|
64
|
+
return this.streamMessageId;
|
|
65
|
+
}
|
|
66
|
+
get cardInstanceId() {
|
|
67
|
+
return this.streamCardId;
|
|
68
|
+
}
|
|
69
|
+
async open() {
|
|
70
|
+
if (!this.host.channel)
|
|
71
|
+
return;
|
|
72
|
+
void this.host.channel.stream(this.chatId, {
|
|
73
|
+
markdown: async (s) => {
|
|
74
|
+
const cardId = s.cardId;
|
|
75
|
+
if (typeof cardId === "string" && cardId) {
|
|
76
|
+
this.streamCardId = cardId;
|
|
77
|
+
}
|
|
78
|
+
this.streamMessageId = s.messageId;
|
|
79
|
+
this.host.registerPendingStream(s.messageId, {
|
|
80
|
+
chatId: this.chatId,
|
|
81
|
+
sourceMessageId: this.sourceMessageId,
|
|
82
|
+
startedAt: new Date().toISOString(),
|
|
83
|
+
});
|
|
84
|
+
if (this.abortController.signal.aborted) {
|
|
85
|
+
this.cardDoneResolve();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
this.writer = new CoalescingCardWriter(async (snapshot) => {
|
|
89
|
+
if (this.abortController.signal.aborted)
|
|
90
|
+
return;
|
|
91
|
+
try {
|
|
92
|
+
if (s.setSnapshot)
|
|
93
|
+
await s.setSnapshot(snapshot.parts);
|
|
94
|
+
else
|
|
95
|
+
await s.setContent(snapshot.content);
|
|
96
|
+
this.lastWriteError = undefined;
|
|
97
|
+
setHttpWrite(this.runStatus, "healthy");
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
101
|
+
setHttpWrite(this.runStatus, "degraded");
|
|
102
|
+
if (snapshot.statusOnly) {
|
|
103
|
+
this.host.log(`飞书任务状态刷新失败(不影响 Agent 运行):${message}`);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this.lastWriteError = err;
|
|
107
|
+
this.host.log(`飞书卡片内容写入失败,等待重放:${message}`);
|
|
108
|
+
throw err;
|
|
109
|
+
}
|
|
110
|
+
}, undefined, (pending, next) => ({
|
|
111
|
+
...next,
|
|
112
|
+
statusOnly: pending.statusOnly && next.statusOnly,
|
|
113
|
+
}));
|
|
114
|
+
this.queueRender = (statusOnly) => {
|
|
115
|
+
const status = renderFeishuRunStatus(this.runStatus);
|
|
116
|
+
const snapshot = this.projector.snapshot();
|
|
117
|
+
const agentText = this.runStatus.state === "running"
|
|
118
|
+
? snapshot.liveText
|
|
119
|
+
: snapshot.finalText;
|
|
120
|
+
const body = (agentText);
|
|
121
|
+
this.writer?.enqueue({
|
|
122
|
+
content: status && body ? `${body}\n\n---\n\n${status}` : body || status,
|
|
123
|
+
parts: {
|
|
124
|
+
answer: this.runStatus.state === "running" ? snapshot.result : agentText,
|
|
125
|
+
progress: (this.runStatus.state === "running"
|
|
126
|
+
? [snapshot.thinking, snapshot.progress].filter(Boolean).join("\n\n") : ""),
|
|
127
|
+
status,
|
|
128
|
+
terminal: this.runStatus.state !== "running",
|
|
129
|
+
},
|
|
130
|
+
statusOnly,
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
this.queueRender(false);
|
|
134
|
+
this.readyResolve();
|
|
135
|
+
await this.cardDone;
|
|
136
|
+
},
|
|
137
|
+
}, { replyTo: this.sourceMessageId }).catch((err) => {
|
|
138
|
+
this.host.log(`卡片建卡失败: ${err instanceof Error ? err.message : String(err)}`);
|
|
139
|
+
this.readyResolve();
|
|
140
|
+
this.cardDoneResolve();
|
|
141
|
+
});
|
|
142
|
+
await this.ready;
|
|
143
|
+
}
|
|
144
|
+
async onAgentEvent(event) {
|
|
145
|
+
await this.ready;
|
|
146
|
+
if (this.abortController.signal.aborted)
|
|
147
|
+
return;
|
|
148
|
+
const recorded = recordFeishuRunActivity(this.runStatus, event);
|
|
149
|
+
if (event.type === "permission_request") {
|
|
150
|
+
void this.host
|
|
151
|
+
.sendMarkdown(this.chatId, `🔐 Agent 请求权限:**${event.title}**`, this.sourceMessageId)
|
|
152
|
+
.catch(() => { });
|
|
153
|
+
if (recorded)
|
|
154
|
+
this.queueRender(true);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const previous = this.projector.snapshot().liveText;
|
|
158
|
+
const next = this.projector.apply(event);
|
|
159
|
+
this.queueRender(previous === next.liveText);
|
|
160
|
+
}
|
|
161
|
+
async reconcileRun(snapshot, inboundState) {
|
|
162
|
+
await this.ready;
|
|
163
|
+
if (this.abortController.signal.aborted)
|
|
164
|
+
return;
|
|
165
|
+
setInboundWebSocket(this.runStatus, inboundState);
|
|
166
|
+
applyRunSnapshot(this.runStatus, snapshot);
|
|
167
|
+
this.queueRender(false);
|
|
168
|
+
await this.writer?.flush();
|
|
169
|
+
if (this.runStatus.state !== "running" && this.lastWriteError) {
|
|
170
|
+
throw this.lastWriteError;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async setCoreEventStreamState(state) {
|
|
174
|
+
await this.ready;
|
|
175
|
+
if (this.abortController.signal.aborted)
|
|
176
|
+
return;
|
|
177
|
+
setCoreEventStream(this.runStatus, state);
|
|
178
|
+
this.queueRender(true);
|
|
179
|
+
await this.writer?.flush();
|
|
180
|
+
}
|
|
181
|
+
async setInboundWebSocketState(state) {
|
|
182
|
+
await this.ready;
|
|
183
|
+
if (this.abortController.signal.aborted)
|
|
184
|
+
return;
|
|
185
|
+
setInboundWebSocket(this.runStatus, state);
|
|
186
|
+
this.queueRender(true);
|
|
187
|
+
await this.writer?.flush();
|
|
188
|
+
}
|
|
189
|
+
async finalize(terminalState) {
|
|
190
|
+
await this.ready;
|
|
191
|
+
if (this.done)
|
|
192
|
+
return;
|
|
193
|
+
finishFeishuRunStatus(this.runStatus, terminalState);
|
|
194
|
+
this.queueRender(false);
|
|
195
|
+
await this.writer?.flush();
|
|
196
|
+
if (this.lastWriteError)
|
|
197
|
+
throw this.lastWriteError;
|
|
198
|
+
this.done = true;
|
|
199
|
+
if (this.streamMessageId && !this.host.isDisconnecting()) {
|
|
200
|
+
this.host.clearPendingStream(this.streamMessageId);
|
|
201
|
+
}
|
|
202
|
+
this.cardDoneResolve();
|
|
203
|
+
}
|
|
204
|
+
abort() {
|
|
205
|
+
if (this.done)
|
|
206
|
+
return;
|
|
207
|
+
this.done = true;
|
|
208
|
+
this.abortController.abort();
|
|
209
|
+
this.cardDoneResolve();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function isTerminalRunSnapshot(snapshot) {
|
|
213
|
+
return snapshot !== null
|
|
214
|
+
&& snapshot.status !== "queued"
|
|
215
|
+
&& snapshot.status !== "running"
|
|
216
|
+
&& snapshot.status !== "waiting";
|
|
217
|
+
}
|
|
218
|
+
/** 每 Session 一个持久 events 订阅,单订阅统一路由 Turn / Run / Delivery。 */
|
|
219
|
+
export class FeishuSessionWatcher {
|
|
220
|
+
host;
|
|
221
|
+
ingress;
|
|
222
|
+
sessionId;
|
|
223
|
+
instanceId;
|
|
224
|
+
abortController = new AbortController();
|
|
225
|
+
afterSequence = 0;
|
|
226
|
+
started = false;
|
|
227
|
+
cards = new Map();
|
|
228
|
+
pendingTurns = new Map();
|
|
229
|
+
deliveries = new Map();
|
|
230
|
+
resumedCards = new Map();
|
|
231
|
+
fatalAgentErrorRuns = new Set();
|
|
232
|
+
permanentlyInvalidCardIds = new Set();
|
|
233
|
+
loggedPermanentCardIds = new Set();
|
|
234
|
+
constructor(host, ingress, sessionId, instanceId) {
|
|
235
|
+
this.host = host;
|
|
236
|
+
this.ingress = ingress;
|
|
237
|
+
this.sessionId = sessionId;
|
|
238
|
+
this.instanceId = instanceId;
|
|
239
|
+
}
|
|
240
|
+
/** 注入初始 cursor 后再启动,避免启动后登记 pending Turn/开卡前消费事件。 */
|
|
241
|
+
start(afterSequence) {
|
|
242
|
+
if (this.started)
|
|
243
|
+
return;
|
|
244
|
+
this.started = true;
|
|
245
|
+
this.afterSequence = afterSequence;
|
|
246
|
+
void this.run().catch((err) => {
|
|
247
|
+
this.host.log(`session watcher 退出: ${err instanceof Error ? err.message : String(err)}`);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
registerPendingTurn(turnId, turn) {
|
|
251
|
+
this.pendingTurns.set(turnId, turn);
|
|
252
|
+
}
|
|
253
|
+
/** 恢复 delivering 状态:按 surfaceMessageId 重放事件投影最终回答,终态更新原卡片。 */
|
|
254
|
+
resumeCardForRun(runId, surfaceMessageId, turnId, owner, showThinking, surfaceCardId) {
|
|
255
|
+
const existing = this.resumedCards.get(runId);
|
|
256
|
+
if (existing) {
|
|
257
|
+
this.deliveries.set(runId, { turnId, owner });
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const runStatus = createFeishuRunStatus();
|
|
261
|
+
this.resumedCards.set(runId, {
|
|
262
|
+
surfaceMessageId,
|
|
263
|
+
surfaceCardId,
|
|
264
|
+
projector: createChannelStreamProjector({
|
|
265
|
+
showThinking,
|
|
266
|
+
maxProgressChars: FEISHU_LIVE_PROGRESS_CHARS,
|
|
267
|
+
}),
|
|
268
|
+
runStatus,
|
|
269
|
+
resultRecovery: "pending",
|
|
270
|
+
projectionReady: false,
|
|
271
|
+
pendingReplayEvents: [],
|
|
272
|
+
projectedSequences: new Set(),
|
|
273
|
+
});
|
|
274
|
+
this.deliveries.set(runId, { turnId, owner });
|
|
275
|
+
}
|
|
276
|
+
async reconcileDelivery(delivery, turn, inboundState) {
|
|
277
|
+
if (delivery.surfaceCardId &&
|
|
278
|
+
this.permanentlyInvalidCardIds.has(delivery.surfaceCardId)) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (!delivery.runId) {
|
|
282
|
+
this.registerPendingTurn(delivery.turnId, turn);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
let card = this.cards.get(delivery.runId);
|
|
286
|
+
if (!delivery.surfaceMessageId) {
|
|
287
|
+
await this.openCardForRun(delivery.runId, turn);
|
|
288
|
+
card = this.cards.get(delivery.runId);
|
|
289
|
+
}
|
|
290
|
+
else if (!card) {
|
|
291
|
+
let surfaceCardId = delivery.surfaceCardId;
|
|
292
|
+
if (!surfaceCardId) {
|
|
293
|
+
try {
|
|
294
|
+
if (!this.host.resolveCardId) {
|
|
295
|
+
throw new Error("CardKit id resolver is unavailable");
|
|
296
|
+
}
|
|
297
|
+
surfaceCardId = await this.host.resolveCardId(delivery.surfaceMessageId);
|
|
298
|
+
const persisted = await this.ingress.ackDelivery(delivery.turnId, delivery.claimOwner ?? "", delivery.surfaceMessageId, surfaceCardId);
|
|
299
|
+
if (!persisted) {
|
|
300
|
+
throw new Error("resolved CardKit id could not be persisted");
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
this.host.log(JSON.stringify({
|
|
305
|
+
event: "feishu_card_id_recovery_failed",
|
|
306
|
+
channel: "feishu",
|
|
307
|
+
sessionId: this.sessionId,
|
|
308
|
+
runId: delivery.runId,
|
|
309
|
+
surfaceMessageId: delivery.surfaceMessageId,
|
|
310
|
+
message: error instanceof Error ? error.message : String(error),
|
|
311
|
+
}));
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
this.resumeCardForRun(delivery.runId, delivery.surfaceMessageId, delivery.turnId, delivery.claimOwner ?? "", turn.showThinking, surfaceCardId);
|
|
316
|
+
}
|
|
317
|
+
if (card) {
|
|
318
|
+
try {
|
|
319
|
+
if (delivery.runSnapshot) {
|
|
320
|
+
await card.reconcileRun(delivery.runSnapshot, inboundState);
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
await card.setInboundWebSocketState(inboundState);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
const messageId = card.cardMessageId;
|
|
328
|
+
if (messageId && this.recordPermanentCardFailure(delivery.runId, messageId, error)) {
|
|
329
|
+
card.abort();
|
|
330
|
+
this.cards.delete(delivery.runId);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
throw error;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const resumed = card ? undefined : this.resumedCards.get(delivery.runId);
|
|
337
|
+
if (resumed) {
|
|
338
|
+
setInboundWebSocket(resumed.runStatus, inboundState);
|
|
339
|
+
const terminal = isTerminalRunSnapshot(delivery.runSnapshot);
|
|
340
|
+
if (terminal || !resumed.projectionReady) {
|
|
341
|
+
await this.restorePersistedResult(delivery, resumed);
|
|
342
|
+
}
|
|
343
|
+
if (delivery.runSnapshot) {
|
|
344
|
+
applyRunSnapshot(resumed.runStatus, delivery.runSnapshot);
|
|
345
|
+
if ((delivery.runSnapshot.status === "running" ||
|
|
346
|
+
delivery.runSnapshot.status === "waiting") &&
|
|
347
|
+
delivery.runSnapshot.sessionActiveRunId !== delivery.runId) {
|
|
348
|
+
recordRunVerificationFailure(resumed.runStatus, "Run 与 Session activeRun 不一致");
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const written = await this.writeResumedCard(delivery.runId, resumed);
|
|
352
|
+
if (terminal && resumed.resultRecovery === "confirmed" && written) {
|
|
353
|
+
await this.completeDeliveryForRun(delivery.runId);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
async restorePersistedResult(delivery, resumed) {
|
|
358
|
+
if (resumed.resultRecovery === "confirmed")
|
|
359
|
+
return;
|
|
360
|
+
if (!delivery.runId || !this.ingress.replayEvents) {
|
|
361
|
+
this.logResultRecoveryFailure(delivery, "finite replay is unavailable");
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
try {
|
|
365
|
+
const events = await this.ingress.replayEvents(delivery.sessionId, {
|
|
366
|
+
afterSequence: delivery.acceptedSequence,
|
|
367
|
+
});
|
|
368
|
+
this.finishProjectionReplay(delivery.runId, resumed, events);
|
|
369
|
+
if (!isTerminalRunSnapshot(delivery.runSnapshot))
|
|
370
|
+
return;
|
|
371
|
+
const expectedTerminalState = delivery.runSnapshot?.status;
|
|
372
|
+
const hasMatchingTerminalEvent = events.some((event) => event.runId === delivery.runId
|
|
373
|
+
&& terminalStateForEvent(event.type) === expectedTerminalState);
|
|
374
|
+
if (!hasMatchingTerminalEvent) {
|
|
375
|
+
this.logResultRecoveryFailure(delivery, "matching terminal event is missing from finite replay");
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
resumed.resultRecovery = "confirmed";
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
this.logResultRecoveryFailure(delivery, error instanceof Error ? error.message : String(error));
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
finishProjectionReplay(runId, resumed, events) {
|
|
385
|
+
const ordered = [...events, ...resumed.pendingReplayEvents].sort((a, b) => a.sequence - b.sequence);
|
|
386
|
+
resumed.pendingReplayEvents = [];
|
|
387
|
+
resumed.projectionReady = true;
|
|
388
|
+
for (const event of ordered) {
|
|
389
|
+
this.applyRecoveredEvent(runId, resumed, event);
|
|
390
|
+
const terminal = event.runId === runId ? terminalStateForEvent(event.type) : undefined;
|
|
391
|
+
if (terminal) {
|
|
392
|
+
finishFeishuRunStatus(resumed.runStatus, terminal);
|
|
393
|
+
resumed.resultRecovery = "confirmed";
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
applyRecoveredEvent(runId, resumed, event) {
|
|
398
|
+
if (event.runId !== runId
|
|
399
|
+
|| resumed.projectedSequences.has(event.sequence))
|
|
400
|
+
return;
|
|
401
|
+
if (!resumed.projectionReady) {
|
|
402
|
+
resumed.pendingReplayEvents.push(event);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (event.type === "AGENT_EVENT") {
|
|
406
|
+
const agentEvent = event.payload.event;
|
|
407
|
+
if (!agentEvent)
|
|
408
|
+
return;
|
|
409
|
+
if (agentEvent.type === "error" && agentEvent.fatal) {
|
|
410
|
+
this.fatalAgentErrorRuns.add(runId);
|
|
411
|
+
}
|
|
412
|
+
recordFeishuRunActivity(resumed.runStatus, agentEvent);
|
|
413
|
+
resumed.projector.apply(agentEvent);
|
|
414
|
+
resumed.projectedSequences.add(event.sequence);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if (event.type === "STEP_FAILED" && !this.fatalAgentErrorRuns.has(runId)) {
|
|
418
|
+
resumed.projector.apply({
|
|
419
|
+
type: "error",
|
|
420
|
+
message: String(event.payload?.error ?? "Step failed"),
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
if (event.type === "STEP_FAILED") {
|
|
424
|
+
resumed.projectedSequences.add(event.sequence);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
logResultRecoveryFailure(delivery, message) {
|
|
428
|
+
this.host.log(JSON.stringify({
|
|
429
|
+
event: "feishu_terminal_result_recovery_failed",
|
|
430
|
+
channel: "feishu",
|
|
431
|
+
sessionId: delivery.sessionId,
|
|
432
|
+
runId: delivery.runId,
|
|
433
|
+
turnId: delivery.turnId,
|
|
434
|
+
message,
|
|
435
|
+
}));
|
|
436
|
+
}
|
|
437
|
+
async setInboundWebSocketState(state) {
|
|
438
|
+
await Promise.all([...this.cards.values()].map((card) => card.setInboundWebSocketState(state)));
|
|
439
|
+
for (const resumed of this.resumedCards.values()) {
|
|
440
|
+
setInboundWebSocket(resumed.runStatus, state);
|
|
441
|
+
await this.writeResumedCard(undefined, resumed);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
async setCoreEventStreamState(state) {
|
|
445
|
+
await Promise.all([...this.cards.values()].map((card) => card.setCoreEventStreamState(state)));
|
|
446
|
+
for (const resumed of this.resumedCards.values()) {
|
|
447
|
+
setCoreEventStream(resumed.runStatus, state);
|
|
448
|
+
await this.writeResumedCard(undefined, resumed);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
recordPermanentCardFailure(runId, messageId, error) {
|
|
452
|
+
if (classifyFeishuCardWriteError(error) !== "permanent")
|
|
453
|
+
return false;
|
|
454
|
+
this.permanentlyInvalidCardIds.add(messageId);
|
|
455
|
+
if (!this.loggedPermanentCardIds.has(messageId)) {
|
|
456
|
+
this.loggedPermanentCardIds.add(messageId);
|
|
457
|
+
this.host.log(JSON.stringify({
|
|
458
|
+
event: "feishu_card_permanently_invalid",
|
|
459
|
+
channel: "feishu",
|
|
460
|
+
sessionId: this.sessionId,
|
|
461
|
+
runId: runId ?? null,
|
|
462
|
+
surfaceMessageId: messageId,
|
|
463
|
+
errorClass: "permanent",
|
|
464
|
+
message: error instanceof Error ? error.message : String(error),
|
|
465
|
+
}));
|
|
466
|
+
}
|
|
467
|
+
return true;
|
|
468
|
+
}
|
|
469
|
+
async writeResumedCard(runId, resumed) {
|
|
470
|
+
if (this.permanentlyInvalidCardIds.has(resumed.surfaceCardId))
|
|
471
|
+
return false;
|
|
472
|
+
// Connection heartbeats must never replace an existing card with an empty projection.
|
|
473
|
+
if (!resumed.projectionReady && resumed.resultRecovery !== "confirmed")
|
|
474
|
+
return false;
|
|
475
|
+
if (resumed.runStatus.state !== "running" && resumed.resultRecovery !== "confirmed")
|
|
476
|
+
return false;
|
|
477
|
+
try {
|
|
478
|
+
await this.host.updateCard(resumed.surfaceCardId, this.resumedCardBody(resumed), resumed.surfaceMessageId);
|
|
479
|
+
setHttpWrite(resumed.runStatus, "healthy");
|
|
480
|
+
return true;
|
|
481
|
+
}
|
|
482
|
+
catch (error) {
|
|
483
|
+
if (this.recordPermanentCardFailure(runId, resumed.surfaceCardId, error)) {
|
|
484
|
+
setHttpWrite(resumed.runStatus, "unavailable");
|
|
485
|
+
return false;
|
|
486
|
+
}
|
|
487
|
+
setHttpWrite(resumed.runStatus, "degraded");
|
|
488
|
+
throw error;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
resumedCardBody(resumed) {
|
|
492
|
+
const status = renderFeishuRunStatus(resumed.runStatus);
|
|
493
|
+
const snapshot = resumed.projector.snapshot();
|
|
494
|
+
const agentText = resumed.runStatus.state === "running"
|
|
495
|
+
? snapshot.liveText
|
|
496
|
+
: resumed.resultRecovery === "pending"
|
|
497
|
+
? "⏳ 结果恢复中"
|
|
498
|
+
: snapshot.finalText;
|
|
499
|
+
return runCardJson({
|
|
500
|
+
answer: resumed.runStatus.state === "running" ? snapshot.result : agentText,
|
|
501
|
+
progress: (resumed.runStatus.state === "running"
|
|
502
|
+
? [snapshot.thinking, snapshot.progress].filter(Boolean).join("\n\n") : ""),
|
|
503
|
+
status,
|
|
504
|
+
terminal: resumed.runStatus.state !== "running",
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
async openCardForRun(runId, turn) {
|
|
508
|
+
if (this.cards.has(runId))
|
|
509
|
+
return;
|
|
510
|
+
const card = new FeishuRunCard(this.host, turn.chatId, turn.sourceMessageId, runId, turn.showThinking);
|
|
511
|
+
this.cards.set(runId, card);
|
|
512
|
+
const owner = `feishu:${this.instanceId}:${runId}`;
|
|
513
|
+
try {
|
|
514
|
+
const claimed = await this.ingress.claimDelivery(turn.turnId, owner);
|
|
515
|
+
if (!claimed) {
|
|
516
|
+
this.cards.delete(runId);
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
await card.open();
|
|
520
|
+
const cardId = card.cardMessageId;
|
|
521
|
+
const cardInstanceId = card.cardInstanceId;
|
|
522
|
+
if (!cardId || !cardInstanceId) {
|
|
523
|
+
throw new Error(`card did not produce a message id for run ${runId}`);
|
|
524
|
+
}
|
|
525
|
+
const acked = await this.ingress.ackDelivery(turn.turnId, owner, cardId, cardInstanceId);
|
|
526
|
+
if (!acked) {
|
|
527
|
+
throw new Error(`ack delivery failed for run ${runId}`);
|
|
528
|
+
}
|
|
529
|
+
this.deliveries.set(runId, { turnId: turn.turnId, owner });
|
|
530
|
+
}
|
|
531
|
+
catch (err) {
|
|
532
|
+
this.cards.delete(runId);
|
|
533
|
+
card.abort();
|
|
534
|
+
throw err;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
async run() {
|
|
538
|
+
while (!this.abortController.signal.aborted) {
|
|
539
|
+
try {
|
|
540
|
+
const pending = [...this.resumedCards.entries()].filter(([, card]) => !card.projectionReady);
|
|
541
|
+
if (pending.length && this.ingress.replayEvents) {
|
|
542
|
+
const history = await this.ingress.replayEvents(this.sessionId, { afterSequence: this.afterSequence });
|
|
543
|
+
for (const [runId, card] of pending) {
|
|
544
|
+
this.finishProjectionReplay(runId, card, history);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
await this.setCoreEventStreamState("connected").catch(() => { });
|
|
548
|
+
for await (const event of this.ingress.events(this.sessionId, {
|
|
549
|
+
afterSequence: this.afterSequence,
|
|
550
|
+
signal: this.abortController.signal,
|
|
551
|
+
})) {
|
|
552
|
+
await this.handle(event);
|
|
553
|
+
// 状态转换成功后才推进 cursor;失败会抛错并由外层按旧 cursor 重连重放。
|
|
554
|
+
this.afterSequence = event.sequence;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
catch (err) {
|
|
558
|
+
if (this.abortController.signal.aborted)
|
|
559
|
+
return;
|
|
560
|
+
await this.setCoreEventStreamState("reconnecting").catch(() => { });
|
|
561
|
+
this.host.log(`session watcher 断线,按 sequence ${this.afterSequence} 重连:${err instanceof Error ? err.message : String(err)}`);
|
|
562
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
async handle(event) {
|
|
567
|
+
if (event.type === "TURN_DISPATCHED" && event.runId && event.target) {
|
|
568
|
+
const turn = this.pendingTurns.get(event.target);
|
|
569
|
+
if (turn) {
|
|
570
|
+
await this.openCardForRun(event.runId, turn);
|
|
571
|
+
this.pendingTurns.delete(event.target);
|
|
572
|
+
}
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
if (event.type === "AGENT_EVENT" && event.runId) {
|
|
576
|
+
const card = this.cards.get(event.runId);
|
|
577
|
+
const resumed = this.resumedCards.get(event.runId);
|
|
578
|
+
const agentEvent = event.payload.event;
|
|
579
|
+
if (agentEvent?.type === "error" && agentEvent.fatal && event.runId) {
|
|
580
|
+
this.fatalAgentErrorRuns.add(event.runId);
|
|
581
|
+
}
|
|
582
|
+
if (resumed && agentEvent) {
|
|
583
|
+
this.applyRecoveredEvent(event.runId, resumed, event);
|
|
584
|
+
}
|
|
585
|
+
if (card && agentEvent && agentEvent.type !== "done") {
|
|
586
|
+
await card.onAgentEvent(agentEvent);
|
|
587
|
+
}
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
if (event.type === "STEP_FAILED" && event.runId) {
|
|
591
|
+
const message = String(event.payload?.error ?? "Step failed");
|
|
592
|
+
if (!this.fatalAgentErrorRuns.has(event.runId)) {
|
|
593
|
+
const card = this.cards.get(event.runId);
|
|
594
|
+
if (card)
|
|
595
|
+
await card.onAgentEvent({ type: "error", message });
|
|
596
|
+
}
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
const terminalState = terminalStateForEvent(event.type);
|
|
600
|
+
if (terminalState && event.runId) {
|
|
601
|
+
const card = this.cards.get(event.runId);
|
|
602
|
+
if (card) {
|
|
603
|
+
try {
|
|
604
|
+
await card.finalize(terminalState);
|
|
605
|
+
this.cards.delete(event.runId);
|
|
606
|
+
}
|
|
607
|
+
catch (error) {
|
|
608
|
+
const messageId = card.cardMessageId;
|
|
609
|
+
if (messageId && this.recordPermanentCardFailure(event.runId, messageId, error)) {
|
|
610
|
+
card.abort();
|
|
611
|
+
this.cards.delete(event.runId);
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
throw error;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
const resumed = this.resumedCards.get(event.runId);
|
|
618
|
+
if (resumed) {
|
|
619
|
+
if (!resumed.projectionReady) {
|
|
620
|
+
resumed.pendingReplayEvents.push(event);
|
|
621
|
+
if (this.ingress.replayEvents)
|
|
622
|
+
return;
|
|
623
|
+
// Legacy ingress replays its ordered event stream through the terminal event.
|
|
624
|
+
this.finishProjectionReplay(event.runId, resumed, []);
|
|
625
|
+
}
|
|
626
|
+
resumed.resultRecovery = "confirmed";
|
|
627
|
+
finishFeishuRunStatus(resumed.runStatus, terminalState);
|
|
628
|
+
const written = await this.writeResumedCard(event.runId, resumed);
|
|
629
|
+
if (!written)
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
await this.completeDeliveryForRun(event.runId);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
async completeDeliveryForRun(runId) {
|
|
636
|
+
const delivery = this.deliveries.get(runId);
|
|
637
|
+
if (!delivery)
|
|
638
|
+
return;
|
|
639
|
+
const completed = await this.ingress.completeDelivery(delivery.turnId, delivery.owner);
|
|
640
|
+
if (!completed) {
|
|
641
|
+
throw new Error(`complete delivery returned false for run ${runId}`);
|
|
642
|
+
}
|
|
643
|
+
this.deliveries.delete(runId);
|
|
644
|
+
this.resumedCards.delete(runId);
|
|
645
|
+
}
|
|
646
|
+
abort() {
|
|
647
|
+
this.abortController.abort();
|
|
648
|
+
for (const card of this.cards.values())
|
|
649
|
+
card.abort();
|
|
650
|
+
this.cards.clear();
|
|
651
|
+
this.resumedCards.clear();
|
|
652
|
+
this.pendingTurns.clear();
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
//# sourceMappingURL=session-watcher.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codebridge/channel-feishu",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@codebridge/core": "0.1.0",
|
|
16
|
+
"@codebridge/router": "0.1.0",
|
|
17
|
+
"@larksuiteoapi/node-sdk": "1.68.0"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Serializes Telegram edits and collapses queued snapshots to the latest text. */
|
|
2
|
+
export declare class CoalescingMessageWriter {
|
|
3
|
+
private readonly write;
|
|
4
|
+
private readonly onError?;
|
|
5
|
+
private pending;
|
|
6
|
+
private draining;
|
|
7
|
+
private closed;
|
|
8
|
+
constructor(write: (text: string) => Promise<void>, onError?: ((error: unknown) => void) | undefined);
|
|
9
|
+
enqueue(text: string): void;
|
|
10
|
+
flush(): Promise<void>;
|
|
11
|
+
close(): void;
|
|
12
|
+
private drain;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=coalescing-message-writer.d.ts.map
|