@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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
InspectionContextObservation,
|
|
2
3
|
ProcessInstance,
|
|
3
|
-
ProcessTurnAnnotation,
|
|
4
4
|
ProcessTurnRecord,
|
|
5
|
+
WorkerLease,
|
|
5
6
|
} from "@leitwerk-dev/domain";
|
|
6
7
|
import type {
|
|
7
8
|
InstanceTreeEdgeSummary,
|
|
@@ -9,8 +10,7 @@ import type {
|
|
|
9
10
|
ProcessInstanceTreeResponseBody,
|
|
10
11
|
ProcessRunTurnView,
|
|
11
12
|
} from "@leitwerk-dev/protocol/http-contracts";
|
|
12
|
-
|
|
13
|
-
type Decision = InstanceTreeEdgeSummary & { timestamp: string };
|
|
13
|
+
import { createInspectionLineage } from "./process-inspection.js";
|
|
14
14
|
|
|
15
15
|
function titleCase(value: string): string {
|
|
16
16
|
return value
|
|
@@ -18,179 +18,31 @@ function titleCase(value: string): string {
|
|
|
18
18
|
.replaceAll(/\b\w/g, (character) => character.toUpperCase());
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
const value = annotation.payload[key];
|
|
23
|
-
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function nextLlmAfterAutomatic(
|
|
27
|
-
automatic: ProcessTurnRecord,
|
|
28
|
-
allRecords: readonly ProcessTurnRecord[],
|
|
29
|
-
): ProcessTurnRecord | undefined {
|
|
30
|
-
const start = allRecords.findIndex((record) => record.id === automatic.id) + 1;
|
|
31
|
-
for (let index = start; index > 0 && index < allRecords.length; index += 1) {
|
|
32
|
-
const record = allRecords[index];
|
|
33
|
-
if (record.turnType === "human" || record.turnType === "external") return undefined;
|
|
34
|
-
if (record.turnType === "llm") return record;
|
|
35
|
-
}
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function actionDecisions(
|
|
40
|
-
process: ProcessInstance,
|
|
41
|
-
annotations: readonly ProcessTurnAnnotation[],
|
|
42
|
-
allRecords: readonly ProcessTurnRecord[],
|
|
43
|
-
llmRecords: readonly ProcessTurnRecord[],
|
|
44
|
-
): Decision[] {
|
|
45
|
-
const llmById = new Map(llmRecords.map((record) => [record.id, record]));
|
|
46
|
-
const claimedTargets = new Set<string>();
|
|
47
|
-
const decisions: Decision[] = [];
|
|
48
|
-
const candidates = annotations
|
|
49
|
-
.filter(
|
|
50
|
-
(annotation) =>
|
|
51
|
-
annotation.annotationType === "acceptance_state" ||
|
|
52
|
-
annotation.annotationType === "external_trigger",
|
|
53
|
-
)
|
|
54
|
-
.sort(
|
|
55
|
-
(left, right) =>
|
|
56
|
-
left.createdAt.localeCompare(right.createdAt) || left.id.localeCompare(right.id),
|
|
57
|
-
);
|
|
58
|
-
for (const annotation of candidates) {
|
|
59
|
-
const actionLabel =
|
|
60
|
-
payloadString(annotation, "actionLabel") ?? payloadString(annotation, "triggerLabel");
|
|
61
|
-
if (!actionLabel) continue;
|
|
62
|
-
|
|
63
|
-
const recordedSourceId = payloadString(annotation, "sourceTurnRecordId");
|
|
64
|
-
const source =
|
|
65
|
-
(recordedSourceId ? llmById.get(recordedSourceId) : undefined) ??
|
|
66
|
-
llmRecords.findLast((record) => record.startedAt.localeCompare(annotation.createdAt) <= 0);
|
|
67
|
-
if (!source) continue;
|
|
68
|
-
|
|
69
|
-
const causedTurnId = payloadString(annotation, "causedSelectedTurnId");
|
|
70
|
-
const causedTurnType = annotation.payload.causedSelectedTurnType;
|
|
71
|
-
const findCaused = (turnType: string) =>
|
|
72
|
-
causedTurnId
|
|
73
|
-
? allRecords.find(
|
|
74
|
-
(record) =>
|
|
75
|
-
record.turnType === turnType &&
|
|
76
|
-
record.turnId === causedTurnId &&
|
|
77
|
-
record.startedAt.localeCompare(annotation.createdAt) >= 0 &&
|
|
78
|
-
!claimedTargets.has(record.id),
|
|
79
|
-
)
|
|
80
|
-
: undefined;
|
|
81
|
-
const directTarget =
|
|
82
|
-
causedTurnType === undefined || causedTurnType === "llm" ? findCaused("llm") : undefined;
|
|
83
|
-
const causedAutomatic = causedTurnType === "automatic" ? findCaused(causedTurnType) : undefined;
|
|
84
|
-
const target =
|
|
85
|
-
directTarget ??
|
|
86
|
-
(causedAutomatic ? nextLlmAfterAutomatic(causedAutomatic, allRecords) : undefined);
|
|
87
|
-
if (target) claimedTargets.add(target.id);
|
|
88
|
-
const isUnapplied = causedTurnType === "human" || causedTurnType === "external";
|
|
89
|
-
decisions.push({
|
|
90
|
-
id: annotation.id,
|
|
91
|
-
sourceNodeId: source.id,
|
|
92
|
-
targetNodeId: target?.id ?? null,
|
|
93
|
-
hasContext: false,
|
|
94
|
-
productLabels: [],
|
|
95
|
-
actionLabel,
|
|
96
|
-
endState: isUnapplied
|
|
97
|
-
? "not_applied"
|
|
98
|
-
: causedAutomatic && !target && process.lifecycleStatus === "completed"
|
|
99
|
-
? "completed"
|
|
100
|
-
: null,
|
|
101
|
-
timestamp: annotation.createdAt,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
return decisions;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function automaticTransitions(
|
|
108
|
-
process: ProcessInstance,
|
|
109
|
-
annotations: readonly ProcessTurnAnnotation[],
|
|
110
|
-
allRecords: readonly ProcessTurnRecord[],
|
|
111
|
-
llmRecords: readonly ProcessTurnRecord[],
|
|
112
|
-
): Decision[] {
|
|
113
|
-
const actionCausedAutomaticIds = new Set<string>();
|
|
114
|
-
for (const annotation of annotations) {
|
|
115
|
-
const causedTurnId = annotation.payload.causedSelectedTurnId;
|
|
116
|
-
const causedTurnType = annotation.payload.causedSelectedTurnType;
|
|
117
|
-
if (typeof causedTurnId !== "string" || causedTurnType !== "automatic") {
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
const caused = allRecords.find(
|
|
121
|
-
(record) =>
|
|
122
|
-
record.turnType === causedTurnType &&
|
|
123
|
-
record.turnId === causedTurnId &&
|
|
124
|
-
record.startedAt.localeCompare(annotation.createdAt) >= 0,
|
|
125
|
-
);
|
|
126
|
-
if (caused) actionCausedAutomaticIds.add(caused.id);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const transitions: Decision[] = [];
|
|
130
|
-
for (const automatic of allRecords.filter((record) => record.turnType === "automatic")) {
|
|
131
|
-
if (actionCausedAutomaticIds.has(automatic.id)) continue;
|
|
132
|
-
const source = llmRecords.findLast(
|
|
133
|
-
(record) => record.startedAt.localeCompare(automatic.startedAt) < 0,
|
|
134
|
-
);
|
|
135
|
-
if (!source) continue;
|
|
136
|
-
const target = nextLlmAfterAutomatic(automatic, allRecords);
|
|
137
|
-
const completesProcess =
|
|
138
|
-
allRecords.at(-1)?.id === automatic.id && process.lifecycleStatus === "completed";
|
|
139
|
-
if (!target && !completesProcess) continue;
|
|
140
|
-
transitions.push({
|
|
141
|
-
id: `automatic:${automatic.id}`,
|
|
142
|
-
sourceNodeId: source.id,
|
|
143
|
-
targetNodeId: target?.id ?? null,
|
|
144
|
-
hasContext: false,
|
|
145
|
-
productLabels: [],
|
|
146
|
-
actionLabel: titleCase(automatic.turnId),
|
|
147
|
-
endState: target ? null : "completed",
|
|
148
|
-
timestamp: automatic.startedAt,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
return transitions;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/** Projects actual Pi turn lineage and redacted prompt/product provenance. */
|
|
21
|
+
/** Compact recorded context relationships. Current definitions supply labels only. @internal */
|
|
155
22
|
export function presentProcessInstanceTree(input: {
|
|
156
23
|
process: ProcessInstance;
|
|
157
24
|
turnRecords: readonly ProcessTurnRecord[];
|
|
158
|
-
|
|
25
|
+
leases?: readonly WorkerLease[];
|
|
26
|
+
observations?: readonly InspectionContextObservation[];
|
|
159
27
|
turnDetails?: readonly ProcessRunTurnView[];
|
|
160
28
|
currentPiEntryId?: string | null;
|
|
161
29
|
}): ProcessInstanceTreeResponseBody {
|
|
162
|
-
const
|
|
163
|
-
(
|
|
164
|
-
left.startedAt.localeCompare(right.startedAt) || left.id.localeCompare(right.id),
|
|
165
|
-
);
|
|
166
|
-
const records = allRecords.filter((record) => record.turnType === "llm");
|
|
167
|
-
const detailsByTurnId = new Map(
|
|
168
|
-
(input.turnDetails ?? []).map((detail) => [detail.turnId, detail] as const),
|
|
169
|
-
);
|
|
170
|
-
const byResultEntryId = new Map(
|
|
171
|
-
records
|
|
172
|
-
.filter((record) => record.resultPiEntryId)
|
|
173
|
-
.map((record) => [record.resultPiEntryId as string, record] as const),
|
|
30
|
+
const records = [...input.turnRecords].sort(
|
|
31
|
+
(a, b) => a.startedAt.localeCompare(b.startedAt) || a.id.localeCompare(b.id),
|
|
174
32
|
);
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
...automaticTransitions(input.process, annotations, allRecords, records),
|
|
179
|
-
].sort(
|
|
180
|
-
(left, right) =>
|
|
181
|
-
left.timestamp.localeCompare(right.timestamp) || left.id.localeCompare(right.id),
|
|
182
|
-
);
|
|
183
|
-
const current =
|
|
184
|
-
input.process.lifecycleStatus === "completed" || input.process.lifecycleStatus === "aborted"
|
|
185
|
-
? null
|
|
186
|
-
: (byResultEntryId.get(input.currentPiEntryId ?? "")?.id ?? records.at(-1)?.id ?? null);
|
|
33
|
+
const observations = input.observations ?? [];
|
|
34
|
+
const lineage = createInspectionLineage({ records, observations, leases: input.leases ?? [] });
|
|
35
|
+
const labels = new Map(input.turnDetails?.map((turn) => [turn.turnId, turn.description]));
|
|
187
36
|
const nodes: InstanceTreeNodeSummary[] = records.map((record) => {
|
|
188
|
-
const
|
|
189
|
-
const
|
|
37
|
+
const origin = lineage.origin(record);
|
|
38
|
+
const source = origin.conversation.state === "recorded" ? origin.conversation.value : null;
|
|
190
39
|
return {
|
|
191
40
|
id: record.id,
|
|
192
|
-
|
|
193
|
-
|
|
41
|
+
turnId: record.turnId,
|
|
42
|
+
turnType: record.turnType,
|
|
43
|
+
origin,
|
|
44
|
+
parentId: source?.turnRecordId === record.id ? null : (source?.turnRecordId ?? null),
|
|
45
|
+
label: labels.get(record.turnId) ?? titleCase(record.turnId),
|
|
194
46
|
pathType: record.pathType,
|
|
195
47
|
resultState:
|
|
196
48
|
record.status === "succeeded"
|
|
@@ -203,60 +55,48 @@ export function presentProcessInstanceTree(input: {
|
|
|
203
55
|
timestamp: record.startedAt,
|
|
204
56
|
};
|
|
205
57
|
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
edgesByKey.set(key, edge);
|
|
225
|
-
return edge;
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
for (const [index, node] of nodes.entries()) {
|
|
229
|
-
const record = records[index];
|
|
230
|
-
if (node.parentId) connect(node.parentId, node.id).hasContext = true;
|
|
231
|
-
const detail = detailsByTurnId.get(record.turnId);
|
|
232
|
-
for (const productName of detail?.consumedProducts ?? []) {
|
|
233
|
-
const publisher = records.findLast(
|
|
234
|
-
(candidate) =>
|
|
235
|
-
candidate.startedAt.localeCompare(record.startedAt) < 0 &&
|
|
236
|
-
candidate.status === "succeeded" &&
|
|
237
|
-
(detailsByTurnId.get(candidate.turnId)?.publishedProducts ?? []).includes(productName),
|
|
238
|
-
);
|
|
239
|
-
if (publisher) connect(publisher.id, record.id).productLabels.push(titleCase(productName));
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const terminalEdges: InstanceTreeEdgeSummary[] = [];
|
|
244
|
-
for (const { timestamp: _, ...decision } of decisions) {
|
|
245
|
-
if (!decision.targetNodeId) {
|
|
246
|
-
terminalEdges.push(decision);
|
|
58
|
+
const edges: InstanceTreeEdgeSummary[] = nodes.flatMap((node) =>
|
|
59
|
+
node.parentId
|
|
60
|
+
? [
|
|
61
|
+
{
|
|
62
|
+
id: `conversation:${node.id}`,
|
|
63
|
+
sourceNodeId: node.parentId,
|
|
64
|
+
targetNodeId: node.id,
|
|
65
|
+
hasContext: true,
|
|
66
|
+
productLabels: [],
|
|
67
|
+
actionLabel: null,
|
|
68
|
+
endState: null,
|
|
69
|
+
},
|
|
70
|
+
]
|
|
71
|
+
: [],
|
|
72
|
+
);
|
|
73
|
+
const byId = new Map(records.map((record) => [record.id, record]));
|
|
74
|
+
for (const observation of observations) {
|
|
75
|
+
if (observation.fact.kind !== "supplied_context" || !byId.has(observation.turnRecordId))
|
|
247
76
|
continue;
|
|
77
|
+
for (const product of observation.fact.products) {
|
|
78
|
+
const producer = byId.get(product.producerTurnRecordId);
|
|
79
|
+
if (!producer || producer.resultPiEntryId !== product.entryId) continue;
|
|
80
|
+
edges.push({
|
|
81
|
+
id: `product:${observation.id}:${product.name}`,
|
|
82
|
+
sourceNodeId: producer.id,
|
|
83
|
+
targetNodeId: observation.turnRecordId,
|
|
84
|
+
hasContext: false,
|
|
85
|
+
productLabels: [product.name],
|
|
86
|
+
actionLabel: null,
|
|
87
|
+
endState: null,
|
|
88
|
+
});
|
|
248
89
|
}
|
|
249
|
-
const target = nodes.find((node) => node.id === decision.targetNodeId);
|
|
250
|
-
const input = target?.parentId
|
|
251
|
-
? connect(target.parentId, target.id)
|
|
252
|
-
: [...edgesByKey.values()].find((edge) => edge.targetNodeId === target?.id);
|
|
253
|
-
(input ?? connect(decision.sourceNodeId, decision.targetNodeId)).actionLabel =
|
|
254
|
-
decision.actionLabel;
|
|
255
90
|
}
|
|
256
|
-
|
|
257
91
|
return {
|
|
258
|
-
currentLeafId:
|
|
92
|
+
currentLeafId:
|
|
93
|
+
input.process.lifecycleStatus === "completed" || input.process.lifecycleStatus === "aborted"
|
|
94
|
+
? null
|
|
95
|
+
: (records.find((record) => record.turnStartRecordId === input.process.currentExecution?.id)
|
|
96
|
+
?.id ??
|
|
97
|
+
records.find((record) => record.status === "running")?.id ??
|
|
98
|
+
(input.currentPiEntryId ? lineage.owner(input.currentPiEntryId) : null)),
|
|
259
99
|
nodes,
|
|
260
|
-
edges
|
|
100
|
+
edges,
|
|
261
101
|
};
|
|
262
102
|
}
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
import type { EngineFailure, ProcessEngine, ProcessEngineLogger } from "./process-engine/types.js";
|
|
17
17
|
import type { ProcessTitleGenerator } from "./process-title-generator.js";
|
|
18
18
|
import { buildProjectUpdatedEffect } from "./project-mutation-service.js";
|
|
19
|
+
import { type LaunchSkillDefaults, resolveLaunchSkills } from "./skills/launch-skills.js";
|
|
19
20
|
import type { WorkerSupervisor } from "./supervisor/worker-supervisor.js";
|
|
20
21
|
import type { Broadcaster } from "./ws/broadcast.js";
|
|
21
22
|
|
|
@@ -57,6 +58,7 @@ export interface ProcessLaunchExecutorDeps
|
|
|
57
58
|
repositoryCredentials?: import("./repository-credentials/service.js").RepositoryCredentialService;
|
|
58
59
|
/** Runner requirement check executed before the durable launch transaction. */
|
|
59
60
|
assertRuntimeAvailable?: (processId: string) => Promise<void>;
|
|
61
|
+
skillDefaults?: LaunchSkillDefaults;
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
/** @internal */
|
|
@@ -191,6 +193,7 @@ export function commitProcessLaunch(
|
|
|
191
193
|
relation?: ProcessLaunchRelationInput,
|
|
192
194
|
actor?: Actor,
|
|
193
195
|
): ProcessLaunchCommit {
|
|
196
|
+
if (launchPlan.preview) throw new Error("Launcher previews cannot be committed");
|
|
194
197
|
return deps.transaction((repos) => {
|
|
195
198
|
if (launchRunId) {
|
|
196
199
|
repos.launchRuns.saveReplay(launchRunId, {
|
|
@@ -394,9 +397,9 @@ async function createProcessFromLaunchPlanWithDisposition(
|
|
|
394
397
|
};
|
|
395
398
|
}
|
|
396
399
|
let resourceSelections = opts?.resourceSelections;
|
|
397
|
-
if (
|
|
400
|
+
if (resourceSelections === undefined) {
|
|
398
401
|
try {
|
|
399
|
-
resourceSelections = deps.
|
|
402
|
+
resourceSelections = resolveLaunchSkills(deps, launchPlan.processId, launchPlan.skillIds);
|
|
400
403
|
} catch (error) {
|
|
401
404
|
return {
|
|
402
405
|
ok: false,
|
|
@@ -41,8 +41,8 @@ function serializeJson(value: unknown): string | null {
|
|
|
41
41
|
return serialized ?? null;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
function normalizeProjectInputs(
|
|
45
|
-
launchConfig: ProcessLaunchConfig,
|
|
44
|
+
export function normalizeProjectInputs(
|
|
45
|
+
launchConfig: Pick<ProcessLaunchConfig, "projects">,
|
|
46
46
|
commitMessages?: CommitMessageConfig,
|
|
47
47
|
): ProcessLaunchPlan["projectInputs"] {
|
|
48
48
|
return (launchConfig.projects ?? []).map((project) => ({
|
|
@@ -54,6 +54,7 @@ function normalizeProjectInputs(
|
|
|
54
54
|
externalUrl: project.externalUrl ?? null,
|
|
55
55
|
metadata: {
|
|
56
56
|
...(project.metadata ?? {}),
|
|
57
|
+
...(project.settingsRepository ? { settingsRepository: project.settingsRepository } : {}),
|
|
57
58
|
[COMMIT_MESSAGE_PROJECT_METADATA_KEY]: resolveCommitMessageMetadata(
|
|
58
59
|
project.repoLocator,
|
|
59
60
|
commitMessages,
|
|
@@ -76,9 +77,23 @@ export function buildProcessLaunchPlan(input: BuildProcessLaunchPlanInput): Proc
|
|
|
76
77
|
const initialState = processDef.initialState(params);
|
|
77
78
|
const state = processDef.stateCodec.parse(initialState);
|
|
78
79
|
const stateJson = serializeJson(processDef.stateCodec.serialize(state));
|
|
80
|
+
if (
|
|
81
|
+
input.launchConfig.primaryRepositoryKey &&
|
|
82
|
+
!input.launchConfig.projects?.some(
|
|
83
|
+
(project) => project.key === input.launchConfig.primaryRepositoryKey,
|
|
84
|
+
)
|
|
85
|
+
) {
|
|
86
|
+
throw new Error("Primary repository must be a project in this launch");
|
|
87
|
+
}
|
|
79
88
|
const launchMetadata = {
|
|
80
89
|
...(input.launchConfig.metadata ?? {}),
|
|
81
90
|
...(input.metadataAdditions ?? {}),
|
|
91
|
+
...(input.launchConfig.primaryRepositoryKey
|
|
92
|
+
? { primaryRepositoryKey: input.launchConfig.primaryRepositoryKey }
|
|
93
|
+
: {}),
|
|
94
|
+
...(input.launchConfig.settingsContext
|
|
95
|
+
? { settingsContext: input.launchConfig.settingsContext }
|
|
96
|
+
: {}),
|
|
82
97
|
};
|
|
83
98
|
|
|
84
99
|
return {
|
|
@@ -88,6 +88,30 @@ export function buildProcessLauncherRegistry(
|
|
|
88
88
|
[],
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
+
async function resolveUiLauncher(
|
|
92
|
+
launcherId: string,
|
|
93
|
+
input: Record<string, unknown>,
|
|
94
|
+
ctx: LauncherContext,
|
|
95
|
+
preview: boolean,
|
|
96
|
+
) {
|
|
97
|
+
const { launcher, ui } = requireUiLauncher(launcherId);
|
|
98
|
+
const resolve = preview
|
|
99
|
+
? (ui.resolvePreviewConfig ?? ui.resolveLaunchConfig)
|
|
100
|
+
: ui.resolveLaunchConfig;
|
|
101
|
+
const resolved = await resolve.call(ui, input, createLauncherContext(launcher.processId, ctx));
|
|
102
|
+
if (!resolved.ok) return resolved;
|
|
103
|
+
const result = buildResolvedProcessLauncher(
|
|
104
|
+
launcher,
|
|
105
|
+
resolved.launchConfig,
|
|
106
|
+
options.commitMessages,
|
|
107
|
+
);
|
|
108
|
+
if (preview) result.launchPlan.preview = true;
|
|
109
|
+
return {
|
|
110
|
+
ok: true as const,
|
|
111
|
+
launcher: result,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
91
115
|
const uiLaunchers = [...launchers.values()]
|
|
92
116
|
.filter((launcher) => launcher.definition.ui)
|
|
93
117
|
.map(
|
|
@@ -142,22 +166,10 @@ export function buildProcessLauncherRegistry(
|
|
|
142
166
|
},
|
|
143
167
|
|
|
144
168
|
async resolveUiLauncher(launcherId, input, ctx = {}) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
);
|
|
150
|
-
if (!resolved.ok) {
|
|
151
|
-
return resolved;
|
|
152
|
-
}
|
|
153
|
-
return {
|
|
154
|
-
ok: true as const,
|
|
155
|
-
launcher: buildResolvedProcessLauncher(
|
|
156
|
-
launcher,
|
|
157
|
-
resolved.launchConfig,
|
|
158
|
-
options.commitMessages,
|
|
159
|
-
),
|
|
160
|
-
};
|
|
169
|
+
return resolveUiLauncher(launcherId, input, ctx, false);
|
|
170
|
+
},
|
|
171
|
+
async resolveUiLauncherPreview(launcherId, input, ctx = {}) {
|
|
172
|
+
return resolveUiLauncher(launcherId, input, ctx, true);
|
|
161
173
|
},
|
|
162
174
|
};
|
|
163
175
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { type ProcessInstance, parseStrictInstanceTurnConfigsJson } from "@leitwerk-dev/domain";
|
|
2
|
+
import type { ProcessModelConfigPatch } from "@leitwerk-dev/protocol/http-contracts";
|
|
3
|
+
import type {
|
|
4
|
+
ProcessModelAvailabilitySnapshot,
|
|
5
|
+
ServerProcessModelPolicy,
|
|
6
|
+
} from "./process-model-policy/index.js";
|
|
7
|
+
import {
|
|
8
|
+
presentProcessModelConfiguration,
|
|
9
|
+
presentProcessModelPolicyFailure,
|
|
10
|
+
} from "./process-model-policy-presenter.js";
|
|
11
|
+
|
|
12
|
+
function record(value: unknown): value is Record<string, unknown> {
|
|
13
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
function profile(value: unknown): value is string | null {
|
|
16
|
+
return value === null || (typeof value === "string" && value.trim().length > 0);
|
|
17
|
+
}
|
|
18
|
+
/** Parse sparse input without dropping explicit clears. @internal */
|
|
19
|
+
export function parseProcessModelConfigPatch(value: unknown): ProcessModelConfigPatch {
|
|
20
|
+
if (
|
|
21
|
+
!record(value) ||
|
|
22
|
+
Object.keys(value).some((key) => key !== "defaultModelProfileId" && key !== "turnConfigs")
|
|
23
|
+
)
|
|
24
|
+
throw new Error("Expected defaultModelProfileId and/or turnConfigs");
|
|
25
|
+
const patch: ProcessModelConfigPatch = {};
|
|
26
|
+
if (Object.hasOwn(value, "defaultModelProfileId")) {
|
|
27
|
+
if (!profile(value.defaultModelProfileId))
|
|
28
|
+
throw new Error("defaultModelProfileId must be a profile ID or null");
|
|
29
|
+
patch.defaultModelProfileId = value.defaultModelProfileId?.trim() ?? null;
|
|
30
|
+
}
|
|
31
|
+
if (Object.hasOwn(value, "turnConfigs")) {
|
|
32
|
+
if (!record(value.turnConfigs)) throw new Error("turnConfigs must be an object");
|
|
33
|
+
patch.turnConfigs = Object.fromEntries(
|
|
34
|
+
Object.entries(value.turnConfigs).map(([id, config]) => {
|
|
35
|
+
if (!record(config) || Object.keys(config).length !== 1 || !profile(config.modelProfileId))
|
|
36
|
+
throw new Error(`Step '${id}' requires modelProfileId as a profile ID or null`);
|
|
37
|
+
return [id, { modelProfileId: config.modelProfileId?.trim() ?? null }];
|
|
38
|
+
}),
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return patch;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Shared preview/save validation and sparse merge against the latest persisted settings. @internal */
|
|
45
|
+
export function prepareProcessModelConfig(input: {
|
|
46
|
+
process: ProcessInstance;
|
|
47
|
+
patch: ProcessModelConfigPatch;
|
|
48
|
+
policy: ServerProcessModelPolicy;
|
|
49
|
+
availability: ProcessModelAvailabilitySnapshot;
|
|
50
|
+
}) {
|
|
51
|
+
const { process, policy, availability } = input;
|
|
52
|
+
const patch = parseProcessModelConfigPatch(input.patch);
|
|
53
|
+
if (process.lifecycleStatus === "completed" || process.lifecycleStatus === "aborted")
|
|
54
|
+
throw new Error("Completed and aborted processes have read-only model settings");
|
|
55
|
+
const parsed = parseStrictInstanceTurnConfigsJson(process.processId, process.turnConfigsJson);
|
|
56
|
+
if (!parsed.ok)
|
|
57
|
+
throw new Error("Saved model configuration is malformed and must be repaired before editing");
|
|
58
|
+
const current = policy.project({ kind: "process_configuration", process, availability });
|
|
59
|
+
const turns = new Map(current.turns.map((turn) => [turn.turnId, turn]));
|
|
60
|
+
const turnConfigs = { ...parsed.value };
|
|
61
|
+
for (const [id, config] of Object.entries(patch.turnConfigs ?? {})) {
|
|
62
|
+
const turn = turns.get(id);
|
|
63
|
+
if (!turn) throw new Error(`Step '${id}' is unknown or does not use a model`);
|
|
64
|
+
if (turn.fixedModelProfileId) throw new Error(`Step '${id}' uses a fixed system model`);
|
|
65
|
+
if (config.modelProfileId === null) delete turnConfigs[id];
|
|
66
|
+
else turnConfigs[id] = { ...turnConfigs[id], modelProfileId: config.modelProfileId };
|
|
67
|
+
}
|
|
68
|
+
const selections = [
|
|
69
|
+
patch.defaultModelProfileId,
|
|
70
|
+
...Object.values(patch.turnConfigs ?? {}).map((config) => config.modelProfileId),
|
|
71
|
+
];
|
|
72
|
+
for (const id of selections) {
|
|
73
|
+
if (!id) continue;
|
|
74
|
+
const validation = policy.evaluate({
|
|
75
|
+
kind: "runtime_selection",
|
|
76
|
+
processId: process.processId,
|
|
77
|
+
availability,
|
|
78
|
+
selection: {
|
|
79
|
+
modelProfileId: id,
|
|
80
|
+
provenance: { kind: "explicit", source: "instance_default" },
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
if (!validation.ok) throw new Error(presentProcessModelPolicyFailure(validation));
|
|
84
|
+
}
|
|
85
|
+
const settings = {
|
|
86
|
+
defaultModelProfileId: Object.hasOwn(patch, "defaultModelProfileId")
|
|
87
|
+
? (patch.defaultModelProfileId ?? null)
|
|
88
|
+
: process.defaultModelProfileId,
|
|
89
|
+
turnConfigsJson: Object.hasOwn(patch, "turnConfigs")
|
|
90
|
+
? JSON.stringify(turnConfigs)
|
|
91
|
+
: process.turnConfigsJson,
|
|
92
|
+
};
|
|
93
|
+
const candidate = { ...process, ...settings };
|
|
94
|
+
return {
|
|
95
|
+
settings,
|
|
96
|
+
modelConfiguration: presentProcessModelConfiguration(
|
|
97
|
+
policy.project({ kind: "process_configuration", process: candidate, availability }),
|
|
98
|
+
),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -96,6 +96,7 @@ export function constructPolicySnapshot(input: {
|
|
|
96
96
|
if (configurationIssues.length > 0)
|
|
97
97
|
throw new ProcessModelPolicyConfigurationError(configurationIssues);
|
|
98
98
|
return {
|
|
99
|
+
defaultProfileId: configSnapshot.pi.default_model_profile,
|
|
99
100
|
profiles,
|
|
100
101
|
profilesById: new Map(profiles.map((profile) => [profile.id, profile])),
|
|
101
102
|
processesById,
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
ProcessModelPolicyEvaluation,
|
|
11
11
|
ValidModelConfiguration,
|
|
12
12
|
} from "./types.js";
|
|
13
|
-
import { provenanceKindForSource } from "./types.js";
|
|
13
|
+
import { isPinnedModelSelection, provenanceKindForSource } from "./types.js";
|
|
14
14
|
|
|
15
15
|
function processPolicy(snapshot: PolicySnapshot, processId: string): PolicyProcess {
|
|
16
16
|
return (
|
|
@@ -86,7 +86,8 @@ function candidate(
|
|
|
86
86
|
| "process_config_turn"
|
|
87
87
|
| "instance_default"
|
|
88
88
|
| "process_config_default"
|
|
89
|
-
| "catalog_default"
|
|
89
|
+
| "catalog_default"
|
|
90
|
+
| "scoped_purpose_default",
|
|
90
91
|
): DurableModelSelection | null {
|
|
91
92
|
const id = trimToNull(modelProfileId);
|
|
92
93
|
return id
|
|
@@ -94,17 +95,6 @@ function candidate(
|
|
|
94
95
|
: null;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
function isValidCandidate(
|
|
98
|
-
snapshot: PolicySnapshot,
|
|
99
|
-
policy: PolicyProcess,
|
|
100
|
-
profileId: string,
|
|
101
|
-
): boolean {
|
|
102
|
-
return (
|
|
103
|
-
snapshot.profilesById.has(profileId) &&
|
|
104
|
-
(!policy.allowedProfileIds || policy.allowedProfileIds.has(profileId))
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
98
|
function resolvedDefault(
|
|
109
99
|
snapshot: PolicySnapshot,
|
|
110
100
|
configuration: ValidModelConfiguration,
|
|
@@ -112,13 +102,9 @@ function resolvedDefault(
|
|
|
112
102
|
const policy = processPolicy(snapshot, configuration.processId);
|
|
113
103
|
const instanceDefault = candidate(configuration.defaultProfileId, "instance_default");
|
|
114
104
|
if (instanceDefault) return instanceDefault;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
]) {
|
|
119
|
-
if (current && isValidCandidate(snapshot, policy, current.modelProfileId)) return current;
|
|
120
|
-
}
|
|
121
|
-
return null;
|
|
105
|
+
const configured = candidate(policy.defaultProfileId, "process_config_default");
|
|
106
|
+
if (configured) return configured;
|
|
107
|
+
return candidate(snapshot.defaultProfileId, "catalog_default");
|
|
122
108
|
}
|
|
123
109
|
|
|
124
110
|
export function resolveDefault(
|
|
@@ -142,11 +128,15 @@ function resolveInherited(
|
|
|
142
128
|
const policy = processPolicy(snapshot, configuration.processId);
|
|
143
129
|
const instanceTurn = candidate(configuration.turnProfileIds.get(turnId), "instance_turn_config");
|
|
144
130
|
if (instanceTurn) return instanceTurn;
|
|
145
|
-
const processTurn = candidate(policy.turnProfileIds[turnId], "process_config_turn");
|
|
146
|
-
if (processTurn && isValidCandidate(snapshot, policy, processTurn.modelProfileId))
|
|
147
|
-
return processTurn;
|
|
148
131
|
const instanceDefault = candidate(configuration.defaultProfileId, "instance_default");
|
|
149
132
|
if (instanceDefault) return instanceDefault;
|
|
133
|
+
const scopedDefault = candidate(
|
|
134
|
+
policy.scopedProfileIdForTurn?.(turnId),
|
|
135
|
+
"scoped_purpose_default",
|
|
136
|
+
);
|
|
137
|
+
if (scopedDefault) return scopedDefault;
|
|
138
|
+
const processTurn = candidate(policy.turnProfileIds[turnId], "process_config_turn");
|
|
139
|
+
if (processTurn) return processTurn;
|
|
150
140
|
return resolvedDefault(snapshot, configuration);
|
|
151
141
|
}
|
|
152
142
|
|
|
@@ -192,8 +182,9 @@ export function resolveTurn(
|
|
|
192
182
|
issues: existingSelection.issues,
|
|
193
183
|
...(availability ? { availabilityRevision: availability.revision } : {}),
|
|
194
184
|
};
|
|
195
|
-
if (override.kind === "clear")
|
|
196
|
-
|
|
185
|
+
if (override.kind === "clear") {
|
|
186
|
+
existingSelection = { kind: "none" };
|
|
187
|
+
}
|
|
197
188
|
if (override.kind === "profile")
|
|
198
189
|
return validateSelection(
|
|
199
190
|
snapshot,
|
|
@@ -208,7 +199,7 @@ export function resolveTurn(
|
|
|
208
199
|
existingSelection.kind === "selected" &&
|
|
209
200
|
(mode === "initial" || mode === "retry" || mode === "continue") &&
|
|
210
201
|
existingSelection.turnId === turnId &&
|
|
211
|
-
existingSelection.selection
|
|
202
|
+
isPinnedModelSelection(existingSelection.selection)
|
|
212
203
|
)
|
|
213
204
|
return validateSelection(
|
|
214
205
|
snapshot,
|
|
@@ -216,12 +207,23 @@ export function resolveTurn(
|
|
|
216
207
|
existingSelection.selection,
|
|
217
208
|
availability,
|
|
218
209
|
);
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
210
|
+
try {
|
|
211
|
+
return validateSelection(
|
|
212
|
+
snapshot,
|
|
213
|
+
configuration.processId,
|
|
214
|
+
resolveInherited(snapshot, configuration, turnId),
|
|
215
|
+
availability,
|
|
216
|
+
);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
return {
|
|
219
|
+
ok: false,
|
|
220
|
+
code: "invalid_model_configuration",
|
|
221
|
+
source: "configuration",
|
|
222
|
+
selection: null,
|
|
223
|
+
issues: [],
|
|
224
|
+
message: error instanceof Error ? error.message : "Invalid scoped settings",
|
|
225
|
+
};
|
|
226
|
+
}
|
|
225
227
|
}
|
|
226
228
|
|
|
227
229
|
export function recoverPreparation(
|