@leitwerk-dev/server 0.2.0 → 0.3.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/dist/app-4QSV4FUQ.js +8 -0
- package/dist/{app-D4XHIbwA.d.ts → app-WfwKzrVk.d.ts} +2029 -410
- package/dist/app.d.ts +55 -12
- package/dist/app.d.ts.map +1 -1
- package/dist/{chunk-AGC2ND53.js → chunk-KIOQNNG6.js} +1645 -750
- package/dist/chunk-KIOQNNG6.js.map +1 -0
- package/dist/{chunk-XTXH6623.js → chunk-LK3RO6C7.js} +1543 -2111
- package/dist/chunk-LK3RO6C7.js.map +1 -0
- package/dist/config/config-loader.d.ts +11 -0
- package/dist/config/config-loader.d.ts.map +1 -1
- package/dist/config/config-types.d.ts +152 -51
- package/dist/config/config-types.d.ts.map +1 -1
- package/dist/db/api-token-repo.d.ts +24 -0
- package/dist/db/api-token-repo.d.ts.map +1 -1
- package/dist/db/auth-repo.d.ts +30 -0
- package/dist/db/auth-repo.d.ts.map +1 -1
- package/dist/db/credential-cipher.d.ts +8 -3
- package/dist/db/credential-cipher.d.ts.map +1 -1
- package/dist/db/database.d.ts +19 -1
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/external-write-log-repo.d.ts +6 -1
- package/dist/db/external-write-log-repo.d.ts.map +1 -1
- package/dist/db/future-execution-repo.d.ts +47 -0
- package/dist/db/future-execution-repo.d.ts.map +1 -1
- package/dist/db/launch-run-repo.d.ts +17 -0
- package/dist/db/launch-run-repo.d.ts.map +1 -1
- package/dist/db/launcher-recent-value-repo.d.ts +15 -0
- package/dist/db/launcher-recent-value-repo.d.ts.map +1 -1
- package/dist/db/pending-external-source-fire-repo.d.ts +33 -0
- package/dist/db/pending-external-source-fire-repo.d.ts.map +1 -1
- package/dist/db/process-event-repo.d.ts +17 -0
- package/dist/db/process-event-repo.d.ts.map +1 -1
- package/dist/db/process-handoff-dedup-key-repo.d.ts +8 -0
- package/dist/db/process-handoff-dedup-key-repo.d.ts.map +1 -1
- package/dist/db/process-input-repo.d.ts +15 -0
- package/dist/db/process-input-repo.d.ts.map +1 -1
- package/dist/db/process-instance-repo.d.ts +49 -0
- package/dist/db/process-instance-repo.d.ts.map +1 -1
- package/dist/db/process-leaf-outcome-snapshot-repo.d.ts +18 -0
- package/dist/db/process-leaf-outcome-snapshot-repo.d.ts.map +1 -1
- package/dist/db/process-project-repo.d.ts +20 -0
- package/dist/db/process-project-repo.d.ts.map +1 -1
- package/dist/db/process-question-request-repo.d.ts +19 -0
- package/dist/db/process-question-request-repo.d.ts.map +1 -1
- package/dist/db/process-relation-repo.d.ts +5 -0
- package/dist/db/process-relation-repo.d.ts.map +1 -1
- package/dist/db/process-skill-repo.d.ts +4 -0
- package/dist/db/process-skill-repo.d.ts.map +1 -1
- package/dist/db/process-title-job-repo.d.ts +22 -0
- package/dist/db/process-title-job-repo.d.ts.map +1 -1
- package/dist/db/process-tool-approval-request-repo.d.ts +20 -0
- package/dist/db/process-tool-approval-request-repo.d.ts.map +1 -1
- package/dist/db/process-turn-annotation-repo.d.ts +22 -2
- package/dist/db/process-turn-annotation-repo.d.ts.map +1 -1
- package/dist/db/process-turn-record-repo.d.ts +27 -0
- package/dist/db/process-turn-record-repo.d.ts.map +1 -1
- package/dist/db/provider-credential-repo.d.ts +16 -0
- package/dist/db/provider-credential-repo.d.ts.map +1 -1
- package/dist/db/repositories.d.ts +33 -0
- package/dist/db/repositories.d.ts.map +1 -1
- package/dist/db/session-transfer-repo.d.ts +49 -1
- package/dist/db/session-transfer-repo.d.ts.map +1 -1
- package/dist/db/skill-repo.d.ts +20 -0
- package/dist/db/skill-repo.d.ts.map +1 -1
- package/dist/db/startup-observation-repo.d.ts +3 -0
- package/dist/db/startup-observation-repo.d.ts.map +1 -1
- package/dist/db/ticket-destination-recent-repo.d.ts +14 -0
- package/dist/db/ticket-destination-recent-repo.d.ts.map +1 -1
- package/dist/db/turn-start-record-repo.d.ts +9 -0
- package/dist/db/turn-start-record-repo.d.ts.map +1 -1
- package/dist/db/turn-summary-repo.d.ts +18 -0
- package/dist/db/turn-summary-repo.d.ts.map +1 -1
- package/dist/db/worker-lease-repo.d.ts +31 -1
- package/dist/db/worker-lease-repo.d.ts.map +1 -1
- package/dist/effects/post-commit-effect.d.ts +29 -0
- package/dist/effects/post-commit-effect.d.ts.map +1 -1
- package/dist/effects/post-commit-runner.d.ts +1 -0
- package/dist/effects/post-commit-runner.d.ts.map +1 -1
- package/dist/entry-ref-patch.d.ts +3 -0
- package/dist/entry-ref-patch.d.ts.map +1 -1
- package/dist/extension-ui/catalog.d.ts +15 -0
- package/dist/extension-ui/catalog.d.ts.map +1 -1
- package/dist/extensions/extension-host.d.ts +6 -0
- package/dist/extensions/extension-host.d.ts.map +1 -1
- package/dist/external-source-service.d.ts +8 -0
- package/dist/external-source-service.d.ts.map +1 -1
- package/dist/future-execution/execution.d.ts +23 -1
- package/dist/future-execution/execution.d.ts.map +1 -1
- package/dist/future-execution/launch-lifecycle.d.ts +76 -0
- package/dist/future-execution/launch-lifecycle.d.ts.map +1 -1
- package/dist/future-execution/lifecycle.d.ts +99 -0
- package/dist/future-execution/lifecycle.d.ts.map +1 -1
- package/dist/future-execution/model-projection.d.ts +6 -0
- package/dist/future-execution/model-projection.d.ts.map +1 -1
- package/dist/future-execution/transition-planner.d.ts +25 -0
- package/dist/future-execution/transition-planner.d.ts.map +1 -1
- package/dist/future-execution-scheduler.d.ts +1 -1
- package/dist/future-execution-scheduler.d.ts.map +1 -1
- package/dist/index.d.ts +3 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -239
- package/dist/index.js.map +1 -1
- package/dist/instance-tree.d.ts +3 -0
- package/dist/instance-tree.d.ts.map +1 -1
- package/dist/integration-tool-registry.d.ts +4 -1
- package/dist/integration-tool-registry.d.ts.map +1 -1
- package/dist/launch-coordinator.d.ts +33 -0
- package/dist/launch-coordinator.d.ts.map +1 -1
- package/dist/launch-pipeline.d.ts +60 -0
- package/dist/launch-pipeline.d.ts.map +1 -1
- package/dist/launcher-recent-values-service.d.ts +3 -0
- package/dist/launcher-recent-values-service.d.ts.map +1 -1
- package/dist/main.js +7 -14
- package/dist/main.js.map +1 -1
- package/dist/model-providers/builtin-server-adapter.d.ts +1 -0
- package/dist/model-providers/builtin-server-adapter.d.ts.map +1 -1
- package/dist/model-providers/credentials.d.ts +17 -0
- package/dist/model-providers/credentials.d.ts.map +1 -1
- package/dist/model-providers/model-status-cache.d.ts +30 -1
- package/dist/model-providers/model-status-cache.d.ts.map +1 -1
- package/dist/model-providers/provider-options.d.ts +21 -1
- package/dist/model-providers/provider-options.d.ts.map +1 -1
- package/dist/model-providers/registry.d.ts +22 -2
- package/dist/model-providers/registry.d.ts.map +1 -1
- package/dist/model-providers/server-adapters.d.ts +19 -0
- package/dist/model-providers/server-adapters.d.ts.map +1 -1
- package/dist/pi-resources/assemble.d.ts +24 -4
- package/dist/pi-resources/assemble.d.ts.map +1 -1
- package/dist/pi-resources/bundle-cache.d.ts +20 -1
- package/dist/pi-resources/bundle-cache.d.ts.map +1 -1
- package/dist/pi-resources/bundle-pin-lifecycle.d.ts +5 -1
- package/dist/pi-resources/bundle-pin-lifecycle.d.ts.map +1 -1
- package/dist/pi-resources/resource-collector.d.ts +11 -0
- package/dist/pi-resources/resource-collector.d.ts.map +1 -1
- package/dist/pi-session-tree.d.ts +13 -1
- package/dist/pi-session-tree.d.ts.map +1 -1
- package/dist/process-action-registry.d.ts +47 -0
- package/dist/process-action-registry.d.ts.map +1 -1
- package/dist/process-deletion-service.d.ts +12 -0
- package/dist/process-deletion-service.d.ts.map +1 -1
- package/dist/process-engine/decision.d.ts +12 -0
- package/dist/process-engine/decision.d.ts.map +1 -1
- package/dist/process-engine/engine.d.ts +1 -0
- package/dist/process-engine/engine.d.ts.map +1 -1
- package/dist/process-engine/operation.d.ts +23 -2
- package/dist/process-engine/operation.d.ts.map +1 -1
- package/dist/process-engine/startup-reconciliation.d.ts +14 -0
- package/dist/process-engine/startup-reconciliation.d.ts.map +1 -1
- package/dist/process-engine/types.d.ts +112 -1
- package/dist/process-engine/types.d.ts.map +1 -1
- package/dist/process-engine/writes/build-process-park-writes.d.ts +3 -0
- package/dist/process-engine/writes/build-process-park-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-recovery-start-writes.d.ts +4 -0
- package/dist/process-engine/writes/build-recovery-start-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-retry-writes.d.ts +3 -0
- package/dist/process-engine/writes/build-retry-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-turn-failed-writes.d.ts +6 -0
- package/dist/process-engine/writes/build-turn-failed-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts +8 -0
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-turn-selection-writes.d.ts +8 -0
- package/dist/process-engine/writes/build-turn-selection-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/commit-writes.d.ts +14 -0
- package/dist/process-engine/writes/commit-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/deferred-extension-events.d.ts +4 -0
- package/dist/process-engine/writes/deferred-extension-events.d.ts.map +1 -1
- package/dist/process-engine/writes/writes.d.ts +67 -0
- package/dist/process-engine/writes/writes.d.ts.map +1 -1
- package/dist/process-graph.d.ts +1 -1
- package/dist/process-graph.d.ts.map +1 -1
- package/dist/process-input-dispatch.d.ts +1 -0
- package/dist/process-input-dispatch.d.ts.map +1 -1
- package/dist/process-launch-executor.d.ts +1 -0
- package/dist/process-launch-executor.d.ts.map +1 -1
- package/dist/process-model-policy/types.d.ts +157 -1
- package/dist/process-model-policy/types.d.ts.map +1 -1
- package/dist/process-operation-coordinator.d.ts +3 -0
- package/dist/process-operation-coordinator.d.ts.map +1 -1
- package/dist/process-question-service.d.ts +36 -20
- package/dist/process-question-service.d.ts.map +1 -1
- package/dist/process-runtime-availability.d.ts +2 -1
- package/dist/process-runtime-availability.d.ts.map +1 -1
- package/dist/process-session-store.d.ts +15 -4
- package/dist/process-session-store.d.ts.map +1 -1
- package/dist/process-title-generator.d.ts +53 -0
- package/dist/process-title-generator.d.ts.map +1 -1
- package/dist/process-turn-navigation.d.ts +1 -30
- package/dist/process-turn-navigation.d.ts.map +1 -1
- package/dist/process-turn-trace.d.ts +7 -0
- package/dist/process-turn-trace.d.ts.map +1 -1
- package/dist/process-ui-registry.d.ts +2 -0
- package/dist/process-ui-registry.d.ts.map +1 -1
- package/dist/process-ui-snapshot-presenter.d.ts +68 -1
- package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
- package/dist/process-watcher-registry.d.ts +5 -0
- package/dist/process-watcher-registry.d.ts.map +1 -1
- package/dist/product-ref-state.d.ts +1 -0
- package/dist/product-ref-state.d.ts.map +1 -1
- package/dist/project-mutation-service.d.ts +19 -0
- package/dist/project-mutation-service.d.ts.map +1 -1
- package/dist/result-image-store.d.ts +20 -0
- package/dist/result-image-store.d.ts.map +1 -1
- package/dist/routes/process-route-helpers.d.ts +30 -0
- package/dist/routes/process-route-helpers.d.ts.map +1 -1
- package/dist/routes/ui-renderers.d.ts +4 -0
- package/dist/routes/ui-renderers.d.ts.map +1 -1
- package/dist/routes/watchers.d.ts +3 -0
- package/dist/routes/watchers.d.ts.map +1 -1
- package/dist/semantic-entry-ref-state.d.ts +1 -0
- package/dist/semantic-entry-ref-state.d.ts.map +1 -1
- package/dist/server-bootstrap/app-lifecycle.d.ts +24 -0
- package/dist/server-bootstrap/app-lifecycle.d.ts.map +1 -0
- package/dist/server-bootstrap/build-host-capabilities.d.ts +5 -1
- package/dist/server-bootstrap/build-host-capabilities.d.ts.map +1 -1
- package/dist/server-topology.d.ts +8 -1
- package/dist/server-topology.d.ts.map +1 -1
- package/dist/session-transfer-helper-relays.d.ts +24 -0
- package/dist/session-transfer-helper-relays.d.ts.map +1 -1
- package/dist/session-transfer-service.d.ts +63 -1
- package/dist/session-transfer-service.d.ts.map +1 -1
- package/dist/skills/catalog-service.d.ts +7 -0
- package/dist/skills/catalog-service.d.ts.map +1 -1
- package/dist/skills/source-importer.d.ts +8 -0
- package/dist/skills/source-importer.d.ts.map +1 -1
- package/dist/startup-evidence.d.ts.map +1 -1
- package/dist/supervisor/ipc-handler.d.ts +28 -0
- package/dist/supervisor/ipc-handler.d.ts.map +1 -1
- package/dist/supervisor/worker-event-ingestor.d.ts +10 -0
- package/dist/supervisor/worker-event-ingestor.d.ts.map +1 -1
- package/dist/supervisor/worker-start-payload-builder.d.ts +13 -0
- package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
- package/dist/supervisor/worker-storage-layout.d.ts +12 -0
- package/dist/supervisor/worker-storage-layout.d.ts.map +1 -1
- package/dist/supervisor/worker-supervisor.d.ts +47 -3
- package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
- package/dist/supervisor/worker-turn-ipc-recorder.d.ts +19 -0
- package/dist/supervisor/worker-turn-ipc-recorder.d.ts.map +1 -1
- package/dist/supervisor/worker-unit-reclaimer.d.ts +3 -0
- package/dist/supervisor/worker-unit-reclaimer.d.ts.map +1 -1
- package/dist/supervisor/worker-websocket-ipc.d.ts +37 -0
- package/dist/supervisor/worker-websocket-ipc.d.ts.map +1 -1
- package/dist/test-helpers/accepted-turn-start.d.ts +22 -0
- package/dist/test-helpers/accepted-turn-start.d.ts.map +1 -1
- package/dist/test-helpers/prepared-fixture-start.d.ts +14 -0
- package/dist/test-helpers/prepared-fixture-start.d.ts.map +1 -0
- package/dist/test-helpers/session-snapshot-fixtures.d.ts +1 -1
- package/dist/test-helpers/session-snapshot-fixtures.d.ts.map +1 -1
- package/dist/test-helpers/turn-start-preflight-fixtures.d.ts +8 -1
- package/dist/test-helpers/turn-start-preflight-fixtures.d.ts.map +1 -1
- package/dist/test-helpers/unit-deps.d.ts +8 -0
- package/dist/test-helpers/unit-deps.d.ts.map +1 -1
- package/dist/testing.d.ts +5 -7
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +60 -53
- package/dist/testing.js.map +1 -1
- package/dist/tool-approval-gate.d.ts +21 -0
- package/dist/tool-approval-gate.d.ts.map +1 -1
- package/dist/turn-result-markdown.d.ts +2 -0
- package/dist/turn-result-markdown.d.ts.map +1 -1
- package/dist/worker-runtime-profile-selection.d.ts +20 -4
- package/dist/worker-runtime-profile-selection.d.ts.map +1 -1
- package/dist/ws/broadcast.d.ts +10 -0
- package/dist/ws/broadcast.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/app.ts +916 -892
- package/src/config/config-loader.ts +12 -0
- package/src/config/config-types.ts +166 -66
- package/src/db/api-token-repo.ts +35 -2
- package/src/db/auth-repo.ts +35 -1
- package/src/db/credential-cipher.ts +8 -3
- package/src/db/database.ts +14 -0
- package/src/db/external-write-log-repo.ts +6 -1
- package/src/db/future-execution-repo.ts +51 -1
- package/src/db/launch-run-repo.ts +17 -0
- package/src/db/launcher-recent-value-repo.ts +15 -0
- package/src/db/pending-external-source-fire-repo.ts +33 -0
- package/src/db/process-event-repo.ts +21 -1
- package/src/db/process-handoff-dedup-key-repo.ts +8 -0
- package/src/db/process-input-repo.ts +15 -0
- package/src/db/process-instance-repo.ts +57 -2
- package/src/db/process-leaf-outcome-snapshot-repo.ts +18 -0
- package/src/db/process-project-repo.ts +20 -0
- package/src/db/process-question-request-repo.ts +19 -0
- package/src/db/process-relation-repo.ts +8 -1
- package/src/db/process-skill-repo.ts +4 -0
- package/src/db/process-title-job-repo.ts +30 -2
- package/src/db/process-tool-approval-request-repo.ts +24 -1
- package/src/db/process-turn-annotation-repo.ts +22 -2
- package/src/db/process-turn-record-repo.ts +27 -0
- package/src/db/provider-credential-repo.ts +20 -1
- package/src/db/repositories.ts +36 -1
- package/src/db/session-transfer-repo.ts +71 -9
- package/src/db/skill-repo.ts +24 -1
- package/src/db/startup-observation-repo.ts +3 -0
- package/src/db/ticket-destination-recent-repo.ts +14 -0
- package/src/db/turn-start-record-repo.ts +12 -1
- package/src/db/turn-summary-repo.ts +29 -2
- package/src/db/worker-lease-repo.ts +31 -1
- package/src/deployment-preflight.ts +1 -1
- package/src/effects/post-commit-effect.ts +42 -3
- package/src/effects/post-commit-runner.ts +1 -0
- package/src/entry-ref-patch.ts +9 -1
- package/src/extension-ui/catalog.ts +15 -0
- package/src/extensions/extension-host.ts +6 -0
- package/src/external-source-service.ts +12 -1
- package/src/future-execution/execution.ts +45 -8
- package/src/future-execution/launch-lifecycle.ts +145 -17
- package/src/future-execution/lifecycle.ts +124 -13
- package/src/future-execution/model-projection.ts +6 -0
- package/src/future-execution/transition-planner.ts +25 -0
- package/src/future-execution-scheduler.ts +7 -6
- package/src/index.ts +5 -153
- package/src/instance-tree.ts +3 -0
- package/src/integration-tool-registry.ts +17 -8
- package/src/launch-coordinator.ts +55 -5
- package/src/launch-pipeline.ts +103 -12
- package/src/launcher-recent-values-service.ts +3 -0
- package/src/main.ts +3 -10
- package/src/model-providers/builtin-server-adapter.ts +1 -0
- package/src/model-providers/credentials.ts +17 -0
- package/src/model-providers/model-status-cache.ts +30 -1
- package/src/model-providers/provider-options.ts +25 -2
- package/src/model-providers/registry.ts +22 -2
- package/src/model-providers/server-adapters.ts +19 -0
- package/src/pi-resources/assemble.ts +24 -4
- package/src/pi-resources/bundle-cache.ts +20 -1
- package/src/pi-resources/bundle-pin-lifecycle.ts +8 -2
- package/src/pi-resources/resource-collector.ts +11 -0
- package/src/pi-session-tree.ts +13 -1
- package/src/process-action-registry.ts +53 -1
- package/src/process-deletion-service.ts +29 -4
- package/src/process-engine/decision.ts +12 -0
- package/src/process-engine/engine.ts +1 -0
- package/src/process-engine/operation.ts +23 -2
- package/src/process-engine/startup-reconciliation.ts +14 -0
- package/src/process-engine/types.ts +176 -14
- package/src/process-engine/writes/build-process-park-writes.ts +3 -0
- package/src/process-engine/writes/build-recovery-start-writes.ts +4 -0
- package/src/process-engine/writes/build-retry-writes.ts +3 -0
- package/src/process-engine/writes/build-turn-failed-writes.ts +6 -0
- package/src/process-engine/writes/build-turn-outcome-writes.ts +8 -0
- package/src/process-engine/writes/build-turn-selection-writes.ts +8 -0
- package/src/process-engine/writes/commit-writes.ts +14 -0
- package/src/process-engine/writes/deferred-extension-events.ts +4 -0
- package/src/process-engine/writes/writes.ts +104 -10
- package/src/process-graph.ts +0 -3
- package/src/process-input-dispatch.ts +1 -0
- package/src/process-launch-executor.ts +1 -0
- package/src/process-model-policy/types.ts +195 -11
- package/src/process-operation-coordinator.ts +3 -0
- package/src/process-question-service.ts +53 -11
- package/src/process-runtime-availability.ts +4 -3
- package/src/process-session-store.ts +15 -4
- package/src/process-title-generator.ts +71 -5
- package/src/process-turn-navigation.ts +4 -1
- package/src/process-turn-trace.ts +7 -0
- package/src/process-ui-registry.ts +2 -0
- package/src/process-ui-snapshot-presenter.ts +75 -3
- package/src/process-watcher-registry.ts +5 -0
- package/src/product-ref-state.ts +1 -0
- package/src/project-mutation-service.ts +22 -1
- package/src/result-image-store.ts +27 -2
- package/src/routes/process-route-helpers.ts +30 -0
- package/src/routes/ui-renderers.ts +4 -0
- package/src/routes/watchers.ts +3 -0
- package/src/semantic-entry-ref-state.ts +1 -0
- package/src/server-bootstrap/app-lifecycle.ts +150 -0
- package/src/server-topology.ts +8 -1
- package/src/session-transfer-helper-relays.ts +33 -2
- package/src/session-transfer-service.ts +75 -7
- package/src/skills/catalog-service.ts +7 -0
- package/src/skills/source-importer.ts +8 -0
- package/src/startup-evidence.ts +23 -41
- package/src/supervisor/ipc-handler.ts +33 -1
- package/src/supervisor/worker-event-ingestor.ts +10 -0
- package/src/supervisor/worker-start-payload-builder.ts +16 -1
- package/src/supervisor/worker-storage-layout.ts +12 -0
- package/src/supervisor/worker-supervisor.ts +119 -133
- package/src/supervisor/worker-turn-ipc-recorder.ts +19 -0
- package/src/supervisor/worker-unit-reclaimer.ts +3 -0
- package/src/supervisor/worker-websocket-ipc.ts +57 -3
- package/src/test-helpers/accepted-turn-start.ts +32 -3
- package/src/test-helpers/prepared-fixture-start.ts +74 -0
- package/src/test-helpers/session-snapshot-fixtures.ts +1 -1
- package/src/test-helpers/turn-start-preflight-fixtures.ts +8 -1
- package/src/test-helpers/unit-deps.ts +13 -1
- package/src/testing.ts +5 -23
- package/src/tool-approval-gate.ts +32 -3
- package/src/turn-result-markdown.ts +2 -0
- package/src/worker-runtime-profile-selection.ts +24 -5
- package/src/ws/broadcast.ts +20 -1
- package/dist/app-I4QQUL5B.js +0 -10
- package/dist/chunk-AGC2ND53.js.map +0 -1
- package/dist/chunk-XTXH6623.js.map +0 -1
- /package/dist/{app-I4QQUL5B.js.map → app-4QSV4FUQ.js.map} +0 -0
package/src/app.ts
CHANGED
|
@@ -105,6 +105,7 @@ import {
|
|
|
105
105
|
import { RepositoryCredentialService } from "./repository-credentials/service.js";
|
|
106
106
|
import { ResultImageStore } from "./result-image-store.js";
|
|
107
107
|
import type { RouteDeps } from "./routes/processes.js";
|
|
108
|
+
import { collectCleanupErrors, createAppLifecycle } from "./server-bootstrap/app-lifecycle.js";
|
|
108
109
|
import { buildHostCapabilities } from "./server-bootstrap/build-host-capabilities.js";
|
|
109
110
|
import { loadServerExtensionCatalog } from "./server-bootstrap/load-extension-catalog.js";
|
|
110
111
|
import { registerHttp } from "./server-bootstrap/register-http.js";
|
|
@@ -126,53 +127,98 @@ import { createToolApprovalGate } from "./tool-approval-gate.js";
|
|
|
126
127
|
import { defaultWorkerRuntimeProfile } from "./worker-runtime-profile-selection.js";
|
|
127
128
|
import { type Broadcaster, createBroadcaster } from "./ws/broadcast.js";
|
|
128
129
|
|
|
130
|
+
/** @public */
|
|
129
131
|
export interface AppOptions {
|
|
130
|
-
|
|
131
|
-
port?: number;
|
|
132
|
+
/** @public */
|
|
132
133
|
config?: LeitwerkConfig;
|
|
134
|
+
/** @internal */
|
|
133
135
|
db?: LeitwerkDb;
|
|
136
|
+
/** @internal */
|
|
134
137
|
logger?: boolean;
|
|
138
|
+
/** @internal */
|
|
135
139
|
extensionCatalog?: ExtensionCatalog | Promise<ExtensionCatalog>;
|
|
140
|
+
/** @internal */
|
|
136
141
|
resolvedExtensionEntries?: readonly DiscoveredExtensionEntry[];
|
|
142
|
+
/** @public */
|
|
137
143
|
extensionLoadingStartDir?: string;
|
|
138
|
-
/** Runtime lane override for extension UI assets. */
|
|
144
|
+
/** Runtime lane override for extension UI assets. @internal */
|
|
139
145
|
extensionUiRuntimeLane?: LeitwerkRuntimeLane;
|
|
140
|
-
/** Pre-provided capabilities injected before extensions are set up (e.g. fake adapters for testing). */
|
|
146
|
+
/** Pre-provided capabilities injected before extensions are set up (e.g. fake adapters for testing). @internal */
|
|
141
147
|
preProvidedCapabilities?: readonly ProvidedCapability[];
|
|
148
|
+
/** @internal */
|
|
142
149
|
processTitleGenerator?: ProcessTitleGenerator;
|
|
143
|
-
/** Test/custom seam for supplying a concrete container runner implementation. */
|
|
150
|
+
/** Test/custom seam for supplying a concrete container runner implementation. @internal */
|
|
144
151
|
workerRunnerRuntime?: {
|
|
152
|
+
/** @internal */
|
|
145
153
|
runner: WorkerRunner;
|
|
154
|
+
/** @internal */
|
|
146
155
|
volume?: ProcessVolume;
|
|
156
|
+
/** @internal */
|
|
147
157
|
exporter: ProcessStateExporter;
|
|
158
|
+
/** @internal */
|
|
148
159
|
webSocketIpc?: WorkerWebSocketIpcManager;
|
|
149
160
|
};
|
|
150
|
-
/** Local runner spawn seam for tests/dev only. */
|
|
161
|
+
/** Local runner spawn seam for tests/dev only. @public */
|
|
151
162
|
localWorkerSpawnImpl?: typeof spawn;
|
|
152
|
-
/** Test seam shared by local Docker admission and worker startup. */
|
|
163
|
+
/** Test seam shared by local Docker admission and worker startup. @public */
|
|
153
164
|
localWorkerDockerPreflightImpl?: (timeoutMs: number) => Promise<void>;
|
|
154
|
-
/** Credential-store seam. Declared credential providers default unavailable until it is wired. */
|
|
165
|
+
/** Credential-store seam. Declared credential providers default unavailable until it is wired. @internal */
|
|
155
166
|
modelProviderCredentialStatus?: ModelProviderCredentialStatusResolver;
|
|
156
167
|
}
|
|
157
168
|
|
|
169
|
+
/** @public */
|
|
170
|
+
export interface ServerListenOptions {
|
|
171
|
+
/** @public */
|
|
172
|
+
host?: string;
|
|
173
|
+
/** @public */
|
|
174
|
+
port?: number;
|
|
175
|
+
/** Only for unauthenticated loopback fixtures. @public */
|
|
176
|
+
useBoundAddressAsBaseUrl?: boolean;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** @public */
|
|
180
|
+
export interface ServerListenResult {
|
|
181
|
+
/** @public */
|
|
182
|
+
address: string;
|
|
183
|
+
/** @public */
|
|
184
|
+
port: number;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** @public */
|
|
158
188
|
export interface AppContext {
|
|
189
|
+
/** @public */
|
|
159
190
|
app: FastifyInstance;
|
|
191
|
+
/** @internal */
|
|
160
192
|
db: LeitwerkDb;
|
|
193
|
+
/** @internal */
|
|
161
194
|
broadcaster: Broadcaster;
|
|
195
|
+
/** @internal */
|
|
162
196
|
config: LeitwerkConfig;
|
|
197
|
+
/** @public */
|
|
163
198
|
deps: RouteDeps;
|
|
164
|
-
|
|
199
|
+
/** @internal */
|
|
165
200
|
modelProviderRegistry: ModelProviderRegistry;
|
|
201
|
+
/** @internal */
|
|
166
202
|
modelProviderServerAdapters: ModelProviderServerAdapterRegistry;
|
|
203
|
+
/** @internal */
|
|
167
204
|
modelStatusCache: ModelStatusCache;
|
|
205
|
+
/** @internal */
|
|
168
206
|
extensionUiCatalog: ExtensionUiCatalog;
|
|
207
|
+
/** @internal */
|
|
169
208
|
processGraphs: ProcessGraphRegistry;
|
|
209
|
+
/** @internal */
|
|
170
210
|
extensionHost: ExtensionHost;
|
|
211
|
+
/** @internal */
|
|
171
212
|
projectMutations: ProjectMutationService;
|
|
213
|
+
/** @internal */
|
|
172
214
|
ipcHandler: IpcHandler;
|
|
215
|
+
/** @public */
|
|
173
216
|
supervisor: WorkerSupervisor;
|
|
174
|
-
|
|
175
|
-
|
|
217
|
+
/** @public */
|
|
218
|
+
listen(options?: ServerListenOptions): Promise<ServerListenResult>;
|
|
219
|
+
/** @public */
|
|
220
|
+
close(): Promise<void>;
|
|
221
|
+
/** @internal */
|
|
176
222
|
isReady(): boolean;
|
|
177
223
|
}
|
|
178
224
|
|
|
@@ -304,11 +350,7 @@ async function createConfiguredWorkerRunnerRuntime(input: {
|
|
|
304
350
|
return { ...created, webSocketIpc: input.webSocketIpc };
|
|
305
351
|
}
|
|
306
352
|
|
|
307
|
-
|
|
308
|
-
const ctx = await createAppContext(opts);
|
|
309
|
-
return ctx.app;
|
|
310
|
-
}
|
|
311
|
-
|
|
353
|
+
/** @public */
|
|
312
354
|
export async function createAppContext(opts: AppOptions = {}): Promise<AppContext> {
|
|
313
355
|
const startupStartedAt = performance.now();
|
|
314
356
|
let previousStartupMark = startupStartedAt;
|
|
@@ -346,263 +388,273 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
|
|
|
346
388
|
);
|
|
347
389
|
previousStartupMark = now;
|
|
348
390
|
};
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
repos,
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
);
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
credentialStatus:
|
|
397
|
-
opts.modelProviderCredentialStatus ??
|
|
398
|
-
(modelProviderRegistry.size > 0
|
|
399
|
-
? modelProviderCredentials.status
|
|
400
|
-
: defaultModelProviderCredentialStatus),
|
|
401
|
-
});
|
|
402
|
-
await modelStatusCache.refresh();
|
|
403
|
-
const modelProviderServerAdapters = await createModelProviderServerAdapterRegistry({
|
|
404
|
-
registry: modelProviderRegistry,
|
|
405
|
-
modelProfiles: config.pi.model_profiles,
|
|
406
|
-
credentials: modelProviderCredentials,
|
|
407
|
-
createBuiltinAdapter: (providerId) => createBuiltinPiServerAdapter(providerId),
|
|
408
|
-
});
|
|
409
|
-
const piResourceBundles = createPiResourceBundleCache();
|
|
410
|
-
const piResourceBundlePins = createPiResourceBundlePinReconciler({
|
|
411
|
-
turnStarts: repos.turnStarts,
|
|
412
|
-
turnRecords: repos.turnRecords,
|
|
413
|
-
bundleCache: piResourceBundles,
|
|
414
|
-
});
|
|
415
|
-
markStartup("model_providers");
|
|
416
|
-
|
|
417
|
-
const broadcaster = createBroadcaster();
|
|
418
|
-
const processOperations = createProcessOperationCoordinator();
|
|
419
|
-
const processGraphs = extensionCatalog.processes;
|
|
420
|
-
const processActionRegistry = buildProcessActionRegistry(extensionCatalog);
|
|
421
|
-
const integrationTools = new IntegrationToolRegistry();
|
|
422
|
-
const processUiRegistry = buildProcessUiRegistry(extensionCatalog);
|
|
423
|
-
const processModelPolicy = createServerProcessModelPolicy({
|
|
424
|
-
config,
|
|
425
|
-
processGraphs,
|
|
426
|
-
processActionRegistry,
|
|
427
|
-
});
|
|
428
|
-
const extensionUiCatalog = await buildExtensionUiCatalog(
|
|
429
|
-
extensionCatalog.modules,
|
|
430
|
-
opts.extensionUiRuntimeLane ? { runtimeLane: opts.extensionUiRuntimeLane } : {},
|
|
431
|
-
);
|
|
432
|
-
markStartup("extension_ui_catalog");
|
|
433
|
-
const launcherModelProfiles: LauncherModelProfileSummary[] = config.pi.model_profiles.map(
|
|
434
|
-
(profile: ModelProfileSnapshot): LauncherModelProfileSummary => ({
|
|
435
|
-
id: profile.id,
|
|
436
|
-
provider: profile.provider,
|
|
437
|
-
modelId: profile.model_id,
|
|
438
|
-
thinkingLevel: profile.thinking_level ?? "off",
|
|
439
|
-
}),
|
|
440
|
-
);
|
|
441
|
-
const launcherModelProfilesById = new Map(
|
|
442
|
-
launcherModelProfiles.map((profile) => [profile.id, profile] as const),
|
|
443
|
-
);
|
|
444
|
-
const getModelProfilesForProcess = (processId: string) => {
|
|
445
|
-
return processModelPolicy
|
|
446
|
-
.project({
|
|
447
|
-
kind: "profile_options",
|
|
448
|
-
processId,
|
|
449
|
-
availability: modelStatusCache.snapshot(),
|
|
450
|
-
})
|
|
451
|
-
.map((profile) => launcherModelProfilesById.get(profile.id))
|
|
452
|
-
.filter(
|
|
453
|
-
(
|
|
454
|
-
profile: LauncherModelProfileSummary | undefined,
|
|
455
|
-
): profile is LauncherModelProfileSummary => profile !== undefined,
|
|
391
|
+
let finishCleanup: (() => Promise<void>) | undefined;
|
|
392
|
+
let stopAcquiredWorkers: (() => Promise<void>) | undefined;
|
|
393
|
+
let closeOwnedDatabase: (() => void) | undefined;
|
|
394
|
+
const preCloseCleanup: Array<() => void | Promise<void>> = [];
|
|
395
|
+
try {
|
|
396
|
+
await app.register(cookie);
|
|
397
|
+
markStartup("fastify_plugins");
|
|
398
|
+
const ownsDb = !opts.db;
|
|
399
|
+
const db = opts.db ?? createConfiguredDatabase(config);
|
|
400
|
+
if (ownsDb) closeOwnedDatabase = () => closeDatabase(db);
|
|
401
|
+
preCloseCleanup.push(() => stopAcquiredWorkers?.());
|
|
402
|
+
app.addHook("onClose", async () => {
|
|
403
|
+
await finishCleanup?.();
|
|
404
|
+
});
|
|
405
|
+
markStartup("database");
|
|
406
|
+
const { resolvedExtensionEntries, extensionCatalog } = await loadServerExtensionCatalog({
|
|
407
|
+
config,
|
|
408
|
+
extensionCatalog: opts.extensionCatalog,
|
|
409
|
+
resolvedExtensionEntries: opts.resolvedExtensionEntries,
|
|
410
|
+
extensionLoadingStartDir: opts.extensionLoadingStartDir,
|
|
411
|
+
});
|
|
412
|
+
markStartup("extension_catalog");
|
|
413
|
+
const modelProviderRegistry = createModelProviderRegistry({
|
|
414
|
+
sets: extensionCatalog.modelProviders,
|
|
415
|
+
piContributions: extensionCatalog.piContributions,
|
|
416
|
+
extensionConfig: config.extensions ?? {},
|
|
417
|
+
modelProfiles: config.pi.model_profiles,
|
|
418
|
+
titleModelProfileId: config.pi.process_title_generation.model_profile,
|
|
419
|
+
});
|
|
420
|
+
const credentialCipher = createCredentialCipherFromEnvironment();
|
|
421
|
+
const repos = createAllRepos(db, {
|
|
422
|
+
...(credentialCipher ? { credentialCipher } : {}),
|
|
423
|
+
});
|
|
424
|
+
repos.transaction((transactionRepos) => {
|
|
425
|
+
// Directly configured skills are no longer supported. Deactivate any left by an older release.
|
|
426
|
+
transactionRepos.skills.reconcile([]);
|
|
427
|
+
transactionRepos.skills.backfillDependencies();
|
|
428
|
+
});
|
|
429
|
+
const skillCatalog = createSkillCatalogService({
|
|
430
|
+
repositories: config.skill_repositories ?? [],
|
|
431
|
+
repos,
|
|
432
|
+
});
|
|
433
|
+
await skillCatalog.refresh();
|
|
434
|
+
markStartup("skill_catalog");
|
|
435
|
+
if (!credentialCipher && repos.providerCredentials.count() > 0) {
|
|
436
|
+
throw new Error(
|
|
437
|
+
"Encrypted provider credentials exist but LEITWERK_CREDENTIAL_ENCRYPTION_KEY is unavailable",
|
|
456
438
|
);
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
let launchCoordinator: LaunchCoordinator | undefined;
|
|
487
|
-
let applyGeneratedFutureExecutionTitle: NonNullable<
|
|
488
|
-
Parameters<typeof createProcessTitleGenerator>[0]["futureExecutionTitleApplier"]
|
|
489
|
-
> = async () => ({
|
|
490
|
-
kind: "failed",
|
|
491
|
-
error: "Future execution lifecycle is not initialized",
|
|
492
|
-
});
|
|
493
|
-
const processTitles: ProcessTitleGenerator | undefined =
|
|
494
|
-
opts.processTitleGenerator ??
|
|
495
|
-
(config.pi.process_title_generation.model_profile === null
|
|
496
|
-
? undefined
|
|
497
|
-
: createProcessTitleGenerator({
|
|
498
|
-
config,
|
|
499
|
-
repos,
|
|
500
|
-
broadcaster,
|
|
501
|
-
extensionHost,
|
|
502
|
-
futureExecutionTitleApplier: (input) => applyGeneratedFutureExecutionTitle(input),
|
|
503
|
-
getLaunchCoordinator: () => launchCoordinator,
|
|
504
|
-
logger: {
|
|
505
|
-
warn: (message, details) => app.log.warn(details ?? {}, message),
|
|
506
|
-
},
|
|
507
|
-
runtime: {
|
|
508
|
-
generateTitle: ({ prompt, maxTokens, providerOptions }) =>
|
|
509
|
-
modelProviderServerAdapters.generateText({
|
|
510
|
-
profileId: config.pi.process_title_generation.model_profile as string,
|
|
511
|
-
prompt,
|
|
512
|
-
systemPrompt: TITLE_SYSTEM_PROMPT,
|
|
513
|
-
maxTokens,
|
|
514
|
-
request: providerOptions,
|
|
515
|
-
}),
|
|
516
|
-
},
|
|
517
|
-
}));
|
|
439
|
+
}
|
|
440
|
+
const modelProviderCredentials = createModelProviderCredentialService({
|
|
441
|
+
registry: modelProviderRegistry,
|
|
442
|
+
repo: repos.providerCredentials,
|
|
443
|
+
});
|
|
444
|
+
modelProviderCredentials.initialize();
|
|
445
|
+
const modelStatusCache = createModelStatusCache({
|
|
446
|
+
registry: modelProviderRegistry,
|
|
447
|
+
modelProfiles: config.pi.model_profiles,
|
|
448
|
+
credentialStatus:
|
|
449
|
+
opts.modelProviderCredentialStatus ??
|
|
450
|
+
(modelProviderRegistry.size > 0
|
|
451
|
+
? modelProviderCredentials.status
|
|
452
|
+
: defaultModelProviderCredentialStatus),
|
|
453
|
+
});
|
|
454
|
+
await modelStatusCache.refresh();
|
|
455
|
+
const modelProviderServerAdapters = await createModelProviderServerAdapterRegistry({
|
|
456
|
+
registry: modelProviderRegistry,
|
|
457
|
+
modelProfiles: config.pi.model_profiles,
|
|
458
|
+
credentials: modelProviderCredentials,
|
|
459
|
+
createBuiltinAdapter: (providerId) => createBuiltinPiServerAdapter(providerId),
|
|
460
|
+
});
|
|
461
|
+
const piResourceBundles = createPiResourceBundleCache();
|
|
462
|
+
const piResourceBundlePins = createPiResourceBundlePinReconciler({
|
|
463
|
+
turnStarts: repos.turnStarts,
|
|
464
|
+
turnRecords: repos.turnRecords,
|
|
465
|
+
bundleCache: piResourceBundles,
|
|
466
|
+
});
|
|
467
|
+
markStartup("model_providers");
|
|
518
468
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
469
|
+
const broadcaster = createBroadcaster();
|
|
470
|
+
const processOperations = createProcessOperationCoordinator();
|
|
471
|
+
const processGraphs = extensionCatalog.processes;
|
|
472
|
+
const processActionRegistry = buildProcessActionRegistry(extensionCatalog);
|
|
473
|
+
const integrationTools = new IntegrationToolRegistry(repos.externalWrites);
|
|
474
|
+
const processUiRegistry = buildProcessUiRegistry(extensionCatalog);
|
|
475
|
+
const processModelPolicy = createServerProcessModelPolicy({
|
|
476
|
+
config,
|
|
477
|
+
processGraphs,
|
|
478
|
+
processActionRegistry,
|
|
479
|
+
});
|
|
480
|
+
const extensionUiCatalog = await buildExtensionUiCatalog(
|
|
481
|
+
extensionCatalog.modules,
|
|
482
|
+
opts.extensionUiRuntimeLane ? { runtimeLane: opts.extensionUiRuntimeLane } : {},
|
|
483
|
+
);
|
|
484
|
+
markStartup("extension_ui_catalog");
|
|
485
|
+
const launcherModelProfiles: LauncherModelProfileSummary[] = config.pi.model_profiles.map(
|
|
486
|
+
(profile: ModelProfileSnapshot): LauncherModelProfileSummary => ({
|
|
487
|
+
id: profile.id,
|
|
488
|
+
provider: profile.provider,
|
|
489
|
+
modelId: profile.model_id,
|
|
490
|
+
thinkingLevel: profile.thinking_level ?? "off",
|
|
491
|
+
}),
|
|
492
|
+
);
|
|
493
|
+
const launcherModelProfilesById = new Map(
|
|
494
|
+
launcherModelProfiles.map((profile) => [profile.id, profile] as const),
|
|
495
|
+
);
|
|
496
|
+
const getModelProfilesForProcess = (processId: string) => {
|
|
497
|
+
return processModelPolicy
|
|
498
|
+
.project({
|
|
499
|
+
kind: "profile_options",
|
|
500
|
+
processId,
|
|
501
|
+
availability: modelStatusCache.snapshot(),
|
|
502
|
+
})
|
|
503
|
+
.map((profile) => launcherModelProfilesById.get(profile.id))
|
|
504
|
+
.filter(
|
|
505
|
+
(
|
|
506
|
+
profile: LauncherModelProfileSummary | undefined,
|
|
507
|
+
): profile is LauncherModelProfileSummary => profile !== undefined,
|
|
508
|
+
);
|
|
509
|
+
};
|
|
510
|
+
const launcherService = buildProcessLauncherRegistry(extensionCatalog, {
|
|
511
|
+
modelProfiles: launcherModelProfiles,
|
|
512
|
+
commitMessages: config.commit_messages,
|
|
513
|
+
getModelProfilesForProcess,
|
|
514
|
+
});
|
|
515
|
+
const processWatcherService = buildProcessWatcherRegistry(extensionCatalog, config, {
|
|
516
|
+
modelProfiles: launcherModelProfiles,
|
|
517
|
+
getModelProfilesForProcess,
|
|
518
|
+
processModelPolicy,
|
|
519
|
+
});
|
|
520
|
+
const workerWebSocketIpc = createWorkerWebSocketIpcManager();
|
|
521
|
+
// This window must open before listen(): workers from the previous server
|
|
522
|
+
// process can reconnect as soon as the socket accepts connections, before
|
|
523
|
+
// startup adoption has registered their worker ids.
|
|
524
|
+
workerWebSocketIpc.setUnknownWorkerConnectionsRetryable(true);
|
|
525
|
+
const serverEpoch = `epoch_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
526
|
+
const sessionSnapshots = createProjectedSessionSnapshotStore(
|
|
527
|
+
createFileBackedProcessSessionSnapshotStore(config.storage.tree_files_dir),
|
|
528
|
+
repos,
|
|
529
|
+
);
|
|
530
|
+
for (const process of repos.processes.listAll()) await sessionSnapshots.backfill(process.id);
|
|
531
|
+
const sessionReader = new ProcessSessionReader(sessionSnapshots);
|
|
532
|
+
const resultImages = new ResultImageStore({
|
|
533
|
+
rootDir: path.join(config.storage.tree_files_dir, "result-images"),
|
|
534
|
+
});
|
|
535
|
+
const authService = createAuthService({ config, repos });
|
|
536
|
+
await registerWebsocket(app, broadcaster, workerWebSocketIpc, authService);
|
|
537
|
+
const extensionHost = createExtensionHost<ServerExtensionEventMap>();
|
|
538
|
+
let launchCoordinator: LaunchCoordinator | undefined;
|
|
539
|
+
let applyGeneratedFutureExecutionTitle: NonNullable<
|
|
540
|
+
Parameters<typeof createProcessTitleGenerator>[0]["futureExecutionTitleApplier"]
|
|
541
|
+
> = async () => ({
|
|
542
|
+
kind: "failed",
|
|
543
|
+
error: "Future execution lifecycle is not initialized",
|
|
544
|
+
});
|
|
545
|
+
const processTitles: ProcessTitleGenerator | undefined =
|
|
546
|
+
opts.processTitleGenerator ??
|
|
547
|
+
(config.pi.process_title_generation.model_profile === null
|
|
548
|
+
? undefined
|
|
549
|
+
: createProcessTitleGenerator({
|
|
550
|
+
config,
|
|
551
|
+
repos,
|
|
552
|
+
broadcaster,
|
|
553
|
+
extensionHost,
|
|
554
|
+
futureExecutionTitleApplier: (input) => applyGeneratedFutureExecutionTitle(input),
|
|
555
|
+
getLaunchCoordinator: () => launchCoordinator,
|
|
556
|
+
logger: {
|
|
557
|
+
warn: (message, details) => app.log.warn(details ?? {}, message),
|
|
558
|
+
},
|
|
559
|
+
runtime: {
|
|
560
|
+
generateTitle: ({ prompt, maxTokens, providerOptions }) =>
|
|
561
|
+
modelProviderServerAdapters.generateText({
|
|
562
|
+
profileId: config.pi.process_title_generation.model_profile as string,
|
|
563
|
+
prompt,
|
|
564
|
+
systemPrompt: TITLE_SYSTEM_PROMPT,
|
|
565
|
+
maxTokens,
|
|
566
|
+
request: providerOptions,
|
|
567
|
+
}),
|
|
568
|
+
},
|
|
569
|
+
}));
|
|
547
570
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
processes: baseDeps.processes,
|
|
568
|
-
turnStarts: baseDeps.turnStarts,
|
|
569
|
-
commands: processEngine,
|
|
570
|
-
policy: processModelPolicy,
|
|
571
|
-
availability: snapshot,
|
|
572
|
-
cause: "availability_transition",
|
|
573
|
-
profileIds,
|
|
574
|
-
logger: app.log,
|
|
575
|
-
});
|
|
571
|
+
const baseDeps = {
|
|
572
|
+
...repos,
|
|
573
|
+
broadcaster,
|
|
574
|
+
processOperations,
|
|
575
|
+
};
|
|
576
|
+
let invalidateExternalSourceArmings: ((instanceId: string) => void) | null = null;
|
|
577
|
+
const projectMutations = createProjectMutationService({
|
|
578
|
+
projects: baseDeps.projects,
|
|
579
|
+
transaction: baseDeps.transaction,
|
|
580
|
+
broadcaster,
|
|
581
|
+
onProjectMutated: (project) => invalidateExternalSourceArmings?.(project.instanceId),
|
|
582
|
+
});
|
|
583
|
+
const launcherRecentValues = createLauncherRecentValuesService({
|
|
584
|
+
repos: baseDeps,
|
|
585
|
+
launcherService,
|
|
586
|
+
});
|
|
587
|
+
const launchPlans: ProcessLaunchPlanServiceLike = {
|
|
588
|
+
async prepare(launchPlan, opts = {}) {
|
|
589
|
+
return processModelPolicy.prepareLaunchPlan(launchPlan, opts);
|
|
576
590
|
},
|
|
591
|
+
};
|
|
592
|
+
const launcherModelConfigs = createLauncherModelConfigService({
|
|
593
|
+
launcherService,
|
|
594
|
+
launchPlans,
|
|
595
|
+
processModelPolicy,
|
|
596
|
+
modelStatusCache,
|
|
577
597
|
});
|
|
578
|
-
|
|
579
|
-
startHooks.push(() => {
|
|
580
|
-
if (modelProviderRegistry.size === 0) return;
|
|
581
|
-
modelStatusRefreshTimer = setInterval(() => {
|
|
582
|
-
void refreshModelStatusAndApplyTransitions().catch((error: unknown) => {
|
|
583
|
-
app.log.warn({ error }, "Model provider status refresh failed");
|
|
584
|
-
});
|
|
585
|
-
}, 15_000);
|
|
586
|
-
});
|
|
587
|
-
stopHooks.push(() => {
|
|
588
|
-
if (modelStatusRefreshTimer) clearInterval(modelStatusRefreshTimer);
|
|
589
|
-
modelStatusRefreshTimer = null;
|
|
590
|
-
});
|
|
591
|
-
let stopAuthSweep: (() => void) | null = null;
|
|
592
|
-
startHooks.push(() => {
|
|
593
|
-
stopAuthSweep = authService.startExpiredAuthStateSweep();
|
|
594
|
-
});
|
|
595
|
-
stopHooks.push(() => {
|
|
596
|
-
stopAuthSweep?.();
|
|
597
|
-
stopAuthSweep = null;
|
|
598
|
-
});
|
|
598
|
+
const polling = createPollingCoordinator(app.log);
|
|
599
599
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
600
|
+
const startHooks: Array<() => void | Promise<void>> = [];
|
|
601
|
+
const stopHooks: Array<() => void | Promise<void>> = [];
|
|
602
|
+
preCloseCleanup.push(async () => {
|
|
603
|
+
const errors = await collectCleanupErrors(stopHooks);
|
|
604
|
+
if (errors.length) throw new AggregateError(errors, "Background service cleanup failed");
|
|
605
|
+
});
|
|
606
|
+
const modelRefreshWork = new Set<Promise<void>>();
|
|
607
|
+
let modelStatusRefreshTimer: NodeJS.Timeout | null = null;
|
|
608
|
+
let futureExecutionLifecycle: FutureExecutionLifecycle;
|
|
609
|
+
async function refreshModelStatusAndApplyTransitions(): Promise<void> {
|
|
610
|
+
const snapshot = await modelStatusCache.refresh();
|
|
611
|
+
await applyProcessModelAvailabilityTransitions({
|
|
612
|
+
snapshot,
|
|
613
|
+
reconcileFutureExecutions: async (profileIds) => {
|
|
614
|
+
await futureExecutionLifecycle.reconcileModelAvailability({
|
|
615
|
+
availability: snapshot,
|
|
616
|
+
profileIds,
|
|
617
|
+
});
|
|
618
|
+
},
|
|
619
|
+
recoverProcesses: async (profileIds) => {
|
|
620
|
+
await recoverModelAvailabilityFailures({
|
|
621
|
+
processes: baseDeps.processes,
|
|
622
|
+
turnStarts: baseDeps.turnStarts,
|
|
623
|
+
commands: processEngine,
|
|
624
|
+
policy: processModelPolicy,
|
|
625
|
+
availability: snapshot,
|
|
626
|
+
cause: "availability_transition",
|
|
627
|
+
profileIds,
|
|
628
|
+
logger: app.log,
|
|
629
|
+
});
|
|
630
|
+
},
|
|
631
|
+
});
|
|
603
632
|
}
|
|
633
|
+
startHooks.push(() => {
|
|
634
|
+
if (modelProviderRegistry.size === 0) return;
|
|
635
|
+
modelStatusRefreshTimer = setInterval(() => {
|
|
636
|
+
const work = refreshModelStatusAndApplyTransitions().catch((error: unknown) => {
|
|
637
|
+
app.log.warn({ error }, "Model provider status refresh failed");
|
|
638
|
+
});
|
|
639
|
+
modelRefreshWork.add(work);
|
|
640
|
+
void work.finally(() => modelRefreshWork.delete(work));
|
|
641
|
+
}, 15_000);
|
|
642
|
+
});
|
|
643
|
+
stopHooks.push(async () => {
|
|
644
|
+
if (modelStatusRefreshTimer) clearInterval(modelStatusRefreshTimer);
|
|
645
|
+
modelStatusRefreshTimer = null;
|
|
646
|
+
await Promise.all(modelRefreshWork);
|
|
647
|
+
});
|
|
648
|
+
let stopAuthSweep: (() => void) | null = null;
|
|
649
|
+
startHooks.push(() => {
|
|
650
|
+
stopAuthSweep = authService.startExpiredAuthStateSweep();
|
|
651
|
+
});
|
|
652
|
+
stopHooks.push(() => {
|
|
653
|
+
stopAuthSweep?.();
|
|
654
|
+
stopAuthSweep = null;
|
|
655
|
+
});
|
|
604
656
|
|
|
605
|
-
|
|
657
|
+
async function reconcileStartup(assertOpen: () => void): Promise<void> {
|
|
606
658
|
if (!supervisor) {
|
|
607
659
|
throw new Error("worker supervisor not initialized");
|
|
608
660
|
}
|
|
@@ -611,6 +663,7 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
|
|
|
611
663
|
await futureExecutionLifecycle.reconcileModelAvailability({
|
|
612
664
|
availability: modelStatusCache.snapshot(),
|
|
613
665
|
});
|
|
666
|
+
assertOpen();
|
|
614
667
|
await recoverModelAvailabilityFailures({
|
|
615
668
|
processes: baseDeps.processes,
|
|
616
669
|
turnStarts: baseDeps.turnStarts,
|
|
@@ -620,13 +673,16 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
|
|
|
620
673
|
cause: "startup_reconciliation",
|
|
621
674
|
logger: app.log,
|
|
622
675
|
});
|
|
676
|
+
assertOpen();
|
|
623
677
|
await reconcilePersistedProcessModelIntegrity({
|
|
624
678
|
processes: baseDeps.processes,
|
|
625
679
|
commands: processEngine,
|
|
626
680
|
policy: processModelPolicy,
|
|
627
681
|
logger: app.log,
|
|
628
682
|
});
|
|
683
|
+
assertOpen();
|
|
629
684
|
await supervisor.adoptRegisteredWorkers();
|
|
685
|
+
assertOpen();
|
|
630
686
|
await reconcileProcessesOnStartup({
|
|
631
687
|
config,
|
|
632
688
|
processes: baseDeps.processes,
|
|
@@ -640,402 +696,343 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
|
|
|
640
696
|
processActionRegistry,
|
|
641
697
|
logger: app.log,
|
|
642
698
|
});
|
|
643
|
-
|
|
699
|
+
assertOpen();
|
|
644
700
|
} finally {
|
|
645
701
|
workerWebSocketIpc.setUnknownWorkerConnectionsRetryable(false);
|
|
646
702
|
}
|
|
647
703
|
}
|
|
648
704
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
backgroundServicesReady = false;
|
|
657
|
-
backgroundServicesStarted = false;
|
|
658
|
-
for (const hook of [...stopHooks].reverse()) {
|
|
659
|
-
await hook();
|
|
660
|
-
}
|
|
661
|
-
throw error;
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
async function stopBackgroundServices(): Promise<void> {
|
|
666
|
-
backgroundServicesReady = false;
|
|
667
|
-
if (!backgroundServicesStarted) {
|
|
668
|
-
return;
|
|
669
|
-
}
|
|
670
|
-
backgroundServicesStarted = false;
|
|
671
|
-
for (const hook of [...stopHooks].reverse()) {
|
|
672
|
-
await hook();
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
let supervisor: WorkerSupervisor | undefined;
|
|
677
|
-
let isNewTurnBlocked = (_instanceId: string): boolean => false;
|
|
678
|
-
const afterSuccessHooks = new Set<(instanceId: string) => void | Promise<void>>();
|
|
679
|
-
const toastTtlMs = parseDurationMs(config.server.websocket.toast_ttl, 6_000, {
|
|
680
|
-
allowHours: true,
|
|
681
|
-
});
|
|
682
|
-
const processEngine = createProcessEngine({
|
|
683
|
-
processes: baseDeps.processes,
|
|
684
|
-
events: baseDeps.events,
|
|
685
|
-
futureExecutions: baseDeps.futureExecutions,
|
|
686
|
-
projects: baseDeps.projects,
|
|
687
|
-
inputs: baseDeps.inputs,
|
|
688
|
-
pendingExternalSourceFires: baseDeps.pendingExternalSourceFires,
|
|
689
|
-
leafOutcomeSnapshots: baseDeps.leafOutcomeSnapshots,
|
|
690
|
-
questionRequests: baseDeps.questionRequests,
|
|
691
|
-
turnRecords: baseDeps.turnRecords,
|
|
692
|
-
turnStarts: baseDeps.turnStarts,
|
|
693
|
-
leases: baseDeps.leases,
|
|
694
|
-
turnAnnotations: baseDeps.turnAnnotations,
|
|
695
|
-
transaction: baseDeps.transaction,
|
|
696
|
-
broadcaster,
|
|
697
|
-
config,
|
|
698
|
-
toastTtlMs,
|
|
699
|
-
processOperations,
|
|
700
|
-
getSupervisor: () => supervisor,
|
|
701
|
-
extensionHost,
|
|
702
|
-
processGraphs,
|
|
703
|
-
sessionReader,
|
|
704
|
-
getProcessActionRegistry: () => processActionRegistry,
|
|
705
|
-
getProcessUiRegistry: () => processUiRegistry,
|
|
706
|
-
logger: app.log,
|
|
707
|
-
processModelPolicy,
|
|
708
|
-
getModelAvailabilitySnapshot: () => modelStatusCache.snapshot(),
|
|
709
|
-
afterRecord(process) {
|
|
710
|
-
// The process volume is the durable source for an already-created start.
|
|
711
|
-
// A missing server-cache entry is valid after restart.
|
|
712
|
-
piResourceBundlePins.reconcile(process);
|
|
713
|
-
toolApprovalGate.reconcile(process.id);
|
|
714
|
-
},
|
|
715
|
-
afterSuccessHooks,
|
|
716
|
-
isNewTurnBlocked: (instanceId) => isNewTurnBlocked(instanceId),
|
|
717
|
-
prepareTurnStarts: (process, writes, providerOptions, availabilitySnapshot) =>
|
|
718
|
-
prepareCreatedTurnStarts(
|
|
719
|
-
{
|
|
720
|
-
config,
|
|
721
|
-
registry: modelProviderRegistry,
|
|
722
|
-
modelStatusCache,
|
|
723
|
-
piContributions: extensionCatalog.piContributions,
|
|
724
|
-
bundleCache: piResourceBundles,
|
|
725
|
-
projects: baseDeps.projects,
|
|
726
|
-
processSkills: baseDeps.processSkills,
|
|
727
|
-
},
|
|
728
|
-
process,
|
|
729
|
-
writes,
|
|
730
|
-
providerOptions,
|
|
731
|
-
availabilitySnapshot,
|
|
732
|
-
),
|
|
733
|
-
});
|
|
734
|
-
|
|
735
|
-
const processQuestions = createProcessQuestionService({
|
|
736
|
-
repos: baseDeps,
|
|
737
|
-
processOperations,
|
|
738
|
-
broadcaster,
|
|
739
|
-
getWorkerId: (instanceId) => supervisor?.getWorker(instanceId)?.workerId ?? null,
|
|
740
|
-
sendQuestionResponse: (instanceId, workerId, payload) =>
|
|
741
|
-
supervisor?.questionResponse(instanceId, workerId, payload),
|
|
742
|
-
emitQuestionRequested: (request) =>
|
|
743
|
-
extensionHost
|
|
744
|
-
.emit("question_requested", { instanceId: request.instanceId, request })
|
|
745
|
-
.catch((error) =>
|
|
746
|
-
app.log.error(
|
|
747
|
-
{ error, instanceId: request.instanceId },
|
|
748
|
-
"Question delivery event failed",
|
|
749
|
-
),
|
|
750
|
-
),
|
|
751
|
-
});
|
|
752
|
-
|
|
753
|
-
const toolApprovalGate = createToolApprovalGate({
|
|
754
|
-
repos: baseDeps,
|
|
755
|
-
processOperations,
|
|
756
|
-
});
|
|
757
|
-
const integrationToolRequests = createIntegrationToolRequestService({
|
|
758
|
-
registry: integrationTools,
|
|
759
|
-
repos: baseDeps,
|
|
760
|
-
processActionRegistry,
|
|
761
|
-
toolApprovalGate,
|
|
762
|
-
});
|
|
763
|
-
const diagnosticTraceWriter = createDiagnosticTraceWriter(
|
|
764
|
-
path.join(config.storage.tree_files_dir, "diagnostic-traces"),
|
|
765
|
-
);
|
|
766
|
-
const ipcHandler = createIpcHandler(
|
|
767
|
-
{
|
|
768
|
-
startupObservations: baseDeps.startupObservations,
|
|
705
|
+
let supervisor: WorkerSupervisor | undefined;
|
|
706
|
+
let isNewTurnBlocked = (_instanceId: string): boolean => false;
|
|
707
|
+
const afterSuccessHooks = new Set<(instanceId: string) => void | Promise<void>>();
|
|
708
|
+
const toastTtlMs = parseDurationMs(config.server.websocket.toast_ttl, 6_000, {
|
|
709
|
+
allowHours: true,
|
|
710
|
+
});
|
|
711
|
+
const processEngine = createProcessEngine({
|
|
769
712
|
processes: baseDeps.processes,
|
|
770
|
-
|
|
713
|
+
events: baseDeps.events,
|
|
714
|
+
futureExecutions: baseDeps.futureExecutions,
|
|
771
715
|
projects: baseDeps.projects,
|
|
772
716
|
inputs: baseDeps.inputs,
|
|
773
|
-
|
|
774
|
-
|
|
717
|
+
pendingExternalSourceFires: baseDeps.pendingExternalSourceFires,
|
|
718
|
+
leafOutcomeSnapshots: baseDeps.leafOutcomeSnapshots,
|
|
719
|
+
questionRequests: baseDeps.questionRequests,
|
|
775
720
|
turnRecords: baseDeps.turnRecords,
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
processQuestions,
|
|
721
|
+
turnStarts: baseDeps.turnStarts,
|
|
722
|
+
leases: baseDeps.leases,
|
|
723
|
+
turnAnnotations: baseDeps.turnAnnotations,
|
|
724
|
+
transaction: baseDeps.transaction,
|
|
781
725
|
broadcaster,
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
appendDiagnosticTrace(instanceId, text) {
|
|
800
|
-
try {
|
|
801
|
-
diagnosticTraceWriter.append(instanceId, text);
|
|
802
|
-
} catch (error) {
|
|
803
|
-
app.log.warn({ error, instanceId }, "Could not append worker diagnostic trace");
|
|
804
|
-
}
|
|
805
|
-
},
|
|
806
|
-
workerEventLogger: config.workers.log_worker_events_to_stdout
|
|
807
|
-
? (entry) => {
|
|
808
|
-
// Worker IPC is WebSocket-only; terminal visibility comes from mirroring
|
|
809
|
-
// worker.event payloads through the server's own logger.
|
|
810
|
-
app.log.info({ source: "worker_event", ...entry }, "worker.event");
|
|
811
|
-
}
|
|
812
|
-
: undefined,
|
|
813
|
-
},
|
|
814
|
-
{
|
|
815
|
-
onTurnTerminalRecorded(instanceId, workerId, turnRecordId) {
|
|
816
|
-
supervisor?.acknowledgeTurnTerminal(instanceId, workerId, { turnRecordId });
|
|
817
|
-
},
|
|
818
|
-
onTurnFailedRecorded(input) {
|
|
819
|
-
app.log.warn(input, "Worker turn failed");
|
|
726
|
+
config,
|
|
727
|
+
toastTtlMs,
|
|
728
|
+
processOperations,
|
|
729
|
+
getSupervisor: () => supervisor,
|
|
730
|
+
extensionHost,
|
|
731
|
+
processGraphs,
|
|
732
|
+
sessionReader,
|
|
733
|
+
getProcessActionRegistry: () => processActionRegistry,
|
|
734
|
+
getProcessUiRegistry: () => processUiRegistry,
|
|
735
|
+
logger: app.log,
|
|
736
|
+
processModelPolicy,
|
|
737
|
+
getModelAvailabilitySnapshot: () => modelStatusCache.snapshot(),
|
|
738
|
+
afterRecord(process) {
|
|
739
|
+
// The process volume is the durable source for an already-created start.
|
|
740
|
+
// A missing server-cache entry is valid after restart.
|
|
741
|
+
piResourceBundlePins.reconcile(process);
|
|
742
|
+
toolApprovalGate.reconcile(process.id);
|
|
820
743
|
},
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
744
|
+
afterSuccessHooks,
|
|
745
|
+
isNewTurnBlocked: (instanceId) => isNewTurnBlocked(instanceId),
|
|
746
|
+
prepareTurnStarts: (process, writes, providerOptions, availabilitySnapshot) =>
|
|
747
|
+
prepareCreatedTurnStarts(
|
|
748
|
+
{
|
|
749
|
+
config,
|
|
750
|
+
registry: modelProviderRegistry,
|
|
751
|
+
modelStatusCache,
|
|
752
|
+
piContributions: extensionCatalog.piContributions,
|
|
753
|
+
bundleCache: piResourceBundles,
|
|
754
|
+
projects: baseDeps.projects,
|
|
755
|
+
processSkills: baseDeps.processSkills,
|
|
832
756
|
},
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
payload.startRecordId,
|
|
840
|
-
payload.turnRecordId,
|
|
841
|
-
);
|
|
842
|
-
},
|
|
843
|
-
onCredentialUpdateResult(instanceId, workerId, payload) {
|
|
844
|
-
supervisor?.credentialUpdateResult(instanceId, workerId, payload);
|
|
845
|
-
},
|
|
846
|
-
onIntegrationToolResult(instanceId, workerId, payload) {
|
|
847
|
-
supervisor?.integrationToolResult(instanceId, workerId, payload);
|
|
848
|
-
},
|
|
849
|
-
},
|
|
850
|
-
);
|
|
757
|
+
process,
|
|
758
|
+
writes,
|
|
759
|
+
providerOptions,
|
|
760
|
+
availabilitySnapshot,
|
|
761
|
+
),
|
|
762
|
+
});
|
|
851
763
|
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
helperRelays: sessionTransferHelperRelays,
|
|
870
|
-
onVolumePoolError: () =>
|
|
871
|
-
app.log.warn("Volume pre-provisioning failed; retrying in the background"),
|
|
872
|
-
localWorkerSpawnImpl: opts.localWorkerSpawnImpl,
|
|
873
|
-
localWorkerDockerPreflightImpl: opts.localWorkerDockerPreflightImpl,
|
|
874
|
-
});
|
|
875
|
-
if (runnerRuntime.volumePool) {
|
|
876
|
-
startHooks.push(() => runnerRuntime.volumePool?.start());
|
|
877
|
-
stopHooks.push(() => runnerRuntime.volumePool?.stop());
|
|
878
|
-
}
|
|
879
|
-
markStartup("worker_runner");
|
|
880
|
-
supervisor = createWorkerSupervisor({
|
|
881
|
-
startupObservations: baseDeps.startupObservations,
|
|
882
|
-
config: supervisorConfig,
|
|
883
|
-
processGraphs,
|
|
884
|
-
processActionRegistry,
|
|
885
|
-
processModelPolicy,
|
|
886
|
-
ipcHandler,
|
|
887
|
-
leases: baseDeps.leases,
|
|
888
|
-
getLaunchCoordinator: () => launchCoordinator,
|
|
889
|
-
processes: baseDeps.processes,
|
|
890
|
-
projects: baseDeps.projects,
|
|
891
|
-
inputs: baseDeps.inputs,
|
|
892
|
-
turnRecords: baseDeps.turnRecords,
|
|
893
|
-
turnStarts: baseDeps.turnStarts,
|
|
894
|
-
events: baseDeps.events,
|
|
895
|
-
broadcaster,
|
|
896
|
-
runnerRuntime,
|
|
897
|
-
logger: app.log,
|
|
898
|
-
resolvedExtensionEntriesJson: serializeResolvedExtensionEntries(resolvedExtensionEntries),
|
|
899
|
-
serverEpoch,
|
|
900
|
-
resolveResourceBundle(digest) {
|
|
901
|
-
return piResourceBundles.get(digest);
|
|
902
|
-
},
|
|
903
|
-
resolveRepositoryCredentials: (input) => repositoryCredentials.resolveWorkerCredentials(input),
|
|
904
|
-
integrationTools,
|
|
905
|
-
resolveCredential: (providerId, options) =>
|
|
906
|
-
modelProviderCredentials.resolve(providerId, options),
|
|
907
|
-
});
|
|
764
|
+
const processQuestions = createProcessQuestionService({
|
|
765
|
+
repos: baseDeps,
|
|
766
|
+
processOperations,
|
|
767
|
+
broadcaster,
|
|
768
|
+
getWorkerId: (instanceId) => supervisor?.getWorker(instanceId)?.workerId ?? null,
|
|
769
|
+
sendQuestionResponse: (instanceId, workerId, payload) =>
|
|
770
|
+
supervisor?.questionResponse(instanceId, workerId, payload),
|
|
771
|
+
emitQuestionRequested: (request) =>
|
|
772
|
+
extensionHost
|
|
773
|
+
.emit("question_requested", { instanceId: request.instanceId, request })
|
|
774
|
+
.catch((error) =>
|
|
775
|
+
app.log.error(
|
|
776
|
+
{ error, instanceId: request.instanceId },
|
|
777
|
+
"Question delivery event failed",
|
|
778
|
+
),
|
|
779
|
+
),
|
|
780
|
+
});
|
|
908
781
|
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
};
|
|
922
|
-
const expiredImageProcesses = new Set(
|
|
923
|
-
planProcessVolumeRetentionCleanup({ processes, now, policy }),
|
|
924
|
-
);
|
|
925
|
-
try {
|
|
926
|
-
const released = await cleanupRetainedProcessVolumes({
|
|
927
|
-
volume: runnerRuntime.volume,
|
|
928
|
-
processes,
|
|
929
|
-
now,
|
|
930
|
-
policy,
|
|
931
|
-
alreadyReleased: releasedRetainedVolumes,
|
|
932
|
-
});
|
|
933
|
-
for (const instanceId of released) releasedRetainedVolumes.add(instanceId);
|
|
934
|
-
} catch (error) {
|
|
935
|
-
app.log.warn({ error }, "retained process volume cleanup failed");
|
|
936
|
-
}
|
|
937
|
-
try {
|
|
938
|
-
await resultImages.cleanupProcesses({
|
|
939
|
-
// Refresh after volume cleanup so a process created during the sweep is
|
|
940
|
-
// never mistaken for an orphan.
|
|
941
|
-
retainedInstanceIds: new Set(baseDeps.processes.listAll().map((process) => process.id)),
|
|
942
|
-
expiredInstanceIds: expiredImageProcesses,
|
|
943
|
-
});
|
|
944
|
-
} catch (error) {
|
|
945
|
-
app.log.warn({ error }, "retained result image cleanup failed");
|
|
946
|
-
} finally {
|
|
947
|
-
retainedVolumeCleanupRunning = false;
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
startHooks.push(() => {
|
|
951
|
-
if (!supervisor) {
|
|
952
|
-
throw new Error("worker supervisor not initialized");
|
|
953
|
-
}
|
|
954
|
-
void runRetainedVolumeCleanup();
|
|
955
|
-
const cleanupIntervalMs = Math.max(
|
|
956
|
-
60_000,
|
|
957
|
-
parseDurationMs(config.workers.cleanup.transient_ttl, 3_600_000, { allowHours: true }),
|
|
782
|
+
const toolApprovalGate = createToolApprovalGate({
|
|
783
|
+
repos: baseDeps,
|
|
784
|
+
processOperations,
|
|
785
|
+
});
|
|
786
|
+
const integrationToolRequests = createIntegrationToolRequestService({
|
|
787
|
+
registry: integrationTools,
|
|
788
|
+
repos: baseDeps,
|
|
789
|
+
processActionRegistry,
|
|
790
|
+
toolApprovalGate,
|
|
791
|
+
});
|
|
792
|
+
const diagnosticTraceWriter = createDiagnosticTraceWriter(
|
|
793
|
+
path.join(config.storage.tree_files_dir, "diagnostic-traces"),
|
|
958
794
|
);
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
795
|
+
const ipcHandler = createIpcHandler(
|
|
796
|
+
{
|
|
797
|
+
startupObservations: baseDeps.startupObservations,
|
|
798
|
+
processes: baseDeps.processes,
|
|
799
|
+
getLaunchCoordinator: () => launchCoordinator,
|
|
800
|
+
projects: baseDeps.projects,
|
|
801
|
+
inputs: baseDeps.inputs,
|
|
802
|
+
events: baseDeps.events,
|
|
803
|
+
leases: baseDeps.leases,
|
|
804
|
+
turnRecords: baseDeps.turnRecords,
|
|
805
|
+
handleIntegrationToolRequest: (instanceId, payload) =>
|
|
806
|
+
integrationToolRequests.handle(instanceId, payload),
|
|
807
|
+
handleIntegrationToolCancel: (instanceId, payload) =>
|
|
808
|
+
void integrationToolRequests.cancel(instanceId, payload),
|
|
809
|
+
processQuestions,
|
|
810
|
+
broadcaster,
|
|
811
|
+
commands: processEngine,
|
|
812
|
+
updateCredential: ({ providerId, expectedRevision, values }) => {
|
|
813
|
+
const result = modelProviderCredentials.compareAndSet({
|
|
814
|
+
providerId,
|
|
815
|
+
expectedRevision,
|
|
816
|
+
value: values,
|
|
817
|
+
});
|
|
818
|
+
if (result.accepted && !lifecycle.isClosing()) {
|
|
819
|
+
const work = refreshModelStatusAndApplyTransitions().catch((error: unknown) => {
|
|
820
|
+
app.log.warn(
|
|
821
|
+
{ error, providerId },
|
|
822
|
+
"Model status refresh after credential update failed",
|
|
823
|
+
);
|
|
824
|
+
});
|
|
825
|
+
modelRefreshWork.add(work);
|
|
826
|
+
void work.finally(() => modelRefreshWork.delete(work));
|
|
827
|
+
}
|
|
828
|
+
return result;
|
|
829
|
+
},
|
|
830
|
+
appendDiagnosticTrace(instanceId, text) {
|
|
831
|
+
try {
|
|
832
|
+
diagnosticTraceWriter.append(instanceId, text);
|
|
833
|
+
} catch (error) {
|
|
834
|
+
app.log.warn({ error, instanceId }, "Could not append worker diagnostic trace");
|
|
835
|
+
}
|
|
836
|
+
},
|
|
837
|
+
workerEventLogger: config.workers.log_worker_events_to_stdout
|
|
838
|
+
? (entry) => {
|
|
839
|
+
// Worker IPC is WebSocket-only; terminal visibility comes from mirroring
|
|
840
|
+
// worker.event payloads through the server's own logger.
|
|
841
|
+
app.log.info({ source: "worker_event", ...entry }, "worker.event");
|
|
842
|
+
}
|
|
843
|
+
: undefined,
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
onTurnTerminalRecorded(instanceId, workerId, turnRecordId) {
|
|
847
|
+
supervisor?.acknowledgeTurnTerminal(instanceId, workerId, { turnRecordId });
|
|
848
|
+
},
|
|
849
|
+
onTurnFailedRecorded(input) {
|
|
850
|
+
app.log.warn(input, "Worker turn failed");
|
|
851
|
+
},
|
|
852
|
+
onTurnTerminalRecordingFailed(input) {
|
|
853
|
+
app.log.error(input, "Worker turn terminal recording failed");
|
|
854
|
+
baseDeps.events.create({
|
|
855
|
+
instanceId: input.instanceId,
|
|
856
|
+
eventType: "worker_terminal_recording_failed",
|
|
857
|
+
data: {
|
|
858
|
+
workerId: input.workerId,
|
|
859
|
+
turnRecordId: input.turnRecordId,
|
|
860
|
+
terminalType: input.terminalType,
|
|
861
|
+
code: input.code,
|
|
862
|
+
message: input.message,
|
|
863
|
+
},
|
|
864
|
+
});
|
|
865
|
+
},
|
|
866
|
+
onWorkerTurnStartAccepted(instanceId, workerId, payload) {
|
|
867
|
+
supervisor?.acceptTurnStart(
|
|
868
|
+
instanceId,
|
|
869
|
+
workerId,
|
|
870
|
+
payload.startRecordId,
|
|
871
|
+
payload.turnRecordId,
|
|
872
|
+
);
|
|
873
|
+
},
|
|
874
|
+
onCredentialUpdateResult(instanceId, workerId, payload) {
|
|
875
|
+
supervisor?.credentialUpdateResult(instanceId, workerId, payload);
|
|
876
|
+
},
|
|
877
|
+
onIntegrationToolResult(instanceId, workerId, payload) {
|
|
878
|
+
supervisor?.integrationToolResult(instanceId, workerId, payload);
|
|
879
|
+
},
|
|
880
|
+
},
|
|
962
881
|
);
|
|
963
|
-
|
|
882
|
+
|
|
883
|
+
const repositoryCredentials = new RepositoryCredentialService(extensionCatalog.processes);
|
|
884
|
+
const sessionTransferLimits = config.session_transfer
|
|
885
|
+
? {
|
|
886
|
+
maxEntries: config.session_transfer.max_entries,
|
|
887
|
+
maxLogicalBytes: config.session_transfer.max_logical_bytes,
|
|
888
|
+
maxCompressedBytes: config.session_transfer.max_compressed_bytes,
|
|
889
|
+
}
|
|
890
|
+
: DEFAULT_SESSION_TRANSFER_LIMITS;
|
|
891
|
+
const sessionTransferHelperRelays = createSessionTransferHelperRelays({
|
|
892
|
+
repos: baseDeps,
|
|
893
|
+
limits: sessionTransferLimits,
|
|
894
|
+
});
|
|
895
|
+
const supervisorConfig = config;
|
|
896
|
+
const runnerRuntime = await createConfiguredWorkerRunnerRuntime({
|
|
897
|
+
config: supervisorConfig,
|
|
898
|
+
webSocketIpc: workerWebSocketIpc,
|
|
899
|
+
provided: opts.workerRunnerRuntime,
|
|
900
|
+
helperRelays: sessionTransferHelperRelays,
|
|
901
|
+
onVolumePoolError: () =>
|
|
902
|
+
app.log.warn("Volume pre-provisioning failed; retrying in the background"),
|
|
903
|
+
localWorkerSpawnImpl: opts.localWorkerSpawnImpl,
|
|
904
|
+
localWorkerDockerPreflightImpl: opts.localWorkerDockerPreflightImpl,
|
|
905
|
+
});
|
|
906
|
+
if (runnerRuntime.volumePool) {
|
|
907
|
+
startHooks.push(() => runnerRuntime.volumePool?.start());
|
|
908
|
+
stopHooks.push(() => runnerRuntime.volumePool?.stop());
|
|
909
|
+
}
|
|
910
|
+
markStartup("worker_runner");
|
|
911
|
+
supervisor = createWorkerSupervisor({
|
|
912
|
+
startupObservations: baseDeps.startupObservations,
|
|
913
|
+
config: supervisorConfig,
|
|
914
|
+
processGraphs,
|
|
915
|
+
processActionRegistry,
|
|
916
|
+
processModelPolicy,
|
|
917
|
+
ipcHandler,
|
|
964
918
|
leases: baseDeps.leases,
|
|
919
|
+
getLaunchCoordinator: () => launchCoordinator,
|
|
965
920
|
processes: baseDeps.processes,
|
|
921
|
+
projects: baseDeps.projects,
|
|
922
|
+
inputs: baseDeps.inputs,
|
|
966
923
|
turnRecords: baseDeps.turnRecords,
|
|
967
924
|
turnStarts: baseDeps.turnStarts,
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
925
|
+
events: baseDeps.events,
|
|
926
|
+
broadcaster,
|
|
927
|
+
runnerRuntime,
|
|
928
|
+
logger: app.log,
|
|
929
|
+
resolvedExtensionEntriesJson: serializeResolvedExtensionEntries(resolvedExtensionEntries),
|
|
930
|
+
serverEpoch,
|
|
931
|
+
resolveResourceBundle(digest) {
|
|
932
|
+
return piResourceBundles.get(digest);
|
|
933
|
+
},
|
|
934
|
+
resolveRepositoryCredentials: (input) =>
|
|
935
|
+
repositoryCredentials.resolveWorkerCredentials(input),
|
|
936
|
+
integrationTools,
|
|
937
|
+
resolveCredential: (providerId, options) =>
|
|
938
|
+
modelProviderCredentials.resolve(providerId, options),
|
|
971
939
|
});
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
940
|
+
|
|
941
|
+
let staleHeartbeatWatchdog: ReturnType<typeof startStaleHeartbeatWatchdog> | null = null;
|
|
942
|
+
let workersClosedForServerShutdown = false;
|
|
943
|
+
stopAcquiredWorkers = async () => {
|
|
944
|
+
if (workersClosedForServerShutdown) return;
|
|
945
|
+
workersClosedForServerShutdown = true;
|
|
946
|
+
if (config.workers.runner === "local") await supervisor?.shutdownAll("server_shutdown");
|
|
947
|
+
else await supervisor?.detachAll("server_shutdown");
|
|
948
|
+
};
|
|
949
|
+
let retentionWork: Promise<void> | undefined;
|
|
950
|
+
let retainedVolumeCleanupTimer: NodeJS.Timeout | null = null;
|
|
951
|
+
let retainedVolumeCleanupRunning = false;
|
|
952
|
+
const releasedRetainedVolumes = new Set<string>();
|
|
953
|
+
async function runRetainedVolumeCleanup(): Promise<void> {
|
|
954
|
+
if (retainedVolumeCleanupRunning) return;
|
|
955
|
+
retainedVolumeCleanupRunning = true;
|
|
956
|
+
const processes = baseDeps.processes.listAll();
|
|
957
|
+
const now = new Date();
|
|
958
|
+
const policy = {
|
|
959
|
+
completedProcessRetention: config.workers.cleanup.completed_process_retention,
|
|
960
|
+
errorProcessRetention: config.workers.cleanup.error_process_retention,
|
|
961
|
+
};
|
|
962
|
+
const expiredImageProcesses = new Set(
|
|
963
|
+
planProcessVolumeRetentionCleanup({ processes, now, policy }),
|
|
964
|
+
);
|
|
965
|
+
try {
|
|
966
|
+
const released = await cleanupRetainedProcessVolumes({
|
|
967
|
+
volume: runnerRuntime.volume,
|
|
968
|
+
processes,
|
|
969
|
+
now,
|
|
970
|
+
policy,
|
|
971
|
+
alreadyReleased: releasedRetainedVolumes,
|
|
972
|
+
});
|
|
973
|
+
for (const instanceId of released) releasedRetainedVolumes.add(instanceId);
|
|
974
|
+
} catch (error) {
|
|
975
|
+
app.log.warn({ error }, "retained process volume cleanup failed");
|
|
976
|
+
}
|
|
977
|
+
try {
|
|
978
|
+
await resultImages.cleanupProcesses({
|
|
979
|
+
// Refresh after volume cleanup so a process created during the sweep is
|
|
980
|
+
// never mistaken for an orphan.
|
|
981
|
+
retainedInstanceIds: new Set(baseDeps.processes.listAll().map((process) => process.id)),
|
|
982
|
+
expiredInstanceIds: expiredImageProcesses,
|
|
983
|
+
});
|
|
984
|
+
} catch (error) {
|
|
985
|
+
app.log.warn({ error }, "retained result image cleanup failed");
|
|
986
|
+
} finally {
|
|
987
|
+
retainedVolumeCleanupRunning = false;
|
|
988
|
+
}
|
|
979
989
|
}
|
|
980
|
-
|
|
990
|
+
startHooks.push(() => {
|
|
991
|
+
if (!supervisor) {
|
|
992
|
+
throw new Error("worker supervisor not initialized");
|
|
993
|
+
}
|
|
994
|
+
retentionWork = runRetainedVolumeCleanup();
|
|
995
|
+
const cleanupIntervalMs = Math.max(
|
|
996
|
+
60_000,
|
|
997
|
+
parseDurationMs(config.workers.cleanup.transient_ttl, 3_600_000, { allowHours: true }),
|
|
998
|
+
);
|
|
999
|
+
retainedVolumeCleanupTimer = setInterval(() => {
|
|
1000
|
+
if (!retainedVolumeCleanupRunning) retentionWork = runRetainedVolumeCleanup();
|
|
1001
|
+
}, cleanupIntervalMs);
|
|
1002
|
+
staleHeartbeatWatchdog = startStaleHeartbeatWatchdog({
|
|
1003
|
+
leases: baseDeps.leases,
|
|
1004
|
+
processes: baseDeps.processes,
|
|
1005
|
+
turnRecords: baseDeps.turnRecords,
|
|
1006
|
+
turnStarts: baseDeps.turnStarts,
|
|
1007
|
+
ipcHandler,
|
|
1008
|
+
supervisor,
|
|
1009
|
+
staleHeartbeatTimeout: config.workers.stale_heartbeat_timeout,
|
|
1010
|
+
});
|
|
1011
|
+
});
|
|
1012
|
+
stopHooks.push(async () => {
|
|
1013
|
+
staleHeartbeatWatchdog?.stop();
|
|
1014
|
+
staleHeartbeatWatchdog = null;
|
|
1015
|
+
if (retainedVolumeCleanupTimer) {
|
|
1016
|
+
clearInterval(retainedVolumeCleanupTimer);
|
|
1017
|
+
retainedVolumeCleanupTimer = null;
|
|
1018
|
+
}
|
|
1019
|
+
await retentionWork;
|
|
1020
|
+
});
|
|
981
1021
|
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
1022
|
+
if (processTitles?.start) {
|
|
1023
|
+
startHooks.push(() => processTitles.start?.());
|
|
1024
|
+
}
|
|
1025
|
+
if (processTitles?.close) {
|
|
1026
|
+
stopHooks.push(() => processTitles.close?.());
|
|
1027
|
+
}
|
|
988
1028
|
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
...baseDeps,
|
|
997
|
-
broadcaster,
|
|
998
|
-
commands: processEngine,
|
|
999
|
-
processTitles,
|
|
1000
|
-
extensionHost,
|
|
1001
|
-
logger: app.log,
|
|
1002
|
-
repositoryCredentials,
|
|
1003
|
-
getSupervisor: () => supervisor,
|
|
1004
|
-
assertRuntimeAvailable: (processId: string) =>
|
|
1005
|
-
assertProcessRuntimeAvailable(
|
|
1006
|
-
{
|
|
1007
|
-
config,
|
|
1008
|
-
processes: extensionCatalog.processes,
|
|
1009
|
-
dockerInfo: opts.localWorkerDockerPreflightImpl,
|
|
1010
|
-
},
|
|
1011
|
-
processId,
|
|
1012
|
-
),
|
|
1013
|
-
};
|
|
1014
|
-
const createProcess = createProcessFromLaunchPlan.bind(null, processLaunchDeps);
|
|
1015
|
-
futureExecutionLifecycle = createFutureExecutionLifecycle({
|
|
1016
|
-
futureExecutions: baseDeps.futureExecutions,
|
|
1017
|
-
processes: baseDeps.processes,
|
|
1018
|
-
projects: baseDeps.projects,
|
|
1019
|
-
processRelations: baseDeps.processRelations,
|
|
1020
|
-
handoffDedupKeys: baseDeps.handoffDedupKeys,
|
|
1021
|
-
turnRecords: baseDeps.turnRecords,
|
|
1022
|
-
skills: baseDeps.skills,
|
|
1023
|
-
processSkills: baseDeps.processSkills,
|
|
1024
|
-
transaction: baseDeps.transaction,
|
|
1025
|
-
broadcaster,
|
|
1026
|
-
commands: processEngine,
|
|
1027
|
-
processOperations,
|
|
1028
|
-
processTitles,
|
|
1029
|
-
extensionHost,
|
|
1030
|
-
launcherService,
|
|
1031
|
-
launcherRecentValues,
|
|
1032
|
-
processGraphs,
|
|
1033
|
-
processActionRegistry: processActionRegistry ?? undefined,
|
|
1034
|
-
processModelPolicy,
|
|
1035
|
-
launchPlans,
|
|
1036
|
-
modelStatusCache,
|
|
1037
|
-
launchPipeline,
|
|
1038
|
-
assertRuntimeAvailable: (processId) =>
|
|
1029
|
+
const launchPipeline = createLaunchPipeline({
|
|
1030
|
+
launchRuns: baseDeps.launchRuns,
|
|
1031
|
+
broadcaster,
|
|
1032
|
+
titleGenerationAvailable: Boolean(processTitles),
|
|
1033
|
+
logger: app.log,
|
|
1034
|
+
});
|
|
1035
|
+
const assertRuntimeAvailable = (processId: string) =>
|
|
1039
1036
|
assertProcessRuntimeAvailable(
|
|
1040
1037
|
{
|
|
1041
1038
|
config,
|
|
@@ -1043,271 +1040,298 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
|
|
|
1043
1040
|
dockerInfo: opts.localWorkerDockerPreflightImpl,
|
|
1044
1041
|
},
|
|
1045
1042
|
processId,
|
|
1046
|
-
),
|
|
1047
|
-
logger: app.log,
|
|
1048
|
-
});
|
|
1049
|
-
applyGeneratedFutureExecutionTitle = (input) =>
|
|
1050
|
-
futureExecutionLifecycle.applyGeneratedFutureLaunchTitleIfUnchanged(input);
|
|
1051
|
-
launchCoordinator = createLaunchCoordinator({
|
|
1052
|
-
events: baseDeps.events,
|
|
1053
|
-
commands: processEngine,
|
|
1054
|
-
launchRuns: baseDeps.launchRuns,
|
|
1055
|
-
processes: baseDeps.processes,
|
|
1056
|
-
leases: baseDeps.leases,
|
|
1057
|
-
turnRecords: baseDeps.turnRecords,
|
|
1058
|
-
turnStarts: baseDeps.turnStarts,
|
|
1059
|
-
titleJobs: baseDeps.titleJobs,
|
|
1060
|
-
launcherService,
|
|
1061
|
-
futureExecutionLifecycle,
|
|
1062
|
-
launchPipeline,
|
|
1063
|
-
launchPlans,
|
|
1064
|
-
createProcessFromLaunchPlan: createProcess,
|
|
1065
|
-
titleGenerationAvailable: Boolean(processTitles),
|
|
1066
|
-
logger: app.log,
|
|
1067
|
-
});
|
|
1068
|
-
startHooks.push(() => launchCoordinator?.reconcileIncomplete());
|
|
1069
|
-
const futureExecutionScheduler = startFutureExecutionScheduler(futureExecutionLifecycle);
|
|
1070
|
-
startHooks.push(() => futureExecutionScheduler.start());
|
|
1071
|
-
stopHooks.push(() => futureExecutionScheduler.stop());
|
|
1072
|
-
const externalSourceService = createExternalSourceService({
|
|
1073
|
-
events: baseDeps.events,
|
|
1074
|
-
processes: baseDeps.processes,
|
|
1075
|
-
projects: baseDeps.projects,
|
|
1076
|
-
pendingExternalSourceFires: baseDeps.pendingExternalSourceFires,
|
|
1077
|
-
commands: processEngine,
|
|
1078
|
-
processActionRegistry,
|
|
1079
|
-
});
|
|
1080
|
-
invalidateExternalSourceArmings = (instanceId) =>
|
|
1081
|
-
externalSourceService.invalidateArmings(instanceId);
|
|
1082
|
-
startHooks.push(() => externalSourceService.reconcileAllArmings());
|
|
1083
|
-
afterSuccessHooks.add(async (instanceId) => {
|
|
1084
|
-
const process = baseDeps.processes.getById(instanceId);
|
|
1085
|
-
if (process) piResourceBundlePins.reconcile(process);
|
|
1086
|
-
await externalSourceService.reconcileArmings(instanceId);
|
|
1087
|
-
await externalSourceService.drainQueued(instanceId);
|
|
1088
|
-
});
|
|
1089
|
-
|
|
1090
|
-
if (!supervisor) throw new Error("worker supervisor not initialized");
|
|
1091
|
-
const deletionPending = new Set<string>();
|
|
1092
|
-
const sessionTransfers = createSessionTransferService({
|
|
1093
|
-
repos: baseDeps,
|
|
1094
|
-
processOperations,
|
|
1095
|
-
supervisor,
|
|
1096
|
-
exporter: runnerRuntime.exporter,
|
|
1097
|
-
helperRelays: sessionTransferHelperRelays,
|
|
1098
|
-
sessionSource: sessionSnapshots,
|
|
1099
|
-
config,
|
|
1100
|
-
limits: sessionTransferLimits,
|
|
1101
|
-
logger: app.log,
|
|
1102
|
-
isDeletionPending: (instanceId) => deletionPending.has(instanceId),
|
|
1103
|
-
onUpdated: (attempt) => {
|
|
1104
|
-
broadcaster.sendDurable(
|
|
1105
|
-
"session_transfer.updated",
|
|
1106
|
-
{ attemptId: attempt.id },
|
|
1107
|
-
attempt.instanceId,
|
|
1108
1043
|
);
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1044
|
+
const processLaunchDeps = {
|
|
1045
|
+
...baseDeps,
|
|
1046
|
+
broadcaster,
|
|
1047
|
+
commands: processEngine,
|
|
1048
|
+
processTitles,
|
|
1049
|
+
extensionHost,
|
|
1050
|
+
logger: app.log,
|
|
1051
|
+
repositoryCredentials,
|
|
1052
|
+
getSupervisor: () => supervisor,
|
|
1053
|
+
assertRuntimeAvailable,
|
|
1054
|
+
};
|
|
1055
|
+
const createProcess = createProcessFromLaunchPlan.bind(null, processLaunchDeps);
|
|
1056
|
+
futureExecutionLifecycle = createFutureExecutionLifecycle({
|
|
1057
|
+
futureExecutions: baseDeps.futureExecutions,
|
|
1058
|
+
processes: baseDeps.processes,
|
|
1059
|
+
projects: baseDeps.projects,
|
|
1060
|
+
processRelations: baseDeps.processRelations,
|
|
1061
|
+
handoffDedupKeys: baseDeps.handoffDedupKeys,
|
|
1062
|
+
turnRecords: baseDeps.turnRecords,
|
|
1063
|
+
skills: baseDeps.skills,
|
|
1064
|
+
processSkills: baseDeps.processSkills,
|
|
1065
|
+
transaction: baseDeps.transaction,
|
|
1066
|
+
broadcaster,
|
|
1067
|
+
commands: processEngine,
|
|
1068
|
+
processOperations,
|
|
1069
|
+
processTitles,
|
|
1070
|
+
extensionHost,
|
|
1071
|
+
launcherService,
|
|
1072
|
+
launcherRecentValues,
|
|
1073
|
+
processGraphs,
|
|
1074
|
+
processActionRegistry: processActionRegistry ?? undefined,
|
|
1075
|
+
processModelPolicy,
|
|
1076
|
+
launchPlans,
|
|
1077
|
+
modelStatusCache,
|
|
1078
|
+
launchPipeline,
|
|
1079
|
+
assertRuntimeAvailable,
|
|
1080
|
+
logger: app.log,
|
|
1081
|
+
});
|
|
1082
|
+
applyGeneratedFutureExecutionTitle = (input) =>
|
|
1083
|
+
futureExecutionLifecycle.applyGeneratedFutureLaunchTitleIfUnchanged(input);
|
|
1084
|
+
launchCoordinator = createLaunchCoordinator({
|
|
1085
|
+
events: baseDeps.events,
|
|
1086
|
+
commands: processEngine,
|
|
1087
|
+
launchRuns: baseDeps.launchRuns,
|
|
1088
|
+
processes: baseDeps.processes,
|
|
1089
|
+
leases: baseDeps.leases,
|
|
1090
|
+
turnRecords: baseDeps.turnRecords,
|
|
1091
|
+
turnStarts: baseDeps.turnStarts,
|
|
1092
|
+
titleJobs: baseDeps.titleJobs,
|
|
1093
|
+
launcherService,
|
|
1094
|
+
futureExecutionLifecycle,
|
|
1095
|
+
launchPipeline,
|
|
1096
|
+
launchPlans,
|
|
1097
|
+
createProcessFromLaunchPlan: createProcess,
|
|
1098
|
+
titleGenerationAvailable: Boolean(processTitles),
|
|
1099
|
+
logger: app.log,
|
|
1100
|
+
});
|
|
1101
|
+
startHooks.push(() => launchCoordinator?.reconcileIncomplete());
|
|
1102
|
+
const futureExecutionScheduler = startFutureExecutionScheduler(futureExecutionLifecycle);
|
|
1103
|
+
startHooks.push(() => futureExecutionScheduler.start());
|
|
1104
|
+
stopHooks.push(() => futureExecutionScheduler.stop());
|
|
1105
|
+
const externalSourceService = createExternalSourceService({
|
|
1106
|
+
events: baseDeps.events,
|
|
1107
|
+
processes: baseDeps.processes,
|
|
1108
|
+
projects: baseDeps.projects,
|
|
1109
|
+
pendingExternalSourceFires: baseDeps.pendingExternalSourceFires,
|
|
1110
|
+
commands: processEngine,
|
|
1111
|
+
processActionRegistry,
|
|
1112
|
+
});
|
|
1113
|
+
invalidateExternalSourceArmings = (instanceId) =>
|
|
1114
|
+
externalSourceService.invalidateArmings(instanceId);
|
|
1115
|
+
startHooks.push(() => externalSourceService.reconcileAllArmings());
|
|
1116
|
+
afterSuccessHooks.add(async (instanceId) => {
|
|
1161
1117
|
const process = baseDeps.processes.getById(instanceId);
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
launcherModelConfigs,
|
|
1167
|
-
launchPlans,
|
|
1168
|
-
processWatcherService,
|
|
1169
|
-
polling,
|
|
1170
|
-
externalSourceService,
|
|
1171
|
-
processModelSelection,
|
|
1172
|
-
resultImages,
|
|
1173
|
-
repositoryCredentials,
|
|
1174
|
-
processQuestions,
|
|
1175
|
-
launchCoordinator,
|
|
1176
|
-
preProvidedCapabilities: opts.preProvidedCapabilities,
|
|
1177
|
-
});
|
|
1118
|
+
if (process) piResourceBundlePins.reconcile(process);
|
|
1119
|
+
await externalSourceService.reconcileArmings(instanceId);
|
|
1120
|
+
await externalSourceService.drainQueued(instanceId);
|
|
1121
|
+
});
|
|
1178
1122
|
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
{
|
|
1182
|
-
|
|
1123
|
+
if (!supervisor) throw new Error("worker supervisor not initialized");
|
|
1124
|
+
const deletionPending = new Set<string>();
|
|
1125
|
+
const sessionTransfers = createSessionTransferService({
|
|
1126
|
+
repos: baseDeps,
|
|
1127
|
+
processOperations,
|
|
1128
|
+
supervisor,
|
|
1129
|
+
exporter: runnerRuntime.exporter,
|
|
1130
|
+
helperRelays: sessionTransferHelperRelays,
|
|
1131
|
+
sessionSource: sessionSnapshots,
|
|
1132
|
+
config,
|
|
1133
|
+
limits: sessionTransferLimits,
|
|
1183
1134
|
logger: app.log,
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1135
|
+
isDeletionPending: (instanceId) => deletionPending.has(instanceId),
|
|
1136
|
+
onUpdated: (attempt) => {
|
|
1137
|
+
broadcaster.sendDurable(
|
|
1138
|
+
"session_transfer.updated",
|
|
1139
|
+
{ attemptId: attempt.id },
|
|
1140
|
+
attempt.instanceId,
|
|
1141
|
+
);
|
|
1190
1142
|
},
|
|
1191
|
-
|
|
1192
|
-
|
|
1143
|
+
});
|
|
1144
|
+
isNewTurnBlocked = (instanceId) => {
|
|
1145
|
+
const attempt = sessionTransfers.activeForProcess(instanceId);
|
|
1146
|
+
return attempt?.state === "queued" || attempt?.state === "exporting";
|
|
1147
|
+
};
|
|
1148
|
+
startHooks.push(async () => {
|
|
1149
|
+
await sessionTransfers.reconcile();
|
|
1150
|
+
sessionTransfers.start();
|
|
1151
|
+
});
|
|
1152
|
+
stopHooks.push(() => sessionTransfers.stop());
|
|
1153
|
+
const processDeletion = createProcessDeletionService({
|
|
1154
|
+
processes: baseDeps.processes,
|
|
1155
|
+
processEngine,
|
|
1156
|
+
processOperations,
|
|
1157
|
+
supervisor,
|
|
1158
|
+
volume: runnerRuntime.volume,
|
|
1159
|
+
sessionSnapshots,
|
|
1160
|
+
resultImages,
|
|
1161
|
+
sessionTransfers,
|
|
1162
|
+
deletionPending,
|
|
1163
|
+
broadcaster,
|
|
1164
|
+
logger: app.log,
|
|
1165
|
+
});
|
|
1166
|
+
|
|
1167
|
+
const processActionListDeps = {
|
|
1168
|
+
projects: baseDeps.projects,
|
|
1169
|
+
futureExecutions: baseDeps.futureExecutions,
|
|
1170
|
+
turnRecords: baseDeps.turnRecords,
|
|
1171
|
+
turnStarts: baseDeps.turnStarts,
|
|
1172
|
+
processGraphs,
|
|
1173
|
+
processActionRegistry,
|
|
1174
|
+
};
|
|
1175
|
+
const processModelSelection = createProcessModelSelection({
|
|
1176
|
+
processGraphs,
|
|
1177
|
+
processActionRegistry,
|
|
1178
|
+
processes: baseDeps.processes,
|
|
1179
|
+
projects: baseDeps.projects,
|
|
1180
|
+
scheduledActions: baseDeps.futureExecutions,
|
|
1181
|
+
turnRecords: baseDeps.turnRecords,
|
|
1182
|
+
turnStarts: baseDeps.turnStarts,
|
|
1183
|
+
instanceTrees: sessionReader,
|
|
1184
|
+
processModelPolicy,
|
|
1185
|
+
modelStatusCache,
|
|
1186
|
+
});
|
|
1187
|
+
const hostCapabilities = buildHostCapabilities({
|
|
1188
|
+
config,
|
|
1189
|
+
baseDeps,
|
|
1190
|
+
projectMutations,
|
|
1191
|
+
commands: processEngine,
|
|
1192
|
+
getSupervisor: () => supervisor,
|
|
1193
|
+
listVisibleActionsForProcess(instanceId: string) {
|
|
1194
|
+
const process = baseDeps.processes.getById(instanceId);
|
|
1195
|
+
return process ? listVisibleOperatorActionsForProcess(processActionListDeps, process) : [];
|
|
1193
1196
|
},
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1197
|
+
launcherService,
|
|
1198
|
+
launcherRecentValues,
|
|
1199
|
+
launcherModelConfigs,
|
|
1200
|
+
launchPlans,
|
|
1201
|
+
processWatcherService,
|
|
1202
|
+
polling,
|
|
1203
|
+
externalSourceService,
|
|
1204
|
+
processModelSelection,
|
|
1205
|
+
resultImages,
|
|
1206
|
+
repositoryCredentials,
|
|
1207
|
+
processQuestions,
|
|
1208
|
+
launchCoordinator,
|
|
1209
|
+
preProvidedCapabilities: opts.preProvidedCapabilities,
|
|
1210
|
+
});
|
|
1211
|
+
|
|
1212
|
+
await setupServerExtensions(
|
|
1213
|
+
extensionCatalog,
|
|
1214
|
+
{
|
|
1215
|
+
events: extensionHost,
|
|
1216
|
+
logger: app.log,
|
|
1217
|
+
provide: hostCapabilities.provide.bind(hostCapabilities),
|
|
1218
|
+
get: hostCapabilities.get.bind(hostCapabilities),
|
|
1219
|
+
require: hostCapabilities.require.bind(hostCapabilities),
|
|
1220
|
+
tool: (definition) => integrationTools.register(definition),
|
|
1221
|
+
onStart(handler: () => void | Promise<void>) {
|
|
1222
|
+
startHooks.push(handler);
|
|
1223
|
+
},
|
|
1224
|
+
onStop(handler: () => void | Promise<void>) {
|
|
1225
|
+
stopHooks.push(handler);
|
|
1226
|
+
},
|
|
1227
|
+
},
|
|
1228
|
+
(id: string) => config.extensions?.[id],
|
|
1229
|
+
);
|
|
1230
|
+
integrationTools.validateTicketProcesses(extensionCatalog.processes);
|
|
1231
|
+
startHooks.push(() => polling.start());
|
|
1232
|
+
stopHooks.push(() => polling.stop());
|
|
1233
|
+
for (const process of extensionCatalog.processes.values()) {
|
|
1234
|
+
for (const [turnId, binding] of process.turns) {
|
|
1235
|
+
const definition = binding.definition;
|
|
1236
|
+
if (definition.kind !== "llm" || !definition.integrationTools?.length) continue;
|
|
1237
|
+
try {
|
|
1238
|
+
integrationTools.declarations(definition.integrationTools);
|
|
1239
|
+
} catch (error) {
|
|
1240
|
+
throw new Error(
|
|
1241
|
+
`Invalid integration tools for process '${process.id}' turn '${turnId}': ${error instanceof Error ? error.message : String(error)}`,
|
|
1242
|
+
);
|
|
1243
|
+
}
|
|
1210
1244
|
}
|
|
1211
1245
|
}
|
|
1212
|
-
|
|
1213
|
-
markStartup("server_extensions");
|
|
1214
|
-
|
|
1215
|
-
const deps: RouteDeps = {
|
|
1216
|
-
externalSourceService,
|
|
1217
|
-
...baseDeps,
|
|
1218
|
-
launchCoordinator,
|
|
1219
|
-
processGraphs,
|
|
1220
|
-
supervisor,
|
|
1221
|
-
processEngine,
|
|
1222
|
-
processQuestions,
|
|
1223
|
-
toolApprovalGate,
|
|
1224
|
-
processDeletion,
|
|
1225
|
-
processActionRegistry,
|
|
1226
|
-
processUiRegistry,
|
|
1227
|
-
extensionHost,
|
|
1228
|
-
launcherService,
|
|
1229
|
-
launcherRecentValues,
|
|
1230
|
-
launchPlans,
|
|
1231
|
-
processTitles,
|
|
1232
|
-
toolRenderers: extensionCatalog.toolRenderers,
|
|
1233
|
-
config,
|
|
1234
|
-
sessionReader,
|
|
1235
|
-
futureExecutionLifecycle,
|
|
1236
|
-
modelProviderRegistry,
|
|
1237
|
-
modelProviderCredentialStatus: modelProviderCredentials.status,
|
|
1238
|
-
modelStatusCache,
|
|
1239
|
-
processModelPolicy,
|
|
1240
|
-
processModelSelection,
|
|
1241
|
-
skillCatalog,
|
|
1242
|
-
sessionTransferService: sessionTransfers,
|
|
1243
|
-
};
|
|
1244
|
-
|
|
1245
|
-
registerHttp({
|
|
1246
|
-
app,
|
|
1247
|
-
isReady: () => backgroundServicesReady,
|
|
1248
|
-
deps,
|
|
1249
|
-
authService,
|
|
1250
|
-
processWatcherService,
|
|
1251
|
-
extensionUiCatalog,
|
|
1252
|
-
integrationTools,
|
|
1253
|
-
sessionSnapshots,
|
|
1254
|
-
resultImages,
|
|
1255
|
-
maxSessionSnapshotBytes: config.workers.session_snapshot_max_size_bytes,
|
|
1256
|
-
extensionUiAssetCacheControl:
|
|
1257
|
-
process.env.LEITWERK_RUNTIME_LANE === "source" ? "no-store" : undefined,
|
|
1258
|
-
});
|
|
1259
|
-
markStartup("routes_ready");
|
|
1246
|
+
markStartup("server_extensions");
|
|
1260
1247
|
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1248
|
+
const deps: RouteDeps = {
|
|
1249
|
+
externalSourceService,
|
|
1250
|
+
...baseDeps,
|
|
1251
|
+
launchCoordinator,
|
|
1252
|
+
processGraphs,
|
|
1253
|
+
supervisor,
|
|
1254
|
+
processEngine,
|
|
1255
|
+
processQuestions,
|
|
1256
|
+
toolApprovalGate,
|
|
1257
|
+
processDeletion,
|
|
1258
|
+
processActionRegistry,
|
|
1259
|
+
processUiRegistry,
|
|
1260
|
+
extensionHost,
|
|
1261
|
+
launcherService,
|
|
1262
|
+
launcherRecentValues,
|
|
1263
|
+
launchPlans,
|
|
1264
|
+
processTitles,
|
|
1265
|
+
toolRenderers: extensionCatalog.toolRenderers,
|
|
1266
|
+
config,
|
|
1267
|
+
sessionReader,
|
|
1268
|
+
futureExecutionLifecycle,
|
|
1269
|
+
modelProviderRegistry,
|
|
1270
|
+
modelProviderCredentialStatus: modelProviderCredentials.status,
|
|
1271
|
+
modelStatusCache,
|
|
1272
|
+
processModelPolicy,
|
|
1273
|
+
processModelSelection,
|
|
1274
|
+
skillCatalog,
|
|
1275
|
+
sessionTransferService: sessionTransfers,
|
|
1276
|
+
};
|
|
1276
1277
|
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1278
|
+
registerHttp({
|
|
1279
|
+
app,
|
|
1280
|
+
isReady: () => lifecycle.isReady(),
|
|
1281
|
+
deps,
|
|
1282
|
+
authService,
|
|
1283
|
+
processWatcherService,
|
|
1284
|
+
extensionUiCatalog,
|
|
1285
|
+
integrationTools,
|
|
1286
|
+
sessionSnapshots,
|
|
1287
|
+
resultImages,
|
|
1288
|
+
maxSessionSnapshotBytes: config.workers.session_snapshot_max_size_bytes,
|
|
1289
|
+
extensionUiAssetCacheControl:
|
|
1290
|
+
process.env.LEITWERK_RUNTIME_LANE === "source" ? "no-store" : undefined,
|
|
1291
|
+
});
|
|
1292
|
+
markStartup("routes_ready");
|
|
1281
1293
|
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1294
|
+
const lifecycle = createAppLifecycle({
|
|
1295
|
+
app,
|
|
1296
|
+
server: config.server,
|
|
1297
|
+
authEnabled: authService.config.enabled,
|
|
1298
|
+
reconcile: reconcileStartup,
|
|
1299
|
+
startHooks,
|
|
1300
|
+
preCloseCleanup,
|
|
1301
|
+
closeDatabase: () => closeOwnedDatabase?.(),
|
|
1302
|
+
});
|
|
1303
|
+
finishCleanup = lifecycle.finishCleanup;
|
|
1292
1304
|
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
}
|
|
1305
|
+
return {
|
|
1306
|
+
app,
|
|
1307
|
+
db,
|
|
1308
|
+
broadcaster,
|
|
1309
|
+
config,
|
|
1310
|
+
deps,
|
|
1311
|
+
modelProviderRegistry,
|
|
1312
|
+
modelProviderServerAdapters,
|
|
1313
|
+
modelStatusCache,
|
|
1314
|
+
extensionUiCatalog,
|
|
1315
|
+
processGraphs,
|
|
1316
|
+
extensionHost,
|
|
1317
|
+
projectMutations,
|
|
1318
|
+
ipcHandler,
|
|
1319
|
+
supervisor,
|
|
1320
|
+
listen: lifecycle.listen,
|
|
1321
|
+
close: lifecycle.close,
|
|
1322
|
+
isReady: lifecycle.isReady,
|
|
1323
|
+
};
|
|
1324
|
+
} catch (error) {
|
|
1325
|
+
const errors = [
|
|
1326
|
+
error,
|
|
1327
|
+
...(await collectCleanupErrors([
|
|
1328
|
+
() => app.close(),
|
|
1329
|
+
() => closeOwnedDatabase?.(),
|
|
1330
|
+
...preCloseCleanup,
|
|
1331
|
+
])),
|
|
1332
|
+
];
|
|
1333
|
+
if (errors.length > 1)
|
|
1334
|
+
throw new AggregateError(errors, "Context construction and cleanup failed", { cause: error });
|
|
1335
|
+
throw error;
|
|
1336
|
+
}
|
|
1313
1337
|
}
|