@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
|
@@ -486,6 +486,7 @@ var configSchema = v.looseObject({
|
|
|
486
486
|
v.strictObject({
|
|
487
487
|
runtime_class_name: v.optional(v.string()),
|
|
488
488
|
host_users: v.optional(v.boolean()),
|
|
489
|
+
gvisor: v.optional(v.boolean()),
|
|
489
490
|
process_storage_class_name: v.optional(v.string()),
|
|
490
491
|
network: v.optional(dockerNetworkSchema)
|
|
491
492
|
})
|
|
@@ -561,11 +562,11 @@ function formatValibotPath(issue2) {
|
|
|
561
562
|
return formatted;
|
|
562
563
|
}
|
|
563
564
|
function formatConfigSchemaIssue(issue2) {
|
|
564
|
-
const
|
|
565
|
+
const path6 = formatValibotPath(issue2);
|
|
565
566
|
if (issue2.type === "non_empty") {
|
|
566
|
-
return { path:
|
|
567
|
+
return { path: path6, message: `${path6} must not be empty when specified` };
|
|
567
568
|
}
|
|
568
|
-
return { path:
|
|
569
|
+
return { path: path6, message: `${path6}: ${issue2.message}` };
|
|
569
570
|
}
|
|
570
571
|
function collectConfigSchemaErrors(config) {
|
|
571
572
|
const parsed = v.safeParse(configSchema, config, { abortEarly: false });
|
|
@@ -616,12 +617,12 @@ function collectServerBaseUrlErrors(config) {
|
|
|
616
617
|
function collectWorkerRuntimeProfileErrors(config) {
|
|
617
618
|
const errors = [];
|
|
618
619
|
const profileIds = new Set(Object.keys(config.worker_runtime_profiles ?? {}));
|
|
619
|
-
const checkReference = (value,
|
|
620
|
+
const checkReference = (value, path6) => {
|
|
620
621
|
if (typeof value !== "string" || value.trim() === "") {
|
|
621
622
|
return;
|
|
622
623
|
}
|
|
623
624
|
if (!profileIds.has(value)) {
|
|
624
|
-
errors.push(`Unknown worker runtime profile '${value}' at ${
|
|
625
|
+
errors.push(`Unknown worker runtime profile '${value}' at ${path6}`);
|
|
625
626
|
}
|
|
626
627
|
};
|
|
627
628
|
for (const [id, profile] of Object.entries(config.worker_runtime_profiles ?? {})) {
|
|
@@ -969,12 +970,12 @@ function validateConfig(raw) {
|
|
|
969
970
|
const config = applyConfigDefaults(raw);
|
|
970
971
|
return validateResolvedConfig(config);
|
|
971
972
|
}
|
|
972
|
-
function shouldRedactForLogging(
|
|
973
|
-
return SENSITIVE_CONFIG_KEY_PATTERN.test(key) || key === "url" && (
|
|
973
|
+
function shouldRedactForLogging(path6, key) {
|
|
974
|
+
return SENSITIVE_CONFIG_KEY_PATTERN.test(key) || key === "url" && (path6[0] === "notifications" || path6.some((segment) => /webhook/i.test(segment)));
|
|
974
975
|
}
|
|
975
|
-
function sanitizeConfigForLogging(value,
|
|
976
|
+
function sanitizeConfigForLogging(value, path6 = []) {
|
|
976
977
|
if (Array.isArray(value)) {
|
|
977
|
-
return value.map((entry, index2) => sanitizeConfigForLogging(entry, [...
|
|
978
|
+
return value.map((entry, index2) => sanitizeConfigForLogging(entry, [...path6, String(index2)]));
|
|
978
979
|
}
|
|
979
980
|
const parsedRecord = v.safeParse(unknownRecordSchema, value);
|
|
980
981
|
if (!parsedRecord.success) {
|
|
@@ -982,11 +983,11 @@ function sanitizeConfigForLogging(value, path5 = []) {
|
|
|
982
983
|
}
|
|
983
984
|
const sanitized = {};
|
|
984
985
|
for (const [key, entry] of Object.entries(parsedRecord.output)) {
|
|
985
|
-
if (shouldRedactForLogging(
|
|
986
|
+
if (shouldRedactForLogging(path6, key)) {
|
|
986
987
|
sanitized[key] = entry === "" ? "" : REDACTED_LOG_VALUE;
|
|
987
988
|
continue;
|
|
988
989
|
}
|
|
989
|
-
sanitized[key] = sanitizeConfigForLogging(entry, [...
|
|
990
|
+
sanitized[key] = sanitizeConfigForLogging(entry, [...path6, key]);
|
|
990
991
|
}
|
|
991
992
|
return sanitized;
|
|
992
993
|
}
|
|
@@ -1965,6 +1966,7 @@ function generateCreateIndexDDL(table) {
|
|
|
1965
1966
|
|
|
1966
1967
|
// src/db/database.ts
|
|
1967
1968
|
var DatabaseSchemaMismatchError = class extends Error {
|
|
1969
|
+
/** @internal */
|
|
1968
1970
|
constructor(sqlitePath, tableName) {
|
|
1969
1971
|
super(
|
|
1970
1972
|
`SQLite schema mismatch for table "${tableName}" at ${sqlitePath}. Known migrations were applied automatically when possible. Stop the server, back up the configured SQLite database, add or apply the required explicit migration for this unknown drift, and restart. Leitwerk never resets configured storage automatically.`
|
|
@@ -2729,6 +2731,53 @@ function closeDatabase(db) {
|
|
|
2729
2731
|
sqlite?.close();
|
|
2730
2732
|
}
|
|
2731
2733
|
|
|
2734
|
+
// src/db/credential-cipher.ts
|
|
2735
|
+
import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
|
|
2736
|
+
var PROVIDER_CREDENTIAL_KEY_ENV = "LEITWERK_CREDENTIAL_ENCRYPTION_KEY";
|
|
2737
|
+
function createUnavailableCredentialCipher() {
|
|
2738
|
+
const unavailable = () => {
|
|
2739
|
+
throw new Error(
|
|
2740
|
+
`Provider credential encryption key is unavailable; set ${PROVIDER_CREDENTIAL_KEY_ENV}`
|
|
2741
|
+
);
|
|
2742
|
+
};
|
|
2743
|
+
return { encrypt: unavailable, decrypt: unavailable };
|
|
2744
|
+
}
|
|
2745
|
+
function createCredentialCipherFromBase64(value) {
|
|
2746
|
+
const normalized = value.trim();
|
|
2747
|
+
if (normalized === "") {
|
|
2748
|
+
throw new Error(`${PROVIDER_CREDENTIAL_KEY_ENV} must not be empty`);
|
|
2749
|
+
}
|
|
2750
|
+
const key = Buffer.from(normalized, "base64");
|
|
2751
|
+
if (key.length !== 32 || key.toString("base64").replace(/=+$/, "") !== normalized.replace(/=+$/, "")) {
|
|
2752
|
+
throw new Error(`${PROVIDER_CREDENTIAL_KEY_ENV} must be Base64 for exactly 32 bytes`);
|
|
2753
|
+
}
|
|
2754
|
+
return createAes256GcmCredentialCipher(key);
|
|
2755
|
+
}
|
|
2756
|
+
function createCredentialCipherFromEnvironment(environment = process.env) {
|
|
2757
|
+
const value = environment[PROVIDER_CREDENTIAL_KEY_ENV];
|
|
2758
|
+
return value === void 0 ? null : createCredentialCipherFromBase64(value);
|
|
2759
|
+
}
|
|
2760
|
+
function createAes256GcmCredentialCipher(key) {
|
|
2761
|
+
if (key.length !== 32) throw new Error("Credential encryption key must be 32 bytes");
|
|
2762
|
+
return {
|
|
2763
|
+
encrypt(plaintext) {
|
|
2764
|
+
const iv = randomBytes(12);
|
|
2765
|
+
const cipher = createCipheriv("aes-256-gcm", key, iv);
|
|
2766
|
+
const body = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
2767
|
+
return Buffer.concat([iv, cipher.getAuthTag(), body]).toString("base64");
|
|
2768
|
+
},
|
|
2769
|
+
decrypt(ciphertext) {
|
|
2770
|
+
const bytes = Buffer.from(ciphertext, "base64");
|
|
2771
|
+
if (bytes.length < 29) throw new Error("Invalid encrypted credential payload");
|
|
2772
|
+
const decipher = createDecipheriv("aes-256-gcm", key, bytes.subarray(0, 12));
|
|
2773
|
+
decipher.setAuthTag(bytes.subarray(12, 28));
|
|
2774
|
+
return Buffer.concat([decipher.update(bytes.subarray(28)), decipher.final()]).toString(
|
|
2775
|
+
"utf8"
|
|
2776
|
+
);
|
|
2777
|
+
}
|
|
2778
|
+
};
|
|
2779
|
+
}
|
|
2780
|
+
|
|
2732
2781
|
// src/db/api-token-repo.ts
|
|
2733
2782
|
import { and, desc, eq, isNull } from "drizzle-orm";
|
|
2734
2783
|
function record2(row) {
|
|
@@ -2748,6 +2797,7 @@ function owned(owner) {
|
|
|
2748
2797
|
}
|
|
2749
2798
|
function createApiTokenRepo(db) {
|
|
2750
2799
|
return {
|
|
2800
|
+
/** @internal */
|
|
2751
2801
|
create({ owner, ...fields }) {
|
|
2752
2802
|
db.insert(apiTokens).values({
|
|
2753
2803
|
...fields,
|
|
@@ -2757,35 +2807,101 @@ function createApiTokenRepo(db) {
|
|
|
2757
2807
|
providerBindingJson: owner.providerBinding ? JSON.stringify(owner.providerBinding) : null
|
|
2758
2808
|
}).run();
|
|
2759
2809
|
},
|
|
2810
|
+
/** @internal */
|
|
2760
2811
|
list(owner) {
|
|
2761
2812
|
return db.select().from(apiTokens).where(owned(owner)).orderBy(desc(apiTokens.createdAt)).all().map(record2);
|
|
2762
2813
|
},
|
|
2814
|
+
/** @internal */
|
|
2763
2815
|
findByHash(hash) {
|
|
2764
2816
|
const row = db.select().from(apiTokens).where(eq(apiTokens.secretHash, hash)).get();
|
|
2765
2817
|
return row ? record2(row) : null;
|
|
2766
2818
|
},
|
|
2819
|
+
/** @internal */
|
|
2767
2820
|
revoke(owner, id, at) {
|
|
2768
2821
|
const filter = and(owned(owner), eq(apiTokens.id, id));
|
|
2769
2822
|
if (!db.select({ id: apiTokens.id }).from(apiTokens).where(filter).get()) return false;
|
|
2770
2823
|
db.update(apiTokens).set({ revokedAt: at }).where(and(filter, isNull(apiTokens.revokedAt))).run();
|
|
2771
2824
|
return true;
|
|
2772
2825
|
},
|
|
2826
|
+
/** @internal */
|
|
2773
2827
|
revokeAll(owner, at) {
|
|
2774
2828
|
const result = db.update(apiTokens).set({ revokedAt: at }).where(and(owned(owner), isNull(apiTokens.revokedAt))).run();
|
|
2775
2829
|
return Number(result.changes);
|
|
2776
2830
|
},
|
|
2831
|
+
/** @internal */
|
|
2777
2832
|
revokeAnonymous(at) {
|
|
2778
2833
|
const result = db.update(apiTokens).set({ revokedAt: at }).where(and(eq(apiTokens.ownerKind, "anonymous"), isNull(apiTokens.revokedAt))).run();
|
|
2779
2834
|
return Number(result.changes);
|
|
2780
2835
|
},
|
|
2836
|
+
/** @internal */
|
|
2781
2837
|
touch(id, at) {
|
|
2782
2838
|
db.update(apiTokens).set({ lastUsedAt: at }).where(eq(apiTokens.id, id)).run();
|
|
2783
2839
|
}
|
|
2784
2840
|
};
|
|
2785
2841
|
}
|
|
2786
2842
|
|
|
2843
|
+
// src/db/startup-observation-repo.ts
|
|
2844
|
+
import { eq as eq2 } from "drizzle-orm";
|
|
2845
|
+
function createStartupObservationRepo(db) {
|
|
2846
|
+
return {
|
|
2847
|
+
/** @internal */
|
|
2848
|
+
record(observation) {
|
|
2849
|
+
if (!Number.isFinite(Date.parse(observation.observedAt)) || observation.sourceAt !== null && !Number.isFinite(Date.parse(observation.sourceAt)))
|
|
2850
|
+
return false;
|
|
2851
|
+
const lease = db.select().from(workerLeases).where(eq2(workerLeases.id, observation.workerLeaseId)).get();
|
|
2852
|
+
if (!lease) return false;
|
|
2853
|
+
return db.insert(startupObservations).values({
|
|
2854
|
+
workerLeaseId: observation.workerLeaseId,
|
|
2855
|
+
milestone: observation.milestone,
|
|
2856
|
+
observationJson: JSON.stringify(observation)
|
|
2857
|
+
}).onConflictDoNothing().run().changes > 0;
|
|
2858
|
+
},
|
|
2859
|
+
/** @internal */
|
|
2860
|
+
listByLease(workerLeaseId) {
|
|
2861
|
+
return db.select().from(startupObservations).where(eq2(startupObservations.workerLeaseId, workerLeaseId)).all().map((row) => JSON.parse(row.observationJson));
|
|
2862
|
+
}
|
|
2863
|
+
};
|
|
2864
|
+
}
|
|
2865
|
+
|
|
2866
|
+
// src/db/turn-summary-repo.ts
|
|
2867
|
+
import { eq as eq3 } from "drizzle-orm";
|
|
2868
|
+
function createTurnSummaryRepo(db) {
|
|
2869
|
+
return {
|
|
2870
|
+
/** @internal */
|
|
2871
|
+
get(turnRecordId) {
|
|
2872
|
+
const row = db.select().from(turnSummaries).where(eq3(turnSummaries.turnRecordId, turnRecordId)).get();
|
|
2873
|
+
return row ? JSON.parse(row.summaryJson) : null;
|
|
2874
|
+
},
|
|
2875
|
+
/** @internal */
|
|
2876
|
+
put(instanceId, turnRecordId, summary) {
|
|
2877
|
+
const summaryJson = JSON.stringify(summary);
|
|
2878
|
+
db.insert(turnSummaries).values({ instanceId, turnRecordId, summaryJson }).onConflictDoUpdate({ target: turnSummaries.turnRecordId, set: { summaryJson } }).run();
|
|
2879
|
+
},
|
|
2880
|
+
/** @internal */
|
|
2881
|
+
listByInstance(instanceId) {
|
|
2882
|
+
return Object.fromEntries(
|
|
2883
|
+
db.select().from(turnSummaries).where(eq3(turnSummaries.instanceId, instanceId)).all().map((row) => [row.turnRecordId, JSON.parse(row.summaryJson)])
|
|
2884
|
+
);
|
|
2885
|
+
},
|
|
2886
|
+
/** @internal */
|
|
2887
|
+
getSession(instanceId) {
|
|
2888
|
+
const row = db.select().from(sessionSummaries).where(eq3(sessionSummaries.instanceId, instanceId)).get();
|
|
2889
|
+
return row ? JSON.parse(row.summaryJson) : null;
|
|
2890
|
+
},
|
|
2891
|
+
/** @internal */
|
|
2892
|
+
putSession(instanceId, summary) {
|
|
2893
|
+
const summaryJson = JSON.stringify(summary);
|
|
2894
|
+
db.insert(sessionSummaries).values({ instanceId, summaryJson }).onConflictDoUpdate({ target: sessionSummaries.instanceId, set: { summaryJson } }).run();
|
|
2895
|
+
},
|
|
2896
|
+
/** @internal */
|
|
2897
|
+
deleteSession(instanceId) {
|
|
2898
|
+
db.delete(sessionSummaries).where(eq3(sessionSummaries.instanceId, instanceId)).run();
|
|
2899
|
+
}
|
|
2900
|
+
};
|
|
2901
|
+
}
|
|
2902
|
+
|
|
2787
2903
|
// src/db/auth-repo.ts
|
|
2788
|
-
import { and as and2, eq as
|
|
2904
|
+
import { and as and2, eq as eq4, gt, lt } from "drizzle-orm";
|
|
2789
2905
|
|
|
2790
2906
|
// src/db/repo-helpers.ts
|
|
2791
2907
|
import { asUnknownRecord } from "@leitwerk-dev/domain";
|
|
@@ -2837,6 +2953,7 @@ function sessionRowToRecord(row) {
|
|
|
2837
2953
|
}
|
|
2838
2954
|
function createAuthSessionRepo(db) {
|
|
2839
2955
|
return {
|
|
2956
|
+
/** @internal */
|
|
2840
2957
|
create(input) {
|
|
2841
2958
|
const ts = now();
|
|
2842
2959
|
const values = {
|
|
@@ -2850,14 +2967,17 @@ function createAuthSessionRepo(db) {
|
|
|
2850
2967
|
db.insert(authSessions).values(values).run();
|
|
2851
2968
|
return sessionRowToRecord(values);
|
|
2852
2969
|
},
|
|
2970
|
+
/** @internal */
|
|
2853
2971
|
getValid(idHash, atIso = now()) {
|
|
2854
|
-
const row = db.select().from(authSessions).where(and2(
|
|
2972
|
+
const row = db.select().from(authSessions).where(and2(eq4(authSessions.idHash, idHash), gt(authSessions.expiresAt, atIso))).get();
|
|
2855
2973
|
return row ? sessionRowToRecord(row) : null;
|
|
2856
2974
|
},
|
|
2975
|
+
/** @internal */
|
|
2857
2976
|
delete(idHash) {
|
|
2858
|
-
const result = db.delete(authSessions).where(
|
|
2977
|
+
const result = db.delete(authSessions).where(eq4(authSessions.idHash, idHash)).run();
|
|
2859
2978
|
return result.changes > 0;
|
|
2860
2979
|
},
|
|
2980
|
+
/** @internal */
|
|
2861
2981
|
deleteExpired(atIso = now()) {
|
|
2862
2982
|
const result = db.delete(authSessions).where(lt(authSessions.expiresAt, atIso)).run();
|
|
2863
2983
|
return Number(result.changes);
|
|
@@ -2866,6 +2986,7 @@ function createAuthSessionRepo(db) {
|
|
|
2866
2986
|
}
|
|
2867
2987
|
function createAuthLoginFlowRepo(db) {
|
|
2868
2988
|
return {
|
|
2989
|
+
/** @internal */
|
|
2869
2990
|
create(input) {
|
|
2870
2991
|
const values = {
|
|
2871
2992
|
idHash: input.idHash,
|
|
@@ -2878,14 +2999,17 @@ function createAuthLoginFlowRepo(db) {
|
|
|
2878
2999
|
db.insert(authLoginFlows).values(values).run();
|
|
2879
3000
|
return values;
|
|
2880
3001
|
},
|
|
3002
|
+
/** @internal */
|
|
2881
3003
|
getValid(idHash, atIso = now()) {
|
|
2882
|
-
const row = db.select().from(authLoginFlows).where(and2(
|
|
3004
|
+
const row = db.select().from(authLoginFlows).where(and2(eq4(authLoginFlows.idHash, idHash), gt(authLoginFlows.expiresAt, atIso))).get();
|
|
2883
3005
|
return row ?? null;
|
|
2884
3006
|
},
|
|
3007
|
+
/** @internal */
|
|
2885
3008
|
delete(idHash) {
|
|
2886
|
-
const result = db.delete(authLoginFlows).where(
|
|
3009
|
+
const result = db.delete(authLoginFlows).where(eq4(authLoginFlows.idHash, idHash)).run();
|
|
2887
3010
|
return result.changes > 0;
|
|
2888
3011
|
},
|
|
3012
|
+
/** @internal */
|
|
2889
3013
|
deleteExpired(atIso = now()) {
|
|
2890
3014
|
const result = db.delete(authLoginFlows).where(lt(authLoginFlows.expiresAt, atIso)).run();
|
|
2891
3015
|
return Number(result.changes);
|
|
@@ -2893,55 +3017,8 @@ function createAuthLoginFlowRepo(db) {
|
|
|
2893
3017
|
};
|
|
2894
3018
|
}
|
|
2895
3019
|
|
|
2896
|
-
// src/db/credential-cipher.ts
|
|
2897
|
-
import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
|
|
2898
|
-
var PROVIDER_CREDENTIAL_KEY_ENV = "LEITWERK_CREDENTIAL_ENCRYPTION_KEY";
|
|
2899
|
-
function createUnavailableCredentialCipher() {
|
|
2900
|
-
const unavailable = () => {
|
|
2901
|
-
throw new Error(
|
|
2902
|
-
`Provider credential encryption key is unavailable; set ${PROVIDER_CREDENTIAL_KEY_ENV}`
|
|
2903
|
-
);
|
|
2904
|
-
};
|
|
2905
|
-
return { encrypt: unavailable, decrypt: unavailable };
|
|
2906
|
-
}
|
|
2907
|
-
function createCredentialCipherFromBase64(value) {
|
|
2908
|
-
const normalized = value.trim();
|
|
2909
|
-
if (normalized === "") {
|
|
2910
|
-
throw new Error(`${PROVIDER_CREDENTIAL_KEY_ENV} must not be empty`);
|
|
2911
|
-
}
|
|
2912
|
-
const key = Buffer.from(normalized, "base64");
|
|
2913
|
-
if (key.length !== 32 || key.toString("base64").replace(/=+$/, "") !== normalized.replace(/=+$/, "")) {
|
|
2914
|
-
throw new Error(`${PROVIDER_CREDENTIAL_KEY_ENV} must be Base64 for exactly 32 bytes`);
|
|
2915
|
-
}
|
|
2916
|
-
return createAes256GcmCredentialCipher(key);
|
|
2917
|
-
}
|
|
2918
|
-
function createCredentialCipherFromEnvironment(environment = process.env) {
|
|
2919
|
-
const value = environment[PROVIDER_CREDENTIAL_KEY_ENV];
|
|
2920
|
-
return value === void 0 ? null : createCredentialCipherFromBase64(value);
|
|
2921
|
-
}
|
|
2922
|
-
function createAes256GcmCredentialCipher(key) {
|
|
2923
|
-
if (key.length !== 32) throw new Error("Credential encryption key must be 32 bytes");
|
|
2924
|
-
return {
|
|
2925
|
-
encrypt(plaintext) {
|
|
2926
|
-
const iv = randomBytes(12);
|
|
2927
|
-
const cipher = createCipheriv("aes-256-gcm", key, iv);
|
|
2928
|
-
const body = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
2929
|
-
return Buffer.concat([iv, cipher.getAuthTag(), body]).toString("base64");
|
|
2930
|
-
},
|
|
2931
|
-
decrypt(ciphertext) {
|
|
2932
|
-
const bytes = Buffer.from(ciphertext, "base64");
|
|
2933
|
-
if (bytes.length < 29) throw new Error("Invalid encrypted credential payload");
|
|
2934
|
-
const decipher = createDecipheriv("aes-256-gcm", key, bytes.subarray(0, 12));
|
|
2935
|
-
decipher.setAuthTag(bytes.subarray(12, 28));
|
|
2936
|
-
return Buffer.concat([decipher.update(bytes.subarray(28)), decipher.final()]).toString(
|
|
2937
|
-
"utf8"
|
|
2938
|
-
);
|
|
2939
|
-
}
|
|
2940
|
-
};
|
|
2941
|
-
}
|
|
2942
|
-
|
|
2943
3020
|
// src/db/external-write-log-repo.ts
|
|
2944
|
-
import { desc as desc2, eq as
|
|
3021
|
+
import { desc as desc2, eq as eq5 } from "drizzle-orm";
|
|
2945
3022
|
function rowToExternalWriteLog(row) {
|
|
2946
3023
|
return {
|
|
2947
3024
|
id: row.id,
|
|
@@ -2954,6 +3031,7 @@ function rowToExternalWriteLog(row) {
|
|
|
2954
3031
|
}
|
|
2955
3032
|
function createExternalWriteLogRepo(db) {
|
|
2956
3033
|
return {
|
|
3034
|
+
/** @internal */
|
|
2957
3035
|
record(input) {
|
|
2958
3036
|
const id = generateId("ewl");
|
|
2959
3037
|
const ts = now();
|
|
@@ -2968,20 +3046,22 @@ function createExternalWriteLogRepo(db) {
|
|
|
2968
3046
|
db.insert(externalWriteLog).values(values).run();
|
|
2969
3047
|
return rowToExternalWriteLog(values);
|
|
2970
3048
|
},
|
|
3049
|
+
/** @internal */
|
|
2971
3050
|
hasDedupKey(dedupKey) {
|
|
2972
|
-
const row = db.select().from(externalWriteLog).where(
|
|
3051
|
+
const row = db.select().from(externalWriteLog).where(eq5(externalWriteLog.dedupKey, dedupKey)).get();
|
|
2973
3052
|
return row !== void 0;
|
|
2974
3053
|
},
|
|
3054
|
+
/** @public */
|
|
2975
3055
|
listByInstance(instanceId) {
|
|
2976
|
-
return db.select().from(externalWriteLog).where(
|
|
3056
|
+
return db.select().from(externalWriteLog).where(eq5(externalWriteLog.instanceId, instanceId)).orderBy(desc2(externalWriteLog.completedAt)).all().map(rowToExternalWriteLog);
|
|
2977
3057
|
}
|
|
2978
3058
|
};
|
|
2979
3059
|
}
|
|
2980
3060
|
|
|
2981
3061
|
// src/db/future-execution-repo.ts
|
|
2982
|
-
import { and as and3, asc, count, desc as desc3, eq as
|
|
3062
|
+
import { and as and3, asc, count, desc as desc3, eq as eq6, inArray, lte, or, sql as sql2 } from "drizzle-orm";
|
|
2983
3063
|
function overviewPredicates(input) {
|
|
2984
|
-
const predicates = [
|
|
3064
|
+
const predicates = [eq6(futureExecutions.kind, "launch")];
|
|
2985
3065
|
if (input.status === "needs_attention") {
|
|
2986
3066
|
predicates.push(sql2`${futureExecutions.blockedReasonJson} is not null`);
|
|
2987
3067
|
} else if (input.status === "scheduled") {
|
|
@@ -2991,7 +3071,7 @@ function overviewPredicates(input) {
|
|
|
2991
3071
|
}
|
|
2992
3072
|
const processType = input.processType?.trim();
|
|
2993
3073
|
if (processType) {
|
|
2994
|
-
predicates.push(
|
|
3074
|
+
predicates.push(eq6(futureExecutions.processId, processType));
|
|
2995
3075
|
}
|
|
2996
3076
|
for (const [index2, pattern] of sqliteLikePatterns(input.query).entries()) {
|
|
2997
3077
|
const matchingLauncherIds = input.matchingLauncherIdsByTerm?.[index2] ?? [];
|
|
@@ -3060,6 +3140,7 @@ function rowToFutureExecution(row) {
|
|
|
3060
3140
|
}
|
|
3061
3141
|
function createFutureExecutionRepo(db) {
|
|
3062
3142
|
return {
|
|
3143
|
+
/** @internal */
|
|
3063
3144
|
create(input) {
|
|
3064
3145
|
const id = input.id ?? generateId("fut");
|
|
3065
3146
|
const ts = now();
|
|
@@ -3082,19 +3163,29 @@ function createFutureExecutionRepo(db) {
|
|
|
3082
3163
|
db.insert(futureExecutions).values(values).run();
|
|
3083
3164
|
return rowToFutureExecution(values);
|
|
3084
3165
|
},
|
|
3166
|
+
/** @internal */
|
|
3085
3167
|
getById(id) {
|
|
3086
|
-
const row = db.select().from(futureExecutions).where(
|
|
3168
|
+
const row = db.select().from(futureExecutions).where(eq6(futureExecutions.id, id)).get();
|
|
3087
3169
|
return row ? rowToFutureExecution(row) : null;
|
|
3088
3170
|
},
|
|
3171
|
+
/** @internal */
|
|
3089
3172
|
listAll() {
|
|
3090
3173
|
return db.select().from(futureExecutions).orderBy(asc(futureExecutions.nextRunAt), asc(futureExecutions.createdAt)).all().map(rowToFutureExecution);
|
|
3091
3174
|
},
|
|
3175
|
+
/** @internal */
|
|
3092
3176
|
countOverview(input) {
|
|
3093
3177
|
return db.select({ value: count() }).from(futureExecutions).where(overviewWhere(input)).get()?.value ?? 0;
|
|
3094
3178
|
},
|
|
3179
|
+
/** @internal */
|
|
3095
3180
|
listOverviewProcessTypes(input) {
|
|
3096
|
-
return db.select({
|
|
3181
|
+
return db.select({
|
|
3182
|
+
/** @internal */
|
|
3183
|
+
processId: futureExecutions.processId,
|
|
3184
|
+
/** @internal */
|
|
3185
|
+
value: count()
|
|
3186
|
+
}).from(futureExecutions).where(overviewWhere(input)).groupBy(futureExecutions.processId).orderBy(asc(futureExecutions.processId)).all();
|
|
3097
3187
|
},
|
|
3188
|
+
/** @internal */
|
|
3098
3189
|
listOverviewWindow(input) {
|
|
3099
3190
|
const fallbackCases = Object.entries(input.launcherFallbackTitles).map(
|
|
3100
3191
|
([launcherId, title2]) => sql2`when ${launcherId} then ${title2}`
|
|
@@ -3117,14 +3208,17 @@ function createFutureExecutionRepo(db) {
|
|
|
3117
3208
|
asc(futureExecutions.id)
|
|
3118
3209
|
).limit(input.limit).all().map(rowToFutureExecution);
|
|
3119
3210
|
},
|
|
3211
|
+
/** @internal */
|
|
3120
3212
|
listOverviewPage(input) {
|
|
3121
3213
|
const items = db.select().from(futureExecutions).where(overviewWhere(input)).orderBy(asc(futureExecutions.nextRunAt), asc(futureExecutions.createdAt)).limit(input.limit).offset(input.offset).all().map(rowToFutureExecution);
|
|
3122
3214
|
const total = this.countOverview(input);
|
|
3123
3215
|
return { items, total };
|
|
3124
3216
|
},
|
|
3217
|
+
/** @internal */
|
|
3125
3218
|
listByInstance(instanceId) {
|
|
3126
|
-
return db.select().from(futureExecutions).where(
|
|
3219
|
+
return db.select().from(futureExecutions).where(eq6(futureExecutions.instanceId, instanceId)).orderBy(asc(futureExecutions.nextRunAt), asc(futureExecutions.createdAt)).all().map(rowToFutureExecution);
|
|
3127
3220
|
},
|
|
3221
|
+
/** @internal */
|
|
3128
3222
|
listRunnableDue(asOf) {
|
|
3129
3223
|
return db.select().from(futureExecutions).where(
|
|
3130
3224
|
and3(
|
|
@@ -3133,30 +3227,34 @@ function createFutureExecutionRepo(db) {
|
|
|
3133
3227
|
)
|
|
3134
3228
|
).orderBy(asc(futureExecutions.nextRunAt), asc(futureExecutions.createdAt)).all().map(rowToFutureExecution);
|
|
3135
3229
|
},
|
|
3230
|
+
/** @internal */
|
|
3136
3231
|
listBlockedCronDue(asOf) {
|
|
3137
3232
|
return db.select().from(futureExecutions).where(
|
|
3138
3233
|
and3(
|
|
3139
3234
|
lte(futureExecutions.nextRunAt, asOf),
|
|
3140
|
-
|
|
3235
|
+
eq6(futureExecutions.scheduleKind, "cron"),
|
|
3141
3236
|
sql2`${futureExecutions.blockedReasonJson} is not null`
|
|
3142
3237
|
)
|
|
3143
3238
|
).orderBy(asc(futureExecutions.nextRunAt), asc(futureExecutions.createdAt)).all().map(rowToFutureExecution);
|
|
3144
3239
|
},
|
|
3240
|
+
/** @internal */
|
|
3145
3241
|
getScheduledActionByInstance(instanceId) {
|
|
3146
3242
|
const row = db.select().from(futureExecutions).where(
|
|
3147
|
-
and3(
|
|
3243
|
+
and3(eq6(futureExecutions.instanceId, instanceId), eq6(futureExecutions.kind, "action"))
|
|
3148
3244
|
).orderBy(asc(futureExecutions.nextRunAt), asc(futureExecutions.createdAt)).get();
|
|
3149
3245
|
return row ? rowToFutureExecution(row) : null;
|
|
3150
3246
|
},
|
|
3247
|
+
/** @internal */
|
|
3151
3248
|
updatePayloadJsonIfUnchanged(id, expectedPayloadJson, payloadJson) {
|
|
3152
3249
|
const result = db.update(futureExecutions).set({ payloadJson, updatedAt: now() }).where(
|
|
3153
3250
|
and3(
|
|
3154
|
-
|
|
3155
|
-
|
|
3251
|
+
eq6(futureExecutions.id, id),
|
|
3252
|
+
eq6(futureExecutions.payloadJson, expectedPayloadJson)
|
|
3156
3253
|
)
|
|
3157
3254
|
).run();
|
|
3158
3255
|
return result.changes > 0 ? this.getById(id) : null;
|
|
3159
3256
|
},
|
|
3257
|
+
/** @internal */
|
|
3160
3258
|
update(id, input) {
|
|
3161
3259
|
const setValues = {
|
|
3162
3260
|
updatedAt: now(),
|
|
@@ -3173,18 +3271,19 @@ function createFutureExecutionRepo(db) {
|
|
|
3173
3271
|
Object.assign(setValues, modelSelectionColumns(input.modelSelection));
|
|
3174
3272
|
if (input.blockedReason !== void 0)
|
|
3175
3273
|
setValues.blockedReasonJson = input.blockedReason ? JSON.stringify(input.blockedReason) : null;
|
|
3176
|
-
db.update(futureExecutions).set(setValues).where(
|
|
3274
|
+
db.update(futureExecutions).set(setValues).where(eq6(futureExecutions.id, id)).run();
|
|
3177
3275
|
return this.getById(id);
|
|
3178
3276
|
},
|
|
3277
|
+
/** @internal */
|
|
3179
3278
|
delete(id) {
|
|
3180
|
-
const result = db.delete(futureExecutions).where(
|
|
3279
|
+
const result = db.delete(futureExecutions).where(eq6(futureExecutions.id, id)).run();
|
|
3181
3280
|
return result.changes > 0;
|
|
3182
3281
|
}
|
|
3183
3282
|
};
|
|
3184
3283
|
}
|
|
3185
3284
|
|
|
3186
3285
|
// src/db/launch-run-repo.ts
|
|
3187
|
-
import { and as and4, asc as asc2, eq as
|
|
3286
|
+
import { and as and4, asc as asc2, eq as eq7, inArray as inArray2 } from "drizzle-orm";
|
|
3188
3287
|
var ACTIVE_STATUSES = ["preparing", "process_created", "starting"];
|
|
3189
3288
|
function parseSteps(value) {
|
|
3190
3289
|
const parsed = JSON.parse(value);
|
|
@@ -3208,6 +3307,7 @@ function toLaunchRun(row) {
|
|
|
3208
3307
|
function createLaunchRunRepo(db) {
|
|
3209
3308
|
const list = (where) => db.select().from(launchRuns).where(where).orderBy(asc2(launchRuns.createdAt), asc2(launchRuns.id)).all().map(toLaunchRun);
|
|
3210
3309
|
return {
|
|
3310
|
+
/** @internal */
|
|
3211
3311
|
create(input) {
|
|
3212
3312
|
const ts = now();
|
|
3213
3313
|
const row = {
|
|
@@ -3226,32 +3326,41 @@ function createLaunchRunRepo(db) {
|
|
|
3226
3326
|
db.insert(launchRuns).values(row).run();
|
|
3227
3327
|
return toLaunchRun(row);
|
|
3228
3328
|
},
|
|
3329
|
+
/** @internal */
|
|
3229
3330
|
getById(id) {
|
|
3230
|
-
const row = db.select().from(launchRuns).where(
|
|
3331
|
+
const row = db.select().from(launchRuns).where(eq7(launchRuns.id, id)).get();
|
|
3231
3332
|
return row ? toLaunchRun(row) : null;
|
|
3232
3333
|
},
|
|
3334
|
+
/** @internal */
|
|
3233
3335
|
saveReplay(runId, payload) {
|
|
3234
3336
|
db.insert(launchRunReplays).values({ launchRunId: runId, payloadJson: JSON.stringify(payload) }).onConflictDoUpdate({
|
|
3235
3337
|
target: launchRunReplays.launchRunId,
|
|
3236
3338
|
set: { payloadJson: JSON.stringify(payload) }
|
|
3237
3339
|
}).run();
|
|
3238
3340
|
},
|
|
3341
|
+
/** @internal */
|
|
3239
3342
|
getReplay(runId) {
|
|
3240
|
-
const row = db.select({ payloadJson: launchRunReplays.payloadJson }).from(launchRunReplays).where(
|
|
3343
|
+
const row = db.select({ payloadJson: launchRunReplays.payloadJson }).from(launchRunReplays).where(eq7(launchRunReplays.launchRunId, runId)).get();
|
|
3241
3344
|
return row ? JSON.parse(row.payloadJson) : null;
|
|
3242
3345
|
},
|
|
3346
|
+
/** @internal */
|
|
3243
3347
|
deleteReplay(runId) {
|
|
3244
|
-
db.delete(launchRunReplays).where(
|
|
3348
|
+
db.delete(launchRunReplays).where(eq7(launchRunReplays.launchRunId, runId)).run();
|
|
3245
3349
|
},
|
|
3350
|
+
/** @internal */
|
|
3246
3351
|
getByIdempotencyKey(key) {
|
|
3247
|
-
const row = db.select().from(launchRuns).where(
|
|
3352
|
+
const row = db.select().from(launchRuns).where(eq7(launchRuns.idempotencyKey, key)).get();
|
|
3248
3353
|
return row ? toLaunchRun(row) : null;
|
|
3249
3354
|
},
|
|
3355
|
+
/** @internal */
|
|
3250
3356
|
archiveIdempotencyKey(id, key) {
|
|
3251
|
-
db.update(launchRuns).set({ idempotencyKey: `${key}:attempt:${id}` }).where(and4(
|
|
3357
|
+
db.update(launchRuns).set({ idempotencyKey: `${key}:attempt:${id}` }).where(and4(eq7(launchRuns.id, id), eq7(launchRuns.idempotencyKey, key))).run();
|
|
3252
3358
|
},
|
|
3253
|
-
|
|
3359
|
+
/** @internal */
|
|
3360
|
+
listByInstance: (instanceId) => list(eq7(launchRuns.instanceId, instanceId)),
|
|
3361
|
+
/** @internal */
|
|
3254
3362
|
listIncomplete: () => list(inArray2(launchRuns.status, [...ACTIVE_STATUSES])),
|
|
3363
|
+
/** @internal */
|
|
3255
3364
|
compareAndSet(next, expectedRevision) {
|
|
3256
3365
|
const updatedAt = now();
|
|
3257
3366
|
const result = db.update(launchRuns).set({
|
|
@@ -3263,9 +3372,10 @@ function createLaunchRunRepo(db) {
|
|
|
3263
3372
|
updatedAt,
|
|
3264
3373
|
completedAt: next.completedAt,
|
|
3265
3374
|
revision: expectedRevision + 1
|
|
3266
|
-
}).where(and4(
|
|
3375
|
+
}).where(and4(eq7(launchRuns.id, next.id), eq7(launchRuns.revision, expectedRevision))).run();
|
|
3267
3376
|
return result.changes > 0 ? this.getById(next.id) : null;
|
|
3268
3377
|
},
|
|
3378
|
+
/** @internal */
|
|
3269
3379
|
update(id, mutate) {
|
|
3270
3380
|
for (let attempt = 0; attempt < 8; attempt += 1) {
|
|
3271
3381
|
const current = this.getById(id);
|
|
@@ -3279,12 +3389,14 @@ function createLaunchRunRepo(db) {
|
|
|
3279
3389
|
}
|
|
3280
3390
|
|
|
3281
3391
|
// src/db/launcher-recent-value-repo.ts
|
|
3282
|
-
import { and as and5, desc as desc4, eq as
|
|
3392
|
+
import { and as and5, desc as desc4, eq as eq8 } from "drizzle-orm";
|
|
3283
3393
|
function createLauncherRecentValueRepo(db) {
|
|
3284
3394
|
return {
|
|
3395
|
+
/** @internal */
|
|
3285
3396
|
listByLauncher(launcherId) {
|
|
3286
|
-
return db.select().from(launcherRecentValues).where(
|
|
3397
|
+
return db.select().from(launcherRecentValues).where(eq8(launcherRecentValues.launcherId, launcherId)).orderBy(desc4(launcherRecentValues.updatedAt), desc4(launcherRecentValues.createdAt)).all();
|
|
3287
3398
|
},
|
|
3399
|
+
/** @internal */
|
|
3288
3400
|
recordValue(input) {
|
|
3289
3401
|
const ts = now();
|
|
3290
3402
|
const row = db.insert(launcherRecentValues).values({
|
|
@@ -3305,22 +3417,23 @@ function createLauncherRecentValueRepo(db) {
|
|
|
3305
3417
|
this.pruneField(input.launcherId, input.fieldId, input.limit ?? 5);
|
|
3306
3418
|
return row;
|
|
3307
3419
|
},
|
|
3420
|
+
/** @internal */
|
|
3308
3421
|
pruneField(launcherId, fieldId, limit = 5) {
|
|
3309
3422
|
const stale = db.select({ id: launcherRecentValues.id }).from(launcherRecentValues).where(
|
|
3310
3423
|
and5(
|
|
3311
|
-
|
|
3312
|
-
|
|
3424
|
+
eq8(launcherRecentValues.launcherId, launcherId),
|
|
3425
|
+
eq8(launcherRecentValues.fieldId, fieldId)
|
|
3313
3426
|
)
|
|
3314
3427
|
).orderBy(desc4(launcherRecentValues.updatedAt), desc4(launcherRecentValues.createdAt)).all().slice(limit);
|
|
3315
3428
|
for (const entry of stale) {
|
|
3316
|
-
db.delete(launcherRecentValues).where(
|
|
3429
|
+
db.delete(launcherRecentValues).where(eq8(launcherRecentValues.id, entry.id)).run();
|
|
3317
3430
|
}
|
|
3318
3431
|
}
|
|
3319
3432
|
};
|
|
3320
3433
|
}
|
|
3321
3434
|
|
|
3322
3435
|
// src/db/pending-external-source-fire-repo.ts
|
|
3323
|
-
import { and as and6, asc as asc3, eq as
|
|
3436
|
+
import { and as and6, asc as asc3, eq as eq9 } from "drizzle-orm";
|
|
3324
3437
|
function parseRecord(json) {
|
|
3325
3438
|
const value = JSON.parse(json);
|
|
3326
3439
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
@@ -3343,6 +3456,7 @@ function rowToPendingExternalSourceFire(row) {
|
|
|
3343
3456
|
}
|
|
3344
3457
|
function createPendingExternalSourceFireRepo(db) {
|
|
3345
3458
|
return {
|
|
3459
|
+
/** @internal */
|
|
3346
3460
|
create(input) {
|
|
3347
3461
|
const ts = now();
|
|
3348
3462
|
const values = {
|
|
@@ -3362,19 +3476,22 @@ function createPendingExternalSourceFireRepo(db) {
|
|
|
3362
3476
|
db.insert(pendingExternalSourceFires).values(values).run();
|
|
3363
3477
|
return rowToPendingExternalSourceFire(values);
|
|
3364
3478
|
},
|
|
3479
|
+
/** @internal */
|
|
3365
3480
|
listByInstance(instanceId) {
|
|
3366
|
-
return db.select().from(pendingExternalSourceFires).where(
|
|
3481
|
+
return db.select().from(pendingExternalSourceFires).where(eq9(pendingExternalSourceFires.instanceId, instanceId)).orderBy(asc3(pendingExternalSourceFires.createdAt)).all().map(rowToPendingExternalSourceFire);
|
|
3367
3482
|
},
|
|
3483
|
+
/** @internal */
|
|
3368
3484
|
getByMergeKey(instanceId, armingId, mergeKey) {
|
|
3369
3485
|
const row = db.select().from(pendingExternalSourceFires).where(
|
|
3370
3486
|
and6(
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3487
|
+
eq9(pendingExternalSourceFires.instanceId, instanceId),
|
|
3488
|
+
eq9(pendingExternalSourceFires.armingId, armingId),
|
|
3489
|
+
eq9(pendingExternalSourceFires.mergeKey, mergeKey)
|
|
3374
3490
|
)
|
|
3375
3491
|
).get();
|
|
3376
3492
|
return row ? rowToPendingExternalSourceFire(row) : null;
|
|
3377
3493
|
},
|
|
3494
|
+
/** @internal */
|
|
3378
3495
|
update(id, input) {
|
|
3379
3496
|
const setValues = {
|
|
3380
3497
|
updatedAt: now(),
|
|
@@ -3382,12 +3499,13 @@ function createPendingExternalSourceFireRepo(db) {
|
|
|
3382
3499
|
};
|
|
3383
3500
|
if (input.input !== void 0) setValues.inputJson = JSON.stringify(input.input);
|
|
3384
3501
|
if (input.event !== void 0) setValues.eventJson = JSON.stringify(input.event);
|
|
3385
|
-
db.update(pendingExternalSourceFires).set(setValues).where(
|
|
3386
|
-
const row = db.select().from(pendingExternalSourceFires).where(
|
|
3502
|
+
db.update(pendingExternalSourceFires).set(setValues).where(eq9(pendingExternalSourceFires.id, id)).run();
|
|
3503
|
+
const row = db.select().from(pendingExternalSourceFires).where(eq9(pendingExternalSourceFires.id, id)).get();
|
|
3387
3504
|
return row ? rowToPendingExternalSourceFire(row) : null;
|
|
3388
3505
|
},
|
|
3506
|
+
/** @internal */
|
|
3389
3507
|
delete(id) {
|
|
3390
|
-
const result = db.delete(pendingExternalSourceFires).where(
|
|
3508
|
+
const result = db.delete(pendingExternalSourceFires).where(eq9(pendingExternalSourceFires.id, id)).run();
|
|
3391
3509
|
return result.changes > 0;
|
|
3392
3510
|
}
|
|
3393
3511
|
};
|
|
@@ -3395,40 +3513,7 @@ function createPendingExternalSourceFireRepo(db) {
|
|
|
3395
3513
|
|
|
3396
3514
|
// src/db/process-event-repo.ts
|
|
3397
3515
|
import { applyEventToCompactTurnSummary, emptyCompactTurnSummary } from "@leitwerk-dev/protocol";
|
|
3398
|
-
import { and as and7, asc as asc4, desc as desc5, eq as
|
|
3399
|
-
|
|
3400
|
-
// src/db/turn-summary-repo.ts
|
|
3401
|
-
import { eq as eq8 } from "drizzle-orm";
|
|
3402
|
-
function createTurnSummaryRepo(db) {
|
|
3403
|
-
return {
|
|
3404
|
-
get(turnRecordId) {
|
|
3405
|
-
const row = db.select().from(turnSummaries).where(eq8(turnSummaries.turnRecordId, turnRecordId)).get();
|
|
3406
|
-
return row ? JSON.parse(row.summaryJson) : null;
|
|
3407
|
-
},
|
|
3408
|
-
put(instanceId, turnRecordId, summary) {
|
|
3409
|
-
const summaryJson = JSON.stringify(summary);
|
|
3410
|
-
db.insert(turnSummaries).values({ instanceId, turnRecordId, summaryJson }).onConflictDoUpdate({ target: turnSummaries.turnRecordId, set: { summaryJson } }).run();
|
|
3411
|
-
},
|
|
3412
|
-
listByInstance(instanceId) {
|
|
3413
|
-
return Object.fromEntries(
|
|
3414
|
-
db.select().from(turnSummaries).where(eq8(turnSummaries.instanceId, instanceId)).all().map((row) => [row.turnRecordId, JSON.parse(row.summaryJson)])
|
|
3415
|
-
);
|
|
3416
|
-
},
|
|
3417
|
-
getSession(instanceId) {
|
|
3418
|
-
const row = db.select().from(sessionSummaries).where(eq8(sessionSummaries.instanceId, instanceId)).get();
|
|
3419
|
-
return row ? JSON.parse(row.summaryJson) : null;
|
|
3420
|
-
},
|
|
3421
|
-
putSession(instanceId, summary) {
|
|
3422
|
-
const summaryJson = JSON.stringify(summary);
|
|
3423
|
-
db.insert(sessionSummaries).values({ instanceId, summaryJson }).onConflictDoUpdate({ target: sessionSummaries.instanceId, set: { summaryJson } }).run();
|
|
3424
|
-
},
|
|
3425
|
-
deleteSession(instanceId) {
|
|
3426
|
-
db.delete(sessionSummaries).where(eq8(sessionSummaries.instanceId, instanceId)).run();
|
|
3427
|
-
}
|
|
3428
|
-
};
|
|
3429
|
-
}
|
|
3430
|
-
|
|
3431
|
-
// src/db/process-event-repo.ts
|
|
3516
|
+
import { and as and7, asc as asc4, desc as desc5, eq as eq10, gte, inArray as inArray3, like, sql as sql3 } from "drizzle-orm";
|
|
3432
3517
|
function rowToProcessEvent(row) {
|
|
3433
3518
|
return {
|
|
3434
3519
|
id: row.id,
|
|
@@ -3443,6 +3528,7 @@ function createProcessEventRepo(db) {
|
|
|
3443
3528
|
const summaries = createTurnSummaryRepo(db);
|
|
3444
3529
|
const listNewest = (where, limit) => db.select().from(processEvents).where(where).orderBy(desc5(processEvents.eventSequence)).limit(limit).all().map(rowToProcessEvent);
|
|
3445
3530
|
return {
|
|
3531
|
+
/** @internal */
|
|
3446
3532
|
create(input) {
|
|
3447
3533
|
const id = generateId("evt");
|
|
3448
3534
|
const ts = now();
|
|
@@ -3475,33 +3561,39 @@ function createProcessEventRepo(db) {
|
|
|
3475
3561
|
});
|
|
3476
3562
|
return rowToProcessEvent(values);
|
|
3477
3563
|
},
|
|
3564
|
+
/** @internal */
|
|
3478
3565
|
latestSequence(instanceId) {
|
|
3479
|
-
return db.select({ sequence: processEvents.eventSequence }).from(processEvents).where(
|
|
3566
|
+
return db.select({ sequence: processEvents.eventSequence }).from(processEvents).where(eq10(processEvents.instanceId, instanceId)).orderBy(desc5(processEvents.eventSequence)).limit(1).get()?.sequence ?? 0;
|
|
3480
3567
|
},
|
|
3568
|
+
/** @internal */
|
|
3481
3569
|
listByTurnRecord(instanceId, turnRecordId) {
|
|
3482
3570
|
return db.select().from(processEvents).where(
|
|
3483
3571
|
and7(
|
|
3484
|
-
|
|
3485
|
-
|
|
3572
|
+
eq10(processEvents.instanceId, instanceId),
|
|
3573
|
+
eq10(processEvents.turnRecordId, turnRecordId)
|
|
3486
3574
|
)
|
|
3487
3575
|
).orderBy(asc4(processEvents.eventSequence)).all().map(rowToProcessEvent);
|
|
3488
3576
|
},
|
|
3577
|
+
/** @internal */
|
|
3489
3578
|
latestByTurnRecordEventType(instanceId, turnRecordId, eventType) {
|
|
3490
3579
|
const row = db.select().from(processEvents).where(
|
|
3491
3580
|
and7(
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3581
|
+
eq10(processEvents.instanceId, instanceId),
|
|
3582
|
+
eq10(processEvents.turnRecordId, turnRecordId),
|
|
3583
|
+
eq10(processEvents.eventType, eventType)
|
|
3495
3584
|
)
|
|
3496
3585
|
).orderBy(desc5(processEvents.eventSequence)).limit(1).get();
|
|
3497
3586
|
return row ? rowToProcessEvent(row) : null;
|
|
3498
3587
|
},
|
|
3588
|
+
/** @internal */
|
|
3499
3589
|
summary(turnRecordId) {
|
|
3500
3590
|
return summaries.get(turnRecordId);
|
|
3501
3591
|
},
|
|
3592
|
+
/** @internal */
|
|
3502
3593
|
listByInstance(instanceId, limit = 100) {
|
|
3503
|
-
return listNewest(
|
|
3594
|
+
return listNewest(eq10(processEvents.instanceId, instanceId), limit);
|
|
3504
3595
|
},
|
|
3596
|
+
/** @internal */
|
|
3505
3597
|
listByInstanceEventTypes(instanceId, eventTypes, limit = 100) {
|
|
3506
3598
|
const filteredEventTypes = [
|
|
3507
3599
|
...new Set(eventTypes.filter((eventType) => eventType.trim() !== ""))
|
|
@@ -3511,24 +3603,26 @@ function createProcessEventRepo(db) {
|
|
|
3511
3603
|
}
|
|
3512
3604
|
const events = filteredEventTypes.flatMap(
|
|
3513
3605
|
(eventType) => listNewest(
|
|
3514
|
-
and7(
|
|
3606
|
+
and7(eq10(processEvents.instanceId, instanceId), eq10(processEvents.eventType, eventType)),
|
|
3515
3607
|
limit
|
|
3516
3608
|
)
|
|
3517
3609
|
);
|
|
3518
3610
|
events.sort((a, b) => (b.eventSequence ?? 0) - (a.eventSequence ?? 0));
|
|
3519
3611
|
return limit < 0 ? events : events.slice(0, limit);
|
|
3520
3612
|
},
|
|
3613
|
+
/** @internal */
|
|
3521
3614
|
listByInstanceSince(instanceId, sinceCreatedAt, options = {}) {
|
|
3522
3615
|
const prefix = typeof options.eventTypePrefix === "string" ? options.eventTypePrefix.trim() : "";
|
|
3523
3616
|
return listNewest(
|
|
3524
3617
|
and7(
|
|
3525
|
-
|
|
3618
|
+
eq10(processEvents.instanceId, instanceId),
|
|
3526
3619
|
gte(processEvents.createdAt, sinceCreatedAt),
|
|
3527
3620
|
prefix ? like(processEvents.eventType, `${prefix}%`) : void 0
|
|
3528
3621
|
),
|
|
3529
3622
|
options.limit ?? 100
|
|
3530
3623
|
);
|
|
3531
3624
|
},
|
|
3625
|
+
/** @internal */
|
|
3532
3626
|
listByInstanceTurnRecordEventTypes(instanceId, turnRecordId, eventTypes) {
|
|
3533
3627
|
const filteredEventTypes = eventTypes.filter((eventType) => eventType.trim() !== "");
|
|
3534
3628
|
if (filteredEventTypes.length === 0 || turnRecordId.trim() === "") {
|
|
@@ -3536,12 +3630,13 @@ function createProcessEventRepo(db) {
|
|
|
3536
3630
|
}
|
|
3537
3631
|
return db.select().from(processEvents).where(
|
|
3538
3632
|
and7(
|
|
3539
|
-
|
|
3633
|
+
eq10(processEvents.instanceId, instanceId),
|
|
3540
3634
|
inArray3(processEvents.eventType, filteredEventTypes),
|
|
3541
|
-
|
|
3635
|
+
eq10(processEvents.turnRecordId, turnRecordId)
|
|
3542
3636
|
)
|
|
3543
3637
|
).orderBy(asc4(processEvents.eventSequence)).all().map(rowToProcessEvent);
|
|
3544
3638
|
},
|
|
3639
|
+
/** @internal */
|
|
3545
3640
|
listByInstanceSinceEventTypes(instanceId, sinceCreatedAt, eventTypes, limit = 100) {
|
|
3546
3641
|
const filteredEventTypes = eventTypes.filter((eventType) => eventType.trim() !== "");
|
|
3547
3642
|
if (filteredEventTypes.length === 0) {
|
|
@@ -3549,7 +3644,7 @@ function createProcessEventRepo(db) {
|
|
|
3549
3644
|
}
|
|
3550
3645
|
return listNewest(
|
|
3551
3646
|
and7(
|
|
3552
|
-
|
|
3647
|
+
eq10(processEvents.instanceId, instanceId),
|
|
3553
3648
|
gte(processEvents.createdAt, sinceCreatedAt),
|
|
3554
3649
|
inArray3(processEvents.eventType, filteredEventTypes)
|
|
3555
3650
|
),
|
|
@@ -3560,7 +3655,7 @@ function createProcessEventRepo(db) {
|
|
|
3560
3655
|
}
|
|
3561
3656
|
|
|
3562
3657
|
// src/db/process-handoff-dedup-key-repo.ts
|
|
3563
|
-
import { eq as
|
|
3658
|
+
import { eq as eq11 } from "drizzle-orm";
|
|
3564
3659
|
function rowToRecord(row) {
|
|
3565
3660
|
return {
|
|
3566
3661
|
key: row.key,
|
|
@@ -3571,6 +3666,7 @@ function rowToRecord(row) {
|
|
|
3571
3666
|
}
|
|
3572
3667
|
function createProcessHandoffDedupKeyRepo(db) {
|
|
3573
3668
|
return {
|
|
3669
|
+
/** @internal */
|
|
3574
3670
|
create(input) {
|
|
3575
3671
|
const values = {
|
|
3576
3672
|
key: input.key,
|
|
@@ -3581,8 +3677,9 @@ function createProcessHandoffDedupKeyRepo(db) {
|
|
|
3581
3677
|
db.insert(processHandoffDedupKeys).values(values).run();
|
|
3582
3678
|
return rowToRecord(values);
|
|
3583
3679
|
},
|
|
3680
|
+
/** @internal */
|
|
3584
3681
|
getByKey(key) {
|
|
3585
|
-
const row = db.select().from(processHandoffDedupKeys).where(
|
|
3682
|
+
const row = db.select().from(processHandoffDedupKeys).where(eq11(processHandoffDedupKeys.key, key)).get();
|
|
3586
3683
|
return row ? rowToRecord(row) : null;
|
|
3587
3684
|
}
|
|
3588
3685
|
};
|
|
@@ -3590,7 +3687,7 @@ function createProcessHandoffDedupKeyRepo(db) {
|
|
|
3590
3687
|
|
|
3591
3688
|
// src/db/process-input-repo.ts
|
|
3592
3689
|
import { parseActorOrSystem, SYSTEM_ACTOR, serializeActor } from "@leitwerk-dev/domain";
|
|
3593
|
-
import { and as and8, asc as asc5, eq as
|
|
3690
|
+
import { and as and8, asc as asc5, eq as eq12, isNull as isNull2, max } from "drizzle-orm";
|
|
3594
3691
|
function toProcessInputTarget(semanticRef, productName) {
|
|
3595
3692
|
if (productName) {
|
|
3596
3693
|
return { productName };
|
|
@@ -3614,11 +3711,12 @@ function rowToProcessInput(row) {
|
|
|
3614
3711
|
function createProcessInputRepo(db) {
|
|
3615
3712
|
const list = (instanceId, unconsumed = false) => db.select().from(processInputs).where(
|
|
3616
3713
|
and8(
|
|
3617
|
-
|
|
3714
|
+
eq12(processInputs.instanceId, instanceId),
|
|
3618
3715
|
unconsumed ? isNull2(processInputs.consumedAt) : void 0
|
|
3619
3716
|
)
|
|
3620
3717
|
).orderBy(asc5(processInputs.sequence)).all().map(rowToProcessInput);
|
|
3621
3718
|
return {
|
|
3719
|
+
/** @internal */
|
|
3622
3720
|
create(input) {
|
|
3623
3721
|
const id = generateId("inp");
|
|
3624
3722
|
const ts = now();
|
|
@@ -3638,18 +3736,23 @@ function createProcessInputRepo(db) {
|
|
|
3638
3736
|
db.insert(processInputs).values(values).run();
|
|
3639
3737
|
return rowToProcessInput(values);
|
|
3640
3738
|
},
|
|
3739
|
+
/** @internal */
|
|
3641
3740
|
listByInstance: (instanceId) => list(instanceId),
|
|
3741
|
+
/** @internal */
|
|
3642
3742
|
listUnconsumed: (instanceId) => list(instanceId, true),
|
|
3743
|
+
/** @internal */
|
|
3643
3744
|
markConsumed(id) {
|
|
3644
|
-
const result = db.update(processInputs).set({ consumedAt: now() }).where(
|
|
3745
|
+
const result = db.update(processInputs).set({ consumedAt: now() }).where(eq12(processInputs.id, id)).run();
|
|
3645
3746
|
return result.changes > 0;
|
|
3646
3747
|
},
|
|
3748
|
+
/** @internal */
|
|
3647
3749
|
delete(id) {
|
|
3648
|
-
const result = db.delete(processInputs).where(
|
|
3750
|
+
const result = db.delete(processInputs).where(eq12(processInputs.id, id)).run();
|
|
3649
3751
|
return result.changes > 0;
|
|
3650
3752
|
},
|
|
3753
|
+
/** @internal */
|
|
3651
3754
|
getMaxSequence(instanceId) {
|
|
3652
|
-
const row = db.select({ sequence: max(processInputs.sequence) }).from(processInputs).where(
|
|
3755
|
+
const row = db.select({ sequence: max(processInputs.sequence) }).from(processInputs).where(eq12(processInputs.instanceId, instanceId)).get();
|
|
3653
3756
|
return row?.sequence ?? 0;
|
|
3654
3757
|
}
|
|
3655
3758
|
};
|
|
@@ -3659,7 +3762,7 @@ function createProcessInputRepo(db) {
|
|
|
3659
3762
|
import {
|
|
3660
3763
|
isProcessSelectedTurnModelSource
|
|
3661
3764
|
} from "@leitwerk-dev/domain";
|
|
3662
|
-
import { and as and9, asc as asc6, count as count2, desc as desc6, eq as
|
|
3765
|
+
import { and as and9, asc as asc6, count as count2, desc as desc6, eq as eq13, inArray as inArray4, notInArray, or as or2, sql as sql4 } from "drizzle-orm";
|
|
3663
3766
|
|
|
3664
3767
|
// src/launch-title.ts
|
|
3665
3768
|
var MAX_PROCESS_TITLE_LENGTH = 80;
|
|
@@ -3706,7 +3809,7 @@ function overviewPredicates2(input) {
|
|
|
3706
3809
|
const predicates = [];
|
|
3707
3810
|
const processType = input.processType?.trim();
|
|
3708
3811
|
if (processType) {
|
|
3709
|
-
predicates.push(
|
|
3812
|
+
predicates.push(eq13(processInstances.processId, processType));
|
|
3710
3813
|
}
|
|
3711
3814
|
switch (input.status ?? "all") {
|
|
3712
3815
|
case "running":
|
|
@@ -3716,10 +3819,10 @@ function overviewPredicates2(input) {
|
|
|
3716
3819
|
predicates.push(inArray4(processInstances.lifecycleStatus, ["waiting", "error"]));
|
|
3717
3820
|
break;
|
|
3718
3821
|
case "completed":
|
|
3719
|
-
predicates.push(
|
|
3822
|
+
predicates.push(eq13(processInstances.lifecycleStatus, "completed"));
|
|
3720
3823
|
break;
|
|
3721
3824
|
case "aborted":
|
|
3722
|
-
predicates.push(
|
|
3825
|
+
predicates.push(eq13(processInstances.lifecycleStatus, "aborted"));
|
|
3723
3826
|
break;
|
|
3724
3827
|
case "scheduled":
|
|
3725
3828
|
predicates.push(sql4`0 = 1`);
|
|
@@ -3779,10 +3882,12 @@ function rowToProcessInstance(row) {
|
|
|
3779
3882
|
}
|
|
3780
3883
|
function createProcessInstanceRepo(db) {
|
|
3781
3884
|
return {
|
|
3885
|
+
/** @internal */
|
|
3782
3886
|
getLaunchIntent(instanceId) {
|
|
3783
|
-
const row = db.select({ launchIntentJson: processInstances.launchIntentJson }).from(processInstances).where(
|
|
3887
|
+
const row = db.select({ launchIntentJson: processInstances.launchIntentJson }).from(processInstances).where(eq13(processInstances.id, instanceId)).get();
|
|
3784
3888
|
return parseLaunchIntent(row?.launchIntentJson ?? null);
|
|
3785
3889
|
},
|
|
3890
|
+
/** @public */
|
|
3786
3891
|
create(input) {
|
|
3787
3892
|
const id = generateId("agt");
|
|
3788
3893
|
const ts = now();
|
|
@@ -3814,28 +3919,46 @@ function createProcessInstanceRepo(db) {
|
|
|
3814
3919
|
db.insert(processInstances).values(values).run();
|
|
3815
3920
|
return rowToProcessInstance({ ...values, planRevision: 0 });
|
|
3816
3921
|
},
|
|
3922
|
+
/** @public */
|
|
3817
3923
|
getById(id) {
|
|
3818
|
-
const row = db.select().from(processInstances).where(
|
|
3924
|
+
const row = db.select().from(processInstances).where(eq13(processInstances.id, id)).get();
|
|
3819
3925
|
return row ? rowToProcessInstance(row) : null;
|
|
3820
3926
|
},
|
|
3927
|
+
/** @public */
|
|
3821
3928
|
listAll() {
|
|
3822
3929
|
return db.select().from(processInstances).orderBy(desc6(processInstances.updatedAt)).all().map(rowToProcessInstance);
|
|
3823
3930
|
},
|
|
3931
|
+
/** @internal */
|
|
3824
3932
|
listCurrent(limit) {
|
|
3825
3933
|
return db.select().from(processInstances).where(notInArray(processInstances.lifecycleStatus, ["completed", "aborted"])).orderBy(desc6(processInstances.updatedAt), asc6(processInstances.id)).limit(limit).all().map(rowToProcessInstance);
|
|
3826
3934
|
},
|
|
3935
|
+
/** @internal */
|
|
3827
3936
|
countCurrent() {
|
|
3828
3937
|
return db.select({ value: count2() }).from(processInstances).where(notInArray(processInstances.lifecycleStatus, ["completed", "aborted"])).get()?.value ?? 0;
|
|
3829
3938
|
},
|
|
3939
|
+
/** @internal */
|
|
3830
3940
|
countOverview(input) {
|
|
3831
3941
|
return db.select({ value: count2() }).from(processInstances).where(overviewWhere2(input)).get()?.value ?? 0;
|
|
3832
3942
|
},
|
|
3943
|
+
/** @internal */
|
|
3833
3944
|
countOverviewByLifecycle(input) {
|
|
3834
|
-
return db.select({
|
|
3945
|
+
return db.select({
|
|
3946
|
+
/** @internal */
|
|
3947
|
+
lifecycleStatus: processInstances.lifecycleStatus,
|
|
3948
|
+
/** @internal */
|
|
3949
|
+
value: count2()
|
|
3950
|
+
}).from(processInstances).where(overviewWhere2({ ...input, status: "all" })).groupBy(processInstances.lifecycleStatus).all();
|
|
3835
3951
|
},
|
|
3952
|
+
/** @internal */
|
|
3836
3953
|
listOverviewProcessTypes(input) {
|
|
3837
|
-
return db.select({
|
|
3954
|
+
return db.select({
|
|
3955
|
+
/** @internal */
|
|
3956
|
+
processId: processInstances.processId,
|
|
3957
|
+
/** @internal */
|
|
3958
|
+
value: count2()
|
|
3959
|
+
}).from(processInstances).where(overviewWhere2(input)).groupBy(processInstances.processId).orderBy(asc6(processInstances.processId)).all();
|
|
3838
3960
|
},
|
|
3961
|
+
/** @internal */
|
|
3839
3962
|
listOverviewWindow(input) {
|
|
3840
3963
|
const title = sql4`coalesce(${processInstances.title}, ${processInstances.externalId}, ${processInstances.id})`;
|
|
3841
3964
|
const status = sql4`case
|
|
@@ -3854,6 +3977,7 @@ function createProcessInstanceRepo(db) {
|
|
|
3854
3977
|
asc6(processInstances.id)
|
|
3855
3978
|
).limit(input.limit).all().map(rowToProcessInstance);
|
|
3856
3979
|
},
|
|
3980
|
+
/** @internal */
|
|
3857
3981
|
setGeneratedTitleIfBlank(id, title) {
|
|
3858
3982
|
const normalizedTitle = normalizeProcessTitleInput(title);
|
|
3859
3983
|
if (!normalizedTitle) {
|
|
@@ -3861,12 +3985,13 @@ function createProcessInstanceRepo(db) {
|
|
|
3861
3985
|
}
|
|
3862
3986
|
const result = db.update(processInstances).set({ title: normalizedTitle, updatedAt: now() }).where(
|
|
3863
3987
|
and9(
|
|
3864
|
-
|
|
3988
|
+
eq13(processInstances.id, id),
|
|
3865
3989
|
sql4`trim(coalesce(${processInstances.title}, '')) = ''`
|
|
3866
3990
|
)
|
|
3867
3991
|
).run();
|
|
3868
3992
|
return result.changes > 0 ? this.getById(id) : null;
|
|
3869
3993
|
},
|
|
3994
|
+
/** @public */
|
|
3870
3995
|
update(id, input) {
|
|
3871
3996
|
const ts = now();
|
|
3872
3997
|
const setValues = {
|
|
@@ -3894,18 +4019,19 @@ function createProcessInstanceRepo(db) {
|
|
|
3894
4019
|
if (isTerminalLifecycleStatus(input.lifecycleStatus)) {
|
|
3895
4020
|
setValues.closedAt = sql4`coalesce(${processInstances.closedAt}, ${ts})`;
|
|
3896
4021
|
}
|
|
3897
|
-
db.update(processInstances).set(setValues).where(
|
|
4022
|
+
db.update(processInstances).set(setValues).where(eq13(processInstances.id, id)).run();
|
|
3898
4023
|
return this.getById(id);
|
|
3899
4024
|
},
|
|
4025
|
+
/** @internal */
|
|
3900
4026
|
delete(id) {
|
|
3901
|
-
const result = db.delete(processInstances).where(
|
|
4027
|
+
const result = db.delete(processInstances).where(eq13(processInstances.id, id)).run();
|
|
3902
4028
|
return result.changes > 0;
|
|
3903
4029
|
}
|
|
3904
4030
|
};
|
|
3905
4031
|
}
|
|
3906
4032
|
|
|
3907
4033
|
// src/db/process-leaf-outcome-snapshot-repo.ts
|
|
3908
|
-
import { and as and10, asc as asc7, desc as desc7, eq as
|
|
4034
|
+
import { and as and10, asc as asc7, desc as desc7, eq as eq14, sql as sql5 } from "drizzle-orm";
|
|
3909
4035
|
function rowToProcessLeafOutcomeSnapshot(row) {
|
|
3910
4036
|
return {
|
|
3911
4037
|
id: row.id,
|
|
@@ -3925,6 +4051,7 @@ function rowToProcessLeafOutcomeSnapshot(row) {
|
|
|
3925
4051
|
}
|
|
3926
4052
|
function createProcessLeafOutcomeSnapshotRepo(db) {
|
|
3927
4053
|
return {
|
|
4054
|
+
/** @internal */
|
|
3928
4055
|
create(input) {
|
|
3929
4056
|
const values = {
|
|
3930
4057
|
id: input.id ?? generateId("los"),
|
|
@@ -3944,17 +4071,19 @@ function createProcessLeafOutcomeSnapshotRepo(db) {
|
|
|
3944
4071
|
db.insert(processLeafOutcomeSnapshots).values(values).run();
|
|
3945
4072
|
return rowToProcessLeafOutcomeSnapshot(values);
|
|
3946
4073
|
},
|
|
4074
|
+
/** @internal */
|
|
3947
4075
|
listByInstance(instanceId) {
|
|
3948
|
-
return db.select().from(processLeafOutcomeSnapshots).where(
|
|
4076
|
+
return db.select().from(processLeafOutcomeSnapshots).where(eq14(processLeafOutcomeSnapshots.instanceId, instanceId)).orderBy(
|
|
3949
4077
|
asc7(processLeafOutcomeSnapshots.anchoredAt),
|
|
3950
4078
|
asc7(processLeafOutcomeSnapshots.createdAt)
|
|
3951
4079
|
).all().map(rowToProcessLeafOutcomeSnapshot);
|
|
3952
4080
|
},
|
|
4081
|
+
/** @internal */
|
|
3953
4082
|
getByInstanceAndLeafEntryId(instanceId, leafEntryId) {
|
|
3954
4083
|
const row = db.select().from(processLeafOutcomeSnapshots).where(
|
|
3955
4084
|
and10(
|
|
3956
|
-
|
|
3957
|
-
|
|
4085
|
+
eq14(processLeafOutcomeSnapshots.instanceId, instanceId),
|
|
4086
|
+
eq14(processLeafOutcomeSnapshots.leafEntryId, leafEntryId)
|
|
3958
4087
|
)
|
|
3959
4088
|
).orderBy(desc7(processLeafOutcomeSnapshots.createdAt), desc7(sql5`rowid`)).limit(1).get();
|
|
3960
4089
|
return row ? rowToProcessLeafOutcomeSnapshot(row) : null;
|
|
@@ -3967,7 +4096,7 @@ import {
|
|
|
3967
4096
|
assertRepoLocator,
|
|
3968
4097
|
detectRepoLocatorKind
|
|
3969
4098
|
} from "@leitwerk-dev/domain";
|
|
3970
|
-
import { and as and11, eq as
|
|
4099
|
+
import { and as and11, eq as eq15, inArray as inArray5 } from "drizzle-orm";
|
|
3971
4100
|
function rowToProcessProject(row) {
|
|
3972
4101
|
return {
|
|
3973
4102
|
id: row.id,
|
|
@@ -3987,6 +4116,7 @@ function rowToProcessProject(row) {
|
|
|
3987
4116
|
}
|
|
3988
4117
|
function createProcessProjectRepo(db) {
|
|
3989
4118
|
return {
|
|
4119
|
+
/** @internal */
|
|
3990
4120
|
create(input) {
|
|
3991
4121
|
const id = generateId("prj");
|
|
3992
4122
|
const ts = now();
|
|
@@ -4010,23 +4140,28 @@ function createProcessProjectRepo(db) {
|
|
|
4010
4140
|
db.insert(processProjects).values(values).run();
|
|
4011
4141
|
return rowToProcessProject(values);
|
|
4012
4142
|
},
|
|
4143
|
+
/** @internal */
|
|
4013
4144
|
getById(id) {
|
|
4014
|
-
const row = db.select().from(processProjects).where(
|
|
4145
|
+
const row = db.select().from(processProjects).where(eq15(processProjects.id, id)).get();
|
|
4015
4146
|
return row ? rowToProcessProject(row) : null;
|
|
4016
4147
|
},
|
|
4148
|
+
/** @public */
|
|
4017
4149
|
listByInstance(instanceId) {
|
|
4018
|
-
return db.select().from(processProjects).where(
|
|
4150
|
+
return db.select().from(processProjects).where(eq15(processProjects.instanceId, instanceId)).all().map(rowToProcessProject);
|
|
4019
4151
|
},
|
|
4152
|
+
/** @internal */
|
|
4020
4153
|
listByInstances(instanceIds) {
|
|
4021
4154
|
if (instanceIds.length === 0) {
|
|
4022
4155
|
return [];
|
|
4023
4156
|
}
|
|
4024
4157
|
return db.select().from(processProjects).where(inArray5(processProjects.instanceId, [...instanceIds])).all().map(rowToProcessProject);
|
|
4025
4158
|
},
|
|
4159
|
+
/** @internal */
|
|
4026
4160
|
getByInstanceAndKey(instanceId, key) {
|
|
4027
|
-
const row = db.select().from(processProjects).where(and11(
|
|
4161
|
+
const row = db.select().from(processProjects).where(and11(eq15(processProjects.instanceId, instanceId), eq15(processProjects.key, key))).get();
|
|
4028
4162
|
return row ? rowToProcessProject(row) : null;
|
|
4029
4163
|
},
|
|
4164
|
+
/** @public */
|
|
4030
4165
|
update(id, input) {
|
|
4031
4166
|
const previous = this.getById(id);
|
|
4032
4167
|
if (!previous) {
|
|
@@ -4048,15 +4183,15 @@ function createProcessProjectRepo(db) {
|
|
|
4048
4183
|
}
|
|
4049
4184
|
if (input.metadata !== void 0)
|
|
4050
4185
|
setValues.metadata = input.metadata ? JSON.stringify(input.metadata) : null;
|
|
4051
|
-
db.update(processProjects).set(setValues).where(
|
|
4052
|
-
const row = db.select().from(processProjects).where(
|
|
4186
|
+
db.update(processProjects).set(setValues).where(eq15(processProjects.id, id)).run();
|
|
4187
|
+
const row = db.select().from(processProjects).where(eq15(processProjects.id, id)).get();
|
|
4053
4188
|
return row ? rowToProcessProject(row) : null;
|
|
4054
4189
|
}
|
|
4055
4190
|
};
|
|
4056
4191
|
}
|
|
4057
4192
|
|
|
4058
4193
|
// src/db/process-question-request-repo.ts
|
|
4059
|
-
import { and as and12, asc as asc8, eq as
|
|
4194
|
+
import { and as and12, asc as asc8, eq as eq16 } from "drizzle-orm";
|
|
4060
4195
|
function map(row) {
|
|
4061
4196
|
return {
|
|
4062
4197
|
id: row.id,
|
|
@@ -4074,26 +4209,30 @@ function map(row) {
|
|
|
4074
4209
|
}
|
|
4075
4210
|
function createProcessQuestionRequestRepo(db) {
|
|
4076
4211
|
const getById = (id) => {
|
|
4077
|
-
const row = db.select().from(processQuestionRequests).where(
|
|
4212
|
+
const row = db.select().from(processQuestionRequests).where(eq16(processQuestionRequests.id, id)).get();
|
|
4078
4213
|
return row ? map(row) : null;
|
|
4079
4214
|
};
|
|
4080
4215
|
const list = (instanceId, openOnly = false) => {
|
|
4081
4216
|
const filters = [
|
|
4082
|
-
...instanceId ? [
|
|
4083
|
-
...openOnly ? [
|
|
4217
|
+
...instanceId ? [eq16(processQuestionRequests.instanceId, instanceId)] : [],
|
|
4218
|
+
...openOnly ? [eq16(processQuestionRequests.status, "open")] : []
|
|
4084
4219
|
];
|
|
4085
4220
|
return db.select().from(processQuestionRequests).where(filters.length ? and12(...filters) : void 0).orderBy(asc8(processQuestionRequests.askedAt)).all().map(map);
|
|
4086
4221
|
};
|
|
4087
4222
|
return {
|
|
4223
|
+
/** @internal */
|
|
4088
4224
|
getById,
|
|
4225
|
+
/** @internal */
|
|
4089
4226
|
listByInstance: (instanceId) => list(instanceId),
|
|
4227
|
+
/** @internal */
|
|
4090
4228
|
listOpen: (instanceId) => list(instanceId, true),
|
|
4229
|
+
/** @internal */
|
|
4091
4230
|
createIdempotent(input) {
|
|
4092
4231
|
const existingRow = db.select().from(processQuestionRequests).where(
|
|
4093
4232
|
and12(
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4233
|
+
eq16(processQuestionRequests.instanceId, input.instanceId),
|
|
4234
|
+
eq16(processQuestionRequests.turnRecordId, input.turnRecordId),
|
|
4235
|
+
eq16(processQuestionRequests.toolCallId, input.toolCallId)
|
|
4097
4236
|
)
|
|
4098
4237
|
).get();
|
|
4099
4238
|
if (existingRow) {
|
|
@@ -4113,6 +4252,7 @@ function createProcessQuestionRequestRepo(db) {
|
|
|
4113
4252
|
}).returning().get();
|
|
4114
4253
|
return { kind: "created", request: map(row) };
|
|
4115
4254
|
},
|
|
4255
|
+
/** @internal */
|
|
4116
4256
|
answer(input) {
|
|
4117
4257
|
const row = db.update(processQuestionRequests).set({
|
|
4118
4258
|
status: "answered",
|
|
@@ -4121,19 +4261,20 @@ function createProcessQuestionRequestRepo(db) {
|
|
|
4121
4261
|
answeredByJson: JSON.stringify(input.actor)
|
|
4122
4262
|
}).where(
|
|
4123
4263
|
and12(
|
|
4124
|
-
|
|
4125
|
-
|
|
4264
|
+
eq16(processQuestionRequests.id, input.id),
|
|
4265
|
+
eq16(processQuestionRequests.status, "open")
|
|
4126
4266
|
)
|
|
4127
4267
|
).returning().get();
|
|
4128
4268
|
return row ? map(row) : null;
|
|
4129
4269
|
},
|
|
4270
|
+
/** @internal */
|
|
4130
4271
|
cancelOpenByTurn(instanceId, turnRecordId) {
|
|
4131
4272
|
return Number(
|
|
4132
4273
|
db.update(processQuestionRequests).set({ status: "cancelled", cancelledAt: now() }).where(
|
|
4133
4274
|
and12(
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4275
|
+
eq16(processQuestionRequests.instanceId, instanceId),
|
|
4276
|
+
eq16(processQuestionRequests.turnRecordId, turnRecordId),
|
|
4277
|
+
eq16(processQuestionRequests.status, "open")
|
|
4137
4278
|
)
|
|
4138
4279
|
).run().changes
|
|
4139
4280
|
);
|
|
@@ -4142,7 +4283,7 @@ function createProcessQuestionRequestRepo(db) {
|
|
|
4142
4283
|
}
|
|
4143
4284
|
|
|
4144
4285
|
// src/db/process-relation-repo.ts
|
|
4145
|
-
import { asc as asc9, eq as
|
|
4286
|
+
import { asc as asc9, eq as eq17 } from "drizzle-orm";
|
|
4146
4287
|
function map2(row) {
|
|
4147
4288
|
return {
|
|
4148
4289
|
parentInstanceId: row.parentInstanceId,
|
|
@@ -4155,6 +4296,7 @@ function map2(row) {
|
|
|
4155
4296
|
}
|
|
4156
4297
|
function createProcessRelationRepo(db) {
|
|
4157
4298
|
return {
|
|
4299
|
+
/** @internal */
|
|
4158
4300
|
create(input) {
|
|
4159
4301
|
const row = db.insert(processRelations).values({
|
|
4160
4302
|
parentInstanceId: input.parentInstanceId,
|
|
@@ -4166,18 +4308,20 @@ function createProcessRelationRepo(db) {
|
|
|
4166
4308
|
}).returning().get();
|
|
4167
4309
|
return map2(row);
|
|
4168
4310
|
},
|
|
4311
|
+
/** @internal */
|
|
4169
4312
|
getByChild(childInstanceId) {
|
|
4170
|
-
const row = db.select().from(processRelations).where(
|
|
4313
|
+
const row = db.select().from(processRelations).where(eq17(processRelations.childInstanceId, childInstanceId)).get();
|
|
4171
4314
|
return row ? map2(row) : null;
|
|
4172
4315
|
},
|
|
4316
|
+
/** @internal */
|
|
4173
4317
|
listByParent(parentInstanceId) {
|
|
4174
|
-
return db.select().from(processRelations).where(
|
|
4318
|
+
return db.select().from(processRelations).where(eq17(processRelations.parentInstanceId, parentInstanceId)).orderBy(asc9(processRelations.createdAt)).all().map(map2);
|
|
4175
4319
|
}
|
|
4176
4320
|
};
|
|
4177
4321
|
}
|
|
4178
4322
|
|
|
4179
4323
|
// src/db/process-skill-repo.ts
|
|
4180
|
-
import { asc as asc10, eq as
|
|
4324
|
+
import { asc as asc10, eq as eq18 } from "drizzle-orm";
|
|
4181
4325
|
|
|
4182
4326
|
// src/pi-resources/resource-collector.ts
|
|
4183
4327
|
import { constants } from "node:fs";
|
|
@@ -4357,13 +4501,14 @@ var ResourceCollector = class {
|
|
|
4357
4501
|
// src/db/process-skill-repo.ts
|
|
4358
4502
|
function createProcessSkillRepo(db) {
|
|
4359
4503
|
return {
|
|
4504
|
+
/** @internal */
|
|
4360
4505
|
attach(instanceId, selections) {
|
|
4361
4506
|
const seen = /* @__PURE__ */ new Set();
|
|
4362
4507
|
selections.forEach((selection, position) => {
|
|
4363
4508
|
if (seen.has(selection.skillId))
|
|
4364
4509
|
throw new Error(`Duplicate skill selection '${selection.skillId}'`);
|
|
4365
4510
|
seen.add(selection.skillId);
|
|
4366
|
-
const revision = db.select().from(skillRevisions).where(
|
|
4511
|
+
const revision = db.select().from(skillRevisions).where(eq18(skillRevisions.id, selection.revisionId)).get();
|
|
4367
4512
|
if (!revision || revision.skillId !== selection.skillId)
|
|
4368
4513
|
throw new Error(`Invalid revision for skill '${selection.skillId}'`);
|
|
4369
4514
|
db.insert(processSkills).values({
|
|
@@ -4374,17 +4519,19 @@ function createProcessSkillRepo(db) {
|
|
|
4374
4519
|
}).run();
|
|
4375
4520
|
});
|
|
4376
4521
|
},
|
|
4522
|
+
/** @internal */
|
|
4377
4523
|
listSelections(instanceId) {
|
|
4378
4524
|
return db.select({
|
|
4379
4525
|
skillId: processSkills.skillId,
|
|
4380
4526
|
revisionId: processSkills.skillRevisionId
|
|
4381
|
-
}).from(processSkills).where(
|
|
4527
|
+
}).from(processSkills).where(eq18(processSkills.instanceId, instanceId)).orderBy(asc10(processSkills.position)).all();
|
|
4382
4528
|
},
|
|
4529
|
+
/** @internal */
|
|
4383
4530
|
listResourceLayers(instanceId) {
|
|
4384
4531
|
return db.select({
|
|
4385
4532
|
digest: skillRevisions.bundleDigest,
|
|
4386
4533
|
bytes: skillRevisions.bundleBytes
|
|
4387
|
-
}).from(processSkills).innerJoin(skillRevisions,
|
|
4534
|
+
}).from(processSkills).innerJoin(skillRevisions, eq18(processSkills.skillRevisionId, skillRevisions.id)).where(eq18(processSkills.instanceId, instanceId)).orderBy(asc10(processSkills.position)).all().map(({ digest, bytes }) => ({
|
|
4388
4535
|
bundle: { digest, bytes },
|
|
4389
4536
|
owner: SKILL_RESOURCE_OWNER
|
|
4390
4537
|
}));
|
|
@@ -4393,12 +4540,13 @@ function createProcessSkillRepo(db) {
|
|
|
4393
4540
|
}
|
|
4394
4541
|
|
|
4395
4542
|
// src/db/process-title-job-repo.ts
|
|
4396
|
-
import { and as and13, asc as asc11, eq as
|
|
4543
|
+
import { and as and13, asc as asc11, eq as eq19, inArray as inArray6, lte as lte2, sql as sql6 } from "drizzle-orm";
|
|
4397
4544
|
function createProcessTitleJobRepo(db) {
|
|
4398
4545
|
function transition(id, from, values) {
|
|
4399
|
-
return db.update(processTitleJobs).set({ ...values, updatedAt: now() }).where(and13(
|
|
4546
|
+
return db.update(processTitleJobs).set({ ...values, updatedAt: now() }).where(and13(eq19(processTitleJobs.id, id), inArray6(processTitleJobs.status, from))).returning().get() ?? null;
|
|
4400
4547
|
}
|
|
4401
4548
|
return {
|
|
4549
|
+
/** @internal */
|
|
4402
4550
|
enqueue(input) {
|
|
4403
4551
|
const ts = now();
|
|
4404
4552
|
const target2 = "processInstanceId" in input ? {
|
|
@@ -4413,7 +4561,7 @@ function createProcessTitleJobRepo(db) {
|
|
|
4413
4561
|
db.update(processTitleJobs).set({ status: "superseded", updatedAt: ts }).where(
|
|
4414
4562
|
and13(
|
|
4415
4563
|
inArray6(processTitleJobs.status, ["pending", "running"]),
|
|
4416
|
-
target2.targetKind === "process" ?
|
|
4564
|
+
target2.targetKind === "process" ? eq19(processTitleJobs.processInstanceId, target2.processInstanceId) : eq19(processTitleJobs.futureExecutionId, target2.futureExecutionId)
|
|
4417
4565
|
)
|
|
4418
4566
|
).run();
|
|
4419
4567
|
return db.insert(processTitleJobs).values({
|
|
@@ -4429,21 +4577,26 @@ function createProcessTitleJobRepo(db) {
|
|
|
4429
4577
|
updatedAt: ts
|
|
4430
4578
|
}).returning().get();
|
|
4431
4579
|
},
|
|
4580
|
+
/** @internal */
|
|
4432
4581
|
getById(id) {
|
|
4433
|
-
const row = db.select().from(processTitleJobs).where(
|
|
4582
|
+
const row = db.select().from(processTitleJobs).where(eq19(processTitleJobs.id, id)).get();
|
|
4434
4583
|
return row ?? null;
|
|
4435
4584
|
},
|
|
4585
|
+
/** @internal */
|
|
4436
4586
|
listByProcessInstance(processInstanceId) {
|
|
4437
|
-
return db.select().from(processTitleJobs).where(
|
|
4587
|
+
return db.select().from(processTitleJobs).where(eq19(processTitleJobs.processInstanceId, processInstanceId)).orderBy(asc11(processTitleJobs.createdAt), asc11(processTitleJobs.id)).all();
|
|
4438
4588
|
},
|
|
4589
|
+
/** @internal */
|
|
4439
4590
|
listAll() {
|
|
4440
4591
|
return db.select().from(processTitleJobs).orderBy(asc11(processTitleJobs.createdAt), asc11(processTitleJobs.id)).all();
|
|
4441
4592
|
},
|
|
4593
|
+
/** @internal */
|
|
4442
4594
|
listDuePending(asOf, limit) {
|
|
4443
4595
|
return db.select().from(processTitleJobs).where(
|
|
4444
|
-
and13(
|
|
4596
|
+
and13(eq19(processTitleJobs.status, "pending"), lte2(processTitleJobs.nextRunAt, asOf))
|
|
4445
4597
|
).orderBy(asc11(processTitleJobs.nextRunAt), asc11(processTitleJobs.createdAt)).limit(Math.max(0, limit)).all();
|
|
4446
4598
|
},
|
|
4599
|
+
/** @internal */
|
|
4447
4600
|
markRunning(id) {
|
|
4448
4601
|
return transition(id, ["pending"], {
|
|
4449
4602
|
status: "running",
|
|
@@ -4451,15 +4604,19 @@ function createProcessTitleJobRepo(db) {
|
|
|
4451
4604
|
lastError: null
|
|
4452
4605
|
});
|
|
4453
4606
|
},
|
|
4607
|
+
/** @internal */
|
|
4454
4608
|
reschedule(id, nextRunAt, lastError) {
|
|
4455
4609
|
return transition(id, ["running"], { status: "pending", nextRunAt, lastError });
|
|
4456
4610
|
},
|
|
4611
|
+
/** @internal */
|
|
4457
4612
|
markCompleted(id) {
|
|
4458
4613
|
return transition(id, ["running"], { status: "completed", lastError: null });
|
|
4459
4614
|
},
|
|
4615
|
+
/** @internal */
|
|
4460
4616
|
markFailed(id, lastError) {
|
|
4461
4617
|
return transition(id, ["running"], { status: "failed", lastError });
|
|
4462
4618
|
},
|
|
4619
|
+
/** @internal */
|
|
4463
4620
|
markSuperseded(id) {
|
|
4464
4621
|
return transition(id, ["pending", "running"], { status: "superseded" });
|
|
4465
4622
|
}
|
|
@@ -4467,7 +4624,7 @@ function createProcessTitleJobRepo(db) {
|
|
|
4467
4624
|
}
|
|
4468
4625
|
|
|
4469
4626
|
// src/db/process-tool-approval-request-repo.ts
|
|
4470
|
-
import { and as and14, asc as asc12, eq as
|
|
4627
|
+
import { and as and14, asc as asc12, eq as eq20 } from "drizzle-orm";
|
|
4471
4628
|
function map3(row) {
|
|
4472
4629
|
return {
|
|
4473
4630
|
id: row.id,
|
|
@@ -4493,20 +4650,23 @@ function map3(row) {
|
|
|
4493
4650
|
function createProcessToolApprovalRequestRepo(db) {
|
|
4494
4651
|
const list = (instanceId, openOnly = false) => {
|
|
4495
4652
|
const filters = [
|
|
4496
|
-
...instanceId ? [
|
|
4497
|
-
...openOnly ? [
|
|
4653
|
+
...instanceId ? [eq20(processToolApprovalRequests.instanceId, instanceId)] : [],
|
|
4654
|
+
...openOnly ? [eq20(processToolApprovalRequests.status, "open")] : []
|
|
4498
4655
|
];
|
|
4499
4656
|
return db.select().from(processToolApprovalRequests).where(filters.length ? and14(...filters) : void 0).orderBy(asc12(processToolApprovalRequests.requestedAt)).all().map(map3);
|
|
4500
4657
|
};
|
|
4501
4658
|
return {
|
|
4659
|
+
/** @internal */
|
|
4502
4660
|
listByInstance: (instanceId) => list(instanceId),
|
|
4661
|
+
/** @internal */
|
|
4503
4662
|
listOpen: (instanceId) => list(instanceId, true),
|
|
4663
|
+
/** @internal */
|
|
4504
4664
|
createIdempotent(input) {
|
|
4505
4665
|
const existing = db.select().from(processToolApprovalRequests).where(
|
|
4506
4666
|
and14(
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4667
|
+
eq20(processToolApprovalRequests.instanceId, input.instanceId),
|
|
4668
|
+
eq20(processToolApprovalRequests.turnRecordId, input.turnRecordId),
|
|
4669
|
+
eq20(processToolApprovalRequests.toolCallId, input.toolCallId)
|
|
4510
4670
|
)
|
|
4511
4671
|
).get();
|
|
4512
4672
|
if (existing) {
|
|
@@ -4528,6 +4688,7 @@ function createProcessToolApprovalRequestRepo(db) {
|
|
|
4528
4688
|
}).returning().get();
|
|
4529
4689
|
return { kind: "created", request: map3(row) };
|
|
4530
4690
|
},
|
|
4691
|
+
/** @internal */
|
|
4531
4692
|
resolve(input) {
|
|
4532
4693
|
if (input.status === "feedback" && !input.feedback?.trim())
|
|
4533
4694
|
throw new Error("Feedback is required");
|
|
@@ -4538,18 +4699,19 @@ function createProcessToolApprovalRequestRepo(db) {
|
|
|
4538
4699
|
feedback: input.feedback?.trim() ?? null
|
|
4539
4700
|
}).where(
|
|
4540
4701
|
and14(
|
|
4541
|
-
|
|
4542
|
-
|
|
4702
|
+
eq20(processToolApprovalRequests.id, input.id),
|
|
4703
|
+
eq20(processToolApprovalRequests.status, "open")
|
|
4543
4704
|
)
|
|
4544
4705
|
).returning().get();
|
|
4545
4706
|
return row ? map3(row) : null;
|
|
4546
4707
|
},
|
|
4708
|
+
/** @internal */
|
|
4547
4709
|
cancelOpenByTurn(instanceId, turnRecordId) {
|
|
4548
4710
|
const result = db.update(processToolApprovalRequests).set({ status: "cancelled", resolvedAt: now() }).where(
|
|
4549
4711
|
and14(
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4712
|
+
eq20(processToolApprovalRequests.instanceId, instanceId),
|
|
4713
|
+
eq20(processToolApprovalRequests.turnRecordId, turnRecordId),
|
|
4714
|
+
eq20(processToolApprovalRequests.status, "open")
|
|
4553
4715
|
)
|
|
4554
4716
|
).run();
|
|
4555
4717
|
return Number(result.changes);
|
|
@@ -4559,7 +4721,7 @@ function createProcessToolApprovalRequestRepo(db) {
|
|
|
4559
4721
|
|
|
4560
4722
|
// src/db/process-turn-annotation-repo.ts
|
|
4561
4723
|
import { parseTurnAnnotationReferences } from "@leitwerk-dev/domain";
|
|
4562
|
-
import { and as and15, asc as asc13, eq as
|
|
4724
|
+
import { and as and15, asc as asc13, eq as eq21 } from "drizzle-orm";
|
|
4563
4725
|
function parseReferences(value) {
|
|
4564
4726
|
try {
|
|
4565
4727
|
return parseTurnAnnotationReferences(JSON.parse(value));
|
|
@@ -4581,6 +4743,7 @@ function rowToProcessTurnAnnotation(row) {
|
|
|
4581
4743
|
}
|
|
4582
4744
|
function createProcessTurnAnnotationRepo(db) {
|
|
4583
4745
|
return {
|
|
4746
|
+
/** @internal */
|
|
4584
4747
|
create(input) {
|
|
4585
4748
|
const id = input.id ?? generateId("tan");
|
|
4586
4749
|
const createdAt = input.createdAt ?? now();
|
|
@@ -4598,10 +4761,12 @@ function createProcessTurnAnnotationRepo(db) {
|
|
|
4598
4761
|
db.insert(turnAnnotations).values(values).run();
|
|
4599
4762
|
return rowToProcessTurnAnnotation(values);
|
|
4600
4763
|
},
|
|
4764
|
+
/** @internal */
|
|
4601
4765
|
getById(id) {
|
|
4602
|
-
const row = db.select().from(turnAnnotations).where(
|
|
4766
|
+
const row = db.select().from(turnAnnotations).where(eq21(turnAnnotations.id, id)).get();
|
|
4603
4767
|
return row ? rowToProcessTurnAnnotation(row) : null;
|
|
4604
4768
|
},
|
|
4769
|
+
/** @internal */
|
|
4605
4770
|
findByKey(instanceId, annotationKey) {
|
|
4606
4771
|
const key = annotationKey.trim();
|
|
4607
4772
|
if (key.length === 0) {
|
|
@@ -4609,15 +4774,17 @@ function createProcessTurnAnnotationRepo(db) {
|
|
|
4609
4774
|
}
|
|
4610
4775
|
const row = db.select().from(turnAnnotations).where(
|
|
4611
4776
|
and15(
|
|
4612
|
-
|
|
4613
|
-
|
|
4777
|
+
eq21(turnAnnotations.instanceId, instanceId),
|
|
4778
|
+
eq21(turnAnnotations.annotationKey, key)
|
|
4614
4779
|
)
|
|
4615
4780
|
).get();
|
|
4616
4781
|
return row ? rowToProcessTurnAnnotation(row) : null;
|
|
4617
4782
|
},
|
|
4783
|
+
/** @internal */
|
|
4618
4784
|
listByInstance(instanceId) {
|
|
4619
|
-
return db.select().from(turnAnnotations).where(
|
|
4785
|
+
return db.select().from(turnAnnotations).where(eq21(turnAnnotations.instanceId, instanceId)).orderBy(asc13(turnAnnotations.createdAt)).all().map(rowToProcessTurnAnnotation);
|
|
4620
4786
|
},
|
|
4787
|
+
/** @internal */
|
|
4621
4788
|
update(id, input) {
|
|
4622
4789
|
const setValues = {
|
|
4623
4790
|
updatedAt: input.updatedAt ?? now(),
|
|
@@ -4627,18 +4794,19 @@ function createProcessTurnAnnotationRepo(db) {
|
|
|
4627
4794
|
if (input.references !== void 0)
|
|
4628
4795
|
setValues.referencesJson = JSON.stringify(input.references);
|
|
4629
4796
|
if (input.payload !== void 0) setValues.payloadJson = JSON.stringify(input.payload);
|
|
4630
|
-
db.update(turnAnnotations).set(setValues).where(
|
|
4797
|
+
db.update(turnAnnotations).set(setValues).where(eq21(turnAnnotations.id, id)).run();
|
|
4631
4798
|
return this.getById(id);
|
|
4632
4799
|
},
|
|
4800
|
+
/** @internal */
|
|
4633
4801
|
delete(id) {
|
|
4634
|
-
const result = db.delete(turnAnnotations).where(
|
|
4802
|
+
const result = db.delete(turnAnnotations).where(eq21(turnAnnotations.id, id)).run();
|
|
4635
4803
|
return result.changes > 0;
|
|
4636
4804
|
}
|
|
4637
4805
|
};
|
|
4638
4806
|
}
|
|
4639
4807
|
|
|
4640
4808
|
// src/db/process-turn-record-repo.ts
|
|
4641
|
-
import { asc as asc14, desc as desc8, eq as
|
|
4809
|
+
import { asc as asc14, desc as desc8, eq as eq22 } from "drizzle-orm";
|
|
4642
4810
|
function rowToProcessTurnRecord(row) {
|
|
4643
4811
|
return {
|
|
4644
4812
|
id: row.id,
|
|
@@ -4667,6 +4835,7 @@ function rowToProcessTurnRecord(row) {
|
|
|
4667
4835
|
}
|
|
4668
4836
|
function createProcessTurnRecordRepo(db) {
|
|
4669
4837
|
return {
|
|
4838
|
+
/** @internal */
|
|
4670
4839
|
create(input) {
|
|
4671
4840
|
const id = input.id ?? generateId("trn");
|
|
4672
4841
|
const values = {
|
|
@@ -4694,19 +4863,23 @@ function createProcessTurnRecordRepo(db) {
|
|
|
4694
4863
|
db.insert(turnRecords).values(values).run();
|
|
4695
4864
|
return rowToProcessTurnRecord(values);
|
|
4696
4865
|
},
|
|
4866
|
+
/** @internal */
|
|
4697
4867
|
getById(id) {
|
|
4698
|
-
const row = db.select().from(turnRecords).where(
|
|
4868
|
+
const row = db.select().from(turnRecords).where(eq22(turnRecords.id, id)).get();
|
|
4699
4869
|
return row ? rowToProcessTurnRecord(row) : null;
|
|
4700
4870
|
},
|
|
4871
|
+
/** @public */
|
|
4701
4872
|
listByInstance(instanceId) {
|
|
4702
|
-
return db.select().from(turnRecords).where(
|
|
4873
|
+
return db.select().from(turnRecords).where(eq22(turnRecords.instanceId, instanceId)).orderBy(asc14(turnRecords.startedAt)).all().map(rowToProcessTurnRecord);
|
|
4703
4874
|
},
|
|
4875
|
+
/** @internal */
|
|
4704
4876
|
getLatestSucceededPrimaryByInstance(instanceId) {
|
|
4705
|
-
const row = db.select().from(turnRecords).where(
|
|
4877
|
+
const row = db.select().from(turnRecords).where(eq22(turnRecords.instanceId, instanceId)).orderBy(desc8(turnRecords.startedAt)).all().map(rowToProcessTurnRecord).find(
|
|
4706
4878
|
(run) => run.status === "succeeded" && run.pathType === "primary" && typeof run.resultPiEntryId === "string" && run.resultPiEntryId.length > 0
|
|
4707
4879
|
);
|
|
4708
4880
|
return row ?? null;
|
|
4709
4881
|
},
|
|
4882
|
+
/** @internal */
|
|
4710
4883
|
update(id, input) {
|
|
4711
4884
|
const setValues = {
|
|
4712
4885
|
turnType: input.turnType,
|
|
@@ -4727,14 +4900,14 @@ function createProcessTurnRecordRepo(db) {
|
|
|
4727
4900
|
setValues.modelSelectionKind = input.modelSelectionProvenance?.kind ?? null;
|
|
4728
4901
|
setValues.modelSelectionSource = input.modelSelectionProvenance?.source ?? null;
|
|
4729
4902
|
}
|
|
4730
|
-
db.update(turnRecords).set(setValues).where(
|
|
4903
|
+
db.update(turnRecords).set(setValues).where(eq22(turnRecords.id, id)).run();
|
|
4731
4904
|
return this.getById(id);
|
|
4732
4905
|
}
|
|
4733
4906
|
};
|
|
4734
4907
|
}
|
|
4735
4908
|
|
|
4736
4909
|
// src/db/provider-credential-repo.ts
|
|
4737
|
-
import { and as and16, count as count3, eq as
|
|
4910
|
+
import { and as and16, count as count3, eq as eq23 } from "drizzle-orm";
|
|
4738
4911
|
function createProviderCredentialRepo(db, cipher) {
|
|
4739
4912
|
const row = (value) => ({
|
|
4740
4913
|
providerId: value.providerId,
|
|
@@ -4744,13 +4917,16 @@ function createProviderCredentialRepo(db, cipher) {
|
|
|
4744
4917
|
updatedAt: value.updatedAt
|
|
4745
4918
|
});
|
|
4746
4919
|
return {
|
|
4920
|
+
/** @internal */
|
|
4747
4921
|
count() {
|
|
4748
4922
|
return db.select({ value: count3() }).from(providerCredentials).get()?.value ?? 0;
|
|
4749
4923
|
},
|
|
4924
|
+
/** @internal */
|
|
4750
4925
|
get(providerId) {
|
|
4751
|
-
const value = db.select().from(providerCredentials).where(
|
|
4926
|
+
const value = db.select().from(providerCredentials).where(eq23(providerCredentials.providerId, providerId)).get();
|
|
4752
4927
|
return value ? row(value) : null;
|
|
4753
4928
|
},
|
|
4929
|
+
/** @internal */
|
|
4754
4930
|
create(input) {
|
|
4755
4931
|
const ts = now();
|
|
4756
4932
|
const value = {
|
|
@@ -4769,6 +4945,7 @@ function createProviderCredentialRepo(db, cipher) {
|
|
|
4769
4945
|
updatedAt: ts
|
|
4770
4946
|
};
|
|
4771
4947
|
},
|
|
4948
|
+
/** @internal */
|
|
4772
4949
|
compareAndSet(input) {
|
|
4773
4950
|
const ts = now();
|
|
4774
4951
|
const revision = input.expectedRevision + 1;
|
|
@@ -4778,8 +4955,8 @@ function createProviderCredentialRepo(db, cipher) {
|
|
|
4778
4955
|
updatedAt: ts
|
|
4779
4956
|
}).where(
|
|
4780
4957
|
and16(
|
|
4781
|
-
|
|
4782
|
-
|
|
4958
|
+
eq23(providerCredentials.providerId, input.providerId),
|
|
4959
|
+
eq23(providerCredentials.revision, input.expectedRevision)
|
|
4783
4960
|
)
|
|
4784
4961
|
).run();
|
|
4785
4962
|
if (result.changes !== 1) return null;
|
|
@@ -4792,7 +4969,7 @@ function createProviderCredentialRepo(db, cipher) {
|
|
|
4792
4969
|
import {
|
|
4793
4970
|
sessionTransferAttemptStateForPhase
|
|
4794
4971
|
} from "@leitwerk-dev/session-transfer";
|
|
4795
|
-
import { and as and17, eq as
|
|
4972
|
+
import { and as and17, eq as eq24, inArray as inArray7, isNotNull, isNull as isNull3, lt as lt2, notExists, or as or3 } from "drizzle-orm";
|
|
4796
4973
|
|
|
4797
4974
|
// src/auth/auth-tokens.ts
|
|
4798
4975
|
import { createHash, randomBytes as randomBytes2, timingSafeEqual } from "node:crypto";
|
|
@@ -4834,6 +5011,7 @@ function createSessionTransferRepo(db) {
|
|
|
4834
5011
|
state: sessionTransferAttemptStateForPhase(row.phase)
|
|
4835
5012
|
} : null;
|
|
4836
5013
|
return {
|
|
5014
|
+
/** @internal */
|
|
4837
5015
|
createGrant(input) {
|
|
4838
5016
|
const rawToken = createOpaqueToken();
|
|
4839
5017
|
const values = {
|
|
@@ -4848,27 +5026,32 @@ function createSessionTransferRepo(db) {
|
|
|
4848
5026
|
db.insert(sessionTransferGrants).values(values).run();
|
|
4849
5027
|
return { grant: this.getGrant(values.id), rawToken };
|
|
4850
5028
|
},
|
|
5029
|
+
/** @internal */
|
|
4851
5030
|
getGrant(id) {
|
|
4852
|
-
return db.select().from(sessionTransferGrants).where(
|
|
5031
|
+
return db.select().from(sessionTransferGrants).where(eq24(sessionTransferGrants.id, id)).get() ?? null;
|
|
4853
5032
|
},
|
|
5033
|
+
/** @internal */
|
|
4854
5034
|
getAttempt(id) {
|
|
4855
5035
|
return toAttempt(
|
|
4856
|
-
db.select().from(sessionTransferAttempts).where(
|
|
5036
|
+
db.select().from(sessionTransferAttempts).where(eq24(sessionTransferAttempts.id, id)).get()
|
|
4857
5037
|
);
|
|
4858
5038
|
},
|
|
5039
|
+
/** @internal */
|
|
4859
5040
|
getActiveByInstance(instanceId) {
|
|
4860
5041
|
return toAttempt(
|
|
4861
5042
|
db.select().from(sessionTransferAttempts).where(
|
|
4862
5043
|
and17(
|
|
4863
|
-
|
|
5044
|
+
eq24(sessionTransferAttempts.instanceId, instanceId),
|
|
4864
5045
|
inArray7(sessionTransferAttempts.phase, ACTIVE_PHASES)
|
|
4865
5046
|
)
|
|
4866
5047
|
).get()
|
|
4867
5048
|
);
|
|
4868
5049
|
},
|
|
5050
|
+
/** @internal */
|
|
4869
5051
|
listActive() {
|
|
4870
5052
|
return db.select().from(sessionTransferAttempts).where(inArray7(sessionTransferAttempts.phase, ACTIVE_PHASES)).all().map((row) => toAttempt(row));
|
|
4871
5053
|
},
|
|
5054
|
+
/** @internal */
|
|
4872
5055
|
startAttempt(input) {
|
|
4873
5056
|
const grant = this.getGrant(input.grantId);
|
|
4874
5057
|
if (!grant || grant.instanceId !== input.instanceId || grant.consumedAt !== null || Date.parse(grant.expiresAt) <= input.now.getTime() || !verifyOpaqueToken(input.token, grant.tokenHash, "hex")) {
|
|
@@ -4902,6 +5085,7 @@ function createSessionTransferRepo(db) {
|
|
|
4902
5085
|
attempt: this.getAttempt(values.id)
|
|
4903
5086
|
};
|
|
4904
5087
|
},
|
|
5088
|
+
/** @internal */
|
|
4905
5089
|
verifyAttempt(input) {
|
|
4906
5090
|
const grant = this.getGrant(input.grantId);
|
|
4907
5091
|
const attempt = this.getAttempt(input.attemptId);
|
|
@@ -4909,10 +5093,12 @@ function createSessionTransferRepo(db) {
|
|
|
4909
5093
|
return null;
|
|
4910
5094
|
return verifyOpaqueToken(input.token, grant.tokenHash, "hex") ? attempt : null;
|
|
4911
5095
|
},
|
|
5096
|
+
/** @internal */
|
|
4912
5097
|
updateAttempt(id, patch) {
|
|
4913
|
-
db.update(sessionTransferAttempts).set(patch).where(
|
|
5098
|
+
db.update(sessionTransferAttempts).set(patch).where(eq24(sessionTransferAttempts.id, id)).run();
|
|
4914
5099
|
return this.getAttempt(id);
|
|
4915
5100
|
},
|
|
5101
|
+
/** @internal */
|
|
4916
5102
|
renew(id, input) {
|
|
4917
5103
|
const attempt = this.getAttempt(id);
|
|
4918
5104
|
if (!attempt || !isActivePhase(attempt.phase)) return attempt;
|
|
@@ -4922,6 +5108,7 @@ function createSessionTransferRepo(db) {
|
|
|
4922
5108
|
);
|
|
4923
5109
|
return this.updateAttempt(id, { leaseUntil: new Date(nextLease).toISOString() });
|
|
4924
5110
|
},
|
|
5111
|
+
/** @internal */
|
|
4925
5112
|
acknowledge(input) {
|
|
4926
5113
|
const attempt = this.getAttempt(input.attemptId);
|
|
4927
5114
|
if (!attempt) return null;
|
|
@@ -4931,8 +5118,8 @@ function createSessionTransferRepo(db) {
|
|
|
4931
5118
|
const completedAt = input.now.toISOString();
|
|
4932
5119
|
db.update(sessionTransferAttempts).set({ phase: "consumed", completedAt }).where(
|
|
4933
5120
|
and17(
|
|
4934
|
-
|
|
4935
|
-
|
|
5121
|
+
eq24(sessionTransferAttempts.id, attempt.id),
|
|
5122
|
+
eq24(sessionTransferAttempts.phase, "awaiting_ack")
|
|
4936
5123
|
)
|
|
4937
5124
|
).run();
|
|
4938
5125
|
db.update(sessionTransferGrants).set({
|
|
@@ -4940,15 +5127,17 @@ function createSessionTransferRepo(db) {
|
|
|
4940
5127
|
tombstoneUntil: new Date(input.now.getTime() + input.tombstoneMs).toISOString()
|
|
4941
5128
|
}).where(
|
|
4942
5129
|
and17(
|
|
4943
|
-
|
|
5130
|
+
eq24(sessionTransferGrants.id, attempt.grantId),
|
|
4944
5131
|
isNull3(sessionTransferGrants.consumedAt)
|
|
4945
5132
|
)
|
|
4946
5133
|
).run();
|
|
4947
5134
|
return this.getAttempt(attempt.id);
|
|
4948
5135
|
},
|
|
5136
|
+
/** @internal */
|
|
4949
5137
|
revokeProcess(instanceId) {
|
|
4950
|
-
db.delete(sessionTransferGrants).where(
|
|
5138
|
+
db.delete(sessionTransferGrants).where(eq24(sessionTransferGrants.instanceId, instanceId)).run();
|
|
4951
5139
|
},
|
|
5140
|
+
/** @internal */
|
|
4952
5141
|
cleanup(now2) {
|
|
4953
5142
|
const cutoff = now2.toISOString();
|
|
4954
5143
|
db.delete(sessionTransferGrants).where(
|
|
@@ -4966,7 +5155,7 @@ function createSessionTransferRepo(db) {
|
|
|
4966
5155
|
notExists(
|
|
4967
5156
|
db.select({ id: sessionTransferAttempts.id }).from(sessionTransferAttempts).where(
|
|
4968
5157
|
and17(
|
|
4969
|
-
|
|
5158
|
+
eq24(sessionTransferAttempts.grantId, sessionTransferGrants.id),
|
|
4970
5159
|
inArray7(sessionTransferAttempts.phase, ACTIVE_PHASES)
|
|
4971
5160
|
)
|
|
4972
5161
|
)
|
|
@@ -4979,7 +5168,7 @@ function createSessionTransferRepo(db) {
|
|
|
4979
5168
|
|
|
4980
5169
|
// src/db/skill-repo.ts
|
|
4981
5170
|
import { verifyCanonicalPiResourceBundle as verifyCanonicalPiResourceBundle2 } from "@leitwerk-dev/worker-protocol";
|
|
4982
|
-
import { and as and18, asc as asc15, count as count4, desc as desc9, eq as
|
|
5171
|
+
import { and as and18, asc as asc15, count as count4, desc as desc9, eq as eq25, isNotNull as isNotNull2, max as max2, notExists as notExists2, notInArray as notInArray2, sql as sql7 } from "drizzle-orm";
|
|
4983
5172
|
|
|
4984
5173
|
// src/skills/skill-dependencies.ts
|
|
4985
5174
|
var EXPLICIT_SKILL_REFERENCE = /\/([A-Za-z0-9][A-Za-z0-9._-]{0,83})|`([A-Za-z0-9][A-Za-z0-9._-]{0,83})`/g;
|
|
@@ -5017,8 +5206,8 @@ function isSkillModelInvocable(markdown) {
|
|
|
5017
5206
|
function revisionForBundle(db, item, timestamp) {
|
|
5018
5207
|
const existing = db.select({ id: skillRevisions.id }).from(skillRevisions).where(
|
|
5019
5208
|
and18(
|
|
5020
|
-
|
|
5021
|
-
|
|
5209
|
+
eq25(skillRevisions.skillId, item.skillId),
|
|
5210
|
+
eq25(skillRevisions.bundleDigest, item.bundle.digest)
|
|
5022
5211
|
)
|
|
5023
5212
|
).get();
|
|
5024
5213
|
if (existing) return existing.id;
|
|
@@ -5049,7 +5238,7 @@ function usageBySkill(db) {
|
|
|
5049
5238
|
skillId: processSkills.skillId,
|
|
5050
5239
|
allTime: count4(),
|
|
5051
5240
|
last30Days: sql7`sum(case when ${processInstances.createdAt} >= ${cutoff} then 1 else 0 end)`
|
|
5052
|
-
}).from(processSkills).innerJoin(processInstances,
|
|
5241
|
+
}).from(processSkills).innerJoin(processInstances, eq25(processSkills.instanceId, processInstances.id)).groupBy(processSkills.skillId).all()) {
|
|
5053
5242
|
result.set(row.skillId, {
|
|
5054
5243
|
...usage(row.skillId),
|
|
5055
5244
|
attachedAllTime: row.allTime,
|
|
@@ -5076,13 +5265,13 @@ function processUsage(db, skillId) {
|
|
|
5076
5265
|
attachedAt: processInstances.createdAt,
|
|
5077
5266
|
invocationCount: count4(skillInvocations.skillId),
|
|
5078
5267
|
lastInvokedAt: max2(skillInvocations.invokedAt)
|
|
5079
|
-
}).from(processSkills).innerJoin(processInstances,
|
|
5268
|
+
}).from(processSkills).innerJoin(processInstances, eq25(processSkills.instanceId, processInstances.id)).leftJoin(
|
|
5080
5269
|
skillInvocations,
|
|
5081
5270
|
and18(
|
|
5082
|
-
|
|
5083
|
-
|
|
5271
|
+
eq25(skillInvocations.instanceId, processSkills.instanceId),
|
|
5272
|
+
eq25(skillInvocations.skillId, processSkills.skillId)
|
|
5084
5273
|
)
|
|
5085
|
-
).where(
|
|
5274
|
+
).where(eq25(processSkills.skillId, skillId)).groupBy(
|
|
5086
5275
|
processSkills.instanceId,
|
|
5087
5276
|
processInstances.title,
|
|
5088
5277
|
processInstances.externalId,
|
|
@@ -5099,12 +5288,12 @@ function skillMarkdown(skillId, bytes, digest) {
|
|
|
5099
5288
|
function pruneNeverInstalledCatalogEntries(db) {
|
|
5100
5289
|
db.delete(skillCatalogEntries).where(
|
|
5101
5290
|
and18(
|
|
5102
|
-
|
|
5291
|
+
eq25(skillCatalogEntries.available, false),
|
|
5103
5292
|
notExists2(
|
|
5104
5293
|
db.select({ id: skillRevisions.id }).from(skillRevisions).where(
|
|
5105
5294
|
and18(
|
|
5106
|
-
|
|
5107
|
-
|
|
5295
|
+
eq25(skillRevisions.skillId, skillCatalogEntries.skillId),
|
|
5296
|
+
eq25(skillRevisions.bundleDigest, skillCatalogEntries.bundleDigest)
|
|
5108
5297
|
)
|
|
5109
5298
|
)
|
|
5110
5299
|
)
|
|
@@ -5112,7 +5301,7 @@ function pruneNeverInstalledCatalogEntries(db) {
|
|
|
5112
5301
|
).run();
|
|
5113
5302
|
}
|
|
5114
5303
|
function recordRevisionDependencies(db, revisionId, markdown) {
|
|
5115
|
-
db.delete(skillRevisionDependencies).where(
|
|
5304
|
+
db.delete(skillRevisionDependencies).where(eq25(skillRevisionDependencies.skillRevisionId, revisionId)).run();
|
|
5116
5305
|
for (const [position, dependencySkillId] of explicitSkillReferenceIds(markdown).entries()) {
|
|
5117
5306
|
db.insert(skillRevisionDependencies).values({ skillRevisionId: revisionId, dependencySkillId, position }).run();
|
|
5118
5307
|
}
|
|
@@ -5135,7 +5324,7 @@ function activateSkill(db, item, registrationKind, timestamp, markdown = skillMa
|
|
|
5135
5324
|
activeRevisionId: revisionId,
|
|
5136
5325
|
registrationKind,
|
|
5137
5326
|
updatedAt: timestamp
|
|
5138
|
-
}).where(
|
|
5327
|
+
}).where(eq25(skills.id, item.skillId)).run();
|
|
5139
5328
|
return revisionId;
|
|
5140
5329
|
}
|
|
5141
5330
|
function catalogView(db) {
|
|
@@ -5150,7 +5339,7 @@ function catalogView(db) {
|
|
|
5150
5339
|
activeDigest: skillRevisions.bundleDigest,
|
|
5151
5340
|
activeBundleBytes: skillRevisions.bundleBytes,
|
|
5152
5341
|
registrationKind: skills.registrationKind
|
|
5153
|
-
}).from(skills).innerJoin(skillRevisions,
|
|
5342
|
+
}).from(skills).innerJoin(skillRevisions, eq25(skills.activeRevisionId, skillRevisions.id)).orderBy(asc15(skills.label), asc15(skills.id)).all();
|
|
5154
5343
|
const installedById = new Map(installedRows.map((row) => [row.id, row]));
|
|
5155
5344
|
const availableSkills = candidates.map((candidate2) => {
|
|
5156
5345
|
const active = installedById.get(candidate2.skillId);
|
|
@@ -5201,11 +5390,13 @@ function catalogView(db) {
|
|
|
5201
5390
|
}
|
|
5202
5391
|
function createSkillRepo(db) {
|
|
5203
5392
|
return {
|
|
5393
|
+
/** @internal */
|
|
5204
5394
|
listAvailable() {
|
|
5205
5395
|
return db.select({ id: skills.id, label: skills.label, description: skills.description }).from(skills).where(isNotNull2(skills.activeRevisionId)).orderBy(asc15(skills.label), asc15(skills.id)).all();
|
|
5206
5396
|
},
|
|
5397
|
+
/** @internal */
|
|
5207
5398
|
resolveActive(ids) {
|
|
5208
|
-
const activeSkills = db.select({ id: skills.id, revisionId: skillRevisions.id }).from(skills).innerJoin(skillRevisions,
|
|
5399
|
+
const activeSkills = db.select({ id: skills.id, revisionId: skillRevisions.id }).from(skills).innerJoin(skillRevisions, eq25(skills.activeRevisionId, skillRevisions.id)).all();
|
|
5209
5400
|
const byId = new Map(activeSkills.map((skill) => [skill.id, skill]));
|
|
5210
5401
|
const dependencies = /* @__PURE__ */ new Map();
|
|
5211
5402
|
for (const dependency of db.select().from(skillRevisionDependencies).all()) {
|
|
@@ -5229,11 +5420,12 @@ function createSkillRepo(db) {
|
|
|
5229
5420
|
for (const id of ids) add(id);
|
|
5230
5421
|
return [...resolved2.values()];
|
|
5231
5422
|
},
|
|
5423
|
+
/** @internal */
|
|
5232
5424
|
reconcile(imported) {
|
|
5233
5425
|
const timestamp = now();
|
|
5234
5426
|
db.update(skills).set({ activeRevisionId: null, updatedAt: timestamp }).where(
|
|
5235
5427
|
and18(
|
|
5236
|
-
|
|
5428
|
+
eq25(skills.registrationKind, "configuration"),
|
|
5237
5429
|
notInArray2(
|
|
5238
5430
|
skills.id,
|
|
5239
5431
|
imported.map((item) => item.skillId)
|
|
@@ -5242,6 +5434,7 @@ function createSkillRepo(db) {
|
|
|
5242
5434
|
).run();
|
|
5243
5435
|
for (const item of imported) activateSkill(db, item, "configuration", timestamp);
|
|
5244
5436
|
},
|
|
5437
|
+
/** @internal */
|
|
5245
5438
|
backfillDependencies() {
|
|
5246
5439
|
for (const revision of db.select().from(skillRevisions).all()) {
|
|
5247
5440
|
recordRevisionDependencies(
|
|
@@ -5251,13 +5444,15 @@ function createSkillRepo(db) {
|
|
|
5251
5444
|
);
|
|
5252
5445
|
}
|
|
5253
5446
|
},
|
|
5447
|
+
/** @internal */
|
|
5254
5448
|
markUnconfiguredCatalogEntries(configuredRepositoryIds) {
|
|
5255
5449
|
db.update(skillCatalogEntries).set({ available: false }).where(notInArray2(skillCatalogEntries.repositoryId, [...configuredRepositoryIds])).run();
|
|
5256
5450
|
pruneNeverInstalledCatalogEntries(db);
|
|
5257
5451
|
},
|
|
5452
|
+
/** @internal */
|
|
5258
5453
|
mergeCatalog(repositoryId, imported) {
|
|
5259
5454
|
const timestamp = now();
|
|
5260
|
-
db.update(skillCatalogEntries).set({ available: false }).where(
|
|
5455
|
+
db.update(skillCatalogEntries).set({ available: false }).where(eq25(skillCatalogEntries.repositoryId, repositoryId)).run();
|
|
5261
5456
|
for (const item of imported) {
|
|
5262
5457
|
const values = {
|
|
5263
5458
|
label: item.label,
|
|
@@ -5276,8 +5471,9 @@ function createSkillRepo(db) {
|
|
|
5276
5471
|
}
|
|
5277
5472
|
pruneNeverInstalledCatalogEntries(db);
|
|
5278
5473
|
},
|
|
5474
|
+
/** @internal */
|
|
5279
5475
|
registerCatalogEntry(repositoryId, skillId) {
|
|
5280
|
-
const candidates = db.select().from(skillCatalogEntries).where(
|
|
5476
|
+
const candidates = db.select().from(skillCatalogEntries).where(eq25(skillCatalogEntries.available, true)).all();
|
|
5281
5477
|
const availableIds = new Set(candidates.map((candidate2) => candidate2.skillId));
|
|
5282
5478
|
const installedIds = new Set(
|
|
5283
5479
|
db.select({ id: skills.id }).from(skills).where(isNotNull2(skills.activeRevisionId)).all().map((skill) => skill.id)
|
|
@@ -5297,7 +5493,7 @@ function createSkillRepo(db) {
|
|
|
5297
5493
|
`Remote skill '${requestedRepositoryId ? `${requestedRepositoryId}/` : ""}${id}' is no longer available`
|
|
5298
5494
|
);
|
|
5299
5495
|
}
|
|
5300
|
-
const current = db.select().from(skills).where(
|
|
5496
|
+
const current = db.select().from(skills).where(eq25(skills.id, id)).get();
|
|
5301
5497
|
if (current?.activeRevisionId && current.registrationKind === "configuration") {
|
|
5302
5498
|
throw new Error(`Skill '${id}' is managed by configuration`);
|
|
5303
5499
|
}
|
|
@@ -5328,15 +5524,18 @@ function createSkillRepo(db) {
|
|
|
5328
5524
|
throw new Error(`Remote skill '${repositoryId}/${skillId}' was not installed`);
|
|
5329
5525
|
return revisionId;
|
|
5330
5526
|
},
|
|
5527
|
+
/** @internal */
|
|
5331
5528
|
remove(skillId) {
|
|
5332
|
-
const current = db.select().from(skills).where(
|
|
5529
|
+
const current = db.select().from(skills).where(eq25(skills.id, skillId)).get();
|
|
5333
5530
|
if (!current?.activeRevisionId || current.registrationKind !== "catalog") return false;
|
|
5334
|
-
db.update(skills).set({ activeRevisionId: null, updatedAt: now() }).where(
|
|
5531
|
+
db.update(skills).set({ activeRevisionId: null, updatedAt: now() }).where(eq25(skills.id, skillId)).run();
|
|
5335
5532
|
return true;
|
|
5336
5533
|
},
|
|
5534
|
+
/** @internal */
|
|
5337
5535
|
catalog() {
|
|
5338
5536
|
return catalogView(db);
|
|
5339
5537
|
},
|
|
5538
|
+
/** @internal */
|
|
5340
5539
|
getCatalogDetail(repositoryId, skillId) {
|
|
5341
5540
|
const item = catalogView(db).availableSkills.find(
|
|
5342
5541
|
(candidate3) => candidate3.repositoryId === repositoryId && candidate3.id === skillId
|
|
@@ -5347,8 +5546,8 @@ function createSkillRepo(db) {
|
|
|
5347
5546
|
digest: skillCatalogEntries.bundleDigest
|
|
5348
5547
|
}).from(skillCatalogEntries).where(
|
|
5349
5548
|
and18(
|
|
5350
|
-
|
|
5351
|
-
|
|
5549
|
+
eq25(skillCatalogEntries.repositoryId, repositoryId),
|
|
5550
|
+
eq25(skillCatalogEntries.skillId, skillId)
|
|
5352
5551
|
)
|
|
5353
5552
|
).get();
|
|
5354
5553
|
if (!candidate2) return null;
|
|
@@ -5358,16 +5557,17 @@ function createSkillRepo(db) {
|
|
|
5358
5557
|
processes: processUsage(db, skillId)
|
|
5359
5558
|
};
|
|
5360
5559
|
},
|
|
5560
|
+
/** @internal */
|
|
5361
5561
|
getInstalledDetail(skillId) {
|
|
5362
5562
|
const item = catalogView(db).installedSkills.find((candidate2) => candidate2.id === skillId);
|
|
5363
5563
|
if (!item) return null;
|
|
5364
|
-
const revision = db.select({ bytes: skillRevisions.bundleBytes, digest: skillRevisions.bundleDigest }).from(skillRevisions).where(
|
|
5564
|
+
const revision = db.select({ bytes: skillRevisions.bundleBytes, digest: skillRevisions.bundleDigest }).from(skillRevisions).where(eq25(skillRevisions.id, item.activeRevisionId)).get();
|
|
5365
5565
|
if (!revision) return null;
|
|
5366
5566
|
const revisions = db.select({
|
|
5367
5567
|
id: skillRevisions.id,
|
|
5368
5568
|
sourceRevision: skillRevisions.sourceRevision,
|
|
5369
5569
|
importedAt: skillRevisions.importedAt
|
|
5370
|
-
}).from(skillRevisions).where(
|
|
5570
|
+
}).from(skillRevisions).where(eq25(skillRevisions.skillId, skillId)).all().map((candidate2) => ({
|
|
5371
5571
|
...candidate2,
|
|
5372
5572
|
active: candidate2.id === item.activeRevisionId
|
|
5373
5573
|
})).sort((left, right) => right.importedAt.localeCompare(left.importedAt));
|
|
@@ -5378,8 +5578,9 @@ function createSkillRepo(db) {
|
|
|
5378
5578
|
revisions
|
|
5379
5579
|
};
|
|
5380
5580
|
},
|
|
5581
|
+
/** @internal */
|
|
5381
5582
|
recordInvocations(input) {
|
|
5382
|
-
const selections = db.select().from(processSkills).where(
|
|
5583
|
+
const selections = db.select().from(processSkills).where(eq25(processSkills.instanceId, input.instanceId)).all();
|
|
5383
5584
|
const uniqueInvocations = new Map(
|
|
5384
5585
|
input.invocations.map((invocation) => [invocation.skillId, invocation])
|
|
5385
5586
|
);
|
|
@@ -5399,28 +5600,30 @@ function createSkillRepo(db) {
|
|
|
5399
5600
|
}
|
|
5400
5601
|
|
|
5401
5602
|
// src/db/ticket-destination-recent-repo.ts
|
|
5402
|
-
import { and as and19, desc as desc10, eq as
|
|
5603
|
+
import { and as and19, desc as desc10, eq as eq26 } from "drizzle-orm";
|
|
5403
5604
|
function map4(row) {
|
|
5404
5605
|
return { ...row };
|
|
5405
5606
|
}
|
|
5406
5607
|
function createTicketDestinationRecentRepo(db) {
|
|
5407
5608
|
return {
|
|
5609
|
+
/** @internal */
|
|
5408
5610
|
list(actorKey, toolName, limit = 5) {
|
|
5409
5611
|
return db.select().from(ticketDestinationRecents).where(
|
|
5410
5612
|
and19(
|
|
5411
|
-
|
|
5412
|
-
|
|
5613
|
+
eq26(ticketDestinationRecents.actorKey, actorKey),
|
|
5614
|
+
eq26(ticketDestinationRecents.toolName, toolName)
|
|
5413
5615
|
)
|
|
5414
5616
|
).orderBy(
|
|
5415
5617
|
desc10(ticketDestinationRecents.updatedAt),
|
|
5416
5618
|
desc10(ticketDestinationRecents.createdAt)
|
|
5417
5619
|
).limit(limit).all().map(map4);
|
|
5418
5620
|
},
|
|
5621
|
+
/** @internal */
|
|
5419
5622
|
record(input) {
|
|
5420
5623
|
const match = and19(
|
|
5421
|
-
|
|
5422
|
-
|
|
5423
|
-
|
|
5624
|
+
eq26(ticketDestinationRecents.actorKey, input.actorKey),
|
|
5625
|
+
eq26(ticketDestinationRecents.toolName, input.toolName),
|
|
5626
|
+
eq26(ticketDestinationRecents.destinationId, input.destinationId)
|
|
5424
5627
|
);
|
|
5425
5628
|
const existing = db.select().from(ticketDestinationRecents).where(match).get();
|
|
5426
5629
|
const updatedAt = now();
|
|
@@ -5442,15 +5645,15 @@ function createTicketDestinationRecentRepo(db) {
|
|
|
5442
5645
|
}
|
|
5443
5646
|
const stale = db.select({ id: ticketDestinationRecents.id }).from(ticketDestinationRecents).where(
|
|
5444
5647
|
and19(
|
|
5445
|
-
|
|
5446
|
-
|
|
5648
|
+
eq26(ticketDestinationRecents.actorKey, input.actorKey),
|
|
5649
|
+
eq26(ticketDestinationRecents.toolName, input.toolName)
|
|
5447
5650
|
)
|
|
5448
5651
|
).orderBy(
|
|
5449
5652
|
desc10(ticketDestinationRecents.updatedAt),
|
|
5450
5653
|
desc10(ticketDestinationRecents.createdAt)
|
|
5451
5654
|
).all().slice(input.limit ?? 5);
|
|
5452
5655
|
for (const entry of stale) {
|
|
5453
|
-
db.delete(ticketDestinationRecents).where(
|
|
5656
|
+
db.delete(ticketDestinationRecents).where(eq26(ticketDestinationRecents.id, entry.id)).run();
|
|
5454
5657
|
}
|
|
5455
5658
|
return result;
|
|
5456
5659
|
}
|
|
@@ -5458,7 +5661,7 @@ function createTicketDestinationRecentRepo(db) {
|
|
|
5458
5661
|
}
|
|
5459
5662
|
|
|
5460
5663
|
// src/db/turn-start-record-repo.ts
|
|
5461
|
-
import { and as and20, eq as
|
|
5664
|
+
import { and as and20, eq as eq27 } from "drizzle-orm";
|
|
5462
5665
|
function map5(row) {
|
|
5463
5666
|
return {
|
|
5464
5667
|
id: row.id,
|
|
@@ -5476,6 +5679,7 @@ function map5(row) {
|
|
|
5476
5679
|
}
|
|
5477
5680
|
function createTurnStartRecordRepo(db) {
|
|
5478
5681
|
return {
|
|
5682
|
+
/** @internal */
|
|
5479
5683
|
create(input) {
|
|
5480
5684
|
const ts = now();
|
|
5481
5685
|
const id = input.id ?? generateId("tsr");
|
|
@@ -5495,20 +5699,23 @@ function createTurnStartRecordRepo(db) {
|
|
|
5495
5699
|
db.insert(turnStartRecords).values(value).run();
|
|
5496
5700
|
return map5(value);
|
|
5497
5701
|
},
|
|
5702
|
+
/** @internal */
|
|
5498
5703
|
getById(id) {
|
|
5499
|
-
const value = db.select().from(turnStartRecords).where(
|
|
5704
|
+
const value = db.select().from(turnStartRecords).where(eq27(turnStartRecords.id, id)).get();
|
|
5500
5705
|
return value ? map5(value) : null;
|
|
5501
5706
|
},
|
|
5707
|
+
/** @internal */
|
|
5502
5708
|
listByInstance(instanceId) {
|
|
5503
|
-
return db.select().from(turnStartRecords).where(
|
|
5709
|
+
return db.select().from(turnStartRecords).where(eq27(turnStartRecords.instanceId, instanceId)).all().map(map5);
|
|
5504
5710
|
},
|
|
5711
|
+
/** @internal */
|
|
5505
5712
|
compareAndSetState(input) {
|
|
5506
5713
|
const current = this.getById(input.id);
|
|
5507
5714
|
if (!current || current.state.kind !== input.expectedKind) return null;
|
|
5508
5715
|
const result = db.update(turnStartRecords).set({ stateJson: JSON.stringify(input.state), updatedAt: now() }).where(
|
|
5509
5716
|
and20(
|
|
5510
|
-
|
|
5511
|
-
|
|
5717
|
+
eq27(turnStartRecords.id, input.id),
|
|
5718
|
+
eq27(turnStartRecords.stateJson, JSON.stringify(current.state))
|
|
5512
5719
|
)
|
|
5513
5720
|
).run();
|
|
5514
5721
|
return result.changes === 1 ? this.getById(input.id) : null;
|
|
@@ -5517,7 +5724,7 @@ function createTurnStartRecordRepo(db) {
|
|
|
5517
5724
|
}
|
|
5518
5725
|
|
|
5519
5726
|
// src/db/worker-lease-repo.ts
|
|
5520
|
-
import { and as and21, asc as asc16, eq as
|
|
5727
|
+
import { and as and21, asc as asc16, eq as eq28, isNull as isNull4 } from "drizzle-orm";
|
|
5521
5728
|
function rowToWorkerLease(row) {
|
|
5522
5729
|
return {
|
|
5523
5730
|
id: row.id,
|
|
@@ -5540,6 +5747,7 @@ function rowToWorkerLease(row) {
|
|
|
5540
5747
|
}
|
|
5541
5748
|
function createWorkerLeaseRepo(db) {
|
|
5542
5749
|
return {
|
|
5750
|
+
/** @internal */
|
|
5543
5751
|
create(input) {
|
|
5544
5752
|
const id = generateId("wls");
|
|
5545
5753
|
const ts = now();
|
|
@@ -5564,20 +5772,25 @@ function createWorkerLeaseRepo(db) {
|
|
|
5564
5772
|
db.insert(workerLeases).values(values).run();
|
|
5565
5773
|
return rowToWorkerLease(values);
|
|
5566
5774
|
},
|
|
5775
|
+
/** @internal */
|
|
5567
5776
|
getByInstance(instanceId) {
|
|
5568
|
-
const row = db.select().from(workerLeases).where(and21(
|
|
5777
|
+
const row = db.select().from(workerLeases).where(and21(eq28(workerLeases.instanceId, instanceId), isNull4(workerLeases.exitedAt))).get();
|
|
5569
5778
|
return row ? rowToWorkerLease(row) : null;
|
|
5570
5779
|
},
|
|
5780
|
+
/** @internal */
|
|
5571
5781
|
getById(id) {
|
|
5572
|
-
const row = db.select().from(workerLeases).where(
|
|
5782
|
+
const row = db.select().from(workerLeases).where(eq28(workerLeases.id, id)).get();
|
|
5573
5783
|
return row ? rowToWorkerLease(row) : null;
|
|
5574
5784
|
},
|
|
5785
|
+
/** @internal */
|
|
5575
5786
|
listByInstance(instanceId) {
|
|
5576
|
-
return db.select().from(workerLeases).where(
|
|
5787
|
+
return db.select().from(workerLeases).where(eq28(workerLeases.instanceId, instanceId)).orderBy(asc16(workerLeases.startedAt), asc16(workerLeases.id)).all().map(rowToWorkerLease);
|
|
5577
5788
|
},
|
|
5789
|
+
/** @internal */
|
|
5578
5790
|
listActive() {
|
|
5579
5791
|
return db.select().from(workerLeases).where(isNull4(workerLeases.exitedAt)).all().map(rowToWorkerLease);
|
|
5580
5792
|
},
|
|
5793
|
+
/** @internal */
|
|
5581
5794
|
update(id, input) {
|
|
5582
5795
|
const setValues = {
|
|
5583
5796
|
state: input.state,
|
|
@@ -5591,53 +5804,34 @@ function createWorkerLeaseRepo(db) {
|
|
|
5591
5804
|
readyAt: input.readyAt,
|
|
5592
5805
|
exitedAt: input.exitedAt
|
|
5593
5806
|
};
|
|
5594
|
-
db.update(workerLeases).set(setValues).where(
|
|
5595
|
-
const row = db.select().from(workerLeases).where(
|
|
5807
|
+
db.update(workerLeases).set(setValues).where(eq28(workerLeases.id, id)).run();
|
|
5808
|
+
const row = db.select().from(workerLeases).where(eq28(workerLeases.id, id)).get();
|
|
5596
5809
|
return row ? rowToWorkerLease(row) : null;
|
|
5597
5810
|
},
|
|
5811
|
+
/** @internal */
|
|
5598
5812
|
observeTimestamp(id, field) {
|
|
5599
5813
|
const column = workerLeases[field];
|
|
5600
|
-
db.update(workerLeases).set({ [field]: now() }).where(and21(
|
|
5814
|
+
db.update(workerLeases).set({ [field]: now() }).where(and21(eq28(workerLeases.id, id), isNull4(column))).run();
|
|
5601
5815
|
return this.getById(id);
|
|
5602
5816
|
},
|
|
5817
|
+
/** @internal */
|
|
5603
5818
|
updateHeartbeat(workerId) {
|
|
5604
|
-
const result = db.update(workerLeases).set({ lastHeartbeatAt: now() }).where(
|
|
5819
|
+
const result = db.update(workerLeases).set({ lastHeartbeatAt: now() }).where(eq28(workerLeases.workerId, workerId)).run();
|
|
5605
5820
|
return result.changes > 0;
|
|
5606
5821
|
},
|
|
5607
|
-
/** Stores the first receipt only. Exact replay is accepted; changed receipts are rejected. */
|
|
5822
|
+
/** Stores the first receipt only. Exact replay is accepted; changed receipts are rejected. @internal */
|
|
5608
5823
|
compareAndSetBootstrapReceipt(id, receipt) {
|
|
5609
|
-
const existing = db.select().from(workerLeases).where(
|
|
5824
|
+
const existing = db.select().from(workerLeases).where(eq28(workerLeases.id, id)).get();
|
|
5610
5825
|
if (!existing) return "missing";
|
|
5611
5826
|
const encoded = JSON.stringify(receipt);
|
|
5612
5827
|
if (existing.bootstrapReceiptJson !== null)
|
|
5613
5828
|
return existing.bootstrapReceiptJson === encoded ? "replay" : "changed";
|
|
5614
|
-
const result = db.update(workerLeases).set({ bootstrapReceiptJson: encoded }).where(and21(
|
|
5829
|
+
const result = db.update(workerLeases).set({ bootstrapReceiptJson: encoded }).where(and21(eq28(workerLeases.id, id), isNull4(workerLeases.bootstrapReceiptJson))).run();
|
|
5615
5830
|
return result.changes === 1 ? "stored" : "changed";
|
|
5616
5831
|
}
|
|
5617
5832
|
};
|
|
5618
5833
|
}
|
|
5619
5834
|
|
|
5620
|
-
// src/db/startup-observation-repo.ts
|
|
5621
|
-
import { eq as eq28 } from "drizzle-orm";
|
|
5622
|
-
function createStartupObservationRepo(db) {
|
|
5623
|
-
return {
|
|
5624
|
-
record(observation) {
|
|
5625
|
-
if (!Number.isFinite(Date.parse(observation.observedAt)) || observation.sourceAt !== null && !Number.isFinite(Date.parse(observation.sourceAt)))
|
|
5626
|
-
return false;
|
|
5627
|
-
const lease = db.select().from(workerLeases).where(eq28(workerLeases.id, observation.workerLeaseId)).get();
|
|
5628
|
-
if (!lease) return false;
|
|
5629
|
-
return db.insert(startupObservations).values({
|
|
5630
|
-
workerLeaseId: observation.workerLeaseId,
|
|
5631
|
-
milestone: observation.milestone,
|
|
5632
|
-
observationJson: JSON.stringify(observation)
|
|
5633
|
-
}).onConflictDoNothing().run().changes > 0;
|
|
5634
|
-
},
|
|
5635
|
-
listByLease(workerLeaseId) {
|
|
5636
|
-
return db.select().from(startupObservations).where(eq28(startupObservations.workerLeaseId, workerLeaseId)).all().map((row) => JSON.parse(row.observationJson));
|
|
5637
|
-
}
|
|
5638
|
-
};
|
|
5639
|
-
}
|
|
5640
|
-
|
|
5641
5835
|
// src/db/repositories.ts
|
|
5642
5836
|
function createAllRepos(db, options = {}) {
|
|
5643
5837
|
const credentialCipher = options.credentialCipher ?? createUnavailableCredentialCipher();
|
|
@@ -5689,10 +5883,8 @@ import {
|
|
|
5689
5883
|
getProcessGraph
|
|
5690
5884
|
} from "@leitwerk-dev/process-sdk";
|
|
5691
5885
|
import {
|
|
5692
|
-
getAllProcessGraphs,
|
|
5693
5886
|
getProcessGraph as getProcessGraph2,
|
|
5694
5887
|
getProcessTurnGraph,
|
|
5695
|
-
getReachableTurnIdsForProcessGraph,
|
|
5696
5888
|
getTurnTransitionsForProcessGraph,
|
|
5697
5889
|
hasProcessGraph,
|
|
5698
5890
|
isTurnAvailableForProcessGraph,
|
|
@@ -6547,280 +6739,6 @@ function createServerProcessModelPolicy(input) {
|
|
|
6547
6739
|
});
|
|
6548
6740
|
}
|
|
6549
6741
|
|
|
6550
|
-
// src/process-action-registry.ts
|
|
6551
|
-
import {
|
|
6552
|
-
createServerProcessBuilder,
|
|
6553
|
-
getExternalActionArmingId,
|
|
6554
|
-
getExternalSourceTransitionId,
|
|
6555
|
-
isAutomaticTurnDefinition,
|
|
6556
|
-
isExternalTurnDefinition,
|
|
6557
|
-
isHumanTurnDefinition,
|
|
6558
|
-
resolveHumanTurnView,
|
|
6559
|
-
toProcessGraphView as toProcessGraphView2
|
|
6560
|
-
} from "@leitwerk-dev/process-sdk";
|
|
6561
|
-
function resolveTurnIntegrationToolNames(registry, process2, turnId) {
|
|
6562
|
-
const turn = registry.getTurnDefinition(process2.processId, turnId);
|
|
6563
|
-
if (turn?.kind !== "llm" && turn?.kind !== "automatic") return [];
|
|
6564
|
-
const dynamic = turn.kind === "llm" && turn.resolveIntegrationTools ? (() => {
|
|
6565
|
-
const context = registry.resolveContextData(process2.processId, process2);
|
|
6566
|
-
return turn.resolveIntegrationTools?.(context.params, context.state) ?? [];
|
|
6567
|
-
})() : [];
|
|
6568
|
-
return [.../* @__PURE__ */ new Set([...turn.integrationTools ?? [], ...dynamic])];
|
|
6569
|
-
}
|
|
6570
|
-
function resolveProcessContextData(processDef, process2) {
|
|
6571
|
-
if (!processDef) {
|
|
6572
|
-
return { params: {}, state: {} };
|
|
6573
|
-
}
|
|
6574
|
-
const params = process2.paramsJson ? processDef.paramsCodec.parse(JSON.parse(process2.paramsJson)) : processDef.paramsCodec.parse(void 0);
|
|
6575
|
-
const state = process2.stateJson ? processDef.stateCodec.parse(JSON.parse(process2.stateJson)) : processDef.initialState(params);
|
|
6576
|
-
return { params, state };
|
|
6577
|
-
}
|
|
6578
|
-
function resolveCurrentTurnForProcess(processDef, process2) {
|
|
6579
|
-
if (!processDef || !process2.selectedTurnId) {
|
|
6580
|
-
return null;
|
|
6581
|
-
}
|
|
6582
|
-
const selectedTurn = processDef.turns.get(process2.selectedTurnId)?.definition;
|
|
6583
|
-
if (!selectedTurn) {
|
|
6584
|
-
return null;
|
|
6585
|
-
}
|
|
6586
|
-
return { turnId: process2.selectedTurnId, turnDef: selectedTurn };
|
|
6587
|
-
}
|
|
6588
|
-
function listExternalTriggers(turnId, turnDef, ctx) {
|
|
6589
|
-
if (isHumanTurnDefinition(turnDef)) {
|
|
6590
|
-
const view = resolveHumanTurnView({ turnId, turn: turnDef });
|
|
6591
|
-
return [
|
|
6592
|
-
...view.externalTriggers.map((trigger) => ({
|
|
6593
|
-
id: trigger.id,
|
|
6594
|
-
kind: "human_action_external_trigger",
|
|
6595
|
-
label: trigger.label,
|
|
6596
|
-
description: trigger.description
|
|
6597
|
-
})),
|
|
6598
|
-
...view.externalActions.filter((action) => {
|
|
6599
|
-
const definition = turnDef.externalActions?.[action.externalActionId];
|
|
6600
|
-
return !definition?.when || definition.when(ctx);
|
|
6601
|
-
}).map((action) => ({
|
|
6602
|
-
id: action.id,
|
|
6603
|
-
externalActionId: action.externalActionId,
|
|
6604
|
-
kind: action.sourceKind,
|
|
6605
|
-
sourceKind: action.sourceKind,
|
|
6606
|
-
label: action.label,
|
|
6607
|
-
description: action.description
|
|
6608
|
-
}))
|
|
6609
|
-
];
|
|
6610
|
-
}
|
|
6611
|
-
if (isExternalTurnDefinition(turnDef)) {
|
|
6612
|
-
return turnDef.transitions.map((transition, index2) => ({
|
|
6613
|
-
id: getExternalSourceTransitionId({ turnId, source: transition.source, index: index2 }),
|
|
6614
|
-
kind: transition.source.kind,
|
|
6615
|
-
label: transition.source.label ?? null,
|
|
6616
|
-
description: transition.source.description ?? null
|
|
6617
|
-
}));
|
|
6618
|
-
}
|
|
6619
|
-
if (isAutomaticTurnDefinition(turnDef) && ctx.process.lifecycleStatus === "waiting") {
|
|
6620
|
-
return Object.entries(turnDef.externalActions ?? {}).filter(([, action]) => !action.when || action.when(ctx)).map(([externalActionId, action]) => ({
|
|
6621
|
-
id: getExternalActionArmingId({ turnId, externalActionId }),
|
|
6622
|
-
externalActionId,
|
|
6623
|
-
kind: action.source.kind,
|
|
6624
|
-
sourceKind: action.source.kind,
|
|
6625
|
-
label: action.label ?? action.source.label ?? null,
|
|
6626
|
-
description: action.description ?? action.source.description ?? null
|
|
6627
|
-
}));
|
|
6628
|
-
}
|
|
6629
|
-
return [];
|
|
6630
|
-
}
|
|
6631
|
-
function resolveCurrentVisibleActionForProcess(processDef, process2, actionId) {
|
|
6632
|
-
const currentTurn = resolveCurrentTurnForProcess(processDef, process2);
|
|
6633
|
-
if (!currentTurn || !isHumanTurnDefinition(currentTurn.turnDef)) {
|
|
6634
|
-
return null;
|
|
6635
|
-
}
|
|
6636
|
-
const view = resolveHumanTurnView({ turnId: currentTurn.turnId, turn: currentTurn.turnDef });
|
|
6637
|
-
return view.actions.find((candidate2) => candidate2.actionId === actionId) ?? null;
|
|
6638
|
-
}
|
|
6639
|
-
function isTurnScopedActionForProcess(processDef, actionId) {
|
|
6640
|
-
if (!processDef) {
|
|
6641
|
-
return false;
|
|
6642
|
-
}
|
|
6643
|
-
for (const [turnId, { definition: turnDef }] of processDef.turns) {
|
|
6644
|
-
if (isHumanTurnDefinition(turnDef)) {
|
|
6645
|
-
const view = resolveHumanTurnView({ turnId, turn: turnDef });
|
|
6646
|
-
if (view.actions.some((action) => action.actionId === actionId) || view.externalTriggers.some((trigger) => trigger.actionId === actionId)) {
|
|
6647
|
-
return true;
|
|
6648
|
-
}
|
|
6649
|
-
}
|
|
6650
|
-
}
|
|
6651
|
-
return false;
|
|
6652
|
-
}
|
|
6653
|
-
function buildSelectedTurnSummaryForProcess(processDef, process2, projects = []) {
|
|
6654
|
-
const currentTurn = resolveCurrentTurnForProcess(processDef, process2);
|
|
6655
|
-
if (!currentTurn) {
|
|
6656
|
-
return null;
|
|
6657
|
-
}
|
|
6658
|
-
const { params, state } = resolveProcessContextData(processDef, process2);
|
|
6659
|
-
return {
|
|
6660
|
-
turnId: currentTurn.turnId,
|
|
6661
|
-
kind: currentTurn.turnDef.kind,
|
|
6662
|
-
description: currentTurn.turnDef.description,
|
|
6663
|
-
commentary: isHumanTurnDefinition(currentTurn.turnDef) ? currentTurn.turnDef.commentary ?? null : null,
|
|
6664
|
-
externalTriggers: listExternalTriggers(currentTurn.turnId, currentTurn.turnDef, {
|
|
6665
|
-
process: process2,
|
|
6666
|
-
projects,
|
|
6667
|
-
params,
|
|
6668
|
-
state
|
|
6669
|
-
})
|
|
6670
|
-
};
|
|
6671
|
-
}
|
|
6672
|
-
function resolveActionTarget(definition, processDef, process2) {
|
|
6673
|
-
if (!definition) return null;
|
|
6674
|
-
const metadata = definition;
|
|
6675
|
-
const preview = "preview" in metadata ? metadata.preview : metadata;
|
|
6676
|
-
if (preview.kind === "fixed_turn") {
|
|
6677
|
-
return { definition, candidateSelectedTurnId: preview.turnId, lifecycleStatus: null };
|
|
6678
|
-
}
|
|
6679
|
-
if (preview.kind === "terminal") {
|
|
6680
|
-
return { definition, candidateSelectedTurnId: null, lifecycleStatus: preview.lifecycleStatus };
|
|
6681
|
-
}
|
|
6682
|
-
if (!processDef || !process2.selectedTurnId) return null;
|
|
6683
|
-
const transitions = toProcessGraphView2(processDef).turns.get(process2.selectedTurnId)?.transitions ?? [];
|
|
6684
|
-
const matchingTransitions = transitions.filter(
|
|
6685
|
-
(transition2) => transition2.trigger === preview.trigger
|
|
6686
|
-
);
|
|
6687
|
-
if (matchingTransitions.length !== 1) return null;
|
|
6688
|
-
const [transition] = matchingTransitions;
|
|
6689
|
-
return {
|
|
6690
|
-
definition,
|
|
6691
|
-
candidateSelectedTurnId: transition.nextTurnId ?? null,
|
|
6692
|
-
lifecycleStatus: transition.lifecycleStatus ?? null
|
|
6693
|
-
};
|
|
6694
|
-
}
|
|
6695
|
-
function resolveActionPreviewForProcess(processDef, process2, action, actionId) {
|
|
6696
|
-
const visibleAction = resolveCurrentVisibleActionForProcess(processDef, process2, actionId);
|
|
6697
|
-
const definition = visibleAction?.preview ?? visibleAction?.scheduling?.preview ?? action?.preview ?? action?.scheduling?.preview ?? null;
|
|
6698
|
-
return resolveActionTarget(definition, processDef, process2);
|
|
6699
|
-
}
|
|
6700
|
-
function resolveTurnScopedActionForProcess(processDef, process2, actionId, source) {
|
|
6701
|
-
const currentTurn = resolveCurrentTurnForProcess(processDef, process2);
|
|
6702
|
-
if (!currentTurn || !isHumanTurnDefinition(currentTurn.turnDef)) return null;
|
|
6703
|
-
const view = resolveHumanTurnView({ turnId: currentTurn.turnId, turn: currentTurn.turnDef });
|
|
6704
|
-
const action = view.actions.find((candidate2) => candidate2.actionId === actionId);
|
|
6705
|
-
if (!action) return null;
|
|
6706
|
-
const common = {
|
|
6707
|
-
turnId: currentTurn.turnId,
|
|
6708
|
-
semanticEntryRefKey: currentTurn.turnDef.reviewSemanticRef ?? null,
|
|
6709
|
-
acceptanceState: action.acceptanceState
|
|
6710
|
-
};
|
|
6711
|
-
if (source !== "external") {
|
|
6712
|
-
return { ...common, kind: "ui_human_action", turnType: "human" };
|
|
6713
|
-
}
|
|
6714
|
-
const externalTrigger = view.externalTriggers.find((trigger) => trigger.actionId === actionId);
|
|
6715
|
-
if (!externalTrigger) return null;
|
|
6716
|
-
return {
|
|
6717
|
-
...common,
|
|
6718
|
-
kind: "external_human_trigger",
|
|
6719
|
-
turnType: "external",
|
|
6720
|
-
externalTrigger: {
|
|
6721
|
-
id: externalTrigger.id,
|
|
6722
|
-
actionId: externalTrigger.actionId,
|
|
6723
|
-
label: externalTrigger.label,
|
|
6724
|
-
description: externalTrigger.description
|
|
6725
|
-
}
|
|
6726
|
-
};
|
|
6727
|
-
}
|
|
6728
|
-
function buildProcessActionRegistry(catalog) {
|
|
6729
|
-
const serverDefs = /* @__PURE__ */ new Map();
|
|
6730
|
-
const processDefs = /* @__PURE__ */ new Map();
|
|
6731
|
-
for (const [processId, processDef] of catalog.processes) {
|
|
6732
|
-
processDefs.set(processId, processDef);
|
|
6733
|
-
if (!processDef.server) {
|
|
6734
|
-
continue;
|
|
6735
|
-
}
|
|
6736
|
-
const builder = createServerProcessBuilder();
|
|
6737
|
-
processDef.server(builder);
|
|
6738
|
-
serverDefs.set(processId, builder.getDefinition());
|
|
6739
|
-
}
|
|
6740
|
-
return {
|
|
6741
|
-
getAction(processId, actionId) {
|
|
6742
|
-
const def = serverDefs.get(processId);
|
|
6743
|
-
if (!def) return void 0;
|
|
6744
|
-
return def.actions.get(actionId);
|
|
6745
|
-
},
|
|
6746
|
-
isTurnScopedAction(processId, actionId) {
|
|
6747
|
-
return isTurnScopedActionForProcess(processDefs.get(processId), actionId);
|
|
6748
|
-
},
|
|
6749
|
-
listVisibleActions(processId, ctx) {
|
|
6750
|
-
const def = serverDefs.get(processId);
|
|
6751
|
-
const processDef = processDefs.get(processId);
|
|
6752
|
-
const currentTurn = resolveCurrentTurnForProcess(processDef, ctx.process);
|
|
6753
|
-
if (!def || !currentTurn || !isHumanTurnDefinition(currentTurn.turnDef)) {
|
|
6754
|
-
return [];
|
|
6755
|
-
}
|
|
6756
|
-
const view = resolveHumanTurnView({
|
|
6757
|
-
turnId: currentTurn.turnId,
|
|
6758
|
-
turn: currentTurn.turnDef
|
|
6759
|
-
});
|
|
6760
|
-
const visible = [];
|
|
6761
|
-
for (const turnAction of view.actions) {
|
|
6762
|
-
const action = def.actions.get(turnAction.actionId);
|
|
6763
|
-
if (!action) {
|
|
6764
|
-
continue;
|
|
6765
|
-
}
|
|
6766
|
-
visible.push({
|
|
6767
|
-
id: action.id,
|
|
6768
|
-
label: turnAction.label ?? action.label,
|
|
6769
|
-
description: turnAction.description ?? null,
|
|
6770
|
-
form: action.form,
|
|
6771
|
-
preview: resolveActionPreviewForProcess(processDef, ctx.process, action, action.id)
|
|
6772
|
-
});
|
|
6773
|
-
}
|
|
6774
|
-
return visible;
|
|
6775
|
-
},
|
|
6776
|
-
getSelectedTurnSummary(processId, process2, projects) {
|
|
6777
|
-
return buildSelectedTurnSummaryForProcess(processDefs.get(processId), process2, projects);
|
|
6778
|
-
},
|
|
6779
|
-
getServerDefinition(processId) {
|
|
6780
|
-
return serverDefs.get(processId);
|
|
6781
|
-
},
|
|
6782
|
-
getTurnDefinition(processId, turnId) {
|
|
6783
|
-
return processDefs.get(processId)?.turns.get(turnId)?.definition;
|
|
6784
|
-
},
|
|
6785
|
-
getProcessGraph(processId) {
|
|
6786
|
-
return processDefs.get(processId);
|
|
6787
|
-
},
|
|
6788
|
-
getProcessDisplayName(processId) {
|
|
6789
|
-
return processDefs.get(processId)?.displayName;
|
|
6790
|
-
},
|
|
6791
|
-
resolveContextData(processId, process2) {
|
|
6792
|
-
return resolveProcessContextData(processDefs.get(processId), process2);
|
|
6793
|
-
},
|
|
6794
|
-
resolveTurnScopedAction(processId, process2, actionId, source) {
|
|
6795
|
-
return resolveTurnScopedActionForProcess(
|
|
6796
|
-
processDefs.get(processId),
|
|
6797
|
-
process2,
|
|
6798
|
-
actionId,
|
|
6799
|
-
source
|
|
6800
|
-
);
|
|
6801
|
-
},
|
|
6802
|
-
resolveActionPreview(processId, process2, actionId) {
|
|
6803
|
-
return resolveActionPreviewForProcess(
|
|
6804
|
-
processDefs.get(processId),
|
|
6805
|
-
process2,
|
|
6806
|
-
serverDefs.get(processId)?.actions.get(actionId),
|
|
6807
|
-
actionId
|
|
6808
|
-
);
|
|
6809
|
-
},
|
|
6810
|
-
resolveActionScheduling(processId, process2, actionId) {
|
|
6811
|
-
const action = serverDefs.get(processId)?.actions.get(actionId);
|
|
6812
|
-
if (action?.executionMode === "side_effect") return null;
|
|
6813
|
-
const processDef = processDefs.get(processId);
|
|
6814
|
-
const visibleAction = resolveCurrentVisibleActionForProcess(processDef, process2, actionId);
|
|
6815
|
-
return resolveActionTarget(
|
|
6816
|
-
visibleAction?.scheduling ?? action?.scheduling ?? null,
|
|
6817
|
-
processDef,
|
|
6818
|
-
process2
|
|
6819
|
-
);
|
|
6820
|
-
}
|
|
6821
|
-
};
|
|
6822
|
-
}
|
|
6823
|
-
|
|
6824
6742
|
// src/launch-pipeline.ts
|
|
6825
6743
|
import { SafeLaunchPreparationError } from "@leitwerk-dev/process-sdk";
|
|
6826
6744
|
var CORE_STEPS = [
|
|
@@ -6954,9 +6872,9 @@ function createLaunchPipeline(deps) {
|
|
|
6954
6872
|
broadcast(run);
|
|
6955
6873
|
return run;
|
|
6956
6874
|
}
|
|
6957
|
-
function fail(id, stepId,
|
|
6958
|
-
mutate(id, (run) => failLaunchRun(run, stepId,
|
|
6959
|
-
return { kind: "failed", failure };
|
|
6875
|
+
function fail(id, stepId, failure2) {
|
|
6876
|
+
mutate(id, (run) => failLaunchRun(run, stepId, failure2.safeSummary));
|
|
6877
|
+
return { kind: "failed", failure: failure2 };
|
|
6960
6878
|
}
|
|
6961
6879
|
return {
|
|
6962
6880
|
open(input) {
|
|
@@ -7004,49 +6922,487 @@ function createLaunchPipeline(deps) {
|
|
|
7004
6922
|
launchRunId,
|
|
7005
6923
|
(run) => transitionLaunchStep(run, "resolve_models_skills", "in_progress")
|
|
7006
6924
|
);
|
|
7007
|
-
const prepared = await adapter.prepare(resolution.value);
|
|
7008
|
-
if (!prepared.ok) return fail(launchRunId, "resolve_models_skills", prepared.failure);
|
|
7009
|
-
mutate(launchRunId, (run) => {
|
|
7010
|
-
let next = transitionLaunchStep(run, "resolve_models_skills", "completed");
|
|
7011
|
-
next = transitionLaunchStep(next, "create_process", "in_progress");
|
|
7012
|
-
return next;
|
|
7013
|
-
});
|
|
7014
|
-
const committed = await adapter.commit(prepared.value, { launchRunId });
|
|
7015
|
-
if (committed.kind === "failed")
|
|
7016
|
-
return fail(launchRunId, "create_process", committed.failure);
|
|
7017
|
-
mutate(
|
|
7018
|
-
launchRunId,
|
|
7019
|
-
(run) => completeCommittedLaunch(
|
|
7020
|
-
run,
|
|
7021
|
-
committed.process,
|
|
7022
|
-
committed.startTurnId,
|
|
7023
|
-
deps.titleGenerationAvailable,
|
|
7024
|
-
committed.kind === "committed_with_reaction_error" ? committed.safeSummary : void 0
|
|
7025
|
-
)
|
|
6925
|
+
const prepared = await adapter.prepare(resolution.value);
|
|
6926
|
+
if (!prepared.ok) return fail(launchRunId, "resolve_models_skills", prepared.failure);
|
|
6927
|
+
mutate(launchRunId, (run) => {
|
|
6928
|
+
let next = transitionLaunchStep(run, "resolve_models_skills", "completed");
|
|
6929
|
+
next = transitionLaunchStep(next, "create_process", "in_progress");
|
|
6930
|
+
return next;
|
|
6931
|
+
});
|
|
6932
|
+
const committed = await adapter.commit(prepared.value, { launchRunId });
|
|
6933
|
+
if (committed.kind === "failed")
|
|
6934
|
+
return fail(launchRunId, "create_process", committed.failure);
|
|
6935
|
+
mutate(
|
|
6936
|
+
launchRunId,
|
|
6937
|
+
(run) => completeCommittedLaunch(
|
|
6938
|
+
run,
|
|
6939
|
+
committed.process,
|
|
6940
|
+
committed.startTurnId,
|
|
6941
|
+
deps.titleGenerationAvailable,
|
|
6942
|
+
committed.kind === "committed_with_reaction_error" ? committed.safeSummary : void 0
|
|
6943
|
+
)
|
|
6944
|
+
);
|
|
6945
|
+
return {
|
|
6946
|
+
kind: committed.kind,
|
|
6947
|
+
result: committed.result,
|
|
6948
|
+
process: committed.process,
|
|
6949
|
+
reused: committed.kind === "committed" ? committed.reused : false
|
|
6950
|
+
};
|
|
6951
|
+
} catch (error) {
|
|
6952
|
+
const run = deps.launchRuns.getById(launchRunId);
|
|
6953
|
+
const failure2 = adapter.unexpectedFailure?.(error) ?? {
|
|
6954
|
+
safeSummary: "The launch could not be completed. Try again.",
|
|
6955
|
+
value: error
|
|
6956
|
+
};
|
|
6957
|
+
return fail(launchRunId, run ? activeStepId(run) : "validate_request", failure2);
|
|
6958
|
+
} finally {
|
|
6959
|
+
deps.launchRuns.deleteReplay(launchRunId);
|
|
6960
|
+
}
|
|
6961
|
+
}
|
|
6962
|
+
};
|
|
6963
|
+
}
|
|
6964
|
+
|
|
6965
|
+
// src/pi-resources/bundle-cache.ts
|
|
6966
|
+
import { sha256Digest as sha256Digest2 } from "@leitwerk-dev/worker-protocol";
|
|
6967
|
+
|
|
6968
|
+
// src/model-providers/provider-boundary-utils.ts
|
|
6969
|
+
function positiveBound(value, fallback, name) {
|
|
6970
|
+
const resolved2 = value ?? fallback;
|
|
6971
|
+
if (!Number.isSafeInteger(resolved2) || resolved2 < 1) {
|
|
6972
|
+
throw new Error(`${name} must be a positive safe integer`);
|
|
6973
|
+
}
|
|
6974
|
+
return resolved2;
|
|
6975
|
+
}
|
|
6976
|
+
async function withTimeout(work, timeoutMs, sentinelMessage = "timeout") {
|
|
6977
|
+
let timer;
|
|
6978
|
+
try {
|
|
6979
|
+
return await Promise.race([
|
|
6980
|
+
work,
|
|
6981
|
+
new Promise((_resolve, reject) => {
|
|
6982
|
+
timer = setTimeout(() => reject(new Error(sentinelMessage)), timeoutMs);
|
|
6983
|
+
})
|
|
6984
|
+
]);
|
|
6985
|
+
} finally {
|
|
6986
|
+
if (timer) clearTimeout(timer);
|
|
6987
|
+
}
|
|
6988
|
+
}
|
|
6989
|
+
function validateCredentialStatus(value, message = "invalid credential status") {
|
|
6990
|
+
if (typeof value !== "object" || value === null || typeof value.available !== "boolean" || !(value.revision === null || Number.isSafeInteger(value.revision) && value.revision >= 0)) {
|
|
6991
|
+
throw new Error(message);
|
|
6992
|
+
}
|
|
6993
|
+
return value;
|
|
6994
|
+
}
|
|
6995
|
+
|
|
6996
|
+
// src/pi-resources/bundle-cache.ts
|
|
6997
|
+
var DEFAULT_MAX_ENTRIES = 64;
|
|
6998
|
+
var DEFAULT_MAX_BYTES = 256 * 1024 * 1024;
|
|
6999
|
+
function createPiResourceBundleCache(options = {}) {
|
|
7000
|
+
const maxEntries = positiveBound(options.maxEntries, DEFAULT_MAX_ENTRIES, "maxEntries");
|
|
7001
|
+
const maxBytes = positiveBound(options.maxBytes, DEFAULT_MAX_BYTES, "maxBytes");
|
|
7002
|
+
const entries = /* @__PURE__ */ new Map();
|
|
7003
|
+
let totalBytes = 0;
|
|
7004
|
+
function touch(entry) {
|
|
7005
|
+
entries.delete(entry.digest);
|
|
7006
|
+
entries.set(entry.digest, entry);
|
|
7007
|
+
}
|
|
7008
|
+
function oldestUnpinned(excluding) {
|
|
7009
|
+
for (const entry of entries.values()) {
|
|
7010
|
+
if (entry.digest !== excluding && entry.pins === 0) return entry;
|
|
7011
|
+
}
|
|
7012
|
+
return null;
|
|
7013
|
+
}
|
|
7014
|
+
function remove(entry) {
|
|
7015
|
+
if (!entries.delete(entry.digest)) return;
|
|
7016
|
+
totalBytes -= entry.bytes.byteLength;
|
|
7017
|
+
}
|
|
7018
|
+
function enforceBounds(newDigest) {
|
|
7019
|
+
while (entries.size > maxEntries || totalBytes > maxBytes) {
|
|
7020
|
+
const candidate2 = oldestUnpinned(newDigest);
|
|
7021
|
+
if (!candidate2) {
|
|
7022
|
+
const inserted = entries.get(newDigest);
|
|
7023
|
+
if (inserted?.pins === 0) remove(inserted);
|
|
7024
|
+
throw new Error("Pi resource bundle cache capacity is exhausted by pinned bundles");
|
|
7025
|
+
}
|
|
7026
|
+
remove(candidate2);
|
|
7027
|
+
}
|
|
7028
|
+
}
|
|
7029
|
+
return {
|
|
7030
|
+
put(bundle) {
|
|
7031
|
+
if (typeof bundle.digest !== "string" || sha256Digest2(bundle.bytes) !== bundle.digest) {
|
|
7032
|
+
throw new Error("Pi resource bundle digest does not match its bytes");
|
|
7033
|
+
}
|
|
7034
|
+
if (bundle.bytes.byteLength > maxBytes) {
|
|
7035
|
+
throw new Error(
|
|
7036
|
+
`Pi resource bundle size ${bundle.bytes.byteLength} exceeds cache byte limit ${maxBytes}`
|
|
7037
|
+
);
|
|
7038
|
+
}
|
|
7039
|
+
const existing = entries.get(bundle.digest);
|
|
7040
|
+
if (existing) {
|
|
7041
|
+
touch(existing);
|
|
7042
|
+
return;
|
|
7043
|
+
}
|
|
7044
|
+
const bytes = Uint8Array.from(bundle.bytes);
|
|
7045
|
+
const entry = {
|
|
7046
|
+
digest: bundle.digest,
|
|
7047
|
+
bytes,
|
|
7048
|
+
pins: 0
|
|
7049
|
+
};
|
|
7050
|
+
entries.set(entry.digest, entry);
|
|
7051
|
+
totalBytes += entry.bytes.byteLength;
|
|
7052
|
+
enforceBounds(entry.digest);
|
|
7053
|
+
},
|
|
7054
|
+
get(digest) {
|
|
7055
|
+
const entry = entries.get(digest);
|
|
7056
|
+
if (!entry) return null;
|
|
7057
|
+
touch(entry);
|
|
7058
|
+
return { digest: entry.digest, bytes: Uint8Array.from(entry.bytes) };
|
|
7059
|
+
},
|
|
7060
|
+
has: (digest) => entries.has(digest),
|
|
7061
|
+
pin(digest) {
|
|
7062
|
+
const entry = entries.get(digest);
|
|
7063
|
+
if (!entry) return false;
|
|
7064
|
+
entry.pins += 1;
|
|
7065
|
+
touch(entry);
|
|
7066
|
+
return true;
|
|
7067
|
+
},
|
|
7068
|
+
unpin(digest) {
|
|
7069
|
+
const entry = entries.get(digest);
|
|
7070
|
+
if (!entry || entry.pins === 0) return false;
|
|
7071
|
+
entry.pins -= 1;
|
|
7072
|
+
touch(entry);
|
|
7073
|
+
return true;
|
|
7074
|
+
},
|
|
7075
|
+
gc() {
|
|
7076
|
+
const removed = [...entries.values()].filter((entry) => entry.pins === 0);
|
|
7077
|
+
let removedBytes = 0;
|
|
7078
|
+
for (const entry of removed) {
|
|
7079
|
+
removedBytes += entry.bytes.byteLength;
|
|
7080
|
+
remove(entry);
|
|
7081
|
+
}
|
|
7082
|
+
return {
|
|
7083
|
+
removedDigests: removed.map((entry) => entry.digest),
|
|
7084
|
+
removedBytes
|
|
7085
|
+
};
|
|
7086
|
+
},
|
|
7087
|
+
stats() {
|
|
7088
|
+
const values = [...entries.values()];
|
|
7089
|
+
return {
|
|
7090
|
+
entries: entries.size,
|
|
7091
|
+
bytes: totalBytes,
|
|
7092
|
+
pinnedEntries: values.filter((entry) => entry.pins > 0).length,
|
|
7093
|
+
pins: values.reduce((total, entry) => total + entry.pins, 0)
|
|
7094
|
+
};
|
|
7095
|
+
}
|
|
7096
|
+
};
|
|
7097
|
+
}
|
|
7098
|
+
|
|
7099
|
+
// src/pi-resources/bundle-pin-lifecycle.ts
|
|
7100
|
+
function pinnedDigest(process2, turnStarts, turnRecords2) {
|
|
7101
|
+
if (process2.currentExecution?.kind !== "worker_start") return null;
|
|
7102
|
+
const start = turnStarts.getById(process2.currentExecution.id);
|
|
7103
|
+
if (!start || start.instanceId !== process2.id || start.turnType !== "llm") return null;
|
|
7104
|
+
if (start.state.kind !== "starting" && start.state.kind !== "accepted") return null;
|
|
7105
|
+
if (start.state.start.kind !== "llm") return null;
|
|
7106
|
+
return start.state.kind === "starting" || turnRecords2.getById(start.state.turnRecordId)?.status === "running" ? start.state.start.piResourceSnapshotDigest : null;
|
|
7107
|
+
}
|
|
7108
|
+
function createPiResourceBundlePinReconciler(deps) {
|
|
7109
|
+
const pinnedByInstance = /* @__PURE__ */ new Map();
|
|
7110
|
+
return {
|
|
7111
|
+
reconcile(process2) {
|
|
7112
|
+
const next = pinnedDigest(process2, deps.turnStarts, deps.turnRecords);
|
|
7113
|
+
const previous = pinnedByInstance.get(process2.id) ?? null;
|
|
7114
|
+
if (previous === next) {
|
|
7115
|
+
return { missingDigest: next && !deps.bundleCache.has(next) ? next : null };
|
|
7116
|
+
}
|
|
7117
|
+
if (previous) deps.bundleCache.unpin(previous);
|
|
7118
|
+
pinnedByInstance.delete(process2.id);
|
|
7119
|
+
if (!next) {
|
|
7120
|
+
return { missingDigest: null };
|
|
7121
|
+
}
|
|
7122
|
+
if (!deps.bundleCache.pin(next)) {
|
|
7123
|
+
return { missingDigest: next };
|
|
7124
|
+
}
|
|
7125
|
+
pinnedByInstance.set(process2.id, next);
|
|
7126
|
+
return { missingDigest: null };
|
|
7127
|
+
}
|
|
7128
|
+
};
|
|
7129
|
+
}
|
|
7130
|
+
|
|
7131
|
+
// src/pi-resources/assemble.ts
|
|
7132
|
+
import { lstat as lstat2, realpath as realpath2 } from "node:fs/promises";
|
|
7133
|
+
import path2 from "node:path";
|
|
7134
|
+
import {
|
|
7135
|
+
canonicalizeJson,
|
|
7136
|
+
canonicalJsonStringify,
|
|
7137
|
+
createCanonicalPiResourceBundle,
|
|
7138
|
+
PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION,
|
|
7139
|
+
sha256Digest as sha256Digest3,
|
|
7140
|
+
validateResourceRelativePath as validateResourceRelativePath2
|
|
7141
|
+
} from "@leitwerk-dev/worker-protocol";
|
|
7142
|
+
import { build } from "esbuild";
|
|
7143
|
+
import {
|
|
7144
|
+
PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION as PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION2
|
|
7145
|
+
} from "@leitwerk-dev/worker-protocol";
|
|
7146
|
+
function jsonBytes(value, location) {
|
|
7147
|
+
return Buffer.from(`${canonicalJsonStringify(value, location)}
|
|
7148
|
+
`, "utf8");
|
|
7149
|
+
}
|
|
7150
|
+
var FORBIDDEN_SECRET_KEYS = /* @__PURE__ */ new Set([
|
|
7151
|
+
"apikey",
|
|
7152
|
+
"accesstoken",
|
|
7153
|
+
"refreshtoken",
|
|
7154
|
+
"brokertoken",
|
|
7155
|
+
"clientsecret",
|
|
7156
|
+
"privatekey",
|
|
7157
|
+
"password",
|
|
7158
|
+
"secret",
|
|
7159
|
+
"authorization"
|
|
7160
|
+
]);
|
|
7161
|
+
function assertNoCredentialFields(value, location) {
|
|
7162
|
+
if (Array.isArray(value)) {
|
|
7163
|
+
value.forEach((item, index2) => {
|
|
7164
|
+
assertNoCredentialFields(item, `${location}[${index2}]`);
|
|
7165
|
+
});
|
|
7166
|
+
return;
|
|
7167
|
+
}
|
|
7168
|
+
if (typeof value !== "object" || value === null) return;
|
|
7169
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
7170
|
+
const normalizedKey = key.toLowerCase().replaceAll(/[^a-z0-9]/g, "");
|
|
7171
|
+
if (FORBIDDEN_SECRET_KEYS.has(normalizedKey)) {
|
|
7172
|
+
throw new Error(
|
|
7173
|
+
`${location}.${key} is credential-bearing and cannot enter a Pi resource snapshot`
|
|
7174
|
+
);
|
|
7175
|
+
}
|
|
7176
|
+
assertNoCredentialFields(nested, `${location}.${key}`);
|
|
7177
|
+
}
|
|
7178
|
+
}
|
|
7179
|
+
function safeExtensionSegment(ownerExtensionId) {
|
|
7180
|
+
const normalized = ownerExtensionId.normalize("NFKD").replaceAll(/[^A-Za-z0-9._-]+/g, "-").replaceAll(/^-+|-+$/g, "") || "extension";
|
|
7181
|
+
if (Buffer.byteLength(normalized, "utf8") <= 56) return normalized;
|
|
7182
|
+
return `${normalized.slice(0, 43)}-${sha256Digest3(Buffer.from(ownerExtensionId)).slice(0, 12)}`;
|
|
7183
|
+
}
|
|
7184
|
+
function extensionSnapshotPath(contribution, index2) {
|
|
7185
|
+
const prefix = String(index2 * 10).padStart(3, "0");
|
|
7186
|
+
return validateResourceRelativePath2(
|
|
7187
|
+
`extensions/${prefix}-${safeExtensionSegment(contribution.ownerExtensionId)}.js`
|
|
7188
|
+
);
|
|
7189
|
+
}
|
|
7190
|
+
var PI_CORE_EXTERNALS = ["@earendil-works/pi-ai", "@earendil-works/pi-coding-agent"];
|
|
7191
|
+
async function buildPiExtensionWrapper(entryPath) {
|
|
7192
|
+
const result = await build({
|
|
7193
|
+
absWorkingDir: path2.dirname(entryPath),
|
|
7194
|
+
bundle: true,
|
|
7195
|
+
stdin: {
|
|
7196
|
+
contents: `
|
|
7197
|
+
import contribution from ${JSON.stringify(entryPath)};
|
|
7198
|
+
import { readFileSync } from "node:fs";
|
|
7199
|
+
|
|
7200
|
+
function readGenerated() {
|
|
7201
|
+
return JSON.parse(readFileSync(new URL("../generated.json", import.meta.url), "utf8"));
|
|
7202
|
+
}
|
|
7203
|
+
|
|
7204
|
+
function credentialBag(generated) {
|
|
7205
|
+
let values;
|
|
7206
|
+
const load = () => {
|
|
7207
|
+
if (values) return values;
|
|
7208
|
+
values = {};
|
|
7209
|
+
for (const credentialPath of generated.declaredCredentialPaths) {
|
|
7210
|
+
if (typeof credentialPath !== "string" || credentialPath.startsWith("/") || credentialPath.includes("..") || credentialPath.includes("\\\\")) {
|
|
7211
|
+
throw new Error("Invalid declared Pi credential path");
|
|
7212
|
+
}
|
|
7213
|
+
const credential = JSON.parse(readFileSync(new URL("../" + credentialPath, import.meta.url), "utf8"));
|
|
7214
|
+
if (credential && typeof credential === "object" && !Array.isArray(credential)) Object.assign(values, credential);
|
|
7215
|
+
}
|
|
7216
|
+
return values;
|
|
7217
|
+
};
|
|
7218
|
+
return {
|
|
7219
|
+
get(key) { const value = load()[key]; return typeof value === "string" ? value : undefined; },
|
|
7220
|
+
require(key) { const value = this.get(key); if (value === undefined) throw new Error("Required Pi worker secret '" + key + "' is unavailable"); return value; },
|
|
7221
|
+
keys() { return Object.keys(load()).filter((key) => typeof load()[key] === "string").sort(); },
|
|
7222
|
+
};
|
|
7223
|
+
}
|
|
7224
|
+
|
|
7225
|
+
export default async function leitwerkPiExtension(pi) {
|
|
7226
|
+
if (typeof contribution !== "function") throw new Error("Leitwerk Pi worker entry must default-export a function");
|
|
7227
|
+
const generated = readGenerated();
|
|
7228
|
+
const workerConfig = generated.providerWorkerConfig === null ? null : generated.providerWorkerConfig?.value;
|
|
7229
|
+
const report = (event) => {
|
|
7230
|
+
if (!event || typeof event !== "object" || Array.isArray(event)) throw new Error("Pi worker report must be an object");
|
|
7231
|
+
pi.events?.emit?.("leitwerk:provider-report", event);
|
|
7232
|
+
};
|
|
7233
|
+
await contribution(pi, {
|
|
7234
|
+
model: { providerId: generated.model.providerId, modelId: generated.model.modelId },
|
|
7235
|
+
options: { ...generated.providerOptions },
|
|
7236
|
+
workerConfig,
|
|
7237
|
+
secrets: credentialBag(generated),
|
|
7238
|
+
report,
|
|
7239
|
+
});
|
|
7240
|
+
}
|
|
7241
|
+
`,
|
|
7242
|
+
resolveDir: path2.dirname(entryPath),
|
|
7243
|
+
sourcefile: "leitwerk-pi-wrapper.js"
|
|
7244
|
+
},
|
|
7245
|
+
format: "esm",
|
|
7246
|
+
platform: "node",
|
|
7247
|
+
target: "node22",
|
|
7248
|
+
write: false,
|
|
7249
|
+
minify: true,
|
|
7250
|
+
sourcemap: false,
|
|
7251
|
+
legalComments: "none",
|
|
7252
|
+
external: PI_CORE_EXTERNALS
|
|
7253
|
+
});
|
|
7254
|
+
const output = result.outputFiles[0];
|
|
7255
|
+
if (!output) throw new Error(`Pi extension wrapper did not produce output for '${entryPath}'`);
|
|
7256
|
+
return output.contents;
|
|
7257
|
+
}
|
|
7258
|
+
function normalizeCredentialPaths(paths) {
|
|
7259
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7260
|
+
const normalized = paths.map((credentialPath) => {
|
|
7261
|
+
const result = validateResourceRelativePath2(credentialPath);
|
|
7262
|
+
if (seen.has(result)) throw new Error(`Duplicate declared credential path '${result}'`);
|
|
7263
|
+
seen.add(result);
|
|
7264
|
+
return result;
|
|
7265
|
+
});
|
|
7266
|
+
return normalized.sort(compareResourcePaths);
|
|
7267
|
+
}
|
|
7268
|
+
function assertCredentialPathsDoNotOverlap(credentialPaths, immutablePaths) {
|
|
7269
|
+
const files = [...immutablePaths];
|
|
7270
|
+
for (const credentialPath of credentialPaths) {
|
|
7271
|
+
for (const immutablePath of files) {
|
|
7272
|
+
if (credentialPath === immutablePath || credentialPath.startsWith(`${immutablePath}/`) || immutablePath.startsWith(`${credentialPath}/`)) {
|
|
7273
|
+
throw new Error(
|
|
7274
|
+
`Declared credential path '${credentialPath}' overlaps immutable resource '${immutablePath}'`
|
|
7275
|
+
);
|
|
7276
|
+
}
|
|
7277
|
+
}
|
|
7278
|
+
}
|
|
7279
|
+
}
|
|
7280
|
+
function requireNonEmptyString(value, location) {
|
|
7281
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
7282
|
+
throw new Error(`${location} must be a non-empty string`);
|
|
7283
|
+
}
|
|
7284
|
+
}
|
|
7285
|
+
function validateAssemblyInput(input) {
|
|
7286
|
+
requireNonEmptyString(input.model.profileId, "model.profileId");
|
|
7287
|
+
requireNonEmptyString(input.model.providerId, "model.providerId");
|
|
7288
|
+
requireNonEmptyString(input.model.modelId, "model.modelId");
|
|
7289
|
+
requireNonEmptyString(input.model.thinkingLevel, "model.thinkingLevel");
|
|
7290
|
+
requireNonEmptyString(input.compatibility.workerApiVersion, "compatibility.workerApiVersion");
|
|
7291
|
+
requireNonEmptyString(input.compatibility.piVersion, "compatibility.piVersion");
|
|
7292
|
+
if (input.compatibility.protocolVersion !== void 0) {
|
|
7293
|
+
requireNonEmptyString(input.compatibility.protocolVersion, "compatibility.protocolVersion");
|
|
7294
|
+
}
|
|
7295
|
+
for (const [fieldId, value] of Object.entries(input.providerOptions)) {
|
|
7296
|
+
if (fieldId.trim() === "" || typeof value !== "string") {
|
|
7297
|
+
throw new Error("providerOptions must contain non-empty field ids and string values");
|
|
7298
|
+
}
|
|
7299
|
+
}
|
|
7300
|
+
if (input.providerWorkerConfig && (!Number.isSafeInteger(input.providerWorkerConfig.version) || input.providerWorkerConfig.version < 1)) {
|
|
7301
|
+
throw new Error("providerWorkerConfig.version must be a positive safe integer");
|
|
7302
|
+
}
|
|
7303
|
+
if (input.systemPrompt !== void 0 && input.systemPrompt !== null) {
|
|
7304
|
+
if (typeof input.systemPrompt !== "string") throw new Error("systemPrompt must be a string");
|
|
7305
|
+
}
|
|
7306
|
+
if (input.appendSystemPrompt !== void 0 && input.appendSystemPrompt !== null) {
|
|
7307
|
+
if (typeof input.appendSystemPrompt !== "string") {
|
|
7308
|
+
throw new Error("appendSystemPrompt must be a string");
|
|
7309
|
+
}
|
|
7310
|
+
}
|
|
7311
|
+
}
|
|
7312
|
+
async function assemblePiResourceSnapshot(input) {
|
|
7313
|
+
validateAssemblyInput(input);
|
|
7314
|
+
assertNoCredentialFields(input.piSettings, "piSettings");
|
|
7315
|
+
assertNoCredentialFields(input.piModels ?? {}, "piModels");
|
|
7316
|
+
assertNoCredentialFields(input.providerOptions, "providerOptions");
|
|
7317
|
+
assertNoCredentialFields(input.providerWorkerConfig?.value ?? {}, "providerWorkerConfig.value");
|
|
7318
|
+
const collector = new ResourceCollector(input.limits);
|
|
7319
|
+
const seenOwners = /* @__PURE__ */ new Set();
|
|
7320
|
+
const workerSourceIdentities = /* @__PURE__ */ new Map();
|
|
7321
|
+
const workerSourceRealPaths = /* @__PURE__ */ new Map();
|
|
7322
|
+
const settings = { ...input.piSettings, packages: [], defaultProjectTrust: "never" };
|
|
7323
|
+
collector.addBytes("settings.json", jsonBytes(settings, "settings.json"));
|
|
7324
|
+
collector.addBytes("models.json", jsonBytes(input.piModels ?? { providers: {} }, "models.json"));
|
|
7325
|
+
if (input.systemPrompt !== void 0 && input.systemPrompt !== null) {
|
|
7326
|
+
collector.addBytes("SYSTEM.md", Buffer.from(input.systemPrompt, "utf8"));
|
|
7327
|
+
}
|
|
7328
|
+
if (input.appendSystemPrompt !== void 0 && input.appendSystemPrompt !== null) {
|
|
7329
|
+
collector.addBytes("APPEND_SYSTEM.md", Buffer.from(input.appendSystemPrompt, "utf8"));
|
|
7330
|
+
}
|
|
7331
|
+
for (const layer of input.resourceLayers ?? []) collector.addBundle(layer.bundle, layer.owner);
|
|
7332
|
+
for (const [index2, contribution] of input.piContributions.entries()) {
|
|
7333
|
+
if (seenOwners.has(contribution.ownerExtensionId)) {
|
|
7334
|
+
throw new Error(
|
|
7335
|
+
`Extension '${contribution.ownerExtensionId}' appears more than once in Pi contributions`
|
|
7336
|
+
);
|
|
7337
|
+
}
|
|
7338
|
+
seenOwners.add(contribution.ownerExtensionId);
|
|
7339
|
+
const baseOwner = {
|
|
7340
|
+
ownerExtensionId: contribution.ownerExtensionId,
|
|
7341
|
+
packageName: contribution.packageName
|
|
7342
|
+
};
|
|
7343
|
+
if (contribution.workerEntryPath) {
|
|
7344
|
+
validatePhysicalSourcePath(contribution.workerEntryPath);
|
|
7345
|
+
const source = await lstat2(contribution.workerEntryPath);
|
|
7346
|
+
if (source.isSymbolicLink() || !source.isFile()) {
|
|
7347
|
+
throw new Error(
|
|
7348
|
+
`Pi resource source must be a regular file: ${contribution.workerEntryPath}`
|
|
7349
|
+
);
|
|
7350
|
+
}
|
|
7351
|
+
const identity = `${source.dev}:${source.ino}`;
|
|
7352
|
+
const physicalPath = await realpath2(contribution.workerEntryPath);
|
|
7353
|
+
const first = workerSourceIdentities.get(identity) ?? workerSourceRealPaths.get(physicalPath);
|
|
7354
|
+
if (first) {
|
|
7355
|
+
throw new Error(
|
|
7356
|
+
`Physical Pi resource file is included more than once: ${contribution.workerEntryPath} (first: ${first})`
|
|
7026
7357
|
);
|
|
7027
|
-
return {
|
|
7028
|
-
kind: committed.kind,
|
|
7029
|
-
result: committed.result,
|
|
7030
|
-
process: committed.process,
|
|
7031
|
-
reused: committed.kind === "committed" ? committed.reused : false
|
|
7032
|
-
};
|
|
7033
|
-
} catch (error) {
|
|
7034
|
-
const run = deps.launchRuns.getById(launchRunId);
|
|
7035
|
-
const failure = adapter.unexpectedFailure?.(error) ?? {
|
|
7036
|
-
safeSummary: "The launch could not be completed. Try again.",
|
|
7037
|
-
value: error
|
|
7038
|
-
};
|
|
7039
|
-
return fail(launchRunId, run ? activeStepId(run) : "validate_request", failure);
|
|
7040
|
-
} finally {
|
|
7041
|
-
deps.launchRuns.deleteReplay(launchRunId);
|
|
7042
7358
|
}
|
|
7359
|
+
workerSourceIdentities.set(identity, contribution.workerEntryPath);
|
|
7360
|
+
workerSourceRealPaths.set(physicalPath, contribution.workerEntryPath);
|
|
7361
|
+
const snapshotPath = extensionSnapshotPath(contribution, index2);
|
|
7362
|
+
collector.addBytes(
|
|
7363
|
+
snapshotPath,
|
|
7364
|
+
await buildPiExtensionWrapper(contribution.workerEntryPath),
|
|
7365
|
+
{ kind: "extension", ...baseOwner }
|
|
7366
|
+
);
|
|
7043
7367
|
}
|
|
7368
|
+
for (const skillDirectory of contribution.resources.skillDirectories) {
|
|
7369
|
+
await collector.addDirectory(skillDirectory, "skills", { kind: "skill", ...baseOwner });
|
|
7370
|
+
}
|
|
7371
|
+
for (const promptDirectory of contribution.resources.promptDirectories) {
|
|
7372
|
+
await collector.addDirectory(promptDirectory, "prompts", { kind: "prompt", ...baseOwner });
|
|
7373
|
+
}
|
|
7374
|
+
}
|
|
7375
|
+
const credentialPaths = normalizeCredentialPaths(input.declaredCredentialPaths);
|
|
7376
|
+
assertCredentialPathsDoNotOverlap(credentialPaths, [...collector.files.keys(), "generated.json"]);
|
|
7377
|
+
const provenance = collector.provenance.slice().sort((left, right) => compareResourcePaths(left.snapshotPath, right.snapshotPath));
|
|
7378
|
+
const generated = {
|
|
7379
|
+
schemaVersion: PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION,
|
|
7380
|
+
model: { ...input.model },
|
|
7381
|
+
providerOptions: { ...input.providerOptions },
|
|
7382
|
+
providerWorkerConfig: input.providerWorkerConfig ? {
|
|
7383
|
+
version: input.providerWorkerConfig.version,
|
|
7384
|
+
value: canonicalizeJson(
|
|
7385
|
+
input.providerWorkerConfig.value,
|
|
7386
|
+
"providerWorkerConfig.value"
|
|
7387
|
+
)
|
|
7388
|
+
} : null,
|
|
7389
|
+
declaredCredentialPaths: credentialPaths,
|
|
7390
|
+
compatibility: { ...input.compatibility },
|
|
7391
|
+
provenance
|
|
7392
|
+
};
|
|
7393
|
+
collector.addBytes("generated.json", jsonBytes(generated, "generated.json"));
|
|
7394
|
+
const resourceFiles = collector.toResourceFiles();
|
|
7395
|
+
const bundle = createCanonicalPiResourceBundle(resourceFiles);
|
|
7396
|
+
return {
|
|
7397
|
+
bundle,
|
|
7398
|
+
generated,
|
|
7399
|
+
files: collector.provenance.map(({ snapshotPath, sha256, size }) => ({ path: snapshotPath, sha256, size })).sort((left, right) => compareResourcePaths(left.path, right.path))
|
|
7044
7400
|
};
|
|
7045
7401
|
}
|
|
7046
7402
|
|
|
7047
7403
|
// src/process-operator-attention.ts
|
|
7048
7404
|
import { trimToNull as trimToNull6 } from "@leitwerk-dev/domain";
|
|
7049
|
-
import { isHumanTurnDefinition
|
|
7405
|
+
import { isHumanTurnDefinition } from "@leitwerk-dev/process-sdk";
|
|
7050
7406
|
import {
|
|
7051
7407
|
createEphemeralWsFrame,
|
|
7052
7408
|
WS_PROCESS_TYPES
|
|
@@ -7133,7 +7489,7 @@ function selectedTurnRequiresActionAttention(deps, process2) {
|
|
|
7133
7489
|
process2.processId,
|
|
7134
7490
|
process2.selectedTurnId
|
|
7135
7491
|
);
|
|
7136
|
-
return !turnDef || !
|
|
7492
|
+
return !turnDef || !isHumanTurnDefinition(turnDef) || turnDef.operatorAttention !== "passive";
|
|
7137
7493
|
}
|
|
7138
7494
|
function buildActionRequiredToast(deps, process2) {
|
|
7139
7495
|
if (process2.lifecycleStatus !== "waiting") {
|
|
@@ -7204,6 +7560,394 @@ function broadcastProcessAttentionToast(deps, input) {
|
|
|
7204
7560
|
return true;
|
|
7205
7561
|
}
|
|
7206
7562
|
|
|
7563
|
+
// src/worker-runtime-profile-selection.ts
|
|
7564
|
+
function trimToUndefined(value) {
|
|
7565
|
+
if (typeof value !== "string") {
|
|
7566
|
+
return void 0;
|
|
7567
|
+
}
|
|
7568
|
+
const trimmed = value.trim();
|
|
7569
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
7570
|
+
}
|
|
7571
|
+
function defaultWorkerRuntimeProfile(config) {
|
|
7572
|
+
if (config.workers.runner === "local") {
|
|
7573
|
+
return config.workers.default_runtime_profile ?? "local";
|
|
7574
|
+
}
|
|
7575
|
+
return (config.workers.runner === "kubernetes" ? config.kubernetes?.default_worker_runtime_profile : void 0) ?? config.workers.default_runtime_profile ?? null;
|
|
7576
|
+
}
|
|
7577
|
+
function selectWorkerRuntimeProfile(input) {
|
|
7578
|
+
const override = trimToUndefined(input.processOverride);
|
|
7579
|
+
if (override) {
|
|
7580
|
+
return resolveProfileImage(override, input.profiles);
|
|
7581
|
+
}
|
|
7582
|
+
const declared = input.componentProfiles.map((entry) => ({ component: entry.component, profile: trimToUndefined(entry.profile) })).filter(
|
|
7583
|
+
(entry) => entry.profile !== void 0
|
|
7584
|
+
);
|
|
7585
|
+
const distinct = new Set(declared.map((entry) => entry.profile));
|
|
7586
|
+
if (distinct.size > 1) {
|
|
7587
|
+
const summary = declared.map((entry) => `${entry.component}=${entry.profile}`).sort().join(", ");
|
|
7588
|
+
return {
|
|
7589
|
+
ok: false,
|
|
7590
|
+
error: `Process '${input.processId}' has conflicting component worker runtime profiles (${summary}); set process_configs.${input.processId}.worker_runtime_profile to resolve`
|
|
7591
|
+
};
|
|
7592
|
+
}
|
|
7593
|
+
if (distinct.size === 1) {
|
|
7594
|
+
const [only] = distinct;
|
|
7595
|
+
return resolveProfileImage(only, input.profiles);
|
|
7596
|
+
}
|
|
7597
|
+
const fallback = trimToUndefined(input.defaultProfile);
|
|
7598
|
+
if (!fallback) {
|
|
7599
|
+
return {
|
|
7600
|
+
ok: false,
|
|
7601
|
+
error: `Process '${input.processId}' selects no worker runtime profile and no default worker runtime profile is configured`
|
|
7602
|
+
};
|
|
7603
|
+
}
|
|
7604
|
+
return resolveProfileImage(fallback, input.profiles);
|
|
7605
|
+
}
|
|
7606
|
+
function resolveProfileImage(runtimeProfile, profiles) {
|
|
7607
|
+
const profile = profiles[runtimeProfile];
|
|
7608
|
+
if (!profile) {
|
|
7609
|
+
return {
|
|
7610
|
+
ok: false,
|
|
7611
|
+
error: `Unknown worker runtime profile '${runtimeProfile}'; configure it under worker_runtime_profiles`
|
|
7612
|
+
};
|
|
7613
|
+
}
|
|
7614
|
+
return {
|
|
7615
|
+
ok: true,
|
|
7616
|
+
runtimeProfile,
|
|
7617
|
+
image: { reference: profile.image }
|
|
7618
|
+
};
|
|
7619
|
+
}
|
|
7620
|
+
function buildRuntimeProfileSelectionInput(args) {
|
|
7621
|
+
const { config, processId, componentKeys } = args;
|
|
7622
|
+
const componentProfiles = componentKeys.map((component) => ({
|
|
7623
|
+
component,
|
|
7624
|
+
profile: config.components[component]?.worker_runtime_profile
|
|
7625
|
+
}));
|
|
7626
|
+
return {
|
|
7627
|
+
processId,
|
|
7628
|
+
processOverride: config.process_configs?.[processId]?.worker_runtime_profile,
|
|
7629
|
+
componentProfiles,
|
|
7630
|
+
defaultProfile: defaultWorkerRuntimeProfile(config) ?? void 0,
|
|
7631
|
+
profiles: config.worker_runtime_profiles ?? {}
|
|
7632
|
+
};
|
|
7633
|
+
}
|
|
7634
|
+
|
|
7635
|
+
// src/process-engine/turn-start-preflight.ts
|
|
7636
|
+
import { filterProviderOptionsForDefinition } from "@leitwerk-dev/process-sdk";
|
|
7637
|
+
import { IPC_PROTOCOL_VERSION, WORKER_API_VERSION } from "@leitwerk-dev/worker-protocol";
|
|
7638
|
+
|
|
7639
|
+
// src/model-providers/provider-options.ts
|
|
7640
|
+
import {
|
|
7641
|
+
resolveProviderOptions
|
|
7642
|
+
} from "@leitwerk-dev/process-sdk";
|
|
7643
|
+
var DEFAULT_OPTION_CHOICE_TIMEOUT_MS = 5e3;
|
|
7644
|
+
var DEFAULT_MAX_CHOICE_FIELDS = 64;
|
|
7645
|
+
var DEFAULT_MAX_CHOICES_PER_FIELD = 256;
|
|
7646
|
+
var DEFAULT_MAX_CHOICE_TEXT_LENGTH = 512;
|
|
7647
|
+
function resolveRegisteredProviderOptions(input) {
|
|
7648
|
+
return resolveProviderOptions({
|
|
7649
|
+
definition: input.provider.definition.options,
|
|
7650
|
+
config: input.provider.config,
|
|
7651
|
+
explicit: input.explicit,
|
|
7652
|
+
profileDefaults: input.profileDefaults
|
|
7653
|
+
});
|
|
7654
|
+
}
|
|
7655
|
+
function validateConfiguredProviderOptions(input) {
|
|
7656
|
+
const result = resolveRegisteredProviderOptions({
|
|
7657
|
+
provider: input.provider,
|
|
7658
|
+
profileDefaults: input.values
|
|
7659
|
+
});
|
|
7660
|
+
if (result.ok) {
|
|
7661
|
+
return [];
|
|
7662
|
+
}
|
|
7663
|
+
return result.issues.filter((issue2) => issue2.code !== "required");
|
|
7664
|
+
}
|
|
7665
|
+
async function loadProviderOptionChoices(input) {
|
|
7666
|
+
const choicesLoader = input.provider.definition.options?.choices;
|
|
7667
|
+
if (!choicesLoader) {
|
|
7668
|
+
return { ok: true, choices: {} };
|
|
7669
|
+
}
|
|
7670
|
+
const timeoutMs = positiveBound(
|
|
7671
|
+
input.timeoutMs,
|
|
7672
|
+
DEFAULT_OPTION_CHOICE_TIMEOUT_MS,
|
|
7673
|
+
"Provider option choice timeout"
|
|
7674
|
+
);
|
|
7675
|
+
const maxFields = positiveBound(
|
|
7676
|
+
input.maxFields,
|
|
7677
|
+
DEFAULT_MAX_CHOICE_FIELDS,
|
|
7678
|
+
"Maximum choice fields"
|
|
7679
|
+
);
|
|
7680
|
+
const maxChoices = positiveBound(
|
|
7681
|
+
input.maxChoicesPerField,
|
|
7682
|
+
DEFAULT_MAX_CHOICES_PER_FIELD,
|
|
7683
|
+
"Maximum choices per field"
|
|
7684
|
+
);
|
|
7685
|
+
const maxTextLength = positiveBound(
|
|
7686
|
+
input.maxTextLength,
|
|
7687
|
+
DEFAULT_MAX_CHOICE_TEXT_LENGTH,
|
|
7688
|
+
"Maximum choice text length"
|
|
7689
|
+
);
|
|
7690
|
+
try {
|
|
7691
|
+
const credentialStatus = validateCredentialStatus(
|
|
7692
|
+
await withTimeout(Promise.resolve(input.credentialStatus(input.provider)), timeoutMs)
|
|
7693
|
+
);
|
|
7694
|
+
const raw = await withTimeout(
|
|
7695
|
+
Promise.resolve(choicesLoader({ config: input.provider.config, credentialStatus })),
|
|
7696
|
+
timeoutMs
|
|
7697
|
+
);
|
|
7698
|
+
const entries = Object.entries(raw);
|
|
7699
|
+
if (entries.length > maxFields) {
|
|
7700
|
+
throw new Error("too many fields");
|
|
7701
|
+
}
|
|
7702
|
+
const fields = input.provider.definition.options?.fields ?? {};
|
|
7703
|
+
const bounded = {};
|
|
7704
|
+
for (const [fieldId, choices] of entries) {
|
|
7705
|
+
if (!(fieldId in fields) || !Array.isArray(choices) || choices.length > maxChoices) {
|
|
7706
|
+
throw new Error("invalid field choices");
|
|
7707
|
+
}
|
|
7708
|
+
bounded[fieldId] = choices.map((choice) => {
|
|
7709
|
+
if (typeof choice?.value !== "string" || typeof choice?.label !== "string" || choice.value.length > maxTextLength || choice.label.length > maxTextLength) {
|
|
7710
|
+
throw new Error("invalid choice");
|
|
7711
|
+
}
|
|
7712
|
+
return { value: choice.value, label: choice.label };
|
|
7713
|
+
});
|
|
7714
|
+
}
|
|
7715
|
+
return { ok: true, choices: bounded };
|
|
7716
|
+
} catch (error) {
|
|
7717
|
+
return {
|
|
7718
|
+
ok: false,
|
|
7719
|
+
safeReason: error instanceof Error && error.message === "timeout" ? "Provider option choices timed out" : "Provider option choices are temporarily unavailable"
|
|
7720
|
+
};
|
|
7721
|
+
}
|
|
7722
|
+
}
|
|
7723
|
+
|
|
7724
|
+
// src/process-engine/turn-start-preflight.ts
|
|
7725
|
+
var PI_RUNTIME_VERSION = "0.81.1";
|
|
7726
|
+
function failure(requestedModelProfileId, providerOptions, code, safeSummary, modelSelectionProvenance, availabilityRevision) {
|
|
7727
|
+
return {
|
|
7728
|
+
kind: "preparation_failed",
|
|
7729
|
+
requestedModelProfileId,
|
|
7730
|
+
providerOptions,
|
|
7731
|
+
code,
|
|
7732
|
+
safeSummary,
|
|
7733
|
+
...modelSelectionProvenance ? { modelSelectionProvenance } : {},
|
|
7734
|
+
...availabilityRevision !== void 0 ? { availabilityRevision } : {}
|
|
7735
|
+
};
|
|
7736
|
+
}
|
|
7737
|
+
function previousProviderOptions(state) {
|
|
7738
|
+
if (state.kind === "preparation_failed") return { ...state.providerOptions };
|
|
7739
|
+
if (state.kind === "superseded" || state.kind === "starting" || state.kind === "accepted") {
|
|
7740
|
+
return state.start?.kind === "llm" ? { ...state.start.providerOptions } : {};
|
|
7741
|
+
}
|
|
7742
|
+
return state.start.kind === "llm" ? { ...state.start.providerOptions } : {};
|
|
7743
|
+
}
|
|
7744
|
+
function previousProviderId(deps, state) {
|
|
7745
|
+
if (state.kind !== "preparation_failed") {
|
|
7746
|
+
return state.start?.kind === "llm" ? state.start.model.providerId : null;
|
|
7747
|
+
}
|
|
7748
|
+
const profileId = state.requestedModelProfileId;
|
|
7749
|
+
return profileId ? deps.config.pi.model_profiles.find((profile) => profile.id === profileId)?.provider ?? null : null;
|
|
7750
|
+
}
|
|
7751
|
+
function parkPreparationFailure(writes, write, state) {
|
|
7752
|
+
write.input.state = state;
|
|
7753
|
+
writes.processPatch.lifecycleStatus = "error";
|
|
7754
|
+
writes.workerIntent = { kind: "reconcile" };
|
|
7755
|
+
}
|
|
7756
|
+
function candidateProcess(process2, writes) {
|
|
7757
|
+
return { ...process2, ...writes.processPatch };
|
|
7758
|
+
}
|
|
7759
|
+
function resolveRuntimeProfile(deps, process2) {
|
|
7760
|
+
if (deps.config.workers.runner === "local") {
|
|
7761
|
+
return { ok: true, id: defaultWorkerRuntimeProfile(deps.config) ?? "local" };
|
|
7762
|
+
}
|
|
7763
|
+
const selection = selectWorkerRuntimeProfile(
|
|
7764
|
+
buildRuntimeProfileSelectionInput({
|
|
7765
|
+
config: deps.config,
|
|
7766
|
+
processId: process2.processId,
|
|
7767
|
+
componentKeys: deps.projects.listByInstance(process2.id).map((project) => project.key)
|
|
7768
|
+
})
|
|
7769
|
+
);
|
|
7770
|
+
return selection.ok ? { ok: true, id: selection.runtimeProfile } : { ok: false, message: selection.error };
|
|
7771
|
+
}
|
|
7772
|
+
function resolveProviderWorkerConfig(provider, options) {
|
|
7773
|
+
if (provider.definition.worker.kind !== "extension_pi_worker") return null;
|
|
7774
|
+
const definition = provider.definition.worker.config;
|
|
7775
|
+
if (!definition) return null;
|
|
7776
|
+
const projected = definition.resolve({ config: provider.config, options });
|
|
7777
|
+
const value = definition.schema.parse(projected);
|
|
7778
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
7779
|
+
throw new Error("Provider worker configuration must be a JSON object");
|
|
7780
|
+
}
|
|
7781
|
+
return { version: definition.version, value };
|
|
7782
|
+
}
|
|
7783
|
+
function resolveProviderPiModels(provider) {
|
|
7784
|
+
const worker = provider.definition.worker;
|
|
7785
|
+
return worker.kind === "configured_pi_provider" ? worker.resolveModels({ config: provider.config }) : { providers: {} };
|
|
7786
|
+
}
|
|
7787
|
+
function buildPiSettings(config) {
|
|
7788
|
+
return {
|
|
7789
|
+
retry: {
|
|
7790
|
+
enabled: config.pi.retry.enabled,
|
|
7791
|
+
maxRetries: config.pi.retry.max_retries,
|
|
7792
|
+
baseDelay: config.pi.retry.base_delay,
|
|
7793
|
+
provider: {
|
|
7794
|
+
timeout: config.pi.retry.provider.timeout,
|
|
7795
|
+
maxRetries: config.pi.retry.provider.max_retries,
|
|
7796
|
+
maxRetryDelay: config.pi.retry.provider.max_retry_delay
|
|
7797
|
+
}
|
|
7798
|
+
}
|
|
7799
|
+
};
|
|
7800
|
+
}
|
|
7801
|
+
async function prepareCreatedTurnStarts(deps, process2, writes, explicitProviderOptions, availabilitySnapshot) {
|
|
7802
|
+
const nextProcess = candidateProcess(process2, writes);
|
|
7803
|
+
const availability = availabilitySnapshot ?? deps.modelStatusCache.snapshot();
|
|
7804
|
+
const provenance = nextProcess.selectedTurnModelKind && nextProcess.selectedTurnModelSource ? {
|
|
7805
|
+
kind: nextProcess.selectedTurnModelKind,
|
|
7806
|
+
source: nextProcess.selectedTurnModelSource
|
|
7807
|
+
} : void 0;
|
|
7808
|
+
for (let index2 = 0; index2 < writes.turnStartWrites.length; index2 += 1) {
|
|
7809
|
+
const write = writes.turnStartWrites[index2];
|
|
7810
|
+
if (!write || write.kind !== "create" || write.input.turnType !== "llm") continue;
|
|
7811
|
+
const requestedProfileId = nextProcess.selectedTurnModelProfileId?.trim() || null;
|
|
7812
|
+
const retainedState = write.input.state;
|
|
7813
|
+
const retainedOptions = previousProviderOptions(retainedState);
|
|
7814
|
+
if (retainedState.kind === "preparation_failed" && retainedState.code === "invalid_model_configuration") {
|
|
7815
|
+
parkPreparationFailure(writes, write, retainedState);
|
|
7816
|
+
continue;
|
|
7817
|
+
}
|
|
7818
|
+
if (!requestedProfileId) {
|
|
7819
|
+
parkPreparationFailure(
|
|
7820
|
+
writes,
|
|
7821
|
+
write,
|
|
7822
|
+
failure(
|
|
7823
|
+
null,
|
|
7824
|
+
retainedOptions,
|
|
7825
|
+
"model_required",
|
|
7826
|
+
"Choose a model before retrying startup",
|
|
7827
|
+
void 0,
|
|
7828
|
+
availability.revision
|
|
7829
|
+
)
|
|
7830
|
+
);
|
|
7831
|
+
continue;
|
|
7832
|
+
}
|
|
7833
|
+
const profile = deps.config.pi.model_profiles.find((item) => item.id === requestedProfileId);
|
|
7834
|
+
if (!profile) {
|
|
7835
|
+
return {
|
|
7836
|
+
ok: false,
|
|
7837
|
+
code: "invalid_model_profile",
|
|
7838
|
+
message: `Unknown model profile '${requestedProfileId}'`
|
|
7839
|
+
};
|
|
7840
|
+
}
|
|
7841
|
+
const provider = deps.registry.require(profile.provider);
|
|
7842
|
+
const retainedProviderId = previousProviderId(deps, retainedState);
|
|
7843
|
+
const recoveryOptions = explicitProviderOptions ? { ...explicitProviderOptions } : retainedProviderId !== null && retainedProviderId !== provider.id ? {
|
|
7844
|
+
...filterProviderOptionsForDefinition(provider.definition.options, retainedOptions)
|
|
7845
|
+
} : retainedOptions;
|
|
7846
|
+
const optionResult = resolveRegisteredProviderOptions({
|
|
7847
|
+
provider,
|
|
7848
|
+
explicit: recoveryOptions,
|
|
7849
|
+
profileDefaults: profile.provider_options ?? {}
|
|
7850
|
+
});
|
|
7851
|
+
if (!optionResult.ok) {
|
|
7852
|
+
const onlyRequired = optionResult.issues.every((issue2) => issue2.code === "required");
|
|
7853
|
+
if (!onlyRequired) {
|
|
7854
|
+
return {
|
|
7855
|
+
ok: false,
|
|
7856
|
+
code: "invalid_provider_options",
|
|
7857
|
+
message: optionResult.issues.map((issue2) => issue2.message).join("; ")
|
|
7858
|
+
};
|
|
7859
|
+
}
|
|
7860
|
+
parkPreparationFailure(
|
|
7861
|
+
writes,
|
|
7862
|
+
write,
|
|
7863
|
+
failure(
|
|
7864
|
+
profile.id,
|
|
7865
|
+
recoveryOptions,
|
|
7866
|
+
"provider_options_required",
|
|
7867
|
+
optionResult.issues.map((issue2) => issue2.message).join("; ")
|
|
7868
|
+
)
|
|
7869
|
+
);
|
|
7870
|
+
continue;
|
|
7871
|
+
}
|
|
7872
|
+
const status = availability.profiles.find((candidate2) => candidate2.profileId === profile.id);
|
|
7873
|
+
if (!status || status.availability !== "available") {
|
|
7874
|
+
parkPreparationFailure(
|
|
7875
|
+
writes,
|
|
7876
|
+
write,
|
|
7877
|
+
failure(
|
|
7878
|
+
profile.id,
|
|
7879
|
+
recoveryOptions,
|
|
7880
|
+
!status || status.availability === "stale" ? "model_stale" : "model_unavailable",
|
|
7881
|
+
status?.safeReason ?? "The selected model status is stale",
|
|
7882
|
+
provenance,
|
|
7883
|
+
availability.revision
|
|
7884
|
+
)
|
|
7885
|
+
);
|
|
7886
|
+
continue;
|
|
7887
|
+
}
|
|
7888
|
+
try {
|
|
7889
|
+
const runtimeProfile = resolveRuntimeProfile(deps, nextProcess);
|
|
7890
|
+
if (!runtimeProfile.ok) throw new Error(runtimeProfile.message);
|
|
7891
|
+
const providerWorkerConfig = resolveProviderWorkerConfig(provider, optionResult.value);
|
|
7892
|
+
const piSettings = buildPiSettings(deps.config);
|
|
7893
|
+
const model = {
|
|
7894
|
+
profileId: profile.id,
|
|
7895
|
+
providerId: profile.provider,
|
|
7896
|
+
modelId: profile.model_id,
|
|
7897
|
+
thinkingLevel: profile.thinking_level ?? "off"
|
|
7898
|
+
};
|
|
7899
|
+
const resourceLayers = deps.processSkills.listResourceLayers(nextProcess.id);
|
|
7900
|
+
const assembled = await assemblePiResourceSnapshot({
|
|
7901
|
+
resourceLayers,
|
|
7902
|
+
piContributions: deps.piContributions,
|
|
7903
|
+
model,
|
|
7904
|
+
providerOptions: optionResult.value,
|
|
7905
|
+
providerWorkerConfig,
|
|
7906
|
+
piSettings,
|
|
7907
|
+
piModels: resolveProviderPiModels(provider),
|
|
7908
|
+
declaredCredentialPaths: [
|
|
7909
|
+
"auth.json",
|
|
7910
|
+
...provider.definition.worker.kind === "extension_pi_worker" ? provider.definition.worker.credentialFiles ?? [] : []
|
|
7911
|
+
],
|
|
7912
|
+
compatibility: {
|
|
7913
|
+
workerApiVersion: WORKER_API_VERSION,
|
|
7914
|
+
piVersion: PI_RUNTIME_VERSION,
|
|
7915
|
+
protocolVersion: IPC_PROTOCOL_VERSION
|
|
7916
|
+
}
|
|
7917
|
+
});
|
|
7918
|
+
deps.bundleCache.put(assembled.bundle);
|
|
7919
|
+
write.input.state = {
|
|
7920
|
+
kind: "starting",
|
|
7921
|
+
start: {
|
|
7922
|
+
kind: "llm",
|
|
7923
|
+
model,
|
|
7924
|
+
...provenance ? { modelSelectionProvenance: provenance } : {},
|
|
7925
|
+
availabilityRevision: availability.revision,
|
|
7926
|
+
providerOptions: { ...optionResult.value },
|
|
7927
|
+
providerWorkerConfig,
|
|
7928
|
+
piResourceSnapshotDigest: assembled.bundle.digest,
|
|
7929
|
+
workerRuntimeProfileId: runtimeProfile.id,
|
|
7930
|
+
piSettings
|
|
7931
|
+
}
|
|
7932
|
+
};
|
|
7933
|
+
writes.processPatch.lifecycleStatus = "active";
|
|
7934
|
+
writes.workerIntent = { kind: "restart_worker" };
|
|
7935
|
+
} catch {
|
|
7936
|
+
parkPreparationFailure(
|
|
7937
|
+
writes,
|
|
7938
|
+
write,
|
|
7939
|
+
failure(
|
|
7940
|
+
profile.id,
|
|
7941
|
+
{ ...optionResult.value },
|
|
7942
|
+
"provider_preflight_failed",
|
|
7943
|
+
"The provider could not prepare this worker start"
|
|
7944
|
+
)
|
|
7945
|
+
);
|
|
7946
|
+
}
|
|
7947
|
+
}
|
|
7948
|
+
return { ok: true };
|
|
7949
|
+
}
|
|
7950
|
+
|
|
7207
7951
|
// src/process-operation-coordinator.ts
|
|
7208
7952
|
function createProcessOperationCoordinator() {
|
|
7209
7953
|
const tails = /* @__PURE__ */ new Map();
|
|
@@ -7234,7 +7978,7 @@ import {
|
|
|
7234
7978
|
stat,
|
|
7235
7979
|
unlink
|
|
7236
7980
|
} from "node:fs/promises";
|
|
7237
|
-
import
|
|
7981
|
+
import path3 from "node:path";
|
|
7238
7982
|
import { atomicWriteUtf8, isEnoent } from "@leitwerk-dev/process-sdk";
|
|
7239
7983
|
|
|
7240
7984
|
// src/pi-session-tree.ts
|
|
@@ -7365,12 +8109,14 @@ function deriveParsedInstanceTree(tree) {
|
|
|
7365
8109
|
|
|
7366
8110
|
// src/process-session-store.ts
|
|
7367
8111
|
var ProcessSessionReader = class {
|
|
8112
|
+
/** @internal */
|
|
7368
8113
|
constructor(source) {
|
|
7369
8114
|
this.source = source;
|
|
7370
8115
|
}
|
|
7371
8116
|
source;
|
|
7372
8117
|
sessionTreeCache = /* @__PURE__ */ new Map();
|
|
7373
8118
|
inFlightReads = /* @__PURE__ */ new Map();
|
|
8119
|
+
/** @internal */
|
|
7374
8120
|
async readSessionTree(instanceId) {
|
|
7375
8121
|
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
7376
8122
|
const handle = await this.source.readSnapshotHandle(instanceId);
|
|
@@ -7397,9 +8143,11 @@ var ProcessSessionReader = class {
|
|
|
7397
8143
|
}
|
|
7398
8144
|
throw new Error(`Unable to read process session snapshot '${instanceId}'`);
|
|
7399
8145
|
}
|
|
8146
|
+
/** @internal */
|
|
7400
8147
|
async readInstanceTree(instanceId) {
|
|
7401
8148
|
return (await this.readSessionTree(instanceId)).parsedTree;
|
|
7402
8149
|
}
|
|
8150
|
+
/** @internal */
|
|
7403
8151
|
async readPiSessionTree(instanceId) {
|
|
7404
8152
|
return (await this.readSessionTree(instanceId)).piTree;
|
|
7405
8153
|
}
|
|
@@ -7425,7 +8173,7 @@ var ProcessSessionReader = class {
|
|
|
7425
8173
|
this.inFlightReads.set(cacheKey, promise);
|
|
7426
8174
|
return promise;
|
|
7427
8175
|
}
|
|
7428
|
-
/** Returns the raw session JSONL, or `null` when no session exists yet. */
|
|
8176
|
+
/** Returns the raw session JSONL, or `null` when no session exists yet. @internal */
|
|
7429
8177
|
async readRawContent(instanceId) {
|
|
7430
8178
|
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
7431
8179
|
const handle = await this.source.readSnapshotHandle(instanceId);
|
|
@@ -7454,13 +8202,13 @@ function assertSafeSessionInstanceId(instanceId) {
|
|
|
7454
8202
|
}
|
|
7455
8203
|
function resolveSessionSnapshotPath(rootDir, instanceId) {
|
|
7456
8204
|
assertSafeSessionInstanceId(instanceId);
|
|
7457
|
-
return
|
|
8205
|
+
return path3.join(rootDir, `${instanceId}.jsonl`);
|
|
7458
8206
|
}
|
|
7459
8207
|
async function atomicCopyFile(sourcePath, targetPath) {
|
|
7460
|
-
await mkdir(
|
|
7461
|
-
const tempPath =
|
|
7462
|
-
|
|
7463
|
-
`.${
|
|
8208
|
+
await mkdir(path3.dirname(targetPath), { recursive: true });
|
|
8209
|
+
const tempPath = path3.join(
|
|
8210
|
+
path3.dirname(targetPath),
|
|
8211
|
+
`.${path3.basename(targetPath)}.${randomUUID()}.tmp`
|
|
7464
8212
|
);
|
|
7465
8213
|
try {
|
|
7466
8214
|
await copyFile(sourcePath, tempPath);
|
|
@@ -7503,7 +8251,7 @@ async function loadSnapshotGeneration(treeFile, expectedSignature) {
|
|
|
7503
8251
|
}
|
|
7504
8252
|
}
|
|
7505
8253
|
function createFileBackedProcessSessionSnapshotStore(treeFilesDir) {
|
|
7506
|
-
const rootDir =
|
|
8254
|
+
const rootDir = path3.resolve(treeFilesDir);
|
|
7507
8255
|
const resolveTreeFile = (instanceId) => resolveSessionSnapshotPath(rootDir, instanceId);
|
|
7508
8256
|
return {
|
|
7509
8257
|
async readSnapshotHandle(instanceId) {
|
|
@@ -7933,9 +8681,20 @@ function buildTurnTraceIndexFromSession(input) {
|
|
|
7933
8681
|
return traces;
|
|
7934
8682
|
}
|
|
7935
8683
|
|
|
8684
|
+
// src/session-transfer-service.ts
|
|
8685
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
8686
|
+
import path5 from "node:path";
|
|
8687
|
+
import { Transform } from "node:stream";
|
|
8688
|
+
import { pipeline } from "node:stream/promises";
|
|
8689
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
8690
|
+
import {
|
|
8691
|
+
DEFAULT_SESSION_TRANSFER_LIMITS as DEFAULT_SESSION_TRANSFER_LIMITS2,
|
|
8692
|
+
parsePiSessionHeader
|
|
8693
|
+
} from "@leitwerk-dev/session-transfer";
|
|
8694
|
+
|
|
7936
8695
|
// src/supervisor/worker-storage-layout.ts
|
|
7937
8696
|
import { existsSync as existsSync3, mkdirSync as mkdirSync2 } from "node:fs";
|
|
7938
|
-
import
|
|
8697
|
+
import path4 from "node:path";
|
|
7939
8698
|
import { expandPiAgentDir } from "@leitwerk-dev/process-sdk/pi-config";
|
|
7940
8699
|
function normalizeContainerMountPath(mountPath) {
|
|
7941
8700
|
const trimmed = mountPath.trim();
|
|
@@ -7943,18 +8702,18 @@ function normalizeContainerMountPath(mountPath) {
|
|
|
7943
8702
|
return "/state";
|
|
7944
8703
|
}
|
|
7945
8704
|
const withLeadingSlash = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
7946
|
-
return
|
|
8705
|
+
return path4.posix.normalize(withLeadingSlash);
|
|
7947
8706
|
}
|
|
7948
8707
|
function joinContainerPath(mountPath, ...segments) {
|
|
7949
8708
|
const normalized = normalizeContainerMountPath(mountPath);
|
|
7950
|
-
return
|
|
8709
|
+
return path4.posix.join(normalized, ...segments);
|
|
7951
8710
|
}
|
|
7952
8711
|
function createLocalWorkerStorageLayout(input) {
|
|
7953
8712
|
return (instanceId) => {
|
|
7954
|
-
const processWorkspacesDir =
|
|
7955
|
-
const treeFilesDir =
|
|
7956
|
-
const workspaceRoot =
|
|
7957
|
-
const primaryTreeFile =
|
|
8713
|
+
const processWorkspacesDir = path4.resolve(input.processWorkspacesDir);
|
|
8714
|
+
const treeFilesDir = path4.resolve(input.treeFilesDir);
|
|
8715
|
+
const workspaceRoot = path4.join(processWorkspacesDir, instanceId);
|
|
8716
|
+
const primaryTreeFile = path4.join(treeFilesDir, `${instanceId}.jsonl`);
|
|
7958
8717
|
const resume = existsSync3(workspaceRoot) || existsSync3(primaryTreeFile);
|
|
7959
8718
|
mkdirSync2(processWorkspacesDir, { recursive: true });
|
|
7960
8719
|
mkdirSync2(treeFilesDir, { recursive: true });
|
|
@@ -7962,7 +8721,7 @@ function createLocalWorkerStorageLayout(input) {
|
|
|
7962
8721
|
return {
|
|
7963
8722
|
primaryTreeFile,
|
|
7964
8723
|
workspaceRoot,
|
|
7965
|
-
piResourceBundlesDir:
|
|
8724
|
+
piResourceBundlesDir: path4.join(workspaceRoot, ".leitwerk", "pi-resource-bundles"),
|
|
7966
8725
|
resume
|
|
7967
8726
|
};
|
|
7968
8727
|
};
|
|
@@ -7997,15 +8756,6 @@ function createWorkerStorageLayout(config) {
|
|
|
7997
8756
|
}
|
|
7998
8757
|
|
|
7999
8758
|
// src/session-transfer-service.ts
|
|
8000
|
-
import { createHash as createHash3 } from "node:crypto";
|
|
8001
|
-
import path4 from "node:path";
|
|
8002
|
-
import { Transform } from "node:stream";
|
|
8003
|
-
import { pipeline } from "node:stream/promises";
|
|
8004
|
-
import { setTimeout as delay } from "node:timers/promises";
|
|
8005
|
-
import {
|
|
8006
|
-
DEFAULT_SESSION_TRANSFER_LIMITS as DEFAULT_SESSION_TRANSFER_LIMITS2,
|
|
8007
|
-
parsePiSessionHeader
|
|
8008
|
-
} from "@leitwerk-dev/session-transfer";
|
|
8009
8759
|
var GRANT_LIFETIME_MS = 60 * 60 * 1e3;
|
|
8010
8760
|
var ATTEMPT_LEASE_MS = 90 * 1e3;
|
|
8011
8761
|
var ATTEMPT_HARD_DEADLINE_MS = 60 * 60 * 1e3;
|
|
@@ -8022,17 +8772,18 @@ function presentSessionTransferOperation(attempt) {
|
|
|
8022
8772
|
}
|
|
8023
8773
|
function relativeSessionCwd(input) {
|
|
8024
8774
|
if (!input.repositoryBacked) return null;
|
|
8025
|
-
const relative =
|
|
8775
|
+
const relative = path5.relative(path5.resolve(input.workspaceRoot), path5.resolve(input.sourceCwd));
|
|
8026
8776
|
if (relative === "") return ".";
|
|
8027
|
-
if (relative === ".." || relative.startsWith(`..${
|
|
8777
|
+
if (relative === ".." || relative.startsWith(`..${path5.sep}`) || path5.isAbsolute(relative)) {
|
|
8028
8778
|
throw new Error("Repository-backed Pi session cwd is outside the process workspace");
|
|
8029
8779
|
}
|
|
8030
|
-
return relative.split(
|
|
8780
|
+
return relative.split(path5.sep).join("/");
|
|
8031
8781
|
}
|
|
8032
8782
|
function createSessionTransferService(deps) {
|
|
8033
8783
|
const now2 = deps.now ?? (() => /* @__PURE__ */ new Date());
|
|
8034
8784
|
const limits = deps.limits ?? DEFAULT_SESSION_TRANSFER_LIMITS2;
|
|
8035
8785
|
const runtimes = /* @__PURE__ */ new Map();
|
|
8786
|
+
const exportWork = /* @__PURE__ */ new Set();
|
|
8036
8787
|
let sweepTimer = null;
|
|
8037
8788
|
function publish(attempt) {
|
|
8038
8789
|
if (attempt && deps.onUpdated) {
|
|
@@ -8107,7 +8858,7 @@ function createSessionTransferService(deps) {
|
|
|
8107
8858
|
streamClaimed: false
|
|
8108
8859
|
};
|
|
8109
8860
|
runtimes.set(attempt.id, runtime);
|
|
8110
|
-
|
|
8861
|
+
const work = (async () => {
|
|
8111
8862
|
updatePhase(attempt.id, "waiting_for_execution_chain");
|
|
8112
8863
|
while (true) {
|
|
8113
8864
|
const reserved = await deps.processOperations.runExclusive(attempt.instanceId, () => {
|
|
@@ -8161,6 +8912,11 @@ function createSessionTransferService(deps) {
|
|
|
8161
8912
|
runtimes.delete(attempt.id);
|
|
8162
8913
|
}
|
|
8163
8914
|
});
|
|
8915
|
+
exportWork.add(work);
|
|
8916
|
+
void work.then(
|
|
8917
|
+
() => exportWork.delete(work),
|
|
8918
|
+
() => exportWork.delete(work)
|
|
8919
|
+
);
|
|
8164
8920
|
}
|
|
8165
8921
|
function cancelAttempt(attempt, code) {
|
|
8166
8922
|
if (["consumed", "cancelled", "failed"].includes(attempt.phase)) return attempt;
|
|
@@ -8188,10 +8944,19 @@ function createSessionTransferService(deps) {
|
|
|
8188
8944
|
deps.repos.sessionTransfers.cleanup(now2());
|
|
8189
8945
|
}
|
|
8190
8946
|
return {
|
|
8947
|
+
/** @internal */
|
|
8191
8948
|
async createGrant(instanceId) {
|
|
8192
8949
|
return deps.processOperations.runExclusive(instanceId, async () => {
|
|
8193
|
-
if (deps.isDeletionPending?.(instanceId))
|
|
8194
|
-
|
|
8950
|
+
if (deps.isDeletionPending?.(instanceId))
|
|
8951
|
+
return {
|
|
8952
|
+
/** @internal */
|
|
8953
|
+
kind: "deletion_pending"
|
|
8954
|
+
};
|
|
8955
|
+
if (!deps.repos.processes.getById(instanceId))
|
|
8956
|
+
return {
|
|
8957
|
+
/** @internal */
|
|
8958
|
+
kind: "not_found"
|
|
8959
|
+
};
|
|
8195
8960
|
const handle = await deps.sessionSource.readSnapshotHandle(instanceId);
|
|
8196
8961
|
if (!handle) return { kind: "not_found" };
|
|
8197
8962
|
const created = deps.repos.sessionTransfers.createGrant({
|
|
@@ -8200,13 +8965,18 @@ function createSessionTransferService(deps) {
|
|
|
8200
8965
|
lifetimeMs: GRANT_LIFETIME_MS
|
|
8201
8966
|
});
|
|
8202
8967
|
return {
|
|
8968
|
+
/** @internal */
|
|
8203
8969
|
kind: "created",
|
|
8970
|
+
/** @internal */
|
|
8204
8971
|
grantId: created.grant.id,
|
|
8972
|
+
/** @internal */
|
|
8205
8973
|
rawToken: created.rawToken,
|
|
8974
|
+
/** @internal */
|
|
8206
8975
|
expiresAt: created.grant.expiresAt
|
|
8207
8976
|
};
|
|
8208
8977
|
});
|
|
8209
8978
|
},
|
|
8979
|
+
/** @internal */
|
|
8210
8980
|
startAttempt(input) {
|
|
8211
8981
|
if (deps.isDeletionPending?.(input.instanceId)) return { kind: "not_found" };
|
|
8212
8982
|
const result = deps.repos.transaction(
|
|
@@ -8223,6 +8993,7 @@ function createSessionTransferService(deps) {
|
|
|
8223
8993
|
}
|
|
8224
8994
|
return result;
|
|
8225
8995
|
},
|
|
8996
|
+
/** @internal */
|
|
8226
8997
|
heartbeat(input) {
|
|
8227
8998
|
const attempt = deps.repos.sessionTransfers.verifyAttempt(input);
|
|
8228
8999
|
if (!attempt) return null;
|
|
@@ -8230,6 +9001,7 @@ function createSessionTransferService(deps) {
|
|
|
8230
9001
|
if (current.phase === "cancelled" || current.phase === "failed") return current;
|
|
8231
9002
|
return deps.repos.sessionTransfers.renew(current.id, { now: now2(), leaseMs: ATTEMPT_LEASE_MS }) ?? current;
|
|
8232
9003
|
},
|
|
9004
|
+
/** @internal */
|
|
8233
9005
|
openStream(input) {
|
|
8234
9006
|
const attempt = deps.repos.sessionTransfers.verifyAttempt(input);
|
|
8235
9007
|
if (!attempt || deadlineCode(attempt)) {
|
|
@@ -8290,15 +9062,18 @@ function createSessionTransferService(deps) {
|
|
|
8290
9062
|
void pipeline(source, meter, { signal: runtime.controller.signal }).catch(() => void 0);
|
|
8291
9063
|
return meter;
|
|
8292
9064
|
},
|
|
9065
|
+
/** @internal */
|
|
8293
9066
|
cancel(input) {
|
|
8294
9067
|
const attempt = deps.repos.sessionTransfers.verifyAttempt(input);
|
|
8295
9068
|
return attempt ? cancelAttempt(attempt, input.code ?? "client_cancelled") : null;
|
|
8296
9069
|
},
|
|
9070
|
+
/** @internal */
|
|
8297
9071
|
cancelForWeb(instanceId, attemptId) {
|
|
8298
9072
|
const attempt = deps.repos.sessionTransfers.getAttempt(attemptId);
|
|
8299
9073
|
if (!attempt || attempt.instanceId !== instanceId) return null;
|
|
8300
9074
|
return attempt.phase === "awaiting_ack" ? attempt : cancelAttempt(attempt, "operator_cancelled");
|
|
8301
9075
|
},
|
|
9076
|
+
/** @internal */
|
|
8302
9077
|
acknowledge(input) {
|
|
8303
9078
|
const attempt = deps.repos.sessionTransfers.verifyAttempt(input);
|
|
8304
9079
|
if (!attempt) return null;
|
|
@@ -8316,14 +9091,17 @@ function createSessionTransferService(deps) {
|
|
|
8316
9091
|
);
|
|
8317
9092
|
return publish(acknowledged);
|
|
8318
9093
|
},
|
|
9094
|
+
/** @internal */
|
|
8319
9095
|
activeForProcess(instanceId) {
|
|
8320
9096
|
return deps.repos.sessionTransfers.getActiveByInstance(instanceId);
|
|
8321
9097
|
},
|
|
9098
|
+
/** @internal */
|
|
8322
9099
|
revokeProcess(instanceId) {
|
|
8323
9100
|
const active = deps.repos.sessionTransfers.getActiveByInstance(instanceId);
|
|
8324
9101
|
if (active) cancelAttempt(active, "process_deleted");
|
|
8325
9102
|
deps.repos.sessionTransfers.revokeProcess(instanceId);
|
|
8326
9103
|
},
|
|
9104
|
+
/** @internal */
|
|
8327
9105
|
async reconcile() {
|
|
8328
9106
|
await deps.exporter.reconcile();
|
|
8329
9107
|
for (const attempt of deps.repos.sessionTransfers.listActive()) {
|
|
@@ -8336,10 +9114,12 @@ function createSessionTransferService(deps) {
|
|
|
8336
9114
|
}
|
|
8337
9115
|
sweep();
|
|
8338
9116
|
},
|
|
9117
|
+
/** @internal */
|
|
8339
9118
|
start() {
|
|
8340
9119
|
if (!sweepTimer) sweepTimer = setInterval(sweep, 15e3);
|
|
8341
9120
|
},
|
|
8342
|
-
|
|
9121
|
+
/** @internal */
|
|
9122
|
+
async stop() {
|
|
8343
9123
|
if (sweepTimer) clearInterval(sweepTimer);
|
|
8344
9124
|
sweepTimer = null;
|
|
8345
9125
|
for (const runtime of runtimes.values()) {
|
|
@@ -8347,9 +9127,15 @@ function createSessionTransferService(deps) {
|
|
|
8347
9127
|
}
|
|
8348
9128
|
runtimes.clear();
|
|
8349
9129
|
deps.helperRelays.stop();
|
|
9130
|
+
const results = await Promise.allSettled(exportWork);
|
|
9131
|
+
const errors = results.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
9132
|
+
if (errors.length) throw new AggregateError(errors, "Session export cleanup failed");
|
|
8350
9133
|
},
|
|
9134
|
+
/** @internal */
|
|
8351
9135
|
helperSpec: deps.helperRelays.helperSpec,
|
|
9136
|
+
/** @internal */
|
|
8352
9137
|
reportHelperPreflight: deps.helperRelays.reportHelperPreflight,
|
|
9138
|
+
/** @internal */
|
|
8353
9139
|
acceptHelperStream: deps.helperRelays.acceptHelperStream
|
|
8354
9140
|
};
|
|
8355
9141
|
}
|
|
@@ -8743,20 +9529,20 @@ function presentLaunchPlanPreparationIssues(issues) {
|
|
|
8743
9529
|
message: issue2.message
|
|
8744
9530
|
}));
|
|
8745
9531
|
}
|
|
8746
|
-
function presentProcessModelPolicyFailure(
|
|
8747
|
-
switch (
|
|
9532
|
+
function presentProcessModelPolicyFailure(failure2) {
|
|
9533
|
+
switch (failure2.code) {
|
|
8748
9534
|
case "model_required":
|
|
8749
9535
|
return "Choose a model before starting this turn";
|
|
8750
9536
|
case "unknown_model_profile":
|
|
8751
|
-
return `Unknown model profile '${
|
|
9537
|
+
return `Unknown model profile '${failure2.modelProfileId}'`;
|
|
8752
9538
|
case "model_profile_not_allowed":
|
|
8753
|
-
return `Model profile '${
|
|
9539
|
+
return `Model profile '${failure2.modelProfileId}' is not allowed for process '${failure2.processId}'`;
|
|
8754
9540
|
case "model_stale":
|
|
8755
|
-
return
|
|
9541
|
+
return failure2.reason ?? "Model status has not been refreshed";
|
|
8756
9542
|
case "model_unavailable":
|
|
8757
|
-
return
|
|
9543
|
+
return failure2.reason ?? "The selected model is unavailable";
|
|
8758
9544
|
case "invalid_model_configuration":
|
|
8759
|
-
return
|
|
9545
|
+
return failure2.source === "selection_provenance" ? "Persisted model selection provenance is invalid" : "Persisted model configuration is invalid";
|
|
8760
9546
|
case "stale_evaluation_snapshot":
|
|
8761
9547
|
return "Model availability changed repeatedly during evaluation";
|
|
8762
9548
|
}
|
|
@@ -8806,9 +9592,9 @@ function presentProcessModelConfiguration(projection) {
|
|
|
8806
9592
|
|
|
8807
9593
|
// src/process-turn-navigation.ts
|
|
8808
9594
|
function presentProcessTurnNavigation(input) {
|
|
8809
|
-
const
|
|
8810
|
-
const currentIndex =
|
|
8811
|
-
const nextId = input.lifecycleStatus === "active" && currentIndex >= 0 ?
|
|
9595
|
+
const path6 = input.graph.happyPath ?? [];
|
|
9596
|
+
const currentIndex = path6.indexOf(input.selectedTurnId ?? "");
|
|
9597
|
+
const nextId = input.lifecycleStatus === "active" && currentIndex >= 0 ? path6[currentIndex + 1] : void 0;
|
|
8812
9598
|
const next = nextId ? input.graph.turns.get(nextId) : void 0;
|
|
8813
9599
|
return {
|
|
8814
9600
|
turns: input.turns.map((turn) => ({
|
|
@@ -9608,16 +10394,14 @@ function buildStartupEvidence(input) {
|
|
|
9608
10394
|
steps
|
|
9609
10395
|
};
|
|
9610
10396
|
});
|
|
9611
|
-
const
|
|
9612
|
-
|
|
9613
|
-
|
|
9614
|
-
return recoveryAttempt ? {
|
|
10397
|
+
const authoritative = attempts.find((attempt) => attempt.status === "succeeded");
|
|
10398
|
+
const recoveredAttempts = attempts.map(
|
|
10399
|
+
(attempt) => attempt.status === "failed" && authoritative ? {
|
|
9615
10400
|
...attempt,
|
|
9616
10401
|
status: "recovered",
|
|
9617
|
-
recoveredByStartRecordId:
|
|
9618
|
-
} : attempt
|
|
9619
|
-
|
|
9620
|
-
const authoritative = recoveredAttempts.findLast((attempt) => attempt.status === "succeeded");
|
|
10402
|
+
recoveredByStartRecordId: authoritative.startRecordId
|
|
10403
|
+
} : attempt
|
|
10404
|
+
);
|
|
9621
10405
|
const currentAttempt = (currentStartId ? recoveredAttempts.find((attempt) => attempt.startRecordId === currentStartId) : void 0) ?? recoveredAttempts.at(-1) ?? null;
|
|
9622
10406
|
return {
|
|
9623
10407
|
attempts: recoveredAttempts,
|
|
@@ -9661,38 +10445,22 @@ function projectLaunchRunStartup(run, evidence, titleState) {
|
|
|
9661
10445
|
let next = run;
|
|
9662
10446
|
const attempt = evidence.currentAttempt;
|
|
9663
10447
|
if (!wasFailed) {
|
|
9664
|
-
for (const id of [
|
|
9665
|
-
"start_worker",
|
|
9666
|
-
"connect_worker",
|
|
9667
|
-
"prepare_workspace",
|
|
9668
|
-
"start_first_turn"
|
|
9669
|
-
]) {
|
|
9670
|
-
const step = attempt?.steps.find((candidate2) => candidate2.id === id);
|
|
9671
|
-
if (!step) {
|
|
9672
|
-
const existing = next.steps.find((candidate2) => candidate2.id === id);
|
|
9673
|
-
if (existing?.status !== "skipped") next = projectStep(next, id, "pending", null);
|
|
9674
|
-
continue;
|
|
9675
|
-
}
|
|
9676
|
-
const status = step.status === "superseded" ? "pending" : step.status;
|
|
9677
|
-
next = projectStep(
|
|
9678
|
-
next,
|
|
9679
|
-
id,
|
|
9680
|
-
status,
|
|
9681
|
-
step.occurredAt,
|
|
9682
|
-
status === "failed" ? attempt?.summary ?? "Worker startup stopped before completion. Retry startup from the process page." : id === "start_worker" && attempt?.summary ? attempt.summary : void 0
|
|
9683
|
-
);
|
|
9684
|
-
}
|
|
9685
10448
|
next = {
|
|
9686
10449
|
...next,
|
|
9687
10450
|
steps: next.steps.map((item) => {
|
|
10451
|
+
if (!Object.hasOwn(STARTUP_STEP_LABELS, item.id)) return item;
|
|
9688
10452
|
const phase = attempt?.steps.find((candidate2) => candidate2.id === item.id);
|
|
9689
|
-
if (!phase) return item;
|
|
9690
|
-
const { startedAt: _start, completedAt: _end, ...rest } = item;
|
|
10453
|
+
if (!phase && item.status === "skipped") return item;
|
|
10454
|
+
const { startedAt: _start, completedAt: _end, safeSummary: _summary, ...rest } = item;
|
|
10455
|
+
const status = !phase || phase.status === "superseded" ? "pending" : phase.status;
|
|
10456
|
+
const safeSummary = status === "failed" ? attempt?.summary ?? "Worker startup stopped before completion. Retry startup from the process page." : item.id === "start_worker" ? attempt?.summary : void 0;
|
|
9691
10457
|
return {
|
|
9692
10458
|
...rest,
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
...phase
|
|
10459
|
+
status,
|
|
10460
|
+
label: phase?.label ?? item.label,
|
|
10461
|
+
...phase?.startedAt ? { startedAt: phase.startedAt } : {},
|
|
10462
|
+
...phase?.endedAt ? { completedAt: phase.endedAt } : {},
|
|
10463
|
+
...phase && safeSummary ? { safeSummary } : {}
|
|
9696
10464
|
};
|
|
9697
10465
|
})
|
|
9698
10466
|
};
|
|
@@ -10171,13 +10939,13 @@ function setupDetail(event) {
|
|
|
10171
10939
|
return null;
|
|
10172
10940
|
}
|
|
10173
10941
|
const provider = asRecord(event.data.provider) ?? {};
|
|
10174
|
-
const
|
|
10942
|
+
const path6 = stringValueOrNull(event.data.path) ?? stringValueOrNull(provider.path);
|
|
10175
10943
|
const pollInterval = stringValueOrNull(event.data.pollInterval) ?? stringValueOrNull(provider.pollInterval);
|
|
10176
|
-
if (
|
|
10177
|
-
return `Watching ${
|
|
10944
|
+
if (path6 && pollInterval) {
|
|
10945
|
+
return `Watching ${path6} \xB7 polling every ${pollInterval}.`;
|
|
10178
10946
|
}
|
|
10179
|
-
if (
|
|
10180
|
-
return `Watching ${
|
|
10947
|
+
if (path6) {
|
|
10948
|
+
return `Watching ${path6}.`;
|
|
10181
10949
|
}
|
|
10182
10950
|
if (pollInterval) {
|
|
10183
10951
|
return `Polling every ${pollInterval}.`;
|
|
@@ -10442,10 +11210,15 @@ function buildProcessUiSnapshotProjections(input) {
|
|
|
10442
11210
|
observations: input.startupObservations ?? []
|
|
10443
11211
|
});
|
|
10444
11212
|
return {
|
|
11213
|
+
/** @internal */
|
|
10445
11214
|
process: projectProcessForUiSnapshot(input.process),
|
|
11215
|
+
/** @internal */
|
|
10446
11216
|
primaryPath: compactPrimaryPathSnapshot(input.primaryPathSnapshot),
|
|
11217
|
+
/** @internal */
|
|
10447
11218
|
timeline: {
|
|
11219
|
+
/** @internal */
|
|
10448
11220
|
prompt,
|
|
11221
|
+
/** @internal */
|
|
10449
11222
|
turns: presentProcessTimelineTurns({
|
|
10450
11223
|
process: input.process,
|
|
10451
11224
|
turnRecords: input.turnRecords,
|
|
@@ -10456,23 +11229,31 @@ function buildProcessUiSnapshotProjections(input) {
|
|
|
10456
11229
|
selectedTurnType: input.selectedTurn?.kind ?? null,
|
|
10457
11230
|
activeModelProfileId: input.activeModelProfileId
|
|
10458
11231
|
}),
|
|
11232
|
+
/** @internal */
|
|
10459
11233
|
tracePreviewsByTurnRecordId,
|
|
11234
|
+
/** @internal */
|
|
10460
11235
|
inputs: input.inputs.map(buildTimelineInputSummary),
|
|
11236
|
+
/** @internal */
|
|
10461
11237
|
externalTriggerSignals: buildExternalTriggerSignals({
|
|
10462
11238
|
externalTriggers: input.selectedTurn?.externalTriggers ?? [],
|
|
10463
11239
|
events: input.events,
|
|
10464
11240
|
isWaitingForSelectedTurn: input.process.lifecycleStatus === "waiting" && (input.selectedTurn?.turnId ?? null) === (input.process.selectedTurnId ?? null)
|
|
10465
11241
|
})
|
|
10466
11242
|
},
|
|
11243
|
+
/** @internal */
|
|
10467
11244
|
recovery,
|
|
11245
|
+
/** @internal */
|
|
10468
11246
|
startup,
|
|
11247
|
+
/** @internal */
|
|
10469
11248
|
startupRecovery: startup.recovery,
|
|
11249
|
+
/** @internal */
|
|
10470
11250
|
processError: buildCurrentProcessError({
|
|
10471
11251
|
process: input.process,
|
|
10472
11252
|
events: input.events,
|
|
10473
11253
|
selectedTurnDescription: input.selectedTurn?.description ?? null,
|
|
10474
11254
|
currentTurnRecovery: recovery
|
|
10475
11255
|
}),
|
|
11256
|
+
/** @internal */
|
|
10476
11257
|
usageEstimate: buildUsageEstimate({
|
|
10477
11258
|
turnRecords: input.turnRecords,
|
|
10478
11259
|
activeTurn,
|
|
@@ -11037,7 +11818,146 @@ function createBroadcaster() {
|
|
|
11037
11818
|
});
|
|
11038
11819
|
broadcast(frame);
|
|
11039
11820
|
}
|
|
11040
|
-
return {
|
|
11821
|
+
return {
|
|
11822
|
+
/** @internal */
|
|
11823
|
+
addClient,
|
|
11824
|
+
/** @internal */
|
|
11825
|
+
broadcast,
|
|
11826
|
+
/** @internal */
|
|
11827
|
+
sendDurable,
|
|
11828
|
+
/** @internal */
|
|
11829
|
+
sendEphemeral
|
|
11830
|
+
};
|
|
11831
|
+
}
|
|
11832
|
+
|
|
11833
|
+
// src/process-engine/writes/writes.ts
|
|
11834
|
+
import {
|
|
11835
|
+
CONTINUE_PROMPT_METADATA_KEY as CONTINUE_PROMPT_METADATA_KEY2,
|
|
11836
|
+
FAILED_TURN_RECOVERY_METADATA_KEY,
|
|
11837
|
+
SYSTEM_ACTOR as SYSTEM_ACTOR2
|
|
11838
|
+
} from "@leitwerk-dev/domain";
|
|
11839
|
+
var METADATA_KEY_GROUPS = {
|
|
11840
|
+
retry: ["retryForkPiEntryId", "retryFromTurnRecordId"],
|
|
11841
|
+
continuation: [
|
|
11842
|
+
"continueFromPiEntryId",
|
|
11843
|
+
"continueFromTurnRecordId",
|
|
11844
|
+
"continueSavedPrimaryLeafEntryId",
|
|
11845
|
+
CONTINUE_PROMPT_METADATA_KEY2,
|
|
11846
|
+
FAILED_TURN_RECOVERY_METADATA_KEY
|
|
11847
|
+
]
|
|
11848
|
+
};
|
|
11849
|
+
function createWrites(init = {}) {
|
|
11850
|
+
return {
|
|
11851
|
+
processPatch: init.processPatch ?? {},
|
|
11852
|
+
changedFields: [...init.changedFields ?? []],
|
|
11853
|
+
...init.projectWrite ? { projectWrite: init.projectWrite } : {},
|
|
11854
|
+
turnRecordWrites: [...init.turnRecordWrites ?? []],
|
|
11855
|
+
turnStartWrites: [...init.turnStartWrites ?? []],
|
|
11856
|
+
turnAnnotationWrites: [...init.turnAnnotationWrites ?? []],
|
|
11857
|
+
leafOutcomeSnapshotWrites: [...init.leafOutcomeSnapshotWrites ?? []],
|
|
11858
|
+
events: [...init.events ?? []],
|
|
11859
|
+
broadcasts: [...init.broadcasts ?? []],
|
|
11860
|
+
queuedInputs: [...init.queuedInputs ?? []],
|
|
11861
|
+
extensionEvents: [...init.extensionEvents ?? []],
|
|
11862
|
+
futureExecutionPlans: [...init.futureExecutionPlans ?? []],
|
|
11863
|
+
pendingExternalSourceFireWrites: [...init.pendingExternalSourceFireWrites ?? []],
|
|
11864
|
+
...init.workerIntent ? { workerIntent: init.workerIntent } : {}
|
|
11865
|
+
};
|
|
11866
|
+
}
|
|
11867
|
+
function mergeWrites(...writesList) {
|
|
11868
|
+
const merged = createWrites();
|
|
11869
|
+
for (const writes of writesList) {
|
|
11870
|
+
if (!writes) continue;
|
|
11871
|
+
Object.assign(merged.processPatch, writes.processPatch);
|
|
11872
|
+
for (const field of writes.changedFields) {
|
|
11873
|
+
if (!merged.changedFields.includes(field)) {
|
|
11874
|
+
merged.changedFields.push(field);
|
|
11875
|
+
}
|
|
11876
|
+
}
|
|
11877
|
+
if (writes.projectWrite) {
|
|
11878
|
+
if (merged.projectWrite) throw new Error("Cannot merge multiple process-project writes");
|
|
11879
|
+
merged.projectWrite = writes.projectWrite;
|
|
11880
|
+
}
|
|
11881
|
+
merged.turnRecordWrites.push(...writes.turnRecordWrites);
|
|
11882
|
+
merged.turnStartWrites.push(...writes.turnStartWrites);
|
|
11883
|
+
merged.turnAnnotationWrites.push(...writes.turnAnnotationWrites);
|
|
11884
|
+
merged.leafOutcomeSnapshotWrites.push(...writes.leafOutcomeSnapshotWrites);
|
|
11885
|
+
merged.events.push(...writes.events);
|
|
11886
|
+
merged.broadcasts.push(...writes.broadcasts);
|
|
11887
|
+
merged.queuedInputs.push(...writes.queuedInputs);
|
|
11888
|
+
merged.extensionEvents.push(...writes.extensionEvents);
|
|
11889
|
+
merged.futureExecutionPlans.push(...writes.futureExecutionPlans);
|
|
11890
|
+
merged.pendingExternalSourceFireWrites.push(...writes.pendingExternalSourceFireWrites);
|
|
11891
|
+
if (writes.workerIntent) {
|
|
11892
|
+
merged.workerIntent = writes.workerIntent;
|
|
11893
|
+
}
|
|
11894
|
+
}
|
|
11895
|
+
return merged;
|
|
11896
|
+
}
|
|
11897
|
+
function isWriteBuildFailure(value) {
|
|
11898
|
+
return typeof value === "object" && value !== null && "ok" in value && value.ok === false;
|
|
11899
|
+
}
|
|
11900
|
+
function applyProcessPatchField(writes, process2, field, value) {
|
|
11901
|
+
if (process2[field] === value) {
|
|
11902
|
+
return;
|
|
11903
|
+
}
|
|
11904
|
+
writes.processPatch[field] = value;
|
|
11905
|
+
if (!writes.changedFields.includes(field)) {
|
|
11906
|
+
writes.changedFields.push(field);
|
|
11907
|
+
}
|
|
11908
|
+
}
|
|
11909
|
+
function applyMetadataPatch(writes, process2, nextMetadata) {
|
|
11910
|
+
if (JSON.stringify(process2.metadata ?? null) === JSON.stringify(nextMetadata)) {
|
|
11911
|
+
return;
|
|
11912
|
+
}
|
|
11913
|
+
writes.processPatch.metadata = nextMetadata;
|
|
11914
|
+
if (!writes.changedFields.includes("metadata")) {
|
|
11915
|
+
writes.changedFields.push("metadata");
|
|
11916
|
+
}
|
|
11917
|
+
}
|
|
11918
|
+
function updateProcessMetadata(writes, process2, clearGroups = [], update = () => {
|
|
11919
|
+
}) {
|
|
11920
|
+
const nextMetadata = process2.metadata ? { ...process2.metadata } : {};
|
|
11921
|
+
for (const group of clearGroups) {
|
|
11922
|
+
for (const key of METADATA_KEY_GROUPS[group]) delete nextMetadata[key];
|
|
11923
|
+
}
|
|
11924
|
+
update(nextMetadata);
|
|
11925
|
+
applyMetadataPatch(writes, process2, Object.keys(nextMetadata).length > 0 ? nextMetadata : null);
|
|
11926
|
+
}
|
|
11927
|
+
function appendProcessEvent(writes, process2, input) {
|
|
11928
|
+
writes.events.push({
|
|
11929
|
+
instanceId: process2.id,
|
|
11930
|
+
eventType: input.eventType,
|
|
11931
|
+
...input.data ? { data: input.data } : {}
|
|
11932
|
+
});
|
|
11933
|
+
writes.broadcasts.push({
|
|
11934
|
+
type: "process.event",
|
|
11935
|
+
payload: {
|
|
11936
|
+
eventType: input.eventType,
|
|
11937
|
+
level: input.level,
|
|
11938
|
+
message: input.message
|
|
11939
|
+
},
|
|
11940
|
+
instanceId: process2.id
|
|
11941
|
+
});
|
|
11942
|
+
}
|
|
11943
|
+
function stampActorOnEvents(writes, actor, eventType) {
|
|
11944
|
+
const resolvedActor = actor ?? SYSTEM_ACTOR2;
|
|
11945
|
+
let stamped = 0;
|
|
11946
|
+
for (const event of writes.events) {
|
|
11947
|
+
if (event.eventType === eventType) {
|
|
11948
|
+
event.data = { ...event.data ?? {}, actor: resolvedActor };
|
|
11949
|
+
stamped += 1;
|
|
11950
|
+
}
|
|
11951
|
+
}
|
|
11952
|
+
return stamped;
|
|
11953
|
+
}
|
|
11954
|
+
function stampActorOnQueuedInputs(writes, actor) {
|
|
11955
|
+
if (!actor) {
|
|
11956
|
+
return;
|
|
11957
|
+
}
|
|
11958
|
+
writes.queuedInputs = writes.queuedInputs.map(
|
|
11959
|
+
(queuedInput) => queuedInput.actor ? queuedInput : { ...queuedInput, actor }
|
|
11960
|
+
);
|
|
11041
11961
|
}
|
|
11042
11962
|
|
|
11043
11963
|
export {
|
|
@@ -11055,61 +11975,34 @@ export {
|
|
|
11055
11975
|
resolveDockerRegistryCredentials,
|
|
11056
11976
|
resolveProcessStorageSize,
|
|
11057
11977
|
SAFE_SKILL_ID_PATTERN,
|
|
11058
|
-
applyConfigDefaults,
|
|
11059
11978
|
loadConfig,
|
|
11060
11979
|
validateConfig,
|
|
11061
11980
|
sanitizeConfigForLogging,
|
|
11062
11981
|
getDefaultConfig,
|
|
11063
11982
|
DatabaseSchemaMismatchError,
|
|
11064
|
-
initializeSchema,
|
|
11065
11983
|
createDatabase,
|
|
11066
11984
|
createInMemoryDatabase,
|
|
11067
11985
|
closeDatabase,
|
|
11068
|
-
createApiTokenRepo,
|
|
11069
11986
|
generateId,
|
|
11070
11987
|
now,
|
|
11071
|
-
createAuthSessionRepo,
|
|
11072
|
-
createAuthLoginFlowRepo,
|
|
11073
|
-
PROVIDER_CREDENTIAL_KEY_ENV,
|
|
11074
|
-
createUnavailableCredentialCipher,
|
|
11075
|
-
createCredentialCipherFromBase64,
|
|
11076
11988
|
createCredentialCipherFromEnvironment,
|
|
11077
|
-
createAes256GcmCredentialCipher,
|
|
11078
|
-
createExternalWriteLogRepo,
|
|
11079
|
-
createFutureExecutionRepo,
|
|
11080
|
-
createLaunchRunRepo,
|
|
11081
|
-
createLauncherRecentValueRepo,
|
|
11082
|
-
createPendingExternalSourceFireRepo,
|
|
11083
|
-
createProcessEventRepo,
|
|
11084
|
-
createProcessHandoffDedupKeyRepo,
|
|
11085
|
-
createProcessInputRepo,
|
|
11086
11989
|
truncateTextAtWordBoundary,
|
|
11087
11990
|
normalizeProcessTitleInput,
|
|
11088
11991
|
applySubmittedProcessTitleToLaunchPlan,
|
|
11089
|
-
createProcessInstanceRepo,
|
|
11090
|
-
createProcessLeafOutcomeSnapshotRepo,
|
|
11091
|
-
createProcessProjectRepo,
|
|
11092
|
-
createProcessQuestionRequestRepo,
|
|
11093
|
-
createProcessRelationRepo,
|
|
11094
11992
|
SKILL_RESOURCE_OWNER,
|
|
11095
|
-
compareResourcePaths,
|
|
11096
|
-
validatePhysicalSourcePath,
|
|
11097
11993
|
ResourceCollector,
|
|
11098
|
-
createProcessSkillRepo,
|
|
11099
|
-
createProcessTitleJobRepo,
|
|
11100
|
-
createProcessToolApprovalRequestRepo,
|
|
11101
|
-
createProcessTurnAnnotationRepo,
|
|
11102
|
-
createProcessTurnRecordRepo,
|
|
11103
|
-
createProviderCredentialRepo,
|
|
11104
|
-
createSessionTransferRepo,
|
|
11105
|
-
createSkillRepo,
|
|
11106
|
-
createTicketDestinationRecentRepo,
|
|
11107
|
-
createTurnStartRecordRepo,
|
|
11108
|
-
createWorkerLeaseRepo,
|
|
11109
11994
|
createAllRepos,
|
|
11110
11995
|
recordTurnProgress,
|
|
11111
11996
|
normalizeExternalEventDescription,
|
|
11112
11997
|
normalizeExternalObservation,
|
|
11998
|
+
createWrites,
|
|
11999
|
+
mergeWrites,
|
|
12000
|
+
isWriteBuildFailure,
|
|
12001
|
+
applyProcessPatchField,
|
|
12002
|
+
updateProcessMetadata,
|
|
12003
|
+
appendProcessEvent,
|
|
12004
|
+
stampActorOnEvents,
|
|
12005
|
+
stampActorOnQueuedInputs,
|
|
11113
12006
|
buildProcessFlowViewForProcess,
|
|
11114
12007
|
getProcessGraph2 as getProcessGraph,
|
|
11115
12008
|
getProcessTurnGraph,
|
|
@@ -11129,8 +12022,6 @@ export {
|
|
|
11129
12022
|
presentProcessModelConfiguration,
|
|
11130
12023
|
evaluateAtStableAvailabilityRevision,
|
|
11131
12024
|
createServerProcessModelPolicy,
|
|
11132
|
-
resolveTurnIntegrationToolNames,
|
|
11133
|
-
buildProcessActionRegistry,
|
|
11134
12025
|
resolveCurrentExecutionTurnRecordId,
|
|
11135
12026
|
presentPipelineResult,
|
|
11136
12027
|
finishLaunchRun,
|
|
@@ -11139,10 +12030,22 @@ export {
|
|
|
11139
12030
|
createLaunchPipeline,
|
|
11140
12031
|
buildStartupEvidence,
|
|
11141
12032
|
projectLaunchRunStartup,
|
|
12033
|
+
positiveBound,
|
|
12034
|
+
withTimeout,
|
|
12035
|
+
validateCredentialStatus,
|
|
12036
|
+
resolveRegisteredProviderOptions,
|
|
12037
|
+
validateConfiguredProviderOptions,
|
|
12038
|
+
loadProviderOptionChoices,
|
|
12039
|
+
createPiResourceBundleCache,
|
|
12040
|
+
createPiResourceBundlePinReconciler,
|
|
11142
12041
|
getProcessDisplayName,
|
|
11143
12042
|
listVisibleActionsForProcess,
|
|
11144
12043
|
getSelectedTurnSummaryForProcess,
|
|
11145
12044
|
broadcastProcessAttentionToast,
|
|
12045
|
+
defaultWorkerRuntimeProfile,
|
|
12046
|
+
selectWorkerRuntimeProfile,
|
|
12047
|
+
buildRuntimeProfileSelectionInput,
|
|
12048
|
+
prepareCreatedTurnStarts,
|
|
11146
12049
|
createProcessOperationCoordinator,
|
|
11147
12050
|
ProcessSessionReader,
|
|
11148
12051
|
isSafeSessionInstanceId,
|
|
@@ -11173,22 +12076,14 @@ export {
|
|
|
11173
12076
|
sendLauncherMutationResponse,
|
|
11174
12077
|
sendScheduledActionMutationResponse,
|
|
11175
12078
|
mergeProcessEventWindowsAscending,
|
|
11176
|
-
buildTurnTracePreview,
|
|
11177
12079
|
buildTurnTraceIndexFromSession,
|
|
11178
|
-
createLocalWorkerStorageLayout,
|
|
11179
|
-
createProcessVolumeWorkerStorageLayout,
|
|
11180
12080
|
resolveWorkerPiAgentDir,
|
|
11181
12081
|
createWorkerStorageLayout,
|
|
11182
12082
|
createSessionTransferService,
|
|
11183
|
-
presentProcessTimelineTurns,
|
|
11184
|
-
buildExternalTriggerSignals,
|
|
11185
|
-
buildCurrentTurnRecovery,
|
|
11186
|
-
buildCurrentProcessError,
|
|
11187
|
-
buildUsageEstimate,
|
|
11188
12083
|
buildProcessUiSnapshotProjections,
|
|
11189
12084
|
ProcessUiSnapshotAssembler,
|
|
11190
12085
|
buildPrimaryPathSnapshotFromTree,
|
|
11191
12086
|
createProjectedSessionSnapshotStore,
|
|
11192
12087
|
createBroadcaster
|
|
11193
12088
|
};
|
|
11194
|
-
//# sourceMappingURL=chunk-
|
|
12089
|
+
//# sourceMappingURL=chunk-KIOQNNG6.js.map
|