@leitwerk-dev/server 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{app-WfwKzrVk.d.ts → app-CsuxFZT5.d.ts} +332 -111
- package/dist/app-JM4CBTND.js +8 -0
- package/dist/app.d.ts +9 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/auth/fastify-auth.d.ts +9 -0
- package/dist/auth/fastify-auth.d.ts.map +1 -1
- package/dist/{chunk-LK3RO6C7.js → chunk-FPMDWQF7.js} +3050 -645
- package/dist/chunk-FPMDWQF7.js.map +1 -0
- package/dist/{chunk-KIOQNNG6.js → chunk-MBHRCQFE.js} +2781 -1822
- package/dist/chunk-MBHRCQFE.js.map +1 -0
- package/dist/config/config-loader.d.ts +1 -1
- package/dist/config/config-loader.d.ts.map +1 -1
- package/dist/config/config-types.d.ts +14 -1
- package/dist/config/config-types.d.ts.map +1 -1
- package/dist/config/kubernetes-docker-isolation.d.ts +7 -0
- package/dist/config/kubernetes-docker-isolation.d.ts.map +1 -0
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/execution-inspection-repo.d.ts +15 -0
- package/dist/db/execution-inspection-repo.d.ts.map +1 -0
- package/dist/db/history-window.d.ts +11 -0
- package/dist/db/history-window.d.ts.map +1 -0
- package/dist/db/mapped-llm-run-repo.d.ts +56 -0
- package/dist/db/mapped-llm-run-repo.d.ts.map +1 -0
- package/dist/db/process-event-repo.d.ts +2 -0
- package/dist/db/process-event-repo.d.ts.map +1 -1
- package/dist/db/process-instance-repo.d.ts +4 -1
- package/dist/db/process-instance-repo.d.ts.map +1 -1
- package/dist/db/process-leaf-outcome-snapshot-repo.d.ts +2 -1
- package/dist/db/process-leaf-outcome-snapshot-repo.d.ts.map +1 -1
- package/dist/db/process-project-repo.d.ts +2 -0
- package/dist/db/process-project-repo.d.ts.map +1 -1
- package/dist/db/process-skill-repo.d.ts.map +1 -1
- package/dist/db/process-turn-annotation-repo.d.ts +4 -1
- package/dist/db/process-turn-annotation-repo.d.ts.map +1 -1
- package/dist/db/process-turn-record-repo.d.ts +7 -1
- package/dist/db/process-turn-record-repo.d.ts.map +1 -1
- package/dist/db/publication-repo.d.ts +5 -0
- package/dist/db/publication-repo.d.ts.map +1 -0
- package/dist/db/repo-helpers.d.ts +6 -0
- package/dist/db/repo-helpers.d.ts.map +1 -1
- package/dist/db/repositories.d.ts +16 -0
- package/dist/db/repositories.d.ts.map +1 -1
- package/dist/db/schema.d.ts +1177 -71
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/scoped-settings-repo.d.ts +37 -0
- package/dist/db/scoped-settings-repo.d.ts.map +1 -0
- package/dist/db/skill-repo.d.ts +3 -0
- package/dist/db/skill-repo.d.ts.map +1 -1
- package/dist/db/turn-start-record-repo.d.ts +2 -1
- package/dist/db/turn-start-record-repo.d.ts.map +1 -1
- package/dist/db/turn-summary-repo.d.ts +1 -1
- package/dist/db/turn-summary-repo.d.ts.map +1 -1
- package/dist/db/worker-lease-repo.d.ts +2 -1
- package/dist/db/worker-lease-repo.d.ts.map +1 -1
- package/dist/domain-logic/outcome-tools.d.ts.map +1 -1
- package/dist/external-source-service.d.ts.map +1 -1
- package/dist/future-execution/execution.d.ts +4 -1
- package/dist/future-execution/execution.d.ts.map +1 -1
- package/dist/future-execution/launch-lifecycle.d.ts +9 -25
- package/dist/future-execution/launch-lifecycle.d.ts.map +1 -1
- package/dist/future-execution/lifecycle.d.ts +3 -28
- package/dist/future-execution/lifecycle.d.ts.map +1 -1
- package/dist/future-execution/model-projection.d.ts.map +1 -1
- package/dist/future-execution/reconciliation.d.ts +1 -0
- package/dist/future-execution/reconciliation.d.ts.map +1 -1
- package/dist/future-execution-presenter.d.ts +4 -14
- package/dist/future-execution-presenter.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/integration-tool-registry.d.ts +11 -2
- package/dist/integration-tool-registry.d.ts.map +1 -1
- package/dist/launch-coordinator-test-harness.d.ts.map +1 -1
- package/dist/launch-coordinator.d.ts.map +1 -1
- package/dist/launcher-model-config-service.d.ts +7 -1
- package/dist/launcher-model-config-service.d.ts.map +1 -1
- package/dist/leaf-outcome-snapshot-capture.d.ts +1 -0
- package/dist/leaf-outcome-snapshot-capture.d.ts.map +1 -1
- package/dist/main.js +3 -3
- package/dist/primary-path-snapshot.d.ts.map +1 -1
- package/dist/process-action-presenter.d.ts +11 -0
- package/dist/process-action-presenter.d.ts.map +1 -0
- package/dist/process-action-registry.d.ts.map +1 -1
- package/dist/process-engine/decision.d.ts +2 -0
- package/dist/process-engine/decision.d.ts.map +1 -1
- package/dist/process-engine/engine.d.ts.map +1 -1
- package/dist/process-engine/mapped-turns.d.ts +45 -0
- package/dist/process-engine/mapped-turns.d.ts.map +1 -0
- package/dist/process-engine/operation.d.ts +1 -1
- package/dist/process-engine/operation.d.ts.map +1 -1
- package/dist/process-engine/ops/accept-worker-turn-start.d.ts +2 -0
- package/dist/process-engine/ops/accept-worker-turn-start.d.ts.map +1 -1
- package/dist/process-engine/ops/continue-failed-turn.d.ts.map +1 -1
- package/dist/process-engine/ops/process-observation.d.ts +6 -0
- package/dist/process-engine/ops/process-observation.d.ts.map +1 -0
- package/dist/process-engine/ops/retry-failed-turn.d.ts.map +1 -1
- package/dist/process-engine/ops/retry-startup.d.ts.map +1 -1
- package/dist/process-engine/ops/start-process.d.ts +2 -0
- package/dist/process-engine/ops/start-process.d.ts.map +1 -1
- package/dist/process-engine/ops/turn-outcome.d.ts.map +1 -1
- package/dist/process-engine/ops/turn-wait.d.ts +30 -0
- package/dist/process-engine/ops/turn-wait.d.ts.map +1 -0
- package/dist/process-engine/ops/update-model-config.d.ts +9 -0
- package/dist/process-engine/ops/update-model-config.d.ts.map +1 -0
- package/dist/process-engine/recorder.d.ts.map +1 -1
- package/dist/process-engine/turn-start-preflight.d.ts +6 -0
- package/dist/process-engine/turn-start-preflight.d.ts.map +1 -1
- package/dist/process-engine/turn-wait-state.d.ts +24 -0
- package/dist/process-engine/turn-wait-state.d.ts.map +1 -0
- package/dist/process-engine/turn-worker-requirement.d.ts +2 -0
- package/dist/process-engine/turn-worker-requirement.d.ts.map +1 -1
- package/dist/process-engine/types.d.ts +10 -1
- package/dist/process-engine/types.d.ts.map +1 -1
- package/dist/process-engine/writes/build-process-abort-writes.d.ts +3 -1
- package/dist/process-engine/writes/build-process-abort-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-recovery-start-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts +10 -1
- 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.map +1 -1
- package/dist/process-engine/writes/commit-writes.d.ts +2 -0
- package/dist/process-engine/writes/commit-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/reserve-selected-turn-start.d.ts +5 -0
- package/dist/process-engine/writes/reserve-selected-turn-start.d.ts.map +1 -0
- package/dist/process-engine/writes/writes.d.ts +35 -49
- 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-inspection-reader.d.ts +21 -0
- package/dist/process-inspection-reader.d.ts.map +1 -0
- package/dist/process-inspection-trace.d.ts +13 -0
- package/dist/process-inspection-trace.d.ts.map +1 -0
- package/dist/process-inspection.d.ts +22 -0
- package/dist/process-inspection.d.ts.map +1 -0
- package/dist/process-instance-tree-presenter.d.ts +4 -3
- package/dist/process-instance-tree-presenter.d.ts.map +1 -1
- package/dist/process-launch-executor.d.ts +2 -0
- package/dist/process-launch-executor.d.ts.map +1 -1
- package/dist/process-launch-plan.d.ts +1 -0
- package/dist/process-launch-plan.d.ts.map +1 -1
- package/dist/process-launcher-registry.d.ts.map +1 -1
- package/dist/process-model-config.d.ts +19 -0
- package/dist/process-model-config.d.ts.map +1 -0
- package/dist/process-model-policy/construct.d.ts.map +1 -1
- package/dist/process-model-policy/evaluate.d.ts.map +1 -1
- package/dist/process-model-policy/index.d.ts +4 -1
- package/dist/process-model-policy/index.d.ts.map +1 -1
- package/dist/process-model-policy/project.d.ts.map +1 -1
- package/dist/process-model-policy/types.d.ts +18 -0
- package/dist/process-model-policy/types.d.ts.map +1 -1
- package/dist/process-model-policy-presenter.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-turn-navigation.d.ts +12 -2
- package/dist/process-turn-navigation.d.ts.map +1 -1
- package/dist/process-turn-trace.d.ts.map +1 -1
- package/dist/process-ui-snapshot-presenter.d.ts +15 -3
- package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
- package/dist/routes/future-executions.d.ts.map +1 -1
- package/dist/routes/launchers.d.ts.map +1 -1
- package/dist/routes/process-actions.d.ts.map +1 -1
- package/dist/routes/process-detail.d.ts.map +1 -1
- package/dist/routes/process-diagnostics-assembler.d.ts +3 -1
- package/dist/routes/process-diagnostics-assembler.d.ts.map +1 -1
- package/dist/routes/process-model-config.d.ts +4 -0
- package/dist/routes/process-model-config.d.ts.map +1 -0
- package/dist/routes/process-primary-path-assembler.d.ts +4 -12
- package/dist/routes/process-primary-path-assembler.d.ts.map +1 -1
- package/dist/routes/process-route-helpers.d.ts +15 -41
- package/dist/routes/process-route-helpers.d.ts.map +1 -1
- package/dist/routes/processes.d.ts.map +1 -1
- package/dist/routes/settings.d.ts +11 -0
- package/dist/routes/settings.d.ts.map +1 -0
- package/dist/routes/ticket-creation.d.ts.map +1 -1
- package/dist/scoped-settings-service.d.ts +83 -0
- package/dist/scoped-settings-service.d.ts.map +1 -0
- package/dist/server-bootstrap/build-host-capabilities.d.ts +2 -0
- package/dist/server-bootstrap/build-host-capabilities.d.ts.map +1 -1
- package/dist/server-bootstrap/register-http.d.ts.map +1 -1
- package/dist/session-summary-projection.d.ts.map +1 -1
- package/dist/skills/bundled-skills.d.ts +5 -0
- package/dist/skills/bundled-skills.d.ts.map +1 -0
- package/dist/skills/catalog-service.d.ts +1 -0
- package/dist/skills/catalog-service.d.ts.map +1 -1
- package/dist/skills/extension-importer.d.ts +11 -0
- package/dist/skills/extension-importer.d.ts.map +1 -0
- package/dist/skills/launch-skills.d.ts +11 -0
- package/dist/skills/launch-skills.d.ts.map +1 -0
- package/dist/skills/skill-frontmatter.d.ts +5 -0
- package/dist/skills/skill-frontmatter.d.ts.map +1 -1
- package/dist/skills/source-importer.d.ts +3 -0
- package/dist/skills/source-importer.d.ts.map +1 -1
- package/dist/startup-evidence.d.ts +3 -0
- package/dist/startup-evidence.d.ts.map +1 -1
- package/dist/supervisor/execution-inspection-ingestor.d.ts +9 -0
- package/dist/supervisor/execution-inspection-ingestor.d.ts.map +1 -0
- package/dist/supervisor/ipc-handler.d.ts +2 -0
- package/dist/supervisor/ipc-handler.d.ts.map +1 -1
- package/dist/supervisor/worker-event-ingestor.d.ts +1 -0
- package/dist/supervisor/worker-event-ingestor.d.ts.map +1 -1
- package/dist/supervisor/worker-start-payload-builder.d.ts +2 -0
- package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
- package/dist/supervisor/worker-supervisor.d.ts +4 -0
- package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
- package/dist/supervisor/worker-turn-ipc-recorder.d.ts +2 -2
- package/dist/supervisor/worker-turn-ipc-recorder.d.ts.map +1 -1
- package/dist/test-helpers/accepted-turn-start.d.ts +18 -4
- package/dist/test-helpers/accepted-turn-start.d.ts.map +1 -1
- package/dist/test-helpers/owned-test-deps.d.ts +18 -0
- package/dist/test-helpers/owned-test-deps.d.ts.map +1 -0
- package/dist/test-helpers/prepared-fixture-start.d.ts.map +1 -1
- package/dist/test-helpers/process-model-fixtures.d.ts +1 -0
- package/dist/test-helpers/process-model-fixtures.d.ts.map +1 -1
- package/dist/test-helpers/scoped-settings-fixtures.d.ts +16 -0
- package/dist/test-helpers/scoped-settings-fixtures.d.ts.map +1 -0
- package/dist/test-helpers/skill-fixtures.d.ts +4 -0
- package/dist/test-helpers/skill-fixtures.d.ts.map +1 -0
- package/dist/testing.d.ts +1 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +14 -10
- package/dist/testing.js.map +1 -1
- package/dist/tool-approval-gate.d.ts +3 -0
- package/dist/tool-approval-gate.d.ts.map +1 -1
- package/dist/turn-progress.d.ts.map +1 -1
- package/dist/turn-wait-service.d.ts +28 -0
- package/dist/turn-wait-service.d.ts.map +1 -0
- package/dist/worker-runtime-profile-selection.d.ts +2 -0
- package/dist/worker-runtime-profile-selection.d.ts.map +1 -1
- package/package.json +20 -19
- package/src/app.ts +117 -5
- package/src/auth/fastify-auth.ts +13 -0
- package/src/config/config-loader.ts +40 -2
- package/src/config/config-types.ts +14 -1
- package/src/config/kubernetes-docker-isolation.ts +21 -0
- package/src/db/database.ts +159 -40
- package/src/db/execution-inspection-repo.ts +163 -0
- package/src/db/history-window.ts +18 -0
- package/src/db/mapped-llm-run-repo.ts +177 -0
- package/src/db/process-event-repo.ts +88 -10
- package/src/db/process-instance-repo.ts +9 -2
- package/src/db/process-leaf-outcome-snapshot-repo.ts +8 -2
- package/src/db/process-project-repo.ts +4 -0
- package/src/db/process-skill-repo.ts +9 -2
- package/src/db/process-turn-annotation-repo.ts +27 -9
- package/src/db/process-turn-record-repo.ts +53 -13
- package/src/db/publication-repo.ts +63 -0
- package/src/db/repo-helpers.ts +11 -1
- package/src/db/repositories.ts +22 -0
- package/src/db/schema.ts +173 -2
- package/src/db/scoped-settings-repo.ts +234 -0
- package/src/db/skill-repo.ts +89 -27
- package/src/db/turn-start-record-repo.ts +13 -3
- package/src/db/turn-summary-repo.ts +12 -3
- package/src/db/worker-lease-repo.ts +8 -2
- package/src/domain-logic/outcome-tools.ts +4 -149
- package/src/external-source-service.ts +33 -7
- package/src/future-execution/execution.ts +9 -2
- package/src/future-execution/launch-lifecycle.ts +87 -78
- package/src/future-execution/lifecycle.ts +5 -34
- package/src/future-execution/model-projection.ts +2 -0
- package/src/future-execution/reconciliation.ts +7 -0
- package/src/future-execution-presenter.ts +14 -22
- package/src/integration-tool-registry.ts +59 -26
- package/src/launch-coordinator-test-harness.ts +8 -4
- package/src/launch-coordinator.ts +10 -1
- package/src/launcher-model-config-service.ts +24 -3
- package/src/leaf-outcome-snapshot-capture.ts +2 -0
- package/src/primary-path-snapshot.ts +3 -4
- package/src/process-action-presenter.ts +98 -0
- package/src/process-action-registry.ts +31 -39
- package/src/process-engine/decision.ts +10 -0
- package/src/process-engine/engine.ts +13 -4
- package/src/process-engine/mapped-turns.ts +328 -0
- package/src/process-engine/operation.ts +1 -1
- package/src/process-engine/ops/accept-worker-turn-start.ts +6 -0
- package/src/process-engine/ops/continue-failed-turn.ts +2 -13
- package/src/process-engine/ops/process-observation.ts +119 -0
- package/src/process-engine/ops/retry-failed-turn.ts +2 -12
- package/src/process-engine/ops/retry-startup.ts +10 -13
- package/src/process-engine/ops/start-process.ts +34 -2
- package/src/process-engine/ops/turn-outcome.ts +65 -62
- package/src/process-engine/ops/turn-wait.ts +225 -0
- package/src/process-engine/ops/update-model-config.ts +66 -0
- package/src/process-engine/recorder.ts +33 -5
- package/src/process-engine/runner.ts +8 -8
- package/src/process-engine/turn-start-preflight.ts +168 -105
- package/src/process-engine/turn-wait-state.ts +126 -0
- package/src/process-engine/turn-worker-requirement.ts +4 -0
- package/src/process-engine/types.ts +15 -0
- package/src/process-engine/writes/build-process-abort-writes.ts +30 -19
- package/src/process-engine/writes/build-recovery-start-writes.ts +1 -0
- package/src/process-engine/writes/build-turn-outcome-writes.ts +118 -21
- package/src/process-engine/writes/build-turn-selection-writes.ts +2 -31
- package/src/process-engine/writes/commit-writes.ts +20 -2
- package/src/process-engine/writes/reserve-selected-turn-start.ts +44 -0
- package/src/process-engine/writes/writes.ts +73 -61
- package/src/process-graph.ts +0 -1
- package/src/process-inspection-reader.ts +305 -0
- package/src/process-inspection-trace.ts +176 -0
- package/src/process-inspection.ts +169 -0
- package/src/process-instance-tree-presenter.ts +56 -216
- package/src/process-launch-executor.ts +5 -2
- package/src/process-launch-plan.ts +17 -2
- package/src/process-launcher-registry.ts +28 -16
- package/src/process-model-config.ts +100 -0
- package/src/process-model-policy/construct.ts +1 -0
- package/src/process-model-policy/evaluate.ts +34 -32
- package/src/process-model-policy/index.ts +45 -3
- package/src/process-model-policy/project.ts +62 -76
- package/src/process-model-policy/types.ts +26 -0
- package/src/process-model-policy-presenter.ts +7 -3
- package/src/process-runtime-availability.ts +9 -4
- package/src/process-turn-navigation.ts +86 -8
- package/src/process-turn-trace.ts +12 -24
- package/src/process-ui-snapshot-presenter.ts +249 -298
- package/src/routes/future-executions.ts +5 -5
- package/src/routes/launchers.ts +51 -1
- package/src/routes/process-actions.ts +10 -10
- package/src/routes/process-detail.ts +25 -2
- package/src/routes/process-diagnostics-assembler.ts +32 -6
- package/src/routes/process-model-config.ts +70 -0
- package/src/routes/process-primary-path-assembler.ts +17 -33
- package/src/routes/process-route-helpers.ts +161 -327
- package/src/routes/processes.ts +2 -0
- package/src/routes/settings.ts +173 -0
- package/src/routes/ticket-creation.ts +28 -5
- package/src/scoped-settings-service.ts +736 -0
- package/src/server-bootstrap/build-host-capabilities.ts +42 -0
- package/src/server-bootstrap/register-http.ts +7 -1
- package/src/session-summary-projection.ts +1 -2
- package/src/skills/bundled-skills.ts +64 -0
- package/src/skills/catalog-service.ts +35 -6
- package/src/skills/extension-importer.ts +97 -0
- package/src/skills/launch-skills.ts +19 -0
- package/src/skills/skill-frontmatter.ts +13 -0
- package/src/skills/source-importer.ts +3 -0
- package/src/startup-evidence.ts +20 -0
- package/src/supervisor/execution-inspection-ingestor.ts +55 -0
- package/src/supervisor/ipc-handler.ts +29 -18
- package/src/supervisor/worker-event-ingestor.ts +30 -14
- package/src/supervisor/worker-start-payload-builder.ts +42 -0
- package/src/supervisor/worker-supervisor.ts +5 -0
- package/src/supervisor/worker-turn-ipc-recorder.ts +13 -1
- package/src/test-helpers/accepted-turn-start.ts +51 -27
- package/src/test-helpers/owned-test-deps.ts +45 -0
- package/src/test-helpers/prepared-fixture-start.ts +1 -0
- package/src/test-helpers/process-model-fixtures.ts +2 -0
- package/src/test-helpers/scoped-settings-fixtures.ts +126 -0
- package/src/test-helpers/skill-fixtures.ts +28 -0
- package/src/testing.ts +4 -1
- package/src/tool-approval-gate.ts +16 -0
- package/src/turn-progress.ts +3 -2
- package/src/turn-wait-service.ts +228 -0
- package/src/worker-runtime-profile-selection.ts +8 -1
- package/dist/app-4QSV4FUQ.js +0 -8
- package/dist/chunk-KIOQNNG6.js.map +0 -1
- package/dist/chunk-LK3RO6C7.js.map +0 -1
- /package/dist/{app-4QSV4FUQ.js.map → app-JM4CBTND.js.map} +0 -0
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
isAutomaticTurnDefinition,
|
|
10
10
|
isLlmTurnDefinition,
|
|
11
11
|
parseStructuralProcessState,
|
|
12
|
+
type ResolvedOutcomeContract,
|
|
12
13
|
} from "@leitwerk-dev/process-sdk";
|
|
13
14
|
import { validateTurnOutcomeCorrelation } from "../../domain-logic/turn-record-guards.js";
|
|
14
15
|
import { captureLeafOutcomeSnapshot } from "../../leaf-outcome-snapshot-capture.js";
|
|
@@ -95,11 +96,20 @@ function resolveOutcomePublication(input: {
|
|
|
95
96
|
turnId: string;
|
|
96
97
|
outcome: string;
|
|
97
98
|
turnPublishedProduct: string | null;
|
|
99
|
+
outcomeContract?: ResolvedOutcomeContract;
|
|
98
100
|
}): {
|
|
99
101
|
productName: string | null;
|
|
100
102
|
markdownParameterName: string | null;
|
|
101
103
|
resultSummaryParameter?: string;
|
|
102
104
|
} {
|
|
105
|
+
if (input.outcomeContract) {
|
|
106
|
+
const outcome = input.outcomeContract.outcomes[input.outcome];
|
|
107
|
+
return {
|
|
108
|
+
productName: outcome?.publishedProduct ?? input.outcomeContract.publishedProduct,
|
|
109
|
+
markdownParameterName: outcome?.turnResultMarkdownParameter ?? null,
|
|
110
|
+
resultSummaryParameter: outcome?.resultSummaryParameter,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
103
113
|
const definition = input.processGraphs.get(input.processId)?.turns.get(input.turnId)?.definition;
|
|
104
114
|
if (!definition || (!isLlmTurnDefinition(definition) && !isAutomaticTurnDefinition(definition))) {
|
|
105
115
|
return { productName: input.turnPublishedProduct, markdownParameterName: null };
|
|
@@ -158,6 +168,16 @@ export const TurnOutcome = defineOperation<"turn_outcome", TurnOutcomeInput, voi
|
|
|
158
168
|
input.onRecorded?.();
|
|
159
169
|
},
|
|
160
170
|
async decide(ctx, input) {
|
|
171
|
+
const currentStart =
|
|
172
|
+
ctx.process.currentExecution?.kind === "worker_start"
|
|
173
|
+
? ctx.deps.turnStarts.getById(ctx.process.currentExecution.id)
|
|
174
|
+
: null;
|
|
175
|
+
const outcomeContract =
|
|
176
|
+
currentStart?.state.kind === "accepted" && currentStart.state.start?.kind === "llm"
|
|
177
|
+
? (currentStart.state.start.outcomeContract as unknown as
|
|
178
|
+
| ResolvedOutcomeContract
|
|
179
|
+
| undefined)
|
|
180
|
+
: undefined;
|
|
161
181
|
const initialPayload = input.payload;
|
|
162
182
|
const turnGraph = getProcessTurnGraph(
|
|
163
183
|
ctx.deps.processGraphs,
|
|
@@ -171,16 +191,12 @@ export const TurnOutcome = defineOperation<"turn_outcome", TurnOutcomeInput, voi
|
|
|
171
191
|
turnId: initialPayload.turnId,
|
|
172
192
|
outcome: initialPayload.outcome,
|
|
173
193
|
turnPublishedProduct: turnGraph?.publishedProduct ?? null,
|
|
194
|
+
outcomeContract,
|
|
174
195
|
});
|
|
175
196
|
const payload = resolveEffectiveOutcomePayload({ payload: initialPayload, publication });
|
|
176
197
|
const publishedProduct = publication.productName;
|
|
177
198
|
const expected =
|
|
178
|
-
|
|
179
|
-
? (() => {
|
|
180
|
-
const state = ctx.deps.turnStarts.getById(ctx.process.currentExecution.id)?.state;
|
|
181
|
-
return state?.kind === "accepted" ? state.turnRecordId : null;
|
|
182
|
-
})()
|
|
183
|
-
: null;
|
|
199
|
+
currentStart?.state.kind === "accepted" ? currentStart.state.turnRecordId : null;
|
|
184
200
|
const correlationError = validateTurnOutcomeCorrelation(ctx.process, payload, expected);
|
|
185
201
|
if (correlationError) {
|
|
186
202
|
return reject(correlationError.code, correlationError.message);
|
|
@@ -197,7 +213,10 @@ export const TurnOutcome = defineOperation<"turn_outcome", TurnOutcomeInput, voi
|
|
|
197
213
|
}
|
|
198
214
|
const requiredMarkdownError = validateRequiredTurnResultMarkdown({
|
|
199
215
|
payload,
|
|
200
|
-
required:
|
|
216
|
+
required: outcomeContract
|
|
217
|
+
? outcomeContract.turnResultMarkdown?.mode !== "none" &&
|
|
218
|
+
outcomeContract.turnResultMarkdown?.required === true
|
|
219
|
+
: turnGraph?.turnResultMarkdownRequired === true,
|
|
201
220
|
});
|
|
202
221
|
if (requiredMarkdownError) {
|
|
203
222
|
return reject(requiredMarkdownError.code, requiredMarkdownError.message);
|
|
@@ -275,70 +294,43 @@ export const TurnOutcome = defineOperation<"turn_outcome", TurnOutcomeInput, voi
|
|
|
275
294
|
});
|
|
276
295
|
}
|
|
277
296
|
const existing = ctx.deps.turnRecords.getById(payload.turnRecordId);
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
turnResultMarkdown: payload.turnResultMarkdown ?? null,
|
|
303
|
-
errorSummary: null,
|
|
304
|
-
errorClass: null,
|
|
305
|
-
startedAt: recordedAt,
|
|
306
|
-
endedAt: recordedAt,
|
|
307
|
-
};
|
|
297
|
+
const completion = {
|
|
298
|
+
turnType: payload.turnType,
|
|
299
|
+
status: "succeeded" as const,
|
|
300
|
+
resultPiEntryId: payload.resultPiEntryId ?? null,
|
|
301
|
+
turnResultMarkdown: payload.turnResultMarkdown ?? null,
|
|
302
|
+
endedAt: recordedAt,
|
|
303
|
+
};
|
|
304
|
+
const completedTurnRecord: ProcessTurnRecord = {
|
|
305
|
+
...(existing ?? {
|
|
306
|
+
id: payload.turnRecordId,
|
|
307
|
+
instanceId: input.instanceId,
|
|
308
|
+
turnId: payload.turnId,
|
|
309
|
+
attemptNumber: 1,
|
|
310
|
+
parentTurnRecordId: null,
|
|
311
|
+
pathType: payload.pathType ?? "primary",
|
|
312
|
+
forkPiEntryId: payload.forkPiEntryId ?? null,
|
|
313
|
+
modelProfileId: null,
|
|
314
|
+
startedAt: recordedAt,
|
|
315
|
+
}),
|
|
316
|
+
...completion,
|
|
317
|
+
turnType: existing ? (payload.turnType ?? existing.turnType) : payload.turnType,
|
|
318
|
+
errorSummary: null,
|
|
319
|
+
errorClass: null,
|
|
320
|
+
};
|
|
308
321
|
if (existing) {
|
|
309
322
|
baseWrites.turnRecordWrites.push({
|
|
310
323
|
kind: "update",
|
|
311
324
|
id: payload.turnRecordId,
|
|
312
|
-
input:
|
|
313
|
-
turnType: payload.turnType,
|
|
314
|
-
status: "succeeded",
|
|
315
|
-
resultPiEntryId: payload.resultPiEntryId ?? null,
|
|
316
|
-
turnResultMarkdown: payload.turnResultMarkdown ?? null,
|
|
317
|
-
endedAt: recordedAt,
|
|
318
|
-
},
|
|
325
|
+
input: completion,
|
|
319
326
|
});
|
|
320
327
|
} else {
|
|
328
|
+
const { modelProfileId, ...recordInput } = completedTurnRecord;
|
|
321
329
|
baseWrites.turnRecordWrites.push({
|
|
322
330
|
kind: "create",
|
|
323
331
|
input: {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
turnId: completedTurnRecord.turnId,
|
|
327
|
-
turnType: completedTurnRecord.turnType,
|
|
328
|
-
status: completedTurnRecord.status,
|
|
329
|
-
attemptNumber: completedTurnRecord.attemptNumber,
|
|
330
|
-
parentTurnRecordId: completedTurnRecord.parentTurnRecordId,
|
|
331
|
-
pathType: completedTurnRecord.pathType,
|
|
332
|
-
forkPiEntryId: completedTurnRecord.forkPiEntryId,
|
|
333
|
-
resultPiEntryId: completedTurnRecord.resultPiEntryId,
|
|
334
|
-
...(completedTurnRecord.modelProfileId !== null
|
|
335
|
-
? { modelProfileId: completedTurnRecord.modelProfileId }
|
|
336
|
-
: {}),
|
|
337
|
-
turnResultMarkdown: completedTurnRecord.turnResultMarkdown,
|
|
338
|
-
errorSummary: completedTurnRecord.errorSummary,
|
|
339
|
-
errorClass: completedTurnRecord.errorClass,
|
|
340
|
-
startedAt: completedTurnRecord.startedAt,
|
|
341
|
-
endedAt: completedTurnRecord.endedAt,
|
|
332
|
+
...recordInput,
|
|
333
|
+
...(modelProfileId !== null ? { modelProfileId } : {}),
|
|
342
334
|
},
|
|
343
335
|
});
|
|
344
336
|
}
|
|
@@ -353,8 +345,12 @@ export const TurnOutcome = defineOperation<"turn_outcome", TurnOutcomeInput, voi
|
|
|
353
345
|
projects,
|
|
354
346
|
payload,
|
|
355
347
|
turnRecords: ctx.deps.turnRecords,
|
|
348
|
+
events: ctx.deps.events,
|
|
356
349
|
processGraphs: ctx.deps.processGraphs,
|
|
357
350
|
processActionRegistry,
|
|
351
|
+
mappedRuns: ctx.deps.mappedRuns,
|
|
352
|
+
iteration: currentStart?.iteration ?? null,
|
|
353
|
+
outcomeContract: outcomeContract ? { ...outcomeContract } : undefined,
|
|
358
354
|
});
|
|
359
355
|
if (isWriteBuildFailure(outcomeWrites)) {
|
|
360
356
|
return reject(outcomeWrites.code, outcomeWrites.message);
|
|
@@ -454,7 +450,14 @@ export const TurnOutcome = defineOperation<"turn_outcome", TurnOutcomeInput, voi
|
|
|
454
450
|
...mergedWrites.processPatch,
|
|
455
451
|
stateJson: mergedWrites.processPatch.stateJson ?? ctx.process.stateJson,
|
|
456
452
|
};
|
|
453
|
+
const mappedWrite = mergedWrites.mappedRunWrites.find(
|
|
454
|
+
(write) =>
|
|
455
|
+
write.kind === "complete_item" && write.input.turnRecordId === completedTurnRecord.id,
|
|
456
|
+
);
|
|
457
457
|
const snapshotInput = await captureLeafOutcomeSnapshot({
|
|
458
|
+
...(mappedWrite?.kind === "complete_item"
|
|
459
|
+
? { mappedResult: JSON.parse(mappedWrite.input.resultJson) as unknown }
|
|
460
|
+
: {}),
|
|
458
461
|
process: capturedProcess,
|
|
459
462
|
projects,
|
|
460
463
|
processActionRegistry,
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import type { Actor } from "@leitwerk-dev/domain";
|
|
2
|
+
import type { InitialProcessBinding } from "@leitwerk-dev/process-sdk";
|
|
3
|
+
import { accept, modelOverrideMetadata, noWrites, reject } from "../decision.js";
|
|
4
|
+
import { defineOperation } from "../operation.js";
|
|
5
|
+
import { pendingTurnWait, turnWaitPredicate, writeTurnWait } from "../turn-wait-state.js";
|
|
6
|
+
import { buildTurnSelectionWrites } from "../writes/build-turn-selection-writes.js";
|
|
7
|
+
import {
|
|
8
|
+
appendProcessEvent,
|
|
9
|
+
applyProcessPatchField,
|
|
10
|
+
createWrites,
|
|
11
|
+
type DecisionMetadata,
|
|
12
|
+
isWriteBuildFailure,
|
|
13
|
+
stampActorOnEvents,
|
|
14
|
+
} from "../writes/writes.js";
|
|
15
|
+
|
|
16
|
+
/** Initialize waiting after a compatible process-definition migration. */
|
|
17
|
+
export const ArmTurnWait = defineOperation<"arm_turn_wait", { instanceId: string }, void>({
|
|
18
|
+
kind: "arm_turn_wait",
|
|
19
|
+
label: "Wait for turn readiness",
|
|
20
|
+
admission: "new_turn",
|
|
21
|
+
decide({ process, deps }) {
|
|
22
|
+
if (
|
|
23
|
+
pendingTurnWait(process) ||
|
|
24
|
+
process.currentExecution ||
|
|
25
|
+
!process.selectedTurnId ||
|
|
26
|
+
process.lifecycleStatus !== "active" ||
|
|
27
|
+
!turnWaitPredicate(deps.processGraphs, process)
|
|
28
|
+
)
|
|
29
|
+
return noWrites();
|
|
30
|
+
const writes = buildTurnSelectionWrites(deps.processGraphs, process, {
|
|
31
|
+
toTurnId: process.selectedTurnId,
|
|
32
|
+
});
|
|
33
|
+
return isWriteBuildFailure(writes) ? writes : accept({ writes });
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
interface ResolveTurnWaitInput {
|
|
38
|
+
instanceId: string;
|
|
39
|
+
waitId: string;
|
|
40
|
+
revision: number;
|
|
41
|
+
paramsJson: string | null;
|
|
42
|
+
stateJson: string | null;
|
|
43
|
+
projectsJson: string;
|
|
44
|
+
/** State validated and encoded by the readiness service. */
|
|
45
|
+
nextStateJson?: string;
|
|
46
|
+
initialBinding?: InitialProcessBinding;
|
|
47
|
+
result: "ready" | "waiting" | "complete" | "abort" | "bind" | "retry" | "error";
|
|
48
|
+
message?: string;
|
|
49
|
+
now: number;
|
|
50
|
+
pollIntervalMs: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Commit a check made outside the process lock, only if its inputs are still current. */
|
|
54
|
+
export const ResolveTurnWait = defineOperation<"resolve_turn_wait", ResolveTurnWaitInput, void>({
|
|
55
|
+
kind: "resolve_turn_wait",
|
|
56
|
+
label: "Resolve turn readiness",
|
|
57
|
+
admission: "new_turn",
|
|
58
|
+
decide({ process, deps }, input) {
|
|
59
|
+
const wait = pendingTurnWait(process);
|
|
60
|
+
if (
|
|
61
|
+
!wait ||
|
|
62
|
+
wait.id !== input.waitId ||
|
|
63
|
+
wait.revision !== input.revision ||
|
|
64
|
+
process.selectedTurnId !== wait.turnId ||
|
|
65
|
+
process.lifecycleStatus !== "waiting" ||
|
|
66
|
+
process.paramsJson !== input.paramsJson ||
|
|
67
|
+
process.stateJson !== input.stateJson ||
|
|
68
|
+
JSON.stringify(deps.projects.listByInstance(process.id)) !== input.projectsJson
|
|
69
|
+
) {
|
|
70
|
+
return reject("turn_wait_superseded", "The waiting condition has changed");
|
|
71
|
+
}
|
|
72
|
+
const writes = createWrites();
|
|
73
|
+
if (input.nextStateJson !== undefined && !["retry", "error"].includes(input.result))
|
|
74
|
+
applyProcessPatchField(writes, process, "stateJson", input.nextStateJson);
|
|
75
|
+
if (input.result === "bind") {
|
|
76
|
+
const binding = input.initialBinding;
|
|
77
|
+
if (
|
|
78
|
+
!binding?.projects.length ||
|
|
79
|
+
!wait.initialSelection ||
|
|
80
|
+
process.currentExecution ||
|
|
81
|
+
deps.projects.listByInstance(process.id).length ||
|
|
82
|
+
deps.turnStarts.listByInstance(process.id).length ||
|
|
83
|
+
deps.turnRecords.listByInstance(process.id).length
|
|
84
|
+
)
|
|
85
|
+
return reject(
|
|
86
|
+
"startup_binding_unavailable",
|
|
87
|
+
"Initial bindings require a process without projects or execution history",
|
|
88
|
+
);
|
|
89
|
+
if (
|
|
90
|
+
Object.keys(binding.metadata ?? {}).some(
|
|
91
|
+
(key) => key === "turnWait" || Object.hasOwn(process.metadata ?? {}, key),
|
|
92
|
+
)
|
|
93
|
+
)
|
|
94
|
+
return reject(
|
|
95
|
+
"startup_binding_superseded",
|
|
96
|
+
"Initial repository binding cannot replace retained metadata",
|
|
97
|
+
);
|
|
98
|
+
const definition = deps.processGraphs.get(process.processId);
|
|
99
|
+
if (!definition) return reject("process_not_found", "Process definition is unavailable");
|
|
100
|
+
applyProcessPatchField(
|
|
101
|
+
writes,
|
|
102
|
+
process,
|
|
103
|
+
"paramsJson",
|
|
104
|
+
JSON.stringify(
|
|
105
|
+
definition.paramsCodec.serialize(definition.paramsCodec.parse(binding.params)),
|
|
106
|
+
),
|
|
107
|
+
);
|
|
108
|
+
applyProcessPatchField(writes, process, "metadata", {
|
|
109
|
+
...process.metadata,
|
|
110
|
+
...binding.metadata,
|
|
111
|
+
...(binding.settingsContext ? { settingsContext: binding.settingsContext } : {}),
|
|
112
|
+
});
|
|
113
|
+
writes.initialProjects = binding.projects.map((project) => ({
|
|
114
|
+
...project,
|
|
115
|
+
instanceId: process.id,
|
|
116
|
+
}));
|
|
117
|
+
writeTurnWait(writes, process, {
|
|
118
|
+
...wait,
|
|
119
|
+
revision: wait.revision + 1,
|
|
120
|
+
message: null,
|
|
121
|
+
failures: 0,
|
|
122
|
+
nextCheckAt: 0,
|
|
123
|
+
});
|
|
124
|
+
appendProcessEvent(writes, process, {
|
|
125
|
+
eventType: "initial_repositories_bound",
|
|
126
|
+
level: "info",
|
|
127
|
+
message: "Startup repository bindings resolved",
|
|
128
|
+
data: { projectKeys: binding.projects.map((p) => p.key) },
|
|
129
|
+
});
|
|
130
|
+
return accept({ writes });
|
|
131
|
+
}
|
|
132
|
+
if (input.result === "ready") {
|
|
133
|
+
writeTurnWait(writes, process, null);
|
|
134
|
+
writes.waitForAdmission = wait.id;
|
|
135
|
+
writes.turnStartWrites.push({ kind: "create", input: wait.start });
|
|
136
|
+
applyProcessPatchField(writes, process, "currentExecution", {
|
|
137
|
+
kind: "worker_start",
|
|
138
|
+
id: wait.start.id as string,
|
|
139
|
+
});
|
|
140
|
+
applyProcessPatchField(writes, process, "lifecycleStatus", "active");
|
|
141
|
+
writes.workerIntent = { kind: "reconcile" };
|
|
142
|
+
return accept({ writes, metadata: wait.metadata });
|
|
143
|
+
}
|
|
144
|
+
if (input.result === "complete" || input.result === "abort") {
|
|
145
|
+
writeTurnWait(writes, process, null);
|
|
146
|
+
applyProcessPatchField(writes, process, "selectedTurnId", null);
|
|
147
|
+
applyProcessPatchField(writes, process, "currentExecution", null);
|
|
148
|
+
applyProcessPatchField(
|
|
149
|
+
writes,
|
|
150
|
+
process,
|
|
151
|
+
"lifecycleStatus",
|
|
152
|
+
input.result === "abort" ? "aborted" : "completed",
|
|
153
|
+
);
|
|
154
|
+
writes.workerIntent = { kind: "reconcile" };
|
|
155
|
+
appendProcessEvent(writes, process, {
|
|
156
|
+
eventType: input.result === "abort" ? "process_aborted" : "process_completed",
|
|
157
|
+
level: "info",
|
|
158
|
+
message: input.message ?? "Waiting condition completed the process",
|
|
159
|
+
});
|
|
160
|
+
return accept({ writes });
|
|
161
|
+
}
|
|
162
|
+
const failures = input.result === "retry" ? wait.failures + 1 : 0;
|
|
163
|
+
const message = input.message ?? null;
|
|
164
|
+
writeTurnWait(writes, process, {
|
|
165
|
+
...wait,
|
|
166
|
+
revision: wait.revision + 1,
|
|
167
|
+
status: input.result === "error" ? "error" : "waiting",
|
|
168
|
+
failures,
|
|
169
|
+
message,
|
|
170
|
+
nextCheckAt:
|
|
171
|
+
input.now +
|
|
172
|
+
(failures
|
|
173
|
+
? Math.min(300_000, input.pollIntervalMs * 2 ** Math.min(failures, 8))
|
|
174
|
+
: input.pollIntervalMs),
|
|
175
|
+
});
|
|
176
|
+
if (input.result === "error")
|
|
177
|
+
applyProcessPatchField(writes, process, "lifecycleStatus", "error");
|
|
178
|
+
if (message !== wait.message)
|
|
179
|
+
appendProcessEvent(writes, process, {
|
|
180
|
+
eventType: message ? "turn_wait_failed" : "turn_wait_recovered",
|
|
181
|
+
level: message ? "warn" : "info",
|
|
182
|
+
message: message ?? "Waiting condition recovered",
|
|
183
|
+
data: { turnId: wait.turnId, retryable: input.result === "retry", safeSummary: message },
|
|
184
|
+
});
|
|
185
|
+
writes.preserveUpdatedAt =
|
|
186
|
+
input.result !== "error" &&
|
|
187
|
+
message === wait.message &&
|
|
188
|
+
writes.changedFields.every((field) => field === "metadata");
|
|
189
|
+
return accept({ writes });
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
export const RetryTurnWait = defineOperation<
|
|
194
|
+
"retry_turn_wait",
|
|
195
|
+
DecisionMetadata & { instanceId: string; actor?: Actor },
|
|
196
|
+
void
|
|
197
|
+
>({
|
|
198
|
+
kind: "retry_turn_wait",
|
|
199
|
+
label: "Retry waiting condition",
|
|
200
|
+
admission: "new_turn",
|
|
201
|
+
decide({ process }, input) {
|
|
202
|
+
const wait = pendingTurnWait(process);
|
|
203
|
+
if (!wait || wait.status !== "error" || process.lifecycleStatus !== "error")
|
|
204
|
+
return reject("retry_target_missing", "No failed waiting condition is current");
|
|
205
|
+
const writes = createWrites();
|
|
206
|
+
writeTurnWait(writes, process, {
|
|
207
|
+
...wait,
|
|
208
|
+
status: "waiting",
|
|
209
|
+
revision: wait.revision + 1,
|
|
210
|
+
nextCheckAt: 0,
|
|
211
|
+
failures: 0,
|
|
212
|
+
message: null,
|
|
213
|
+
metadata: { ...wait.metadata, ...modelOverrideMetadata(input) },
|
|
214
|
+
});
|
|
215
|
+
applyProcessPatchField(writes, process, "lifecycleStatus", "waiting");
|
|
216
|
+
appendProcessEvent(writes, process, {
|
|
217
|
+
eventType: "turn_wait_retry",
|
|
218
|
+
level: "info",
|
|
219
|
+
message: "Waiting condition retry requested",
|
|
220
|
+
data: { turnId: wait.turnId },
|
|
221
|
+
});
|
|
222
|
+
stampActorOnEvents(writes, input.actor, "turn_wait_retry");
|
|
223
|
+
return accept({ writes });
|
|
224
|
+
},
|
|
225
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Actor } from "@leitwerk-dev/domain";
|
|
2
|
+
import type {
|
|
3
|
+
ProcessModelConfigPatch,
|
|
4
|
+
ProcessModelConfigResponseBody,
|
|
5
|
+
} from "@leitwerk-dev/protocol/http-contracts";
|
|
6
|
+
import { prepareProcessModelConfig } from "../../process-model-config.js";
|
|
7
|
+
import { accept, reject } from "../decision.js";
|
|
8
|
+
import { defineOperation } from "../operation.js";
|
|
9
|
+
import { appendProcessEvent, applyProcessPatchField, createWrites } from "../writes/writes.js";
|
|
10
|
+
|
|
11
|
+
/** @internal */
|
|
12
|
+
export const UpdateModelConfig = defineOperation<
|
|
13
|
+
"update_model_config",
|
|
14
|
+
{
|
|
15
|
+
instanceId: string;
|
|
16
|
+
patch: ProcessModelConfigPatch;
|
|
17
|
+
actor: Actor;
|
|
18
|
+
},
|
|
19
|
+
ProcessModelConfigResponseBody
|
|
20
|
+
>({
|
|
21
|
+
kind: "update_model_config",
|
|
22
|
+
decide(ctx, input) {
|
|
23
|
+
let prepared: ReturnType<typeof prepareProcessModelConfig>;
|
|
24
|
+
try {
|
|
25
|
+
prepared = prepareProcessModelConfig({
|
|
26
|
+
process: ctx.process,
|
|
27
|
+
patch: input.patch,
|
|
28
|
+
policy: ctx.deps.processModelPolicy,
|
|
29
|
+
availability: ctx.deps.getModelAvailabilitySnapshot(),
|
|
30
|
+
});
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return reject(
|
|
33
|
+
"invalid_model_config",
|
|
34
|
+
error instanceof Error ? error.message : "Invalid model configuration",
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
const writes = createWrites();
|
|
38
|
+
applyProcessPatchField(
|
|
39
|
+
writes,
|
|
40
|
+
ctx.process,
|
|
41
|
+
"defaultModelProfileId",
|
|
42
|
+
prepared.settings.defaultModelProfileId,
|
|
43
|
+
);
|
|
44
|
+
applyProcessPatchField(
|
|
45
|
+
writes,
|
|
46
|
+
ctx.process,
|
|
47
|
+
"turnConfigsJson",
|
|
48
|
+
prepared.settings.turnConfigsJson,
|
|
49
|
+
);
|
|
50
|
+
appendProcessEvent(writes, ctx.process, {
|
|
51
|
+
eventType: "model_configuration_changed",
|
|
52
|
+
level: "info",
|
|
53
|
+
message: "Model defaults updated for future executions",
|
|
54
|
+
data: {
|
|
55
|
+
actor: input.actor,
|
|
56
|
+
patch: input.patch,
|
|
57
|
+
previous: {
|
|
58
|
+
defaultModelProfileId: ctx.process.defaultModelProfileId,
|
|
59
|
+
turnConfigsJson: ctx.process.turnConfigsJson,
|
|
60
|
+
},
|
|
61
|
+
settings: prepared.settings,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
return accept({ writes, data: { modelConfiguration: prepared.modelConfiguration } });
|
|
65
|
+
},
|
|
66
|
+
});
|
|
@@ -13,12 +13,14 @@ import { evaluateAtStableAvailabilityRevision } from "../process-model-policy/in
|
|
|
13
13
|
import { presentProcessModelPolicyFailure } from "../process-model-policy-presenter.js";
|
|
14
14
|
import type { Decision, Reaction } from "./decision.js";
|
|
15
15
|
import { logProcessEngineError, publicInternalEngineFailureMessage } from "./internal-failures.js";
|
|
16
|
+
import { planMappedTurnEntries } from "./mapped-turns.js";
|
|
16
17
|
import type {
|
|
17
18
|
OperationData,
|
|
18
19
|
OperationInput,
|
|
19
20
|
OperationInputBase,
|
|
20
21
|
OperationSpec,
|
|
21
22
|
} from "./operation.js";
|
|
23
|
+
import { deferTurnWaitStarts, pendingTurnWait } from "./turn-wait-state.js";
|
|
22
24
|
import type {
|
|
23
25
|
EngineErrorCode,
|
|
24
26
|
ProcessEngineDeps,
|
|
@@ -161,6 +163,19 @@ export async function record<TOp extends OperationSpec<string, OperationInputBas
|
|
|
161
163
|
* commits all writes in one SQLite transaction, then derives a complete
|
|
162
164
|
* reaction list for the post-commit stage.
|
|
163
165
|
*/
|
|
166
|
+
deferTurnWaitStarts(deps.processGraphs, initialProcess, decision.writes, decision.metadata);
|
|
167
|
+
const mappedPlan = await planMappedTurnEntries({
|
|
168
|
+
processGraphs: deps.processGraphs,
|
|
169
|
+
registry: deps.getProcessActionRegistry?.(),
|
|
170
|
+
mappedRuns: deps.mappedRuns,
|
|
171
|
+
projects: deps.projects,
|
|
172
|
+
process: initialProcess,
|
|
173
|
+
writes: decision.writes,
|
|
174
|
+
});
|
|
175
|
+
if (!mappedPlan.ok) {
|
|
176
|
+
return { ok: false, stage: "pre_commit", code: mappedPlan.code, message: mappedPlan.message };
|
|
177
|
+
}
|
|
178
|
+
deferTurnWaitStarts(deps.processGraphs, initialProcess, decision.writes, decision.metadata);
|
|
164
179
|
const baselineWrites = structuredClone(decision.writes);
|
|
165
180
|
const runModelPreparation = async (availability: ModelStatusCacheSnapshot) => {
|
|
166
181
|
const candidateProcess: ProcessInstance = {
|
|
@@ -172,13 +187,24 @@ export async function record<TOp extends OperationSpec<string, OperationInputBas
|
|
|
172
187
|
write.kind === "create" && write.input.turnType === "llm",
|
|
173
188
|
);
|
|
174
189
|
const shouldResolveSelection =
|
|
190
|
+
!pendingTurnWait(candidateProcess) &&
|
|
175
191
|
!!candidateProcess.selectedTurnId &&
|
|
176
192
|
(!!createdStart ||
|
|
177
193
|
candidateProcess.selectedTurnId !== initialProcess.selectedTurnId ||
|
|
178
194
|
(candidateProcess.lifecycleStatus === "active" &&
|
|
179
195
|
initialProcess.lifecycleStatus !== "active") ||
|
|
180
196
|
Object.hasOwn(decision.metadata ?? {}, "nextTurnModelProfileId"));
|
|
181
|
-
if (
|
|
197
|
+
if (
|
|
198
|
+
(candidateProcess.selectedTurnId &&
|
|
199
|
+
deps.processGraphs
|
|
200
|
+
.get(candidateProcess.processId)
|
|
201
|
+
?.turns.get(candidateProcess.selectedTurnId)?.definition.kind !== "llm") ||
|
|
202
|
+
(!candidateProcess.selectedTurnId &&
|
|
203
|
+
!(
|
|
204
|
+
candidateProcess.lifecycleStatus === "discovered" &&
|
|
205
|
+
candidateProcess.selectedTurnModelSource === "launch_override"
|
|
206
|
+
))
|
|
207
|
+
) {
|
|
182
208
|
applyProcessPatchField(decision.writes, initialProcess, "selectedTurnModelProfileId", null);
|
|
183
209
|
applyProcessPatchField(decision.writes, initialProcess, "selectedTurnModelKind", null);
|
|
184
210
|
applyProcessPatchField(decision.writes, initialProcess, "selectedTurnModelSource", null);
|
|
@@ -190,10 +216,12 @@ export async function record<TOp extends OperationSpec<string, OperationInputBas
|
|
|
190
216
|
availability,
|
|
191
217
|
startKind: createdStart?.input.startKind,
|
|
192
218
|
initialSelection:
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
219
|
+
(decision.writes.waitForAdmission === pendingTurnWait(initialProcess)?.id &&
|
|
220
|
+
pendingTurnWait(initialProcess)?.initialSelection === true) ||
|
|
221
|
+
(createdStart?.input.startKind === "selected_turn" &&
|
|
222
|
+
initialProcess.selectedTurnId === null &&
|
|
223
|
+
initialProcess.lifecycleStatus === "discovered" &&
|
|
224
|
+
initialProcess.planRevision === 0),
|
|
197
225
|
...(Object.hasOwn(decision.metadata ?? {}, "nextTurnModelProfileId")
|
|
198
226
|
? { modelOverride: decision.metadata?.nextTurnModelProfileId ?? null }
|
|
199
227
|
: {}),
|
|
@@ -216,14 +216,6 @@ export function createEngineRunner(
|
|
|
216
216
|
if (lockedOutcome.kind === "pre_commit_failed") {
|
|
217
217
|
return mapPreCommitFailure(lockedOutcome.failure, lockedOutcome.initialProcess);
|
|
218
218
|
}
|
|
219
|
-
if (lockedOutcome.kind === "post_commit_failed") {
|
|
220
|
-
return mapPostCommitFailure(
|
|
221
|
-
lockedOutcome.recorded as RecordedDecision<
|
|
222
|
-
OperationSpec<string, OperationInputBase, OperationData<TOp>>
|
|
223
|
-
>,
|
|
224
|
-
lockedOutcome.failure,
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
219
|
|
|
228
220
|
const { recorded } = lockedOutcome;
|
|
229
221
|
try {
|
|
@@ -237,6 +229,14 @@ export function createEngineRunner(
|
|
|
237
229
|
code: "after_record_callback_failed",
|
|
238
230
|
});
|
|
239
231
|
}
|
|
232
|
+
if (lockedOutcome.kind === "post_commit_failed") {
|
|
233
|
+
return mapPostCommitFailure(
|
|
234
|
+
lockedOutcome.recorded as RecordedDecision<
|
|
235
|
+
OperationSpec<string, OperationInputBase, OperationData<TOp>>
|
|
236
|
+
>,
|
|
237
|
+
lockedOutcome.failure,
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
240
|
try {
|
|
241
241
|
await deps.afterRecord?.(recorded.process);
|
|
242
242
|
const dispatchResult = await dispatchReactions(
|