@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
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
SAFE_SKILL_ID_PATTERN,
|
|
8
8
|
SKILL_RESOURCE_OWNER,
|
|
9
9
|
actorForRequest,
|
|
10
|
+
appendProcessEvent,
|
|
11
|
+
applyProcessPatchField,
|
|
10
12
|
applySubmittedProcessTitleToLaunchPlan,
|
|
11
13
|
authenticateBrowserRequest,
|
|
12
14
|
authenticateRequest,
|
|
@@ -15,13 +17,12 @@ import {
|
|
|
15
17
|
buildFutureExecutionSummaries,
|
|
16
18
|
buildLauncherModelConfigSchema,
|
|
17
19
|
buildPrimaryPathSnapshotFromTree,
|
|
18
|
-
buildProcessActionRegistry,
|
|
19
20
|
buildProcessFlowViewForProcess,
|
|
20
21
|
buildProcessLaunchConfigurationView,
|
|
21
22
|
buildProcessRunDetailsView,
|
|
23
|
+
buildRuntimeProfileSelectionInput,
|
|
22
24
|
buildStartupEvidence,
|
|
23
25
|
closeDatabase,
|
|
24
|
-
compareResourcePaths,
|
|
25
26
|
completeCommittedLaunch,
|
|
26
27
|
createAllRepos,
|
|
27
28
|
createBroadcaster,
|
|
@@ -31,11 +32,15 @@ import {
|
|
|
31
32
|
createInMemoryDatabase,
|
|
32
33
|
createLaunchPipeline,
|
|
33
34
|
createOpaqueToken,
|
|
35
|
+
createPiResourceBundleCache,
|
|
36
|
+
createPiResourceBundlePinReconciler,
|
|
34
37
|
createProcessOperationCoordinator,
|
|
35
38
|
createProjectedSessionSnapshotStore,
|
|
36
39
|
createServerProcessModelPolicy,
|
|
37
40
|
createSessionTransferService,
|
|
38
41
|
createWorkerStorageLayout,
|
|
42
|
+
createWrites,
|
|
43
|
+
defaultWorkerRuntimeProfile,
|
|
39
44
|
evaluateAtStableAvailabilityRevision,
|
|
40
45
|
failLaunchRun,
|
|
41
46
|
finishLaunchRun,
|
|
@@ -57,11 +62,14 @@ import {
|
|
|
57
62
|
isLoopbackHttpUrl,
|
|
58
63
|
isSafeSessionInstanceId,
|
|
59
64
|
isTurnAvailableForProcessGraph,
|
|
65
|
+
isWriteBuildFailure,
|
|
60
66
|
isoFromNow,
|
|
61
67
|
listVisibleActionsForProcess,
|
|
62
68
|
listVisibleActionsForProcess2,
|
|
69
|
+
loadProviderOptionChoices,
|
|
63
70
|
logProcessEngineError,
|
|
64
71
|
mergeProcessEventWindowsAscending,
|
|
72
|
+
mergeWrites,
|
|
65
73
|
normalizeActionRequest,
|
|
66
74
|
normalizeContinueRequest,
|
|
67
75
|
normalizeExternalEventDescription,
|
|
@@ -70,6 +78,8 @@ import {
|
|
|
70
78
|
normalizeProcessTitleInput,
|
|
71
79
|
normalizeRecoveryModelRequest,
|
|
72
80
|
now,
|
|
81
|
+
positiveBound,
|
|
82
|
+
prepareCreatedTurnStarts,
|
|
73
83
|
presentLaunchPlanPreparationIssues,
|
|
74
84
|
presentLauncherModelConfigPreview,
|
|
75
85
|
presentLauncherModelConfigSchema,
|
|
@@ -88,24 +98,30 @@ import {
|
|
|
88
98
|
resolveCurrentExecutionTurnRecordId,
|
|
89
99
|
resolveDockerRegistryCredentials,
|
|
90
100
|
resolveProcessStorageSize,
|
|
91
|
-
|
|
101
|
+
resolveRegisteredProviderOptions,
|
|
92
102
|
resolveWorkerPiAgentDir,
|
|
93
103
|
routeConfig,
|
|
104
|
+
selectWorkerRuntimeProfile,
|
|
94
105
|
sendActionRequestNormalizationError,
|
|
95
106
|
sendLauncherLookupFailure,
|
|
96
107
|
sendLauncherMutationResponse,
|
|
97
108
|
sendLauncherRequestNormalizationError,
|
|
98
109
|
sendScheduledActionMutationResponse,
|
|
99
110
|
serializeProcessGraph,
|
|
111
|
+
stampActorOnEvents,
|
|
112
|
+
stampActorOnQueuedInputs,
|
|
100
113
|
tokenExpiry,
|
|
101
114
|
truncateTextAtWordBoundary,
|
|
115
|
+
updateProcessMetadata,
|
|
102
116
|
validateConfig,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
117
|
+
validateConfiguredProviderOptions,
|
|
118
|
+
validateCredentialStatus,
|
|
119
|
+
verifyOpaqueToken,
|
|
120
|
+
withTimeout
|
|
121
|
+
} from "./chunk-KIOQNNG6.js";
|
|
106
122
|
|
|
107
123
|
// src/app.ts
|
|
108
|
-
import
|
|
124
|
+
import path8 from "node:path";
|
|
109
125
|
import cookie from "@fastify/cookie";
|
|
110
126
|
import {
|
|
111
127
|
serializeResolvedExtensionEntries,
|
|
@@ -935,136 +951,6 @@ import {
|
|
|
935
951
|
isHumanTurnDefinition
|
|
936
952
|
} from "@leitwerk-dev/process-sdk";
|
|
937
953
|
|
|
938
|
-
// src/process-engine/writes/writes.ts
|
|
939
|
-
import {
|
|
940
|
-
CONTINUE_PROMPT_METADATA_KEY,
|
|
941
|
-
FAILED_TURN_RECOVERY_METADATA_KEY,
|
|
942
|
-
SYSTEM_ACTOR
|
|
943
|
-
} from "@leitwerk-dev/domain";
|
|
944
|
-
var METADATA_KEY_GROUPS = {
|
|
945
|
-
retry: ["retryForkPiEntryId", "retryFromTurnRecordId"],
|
|
946
|
-
continuation: [
|
|
947
|
-
"continueFromPiEntryId",
|
|
948
|
-
"continueFromTurnRecordId",
|
|
949
|
-
"continueSavedPrimaryLeafEntryId",
|
|
950
|
-
CONTINUE_PROMPT_METADATA_KEY,
|
|
951
|
-
FAILED_TURN_RECOVERY_METADATA_KEY
|
|
952
|
-
]
|
|
953
|
-
};
|
|
954
|
-
function createWrites(init = {}) {
|
|
955
|
-
return {
|
|
956
|
-
processPatch: init.processPatch ?? {},
|
|
957
|
-
changedFields: [...init.changedFields ?? []],
|
|
958
|
-
...init.projectWrite ? { projectWrite: init.projectWrite } : {},
|
|
959
|
-
turnRecordWrites: [...init.turnRecordWrites ?? []],
|
|
960
|
-
turnStartWrites: [...init.turnStartWrites ?? []],
|
|
961
|
-
turnAnnotationWrites: [...init.turnAnnotationWrites ?? []],
|
|
962
|
-
leafOutcomeSnapshotWrites: [...init.leafOutcomeSnapshotWrites ?? []],
|
|
963
|
-
events: [...init.events ?? []],
|
|
964
|
-
broadcasts: [...init.broadcasts ?? []],
|
|
965
|
-
queuedInputs: [...init.queuedInputs ?? []],
|
|
966
|
-
extensionEvents: [...init.extensionEvents ?? []],
|
|
967
|
-
futureExecutionPlans: [...init.futureExecutionPlans ?? []],
|
|
968
|
-
pendingExternalSourceFireWrites: [...init.pendingExternalSourceFireWrites ?? []],
|
|
969
|
-
...init.workerIntent ? { workerIntent: init.workerIntent } : {}
|
|
970
|
-
};
|
|
971
|
-
}
|
|
972
|
-
function mergeWrites(...writesList) {
|
|
973
|
-
const merged = createWrites();
|
|
974
|
-
for (const writes of writesList) {
|
|
975
|
-
if (!writes) continue;
|
|
976
|
-
Object.assign(merged.processPatch, writes.processPatch);
|
|
977
|
-
for (const field of writes.changedFields) {
|
|
978
|
-
if (!merged.changedFields.includes(field)) {
|
|
979
|
-
merged.changedFields.push(field);
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
if (writes.projectWrite) {
|
|
983
|
-
if (merged.projectWrite) throw new Error("Cannot merge multiple process-project writes");
|
|
984
|
-
merged.projectWrite = writes.projectWrite;
|
|
985
|
-
}
|
|
986
|
-
merged.turnRecordWrites.push(...writes.turnRecordWrites);
|
|
987
|
-
merged.turnStartWrites.push(...writes.turnStartWrites);
|
|
988
|
-
merged.turnAnnotationWrites.push(...writes.turnAnnotationWrites);
|
|
989
|
-
merged.leafOutcomeSnapshotWrites.push(...writes.leafOutcomeSnapshotWrites);
|
|
990
|
-
merged.events.push(...writes.events);
|
|
991
|
-
merged.broadcasts.push(...writes.broadcasts);
|
|
992
|
-
merged.queuedInputs.push(...writes.queuedInputs);
|
|
993
|
-
merged.extensionEvents.push(...writes.extensionEvents);
|
|
994
|
-
merged.futureExecutionPlans.push(...writes.futureExecutionPlans);
|
|
995
|
-
merged.pendingExternalSourceFireWrites.push(...writes.pendingExternalSourceFireWrites);
|
|
996
|
-
if (writes.workerIntent) {
|
|
997
|
-
merged.workerIntent = writes.workerIntent;
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
return merged;
|
|
1001
|
-
}
|
|
1002
|
-
function isWriteBuildFailure(value) {
|
|
1003
|
-
return typeof value === "object" && value !== null && "ok" in value && value.ok === false;
|
|
1004
|
-
}
|
|
1005
|
-
function applyProcessPatchField(writes, process2, field, value) {
|
|
1006
|
-
if (process2[field] === value) {
|
|
1007
|
-
return;
|
|
1008
|
-
}
|
|
1009
|
-
writes.processPatch[field] = value;
|
|
1010
|
-
if (!writes.changedFields.includes(field)) {
|
|
1011
|
-
writes.changedFields.push(field);
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
function applyMetadataPatch(writes, process2, nextMetadata) {
|
|
1015
|
-
if (JSON.stringify(process2.metadata ?? null) === JSON.stringify(nextMetadata)) {
|
|
1016
|
-
return;
|
|
1017
|
-
}
|
|
1018
|
-
writes.processPatch.metadata = nextMetadata;
|
|
1019
|
-
if (!writes.changedFields.includes("metadata")) {
|
|
1020
|
-
writes.changedFields.push("metadata");
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
function updateProcessMetadata(writes, process2, clearGroups = [], update = () => {
|
|
1024
|
-
}) {
|
|
1025
|
-
const nextMetadata = process2.metadata ? { ...process2.metadata } : {};
|
|
1026
|
-
for (const group of clearGroups) {
|
|
1027
|
-
for (const key of METADATA_KEY_GROUPS[group]) delete nextMetadata[key];
|
|
1028
|
-
}
|
|
1029
|
-
update(nextMetadata);
|
|
1030
|
-
applyMetadataPatch(writes, process2, Object.keys(nextMetadata).length > 0 ? nextMetadata : null);
|
|
1031
|
-
}
|
|
1032
|
-
function appendProcessEvent(writes, process2, input) {
|
|
1033
|
-
writes.events.push({
|
|
1034
|
-
instanceId: process2.id,
|
|
1035
|
-
eventType: input.eventType,
|
|
1036
|
-
...input.data ? { data: input.data } : {}
|
|
1037
|
-
});
|
|
1038
|
-
writes.broadcasts.push({
|
|
1039
|
-
type: "process.event",
|
|
1040
|
-
payload: {
|
|
1041
|
-
eventType: input.eventType,
|
|
1042
|
-
level: input.level,
|
|
1043
|
-
message: input.message
|
|
1044
|
-
},
|
|
1045
|
-
instanceId: process2.id
|
|
1046
|
-
});
|
|
1047
|
-
}
|
|
1048
|
-
function stampActorOnEvents(writes, actor, eventType) {
|
|
1049
|
-
const resolvedActor = actor ?? SYSTEM_ACTOR;
|
|
1050
|
-
let stamped = 0;
|
|
1051
|
-
for (const event of writes.events) {
|
|
1052
|
-
if (event.eventType === eventType) {
|
|
1053
|
-
event.data = { ...event.data ?? {}, actor: resolvedActor };
|
|
1054
|
-
stamped += 1;
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
return stamped;
|
|
1058
|
-
}
|
|
1059
|
-
function stampActorOnQueuedInputs(writes, actor) {
|
|
1060
|
-
if (!actor) {
|
|
1061
|
-
return;
|
|
1062
|
-
}
|
|
1063
|
-
writes.queuedInputs = writes.queuedInputs.map(
|
|
1064
|
-
(queuedInput) => queuedInput.actor ? queuedInput : { ...queuedInput, actor }
|
|
1065
|
-
);
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
954
|
// src/process-engine/decision.ts
|
|
1069
955
|
function accept(input = {}) {
|
|
1070
956
|
return {
|
|
@@ -2048,7 +1934,7 @@ function createExternalSourceService(deps) {
|
|
|
2048
1934
|
`External source '${input.armingId}' is stale for selected turn '${String(ctx.process.selectedTurnId)}'`
|
|
2049
1935
|
);
|
|
2050
1936
|
}
|
|
2051
|
-
const failedDecision = (
|
|
1937
|
+
const failedDecision = (failure) => {
|
|
2052
1938
|
const writes = createWrites();
|
|
2053
1939
|
appendExternalSourceEvent(
|
|
2054
1940
|
writes,
|
|
@@ -2058,11 +1944,11 @@ function createExternalSourceService(deps) {
|
|
|
2058
1944
|
...armingEventData(arming),
|
|
2059
1945
|
provider: input.event,
|
|
2060
1946
|
fireInput: input.input,
|
|
2061
|
-
code:
|
|
2062
|
-
message:
|
|
1947
|
+
code: failure.code,
|
|
1948
|
+
message: failure.message
|
|
2063
1949
|
})
|
|
2064
1950
|
);
|
|
2065
|
-
return accept({ writes, data: { ok: false, code:
|
|
1951
|
+
return accept({ writes, data: { ok: false, code: failure.code } });
|
|
2066
1952
|
};
|
|
2067
1953
|
const effectWrites = await buildExternalSourceEffectWrites({
|
|
2068
1954
|
arming,
|
|
@@ -2576,7 +2462,7 @@ function createExternalSourceService(deps) {
|
|
|
2576
2462
|
|
|
2577
2463
|
// src/future-execution/lifecycle.ts
|
|
2578
2464
|
import {
|
|
2579
|
-
SYSTEM_ACTOR as
|
|
2465
|
+
SYSTEM_ACTOR as SYSTEM_ACTOR2
|
|
2580
2466
|
} from "@leitwerk-dev/domain";
|
|
2581
2467
|
import {
|
|
2582
2468
|
parseFutureActionPayloadJson as parseFutureActionPayloadJson3,
|
|
@@ -2920,7 +2806,7 @@ async function planProcessAction(input) {
|
|
|
2920
2806
|
if ("ok" in planned) {
|
|
2921
2807
|
return planned;
|
|
2922
2808
|
}
|
|
2923
|
-
const
|
|
2809
|
+
const candidateProcess = {
|
|
2924
2810
|
...input.process,
|
|
2925
2811
|
...planned.processPatch
|
|
2926
2812
|
};
|
|
@@ -2932,7 +2818,7 @@ async function planProcessAction(input) {
|
|
|
2932
2818
|
visibleAction: visibleAction ?? null,
|
|
2933
2819
|
resolvedTurnAction,
|
|
2934
2820
|
writes: planned,
|
|
2935
|
-
candidateProcess
|
|
2821
|
+
candidateProcess,
|
|
2936
2822
|
candidateSelectedTurnId
|
|
2937
2823
|
};
|
|
2938
2824
|
}
|
|
@@ -3650,15 +3536,15 @@ function recoverDeduplicatedCommit(deps, dedupKey, futureExecutionPlan) {
|
|
|
3650
3536
|
return deps.transaction((repos) => reuseDeduplicatedCommit(repos, dedupKey, futureExecutionPlan));
|
|
3651
3537
|
}
|
|
3652
3538
|
function launchStartFailure(commit, result) {
|
|
3653
|
-
const
|
|
3539
|
+
const failure = mapLaunchStartFailure(result);
|
|
3654
3540
|
const process2 = result.process ?? commit.process;
|
|
3655
3541
|
return {
|
|
3656
3542
|
ok: false,
|
|
3657
3543
|
stage: "post_commit",
|
|
3658
|
-
status:
|
|
3544
|
+
status: failure.status,
|
|
3659
3545
|
body: {
|
|
3660
|
-
...
|
|
3661
|
-
process:
|
|
3546
|
+
...failure.body,
|
|
3547
|
+
process: failure.body.process ?? process2,
|
|
3662
3548
|
projects: commit.projects
|
|
3663
3549
|
},
|
|
3664
3550
|
process: process2,
|
|
@@ -3774,12 +3660,12 @@ async function createProcessFromLaunchPlanWithDisposition(deps, launchPlan, opts
|
|
|
3774
3660
|
reused: commit.dedupReused === true
|
|
3775
3661
|
} : launchStartFailure(commit, started);
|
|
3776
3662
|
} catch (error) {
|
|
3777
|
-
const
|
|
3663
|
+
const failure = toLaunchFailureBody(error, {
|
|
3778
3664
|
createdProcess: commit.process,
|
|
3779
3665
|
projects: commit.projects
|
|
3780
3666
|
});
|
|
3781
3667
|
return {
|
|
3782
|
-
...
|
|
3668
|
+
...failure,
|
|
3783
3669
|
stage: "post_commit",
|
|
3784
3670
|
process: commit.process,
|
|
3785
3671
|
projects: commit.projects
|
|
@@ -4333,7 +4219,7 @@ function createFutureExecutionExecutor(deps) {
|
|
|
4333
4219
|
// src/future-execution/launch-lifecycle.ts
|
|
4334
4220
|
import {
|
|
4335
4221
|
normalizeLaunchModelConfigInput,
|
|
4336
|
-
SYSTEM_ACTOR
|
|
4222
|
+
SYSTEM_ACTOR
|
|
4337
4223
|
} from "@leitwerk-dev/domain";
|
|
4338
4224
|
import {
|
|
4339
4225
|
parseFutureLaunchPayloadJson as parseFutureLaunchPayloadJson3,
|
|
@@ -4548,29 +4434,29 @@ function createFutureLaunchLifecycle(deps, options = {}) {
|
|
|
4548
4434
|
const opened = deps.launchPipeline.open({ launcherId: existing.launcherId, origin: "ui" });
|
|
4549
4435
|
const result = await deps.launchPipeline.run(opened.launchRunId, {
|
|
4550
4436
|
async resolve() {
|
|
4551
|
-
const
|
|
4437
|
+
const failure = (value) => ({
|
|
4552
4438
|
kind: "failed",
|
|
4553
4439
|
failure: { safeSummary: "Review the launch configuration and try again.", value }
|
|
4554
4440
|
});
|
|
4555
4441
|
if (!deps.launcherService)
|
|
4556
|
-
return
|
|
4442
|
+
return failure({ kind: "unavailable", reason: "Launcher service is not available" });
|
|
4557
4443
|
const parsed = parseFutureLaunchPayloadJson3(existing.payloadJson);
|
|
4558
4444
|
if (!parsed.ok)
|
|
4559
|
-
return
|
|
4445
|
+
return failure(invalidOutcome("invalid_payload", "Scheduled launch payload is invalid"));
|
|
4560
4446
|
const launchRequest = resolveScheduledLaunchUpdateRequest(existing, request, parsed.value);
|
|
4561
|
-
if (!launchRequest.ok) return
|
|
4447
|
+
if (!launchRequest.ok) return failure({ kind: "invalid", issues: [launchRequest.issue] });
|
|
4562
4448
|
const resolved = await deps.launcherService.resolveUiLauncher(
|
|
4563
4449
|
existing.launcherId ?? parsed.value.launchPlan.launcherId,
|
|
4564
4450
|
launchRequest.value.launcherInput
|
|
4565
4451
|
);
|
|
4566
|
-
if (!resolved.ok) return
|
|
4452
|
+
if (!resolved.ok) return failure(launcherResolutionFailure(resolved));
|
|
4567
4453
|
return {
|
|
4568
4454
|
kind: "resolved",
|
|
4569
4455
|
value: {
|
|
4570
4456
|
payload: parsed.value,
|
|
4571
4457
|
request: launchRequest.value,
|
|
4572
4458
|
launcher: resolved.launcher,
|
|
4573
|
-
actor: actor ?? launchRequest.value.actor ??
|
|
4459
|
+
actor: actor ?? launchRequest.value.actor ?? SYSTEM_ACTOR
|
|
4574
4460
|
}
|
|
4575
4461
|
};
|
|
4576
4462
|
},
|
|
@@ -4667,6 +4553,7 @@ function createFutureLaunchLifecycle(deps, options = {}) {
|
|
|
4667
4553
|
return result.result;
|
|
4668
4554
|
}
|
|
4669
4555
|
return {
|
|
4556
|
+
/** @internal */
|
|
4670
4557
|
async prepareLaunch(launcherId, request, opts) {
|
|
4671
4558
|
return prepareLaunchInternal({
|
|
4672
4559
|
launcherId,
|
|
@@ -4674,9 +4561,10 @@ function createFutureLaunchLifecycle(deps, options = {}) {
|
|
|
4674
4561
|
...opts?.resolvedLauncher ? { resolvedLauncher: opts.resolvedLauncher } : {}
|
|
4675
4562
|
});
|
|
4676
4563
|
},
|
|
4564
|
+
/** @internal */
|
|
4677
4565
|
async commitPreparedLaunch(prepared, opts) {
|
|
4678
4566
|
if (prepared.schedule.mode !== "now")
|
|
4679
|
-
return persistPreparedLaunch({ ...prepared, actor: opts?.actor ??
|
|
4567
|
+
return persistPreparedLaunch({ ...prepared, actor: opts?.actor ?? SYSTEM_ACTOR });
|
|
4680
4568
|
const created = await createProcessFromLaunchPlan(deps, prepared.launchPlan, {
|
|
4681
4569
|
...opts,
|
|
4682
4570
|
resourceSelections: prepared.resourceSelections,
|
|
@@ -4691,6 +4579,7 @@ function createFutureLaunchLifecycle(deps, options = {}) {
|
|
|
4691
4579
|
operation: "created"
|
|
4692
4580
|
};
|
|
4693
4581
|
},
|
|
4582
|
+
/** @internal */
|
|
4694
4583
|
async applyGeneratedFutureLaunchTitleIfUnchanged(input) {
|
|
4695
4584
|
return runFutureExecutionExclusive(
|
|
4696
4585
|
deps.processOperations,
|
|
@@ -4732,6 +4621,7 @@ function createFutureLaunchLifecycle(deps, options = {}) {
|
|
|
4732
4621
|
}
|
|
4733
4622
|
);
|
|
4734
4623
|
},
|
|
4624
|
+
/** @internal */
|
|
4735
4625
|
async reviseScheduledLaunch(futureExecutionId, request, opts) {
|
|
4736
4626
|
const operationTime = now2();
|
|
4737
4627
|
return runFutureExecutionExclusive(deps.processOperations, futureExecutionId, async () => {
|
|
@@ -4755,7 +4645,7 @@ function createFutureLaunchLifecycle(deps, options = {}) {
|
|
|
4755
4645
|
return persistPreparedLaunch({
|
|
4756
4646
|
...prepared.prepared,
|
|
4757
4647
|
existing,
|
|
4758
|
-
actor: opts?.actor ?? launchRequest.value.actor ??
|
|
4648
|
+
actor: opts?.actor ?? launchRequest.value.actor ?? SYSTEM_ACTOR
|
|
4759
4649
|
});
|
|
4760
4650
|
});
|
|
4761
4651
|
}
|
|
@@ -5057,9 +4947,13 @@ function createFutureExecutionLifecycle(deps, _options = {}) {
|
|
|
5057
4947
|
return items;
|
|
5058
4948
|
}
|
|
5059
4949
|
return {
|
|
4950
|
+
/** @internal */
|
|
5060
4951
|
prepareLaunch: launchLifecycle.prepareLaunch,
|
|
4952
|
+
/** @internal */
|
|
5061
4953
|
commitPreparedLaunch: launchLifecycle.commitPreparedLaunch,
|
|
4954
|
+
/** @internal */
|
|
5062
4955
|
reviseScheduledLaunch: launchLifecycle.reviseScheduledLaunch,
|
|
4956
|
+
/** @internal */
|
|
5063
4957
|
async scheduleAction(process2, actionId, request, opts) {
|
|
5064
4958
|
const operationTime = nowFn();
|
|
5065
4959
|
const scheduleValidation = validateScheduleRequestInput2(request.schedule, ["now", "once"]);
|
|
@@ -5090,7 +4984,7 @@ function createFutureExecutionLifecycle(deps, _options = {}) {
|
|
|
5090
4984
|
actionInput: request.input,
|
|
5091
4985
|
nextTurnModelProfileId: typeof request.nextTurnModelProfileId === "string" ? request.nextTurnModelProfileId : null,
|
|
5092
4986
|
overrideProvided: typeof request.nextTurnModelProfileId === "string",
|
|
5093
|
-
actor: opts?.actor ??
|
|
4987
|
+
actor: opts?.actor ?? SYSTEM_ACTOR2,
|
|
5094
4988
|
nextRunAt: validatedSchedule.nextRunAt,
|
|
5095
4989
|
operationTime
|
|
5096
4990
|
});
|
|
@@ -5102,6 +4996,7 @@ function createFutureExecutionLifecycle(deps, _options = {}) {
|
|
|
5102
4996
|
...opts?.actor ? { actor: opts.actor } : {}
|
|
5103
4997
|
});
|
|
5104
4998
|
},
|
|
4999
|
+
/** @internal */
|
|
5105
5000
|
async reviseScheduledAction(futureExecutionId, request, opts) {
|
|
5106
5001
|
const operationTime = nowFn();
|
|
5107
5002
|
return runFutureExecutionExclusive(
|
|
@@ -5142,7 +5037,7 @@ function createFutureExecutionLifecycle(deps, _options = {}) {
|
|
|
5142
5037
|
source: "scheduled",
|
|
5143
5038
|
scheduledExecutionId: existing.id,
|
|
5144
5039
|
consumeScheduledExecutionOnSuccess: true,
|
|
5145
|
-
actor: opts?.actor ?? resolvedActionRequest.value.actor ??
|
|
5040
|
+
actor: opts?.actor ?? resolvedActionRequest.value.actor ?? SYSTEM_ACTOR2
|
|
5146
5041
|
}
|
|
5147
5042
|
);
|
|
5148
5043
|
}
|
|
@@ -5167,7 +5062,7 @@ function createFutureExecutionLifecycle(deps, _options = {}) {
|
|
|
5167
5062
|
actionInput: resolvedActionRequest.value.input,
|
|
5168
5063
|
nextTurnModelProfileId: resolvedActionRequest.value.nextTurnModelProfileId,
|
|
5169
5064
|
overrideProvided: resolvedActionRequest.value.nextTurnModelProfileId !== null,
|
|
5170
|
-
actor: opts?.actor ?? resolvedActionRequest.value.actor ??
|
|
5065
|
+
actor: opts?.actor ?? resolvedActionRequest.value.actor ?? SYSTEM_ACTOR2,
|
|
5171
5066
|
nextRunAt: validatedSchedule.nextRunAt,
|
|
5172
5067
|
operationTime
|
|
5173
5068
|
});
|
|
@@ -5176,6 +5071,7 @@ function createFutureExecutionLifecycle(deps, _options = {}) {
|
|
|
5176
5071
|
}
|
|
5177
5072
|
);
|
|
5178
5073
|
},
|
|
5074
|
+
/** @internal */
|
|
5179
5075
|
async cancel(futureExecutionId) {
|
|
5180
5076
|
return runFutureExecutionExclusive(deps.processOperations, futureExecutionId, async () => {
|
|
5181
5077
|
const execution = deps.futureExecutions.getById(futureExecutionId);
|
|
@@ -5191,7 +5087,9 @@ function createFutureExecutionLifecycle(deps, _options = {}) {
|
|
|
5191
5087
|
};
|
|
5192
5088
|
});
|
|
5193
5089
|
},
|
|
5090
|
+
/** @internal */
|
|
5194
5091
|
applyGeneratedFutureLaunchTitleIfUnchanged: launchLifecycle.applyGeneratedFutureLaunchTitleIfUnchanged,
|
|
5092
|
+
/** @internal */
|
|
5195
5093
|
async reconcileModelAvailability(input) {
|
|
5196
5094
|
const asOf = input.asOf ?? nowFn().toISOString();
|
|
5197
5095
|
if (!deps.processGraphs || !deps.processActionRegistry) {
|
|
@@ -5213,18 +5111,32 @@ function createFutureExecutionLifecycle(deps, _options = {}) {
|
|
|
5213
5111
|
processTitles: deps.processTitles,
|
|
5214
5112
|
asOf
|
|
5215
5113
|
});
|
|
5216
|
-
return result.reaction.ok ? {
|
|
5114
|
+
return result.reaction.ok ? {
|
|
5115
|
+
/** @internal */
|
|
5116
|
+
kind: "reconciled",
|
|
5117
|
+
/** @internal */
|
|
5118
|
+
changed: result.changed,
|
|
5119
|
+
/** @internal */
|
|
5120
|
+
asOf
|
|
5121
|
+
} : {
|
|
5122
|
+
/** @internal */
|
|
5217
5123
|
kind: "committed_with_reaction_error",
|
|
5124
|
+
/** @internal */
|
|
5218
5125
|
changed: result.changed,
|
|
5126
|
+
/** @internal */
|
|
5219
5127
|
asOf,
|
|
5128
|
+
/** @internal */
|
|
5220
5129
|
error: result.reaction.message,
|
|
5130
|
+
/** @internal */
|
|
5221
5131
|
code: result.reaction.code
|
|
5222
5132
|
};
|
|
5223
5133
|
},
|
|
5134
|
+
/** @internal */
|
|
5224
5135
|
async reconcileMissedScheduleOccurrences(asOf) {
|
|
5225
5136
|
await executor.reconcileMissedCronRowsOnStartup(asOf);
|
|
5226
5137
|
return { kind: "occurrences_advanced", asOf };
|
|
5227
5138
|
},
|
|
5139
|
+
/** @internal */
|
|
5228
5140
|
async runDueWork(asOf) {
|
|
5229
5141
|
const blockedItems = await executeDueRows(
|
|
5230
5142
|
deps.futureExecutions.listBlockedCronDue(asOf),
|
|
@@ -5249,16 +5161,17 @@ function startFutureExecutionScheduler(lifecycle, options = {}) {
|
|
|
5249
5161
|
const pollIntervalMs = options.pollIntervalMs ?? 1e3;
|
|
5250
5162
|
const nowFn = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
5251
5163
|
let timer = null;
|
|
5252
|
-
let tickInProgress
|
|
5164
|
+
let tickInProgress;
|
|
5253
5165
|
async function tick() {
|
|
5254
5166
|
if (tickInProgress) {
|
|
5255
|
-
return;
|
|
5167
|
+
return tickInProgress;
|
|
5256
5168
|
}
|
|
5257
|
-
tickInProgress =
|
|
5169
|
+
tickInProgress = lifecycle.runDueWork(nowFn().toISOString()).then(() => {
|
|
5170
|
+
});
|
|
5258
5171
|
try {
|
|
5259
|
-
await
|
|
5172
|
+
await tickInProgress;
|
|
5260
5173
|
} finally {
|
|
5261
|
-
tickInProgress =
|
|
5174
|
+
tickInProgress = void 0;
|
|
5262
5175
|
}
|
|
5263
5176
|
}
|
|
5264
5177
|
return {
|
|
@@ -5272,21 +5185,302 @@ function startFutureExecutionScheduler(lifecycle, options = {}) {
|
|
|
5272
5185
|
void tick();
|
|
5273
5186
|
}, pollIntervalMs);
|
|
5274
5187
|
},
|
|
5275
|
-
stop() {
|
|
5188
|
+
async stop() {
|
|
5276
5189
|
if (timer) {
|
|
5277
5190
|
clearInterval(timer);
|
|
5278
5191
|
timer = null;
|
|
5279
5192
|
}
|
|
5193
|
+
await tickInProgress;
|
|
5280
5194
|
}
|
|
5281
5195
|
};
|
|
5282
5196
|
}
|
|
5283
5197
|
|
|
5284
5198
|
// src/integration-tool-registry.ts
|
|
5285
5199
|
import {
|
|
5200
|
+
bindExternalWrites
|
|
5201
|
+
} from "@leitwerk-dev/external-writes/internal";
|
|
5202
|
+
import {
|
|
5203
|
+
objectArg,
|
|
5286
5204
|
parseJsonData,
|
|
5287
5205
|
RESERVED_INTEGRATION_TOOL_NAMES
|
|
5288
5206
|
} from "@leitwerk-dev/process-sdk";
|
|
5289
5207
|
import * as v2 from "valibot";
|
|
5208
|
+
|
|
5209
|
+
// src/process-action-registry.ts
|
|
5210
|
+
import {
|
|
5211
|
+
createServerProcessBuilder,
|
|
5212
|
+
getExternalActionArmingId as getExternalActionArmingId2,
|
|
5213
|
+
getExternalSourceTransitionId as getExternalSourceTransitionId2,
|
|
5214
|
+
isAutomaticTurnDefinition,
|
|
5215
|
+
isExternalTurnDefinition as isExternalTurnDefinition2,
|
|
5216
|
+
isHumanTurnDefinition as isHumanTurnDefinition2,
|
|
5217
|
+
resolveHumanTurnView,
|
|
5218
|
+
toProcessGraphView
|
|
5219
|
+
} from "@leitwerk-dev/process-sdk";
|
|
5220
|
+
function resolveTurnIntegrationToolNames(registry, process2, turnId) {
|
|
5221
|
+
const turn = registry.getTurnDefinition(process2.processId, turnId);
|
|
5222
|
+
if (turn?.kind !== "llm" && turn?.kind !== "automatic") return [];
|
|
5223
|
+
const dynamic = turn.kind === "llm" && turn.resolveIntegrationTools ? (() => {
|
|
5224
|
+
const context = registry.resolveContextData(process2.processId, process2);
|
|
5225
|
+
return turn.resolveIntegrationTools?.(context.params, context.state) ?? [];
|
|
5226
|
+
})() : [];
|
|
5227
|
+
return [.../* @__PURE__ */ new Set([...turn.integrationTools ?? [], ...dynamic])];
|
|
5228
|
+
}
|
|
5229
|
+
function resolveProcessContextData(processDef, process2) {
|
|
5230
|
+
if (!processDef) {
|
|
5231
|
+
return { params: {}, state: {} };
|
|
5232
|
+
}
|
|
5233
|
+
const params2 = process2.paramsJson ? processDef.paramsCodec.parse(JSON.parse(process2.paramsJson)) : processDef.paramsCodec.parse(void 0);
|
|
5234
|
+
const state = process2.stateJson ? processDef.stateCodec.parse(JSON.parse(process2.stateJson)) : processDef.initialState(params2);
|
|
5235
|
+
return { params: params2, state };
|
|
5236
|
+
}
|
|
5237
|
+
function resolveCurrentTurnForProcess(processDef, process2) {
|
|
5238
|
+
if (!processDef || !process2.selectedTurnId) {
|
|
5239
|
+
return null;
|
|
5240
|
+
}
|
|
5241
|
+
const selectedTurn = processDef.turns.get(process2.selectedTurnId)?.definition;
|
|
5242
|
+
if (!selectedTurn) {
|
|
5243
|
+
return null;
|
|
5244
|
+
}
|
|
5245
|
+
return { turnId: process2.selectedTurnId, turnDef: selectedTurn };
|
|
5246
|
+
}
|
|
5247
|
+
function listExternalTriggers(turnId, turnDef, ctx) {
|
|
5248
|
+
if (isHumanTurnDefinition2(turnDef)) {
|
|
5249
|
+
const view = resolveHumanTurnView({ turnId, turn: turnDef });
|
|
5250
|
+
return [
|
|
5251
|
+
...view.externalTriggers.map((trigger) => ({
|
|
5252
|
+
id: trigger.id,
|
|
5253
|
+
kind: "human_action_external_trigger",
|
|
5254
|
+
label: trigger.label,
|
|
5255
|
+
description: trigger.description
|
|
5256
|
+
})),
|
|
5257
|
+
...view.externalActions.filter((action) => {
|
|
5258
|
+
const definition = turnDef.externalActions?.[action.externalActionId];
|
|
5259
|
+
return !definition?.when || definition.when(ctx);
|
|
5260
|
+
}).map((action) => ({
|
|
5261
|
+
id: action.id,
|
|
5262
|
+
externalActionId: action.externalActionId,
|
|
5263
|
+
kind: action.sourceKind,
|
|
5264
|
+
sourceKind: action.sourceKind,
|
|
5265
|
+
label: action.label,
|
|
5266
|
+
description: action.description
|
|
5267
|
+
}))
|
|
5268
|
+
];
|
|
5269
|
+
}
|
|
5270
|
+
if (isExternalTurnDefinition2(turnDef)) {
|
|
5271
|
+
return turnDef.transitions.map((transition, index) => ({
|
|
5272
|
+
id: getExternalSourceTransitionId2({ turnId, source: transition.source, index }),
|
|
5273
|
+
kind: transition.source.kind,
|
|
5274
|
+
label: transition.source.label ?? null,
|
|
5275
|
+
description: transition.source.description ?? null
|
|
5276
|
+
}));
|
|
5277
|
+
}
|
|
5278
|
+
if (isAutomaticTurnDefinition(turnDef) && ctx.process.lifecycleStatus === "waiting") {
|
|
5279
|
+
return Object.entries(turnDef.externalActions ?? {}).filter(([, action]) => !action.when || action.when(ctx)).map(([externalActionId, action]) => ({
|
|
5280
|
+
id: getExternalActionArmingId2({ turnId, externalActionId }),
|
|
5281
|
+
externalActionId,
|
|
5282
|
+
kind: action.source.kind,
|
|
5283
|
+
sourceKind: action.source.kind,
|
|
5284
|
+
label: action.label ?? action.source.label ?? null,
|
|
5285
|
+
description: action.description ?? action.source.description ?? null
|
|
5286
|
+
}));
|
|
5287
|
+
}
|
|
5288
|
+
return [];
|
|
5289
|
+
}
|
|
5290
|
+
function resolveCurrentVisibleActionForProcess(processDef, process2, actionId) {
|
|
5291
|
+
const currentTurn = resolveCurrentTurnForProcess(processDef, process2);
|
|
5292
|
+
if (!currentTurn || !isHumanTurnDefinition2(currentTurn.turnDef)) {
|
|
5293
|
+
return null;
|
|
5294
|
+
}
|
|
5295
|
+
const view = resolveHumanTurnView({ turnId: currentTurn.turnId, turn: currentTurn.turnDef });
|
|
5296
|
+
return view.actions.find((candidate) => candidate.actionId === actionId) ?? null;
|
|
5297
|
+
}
|
|
5298
|
+
function isTurnScopedActionForProcess(processDef, actionId) {
|
|
5299
|
+
if (!processDef) {
|
|
5300
|
+
return false;
|
|
5301
|
+
}
|
|
5302
|
+
for (const [turnId, { definition: turnDef }] of processDef.turns) {
|
|
5303
|
+
if (isHumanTurnDefinition2(turnDef)) {
|
|
5304
|
+
const view = resolveHumanTurnView({ turnId, turn: turnDef });
|
|
5305
|
+
if (view.actions.some((action) => action.actionId === actionId) || view.externalTriggers.some((trigger) => trigger.actionId === actionId)) {
|
|
5306
|
+
return true;
|
|
5307
|
+
}
|
|
5308
|
+
}
|
|
5309
|
+
}
|
|
5310
|
+
return false;
|
|
5311
|
+
}
|
|
5312
|
+
function buildSelectedTurnSummaryForProcess(processDef, process2, projects = []) {
|
|
5313
|
+
const currentTurn = resolveCurrentTurnForProcess(processDef, process2);
|
|
5314
|
+
if (!currentTurn) {
|
|
5315
|
+
return null;
|
|
5316
|
+
}
|
|
5317
|
+
const { params: params2, state } = resolveProcessContextData(processDef, process2);
|
|
5318
|
+
return {
|
|
5319
|
+
turnId: currentTurn.turnId,
|
|
5320
|
+
kind: currentTurn.turnDef.kind,
|
|
5321
|
+
description: currentTurn.turnDef.description,
|
|
5322
|
+
commentary: isHumanTurnDefinition2(currentTurn.turnDef) ? currentTurn.turnDef.commentary ?? null : null,
|
|
5323
|
+
externalTriggers: listExternalTriggers(currentTurn.turnId, currentTurn.turnDef, {
|
|
5324
|
+
process: process2,
|
|
5325
|
+
projects,
|
|
5326
|
+
params: params2,
|
|
5327
|
+
state
|
|
5328
|
+
})
|
|
5329
|
+
};
|
|
5330
|
+
}
|
|
5331
|
+
function resolveActionTarget(definition, processDef, process2) {
|
|
5332
|
+
if (!definition) return null;
|
|
5333
|
+
const metadata = definition;
|
|
5334
|
+
const preview = "preview" in metadata ? metadata.preview : metadata;
|
|
5335
|
+
if (preview.kind === "fixed_turn") {
|
|
5336
|
+
return { definition, candidateSelectedTurnId: preview.turnId, lifecycleStatus: null };
|
|
5337
|
+
}
|
|
5338
|
+
if (preview.kind === "terminal") {
|
|
5339
|
+
return { definition, candidateSelectedTurnId: null, lifecycleStatus: preview.lifecycleStatus };
|
|
5340
|
+
}
|
|
5341
|
+
if (!processDef || !process2.selectedTurnId) return null;
|
|
5342
|
+
const transitions = toProcessGraphView(processDef).turns.get(process2.selectedTurnId)?.transitions ?? [];
|
|
5343
|
+
const matchingTransitions = transitions.filter(
|
|
5344
|
+
(transition2) => transition2.trigger === preview.trigger
|
|
5345
|
+
);
|
|
5346
|
+
if (matchingTransitions.length !== 1) return null;
|
|
5347
|
+
const [transition] = matchingTransitions;
|
|
5348
|
+
return {
|
|
5349
|
+
definition,
|
|
5350
|
+
candidateSelectedTurnId: transition.nextTurnId ?? null,
|
|
5351
|
+
lifecycleStatus: transition.lifecycleStatus ?? null
|
|
5352
|
+
};
|
|
5353
|
+
}
|
|
5354
|
+
function resolveActionPreviewForProcess(processDef, process2, action, actionId) {
|
|
5355
|
+
const visibleAction = resolveCurrentVisibleActionForProcess(processDef, process2, actionId);
|
|
5356
|
+
const definition = visibleAction?.preview ?? visibleAction?.scheduling?.preview ?? action?.preview ?? action?.scheduling?.preview ?? null;
|
|
5357
|
+
return resolveActionTarget(definition, processDef, process2);
|
|
5358
|
+
}
|
|
5359
|
+
function resolveTurnScopedActionForProcess(processDef, process2, actionId, source) {
|
|
5360
|
+
const currentTurn = resolveCurrentTurnForProcess(processDef, process2);
|
|
5361
|
+
if (!currentTurn || !isHumanTurnDefinition2(currentTurn.turnDef)) return null;
|
|
5362
|
+
const view = resolveHumanTurnView({ turnId: currentTurn.turnId, turn: currentTurn.turnDef });
|
|
5363
|
+
const action = view.actions.find((candidate) => candidate.actionId === actionId);
|
|
5364
|
+
if (!action) return null;
|
|
5365
|
+
const common = {
|
|
5366
|
+
turnId: currentTurn.turnId,
|
|
5367
|
+
semanticEntryRefKey: currentTurn.turnDef.reviewSemanticRef ?? null,
|
|
5368
|
+
acceptanceState: action.acceptanceState
|
|
5369
|
+
};
|
|
5370
|
+
if (source !== "external") {
|
|
5371
|
+
return { ...common, kind: "ui_human_action", turnType: "human" };
|
|
5372
|
+
}
|
|
5373
|
+
const externalTrigger = view.externalTriggers.find((trigger) => trigger.actionId === actionId);
|
|
5374
|
+
if (!externalTrigger) return null;
|
|
5375
|
+
return {
|
|
5376
|
+
...common,
|
|
5377
|
+
kind: "external_human_trigger",
|
|
5378
|
+
turnType: "external",
|
|
5379
|
+
externalTrigger: {
|
|
5380
|
+
id: externalTrigger.id,
|
|
5381
|
+
actionId: externalTrigger.actionId,
|
|
5382
|
+
label: externalTrigger.label,
|
|
5383
|
+
description: externalTrigger.description
|
|
5384
|
+
}
|
|
5385
|
+
};
|
|
5386
|
+
}
|
|
5387
|
+
function buildProcessActionRegistry(catalog) {
|
|
5388
|
+
const serverDefs = /* @__PURE__ */ new Map();
|
|
5389
|
+
const processDefs = /* @__PURE__ */ new Map();
|
|
5390
|
+
for (const [processId, processDef] of catalog.processes) {
|
|
5391
|
+
processDefs.set(processId, processDef);
|
|
5392
|
+
if (!processDef.server) {
|
|
5393
|
+
continue;
|
|
5394
|
+
}
|
|
5395
|
+
const builder = createServerProcessBuilder();
|
|
5396
|
+
processDef.server(builder);
|
|
5397
|
+
serverDefs.set(processId, builder.getDefinition());
|
|
5398
|
+
}
|
|
5399
|
+
return {
|
|
5400
|
+
getAction(processId, actionId) {
|
|
5401
|
+
const def = serverDefs.get(processId);
|
|
5402
|
+
if (!def) return void 0;
|
|
5403
|
+
return def.actions.get(actionId);
|
|
5404
|
+
},
|
|
5405
|
+
isTurnScopedAction(processId, actionId) {
|
|
5406
|
+
return isTurnScopedActionForProcess(processDefs.get(processId), actionId);
|
|
5407
|
+
},
|
|
5408
|
+
listVisibleActions(processId, ctx) {
|
|
5409
|
+
const def = serverDefs.get(processId);
|
|
5410
|
+
const processDef = processDefs.get(processId);
|
|
5411
|
+
const currentTurn = resolveCurrentTurnForProcess(processDef, ctx.process);
|
|
5412
|
+
if (!def || !currentTurn || !isHumanTurnDefinition2(currentTurn.turnDef)) {
|
|
5413
|
+
return [];
|
|
5414
|
+
}
|
|
5415
|
+
const view = resolveHumanTurnView({
|
|
5416
|
+
turnId: currentTurn.turnId,
|
|
5417
|
+
turn: currentTurn.turnDef
|
|
5418
|
+
});
|
|
5419
|
+
const visible = [];
|
|
5420
|
+
for (const turnAction of view.actions) {
|
|
5421
|
+
const action = def.actions.get(turnAction.actionId);
|
|
5422
|
+
if (!action) {
|
|
5423
|
+
continue;
|
|
5424
|
+
}
|
|
5425
|
+
visible.push({
|
|
5426
|
+
id: action.id,
|
|
5427
|
+
label: turnAction.label ?? action.label,
|
|
5428
|
+
description: turnAction.description ?? null,
|
|
5429
|
+
form: action.form,
|
|
5430
|
+
preview: resolveActionPreviewForProcess(processDef, ctx.process, action, action.id)
|
|
5431
|
+
});
|
|
5432
|
+
}
|
|
5433
|
+
return visible;
|
|
5434
|
+
},
|
|
5435
|
+
getSelectedTurnSummary(processId, process2, projects) {
|
|
5436
|
+
return buildSelectedTurnSummaryForProcess(processDefs.get(processId), process2, projects);
|
|
5437
|
+
},
|
|
5438
|
+
getServerDefinition(processId) {
|
|
5439
|
+
return serverDefs.get(processId);
|
|
5440
|
+
},
|
|
5441
|
+
getTurnDefinition(processId, turnId) {
|
|
5442
|
+
return processDefs.get(processId)?.turns.get(turnId)?.definition;
|
|
5443
|
+
},
|
|
5444
|
+
getProcessGraph(processId) {
|
|
5445
|
+
return processDefs.get(processId);
|
|
5446
|
+
},
|
|
5447
|
+
getProcessDisplayName(processId) {
|
|
5448
|
+
return processDefs.get(processId)?.displayName;
|
|
5449
|
+
},
|
|
5450
|
+
resolveContextData(processId, process2) {
|
|
5451
|
+
return resolveProcessContextData(processDefs.get(processId), process2);
|
|
5452
|
+
},
|
|
5453
|
+
resolveTurnScopedAction(processId, process2, actionId, source) {
|
|
5454
|
+
return resolveTurnScopedActionForProcess(
|
|
5455
|
+
processDefs.get(processId),
|
|
5456
|
+
process2,
|
|
5457
|
+
actionId,
|
|
5458
|
+
source
|
|
5459
|
+
);
|
|
5460
|
+
},
|
|
5461
|
+
resolveActionPreview(processId, process2, actionId) {
|
|
5462
|
+
return resolveActionPreviewForProcess(
|
|
5463
|
+
processDefs.get(processId),
|
|
5464
|
+
process2,
|
|
5465
|
+
serverDefs.get(processId)?.actions.get(actionId),
|
|
5466
|
+
actionId
|
|
5467
|
+
);
|
|
5468
|
+
},
|
|
5469
|
+
resolveActionScheduling(processId, process2, actionId) {
|
|
5470
|
+
const action = serverDefs.get(processId)?.actions.get(actionId);
|
|
5471
|
+
if (action?.executionMode === "side_effect") return null;
|
|
5472
|
+
const processDef = processDefs.get(processId);
|
|
5473
|
+
const visibleAction = resolveCurrentVisibleActionForProcess(processDef, process2, actionId);
|
|
5474
|
+
return resolveActionTarget(
|
|
5475
|
+
visibleAction?.scheduling ?? action?.scheduling ?? null,
|
|
5476
|
+
processDef,
|
|
5477
|
+
process2
|
|
5478
|
+
);
|
|
5479
|
+
}
|
|
5480
|
+
};
|
|
5481
|
+
}
|
|
5482
|
+
|
|
5483
|
+
// src/integration-tool-registry.ts
|
|
5290
5484
|
var TOOL_NAME = /^[a-z][a-z0-9_]{0,63}$/;
|
|
5291
5485
|
var RESERVED_TOOL_NAMES = new Set(RESERVED_INTEGRATION_TOOL_NAMES);
|
|
5292
5486
|
function isTicketCreationTool(definition) {
|
|
@@ -5421,12 +5615,7 @@ function resolveJsonPointer(value, pointer) {
|
|
|
5421
5615
|
return current[key];
|
|
5422
5616
|
}, value);
|
|
5423
5617
|
}
|
|
5424
|
-
|
|
5425
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
5426
|
-
throw new Error("Integration tool arguments must be an object");
|
|
5427
|
-
}
|
|
5428
|
-
return value;
|
|
5429
|
-
}
|
|
5618
|
+
var parseToolArgs = (value) => objectArg(value, "Integration tool arguments must be an object");
|
|
5430
5619
|
function persistedTicketActor(value) {
|
|
5431
5620
|
return parseSchema(persistedActorSchema, value, "Ticket creation actor is invalid");
|
|
5432
5621
|
}
|
|
@@ -5465,6 +5654,10 @@ function withTicketDestinationParameter(parameters, destinations) {
|
|
|
5465
5654
|
};
|
|
5466
5655
|
}
|
|
5467
5656
|
var IntegrationToolRegistry = class {
|
|
5657
|
+
constructor(writes) {
|
|
5658
|
+
this.writes = writes;
|
|
5659
|
+
}
|
|
5660
|
+
writes;
|
|
5468
5661
|
tools = /* @__PURE__ */ new Map();
|
|
5469
5662
|
executions = /* @__PURE__ */ new Map();
|
|
5470
5663
|
register(definition) {
|
|
@@ -5552,7 +5745,11 @@ var IntegrationToolRegistry = class {
|
|
|
5552
5745
|
throw new Error("Integration tool execution cancelled");
|
|
5553
5746
|
}
|
|
5554
5747
|
return definition.execute(
|
|
5555
|
-
{
|
|
5748
|
+
{
|
|
5749
|
+
...ctx,
|
|
5750
|
+
signal: controller.signal,
|
|
5751
|
+
externalWrites: bindExternalWrites(this.writes, ctx.process.id)
|
|
5752
|
+
},
|
|
5556
5753
|
definition.parse?.(args) ?? parseToolArgs(args)
|
|
5557
5754
|
);
|
|
5558
5755
|
}).finally(() => this.executions.delete(ctx.idempotencyKey));
|
|
@@ -5829,7 +6026,7 @@ function createLaunchCoordinator(deps) {
|
|
|
5829
6026
|
const projected = project(run);
|
|
5830
6027
|
return JSON.stringify(projected) === JSON.stringify(run) ? run : mutate(run.id, () => projected);
|
|
5831
6028
|
}
|
|
5832
|
-
function
|
|
6029
|
+
function failure(safeSummary, value) {
|
|
5833
6030
|
return { safeSummary, value };
|
|
5834
6031
|
}
|
|
5835
6032
|
function existingLaunchResult(run) {
|
|
@@ -5872,7 +6069,7 @@ function createLaunchCoordinator(deps) {
|
|
|
5872
6069
|
if (request.request.schedule.mode !== "now") {
|
|
5873
6070
|
return {
|
|
5874
6071
|
kind: "failed",
|
|
5875
|
-
failure:
|
|
6072
|
+
failure: failure("Use the scheduling controls to save a future launch.", {
|
|
5876
6073
|
kind: "invalid",
|
|
5877
6074
|
issues: [
|
|
5878
6075
|
{
|
|
@@ -5889,7 +6086,7 @@ function createLaunchCoordinator(deps) {
|
|
|
5889
6086
|
);
|
|
5890
6087
|
return resolved.ok ? { kind: "resolved", value: resolved.launcher } : {
|
|
5891
6088
|
kind: "failed",
|
|
5892
|
-
failure:
|
|
6089
|
+
failure: failure("Review the highlighted launcher fields and try again.", {
|
|
5893
6090
|
kind: "invalid",
|
|
5894
6091
|
issues: resolved.errors
|
|
5895
6092
|
})
|
|
@@ -5932,7 +6129,7 @@ function createLaunchCoordinator(deps) {
|
|
|
5932
6129
|
} : prepared.prepared
|
|
5933
6130
|
} : {
|
|
5934
6131
|
ok: false,
|
|
5935
|
-
failure:
|
|
6132
|
+
failure: failure("Review the launch configuration and try again.", prepared.outcome)
|
|
5936
6133
|
};
|
|
5937
6134
|
},
|
|
5938
6135
|
async commit(prepared, ctx) {
|
|
@@ -5960,14 +6157,14 @@ function createLaunchCoordinator(deps) {
|
|
|
5960
6157
|
}
|
|
5961
6158
|
return {
|
|
5962
6159
|
kind: "failed",
|
|
5963
|
-
failure:
|
|
6160
|
+
failure: failure(
|
|
5964
6161
|
"The process could not be created. Check availability and try again.",
|
|
5965
6162
|
result
|
|
5966
6163
|
)
|
|
5967
6164
|
};
|
|
5968
6165
|
},
|
|
5969
6166
|
unexpectedFailure() {
|
|
5970
|
-
return
|
|
6167
|
+
return failure("The launch could not be completed. Try again.", {
|
|
5971
6168
|
kind: "failed",
|
|
5972
6169
|
issue: { code: "launch_failed", message: "The launch could not be completed" }
|
|
5973
6170
|
});
|
|
@@ -6142,7 +6339,7 @@ function createLaunchCoordinator(deps) {
|
|
|
6142
6339
|
);
|
|
6143
6340
|
return prepared.ok ? { ok: true, value: prepared.launchPlan } : {
|
|
6144
6341
|
ok: false,
|
|
6145
|
-
failure:
|
|
6342
|
+
failure: failure(
|
|
6146
6343
|
"The launch model configuration is unavailable. Review the watcher configuration.",
|
|
6147
6344
|
prepared
|
|
6148
6345
|
)
|
|
@@ -6587,34 +6784,6 @@ function createModelProviderCredentialService(input) {
|
|
|
6587
6784
|
};
|
|
6588
6785
|
}
|
|
6589
6786
|
|
|
6590
|
-
// src/model-providers/provider-boundary-utils.ts
|
|
6591
|
-
function positiveBound(value, fallback, name) {
|
|
6592
|
-
const resolved = value ?? fallback;
|
|
6593
|
-
if (!Number.isSafeInteger(resolved) || resolved < 1) {
|
|
6594
|
-
throw new Error(`${name} must be a positive safe integer`);
|
|
6595
|
-
}
|
|
6596
|
-
return resolved;
|
|
6597
|
-
}
|
|
6598
|
-
async function withTimeout(work, timeoutMs, sentinelMessage = "timeout") {
|
|
6599
|
-
let timer;
|
|
6600
|
-
try {
|
|
6601
|
-
return await Promise.race([
|
|
6602
|
-
work,
|
|
6603
|
-
new Promise((_resolve, reject2) => {
|
|
6604
|
-
timer = setTimeout(() => reject2(new Error(sentinelMessage)), timeoutMs);
|
|
6605
|
-
})
|
|
6606
|
-
]);
|
|
6607
|
-
} finally {
|
|
6608
|
-
if (timer) clearTimeout(timer);
|
|
6609
|
-
}
|
|
6610
|
-
}
|
|
6611
|
-
function validateCredentialStatus(value, message = "invalid credential status") {
|
|
6612
|
-
if (typeof value !== "object" || value === null || typeof value.available !== "boolean" || !(value.revision === null || Number.isSafeInteger(value.revision) && value.revision >= 0)) {
|
|
6613
|
-
throw new Error(message);
|
|
6614
|
-
}
|
|
6615
|
-
return value;
|
|
6616
|
-
}
|
|
6617
|
-
|
|
6618
6787
|
// src/model-providers/model-status-cache.ts
|
|
6619
6788
|
var DEFAULT_STATUS_TTL_MS = 3e4;
|
|
6620
6789
|
var DEFAULT_STATUS_TIMEOUT_MS = 5e3;
|
|
@@ -6820,91 +6989,6 @@ function createModelStatusCache(input) {
|
|
|
6820
6989
|
};
|
|
6821
6990
|
}
|
|
6822
6991
|
|
|
6823
|
-
// src/model-providers/provider-options.ts
|
|
6824
|
-
import {
|
|
6825
|
-
resolveProviderOptions
|
|
6826
|
-
} from "@leitwerk-dev/process-sdk";
|
|
6827
|
-
var DEFAULT_OPTION_CHOICE_TIMEOUT_MS = 5e3;
|
|
6828
|
-
var DEFAULT_MAX_CHOICE_FIELDS = 64;
|
|
6829
|
-
var DEFAULT_MAX_CHOICES_PER_FIELD = 256;
|
|
6830
|
-
var DEFAULT_MAX_CHOICE_TEXT_LENGTH = 512;
|
|
6831
|
-
function resolveRegisteredProviderOptions(input) {
|
|
6832
|
-
return resolveProviderOptions({
|
|
6833
|
-
definition: input.provider.definition.options,
|
|
6834
|
-
config: input.provider.config,
|
|
6835
|
-
explicit: input.explicit,
|
|
6836
|
-
profileDefaults: input.profileDefaults
|
|
6837
|
-
});
|
|
6838
|
-
}
|
|
6839
|
-
function validateConfiguredProviderOptions(input) {
|
|
6840
|
-
const result = resolveRegisteredProviderOptions({
|
|
6841
|
-
provider: input.provider,
|
|
6842
|
-
profileDefaults: input.values
|
|
6843
|
-
});
|
|
6844
|
-
if (result.ok) {
|
|
6845
|
-
return [];
|
|
6846
|
-
}
|
|
6847
|
-
return result.issues.filter((issue) => issue.code !== "required");
|
|
6848
|
-
}
|
|
6849
|
-
async function loadProviderOptionChoices(input) {
|
|
6850
|
-
const choicesLoader = input.provider.definition.options?.choices;
|
|
6851
|
-
if (!choicesLoader) {
|
|
6852
|
-
return { ok: true, choices: {} };
|
|
6853
|
-
}
|
|
6854
|
-
const timeoutMs = positiveBound(
|
|
6855
|
-
input.timeoutMs,
|
|
6856
|
-
DEFAULT_OPTION_CHOICE_TIMEOUT_MS,
|
|
6857
|
-
"Provider option choice timeout"
|
|
6858
|
-
);
|
|
6859
|
-
const maxFields = positiveBound(
|
|
6860
|
-
input.maxFields,
|
|
6861
|
-
DEFAULT_MAX_CHOICE_FIELDS,
|
|
6862
|
-
"Maximum choice fields"
|
|
6863
|
-
);
|
|
6864
|
-
const maxChoices = positiveBound(
|
|
6865
|
-
input.maxChoicesPerField,
|
|
6866
|
-
DEFAULT_MAX_CHOICES_PER_FIELD,
|
|
6867
|
-
"Maximum choices per field"
|
|
6868
|
-
);
|
|
6869
|
-
const maxTextLength = positiveBound(
|
|
6870
|
-
input.maxTextLength,
|
|
6871
|
-
DEFAULT_MAX_CHOICE_TEXT_LENGTH,
|
|
6872
|
-
"Maximum choice text length"
|
|
6873
|
-
);
|
|
6874
|
-
try {
|
|
6875
|
-
const credentialStatus = validateCredentialStatus(
|
|
6876
|
-
await withTimeout(Promise.resolve(input.credentialStatus(input.provider)), timeoutMs)
|
|
6877
|
-
);
|
|
6878
|
-
const raw = await withTimeout(
|
|
6879
|
-
Promise.resolve(choicesLoader({ config: input.provider.config, credentialStatus })),
|
|
6880
|
-
timeoutMs
|
|
6881
|
-
);
|
|
6882
|
-
const entries = Object.entries(raw);
|
|
6883
|
-
if (entries.length > maxFields) {
|
|
6884
|
-
throw new Error("too many fields");
|
|
6885
|
-
}
|
|
6886
|
-
const fields = input.provider.definition.options?.fields ?? {};
|
|
6887
|
-
const bounded = {};
|
|
6888
|
-
for (const [fieldId, choices] of entries) {
|
|
6889
|
-
if (!(fieldId in fields) || !Array.isArray(choices) || choices.length > maxChoices) {
|
|
6890
|
-
throw new Error("invalid field choices");
|
|
6891
|
-
}
|
|
6892
|
-
bounded[fieldId] = choices.map((choice) => {
|
|
6893
|
-
if (typeof choice?.value !== "string" || typeof choice?.label !== "string" || choice.value.length > maxTextLength || choice.label.length > maxTextLength) {
|
|
6894
|
-
throw new Error("invalid choice");
|
|
6895
|
-
}
|
|
6896
|
-
return { value: choice.value, label: choice.label };
|
|
6897
|
-
});
|
|
6898
|
-
}
|
|
6899
|
-
return { ok: true, choices: bounded };
|
|
6900
|
-
} catch (error) {
|
|
6901
|
-
return {
|
|
6902
|
-
ok: false,
|
|
6903
|
-
safeReason: error instanceof Error && error.message === "timeout" ? "Provider option choices timed out" : "Provider option choices are temporarily unavailable"
|
|
6904
|
-
};
|
|
6905
|
-
}
|
|
6906
|
-
}
|
|
6907
|
-
|
|
6908
6992
|
// src/model-providers/registry.ts
|
|
6909
6993
|
import { toErrorMessage as errorMessage } from "@leitwerk-dev/domain";
|
|
6910
6994
|
var defaultModelProviderCredentialStatus = (provider) => provider.definition.credential ? { available: false, revision: null } : { available: true, revision: null };
|
|
@@ -7106,472 +7190,64 @@ async function createModelProviderServerAdapterRegistry(input) {
|
|
|
7106
7190
|
};
|
|
7107
7191
|
}
|
|
7108
7192
|
|
|
7109
|
-
// src/
|
|
7110
|
-
|
|
7111
|
-
|
|
7112
|
-
|
|
7113
|
-
|
|
7114
|
-
|
|
7115
|
-
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
|
|
7121
|
-
|
|
7122
|
-
|
|
7123
|
-
}
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
|
|
7133
|
-
|
|
7134
|
-
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
|
|
7144
|
-
|
|
7145
|
-
|
|
7146
|
-
|
|
7147
|
-
|
|
7148
|
-
|
|
7149
|
-
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
);
|
|
7193
|
+
// src/process-deletion-service.ts
|
|
7194
|
+
var TERMINAL_STATUSES2 = /* @__PURE__ */ new Set(["completed", "aborted"]);
|
|
7195
|
+
var CLEANUP_FAILURE_MESSAGE = "The process could not be deleted; retry deletion";
|
|
7196
|
+
function createProcessDeletionService(deps) {
|
|
7197
|
+
return {
|
|
7198
|
+
async deleteProcess(instanceId, actor) {
|
|
7199
|
+
deps.deletionPending?.add(instanceId);
|
|
7200
|
+
try {
|
|
7201
|
+
const initial = deps.processes.getById(instanceId);
|
|
7202
|
+
if (!initial) return { ok: false, kind: "not_found" };
|
|
7203
|
+
deps.sessionTransfers?.revokeProcess(instanceId);
|
|
7204
|
+
if (!TERMINAL_STATUSES2.has(initial.lifecycleStatus)) {
|
|
7205
|
+
const aborted = await deps.processEngine.abortProcess(instanceId, { actor });
|
|
7206
|
+
if (!aborted.ok) return { ok: false, kind: "abort_failed", failure: aborted };
|
|
7207
|
+
}
|
|
7208
|
+
try {
|
|
7209
|
+
await deps.supervisor.stopWorker(instanceId, "process_deleted");
|
|
7210
|
+
return await deps.processOperations.runExclusive(instanceId, async () => {
|
|
7211
|
+
const process2 = deps.processes.getById(instanceId);
|
|
7212
|
+
if (!process2) return { ok: false, kind: "not_found" };
|
|
7213
|
+
if (!TERMINAL_STATUSES2.has(process2.lifecycleStatus)) {
|
|
7214
|
+
return { ok: false, kind: "cleanup_failed", message: CLEANUP_FAILURE_MESSAGE };
|
|
7215
|
+
}
|
|
7216
|
+
await Promise.all([
|
|
7217
|
+
deps.volume?.deleteProcessResources(instanceId),
|
|
7218
|
+
deps.sessionSnapshots.deleteSnapshot(instanceId),
|
|
7219
|
+
deps.resultImages.deleteProcess(instanceId)
|
|
7220
|
+
]);
|
|
7221
|
+
if (!deps.processes.delete(instanceId)) return { ok: false, kind: "not_found" };
|
|
7222
|
+
try {
|
|
7223
|
+
deps.broadcaster.sendDurable("process.deleted", { instanceId }, instanceId);
|
|
7224
|
+
} catch (error) {
|
|
7225
|
+
deps.logger?.error({ error, instanceId }, "process deletion broadcast failed");
|
|
7226
|
+
}
|
|
7227
|
+
return { ok: true };
|
|
7228
|
+
});
|
|
7229
|
+
} catch (error) {
|
|
7230
|
+
deps.logger?.error({ error, instanceId }, "process deletion cleanup failed");
|
|
7231
|
+
return { ok: false, kind: "cleanup_failed", message: CLEANUP_FAILURE_MESSAGE };
|
|
7232
|
+
}
|
|
7233
|
+
} finally {
|
|
7234
|
+
deps.deletionPending?.delete(instanceId);
|
|
7235
|
+
}
|
|
7153
7236
|
}
|
|
7154
|
-
|
|
7155
|
-
}
|
|
7156
|
-
}
|
|
7157
|
-
function safeExtensionSegment(ownerExtensionId) {
|
|
7158
|
-
const normalized = ownerExtensionId.normalize("NFKD").replaceAll(/[^A-Za-z0-9._-]+/g, "-").replaceAll(/^-+|-+$/g, "") || "extension";
|
|
7159
|
-
if (Buffer.byteLength(normalized, "utf8") <= 56) return normalized;
|
|
7160
|
-
return `${normalized.slice(0, 43)}-${sha256Digest(Buffer.from(ownerExtensionId)).slice(0, 12)}`;
|
|
7161
|
-
}
|
|
7162
|
-
function extensionSnapshotPath(contribution, index) {
|
|
7163
|
-
const prefix = String(index * 10).padStart(3, "0");
|
|
7164
|
-
return validateResourceRelativePath(
|
|
7165
|
-
`extensions/${prefix}-${safeExtensionSegment(contribution.ownerExtensionId)}.js`
|
|
7166
|
-
);
|
|
7167
|
-
}
|
|
7168
|
-
var PI_CORE_EXTERNALS = ["@earendil-works/pi-ai", "@earendil-works/pi-coding-agent"];
|
|
7169
|
-
async function buildPiExtensionWrapper(entryPath) {
|
|
7170
|
-
const result = await build({
|
|
7171
|
-
absWorkingDir: path2.dirname(entryPath),
|
|
7172
|
-
bundle: true,
|
|
7173
|
-
stdin: {
|
|
7174
|
-
contents: `
|
|
7175
|
-
import contribution from ${JSON.stringify(entryPath)};
|
|
7176
|
-
import { readFileSync } from "node:fs";
|
|
7177
|
-
|
|
7178
|
-
function readGenerated() {
|
|
7179
|
-
return JSON.parse(readFileSync(new URL("../generated.json", import.meta.url), "utf8"));
|
|
7237
|
+
};
|
|
7180
7238
|
}
|
|
7181
7239
|
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
const load = () => {
|
|
7185
|
-
if (values) return values;
|
|
7186
|
-
values = {};
|
|
7187
|
-
for (const credentialPath of generated.declaredCredentialPaths) {
|
|
7188
|
-
if (typeof credentialPath !== "string" || credentialPath.startsWith("/") || credentialPath.includes("..") || credentialPath.includes("\\\\")) {
|
|
7189
|
-
throw new Error("Invalid declared Pi credential path");
|
|
7190
|
-
}
|
|
7191
|
-
const credential = JSON.parse(readFileSync(new URL("../" + credentialPath, import.meta.url), "utf8"));
|
|
7192
|
-
if (credential && typeof credential === "object" && !Array.isArray(credential)) Object.assign(values, credential);
|
|
7193
|
-
}
|
|
7194
|
-
return values;
|
|
7195
|
-
};
|
|
7240
|
+
// src/process-attention-notifier.ts
|
|
7241
|
+
function attentionDeps(deps) {
|
|
7196
7242
|
return {
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
const generated = readGenerated();
|
|
7206
|
-
const workerConfig = generated.providerWorkerConfig === null ? null : generated.providerWorkerConfig?.value;
|
|
7207
|
-
const report = (event) => {
|
|
7208
|
-
if (!event || typeof event !== "object" || Array.isArray(event)) throw new Error("Pi worker report must be an object");
|
|
7209
|
-
pi.events?.emit?.("leitwerk:provider-report", event);
|
|
7210
|
-
};
|
|
7211
|
-
await contribution(pi, {
|
|
7212
|
-
model: { providerId: generated.model.providerId, modelId: generated.model.modelId },
|
|
7213
|
-
options: { ...generated.providerOptions },
|
|
7214
|
-
workerConfig,
|
|
7215
|
-
secrets: credentialBag(generated),
|
|
7216
|
-
report,
|
|
7217
|
-
});
|
|
7218
|
-
}
|
|
7219
|
-
`,
|
|
7220
|
-
resolveDir: path2.dirname(entryPath),
|
|
7221
|
-
sourcefile: "leitwerk-pi-wrapper.js"
|
|
7222
|
-
},
|
|
7223
|
-
format: "esm",
|
|
7224
|
-
platform: "node",
|
|
7225
|
-
target: "node22",
|
|
7226
|
-
write: false,
|
|
7227
|
-
minify: true,
|
|
7228
|
-
sourcemap: false,
|
|
7229
|
-
legalComments: "none",
|
|
7230
|
-
external: PI_CORE_EXTERNALS
|
|
7231
|
-
});
|
|
7232
|
-
const output = result.outputFiles[0];
|
|
7233
|
-
if (!output) throw new Error(`Pi extension wrapper did not produce output for '${entryPath}'`);
|
|
7234
|
-
return output.contents;
|
|
7235
|
-
}
|
|
7236
|
-
function normalizeCredentialPaths(paths) {
|
|
7237
|
-
const seen = /* @__PURE__ */ new Set();
|
|
7238
|
-
const normalized = paths.map((credentialPath) => {
|
|
7239
|
-
const result = validateResourceRelativePath(credentialPath);
|
|
7240
|
-
if (seen.has(result)) throw new Error(`Duplicate declared credential path '${result}'`);
|
|
7241
|
-
seen.add(result);
|
|
7242
|
-
return result;
|
|
7243
|
-
});
|
|
7244
|
-
return normalized.sort(compareResourcePaths);
|
|
7245
|
-
}
|
|
7246
|
-
function assertCredentialPathsDoNotOverlap(credentialPaths, immutablePaths) {
|
|
7247
|
-
const files = [...immutablePaths];
|
|
7248
|
-
for (const credentialPath of credentialPaths) {
|
|
7249
|
-
for (const immutablePath of files) {
|
|
7250
|
-
if (credentialPath === immutablePath || credentialPath.startsWith(`${immutablePath}/`) || immutablePath.startsWith(`${credentialPath}/`)) {
|
|
7251
|
-
throw new Error(
|
|
7252
|
-
`Declared credential path '${credentialPath}' overlaps immutable resource '${immutablePath}'`
|
|
7253
|
-
);
|
|
7254
|
-
}
|
|
7255
|
-
}
|
|
7256
|
-
}
|
|
7257
|
-
}
|
|
7258
|
-
function requireNonEmptyString(value, location) {
|
|
7259
|
-
if (typeof value !== "string" || value.trim() === "") {
|
|
7260
|
-
throw new Error(`${location} must be a non-empty string`);
|
|
7261
|
-
}
|
|
7262
|
-
}
|
|
7263
|
-
function validateAssemblyInput(input) {
|
|
7264
|
-
requireNonEmptyString(input.model.profileId, "model.profileId");
|
|
7265
|
-
requireNonEmptyString(input.model.providerId, "model.providerId");
|
|
7266
|
-
requireNonEmptyString(input.model.modelId, "model.modelId");
|
|
7267
|
-
requireNonEmptyString(input.model.thinkingLevel, "model.thinkingLevel");
|
|
7268
|
-
requireNonEmptyString(input.compatibility.workerApiVersion, "compatibility.workerApiVersion");
|
|
7269
|
-
requireNonEmptyString(input.compatibility.piVersion, "compatibility.piVersion");
|
|
7270
|
-
if (input.compatibility.protocolVersion !== void 0) {
|
|
7271
|
-
requireNonEmptyString(input.compatibility.protocolVersion, "compatibility.protocolVersion");
|
|
7272
|
-
}
|
|
7273
|
-
for (const [fieldId, value] of Object.entries(input.providerOptions)) {
|
|
7274
|
-
if (fieldId.trim() === "" || typeof value !== "string") {
|
|
7275
|
-
throw new Error("providerOptions must contain non-empty field ids and string values");
|
|
7276
|
-
}
|
|
7277
|
-
}
|
|
7278
|
-
if (input.providerWorkerConfig && (!Number.isSafeInteger(input.providerWorkerConfig.version) || input.providerWorkerConfig.version < 1)) {
|
|
7279
|
-
throw new Error("providerWorkerConfig.version must be a positive safe integer");
|
|
7280
|
-
}
|
|
7281
|
-
if (input.systemPrompt !== void 0 && input.systemPrompt !== null) {
|
|
7282
|
-
if (typeof input.systemPrompt !== "string") throw new Error("systemPrompt must be a string");
|
|
7283
|
-
}
|
|
7284
|
-
if (input.appendSystemPrompt !== void 0 && input.appendSystemPrompt !== null) {
|
|
7285
|
-
if (typeof input.appendSystemPrompt !== "string") {
|
|
7286
|
-
throw new Error("appendSystemPrompt must be a string");
|
|
7287
|
-
}
|
|
7288
|
-
}
|
|
7289
|
-
}
|
|
7290
|
-
async function assemblePiResourceSnapshot(input) {
|
|
7291
|
-
validateAssemblyInput(input);
|
|
7292
|
-
assertNoCredentialFields(input.piSettings, "piSettings");
|
|
7293
|
-
assertNoCredentialFields(input.piModels ?? {}, "piModels");
|
|
7294
|
-
assertNoCredentialFields(input.providerOptions, "providerOptions");
|
|
7295
|
-
assertNoCredentialFields(input.providerWorkerConfig?.value ?? {}, "providerWorkerConfig.value");
|
|
7296
|
-
const collector = new ResourceCollector(input.limits);
|
|
7297
|
-
const seenOwners = /* @__PURE__ */ new Set();
|
|
7298
|
-
const workerSourceIdentities = /* @__PURE__ */ new Map();
|
|
7299
|
-
const workerSourceRealPaths = /* @__PURE__ */ new Map();
|
|
7300
|
-
const settings = { ...input.piSettings, packages: [], defaultProjectTrust: "never" };
|
|
7301
|
-
collector.addBytes("settings.json", jsonBytes(settings, "settings.json"));
|
|
7302
|
-
collector.addBytes("models.json", jsonBytes(input.piModels ?? { providers: {} }, "models.json"));
|
|
7303
|
-
if (input.systemPrompt !== void 0 && input.systemPrompt !== null) {
|
|
7304
|
-
collector.addBytes("SYSTEM.md", Buffer.from(input.systemPrompt, "utf8"));
|
|
7305
|
-
}
|
|
7306
|
-
if (input.appendSystemPrompt !== void 0 && input.appendSystemPrompt !== null) {
|
|
7307
|
-
collector.addBytes("APPEND_SYSTEM.md", Buffer.from(input.appendSystemPrompt, "utf8"));
|
|
7308
|
-
}
|
|
7309
|
-
for (const layer of input.resourceLayers ?? []) collector.addBundle(layer.bundle, layer.owner);
|
|
7310
|
-
for (const [index, contribution] of input.piContributions.entries()) {
|
|
7311
|
-
if (seenOwners.has(contribution.ownerExtensionId)) {
|
|
7312
|
-
throw new Error(
|
|
7313
|
-
`Extension '${contribution.ownerExtensionId}' appears more than once in Pi contributions`
|
|
7314
|
-
);
|
|
7315
|
-
}
|
|
7316
|
-
seenOwners.add(contribution.ownerExtensionId);
|
|
7317
|
-
const baseOwner = {
|
|
7318
|
-
ownerExtensionId: contribution.ownerExtensionId,
|
|
7319
|
-
packageName: contribution.packageName
|
|
7320
|
-
};
|
|
7321
|
-
if (contribution.workerEntryPath) {
|
|
7322
|
-
validatePhysicalSourcePath(contribution.workerEntryPath);
|
|
7323
|
-
const source = await lstat(contribution.workerEntryPath);
|
|
7324
|
-
if (source.isSymbolicLink() || !source.isFile()) {
|
|
7325
|
-
throw new Error(
|
|
7326
|
-
`Pi resource source must be a regular file: ${contribution.workerEntryPath}`
|
|
7327
|
-
);
|
|
7328
|
-
}
|
|
7329
|
-
const identity = `${source.dev}:${source.ino}`;
|
|
7330
|
-
const physicalPath = await realpath(contribution.workerEntryPath);
|
|
7331
|
-
const first = workerSourceIdentities.get(identity) ?? workerSourceRealPaths.get(physicalPath);
|
|
7332
|
-
if (first) {
|
|
7333
|
-
throw new Error(
|
|
7334
|
-
`Physical Pi resource file is included more than once: ${contribution.workerEntryPath} (first: ${first})`
|
|
7335
|
-
);
|
|
7336
|
-
}
|
|
7337
|
-
workerSourceIdentities.set(identity, contribution.workerEntryPath);
|
|
7338
|
-
workerSourceRealPaths.set(physicalPath, contribution.workerEntryPath);
|
|
7339
|
-
const snapshotPath = extensionSnapshotPath(contribution, index);
|
|
7340
|
-
collector.addBytes(
|
|
7341
|
-
snapshotPath,
|
|
7342
|
-
await buildPiExtensionWrapper(contribution.workerEntryPath),
|
|
7343
|
-
{ kind: "extension", ...baseOwner }
|
|
7344
|
-
);
|
|
7345
|
-
}
|
|
7346
|
-
for (const skillDirectory of contribution.resources.skillDirectories) {
|
|
7347
|
-
await collector.addDirectory(skillDirectory, "skills", { kind: "skill", ...baseOwner });
|
|
7348
|
-
}
|
|
7349
|
-
for (const promptDirectory of contribution.resources.promptDirectories) {
|
|
7350
|
-
await collector.addDirectory(promptDirectory, "prompts", { kind: "prompt", ...baseOwner });
|
|
7351
|
-
}
|
|
7352
|
-
}
|
|
7353
|
-
const credentialPaths = normalizeCredentialPaths(input.declaredCredentialPaths);
|
|
7354
|
-
assertCredentialPathsDoNotOverlap(credentialPaths, [...collector.files.keys(), "generated.json"]);
|
|
7355
|
-
const provenance = collector.provenance.slice().sort((left, right) => compareResourcePaths(left.snapshotPath, right.snapshotPath));
|
|
7356
|
-
const generated = {
|
|
7357
|
-
schemaVersion: PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION,
|
|
7358
|
-
model: { ...input.model },
|
|
7359
|
-
providerOptions: { ...input.providerOptions },
|
|
7360
|
-
providerWorkerConfig: input.providerWorkerConfig ? {
|
|
7361
|
-
version: input.providerWorkerConfig.version,
|
|
7362
|
-
value: canonicalizeJson(
|
|
7363
|
-
input.providerWorkerConfig.value,
|
|
7364
|
-
"providerWorkerConfig.value"
|
|
7365
|
-
)
|
|
7366
|
-
} : null,
|
|
7367
|
-
declaredCredentialPaths: credentialPaths,
|
|
7368
|
-
compatibility: { ...input.compatibility },
|
|
7369
|
-
provenance
|
|
7370
|
-
};
|
|
7371
|
-
collector.addBytes("generated.json", jsonBytes(generated, "generated.json"));
|
|
7372
|
-
const resourceFiles = collector.toResourceFiles();
|
|
7373
|
-
const bundle = createCanonicalPiResourceBundle(resourceFiles);
|
|
7374
|
-
return {
|
|
7375
|
-
bundle,
|
|
7376
|
-
generated,
|
|
7377
|
-
files: collector.provenance.map(({ snapshotPath, sha256, size }) => ({ path: snapshotPath, sha256, size })).sort((left, right) => compareResourcePaths(left.path, right.path))
|
|
7378
|
-
};
|
|
7379
|
-
}
|
|
7380
|
-
|
|
7381
|
-
// src/pi-resources/bundle-cache.ts
|
|
7382
|
-
import { sha256Digest as sha256Digest2 } from "@leitwerk-dev/worker-protocol";
|
|
7383
|
-
var DEFAULT_MAX_ENTRIES = 64;
|
|
7384
|
-
var DEFAULT_MAX_BYTES = 256 * 1024 * 1024;
|
|
7385
|
-
function createPiResourceBundleCache(options = {}) {
|
|
7386
|
-
const maxEntries = positiveBound(options.maxEntries, DEFAULT_MAX_ENTRIES, "maxEntries");
|
|
7387
|
-
const maxBytes = positiveBound(options.maxBytes, DEFAULT_MAX_BYTES, "maxBytes");
|
|
7388
|
-
const entries = /* @__PURE__ */ new Map();
|
|
7389
|
-
let totalBytes = 0;
|
|
7390
|
-
function touch(entry) {
|
|
7391
|
-
entries.delete(entry.digest);
|
|
7392
|
-
entries.set(entry.digest, entry);
|
|
7393
|
-
}
|
|
7394
|
-
function oldestUnpinned(excluding) {
|
|
7395
|
-
for (const entry of entries.values()) {
|
|
7396
|
-
if (entry.digest !== excluding && entry.pins === 0) return entry;
|
|
7397
|
-
}
|
|
7398
|
-
return null;
|
|
7399
|
-
}
|
|
7400
|
-
function remove(entry) {
|
|
7401
|
-
if (!entries.delete(entry.digest)) return;
|
|
7402
|
-
totalBytes -= entry.bytes.byteLength;
|
|
7403
|
-
}
|
|
7404
|
-
function enforceBounds(newDigest) {
|
|
7405
|
-
while (entries.size > maxEntries || totalBytes > maxBytes) {
|
|
7406
|
-
const candidate = oldestUnpinned(newDigest);
|
|
7407
|
-
if (!candidate) {
|
|
7408
|
-
const inserted = entries.get(newDigest);
|
|
7409
|
-
if (inserted?.pins === 0) remove(inserted);
|
|
7410
|
-
throw new Error("Pi resource bundle cache capacity is exhausted by pinned bundles");
|
|
7411
|
-
}
|
|
7412
|
-
remove(candidate);
|
|
7413
|
-
}
|
|
7414
|
-
}
|
|
7415
|
-
return {
|
|
7416
|
-
put(bundle) {
|
|
7417
|
-
if (typeof bundle.digest !== "string" || sha256Digest2(bundle.bytes) !== bundle.digest) {
|
|
7418
|
-
throw new Error("Pi resource bundle digest does not match its bytes");
|
|
7419
|
-
}
|
|
7420
|
-
if (bundle.bytes.byteLength > maxBytes) {
|
|
7421
|
-
throw new Error(
|
|
7422
|
-
`Pi resource bundle size ${bundle.bytes.byteLength} exceeds cache byte limit ${maxBytes}`
|
|
7423
|
-
);
|
|
7424
|
-
}
|
|
7425
|
-
const existing = entries.get(bundle.digest);
|
|
7426
|
-
if (existing) {
|
|
7427
|
-
touch(existing);
|
|
7428
|
-
return;
|
|
7429
|
-
}
|
|
7430
|
-
const bytes = Uint8Array.from(bundle.bytes);
|
|
7431
|
-
const entry = {
|
|
7432
|
-
digest: bundle.digest,
|
|
7433
|
-
bytes,
|
|
7434
|
-
pins: 0
|
|
7435
|
-
};
|
|
7436
|
-
entries.set(entry.digest, entry);
|
|
7437
|
-
totalBytes += entry.bytes.byteLength;
|
|
7438
|
-
enforceBounds(entry.digest);
|
|
7439
|
-
},
|
|
7440
|
-
get(digest) {
|
|
7441
|
-
const entry = entries.get(digest);
|
|
7442
|
-
if (!entry) return null;
|
|
7443
|
-
touch(entry);
|
|
7444
|
-
return { digest: entry.digest, bytes: Uint8Array.from(entry.bytes) };
|
|
7445
|
-
},
|
|
7446
|
-
has: (digest) => entries.has(digest),
|
|
7447
|
-
pin(digest) {
|
|
7448
|
-
const entry = entries.get(digest);
|
|
7449
|
-
if (!entry) return false;
|
|
7450
|
-
entry.pins += 1;
|
|
7451
|
-
touch(entry);
|
|
7452
|
-
return true;
|
|
7453
|
-
},
|
|
7454
|
-
unpin(digest) {
|
|
7455
|
-
const entry = entries.get(digest);
|
|
7456
|
-
if (!entry || entry.pins === 0) return false;
|
|
7457
|
-
entry.pins -= 1;
|
|
7458
|
-
touch(entry);
|
|
7459
|
-
return true;
|
|
7460
|
-
},
|
|
7461
|
-
gc() {
|
|
7462
|
-
const removed = [...entries.values()].filter((entry) => entry.pins === 0);
|
|
7463
|
-
let removedBytes = 0;
|
|
7464
|
-
for (const entry of removed) {
|
|
7465
|
-
removedBytes += entry.bytes.byteLength;
|
|
7466
|
-
remove(entry);
|
|
7467
|
-
}
|
|
7468
|
-
return {
|
|
7469
|
-
removedDigests: removed.map((entry) => entry.digest),
|
|
7470
|
-
removedBytes
|
|
7471
|
-
};
|
|
7472
|
-
},
|
|
7473
|
-
stats() {
|
|
7474
|
-
const values = [...entries.values()];
|
|
7475
|
-
return {
|
|
7476
|
-
entries: entries.size,
|
|
7477
|
-
bytes: totalBytes,
|
|
7478
|
-
pinnedEntries: values.filter((entry) => entry.pins > 0).length,
|
|
7479
|
-
pins: values.reduce((total, entry) => total + entry.pins, 0)
|
|
7480
|
-
};
|
|
7481
|
-
}
|
|
7482
|
-
};
|
|
7483
|
-
}
|
|
7484
|
-
|
|
7485
|
-
// src/pi-resources/bundle-pin-lifecycle.ts
|
|
7486
|
-
function pinnedDigest(process2, turnStarts, turnRecords) {
|
|
7487
|
-
if (process2.currentExecution?.kind !== "worker_start") return null;
|
|
7488
|
-
const start = turnStarts.getById(process2.currentExecution.id);
|
|
7489
|
-
if (!start || start.instanceId !== process2.id || start.turnType !== "llm") return null;
|
|
7490
|
-
if (start.state.kind !== "starting" && start.state.kind !== "accepted") return null;
|
|
7491
|
-
if (start.state.start.kind !== "llm") return null;
|
|
7492
|
-
return start.state.kind === "starting" || turnRecords.getById(start.state.turnRecordId)?.status === "running" ? start.state.start.piResourceSnapshotDigest : null;
|
|
7493
|
-
}
|
|
7494
|
-
function createPiResourceBundlePinReconciler(deps) {
|
|
7495
|
-
const pinnedByInstance = /* @__PURE__ */ new Map();
|
|
7496
|
-
return {
|
|
7497
|
-
reconcile(process2) {
|
|
7498
|
-
const next = pinnedDigest(process2, deps.turnStarts, deps.turnRecords);
|
|
7499
|
-
const previous = pinnedByInstance.get(process2.id) ?? null;
|
|
7500
|
-
if (previous === next) {
|
|
7501
|
-
return { missingDigest: next && !deps.bundleCache.has(next) ? next : null };
|
|
7502
|
-
}
|
|
7503
|
-
if (previous) deps.bundleCache.unpin(previous);
|
|
7504
|
-
pinnedByInstance.delete(process2.id);
|
|
7505
|
-
if (!next) {
|
|
7506
|
-
return { missingDigest: null };
|
|
7507
|
-
}
|
|
7508
|
-
if (!deps.bundleCache.pin(next)) {
|
|
7509
|
-
return { missingDigest: next };
|
|
7510
|
-
}
|
|
7511
|
-
pinnedByInstance.set(process2.id, next);
|
|
7512
|
-
return { missingDigest: null };
|
|
7513
|
-
}
|
|
7514
|
-
};
|
|
7515
|
-
}
|
|
7516
|
-
|
|
7517
|
-
// src/process-deletion-service.ts
|
|
7518
|
-
var TERMINAL_STATUSES2 = /* @__PURE__ */ new Set(["completed", "aborted"]);
|
|
7519
|
-
var CLEANUP_FAILURE_MESSAGE = "The process could not be deleted; retry deletion";
|
|
7520
|
-
function createProcessDeletionService(deps) {
|
|
7521
|
-
return {
|
|
7522
|
-
async deleteProcess(instanceId, actor) {
|
|
7523
|
-
deps.deletionPending?.add(instanceId);
|
|
7524
|
-
try {
|
|
7525
|
-
const initial = deps.processes.getById(instanceId);
|
|
7526
|
-
if (!initial) return { ok: false, kind: "not_found" };
|
|
7527
|
-
deps.sessionTransfers?.revokeProcess(instanceId);
|
|
7528
|
-
if (!TERMINAL_STATUSES2.has(initial.lifecycleStatus)) {
|
|
7529
|
-
const aborted = await deps.processEngine.abortProcess(instanceId, { actor });
|
|
7530
|
-
if (!aborted.ok) return { ok: false, kind: "abort_failed", failure: aborted };
|
|
7531
|
-
}
|
|
7532
|
-
try {
|
|
7533
|
-
await deps.supervisor.stopWorker(instanceId, "process_deleted");
|
|
7534
|
-
return await deps.processOperations.runExclusive(instanceId, async () => {
|
|
7535
|
-
const process2 = deps.processes.getById(instanceId);
|
|
7536
|
-
if (!process2) return { ok: false, kind: "not_found" };
|
|
7537
|
-
if (!TERMINAL_STATUSES2.has(process2.lifecycleStatus)) {
|
|
7538
|
-
return { ok: false, kind: "cleanup_failed", message: CLEANUP_FAILURE_MESSAGE };
|
|
7539
|
-
}
|
|
7540
|
-
await Promise.all([
|
|
7541
|
-
deps.volume?.deleteProcessResources(instanceId),
|
|
7542
|
-
deps.sessionSnapshots.deleteSnapshot(instanceId),
|
|
7543
|
-
deps.resultImages.deleteProcess(instanceId)
|
|
7544
|
-
]);
|
|
7545
|
-
if (!deps.processes.delete(instanceId)) return { ok: false, kind: "not_found" };
|
|
7546
|
-
try {
|
|
7547
|
-
deps.broadcaster.sendDurable("process.deleted", { instanceId }, instanceId);
|
|
7548
|
-
} catch (error) {
|
|
7549
|
-
deps.logger?.error({ error, instanceId }, "process deletion broadcast failed");
|
|
7550
|
-
}
|
|
7551
|
-
return { ok: true };
|
|
7552
|
-
});
|
|
7553
|
-
} catch (error) {
|
|
7554
|
-
deps.logger?.error({ error, instanceId }, "process deletion cleanup failed");
|
|
7555
|
-
return { ok: false, kind: "cleanup_failed", message: CLEANUP_FAILURE_MESSAGE };
|
|
7556
|
-
}
|
|
7557
|
-
} finally {
|
|
7558
|
-
deps.deletionPending?.delete(instanceId);
|
|
7559
|
-
}
|
|
7560
|
-
}
|
|
7561
|
-
};
|
|
7562
|
-
}
|
|
7563
|
-
|
|
7564
|
-
// src/process-attention-notifier.ts
|
|
7565
|
-
function attentionDeps(deps) {
|
|
7566
|
-
return {
|
|
7567
|
-
projects: deps.projects,
|
|
7568
|
-
futureExecutions: deps.futureExecutions,
|
|
7569
|
-
turnRecords: deps.turnRecords,
|
|
7570
|
-
turnStarts: deps.turnStarts,
|
|
7571
|
-
processGraphs: deps.processGraphs,
|
|
7572
|
-
processActionRegistry: deps.getProcessActionRegistry?.(),
|
|
7573
|
-
broadcaster: deps.broadcaster,
|
|
7574
|
-
toastTtlMs: deps.toastTtlMs
|
|
7243
|
+
projects: deps.projects,
|
|
7244
|
+
futureExecutions: deps.futureExecutions,
|
|
7245
|
+
turnRecords: deps.turnRecords,
|
|
7246
|
+
turnStarts: deps.turnStarts,
|
|
7247
|
+
processGraphs: deps.processGraphs,
|
|
7248
|
+
processActionRegistry: deps.getProcessActionRegistry?.(),
|
|
7249
|
+
broadcaster: deps.broadcaster,
|
|
7250
|
+
toastTtlMs: deps.toastTtlMs
|
|
7575
7251
|
};
|
|
7576
7252
|
}
|
|
7577
7253
|
function maybeBroadcastActionRequiredToast(deps, result) {
|
|
@@ -7737,7 +7413,7 @@ var AbortProcess = defineOperation({
|
|
|
7737
7413
|
});
|
|
7738
7414
|
|
|
7739
7415
|
// src/process-engine/ops/abort-turn.ts
|
|
7740
|
-
import { SYSTEM_ACTOR as
|
|
7416
|
+
import { SYSTEM_ACTOR as SYSTEM_ACTOR3 } from "@leitwerk-dev/domain";
|
|
7741
7417
|
var AbortTurn = defineOperation({
|
|
7742
7418
|
kind: "abort_turn",
|
|
7743
7419
|
label: "Abort running turn",
|
|
@@ -7763,7 +7439,7 @@ var AbortTurn = defineOperation({
|
|
|
7763
7439
|
if (!supervisor.getWorker(ctx.process.id)) {
|
|
7764
7440
|
return reject("worker_unavailable", "No active worker is available to stop this turn");
|
|
7765
7441
|
}
|
|
7766
|
-
const actor = input.actor ??
|
|
7442
|
+
const actor = input.actor ?? SYSTEM_ACTOR3;
|
|
7767
7443
|
const writes = createWrites({ workerIntent: { kind: "abort_turn", reason: input.reason } });
|
|
7768
7444
|
appendProcessEvent(writes, ctx.process, {
|
|
7769
7445
|
eventType: "turn_abort_requested",
|
|
@@ -7917,7 +7593,7 @@ function readCurrentPrimaryPathLeafEntryId(stateJson) {
|
|
|
7917
7593
|
|
|
7918
7594
|
// src/process-engine/writes/build-continue-failed-turn-writes.ts
|
|
7919
7595
|
import {
|
|
7920
|
-
CONTINUE_PROMPT_METADATA_KEY
|
|
7596
|
+
CONTINUE_PROMPT_METADATA_KEY,
|
|
7921
7597
|
inferTerminalRecordingFailedTurnRecoveryContext,
|
|
7922
7598
|
normalizeContinuePrompt,
|
|
7923
7599
|
readFailedTurnRecoveryContext
|
|
@@ -7978,7 +7654,7 @@ function buildContinueFailedTurnWrites(input) {
|
|
|
7978
7654
|
if (!failedTurnRecovery) {
|
|
7979
7655
|
throw new Error(`Failed turn '${failedRun.id}' is missing recovery context`);
|
|
7980
7656
|
}
|
|
7981
|
-
const continuePrompt = normalizeContinuePrompt(input.prompt) ?? normalizeContinuePrompt(process2.metadata?.[
|
|
7657
|
+
const continuePrompt = normalizeContinuePrompt(input.prompt) ?? normalizeContinuePrompt(process2.metadata?.[CONTINUE_PROMPT_METADATA_KEY]) ?? failedTurnRecovery.suggestedContinuePrompt;
|
|
7982
7658
|
const currentPrimaryPathLeafEntryId = readCurrentPrimaryPathLeafEntryId(process2.stateJson);
|
|
7983
7659
|
const plan = buildRecoveryStartWrites(input, {
|
|
7984
7660
|
startKind: "continue",
|
|
@@ -7992,7 +7668,7 @@ function buildContinueFailedTurnWrites(input) {
|
|
|
7992
7668
|
updateProcessMetadata(plan, process2, ["retry"], (metadata) => {
|
|
7993
7669
|
metadata.continueFromTurnRecordId = failedRun.id;
|
|
7994
7670
|
metadata.continueFromPiEntryId = continueFromPiEntryId;
|
|
7995
|
-
metadata[
|
|
7671
|
+
metadata[CONTINUE_PROMPT_METADATA_KEY] = continuePrompt;
|
|
7996
7672
|
if (failedRun.pathType !== "primary" && currentPrimaryPathLeafEntryId && currentPrimaryPathLeafEntryId !== continueFromPiEntryId) {
|
|
7997
7673
|
metadata.continueSavedPrimaryLeafEntryId = currentPrimaryPathLeafEntryId;
|
|
7998
7674
|
} else {
|
|
@@ -8194,7 +7870,7 @@ var ParkDeferredProcessActivationFailure = defineOperation({
|
|
|
8194
7870
|
});
|
|
8195
7871
|
|
|
8196
7872
|
// src/process-engine/ops/execute-action.ts
|
|
8197
|
-
import { isProcessTurnType, SYSTEM_ACTOR as
|
|
7873
|
+
import { isProcessTurnType, SYSTEM_ACTOR as SYSTEM_ACTOR4 } from "@leitwerk-dev/domain";
|
|
8198
7874
|
import {
|
|
8199
7875
|
isLlmTurnDefinition as isLlmTurnDefinition2
|
|
8200
7876
|
} from "@leitwerk-dev/process-sdk";
|
|
@@ -8310,7 +7986,7 @@ var ExecuteAction = defineOperation({
|
|
|
8310
7986
|
async decide(ctx, input) {
|
|
8311
7987
|
const actionSource = input.opts?.source ?? "ui";
|
|
8312
7988
|
const actionOrigin = input.opts?.origin ?? DEFAULT_ACTION_ORIGIN_BY_SOURCE[actionSource];
|
|
8313
|
-
const actor = input.opts?.actor ??
|
|
7989
|
+
const actor = input.opts?.actor ?? SYSTEM_ACTOR4;
|
|
8314
7990
|
const scheduledAction = ctx.deps.futureExecutions.getScheduledActionByInstance(
|
|
8315
7991
|
input.instanceId
|
|
8316
7992
|
);
|
|
@@ -8850,7 +8526,7 @@ import {
|
|
|
8850
8526
|
areSemanticEntryRefsEqual as sameEntryRef
|
|
8851
8527
|
} from "@leitwerk-dev/domain";
|
|
8852
8528
|
import {
|
|
8853
|
-
isAutomaticTurnDefinition as
|
|
8529
|
+
isAutomaticTurnDefinition as isAutomaticTurnDefinition3,
|
|
8854
8530
|
isLlmTurnDefinition as isLlmTurnDefinition4,
|
|
8855
8531
|
parseStructuralProcessState
|
|
8856
8532
|
} from "@leitwerk-dev/process-sdk";
|
|
@@ -8964,7 +8640,7 @@ import {
|
|
|
8964
8640
|
trimString
|
|
8965
8641
|
} from "@leitwerk-dev/domain";
|
|
8966
8642
|
import {
|
|
8967
|
-
isAutomaticTurnDefinition,
|
|
8643
|
+
isAutomaticTurnDefinition as isAutomaticTurnDefinition2,
|
|
8968
8644
|
isLlmTurnDefinition as isLlmTurnDefinition3
|
|
8969
8645
|
} from "@leitwerk-dev/process-sdk";
|
|
8970
8646
|
import * as v3 from "valibot";
|
|
@@ -9056,7 +8732,7 @@ function resolveOutcomeValidationContract(turnDefinition, turnId, outcome) {
|
|
|
9056
8732
|
`'${turnId}' is not registered in the loaded turn catalog`
|
|
9057
8733
|
);
|
|
9058
8734
|
}
|
|
9059
|
-
if (!isLlmTurnDefinition3(turnDefinition) && !
|
|
8735
|
+
if (!isLlmTurnDefinition3(turnDefinition) && !isAutomaticTurnDefinition2(turnDefinition)) {
|
|
9060
8736
|
return validationFailure2(
|
|
9061
8737
|
"turn_outcome_unsupported",
|
|
9062
8738
|
`'${turnId}' does not support turn outcomes`
|
|
@@ -9300,17 +8976,17 @@ async function buildTurnOutcomeWrites(input) {
|
|
|
9300
8976
|
return effectWrites;
|
|
9301
8977
|
}
|
|
9302
8978
|
let writes = mergeWrites(baseWrites, effectWrites);
|
|
9303
|
-
let
|
|
9304
|
-
if (
|
|
8979
|
+
let candidateProcess = { ...input.process, ...writes.processPatch };
|
|
8980
|
+
if (candidateProcess.selectedTurnId === input.payload.turnId && candidateProcess.lifecycleStatus === "active" && !hasExplicitTurnSelectionChange(input.process, effectWrites)) {
|
|
9305
8981
|
const outcomeTransition = findOutcomeTransition(
|
|
9306
8982
|
input.processGraphs,
|
|
9307
|
-
|
|
8983
|
+
candidateProcess.processId,
|
|
9308
8984
|
input.payload.turnId,
|
|
9309
8985
|
input.payload.outcome
|
|
9310
8986
|
);
|
|
9311
8987
|
if (outcomeTransition) {
|
|
9312
|
-
const transitionWrites = buildTurnSelectionWrites(input.processGraphs,
|
|
9313
|
-
fromTurnId:
|
|
8988
|
+
const transitionWrites = buildTurnSelectionWrites(input.processGraphs, candidateProcess, {
|
|
8989
|
+
fromTurnId: candidateProcess.selectedTurnId,
|
|
9314
8990
|
toTurnId: outcomeTransition.toTurnId,
|
|
9315
8991
|
...outcomeTransition.lifecycleStatus !== void 0 ? { lifecycleStatus: outcomeTransition.lifecycleStatus } : {},
|
|
9316
8992
|
state: void 0
|
|
@@ -9319,7 +8995,7 @@ async function buildTurnOutcomeWrites(input) {
|
|
|
9319
8995
|
return transitionWrites;
|
|
9320
8996
|
}
|
|
9321
8997
|
writes = mergeWrites(writes, transitionWrites);
|
|
9322
|
-
|
|
8998
|
+
candidateProcess = { ...candidateProcess, ...transitionWrites.processPatch };
|
|
9323
8999
|
}
|
|
9324
9000
|
}
|
|
9325
9001
|
writes.extensionEvents.push(
|
|
@@ -9410,7 +9086,7 @@ function validatePublishedProductOutcome(input) {
|
|
|
9410
9086
|
}
|
|
9411
9087
|
function resolveOutcomePublication(input) {
|
|
9412
9088
|
const definition = input.processGraphs.get(input.processId)?.turns.get(input.turnId)?.definition;
|
|
9413
|
-
if (!definition || !isLlmTurnDefinition4(definition) && !
|
|
9089
|
+
if (!definition || !isLlmTurnDefinition4(definition) && !isAutomaticTurnDefinition3(definition)) {
|
|
9414
9090
|
return { productName: input.turnPublishedProduct, markdownParameterName: null };
|
|
9415
9091
|
}
|
|
9416
9092
|
const outcome = definition.outcomes?.[input.outcome];
|
|
@@ -9618,9 +9294,9 @@ var TurnOutcome = defineOperation({
|
|
|
9618
9294
|
if (ctx.process.lifecycleStatus === "error") {
|
|
9619
9295
|
applyProcessPatchField(baseWrites, ctx.process, "lifecycleStatus", "active");
|
|
9620
9296
|
}
|
|
9621
|
-
const
|
|
9297
|
+
const candidateProcess = { ...ctx.process, ...baseWrites.processPatch };
|
|
9622
9298
|
const outcomeWrites = await buildTurnOutcomeWrites({
|
|
9623
|
-
process:
|
|
9299
|
+
process: candidateProcess,
|
|
9624
9300
|
projects,
|
|
9625
9301
|
payload,
|
|
9626
9302
|
turnRecords: ctx.deps.turnRecords,
|
|
@@ -10256,23 +9932,23 @@ function buildRecordedDecision(input) {
|
|
|
10256
9932
|
async function record2(deps, operation, input, initialProcess, decision) {
|
|
10257
9933
|
const baselineWrites = structuredClone(decision.writes);
|
|
10258
9934
|
const runModelPreparation = async (availability) => {
|
|
10259
|
-
const
|
|
9935
|
+
const candidateProcess = {
|
|
10260
9936
|
...initialProcess,
|
|
10261
9937
|
...decision.writes.processPatch
|
|
10262
9938
|
};
|
|
10263
9939
|
const createdStart = decision.writes.turnStartWrites.find(
|
|
10264
9940
|
(write) => write.kind === "create" && write.input.turnType === "llm"
|
|
10265
9941
|
);
|
|
10266
|
-
const shouldResolveSelection = !!
|
|
10267
|
-
if (!
|
|
9942
|
+
const shouldResolveSelection = !!candidateProcess.selectedTurnId && (!!createdStart || candidateProcess.selectedTurnId !== initialProcess.selectedTurnId || candidateProcess.lifecycleStatus === "active" && initialProcess.lifecycleStatus !== "active" || Object.hasOwn(decision.metadata ?? {}, "nextTurnModelProfileId"));
|
|
9943
|
+
if (!candidateProcess.selectedTurnId) {
|
|
10268
9944
|
applyProcessPatchField(decision.writes, initialProcess, "selectedTurnModelProfileId", null);
|
|
10269
9945
|
applyProcessPatchField(decision.writes, initialProcess, "selectedTurnModelKind", null);
|
|
10270
9946
|
applyProcessPatchField(decision.writes, initialProcess, "selectedTurnModelSource", null);
|
|
10271
|
-
} else if (shouldResolveSelection &&
|
|
9947
|
+
} else if (shouldResolveSelection && candidateProcess.selectedTurnId) {
|
|
10272
9948
|
const resolution = deps.processModelPolicy.evaluate({
|
|
10273
9949
|
kind: "process_turn",
|
|
10274
|
-
process:
|
|
10275
|
-
turnId:
|
|
9950
|
+
process: candidateProcess,
|
|
9951
|
+
turnId: candidateProcess.selectedTurnId,
|
|
10276
9952
|
availability,
|
|
10277
9953
|
startKind: createdStart?.input.startKind,
|
|
10278
9954
|
initialSelection: createdStart?.input.startKind === "selected_turn" && initialProcess.selectedTurnId === null && initialProcess.lifecycleStatus === "discovered" && initialProcess.planRevision === 0,
|
|
@@ -10281,7 +9957,7 @@ async function record2(deps, operation, input, initialProcess, decision) {
|
|
|
10281
9957
|
if (!resolution.ok && resolution.code !== "model_unavailable" && resolution.code !== "model_stale" && resolution.code !== "model_required") {
|
|
10282
9958
|
const message = presentProcessModelPolicyFailure(resolution);
|
|
10283
9959
|
if (createdStart) {
|
|
10284
|
-
parkInvalidModelConfiguration(decision.writes, createdStart,
|
|
9960
|
+
parkInvalidModelConfiguration(decision.writes, createdStart, candidateProcess, message);
|
|
10285
9961
|
return { ok: true };
|
|
10286
9962
|
}
|
|
10287
9963
|
return {
|
|
@@ -10421,27 +10097,27 @@ function resolveMessages(operation, input) {
|
|
|
10421
10097
|
function shouldReportBestEffortFailures(operation, input) {
|
|
10422
10098
|
return typeof operation.reportBestEffortFailures === "function" ? operation.reportBestEffortFailures(input) : operation.reportBestEffortFailures === true;
|
|
10423
10099
|
}
|
|
10424
|
-
function mapPreCommitFailure(
|
|
10100
|
+
function mapPreCommitFailure(failure, initialProcess) {
|
|
10425
10101
|
return {
|
|
10426
10102
|
ok: false,
|
|
10427
|
-
code:
|
|
10103
|
+
code: failure.code,
|
|
10428
10104
|
message: publicEngineFailureMessage({
|
|
10429
|
-
code:
|
|
10430
|
-
message:
|
|
10105
|
+
code: failure.code,
|
|
10106
|
+
message: failure.message,
|
|
10431
10107
|
stage: "pre_commit"
|
|
10432
10108
|
}),
|
|
10433
10109
|
...initialProcess ? { process: initialProcess } : {},
|
|
10434
|
-
...
|
|
10110
|
+
...failure.data !== void 0 ? { data: failure.data } : {},
|
|
10435
10111
|
stage: "pre_commit"
|
|
10436
10112
|
};
|
|
10437
10113
|
}
|
|
10438
|
-
function mapPostCommitFailure(recorded,
|
|
10114
|
+
function mapPostCommitFailure(recorded, failure) {
|
|
10439
10115
|
return {
|
|
10440
10116
|
ok: false,
|
|
10441
|
-
code:
|
|
10117
|
+
code: failure.code,
|
|
10442
10118
|
message: publicEngineFailureMessage({
|
|
10443
|
-
code:
|
|
10444
|
-
message:
|
|
10119
|
+
code: failure.code,
|
|
10120
|
+
message: failure.message,
|
|
10445
10121
|
stage: "post_commit"
|
|
10446
10122
|
}),
|
|
10447
10123
|
process: recorded.process,
|
|
@@ -10687,8 +10363,8 @@ function createProcessEngine(deps) {
|
|
|
10687
10363
|
activateDeferredProcess(instanceId, prepared) {
|
|
10688
10364
|
return run(ActivateDeferredProcess, { instanceId, prepared });
|
|
10689
10365
|
},
|
|
10690
|
-
parkDeferredProcessActivationFailure(instanceId,
|
|
10691
|
-
return run(ParkDeferredProcessActivationFailure, { instanceId, failure
|
|
10366
|
+
parkDeferredProcessActivationFailure(instanceId, failure) {
|
|
10367
|
+
return run(ParkDeferredProcessActivationFailure, { instanceId, failure });
|
|
10692
10368
|
},
|
|
10693
10369
|
startProcess(instanceId, startTurnId, opts) {
|
|
10694
10370
|
return run(StartProcess, { instanceId, startTurnId, actor: opts?.actor });
|
|
@@ -11054,309 +10730,6 @@ async function reconcileProcessesOnStartup(deps) {
|
|
|
11054
10730
|
);
|
|
11055
10731
|
}
|
|
11056
10732
|
|
|
11057
|
-
// src/process-engine/turn-start-preflight.ts
|
|
11058
|
-
import { filterProviderOptionsForDefinition } from "@leitwerk-dev/process-sdk";
|
|
11059
|
-
import { IPC_PROTOCOL_VERSION, WORKER_API_VERSION } from "@leitwerk-dev/worker-protocol";
|
|
11060
|
-
|
|
11061
|
-
// src/worker-runtime-profile-selection.ts
|
|
11062
|
-
function trimToUndefined(value) {
|
|
11063
|
-
if (typeof value !== "string") {
|
|
11064
|
-
return void 0;
|
|
11065
|
-
}
|
|
11066
|
-
const trimmed = value.trim();
|
|
11067
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
11068
|
-
}
|
|
11069
|
-
function defaultWorkerRuntimeProfile(config) {
|
|
11070
|
-
if (config.workers.runner === "local") {
|
|
11071
|
-
return config.workers.default_runtime_profile ?? "local";
|
|
11072
|
-
}
|
|
11073
|
-
return (config.workers.runner === "kubernetes" ? config.kubernetes?.default_worker_runtime_profile : void 0) ?? config.workers.default_runtime_profile ?? null;
|
|
11074
|
-
}
|
|
11075
|
-
function selectWorkerRuntimeProfile(input) {
|
|
11076
|
-
const override = trimToUndefined(input.processOverride);
|
|
11077
|
-
if (override) {
|
|
11078
|
-
return resolveProfileImage(override, input.profiles);
|
|
11079
|
-
}
|
|
11080
|
-
const declared = input.componentProfiles.map((entry) => ({ component: entry.component, profile: trimToUndefined(entry.profile) })).filter(
|
|
11081
|
-
(entry) => entry.profile !== void 0
|
|
11082
|
-
);
|
|
11083
|
-
const distinct = new Set(declared.map((entry) => entry.profile));
|
|
11084
|
-
if (distinct.size > 1) {
|
|
11085
|
-
const summary = declared.map((entry) => `${entry.component}=${entry.profile}`).sort().join(", ");
|
|
11086
|
-
return {
|
|
11087
|
-
ok: false,
|
|
11088
|
-
error: `Process '${input.processId}' has conflicting component worker runtime profiles (${summary}); set process_configs.${input.processId}.worker_runtime_profile to resolve`
|
|
11089
|
-
};
|
|
11090
|
-
}
|
|
11091
|
-
if (distinct.size === 1) {
|
|
11092
|
-
const [only] = distinct;
|
|
11093
|
-
return resolveProfileImage(only, input.profiles);
|
|
11094
|
-
}
|
|
11095
|
-
const fallback = trimToUndefined(input.defaultProfile);
|
|
11096
|
-
if (!fallback) {
|
|
11097
|
-
return {
|
|
11098
|
-
ok: false,
|
|
11099
|
-
error: `Process '${input.processId}' selects no worker runtime profile and no default worker runtime profile is configured`
|
|
11100
|
-
};
|
|
11101
|
-
}
|
|
11102
|
-
return resolveProfileImage(fallback, input.profiles);
|
|
11103
|
-
}
|
|
11104
|
-
function resolveProfileImage(runtimeProfile, profiles) {
|
|
11105
|
-
const profile = profiles[runtimeProfile];
|
|
11106
|
-
if (!profile) {
|
|
11107
|
-
return {
|
|
11108
|
-
ok: false,
|
|
11109
|
-
error: `Unknown worker runtime profile '${runtimeProfile}'; configure it under worker_runtime_profiles`
|
|
11110
|
-
};
|
|
11111
|
-
}
|
|
11112
|
-
return {
|
|
11113
|
-
ok: true,
|
|
11114
|
-
runtimeProfile,
|
|
11115
|
-
image: { reference: profile.image }
|
|
11116
|
-
};
|
|
11117
|
-
}
|
|
11118
|
-
function buildRuntimeProfileSelectionInput(args) {
|
|
11119
|
-
const { config, processId, componentKeys } = args;
|
|
11120
|
-
const componentProfiles = componentKeys.map((component) => ({
|
|
11121
|
-
component,
|
|
11122
|
-
profile: config.components[component]?.worker_runtime_profile
|
|
11123
|
-
}));
|
|
11124
|
-
return {
|
|
11125
|
-
processId,
|
|
11126
|
-
processOverride: config.process_configs?.[processId]?.worker_runtime_profile,
|
|
11127
|
-
componentProfiles,
|
|
11128
|
-
defaultProfile: defaultWorkerRuntimeProfile(config) ?? void 0,
|
|
11129
|
-
profiles: config.worker_runtime_profiles ?? {}
|
|
11130
|
-
};
|
|
11131
|
-
}
|
|
11132
|
-
|
|
11133
|
-
// src/process-engine/turn-start-preflight.ts
|
|
11134
|
-
var PI_RUNTIME_VERSION = "0.81.1";
|
|
11135
|
-
function failure(requestedModelProfileId, providerOptions, code, safeSummary, modelSelectionProvenance, availabilityRevision) {
|
|
11136
|
-
return {
|
|
11137
|
-
kind: "preparation_failed",
|
|
11138
|
-
requestedModelProfileId,
|
|
11139
|
-
providerOptions,
|
|
11140
|
-
code,
|
|
11141
|
-
safeSummary,
|
|
11142
|
-
...modelSelectionProvenance ? { modelSelectionProvenance } : {},
|
|
11143
|
-
...availabilityRevision !== void 0 ? { availabilityRevision } : {}
|
|
11144
|
-
};
|
|
11145
|
-
}
|
|
11146
|
-
function previousProviderOptions(state) {
|
|
11147
|
-
if (state.kind === "preparation_failed") return { ...state.providerOptions };
|
|
11148
|
-
if (state.kind === "superseded" || state.kind === "starting" || state.kind === "accepted") {
|
|
11149
|
-
return state.start?.kind === "llm" ? { ...state.start.providerOptions } : {};
|
|
11150
|
-
}
|
|
11151
|
-
return state.start.kind === "llm" ? { ...state.start.providerOptions } : {};
|
|
11152
|
-
}
|
|
11153
|
-
function previousProviderId(deps, state) {
|
|
11154
|
-
if (state.kind !== "preparation_failed") {
|
|
11155
|
-
return state.start?.kind === "llm" ? state.start.model.providerId : null;
|
|
11156
|
-
}
|
|
11157
|
-
const profileId = state.requestedModelProfileId;
|
|
11158
|
-
return profileId ? deps.config.pi.model_profiles.find((profile) => profile.id === profileId)?.provider ?? null : null;
|
|
11159
|
-
}
|
|
11160
|
-
function parkPreparationFailure(writes, write, state) {
|
|
11161
|
-
write.input.state = state;
|
|
11162
|
-
writes.processPatch.lifecycleStatus = "error";
|
|
11163
|
-
writes.workerIntent = { kind: "reconcile" };
|
|
11164
|
-
}
|
|
11165
|
-
function candidateProcess(process2, writes) {
|
|
11166
|
-
return { ...process2, ...writes.processPatch };
|
|
11167
|
-
}
|
|
11168
|
-
function resolveRuntimeProfile(deps, process2) {
|
|
11169
|
-
if (deps.config.workers.runner === "local") {
|
|
11170
|
-
return { ok: true, id: defaultWorkerRuntimeProfile(deps.config) ?? "local" };
|
|
11171
|
-
}
|
|
11172
|
-
const selection = selectWorkerRuntimeProfile(
|
|
11173
|
-
buildRuntimeProfileSelectionInput({
|
|
11174
|
-
config: deps.config,
|
|
11175
|
-
processId: process2.processId,
|
|
11176
|
-
componentKeys: deps.projects.listByInstance(process2.id).map((project) => project.key)
|
|
11177
|
-
})
|
|
11178
|
-
);
|
|
11179
|
-
return selection.ok ? { ok: true, id: selection.runtimeProfile } : { ok: false, message: selection.error };
|
|
11180
|
-
}
|
|
11181
|
-
function resolveProviderWorkerConfig(provider, options) {
|
|
11182
|
-
if (provider.definition.worker.kind !== "extension_pi_worker") return null;
|
|
11183
|
-
const definition = provider.definition.worker.config;
|
|
11184
|
-
if (!definition) return null;
|
|
11185
|
-
const projected = definition.resolve({ config: provider.config, options });
|
|
11186
|
-
const value = definition.schema.parse(projected);
|
|
11187
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
11188
|
-
throw new Error("Provider worker configuration must be a JSON object");
|
|
11189
|
-
}
|
|
11190
|
-
return { version: definition.version, value };
|
|
11191
|
-
}
|
|
11192
|
-
function resolveProviderPiModels(provider) {
|
|
11193
|
-
const worker = provider.definition.worker;
|
|
11194
|
-
return worker.kind === "configured_pi_provider" ? worker.resolveModels({ config: provider.config }) : { providers: {} };
|
|
11195
|
-
}
|
|
11196
|
-
function buildPiSettings(config) {
|
|
11197
|
-
return {
|
|
11198
|
-
retry: {
|
|
11199
|
-
enabled: config.pi.retry.enabled,
|
|
11200
|
-
maxRetries: config.pi.retry.max_retries,
|
|
11201
|
-
baseDelay: config.pi.retry.base_delay,
|
|
11202
|
-
provider: {
|
|
11203
|
-
timeout: config.pi.retry.provider.timeout,
|
|
11204
|
-
maxRetries: config.pi.retry.provider.max_retries,
|
|
11205
|
-
maxRetryDelay: config.pi.retry.provider.max_retry_delay
|
|
11206
|
-
}
|
|
11207
|
-
}
|
|
11208
|
-
};
|
|
11209
|
-
}
|
|
11210
|
-
async function prepareCreatedTurnStarts(deps, process2, writes, explicitProviderOptions, availabilitySnapshot) {
|
|
11211
|
-
const nextProcess = candidateProcess(process2, writes);
|
|
11212
|
-
const availability = availabilitySnapshot ?? deps.modelStatusCache.snapshot();
|
|
11213
|
-
const provenance = nextProcess.selectedTurnModelKind && nextProcess.selectedTurnModelSource ? {
|
|
11214
|
-
kind: nextProcess.selectedTurnModelKind,
|
|
11215
|
-
source: nextProcess.selectedTurnModelSource
|
|
11216
|
-
} : void 0;
|
|
11217
|
-
for (let index = 0; index < writes.turnStartWrites.length; index += 1) {
|
|
11218
|
-
const write = writes.turnStartWrites[index];
|
|
11219
|
-
if (!write || write.kind !== "create" || write.input.turnType !== "llm") continue;
|
|
11220
|
-
const requestedProfileId = nextProcess.selectedTurnModelProfileId?.trim() || null;
|
|
11221
|
-
const retainedState = write.input.state;
|
|
11222
|
-
const retainedOptions = previousProviderOptions(retainedState);
|
|
11223
|
-
if (retainedState.kind === "preparation_failed" && retainedState.code === "invalid_model_configuration") {
|
|
11224
|
-
parkPreparationFailure(writes, write, retainedState);
|
|
11225
|
-
continue;
|
|
11226
|
-
}
|
|
11227
|
-
if (!requestedProfileId) {
|
|
11228
|
-
parkPreparationFailure(
|
|
11229
|
-
writes,
|
|
11230
|
-
write,
|
|
11231
|
-
failure(
|
|
11232
|
-
null,
|
|
11233
|
-
retainedOptions,
|
|
11234
|
-
"model_required",
|
|
11235
|
-
"Choose a model before retrying startup",
|
|
11236
|
-
void 0,
|
|
11237
|
-
availability.revision
|
|
11238
|
-
)
|
|
11239
|
-
);
|
|
11240
|
-
continue;
|
|
11241
|
-
}
|
|
11242
|
-
const profile = deps.config.pi.model_profiles.find((item) => item.id === requestedProfileId);
|
|
11243
|
-
if (!profile) {
|
|
11244
|
-
return {
|
|
11245
|
-
ok: false,
|
|
11246
|
-
code: "invalid_model_profile",
|
|
11247
|
-
message: `Unknown model profile '${requestedProfileId}'`
|
|
11248
|
-
};
|
|
11249
|
-
}
|
|
11250
|
-
const provider = deps.registry.require(profile.provider);
|
|
11251
|
-
const retainedProviderId = previousProviderId(deps, retainedState);
|
|
11252
|
-
const recoveryOptions = explicitProviderOptions ? { ...explicitProviderOptions } : retainedProviderId !== null && retainedProviderId !== provider.id ? {
|
|
11253
|
-
...filterProviderOptionsForDefinition(provider.definition.options, retainedOptions)
|
|
11254
|
-
} : retainedOptions;
|
|
11255
|
-
const optionResult = resolveRegisteredProviderOptions({
|
|
11256
|
-
provider,
|
|
11257
|
-
explicit: recoveryOptions,
|
|
11258
|
-
profileDefaults: profile.provider_options ?? {}
|
|
11259
|
-
});
|
|
11260
|
-
if (!optionResult.ok) {
|
|
11261
|
-
const onlyRequired = optionResult.issues.every((issue) => issue.code === "required");
|
|
11262
|
-
if (!onlyRequired) {
|
|
11263
|
-
return {
|
|
11264
|
-
ok: false,
|
|
11265
|
-
code: "invalid_provider_options",
|
|
11266
|
-
message: optionResult.issues.map((issue) => issue.message).join("; ")
|
|
11267
|
-
};
|
|
11268
|
-
}
|
|
11269
|
-
parkPreparationFailure(
|
|
11270
|
-
writes,
|
|
11271
|
-
write,
|
|
11272
|
-
failure(
|
|
11273
|
-
profile.id,
|
|
11274
|
-
recoveryOptions,
|
|
11275
|
-
"provider_options_required",
|
|
11276
|
-
optionResult.issues.map((issue) => issue.message).join("; ")
|
|
11277
|
-
)
|
|
11278
|
-
);
|
|
11279
|
-
continue;
|
|
11280
|
-
}
|
|
11281
|
-
const status = availability.profiles.find((candidate) => candidate.profileId === profile.id);
|
|
11282
|
-
if (!status || status.availability !== "available") {
|
|
11283
|
-
parkPreparationFailure(
|
|
11284
|
-
writes,
|
|
11285
|
-
write,
|
|
11286
|
-
failure(
|
|
11287
|
-
profile.id,
|
|
11288
|
-
recoveryOptions,
|
|
11289
|
-
!status || status.availability === "stale" ? "model_stale" : "model_unavailable",
|
|
11290
|
-
status?.safeReason ?? "The selected model status is stale",
|
|
11291
|
-
provenance,
|
|
11292
|
-
availability.revision
|
|
11293
|
-
)
|
|
11294
|
-
);
|
|
11295
|
-
continue;
|
|
11296
|
-
}
|
|
11297
|
-
try {
|
|
11298
|
-
const runtimeProfile = resolveRuntimeProfile(deps, nextProcess);
|
|
11299
|
-
if (!runtimeProfile.ok) throw new Error(runtimeProfile.message);
|
|
11300
|
-
const providerWorkerConfig = resolveProviderWorkerConfig(provider, optionResult.value);
|
|
11301
|
-
const piSettings = buildPiSettings(deps.config);
|
|
11302
|
-
const model = {
|
|
11303
|
-
profileId: profile.id,
|
|
11304
|
-
providerId: profile.provider,
|
|
11305
|
-
modelId: profile.model_id,
|
|
11306
|
-
thinkingLevel: profile.thinking_level ?? "off"
|
|
11307
|
-
};
|
|
11308
|
-
const resourceLayers = deps.processSkills.listResourceLayers(nextProcess.id);
|
|
11309
|
-
const assembled = await assemblePiResourceSnapshot({
|
|
11310
|
-
resourceLayers,
|
|
11311
|
-
piContributions: deps.piContributions,
|
|
11312
|
-
model,
|
|
11313
|
-
providerOptions: optionResult.value,
|
|
11314
|
-
providerWorkerConfig,
|
|
11315
|
-
piSettings,
|
|
11316
|
-
piModels: resolveProviderPiModels(provider),
|
|
11317
|
-
declaredCredentialPaths: [
|
|
11318
|
-
"auth.json",
|
|
11319
|
-
...provider.definition.worker.kind === "extension_pi_worker" ? provider.definition.worker.credentialFiles ?? [] : []
|
|
11320
|
-
],
|
|
11321
|
-
compatibility: {
|
|
11322
|
-
workerApiVersion: WORKER_API_VERSION,
|
|
11323
|
-
piVersion: PI_RUNTIME_VERSION,
|
|
11324
|
-
protocolVersion: IPC_PROTOCOL_VERSION
|
|
11325
|
-
}
|
|
11326
|
-
});
|
|
11327
|
-
deps.bundleCache.put(assembled.bundle);
|
|
11328
|
-
write.input.state = {
|
|
11329
|
-
kind: "starting",
|
|
11330
|
-
start: {
|
|
11331
|
-
kind: "llm",
|
|
11332
|
-
model,
|
|
11333
|
-
...provenance ? { modelSelectionProvenance: provenance } : {},
|
|
11334
|
-
availabilityRevision: availability.revision,
|
|
11335
|
-
providerOptions: { ...optionResult.value },
|
|
11336
|
-
providerWorkerConfig,
|
|
11337
|
-
piResourceSnapshotDigest: assembled.bundle.digest,
|
|
11338
|
-
workerRuntimeProfileId: runtimeProfile.id,
|
|
11339
|
-
piSettings
|
|
11340
|
-
}
|
|
11341
|
-
};
|
|
11342
|
-
writes.processPatch.lifecycleStatus = "active";
|
|
11343
|
-
writes.workerIntent = { kind: "restart_worker" };
|
|
11344
|
-
} catch {
|
|
11345
|
-
parkPreparationFailure(
|
|
11346
|
-
writes,
|
|
11347
|
-
write,
|
|
11348
|
-
failure(
|
|
11349
|
-
profile.id,
|
|
11350
|
-
{ ...optionResult.value },
|
|
11351
|
-
"provider_preflight_failed",
|
|
11352
|
-
"The provider could not prepare this worker start"
|
|
11353
|
-
)
|
|
11354
|
-
);
|
|
11355
|
-
}
|
|
11356
|
-
}
|
|
11357
|
-
return { ok: true };
|
|
11358
|
-
}
|
|
11359
|
-
|
|
11360
10733
|
// src/process-launcher-registry.ts
|
|
11361
10734
|
import { buildProcessLaunchers } from "@leitwerk-dev/process-sdk";
|
|
11362
10735
|
|
|
@@ -11860,7 +11233,9 @@ function createProcessQuestionService(input) {
|
|
|
11860
11233
|
});
|
|
11861
11234
|
};
|
|
11862
11235
|
return {
|
|
11236
|
+
/** @internal */
|
|
11863
11237
|
listOpen: (instanceId) => input.repos.questionRequests.listOpen(instanceId),
|
|
11238
|
+
/** @internal */
|
|
11864
11239
|
async handleWorkerRequest(instanceId, workerLeaseId, workerId, payload) {
|
|
11865
11240
|
const result = await input.processOperations.runExclusive(
|
|
11866
11241
|
instanceId,
|
|
@@ -11916,6 +11291,7 @@ function createProcessQuestionService(input) {
|
|
|
11916
11291
|
instanceId
|
|
11917
11292
|
);
|
|
11918
11293
|
},
|
|
11294
|
+
/** @internal */
|
|
11919
11295
|
async submitAnswers(instanceId, requestId, draftInput, actor) {
|
|
11920
11296
|
try {
|
|
11921
11297
|
const result = await input.processOperations.runExclusive(
|
|
@@ -11955,7 +11331,10 @@ function createProcessQuestionService(input) {
|
|
|
11955
11331
|
eventType: "question_answered",
|
|
11956
11332
|
data: { requestId: request.id, actorId: actor.id }
|
|
11957
11333
|
});
|
|
11958
|
-
return {
|
|
11334
|
+
return {
|
|
11335
|
+
ok: true,
|
|
11336
|
+
request: answered
|
|
11337
|
+
};
|
|
11959
11338
|
})
|
|
11960
11339
|
);
|
|
11961
11340
|
if (!result.ok) return result;
|
|
@@ -11983,12 +11362,12 @@ import { parseDurationMs as parseDurationMs2 } from "@leitwerk-dev/watcher-utils
|
|
|
11983
11362
|
import { preflightHostDocker } from "@leitwerk-dev/worker-runners/local";
|
|
11984
11363
|
function resolveKubernetesDockerConfig(config) {
|
|
11985
11364
|
const docker = config.kubernetes?.docker;
|
|
11986
|
-
if (!docker?.runtime_class_name?.trim() || typeof docker.host_users !== "boolean" || !docker.process_storage_class_name?.trim()) {
|
|
11365
|
+
if (!docker?.runtime_class_name?.trim() || (docker.gvisor ? docker.host_users !== void 0 : typeof docker.host_users !== "boolean") || !docker.process_storage_class_name?.trim()) {
|
|
11987
11366
|
return void 0;
|
|
11988
11367
|
}
|
|
11989
11368
|
return {
|
|
11990
11369
|
runtimeClassName: docker.runtime_class_name,
|
|
11991
|
-
hostUsers: docker.host_users,
|
|
11370
|
+
...docker.gvisor ? { gvisor: true } : { hostUsers: docker.host_users },
|
|
11992
11371
|
processStorageClassName: docker.process_storage_class_name,
|
|
11993
11372
|
...docker.network ? { network: docker.network } : {}
|
|
11994
11373
|
};
|
|
@@ -12936,7 +12315,7 @@ var RepositoryCredentialService = class {
|
|
|
12936
12315
|
// src/result-image-store.ts
|
|
12937
12316
|
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
12938
12317
|
import { mkdir, readdir, readFile as readFile2, rename, rm, writeFile } from "node:fs/promises";
|
|
12939
|
-
import
|
|
12318
|
+
import path2 from "node:path";
|
|
12940
12319
|
import {
|
|
12941
12320
|
isResultImageStorageSegment,
|
|
12942
12321
|
parseResultImageId
|
|
@@ -12952,22 +12331,25 @@ var MIME_BY_EXTENSION = {
|
|
|
12952
12331
|
webp: "image/webp"
|
|
12953
12332
|
};
|
|
12954
12333
|
var ResultImageStore = class {
|
|
12334
|
+
/** @internal */
|
|
12955
12335
|
rootDir;
|
|
12336
|
+
/** @internal */
|
|
12956
12337
|
constructor(input) {
|
|
12957
|
-
this.rootDir =
|
|
12338
|
+
this.rootDir = path2.resolve(input.rootDir);
|
|
12958
12339
|
}
|
|
12959
12340
|
turnDir(instanceId, turnRecordId) {
|
|
12960
12341
|
if (!isResultImageStorageSegment(instanceId) || !isResultImageStorageSegment(turnRecordId))
|
|
12961
12342
|
throw new Error("Invalid result image storage id");
|
|
12962
|
-
return
|
|
12343
|
+
return path2.join(this.rootDir, instanceId, turnRecordId);
|
|
12963
12344
|
}
|
|
12345
|
+
/** @internal */
|
|
12964
12346
|
async put(input) {
|
|
12965
12347
|
const dir = this.turnDir(input.instanceId, input.turnRecordId);
|
|
12966
12348
|
await mkdir(dir, { recursive: true });
|
|
12967
12349
|
const digest = createHash2("sha256").update(input.bytes).digest("hex");
|
|
12968
12350
|
const imageId = `img_${digest}.${EXTENSIONS[input.mimeType]}`;
|
|
12969
|
-
const destination =
|
|
12970
|
-
const temporary =
|
|
12351
|
+
const destination = path2.join(dir, imageId);
|
|
12352
|
+
const temporary = path2.join(dir, `.${imageId}.${randomUUID2()}.tmp`);
|
|
12971
12353
|
try {
|
|
12972
12354
|
await writeFile(temporary, input.bytes, { flag: "wx" });
|
|
12973
12355
|
await rename(temporary, destination);
|
|
@@ -12976,11 +12358,13 @@ var ResultImageStore = class {
|
|
|
12976
12358
|
}
|
|
12977
12359
|
return { imageId, mimeType: input.mimeType, byteSize: input.bytes.length };
|
|
12978
12360
|
}
|
|
12361
|
+
/** @internal */
|
|
12979
12362
|
async deleteProcess(instanceId) {
|
|
12980
12363
|
if (!isResultImageStorageSegment(instanceId))
|
|
12981
12364
|
throw new Error("Invalid result image storage id");
|
|
12982
|
-
await rm(
|
|
12365
|
+
await rm(path2.join(this.rootDir, instanceId), { recursive: true, force: true });
|
|
12983
12366
|
}
|
|
12367
|
+
/** @internal */
|
|
12984
12368
|
async cleanupProcesses(input) {
|
|
12985
12369
|
let entries;
|
|
12986
12370
|
try {
|
|
@@ -12993,16 +12377,17 @@ var ResultImageStore = class {
|
|
|
12993
12377
|
for (const entry of entries) {
|
|
12994
12378
|
if (!entry.isDirectory() || !isResultImageStorageSegment(entry.name) || input.retainedInstanceIds.has(entry.name) && !input.expiredInstanceIds?.has(entry.name))
|
|
12995
12379
|
continue;
|
|
12996
|
-
await rm(
|
|
12380
|
+
await rm(path2.join(this.rootDir, entry.name), { recursive: true, force: true });
|
|
12997
12381
|
removed.push(entry.name);
|
|
12998
12382
|
}
|
|
12999
12383
|
return removed;
|
|
13000
12384
|
}
|
|
12385
|
+
/** @internal */
|
|
13001
12386
|
async get(instanceId, turnRecordId, imageId) {
|
|
13002
12387
|
const extension = parseResultImageId(imageId)?.extension;
|
|
13003
12388
|
if (!extension) return null;
|
|
13004
12389
|
try {
|
|
13005
|
-
const bytes = await readFile2(
|
|
12390
|
+
const bytes = await readFile2(path2.join(this.turnDir(instanceId, turnRecordId), imageId));
|
|
13006
12391
|
return {
|
|
13007
12392
|
metadata: { imageId, mimeType: MIME_BY_EXTENSION[extension], byteSize: bytes.length },
|
|
13008
12393
|
bytes
|
|
@@ -13014,10 +12399,142 @@ var ResultImageStore = class {
|
|
|
13014
12399
|
}
|
|
13015
12400
|
};
|
|
13016
12401
|
|
|
13017
|
-
// src/server-bootstrap/
|
|
13018
|
-
|
|
13019
|
-
|
|
13020
|
-
|
|
12402
|
+
// src/server-bootstrap/app-lifecycle.ts
|
|
12403
|
+
async function collectCleanupErrors(operations) {
|
|
12404
|
+
const errors = [];
|
|
12405
|
+
for (const operation of [...operations].reverse()) {
|
|
12406
|
+
try {
|
|
12407
|
+
await operation();
|
|
12408
|
+
} catch (error) {
|
|
12409
|
+
errors.push(error);
|
|
12410
|
+
}
|
|
12411
|
+
}
|
|
12412
|
+
return errors;
|
|
12413
|
+
}
|
|
12414
|
+
function createAppLifecycle(input) {
|
|
12415
|
+
const { app } = input;
|
|
12416
|
+
let closing = false;
|
|
12417
|
+
let closePromise;
|
|
12418
|
+
let startupOperation;
|
|
12419
|
+
let startupPromise;
|
|
12420
|
+
let binding2;
|
|
12421
|
+
let bindOperation;
|
|
12422
|
+
const cleanupErrors = [];
|
|
12423
|
+
function assertOpen() {
|
|
12424
|
+
if (closing) throw new Error("AppContext startup interrupted: context is closed");
|
|
12425
|
+
}
|
|
12426
|
+
function close() {
|
|
12427
|
+
closing = true;
|
|
12428
|
+
backgroundServicesReady = false;
|
|
12429
|
+
closePromise ??= (async () => {
|
|
12430
|
+
await bindOperation?.catch(() => {
|
|
12431
|
+
});
|
|
12432
|
+
await startupOperation?.catch(() => {
|
|
12433
|
+
});
|
|
12434
|
+
await app.close();
|
|
12435
|
+
})();
|
|
12436
|
+
return closePromise;
|
|
12437
|
+
}
|
|
12438
|
+
async function failStartup(error) {
|
|
12439
|
+
try {
|
|
12440
|
+
await close();
|
|
12441
|
+
} catch (cleanupError) {
|
|
12442
|
+
throw new AggregateError([error, cleanupError], "Server startup failed and cleanup failed", {
|
|
12443
|
+
cause: error
|
|
12444
|
+
});
|
|
12445
|
+
}
|
|
12446
|
+
throw error;
|
|
12447
|
+
}
|
|
12448
|
+
async function listen(options = {}) {
|
|
12449
|
+
assertOpen();
|
|
12450
|
+
if (binding2) {
|
|
12451
|
+
for (const key of ["host", "port", "useBoundAddressAsBaseUrl"]) {
|
|
12452
|
+
if (options[key] !== void 0 && options[key] !== binding2[key])
|
|
12453
|
+
throw new Error(`Conflicting listener option: ${key}`);
|
|
12454
|
+
}
|
|
12455
|
+
} else {
|
|
12456
|
+
if (app.server.listening) throw new Error("Cannot adopt a manually bound listener");
|
|
12457
|
+
const requested = {
|
|
12458
|
+
host: options.host ?? input.server.host,
|
|
12459
|
+
port: options.port ?? input.server.port,
|
|
12460
|
+
useBoundAddressAsBaseUrl: options.useBoundAddressAsBaseUrl ?? false
|
|
12461
|
+
};
|
|
12462
|
+
if (requested.useBoundAddressAsBaseUrl && (input.authEnabled || !["127.0.0.1", "::1", "localhost"].includes(requested.host)))
|
|
12463
|
+
throw new Error("Bound base URL requires an unauthenticated loopback listener");
|
|
12464
|
+
binding2 = requested;
|
|
12465
|
+
bindOperation = (async () => {
|
|
12466
|
+
const started = performance.now();
|
|
12467
|
+
const address = await app.listen({ host: requested.host, port: requested.port });
|
|
12468
|
+
app.log.info(
|
|
12469
|
+
{ listenDurationMs: Math.round((performance.now() - started) * 10) / 10 },
|
|
12470
|
+
"Server HTTP listener ready"
|
|
12471
|
+
);
|
|
12472
|
+
const info = app.server.address();
|
|
12473
|
+
if (!info || typeof info === "string") throw new Error("Expected TCP listener address");
|
|
12474
|
+
if (requested.useBoundAddressAsBaseUrl) input.server.base_url = address;
|
|
12475
|
+
return { address, port: info.port };
|
|
12476
|
+
})();
|
|
12477
|
+
}
|
|
12478
|
+
let result;
|
|
12479
|
+
try {
|
|
12480
|
+
if (!bindOperation) throw new Error("Listener was not initialized");
|
|
12481
|
+
result = await bindOperation;
|
|
12482
|
+
} catch (error) {
|
|
12483
|
+
return failStartup(error);
|
|
12484
|
+
}
|
|
12485
|
+
await startServices();
|
|
12486
|
+
assertOpen();
|
|
12487
|
+
return result;
|
|
12488
|
+
}
|
|
12489
|
+
function startServices() {
|
|
12490
|
+
if (closing)
|
|
12491
|
+
return Promise.reject(new Error("AppContext startup interrupted: context is closed"));
|
|
12492
|
+
if (startupPromise) return startupPromise;
|
|
12493
|
+
startupOperation = (async () => {
|
|
12494
|
+
await bindOperation;
|
|
12495
|
+
assertOpen();
|
|
12496
|
+
await input.reconcile(assertOpen);
|
|
12497
|
+
for (const hook of input.startHooks) {
|
|
12498
|
+
assertOpen();
|
|
12499
|
+
await hook();
|
|
12500
|
+
}
|
|
12501
|
+
assertOpen();
|
|
12502
|
+
backgroundServicesReady = true;
|
|
12503
|
+
})();
|
|
12504
|
+
startupPromise = startupOperation.catch(failStartup);
|
|
12505
|
+
return startupPromise;
|
|
12506
|
+
}
|
|
12507
|
+
let backgroundServicesReady = false;
|
|
12508
|
+
let cleanupOperation;
|
|
12509
|
+
function cleanup() {
|
|
12510
|
+
closing = true;
|
|
12511
|
+
backgroundServicesReady = false;
|
|
12512
|
+
cleanupOperation ??= (async () => {
|
|
12513
|
+
await startupOperation?.catch(() => {
|
|
12514
|
+
});
|
|
12515
|
+
cleanupErrors.push(...await collectCleanupErrors(input.preCloseCleanup.splice(0)));
|
|
12516
|
+
})();
|
|
12517
|
+
return cleanupOperation;
|
|
12518
|
+
}
|
|
12519
|
+
app.addHook("preClose", cleanup);
|
|
12520
|
+
async function finishCleanup() {
|
|
12521
|
+
await cleanup();
|
|
12522
|
+
cleanupErrors.push(...await collectCleanupErrors([input.closeDatabase]));
|
|
12523
|
+
if (cleanupErrors.length) throw new AggregateError(cleanupErrors, "AppContext cleanup failed");
|
|
12524
|
+
}
|
|
12525
|
+
return {
|
|
12526
|
+
listen,
|
|
12527
|
+
close,
|
|
12528
|
+
isReady: () => backgroundServicesReady,
|
|
12529
|
+
isClosing: () => closing,
|
|
12530
|
+
finishCleanup
|
|
12531
|
+
};
|
|
12532
|
+
}
|
|
12533
|
+
|
|
12534
|
+
// src/server-bootstrap/build-host-capabilities.ts
|
|
12535
|
+
import path3 from "node:path";
|
|
12536
|
+
import { SYSTEM_ACTOR as SYSTEM_ACTOR5 } from "@leitwerk-dev/domain";
|
|
12537
|
+
import {
|
|
13021
12538
|
coreHostCapabilities,
|
|
13022
12539
|
createCapabilityAccessor
|
|
13023
12540
|
} from "@leitwerk-dev/process-sdk";
|
|
@@ -13030,7 +12547,7 @@ function buildHostCapabilities(input) {
|
|
|
13030
12547
|
return input.config.server.base_url;
|
|
13031
12548
|
},
|
|
13032
12549
|
get processWorkspacesDir() {
|
|
13033
|
-
return
|
|
12550
|
+
return path3.resolve(input.config.storage.process_workspaces_dir);
|
|
13034
12551
|
},
|
|
13035
12552
|
components: input.config.components,
|
|
13036
12553
|
externalWrites: input.baseDeps.externalWrites,
|
|
@@ -13059,13 +12576,13 @@ function buildHostCapabilities(input) {
|
|
|
13059
12576
|
startProgrammatic(request, opts) {
|
|
13060
12577
|
return input.launchCoordinator.startProgrammatic(request, {
|
|
13061
12578
|
idempotencyKey: opts.idempotencyKey,
|
|
13062
|
-
actor: opts.actor ??
|
|
12579
|
+
actor: opts.actor ?? SYSTEM_ACTOR5
|
|
13063
12580
|
});
|
|
13064
12581
|
},
|
|
13065
12582
|
startWatcher(watcher, event, opts) {
|
|
13066
12583
|
return input.launchCoordinator.startWatcher(watcher, event, {
|
|
13067
12584
|
idempotencyKey: opts.idempotencyKey,
|
|
13068
|
-
actor: opts.actor ??
|
|
12585
|
+
actor: opts.actor ?? SYSTEM_ACTOR5
|
|
13069
12586
|
});
|
|
13070
12587
|
}
|
|
13071
12588
|
},
|
|
@@ -13357,7 +12874,7 @@ function registerInternalSessionTransferExportRoutes(app, service) {
|
|
|
13357
12874
|
// src/routes/internal-worker-session-snapshot.ts
|
|
13358
12875
|
import { mkdtemp, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
13359
12876
|
import { tmpdir } from "node:os";
|
|
13360
|
-
import
|
|
12877
|
+
import path4 from "node:path";
|
|
13361
12878
|
import { StringDecoder } from "node:string_decoder";
|
|
13362
12879
|
import {
|
|
13363
12880
|
WORKER_SESSION_SNAPSHOT_CONTENT_TYPE,
|
|
@@ -13456,8 +12973,8 @@ function validateJsonLine(line, lineNumber) {
|
|
|
13456
12973
|
}
|
|
13457
12974
|
}
|
|
13458
12975
|
async function streamSnapshotToTempFile(payload, bodyLimit) {
|
|
13459
|
-
const dir = await mkdtemp(
|
|
13460
|
-
const file =
|
|
12976
|
+
const dir = await mkdtemp(path4.join(tmpdir(), "leitwerk-session-snapshot-"));
|
|
12977
|
+
const file = path4.join(dir, "snapshot.jsonl");
|
|
13461
12978
|
let bytes = 0;
|
|
13462
12979
|
const decoder = new StringDecoder("utf8");
|
|
13463
12980
|
let pendingLine = "";
|
|
@@ -13586,7 +13103,7 @@ function registerInternalWorkerSessionSnapshotRoutes(input) {
|
|
|
13586
13103
|
await input.sessionSnapshots.writeSnapshotFile(instanceId, body.path);
|
|
13587
13104
|
reply.code(204).send();
|
|
13588
13105
|
} finally {
|
|
13589
|
-
if (body?.path) await rm2(
|
|
13106
|
+
if (body?.path) await rm2(path4.dirname(body.path), { recursive: true, force: true });
|
|
13590
13107
|
}
|
|
13591
13108
|
return reply;
|
|
13592
13109
|
}
|
|
@@ -13952,8 +13469,8 @@ function mapEngineFailure(result, variant) {
|
|
|
13952
13469
|
};
|
|
13953
13470
|
}
|
|
13954
13471
|
function sendEngineFailure(reply, result, variant) {
|
|
13955
|
-
const
|
|
13956
|
-
return reply.code(
|
|
13472
|
+
const failure = mapEngineFailure(result, variant);
|
|
13473
|
+
return reply.code(failure.status).send(failure.body);
|
|
13957
13474
|
}
|
|
13958
13475
|
|
|
13959
13476
|
// src/routes/process-actions.ts
|
|
@@ -15459,7 +14976,7 @@ function registerHttp(input) {
|
|
|
15459
14976
|
|
|
15460
14977
|
// src/server-topology.ts
|
|
15461
14978
|
import { readFileSync } from "node:fs";
|
|
15462
|
-
var defaultFileReader = (
|
|
14979
|
+
var defaultFileReader = (path9) => readFileSync(path9, "utf8");
|
|
15463
14980
|
function resolveServerTlsOptions(config, readFile5 = defaultFileReader) {
|
|
15464
14981
|
const tls = config.internal_tls;
|
|
15465
14982
|
if (!tls || tls.enabled !== true) {
|
|
@@ -15524,6 +15041,7 @@ function createSessionTransferHelperRelays(deps) {
|
|
|
15524
15041
|
return helper;
|
|
15525
15042
|
}
|
|
15526
15043
|
return {
|
|
15044
|
+
/** @internal */
|
|
15527
15045
|
create(input) {
|
|
15528
15046
|
const attempt = deps.repos.sessionTransfers.getActiveByInstance(input.instanceId);
|
|
15529
15047
|
if (!attempt || attempt.state !== "queued" && attempt.state !== "exporting") {
|
|
@@ -15566,16 +15084,19 @@ function createSessionTransferHelperRelays(deps) {
|
|
|
15566
15084
|
fail: runtime.fail
|
|
15567
15085
|
};
|
|
15568
15086
|
},
|
|
15087
|
+
/** @internal */
|
|
15569
15088
|
sweep() {
|
|
15570
15089
|
const currentTime = now2().getTime();
|
|
15571
15090
|
for (const helper of helpers.values()) {
|
|
15572
15091
|
if (helper.expiresAt <= currentTime) helper.fail(new Error("export_helper_expired"));
|
|
15573
15092
|
}
|
|
15574
15093
|
},
|
|
15094
|
+
/** @internal */
|
|
15575
15095
|
stop() {
|
|
15576
15096
|
for (const helper of helpers.values()) helper.fail(new Error("server_stopping"));
|
|
15577
15097
|
helpers.clear();
|
|
15578
15098
|
},
|
|
15099
|
+
/** @internal */
|
|
15579
15100
|
helperSpec(input) {
|
|
15580
15101
|
const helper = active(input.exportId, input.credential);
|
|
15581
15102
|
if (!helper || helper.reported || helper.streamAccepted) return null;
|
|
@@ -15588,6 +15109,7 @@ function createSessionTransferHelperRelays(deps) {
|
|
|
15588
15109
|
limits: { ...deps.limits }
|
|
15589
15110
|
};
|
|
15590
15111
|
},
|
|
15112
|
+
/** @internal */
|
|
15591
15113
|
async reportHelperPreflight(input) {
|
|
15592
15114
|
const helper = active(input.exportId, input.credential);
|
|
15593
15115
|
if (!helper || helper.reported || helper.streamAccepted) return false;
|
|
@@ -15610,6 +15132,7 @@ function createSessionTransferHelperRelays(deps) {
|
|
|
15610
15132
|
return false;
|
|
15611
15133
|
}
|
|
15612
15134
|
},
|
|
15135
|
+
/** @internal */
|
|
15613
15136
|
acceptHelperStream(input) {
|
|
15614
15137
|
const helper = active(input.exportId, input.credential);
|
|
15615
15138
|
if (!helper?.reported || helper.streamAccepted) return false;
|
|
@@ -15628,21 +15151,21 @@ function createSessionTransferHelperRelays(deps) {
|
|
|
15628
15151
|
import { execFile } from "node:child_process";
|
|
15629
15152
|
import { mkdtemp as mkdtemp2, readdir as readdir2, readFile as readFile4, rm as rm3 } from "node:fs/promises";
|
|
15630
15153
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
15631
|
-
import
|
|
15154
|
+
import path5 from "node:path";
|
|
15632
15155
|
import { promisify } from "node:util";
|
|
15633
15156
|
import {
|
|
15634
|
-
createCanonicalPiResourceBundle
|
|
15157
|
+
createCanonicalPiResourceBundle
|
|
15635
15158
|
} from "@leitwerk-dev/worker-protocol";
|
|
15636
15159
|
var execFileAsync = promisify(execFile);
|
|
15637
15160
|
var GIT_ENV = { ...process.env, GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "/bin/false" };
|
|
15638
15161
|
var FORBIDDEN_SKILL_NAMES = /* @__PURE__ */ new Set([".git"]);
|
|
15639
15162
|
function isWithin(root, candidate) {
|
|
15640
|
-
const relative =
|
|
15641
|
-
return relative === "" || relative !== ".." && !relative.startsWith(`..${
|
|
15163
|
+
const relative = path5.relative(root, candidate);
|
|
15164
|
+
return relative === "" || relative !== ".." && !relative.startsWith(`..${path5.sep}`);
|
|
15642
15165
|
}
|
|
15643
15166
|
async function importSkillDirectory(root, skill, sourceRevision) {
|
|
15644
15167
|
const collector = new ResourceCollector();
|
|
15645
|
-
await collector.addDirectory(
|
|
15168
|
+
await collector.addDirectory(path5.resolve(root), `skills/${skill.id}`, SKILL_RESOURCE_OWNER, {
|
|
15646
15169
|
forbiddenNames: FORBIDDEN_SKILL_NAMES
|
|
15647
15170
|
});
|
|
15648
15171
|
const files = collector.toResourceFiles();
|
|
@@ -15653,7 +15176,7 @@ async function importSkillDirectory(root, skill, sourceRevision) {
|
|
|
15653
15176
|
skillId: skill.id,
|
|
15654
15177
|
label: skill.label ?? skill.id,
|
|
15655
15178
|
description: skill.description ?? null,
|
|
15656
|
-
bundle:
|
|
15179
|
+
bundle: createCanonicalPiResourceBundle(files),
|
|
15657
15180
|
sourceRevision
|
|
15658
15181
|
};
|
|
15659
15182
|
}
|
|
@@ -15685,14 +15208,14 @@ async function discoverSkillRoots(catalogRoot) {
|
|
|
15685
15208
|
const entries = (await readdir2(directory, { withFileTypes: true })).sort(
|
|
15686
15209
|
(left, right) => left.name.localeCompare(right.name)
|
|
15687
15210
|
);
|
|
15688
|
-
const skillId =
|
|
15211
|
+
const skillId = path5.basename(directory);
|
|
15689
15212
|
if (SAFE_SKILL_ID_PATTERN.test(skillId) && entries.some((entry) => entry.name === "SKILL.md" && entry.isFile())) {
|
|
15690
15213
|
result.push(directory);
|
|
15691
15214
|
return;
|
|
15692
15215
|
}
|
|
15693
15216
|
for (const entry of entries) {
|
|
15694
15217
|
if (entry.isDirectory() && entry.name !== ".git") {
|
|
15695
|
-
await visit(
|
|
15218
|
+
await visit(path5.join(directory, entry.name));
|
|
15696
15219
|
}
|
|
15697
15220
|
}
|
|
15698
15221
|
};
|
|
@@ -15700,20 +15223,20 @@ async function discoverSkillRoots(catalogRoot) {
|
|
|
15700
15223
|
return result;
|
|
15701
15224
|
}
|
|
15702
15225
|
function repositorySourcePath(checkoutRoot, skillRoot) {
|
|
15703
|
-
return
|
|
15226
|
+
return path5.relative(checkoutRoot, skillRoot).split(path5.sep).join(path5.posix.sep);
|
|
15704
15227
|
}
|
|
15705
15228
|
async function importSkillRepository(repository) {
|
|
15706
|
-
const tempRoot = await mkdtemp2(
|
|
15229
|
+
const tempRoot = await mkdtemp2(path5.join(tmpdir2(), "leitwerk-skill-repository-"));
|
|
15707
15230
|
try {
|
|
15708
|
-
const checkout = await checkoutGitSource(repository,
|
|
15709
|
-
const catalogRoot =
|
|
15231
|
+
const checkout = await checkoutGitSource(repository, path5.join(tempRoot, "checkout"));
|
|
15232
|
+
const catalogRoot = path5.resolve(checkout.root, repository.path ?? "skills");
|
|
15710
15233
|
if (!isWithin(checkout.root, catalogRoot)) {
|
|
15711
15234
|
throw new Error(`Skill repository '${repository.id}' path escapes its checkout`);
|
|
15712
15235
|
}
|
|
15713
15236
|
const skillRoots = await discoverSkillRoots(catalogRoot);
|
|
15714
15237
|
const rootsById = /* @__PURE__ */ new Map();
|
|
15715
15238
|
for (const skillRoot of skillRoots) {
|
|
15716
|
-
const skillId =
|
|
15239
|
+
const skillId = path5.basename(skillRoot);
|
|
15717
15240
|
const previous = rootsById.get(skillId);
|
|
15718
15241
|
if (previous) {
|
|
15719
15242
|
throw new Error(
|
|
@@ -15724,8 +15247,8 @@ async function importSkillRepository(repository) {
|
|
|
15724
15247
|
}
|
|
15725
15248
|
const skills = [];
|
|
15726
15249
|
for (const skillRoot of skillRoots) {
|
|
15727
|
-
const skillId =
|
|
15728
|
-
const markdown = await readFile4(
|
|
15250
|
+
const skillId = path5.basename(skillRoot);
|
|
15251
|
+
const markdown = await readFile4(path5.join(skillRoot, "SKILL.md"), "utf8");
|
|
15729
15252
|
const imported = await importSkillDirectory(
|
|
15730
15253
|
skillRoot,
|
|
15731
15254
|
{
|
|
@@ -15820,12 +15343,12 @@ function createSkillCatalogService(input) {
|
|
|
15820
15343
|
|
|
15821
15344
|
// src/supervisor/diagnostic-trace-writer.ts
|
|
15822
15345
|
import { appendFileSync, mkdirSync } from "node:fs";
|
|
15823
|
-
import
|
|
15346
|
+
import path6 from "node:path";
|
|
15824
15347
|
function createDiagnosticTraceWriter(directory) {
|
|
15825
15348
|
mkdirSync(directory, { recursive: true, mode: 448 });
|
|
15826
15349
|
return {
|
|
15827
15350
|
append(instanceId, text) {
|
|
15828
|
-
appendFileSync(
|
|
15351
|
+
appendFileSync(path6.join(directory, `${instanceId}.log`), text, {
|
|
15829
15352
|
encoding: "utf8",
|
|
15830
15353
|
mode: 384
|
|
15831
15354
|
});
|
|
@@ -16457,6 +15980,7 @@ function createIpcHandler(deps, callbacks) {
|
|
|
16457
15980
|
}
|
|
16458
15981
|
);
|
|
16459
15982
|
return {
|
|
15983
|
+
/** @internal */
|
|
16460
15984
|
handleMessage(envelope) {
|
|
16461
15985
|
const decoded = decodeWorkerToServerMessage(envelope);
|
|
16462
15986
|
if (!decoded.ok) {
|
|
@@ -17107,8 +16631,8 @@ function decideIdleWorkerStop(input) {
|
|
|
17107
16631
|
}
|
|
17108
16632
|
|
|
17109
16633
|
// src/supervisor/worker-api-compatibility.ts
|
|
17110
|
-
import { WORKER_API_VERSION
|
|
17111
|
-
function checkWorkerApiCompatibility(payload, expectedApiVersion =
|
|
16634
|
+
import { WORKER_API_VERSION } from "@leitwerk-dev/worker-protocol";
|
|
16635
|
+
function checkWorkerApiCompatibility(payload, expectedApiVersion = WORKER_API_VERSION, options = {}) {
|
|
17112
16636
|
if (payload.apiVersion === void 0) {
|
|
17113
16637
|
if (options.requireApiVersion === true) {
|
|
17114
16638
|
return {
|
|
@@ -17256,7 +16780,7 @@ function createWorkerShutdownController(input) {
|
|
|
17256
16780
|
|
|
17257
16781
|
// src/supervisor/worker-start-payload-builder.ts
|
|
17258
16782
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
17259
|
-
import
|
|
16783
|
+
import path7 from "node:path";
|
|
17260
16784
|
import { parseProductRefsFromStateJsonLenient } from "@leitwerk-dev/domain";
|
|
17261
16785
|
import { parseDurationMs as parseDurationMs6 } from "@leitwerk-dev/watcher-utils";
|
|
17262
16786
|
import {
|
|
@@ -17486,7 +17010,7 @@ function createWorkerStartPayloadBuilder(deps) {
|
|
|
17486
17010
|
30 * 60 * 1e3,
|
|
17487
17011
|
{ allowHours: true }
|
|
17488
17012
|
),
|
|
17489
|
-
processStorageRoot: deps.config.workers.runner === "local" ? treePaths.workspaceRoot :
|
|
17013
|
+
processStorageRoot: deps.config.workers.runner === "local" ? treePaths.workspaceRoot : path7.dirname(treePaths.workspaceRoot)
|
|
17490
17014
|
},
|
|
17491
17015
|
...treePaths.resume ? { resumeLeafEntryId } : {},
|
|
17492
17016
|
...llmPreparation ? { llmPreparation } : {},
|
|
@@ -17740,9 +17264,11 @@ function createWorkerWebSocketIpcManager(options = {}) {
|
|
|
17740
17264
|
}
|
|
17741
17265
|
}
|
|
17742
17266
|
return {
|
|
17267
|
+
/** @internal */
|
|
17743
17268
|
setUnknownWorkerConnectionsRetryable(enabled) {
|
|
17744
17269
|
retryUnknownWorkerConnections = enabled;
|
|
17745
17270
|
},
|
|
17271
|
+
/** @internal */
|
|
17746
17272
|
verifyWorkerToken({
|
|
17747
17273
|
instanceId,
|
|
17748
17274
|
workerId,
|
|
@@ -17751,6 +17277,7 @@ function createWorkerWebSocketIpcManager(options = {}) {
|
|
|
17751
17277
|
const entry = pending.get(connectionKey(instanceId, workerId));
|
|
17752
17278
|
return entry ? verifyWorkerConnectToken(token, entry.tokenHash) : false;
|
|
17753
17279
|
},
|
|
17280
|
+
/** @internal */
|
|
17754
17281
|
registerWorker({
|
|
17755
17282
|
instanceId,
|
|
17756
17283
|
workerId,
|
|
@@ -17768,6 +17295,7 @@ function createWorkerWebSocketIpcManager(options = {}) {
|
|
|
17768
17295
|
outbound: []
|
|
17769
17296
|
});
|
|
17770
17297
|
},
|
|
17298
|
+
/** @internal */
|
|
17771
17299
|
bindSocket({
|
|
17772
17300
|
instanceId,
|
|
17773
17301
|
workerId,
|
|
@@ -17838,6 +17366,7 @@ function createWorkerWebSocketIpcManager(options = {}) {
|
|
|
17838
17366
|
});
|
|
17839
17367
|
return { ok: true };
|
|
17840
17368
|
},
|
|
17369
|
+
/** @internal */
|
|
17841
17370
|
send(instanceId, workerId, message) {
|
|
17842
17371
|
const entry = pending.get(connectionKey(instanceId, workerId));
|
|
17843
17372
|
if (!entry) {
|
|
@@ -17857,6 +17386,7 @@ function createWorkerWebSocketIpcManager(options = {}) {
|
|
|
17857
17386
|
}
|
|
17858
17387
|
queueOutbound(entry, data);
|
|
17859
17388
|
},
|
|
17389
|
+
/** @internal */
|
|
17860
17390
|
unregister(instanceId, workerId, reason) {
|
|
17861
17391
|
const key = connectionKey(instanceId, workerId);
|
|
17862
17392
|
const entry = pending.get(key);
|
|
@@ -17877,6 +17407,9 @@ function createWorkerWebSocketIpcManager(options = {}) {
|
|
|
17877
17407
|
}
|
|
17878
17408
|
|
|
17879
17409
|
// src/supervisor/worker-supervisor.ts
|
|
17410
|
+
function isLiveWorkerLease(lease, workerId) {
|
|
17411
|
+
return lease?.workerId === workerId && !["draining", "cleanup", "failed", "exited"].includes(lease.state);
|
|
17412
|
+
}
|
|
17880
17413
|
function generateWorkerId() {
|
|
17881
17414
|
const ts = Date.now().toString(36);
|
|
17882
17415
|
const rand = Math.random().toString(36).slice(2, 10);
|
|
@@ -17955,19 +17488,11 @@ function createWorkerSupervisor(deps) {
|
|
|
17955
17488
|
);
|
|
17956
17489
|
}
|
|
17957
17490
|
function clearStartupTimer(instanceId) {
|
|
17958
|
-
|
|
17959
|
-
if (timer === void 0) {
|
|
17960
|
-
return;
|
|
17961
|
-
}
|
|
17962
|
-
clearTimeout(timer);
|
|
17491
|
+
clearTimeout(startupTimers.get(instanceId));
|
|
17963
17492
|
startupTimers.delete(instanceId);
|
|
17964
17493
|
}
|
|
17965
17494
|
function clearIdleStopTimer(instanceId) {
|
|
17966
|
-
|
|
17967
|
-
if (timer === void 0) {
|
|
17968
|
-
return;
|
|
17969
|
-
}
|
|
17970
|
-
clearTimeout(timer);
|
|
17495
|
+
clearTimeout(idleStopTimers.get(instanceId));
|
|
17971
17496
|
idleStopTimers.delete(instanceId);
|
|
17972
17497
|
}
|
|
17973
17498
|
function selectedTurnForProcess(instanceId) {
|
|
@@ -18168,25 +17693,19 @@ function createWorkerSupervisor(deps) {
|
|
|
18168
17693
|
clearStartupTimer(instanceId);
|
|
18169
17694
|
clearIdleStopTimer(instanceId);
|
|
18170
17695
|
const leaseBeforeError = safeGetLeaseByInstance(instanceId);
|
|
18171
|
-
const shouldNormalizeProcessError = leaseBeforeError?.workerId === workerId && leaseBeforeError.state !== "draining" && leaseBeforeError.state !== "cleanup" && leaseBeforeError.state !== "failed" && leaseBeforeError.state !== "exited";
|
|
18172
17696
|
const shouldStopWorker = error instanceof WorkerOutboundBufferOverflowError;
|
|
18173
|
-
if (
|
|
18174
|
-
|
|
18175
|
-
|
|
18176
|
-
|
|
18177
|
-
|
|
18178
|
-
|
|
18179
|
-
|
|
18180
|
-
|
|
17697
|
+
if (isLiveWorkerLease(leaseBeforeError, workerId)) {
|
|
17698
|
+
const errorMessage3 = error instanceof Error ? error.message : String(error);
|
|
17699
|
+
const startupTimedOut = startupTimedOutWorkers.delete(
|
|
17700
|
+
timedOutWorkerKey(instanceId, workerId)
|
|
17701
|
+
);
|
|
17702
|
+
const failedBeforeBootstrap = leaseBeforeError.state === "spawning" || leaseBeforeError.state === "bootstrapping";
|
|
17703
|
+
emitServerObservedWorkerFailure(instanceId, workerId, {
|
|
17704
|
+
errorCode: shouldStopWorker ? "worker_websocket_outbound_buffer_overflow" : startupTimedOut ? "startup_timeout" : failedBeforeBootstrap ? "spawn_error" : "process_error",
|
|
17705
|
+
message: startupTimedOut ? `Worker startup timed out after ${startupTimeoutMs}ms: ${errorMessage3}` : failedBeforeBootstrap ? `Worker process error before bootstrap completed: ${errorMessage3}` : `Worker process error: ${errorMessage3}`,
|
|
17706
|
+
errorClass: "infrastructure"
|
|
17707
|
+
});
|
|
18181
17708
|
}
|
|
18182
|
-
const errorMessage3 = error instanceof Error ? error.message : String(error);
|
|
18183
|
-
const startupTimedOut = startupTimedOutWorkers.delete(timedOutWorkerKey(instanceId, workerId));
|
|
18184
|
-
const failedBeforeBootstrap = leaseBeforeError.state === "spawning" || leaseBeforeError.state === "bootstrapping";
|
|
18185
|
-
emitServerObservedWorkerFailure(instanceId, workerId, {
|
|
18186
|
-
errorCode: shouldStopWorker ? "worker_websocket_outbound_buffer_overflow" : startupTimedOut ? "startup_timeout" : failedBeforeBootstrap ? "spawn_error" : "process_error",
|
|
18187
|
-
message: startupTimedOut ? `Worker startup timed out after ${startupTimeoutMs}ms: ${errorMessage3}` : failedBeforeBootstrap ? `Worker process error before bootstrap completed: ${errorMessage3}` : `Worker process error: ${errorMessage3}`,
|
|
18188
|
-
errorClass: "infrastructure"
|
|
18189
|
-
});
|
|
18190
17709
|
if (shouldStopWorker) {
|
|
18191
17710
|
const handle = workers.get(instanceId);
|
|
18192
17711
|
if (handle?.workerId === workerId) {
|
|
@@ -18210,8 +17729,7 @@ function createWorkerSupervisor(deps) {
|
|
|
18210
17729
|
pendingCleanup.delete(instanceId);
|
|
18211
17730
|
const leaseBeforeExit = safeGetLeaseByInstance(instanceId);
|
|
18212
17731
|
const startupTimedOut = startupTimedOutWorkers.delete(timedOutWorkerKey(instanceId, workerId));
|
|
18213
|
-
|
|
18214
|
-
if (shouldNormalizeUnexpectedExit) {
|
|
17732
|
+
if (isLiveWorkerLease(leaseBeforeExit, workerId)) {
|
|
18215
17733
|
const diagnostics = formatWorkerExitDiagnostics(info);
|
|
18216
17734
|
emitServerObservedWorkerFailure(instanceId, workerId, {
|
|
18217
17735
|
errorCode: startupTimedOut ? "startup_timeout" : info?.oomKilled ? "process_oom_killed" : "process_exited",
|
|
@@ -18257,31 +17775,7 @@ function createWorkerSupervisor(deps) {
|
|
|
18257
17775
|
}
|
|
18258
17776
|
};
|
|
18259
17777
|
}
|
|
18260
|
-
function
|
|
18261
|
-
if (!runnerRuntime) {
|
|
18262
|
-
throw new Error("runner runtime is not configured");
|
|
18263
|
-
}
|
|
18264
|
-
runnerRuntime.webSocketIpc.registerWorker({
|
|
18265
|
-
instanceId: input.instanceId,
|
|
18266
|
-
workerId: input.workerId,
|
|
18267
|
-
callbacks: {
|
|
18268
|
-
onEnvelope: input.onEnvelope,
|
|
18269
|
-
onInvalidOutput: input.onInvalidMessage,
|
|
18270
|
-
onRuntimeError: input.onRuntimeError
|
|
18271
|
-
},
|
|
18272
|
-
tokenHash: input.tokenHash
|
|
18273
|
-
});
|
|
18274
|
-
return {
|
|
18275
|
-
unregister(reason) {
|
|
18276
|
-
runnerRuntime.webSocketIpc.unregister(input.instanceId, input.workerId, reason);
|
|
18277
|
-
}
|
|
18278
|
-
};
|
|
18279
|
-
}
|
|
18280
|
-
function resolveRunnerStartSelection(instanceId) {
|
|
18281
|
-
const process2 = deps.processes.getById(instanceId);
|
|
18282
|
-
if (!process2) {
|
|
18283
|
-
throw new Error(`Cannot start worker for missing process ${instanceId}`);
|
|
18284
|
-
}
|
|
17778
|
+
function resolveRunnerStartSelection(process2) {
|
|
18285
17779
|
if (deps.config.workers.runner === "local") {
|
|
18286
17780
|
return {
|
|
18287
17781
|
selection: {
|
|
@@ -18296,7 +17790,7 @@ function createWorkerSupervisor(deps) {
|
|
|
18296
17790
|
buildRuntimeProfileSelectionInput({
|
|
18297
17791
|
config: deps.config,
|
|
18298
17792
|
processId: process2.processId,
|
|
18299
|
-
componentKeys: deps.projects.listByInstance(
|
|
17793
|
+
componentKeys: deps.projects.listByInstance(process2.id).map((project) => project.key)
|
|
18300
17794
|
})
|
|
18301
17795
|
);
|
|
18302
17796
|
if (!selection.ok) {
|
|
@@ -18315,9 +17809,9 @@ function createWorkerSupervisor(deps) {
|
|
|
18315
17809
|
return deps.config.server.base_url;
|
|
18316
17810
|
}
|
|
18317
17811
|
async function startRunnerWorker(options, connect) {
|
|
18318
|
-
const { selection, profile } = resolveRunnerStartSelection(options.instanceId);
|
|
18319
17812
|
const process2 = deps.processes.getById(options.instanceId);
|
|
18320
17813
|
if (!process2) throw new Error(`Cannot start worker for missing process ${options.instanceId}`);
|
|
17814
|
+
const { selection, profile } = resolveRunnerStartSelection(process2);
|
|
18321
17815
|
const docker = deps.processGraphs.get(process2.processId)?.runtime?.docker === true;
|
|
18322
17816
|
const resourceLimits = profile?.resources?.limits ?? (profile?.resources ? { cpu: profile.resources.cpu, memory: profile.resources.memory } : void 0);
|
|
18323
17817
|
const observer = createStartupObserver(
|
|
@@ -18449,44 +17943,43 @@ function createWorkerSupervisor(deps) {
|
|
|
18449
17943
|
let unregisterStartRegistration;
|
|
18450
17944
|
const earlyEnvelopes = [];
|
|
18451
17945
|
try {
|
|
18452
|
-
|
|
18453
|
-
instanceId,
|
|
18454
|
-
workerId,
|
|
18455
|
-
startupDeadlineMs,
|
|
18456
|
-
resolvedExtensionEntriesJson: deps.resolvedExtensionEntriesJson,
|
|
18457
|
-
onEnvelope: (envelope) => {
|
|
18458
|
-
if (workers.has(instanceId)) {
|
|
18459
|
-
routeEnvelope(envelope, instanceId);
|
|
18460
|
-
} else {
|
|
18461
|
-
earlyEnvelopes.push(envelope);
|
|
18462
|
-
}
|
|
18463
|
-
},
|
|
18464
|
-
onInvalidMessage: () => {
|
|
18465
|
-
emitServerObservedWorkerFailure(instanceId, workerId, {
|
|
18466
|
-
errorCode: "invalid_worker_websocket_ipc",
|
|
18467
|
-
message: "Worker emitted invalid WebSocket IPC message",
|
|
18468
|
-
errorClass: "infrastructure"
|
|
18469
|
-
});
|
|
18470
|
-
},
|
|
18471
|
-
onRuntimeError: (error) => handleProcessError(instanceId, workerId, error),
|
|
18472
|
-
snapshotToken,
|
|
18473
|
-
onRuntimeExit: () => {
|
|
18474
|
-
processExitedBeforeRegistration = !workers.has(instanceId);
|
|
18475
|
-
}
|
|
18476
|
-
};
|
|
18477
|
-
const connect = registerRunnerWebSocket({
|
|
17946
|
+
runnerRuntime.webSocketIpc.registerWorker({
|
|
18478
17947
|
instanceId,
|
|
18479
17948
|
workerId,
|
|
18480
17949
|
tokenHash: connectTokenHash,
|
|
18481
|
-
|
|
18482
|
-
|
|
18483
|
-
|
|
18484
|
-
|
|
18485
|
-
|
|
18486
|
-
|
|
18487
|
-
|
|
18488
|
-
|
|
17950
|
+
callbacks: {
|
|
17951
|
+
onEnvelope: (envelope) => {
|
|
17952
|
+
if (workers.has(instanceId)) {
|
|
17953
|
+
routeEnvelope(envelope, instanceId);
|
|
17954
|
+
} else {
|
|
17955
|
+
earlyEnvelopes.push(envelope);
|
|
17956
|
+
}
|
|
17957
|
+
},
|
|
17958
|
+
onInvalidOutput: () => {
|
|
17959
|
+
emitServerObservedWorkerFailure(instanceId, workerId, {
|
|
17960
|
+
errorCode: "invalid_worker_websocket_ipc",
|
|
17961
|
+
message: "Worker emitted invalid WebSocket IPC message",
|
|
17962
|
+
errorClass: "infrastructure"
|
|
17963
|
+
});
|
|
17964
|
+
},
|
|
17965
|
+
onRuntimeError: (error) => handleProcessError(instanceId, workerId, error)
|
|
17966
|
+
}
|
|
18489
17967
|
});
|
|
17968
|
+
const unregister = (reason) => runnerRuntime.webSocketIpc.unregister(instanceId, workerId, reason);
|
|
17969
|
+
unregisterStartRegistration = () => unregister("start_failed");
|
|
17970
|
+
handle = await startRunnerWorker(
|
|
17971
|
+
{
|
|
17972
|
+
instanceId,
|
|
17973
|
+
workerId,
|
|
17974
|
+
startupDeadlineMs,
|
|
17975
|
+
resolvedExtensionEntriesJson: deps.resolvedExtensionEntriesJson,
|
|
17976
|
+
snapshotToken,
|
|
17977
|
+
onRuntimeExit: () => {
|
|
17978
|
+
processExitedBeforeRegistration = !workers.has(instanceId);
|
|
17979
|
+
}
|
|
17980
|
+
},
|
|
17981
|
+
{ token: connectToken, unregister }
|
|
17982
|
+
);
|
|
18490
17983
|
unregisterStartRegistration = void 0;
|
|
18491
17984
|
} catch (error) {
|
|
18492
17985
|
unregisterStartRegistration?.();
|
|
@@ -18574,14 +18067,10 @@ function createWorkerSupervisor(deps) {
|
|
|
18574
18067
|
if (!handle) {
|
|
18575
18068
|
return;
|
|
18576
18069
|
}
|
|
18577
|
-
|
|
18070
|
+
sendToCurrentWorker(instanceId, handle.workerId, {
|
|
18578
18071
|
type: "worker.abort_turn",
|
|
18579
|
-
instanceId,
|
|
18580
|
-
workerId: handle.workerId,
|
|
18581
|
-
messageId: randomUUID6(),
|
|
18582
18072
|
payload: { reason }
|
|
18583
18073
|
});
|
|
18584
|
-
handle.send(msg);
|
|
18585
18074
|
},
|
|
18586
18075
|
deliverInputs(instanceId, inputs) {
|
|
18587
18076
|
const handle = workers.get(instanceId);
|
|
@@ -18665,7 +18154,9 @@ function createToolApprovalGate(input) {
|
|
|
18665
18154
|
}
|
|
18666
18155
|
}
|
|
18667
18156
|
return {
|
|
18157
|
+
/** @internal */
|
|
18668
18158
|
reconcile,
|
|
18159
|
+
/** @internal */
|
|
18669
18160
|
async review(requestInput) {
|
|
18670
18161
|
if (!isCurrentTurn(input.repos, requestInput)) return { kind: "declined" };
|
|
18671
18162
|
const result = input.repos.toolApprovalRequests.createIdempotent(requestInput);
|
|
@@ -18677,9 +18168,11 @@ function createToolApprovalGate(input) {
|
|
|
18677
18168
|
waiters.set(result.request.id, pending);
|
|
18678
18169
|
});
|
|
18679
18170
|
},
|
|
18171
|
+
/** @internal */
|
|
18680
18172
|
listOpen(instanceId) {
|
|
18681
18173
|
return input.repos.toolApprovalRequests.listOpen(instanceId);
|
|
18682
18174
|
},
|
|
18175
|
+
/** @internal */
|
|
18683
18176
|
async resolve(instanceId, requestId, decision, actor) {
|
|
18684
18177
|
const resolved = await input.processOperations.runExclusive(
|
|
18685
18178
|
instanceId,
|
|
@@ -18701,6 +18194,7 @@ function createToolApprovalGate(input) {
|
|
|
18701
18194
|
reconcile(instanceId);
|
|
18702
18195
|
return resolved;
|
|
18703
18196
|
},
|
|
18197
|
+
/** @internal */
|
|
18704
18198
|
cancelTurn(instanceId, turnRecordId) {
|
|
18705
18199
|
const changed = input.repos.toolApprovalRequests.cancelOpenByTurn(instanceId, turnRecordId);
|
|
18706
18200
|
reconcile(instanceId);
|
|
@@ -18808,10 +18302,6 @@ async function createConfiguredWorkerRunnerRuntime(input) {
|
|
|
18808
18302
|
});
|
|
18809
18303
|
return { ...created, webSocketIpc: input.webSocketIpc };
|
|
18810
18304
|
}
|
|
18811
|
-
async function createApp(opts = {}) {
|
|
18812
|
-
const ctx = await createAppContext(opts);
|
|
18813
|
-
return ctx.app;
|
|
18814
|
-
}
|
|
18815
18305
|
async function createAppContext(opts = {}) {
|
|
18816
18306
|
const startupStartedAt = performance.now();
|
|
18817
18307
|
let previousStartupMark = startupStartedAt;
|
|
@@ -18846,238 +18336,249 @@ ${configErrors.join("\n")}`);
|
|
|
18846
18336
|
);
|
|
18847
18337
|
previousStartupMark = now2;
|
|
18848
18338
|
};
|
|
18849
|
-
|
|
18850
|
-
|
|
18851
|
-
|
|
18852
|
-
const
|
|
18853
|
-
|
|
18854
|
-
|
|
18855
|
-
|
|
18856
|
-
|
|
18857
|
-
|
|
18858
|
-
|
|
18859
|
-
|
|
18860
|
-
|
|
18861
|
-
|
|
18862
|
-
|
|
18863
|
-
|
|
18864
|
-
|
|
18865
|
-
|
|
18866
|
-
|
|
18867
|
-
|
|
18868
|
-
|
|
18869
|
-
|
|
18870
|
-
|
|
18871
|
-
|
|
18872
|
-
|
|
18873
|
-
|
|
18874
|
-
|
|
18875
|
-
|
|
18876
|
-
|
|
18877
|
-
|
|
18878
|
-
|
|
18879
|
-
|
|
18880
|
-
|
|
18881
|
-
|
|
18882
|
-
|
|
18883
|
-
|
|
18884
|
-
|
|
18885
|
-
);
|
|
18886
|
-
|
|
18887
|
-
|
|
18888
|
-
|
|
18889
|
-
|
|
18890
|
-
|
|
18891
|
-
|
|
18892
|
-
|
|
18893
|
-
|
|
18894
|
-
|
|
18895
|
-
|
|
18896
|
-
|
|
18897
|
-
|
|
18898
|
-
|
|
18899
|
-
|
|
18900
|
-
|
|
18901
|
-
|
|
18902
|
-
|
|
18903
|
-
|
|
18904
|
-
|
|
18905
|
-
|
|
18906
|
-
|
|
18907
|
-
|
|
18908
|
-
|
|
18909
|
-
|
|
18910
|
-
|
|
18911
|
-
|
|
18912
|
-
|
|
18913
|
-
|
|
18914
|
-
|
|
18915
|
-
|
|
18916
|
-
|
|
18917
|
-
|
|
18918
|
-
|
|
18919
|
-
|
|
18920
|
-
|
|
18921
|
-
|
|
18922
|
-
|
|
18923
|
-
extensionCatalog.
|
|
18924
|
-
|
|
18925
|
-
|
|
18926
|
-
|
|
18927
|
-
|
|
18928
|
-
|
|
18929
|
-
|
|
18930
|
-
|
|
18931
|
-
|
|
18932
|
-
|
|
18933
|
-
|
|
18934
|
-
|
|
18935
|
-
const launcherModelProfilesById = new Map(
|
|
18936
|
-
launcherModelProfiles.map((profile) => [profile.id, profile])
|
|
18937
|
-
);
|
|
18938
|
-
const getModelProfilesForProcess = (processId) => {
|
|
18939
|
-
return processModelPolicy.project({
|
|
18940
|
-
kind: "profile_options",
|
|
18941
|
-
processId,
|
|
18942
|
-
availability: modelStatusCache.snapshot()
|
|
18943
|
-
}).map((profile) => launcherModelProfilesById.get(profile.id)).filter(
|
|
18944
|
-
(profile) => profile !== void 0
|
|
18339
|
+
let finishCleanup;
|
|
18340
|
+
let stopAcquiredWorkers;
|
|
18341
|
+
let closeOwnedDatabase;
|
|
18342
|
+
const preCloseCleanup = [];
|
|
18343
|
+
try {
|
|
18344
|
+
await app.register(cookie);
|
|
18345
|
+
markStartup("fastify_plugins");
|
|
18346
|
+
const ownsDb = !opts.db;
|
|
18347
|
+
const db = opts.db ?? createConfiguredDatabase(config);
|
|
18348
|
+
if (ownsDb) closeOwnedDatabase = () => closeDatabase(db);
|
|
18349
|
+
preCloseCleanup.push(() => stopAcquiredWorkers?.());
|
|
18350
|
+
app.addHook("onClose", async () => {
|
|
18351
|
+
await finishCleanup?.();
|
|
18352
|
+
});
|
|
18353
|
+
markStartup("database");
|
|
18354
|
+
const { resolvedExtensionEntries, extensionCatalog } = await loadServerExtensionCatalog({
|
|
18355
|
+
config,
|
|
18356
|
+
extensionCatalog: opts.extensionCatalog,
|
|
18357
|
+
resolvedExtensionEntries: opts.resolvedExtensionEntries,
|
|
18358
|
+
extensionLoadingStartDir: opts.extensionLoadingStartDir
|
|
18359
|
+
});
|
|
18360
|
+
markStartup("extension_catalog");
|
|
18361
|
+
const modelProviderRegistry = createModelProviderRegistry({
|
|
18362
|
+
sets: extensionCatalog.modelProviders,
|
|
18363
|
+
piContributions: extensionCatalog.piContributions,
|
|
18364
|
+
extensionConfig: config.extensions ?? {},
|
|
18365
|
+
modelProfiles: config.pi.model_profiles,
|
|
18366
|
+
titleModelProfileId: config.pi.process_title_generation.model_profile
|
|
18367
|
+
});
|
|
18368
|
+
const credentialCipher = createCredentialCipherFromEnvironment();
|
|
18369
|
+
const repos = createAllRepos(db, {
|
|
18370
|
+
...credentialCipher ? { credentialCipher } : {}
|
|
18371
|
+
});
|
|
18372
|
+
repos.transaction((transactionRepos) => {
|
|
18373
|
+
transactionRepos.skills.reconcile([]);
|
|
18374
|
+
transactionRepos.skills.backfillDependencies();
|
|
18375
|
+
});
|
|
18376
|
+
const skillCatalog = createSkillCatalogService({
|
|
18377
|
+
repositories: config.skill_repositories ?? [],
|
|
18378
|
+
repos
|
|
18379
|
+
});
|
|
18380
|
+
await skillCatalog.refresh();
|
|
18381
|
+
markStartup("skill_catalog");
|
|
18382
|
+
if (!credentialCipher && repos.providerCredentials.count() > 0) {
|
|
18383
|
+
throw new Error(
|
|
18384
|
+
"Encrypted provider credentials exist but LEITWERK_CREDENTIAL_ENCRYPTION_KEY is unavailable"
|
|
18385
|
+
);
|
|
18386
|
+
}
|
|
18387
|
+
const modelProviderCredentials = createModelProviderCredentialService({
|
|
18388
|
+
registry: modelProviderRegistry,
|
|
18389
|
+
repo: repos.providerCredentials
|
|
18390
|
+
});
|
|
18391
|
+
modelProviderCredentials.initialize();
|
|
18392
|
+
const modelStatusCache = createModelStatusCache({
|
|
18393
|
+
registry: modelProviderRegistry,
|
|
18394
|
+
modelProfiles: config.pi.model_profiles,
|
|
18395
|
+
credentialStatus: opts.modelProviderCredentialStatus ?? (modelProviderRegistry.size > 0 ? modelProviderCredentials.status : defaultModelProviderCredentialStatus)
|
|
18396
|
+
});
|
|
18397
|
+
await modelStatusCache.refresh();
|
|
18398
|
+
const modelProviderServerAdapters = await createModelProviderServerAdapterRegistry({
|
|
18399
|
+
registry: modelProviderRegistry,
|
|
18400
|
+
modelProfiles: config.pi.model_profiles,
|
|
18401
|
+
credentials: modelProviderCredentials,
|
|
18402
|
+
createBuiltinAdapter: (providerId) => createBuiltinPiServerAdapter(providerId)
|
|
18403
|
+
});
|
|
18404
|
+
const piResourceBundles = createPiResourceBundleCache();
|
|
18405
|
+
const piResourceBundlePins = createPiResourceBundlePinReconciler({
|
|
18406
|
+
turnStarts: repos.turnStarts,
|
|
18407
|
+
turnRecords: repos.turnRecords,
|
|
18408
|
+
bundleCache: piResourceBundles
|
|
18409
|
+
});
|
|
18410
|
+
markStartup("model_providers");
|
|
18411
|
+
const broadcaster = createBroadcaster();
|
|
18412
|
+
const processOperations = createProcessOperationCoordinator();
|
|
18413
|
+
const processGraphs = extensionCatalog.processes;
|
|
18414
|
+
const processActionRegistry = buildProcessActionRegistry(extensionCatalog);
|
|
18415
|
+
const integrationTools = new IntegrationToolRegistry(repos.externalWrites);
|
|
18416
|
+
const processUiRegistry = buildProcessUiRegistry(extensionCatalog);
|
|
18417
|
+
const processModelPolicy = createServerProcessModelPolicy({
|
|
18418
|
+
config,
|
|
18419
|
+
processGraphs,
|
|
18420
|
+
processActionRegistry
|
|
18421
|
+
});
|
|
18422
|
+
const extensionUiCatalog = await buildExtensionUiCatalog(
|
|
18423
|
+
extensionCatalog.modules,
|
|
18424
|
+
opts.extensionUiRuntimeLane ? { runtimeLane: opts.extensionUiRuntimeLane } : {}
|
|
18945
18425
|
);
|
|
18946
|
-
|
|
18947
|
-
|
|
18948
|
-
|
|
18949
|
-
|
|
18950
|
-
|
|
18951
|
-
|
|
18952
|
-
|
|
18953
|
-
modelProfiles: launcherModelProfiles,
|
|
18954
|
-
getModelProfilesForProcess,
|
|
18955
|
-
processModelPolicy
|
|
18956
|
-
});
|
|
18957
|
-
const workerWebSocketIpc = createWorkerWebSocketIpcManager();
|
|
18958
|
-
workerWebSocketIpc.setUnknownWorkerConnectionsRetryable(true);
|
|
18959
|
-
const serverEpoch = `epoch_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
18960
|
-
const sessionSnapshots = createProjectedSessionSnapshotStore(
|
|
18961
|
-
createFileBackedProcessSessionSnapshotStore(config.storage.tree_files_dir),
|
|
18962
|
-
repos
|
|
18963
|
-
);
|
|
18964
|
-
for (const process2 of repos.processes.listAll()) await sessionSnapshots.backfill(process2.id);
|
|
18965
|
-
const sessionReader = new ProcessSessionReader(sessionSnapshots);
|
|
18966
|
-
const resultImages = new ResultImageStore({
|
|
18967
|
-
rootDir: path9.join(config.storage.tree_files_dir, "result-images")
|
|
18968
|
-
});
|
|
18969
|
-
const authService = createAuthService({ config, repos });
|
|
18970
|
-
await registerWebsocket(app, broadcaster, workerWebSocketIpc, authService);
|
|
18971
|
-
const extensionHost = createExtensionHost();
|
|
18972
|
-
let launchCoordinator;
|
|
18973
|
-
let applyGeneratedFutureExecutionTitle = async () => ({
|
|
18974
|
-
kind: "failed",
|
|
18975
|
-
error: "Future execution lifecycle is not initialized"
|
|
18976
|
-
});
|
|
18977
|
-
const processTitles = opts.processTitleGenerator ?? (config.pi.process_title_generation.model_profile === null ? void 0 : createProcessTitleGenerator({
|
|
18978
|
-
config,
|
|
18979
|
-
repos,
|
|
18980
|
-
broadcaster,
|
|
18981
|
-
extensionHost,
|
|
18982
|
-
futureExecutionTitleApplier: (input) => applyGeneratedFutureExecutionTitle(input),
|
|
18983
|
-
getLaunchCoordinator: () => launchCoordinator,
|
|
18984
|
-
logger: {
|
|
18985
|
-
warn: (message, details) => app.log.warn(details ?? {}, message)
|
|
18986
|
-
},
|
|
18987
|
-
runtime: {
|
|
18988
|
-
generateTitle: ({ prompt, maxTokens, providerOptions }) => modelProviderServerAdapters.generateText({
|
|
18989
|
-
profileId: config.pi.process_title_generation.model_profile,
|
|
18990
|
-
prompt,
|
|
18991
|
-
systemPrompt: TITLE_SYSTEM_PROMPT,
|
|
18992
|
-
maxTokens,
|
|
18993
|
-
request: providerOptions
|
|
18426
|
+
markStartup("extension_ui_catalog");
|
|
18427
|
+
const launcherModelProfiles = config.pi.model_profiles.map(
|
|
18428
|
+
(profile) => ({
|
|
18429
|
+
id: profile.id,
|
|
18430
|
+
provider: profile.provider,
|
|
18431
|
+
modelId: profile.model_id,
|
|
18432
|
+
thinkingLevel: profile.thinking_level ?? "off"
|
|
18994
18433
|
})
|
|
18995
|
-
|
|
18996
|
-
|
|
18997
|
-
|
|
18998
|
-
|
|
18999
|
-
|
|
19000
|
-
|
|
19001
|
-
|
|
19002
|
-
|
|
19003
|
-
|
|
19004
|
-
|
|
19005
|
-
|
|
19006
|
-
|
|
19007
|
-
|
|
19008
|
-
|
|
19009
|
-
|
|
19010
|
-
|
|
19011
|
-
|
|
19012
|
-
|
|
19013
|
-
|
|
19014
|
-
|
|
19015
|
-
|
|
19016
|
-
|
|
19017
|
-
|
|
19018
|
-
|
|
19019
|
-
|
|
19020
|
-
|
|
19021
|
-
|
|
19022
|
-
|
|
19023
|
-
|
|
19024
|
-
|
|
19025
|
-
|
|
19026
|
-
|
|
19027
|
-
|
|
19028
|
-
|
|
19029
|
-
|
|
19030
|
-
|
|
19031
|
-
|
|
19032
|
-
|
|
19033
|
-
|
|
19034
|
-
|
|
19035
|
-
|
|
19036
|
-
|
|
19037
|
-
|
|
19038
|
-
|
|
19039
|
-
|
|
19040
|
-
|
|
18434
|
+
);
|
|
18435
|
+
const launcherModelProfilesById = new Map(
|
|
18436
|
+
launcherModelProfiles.map((profile) => [profile.id, profile])
|
|
18437
|
+
);
|
|
18438
|
+
const getModelProfilesForProcess = (processId) => {
|
|
18439
|
+
return processModelPolicy.project({
|
|
18440
|
+
kind: "profile_options",
|
|
18441
|
+
processId,
|
|
18442
|
+
availability: modelStatusCache.snapshot()
|
|
18443
|
+
}).map((profile) => launcherModelProfilesById.get(profile.id)).filter(
|
|
18444
|
+
(profile) => profile !== void 0
|
|
18445
|
+
);
|
|
18446
|
+
};
|
|
18447
|
+
const launcherService = buildProcessLauncherRegistry(extensionCatalog, {
|
|
18448
|
+
modelProfiles: launcherModelProfiles,
|
|
18449
|
+
commitMessages: config.commit_messages,
|
|
18450
|
+
getModelProfilesForProcess
|
|
18451
|
+
});
|
|
18452
|
+
const processWatcherService = buildProcessWatcherRegistry(extensionCatalog, config, {
|
|
18453
|
+
modelProfiles: launcherModelProfiles,
|
|
18454
|
+
getModelProfilesForProcess,
|
|
18455
|
+
processModelPolicy
|
|
18456
|
+
});
|
|
18457
|
+
const workerWebSocketIpc = createWorkerWebSocketIpcManager();
|
|
18458
|
+
workerWebSocketIpc.setUnknownWorkerConnectionsRetryable(true);
|
|
18459
|
+
const serverEpoch = `epoch_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
18460
|
+
const sessionSnapshots = createProjectedSessionSnapshotStore(
|
|
18461
|
+
createFileBackedProcessSessionSnapshotStore(config.storage.tree_files_dir),
|
|
18462
|
+
repos
|
|
18463
|
+
);
|
|
18464
|
+
for (const process2 of repos.processes.listAll()) await sessionSnapshots.backfill(process2.id);
|
|
18465
|
+
const sessionReader = new ProcessSessionReader(sessionSnapshots);
|
|
18466
|
+
const resultImages = new ResultImageStore({
|
|
18467
|
+
rootDir: path8.join(config.storage.tree_files_dir, "result-images")
|
|
18468
|
+
});
|
|
18469
|
+
const authService = createAuthService({ config, repos });
|
|
18470
|
+
await registerWebsocket(app, broadcaster, workerWebSocketIpc, authService);
|
|
18471
|
+
const extensionHost = createExtensionHost();
|
|
18472
|
+
let launchCoordinator;
|
|
18473
|
+
let applyGeneratedFutureExecutionTitle = async () => ({
|
|
18474
|
+
kind: "failed",
|
|
18475
|
+
error: "Future execution lifecycle is not initialized"
|
|
18476
|
+
});
|
|
18477
|
+
const processTitles = opts.processTitleGenerator ?? (config.pi.process_title_generation.model_profile === null ? void 0 : createProcessTitleGenerator({
|
|
18478
|
+
config,
|
|
18479
|
+
repos,
|
|
18480
|
+
broadcaster,
|
|
18481
|
+
extensionHost,
|
|
18482
|
+
futureExecutionTitleApplier: (input) => applyGeneratedFutureExecutionTitle(input),
|
|
18483
|
+
getLaunchCoordinator: () => launchCoordinator,
|
|
18484
|
+
logger: {
|
|
18485
|
+
warn: (message, details) => app.log.warn(details ?? {}, message)
|
|
19041
18486
|
},
|
|
19042
|
-
|
|
19043
|
-
|
|
19044
|
-
|
|
19045
|
-
|
|
19046
|
-
|
|
19047
|
-
|
|
19048
|
-
|
|
19049
|
-
|
|
19050
|
-
profileIds,
|
|
19051
|
-
logger: app.log
|
|
19052
|
-
});
|
|
18487
|
+
runtime: {
|
|
18488
|
+
generateTitle: ({ prompt, maxTokens, providerOptions }) => modelProviderServerAdapters.generateText({
|
|
18489
|
+
profileId: config.pi.process_title_generation.model_profile,
|
|
18490
|
+
prompt,
|
|
18491
|
+
systemPrompt: TITLE_SYSTEM_PROMPT,
|
|
18492
|
+
maxTokens,
|
|
18493
|
+
request: providerOptions
|
|
18494
|
+
})
|
|
19053
18495
|
}
|
|
18496
|
+
}));
|
|
18497
|
+
const baseDeps = {
|
|
18498
|
+
...repos,
|
|
18499
|
+
broadcaster,
|
|
18500
|
+
processOperations
|
|
18501
|
+
};
|
|
18502
|
+
let invalidateExternalSourceArmings = null;
|
|
18503
|
+
const projectMutations = createProjectMutationService({
|
|
18504
|
+
projects: baseDeps.projects,
|
|
18505
|
+
transaction: baseDeps.transaction,
|
|
18506
|
+
broadcaster,
|
|
18507
|
+
onProjectMutated: (project) => invalidateExternalSourceArmings?.(project.instanceId)
|
|
19054
18508
|
});
|
|
19055
|
-
|
|
19056
|
-
|
|
19057
|
-
|
|
19058
|
-
|
|
19059
|
-
|
|
19060
|
-
|
|
18509
|
+
const launcherRecentValues = createLauncherRecentValuesService({
|
|
18510
|
+
repos: baseDeps,
|
|
18511
|
+
launcherService
|
|
18512
|
+
});
|
|
18513
|
+
const launchPlans = {
|
|
18514
|
+
async prepare(launchPlan, opts2 = {}) {
|
|
18515
|
+
return processModelPolicy.prepareLaunchPlan(launchPlan, opts2);
|
|
18516
|
+
}
|
|
18517
|
+
};
|
|
18518
|
+
const launcherModelConfigs = createLauncherModelConfigService({
|
|
18519
|
+
launcherService,
|
|
18520
|
+
launchPlans,
|
|
18521
|
+
processModelPolicy,
|
|
18522
|
+
modelStatusCache
|
|
18523
|
+
});
|
|
18524
|
+
const polling = createPollingCoordinator(app.log);
|
|
18525
|
+
const startHooks = [];
|
|
18526
|
+
const stopHooks = [];
|
|
18527
|
+
preCloseCleanup.push(async () => {
|
|
18528
|
+
const errors = await collectCleanupErrors(stopHooks);
|
|
18529
|
+
if (errors.length) throw new AggregateError(errors, "Background service cleanup failed");
|
|
18530
|
+
});
|
|
18531
|
+
const modelRefreshWork = /* @__PURE__ */ new Set();
|
|
18532
|
+
let modelStatusRefreshTimer = null;
|
|
18533
|
+
let futureExecutionLifecycle;
|
|
18534
|
+
async function refreshModelStatusAndApplyTransitions() {
|
|
18535
|
+
const snapshot = await modelStatusCache.refresh();
|
|
18536
|
+
await applyProcessModelAvailabilityTransitions({
|
|
18537
|
+
snapshot,
|
|
18538
|
+
reconcileFutureExecutions: async (profileIds) => {
|
|
18539
|
+
await futureExecutionLifecycle.reconcileModelAvailability({
|
|
18540
|
+
availability: snapshot,
|
|
18541
|
+
profileIds
|
|
18542
|
+
});
|
|
18543
|
+
},
|
|
18544
|
+
recoverProcesses: async (profileIds) => {
|
|
18545
|
+
await recoverModelAvailabilityFailures({
|
|
18546
|
+
processes: baseDeps.processes,
|
|
18547
|
+
turnStarts: baseDeps.turnStarts,
|
|
18548
|
+
commands: processEngine,
|
|
18549
|
+
policy: processModelPolicy,
|
|
18550
|
+
availability: snapshot,
|
|
18551
|
+
cause: "availability_transition",
|
|
18552
|
+
profileIds,
|
|
18553
|
+
logger: app.log
|
|
18554
|
+
});
|
|
18555
|
+
}
|
|
19061
18556
|
});
|
|
19062
|
-
}, 15e3);
|
|
19063
|
-
});
|
|
19064
|
-
stopHooks.push(() => {
|
|
19065
|
-
if (modelStatusRefreshTimer) clearInterval(modelStatusRefreshTimer);
|
|
19066
|
-
modelStatusRefreshTimer = null;
|
|
19067
|
-
});
|
|
19068
|
-
let stopAuthSweep = null;
|
|
19069
|
-
startHooks.push(() => {
|
|
19070
|
-
stopAuthSweep = authService.startExpiredAuthStateSweep();
|
|
19071
|
-
});
|
|
19072
|
-
stopHooks.push(() => {
|
|
19073
|
-
stopAuthSweep?.();
|
|
19074
|
-
stopAuthSweep = null;
|
|
19075
|
-
});
|
|
19076
|
-
async function startBackgroundServices() {
|
|
19077
|
-
if (backgroundServicesStarted) {
|
|
19078
|
-
return;
|
|
19079
18557
|
}
|
|
19080
|
-
|
|
18558
|
+
startHooks.push(() => {
|
|
18559
|
+
if (modelProviderRegistry.size === 0) return;
|
|
18560
|
+
modelStatusRefreshTimer = setInterval(() => {
|
|
18561
|
+
const work = refreshModelStatusAndApplyTransitions().catch((error) => {
|
|
18562
|
+
app.log.warn({ error }, "Model provider status refresh failed");
|
|
18563
|
+
});
|
|
18564
|
+
modelRefreshWork.add(work);
|
|
18565
|
+
void work.finally(() => modelRefreshWork.delete(work));
|
|
18566
|
+
}, 15e3);
|
|
18567
|
+
});
|
|
18568
|
+
stopHooks.push(async () => {
|
|
18569
|
+
if (modelStatusRefreshTimer) clearInterval(modelStatusRefreshTimer);
|
|
18570
|
+
modelStatusRefreshTimer = null;
|
|
18571
|
+
await Promise.all(modelRefreshWork);
|
|
18572
|
+
});
|
|
18573
|
+
let stopAuthSweep = null;
|
|
18574
|
+
startHooks.push(() => {
|
|
18575
|
+
stopAuthSweep = authService.startExpiredAuthStateSweep();
|
|
18576
|
+
});
|
|
18577
|
+
stopHooks.push(() => {
|
|
18578
|
+
stopAuthSweep?.();
|
|
18579
|
+
stopAuthSweep = null;
|
|
18580
|
+
});
|
|
18581
|
+
async function reconcileStartup(assertOpen) {
|
|
19081
18582
|
if (!supervisor) {
|
|
19082
18583
|
throw new Error("worker supervisor not initialized");
|
|
19083
18584
|
}
|
|
@@ -19086,6 +18587,7 @@ ${configErrors.join("\n")}`);
|
|
|
19086
18587
|
await futureExecutionLifecycle.reconcileModelAvailability({
|
|
19087
18588
|
availability: modelStatusCache.snapshot()
|
|
19088
18589
|
});
|
|
18590
|
+
assertOpen();
|
|
19089
18591
|
await recoverModelAvailabilityFailures({
|
|
19090
18592
|
processes: baseDeps.processes,
|
|
19091
18593
|
turnStarts: baseDeps.turnStarts,
|
|
@@ -19095,13 +18597,16 @@ ${configErrors.join("\n")}`);
|
|
|
19095
18597
|
cause: "startup_reconciliation",
|
|
19096
18598
|
logger: app.log
|
|
19097
18599
|
});
|
|
18600
|
+
assertOpen();
|
|
19098
18601
|
await reconcilePersistedProcessModelIntegrity({
|
|
19099
18602
|
processes: baseDeps.processes,
|
|
19100
18603
|
commands: processEngine,
|
|
19101
18604
|
policy: processModelPolicy,
|
|
19102
18605
|
logger: app.log
|
|
19103
18606
|
});
|
|
18607
|
+
assertOpen();
|
|
19104
18608
|
await supervisor.adoptRegisteredWorkers();
|
|
18609
|
+
assertOpen();
|
|
19105
18610
|
await reconcileProcessesOnStartup({
|
|
19106
18611
|
config,
|
|
19107
18612
|
processes: baseDeps.processes,
|
|
@@ -19115,684 +18620,611 @@ ${configErrors.join("\n")}`);
|
|
|
19115
18620
|
processActionRegistry,
|
|
19116
18621
|
logger: app.log
|
|
19117
18622
|
});
|
|
19118
|
-
|
|
18623
|
+
assertOpen();
|
|
19119
18624
|
} finally {
|
|
19120
18625
|
workerWebSocketIpc.setUnknownWorkerConnectionsRetryable(false);
|
|
19121
18626
|
}
|
|
19122
18627
|
}
|
|
19123
|
-
|
|
19124
|
-
|
|
19125
|
-
|
|
19126
|
-
|
|
19127
|
-
|
|
19128
|
-
|
|
19129
|
-
|
|
19130
|
-
backgroundServicesReady = false;
|
|
19131
|
-
backgroundServicesStarted = false;
|
|
19132
|
-
for (const hook of [...stopHooks].reverse()) {
|
|
19133
|
-
await hook();
|
|
19134
|
-
}
|
|
19135
|
-
throw error;
|
|
19136
|
-
}
|
|
19137
|
-
}
|
|
19138
|
-
async function stopBackgroundServices() {
|
|
19139
|
-
backgroundServicesReady = false;
|
|
19140
|
-
if (!backgroundServicesStarted) {
|
|
19141
|
-
return;
|
|
19142
|
-
}
|
|
19143
|
-
backgroundServicesStarted = false;
|
|
19144
|
-
for (const hook of [...stopHooks].reverse()) {
|
|
19145
|
-
await hook();
|
|
19146
|
-
}
|
|
19147
|
-
}
|
|
19148
|
-
let supervisor;
|
|
19149
|
-
let isNewTurnBlocked = (_instanceId) => false;
|
|
19150
|
-
const afterSuccessHooks = /* @__PURE__ */ new Set();
|
|
19151
|
-
const toastTtlMs = parseDurationMs8(config.server.websocket.toast_ttl, 6e3, {
|
|
19152
|
-
allowHours: true
|
|
19153
|
-
});
|
|
19154
|
-
const processEngine = createProcessEngine({
|
|
19155
|
-
processes: baseDeps.processes,
|
|
19156
|
-
events: baseDeps.events,
|
|
19157
|
-
futureExecutions: baseDeps.futureExecutions,
|
|
19158
|
-
projects: baseDeps.projects,
|
|
19159
|
-
inputs: baseDeps.inputs,
|
|
19160
|
-
pendingExternalSourceFires: baseDeps.pendingExternalSourceFires,
|
|
19161
|
-
leafOutcomeSnapshots: baseDeps.leafOutcomeSnapshots,
|
|
19162
|
-
questionRequests: baseDeps.questionRequests,
|
|
19163
|
-
turnRecords: baseDeps.turnRecords,
|
|
19164
|
-
turnStarts: baseDeps.turnStarts,
|
|
19165
|
-
leases: baseDeps.leases,
|
|
19166
|
-
turnAnnotations: baseDeps.turnAnnotations,
|
|
19167
|
-
transaction: baseDeps.transaction,
|
|
19168
|
-
broadcaster,
|
|
19169
|
-
config,
|
|
19170
|
-
toastTtlMs,
|
|
19171
|
-
processOperations,
|
|
19172
|
-
getSupervisor: () => supervisor,
|
|
19173
|
-
extensionHost,
|
|
19174
|
-
processGraphs,
|
|
19175
|
-
sessionReader,
|
|
19176
|
-
getProcessActionRegistry: () => processActionRegistry,
|
|
19177
|
-
getProcessUiRegistry: () => processUiRegistry,
|
|
19178
|
-
logger: app.log,
|
|
19179
|
-
processModelPolicy,
|
|
19180
|
-
getModelAvailabilitySnapshot: () => modelStatusCache.snapshot(),
|
|
19181
|
-
afterRecord(process2) {
|
|
19182
|
-
piResourceBundlePins.reconcile(process2);
|
|
19183
|
-
toolApprovalGate.reconcile(process2.id);
|
|
19184
|
-
},
|
|
19185
|
-
afterSuccessHooks,
|
|
19186
|
-
isNewTurnBlocked: (instanceId) => isNewTurnBlocked(instanceId),
|
|
19187
|
-
prepareTurnStarts: (process2, writes, providerOptions, availabilitySnapshot) => prepareCreatedTurnStarts(
|
|
19188
|
-
{
|
|
19189
|
-
config,
|
|
19190
|
-
registry: modelProviderRegistry,
|
|
19191
|
-
modelStatusCache,
|
|
19192
|
-
piContributions: extensionCatalog.piContributions,
|
|
19193
|
-
bundleCache: piResourceBundles,
|
|
19194
|
-
projects: baseDeps.projects,
|
|
19195
|
-
processSkills: baseDeps.processSkills
|
|
19196
|
-
},
|
|
19197
|
-
process2,
|
|
19198
|
-
writes,
|
|
19199
|
-
providerOptions,
|
|
19200
|
-
availabilitySnapshot
|
|
19201
|
-
)
|
|
19202
|
-
});
|
|
19203
|
-
const processQuestions = createProcessQuestionService({
|
|
19204
|
-
repos: baseDeps,
|
|
19205
|
-
processOperations,
|
|
19206
|
-
broadcaster,
|
|
19207
|
-
getWorkerId: (instanceId) => supervisor?.getWorker(instanceId)?.workerId ?? null,
|
|
19208
|
-
sendQuestionResponse: (instanceId, workerId, payload) => supervisor?.questionResponse(instanceId, workerId, payload),
|
|
19209
|
-
emitQuestionRequested: (request) => extensionHost.emit("question_requested", { instanceId: request.instanceId, request }).catch(
|
|
19210
|
-
(error) => app.log.error(
|
|
19211
|
-
{ error, instanceId: request.instanceId },
|
|
19212
|
-
"Question delivery event failed"
|
|
19213
|
-
)
|
|
19214
|
-
)
|
|
19215
|
-
});
|
|
19216
|
-
const toolApprovalGate = createToolApprovalGate({
|
|
19217
|
-
repos: baseDeps,
|
|
19218
|
-
processOperations
|
|
19219
|
-
});
|
|
19220
|
-
const integrationToolRequests = createIntegrationToolRequestService({
|
|
19221
|
-
registry: integrationTools,
|
|
19222
|
-
repos: baseDeps,
|
|
19223
|
-
processActionRegistry,
|
|
19224
|
-
toolApprovalGate
|
|
19225
|
-
});
|
|
19226
|
-
const diagnosticTraceWriter = createDiagnosticTraceWriter(
|
|
19227
|
-
path9.join(config.storage.tree_files_dir, "diagnostic-traces")
|
|
19228
|
-
);
|
|
19229
|
-
const ipcHandler = createIpcHandler(
|
|
19230
|
-
{
|
|
19231
|
-
startupObservations: baseDeps.startupObservations,
|
|
18628
|
+
let supervisor;
|
|
18629
|
+
let isNewTurnBlocked = (_instanceId) => false;
|
|
18630
|
+
const afterSuccessHooks = /* @__PURE__ */ new Set();
|
|
18631
|
+
const toastTtlMs = parseDurationMs8(config.server.websocket.toast_ttl, 6e3, {
|
|
18632
|
+
allowHours: true
|
|
18633
|
+
});
|
|
18634
|
+
const processEngine = createProcessEngine({
|
|
19232
18635
|
processes: baseDeps.processes,
|
|
19233
|
-
|
|
18636
|
+
events: baseDeps.events,
|
|
18637
|
+
futureExecutions: baseDeps.futureExecutions,
|
|
19234
18638
|
projects: baseDeps.projects,
|
|
19235
18639
|
inputs: baseDeps.inputs,
|
|
19236
|
-
|
|
19237
|
-
|
|
18640
|
+
pendingExternalSourceFires: baseDeps.pendingExternalSourceFires,
|
|
18641
|
+
leafOutcomeSnapshots: baseDeps.leafOutcomeSnapshots,
|
|
18642
|
+
questionRequests: baseDeps.questionRequests,
|
|
19238
18643
|
turnRecords: baseDeps.turnRecords,
|
|
19239
|
-
|
|
19240
|
-
|
|
19241
|
-
|
|
18644
|
+
turnStarts: baseDeps.turnStarts,
|
|
18645
|
+
leases: baseDeps.leases,
|
|
18646
|
+
turnAnnotations: baseDeps.turnAnnotations,
|
|
18647
|
+
transaction: baseDeps.transaction,
|
|
19242
18648
|
broadcaster,
|
|
19243
|
-
|
|
19244
|
-
|
|
19245
|
-
|
|
19246
|
-
|
|
19247
|
-
|
|
19248
|
-
|
|
19249
|
-
|
|
19250
|
-
|
|
19251
|
-
|
|
19252
|
-
|
|
19253
|
-
|
|
19254
|
-
|
|
19255
|
-
|
|
19256
|
-
|
|
19257
|
-
|
|
19258
|
-
return result;
|
|
19259
|
-
},
|
|
19260
|
-
appendDiagnosticTrace(instanceId, text) {
|
|
19261
|
-
try {
|
|
19262
|
-
diagnosticTraceWriter.append(instanceId, text);
|
|
19263
|
-
} catch (error) {
|
|
19264
|
-
app.log.warn({ error, instanceId }, "Could not append worker diagnostic trace");
|
|
19265
|
-
}
|
|
19266
|
-
},
|
|
19267
|
-
workerEventLogger: config.workers.log_worker_events_to_stdout ? (entry) => {
|
|
19268
|
-
app.log.info({ source: "worker_event", ...entry }, "worker.event");
|
|
19269
|
-
} : void 0
|
|
19270
|
-
},
|
|
19271
|
-
{
|
|
19272
|
-
onTurnTerminalRecorded(instanceId, workerId, turnRecordId) {
|
|
19273
|
-
supervisor?.acknowledgeTurnTerminal(instanceId, workerId, { turnRecordId });
|
|
19274
|
-
},
|
|
19275
|
-
onTurnFailedRecorded(input) {
|
|
19276
|
-
app.log.warn(input, "Worker turn failed");
|
|
18649
|
+
config,
|
|
18650
|
+
toastTtlMs,
|
|
18651
|
+
processOperations,
|
|
18652
|
+
getSupervisor: () => supervisor,
|
|
18653
|
+
extensionHost,
|
|
18654
|
+
processGraphs,
|
|
18655
|
+
sessionReader,
|
|
18656
|
+
getProcessActionRegistry: () => processActionRegistry,
|
|
18657
|
+
getProcessUiRegistry: () => processUiRegistry,
|
|
18658
|
+
logger: app.log,
|
|
18659
|
+
processModelPolicy,
|
|
18660
|
+
getModelAvailabilitySnapshot: () => modelStatusCache.snapshot(),
|
|
18661
|
+
afterRecord(process2) {
|
|
18662
|
+
piResourceBundlePins.reconcile(process2);
|
|
18663
|
+
toolApprovalGate.reconcile(process2.id);
|
|
19277
18664
|
},
|
|
19278
|
-
|
|
19279
|
-
|
|
19280
|
-
|
|
19281
|
-
|
|
19282
|
-
|
|
19283
|
-
|
|
19284
|
-
|
|
19285
|
-
|
|
19286
|
-
|
|
19287
|
-
|
|
19288
|
-
|
|
18665
|
+
afterSuccessHooks,
|
|
18666
|
+
isNewTurnBlocked: (instanceId) => isNewTurnBlocked(instanceId),
|
|
18667
|
+
prepareTurnStarts: (process2, writes, providerOptions, availabilitySnapshot) => prepareCreatedTurnStarts(
|
|
18668
|
+
{
|
|
18669
|
+
config,
|
|
18670
|
+
registry: modelProviderRegistry,
|
|
18671
|
+
modelStatusCache,
|
|
18672
|
+
piContributions: extensionCatalog.piContributions,
|
|
18673
|
+
bundleCache: piResourceBundles,
|
|
18674
|
+
projects: baseDeps.projects,
|
|
18675
|
+
processSkills: baseDeps.processSkills
|
|
18676
|
+
},
|
|
18677
|
+
process2,
|
|
18678
|
+
writes,
|
|
18679
|
+
providerOptions,
|
|
18680
|
+
availabilitySnapshot
|
|
18681
|
+
)
|
|
18682
|
+
});
|
|
18683
|
+
const processQuestions = createProcessQuestionService({
|
|
18684
|
+
repos: baseDeps,
|
|
18685
|
+
processOperations,
|
|
18686
|
+
broadcaster,
|
|
18687
|
+
getWorkerId: (instanceId) => supervisor?.getWorker(instanceId)?.workerId ?? null,
|
|
18688
|
+
sendQuestionResponse: (instanceId, workerId, payload) => supervisor?.questionResponse(instanceId, workerId, payload),
|
|
18689
|
+
emitQuestionRequested: (request) => extensionHost.emit("question_requested", { instanceId: request.instanceId, request }).catch(
|
|
18690
|
+
(error) => app.log.error(
|
|
18691
|
+
{ error, instanceId: request.instanceId },
|
|
18692
|
+
"Question delivery event failed"
|
|
18693
|
+
)
|
|
18694
|
+
)
|
|
18695
|
+
});
|
|
18696
|
+
const toolApprovalGate = createToolApprovalGate({
|
|
18697
|
+
repos: baseDeps,
|
|
18698
|
+
processOperations
|
|
18699
|
+
});
|
|
18700
|
+
const integrationToolRequests = createIntegrationToolRequestService({
|
|
18701
|
+
registry: integrationTools,
|
|
18702
|
+
repos: baseDeps,
|
|
18703
|
+
processActionRegistry,
|
|
18704
|
+
toolApprovalGate
|
|
18705
|
+
});
|
|
18706
|
+
const diagnosticTraceWriter = createDiagnosticTraceWriter(
|
|
18707
|
+
path8.join(config.storage.tree_files_dir, "diagnostic-traces")
|
|
18708
|
+
);
|
|
18709
|
+
const ipcHandler = createIpcHandler(
|
|
18710
|
+
{
|
|
18711
|
+
startupObservations: baseDeps.startupObservations,
|
|
18712
|
+
processes: baseDeps.processes,
|
|
18713
|
+
getLaunchCoordinator: () => launchCoordinator,
|
|
18714
|
+
projects: baseDeps.projects,
|
|
18715
|
+
inputs: baseDeps.inputs,
|
|
18716
|
+
events: baseDeps.events,
|
|
18717
|
+
leases: baseDeps.leases,
|
|
18718
|
+
turnRecords: baseDeps.turnRecords,
|
|
18719
|
+
handleIntegrationToolRequest: (instanceId, payload) => integrationToolRequests.handle(instanceId, payload),
|
|
18720
|
+
handleIntegrationToolCancel: (instanceId, payload) => void integrationToolRequests.cancel(instanceId, payload),
|
|
18721
|
+
processQuestions,
|
|
18722
|
+
broadcaster,
|
|
18723
|
+
commands: processEngine,
|
|
18724
|
+
updateCredential: ({ providerId, expectedRevision, values }) => {
|
|
18725
|
+
const result = modelProviderCredentials.compareAndSet({
|
|
18726
|
+
providerId,
|
|
18727
|
+
expectedRevision,
|
|
18728
|
+
value: values
|
|
18729
|
+
});
|
|
18730
|
+
if (result.accepted && !lifecycle.isClosing()) {
|
|
18731
|
+
const work = refreshModelStatusAndApplyTransitions().catch((error) => {
|
|
18732
|
+
app.log.warn(
|
|
18733
|
+
{ error, providerId },
|
|
18734
|
+
"Model status refresh after credential update failed"
|
|
18735
|
+
);
|
|
18736
|
+
});
|
|
18737
|
+
modelRefreshWork.add(work);
|
|
18738
|
+
void work.finally(() => modelRefreshWork.delete(work));
|
|
19289
18739
|
}
|
|
19290
|
-
|
|
19291
|
-
|
|
19292
|
-
|
|
19293
|
-
|
|
19294
|
-
|
|
19295
|
-
|
|
19296
|
-
|
|
19297
|
-
|
|
19298
|
-
|
|
19299
|
-
|
|
19300
|
-
|
|
19301
|
-
|
|
18740
|
+
return result;
|
|
18741
|
+
},
|
|
18742
|
+
appendDiagnosticTrace(instanceId, text) {
|
|
18743
|
+
try {
|
|
18744
|
+
diagnosticTraceWriter.append(instanceId, text);
|
|
18745
|
+
} catch (error) {
|
|
18746
|
+
app.log.warn({ error, instanceId }, "Could not append worker diagnostic trace");
|
|
18747
|
+
}
|
|
18748
|
+
},
|
|
18749
|
+
workerEventLogger: config.workers.log_worker_events_to_stdout ? (entry) => {
|
|
18750
|
+
app.log.info({ source: "worker_event", ...entry }, "worker.event");
|
|
18751
|
+
} : void 0
|
|
19302
18752
|
},
|
|
19303
|
-
|
|
19304
|
-
|
|
18753
|
+
{
|
|
18754
|
+
onTurnTerminalRecorded(instanceId, workerId, turnRecordId) {
|
|
18755
|
+
supervisor?.acknowledgeTurnTerminal(instanceId, workerId, { turnRecordId });
|
|
18756
|
+
},
|
|
18757
|
+
onTurnFailedRecorded(input) {
|
|
18758
|
+
app.log.warn(input, "Worker turn failed");
|
|
18759
|
+
},
|
|
18760
|
+
onTurnTerminalRecordingFailed(input) {
|
|
18761
|
+
app.log.error(input, "Worker turn terminal recording failed");
|
|
18762
|
+
baseDeps.events.create({
|
|
18763
|
+
instanceId: input.instanceId,
|
|
18764
|
+
eventType: "worker_terminal_recording_failed",
|
|
18765
|
+
data: {
|
|
18766
|
+
workerId: input.workerId,
|
|
18767
|
+
turnRecordId: input.turnRecordId,
|
|
18768
|
+
terminalType: input.terminalType,
|
|
18769
|
+
code: input.code,
|
|
18770
|
+
message: input.message
|
|
18771
|
+
}
|
|
18772
|
+
});
|
|
18773
|
+
},
|
|
18774
|
+
onWorkerTurnStartAccepted(instanceId, workerId, payload) {
|
|
18775
|
+
supervisor?.acceptTurnStart(
|
|
18776
|
+
instanceId,
|
|
18777
|
+
workerId,
|
|
18778
|
+
payload.startRecordId,
|
|
18779
|
+
payload.turnRecordId
|
|
18780
|
+
);
|
|
18781
|
+
},
|
|
18782
|
+
onCredentialUpdateResult(instanceId, workerId, payload) {
|
|
18783
|
+
supervisor?.credentialUpdateResult(instanceId, workerId, payload);
|
|
18784
|
+
},
|
|
18785
|
+
onIntegrationToolResult(instanceId, workerId, payload) {
|
|
18786
|
+
supervisor?.integrationToolResult(instanceId, workerId, payload);
|
|
18787
|
+
}
|
|
19305
18788
|
}
|
|
19306
|
-
}
|
|
19307
|
-
);
|
|
19308
|
-
const repositoryCredentials = new RepositoryCredentialService(extensionCatalog.processes);
|
|
19309
|
-
const sessionTransferLimits = config.session_transfer ? {
|
|
19310
|
-
maxEntries: config.session_transfer.max_entries,
|
|
19311
|
-
maxLogicalBytes: config.session_transfer.max_logical_bytes,
|
|
19312
|
-
maxCompressedBytes: config.session_transfer.max_compressed_bytes
|
|
19313
|
-
} : DEFAULT_SESSION_TRANSFER_LIMITS;
|
|
19314
|
-
const sessionTransferHelperRelays = createSessionTransferHelperRelays({
|
|
19315
|
-
repos: baseDeps,
|
|
19316
|
-
limits: sessionTransferLimits
|
|
19317
|
-
});
|
|
19318
|
-
const supervisorConfig = config;
|
|
19319
|
-
const runnerRuntime = await createConfiguredWorkerRunnerRuntime({
|
|
19320
|
-
config: supervisorConfig,
|
|
19321
|
-
webSocketIpc: workerWebSocketIpc,
|
|
19322
|
-
provided: opts.workerRunnerRuntime,
|
|
19323
|
-
helperRelays: sessionTransferHelperRelays,
|
|
19324
|
-
onVolumePoolError: () => app.log.warn("Volume pre-provisioning failed; retrying in the background"),
|
|
19325
|
-
localWorkerSpawnImpl: opts.localWorkerSpawnImpl,
|
|
19326
|
-
localWorkerDockerPreflightImpl: opts.localWorkerDockerPreflightImpl
|
|
19327
|
-
});
|
|
19328
|
-
if (runnerRuntime.volumePool) {
|
|
19329
|
-
startHooks.push(() => runnerRuntime.volumePool?.start());
|
|
19330
|
-
stopHooks.push(() => runnerRuntime.volumePool?.stop());
|
|
19331
|
-
}
|
|
19332
|
-
markStartup("worker_runner");
|
|
19333
|
-
supervisor = createWorkerSupervisor({
|
|
19334
|
-
startupObservations: baseDeps.startupObservations,
|
|
19335
|
-
config: supervisorConfig,
|
|
19336
|
-
processGraphs,
|
|
19337
|
-
processActionRegistry,
|
|
19338
|
-
processModelPolicy,
|
|
19339
|
-
ipcHandler,
|
|
19340
|
-
leases: baseDeps.leases,
|
|
19341
|
-
getLaunchCoordinator: () => launchCoordinator,
|
|
19342
|
-
processes: baseDeps.processes,
|
|
19343
|
-
projects: baseDeps.projects,
|
|
19344
|
-
inputs: baseDeps.inputs,
|
|
19345
|
-
turnRecords: baseDeps.turnRecords,
|
|
19346
|
-
turnStarts: baseDeps.turnStarts,
|
|
19347
|
-
events: baseDeps.events,
|
|
19348
|
-
broadcaster,
|
|
19349
|
-
runnerRuntime,
|
|
19350
|
-
logger: app.log,
|
|
19351
|
-
resolvedExtensionEntriesJson: serializeResolvedExtensionEntries(resolvedExtensionEntries),
|
|
19352
|
-
serverEpoch,
|
|
19353
|
-
resolveResourceBundle(digest) {
|
|
19354
|
-
return piResourceBundles.get(digest);
|
|
19355
|
-
},
|
|
19356
|
-
resolveRepositoryCredentials: (input) => repositoryCredentials.resolveWorkerCredentials(input),
|
|
19357
|
-
integrationTools,
|
|
19358
|
-
resolveCredential: (providerId, options) => modelProviderCredentials.resolve(providerId, options)
|
|
19359
|
-
});
|
|
19360
|
-
let staleHeartbeatWatchdog = null;
|
|
19361
|
-
let retainedVolumeCleanupTimer = null;
|
|
19362
|
-
let retainedVolumeCleanupRunning = false;
|
|
19363
|
-
const releasedRetainedVolumes = /* @__PURE__ */ new Set();
|
|
19364
|
-
async function runRetainedVolumeCleanup() {
|
|
19365
|
-
if (retainedVolumeCleanupRunning) return;
|
|
19366
|
-
retainedVolumeCleanupRunning = true;
|
|
19367
|
-
const processes = baseDeps.processes.listAll();
|
|
19368
|
-
const now2 = /* @__PURE__ */ new Date();
|
|
19369
|
-
const policy = {
|
|
19370
|
-
completedProcessRetention: config.workers.cleanup.completed_process_retention,
|
|
19371
|
-
errorProcessRetention: config.workers.cleanup.error_process_retention
|
|
19372
|
-
};
|
|
19373
|
-
const expiredImageProcesses = new Set(
|
|
19374
|
-
planProcessVolumeRetentionCleanup({ processes, now: now2, policy })
|
|
19375
18789
|
);
|
|
19376
|
-
|
|
19377
|
-
|
|
19378
|
-
|
|
19379
|
-
|
|
19380
|
-
|
|
19381
|
-
|
|
19382
|
-
|
|
19383
|
-
|
|
19384
|
-
|
|
19385
|
-
}
|
|
19386
|
-
|
|
19387
|
-
|
|
19388
|
-
|
|
19389
|
-
|
|
19390
|
-
|
|
19391
|
-
|
|
19392
|
-
|
|
19393
|
-
|
|
19394
|
-
|
|
19395
|
-
}
|
|
19396
|
-
|
|
19397
|
-
|
|
19398
|
-
|
|
19399
|
-
}
|
|
19400
|
-
}
|
|
19401
|
-
startHooks.push(() => {
|
|
19402
|
-
if (!supervisor) {
|
|
19403
|
-
throw new Error("worker supervisor not initialized");
|
|
18790
|
+
const repositoryCredentials = new RepositoryCredentialService(extensionCatalog.processes);
|
|
18791
|
+
const sessionTransferLimits = config.session_transfer ? {
|
|
18792
|
+
maxEntries: config.session_transfer.max_entries,
|
|
18793
|
+
maxLogicalBytes: config.session_transfer.max_logical_bytes,
|
|
18794
|
+
maxCompressedBytes: config.session_transfer.max_compressed_bytes
|
|
18795
|
+
} : DEFAULT_SESSION_TRANSFER_LIMITS;
|
|
18796
|
+
const sessionTransferHelperRelays = createSessionTransferHelperRelays({
|
|
18797
|
+
repos: baseDeps,
|
|
18798
|
+
limits: sessionTransferLimits
|
|
18799
|
+
});
|
|
18800
|
+
const supervisorConfig = config;
|
|
18801
|
+
const runnerRuntime = await createConfiguredWorkerRunnerRuntime({
|
|
18802
|
+
config: supervisorConfig,
|
|
18803
|
+
webSocketIpc: workerWebSocketIpc,
|
|
18804
|
+
provided: opts.workerRunnerRuntime,
|
|
18805
|
+
helperRelays: sessionTransferHelperRelays,
|
|
18806
|
+
onVolumePoolError: () => app.log.warn("Volume pre-provisioning failed; retrying in the background"),
|
|
18807
|
+
localWorkerSpawnImpl: opts.localWorkerSpawnImpl,
|
|
18808
|
+
localWorkerDockerPreflightImpl: opts.localWorkerDockerPreflightImpl
|
|
18809
|
+
});
|
|
18810
|
+
if (runnerRuntime.volumePool) {
|
|
18811
|
+
startHooks.push(() => runnerRuntime.volumePool?.start());
|
|
18812
|
+
stopHooks.push(() => runnerRuntime.volumePool?.stop());
|
|
19404
18813
|
}
|
|
19405
|
-
|
|
19406
|
-
|
|
19407
|
-
|
|
19408
|
-
|
|
19409
|
-
|
|
19410
|
-
|
|
19411
|
-
|
|
19412
|
-
|
|
19413
|
-
);
|
|
19414
|
-
staleHeartbeatWatchdog = startStaleHeartbeatWatchdog({
|
|
18814
|
+
markStartup("worker_runner");
|
|
18815
|
+
supervisor = createWorkerSupervisor({
|
|
18816
|
+
startupObservations: baseDeps.startupObservations,
|
|
18817
|
+
config: supervisorConfig,
|
|
18818
|
+
processGraphs,
|
|
18819
|
+
processActionRegistry,
|
|
18820
|
+
processModelPolicy,
|
|
18821
|
+
ipcHandler,
|
|
19415
18822
|
leases: baseDeps.leases,
|
|
18823
|
+
getLaunchCoordinator: () => launchCoordinator,
|
|
19416
18824
|
processes: baseDeps.processes,
|
|
18825
|
+
projects: baseDeps.projects,
|
|
18826
|
+
inputs: baseDeps.inputs,
|
|
19417
18827
|
turnRecords: baseDeps.turnRecords,
|
|
19418
18828
|
turnStarts: baseDeps.turnStarts,
|
|
19419
|
-
|
|
19420
|
-
|
|
19421
|
-
|
|
18829
|
+
events: baseDeps.events,
|
|
18830
|
+
broadcaster,
|
|
18831
|
+
runnerRuntime,
|
|
18832
|
+
logger: app.log,
|
|
18833
|
+
resolvedExtensionEntriesJson: serializeResolvedExtensionEntries(resolvedExtensionEntries),
|
|
18834
|
+
serverEpoch,
|
|
18835
|
+
resolveResourceBundle(digest) {
|
|
18836
|
+
return piResourceBundles.get(digest);
|
|
18837
|
+
},
|
|
18838
|
+
resolveRepositoryCredentials: (input) => repositoryCredentials.resolveWorkerCredentials(input),
|
|
18839
|
+
integrationTools,
|
|
18840
|
+
resolveCredential: (providerId, options) => modelProviderCredentials.resolve(providerId, options)
|
|
19422
18841
|
});
|
|
19423
|
-
|
|
19424
|
-
|
|
19425
|
-
|
|
19426
|
-
|
|
19427
|
-
|
|
19428
|
-
|
|
19429
|
-
|
|
18842
|
+
let staleHeartbeatWatchdog = null;
|
|
18843
|
+
let workersClosedForServerShutdown = false;
|
|
18844
|
+
stopAcquiredWorkers = async () => {
|
|
18845
|
+
if (workersClosedForServerShutdown) return;
|
|
18846
|
+
workersClosedForServerShutdown = true;
|
|
18847
|
+
if (config.workers.runner === "local") await supervisor?.shutdownAll("server_shutdown");
|
|
18848
|
+
else await supervisor?.detachAll("server_shutdown");
|
|
18849
|
+
};
|
|
18850
|
+
let retentionWork;
|
|
18851
|
+
let retainedVolumeCleanupTimer = null;
|
|
18852
|
+
let retainedVolumeCleanupRunning = false;
|
|
18853
|
+
const releasedRetainedVolumes = /* @__PURE__ */ new Set();
|
|
18854
|
+
async function runRetainedVolumeCleanup() {
|
|
18855
|
+
if (retainedVolumeCleanupRunning) return;
|
|
18856
|
+
retainedVolumeCleanupRunning = true;
|
|
18857
|
+
const processes = baseDeps.processes.listAll();
|
|
18858
|
+
const now2 = /* @__PURE__ */ new Date();
|
|
18859
|
+
const policy = {
|
|
18860
|
+
completedProcessRetention: config.workers.cleanup.completed_process_retention,
|
|
18861
|
+
errorProcessRetention: config.workers.cleanup.error_process_retention
|
|
18862
|
+
};
|
|
18863
|
+
const expiredImageProcesses = new Set(
|
|
18864
|
+
planProcessVolumeRetentionCleanup({ processes, now: now2, policy })
|
|
18865
|
+
);
|
|
18866
|
+
try {
|
|
18867
|
+
const released = await cleanupRetainedProcessVolumes({
|
|
18868
|
+
volume: runnerRuntime.volume,
|
|
18869
|
+
processes,
|
|
18870
|
+
now: now2,
|
|
18871
|
+
policy,
|
|
18872
|
+
alreadyReleased: releasedRetainedVolumes
|
|
18873
|
+
});
|
|
18874
|
+
for (const instanceId of released) releasedRetainedVolumes.add(instanceId);
|
|
18875
|
+
} catch (error) {
|
|
18876
|
+
app.log.warn({ error }, "retained process volume cleanup failed");
|
|
18877
|
+
}
|
|
18878
|
+
try {
|
|
18879
|
+
await resultImages.cleanupProcesses({
|
|
18880
|
+
// Refresh after volume cleanup so a process created during the sweep is
|
|
18881
|
+
// never mistaken for an orphan.
|
|
18882
|
+
retainedInstanceIds: new Set(baseDeps.processes.listAll().map((process2) => process2.id)),
|
|
18883
|
+
expiredInstanceIds: expiredImageProcesses
|
|
18884
|
+
});
|
|
18885
|
+
} catch (error) {
|
|
18886
|
+
app.log.warn({ error }, "retained result image cleanup failed");
|
|
18887
|
+
} finally {
|
|
18888
|
+
retainedVolumeCleanupRunning = false;
|
|
18889
|
+
}
|
|
19430
18890
|
}
|
|
19431
|
-
|
|
19432
|
-
|
|
19433
|
-
|
|
19434
|
-
|
|
19435
|
-
|
|
19436
|
-
|
|
19437
|
-
|
|
19438
|
-
|
|
19439
|
-
|
|
19440
|
-
|
|
19441
|
-
|
|
19442
|
-
|
|
19443
|
-
|
|
19444
|
-
|
|
19445
|
-
|
|
19446
|
-
|
|
19447
|
-
|
|
19448
|
-
|
|
19449
|
-
|
|
19450
|
-
|
|
19451
|
-
|
|
19452
|
-
|
|
19453
|
-
|
|
19454
|
-
|
|
19455
|
-
|
|
19456
|
-
|
|
19457
|
-
|
|
19458
|
-
|
|
19459
|
-
|
|
19460
|
-
|
|
19461
|
-
|
|
19462
|
-
|
|
19463
|
-
|
|
19464
|
-
|
|
19465
|
-
|
|
19466
|
-
|
|
19467
|
-
|
|
19468
|
-
|
|
19469
|
-
|
|
19470
|
-
|
|
19471
|
-
|
|
19472
|
-
|
|
19473
|
-
|
|
19474
|
-
|
|
19475
|
-
processOperations,
|
|
19476
|
-
processTitles,
|
|
19477
|
-
extensionHost,
|
|
19478
|
-
launcherService,
|
|
19479
|
-
launcherRecentValues,
|
|
19480
|
-
processGraphs,
|
|
19481
|
-
processActionRegistry: processActionRegistry ?? void 0,
|
|
19482
|
-
processModelPolicy,
|
|
19483
|
-
launchPlans,
|
|
19484
|
-
modelStatusCache,
|
|
19485
|
-
launchPipeline,
|
|
19486
|
-
assertRuntimeAvailable: (processId) => assertProcessRuntimeAvailable(
|
|
18891
|
+
startHooks.push(() => {
|
|
18892
|
+
if (!supervisor) {
|
|
18893
|
+
throw new Error("worker supervisor not initialized");
|
|
18894
|
+
}
|
|
18895
|
+
retentionWork = runRetainedVolumeCleanup();
|
|
18896
|
+
const cleanupIntervalMs = Math.max(
|
|
18897
|
+
6e4,
|
|
18898
|
+
parseDurationMs8(config.workers.cleanup.transient_ttl, 36e5, { allowHours: true })
|
|
18899
|
+
);
|
|
18900
|
+
retainedVolumeCleanupTimer = setInterval(() => {
|
|
18901
|
+
if (!retainedVolumeCleanupRunning) retentionWork = runRetainedVolumeCleanup();
|
|
18902
|
+
}, cleanupIntervalMs);
|
|
18903
|
+
staleHeartbeatWatchdog = startStaleHeartbeatWatchdog({
|
|
18904
|
+
leases: baseDeps.leases,
|
|
18905
|
+
processes: baseDeps.processes,
|
|
18906
|
+
turnRecords: baseDeps.turnRecords,
|
|
18907
|
+
turnStarts: baseDeps.turnStarts,
|
|
18908
|
+
ipcHandler,
|
|
18909
|
+
supervisor,
|
|
18910
|
+
staleHeartbeatTimeout: config.workers.stale_heartbeat_timeout
|
|
18911
|
+
});
|
|
18912
|
+
});
|
|
18913
|
+
stopHooks.push(async () => {
|
|
18914
|
+
staleHeartbeatWatchdog?.stop();
|
|
18915
|
+
staleHeartbeatWatchdog = null;
|
|
18916
|
+
if (retainedVolumeCleanupTimer) {
|
|
18917
|
+
clearInterval(retainedVolumeCleanupTimer);
|
|
18918
|
+
retainedVolumeCleanupTimer = null;
|
|
18919
|
+
}
|
|
18920
|
+
await retentionWork;
|
|
18921
|
+
});
|
|
18922
|
+
if (processTitles?.start) {
|
|
18923
|
+
startHooks.push(() => processTitles.start?.());
|
|
18924
|
+
}
|
|
18925
|
+
if (processTitles?.close) {
|
|
18926
|
+
stopHooks.push(() => processTitles.close?.());
|
|
18927
|
+
}
|
|
18928
|
+
const launchPipeline = createLaunchPipeline({
|
|
18929
|
+
launchRuns: baseDeps.launchRuns,
|
|
18930
|
+
broadcaster,
|
|
18931
|
+
titleGenerationAvailable: Boolean(processTitles),
|
|
18932
|
+
logger: app.log
|
|
18933
|
+
});
|
|
18934
|
+
const assertRuntimeAvailable = (processId) => assertProcessRuntimeAvailable(
|
|
19487
18935
|
{
|
|
19488
18936
|
config,
|
|
19489
18937
|
processes: extensionCatalog.processes,
|
|
19490
18938
|
dockerInfo: opts.localWorkerDockerPreflightImpl
|
|
19491
18939
|
},
|
|
19492
18940
|
processId
|
|
19493
|
-
)
|
|
19494
|
-
|
|
19495
|
-
|
|
19496
|
-
|
|
19497
|
-
|
|
19498
|
-
|
|
19499
|
-
|
|
19500
|
-
|
|
19501
|
-
|
|
19502
|
-
|
|
19503
|
-
|
|
19504
|
-
|
|
19505
|
-
|
|
19506
|
-
|
|
19507
|
-
|
|
19508
|
-
|
|
19509
|
-
|
|
19510
|
-
|
|
19511
|
-
|
|
19512
|
-
|
|
19513
|
-
|
|
19514
|
-
|
|
19515
|
-
|
|
19516
|
-
|
|
19517
|
-
|
|
19518
|
-
|
|
19519
|
-
|
|
19520
|
-
|
|
19521
|
-
|
|
19522
|
-
|
|
19523
|
-
|
|
19524
|
-
|
|
19525
|
-
|
|
19526
|
-
|
|
19527
|
-
|
|
19528
|
-
|
|
19529
|
-
|
|
19530
|
-
|
|
19531
|
-
|
|
19532
|
-
|
|
19533
|
-
|
|
19534
|
-
|
|
19535
|
-
|
|
19536
|
-
|
|
19537
|
-
|
|
19538
|
-
|
|
19539
|
-
|
|
19540
|
-
|
|
19541
|
-
|
|
19542
|
-
|
|
19543
|
-
|
|
19544
|
-
|
|
19545
|
-
|
|
19546
|
-
|
|
19547
|
-
|
|
19548
|
-
|
|
19549
|
-
|
|
19550
|
-
|
|
19551
|
-
|
|
19552
|
-
|
|
19553
|
-
|
|
19554
|
-
|
|
19555
|
-
|
|
19556
|
-
|
|
19557
|
-
|
|
19558
|
-
|
|
19559
|
-
|
|
19560
|
-
|
|
19561
|
-
|
|
19562
|
-
|
|
19563
|
-
|
|
19564
|
-
|
|
19565
|
-
processes: baseDeps.processes,
|
|
19566
|
-
processEngine,
|
|
19567
|
-
processOperations,
|
|
19568
|
-
supervisor,
|
|
19569
|
-
volume: runnerRuntime.volume,
|
|
19570
|
-
sessionSnapshots,
|
|
19571
|
-
resultImages,
|
|
19572
|
-
sessionTransfers,
|
|
19573
|
-
deletionPending,
|
|
19574
|
-
broadcaster,
|
|
19575
|
-
logger: app.log
|
|
19576
|
-
});
|
|
19577
|
-
const processActionListDeps = {
|
|
19578
|
-
projects: baseDeps.projects,
|
|
19579
|
-
futureExecutions: baseDeps.futureExecutions,
|
|
19580
|
-
turnRecords: baseDeps.turnRecords,
|
|
19581
|
-
turnStarts: baseDeps.turnStarts,
|
|
19582
|
-
processGraphs,
|
|
19583
|
-
processActionRegistry
|
|
19584
|
-
};
|
|
19585
|
-
const processModelSelection = createProcessModelSelection({
|
|
19586
|
-
processGraphs,
|
|
19587
|
-
processActionRegistry,
|
|
19588
|
-
processes: baseDeps.processes,
|
|
19589
|
-
projects: baseDeps.projects,
|
|
19590
|
-
scheduledActions: baseDeps.futureExecutions,
|
|
19591
|
-
turnRecords: baseDeps.turnRecords,
|
|
19592
|
-
turnStarts: baseDeps.turnStarts,
|
|
19593
|
-
instanceTrees: sessionReader,
|
|
19594
|
-
processModelPolicy,
|
|
19595
|
-
modelStatusCache
|
|
19596
|
-
});
|
|
19597
|
-
const hostCapabilities = buildHostCapabilities({
|
|
19598
|
-
config,
|
|
19599
|
-
baseDeps,
|
|
19600
|
-
projectMutations,
|
|
19601
|
-
commands: processEngine,
|
|
19602
|
-
getSupervisor: () => supervisor,
|
|
19603
|
-
listVisibleActionsForProcess(instanceId) {
|
|
18941
|
+
);
|
|
18942
|
+
const processLaunchDeps = {
|
|
18943
|
+
...baseDeps,
|
|
18944
|
+
broadcaster,
|
|
18945
|
+
commands: processEngine,
|
|
18946
|
+
processTitles,
|
|
18947
|
+
extensionHost,
|
|
18948
|
+
logger: app.log,
|
|
18949
|
+
repositoryCredentials,
|
|
18950
|
+
getSupervisor: () => supervisor,
|
|
18951
|
+
assertRuntimeAvailable
|
|
18952
|
+
};
|
|
18953
|
+
const createProcess = createProcessFromLaunchPlan.bind(null, processLaunchDeps);
|
|
18954
|
+
futureExecutionLifecycle = createFutureExecutionLifecycle({
|
|
18955
|
+
futureExecutions: baseDeps.futureExecutions,
|
|
18956
|
+
processes: baseDeps.processes,
|
|
18957
|
+
projects: baseDeps.projects,
|
|
18958
|
+
processRelations: baseDeps.processRelations,
|
|
18959
|
+
handoffDedupKeys: baseDeps.handoffDedupKeys,
|
|
18960
|
+
turnRecords: baseDeps.turnRecords,
|
|
18961
|
+
skills: baseDeps.skills,
|
|
18962
|
+
processSkills: baseDeps.processSkills,
|
|
18963
|
+
transaction: baseDeps.transaction,
|
|
18964
|
+
broadcaster,
|
|
18965
|
+
commands: processEngine,
|
|
18966
|
+
processOperations,
|
|
18967
|
+
processTitles,
|
|
18968
|
+
extensionHost,
|
|
18969
|
+
launcherService,
|
|
18970
|
+
launcherRecentValues,
|
|
18971
|
+
processGraphs,
|
|
18972
|
+
processActionRegistry: processActionRegistry ?? void 0,
|
|
18973
|
+
processModelPolicy,
|
|
18974
|
+
launchPlans,
|
|
18975
|
+
modelStatusCache,
|
|
18976
|
+
launchPipeline,
|
|
18977
|
+
assertRuntimeAvailable,
|
|
18978
|
+
logger: app.log
|
|
18979
|
+
});
|
|
18980
|
+
applyGeneratedFutureExecutionTitle = (input) => futureExecutionLifecycle.applyGeneratedFutureLaunchTitleIfUnchanged(input);
|
|
18981
|
+
launchCoordinator = createLaunchCoordinator({
|
|
18982
|
+
events: baseDeps.events,
|
|
18983
|
+
commands: processEngine,
|
|
18984
|
+
launchRuns: baseDeps.launchRuns,
|
|
18985
|
+
processes: baseDeps.processes,
|
|
18986
|
+
leases: baseDeps.leases,
|
|
18987
|
+
turnRecords: baseDeps.turnRecords,
|
|
18988
|
+
turnStarts: baseDeps.turnStarts,
|
|
18989
|
+
titleJobs: baseDeps.titleJobs,
|
|
18990
|
+
launcherService,
|
|
18991
|
+
futureExecutionLifecycle,
|
|
18992
|
+
launchPipeline,
|
|
18993
|
+
launchPlans,
|
|
18994
|
+
createProcessFromLaunchPlan: createProcess,
|
|
18995
|
+
titleGenerationAvailable: Boolean(processTitles),
|
|
18996
|
+
logger: app.log
|
|
18997
|
+
});
|
|
18998
|
+
startHooks.push(() => launchCoordinator?.reconcileIncomplete());
|
|
18999
|
+
const futureExecutionScheduler = startFutureExecutionScheduler(futureExecutionLifecycle);
|
|
19000
|
+
startHooks.push(() => futureExecutionScheduler.start());
|
|
19001
|
+
stopHooks.push(() => futureExecutionScheduler.stop());
|
|
19002
|
+
const externalSourceService = createExternalSourceService({
|
|
19003
|
+
events: baseDeps.events,
|
|
19004
|
+
processes: baseDeps.processes,
|
|
19005
|
+
projects: baseDeps.projects,
|
|
19006
|
+
pendingExternalSourceFires: baseDeps.pendingExternalSourceFires,
|
|
19007
|
+
commands: processEngine,
|
|
19008
|
+
processActionRegistry
|
|
19009
|
+
});
|
|
19010
|
+
invalidateExternalSourceArmings = (instanceId) => externalSourceService.invalidateArmings(instanceId);
|
|
19011
|
+
startHooks.push(() => externalSourceService.reconcileAllArmings());
|
|
19012
|
+
afterSuccessHooks.add(async (instanceId) => {
|
|
19604
19013
|
const process2 = baseDeps.processes.getById(instanceId);
|
|
19605
|
-
|
|
19606
|
-
|
|
19607
|
-
|
|
19608
|
-
|
|
19609
|
-
|
|
19610
|
-
|
|
19611
|
-
|
|
19612
|
-
|
|
19613
|
-
|
|
19614
|
-
|
|
19615
|
-
|
|
19616
|
-
|
|
19617
|
-
|
|
19618
|
-
|
|
19619
|
-
|
|
19620
|
-
});
|
|
19621
|
-
await setupServerExtensions(
|
|
19622
|
-
extensionCatalog,
|
|
19623
|
-
{
|
|
19624
|
-
events: extensionHost,
|
|
19014
|
+
if (process2) piResourceBundlePins.reconcile(process2);
|
|
19015
|
+
await externalSourceService.reconcileArmings(instanceId);
|
|
19016
|
+
await externalSourceService.drainQueued(instanceId);
|
|
19017
|
+
});
|
|
19018
|
+
if (!supervisor) throw new Error("worker supervisor not initialized");
|
|
19019
|
+
const deletionPending = /* @__PURE__ */ new Set();
|
|
19020
|
+
const sessionTransfers = createSessionTransferService({
|
|
19021
|
+
repos: baseDeps,
|
|
19022
|
+
processOperations,
|
|
19023
|
+
supervisor,
|
|
19024
|
+
exporter: runnerRuntime.exporter,
|
|
19025
|
+
helperRelays: sessionTransferHelperRelays,
|
|
19026
|
+
sessionSource: sessionSnapshots,
|
|
19027
|
+
config,
|
|
19028
|
+
limits: sessionTransferLimits,
|
|
19625
19029
|
logger: app.log,
|
|
19626
|
-
|
|
19627
|
-
|
|
19628
|
-
|
|
19629
|
-
|
|
19630
|
-
|
|
19631
|
-
|
|
19632
|
-
},
|
|
19633
|
-
onStop(handler) {
|
|
19634
|
-
stopHooks.push(handler);
|
|
19635
|
-
}
|
|
19636
|
-
},
|
|
19637
|
-
(id) => config.extensions?.[id]
|
|
19638
|
-
);
|
|
19639
|
-
integrationTools.validateTicketProcesses(extensionCatalog.processes);
|
|
19640
|
-
startHooks.push(() => polling.start());
|
|
19641
|
-
stopHooks.push(() => polling.stop());
|
|
19642
|
-
for (const process2 of extensionCatalog.processes.values()) {
|
|
19643
|
-
for (const [turnId, binding2] of process2.turns) {
|
|
19644
|
-
const definition = binding2.definition;
|
|
19645
|
-
if (definition.kind !== "llm" || !definition.integrationTools?.length) continue;
|
|
19646
|
-
try {
|
|
19647
|
-
integrationTools.declarations(definition.integrationTools);
|
|
19648
|
-
} catch (error) {
|
|
19649
|
-
throw new Error(
|
|
19650
|
-
`Invalid integration tools for process '${process2.id}' turn '${turnId}': ${error instanceof Error ? error.message : String(error)}`
|
|
19030
|
+
isDeletionPending: (instanceId) => deletionPending.has(instanceId),
|
|
19031
|
+
onUpdated: (attempt) => {
|
|
19032
|
+
broadcaster.sendDurable(
|
|
19033
|
+
"session_transfer.updated",
|
|
19034
|
+
{ attemptId: attempt.id },
|
|
19035
|
+
attempt.instanceId
|
|
19651
19036
|
);
|
|
19652
19037
|
}
|
|
19653
|
-
}
|
|
19654
|
-
|
|
19655
|
-
|
|
19656
|
-
|
|
19657
|
-
|
|
19658
|
-
|
|
19659
|
-
|
|
19660
|
-
|
|
19661
|
-
|
|
19662
|
-
|
|
19663
|
-
|
|
19664
|
-
|
|
19665
|
-
|
|
19666
|
-
|
|
19667
|
-
|
|
19668
|
-
|
|
19669
|
-
|
|
19670
|
-
|
|
19671
|
-
|
|
19672
|
-
|
|
19673
|
-
|
|
19674
|
-
|
|
19675
|
-
|
|
19676
|
-
|
|
19677
|
-
|
|
19678
|
-
|
|
19679
|
-
|
|
19680
|
-
|
|
19681
|
-
|
|
19682
|
-
|
|
19683
|
-
|
|
19684
|
-
|
|
19685
|
-
|
|
19686
|
-
|
|
19687
|
-
|
|
19688
|
-
|
|
19689
|
-
|
|
19690
|
-
|
|
19691
|
-
|
|
19692
|
-
|
|
19693
|
-
|
|
19694
|
-
|
|
19695
|
-
|
|
19696
|
-
|
|
19697
|
-
|
|
19698
|
-
|
|
19699
|
-
|
|
19700
|
-
|
|
19701
|
-
|
|
19702
|
-
|
|
19703
|
-
|
|
19704
|
-
|
|
19705
|
-
|
|
19706
|
-
|
|
19707
|
-
|
|
19708
|
-
|
|
19709
|
-
|
|
19710
|
-
|
|
19711
|
-
|
|
19712
|
-
|
|
19713
|
-
|
|
19714
|
-
|
|
19715
|
-
|
|
19716
|
-
|
|
19717
|
-
|
|
19718
|
-
|
|
19719
|
-
|
|
19720
|
-
|
|
19721
|
-
|
|
19722
|
-
|
|
19723
|
-
|
|
19724
|
-
|
|
19038
|
+
});
|
|
19039
|
+
isNewTurnBlocked = (instanceId) => {
|
|
19040
|
+
const attempt = sessionTransfers.activeForProcess(instanceId);
|
|
19041
|
+
return attempt?.state === "queued" || attempt?.state === "exporting";
|
|
19042
|
+
};
|
|
19043
|
+
startHooks.push(async () => {
|
|
19044
|
+
await sessionTransfers.reconcile();
|
|
19045
|
+
sessionTransfers.start();
|
|
19046
|
+
});
|
|
19047
|
+
stopHooks.push(() => sessionTransfers.stop());
|
|
19048
|
+
const processDeletion = createProcessDeletionService({
|
|
19049
|
+
processes: baseDeps.processes,
|
|
19050
|
+
processEngine,
|
|
19051
|
+
processOperations,
|
|
19052
|
+
supervisor,
|
|
19053
|
+
volume: runnerRuntime.volume,
|
|
19054
|
+
sessionSnapshots,
|
|
19055
|
+
resultImages,
|
|
19056
|
+
sessionTransfers,
|
|
19057
|
+
deletionPending,
|
|
19058
|
+
broadcaster,
|
|
19059
|
+
logger: app.log
|
|
19060
|
+
});
|
|
19061
|
+
const processActionListDeps = {
|
|
19062
|
+
projects: baseDeps.projects,
|
|
19063
|
+
futureExecutions: baseDeps.futureExecutions,
|
|
19064
|
+
turnRecords: baseDeps.turnRecords,
|
|
19065
|
+
turnStarts: baseDeps.turnStarts,
|
|
19066
|
+
processGraphs,
|
|
19067
|
+
processActionRegistry
|
|
19068
|
+
};
|
|
19069
|
+
const processModelSelection = createProcessModelSelection({
|
|
19070
|
+
processGraphs,
|
|
19071
|
+
processActionRegistry,
|
|
19072
|
+
processes: baseDeps.processes,
|
|
19073
|
+
projects: baseDeps.projects,
|
|
19074
|
+
scheduledActions: baseDeps.futureExecutions,
|
|
19075
|
+
turnRecords: baseDeps.turnRecords,
|
|
19076
|
+
turnStarts: baseDeps.turnStarts,
|
|
19077
|
+
instanceTrees: sessionReader,
|
|
19078
|
+
processModelPolicy,
|
|
19079
|
+
modelStatusCache
|
|
19080
|
+
});
|
|
19081
|
+
const hostCapabilities = buildHostCapabilities({
|
|
19082
|
+
config,
|
|
19083
|
+
baseDeps,
|
|
19084
|
+
projectMutations,
|
|
19085
|
+
commands: processEngine,
|
|
19086
|
+
getSupervisor: () => supervisor,
|
|
19087
|
+
listVisibleActionsForProcess(instanceId) {
|
|
19088
|
+
const process2 = baseDeps.processes.getById(instanceId);
|
|
19089
|
+
return process2 ? listVisibleActionsForProcess(processActionListDeps, process2) : [];
|
|
19090
|
+
},
|
|
19091
|
+
launcherService,
|
|
19092
|
+
launcherRecentValues,
|
|
19093
|
+
launcherModelConfigs,
|
|
19094
|
+
launchPlans,
|
|
19095
|
+
processWatcherService,
|
|
19096
|
+
polling,
|
|
19097
|
+
externalSourceService,
|
|
19098
|
+
processModelSelection,
|
|
19099
|
+
resultImages,
|
|
19100
|
+
repositoryCredentials,
|
|
19101
|
+
processQuestions,
|
|
19102
|
+
launchCoordinator,
|
|
19103
|
+
preProvidedCapabilities: opts.preProvidedCapabilities
|
|
19104
|
+
});
|
|
19105
|
+
await setupServerExtensions(
|
|
19106
|
+
extensionCatalog,
|
|
19107
|
+
{
|
|
19108
|
+
events: extensionHost,
|
|
19109
|
+
logger: app.log,
|
|
19110
|
+
provide: hostCapabilities.provide.bind(hostCapabilities),
|
|
19111
|
+
get: hostCapabilities.get.bind(hostCapabilities),
|
|
19112
|
+
require: hostCapabilities.require.bind(hostCapabilities),
|
|
19113
|
+
tool: (definition) => integrationTools.register(definition),
|
|
19114
|
+
onStart(handler) {
|
|
19115
|
+
startHooks.push(handler);
|
|
19116
|
+
},
|
|
19117
|
+
onStop(handler) {
|
|
19118
|
+
stopHooks.push(handler);
|
|
19119
|
+
}
|
|
19120
|
+
},
|
|
19121
|
+
(id) => config.extensions?.[id]
|
|
19122
|
+
);
|
|
19123
|
+
integrationTools.validateTicketProcesses(extensionCatalog.processes);
|
|
19124
|
+
startHooks.push(() => polling.start());
|
|
19125
|
+
stopHooks.push(() => polling.stop());
|
|
19126
|
+
for (const process2 of extensionCatalog.processes.values()) {
|
|
19127
|
+
for (const [turnId, binding2] of process2.turns) {
|
|
19128
|
+
const definition = binding2.definition;
|
|
19129
|
+
if (definition.kind !== "llm" || !definition.integrationTools?.length) continue;
|
|
19130
|
+
try {
|
|
19131
|
+
integrationTools.declarations(definition.integrationTools);
|
|
19132
|
+
} catch (error) {
|
|
19133
|
+
throw new Error(
|
|
19134
|
+
`Invalid integration tools for process '${process2.id}' turn '${turnId}': ${error instanceof Error ? error.message : String(error)}`
|
|
19135
|
+
);
|
|
19136
|
+
}
|
|
19725
19137
|
}
|
|
19726
19138
|
}
|
|
19727
|
-
|
|
19728
|
-
|
|
19729
|
-
|
|
19730
|
-
|
|
19731
|
-
|
|
19732
|
-
|
|
19733
|
-
|
|
19734
|
-
|
|
19735
|
-
|
|
19736
|
-
|
|
19737
|
-
|
|
19738
|
-
|
|
19739
|
-
|
|
19740
|
-
|
|
19741
|
-
|
|
19742
|
-
|
|
19743
|
-
|
|
19744
|
-
|
|
19745
|
-
|
|
19746
|
-
|
|
19747
|
-
|
|
19139
|
+
markStartup("server_extensions");
|
|
19140
|
+
const deps = {
|
|
19141
|
+
externalSourceService,
|
|
19142
|
+
...baseDeps,
|
|
19143
|
+
launchCoordinator,
|
|
19144
|
+
processGraphs,
|
|
19145
|
+
supervisor,
|
|
19146
|
+
processEngine,
|
|
19147
|
+
processQuestions,
|
|
19148
|
+
toolApprovalGate,
|
|
19149
|
+
processDeletion,
|
|
19150
|
+
processActionRegistry,
|
|
19151
|
+
processUiRegistry,
|
|
19152
|
+
extensionHost,
|
|
19153
|
+
launcherService,
|
|
19154
|
+
launcherRecentValues,
|
|
19155
|
+
launchPlans,
|
|
19156
|
+
processTitles,
|
|
19157
|
+
toolRenderers: extensionCatalog.toolRenderers,
|
|
19158
|
+
config,
|
|
19159
|
+
sessionReader,
|
|
19160
|
+
futureExecutionLifecycle,
|
|
19161
|
+
modelProviderRegistry,
|
|
19162
|
+
modelProviderCredentialStatus: modelProviderCredentials.status,
|
|
19163
|
+
modelStatusCache,
|
|
19164
|
+
processModelPolicy,
|
|
19165
|
+
processModelSelection,
|
|
19166
|
+
skillCatalog,
|
|
19167
|
+
sessionTransferService: sessionTransfers
|
|
19168
|
+
};
|
|
19169
|
+
registerHttp({
|
|
19170
|
+
app,
|
|
19171
|
+
isReady: () => lifecycle.isReady(),
|
|
19172
|
+
deps,
|
|
19173
|
+
authService,
|
|
19174
|
+
processWatcherService,
|
|
19175
|
+
extensionUiCatalog,
|
|
19176
|
+
integrationTools,
|
|
19177
|
+
sessionSnapshots,
|
|
19178
|
+
resultImages,
|
|
19179
|
+
maxSessionSnapshotBytes: config.workers.session_snapshot_max_size_bytes,
|
|
19180
|
+
extensionUiAssetCacheControl: process.env.LEITWERK_RUNTIME_LANE === "source" ? "no-store" : void 0
|
|
19181
|
+
});
|
|
19182
|
+
markStartup("routes_ready");
|
|
19183
|
+
const lifecycle = createAppLifecycle({
|
|
19184
|
+
app,
|
|
19185
|
+
server: config.server,
|
|
19186
|
+
authEnabled: authService.config.enabled,
|
|
19187
|
+
reconcile: reconcileStartup,
|
|
19188
|
+
startHooks,
|
|
19189
|
+
preCloseCleanup,
|
|
19190
|
+
closeDatabase: () => closeOwnedDatabase?.()
|
|
19191
|
+
});
|
|
19192
|
+
finishCleanup = lifecycle.finishCleanup;
|
|
19193
|
+
return {
|
|
19194
|
+
app,
|
|
19195
|
+
db,
|
|
19196
|
+
broadcaster,
|
|
19197
|
+
config,
|
|
19198
|
+
deps,
|
|
19199
|
+
modelProviderRegistry,
|
|
19200
|
+
modelProviderServerAdapters,
|
|
19201
|
+
modelStatusCache,
|
|
19202
|
+
extensionUiCatalog,
|
|
19203
|
+
processGraphs,
|
|
19204
|
+
extensionHost,
|
|
19205
|
+
projectMutations,
|
|
19206
|
+
ipcHandler,
|
|
19207
|
+
supervisor,
|
|
19208
|
+
listen: lifecycle.listen,
|
|
19209
|
+
close: lifecycle.close,
|
|
19210
|
+
isReady: lifecycle.isReady
|
|
19211
|
+
};
|
|
19212
|
+
} catch (error) {
|
|
19213
|
+
const errors = [
|
|
19214
|
+
error,
|
|
19215
|
+
...await collectCleanupErrors([
|
|
19216
|
+
() => app.close(),
|
|
19217
|
+
() => closeOwnedDatabase?.(),
|
|
19218
|
+
...preCloseCleanup
|
|
19219
|
+
])
|
|
19220
|
+
];
|
|
19221
|
+
if (errors.length > 1)
|
|
19222
|
+
throw new AggregateError(errors, "Context construction and cleanup failed", { cause: error });
|
|
19223
|
+
throw error;
|
|
19224
|
+
}
|
|
19748
19225
|
}
|
|
19749
19226
|
|
|
19750
19227
|
export {
|
|
19751
|
-
buildExtensionUiCatalog,
|
|
19752
|
-
resolveExtensionUiAssetPath,
|
|
19753
|
-
inferExtensionUiAssetContentType,
|
|
19754
|
-
createExtensionHost,
|
|
19755
|
-
buildTurnSelectionWrites,
|
|
19756
|
-
emitDeferredExtensionEvent,
|
|
19757
|
-
buildProjectUpdatedFrame,
|
|
19758
|
-
buildProjectUpdatedEffect,
|
|
19759
|
-
commitProjectCreate,
|
|
19760
|
-
commitProjectUpdate,
|
|
19761
|
-
createProjectMutationService,
|
|
19762
|
-
createBuiltinPiServerAdapter,
|
|
19763
|
-
createModelProviderCredentialService,
|
|
19764
|
-
createModelStatusCache,
|
|
19765
|
-
resolveRegisteredProviderOptions,
|
|
19766
|
-
validateConfiguredProviderOptions,
|
|
19767
|
-
loadProviderOptionChoices,
|
|
19768
|
-
defaultModelProviderCredentialStatus,
|
|
19769
|
-
createModelProviderRegistry,
|
|
19770
|
-
createModelProviderServerAdapterRegistry,
|
|
19771
|
-
assemblePiResourceSnapshot,
|
|
19772
|
-
PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION2 as PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION,
|
|
19773
|
-
createPiResourceBundleCache,
|
|
19774
|
-
createPiResourceBundlePinReconciler,
|
|
19775
|
-
buildParkProcessWrites,
|
|
19776
|
-
buildRetryWrites,
|
|
19777
|
-
buildTurnFailedWrites,
|
|
19778
|
-
buildTurnOutcomeWrites,
|
|
19779
|
-
createProcessEngine,
|
|
19780
|
-
shouldResumeProcessOnStartup,
|
|
19781
|
-
reconcileProcessesOnStartup,
|
|
19782
|
-
selectWorkerRuntimeProfile,
|
|
19783
|
-
buildRuntimeProfileSelectionInput,
|
|
19784
|
-
normalizeProcessTitle,
|
|
19785
|
-
buildProcessTitleSourceFields,
|
|
19786
|
-
buildProcessTitlePrompt,
|
|
19787
|
-
createProcessTitleGenerator,
|
|
19788
|
-
buildProcessWatcherRegistry,
|
|
19789
|
-
ResultImageStore,
|
|
19790
|
-
registerUiRendererRoutes,
|
|
19791
|
-
registerWatcherRoutes,
|
|
19792
|
-
resolveServerTlsOptions,
|
|
19793
|
-
createIpcHandler,
|
|
19794
|
-
createWorkerSupervisor,
|
|
19795
|
-
createApp,
|
|
19796
19228
|
createAppContext
|
|
19797
19229
|
};
|
|
19798
|
-
//# sourceMappingURL=chunk-
|
|
19230
|
+
//# sourceMappingURL=chunk-LK3RO6C7.js.map
|