@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
package/src/db/skill-repo.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
} from "@leitwerk-dev/protocol";
|
|
11
11
|
import { verifyCanonicalPiResourceBundle } from "@leitwerk-dev/worker-protocol";
|
|
12
12
|
import { and, asc, count, desc, eq, isNotNull, max, notExists, notInArray, sql } from "drizzle-orm";
|
|
13
|
+
import type { ImportedExtensionSkill } from "../skills/extension-importer.js";
|
|
13
14
|
import { explicitSkillReferenceIds, referencedSkillIds } from "../skills/skill-dependencies.js";
|
|
14
15
|
import { isSkillModelInvocable } from "../skills/skill-frontmatter.js";
|
|
15
16
|
import type { ImportedRepositorySkill, ImportedSkill } from "../skills/source-importer.js";
|
|
@@ -45,6 +46,7 @@ function revisionForBundle(db: LeitwerkDb, item: ImportedSkill, timestamp: strin
|
|
|
45
46
|
bundleDigest: item.bundle.digest,
|
|
46
47
|
bundleBytes: Buffer.from(item.bundle.bytes),
|
|
47
48
|
sourceRevision: item.sourceRevision,
|
|
49
|
+
provenance: item.provenance ?? null,
|
|
48
50
|
importedAt: timestamp,
|
|
49
51
|
})
|
|
50
52
|
.run();
|
|
@@ -156,11 +158,16 @@ function pruneNeverInstalledCatalogEntries(db: LeitwerkDb): void {
|
|
|
156
158
|
.run();
|
|
157
159
|
}
|
|
158
160
|
|
|
159
|
-
function recordRevisionDependencies(
|
|
161
|
+
function recordRevisionDependencies(
|
|
162
|
+
db: LeitwerkDb,
|
|
163
|
+
revisionId: string,
|
|
164
|
+
markdown: string,
|
|
165
|
+
dependencyIds = explicitSkillReferenceIds(markdown),
|
|
166
|
+
): void {
|
|
160
167
|
db.delete(skillRevisionDependencies)
|
|
161
168
|
.where(eq(skillRevisionDependencies.skillRevisionId, revisionId))
|
|
162
169
|
.run();
|
|
163
|
-
for (const [position, dependencySkillId] of
|
|
170
|
+
for (const [position, dependencySkillId] of dependencyIds.entries()) {
|
|
164
171
|
db.insert(skillRevisionDependencies)
|
|
165
172
|
.values({ skillRevisionId: revisionId, dependencySkillId, position })
|
|
166
173
|
.run();
|
|
@@ -170,7 +177,7 @@ function recordRevisionDependencies(db: LeitwerkDb, revisionId: string, markdown
|
|
|
170
177
|
function activateSkill(
|
|
171
178
|
db: LeitwerkDb,
|
|
172
179
|
item: ImportedSkill,
|
|
173
|
-
registrationKind: "configuration" | "catalog",
|
|
180
|
+
registrationKind: "configuration" | "catalog" | "extension",
|
|
174
181
|
timestamp: string,
|
|
175
182
|
markdown = skillMarkdown(item.skillId, item.bundle.bytes, item.bundle.digest),
|
|
176
183
|
): string {
|
|
@@ -187,13 +194,14 @@ function activateSkill(
|
|
|
187
194
|
.onConflictDoNothing()
|
|
188
195
|
.run();
|
|
189
196
|
const revisionId = revisionForBundle(db, item, timestamp);
|
|
190
|
-
recordRevisionDependencies(db, revisionId, markdown);
|
|
197
|
+
recordRevisionDependencies(db, revisionId, markdown, item.provenance?.dependencies);
|
|
191
198
|
db.update(skills)
|
|
192
199
|
.set({
|
|
193
200
|
label: item.label,
|
|
194
201
|
description: item.description,
|
|
195
202
|
activeRevisionId: revisionId,
|
|
196
203
|
registrationKind,
|
|
204
|
+
ownerExtensionId: item.provenance?.extensionId ?? null,
|
|
197
205
|
updatedAt: timestamp,
|
|
198
206
|
})
|
|
199
207
|
.where(eq(skills.id, item.skillId))
|
|
@@ -201,6 +209,20 @@ function activateSkill(
|
|
|
201
209
|
return revisionId;
|
|
202
210
|
}
|
|
203
211
|
|
|
212
|
+
function reconcileSkills(
|
|
213
|
+
db: LeitwerkDb,
|
|
214
|
+
imported: readonly ImportedSkill[],
|
|
215
|
+
registrationKind: "configuration" | "extension",
|
|
216
|
+
): void {
|
|
217
|
+
const timestamp = now();
|
|
218
|
+
const ids = imported.map((item) => item.skillId);
|
|
219
|
+
db.update(skills)
|
|
220
|
+
.set({ activeRevisionId: null, updatedAt: timestamp })
|
|
221
|
+
.where(and(eq(skills.registrationKind, registrationKind), notInArray(skills.id, ids)))
|
|
222
|
+
.run();
|
|
223
|
+
for (const item of imported) activateSkill(db, item, registrationKind, timestamp);
|
|
224
|
+
}
|
|
225
|
+
|
|
204
226
|
function catalogView(db: LeitwerkDb): {
|
|
205
227
|
/** @internal */
|
|
206
228
|
availableSkills: SkillCatalogItem[];
|
|
@@ -219,12 +241,22 @@ function catalogView(db: LeitwerkDb): {
|
|
|
219
241
|
activeDigest: skillRevisions.bundleDigest,
|
|
220
242
|
activeBundleBytes: skillRevisions.bundleBytes,
|
|
221
243
|
registrationKind: skills.registrationKind,
|
|
244
|
+
ownerExtensionId: skills.ownerExtensionId,
|
|
245
|
+
provenance: skillRevisions.provenance,
|
|
222
246
|
})
|
|
223
247
|
.from(skills)
|
|
224
248
|
.innerJoin(skillRevisions, eq(skills.activeRevisionId, skillRevisions.id))
|
|
225
249
|
.orderBy(asc(skills.label), asc(skills.id))
|
|
226
250
|
.all();
|
|
227
251
|
const installedById = new Map(installedRows.map((row) => [row.id, row]));
|
|
252
|
+
const extensionIds = new Set(
|
|
253
|
+
db
|
|
254
|
+
.select({ id: skills.id })
|
|
255
|
+
.from(skills)
|
|
256
|
+
.where(eq(skills.registrationKind, "extension"))
|
|
257
|
+
.all()
|
|
258
|
+
.map((skill) => skill.id),
|
|
259
|
+
);
|
|
228
260
|
const availableSkills = candidates.map((candidate) => {
|
|
229
261
|
const active = installedById.get(candidate.skillId);
|
|
230
262
|
const registered = Boolean(
|
|
@@ -241,7 +273,9 @@ function catalogView(db: LeitwerkDb): {
|
|
|
241
273
|
updateAvailable: Boolean(
|
|
242
274
|
candidate.available && active?.registrationKind === "catalog" && !registered,
|
|
243
275
|
),
|
|
244
|
-
conflict:
|
|
276
|
+
conflict:
|
|
277
|
+
candidate.available &&
|
|
278
|
+
(active?.registrationKind === "configuration" || extensionIds.has(candidate.skillId)),
|
|
245
279
|
stale: !candidate.available,
|
|
246
280
|
modelInvocable: isSkillModelInvocable(
|
|
247
281
|
skillMarkdown(candidate.skillId, candidate.bundleBytes, candidate.bundleDigest),
|
|
@@ -262,12 +296,17 @@ function catalogView(db: LeitwerkDb): {
|
|
|
262
296
|
activeRevisionId: skill.activeRevisionId,
|
|
263
297
|
activeSourceRevision: skill.activeSourceRevision,
|
|
264
298
|
registrationKind: skill.registrationKind,
|
|
299
|
+
...(skill.ownerExtensionId
|
|
300
|
+
? { ownerExtensionId: skill.ownerExtensionId, provenance: skill.provenance }
|
|
301
|
+
: {}),
|
|
265
302
|
sourceRepositoryId:
|
|
266
|
-
|
|
267
|
-
?
|
|
268
|
-
:
|
|
269
|
-
? (
|
|
270
|
-
:
|
|
303
|
+
skill.registrationKind === "extension"
|
|
304
|
+
? null
|
|
305
|
+
: matching.length === 1
|
|
306
|
+
? (matching[0]?.repositoryId ?? null)
|
|
307
|
+
: activeSource.length === 1
|
|
308
|
+
? (activeSource[0]?.repositoryId ?? null)
|
|
309
|
+
: null,
|
|
271
310
|
updateAvailable:
|
|
272
311
|
skill.registrationKind === "catalog" &&
|
|
273
312
|
available.length === 1 &&
|
|
@@ -296,7 +335,11 @@ export function createSkillRepo(db: LeitwerkDb) {
|
|
|
296
335
|
/** @internal */
|
|
297
336
|
resolveActive(ids: readonly string[]): SkillSelection[] {
|
|
298
337
|
const activeSkills = db
|
|
299
|
-
.select({
|
|
338
|
+
.select({
|
|
339
|
+
id: skills.id,
|
|
340
|
+
revisionId: skillRevisions.id,
|
|
341
|
+
registrationKind: skills.registrationKind,
|
|
342
|
+
})
|
|
300
343
|
.from(skills)
|
|
301
344
|
.innerJoin(skillRevisions, eq(skills.activeRevisionId, skillRevisions.id))
|
|
302
345
|
.all();
|
|
@@ -315,6 +358,8 @@ export function createSkillRepo(db: LeitwerkDb) {
|
|
|
315
358
|
if (!skill) throw new Error(`Unknown or unavailable skill '${id}'`);
|
|
316
359
|
visiting.add(id);
|
|
317
360
|
for (const dependencyId of dependencies.get(skill.revisionId) ?? []) {
|
|
361
|
+
if (skill.registrationKind === "extension" && !byId.has(dependencyId))
|
|
362
|
+
throw new Error(`Missing dependency '${dependencyId}' for skill '${id}'`);
|
|
318
363
|
if (dependencyId !== id && byId.has(dependencyId)) add(dependencyId);
|
|
319
364
|
}
|
|
320
365
|
visiting.delete(id);
|
|
@@ -325,20 +370,30 @@ export function createSkillRepo(db: LeitwerkDb) {
|
|
|
325
370
|
},
|
|
326
371
|
/** @internal */
|
|
327
372
|
reconcile(imported: readonly ImportedSkill[]): void {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
373
|
+
reconcileSkills(db, imported, "configuration");
|
|
374
|
+
},
|
|
375
|
+
/** Reconcile all loaded extension packs in the caller's startup transaction. @internal */
|
|
376
|
+
reconcileExtensions(imported: readonly ImportedExtensionSkill[]): void {
|
|
377
|
+
const byId = new Map(imported.map((item) => [item.skillId, item]));
|
|
378
|
+
if (byId.size !== imported.length) throw new Error("Duplicate extension skill ID");
|
|
379
|
+
for (const item of imported) {
|
|
380
|
+
const current = db.select().from(skills).where(eq(skills.id, item.skillId)).get();
|
|
381
|
+
if (
|
|
382
|
+
current &&
|
|
383
|
+
(current.registrationKind !== "extension" ||
|
|
384
|
+
current.ownerExtensionId !== item.provenance.extensionId)
|
|
385
|
+
) {
|
|
386
|
+
throw new Error(
|
|
387
|
+
`Skill '${item.skillId}' is already owned by '${current.ownerExtensionId ?? current.registrationKind}'`,
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
for (const dependency of item.provenance.dependencies) {
|
|
391
|
+
if (byId.get(dependency)?.provenance.extensionId !== item.provenance.extensionId) {
|
|
392
|
+
throw new Error(`Missing pack dependency '${dependency}' for skill '${item.skillId}'`);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
reconcileSkills(db, imported, "extension");
|
|
342
397
|
},
|
|
343
398
|
/** @internal */
|
|
344
399
|
backfillDependencies(): void {
|
|
@@ -347,6 +402,7 @@ export function createSkillRepo(db: LeitwerkDb) {
|
|
|
347
402
|
db,
|
|
348
403
|
revision.id,
|
|
349
404
|
skillMarkdown(revision.skillId, revision.bundleBytes, revision.bundleDigest),
|
|
405
|
+
revision.provenance?.dependencies,
|
|
350
406
|
);
|
|
351
407
|
}
|
|
352
408
|
},
|
|
@@ -423,8 +479,13 @@ export function createSkillRepo(db: LeitwerkDb) {
|
|
|
423
479
|
);
|
|
424
480
|
}
|
|
425
481
|
const current = db.select().from(skills).where(eq(skills.id, id)).get();
|
|
426
|
-
if (
|
|
427
|
-
|
|
482
|
+
if (
|
|
483
|
+
current?.registrationKind === "extension" ||
|
|
484
|
+
(current?.activeRevisionId && current.registrationKind === "configuration")
|
|
485
|
+
) {
|
|
486
|
+
throw new Error(
|
|
487
|
+
`Skill '${id}' is managed by ${current.ownerExtensionId ?? "configuration"}`,
|
|
488
|
+
);
|
|
428
489
|
}
|
|
429
490
|
visiting.add(id);
|
|
430
491
|
const markdown = skillMarkdown(id, candidate.bundleBytes, candidate.bundleDigest);
|
|
@@ -510,6 +571,7 @@ export function createSkillRepo(db: LeitwerkDb) {
|
|
|
510
571
|
id: skillRevisions.id,
|
|
511
572
|
sourceRevision: skillRevisions.sourceRevision,
|
|
512
573
|
importedAt: skillRevisions.importedAt,
|
|
574
|
+
provenance: skillRevisions.provenance,
|
|
513
575
|
})
|
|
514
576
|
.from(skillRevisions)
|
|
515
577
|
.where(eq(skillRevisions.skillId, skillId))
|
|
@@ -6,7 +6,8 @@ import type {
|
|
|
6
6
|
} from "@leitwerk-dev/domain";
|
|
7
7
|
import { and, eq } from "drizzle-orm";
|
|
8
8
|
import type { LeitwerkDb } from "./database.js";
|
|
9
|
-
import {
|
|
9
|
+
import { type HistoryWindow, historyWindow } from "./history-window.js";
|
|
10
|
+
import { generateId, mappedItemRef, now, parsePersistedJson } from "./repo-helpers.js";
|
|
10
11
|
import * as s from "./schema.js";
|
|
11
12
|
|
|
12
13
|
function map(row: typeof s.turnStartRecords.$inferSelect): TurnStartRecord {
|
|
@@ -22,6 +23,7 @@ function map(row: typeof s.turnStartRecords.$inferSelect): TurnStartRecord {
|
|
|
22
23
|
? parsePersistedJson(row.continuationJson, "turn start continuation")
|
|
23
24
|
: null,
|
|
24
25
|
state: parsePersistedJson<TurnStartRecordState>(row.stateJson, "turn start state"),
|
|
26
|
+
iteration: mappedItemRef(row),
|
|
25
27
|
createdAt: row.createdAt,
|
|
26
28
|
updatedAt: row.updatedAt,
|
|
27
29
|
};
|
|
@@ -51,6 +53,9 @@ export function createTurnStartRecordRepo(db: LeitwerkDb) {
|
|
|
51
53
|
stateJson: JSON.stringify(input.state),
|
|
52
54
|
createdAt: ts,
|
|
53
55
|
updatedAt: ts,
|
|
56
|
+
mappedRunId: input.iteration?.runId ?? null,
|
|
57
|
+
mappedItemKey: input.iteration?.itemKey ?? null,
|
|
58
|
+
mappedItemIndex: input.iteration?.itemIndex ?? null,
|
|
54
59
|
};
|
|
55
60
|
db.insert(s.turnStartRecords).values(value).run();
|
|
56
61
|
return map(value);
|
|
@@ -61,11 +66,16 @@ export function createTurnStartRecordRepo(db: LeitwerkDb) {
|
|
|
61
66
|
return value ? map(value) : null;
|
|
62
67
|
},
|
|
63
68
|
/** @internal */
|
|
64
|
-
listByInstance(instanceId: string): TurnStartRecord[] {
|
|
69
|
+
listByInstance(instanceId: string, window?: HistoryWindow): TurnStartRecord[] {
|
|
65
70
|
return db
|
|
66
71
|
.select()
|
|
67
72
|
.from(s.turnStartRecords)
|
|
68
|
-
.where(
|
|
73
|
+
.where(
|
|
74
|
+
and(
|
|
75
|
+
eq(s.turnStartRecords.instanceId, instanceId),
|
|
76
|
+
historyWindow(s.turnStartRecords.createdAt, window),
|
|
77
|
+
),
|
|
78
|
+
)
|
|
69
79
|
.all()
|
|
70
80
|
.map(map);
|
|
71
81
|
},
|
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
PrimaryPathUiSnapshot,
|
|
4
4
|
TurnTracePreview,
|
|
5
5
|
} from "@leitwerk-dev/protocol";
|
|
6
|
-
import { eq } from "drizzle-orm";
|
|
6
|
+
import { and, eq, inArray } from "drizzle-orm";
|
|
7
7
|
import type { LeitwerkDb } from "./database.js";
|
|
8
8
|
import { sessionSummaries, turnSummaries } from "./schema.js";
|
|
9
9
|
|
|
@@ -60,12 +60,21 @@ export function createTurnSummaryRepo(db: LeitwerkDb) {
|
|
|
60
60
|
.run();
|
|
61
61
|
},
|
|
62
62
|
/** @internal */
|
|
63
|
-
listByInstance(
|
|
63
|
+
listByInstance(
|
|
64
|
+
instanceId: string,
|
|
65
|
+
turnRecordIds?: string[],
|
|
66
|
+
): Record<string, CompactTurnSummary> {
|
|
67
|
+
if (turnRecordIds?.length === 0) return {};
|
|
64
68
|
return Object.fromEntries(
|
|
65
69
|
db
|
|
66
70
|
.select()
|
|
67
71
|
.from(turnSummaries)
|
|
68
|
-
.where(
|
|
72
|
+
.where(
|
|
73
|
+
and(
|
|
74
|
+
eq(turnSummaries.instanceId, instanceId),
|
|
75
|
+
turnRecordIds ? inArray(turnSummaries.turnRecordId, turnRecordIds) : undefined,
|
|
76
|
+
),
|
|
77
|
+
)
|
|
69
78
|
.all()
|
|
70
79
|
.map((row) => [row.turnRecordId, JSON.parse(row.summaryJson) as CompactTurnSummary]),
|
|
71
80
|
);
|
|
@@ -2,6 +2,7 @@ import type { WorkerBootstrapReceipt, WorkerLease, WorkerState } from "@leitwerk
|
|
|
2
2
|
import { and, asc, eq, isNull } from "drizzle-orm";
|
|
3
3
|
import type { SQLiteUpdateSetSource } from "drizzle-orm/sqlite-core";
|
|
4
4
|
import type { LeitwerkDb } from "./database.js";
|
|
5
|
+
import { type HistoryWindow, historyWindow } from "./history-window.js";
|
|
5
6
|
import { generateId, now } from "./repo-helpers.js";
|
|
6
7
|
import * as s from "./schema.js";
|
|
7
8
|
|
|
@@ -120,11 +121,16 @@ export function createWorkerLeaseRepo(db: LeitwerkDb) {
|
|
|
120
121
|
},
|
|
121
122
|
|
|
122
123
|
/** @internal */
|
|
123
|
-
listByInstance(instanceId: string): WorkerLease[] {
|
|
124
|
+
listByInstance(instanceId: string, window?: HistoryWindow): WorkerLease[] {
|
|
124
125
|
return db
|
|
125
126
|
.select()
|
|
126
127
|
.from(s.workerLeases)
|
|
127
|
-
.where(
|
|
128
|
+
.where(
|
|
129
|
+
and(
|
|
130
|
+
eq(s.workerLeases.instanceId, instanceId),
|
|
131
|
+
historyWindow(s.workerLeases.startedAt, window),
|
|
132
|
+
),
|
|
133
|
+
)
|
|
128
134
|
.orderBy(asc(s.workerLeases.startedAt), asc(s.workerLeases.id))
|
|
129
135
|
.all()
|
|
130
136
|
.map(rowToWorkerLease);
|
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
isLlmTurnDefinition,
|
|
10
10
|
type OutcomeToolParameterSpec,
|
|
11
11
|
type TurnDefinition,
|
|
12
|
+
validateOutcomeParameters,
|
|
12
13
|
} from "@leitwerk-dev/process-sdk";
|
|
13
|
-
import * as v from "valibot";
|
|
14
14
|
import { isTurnAvailableForProcessGraph, type ProcessGraphRegistry } from "../process-graph.js";
|
|
15
15
|
|
|
16
16
|
interface OutcomeToolValidationContract {
|
|
@@ -35,105 +35,6 @@ function validationFailure(code: string, message: string): OutcomeValidationFail
|
|
|
35
35
|
return { ok: false, code, message };
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function toSnakeCase(value: string): string {
|
|
39
|
-
return value
|
|
40
|
-
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
41
|
-
.replace(/[^a-zA-Z0-9]+/g, "_")
|
|
42
|
-
.replace(/^_+|_+$/g, "")
|
|
43
|
-
.toLowerCase();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function invalidParameterCode(key: string, spec: OutcomeToolParameterSpec): string {
|
|
47
|
-
return spec.invalidErrorCode ?? `invalid_${toSnakeCase(key)}`;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function requiredParameterError(
|
|
51
|
-
turnId: string,
|
|
52
|
-
outcome: string,
|
|
53
|
-
key: string,
|
|
54
|
-
spec: OutcomeToolParameterSpec,
|
|
55
|
-
): OutcomeValidationFailure {
|
|
56
|
-
return validationFailure(
|
|
57
|
-
spec.requiredErrorCode ?? `${toSnakeCase(key)}_required`,
|
|
58
|
-
`${turnId}.${outcome} requires a non-empty ${key}`,
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function minItemsParameterError(
|
|
63
|
-
turnId: string,
|
|
64
|
-
outcome: string,
|
|
65
|
-
key: string,
|
|
66
|
-
spec: OutcomeToolParameterSpec,
|
|
67
|
-
): OutcomeValidationFailure {
|
|
68
|
-
return validationFailure(
|
|
69
|
-
spec.minItemsErrorCode ?? spec.requiredErrorCode ?? `${toSnakeCase(key)}_required`,
|
|
70
|
-
`${turnId}.${outcome} requires at least ${spec.minItems ?? 0} item(s) for ${key}`,
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function invalidParameterError(
|
|
75
|
-
turnId: string,
|
|
76
|
-
outcome: string,
|
|
77
|
-
key: string,
|
|
78
|
-
spec: OutcomeToolParameterSpec,
|
|
79
|
-
expected: string,
|
|
80
|
-
): OutcomeValidationFailure {
|
|
81
|
-
return validationFailure(
|
|
82
|
-
invalidParameterCode(key, spec),
|
|
83
|
-
`${turnId}.${outcome} expects ${key} to be ${expected}`,
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function minimumParameterError(
|
|
88
|
-
turnId: string,
|
|
89
|
-
outcome: string,
|
|
90
|
-
key: string,
|
|
91
|
-
spec: OutcomeToolParameterSpec,
|
|
92
|
-
): OutcomeValidationFailure {
|
|
93
|
-
return validationFailure(
|
|
94
|
-
spec.minimumErrorCode ?? invalidParameterCode(key, spec),
|
|
95
|
-
`${turnId}.${outcome} expects ${key} to be >= ${spec.minimum ?? 0}`,
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
type OutcomeParameterSchema = v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>;
|
|
100
|
-
|
|
101
|
-
const scalarParameters = {
|
|
102
|
-
string: { schema: v.string(), label: "a string", plural: "strings" },
|
|
103
|
-
number: {
|
|
104
|
-
schema: v.pipe(v.number(), v.finite()),
|
|
105
|
-
label: "a finite number",
|
|
106
|
-
plural: "finite numbers",
|
|
107
|
-
},
|
|
108
|
-
boolean: { schema: v.boolean(), label: "a boolean", plural: "booleans" },
|
|
109
|
-
object: {
|
|
110
|
-
schema: v.custom<Record<string, unknown>>(isJsonObject, "Expected an object"),
|
|
111
|
-
label: "an object",
|
|
112
|
-
plural: "objects",
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
function compileOutcomeParameterSchema(spec: OutcomeToolParameterSpec): OutcomeParameterSchema {
|
|
117
|
-
return spec.type === "array"
|
|
118
|
-
? v.array(scalarParameters[spec.items?.type ?? "string"].schema)
|
|
119
|
-
: scalarParameters[spec.type].schema;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function effectiveArrayItemCount(
|
|
123
|
-
spec: OutcomeToolParameterSpec,
|
|
124
|
-
value: readonly unknown[],
|
|
125
|
-
): number {
|
|
126
|
-
return (spec.items?.type ?? "string") === "string"
|
|
127
|
-
? normalizeStringArray(value).length
|
|
128
|
-
: value.length;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function expectedParameterLabel(spec: OutcomeToolParameterSpec): string {
|
|
132
|
-
return spec.type === "array"
|
|
133
|
-
? `an array of ${scalarParameters[spec.items?.type ?? "string"].plural}`
|
|
134
|
-
: scalarParameters[spec.type].label;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
38
|
function jsonValuesEqual(left: unknown, right: unknown): boolean {
|
|
138
39
|
if (left === right) {
|
|
139
40
|
return true;
|
|
@@ -254,11 +155,7 @@ function validateTurnEndResultParams(
|
|
|
254
155
|
params: Record<string, unknown>,
|
|
255
156
|
expectedParams: Record<string, unknown>,
|
|
256
157
|
): OutcomeValidationFailure | null {
|
|
257
|
-
|
|
258
|
-
v.custom((value) => jsonValuesEqual(value, expectedParams)),
|
|
259
|
-
params,
|
|
260
|
-
);
|
|
261
|
-
if (parsed.success) {
|
|
158
|
+
if (jsonValuesEqual(params, expectedParams)) {
|
|
262
159
|
return null;
|
|
263
160
|
}
|
|
264
161
|
return validationFailure(
|
|
@@ -274,50 +171,8 @@ function validateDeclaredOutcomeParameters(
|
|
|
274
171
|
parameterSpecs: Record<string, OutcomeToolParameterSpec>,
|
|
275
172
|
knownProjectKeys?: ReadonlySet<string>,
|
|
276
173
|
): OutcomeValidationFailure | null {
|
|
277
|
-
const
|
|
278
|
-
if (
|
|
279
|
-
return validationFailure(
|
|
280
|
-
"unknown_parameter",
|
|
281
|
-
`${turnId}.${outcome} received unknown parameter(s): ${unknownKeys.join(", ")}`,
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
for (const [key, spec] of Object.entries(parameterSpecs)) {
|
|
286
|
-
const value = params[key];
|
|
287
|
-
if (value === undefined) {
|
|
288
|
-
if (spec.required) {
|
|
289
|
-
return requiredParameterError(turnId, outcome, key, spec);
|
|
290
|
-
}
|
|
291
|
-
continue;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (!v.safeParse(compileOutcomeParameterSchema(spec), value).success) {
|
|
295
|
-
return invalidParameterError(turnId, outcome, key, spec, expectedParameterLabel(spec));
|
|
296
|
-
}
|
|
297
|
-
if (spec.type === "string" && trimString(value as string) === "" && spec.required) {
|
|
298
|
-
return requiredParameterError(turnId, outcome, key, spec);
|
|
299
|
-
}
|
|
300
|
-
if (spec.type === "number" && spec.minimum !== undefined && (value as number) < spec.minimum) {
|
|
301
|
-
return minimumParameterError(turnId, outcome, key, spec);
|
|
302
|
-
}
|
|
303
|
-
if (
|
|
304
|
-
spec.enum &&
|
|
305
|
-
spec.enum.length > 0 &&
|
|
306
|
-
typeof value === "string" &&
|
|
307
|
-
!spec.enum.includes(value)
|
|
308
|
-
) {
|
|
309
|
-
return invalidParameterError(turnId, outcome, key, spec, `one of: ${spec.enum.join(", ")}`);
|
|
310
|
-
}
|
|
311
|
-
if (spec.type === "array") {
|
|
312
|
-
const effectiveItemCount = effectiveArrayItemCount(spec, value as readonly unknown[]);
|
|
313
|
-
if (spec.required && effectiveItemCount === 0) {
|
|
314
|
-
return requiredParameterError(turnId, outcome, key, spec);
|
|
315
|
-
}
|
|
316
|
-
if (spec.minItems !== undefined && effectiveItemCount < spec.minItems) {
|
|
317
|
-
return minItemsParameterError(turnId, outcome, key, spec);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
174
|
+
const [issue] = validateOutcomeParameters(parameterSpecs, params);
|
|
175
|
+
if (issue) return validationFailure(issue.code, `${turnId}.${outcome}: ${issue.message}`);
|
|
321
176
|
const projectError = validateChangedProjects(params.changedProjects, knownProjectKeys);
|
|
322
177
|
if (projectError) {
|
|
323
178
|
return projectError;
|
|
@@ -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
|