@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,754 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { AgentEventAggregator } from "./agent-event-aggregator.js";
|
|
3
|
+
import { RunHeartbeat } from "./run-heartbeat.js";
|
|
4
|
+
const PROVIDER_LEASE_MS = 60_000;
|
|
5
|
+
const AGENT_EVENT_LEASE_RENEW_INTERVAL_MS = 15_000;
|
|
6
|
+
class ProviderSessionBusyError extends Error {
|
|
7
|
+
constructor() {
|
|
8
|
+
super("provider_session_busy");
|
|
9
|
+
this.name = "ProviderSessionBusyError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
class ProviderSessionOccupiedError extends Error {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "ProviderSessionOccupiedError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function isProviderSessionOccupiedMessage(message) {
|
|
19
|
+
return message.includes("已被另一个 Runner 任务占用")
|
|
20
|
+
|| message.includes("正在运行;请等待当前任务结束");
|
|
21
|
+
}
|
|
22
|
+
export class RunExecutor {
|
|
23
|
+
store;
|
|
24
|
+
runner;
|
|
25
|
+
options;
|
|
26
|
+
activeControllers = new Map();
|
|
27
|
+
activeCompletions = new Map();
|
|
28
|
+
activeAsyncErrors = new Map();
|
|
29
|
+
activeProviderSessions = new Map();
|
|
30
|
+
constructor(store, runner, options) {
|
|
31
|
+
this.store = store;
|
|
32
|
+
this.runner = runner;
|
|
33
|
+
this.options = options;
|
|
34
|
+
}
|
|
35
|
+
claimProviderSession(agentId, providerSessionId, runId) {
|
|
36
|
+
const now = new Date();
|
|
37
|
+
const claimed = this.store.claimProviderSession({
|
|
38
|
+
agentId,
|
|
39
|
+
providerSessionId,
|
|
40
|
+
runId,
|
|
41
|
+
now: now.toISOString(),
|
|
42
|
+
expiresAt: new Date(now.getTime() + PROVIDER_LEASE_MS).toISOString(),
|
|
43
|
+
});
|
|
44
|
+
if (claimed) {
|
|
45
|
+
this.activeProviderSessions.set(runId, { agentId, providerSessionId });
|
|
46
|
+
}
|
|
47
|
+
return claimed;
|
|
48
|
+
}
|
|
49
|
+
renewProviderSession(runId) {
|
|
50
|
+
const active = this.activeProviderSessions.get(runId);
|
|
51
|
+
if (!active)
|
|
52
|
+
return true;
|
|
53
|
+
return this.store.renewProviderSession({
|
|
54
|
+
agentId: active.agentId,
|
|
55
|
+
providerSessionId: active.providerSessionId,
|
|
56
|
+
runId,
|
|
57
|
+
expiresAt: new Date(Date.now() + PROVIDER_LEASE_MS).toISOString(),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** 本进程是否仍在执行该 Run(供恢复扫描判断能否自我续租,而不是自杀)。 */
|
|
61
|
+
isExecuting(runId) {
|
|
62
|
+
const controller = this.activeControllers.get(runId);
|
|
63
|
+
return controller !== undefined && !controller.signal.aborted;
|
|
64
|
+
}
|
|
65
|
+
cancelRun(runId) {
|
|
66
|
+
const run = this.store.getRun(runId);
|
|
67
|
+
if (!run)
|
|
68
|
+
throw new Error(`Run not found: ${runId}`);
|
|
69
|
+
if (["succeeded", "failed", "cancelled", "interrupted"].includes(run.status))
|
|
70
|
+
return run;
|
|
71
|
+
this.activeControllers.get(runId)?.abort();
|
|
72
|
+
return run.sessionId ? run : this.cancel(run);
|
|
73
|
+
}
|
|
74
|
+
async cancelRunAndWait(runId) {
|
|
75
|
+
const run = this.store.getRun(runId);
|
|
76
|
+
if (!run)
|
|
77
|
+
throw new Error(`Run not found: ${runId}`);
|
|
78
|
+
if (["succeeded", "failed", "cancelled"].includes(run.status))
|
|
79
|
+
return run;
|
|
80
|
+
const controller = this.activeControllers.get(runId);
|
|
81
|
+
const completion = this.activeCompletions.get(runId);
|
|
82
|
+
if (!controller || !completion)
|
|
83
|
+
return this.cancelRun(runId);
|
|
84
|
+
controller.abort();
|
|
85
|
+
await completion;
|
|
86
|
+
const result = this.store.getRun(runId);
|
|
87
|
+
if (result.status === "failed") {
|
|
88
|
+
throw new Error("Runner cancellation failed");
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
async execute(runId, signal, _options) {
|
|
93
|
+
let nextRunId = null;
|
|
94
|
+
const initial = this.store.getRun(runId);
|
|
95
|
+
if (!initial)
|
|
96
|
+
throw new Error(`Run not found: ${runId}`);
|
|
97
|
+
if (initial.status !== "queued")
|
|
98
|
+
return initial;
|
|
99
|
+
if (this.options.shouldPauseDispatch?.())
|
|
100
|
+
return initial;
|
|
101
|
+
const workItem = this.store.getWorkItem(initial.workItemId);
|
|
102
|
+
if (!workItem)
|
|
103
|
+
throw new Error(`WorkItem not found: ${initial.workItemId}`);
|
|
104
|
+
if (initial.sessionId) {
|
|
105
|
+
this.requireSessionExecutionOptions();
|
|
106
|
+
const claimed = this.options.sessionLeaseService.claim(runId, this.options.executorOwner);
|
|
107
|
+
if (!claimed)
|
|
108
|
+
return this.store.getRun(runId);
|
|
109
|
+
}
|
|
110
|
+
if (workItem.riskLevel === "production_write") {
|
|
111
|
+
this.throwIfCancellationRequested(runId);
|
|
112
|
+
if (!this.options.approvals) {
|
|
113
|
+
throw new Error("Approval service is required for production_write runs");
|
|
114
|
+
}
|
|
115
|
+
const approvalScope = approvalScopeFor(workItem, runId, undefined, "production");
|
|
116
|
+
const inputHash = `sha256:${hashInput(approvalScope)}`;
|
|
117
|
+
const existing = this.options.approvals
|
|
118
|
+
.listForRun(runId)
|
|
119
|
+
.find((approval) => approval.stepId === "run" && approval.inputHash === inputHash);
|
|
120
|
+
if (!existing || existing.status !== "granted") {
|
|
121
|
+
if (!existing || existing.status === "expired" || existing.status === "revoked" || existing.status === "consumed") {
|
|
122
|
+
this.options.approvals.request({
|
|
123
|
+
workItemId: workItem.id,
|
|
124
|
+
runId,
|
|
125
|
+
stepId: "run",
|
|
126
|
+
capabilityId: "run.production",
|
|
127
|
+
...approvalScope,
|
|
128
|
+
inputHash,
|
|
129
|
+
requestedBy: "system",
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
this.throwIfCancellationRequested(runId);
|
|
133
|
+
return this.markWaiting(initial);
|
|
134
|
+
}
|
|
135
|
+
if (!this.options.approvals.consume(existing.id, runId, "run", inputHash)) {
|
|
136
|
+
this.throwIfCancellationRequested(runId);
|
|
137
|
+
return this.markWaiting(initial);
|
|
138
|
+
}
|
|
139
|
+
this.throwIfCancellationRequested(runId);
|
|
140
|
+
}
|
|
141
|
+
// Task 9 resume 路径:确定会进入 Runner 之后、调 Runner 前才 claim,
|
|
142
|
+
// 避免审批 markWaiting 提前 return 时留下未释放的 lease。
|
|
143
|
+
if (initial.sessionId && initial.providerSessionId && initial.agentId) {
|
|
144
|
+
const providerClaimed = this.claimProviderSession(initial.agentId, initial.providerSessionId, runId);
|
|
145
|
+
if (!providerClaimed) {
|
|
146
|
+
return this.interrupt(initial, "provider_session_busy");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (!initial.sessionId)
|
|
150
|
+
this.store.updateRunStatus(runId, "running");
|
|
151
|
+
if (!this.hasRunEvent(workItem.id, runId, "RUN_STARTED")) {
|
|
152
|
+
this.appendRunEvent(initial, {
|
|
153
|
+
workItemId: workItem.id,
|
|
154
|
+
runId,
|
|
155
|
+
type: "RUN_STARTED",
|
|
156
|
+
actor: "system",
|
|
157
|
+
target: runId,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
const controller = new AbortController();
|
|
161
|
+
const activeSignal = signal ? AbortSignal.any([signal, controller.signal]) : controller.signal;
|
|
162
|
+
let leaseLost = false;
|
|
163
|
+
let providerLeaseLost = false;
|
|
164
|
+
const heartbeat = initial.sessionId
|
|
165
|
+
? new RunHeartbeat({
|
|
166
|
+
runId,
|
|
167
|
+
owner: this.options.executorOwner,
|
|
168
|
+
renew: (id, owner) => {
|
|
169
|
+
const renewed = this.options.sessionLeaseService.renew(id, owner);
|
|
170
|
+
if (!renewed)
|
|
171
|
+
return null;
|
|
172
|
+
if (!this.renewProviderSession(runId)) {
|
|
173
|
+
// 只标记失败 + abort + 停表,终态由主路径唯一调用 finishRun。
|
|
174
|
+
providerLeaseLost = true;
|
|
175
|
+
controller.abort();
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
return renewed;
|
|
179
|
+
},
|
|
180
|
+
onLeaseLost: () => {
|
|
181
|
+
leaseLost = true;
|
|
182
|
+
controller.abort();
|
|
183
|
+
},
|
|
184
|
+
})
|
|
185
|
+
: null;
|
|
186
|
+
let completeExecution;
|
|
187
|
+
const completion = new Promise((resolve) => {
|
|
188
|
+
completeExecution = resolve;
|
|
189
|
+
});
|
|
190
|
+
this.activeControllers.set(runId, controller);
|
|
191
|
+
this.activeCompletions.set(runId, completion);
|
|
192
|
+
heartbeat?.start();
|
|
193
|
+
try {
|
|
194
|
+
this.throwIfCancellationRequested(runId);
|
|
195
|
+
{
|
|
196
|
+
this.appendRunEvent(initial, {
|
|
197
|
+
workItemId: workItem.id,
|
|
198
|
+
runId,
|
|
199
|
+
type: "STEP_STARTED",
|
|
200
|
+
actor: "system",
|
|
201
|
+
target: runId,
|
|
202
|
+
});
|
|
203
|
+
await this.executeStepOnce(workItem, initial, activeSignal);
|
|
204
|
+
if (activeSignal.aborted) {
|
|
205
|
+
if (providerLeaseLost)
|
|
206
|
+
return this.interrupt(initial, "provider_session_busy");
|
|
207
|
+
if (leaseLost)
|
|
208
|
+
return this.store.getRun(runId);
|
|
209
|
+
return this.cancel(initial);
|
|
210
|
+
}
|
|
211
|
+
this.throwIfCancellationRequested(runId);
|
|
212
|
+
this.appendRunEvent(initial, {
|
|
213
|
+
workItemId: workItem.id,
|
|
214
|
+
runId,
|
|
215
|
+
type: "STEP_SUCCEEDED",
|
|
216
|
+
actor: "system",
|
|
217
|
+
target: runId,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
if (activeSignal.aborted) {
|
|
221
|
+
if (providerLeaseLost)
|
|
222
|
+
return this.interrupt(initial, "provider_session_busy");
|
|
223
|
+
if (leaseLost)
|
|
224
|
+
return this.store.getRun(runId);
|
|
225
|
+
return this.cancel(initial);
|
|
226
|
+
}
|
|
227
|
+
this.throwIfCancellationRequested(runId);
|
|
228
|
+
const succeeded = this.succeed(initial);
|
|
229
|
+
nextRunId = succeeded.nextRunId;
|
|
230
|
+
return succeeded.run;
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
const failure = this.activeAsyncErrors.get(runId) ?? error;
|
|
234
|
+
if (providerLeaseLost) {
|
|
235
|
+
return this.interrupt(initial, "provider_session_busy");
|
|
236
|
+
}
|
|
237
|
+
if (leaseLost || isRunLeaseLost(failure)) {
|
|
238
|
+
return this.store.getRun(runId);
|
|
239
|
+
}
|
|
240
|
+
if (failure instanceof ProviderSessionBusyError
|
|
241
|
+
|| failure instanceof ProviderSessionOccupiedError) {
|
|
242
|
+
return this.interrupt(initial, "provider_session_busy");
|
|
243
|
+
}
|
|
244
|
+
if (failure instanceof UnsafeProviderDisconnect) {
|
|
245
|
+
return this.interrupt(initial, failure.boundary === "outcome_unknown"
|
|
246
|
+
? "provider_disconnect_unknown_outcome"
|
|
247
|
+
: "provider_disconnect_after_side_effect_boundary");
|
|
248
|
+
}
|
|
249
|
+
if (initial.sessionId
|
|
250
|
+
&& activeSignal.aborted
|
|
251
|
+
&& isRunnerCancellationError(failure)) {
|
|
252
|
+
throw failure;
|
|
253
|
+
}
|
|
254
|
+
if (failure instanceof RunCancellationRequested
|
|
255
|
+
|| (activeSignal.aborted && !isRunnerCancellationError(failure))) {
|
|
256
|
+
controller.abort();
|
|
257
|
+
return this.cancel(initial);
|
|
258
|
+
}
|
|
259
|
+
this.appendRunEvent(initial, {
|
|
260
|
+
workItemId: workItem.id,
|
|
261
|
+
runId,
|
|
262
|
+
type: "STEP_FAILED",
|
|
263
|
+
actor: "system",
|
|
264
|
+
target: runId,
|
|
265
|
+
payload: {
|
|
266
|
+
error: failure instanceof Error
|
|
267
|
+
? failure.message
|
|
268
|
+
: String(failure),
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
this.fail(initial, failure);
|
|
272
|
+
throw failure;
|
|
273
|
+
}
|
|
274
|
+
finally {
|
|
275
|
+
heartbeat?.close();
|
|
276
|
+
this.activeAsyncErrors.delete(runId);
|
|
277
|
+
this.activeProviderSessions.delete(runId);
|
|
278
|
+
if (this.activeControllers.get(runId) === controller)
|
|
279
|
+
this.activeControllers.delete(runId);
|
|
280
|
+
completeExecution();
|
|
281
|
+
if (this.activeCompletions.get(runId) === completion) {
|
|
282
|
+
this.activeCompletions.delete(runId);
|
|
283
|
+
}
|
|
284
|
+
if (nextRunId) {
|
|
285
|
+
void this.execute(nextRunId).catch(() => { });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
succeed(run) {
|
|
290
|
+
if (run.sessionId) {
|
|
291
|
+
const finished = this.options.sessionCoordinator.finishRun({
|
|
292
|
+
sessionId: run.sessionId,
|
|
293
|
+
runId: run.id,
|
|
294
|
+
status: "succeeded",
|
|
295
|
+
});
|
|
296
|
+
return {
|
|
297
|
+
run: finished.run,
|
|
298
|
+
nextRunId: finished.dispatched?.run.id ?? null,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
this.store.updateRunStatus(run.id, "succeeded");
|
|
302
|
+
this.appendRunEvent(run, {
|
|
303
|
+
workItemId: run.workItemId,
|
|
304
|
+
runId: run.id,
|
|
305
|
+
type: "RUN_SUCCEEDED",
|
|
306
|
+
actor: "system",
|
|
307
|
+
target: run.id,
|
|
308
|
+
});
|
|
309
|
+
this.appendRunEvent(run, {
|
|
310
|
+
workItemId: run.workItemId,
|
|
311
|
+
runId: run.id,
|
|
312
|
+
type: "WORK_ITEM_COMPLETED",
|
|
313
|
+
actor: "system",
|
|
314
|
+
target: run.id,
|
|
315
|
+
});
|
|
316
|
+
return { run: this.store.getRun(run.id), nextRunId: null };
|
|
317
|
+
}
|
|
318
|
+
fail(run, error) {
|
|
319
|
+
if (run.sessionId) {
|
|
320
|
+
return this.options.sessionCoordinator.finishRun({
|
|
321
|
+
sessionId: run.sessionId,
|
|
322
|
+
runId: run.id,
|
|
323
|
+
status: "failed",
|
|
324
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
325
|
+
}).run;
|
|
326
|
+
}
|
|
327
|
+
this.store.updateRunStatus(run.id, "failed");
|
|
328
|
+
this.store.appendEvent({
|
|
329
|
+
workItemId: run.workItemId,
|
|
330
|
+
runId: run.id,
|
|
331
|
+
type: "RUN_FAILED",
|
|
332
|
+
actor: "system",
|
|
333
|
+
target: run.id,
|
|
334
|
+
payload: {
|
|
335
|
+
error: error instanceof Error ? error.message : String(error),
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
return this.store.getRun(run.id);
|
|
339
|
+
}
|
|
340
|
+
markWaiting(run) {
|
|
341
|
+
return run.sessionId
|
|
342
|
+
? this.store.updateRunControl(run.id, {
|
|
343
|
+
status: "waiting",
|
|
344
|
+
leaseOwner: null,
|
|
345
|
+
leaseExpiresAt: null,
|
|
346
|
+
})
|
|
347
|
+
: this.store.updateRunStatus(run.id, "waiting");
|
|
348
|
+
}
|
|
349
|
+
dropPoisonedProviderSession(run) {
|
|
350
|
+
if (!run.sessionId)
|
|
351
|
+
return { ...run, providerSessionId: null };
|
|
352
|
+
const sessionId = run.sessionId;
|
|
353
|
+
const agentId = run.agentId;
|
|
354
|
+
const providerSessionId = run.providerSessionId;
|
|
355
|
+
this.store.withSessionTransaction((tx) => {
|
|
356
|
+
if (agentId && providerSessionId) {
|
|
357
|
+
tx.releaseProviderSession({
|
|
358
|
+
agentId,
|
|
359
|
+
providerSessionId,
|
|
360
|
+
runId: run.id,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
tx.updateRun(run.id, { providerSessionId: null });
|
|
364
|
+
tx.setSessionProviderSessionId(sessionId, null);
|
|
365
|
+
});
|
|
366
|
+
this.activeProviderSessions.delete(run.id);
|
|
367
|
+
return { ...run, providerSessionId: null };
|
|
368
|
+
}
|
|
369
|
+
interrupt(run, reason) {
|
|
370
|
+
if (run.sessionId) {
|
|
371
|
+
return this.options.sessionCoordinator.finishRun({
|
|
372
|
+
sessionId: run.sessionId,
|
|
373
|
+
runId: run.id,
|
|
374
|
+
status: "interrupted",
|
|
375
|
+
reason,
|
|
376
|
+
}).run;
|
|
377
|
+
}
|
|
378
|
+
this.store.updateRunControl(run.id, {
|
|
379
|
+
status: "interrupted",
|
|
380
|
+
terminalReason: reason,
|
|
381
|
+
});
|
|
382
|
+
this.store.appendEvent({
|
|
383
|
+
workItemId: run.workItemId,
|
|
384
|
+
runId: run.id,
|
|
385
|
+
type: "RUN_INTERRUPTED",
|
|
386
|
+
actor: "system",
|
|
387
|
+
target: run.id,
|
|
388
|
+
payload: { reason },
|
|
389
|
+
});
|
|
390
|
+
return this.store.getRun(run.id);
|
|
391
|
+
}
|
|
392
|
+
cancel(run) {
|
|
393
|
+
const current = this.store.getRun(run.id);
|
|
394
|
+
if (current?.status === "cancelled")
|
|
395
|
+
return current;
|
|
396
|
+
if (run.sessionId) {
|
|
397
|
+
return this.options.sessionCoordinator.finishRun({
|
|
398
|
+
sessionId: run.sessionId,
|
|
399
|
+
runId: run.id,
|
|
400
|
+
status: "cancelled",
|
|
401
|
+
reason: "cancel_requested",
|
|
402
|
+
}).run;
|
|
403
|
+
}
|
|
404
|
+
this.store.updateRunStatus(run.id, "cancelled");
|
|
405
|
+
this.store.appendEvent({
|
|
406
|
+
workItemId: run.workItemId,
|
|
407
|
+
runId: run.id,
|
|
408
|
+
type: "RUN_CANCELLED",
|
|
409
|
+
actor: "system",
|
|
410
|
+
target: run.id,
|
|
411
|
+
});
|
|
412
|
+
return this.store.getRun(run.id);
|
|
413
|
+
}
|
|
414
|
+
async executeStepOnce(workItem, run, signal) {
|
|
415
|
+
this.throwIfCancellationRequested(run.id);
|
|
416
|
+
let request = await this.options.resolveRequest(workItem, run);
|
|
417
|
+
const latestMessage = this.store
|
|
418
|
+
.listEvents(workItem.id)
|
|
419
|
+
.reverse()
|
|
420
|
+
.find((event) => event.type === "MESSAGE_RECEIVED");
|
|
421
|
+
const attachmentIds = Array.isArray(latestMessage?.payload.attachment_ids)
|
|
422
|
+
? latestMessage.payload.attachment_ids.filter((id) => typeof id === "string")
|
|
423
|
+
: [];
|
|
424
|
+
const messageAttachments = this.store.listMessageAttachments(workItem.id, attachmentIds).map((attachment) => ({
|
|
425
|
+
name: attachment.name,
|
|
426
|
+
mimeType: attachment.mimeType,
|
|
427
|
+
dataBase64: attachment.dataBase64,
|
|
428
|
+
}));
|
|
429
|
+
if (messageAttachments.length) {
|
|
430
|
+
request = { ...request, attachments: [...(request.attachments ?? []), ...messageAttachments] };
|
|
431
|
+
}
|
|
432
|
+
this.throwIfCancellationRequested(run.id);
|
|
433
|
+
let replaySafety = this.store.getRun(run.id)?.replaySafety ?? "safe";
|
|
434
|
+
let droppedOccupiedResume = false;
|
|
435
|
+
let renewFromEventAfter = 0;
|
|
436
|
+
let pendingThought = null;
|
|
437
|
+
let pendingThoughtKey = null;
|
|
438
|
+
const thoughtKey = (event) => `${event.blockId ?? event.messageId ?? ""}:${event.type}`;
|
|
439
|
+
const persistCoalescedThought = () => {
|
|
440
|
+
if (!pendingThought)
|
|
441
|
+
return;
|
|
442
|
+
const event = pendingThought;
|
|
443
|
+
pendingThought = null;
|
|
444
|
+
pendingThoughtKey = null;
|
|
445
|
+
this.appendRunEvent(run, {
|
|
446
|
+
workItemId: workItem.id,
|
|
447
|
+
runId: run.id,
|
|
448
|
+
type: "AGENT_EVENT",
|
|
449
|
+
actor: "adapter",
|
|
450
|
+
target: event.type,
|
|
451
|
+
payload: { event },
|
|
452
|
+
});
|
|
453
|
+
};
|
|
454
|
+
const persistAgentEvent = (event) => {
|
|
455
|
+
this.throwIfCancellationRequested(run.id);
|
|
456
|
+
// provider lease 丢失后,persist 入口直接拒绝写入(不依赖 runner 尊重 abort)。
|
|
457
|
+
if (signal?.aborted) {
|
|
458
|
+
throw new RunCancellationRequested();
|
|
459
|
+
}
|
|
460
|
+
// Agent 事件本身就是执行器仍存活的持久证据。定时心跳若因事件循环抖动
|
|
461
|
+
// 错过一个窗口,先续租再落事件,避免恢复扫描把仍在产出事件的 Run 误判中断。
|
|
462
|
+
const now = Date.now();
|
|
463
|
+
if (run.sessionId && now >= renewFromEventAfter) {
|
|
464
|
+
if (!this.options.sessionLeaseService.renew(run.id, this.options.executorOwner)) {
|
|
465
|
+
throw new Error("run_lease_lost");
|
|
466
|
+
}
|
|
467
|
+
if (!this.renewProviderSession(run.id)) {
|
|
468
|
+
throw new ProviderSessionBusyError();
|
|
469
|
+
}
|
|
470
|
+
renewFromEventAfter = now + AGENT_EVENT_LEASE_RENEW_INTERVAL_MS;
|
|
471
|
+
}
|
|
472
|
+
if (event.type === "error"
|
|
473
|
+
&& event.fatal
|
|
474
|
+
&& isProviderSessionOccupiedMessage(event.message)) {
|
|
475
|
+
throw new ProviderSessionOccupiedError(event.message);
|
|
476
|
+
}
|
|
477
|
+
// Task 9 fresh 路径:首个 session 事件到达时,persist 前原子
|
|
478
|
+
// updateRun(providerSessionId) + claim;失败则中断本 run,不 append AGENT_EVENT。
|
|
479
|
+
if (event.type === "session"
|
|
480
|
+
&& event.sessionId
|
|
481
|
+
&& run.sessionId
|
|
482
|
+
&& run.agentId
|
|
483
|
+
&& !run.providerSessionId) {
|
|
484
|
+
const agentId = run.agentId;
|
|
485
|
+
const sessionId = run.sessionId;
|
|
486
|
+
const claimed = this.store.withSessionTransaction((tx) => {
|
|
487
|
+
const now = new Date();
|
|
488
|
+
const ok = tx.claimProviderSession({
|
|
489
|
+
agentId,
|
|
490
|
+
providerSessionId: event.sessionId,
|
|
491
|
+
runId: run.id,
|
|
492
|
+
now: now.toISOString(),
|
|
493
|
+
expiresAt: new Date(now.getTime() + PROVIDER_LEASE_MS).toISOString(),
|
|
494
|
+
});
|
|
495
|
+
if (!ok)
|
|
496
|
+
return false;
|
|
497
|
+
// claim 成功才写 identity;失败时事务内无写,return false 不会留下脏 runtime。
|
|
498
|
+
tx.updateRun(run.id, { providerSessionId: event.sessionId });
|
|
499
|
+
tx.setSessionProviderSessionId(sessionId, event.sessionId);
|
|
500
|
+
return true;
|
|
501
|
+
});
|
|
502
|
+
if (!claimed) {
|
|
503
|
+
throw new ProviderSessionBusyError();
|
|
504
|
+
}
|
|
505
|
+
run = { ...run, providerSessionId: event.sessionId };
|
|
506
|
+
this.activeProviderSessions.set(run.id, {
|
|
507
|
+
agentId,
|
|
508
|
+
providerSessionId: event.sessionId,
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
const nextReplaySafety = replaySafetyAfterEvent(replaySafety, event);
|
|
512
|
+
if (nextReplaySafety !== replaySafety) {
|
|
513
|
+
replaySafety = nextReplaySafety;
|
|
514
|
+
this.updateReplaySafety(run, replaySafety);
|
|
515
|
+
}
|
|
516
|
+
// thought_delta 只直播、不逐段写 domain_events。Pi 思考流会在主线程
|
|
517
|
+
// 打出成百上千笔同步事务;思考块结束(下一个非 thought 事件或 Run 收尾)
|
|
518
|
+
// 再落一条合并后的 AGENT_EVENT,供时间线和重连回放。
|
|
519
|
+
if (event.type === "thought_delta") {
|
|
520
|
+
const key = thoughtKey(event);
|
|
521
|
+
if (pendingThought && pendingThoughtKey !== key) {
|
|
522
|
+
persistCoalescedThought();
|
|
523
|
+
}
|
|
524
|
+
if (!pendingThought) {
|
|
525
|
+
pendingThought = { ...event };
|
|
526
|
+
pendingThoughtKey = key;
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
pendingThought = {
|
|
530
|
+
...pendingThought,
|
|
531
|
+
text: pendingThought.text + event.text,
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
this.options.onEvent?.(run, event);
|
|
535
|
+
this.throwIfCancellationRequested(run.id);
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
persistCoalescedThought();
|
|
539
|
+
this.appendRunEvent(run, {
|
|
540
|
+
workItemId: workItem.id,
|
|
541
|
+
runId: run.id,
|
|
542
|
+
type: "AGENT_EVENT",
|
|
543
|
+
actor: "adapter",
|
|
544
|
+
target: event.type,
|
|
545
|
+
payload: { event },
|
|
546
|
+
});
|
|
547
|
+
this.options.onEvent?.(run, event);
|
|
548
|
+
this.throwIfCancellationRequested(run.id);
|
|
549
|
+
if (event.type === "done" && event.exitCode !== 0) {
|
|
550
|
+
throw new Error(`Runner exited with code ${event.exitCode}`);
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
for (let attemptNumber = 1; attemptNumber <= 3; attemptNumber += 1) {
|
|
554
|
+
const attempt = this.store.startRunAttempt(run.id);
|
|
555
|
+
const aggregator = new AgentEventAggregator({
|
|
556
|
+
runId: run.id,
|
|
557
|
+
emit: persistAgentEvent,
|
|
558
|
+
onError: (error) => {
|
|
559
|
+
this.activeAsyncErrors.set(run.id, error);
|
|
560
|
+
this.activeControllers.get(run.id)?.abort();
|
|
561
|
+
},
|
|
562
|
+
});
|
|
563
|
+
try {
|
|
564
|
+
for await (const event of this.runner.run(request, { signal })) {
|
|
565
|
+
aggregator.accept(event);
|
|
566
|
+
}
|
|
567
|
+
const asynchronousError = this.activeAsyncErrors.get(run.id);
|
|
568
|
+
if (asynchronousError)
|
|
569
|
+
throw asynchronousError;
|
|
570
|
+
aggregator.close();
|
|
571
|
+
persistCoalescedThought();
|
|
572
|
+
this.store.finishRunAttempt(attempt.attemptId, {
|
|
573
|
+
providerError: null,
|
|
574
|
+
sideEffectBoundary: replaySafety,
|
|
575
|
+
});
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
catch (error) {
|
|
579
|
+
try {
|
|
580
|
+
aggregator.close();
|
|
581
|
+
persistCoalescedThought();
|
|
582
|
+
}
|
|
583
|
+
catch (flushError) {
|
|
584
|
+
error = flushError;
|
|
585
|
+
}
|
|
586
|
+
this.store.finishRunAttempt(attempt.attemptId, {
|
|
587
|
+
providerError: error instanceof Error
|
|
588
|
+
? error.message
|
|
589
|
+
: String(error),
|
|
590
|
+
sideEffectBoundary: replaySafety,
|
|
591
|
+
});
|
|
592
|
+
if (error instanceof ProviderSessionOccupiedError
|
|
593
|
+
&& request.resumeSessionId
|
|
594
|
+
&& !droppedOccupiedResume) {
|
|
595
|
+
droppedOccupiedResume = true;
|
|
596
|
+
run = this.dropPoisonedProviderSession(run);
|
|
597
|
+
request = { ...request, resumeSessionId: undefined };
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
if (!isProviderTransportError(error))
|
|
601
|
+
throw error;
|
|
602
|
+
if (replaySafety !== "safe") {
|
|
603
|
+
throw new UnsafeProviderDisconnect(error, replaySafety);
|
|
604
|
+
}
|
|
605
|
+
if (attemptNumber === 3)
|
|
606
|
+
throw error;
|
|
607
|
+
await retryDelay(500 * 2 ** (attemptNumber - 1), signal);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
appendRunEvent(run, input) {
|
|
612
|
+
if (run.sessionId) {
|
|
613
|
+
this.store.appendLeasedRunEvent(this.options.executorOwner, {
|
|
614
|
+
...input,
|
|
615
|
+
runId: run.id,
|
|
616
|
+
sessionId: run.sessionId,
|
|
617
|
+
});
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
this.store.appendEvent(input);
|
|
621
|
+
}
|
|
622
|
+
updateReplaySafety(run, replaySafety) {
|
|
623
|
+
if (run.sessionId) {
|
|
624
|
+
this.store.updateLeasedRunReplaySafety(run.id, this.options.executorOwner, replaySafety);
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
this.store.updateRunControl(run.id, { replaySafety });
|
|
628
|
+
}
|
|
629
|
+
requireSessionExecutionOptions() {
|
|
630
|
+
if (!this.options.sessionCoordinator
|
|
631
|
+
|| !this.options.sessionLeaseService
|
|
632
|
+
|| !this.options.executorOwner) {
|
|
633
|
+
throw new Error("Session-bound Runs require a Coordinator, lease service, and executor owner");
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
throwIfCancellationRequested(runId) {
|
|
637
|
+
if (this.store.getRun(runId)?.cancelRequestedAt) {
|
|
638
|
+
throw new RunCancellationRequested();
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
hasRunEvent(workItemId, runId, type) {
|
|
642
|
+
return this.store.listEvents(workItemId).some((event) => event.runId === runId && event.type === type);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
class RunCancellationRequested extends Error {
|
|
646
|
+
constructor() {
|
|
647
|
+
super("run_cancellation_requested");
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
class UnsafeProviderDisconnect extends Error {
|
|
651
|
+
cause;
|
|
652
|
+
boundary;
|
|
653
|
+
constructor(cause, boundary) {
|
|
654
|
+
super(cause instanceof Error
|
|
655
|
+
? cause.message
|
|
656
|
+
: "Provider disconnected after a side-effect boundary");
|
|
657
|
+
this.cause = cause;
|
|
658
|
+
this.boundary = boundary;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
function replaySafetyAfterEvent(current, event) {
|
|
662
|
+
if (current === "outcome_unknown")
|
|
663
|
+
return current;
|
|
664
|
+
if (event.type === "tool_start" && event.sideEffects !== false) {
|
|
665
|
+
return "outcome_unknown";
|
|
666
|
+
}
|
|
667
|
+
if (event.type === "tool_start")
|
|
668
|
+
return "side_effect_started";
|
|
669
|
+
if (event.type === "tool_end" && event.sideEffects === true) {
|
|
670
|
+
return "outcome_unknown";
|
|
671
|
+
}
|
|
672
|
+
return current;
|
|
673
|
+
}
|
|
674
|
+
function isRunLeaseLost(error) {
|
|
675
|
+
return error instanceof Error && error.message === "run_lease_lost";
|
|
676
|
+
}
|
|
677
|
+
function isProviderTransportError(error) {
|
|
678
|
+
return error instanceof Error
|
|
679
|
+
&& !isRunnerCancellationError(error)
|
|
680
|
+
&& /socket|offline|disconnect|econn|network|fetch failed/i.test(error.message);
|
|
681
|
+
}
|
|
682
|
+
function isRunnerCancellationError(error) {
|
|
683
|
+
return error instanceof Error && error.name === "RunnerCancellationError";
|
|
684
|
+
}
|
|
685
|
+
function approvalScopeFor(workItem, runId, step, environment) {
|
|
686
|
+
const sessionId = workItem.conversationId.startsWith("conv_")
|
|
687
|
+
? `sess_${workItem.conversationId.slice("conv_".length)}`
|
|
688
|
+
: workItem.conversationId;
|
|
689
|
+
const targetResource = typeof workItem.identifiers.target_resource === "string"
|
|
690
|
+
? workItem.identifiers.target_resource
|
|
691
|
+
: step?.capabilityId ?? workItem.workspaceScope[0] ?? "run";
|
|
692
|
+
return {
|
|
693
|
+
sessionId,
|
|
694
|
+
environment,
|
|
695
|
+
targetResource,
|
|
696
|
+
input: {
|
|
697
|
+
workItemId: workItem.id,
|
|
698
|
+
runId,
|
|
699
|
+
title: workItem.title,
|
|
700
|
+
identifiers: workItem.identifiers,
|
|
701
|
+
workspaceScope: workItem.workspaceScope,
|
|
702
|
+
step: step
|
|
703
|
+
? {
|
|
704
|
+
id: step.id,
|
|
705
|
+
capabilityId: step.capabilityId,
|
|
706
|
+
risk: step.risk,
|
|
707
|
+
purpose: step.purpose,
|
|
708
|
+
dependsOn: step.dependsOn,
|
|
709
|
+
guard: step.guard,
|
|
710
|
+
approval: step.approval,
|
|
711
|
+
branches: step.branches,
|
|
712
|
+
retry: step.retry ?? null,
|
|
713
|
+
}
|
|
714
|
+
: null,
|
|
715
|
+
sessionId,
|
|
716
|
+
environment,
|
|
717
|
+
targetResource,
|
|
718
|
+
},
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
function hashInput(scope) {
|
|
722
|
+
return createHash("sha256")
|
|
723
|
+
.update(stableStringify(scope.input))
|
|
724
|
+
.digest("hex");
|
|
725
|
+
}
|
|
726
|
+
function stableStringify(value) {
|
|
727
|
+
if (Array.isArray(value))
|
|
728
|
+
return `[${value.map(stableStringify).join(",")}]`;
|
|
729
|
+
if (value && typeof value === "object") {
|
|
730
|
+
return `{${Object.entries(value)
|
|
731
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
732
|
+
.map(([key, entry]) => `${JSON.stringify(key)}:${stableStringify(entry)}`)
|
|
733
|
+
.join(",")}}`;
|
|
734
|
+
}
|
|
735
|
+
return JSON.stringify(value);
|
|
736
|
+
}
|
|
737
|
+
async function retryDelay(delayMs, signal) {
|
|
738
|
+
if (signal?.aborted)
|
|
739
|
+
throw new DOMException("aborted", "AbortError");
|
|
740
|
+
if (delayMs <= 0)
|
|
741
|
+
return;
|
|
742
|
+
await new Promise((resolve, reject) => {
|
|
743
|
+
const onAbort = () => {
|
|
744
|
+
clearTimeout(timer);
|
|
745
|
+
reject(new DOMException("aborted", "AbortError"));
|
|
746
|
+
};
|
|
747
|
+
const timer = setTimeout(() => {
|
|
748
|
+
signal?.removeEventListener("abort", onAbort);
|
|
749
|
+
resolve();
|
|
750
|
+
}, delayMs);
|
|
751
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
//# sourceMappingURL=index.js.map
|