@leitwerk-dev/server 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{app-BuJCdkvy.d.ts → app-CtlotzYm.d.ts} +312 -121
- package/dist/app-KR3N2JAE.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-QCHS3X33.js → chunk-OUA5EZS2.js} +3127 -689
- package/dist/chunk-OUA5EZS2.js.map +1 -0
- package/dist/{chunk-HK6BLLHA.js → chunk-YLWY4UTT.js} +2424 -1580
- package/dist/chunk-YLWY4UTT.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 +16 -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/dashboard-model-issues.d.ts +10 -0
- package/dist/dashboard-model-issues.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/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 +21 -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 +4 -0
- 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/repositories.d.ts +12 -0
- package/dist/db/repositories.d.ts.map +1 -1
- package/dist/db/schema.d.ts +693 -2
- 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 +10 -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/domain-logic/worker-lease-lifecycle.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.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.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 +1 -6
- package/dist/process-action-presenter.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/process-engine/ops/automatic-retry-startup.d.ts +8 -0
- package/dist/process-engine/ops/automatic-retry-startup.d.ts.map +1 -0
- 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 +2 -0
- 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 +13 -2
- 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-turn-outcome-writes.d.ts +2 -0
- package/dist/process-engine/writes/build-turn-outcome-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/writes.d.ts +28 -60
- 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-availability-recovery.d.ts +1 -1
- package/dist/process-model-availability-recovery.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-trace.d.ts.map +1 -1
- package/dist/process-ui-snapshot-presenter.d.ts +14 -3
- package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
- package/dist/routes/dashboard.d.ts +17 -0
- package/dist/routes/dashboard.d.ts.map +1 -0
- 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-model-config.d.ts +4 -0
- package/dist/routes/process-model-config.d.ts.map +1 -0
- package/dist/routes/process-route-helpers.d.ts +8 -9
- 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 +98 -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 +7 -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 +4 -3
- package/dist/startup-evidence.d.ts.map +1 -1
- package/dist/startup-retry-policy.d.ts +8 -0
- package/dist/startup-retry-policy.d.ts.map +1 -0
- 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.map +1 -1
- package/dist/supervisor/worker-supervisor.d.ts +2 -0
- package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
- 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.js +2 -1
- 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 +177 -25
- package/src/auth/fastify-auth.ts +13 -0
- package/src/config/config-loader.ts +42 -2
- package/src/config/config-types.ts +16 -1
- package/src/config/kubernetes-docker-isolation.ts +21 -0
- package/src/dashboard-model-issues.ts +199 -0
- package/src/db/database.ts +131 -40
- package/src/db/execution-inspection-repo.ts +163 -0
- package/src/db/history-window.ts +18 -0
- package/src/db/process-event-repo.ts +88 -10
- package/src/db/process-instance-repo.ts +33 -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 +45 -12
- package/src/db/publication-repo.ts +63 -0
- package/src/db/repositories.ts +17 -0
- package/src/db/schema.ts +103 -1
- 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 +36 -4
- package/src/db/worker-lease-repo.ts +8 -2
- package/src/domain-logic/outcome-tools.ts +18 -216
- package/src/domain-logic/worker-lease-lifecycle.ts +2 -1
- 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 +7 -8
- package/src/integration-tool-registry.ts +59 -26
- 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 +22 -57
- package/src/process-action-registry.ts +31 -39
- package/src/process-engine/decision.ts +10 -0
- package/src/process-engine/engine.ts +25 -2
- package/src/process-engine/mapped-turns.ts +5 -7
- package/src/process-engine/ops/automatic-retry-startup.ts +93 -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 +20 -16
- package/src/process-engine/ops/start-process.ts +34 -2
- package/src/process-engine/ops/turn-outcome.ts +61 -60
- 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 +34 -5
- 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 +21 -0
- package/src/process-engine/writes/build-process-abort-writes.ts +30 -20
- package/src/process-engine/writes/build-turn-outcome-writes.ts +39 -2
- package/src/process-engine/writes/commit-writes.ts +16 -4
- package/src/process-engine/writes/writes.ts +59 -74
- 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-availability-recovery.ts +6 -4
- 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-trace.ts +12 -24
- package/src/process-ui-snapshot-presenter.ts +210 -295
- package/src/routes/dashboard.ts +106 -0
- 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-model-config.ts +70 -0
- package/src/routes/process-route-helpers.ts +153 -162
- 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 +797 -0
- package/src/server-bootstrap/build-host-capabilities.ts +42 -0
- package/src/server-bootstrap/register-http.ts +12 -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 +94 -0
- package/src/skills/launch-skills.ts +19 -0
- package/src/skills/skill-frontmatter.ts +19 -6
- package/src/skills/source-importer.ts +7 -13
- package/src/startup-evidence.ts +29 -8
- package/src/startup-retry-policy.ts +106 -0
- package/src/supervisor/execution-inspection-ingestor.ts +55 -0
- package/src/supervisor/ipc-handler.ts +2 -0
- package/src/supervisor/worker-event-ingestor.ts +30 -14
- package/src/supervisor/worker-start-payload-builder.ts +17 -0
- package/src/supervisor/worker-supervisor.ts +26 -1
- 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/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-MSJXFK33.js +0 -8
- package/dist/chunk-HK6BLLHA.js.map +0 -1
- package/dist/chunk-QCHS3X33.js.map +0 -1
- /package/dist/{app-MSJXFK33.js.map → app-KR3N2JAE.js.map} +0 -0
|
@@ -7,11 +7,10 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
isAutomaticTurnDefinition,
|
|
9
9
|
isLlmTurnDefinition,
|
|
10
|
-
type OutcomeToolArrayItemSpec,
|
|
11
10
|
type OutcomeToolParameterSpec,
|
|
12
11
|
type TurnDefinition,
|
|
12
|
+
validateOutcomeParameters,
|
|
13
13
|
} from "@leitwerk-dev/process-sdk";
|
|
14
|
-
import * as v from "valibot";
|
|
15
14
|
import { isTurnAvailableForProcessGraph, type ProcessGraphRegistry } from "../process-graph.js";
|
|
16
15
|
|
|
17
16
|
interface OutcomeToolValidationContract {
|
|
@@ -36,172 +35,21 @@ function validationFailure(code: string, message: string): OutcomeValidationFail
|
|
|
36
35
|
return { ok: false, code, message };
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
function toSnakeCase(value: string): string {
|
|
40
|
-
return value
|
|
41
|
-
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
42
|
-
.replace(/[^a-zA-Z0-9]+/g, "_")
|
|
43
|
-
.replace(/^_+|_+$/g, "")
|
|
44
|
-
.toLowerCase();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function invalidParameterCode(key: string, spec: OutcomeToolParameterSpec): string {
|
|
48
|
-
return spec.invalidErrorCode ?? `invalid_${toSnakeCase(key)}`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function requiredParameterError(
|
|
52
|
-
turnId: string,
|
|
53
|
-
outcome: string,
|
|
54
|
-
key: string,
|
|
55
|
-
spec: OutcomeToolParameterSpec,
|
|
56
|
-
): OutcomeValidationFailure {
|
|
57
|
-
return validationFailure(
|
|
58
|
-
spec.requiredErrorCode ?? `${toSnakeCase(key)}_required`,
|
|
59
|
-
`${turnId}.${outcome} requires a non-empty ${key}`,
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function minItemsParameterError(
|
|
64
|
-
turnId: string,
|
|
65
|
-
outcome: string,
|
|
66
|
-
key: string,
|
|
67
|
-
spec: OutcomeToolParameterSpec,
|
|
68
|
-
): OutcomeValidationFailure {
|
|
69
|
-
return validationFailure(
|
|
70
|
-
spec.minItemsErrorCode ?? spec.requiredErrorCode ?? `${toSnakeCase(key)}_required`,
|
|
71
|
-
`${turnId}.${outcome} requires at least ${spec.minItems ?? 0} item(s) for ${key}`,
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function invalidParameterError(
|
|
76
|
-
turnId: string,
|
|
77
|
-
outcome: string,
|
|
78
|
-
key: string,
|
|
79
|
-
spec: OutcomeToolParameterSpec,
|
|
80
|
-
expected: string,
|
|
81
|
-
): OutcomeValidationFailure {
|
|
82
|
-
return validationFailure(
|
|
83
|
-
invalidParameterCode(key, spec),
|
|
84
|
-
`${turnId}.${outcome} expects ${key} to be ${expected}`,
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function minimumParameterError(
|
|
89
|
-
turnId: string,
|
|
90
|
-
outcome: string,
|
|
91
|
-
key: string,
|
|
92
|
-
spec: OutcomeToolParameterSpec,
|
|
93
|
-
): OutcomeValidationFailure {
|
|
94
|
-
return validationFailure(
|
|
95
|
-
spec.minimumErrorCode ?? invalidParameterCode(key, spec),
|
|
96
|
-
`${turnId}.${outcome} expects ${key} to be >= ${spec.minimum ?? 0}`,
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
type OutcomeParameterSchema = v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>;
|
|
101
|
-
|
|
102
|
-
const scalarParameters = {
|
|
103
|
-
string: { schema: v.string(), label: "a string", plural: "strings" },
|
|
104
|
-
number: {
|
|
105
|
-
schema: v.pipe(v.number(), v.finite()),
|
|
106
|
-
label: "a finite number",
|
|
107
|
-
plural: "finite numbers",
|
|
108
|
-
},
|
|
109
|
-
boolean: { schema: v.boolean(), label: "a boolean", plural: "booleans" },
|
|
110
|
-
object: {
|
|
111
|
-
schema: v.custom<Record<string, unknown>>(isJsonObject, "Expected an object"),
|
|
112
|
-
label: "an object",
|
|
113
|
-
plural: "objects",
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
function matchesNestedOutcomeSpec(spec: OutcomeToolArrayItemSpec, value: unknown): boolean {
|
|
118
|
-
switch (spec.type) {
|
|
119
|
-
case "string":
|
|
120
|
-
return typeof value === "string";
|
|
121
|
-
case "number":
|
|
122
|
-
return typeof value === "number" && Number.isFinite(value);
|
|
123
|
-
case "boolean":
|
|
124
|
-
return typeof value === "boolean";
|
|
125
|
-
case "array": {
|
|
126
|
-
const itemSpec = spec.items;
|
|
127
|
-
return (
|
|
128
|
-
Array.isArray(value) &&
|
|
129
|
-
(spec.minItems === undefined || value.length >= spec.minItems) &&
|
|
130
|
-
(!itemSpec || value.every((item) => matchesNestedOutcomeSpec(itemSpec, item)))
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
case "object": {
|
|
134
|
-
if (!isJsonObject(value)) return false;
|
|
135
|
-
const properties = spec.properties ?? {};
|
|
136
|
-
if ((spec.required ?? []).some((key) => !Object.hasOwn(value, key))) return false;
|
|
137
|
-
if (
|
|
138
|
-
spec.additionalProperties === false &&
|
|
139
|
-
Object.keys(value).some((key) => !Object.hasOwn(properties, key))
|
|
140
|
-
)
|
|
141
|
-
return false;
|
|
142
|
-
return Object.entries(properties).every(
|
|
143
|
-
([key, property]) =>
|
|
144
|
-
!Object.hasOwn(value, key) || matchesNestedOutcomeSpec(property, value[key]),
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
default:
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function compileOutcomeParameterSchema(spec: OutcomeToolParameterSpec): OutcomeParameterSchema {
|
|
153
|
-
if (spec.type !== "array") return scalarParameters[spec.type].schema;
|
|
154
|
-
const itemSpec = spec.items ?? { type: "string" };
|
|
155
|
-
return v.custom(
|
|
156
|
-
(value) =>
|
|
157
|
-
Array.isArray(value) && value.every((item) => matchesNestedOutcomeSpec(itemSpec, item)),
|
|
158
|
-
"Expected an array matching its declared item schema",
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function effectiveArrayItemCount(
|
|
163
|
-
spec: OutcomeToolParameterSpec,
|
|
164
|
-
value: readonly unknown[],
|
|
165
|
-
): number {
|
|
166
|
-
return (spec.items?.type ?? "string") === "string"
|
|
167
|
-
? normalizeStringArray(value).length
|
|
168
|
-
: value.length;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function expectedParameterLabel(spec: OutcomeToolParameterSpec): string {
|
|
172
|
-
if (spec.type !== "array") return scalarParameters[spec.type].label;
|
|
173
|
-
if (spec.items?.type === "object")
|
|
174
|
-
return spec.items.properties
|
|
175
|
-
? "an array of objects matching the declared schema"
|
|
176
|
-
: "an array of objects";
|
|
177
|
-
if (spec.items?.type === "array") return "an array of arrays matching the declared schema";
|
|
178
|
-
return `an array of ${scalarParameters[spec.items?.type ?? "string"].plural}`;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
38
|
function jsonValuesEqual(left: unknown, right: unknown): boolean {
|
|
182
|
-
if (left === right)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
for (let index = 0; index < leftKeys.length; index += 1) {
|
|
198
|
-
if (leftKeys[index] !== rightKeys[index]) {
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return leftKeys.every((key) => jsonValuesEqual(left[key], right[key]));
|
|
203
|
-
}
|
|
204
|
-
return false;
|
|
39
|
+
if (left === right) return true;
|
|
40
|
+
if (Array.isArray(left) && Array.isArray(right))
|
|
41
|
+
return (
|
|
42
|
+
left.length === right.length &&
|
|
43
|
+
left.every((value, index) => jsonValuesEqual(value, right[index]))
|
|
44
|
+
);
|
|
45
|
+
return (
|
|
46
|
+
isJsonObject(left) &&
|
|
47
|
+
isJsonObject(right) &&
|
|
48
|
+
Object.keys(left).length === Object.keys(right).length &&
|
|
49
|
+
Object.keys(left).every(
|
|
50
|
+
(key) => Object.hasOwn(right, key) && jsonValuesEqual(left[key], right[key]),
|
|
51
|
+
)
|
|
52
|
+
);
|
|
205
53
|
}
|
|
206
54
|
|
|
207
55
|
function resolveOutcomeValidationContract(
|
|
@@ -298,11 +146,7 @@ function validateTurnEndResultParams(
|
|
|
298
146
|
params: Record<string, unknown>,
|
|
299
147
|
expectedParams: Record<string, unknown>,
|
|
300
148
|
): OutcomeValidationFailure | null {
|
|
301
|
-
|
|
302
|
-
v.custom((value) => jsonValuesEqual(value, expectedParams)),
|
|
303
|
-
params,
|
|
304
|
-
);
|
|
305
|
-
if (parsed.success) {
|
|
149
|
+
if (jsonValuesEqual(params, expectedParams)) {
|
|
306
150
|
return null;
|
|
307
151
|
}
|
|
308
152
|
return validationFailure(
|
|
@@ -318,50 +162,8 @@ function validateDeclaredOutcomeParameters(
|
|
|
318
162
|
parameterSpecs: Record<string, OutcomeToolParameterSpec>,
|
|
319
163
|
knownProjectKeys?: ReadonlySet<string>,
|
|
320
164
|
): OutcomeValidationFailure | null {
|
|
321
|
-
const
|
|
322
|
-
if (
|
|
323
|
-
return validationFailure(
|
|
324
|
-
"unknown_parameter",
|
|
325
|
-
`${turnId}.${outcome} received unknown parameter(s): ${unknownKeys.join(", ")}`,
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
for (const [key, spec] of Object.entries(parameterSpecs)) {
|
|
330
|
-
const value = params[key];
|
|
331
|
-
if (value === undefined) {
|
|
332
|
-
if (spec.required) {
|
|
333
|
-
return requiredParameterError(turnId, outcome, key, spec);
|
|
334
|
-
}
|
|
335
|
-
continue;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
if (!v.safeParse(compileOutcomeParameterSchema(spec), value).success) {
|
|
339
|
-
return invalidParameterError(turnId, outcome, key, spec, expectedParameterLabel(spec));
|
|
340
|
-
}
|
|
341
|
-
if (spec.type === "string" && trimString(value as string) === "" && spec.required) {
|
|
342
|
-
return requiredParameterError(turnId, outcome, key, spec);
|
|
343
|
-
}
|
|
344
|
-
if (spec.type === "number" && spec.minimum !== undefined && (value as number) < spec.minimum) {
|
|
345
|
-
return minimumParameterError(turnId, outcome, key, spec);
|
|
346
|
-
}
|
|
347
|
-
if (
|
|
348
|
-
spec.enum &&
|
|
349
|
-
spec.enum.length > 0 &&
|
|
350
|
-
typeof value === "string" &&
|
|
351
|
-
!spec.enum.includes(value)
|
|
352
|
-
) {
|
|
353
|
-
return invalidParameterError(turnId, outcome, key, spec, `one of: ${spec.enum.join(", ")}`);
|
|
354
|
-
}
|
|
355
|
-
if (spec.type === "array") {
|
|
356
|
-
const effectiveItemCount = effectiveArrayItemCount(spec, value as readonly unknown[]);
|
|
357
|
-
if (spec.required && effectiveItemCount === 0) {
|
|
358
|
-
return requiredParameterError(turnId, outcome, key, spec);
|
|
359
|
-
}
|
|
360
|
-
if (spec.minItems !== undefined && effectiveItemCount < spec.minItems) {
|
|
361
|
-
return minItemsParameterError(turnId, outcome, key, spec);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
165
|
+
const [issue] = validateOutcomeParameters(parameterSpecs, params);
|
|
166
|
+
if (issue) return validationFailure(issue.code, `${turnId}.${outcome}: ${issue.message}`);
|
|
365
167
|
const projectError = validateChangedProjects(params.changedProjects, knownProjectKeys);
|
|
366
168
|
if (projectError) {
|
|
367
169
|
return projectError;
|
|
@@ -38,6 +38,7 @@ const WORKER_LEASE_TRANSITIONS: ReadonlyArray<WorkerLeaseTransitionRule> = [
|
|
|
38
38
|
{ from: "idle", to: "failed", observation: "failure_reported" },
|
|
39
39
|
{ from: "busy", to: "failed", observation: "failure_reported" },
|
|
40
40
|
{ from: "draining", to: "failed", observation: "failure_reported" },
|
|
41
|
+
{ from: "cleanup", to: "failed", observation: "failure_reported" },
|
|
41
42
|
|
|
42
43
|
{ from: "draining", to: "cleanup", observation: "cleanup_completed" },
|
|
43
44
|
{ from: "failed", to: "cleanup", observation: "cleanup_completed" },
|
|
@@ -68,7 +69,7 @@ const WORKER_LEASE_NOOPS: Readonly<Record<WorkerLeaseObservation, ReadonlySet<Wo
|
|
|
68
69
|
busy_reported: new Set(["busy", "draining", "failed", "cleanup", "exited"]),
|
|
69
70
|
idle_reported: new Set(["idle", "draining", "failed", "cleanup", "exited"]),
|
|
70
71
|
stop_requested: new Set(["absent", "draining", "failed", "cleanup", "exited"]),
|
|
71
|
-
failure_reported: new Set(["failed", "
|
|
72
|
+
failure_reported: new Set(["failed", "exited"]),
|
|
72
73
|
cleanup_completed: new Set(["cleanup", "exited"]),
|
|
73
74
|
process_exited: new Set(["absent", "exited"]),
|
|
74
75
|
reclaimed: new Set(["absent"]),
|
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
getExternalActionTransitionTrigger,
|
|
23
23
|
getExternalSourceTransitionId,
|
|
24
24
|
isExternalTurnDefinition,
|
|
25
|
-
isHumanTurnDefinition,
|
|
26
25
|
} from "@leitwerk-dev/process-sdk";
|
|
27
26
|
import { generateId, now } from "./db/repo-helpers.js";
|
|
28
27
|
import type { PendingExternalSourceFire, RepositoryBundle } from "./db/repositories.js";
|
|
@@ -447,9 +446,6 @@ export function createExternalSourceService(
|
|
|
447
446
|
return armed;
|
|
448
447
|
}
|
|
449
448
|
|
|
450
|
-
if (!isHumanTurnDefinition(turnDef) && turnDef.kind !== "automatic") {
|
|
451
|
-
return [];
|
|
452
|
-
}
|
|
453
449
|
for (const [externalActionId, action] of Object.entries(turnDef.externalActions ?? {})) {
|
|
454
450
|
if (action.when && !action.when({ ...context })) {
|
|
455
451
|
continue;
|
|
@@ -535,14 +531,13 @@ export function createExternalSourceService(
|
|
|
535
531
|
}
|
|
536
532
|
for (const [turnId, binding] of processDef.turns) {
|
|
537
533
|
const turnDef = binding.definition;
|
|
538
|
-
if (
|
|
534
|
+
if (turnDef.kind !== "external") {
|
|
539
535
|
for (const [externalActionId, action] of Object.entries(turnDef.externalActions ?? {})) {
|
|
540
536
|
if (getExternalActionArmingId({ turnId, externalActionId }) === armingId) {
|
|
541
537
|
return { turnId, externalActionId, sourceKind: action.source.kind };
|
|
542
538
|
}
|
|
543
539
|
}
|
|
544
|
-
}
|
|
545
|
-
if (isExternalTurnDefinition(turnDef)) {
|
|
540
|
+
} else {
|
|
546
541
|
for (const [index, transition] of turnDef.transitions.entries()) {
|
|
547
542
|
const id = getExternalSourceTransitionId({
|
|
548
543
|
turnId,
|
|
@@ -742,6 +737,16 @@ export function createExternalSourceService(
|
|
|
742
737
|
);
|
|
743
738
|
return accept({ writes, data: { ok: false, code: failure.code } });
|
|
744
739
|
};
|
|
740
|
+
const targetTurn = arming.transition.to
|
|
741
|
+
? ctx.deps.processGraphs.get(ctx.process.processId)?.turns.get(arming.transition.to)
|
|
742
|
+
?.definition
|
|
743
|
+
: undefined;
|
|
744
|
+
const wakesWorker = targetTurn?.kind === "llm" || targetTurn?.kind === "automatic";
|
|
745
|
+
if (wakesWorker && !targetTurn.waitFor)
|
|
746
|
+
return reject(
|
|
747
|
+
"external_readiness_required",
|
|
748
|
+
"External worker targets must declare waitFor",
|
|
749
|
+
);
|
|
745
750
|
|
|
746
751
|
const effectWrites = await buildExternalSourceEffectWrites({
|
|
747
752
|
arming,
|
|
@@ -834,6 +839,12 @@ export function createExternalSourceService(
|
|
|
834
839
|
);
|
|
835
840
|
}
|
|
836
841
|
}
|
|
842
|
+
// A readiness notification is an edge, not a business turn. Published human
|
|
843
|
+
// input still keeps its product record for prompt/chronicle references.
|
|
844
|
+
if (wakesWorker && !publishedInput) {
|
|
845
|
+
externalWrites.turnRecordWrites = [];
|
|
846
|
+
externalWrites.turnAnnotationWrites = [];
|
|
847
|
+
}
|
|
837
848
|
|
|
838
849
|
for (const pendingFireId of input.pendingFireIds ?? []) {
|
|
839
850
|
externalWrites.pendingExternalSourceFireWrites.push({
|
|
@@ -925,6 +936,21 @@ export function createExternalSourceService(
|
|
|
925
936
|
refreshedAt: recordedAt,
|
|
926
937
|
};
|
|
927
938
|
const writes = createWrites();
|
|
939
|
+
if (input.state !== undefined) {
|
|
940
|
+
const definition = ctx.deps.processGraphs.get(ctx.process.processId);
|
|
941
|
+
if (!definition) return reject("process_not_found", "Process definition is unavailable");
|
|
942
|
+
try {
|
|
943
|
+
const state = definition.stateCodec.parse(input.state);
|
|
944
|
+
applyProcessPatchField(
|
|
945
|
+
writes,
|
|
946
|
+
ctx.process,
|
|
947
|
+
"stateJson",
|
|
948
|
+
JSON.stringify(definition.stateCodec.serialize(state)),
|
|
949
|
+
);
|
|
950
|
+
} catch {
|
|
951
|
+
return reject("invalid_process_state", "Invalid observation state");
|
|
952
|
+
}
|
|
953
|
+
}
|
|
928
954
|
writes.turnAnnotationWrites.push(
|
|
929
955
|
previous
|
|
930
956
|
? { kind: "update", id: previous.id, input: { payload, updatedAt: recordedAt } }
|
|
@@ -17,9 +17,13 @@ import type { ProcessEngine, ProcessEngineLogger } from "../process-engine/types
|
|
|
17
17
|
import type { ProcessGraphRegistry } from "../process-graph.js";
|
|
18
18
|
import { createScheduledProcessFromLaunchPlan } from "../process-launch-executor.js";
|
|
19
19
|
import { toLaunchPipelineCommit } from "../process-launch-pipeline-adapter.js";
|
|
20
|
-
import
|
|
20
|
+
import {
|
|
21
|
+
isPinnedModelSelection,
|
|
22
|
+
type ServerProcessModelPolicy,
|
|
23
|
+
} from "../process-model-policy/index.js";
|
|
21
24
|
import type { ProcessOperationCoordinator } from "../process-operation-coordinator.js";
|
|
22
25
|
import type { ProcessTitleGenerator } from "../process-title-generator.js";
|
|
26
|
+
import type { LaunchSkillDefaults } from "../skills/launch-skills.js";
|
|
23
27
|
import type { Broadcaster } from "../ws/broadcast.js";
|
|
24
28
|
import {
|
|
25
29
|
projectFutureExecutionModelState,
|
|
@@ -55,6 +59,8 @@ export interface FutureExecutionExecutorDeps
|
|
|
55
59
|
| "transaction"
|
|
56
60
|
> {
|
|
57
61
|
/** @internal */
|
|
62
|
+
skillDefaults?: LaunchSkillDefaults;
|
|
63
|
+
/** @internal */
|
|
58
64
|
turnRecords?: RepositoryBundle["turnRecords"];
|
|
59
65
|
/** @internal */
|
|
60
66
|
broadcaster: Broadcaster;
|
|
@@ -440,7 +446,8 @@ export function createFutureExecutionExecutor(deps: FutureExecutionExecutorDeps)
|
|
|
440
446
|
return;
|
|
441
447
|
}
|
|
442
448
|
if (
|
|
443
|
-
!latest.modelSelection
|
|
449
|
+
(!latest.modelSelection ||
|
|
450
|
+
(latest.kind === "action" && !isPinnedModelSelection(latest.modelSelection))) &&
|
|
444
451
|
deps.processGraphs &&
|
|
445
452
|
deps.processActionRegistry &&
|
|
446
453
|
deps.turnRecords
|
|
@@ -50,6 +50,7 @@ import type { ServerProcessModelPolicy } from "../process-model-policy/index.js"
|
|
|
50
50
|
import { presentLaunchPlanPreparationIssues } from "../process-model-policy-presenter.js";
|
|
51
51
|
import type { ProcessOperationCoordinator } from "../process-operation-coordinator.js";
|
|
52
52
|
import type { ProcessTitleGenerator } from "../process-title-generator.js";
|
|
53
|
+
import { type LaunchSkillDefaults, resolveLaunchSkills } from "../skills/launch-skills.js";
|
|
53
54
|
import type { Broadcaster } from "../ws/broadcast.js";
|
|
54
55
|
import { projectLaunchPlanModelState } from "./model-projection.js";
|
|
55
56
|
import {
|
|
@@ -65,7 +66,7 @@ import { planConsumeFutureExecution } from "./transition-planner.js";
|
|
|
65
66
|
export interface FutureExecutionIssue extends LauncherValidationError {}
|
|
66
67
|
|
|
67
68
|
/** @internal */
|
|
68
|
-
type LaunchFailure =
|
|
69
|
+
export type LaunchFailure =
|
|
69
70
|
| {
|
|
70
71
|
/** @internal */
|
|
71
72
|
kind: "invalid";
|
|
@@ -147,31 +148,10 @@ export type LaunchMutationOutcome =
|
|
|
147
148
|
export interface NormalizedScheduledLaunchInput extends ParsedLauncherRequestBody {}
|
|
148
149
|
|
|
149
150
|
/** @internal */
|
|
150
|
-
export type ValidatedLaunchSchedule =
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
/** @internal */
|
|
155
|
-
nextRunAt: null;
|
|
156
|
-
/** @internal */
|
|
157
|
-
cronExpression: null;
|
|
158
|
-
}
|
|
159
|
-
| {
|
|
160
|
-
/** @internal */
|
|
161
|
-
mode: "once";
|
|
162
|
-
/** @internal */
|
|
163
|
-
nextRunAt: string;
|
|
164
|
-
/** @internal */
|
|
165
|
-
cronExpression: null;
|
|
166
|
-
}
|
|
167
|
-
| {
|
|
168
|
-
/** @internal */
|
|
169
|
-
mode: "cron";
|
|
170
|
-
/** @internal */
|
|
171
|
-
nextRunAt: string;
|
|
172
|
-
/** @internal */
|
|
173
|
-
cronExpression: string;
|
|
174
|
-
};
|
|
151
|
+
export type ValidatedLaunchSchedule = Extract<
|
|
152
|
+
ReturnType<typeof validateScheduleRequestInput>,
|
|
153
|
+
{ ok: true }
|
|
154
|
+
>["value"];
|
|
175
155
|
|
|
176
156
|
/** @internal */
|
|
177
157
|
export interface PreparedLaunch {
|
|
@@ -234,6 +214,7 @@ export interface FutureLaunchLifecycleDeps
|
|
|
234
214
|
processModelPolicy: ServerProcessModelPolicy;
|
|
235
215
|
modelStatusCache: Pick<ModelStatusCache, "snapshot">;
|
|
236
216
|
logger?: ProcessEngineLogger;
|
|
217
|
+
skillDefaults?: LaunchSkillDefaults;
|
|
237
218
|
}
|
|
238
219
|
|
|
239
220
|
function invalidOutcome(
|
|
@@ -244,13 +225,14 @@ function invalidOutcome(
|
|
|
244
225
|
}
|
|
245
226
|
|
|
246
227
|
function resolveSelectedSkills(
|
|
247
|
-
|
|
228
|
+
deps: FutureLaunchLifecycleDeps,
|
|
229
|
+
processId: string,
|
|
248
230
|
ids: readonly string[],
|
|
249
231
|
):
|
|
250
232
|
| { ok: true; value: readonly SkillSelection[] }
|
|
251
233
|
| { ok: false; outcome: Extract<LaunchFailure, { kind: "invalid" }> } {
|
|
252
234
|
try {
|
|
253
|
-
return { ok: true, value:
|
|
235
|
+
return { ok: true, value: resolveLaunchSkills(deps, processId, ids) };
|
|
254
236
|
} catch (error) {
|
|
255
237
|
return {
|
|
256
238
|
ok: false,
|
|
@@ -293,30 +275,61 @@ function launchFailureOutcome(
|
|
|
293
275
|
: { kind: "failed", issue };
|
|
294
276
|
}
|
|
295
277
|
|
|
296
|
-
function
|
|
278
|
+
function preservedScheduleSkills(
|
|
279
|
+
payload: FutureLaunchPayload,
|
|
280
|
+
selectedSkillIds: readonly string[] | undefined,
|
|
281
|
+
): readonly SkillSelection[] | undefined {
|
|
282
|
+
if (selectedSkillIds === undefined) return payload.resourceSelections;
|
|
283
|
+
const previous = new Set(payload.selectedSkillIds);
|
|
284
|
+
const selected = new Set(selectedSkillIds);
|
|
285
|
+
return previous.size === selected.size && [...selected].every((id) => previous.has(id))
|
|
286
|
+
? payload.resourceSelections
|
|
287
|
+
: undefined;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function normalizeScheduledLaunchUpdate(
|
|
297
291
|
execution: FutureExecution,
|
|
298
292
|
request: NormalizedScheduledLaunchInput,
|
|
299
|
-
|
|
293
|
+
expectedLauncherId?: string,
|
|
300
294
|
) {
|
|
295
|
+
const parsed = parseFutureLaunchPayloadJson(execution.payloadJson);
|
|
296
|
+
if (!parsed.ok)
|
|
297
|
+
return {
|
|
298
|
+
ok: false as const,
|
|
299
|
+
outcome: invalidOutcome("invalid_payload", "Scheduled launch payload is invalid"),
|
|
300
|
+
};
|
|
301
|
+
const payload = parsed.value;
|
|
302
|
+
const launcherId = execution.launcherId ?? payload.launchPlan.launcherId;
|
|
303
|
+
if (expectedLauncherId !== undefined && launcherId !== expectedLauncherId)
|
|
304
|
+
return {
|
|
305
|
+
ok: false as const,
|
|
306
|
+
outcome: invalidOutcome("invalid_schedule", "Schedule belongs to another launcher"),
|
|
307
|
+
};
|
|
301
308
|
const schedule = request.scheduleProvided
|
|
302
309
|
? ({ ok: true, value: request.schedule } as const)
|
|
303
310
|
: resolveStoredScheduleRequest(execution);
|
|
304
|
-
if (!schedule.ok)
|
|
311
|
+
if (!schedule.ok)
|
|
312
|
+
return { ok: false as const, outcome: { kind: "invalid" as const, issues: [schedule.issue] } };
|
|
305
313
|
return {
|
|
306
314
|
ok: true as const,
|
|
307
315
|
value: {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
:
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
316
|
+
launcherId,
|
|
317
|
+
request: {
|
|
318
|
+
title: request.titleProvided ? request.title : payload.launchPlan.processInput.title,
|
|
319
|
+
titleProvided: true,
|
|
320
|
+
launcherInput: request.launcherInputProvided
|
|
321
|
+
? request.launcherInput
|
|
322
|
+
: payload.launcherInput,
|
|
323
|
+
launcherInputProvided: true,
|
|
324
|
+
skillIds: request.skillIds ?? payload.selectedSkillIds,
|
|
325
|
+
modelConfig: request.modelConfigProvided ? request.modelConfig : payload.modelConfig,
|
|
326
|
+
modelConfigProvided: request.modelConfigProvided,
|
|
327
|
+
schedule: schedule.value,
|
|
328
|
+
scheduleProvided: true,
|
|
329
|
+
actor: payload.actor,
|
|
330
|
+
},
|
|
331
|
+
baseLaunchPlan: payload.launchPlan,
|
|
332
|
+
resourceSelections: preservedScheduleSkills(payload, request.skillIds),
|
|
320
333
|
},
|
|
321
334
|
};
|
|
322
335
|
}
|
|
@@ -389,6 +402,7 @@ export function createFutureLaunchLifecycle(
|
|
|
389
402
|
async function persistPreparedLaunch(
|
|
390
403
|
input: PreparedLaunch & { existing?: FutureExecution; actor: Actor },
|
|
391
404
|
): Promise<LaunchMutationOutcome> {
|
|
405
|
+
if (input.launchPlan.preview) throw new Error("Launcher previews cannot be committed");
|
|
392
406
|
if (input.schedule.mode === "now") throw new Error("Immediate launches cannot be persisted");
|
|
393
407
|
const values = {
|
|
394
408
|
scheduleKind: input.schedule.mode,
|
|
@@ -444,9 +458,10 @@ export function createFutureLaunchLifecycle(
|
|
|
444
458
|
? { ok: true as const, launcher: input.resolvedLauncher }
|
|
445
459
|
: await deps.launcherService.resolveUiLauncher(input.launcherId, input.request.launcherInput);
|
|
446
460
|
if (!resolved.ok) return { ok: false, outcome: launcherResolutionFailure(resolved) };
|
|
447
|
-
const resourceSelections =
|
|
448
|
-
|
|
449
|
-
|
|
461
|
+
const resourceSelections =
|
|
462
|
+
input.resourceSelections !== undefined
|
|
463
|
+
? { ok: true as const, value: input.resourceSelections }
|
|
464
|
+
: resolveSelectedSkills(deps, resolved.launcher.processId, input.request.skillIds ?? []);
|
|
450
465
|
if (!resourceSelections.ok) return { ok: false, outcome: resourceSelections.outcome };
|
|
451
466
|
|
|
452
467
|
// A revised launch uses its persisted plan as the source of stored model
|
|
@@ -491,12 +506,10 @@ export function createFutureLaunchLifecycle(
|
|
|
491
506
|
actor?: Actor,
|
|
492
507
|
): Promise<LaunchMutationOutcome> {
|
|
493
508
|
const opened = deps.launchPipeline.open({ launcherId: existing.launcherId, origin: "ui" });
|
|
494
|
-
type ResolvedRevision =
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
actor: Actor;
|
|
499
|
-
};
|
|
509
|
+
type ResolvedRevision = Extract<
|
|
510
|
+
ReturnType<typeof normalizeScheduledLaunchUpdate>,
|
|
511
|
+
{ ok: true }
|
|
512
|
+
>["value"] & { launcher: ResolvedProcessLauncher; actor: Actor };
|
|
500
513
|
const result = await deps.launchPipeline.run<
|
|
501
514
|
ResolvedRevision,
|
|
502
515
|
PreparedLaunch & { actor: Actor },
|
|
@@ -510,23 +523,19 @@ export function createFutureLaunchLifecycle(
|
|
|
510
523
|
});
|
|
511
524
|
if (!deps.launcherService)
|
|
512
525
|
return failure({ kind: "unavailable", reason: "Launcher service is not available" });
|
|
513
|
-
const
|
|
514
|
-
if (!
|
|
515
|
-
return failure(invalidOutcome("invalid_payload", "Scheduled launch payload is invalid"));
|
|
516
|
-
const launchRequest = resolveScheduledLaunchUpdateRequest(existing, request, parsed.value);
|
|
517
|
-
if (!launchRequest.ok) return failure({ kind: "invalid", issues: [launchRequest.issue] });
|
|
526
|
+
const update = normalizeScheduledLaunchUpdate(existing, request);
|
|
527
|
+
if (!update.ok) return failure(update.outcome);
|
|
518
528
|
const resolved = await deps.launcherService.resolveUiLauncher(
|
|
519
|
-
|
|
520
|
-
|
|
529
|
+
update.value.launcherId,
|
|
530
|
+
update.value.request.launcherInput,
|
|
521
531
|
);
|
|
522
532
|
if (!resolved.ok) return failure(launcherResolutionFailure(resolved));
|
|
523
533
|
return {
|
|
524
534
|
kind: "resolved",
|
|
525
535
|
value: {
|
|
526
|
-
|
|
527
|
-
request: launchRequest.value,
|
|
536
|
+
...update.value,
|
|
528
537
|
launcher: resolved.launcher,
|
|
529
|
-
actor: actor ??
|
|
538
|
+
actor: actor ?? update.value.request.actor ?? SYSTEM_ACTOR,
|
|
530
539
|
},
|
|
531
540
|
};
|
|
532
541
|
},
|
|
@@ -544,10 +553,8 @@ export function createFutureLaunchLifecycle(
|
|
|
544
553
|
},
|
|
545
554
|
async prepare(resolved) {
|
|
546
555
|
const prepared = await prepareLaunchInternal({
|
|
556
|
+
...resolved,
|
|
547
557
|
launcherId: resolved.launcher.launcherId,
|
|
548
|
-
request: resolved.request,
|
|
549
|
-
baseLaunchPlan: resolved.payload.launchPlan,
|
|
550
|
-
resourceSelections: request.skillIds ? undefined : resolved.payload.resourceSelections,
|
|
551
558
|
operationTime,
|
|
552
559
|
resolvedLauncher: resolved.launcher,
|
|
553
560
|
});
|
|
@@ -638,8 +645,19 @@ export function createFutureLaunchLifecycle(
|
|
|
638
645
|
opts?: {
|
|
639
646
|
/** @internal */
|
|
640
647
|
resolvedLauncher?: ResolvedProcessLauncher;
|
|
648
|
+
/** Existing schedule being previewed; pins survive unchanged skill selections. @internal */
|
|
649
|
+
futureExecutionId?: string;
|
|
641
650
|
},
|
|
642
651
|
): Promise<PreparedLaunchResult> {
|
|
652
|
+
if (opts?.futureExecutionId !== undefined) {
|
|
653
|
+
const existing = deps.futureExecutions.getById(opts.futureExecutionId);
|
|
654
|
+
if (!existing || existing.kind !== "launch") {
|
|
655
|
+
return { ok: false, outcome: { kind: "not_found", target: "launch" } };
|
|
656
|
+
}
|
|
657
|
+
const update = normalizeScheduledLaunchUpdate(existing, request, launcherId);
|
|
658
|
+
if (!update.ok) return update;
|
|
659
|
+
return prepareLaunchInternal({ ...update.value, resolvedLauncher: opts.resolvedLauncher });
|
|
660
|
+
}
|
|
643
661
|
return prepareLaunchInternal({
|
|
644
662
|
launcherId,
|
|
645
663
|
request,
|
|
@@ -769,23 +787,14 @@ export function createFutureLaunchLifecycle(
|
|
|
769
787
|
if (!existing || existing.kind !== "launch") return { kind: "not_found", target: "launch" };
|
|
770
788
|
if (request.scheduleProvided && request.schedule.mode === "now")
|
|
771
789
|
return launchScheduledNow(existing, request, operationTime, opts?.actor);
|
|
772
|
-
const
|
|
773
|
-
if (!
|
|
774
|
-
|
|
775
|
-
const launchRequest = resolveScheduledLaunchUpdateRequest(existing, request, parsed.value);
|
|
776
|
-
if (!launchRequest.ok) return { kind: "invalid", issues: [launchRequest.issue] };
|
|
777
|
-
const prepared = await prepareLaunchInternal({
|
|
778
|
-
launcherId: existing.launcherId ?? parsed.value.launchPlan.launcherId,
|
|
779
|
-
request: launchRequest.value,
|
|
780
|
-
baseLaunchPlan: parsed.value.launchPlan,
|
|
781
|
-
resourceSelections: request.skillIds ? undefined : parsed.value.resourceSelections,
|
|
782
|
-
operationTime,
|
|
783
|
-
});
|
|
790
|
+
const update = normalizeScheduledLaunchUpdate(existing, request);
|
|
791
|
+
if (!update.ok) return update.outcome;
|
|
792
|
+
const prepared = await prepareLaunchInternal({ ...update.value, operationTime });
|
|
784
793
|
if (!prepared.ok) return prepared.outcome;
|
|
785
794
|
return persistPreparedLaunch({
|
|
786
795
|
...prepared.prepared,
|
|
787
796
|
existing,
|
|
788
|
-
actor: opts?.actor ??
|
|
797
|
+
actor: opts?.actor ?? update.value.request.actor ?? SYSTEM_ACTOR,
|
|
789
798
|
});
|
|
790
799
|
});
|
|
791
800
|
},
|