@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,290 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { appendJsonl } from "@codebridge/core";
|
|
3
|
+
import { RunnerClient, } from "@codebridge/runner-client";
|
|
4
|
+
import { SessionRouter } from "./session-router.js";
|
|
5
|
+
export class RunOrchestrator {
|
|
6
|
+
options;
|
|
7
|
+
router;
|
|
8
|
+
client;
|
|
9
|
+
activeChatRuns = new Map();
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.options = options;
|
|
12
|
+
this.router = new SessionRouter(options.dataDir);
|
|
13
|
+
this.router.initFromConfig(options.config);
|
|
14
|
+
this.client = new RunnerClient({
|
|
15
|
+
baseUrl: options.config.runner.url,
|
|
16
|
+
token: options.config.runner.token,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
updateConfig(config) {
|
|
20
|
+
this.options.config = config;
|
|
21
|
+
this.router.initFromConfig(config);
|
|
22
|
+
}
|
|
23
|
+
chatRunKey(chatId, topicId) {
|
|
24
|
+
return `${chatId}|${topicId ?? ""}`;
|
|
25
|
+
}
|
|
26
|
+
hasActiveRun(chatId, topicId) {
|
|
27
|
+
return this.activeChatRuns.has(this.chatRunKey(chatId, topicId));
|
|
28
|
+
}
|
|
29
|
+
/** 活跃任务已运行的毫秒数;无活跃任务时返回 undefined */
|
|
30
|
+
activeRunElapsedMs(chatId, topicId) {
|
|
31
|
+
const active = this.activeChatRuns.get(this.chatRunKey(chatId, topicId));
|
|
32
|
+
return active ? Date.now() - active.startedAt : undefined;
|
|
33
|
+
}
|
|
34
|
+
activeRunStatus(chatId, topicId) {
|
|
35
|
+
const active = this.activeChatRuns.get(this.chatRunKey(chatId, topicId));
|
|
36
|
+
if (!active)
|
|
37
|
+
return undefined;
|
|
38
|
+
return {
|
|
39
|
+
runId: active.runId,
|
|
40
|
+
startedAt: active.startedAt,
|
|
41
|
+
lastActivityAt: active.lastActivityAt,
|
|
42
|
+
currentPhase: active.currentPhase,
|
|
43
|
+
...(active.lastCheckpoint
|
|
44
|
+
? { lastCheckpoint: active.lastCheckpoint }
|
|
45
|
+
: {}),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async cancelActiveForChat(chatId, topicId) {
|
|
49
|
+
const key = this.chatRunKey(chatId, topicId);
|
|
50
|
+
const active = this.activeChatRuns.get(key);
|
|
51
|
+
if (!active)
|
|
52
|
+
return false;
|
|
53
|
+
active.controller.abort();
|
|
54
|
+
await this.client.cancel(active.runId).catch(() => { });
|
|
55
|
+
await active.finished;
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
async steerActiveForChat(chatId, topicId, prompt) {
|
|
59
|
+
const active = this.activeChatRuns.get(this.chatRunKey(chatId, topicId));
|
|
60
|
+
if (!active)
|
|
61
|
+
return { ok: false, error: "当前没有正在运行的任务" };
|
|
62
|
+
return this.client.steer(active.runId, prompt);
|
|
63
|
+
}
|
|
64
|
+
async *runAgent(chatId, topicId, prompt, attachments) {
|
|
65
|
+
await this.cancelActiveForChat(chatId, topicId);
|
|
66
|
+
const sessionKey = this.router.buildSessionKey(chatId, topicId);
|
|
67
|
+
const runOpts = this.router.resolveRunOptions(chatId, topicId, this.options.config);
|
|
68
|
+
// 不再从 sessions.json 读取续聊 session(Task 12)。
|
|
69
|
+
const resumeSessionId = undefined;
|
|
70
|
+
const runId = this.router.newRunId();
|
|
71
|
+
const chatKey = this.chatRunKey(chatId, topicId);
|
|
72
|
+
const controller = new AbortController();
|
|
73
|
+
let resolveFinished;
|
|
74
|
+
const finished = new Promise((resolve) => {
|
|
75
|
+
resolveFinished = resolve;
|
|
76
|
+
});
|
|
77
|
+
const startedAt = Date.now();
|
|
78
|
+
this.activeChatRuns.set(chatKey, {
|
|
79
|
+
runId,
|
|
80
|
+
controller,
|
|
81
|
+
startedAt,
|
|
82
|
+
lastActivityAt: startedAt,
|
|
83
|
+
currentPhase: "任务启动",
|
|
84
|
+
finished,
|
|
85
|
+
});
|
|
86
|
+
const logPath = path.join(this.options.dataDir, "logs", `${new Date().toISOString().slice(0, 10)}.jsonl`);
|
|
87
|
+
appendJsonl(logPath, {
|
|
88
|
+
event: "intake",
|
|
89
|
+
runId,
|
|
90
|
+
chatId,
|
|
91
|
+
topicId,
|
|
92
|
+
prompt: prompt.slice(0, 200),
|
|
93
|
+
ts: new Date().toISOString(),
|
|
94
|
+
});
|
|
95
|
+
const request = {
|
|
96
|
+
runId,
|
|
97
|
+
sessionKey,
|
|
98
|
+
prompt,
|
|
99
|
+
attachments,
|
|
100
|
+
resumeSessionId,
|
|
101
|
+
model: runOpts.model,
|
|
102
|
+
effort: runOpts.effort,
|
|
103
|
+
mode: runOpts.mode,
|
|
104
|
+
claudePermissionMode: runOpts.claudePermissionMode,
|
|
105
|
+
additionalDirectories: runOpts.additionalDirectories,
|
|
106
|
+
acpConfig: runOpts.acpConfig,
|
|
107
|
+
};
|
|
108
|
+
let sessionId;
|
|
109
|
+
let stopped = false;
|
|
110
|
+
let loggedDone = false;
|
|
111
|
+
const logDone = () => {
|
|
112
|
+
if (loggedDone)
|
|
113
|
+
return;
|
|
114
|
+
loggedDone = true;
|
|
115
|
+
appendJsonl(logPath, {
|
|
116
|
+
event: "done",
|
|
117
|
+
runId,
|
|
118
|
+
sessionId,
|
|
119
|
+
stopped: controller.signal.aborted || stopped,
|
|
120
|
+
ts: new Date().toISOString(),
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
const persistSession = (id) => {
|
|
124
|
+
if (!id)
|
|
125
|
+
return;
|
|
126
|
+
sessionId = id;
|
|
127
|
+
};
|
|
128
|
+
try {
|
|
129
|
+
try {
|
|
130
|
+
for await (const event of this.client.run(request, {
|
|
131
|
+
signal: controller.signal,
|
|
132
|
+
})) {
|
|
133
|
+
if (controller.signal.aborted) {
|
|
134
|
+
stopped = true;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
this.options.onEvent?.(runId, event);
|
|
138
|
+
const active = this.activeChatRuns.get(chatKey);
|
|
139
|
+
if (active?.runId === runId) {
|
|
140
|
+
let phase;
|
|
141
|
+
switch (event.type) {
|
|
142
|
+
case "text_delta":
|
|
143
|
+
phase =
|
|
144
|
+
event.phase === "commentary" ? "任务检查点" : "生成回复";
|
|
145
|
+
if (event.phase === "commentary") {
|
|
146
|
+
const sameMessage = Boolean(event.messageId) &&
|
|
147
|
+
active.checkpointMessageId === event.messageId;
|
|
148
|
+
active.checkpointText = sameMessage
|
|
149
|
+
? `${active.checkpointText ?? ""}${event.text}`
|
|
150
|
+
: event.text;
|
|
151
|
+
active.checkpointMessageId = event.messageId;
|
|
152
|
+
const checkpoint = active.checkpointText
|
|
153
|
+
.replace(/\s+/g, " ")
|
|
154
|
+
.trim();
|
|
155
|
+
if (checkpoint) {
|
|
156
|
+
active.lastCheckpoint =
|
|
157
|
+
checkpoint.length > 240
|
|
158
|
+
? `${checkpoint.slice(0, 239)}…`
|
|
159
|
+
: checkpoint;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
case "thought_delta":
|
|
164
|
+
phase = "分析任务";
|
|
165
|
+
break;
|
|
166
|
+
case "tool_start":
|
|
167
|
+
phase = `工具执行:${event.name}`;
|
|
168
|
+
break;
|
|
169
|
+
case "tool_update":
|
|
170
|
+
phase = event.name
|
|
171
|
+
? `工具执行:${event.name}`
|
|
172
|
+
: active.currentPhase;
|
|
173
|
+
break;
|
|
174
|
+
case "tool_end":
|
|
175
|
+
phase = event.name ? `工具完成:${event.name}` : "工具完成";
|
|
176
|
+
break;
|
|
177
|
+
case "plan":
|
|
178
|
+
case "plan_update":
|
|
179
|
+
case "plan_removed":
|
|
180
|
+
phase = "更新计划";
|
|
181
|
+
break;
|
|
182
|
+
case "permission_request":
|
|
183
|
+
phase = "等待权限确认";
|
|
184
|
+
break;
|
|
185
|
+
default:
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
if (phase) {
|
|
189
|
+
active.lastActivityAt = Date.now();
|
|
190
|
+
active.currentPhase = phase;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (event.type === "session") {
|
|
194
|
+
persistSession(event.sessionId);
|
|
195
|
+
}
|
|
196
|
+
yield event;
|
|
197
|
+
if (event.type === "done")
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
if (controller.signal.aborted) {
|
|
203
|
+
stopped = true;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
207
|
+
yield { type: "error", message, fatal: true };
|
|
208
|
+
yield { type: "done", exitCode: 1 };
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// 不再写 sessions.json(Task 12);session 绑定由 Catalog 权威。
|
|
212
|
+
if (stopped) {
|
|
213
|
+
yield { type: "error", message: "任务已停止", fatal: false };
|
|
214
|
+
yield { type: "done", exitCode: 130 };
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
finally {
|
|
218
|
+
if (this.activeChatRuns.get(chatKey)?.runId === runId) {
|
|
219
|
+
this.activeChatRuns.delete(chatKey);
|
|
220
|
+
}
|
|
221
|
+
logDone();
|
|
222
|
+
resolveFinished();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async doctor() {
|
|
226
|
+
return this.client.doctor();
|
|
227
|
+
}
|
|
228
|
+
async health() {
|
|
229
|
+
return this.client.health();
|
|
230
|
+
}
|
|
231
|
+
async authorizeDirectory(directory) {
|
|
232
|
+
return this.client.authorizeDirectory(directory);
|
|
233
|
+
}
|
|
234
|
+
async listSessions(chatId, topicId, options) {
|
|
235
|
+
const key = this.router.buildSessionKey(chatId, topicId);
|
|
236
|
+
const result = await this.client.listSessions(key.backendId, key.cwd, options);
|
|
237
|
+
if (result.error) {
|
|
238
|
+
throw new Error(result.error);
|
|
239
|
+
}
|
|
240
|
+
return result.sessions;
|
|
241
|
+
}
|
|
242
|
+
/** prompt_feishu:把 /approve /deny 转给当前 run 挂起的权限请求 */
|
|
243
|
+
async resolveActivePermission(chatId, topicId, approve) {
|
|
244
|
+
const active = this.activeChatRuns.get(this.chatRunKey(chatId, topicId));
|
|
245
|
+
if (!active)
|
|
246
|
+
return false;
|
|
247
|
+
return this.client.resolvePermission(active.runId, approve);
|
|
248
|
+
}
|
|
249
|
+
async listConfigOptions(chatId, topicId) {
|
|
250
|
+
const key = this.router.buildSessionKey(chatId, topicId);
|
|
251
|
+
const result = await this.client.listConfigOptions(key.backendId, key.cwd);
|
|
252
|
+
if (result.error)
|
|
253
|
+
throw new Error(result.error);
|
|
254
|
+
return result.options;
|
|
255
|
+
}
|
|
256
|
+
async closeSession(chatId, topicId, sessionId) {
|
|
257
|
+
return this.manageSession("close", chatId, topicId, sessionId);
|
|
258
|
+
}
|
|
259
|
+
async deleteSession(chatId, topicId, sessionId) {
|
|
260
|
+
return this.manageSession("delete", chatId, topicId, sessionId);
|
|
261
|
+
}
|
|
262
|
+
async manageSession(action, chatId, topicId, sessionId) {
|
|
263
|
+
const key = this.router.buildSessionKey(chatId, topicId);
|
|
264
|
+
// 不再用 sessions.json 判断「当前槽位 session 是否运行中」(Task 12);
|
|
265
|
+
// 运行中保护由 provider lease + runner 侧处理。
|
|
266
|
+
const result = action === "close"
|
|
267
|
+
? await this.client.closeSession(key.backendId, key.cwd, sessionId)
|
|
268
|
+
: await this.client.deleteSession(key.backendId, key.cwd, sessionId);
|
|
269
|
+
return result;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
export function agentEventToMarkdown(event) {
|
|
273
|
+
switch (event.type) {
|
|
274
|
+
case "text_delta":
|
|
275
|
+
return event.text;
|
|
276
|
+
case "tool_start":
|
|
277
|
+
return `\n🔧 \`${event.name}\` …\n`;
|
|
278
|
+
case "tool_update":
|
|
279
|
+
return `\n↳ \`${event.name ?? "tool"}\`${event.status ? ` (${event.status})` : ""}\n`;
|
|
280
|
+
case "tool_end":
|
|
281
|
+
return `\n✓ \`${event.name ?? "tool"}\`\n`;
|
|
282
|
+
case "error":
|
|
283
|
+
return `\n❌ ${event.message}\n`;
|
|
284
|
+
case "done":
|
|
285
|
+
return event.exitCode === 0 ? "" : `\n(退出码 ${event.exitCode})\n`;
|
|
286
|
+
default:
|
|
287
|
+
return "";
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=orchestrator.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CliSessionSummary } from "@codebridge/runner-client";
|
|
2
|
+
export declare function isNoisePreview(text: string): boolean;
|
|
3
|
+
export declare function cleanSessionPreview(preview: string, max?: number): string;
|
|
4
|
+
/** 列表里显示项目名:优先最后 1–2 段有意义路径 */
|
|
5
|
+
export declare function compactProjectPath(cwd: string): string;
|
|
6
|
+
export declare function formatElapsed(ms: number): string;
|
|
7
|
+
export declare function formatWhenShort(iso: string): string;
|
|
8
|
+
export interface SessionListFormatOptions {
|
|
9
|
+
backendId: string;
|
|
10
|
+
scopeCwd: string;
|
|
11
|
+
listAll: boolean;
|
|
12
|
+
total: number;
|
|
13
|
+
showCwd: boolean;
|
|
14
|
+
displayLimit?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare function formatSessionListHeader(options: SessionListFormatOptions): string;
|
|
17
|
+
export declare function formatSessionLine(session: CliSessionSummary, index: number, showCwd: boolean): string;
|
|
18
|
+
export declare function formatSessionListFooter(boundSessionId?: string): string;
|
|
19
|
+
//# sourceMappingURL=session-list-format.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
export function isNoisePreview(text) {
|
|
3
|
+
const t = text.trim();
|
|
4
|
+
if (!t || t === "(no preview)")
|
|
5
|
+
return true;
|
|
6
|
+
if (/^\d+$/.test(t))
|
|
7
|
+
return true;
|
|
8
|
+
if (t.startsWith("Caveat: The messages below"))
|
|
9
|
+
return true;
|
|
10
|
+
if (t.startsWith("<local-command"))
|
|
11
|
+
return true;
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
export function cleanSessionPreview(preview, max = 64) {
|
|
15
|
+
const one = preview.replace(/\s+/g, " ").trim();
|
|
16
|
+
if (isNoisePreview(one))
|
|
17
|
+
return "(无有效预览)";
|
|
18
|
+
return one.length <= max ? one : `${one.slice(0, max)}…`;
|
|
19
|
+
}
|
|
20
|
+
/** 列表里显示项目名:优先最后 1–2 段有意义路径 */
|
|
21
|
+
export function compactProjectPath(cwd) {
|
|
22
|
+
const parts = path.resolve(cwd).split(path.sep).filter(Boolean);
|
|
23
|
+
if (parts.length === 0)
|
|
24
|
+
return cwd;
|
|
25
|
+
if (parts.length <= 2)
|
|
26
|
+
return parts.join(path.sep);
|
|
27
|
+
const last = parts[parts.length - 1];
|
|
28
|
+
const prev = parts[parts.length - 2];
|
|
29
|
+
if (prev === "com" || prev.includes(".")) {
|
|
30
|
+
return last;
|
|
31
|
+
}
|
|
32
|
+
return `${prev}${path.sep}${last}`;
|
|
33
|
+
}
|
|
34
|
+
export function formatElapsed(ms) {
|
|
35
|
+
const totalSeconds = Math.max(0, Math.floor(ms / 1000));
|
|
36
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
37
|
+
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
38
|
+
const seconds = totalSeconds % 60;
|
|
39
|
+
if (hours > 0)
|
|
40
|
+
return `${hours} 小时 ${minutes} 分`;
|
|
41
|
+
if (minutes > 0)
|
|
42
|
+
return `${minutes} 分 ${seconds} 秒`;
|
|
43
|
+
return `${seconds} 秒`;
|
|
44
|
+
}
|
|
45
|
+
export function formatWhenShort(iso) {
|
|
46
|
+
try {
|
|
47
|
+
const d = new Date(iso);
|
|
48
|
+
const month = d.getMonth() + 1;
|
|
49
|
+
const day = d.getDate();
|
|
50
|
+
const hour = String(d.getHours()).padStart(2, "0");
|
|
51
|
+
const minute = String(d.getMinutes()).padStart(2, "0");
|
|
52
|
+
return `${month}/${day} ${hour}:${minute}`;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return iso;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export function formatSessionListHeader(options) {
|
|
59
|
+
const scope = compactProjectPath(options.scopeCwd);
|
|
60
|
+
const scopeLabel = options.listAll
|
|
61
|
+
? "全部目录"
|
|
62
|
+
: `\`${scope}\` 及子目录`;
|
|
63
|
+
const countNote = options.total > (options.displayLimit ?? options.total)
|
|
64
|
+
? `(显示最近 ${options.displayLimit} / 共 ${options.total} 条)`
|
|
65
|
+
: `(共 ${options.total} 条)`;
|
|
66
|
+
return [
|
|
67
|
+
`**${options.backendId}** 本地 session ${countNote}`,
|
|
68
|
+
`范围:${scopeLabel}`,
|
|
69
|
+
].join("\n");
|
|
70
|
+
}
|
|
71
|
+
export function formatSessionLine(session, index, showCwd) {
|
|
72
|
+
const id = session.id.slice(0, 8);
|
|
73
|
+
const when = formatWhenShort(session.updatedAt);
|
|
74
|
+
const preview = cleanSessionPreview(session.preview);
|
|
75
|
+
if (!showCwd) {
|
|
76
|
+
return [
|
|
77
|
+
`**${index + 1}.** \`${id}\` · ${when}${session.additionalDirectories?.length ? ` · roots +${session.additionalDirectories.length}` : ""}`,
|
|
78
|
+
` ${preview}`,
|
|
79
|
+
].join("\n");
|
|
80
|
+
}
|
|
81
|
+
const project = compactProjectPath(session.cwd);
|
|
82
|
+
return [
|
|
83
|
+
`**${index + 1}.** \`${id}\` · ${when} · ${project}${session.additionalDirectories?.length ? ` · roots +${session.additionalDirectories.length}` : ""}`,
|
|
84
|
+
` ${preview}`,
|
|
85
|
+
].join("\n");
|
|
86
|
+
}
|
|
87
|
+
export function formatSessionListFooter(boundSessionId) {
|
|
88
|
+
const lines = [
|
|
89
|
+
"---",
|
|
90
|
+
"回复 `/resume <序号>` 绑定 · `/resume last` 选最近一条",
|
|
91
|
+
];
|
|
92
|
+
if (boundSessionId) {
|
|
93
|
+
lines.push(`当前已绑定:\`${boundSessionId.slice(0, 8)}…\``);
|
|
94
|
+
}
|
|
95
|
+
return lines.join("\n");
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=session-list-format.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ChannelCommandContext, SessionAutoRotateConfig } from "@codebridge/core";
|
|
2
|
+
/**
|
|
3
|
+
* Decide whether the next channel message should start a fresh provider session
|
|
4
|
+
* instead of resuming the bound one. Returns a user-facing reason, or undefined.
|
|
5
|
+
* Never rotates a busy session: queued turns would be left paused on the old one.
|
|
6
|
+
*/
|
|
7
|
+
export declare function sessionRotationReason(context: ChannelCommandContext, policy: SessionAutoRotateConfig | undefined, now: number): string | undefined;
|
|
8
|
+
export declare function sessionRotationNotice(reason: string): string;
|
|
9
|
+
//# sourceMappingURL=session-rotation.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const DEFAULT_IDLE_HOURS = 12;
|
|
2
|
+
const DEFAULT_MAX_CONTEXT_RATIO = 0.5;
|
|
3
|
+
/**
|
|
4
|
+
* Decide whether the next channel message should start a fresh provider session
|
|
5
|
+
* instead of resuming the bound one. Returns a user-facing reason, or undefined.
|
|
6
|
+
* Never rotates a busy session: queued turns would be left paused on the old one.
|
|
7
|
+
*/
|
|
8
|
+
export function sessionRotationReason(context, policy, now) {
|
|
9
|
+
if (policy?.enabled === false || !context.sessionId)
|
|
10
|
+
return undefined;
|
|
11
|
+
if (context.activeRunId || (context.queuedTurns ?? 0) > 0)
|
|
12
|
+
return undefined;
|
|
13
|
+
const ratio = policy?.maxContextRatio ?? DEFAULT_MAX_CONTEXT_RATIO;
|
|
14
|
+
const { contextUsed: used, contextSize: size, contextFirstUsed: first } = context;
|
|
15
|
+
// Only rotate a session that grew past the limit itself. One that started above it was
|
|
16
|
+
// resumed on purpose (/resume) or carries a huge base prompt; rotating it would loop.
|
|
17
|
+
const grewPastLimit = first === null || first === undefined || first / (size || 1) < ratio;
|
|
18
|
+
if (used && size && used / size >= ratio && grewPastLimit) {
|
|
19
|
+
return `上一会话上下文已用 ${Math.round((used / size) * 100)}%(${Math.round(used / 1000)}k / ${Math.round(size / 1000)}k tokens)`;
|
|
20
|
+
}
|
|
21
|
+
const idleMs = (policy?.idleHours ?? DEFAULT_IDLE_HOURS) * 3_600_000;
|
|
22
|
+
const last = context.lastActivityAt ? Date.parse(context.lastActivityAt) : Number.NaN;
|
|
23
|
+
if (idleMs > 0 && Number.isFinite(last) && now - last >= idleMs) {
|
|
24
|
+
return `上一会话已闲置 ${Math.floor((now - last) / 3_600_000)} 小时`;
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
export function sessionRotationNotice(reason) {
|
|
29
|
+
return `🆕 ${reason},已自动开启新会话,本条消息不带之前的上下文。需要接着旧会话可发 /resume。`;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=session-rotation.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type AppConfig, type ClaudePermissionMode, type SessionKey } from "@codebridge/core";
|
|
2
|
+
export interface ChatBinding {
|
|
3
|
+
backendId: string;
|
|
4
|
+
cwd: string;
|
|
5
|
+
topicId?: string;
|
|
6
|
+
model?: string;
|
|
7
|
+
effort?: string;
|
|
8
|
+
mode?: string;
|
|
9
|
+
claudePermissionMode?: ClaudePermissionMode;
|
|
10
|
+
additionalDirectories?: string[];
|
|
11
|
+
acpConfig?: Record<string, string | boolean>;
|
|
12
|
+
/** 卡片是否展示思考/工具过程;缺省=true(显示)。纯展示偏好,切 backend 不清除 */
|
|
13
|
+
showThinking?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface ResolvedRunOptions {
|
|
16
|
+
model?: string;
|
|
17
|
+
effort?: string;
|
|
18
|
+
mode?: string;
|
|
19
|
+
claudePermissionMode?: ClaudePermissionMode;
|
|
20
|
+
additionalDirectories?: string[];
|
|
21
|
+
acpConfig?: Record<string, string | boolean>;
|
|
22
|
+
}
|
|
23
|
+
export declare class SessionRouter {
|
|
24
|
+
private readonly workspaces;
|
|
25
|
+
private readonly bindings;
|
|
26
|
+
private readonly generations;
|
|
27
|
+
constructor(dataDir: string);
|
|
28
|
+
private bindingKey;
|
|
29
|
+
private slotKey;
|
|
30
|
+
/** 当前槽位(backend+cwd)指向第几代 Session,默认 0。 */
|
|
31
|
+
getSlotGeneration(chatId: string, topicId?: string): number;
|
|
32
|
+
/** /new 对当前槽位 +1,返回新 generation。 */
|
|
33
|
+
incrementSlotGeneration(chatId: string, topicId?: string): number;
|
|
34
|
+
/** 供 bridge 组装 ingress 消息的槽位描述(agent/cwd 已规范化)。 */
|
|
35
|
+
buildSlot(chatId: string, topicId?: string): {
|
|
36
|
+
agentId: string;
|
|
37
|
+
workspaceKey: string;
|
|
38
|
+
generation: number;
|
|
39
|
+
};
|
|
40
|
+
getBinding(chatId: string, topicId?: string): ChatBinding;
|
|
41
|
+
setBinding(chatId: string, binding: Partial<ChatBinding>, topicId?: string): void;
|
|
42
|
+
clearModel(chatId: string, topicId?: string): void;
|
|
43
|
+
clearEffort(chatId: string, topicId?: string): void;
|
|
44
|
+
clearClaudePermissionMode(chatId: string, topicId?: string): void;
|
|
45
|
+
clearMode(chatId: string, topicId?: string): void;
|
|
46
|
+
clearAcpConfig(chatId: string, topicId?: string): void;
|
|
47
|
+
/** 切换 backend 时清除 model/effort/permission 会话覆盖 */
|
|
48
|
+
clearRunOverrides(chatId: string, topicId?: string): void;
|
|
49
|
+
resolveRunOptions(chatId: string, topicId: string | undefined, config: AppConfig): ResolvedRunOptions;
|
|
50
|
+
private defaultCwd;
|
|
51
|
+
private config;
|
|
52
|
+
initFromConfig(config: AppConfig): void;
|
|
53
|
+
buildSessionKey(chatId: string, topicId?: string): SessionKey;
|
|
54
|
+
listWorkspaceNames(): Record<string, string>;
|
|
55
|
+
saveWorkspace(name: string, cwd: string): void;
|
|
56
|
+
removeWorkspace(name: string): void;
|
|
57
|
+
newRunId(): string;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=session-router.d.ts.map
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { JsonMapStore, canonicalWorkspaceKey, resolveDefaultAgentId, serializeSessionKey, } from "@codebridge/core";
|
|
4
|
+
export class SessionRouter {
|
|
5
|
+
workspaces;
|
|
6
|
+
bindings;
|
|
7
|
+
generations;
|
|
8
|
+
constructor(dataDir) {
|
|
9
|
+
this.workspaces = new JsonMapStore(path.join(dataDir, "workspaces.json"));
|
|
10
|
+
this.bindings = new JsonMapStore(path.join(dataDir, "chat-bindings.json"));
|
|
11
|
+
this.generations = new JsonMapStore(path.join(dataDir, "slot-generations.json"));
|
|
12
|
+
}
|
|
13
|
+
bindingKey(chatId, topicId) {
|
|
14
|
+
return `${chatId}|${topicId ?? ""}`;
|
|
15
|
+
}
|
|
16
|
+
slotKey(chatId, topicId) {
|
|
17
|
+
const binding = this.getBinding(chatId, topicId);
|
|
18
|
+
return serializeSessionKey({
|
|
19
|
+
chatId,
|
|
20
|
+
topicId,
|
|
21
|
+
backendId: binding.backendId,
|
|
22
|
+
cwd: canonicalWorkspaceKey(binding.cwd).key,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** 当前槽位(backend+cwd)指向第几代 Session,默认 0。 */
|
|
26
|
+
getSlotGeneration(chatId, topicId) {
|
|
27
|
+
return this.generations.read()[this.slotKey(chatId, topicId)] ?? 0;
|
|
28
|
+
}
|
|
29
|
+
/** /new 对当前槽位 +1,返回新 generation。 */
|
|
30
|
+
incrementSlotGeneration(chatId, topicId) {
|
|
31
|
+
const key = this.slotKey(chatId, topicId);
|
|
32
|
+
const next = (this.generations.read()[key] ?? 0) + 1;
|
|
33
|
+
this.generations.update((all) => ({ ...all, [key]: next }));
|
|
34
|
+
return next;
|
|
35
|
+
}
|
|
36
|
+
/** 供 bridge 组装 ingress 消息的槽位描述(agent/cwd 已规范化)。 */
|
|
37
|
+
buildSlot(chatId, topicId) {
|
|
38
|
+
const binding = this.getBinding(chatId, topicId);
|
|
39
|
+
return {
|
|
40
|
+
agentId: binding.backendId,
|
|
41
|
+
workspaceKey: canonicalWorkspaceKey(binding.cwd).key,
|
|
42
|
+
generation: this.getSlotGeneration(chatId, topicId),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
getBinding(chatId, topicId) {
|
|
46
|
+
const key = this.bindingKey(chatId, topicId);
|
|
47
|
+
const stored = this.bindings.read()[key];
|
|
48
|
+
if (stored)
|
|
49
|
+
return { ...stored };
|
|
50
|
+
// 话题级绑定缺省时继承所在会话的绑定(backend/cwd/model 等);
|
|
51
|
+
// 不落盘,话题内显式 setBinding 时才写入话题级覆盖
|
|
52
|
+
if (topicId)
|
|
53
|
+
return this.getBinding(chatId);
|
|
54
|
+
const config = {
|
|
55
|
+
backendId: this.config
|
|
56
|
+
? resolveDefaultAgentId(this.config)
|
|
57
|
+
: "cursor",
|
|
58
|
+
cwd: this.defaultCwd,
|
|
59
|
+
};
|
|
60
|
+
this.bindings.update((all) => ({ ...all, [key]: config }));
|
|
61
|
+
return { ...config };
|
|
62
|
+
}
|
|
63
|
+
setBinding(chatId, binding, topicId) {
|
|
64
|
+
const key = this.bindingKey(chatId, topicId);
|
|
65
|
+
const current = this.getBinding(chatId, topicId);
|
|
66
|
+
const next = { ...current, ...binding };
|
|
67
|
+
this.bindings.update((all) => ({ ...all, [key]: next }));
|
|
68
|
+
}
|
|
69
|
+
clearModel(chatId, topicId) {
|
|
70
|
+
const key = this.bindingKey(chatId, topicId);
|
|
71
|
+
this.bindings.update((all) => {
|
|
72
|
+
const current = all[key];
|
|
73
|
+
if (!current)
|
|
74
|
+
return all;
|
|
75
|
+
const next = { ...current };
|
|
76
|
+
delete next.model;
|
|
77
|
+
return { ...all, [key]: next };
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
clearEffort(chatId, topicId) {
|
|
81
|
+
const key = this.bindingKey(chatId, topicId);
|
|
82
|
+
this.bindings.update((all) => {
|
|
83
|
+
const current = all[key];
|
|
84
|
+
if (!current)
|
|
85
|
+
return all;
|
|
86
|
+
const next = { ...current };
|
|
87
|
+
delete next.effort;
|
|
88
|
+
return { ...all, [key]: next };
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
clearClaudePermissionMode(chatId, topicId) {
|
|
92
|
+
const key = this.bindingKey(chatId, topicId);
|
|
93
|
+
this.bindings.update((all) => {
|
|
94
|
+
const current = all[key];
|
|
95
|
+
if (!current)
|
|
96
|
+
return all;
|
|
97
|
+
const next = { ...current };
|
|
98
|
+
delete next.claudePermissionMode;
|
|
99
|
+
return { ...all, [key]: next };
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
clearMode(chatId, topicId) {
|
|
103
|
+
const key = this.bindingKey(chatId, topicId);
|
|
104
|
+
this.bindings.update((all) => {
|
|
105
|
+
const current = all[key];
|
|
106
|
+
if (!current)
|
|
107
|
+
return all;
|
|
108
|
+
const next = { ...current };
|
|
109
|
+
delete next.mode;
|
|
110
|
+
return { ...all, [key]: next };
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
clearAcpConfig(chatId, topicId) {
|
|
114
|
+
const key = this.bindingKey(chatId, topicId);
|
|
115
|
+
this.bindings.update((all) => {
|
|
116
|
+
const current = all[key];
|
|
117
|
+
if (!current)
|
|
118
|
+
return all;
|
|
119
|
+
const next = { ...current };
|
|
120
|
+
delete next.acpConfig;
|
|
121
|
+
return { ...all, [key]: next };
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/** 切换 backend 时清除 model/effort/permission 会话覆盖 */
|
|
125
|
+
clearRunOverrides(chatId, topicId) {
|
|
126
|
+
this.clearModel(chatId, topicId);
|
|
127
|
+
this.clearEffort(chatId, topicId);
|
|
128
|
+
this.clearMode(chatId, topicId);
|
|
129
|
+
this.clearClaudePermissionMode(chatId, topicId);
|
|
130
|
+
this.clearAcpConfig(chatId, topicId);
|
|
131
|
+
}
|
|
132
|
+
resolveRunOptions(chatId, topicId, config) {
|
|
133
|
+
const binding = this.getBinding(chatId, topicId);
|
|
134
|
+
const profile = config.backends[binding.backendId];
|
|
135
|
+
const rawModel = binding.model ?? profile?.model;
|
|
136
|
+
const rawEffort = binding.effort ?? profile?.effort;
|
|
137
|
+
const rawPermission = binding.claudePermissionMode ?? profile?.claudePermissionMode;
|
|
138
|
+
return {
|
|
139
|
+
model: rawModel,
|
|
140
|
+
effort: rawEffort,
|
|
141
|
+
mode: binding.mode ?? rawPermission,
|
|
142
|
+
claudePermissionMode: rawPermission,
|
|
143
|
+
additionalDirectories: binding.additionalDirectories,
|
|
144
|
+
acpConfig: binding.acpConfig,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
defaultCwd = process.cwd();
|
|
148
|
+
config;
|
|
149
|
+
initFromConfig(config) {
|
|
150
|
+
const cwd = config.workspaces?.default ??
|
|
151
|
+
config.workspaces?.root ??
|
|
152
|
+
process.cwd();
|
|
153
|
+
this.defaultCwd = cwd;
|
|
154
|
+
this.config = config;
|
|
155
|
+
}
|
|
156
|
+
buildSessionKey(chatId, topicId) {
|
|
157
|
+
const b = this.getBinding(chatId, topicId);
|
|
158
|
+
return {
|
|
159
|
+
chatId,
|
|
160
|
+
topicId,
|
|
161
|
+
backendId: b.backendId,
|
|
162
|
+
cwd: b.cwd,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
listWorkspaceNames() {
|
|
166
|
+
return this.workspaces.read();
|
|
167
|
+
}
|
|
168
|
+
saveWorkspace(name, cwd) {
|
|
169
|
+
this.workspaces.update((all) => ({ ...all, [name]: cwd }));
|
|
170
|
+
}
|
|
171
|
+
removeWorkspace(name) {
|
|
172
|
+
this.workspaces.update((all) => {
|
|
173
|
+
const next = { ...all };
|
|
174
|
+
delete next[name];
|
|
175
|
+
return next;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
newRunId() {
|
|
179
|
+
return randomUUID();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=session-router.js.map
|