@leitwerk-dev/server 0.2.0 → 0.2.1
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-7PKX73TU.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-XTXH6623.js → chunk-CNITOV76.js} +1359 -991
- package/dist/chunk-CNITOV76.js.map +1 -0
- package/dist/{chunk-AGC2ND53.js → chunk-ZSKM25SD.js} +588 -667
- package/dist/chunk-ZSKM25SD.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 +17 -0
- package/dist/test-helpers/accepted-turn-start.d.ts.map +1 -1
- 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 +4 -7
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +2 -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 +28 -2
- 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 +4 -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-7PKX73TU.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
|
})
|
|
@@ -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 = [
|
|
@@ -7046,7 +6964,7 @@ function createLaunchPipeline(deps) {
|
|
|
7046
6964
|
|
|
7047
6965
|
// src/process-operator-attention.ts
|
|
7048
6966
|
import { trimToNull as trimToNull6 } from "@leitwerk-dev/domain";
|
|
7049
|
-
import { isHumanTurnDefinition
|
|
6967
|
+
import { isHumanTurnDefinition } from "@leitwerk-dev/process-sdk";
|
|
7050
6968
|
import {
|
|
7051
6969
|
createEphemeralWsFrame,
|
|
7052
6970
|
WS_PROCESS_TYPES
|
|
@@ -7133,7 +7051,7 @@ function selectedTurnRequiresActionAttention(deps, process2) {
|
|
|
7133
7051
|
process2.processId,
|
|
7134
7052
|
process2.selectedTurnId
|
|
7135
7053
|
);
|
|
7136
|
-
return !turnDef || !
|
|
7054
|
+
return !turnDef || !isHumanTurnDefinition(turnDef) || turnDef.operatorAttention !== "passive";
|
|
7137
7055
|
}
|
|
7138
7056
|
function buildActionRequiredToast(deps, process2) {
|
|
7139
7057
|
if (process2.lifecycleStatus !== "waiting") {
|
|
@@ -7365,12 +7283,14 @@ function deriveParsedInstanceTree(tree) {
|
|
|
7365
7283
|
|
|
7366
7284
|
// src/process-session-store.ts
|
|
7367
7285
|
var ProcessSessionReader = class {
|
|
7286
|
+
/** @internal */
|
|
7368
7287
|
constructor(source) {
|
|
7369
7288
|
this.source = source;
|
|
7370
7289
|
}
|
|
7371
7290
|
source;
|
|
7372
7291
|
sessionTreeCache = /* @__PURE__ */ new Map();
|
|
7373
7292
|
inFlightReads = /* @__PURE__ */ new Map();
|
|
7293
|
+
/** @internal */
|
|
7374
7294
|
async readSessionTree(instanceId) {
|
|
7375
7295
|
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
7376
7296
|
const handle = await this.source.readSnapshotHandle(instanceId);
|
|
@@ -7397,9 +7317,11 @@ var ProcessSessionReader = class {
|
|
|
7397
7317
|
}
|
|
7398
7318
|
throw new Error(`Unable to read process session snapshot '${instanceId}'`);
|
|
7399
7319
|
}
|
|
7320
|
+
/** @internal */
|
|
7400
7321
|
async readInstanceTree(instanceId) {
|
|
7401
7322
|
return (await this.readSessionTree(instanceId)).parsedTree;
|
|
7402
7323
|
}
|
|
7324
|
+
/** @internal */
|
|
7403
7325
|
async readPiSessionTree(instanceId) {
|
|
7404
7326
|
return (await this.readSessionTree(instanceId)).piTree;
|
|
7405
7327
|
}
|
|
@@ -7425,7 +7347,7 @@ var ProcessSessionReader = class {
|
|
|
7425
7347
|
this.inFlightReads.set(cacheKey, promise);
|
|
7426
7348
|
return promise;
|
|
7427
7349
|
}
|
|
7428
|
-
/** Returns the raw session JSONL, or `null` when no session exists yet. */
|
|
7350
|
+
/** Returns the raw session JSONL, or `null` when no session exists yet. @internal */
|
|
7429
7351
|
async readRawContent(instanceId) {
|
|
7430
7352
|
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
7431
7353
|
const handle = await this.source.readSnapshotHandle(instanceId);
|
|
@@ -7933,6 +7855,17 @@ function buildTurnTraceIndexFromSession(input) {
|
|
|
7933
7855
|
return traces;
|
|
7934
7856
|
}
|
|
7935
7857
|
|
|
7858
|
+
// src/session-transfer-service.ts
|
|
7859
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
7860
|
+
import path4 from "node:path";
|
|
7861
|
+
import { Transform } from "node:stream";
|
|
7862
|
+
import { pipeline } from "node:stream/promises";
|
|
7863
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
7864
|
+
import {
|
|
7865
|
+
DEFAULT_SESSION_TRANSFER_LIMITS as DEFAULT_SESSION_TRANSFER_LIMITS2,
|
|
7866
|
+
parsePiSessionHeader
|
|
7867
|
+
} from "@leitwerk-dev/session-transfer";
|
|
7868
|
+
|
|
7936
7869
|
// src/supervisor/worker-storage-layout.ts
|
|
7937
7870
|
import { existsSync as existsSync3, mkdirSync as mkdirSync2 } from "node:fs";
|
|
7938
7871
|
import path3 from "node:path";
|
|
@@ -7997,15 +7930,6 @@ function createWorkerStorageLayout(config) {
|
|
|
7997
7930
|
}
|
|
7998
7931
|
|
|
7999
7932
|
// 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
7933
|
var GRANT_LIFETIME_MS = 60 * 60 * 1e3;
|
|
8010
7934
|
var ATTEMPT_LEASE_MS = 90 * 1e3;
|
|
8011
7935
|
var ATTEMPT_HARD_DEADLINE_MS = 60 * 60 * 1e3;
|
|
@@ -8033,6 +7957,7 @@ function createSessionTransferService(deps) {
|
|
|
8033
7957
|
const now2 = deps.now ?? (() => /* @__PURE__ */ new Date());
|
|
8034
7958
|
const limits = deps.limits ?? DEFAULT_SESSION_TRANSFER_LIMITS2;
|
|
8035
7959
|
const runtimes = /* @__PURE__ */ new Map();
|
|
7960
|
+
const exportWork = /* @__PURE__ */ new Set();
|
|
8036
7961
|
let sweepTimer = null;
|
|
8037
7962
|
function publish(attempt) {
|
|
8038
7963
|
if (attempt && deps.onUpdated) {
|
|
@@ -8107,7 +8032,7 @@ function createSessionTransferService(deps) {
|
|
|
8107
8032
|
streamClaimed: false
|
|
8108
8033
|
};
|
|
8109
8034
|
runtimes.set(attempt.id, runtime);
|
|
8110
|
-
|
|
8035
|
+
const work = (async () => {
|
|
8111
8036
|
updatePhase(attempt.id, "waiting_for_execution_chain");
|
|
8112
8037
|
while (true) {
|
|
8113
8038
|
const reserved = await deps.processOperations.runExclusive(attempt.instanceId, () => {
|
|
@@ -8161,6 +8086,11 @@ function createSessionTransferService(deps) {
|
|
|
8161
8086
|
runtimes.delete(attempt.id);
|
|
8162
8087
|
}
|
|
8163
8088
|
});
|
|
8089
|
+
exportWork.add(work);
|
|
8090
|
+
void work.then(
|
|
8091
|
+
() => exportWork.delete(work),
|
|
8092
|
+
() => exportWork.delete(work)
|
|
8093
|
+
);
|
|
8164
8094
|
}
|
|
8165
8095
|
function cancelAttempt(attempt, code) {
|
|
8166
8096
|
if (["consumed", "cancelled", "failed"].includes(attempt.phase)) return attempt;
|
|
@@ -8188,10 +8118,19 @@ function createSessionTransferService(deps) {
|
|
|
8188
8118
|
deps.repos.sessionTransfers.cleanup(now2());
|
|
8189
8119
|
}
|
|
8190
8120
|
return {
|
|
8121
|
+
/** @internal */
|
|
8191
8122
|
async createGrant(instanceId) {
|
|
8192
8123
|
return deps.processOperations.runExclusive(instanceId, async () => {
|
|
8193
|
-
if (deps.isDeletionPending?.(instanceId))
|
|
8194
|
-
|
|
8124
|
+
if (deps.isDeletionPending?.(instanceId))
|
|
8125
|
+
return {
|
|
8126
|
+
/** @internal */
|
|
8127
|
+
kind: "deletion_pending"
|
|
8128
|
+
};
|
|
8129
|
+
if (!deps.repos.processes.getById(instanceId))
|
|
8130
|
+
return {
|
|
8131
|
+
/** @internal */
|
|
8132
|
+
kind: "not_found"
|
|
8133
|
+
};
|
|
8195
8134
|
const handle = await deps.sessionSource.readSnapshotHandle(instanceId);
|
|
8196
8135
|
if (!handle) return { kind: "not_found" };
|
|
8197
8136
|
const created = deps.repos.sessionTransfers.createGrant({
|
|
@@ -8200,13 +8139,18 @@ function createSessionTransferService(deps) {
|
|
|
8200
8139
|
lifetimeMs: GRANT_LIFETIME_MS
|
|
8201
8140
|
});
|
|
8202
8141
|
return {
|
|
8142
|
+
/** @internal */
|
|
8203
8143
|
kind: "created",
|
|
8144
|
+
/** @internal */
|
|
8204
8145
|
grantId: created.grant.id,
|
|
8146
|
+
/** @internal */
|
|
8205
8147
|
rawToken: created.rawToken,
|
|
8148
|
+
/** @internal */
|
|
8206
8149
|
expiresAt: created.grant.expiresAt
|
|
8207
8150
|
};
|
|
8208
8151
|
});
|
|
8209
8152
|
},
|
|
8153
|
+
/** @internal */
|
|
8210
8154
|
startAttempt(input) {
|
|
8211
8155
|
if (deps.isDeletionPending?.(input.instanceId)) return { kind: "not_found" };
|
|
8212
8156
|
const result = deps.repos.transaction(
|
|
@@ -8223,6 +8167,7 @@ function createSessionTransferService(deps) {
|
|
|
8223
8167
|
}
|
|
8224
8168
|
return result;
|
|
8225
8169
|
},
|
|
8170
|
+
/** @internal */
|
|
8226
8171
|
heartbeat(input) {
|
|
8227
8172
|
const attempt = deps.repos.sessionTransfers.verifyAttempt(input);
|
|
8228
8173
|
if (!attempt) return null;
|
|
@@ -8230,6 +8175,7 @@ function createSessionTransferService(deps) {
|
|
|
8230
8175
|
if (current.phase === "cancelled" || current.phase === "failed") return current;
|
|
8231
8176
|
return deps.repos.sessionTransfers.renew(current.id, { now: now2(), leaseMs: ATTEMPT_LEASE_MS }) ?? current;
|
|
8232
8177
|
},
|
|
8178
|
+
/** @internal */
|
|
8233
8179
|
openStream(input) {
|
|
8234
8180
|
const attempt = deps.repos.sessionTransfers.verifyAttempt(input);
|
|
8235
8181
|
if (!attempt || deadlineCode(attempt)) {
|
|
@@ -8290,15 +8236,18 @@ function createSessionTransferService(deps) {
|
|
|
8290
8236
|
void pipeline(source, meter, { signal: runtime.controller.signal }).catch(() => void 0);
|
|
8291
8237
|
return meter;
|
|
8292
8238
|
},
|
|
8239
|
+
/** @internal */
|
|
8293
8240
|
cancel(input) {
|
|
8294
8241
|
const attempt = deps.repos.sessionTransfers.verifyAttempt(input);
|
|
8295
8242
|
return attempt ? cancelAttempt(attempt, input.code ?? "client_cancelled") : null;
|
|
8296
8243
|
},
|
|
8244
|
+
/** @internal */
|
|
8297
8245
|
cancelForWeb(instanceId, attemptId) {
|
|
8298
8246
|
const attempt = deps.repos.sessionTransfers.getAttempt(attemptId);
|
|
8299
8247
|
if (!attempt || attempt.instanceId !== instanceId) return null;
|
|
8300
8248
|
return attempt.phase === "awaiting_ack" ? attempt : cancelAttempt(attempt, "operator_cancelled");
|
|
8301
8249
|
},
|
|
8250
|
+
/** @internal */
|
|
8302
8251
|
acknowledge(input) {
|
|
8303
8252
|
const attempt = deps.repos.sessionTransfers.verifyAttempt(input);
|
|
8304
8253
|
if (!attempt) return null;
|
|
@@ -8316,14 +8265,17 @@ function createSessionTransferService(deps) {
|
|
|
8316
8265
|
);
|
|
8317
8266
|
return publish(acknowledged);
|
|
8318
8267
|
},
|
|
8268
|
+
/** @internal */
|
|
8319
8269
|
activeForProcess(instanceId) {
|
|
8320
8270
|
return deps.repos.sessionTransfers.getActiveByInstance(instanceId);
|
|
8321
8271
|
},
|
|
8272
|
+
/** @internal */
|
|
8322
8273
|
revokeProcess(instanceId) {
|
|
8323
8274
|
const active = deps.repos.sessionTransfers.getActiveByInstance(instanceId);
|
|
8324
8275
|
if (active) cancelAttempt(active, "process_deleted");
|
|
8325
8276
|
deps.repos.sessionTransfers.revokeProcess(instanceId);
|
|
8326
8277
|
},
|
|
8278
|
+
/** @internal */
|
|
8327
8279
|
async reconcile() {
|
|
8328
8280
|
await deps.exporter.reconcile();
|
|
8329
8281
|
for (const attempt of deps.repos.sessionTransfers.listActive()) {
|
|
@@ -8336,10 +8288,12 @@ function createSessionTransferService(deps) {
|
|
|
8336
8288
|
}
|
|
8337
8289
|
sweep();
|
|
8338
8290
|
},
|
|
8291
|
+
/** @internal */
|
|
8339
8292
|
start() {
|
|
8340
8293
|
if (!sweepTimer) sweepTimer = setInterval(sweep, 15e3);
|
|
8341
8294
|
},
|
|
8342
|
-
|
|
8295
|
+
/** @internal */
|
|
8296
|
+
async stop() {
|
|
8343
8297
|
if (sweepTimer) clearInterval(sweepTimer);
|
|
8344
8298
|
sweepTimer = null;
|
|
8345
8299
|
for (const runtime of runtimes.values()) {
|
|
@@ -8347,9 +8301,15 @@ function createSessionTransferService(deps) {
|
|
|
8347
8301
|
}
|
|
8348
8302
|
runtimes.clear();
|
|
8349
8303
|
deps.helperRelays.stop();
|
|
8304
|
+
const results = await Promise.allSettled(exportWork);
|
|
8305
|
+
const errors = results.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
8306
|
+
if (errors.length) throw new AggregateError(errors, "Session export cleanup failed");
|
|
8350
8307
|
},
|
|
8308
|
+
/** @internal */
|
|
8351
8309
|
helperSpec: deps.helperRelays.helperSpec,
|
|
8310
|
+
/** @internal */
|
|
8352
8311
|
reportHelperPreflight: deps.helperRelays.reportHelperPreflight,
|
|
8312
|
+
/** @internal */
|
|
8353
8313
|
acceptHelperStream: deps.helperRelays.acceptHelperStream
|
|
8354
8314
|
};
|
|
8355
8315
|
}
|
|
@@ -9608,16 +9568,14 @@ function buildStartupEvidence(input) {
|
|
|
9608
9568
|
steps
|
|
9609
9569
|
};
|
|
9610
9570
|
});
|
|
9611
|
-
const
|
|
9612
|
-
|
|
9613
|
-
|
|
9614
|
-
return recoveryAttempt ? {
|
|
9571
|
+
const authoritative = attempts.find((attempt) => attempt.status === "succeeded");
|
|
9572
|
+
const recoveredAttempts = attempts.map(
|
|
9573
|
+
(attempt) => attempt.status === "failed" && authoritative ? {
|
|
9615
9574
|
...attempt,
|
|
9616
9575
|
status: "recovered",
|
|
9617
|
-
recoveredByStartRecordId:
|
|
9618
|
-
} : attempt
|
|
9619
|
-
|
|
9620
|
-
const authoritative = recoveredAttempts.findLast((attempt) => attempt.status === "succeeded");
|
|
9576
|
+
recoveredByStartRecordId: authoritative.startRecordId
|
|
9577
|
+
} : attempt
|
|
9578
|
+
);
|
|
9621
9579
|
const currentAttempt = (currentStartId ? recoveredAttempts.find((attempt) => attempt.startRecordId === currentStartId) : void 0) ?? recoveredAttempts.at(-1) ?? null;
|
|
9622
9580
|
return {
|
|
9623
9581
|
attempts: recoveredAttempts,
|
|
@@ -9661,38 +9619,22 @@ function projectLaunchRunStartup(run, evidence, titleState) {
|
|
|
9661
9619
|
let next = run;
|
|
9662
9620
|
const attempt = evidence.currentAttempt;
|
|
9663
9621
|
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
9622
|
next = {
|
|
9686
9623
|
...next,
|
|
9687
9624
|
steps: next.steps.map((item) => {
|
|
9625
|
+
if (!Object.hasOwn(STARTUP_STEP_LABELS, item.id)) return item;
|
|
9688
9626
|
const phase = attempt?.steps.find((candidate2) => candidate2.id === item.id);
|
|
9689
|
-
if (!phase) return item;
|
|
9690
|
-
const { startedAt: _start, completedAt: _end, ...rest } = item;
|
|
9627
|
+
if (!phase && item.status === "skipped") return item;
|
|
9628
|
+
const { startedAt: _start, completedAt: _end, safeSummary: _summary, ...rest } = item;
|
|
9629
|
+
const status = !phase || phase.status === "superseded" ? "pending" : phase.status;
|
|
9630
|
+
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
9631
|
return {
|
|
9692
9632
|
...rest,
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
...phase
|
|
9633
|
+
status,
|
|
9634
|
+
label: phase?.label ?? item.label,
|
|
9635
|
+
...phase?.startedAt ? { startedAt: phase.startedAt } : {},
|
|
9636
|
+
...phase?.endedAt ? { completedAt: phase.endedAt } : {},
|
|
9637
|
+
...phase && safeSummary ? { safeSummary } : {}
|
|
9696
9638
|
};
|
|
9697
9639
|
})
|
|
9698
9640
|
};
|
|
@@ -10442,10 +10384,15 @@ function buildProcessUiSnapshotProjections(input) {
|
|
|
10442
10384
|
observations: input.startupObservations ?? []
|
|
10443
10385
|
});
|
|
10444
10386
|
return {
|
|
10387
|
+
/** @internal */
|
|
10445
10388
|
process: projectProcessForUiSnapshot(input.process),
|
|
10389
|
+
/** @internal */
|
|
10446
10390
|
primaryPath: compactPrimaryPathSnapshot(input.primaryPathSnapshot),
|
|
10391
|
+
/** @internal */
|
|
10447
10392
|
timeline: {
|
|
10393
|
+
/** @internal */
|
|
10448
10394
|
prompt,
|
|
10395
|
+
/** @internal */
|
|
10449
10396
|
turns: presentProcessTimelineTurns({
|
|
10450
10397
|
process: input.process,
|
|
10451
10398
|
turnRecords: input.turnRecords,
|
|
@@ -10456,23 +10403,31 @@ function buildProcessUiSnapshotProjections(input) {
|
|
|
10456
10403
|
selectedTurnType: input.selectedTurn?.kind ?? null,
|
|
10457
10404
|
activeModelProfileId: input.activeModelProfileId
|
|
10458
10405
|
}),
|
|
10406
|
+
/** @internal */
|
|
10459
10407
|
tracePreviewsByTurnRecordId,
|
|
10408
|
+
/** @internal */
|
|
10460
10409
|
inputs: input.inputs.map(buildTimelineInputSummary),
|
|
10410
|
+
/** @internal */
|
|
10461
10411
|
externalTriggerSignals: buildExternalTriggerSignals({
|
|
10462
10412
|
externalTriggers: input.selectedTurn?.externalTriggers ?? [],
|
|
10463
10413
|
events: input.events,
|
|
10464
10414
|
isWaitingForSelectedTurn: input.process.lifecycleStatus === "waiting" && (input.selectedTurn?.turnId ?? null) === (input.process.selectedTurnId ?? null)
|
|
10465
10415
|
})
|
|
10466
10416
|
},
|
|
10417
|
+
/** @internal */
|
|
10467
10418
|
recovery,
|
|
10419
|
+
/** @internal */
|
|
10468
10420
|
startup,
|
|
10421
|
+
/** @internal */
|
|
10469
10422
|
startupRecovery: startup.recovery,
|
|
10423
|
+
/** @internal */
|
|
10470
10424
|
processError: buildCurrentProcessError({
|
|
10471
10425
|
process: input.process,
|
|
10472
10426
|
events: input.events,
|
|
10473
10427
|
selectedTurnDescription: input.selectedTurn?.description ?? null,
|
|
10474
10428
|
currentTurnRecovery: recovery
|
|
10475
10429
|
}),
|
|
10430
|
+
/** @internal */
|
|
10476
10431
|
usageEstimate: buildUsageEstimate({
|
|
10477
10432
|
turnRecords: input.turnRecords,
|
|
10478
10433
|
activeTurn,
|
|
@@ -11037,7 +10992,16 @@ function createBroadcaster() {
|
|
|
11037
10992
|
});
|
|
11038
10993
|
broadcast(frame);
|
|
11039
10994
|
}
|
|
11040
|
-
return {
|
|
10995
|
+
return {
|
|
10996
|
+
/** @internal */
|
|
10997
|
+
addClient,
|
|
10998
|
+
/** @internal */
|
|
10999
|
+
broadcast,
|
|
11000
|
+
/** @internal */
|
|
11001
|
+
sendDurable,
|
|
11002
|
+
/** @internal */
|
|
11003
|
+
sendEphemeral
|
|
11004
|
+
};
|
|
11041
11005
|
}
|
|
11042
11006
|
|
|
11043
11007
|
export {
|
|
@@ -11055,57 +11019,24 @@ export {
|
|
|
11055
11019
|
resolveDockerRegistryCredentials,
|
|
11056
11020
|
resolveProcessStorageSize,
|
|
11057
11021
|
SAFE_SKILL_ID_PATTERN,
|
|
11058
|
-
applyConfigDefaults,
|
|
11059
11022
|
loadConfig,
|
|
11060
11023
|
validateConfig,
|
|
11061
11024
|
sanitizeConfigForLogging,
|
|
11062
11025
|
getDefaultConfig,
|
|
11063
11026
|
DatabaseSchemaMismatchError,
|
|
11064
|
-
initializeSchema,
|
|
11065
11027
|
createDatabase,
|
|
11066
11028
|
createInMemoryDatabase,
|
|
11067
11029
|
closeDatabase,
|
|
11068
|
-
createApiTokenRepo,
|
|
11069
11030
|
generateId,
|
|
11070
11031
|
now,
|
|
11071
|
-
createAuthSessionRepo,
|
|
11072
|
-
createAuthLoginFlowRepo,
|
|
11073
|
-
PROVIDER_CREDENTIAL_KEY_ENV,
|
|
11074
|
-
createUnavailableCredentialCipher,
|
|
11075
|
-
createCredentialCipherFromBase64,
|
|
11076
11032
|
createCredentialCipherFromEnvironment,
|
|
11077
|
-
createAes256GcmCredentialCipher,
|
|
11078
|
-
createExternalWriteLogRepo,
|
|
11079
|
-
createFutureExecutionRepo,
|
|
11080
|
-
createLaunchRunRepo,
|
|
11081
|
-
createLauncherRecentValueRepo,
|
|
11082
|
-
createPendingExternalSourceFireRepo,
|
|
11083
|
-
createProcessEventRepo,
|
|
11084
|
-
createProcessHandoffDedupKeyRepo,
|
|
11085
|
-
createProcessInputRepo,
|
|
11086
11033
|
truncateTextAtWordBoundary,
|
|
11087
11034
|
normalizeProcessTitleInput,
|
|
11088
11035
|
applySubmittedProcessTitleToLaunchPlan,
|
|
11089
|
-
createProcessInstanceRepo,
|
|
11090
|
-
createProcessLeafOutcomeSnapshotRepo,
|
|
11091
|
-
createProcessProjectRepo,
|
|
11092
|
-
createProcessQuestionRequestRepo,
|
|
11093
|
-
createProcessRelationRepo,
|
|
11094
11036
|
SKILL_RESOURCE_OWNER,
|
|
11095
11037
|
compareResourcePaths,
|
|
11096
11038
|
validatePhysicalSourcePath,
|
|
11097
11039
|
ResourceCollector,
|
|
11098
|
-
createProcessSkillRepo,
|
|
11099
|
-
createProcessTitleJobRepo,
|
|
11100
|
-
createProcessToolApprovalRequestRepo,
|
|
11101
|
-
createProcessTurnAnnotationRepo,
|
|
11102
|
-
createProcessTurnRecordRepo,
|
|
11103
|
-
createProviderCredentialRepo,
|
|
11104
|
-
createSessionTransferRepo,
|
|
11105
|
-
createSkillRepo,
|
|
11106
|
-
createTicketDestinationRecentRepo,
|
|
11107
|
-
createTurnStartRecordRepo,
|
|
11108
|
-
createWorkerLeaseRepo,
|
|
11109
11040
|
createAllRepos,
|
|
11110
11041
|
recordTurnProgress,
|
|
11111
11042
|
normalizeExternalEventDescription,
|
|
@@ -11129,8 +11060,6 @@ export {
|
|
|
11129
11060
|
presentProcessModelConfiguration,
|
|
11130
11061
|
evaluateAtStableAvailabilityRevision,
|
|
11131
11062
|
createServerProcessModelPolicy,
|
|
11132
|
-
resolveTurnIntegrationToolNames,
|
|
11133
|
-
buildProcessActionRegistry,
|
|
11134
11063
|
resolveCurrentExecutionTurnRecordId,
|
|
11135
11064
|
presentPipelineResult,
|
|
11136
11065
|
finishLaunchRun,
|
|
@@ -11173,22 +11102,14 @@ export {
|
|
|
11173
11102
|
sendLauncherMutationResponse,
|
|
11174
11103
|
sendScheduledActionMutationResponse,
|
|
11175
11104
|
mergeProcessEventWindowsAscending,
|
|
11176
|
-
buildTurnTracePreview,
|
|
11177
11105
|
buildTurnTraceIndexFromSession,
|
|
11178
|
-
createLocalWorkerStorageLayout,
|
|
11179
|
-
createProcessVolumeWorkerStorageLayout,
|
|
11180
11106
|
resolveWorkerPiAgentDir,
|
|
11181
11107
|
createWorkerStorageLayout,
|
|
11182
11108
|
createSessionTransferService,
|
|
11183
|
-
presentProcessTimelineTurns,
|
|
11184
|
-
buildExternalTriggerSignals,
|
|
11185
|
-
buildCurrentTurnRecovery,
|
|
11186
|
-
buildCurrentProcessError,
|
|
11187
|
-
buildUsageEstimate,
|
|
11188
11109
|
buildProcessUiSnapshotProjections,
|
|
11189
11110
|
ProcessUiSnapshotAssembler,
|
|
11190
11111
|
buildPrimaryPathSnapshotFromTree,
|
|
11191
11112
|
createProjectedSessionSnapshotStore,
|
|
11192
11113
|
createBroadcaster
|
|
11193
11114
|
};
|
|
11194
|
-
//# sourceMappingURL=chunk-
|
|
11115
|
+
//# sourceMappingURL=chunk-ZSKM25SD.js.map
|