@0xmaxma/claude-gateway 2.0.6 → 2.0.8
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/README.md +15 -1
- package/config.template.json +5 -3
- package/dist/agent/builtin-commands.js +5 -5
- package/dist/agent/builtin-commands.js.map +1 -1
- package/dist/agent/command-help.d.ts +9 -0
- package/dist/agent/command-help.d.ts.map +1 -0
- package/dist/agent/command-help.js +50 -0
- package/dist/agent/command-help.js.map +1 -0
- package/dist/agent/dreaming/index.d.ts +6 -3
- package/dist/agent/dreaming/index.d.ts.map +1 -1
- package/dist/agent/dreaming/index.js +21 -1
- package/dist/agent/dreaming/index.js.map +1 -1
- package/dist/agent/knowledge/reflection.d.ts +7 -4
- package/dist/agent/knowledge/reflection.d.ts.map +1 -1
- package/dist/agent/knowledge/reflection.js +19 -1
- package/dist/agent/knowledge/reflection.js.map +1 -1
- package/dist/agent/runner.d.ts +51 -3
- package/dist/agent/runner.d.ts.map +1 -1
- package/dist/agent/runner.js +244 -66
- package/dist/agent/runner.js.map +1 -1
- package/dist/agent/session-confirmations.d.ts +12 -0
- package/dist/agent/session-confirmations.d.ts.map +1 -0
- package/dist/agent/session-confirmations.js +43 -0
- package/dist/agent/session-confirmations.js.map +1 -0
- package/dist/agent/session-status.d.ts +7 -0
- package/dist/agent/session-status.d.ts.map +1 -0
- package/dist/agent/session-status.js +16 -0
- package/dist/agent/session-status.js.map +1 -0
- package/dist/agent/skill-learning/index.d.ts +5 -1
- package/dist/agent/skill-learning/index.d.ts.map +1 -1
- package/dist/agent/skill-learning/index.js +23 -1
- package/dist/agent/skill-learning/index.js.map +1 -1
- package/dist/agent/skill-learning/notifier.d.ts +2 -1
- package/dist/agent/skill-learning/notifier.d.ts.map +1 -1
- package/dist/agent/skill-learning/notifier.js +1 -0
- package/dist/agent/skill-learning/notifier.js.map +1 -1
- package/dist/api/apps-router.d.ts.map +1 -1
- package/dist/api/apps-router.js +1 -3
- package/dist/api/apps-router.js.map +1 -1
- package/dist/api/cron-router.d.ts +1 -1
- package/dist/api/cron-router.d.ts.map +1 -1
- package/dist/api/cron-router.js +4 -4
- package/dist/api/cron-router.js.map +1 -1
- package/dist/api/dashboard-processes.d.ts +86 -0
- package/dist/api/dashboard-processes.d.ts.map +1 -0
- package/dist/api/dashboard-processes.js +155 -0
- package/dist/api/dashboard-processes.js.map +1 -0
- package/dist/api/dashboard-sessions.d.ts +15 -0
- package/dist/api/dashboard-sessions.d.ts.map +1 -0
- package/dist/api/dashboard-sessions.js +66 -0
- package/dist/api/dashboard-sessions.js.map +1 -0
- package/dist/api/gateway-router.d.ts +3 -4
- package/dist/api/gateway-router.d.ts.map +1 -1
- package/dist/api/gateway-router.js +77 -56
- package/dist/api/gateway-router.js.map +1 -1
- package/dist/api/oauth-connectors-router.d.ts +1 -1
- package/dist/api/oauth-connectors-router.d.ts.map +1 -1
- package/dist/api/oauth-connectors-router.js +11 -21
- package/dist/api/oauth-connectors-router.js.map +1 -1
- package/dist/api/router.d.ts +1 -1
- package/dist/api/router.d.ts.map +1 -1
- package/dist/api/router.js +119 -14
- package/dist/api/router.js.map +1 -1
- package/dist/api/share-router.d.ts +1 -1
- package/dist/api/share-router.d.ts.map +1 -1
- package/dist/api/share-router.js +1 -1
- package/dist/api/share-router.js.map +1 -1
- package/dist/api/slack-webhook-router.js +1 -1
- package/dist/api/slack-webhook-router.js.map +1 -1
- package/dist/api/voice-router.d.ts +1 -0
- package/dist/api/voice-router.d.ts.map +1 -1
- package/dist/api/voice-router.js +7 -0
- package/dist/api/voice-router.js.map +1 -1
- package/dist/api/voice-settings-router.d.ts.map +1 -1
- package/dist/api/voice-settings-router.js +2 -1
- package/dist/api/voice-settings-router.js.map +1 -1
- package/dist/apps/agent-container-migration.d.ts +2 -0
- package/dist/apps/agent-container-migration.d.ts.map +1 -1
- package/dist/apps/agent-container-migration.js +59 -2
- package/dist/apps/agent-container-migration.js.map +1 -1
- package/dist/apps/agent-manager.d.ts +4 -2
- package/dist/apps/agent-manager.d.ts.map +1 -1
- package/dist/apps/agent-manager.js +39 -3
- package/dist/apps/agent-manager.js.map +1 -1
- package/dist/apps/installer.d.ts +4 -3
- package/dist/apps/installer.d.ts.map +1 -1
- package/dist/apps/installer.js +8 -4
- package/dist/apps/installer.js.map +1 -1
- package/dist/build-provenance.json +8 -0
- package/dist/cli/args.js +1 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/commands/app.d.ts.map +1 -1
- package/dist/cli/commands/app.js +39 -3
- package/dist/cli/commands/app.js.map +1 -1
- package/dist/cli/commands/doctor.d.ts.map +1 -1
- package/dist/cli/commands/doctor.js +6 -2
- package/dist/cli/commands/doctor.js.map +1 -1
- package/dist/cli/commands/safemode.d.ts +2 -0
- package/dist/cli/commands/safemode.d.ts.map +1 -0
- package/dist/cli/commands/safemode.js +279 -0
- package/dist/cli/commands/safemode.js.map +1 -0
- package/dist/cli/dependencies.d.ts +2 -0
- package/dist/cli/dependencies.d.ts.map +1 -1
- package/dist/cli/dependencies.js +81 -0
- package/dist/cli/dependencies.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +11 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/manager.d.ts.map +1 -1
- package/dist/cli/manager.js +4 -1
- package/dist/cli/manager.js.map +1 -1
- package/dist/config/agent-lifecycle.d.ts +26 -0
- package/dist/config/agent-lifecycle.d.ts.map +1 -0
- package/dist/config/agent-lifecycle.js +63 -0
- package/dist/config/agent-lifecycle.js.map +1 -0
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +11 -0
- package/dist/config/loader.js.map +1 -1
- package/dist/config/reload-policy.d.ts +9 -0
- package/dist/config/reload-policy.d.ts.map +1 -0
- package/dist/config/reload-policy.js +62 -0
- package/dist/config/reload-policy.js.map +1 -0
- package/dist/config/watcher.d.ts +3 -2
- package/dist/config/watcher.d.ts.map +1 -1
- package/dist/config/watcher.js +34 -51
- package/dist/config/watcher.js.map +1 -1
- package/dist/cron/tool-schemas.d.ts +296 -0
- package/dist/cron/tool-schemas.d.ts.map +1 -0
- package/dist/cron/tool-schemas.js +122 -0
- package/dist/cron/tool-schemas.js.map +1 -0
- package/dist/history/db.d.ts +4 -0
- package/dist/history/db.d.ts.map +1 -1
- package/dist/history/db.js +33 -5
- package/dist/history/db.js.map +1 -1
- package/dist/history/types.d.ts +1 -0
- package/dist/history/types.d.ts.map +1 -1
- package/dist/index.js +141 -158
- package/dist/index.js.map +1 -1
- package/dist/orchestration/agent-tool-schemas.js +4 -4
- package/dist/orchestration/agent-tool-schemas.js.map +1 -1
- package/dist/orchestration/background-work.d.ts +9 -0
- package/dist/orchestration/background-work.d.ts.map +1 -0
- package/dist/orchestration/background-work.js +49 -0
- package/dist/orchestration/background-work.js.map +1 -0
- package/dist/orchestration/bridge.d.ts +6 -15
- package/dist/orchestration/bridge.d.ts.map +1 -1
- package/dist/orchestration/bridge.js +67 -32
- package/dist/orchestration/bridge.js.map +1 -1
- package/dist/orchestration/capabilities.d.ts.map +1 -1
- package/dist/orchestration/capabilities.js +18 -10
- package/dist/orchestration/capabilities.js.map +1 -1
- package/dist/orchestration/capacity.d.ts +3 -2
- package/dist/orchestration/capacity.d.ts.map +1 -1
- package/dist/orchestration/capacity.js +7 -0
- package/dist/orchestration/capacity.js.map +1 -1
- package/dist/orchestration/channel-controls.d.ts.map +1 -1
- package/dist/orchestration/channel-controls.js +3 -2
- package/dist/orchestration/channel-controls.js.map +1 -1
- package/dist/orchestration/channel-speech.d.ts +1 -1
- package/dist/orchestration/channel-speech.d.ts.map +1 -1
- package/dist/orchestration/channel-speech.js +2 -2
- package/dist/orchestration/channel-speech.js.map +1 -1
- package/dist/orchestration/cli-skills.d.ts +5 -0
- package/dist/orchestration/cli-skills.d.ts.map +1 -1
- package/dist/orchestration/config.d.ts +13 -0
- package/dist/orchestration/config.d.ts.map +1 -1
- package/dist/orchestration/config.js +6 -0
- package/dist/orchestration/config.js.map +1 -1
- package/dist/orchestration/container-tool-schemas.d.ts +37 -0
- package/dist/orchestration/container-tool-schemas.d.ts.map +1 -0
- package/dist/orchestration/container-tool-schemas.js +27 -0
- package/dist/orchestration/container-tool-schemas.js.map +1 -0
- package/dist/orchestration/container.d.ts.map +1 -1
- package/dist/orchestration/container.js +7 -0
- package/dist/orchestration/container.js.map +1 -1
- package/dist/orchestration/dashboard-provider-wait.d.ts +9 -0
- package/dist/orchestration/dashboard-provider-wait.d.ts.map +1 -0
- package/dist/orchestration/dashboard-provider-wait.js +26 -0
- package/dist/orchestration/dashboard-provider-wait.js.map +1 -0
- package/dist/orchestration/dashboard-reader-worker.js +18 -11
- package/dist/orchestration/dashboard-reader-worker.js.map +1 -1
- package/dist/orchestration/decision-context.js +1 -1
- package/dist/orchestration/decision-context.js.map +1 -1
- package/dist/orchestration/delivery.d.ts +2 -1
- package/dist/orchestration/delivery.d.ts.map +1 -1
- package/dist/orchestration/delivery.js +39 -5
- package/dist/orchestration/delivery.js.map +1 -1
- package/dist/orchestration/file-delivery.d.ts +1 -1
- package/dist/orchestration/file-delivery.d.ts.map +1 -1
- package/dist/orchestration/file-delivery.js +8 -1
- package/dist/orchestration/file-delivery.js.map +1 -1
- package/dist/orchestration/gateway-config.js +1 -1
- package/dist/orchestration/gateway-config.js.map +1 -1
- package/dist/orchestration/gateway-tasks/controller.d.ts +29 -0
- package/dist/orchestration/gateway-tasks/controller.d.ts.map +1 -0
- package/dist/orchestration/gateway-tasks/controller.js +139 -0
- package/dist/orchestration/gateway-tasks/controller.js.map +1 -0
- package/dist/orchestration/gateway-tasks/safemode.d.ts +19 -0
- package/dist/orchestration/gateway-tasks/safemode.d.ts.map +1 -0
- package/dist/orchestration/gateway-tasks/safemode.js +128 -0
- package/dist/orchestration/gateway-tasks/safemode.js.map +1 -0
- package/dist/orchestration/line-quota.d.ts +57 -0
- package/dist/orchestration/line-quota.d.ts.map +1 -0
- package/dist/orchestration/line-quota.js +191 -0
- package/dist/orchestration/line-quota.js.map +1 -0
- package/dist/orchestration/process-turn.d.ts +12 -2
- package/dist/orchestration/process-turn.d.ts.map +1 -1
- package/dist/orchestration/process-turn.js +72 -12
- package/dist/orchestration/process-turn.js.map +1 -1
- package/dist/orchestration/provider-admission.d.ts +63 -0
- package/dist/orchestration/provider-admission.d.ts.map +1 -0
- package/dist/orchestration/provider-admission.js +175 -0
- package/dist/orchestration/provider-admission.js.map +1 -0
- package/dist/orchestration/provider-error-metadata.d.ts +9 -0
- package/dist/orchestration/provider-error-metadata.d.ts.map +1 -0
- package/dist/orchestration/provider-error-metadata.js +28 -0
- package/dist/orchestration/provider-error-metadata.js.map +1 -0
- package/dist/orchestration/provider-scope.d.ts +28 -0
- package/dist/orchestration/provider-scope.d.ts.map +1 -0
- package/dist/orchestration/provider-scope.js +137 -0
- package/dist/orchestration/provider-scope.js.map +1 -0
- package/dist/orchestration/recovery.d.ts.map +1 -1
- package/dist/orchestration/recovery.js +4 -2
- package/dist/orchestration/recovery.js.map +1 -1
- package/dist/orchestration/runtime.d.ts +23 -0
- package/dist/orchestration/runtime.d.ts.map +1 -1
- package/dist/orchestration/runtime.js +248 -28
- package/dist/orchestration/runtime.js.map +1 -1
- package/dist/orchestration/skills.d.ts +2 -0
- package/dist/orchestration/skills.d.ts.map +1 -1
- package/dist/orchestration/skills.js +4 -3
- package/dist/orchestration/skills.js.map +1 -1
- package/dist/orchestration/store.d.ts +6 -0
- package/dist/orchestration/store.d.ts.map +1 -1
- package/dist/orchestration/store.js +51 -10
- package/dist/orchestration/store.js.map +1 -1
- package/dist/orchestration/task-controls.d.ts +12 -0
- package/dist/orchestration/task-controls.d.ts.map +1 -1
- package/dist/orchestration/task-controls.js +3 -1
- package/dist/orchestration/task-controls.js.map +1 -1
- package/dist/orchestration/tasks/driver.d.ts +5 -2
- package/dist/orchestration/tasks/driver.d.ts.map +1 -1
- package/dist/orchestration/tasks/driver.js +116 -15
- package/dist/orchestration/tasks/driver.js.map +1 -1
- package/dist/orchestration/tasks/pool.d.ts +2 -0
- package/dist/orchestration/tasks/pool.d.ts.map +1 -1
- package/dist/orchestration/tasks/pool.js +4 -0
- package/dist/orchestration/tasks/pool.js.map +1 -1
- package/dist/orchestration/tasks/scheduler.d.ts +12 -2
- package/dist/orchestration/tasks/scheduler.d.ts.map +1 -1
- package/dist/orchestration/tasks/scheduler.js +81 -7
- package/dist/orchestration/tasks/scheduler.js.map +1 -1
- package/dist/orchestration/tasks/service.d.ts +5 -1
- package/dist/orchestration/tasks/service.d.ts.map +1 -1
- package/dist/orchestration/tasks/service.js +49 -10
- package/dist/orchestration/tasks/service.js.map +1 -1
- package/dist/orchestration/token-ledger.d.ts +1 -0
- package/dist/orchestration/token-ledger.d.ts.map +1 -1
- package/dist/orchestration/token-ledger.js +6 -2
- package/dist/orchestration/token-ledger.js.map +1 -1
- package/dist/orchestration/token-usage.d.ts +3 -0
- package/dist/orchestration/token-usage.d.ts.map +1 -1
- package/dist/orchestration/token-usage.js +12 -3
- package/dist/orchestration/token-usage.js.map +1 -1
- package/dist/orchestration/types.d.ts +22 -1
- package/dist/orchestration/types.d.ts.map +1 -1
- package/dist/orchestration/types.js.map +1 -1
- package/dist/orchestration/worker-crons.d.ts +5 -0
- package/dist/orchestration/worker-crons.d.ts.map +1 -0
- package/dist/orchestration/worker-crons.js +84 -0
- package/dist/orchestration/worker-crons.js.map +1 -0
- package/dist/orchestration/worker-harness.d.ts +15 -0
- package/dist/orchestration/worker-harness.d.ts.map +1 -0
- package/dist/orchestration/worker-harness.js +72 -0
- package/dist/orchestration/worker-harness.js.map +1 -0
- package/dist/safemode/config.d.ts +7 -0
- package/dist/safemode/config.d.ts.map +1 -0
- package/dist/safemode/config.js +67 -0
- package/dist/safemode/config.js.map +1 -0
- package/dist/safemode/context.d.ts +7 -0
- package/dist/safemode/context.d.ts.map +1 -0
- package/dist/safemode/context.js +397 -0
- package/dist/safemode/context.js.map +1 -0
- package/dist/safemode/external-owners.d.ts +19 -0
- package/dist/safemode/external-owners.d.ts.map +1 -0
- package/dist/safemode/external-owners.js +229 -0
- package/dist/safemode/external-owners.js.map +1 -0
- package/dist/safemode/native.d.ts +38 -0
- package/dist/safemode/native.d.ts.map +1 -0
- package/dist/safemode/native.js +220 -0
- package/dist/safemode/native.js.map +1 -0
- package/dist/safemode/params.d.ts +10 -0
- package/dist/safemode/params.d.ts.map +1 -0
- package/dist/safemode/params.js +86 -0
- package/dist/safemode/params.js.map +1 -0
- package/dist/safemode/provenance.d.ts +45 -0
- package/dist/safemode/provenance.d.ts.map +1 -0
- package/dist/safemode/provenance.js +153 -0
- package/dist/safemode/provenance.js.map +1 -0
- package/dist/safemode/runner.d.ts +17 -0
- package/dist/safemode/runner.d.ts.map +1 -0
- package/dist/safemode/runner.js +398 -0
- package/dist/safemode/runner.js.map +1 -0
- package/dist/safemode/store.d.ts +56 -0
- package/dist/safemode/store.d.ts.map +1 -0
- package/dist/safemode/store.js +451 -0
- package/dist/safemode/store.js.map +1 -0
- package/dist/session/codex-auth.d.ts +37 -0
- package/dist/session/codex-auth.d.ts.map +1 -0
- package/dist/session/codex-auth.js +266 -0
- package/dist/session/codex-auth.js.map +1 -0
- package/dist/session/codex-container-runtime.d.ts +15 -0
- package/dist/session/codex-container-runtime.d.ts.map +1 -0
- package/dist/session/codex-container-runtime.js +85 -0
- package/dist/session/codex-container-runtime.js.map +1 -0
- package/dist/session/codex-context-defaults.json +5 -0
- package/dist/session/codex-context.d.ts +13 -0
- package/dist/session/codex-context.d.ts.map +1 -0
- package/dist/session/codex-context.js +27 -0
- package/dist/session/codex-context.js.map +1 -0
- package/dist/session/codex-extension-discovery.d.ts +21 -0
- package/dist/session/codex-extension-discovery.d.ts.map +1 -0
- package/dist/session/codex-extension-discovery.js +132 -0
- package/dist/session/codex-extension-discovery.js.map +1 -0
- package/dist/session/codex-native-mcp-client.d.ts +37 -0
- package/dist/session/codex-native-mcp-client.d.ts.map +1 -0
- package/dist/session/codex-native-mcp-client.js +164 -0
- package/dist/session/codex-native-mcp-client.js.map +1 -0
- package/dist/session/codex-policy.d.ts +6 -0
- package/dist/session/codex-policy.d.ts.map +1 -0
- package/dist/session/codex-policy.js +17 -0
- package/dist/session/codex-policy.js.map +1 -0
- package/dist/session/codex-process.d.ts +120 -0
- package/dist/session/codex-process.d.ts.map +1 -0
- package/dist/session/codex-process.js +817 -0
- package/dist/session/codex-process.js.map +1 -0
- package/dist/session/codex-runtime.d.ts +20 -0
- package/dist/session/codex-runtime.d.ts.map +1 -0
- package/dist/session/codex-runtime.js +190 -0
- package/dist/session/codex-runtime.js.map +1 -0
- package/dist/session/codex-tool-capture.d.ts +35 -0
- package/dist/session/codex-tool-capture.d.ts.map +1 -0
- package/dist/session/codex-tool-capture.js +178 -0
- package/dist/session/codex-tool-capture.js.map +1 -0
- package/dist/session/container-connectors.d.ts +10 -0
- package/dist/session/container-connectors.d.ts.map +1 -0
- package/dist/session/container-connectors.js +41 -0
- package/dist/session/container-connectors.js.map +1 -0
- package/dist/session/container-extensions.d.ts +4 -0
- package/dist/session/container-extensions.d.ts.map +1 -0
- package/dist/session/container-extensions.js +45 -0
- package/dist/session/container-extensions.js.map +1 -0
- package/dist/session/managed-connectors.d.ts +16 -0
- package/dist/session/managed-connectors.d.ts.map +1 -0
- package/dist/session/managed-connectors.js +25 -0
- package/dist/session/managed-connectors.js.map +1 -0
- package/dist/session/process-diagnostics.d.ts +14 -0
- package/dist/session/process-diagnostics.d.ts.map +1 -0
- package/dist/session/process-diagnostics.js +39 -0
- package/dist/session/process-diagnostics.js.map +1 -0
- package/dist/session/process.d.ts +4 -0
- package/dist/session/process.d.ts.map +1 -1
- package/dist/session/process.js +21 -16
- package/dist/session/process.js.map +1 -1
- package/dist/session/request-tool-capture.d.ts +1 -1
- package/dist/session/request-tool-capture.d.ts.map +1 -1
- package/dist/session/runtime-profile.d.ts +8 -0
- package/dist/session/runtime-profile.d.ts.map +1 -1
- package/dist/session/runtime-profile.js +3 -2
- package/dist/session/runtime-profile.js.map +1 -1
- package/dist/session/worker-environment.d.ts +5 -0
- package/dist/session/worker-environment.d.ts.map +1 -0
- package/dist/session/worker-environment.js +27 -0
- package/dist/session/worker-environment.js.map +1 -0
- package/dist/session/worker-extensions.d.ts +20 -0
- package/dist/session/worker-extensions.d.ts.map +1 -0
- package/dist/session/worker-extensions.js +322 -0
- package/dist/session/worker-extensions.js.map +1 -0
- package/dist/share/share-store.d.ts +5 -11
- package/dist/share/share-store.d.ts.map +1 -1
- package/dist/share/share-store.js +33 -5
- package/dist/share/share-store.js.map +1 -1
- package/dist/skills/loader.d.ts +2 -0
- package/dist/skills/loader.d.ts.map +1 -1
- package/dist/skills/loader.js.map +1 -1
- package/dist/types.d.ts +30 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/codex-context.d.ts +4 -0
- package/dist/ui/codex-context.d.ts.map +1 -0
- package/dist/ui/codex-context.js +15 -0
- package/dist/ui/codex-context.js.map +1 -0
- package/dist/ui/dashboard-client.d.ts.map +1 -1
- package/dist/ui/dashboard-client.js +17 -13
- package/dist/ui/dashboard-client.js.map +1 -1
- package/dist/ui/dashboard-presentation.d.ts +3 -1
- package/dist/ui/dashboard-presentation.d.ts.map +1 -1
- package/dist/ui/dashboard-presentation.js +17 -3
- package/dist/ui/dashboard-presentation.js.map +1 -1
- package/dist/ui/token-report.d.ts +9 -0
- package/dist/ui/token-report.d.ts.map +1 -1
- package/dist/ui/token-report.js +23 -11
- package/dist/ui/token-report.js.map +1 -1
- package/dist/ui/web-ui.d.ts.map +1 -1
- package/dist/ui/web-ui.js +53 -132
- package/dist/ui/web-ui.js.map +1 -1
- package/dist/voice/providers/paxalabs-live-stt.d.ts +29 -0
- package/dist/voice/providers/paxalabs-live-stt.d.ts.map +1 -0
- package/dist/voice/providers/paxalabs-live-stt.js +137 -0
- package/dist/voice/providers/paxalabs-live-stt.js.map +1 -0
- package/dist/voice/providers/registry.d.ts.map +1 -1
- package/dist/voice/providers/registry.js +2 -1
- package/dist/voice/providers/registry.js.map +1 -1
- package/mcp/capability-catalog.ts +2 -0
- package/mcp/extension-catalog.ts +18 -0
- package/mcp/lazy-connector.ts +4 -2
- package/mcp/lazy-tools.test.ts +29 -0
- package/mcp/modules.ts +1 -0
- package/mcp/server.ts +2 -2
- package/mcp/tools/cron/module.ts +8 -114
- package/mcp/tools/discord/commands.ts +4 -1
- package/mcp/tools/safemode/module.test.ts +29 -0
- package/mcp/tools/telegram/receiver-server.ts +6 -24
- package/mcp/tools/telegram/task-detail.ts +2 -1
- package/package.json +3 -2
- package/scripts/orchestration/audit-codex-context.cjs +83 -0
- package/scripts/orchestration/benchmark-worker-harnesses.cjs +112 -0
- package/scripts/orchestration/smoke-codex-extensions.ts +29 -0
- package/scripts/orchestration/smoke-codex-worker.cjs +166 -0
- package/scripts/orchestration/smoke-safemode-codex.cjs +66 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AgentOrchestrationRuntime = void 0;
|
|
4
|
+
const controller_1 = require("./gateway-tasks/controller");
|
|
5
|
+
const safemode_1 = require("./gateway-tasks/safemode");
|
|
6
|
+
const worker_crons_1 = require("./worker-crons");
|
|
4
7
|
const compact_measurements_1 = require("./compact-measurements");
|
|
5
8
|
const session_compaction_1 = require("./session-compaction");
|
|
6
9
|
const context_delivery_1 = require("./context-delivery");
|
|
@@ -70,8 +73,11 @@ const capacity_1 = require("./capacity");
|
|
|
70
73
|
const cleanup_1 = require("./tasks/cleanup");
|
|
71
74
|
const task_files_1 = require("./task-files");
|
|
72
75
|
const worker_shares_1 = require("./worker-shares");
|
|
76
|
+
const provider_admission_1 = require("./provider-admission");
|
|
77
|
+
const provider_scope_1 = require("./provider-scope");
|
|
73
78
|
/** Stable instructions are carried in the system prefix, not appended to every
|
|
74
79
|
* resumed user turn. Per-turn authorization flags remain explicit below it. */
|
|
80
|
+
const GATEWAY_TASK_INSTRUCTIONS = 'For safemode discovery use capabilities_list(scope=safemode); this creates no task. For authorized work on a discovered session use task_spawn(target_profile=gateway-managed, gateway_target={adapter:safemode,session_id:...}). Gateway-managed tasks are followed by the gateway and report results automatically; never spawn a polling worker.';
|
|
75
81
|
const CONTEXT_DELIVERY_INSTRUCTIONS = 'Worker profiles: default-worker is the general-purpose worker for research, files, browser/API operations, services, calculations and code. In host mode it uses the Agent working environment; no Git or projectRoot is required. In container mode it stays inside the app container. Only explicitly configured isolated-worktree mode requires Git for default-worker; media-worker remains available for standalone scratch work in isolated modes. State the authorized working directory in task instructions; workers may change directories only within their execution boundary. Serialize conflicting edits to the same shared files; continue related work with continue_task_id. Task context is incremental within a resumed CLI conversation. Omission means unchanged, not deleted. On a fresh context only active/waiting tasks and current reports are bootstrapped; use task_status for other past work or full results. Receipt recovery is evidence, not authorization to replay a command. Previously supplied materials remain in the resumed context; preserve their references when assigning workers. Never infer that missing image bytes mean a missing attachment if its ref was already supplied.';
|
|
76
82
|
class AgentOrchestrationRuntime {
|
|
77
83
|
setBrowserVoice(sessionId, principalId, enabled) {
|
|
@@ -122,7 +128,10 @@ class AgentOrchestrationRuntime {
|
|
|
122
128
|
this.taskControls = new task_controls_1.TaskControls(store, tasks);
|
|
123
129
|
this.stopControls = new stop_controls_1.StopControls(store, tasks, id => this.stopResponse(id));
|
|
124
130
|
this.channelControls = new channel_controls_1.ChannelControls(store, this.taskControls, this.stopControls, new telegram_voices_1.TelegramVoices(store, () => this.config.voice.tts, voice_catalog_1.voiceChoices, 8), () => (this.config.voice.enabled && this.config.voice.notes.replyWithVoice));
|
|
125
|
-
this.delivery = new delivery_1.DeliveryOutbox(store, (0, delivery_1.channelSender)(() => this.agent, fetch, (binding, speech) => Boolean(this.config.enabled && this.config.channels.includes(String(binding.channel)) && (this.config.voice.enabled && this.config.voice.notes.replyWithVoice) && (0, voice_reply_policy_1.voiceReplyAllowed)(store.channelVoiceMode(String(binding.channel), String(binding.chat_id), String(binding.thread_key ?? '')), speech.voiceOrigin === true) && (0, model_ref_1.canonicalVoiceProvider)(this.config.voice.tts.provider) === (0, model_ref_1.canonicalVoiceProvider)(speech.provider)), host.sendLinkedChannel
|
|
131
|
+
this.delivery = new delivery_1.DeliveryOutbox(store, (0, delivery_1.channelSender)(() => this.agent, fetch, (binding, speech) => Boolean(this.config.enabled && this.config.channels.includes(String(binding.channel)) && (this.config.voice.enabled && this.config.voice.notes.replyWithVoice) && (0, voice_reply_policy_1.voiceReplyAllowed)(store.channelVoiceMode(String(binding.channel), String(binding.chat_id), String(binding.thread_key ?? '')), speech.voiceOrigin === true) && (0, model_ref_1.canonicalVoiceProvider)(this.config.voice.tts.provider) === (0, model_ref_1.canonicalVoiceProvider)(speech.provider)), host.sendLinkedChannel,
|
|
132
|
+
// Includes 'processing' so the delivery that just 429'd (already claimed,
|
|
133
|
+
// no longer 'pending') still counts itself as part of the group needing quota.
|
|
134
|
+
() => Number(store.get(`SELECT COUNT(*) n FROM outbox o JOIN deliveries d ON d.id=json_extract(o.payload_json,'$.deliveryId') JOIN conversation_bindings b ON b.id=d.binding_id WHERE o.kind='delivery' AND o.state IN ('pending','processing') AND b.channel='line'`).n)));
|
|
126
135
|
this.decisions = new decisions_1.DecisionService(store, (response, binding, text) => {
|
|
127
136
|
this.delivery.enqueue(response, binding, text);
|
|
128
137
|
const spoken = store.get('SELECT text FROM response_speech WHERE response_id=?', response);
|
|
@@ -184,10 +193,13 @@ class AgentOrchestrationRuntime {
|
|
|
184
193
|
}
|
|
185
194
|
const tasks = new service_1.TaskService(store, agent.orchestration, agent.workspace);
|
|
186
195
|
const files = new task_files_1.TaskFiles(store, (0, path_1.join)(agent.workspace, '../..'), agent.type === 'app-agent' ? (0, path_1.join)(root, 'container-files') : undefined, agent.workspace);
|
|
187
|
-
const
|
|
196
|
+
const safemodeAllowed = () => agent.type !== 'app-agent' && Boolean(gateway.safemode?.allowedAgentIds?.includes(agent.id));
|
|
197
|
+
const gatewayAdapters = new Map(agent.type === 'app-agent' ? [] : [['safemode', new safemode_1.SafemodeTaskAdapter(agent.id, safemodeAllowed)]]);
|
|
198
|
+
const bridge = new bridge_1.TaskBridge(tasks, files, (0, worker_shares_1.workerShares)(files, agent, gateway), host.skills ? () => host.skills() : undefined, agent.type === 'app-agent' ? { agent, spool: (0, path_1.join)(root, 'container-files') } : undefined, (0, worker_crons_1.workerCrons)(files, agent, gateway), gatewayAdapters);
|
|
188
199
|
const personalRetention = (0, config_1.resolveDreamingConfig)(agent.dreaming, gateway.gateway.dreaming, gateway.gateway.timezone).staleness;
|
|
189
200
|
const sharedRetention = (0, knowledge_1.resolveSharedConfig)(agent.knowledge?.shared, gateway.gateway.knowledge?.shared).staleness;
|
|
190
201
|
bridge.recordRetrievals = (personalRetention.enabled && personalRetention.recordRetrievals) || (sharedRetention.enabled && sharedRetention.recordRetrievals);
|
|
202
|
+
let admissionStore;
|
|
191
203
|
try {
|
|
192
204
|
(0, recovery_1.recoverOrchestration)(store);
|
|
193
205
|
(0, session_compaction_1.recoverSessionCompaction)(store);
|
|
@@ -195,6 +207,8 @@ class AgentOrchestrationRuntime {
|
|
|
195
207
|
// their global capacity conservatively as well as the per-agent slots.
|
|
196
208
|
const recoveredReservations = new Map();
|
|
197
209
|
for (const row of store.all("SELECT id FROM tasks WHERE state='needs_reconciliation' AND active_attempt_id IS NOT NULL")) {
|
|
210
|
+
if (store.task(String(row.id))?.gatewayTarget)
|
|
211
|
+
continue;
|
|
198
212
|
recoveredReservations.set(String(row.id), (0, capacity_1.gatewayCapacity)(gateway).acquireWorker(agent.id, String(row.id), false));
|
|
199
213
|
}
|
|
200
214
|
if (agent.orchestration?.enabled)
|
|
@@ -209,11 +223,49 @@ class AgentOrchestrationRuntime {
|
|
|
209
223
|
const workspaces = new workspace_1.TaskWorkspaces(store, project, (0, path_1.join)(root, 'task-worktrees'), agent.orchestration?.tasks?.workspaceMode);
|
|
210
224
|
for (const row of store.all("SELECT id FROM tasks WHERE state IN ('completed','failed','cancelled')"))
|
|
211
225
|
await workspaces.release(String(row.id));
|
|
212
|
-
const
|
|
213
|
-
const
|
|
226
|
+
const providerAdmission = admissionStore = new provider_admission_1.ProviderAdmissionStore((0, path_1.join)(sessions.getAgentsBaseDir(), 'provider-admission.db'));
|
|
227
|
+
const providerPolicy = () => runtime.config.providerAdmission;
|
|
228
|
+
const driver = workerDriver ?? new driver_1.ClaudeWorkerDriver(agent, gateway, tasks, bridge, workspaces, (0, path_1.join)(root, 'task-attempts'), host.onManagedTurn, (task, permit, harness, model, resolvedIdentity) => {
|
|
229
|
+
const actualAgent = { ...agent, workers: { ...agent.workers, harness } };
|
|
230
|
+
const scope = resolvedIdentity
|
|
231
|
+
? (0, provider_scope_1.resolvedCodexProviderScope)(resolvedIdentity, providerPolicy().recoveryGeneration)
|
|
232
|
+
: (0, provider_scope_1.resolveProviderScope)(actualAgent, gateway, model, 'worker', task.resourceProfile?.projectRoot);
|
|
233
|
+
const configured = (0, provider_scope_1.resolveProviderScope)(agent, gateway, task.model, 'worker', task.resourceProfile?.projectRoot);
|
|
234
|
+
store.run('INSERT INTO provider_task_routes VALUES(?,?,?) ON CONFLICT(task_id) DO UPDATE SET configured_scope=excluded.configured_scope,actual_scope=excluded.actual_scope', task.taskId, configured, scope);
|
|
235
|
+
if (scope === permit.scope)
|
|
236
|
+
return;
|
|
237
|
+
providerAdmission.release(permit);
|
|
238
|
+
const next = providerAdmission.acquire(scope, providerPolicy());
|
|
239
|
+
if (next.waiting) {
|
|
240
|
+
runtime.waitForProvider(task.taskId, task.conversationId, scope, next.waiting);
|
|
241
|
+
throw new types_2.OrchestrationError('PROVIDER_WAITING');
|
|
242
|
+
}
|
|
243
|
+
delete permit.probe;
|
|
244
|
+
Object.assign(permit, next.permit);
|
|
245
|
+
});
|
|
246
|
+
const scheduler = new scheduler_1.WorkerScheduler(tasks, driver, undefined, recoveredReservations, {
|
|
247
|
+
acquire: task => {
|
|
248
|
+
const configured = (0, provider_scope_1.resolveProviderScope)(agent, gateway, task.model, 'worker', task.resourceProfile?.projectRoot);
|
|
249
|
+
const previous = store.get('SELECT configured_scope,actual_scope FROM provider_task_routes WHERE task_id=?', task.taskId);
|
|
250
|
+
const scope = previous?.configured_scope === configured ? String(previous.actual_scope) : configured;
|
|
251
|
+
const result = providerAdmission.acquire(scope, providerPolicy());
|
|
252
|
+
if (result.waiting)
|
|
253
|
+
runtime.waitForProvider(task.taskId, task.conversationId, scope, result.waiting);
|
|
254
|
+
else
|
|
255
|
+
store.run('DELETE FROM provider_waits WHERE entity_id=?', task.taskId);
|
|
256
|
+
return result;
|
|
257
|
+
},
|
|
258
|
+
renew: permit => providerAdmission.renew(permit, providerPolicy()),
|
|
259
|
+
settle: (permit, result) => {
|
|
260
|
+
if (providerAdmission.settle(permit, result, providerPolicy()))
|
|
261
|
+
runtime.providerRecovered(permit.scope);
|
|
262
|
+
},
|
|
263
|
+
release: permit => providerAdmission.release(permit),
|
|
264
|
+
});
|
|
214
265
|
const cleanup = new cleanup_1.ResourceCleanup(store, (0, path_1.join)(root, 'task-worktrees'), (0, path_1.join)(root, 'task-artifacts'), (0, config_2.resolveOrchestrationConfig)(agent.orchestration).tasks.resourceRetentionDays);
|
|
215
266
|
const runtime = new AgentOrchestrationRuntime(agent, root, host, store, new history_1.OrchestrationHistoryWriter(store, sessions, historyDb), scheduler, bridge, tasks);
|
|
216
267
|
runtime.gateway = gateway;
|
|
268
|
+
runtime.providerAdmission = providerAdmission;
|
|
217
269
|
runtime.releaseLock = releaseLock;
|
|
218
270
|
runtime.settleResources = async () => { cleanup.stop(); await workspaces.settle(); await cleanup.settle(); };
|
|
219
271
|
const shared = (0, knowledge_1.resolveSharedConfig)(agent.knowledge?.shared, gateway.gateway.knowledge?.shared);
|
|
@@ -222,6 +274,8 @@ class AgentOrchestrationRuntime {
|
|
|
222
274
|
runtime.drain();
|
|
223
275
|
await runtime.flushHistory();
|
|
224
276
|
scheduler.start();
|
|
277
|
+
runtime.gatewayTasks = new controller_1.GatewayTaskController(tasks, gatewayAdapters);
|
|
278
|
+
runtime.gatewayTasks.start();
|
|
225
279
|
runtime.mailboxTimer = setInterval(() => {
|
|
226
280
|
try {
|
|
227
281
|
runtime.pumpMailbox();
|
|
@@ -252,6 +306,7 @@ class AgentOrchestrationRuntime {
|
|
|
252
306
|
return runtime;
|
|
253
307
|
}
|
|
254
308
|
catch (error) {
|
|
309
|
+
admissionStore?.close();
|
|
255
310
|
await bridge.close();
|
|
256
311
|
store.close();
|
|
257
312
|
releaseLock();
|
|
@@ -267,14 +322,60 @@ class AgentOrchestrationRuntime {
|
|
|
267
322
|
if (!Number.isSafeInteger(after) || after < 0 || after > Number(conversation.last_event_seq))
|
|
268
323
|
throw new types_2.OrchestrationError('INVALID_CURSOR');
|
|
269
324
|
const tasks = this.tasks.status(id, principalId).map(t => {
|
|
270
|
-
return { taskId: t.taskId, title: t.title, state: t.state, stateVersion: t.stateVersion, progress: t.latestProgress, execution: t.execution, result: t.result?.summary, updatedAt: Math.max(t.updatedAt, t.execution?.lastActivityAt ?? 0) };
|
|
325
|
+
return { taskId: t.taskId, title: t.title, state: t.state, stateVersion: t.stateVersion, providerWaiting: t.providerWaiting, progress: t.latestProgress, execution: t.execution, result: t.result?.summary, updatedAt: Math.max(t.updatedAt, t.execution?.lastActivityAt ?? 0) };
|
|
271
326
|
});
|
|
272
327
|
const responses = this.store.all('SELECT id,request_id,state,generated_text,COALESCE(completed_at,created_at) AS message_at FROM assistant_responses WHERE conversation_id=? ORDER BY message_at DESC,rowid DESC LIMIT 100', id).reverse().map(r => ({
|
|
273
328
|
id: r.id, requestId: r.request_id, state: r.state, text: r.generated_text, createdAt: r.message_at,
|
|
274
329
|
files: this.store.all('SELECT path FROM task_files WHERE response_id=? ORDER BY created_at,id', r.id).map(f => f.path),
|
|
275
330
|
}));
|
|
276
331
|
const tools = this.store.all("SELECT seq,payload_json FROM conversation_events WHERE conversation_id=? AND seq>? AND type='tool.activity' ORDER BY seq LIMIT 500", id, after).map(r => ({ seq: r.seq, ...JSON.parse(String(r.payload_json)).payload }));
|
|
277
|
-
|
|
332
|
+
const waiting = this.store.get('SELECT waiting_json FROM provider_waits WHERE entity_id=?', `session:${sessionId}`);
|
|
333
|
+
return { cursor: tools.length === 500 ? tools[tools.length - 1].seq : Number(conversation.last_event_seq), tasks, responses, tools, busy: this.isBusy(sessionId), providerWaiting: waiting ? JSON.parse(String(waiting.waiting_json)) : undefined };
|
|
334
|
+
}
|
|
335
|
+
waitForProvider(entity, conversationId, scope, waiting) {
|
|
336
|
+
const previous = this.store.get('SELECT waiting_json FROM provider_waits WHERE entity_id=?', entity);
|
|
337
|
+
const data = JSON.stringify(waiting);
|
|
338
|
+
let text = '';
|
|
339
|
+
let changed = false;
|
|
340
|
+
this.store.compose(() => {
|
|
341
|
+
if (previous?.waiting_json !== data) {
|
|
342
|
+
changed = true;
|
|
343
|
+
this.store.run('INSERT INTO provider_waits VALUES(?,?,?,?,?) ON CONFLICT(entity_id) DO UPDATE SET scope=excluded.scope,waiting_json=excluded.waiting_json,updated_at=excluded.updated_at', entity, conversationId, scope, data, Date.now());
|
|
344
|
+
this.store.appendEvent(conversationId, 'provider.waiting', { entity, ...waiting });
|
|
345
|
+
}
|
|
346
|
+
const notice = this.store.get('SELECT episode FROM provider_notices WHERE conversation_id=? AND scope=?', conversationId, scope);
|
|
347
|
+
if (notice?.episode !== waiting.episode) {
|
|
348
|
+
text = waiting.requiresConfigurationChange
|
|
349
|
+
? 'Waiting for provider. Check the provider credentials, model or quota. Your pending messages and task results are saved.'
|
|
350
|
+
: 'Waiting for provider. Your pending messages and task results are saved. I will retry automatically after the cooldown.';
|
|
351
|
+
const response = this.decisions.notice(conversationId, text, true);
|
|
352
|
+
this.store.run('INSERT INTO provider_notices VALUES(?,?,?,0) ON CONFLICT(conversation_id,scope) DO UPDATE SET episode=excluded.episode,recovered=0', conversationId, scope, waiting.episode);
|
|
353
|
+
const session = this.store.get('SELECT agent_session_id FROM conversations WHERE id=?', conversationId);
|
|
354
|
+
if (session)
|
|
355
|
+
this.publishText(String(session.agent_session_id), response, text, true);
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
if (changed || text) {
|
|
359
|
+
void this.flushHistory().catch(() => { });
|
|
360
|
+
void this.delivery.tick().catch(() => { });
|
|
361
|
+
}
|
|
362
|
+
return text;
|
|
363
|
+
}
|
|
364
|
+
providerRecovered(scope) {
|
|
365
|
+
this.store.compose(() => {
|
|
366
|
+
this.store.run('DELETE FROM provider_waits WHERE scope=?', scope);
|
|
367
|
+
for (const conversation of this.store.all(`SELECT n.conversation_id,c.agent_session_id FROM provider_notices n
|
|
368
|
+
JOIN conversations c ON c.id=n.conversation_id WHERE n.scope=? AND n.recovered=0 AND c.status='active'`, scope)) {
|
|
369
|
+
const conversationId = String(conversation.conversation_id), sessionId = String(conversation.agent_session_id);
|
|
370
|
+
this.store.run('UPDATE provider_notices SET recovered=1 WHERE conversation_id=? AND scope=?', conversationId, scope);
|
|
371
|
+
this.store.appendEvent(conversationId, 'provider.recovered', {});
|
|
372
|
+
const text = 'The provider is responding again. Pending messages and task reports can continue.';
|
|
373
|
+
const response = this.decisions.notice(conversationId, text, true);
|
|
374
|
+
this.publishText(sessionId, response, text, true);
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
void this.flushHistory().catch(() => { });
|
|
378
|
+
void this.delivery.tick().catch(() => { });
|
|
278
379
|
}
|
|
279
380
|
isBusy(sessionId) { return this.active.has(sessionId); }
|
|
280
381
|
isCompacting(sessionId) { return this.active.get(sessionId)?.maintenance === 'compact'; }
|
|
@@ -330,6 +431,7 @@ class AgentOrchestrationRuntime {
|
|
|
330
431
|
if (this.agent.type !== 'app-agent' && config?.tasks?.workspaceMode === 'container')
|
|
331
432
|
throw new types_2.OrchestrationError('CONTAINER_REQUIRED');
|
|
332
433
|
this.config = (0, config_2.resolveOrchestrationConfig)(config, backendAgent.voice ?? { enabled: false });
|
|
434
|
+
this.agent.orchestration = config;
|
|
333
435
|
this.tasks.configure(config);
|
|
334
436
|
if (!this.config.enabled)
|
|
335
437
|
this.drain();
|
|
@@ -423,6 +525,18 @@ class AgentOrchestrationRuntime {
|
|
|
423
525
|
void operation.finally(() => this.pending.delete(operation)).catch(() => { });
|
|
424
526
|
return operation;
|
|
425
527
|
}
|
|
528
|
+
/** Lightweight live ownership only: no transcript or token-ledger scans. */
|
|
529
|
+
processOwners() {
|
|
530
|
+
return this.store.all(`SELECT t.snapshot_json,a.payload_json FROM tasks t JOIN task_attempts a
|
|
531
|
+
ON a.id=t.active_attempt_id WHERE t.active_attempt_id IS NOT NULL`).flatMap(row => {
|
|
532
|
+
const task = JSON.parse(String(row.snapshot_json)), attempt = JSON.parse(String(row.payload_json));
|
|
533
|
+
const pid = attempt.processIdentity?.pid;
|
|
534
|
+
return Number.isInteger(pid) ? [{ pid, startTicks: attempt.processIdentity?.startTicks, group: 'worker', agentId: this.agent.id,
|
|
535
|
+
sessionId: task.agentSessionId, taskId: task.taskId, title: task.title,
|
|
536
|
+
harness: attempt.harness ?? 'claude', model: attempt.harnessModel ?? task.model,
|
|
537
|
+
container: this.agent.type === 'app-agent' ? this.agent.container : undefined }] : [];
|
|
538
|
+
});
|
|
539
|
+
}
|
|
426
540
|
sessionContextWindow(sessionId) {
|
|
427
541
|
if (!this.store.get("SELECT name FROM sqlite_master WHERE name='token_turns'"))
|
|
428
542
|
return null;
|
|
@@ -447,8 +561,8 @@ class AgentOrchestrationRuntime {
|
|
|
447
561
|
const tool = event ? JSON.parse(String(event.payload_json)).payload : undefined;
|
|
448
562
|
const measured = (0, token_ledger_1.summarizeTokenTurns)((0, token_ledger_1.measuredTurns)(this.store, String(row.agent_session_id)).filter(turn => turn.id === attempt?.attemptId));
|
|
449
563
|
return { tokenSummary: { totalTokens: measured.totalTokens }, contextTools: measured.contextTools, loadedTools: measured.loadedTools, usedTools: measured.usedTools, taskId: row.id, sessionId: row.agent_session_id, state: row.state, title: snapshot.title,
|
|
450
|
-
execution: snapshot.execution, workerId: attempt?.workerId, workstreamId: snapshot.workstreamId, continueTaskId: snapshot.continueTaskId, resumed: attempt?.resumeSession,
|
|
451
|
-
attemptId: attempt?.attemptId, workerSessionId: attempt?.sessionId, hostProcessId: row.active_attempt_id ? attempt?.processIdentity?.pid : undefined,
|
|
564
|
+
executionType: snapshot.gatewayTarget ? 'gateway-managed' : 'worker', gatewayTarget: snapshot.gatewayTarget, execution: snapshot.execution, workerId: attempt?.workerId, workstreamId: snapshot.workstreamId, continueTaskId: snapshot.continueTaskId, resumed: attempt?.resumeSession,
|
|
565
|
+
attemptId: attempt?.attemptId, workerSessionId: snapshot.gatewayTarget ? undefined : attempt?.sessionId, targetSessionId: snapshot.gatewayTarget?.sessionId, hostProcessId: row.active_attempt_id ? attempt?.processIdentity?.pid : undefined,
|
|
452
566
|
container: this.agent.type === 'app-agent' ? this.agent.container : undefined,
|
|
453
567
|
lastTool: tool ? { name: tool.name, type: tool.type, is_error: tool.is_error } : undefined };
|
|
454
568
|
});
|
|
@@ -673,6 +787,7 @@ class AgentOrchestrationRuntime {
|
|
|
673
787
|
}
|
|
674
788
|
return receipt;
|
|
675
789
|
});
|
|
790
|
+
void this.flushHistory().catch(() => { });
|
|
676
791
|
if (this.config.conversation.semanticIntake)
|
|
677
792
|
this.intake.touch(receipt.inputId);
|
|
678
793
|
const previous = this.inputResponses.get(receipt.inputId);
|
|
@@ -719,6 +834,12 @@ class AgentOrchestrationRuntime {
|
|
|
719
834
|
if (Date.now() >= this.nextQuestionCheck) {
|
|
720
835
|
this.questionControls.tick();
|
|
721
836
|
this.nextQuestionCheck = Date.now() + 1000;
|
|
837
|
+
// A sibling agent or a worker can recover the shared circuit without a
|
|
838
|
+
// conversation turn here. Deliver its notices through the same outbox.
|
|
839
|
+
for (const row of this.store.all('SELECT DISTINCT scope FROM provider_notices WHERE recovered=0 LIMIT 100')) {
|
|
840
|
+
if (this.providerAdmission.recovered(String(row.scope)))
|
|
841
|
+
this.providerRecovered(String(row.scope));
|
|
842
|
+
}
|
|
722
843
|
}
|
|
723
844
|
for (const conversation of this.questionControls.initialReviews([...this.active.keys()])) {
|
|
724
845
|
this.store.compose(() => {
|
|
@@ -741,25 +862,46 @@ class AgentOrchestrationRuntime {
|
|
|
741
862
|
ingressKey: `notification:${row.notification_id}${row.previous_input_id ? `:retry:${row.previous_seq}` : ''}`, capabilities: { execute: false, writeMemory: false } }, this.config.conversation.maxPendingInputs);
|
|
742
863
|
}
|
|
743
864
|
}
|
|
744
|
-
|
|
745
|
-
|
|
865
|
+
let mailboxCursor = 0;
|
|
866
|
+
const visitedSessions = new Set();
|
|
867
|
+
mailbox: while (this.active.size < this.config.conversation.maxActiveSessions) {
|
|
868
|
+
const rows = this.store.all("SELECT i.*,i.rowid AS mailbox_row FROM conversation_inputs i JOIN conversations c ON c.id=i.conversation_id WHERE i.status='accepted' AND i.rowid>? AND c.agent_session_id NOT IN (SELECT value FROM json_each(?)) ORDER BY i.rowid LIMIT 100", mailboxCursor, JSON.stringify([...this.active.keys()]));
|
|
869
|
+
if (!rows.length)
|
|
746
870
|
break;
|
|
747
|
-
const
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
871
|
+
for (const row of rows) {
|
|
872
|
+
mailboxCursor = Number(row.mailbox_row);
|
|
873
|
+
if (this.active.size >= this.config.conversation.maxActiveSessions)
|
|
874
|
+
break;
|
|
875
|
+
const input = JSON.parse(String(row.ingress_json));
|
|
876
|
+
if (!input.scope || !input.capabilities || this.active.has(input.scope.agentSessionId))
|
|
877
|
+
continue;
|
|
878
|
+
if (visitedSessions.has(input.scope.agentSessionId))
|
|
879
|
+
continue;
|
|
880
|
+
visitedSessions.add(input.scope.agentSessionId);
|
|
881
|
+
const scope = (0, provider_scope_1.resolveProviderScope)(this.agent, this.gateway, input.model, 'agent');
|
|
882
|
+
const waiting = this.providerAdmission.inspect(scope, this.config.providerAdmission);
|
|
883
|
+
if (waiting) {
|
|
884
|
+
const text = this.waitForProvider(`session:${input.scope.agentSessionId}`, String(row.conversation_id), scope, waiting);
|
|
885
|
+
if (text)
|
|
886
|
+
this.deferred.get(String(row.id))?.resolve(text);
|
|
887
|
+
continue;
|
|
888
|
+
}
|
|
889
|
+
// A persisted input retains the authenticated scope and model from ingress.
|
|
890
|
+
// Recovery can repeat inference, but committed tool receipts remain fenced.
|
|
891
|
+
const result = this.send({ ...input, acceptedInputId: String(row.id) }, input.capabilities, { timeoutMs: this.config.conversation.maxDecisionDurationMs, model: input.model, onTool: event => this.inputTools.get(String(row.id))?.(event), onText: text => {
|
|
892
|
+
const responseId = this.responseIdForInput(String(row.id));
|
|
893
|
+
if (input.modality !== 'live_voice' && responseId) {
|
|
894
|
+
try {
|
|
895
|
+
this.inputStreams.get(String(row.id))?.push({ responseId, text });
|
|
896
|
+
}
|
|
897
|
+
catch { /* slow audio cannot stall inference */ }
|
|
757
898
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
899
|
+
} });
|
|
900
|
+
void result.then(text => this.deferred.get(String(row.id))?.resolve(text), error => this.deferred.get(String(row.id))?.reject(error))
|
|
901
|
+
.finally(() => this.deferred.delete(String(row.id)));
|
|
902
|
+
}
|
|
903
|
+
if (this.active.size >= this.config.conversation.maxActiveSessions)
|
|
904
|
+
break mailbox;
|
|
763
905
|
}
|
|
764
906
|
}
|
|
765
907
|
async run(input, capabilities, options) {
|
|
@@ -779,13 +921,29 @@ class AgentOrchestrationRuntime {
|
|
|
779
921
|
const questionReview = Boolean(input.ingressKey?.startsWith('question-review:'));
|
|
780
922
|
let internalReview = false;
|
|
781
923
|
let streamedDisplay = '';
|
|
924
|
+
let providerPermit;
|
|
925
|
+
let providerRenewal;
|
|
782
926
|
try {
|
|
783
927
|
const receipt = this.store.acceptInput(input, this.config.conversation.maxPendingInputs);
|
|
928
|
+
await this.flushHistory();
|
|
784
929
|
if (this.config.conversation.semanticIntake)
|
|
785
930
|
this.intake.touch(receipt.inputId);
|
|
786
931
|
const admitted = this.store.get('SELECT ingress_json,binding_id FROM conversation_inputs WHERE id=?', receipt.inputId);
|
|
787
932
|
const admittedModel = admitted ? JSON.parse(String(admitted.ingress_json)).model : undefined;
|
|
788
|
-
options = { ...options, model: options.model ?? admittedModel ?? input.model };
|
|
933
|
+
options = { ...options, model: options.model ?? admittedModel ?? input.model ?? this.agent.claude.model };
|
|
934
|
+
const providerScope = (0, provider_scope_1.resolveProviderScope)(this.agent, this.gateway, options.model, 'agent');
|
|
935
|
+
const provider = this.providerAdmission.acquire(providerScope, this.config.providerAdmission);
|
|
936
|
+
if (provider.waiting)
|
|
937
|
+
return this.waitForProvider(`session:${sessionId}`, receipt.conversationId, providerScope, provider.waiting);
|
|
938
|
+
providerPermit = provider.permit;
|
|
939
|
+
this.store.run('DELETE FROM provider_waits WHERE entity_id=?', `session:${sessionId}`);
|
|
940
|
+
if (providerPermit.probe) {
|
|
941
|
+
providerRenewal = setInterval(() => { try {
|
|
942
|
+
this.providerAdmission.renew(providerPermit, this.config.providerAdmission);
|
|
943
|
+
}
|
|
944
|
+
catch { /* durable lease expires conservatively */ } }, Math.max(250, Math.floor(this.config.providerAdmission.probeLeaseMs / 3)));
|
|
945
|
+
providerRenewal.unref();
|
|
946
|
+
}
|
|
789
947
|
if (this.draining)
|
|
790
948
|
this.store.run("UPDATE conversations SET status='draining' WHERE id=?", receipt.conversationId);
|
|
791
949
|
this.seenSessions.add(sessionId);
|
|
@@ -1106,7 +1264,7 @@ class AgentOrchestrationRuntime {
|
|
|
1106
1264
|
// produced, while speech and review turns fill the optional fields their per-turn overlay
|
|
1107
1265
|
// asks for. This restores the structured-output guarantee without a per-turn tools diff.
|
|
1108
1266
|
ticket.profile.responseSchema = response_schema_1.ORCHESTRATION_RESPONSE_SCHEMA;
|
|
1109
|
-
ticket.profile.overlay += `\n\n${CONTEXT_DELIVERY_INSTRUCTIONS}\n\nOnly when the current turn explicitly enables semantic intake, apply these rules:\n${conversation_intake_1.INTAKE_OVERLAY}`;
|
|
1267
|
+
ticket.profile.overlay += `\n\n${CONTEXT_DELIVERY_INSTRUCTIONS}${this.agent.type !== 'app-agent' && this.gateway.safemode?.allowedAgentIds?.includes(this.agent.id) ? '\n' + GATEWAY_TASK_INSTRUCTIONS : ''}\n\nOnly when the current turn explicitly enables semantic intake, apply these rules:\n${conversation_intake_1.INTAKE_OVERLAY}`;
|
|
1110
1268
|
// Continue the CLI session this agent session already has a transcript for. Each decision
|
|
1111
1269
|
// turn is still its own process; resuming is what lets the next one reuse the previous
|
|
1112
1270
|
// turn's cached prefix instead of paying a full cache write, and it replaces the flattened
|
|
@@ -1129,6 +1287,7 @@ class AgentOrchestrationRuntime {
|
|
|
1129
1287
|
ticket.profile.excludedHistoryOperationIds = this.store.all(`SELECT r.id FROM assistant_responses r
|
|
1130
1288
|
JOIN conversation_decisions d ON d.id=r.decision_id WHERE d.session_id=? AND r.state='failed'`, sessionId)
|
|
1131
1289
|
.map(row => `response:${row.id}`);
|
|
1290
|
+
ticket.profile.responseId = decision.responseId;
|
|
1132
1291
|
agentSession = await this.host.createAgentSession(sessionId, ticket.profile, options.model, input.scope);
|
|
1133
1292
|
const reportingTasks = new Set(this.store.all("SELECT task_id FROM notifications WHERE decision_id=? AND status='assigned'", decision.decisionId).map(row => String(row.task_id)));
|
|
1134
1293
|
const taskCandidates = this.tasks.context(receipt.conversationId, input.scope.principalId, decision.decisionId)
|
|
@@ -1210,7 +1369,23 @@ class AgentOrchestrationRuntime {
|
|
|
1210
1369
|
displayChunk(chunk);
|
|
1211
1370
|
});
|
|
1212
1371
|
active.turn = turn;
|
|
1372
|
+
let providerResponded = false;
|
|
1373
|
+
void turn.providerReady.then(() => {
|
|
1374
|
+
providerResponded = true;
|
|
1375
|
+
try {
|
|
1376
|
+
if (!active.stopping && this.providerAdmission.settle(providerPermit, 'success', this.config.providerAdmission))
|
|
1377
|
+
this.providerRecovered(providerPermit.scope);
|
|
1378
|
+
}
|
|
1379
|
+
catch { /* Never turn a successful inference into a failed task receipt. */ }
|
|
1380
|
+
}).catch(() => { });
|
|
1213
1381
|
const response = await turn.result;
|
|
1382
|
+
if (!response.interrupted && !providerResponded) {
|
|
1383
|
+
try {
|
|
1384
|
+
if (this.providerAdmission.settle(providerPermit, 'success', this.config.providerAdmission))
|
|
1385
|
+
this.providerRecovered(providerPermit.scope);
|
|
1386
|
+
}
|
|
1387
|
+
catch { /* Provider bookkeeping cannot invalidate a completed inference. */ }
|
|
1388
|
+
}
|
|
1214
1389
|
if (!response.interrupted) {
|
|
1215
1390
|
// A completed CLI turn has consumed its tool results. Failed/interrupted
|
|
1216
1391
|
// turns never advance this checkpoint, so committed receipts can recover.
|
|
@@ -1284,6 +1459,13 @@ class AgentOrchestrationRuntime {
|
|
|
1284
1459
|
? (speechEnabled || active.stopReason === 'barge-in' || parsed.outcome !== 'structured' ? stoppedDisplay : surfaces.display || 'Response stopped.')
|
|
1285
1460
|
: surfaces.display || '';
|
|
1286
1461
|
this.decisions.finish(decision, display, response.interrupted ? 'interrupted' : 'completed', channelSpeech && !silent ? taskSpeech || surfaces.spoken : undefined, !active.stopping && !silent);
|
|
1462
|
+
if (active.notification && !response.interrupted) {
|
|
1463
|
+
const batch = this.store.get('SELECT COUNT(*)-COUNT(DISTINCT task_id) n FROM notifications WHERE decision_id=?', decision.decisionId);
|
|
1464
|
+
try {
|
|
1465
|
+
this.providerAdmission.coalesced(Number(batch?.n ?? 0));
|
|
1466
|
+
}
|
|
1467
|
+
catch { /* telemetry cannot invalidate a report */ }
|
|
1468
|
+
}
|
|
1287
1469
|
if (!silent && speechEnabled && !response.interrupted && !taskSpeech) {
|
|
1288
1470
|
if (!channelSpeech)
|
|
1289
1471
|
this.store.run('INSERT INTO response_speech VALUES(?,?)', decision.responseId, surfaces.spoken);
|
|
@@ -1328,6 +1510,15 @@ class AgentOrchestrationRuntime {
|
|
|
1328
1510
|
return silent ? acknowledgement : display || acknowledgement;
|
|
1329
1511
|
}
|
|
1330
1512
|
catch (error) {
|
|
1513
|
+
if (providerPermit && active.turn && !active.stopping) {
|
|
1514
|
+
const failure = (0, provider_admission_1.providerFailure)(error);
|
|
1515
|
+
if (failure) {
|
|
1516
|
+
try {
|
|
1517
|
+
this.providerAdmission.settle(providerPermit, failure, this.config.providerAdmission);
|
|
1518
|
+
}
|
|
1519
|
+
catch { /* Preserve original error and cleanup even when shared storage is busy. */ }
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1331
1522
|
// Retain a safe diagnostic code; never log prompts, credentials or provider bodies.
|
|
1332
1523
|
failedTurn = true;
|
|
1333
1524
|
const failure = error;
|
|
@@ -1381,6 +1572,14 @@ class AgentOrchestrationRuntime {
|
|
|
1381
1572
|
throw error;
|
|
1382
1573
|
}
|
|
1383
1574
|
finally {
|
|
1575
|
+
if (providerRenewal)
|
|
1576
|
+
clearInterval(providerRenewal);
|
|
1577
|
+
if (providerPermit) {
|
|
1578
|
+
try {
|
|
1579
|
+
this.providerAdmission.release(providerPermit);
|
|
1580
|
+
}
|
|
1581
|
+
catch { /* lease expires; process cleanup must still run */ }
|
|
1582
|
+
}
|
|
1384
1583
|
removeContextObserver?.();
|
|
1385
1584
|
revoke?.();
|
|
1386
1585
|
if (agentSession)
|
|
@@ -1396,7 +1595,23 @@ class AgentOrchestrationRuntime {
|
|
|
1396
1595
|
}
|
|
1397
1596
|
stopResponse(sessionId, reason = 'user') {
|
|
1398
1597
|
const active = this.active.get(sessionId);
|
|
1399
|
-
if (!active
|
|
1598
|
+
if (!active) {
|
|
1599
|
+
if (reason !== 'user' || !this.store.get('SELECT entity_id FROM provider_waits WHERE entity_id=?', `session:${sessionId}`))
|
|
1600
|
+
return false;
|
|
1601
|
+
let stopped = false;
|
|
1602
|
+
for (const row of this.store.all("SELECT i.* FROM conversation_inputs i JOIN conversations c ON c.id=i.conversation_id WHERE c.agent_session_id=? AND i.status='accepted' ORDER BY i.input_seq", sessionId)) {
|
|
1603
|
+
const decision = this.decisions.begin(String(row.conversation_id), String(row.principal_id), [String(row.id)], row.request_id ? String(row.request_id) : undefined);
|
|
1604
|
+
this.decisions.interrupt(decision);
|
|
1605
|
+
this.decisions.finish(decision, '', 'interrupted', undefined, false);
|
|
1606
|
+
this.deferred.get(String(row.id))?.resolve('Response stopped.');
|
|
1607
|
+
this.deferred.delete(String(row.id));
|
|
1608
|
+
stopped = true;
|
|
1609
|
+
}
|
|
1610
|
+
this.store.run('DELETE FROM provider_waits WHERE entity_id=?', `session:${sessionId}`);
|
|
1611
|
+
void this.flushHistory().catch(() => { });
|
|
1612
|
+
return stopped;
|
|
1613
|
+
}
|
|
1614
|
+
if (active.stopping)
|
|
1400
1615
|
return false;
|
|
1401
1616
|
active.stopping = true;
|
|
1402
1617
|
active.stopReason = reason;
|
|
@@ -1410,6 +1625,9 @@ class AgentOrchestrationRuntime {
|
|
|
1410
1625
|
for (const row of this.store.all("SELECT operation_id FROM history_operations WHERE state='pending' ORDER BY updated_at LIMIT 200"))
|
|
1411
1626
|
await this.history.write(String(row.operation_id));
|
|
1412
1627
|
}
|
|
1628
|
+
hasPendingWork() {
|
|
1629
|
+
return !!(this.active.size || this.pending.size || this.store.get("SELECT id FROM conversation_inputs WHERE status IN ('accepted','assigned') LIMIT 1") || this.store.get("SELECT id FROM tasks WHERE state NOT IN ('completed','failed','cancelled') LIMIT 1"));
|
|
1630
|
+
}
|
|
1413
1631
|
drain() {
|
|
1414
1632
|
this.draining = true;
|
|
1415
1633
|
this.store.run("UPDATE conversations SET status='draining' WHERE status='active'");
|
|
@@ -1437,6 +1655,7 @@ class AgentOrchestrationRuntime {
|
|
|
1437
1655
|
this.drain();
|
|
1438
1656
|
for (const sessionId of this.active.keys())
|
|
1439
1657
|
this.stopResponse(sessionId);
|
|
1658
|
+
await this.gatewayTasks?.close();
|
|
1440
1659
|
await this.scheduler.close();
|
|
1441
1660
|
await this.settleResources();
|
|
1442
1661
|
await Promise.allSettled([...this.pending]);
|
|
@@ -1445,6 +1664,7 @@ class AgentOrchestrationRuntime {
|
|
|
1445
1664
|
// Caller waits for pending conversational responses before releasing store.
|
|
1446
1665
|
if (this.active.size)
|
|
1447
1666
|
throw new types_2.OrchestrationError('ACTIVE_DECISIONS_DURING_SHUTDOWN');
|
|
1667
|
+
this.providerAdmission.close();
|
|
1448
1668
|
this.store.close();
|
|
1449
1669
|
this.releaseLock();
|
|
1450
1670
|
}
|