@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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
isUnknownRecord,
|
|
2
3
|
normalizeLaunchModelConfigInput,
|
|
3
4
|
type ProcessEvent,
|
|
4
5
|
type ProcessInstance,
|
|
@@ -9,7 +10,6 @@ import {
|
|
|
9
10
|
import type { ProcessModelSelectionServiceLike } from "@leitwerk-dev/process-sdk";
|
|
10
11
|
import {
|
|
11
12
|
findUiLauncherById,
|
|
12
|
-
isLlmTurnDefinition,
|
|
13
13
|
type OutcomeToolParameterSpec,
|
|
14
14
|
type ProcessLauncherService,
|
|
15
15
|
type ProcessLaunchPlanServiceLike,
|
|
@@ -20,11 +20,7 @@ import {
|
|
|
20
20
|
resolveProcessPiConfig,
|
|
21
21
|
resolveTurnActiveToolNames,
|
|
22
22
|
} from "@leitwerk-dev/process-sdk/pi-config";
|
|
23
|
-
import {
|
|
24
|
-
parseActionRequestBody,
|
|
25
|
-
parseLauncherInputJson,
|
|
26
|
-
parseLauncherRequestBody,
|
|
27
|
-
} from "@leitwerk-dev/protocol";
|
|
23
|
+
import { parseLauncherInputJson, parseLauncherRequestBody } from "@leitwerk-dev/protocol";
|
|
28
24
|
import type {
|
|
29
25
|
LauncherModelConfigSchema,
|
|
30
26
|
LauncherMutationResponseBody,
|
|
@@ -44,7 +40,6 @@ import type {
|
|
|
44
40
|
ActionMutationOutcome,
|
|
45
41
|
FutureExecutionLifecycle,
|
|
46
42
|
LaunchMutationOutcome,
|
|
47
|
-
NormalizedScheduledActionInput,
|
|
48
43
|
NormalizedScheduledLaunchInput,
|
|
49
44
|
} from "../future-execution/index.js";
|
|
50
45
|
import {
|
|
@@ -93,6 +88,7 @@ export interface RouteDeps
|
|
|
93
88
|
| "inputs"
|
|
94
89
|
| "events"
|
|
95
90
|
| "turnSummaries"
|
|
91
|
+
| "executionInspections"
|
|
96
92
|
| "futureExecutions"
|
|
97
93
|
| "skills"
|
|
98
94
|
| "processSkills"
|
|
@@ -109,6 +105,12 @@ export interface RouteDeps
|
|
|
109
105
|
| "transaction"
|
|
110
106
|
> {
|
|
111
107
|
/** @internal */
|
|
108
|
+
scopedSettingsService?: import("../scoped-settings-service.js").ScopedSettingsService;
|
|
109
|
+
/** @internal */
|
|
110
|
+
topicWiki?: RepositoryBundle["topicWiki"];
|
|
111
|
+
/** @internal */
|
|
112
|
+
onSettingsChanged?: () => Promise<void>;
|
|
113
|
+
/** @internal */
|
|
112
114
|
mappedRuns?: RepositoryBundle["mappedRuns"];
|
|
113
115
|
/** @internal */
|
|
114
116
|
startupObservations?: RepositoryBundle["startupObservations"];
|
|
@@ -177,6 +179,16 @@ export function routeConfig(deps: Pick<RouteDeps, "config">): LeitwerkConfig {
|
|
|
177
179
|
return deps.config ?? getDefaultConfig();
|
|
178
180
|
}
|
|
179
181
|
|
|
182
|
+
function safeLaunchValue(value: unknown): unknown {
|
|
183
|
+
if (typeof value === "string") return redactCredentialBearingAbsoluteUrl(value);
|
|
184
|
+
if (Array.isArray(value)) return value.map(safeLaunchValue);
|
|
185
|
+
if (value && typeof value === "object")
|
|
186
|
+
return Object.fromEntries(
|
|
187
|
+
Object.entries(value).map(([key, item]) => [key, safeLaunchValue(item)]),
|
|
188
|
+
);
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
191
|
+
|
|
180
192
|
function formatLaunchParameterValue(value: unknown): string | null {
|
|
181
193
|
if (value === undefined || value === null) {
|
|
182
194
|
return null;
|
|
@@ -185,37 +197,31 @@ function formatLaunchParameterValue(value: unknown): string | null {
|
|
|
185
197
|
const normalized = redactCredentialBearingAbsoluteUrl(value.trim());
|
|
186
198
|
return normalized === "" ? null : normalized;
|
|
187
199
|
}
|
|
188
|
-
return
|
|
200
|
+
return typeof value === "object"
|
|
201
|
+
? JSON.stringify(safeLaunchValue(value), null, 2)
|
|
202
|
+
: String(value);
|
|
189
203
|
}
|
|
190
204
|
|
|
191
205
|
function buildLaunchParameterRows(
|
|
192
206
|
params: Record<string, unknown>,
|
|
193
207
|
launcher: ReturnType<ProcessLauncherService["listUiLaunchers"]>[number] | null,
|
|
194
208
|
): ProcessLaunchConfigurationView["parameters"] {
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
rows.push({
|
|
213
|
-
fieldId,
|
|
214
|
-
label: fieldId,
|
|
215
|
-
value: formatLaunchParameterValue(params[fieldId]),
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
return rows;
|
|
209
|
+
const fields = (launcher?.launchConfigSchema.fields ?? []).filter((field) =>
|
|
210
|
+
Object.hasOwn(params, field.id),
|
|
211
|
+
);
|
|
212
|
+
const declared = new Set(fields.map((field) => field.id));
|
|
213
|
+
return [
|
|
214
|
+
...fields,
|
|
215
|
+
...Object.keys(params)
|
|
216
|
+
.sort((left, right) => left.localeCompare(right))
|
|
217
|
+
.filter((id) => !declared.has(id))
|
|
218
|
+
.map((id) => ({ id, label: id })),
|
|
219
|
+
].map(({ id, label }) => ({
|
|
220
|
+
fieldId: id,
|
|
221
|
+
label: label || id,
|
|
222
|
+
value: formatLaunchParameterValue(params[id]),
|
|
223
|
+
rawValue: safeLaunchValue(params[id]),
|
|
224
|
+
}));
|
|
219
225
|
}
|
|
220
226
|
|
|
221
227
|
export function buildProcessLaunchConfigurationView(
|
|
@@ -279,18 +285,57 @@ export function buildProcessRunDetailsView(
|
|
|
279
285
|
const turns: ProcessRunTurnView[] = [];
|
|
280
286
|
|
|
281
287
|
for (const [turnId, turnContract] of contract.turns) {
|
|
282
|
-
if (turnContract.turnType !== "llm") {
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
288
|
const turnDef = deps.processActionRegistry?.getTurnDefinition(process.processId, turnId);
|
|
286
|
-
if (!turnDef
|
|
289
|
+
if (!turnDef) continue;
|
|
290
|
+
const common = {
|
|
291
|
+
turnId,
|
|
292
|
+
description: turnDef.description,
|
|
293
|
+
consumedProducts: [...(turnContract.consumedProducts ?? [])],
|
|
294
|
+
};
|
|
295
|
+
if (turnDef.kind !== "llm") {
|
|
296
|
+
const actions =
|
|
297
|
+
turnDef.kind === "human"
|
|
298
|
+
? Object.entries(turnDef.actions).map(([name, action]) => ({
|
|
299
|
+
name,
|
|
300
|
+
label: action.label,
|
|
301
|
+
description: action.description,
|
|
302
|
+
form: action.form,
|
|
303
|
+
}))
|
|
304
|
+
: [];
|
|
305
|
+
const outcomes =
|
|
306
|
+
turnDef.kind === "automatic"
|
|
307
|
+
? Object.entries(turnDef.outcomes ?? {}).map(([name, outcome]) => ({
|
|
308
|
+
name,
|
|
309
|
+
description: outcome?.description,
|
|
310
|
+
parameters: outcome?.parameters,
|
|
311
|
+
}))
|
|
312
|
+
: [];
|
|
313
|
+
turns.push({
|
|
314
|
+
...common,
|
|
315
|
+
pathType: "not_applicable",
|
|
316
|
+
publishedProducts: [...(turnContract.publishedProducts ?? [])],
|
|
317
|
+
activePiToolNames: [],
|
|
318
|
+
outcomeActions: [],
|
|
319
|
+
integrationToolNames: turnDef.kind === "automatic" ? (turnDef.integrationTools ?? []) : [],
|
|
320
|
+
definitionContract: {
|
|
321
|
+
kind: turnDef.kind,
|
|
322
|
+
actions,
|
|
323
|
+
outcomes,
|
|
324
|
+
reviewProduct: turnDef.kind === "human" ? turnDef.reviewProduct : undefined,
|
|
325
|
+
},
|
|
326
|
+
});
|
|
287
327
|
continue;
|
|
288
328
|
}
|
|
289
329
|
turns.push({
|
|
290
|
-
|
|
291
|
-
description: turnDef.description,
|
|
330
|
+
...common,
|
|
292
331
|
pathType: turnDef.branchType,
|
|
293
|
-
|
|
332
|
+
definitionContract: {
|
|
333
|
+
kind: turnDef.kind,
|
|
334
|
+
context: turnDef.context,
|
|
335
|
+
modelPurpose: turnDef.modelPurpose ?? null,
|
|
336
|
+
askQuestions: turnDef.askQuestions ?? false,
|
|
337
|
+
},
|
|
338
|
+
integrationToolNames: turnDef.integrationTools ?? [],
|
|
294
339
|
publishedProducts: [
|
|
295
340
|
...new Set(
|
|
296
341
|
[turnContract.publishedProduct, ...(turnContract.publishedProducts ?? [])].filter(
|
|
@@ -318,7 +363,7 @@ export function buildProcessRunDetailsView(
|
|
|
318
363
|
Object.entries(toolSpec.parameters) as [string, OutcomeToolParameterSpec][]
|
|
319
364
|
).map(([parameterName, parameterSpec]) => ({
|
|
320
365
|
name: parameterName,
|
|
321
|
-
type: parameterSpec.type,
|
|
366
|
+
type: parameterSpec.type ?? "union",
|
|
322
367
|
description: parameterSpec.description,
|
|
323
368
|
required: parameterSpec.required === true,
|
|
324
369
|
})),
|
|
@@ -370,75 +415,71 @@ export interface NormalizedRecoveryModelRequest {
|
|
|
370
415
|
providerOptions?: Record<string, string>;
|
|
371
416
|
}
|
|
372
417
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
418
|
+
const modelRequestEntries = {
|
|
419
|
+
nextTurnModelProfileId: v.exactOptional(
|
|
420
|
+
v.pipe(
|
|
421
|
+
v.nullish(v.string("nextTurnModelProfileId must be a string or null")),
|
|
422
|
+
v.transform((value) => value?.trim() || null),
|
|
423
|
+
),
|
|
424
|
+
),
|
|
425
|
+
providerOptions: v.exactOptional(
|
|
426
|
+
v.pipe(
|
|
427
|
+
v.custom<Record<string, unknown>>(
|
|
428
|
+
isUnknownRecord,
|
|
429
|
+
"providerOptions must be an object of string values",
|
|
430
|
+
),
|
|
431
|
+
v.maxEntries(64, "providerOptions has too many fields"),
|
|
432
|
+
v.guard(
|
|
433
|
+
(options): options is Record<string, string> =>
|
|
434
|
+
Object.entries(options).every(
|
|
435
|
+
([key, value]) =>
|
|
436
|
+
key.length > 0 &&
|
|
437
|
+
key.length <= 128 &&
|
|
438
|
+
typeof value === "string" &&
|
|
439
|
+
value.length <= 4096,
|
|
440
|
+
),
|
|
441
|
+
"providerOptions contains an invalid field",
|
|
442
|
+
),
|
|
443
|
+
v.transform((options) => Object.assign({}, options)),
|
|
444
|
+
),
|
|
445
|
+
),
|
|
446
|
+
};
|
|
447
|
+
const promptSchema = v.exactOptional(
|
|
448
|
+
v.pipe(
|
|
449
|
+
v.nullish(v.string("prompt must be a string or null")),
|
|
450
|
+
v.transform((value) => value ?? null),
|
|
451
|
+
),
|
|
452
|
+
);
|
|
390
453
|
|
|
391
454
|
function parseModelRequest(
|
|
392
455
|
value: unknown,
|
|
393
|
-
|
|
394
|
-
):
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
typeof modelProfileId !== "string"
|
|
421
|
-
) {
|
|
422
|
-
return { ok: false, error: "nextTurnModelProfileId must be a string or null" };
|
|
423
|
-
}
|
|
424
|
-
const providerOptionsProvided = Object.hasOwn(body, "providerOptions");
|
|
425
|
-
const providerOptions = providerOptionsProvided
|
|
426
|
-
? normalizeProviderOptions(body.providerOptions)
|
|
427
|
-
: ({ ok: true, value: {} } as const);
|
|
428
|
-
if (!providerOptions.ok) return providerOptions;
|
|
429
|
-
return {
|
|
430
|
-
ok: true,
|
|
431
|
-
body,
|
|
432
|
-
request: {
|
|
433
|
-
...(nextTurnModelProfileIdProvided
|
|
434
|
-
? {
|
|
435
|
-
nextTurnModelProfileId:
|
|
436
|
-
typeof modelProfileId === "string" ? modelProfileId.trim() || null : null,
|
|
437
|
-
}
|
|
438
|
-
: {}),
|
|
439
|
-
...(providerOptionsProvided ? { providerOptions: providerOptions.value } : {}),
|
|
440
|
-
},
|
|
441
|
-
};
|
|
456
|
+
requestName: "continue" | "recovery",
|
|
457
|
+
): { ok: true; request: NormalizedContinueRequest } | { ok: false; error: string } {
|
|
458
|
+
const schema =
|
|
459
|
+
requestName === "continue"
|
|
460
|
+
? v.object({ ...modelRequestEntries, prompt: promptSchema })
|
|
461
|
+
: v.object(modelRequestEntries);
|
|
462
|
+
const shape =
|
|
463
|
+
requestName === "continue"
|
|
464
|
+
? "{ prompt, nextTurnModelProfileId, providerOptions }"
|
|
465
|
+
: "{ nextTurnModelProfileId, providerOptions }";
|
|
466
|
+
const parsed = v.safeParse(
|
|
467
|
+
v.pipe(
|
|
468
|
+
v.unknown(),
|
|
469
|
+
v.check(isUnknownRecord, `${requestName} request body must be an object`),
|
|
470
|
+
unknownRecordSchema,
|
|
471
|
+
v.check(
|
|
472
|
+
(body) => Object.keys(body).every((key) => Object.hasOwn(schema.entries, key)),
|
|
473
|
+
`${requestName} request body must use ${shape}`,
|
|
474
|
+
),
|
|
475
|
+
schema,
|
|
476
|
+
),
|
|
477
|
+
value ?? {},
|
|
478
|
+
{ abortEarly: true },
|
|
479
|
+
);
|
|
480
|
+
return parsed.success
|
|
481
|
+
? { ok: true, request: parsed.output }
|
|
482
|
+
: { ok: false, error: parsed.issues[0].message };
|
|
442
483
|
}
|
|
443
484
|
|
|
444
485
|
export function normalizeLauncherRequest(value: unknown):
|
|
@@ -467,25 +508,6 @@ export function normalizeLauncherRequest(value: unknown):
|
|
|
467
508
|
};
|
|
468
509
|
}
|
|
469
510
|
|
|
470
|
-
export function normalizeActionRequest(value: unknown):
|
|
471
|
-
| {
|
|
472
|
-
ok: true;
|
|
473
|
-
request: NormalizedScheduledActionInput;
|
|
474
|
-
}
|
|
475
|
-
| {
|
|
476
|
-
ok: false;
|
|
477
|
-
error: string;
|
|
478
|
-
} {
|
|
479
|
-
const parsed = parseActionRequestBody(value);
|
|
480
|
-
if (!parsed.ok) {
|
|
481
|
-
return { ok: false, error: parsed.error };
|
|
482
|
-
}
|
|
483
|
-
return {
|
|
484
|
-
ok: true,
|
|
485
|
-
request: parsed.value,
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
|
|
489
511
|
function isScheduleRequestError(error: string): boolean {
|
|
490
512
|
return (
|
|
491
513
|
error === "schedule must be an object" ||
|
|
@@ -512,38 +534,13 @@ export function sendActionRequestNormalizationError(reply: FastifyReply, error:
|
|
|
512
534
|
export function normalizeContinueRequest(
|
|
513
535
|
value: unknown,
|
|
514
536
|
): { ok: true; request: NormalizedContinueRequest } | { ok: false; error: string } {
|
|
515
|
-
|
|
516
|
-
requestName: "continue",
|
|
517
|
-
allowedKeys: ["prompt", "nextTurnModelProfileId", "providerOptions"],
|
|
518
|
-
expectedShape: "{ prompt, nextTurnModelProfileId, providerOptions }",
|
|
519
|
-
});
|
|
520
|
-
if (!parsed.ok) return parsed;
|
|
521
|
-
if (
|
|
522
|
-
parsed.body.prompt !== undefined &&
|
|
523
|
-
parsed.body.prompt !== null &&
|
|
524
|
-
typeof parsed.body.prompt !== "string"
|
|
525
|
-
) {
|
|
526
|
-
return { ok: false, error: "prompt must be a string or null" };
|
|
527
|
-
}
|
|
528
|
-
const promptProvided = Object.hasOwn(parsed.body, "prompt");
|
|
529
|
-
return {
|
|
530
|
-
ok: true,
|
|
531
|
-
request: {
|
|
532
|
-
...parsed.request,
|
|
533
|
-
...(promptProvided ? { prompt: parsed.body.prompt ?? null } : {}),
|
|
534
|
-
},
|
|
535
|
-
};
|
|
537
|
+
return parseModelRequest(value, "continue");
|
|
536
538
|
}
|
|
537
539
|
|
|
538
540
|
export function normalizeRecoveryModelRequest(
|
|
539
541
|
value: unknown,
|
|
540
542
|
): { ok: true; request: NormalizedRecoveryModelRequest } | { ok: false; error: string } {
|
|
541
|
-
|
|
542
|
-
requestName: "recovery",
|
|
543
|
-
allowedKeys: ["nextTurnModelProfileId", "providerOptions"],
|
|
544
|
-
expectedShape: "{ nextTurnModelProfileId, providerOptions }",
|
|
545
|
-
});
|
|
546
|
-
return parsed.ok ? { ok: true, request: parsed.request } : parsed;
|
|
543
|
+
return parseModelRequest(value, "recovery");
|
|
547
544
|
}
|
|
548
545
|
|
|
549
546
|
export function buildLauncherModelConfigSchema(
|
|
@@ -687,16 +684,10 @@ export function sendScheduledActionMutationResponse(
|
|
|
687
684
|
export function mergeProcessEventWindowsAscending(
|
|
688
685
|
windows: readonly (readonly ProcessEvent[])[],
|
|
689
686
|
): ProcessEvent[] {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
return [...eventsById.values()].sort((left, right) => {
|
|
697
|
-
const createdAtComparison = left.createdAt.localeCompare(right.createdAt);
|
|
698
|
-
return createdAtComparison !== 0 ? createdAtComparison : left.id.localeCompare(right.id);
|
|
699
|
-
});
|
|
687
|
+
return [...new Map(windows.flat().map((event) => [event.id, event])).values()].sort(
|
|
688
|
+
(left, right) =>
|
|
689
|
+
left.createdAt.localeCompare(right.createdAt) || left.id.localeCompare(right.id),
|
|
690
|
+
);
|
|
700
691
|
}
|
|
701
692
|
|
|
702
693
|
export { getSelectedTurnSummaryForProcess };
|
package/src/routes/processes.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { registerFutureExecutionRoutes } from "./future-executions.js";
|
|
|
3
3
|
import { registerLauncherRoutes } from "./launchers.js";
|
|
4
4
|
import { registerProcessActionRoutes } from "./process-actions.js";
|
|
5
5
|
import { registerProcessDetailRoutes } from "./process-detail.js";
|
|
6
|
+
import { registerProcessModelConfigRoutes } from "./process-model-config.js";
|
|
6
7
|
import { registerProcessQuestionRoutes } from "./process-questions.js";
|
|
7
8
|
import type { RouteDeps } from "./process-route-helpers.js";
|
|
8
9
|
import { registerProcessSessionRoutes } from "./process-session.js";
|
|
@@ -12,6 +13,7 @@ export type { RouteDeps } from "./process-route-helpers.js";
|
|
|
12
13
|
|
|
13
14
|
export function registerProcessRoutes(app: FastifyInstance, deps: RouteDeps) {
|
|
14
15
|
registerProcessDetailRoutes(app, deps);
|
|
16
|
+
registerProcessModelConfigRoutes(app, deps);
|
|
15
17
|
registerLauncherRoutes(app, deps, deps.futureExecutionLifecycle);
|
|
16
18
|
registerFutureExecutionRoutes(app, deps, deps.futureExecutionLifecycle);
|
|
17
19
|
registerProcessActionRoutes(app, deps, deps.futureExecutionLifecycle);
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { FastifyInstance, FastifyRequest } from "fastify";
|
|
2
|
+
import { actorForRequest } from "../auth/fastify-auth.js";
|
|
3
|
+
import type { RepositoryBundle } from "../db/repositories.js";
|
|
4
|
+
import type { ProcessOperationCoordinator } from "../process-operation-coordinator.js";
|
|
5
|
+
import type { ScopedSettingsService } from "../scoped-settings-service.js";
|
|
6
|
+
import { SettingsError } from "../scoped-settings-service.js";
|
|
7
|
+
|
|
8
|
+
type Change = {
|
|
9
|
+
subjectId: string;
|
|
10
|
+
key: string;
|
|
11
|
+
value?: unknown;
|
|
12
|
+
mode?: "replace";
|
|
13
|
+
reset?: boolean;
|
|
14
|
+
expectedRevision: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function parseChange(value: unknown): Change {
|
|
18
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
19
|
+
throw new SettingsError("Expected a settings change", 400);
|
|
20
|
+
const raw = value as Record<string, unknown>;
|
|
21
|
+
if (
|
|
22
|
+
typeof raw.subjectId !== "string" ||
|
|
23
|
+
typeof raw.key !== "string" ||
|
|
24
|
+
!Number.isSafeInteger(raw.expectedRevision) ||
|
|
25
|
+
Number(raw.expectedRevision) < 0 ||
|
|
26
|
+
(raw.mode !== undefined && raw.mode !== "replace") ||
|
|
27
|
+
(raw.reset !== undefined && typeof raw.reset !== "boolean") ||
|
|
28
|
+
(!raw.reset && !Object.hasOwn(raw, "value"))
|
|
29
|
+
)
|
|
30
|
+
throw new SettingsError(
|
|
31
|
+
"Provide subjectId, key, value, and expectedRevision; mode must be replace",
|
|
32
|
+
400,
|
|
33
|
+
);
|
|
34
|
+
return raw as Change;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @internal */
|
|
38
|
+
export function registerSettingsRoutes(
|
|
39
|
+
app: FastifyInstance,
|
|
40
|
+
settings: ScopedSettingsService,
|
|
41
|
+
repos: Pick<RepositoryBundle, "processes" | "turnStarts" | "projects" | "events"> & {
|
|
42
|
+
processOperations: ProcessOperationCoordinator;
|
|
43
|
+
broadcaster: import("../ws/broadcast.js").Broadcaster;
|
|
44
|
+
onSettingsChanged?: () => Promise<void>;
|
|
45
|
+
},
|
|
46
|
+
) {
|
|
47
|
+
function normalizedChange(request: FastifyRequest) {
|
|
48
|
+
const change = parseChange(request.body);
|
|
49
|
+
return {
|
|
50
|
+
...change,
|
|
51
|
+
value: change.value,
|
|
52
|
+
reset: change.reset ?? false,
|
|
53
|
+
actor: actorForRequest(request),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
app.get("/api/settings/definitions", async () => ({ definitions: settings.definitions() }));
|
|
57
|
+
app.get("/api/settings/scopes", async () => settings.listScopes());
|
|
58
|
+
app.get<{ Querystring: { scopeType?: string } }>("/api/settings/overview", async (request) => {
|
|
59
|
+
if (!request.query.scopeType) throw new SettingsError("Provide scopeType", 400);
|
|
60
|
+
return settings.overview(request.query.scopeType);
|
|
61
|
+
});
|
|
62
|
+
app.post("/api/settings/scopes/refresh", async () => {
|
|
63
|
+
const scopes = await settings.refresh();
|
|
64
|
+
await repos.onSettingsChanged?.();
|
|
65
|
+
repos.broadcaster.sendDurable("settings.updated", { subjectId: "instance" });
|
|
66
|
+
return scopes;
|
|
67
|
+
});
|
|
68
|
+
app.get<{ Querystring: { subjectId?: string } }>("/api/settings/preview", async (request) =>
|
|
69
|
+
settings.preview(request.query.subjectId ?? "instance"),
|
|
70
|
+
);
|
|
71
|
+
app.get<{ Querystring: { subjectId: string; key: string; search?: string } }>(
|
|
72
|
+
"/api/settings/choices",
|
|
73
|
+
async (request) => {
|
|
74
|
+
if (!request.query.subjectId || !request.query.key)
|
|
75
|
+
throw new SettingsError("Provide subjectId and key", 400);
|
|
76
|
+
return {
|
|
77
|
+
choices: await settings.choices(
|
|
78
|
+
request.query.subjectId,
|
|
79
|
+
request.query.key,
|
|
80
|
+
request.query.search,
|
|
81
|
+
),
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
app.post("/api/settings/preview", async (request) => {
|
|
86
|
+
return settings.previewDraft(normalizedChange(request));
|
|
87
|
+
});
|
|
88
|
+
app.put("/api/settings/overrides", async (request) => {
|
|
89
|
+
const change = normalizedChange(request);
|
|
90
|
+
settings.write(change);
|
|
91
|
+
await repos.onSettingsChanged?.();
|
|
92
|
+
repos.broadcaster.sendDurable("settings.updated", { subjectId: change.subjectId });
|
|
93
|
+
return settings.preview(change.subjectId);
|
|
94
|
+
});
|
|
95
|
+
app.put<{
|
|
96
|
+
Params: { instanceId: string };
|
|
97
|
+
Body: { primaryRepositoryKey: string | null; expectedPrimaryRepositoryKey: string | null };
|
|
98
|
+
}>("/api/settings/processes/:instanceId/primary-repository", async (request) => {
|
|
99
|
+
const result = await repos.processOperations.runExclusive(request.params.instanceId, () => {
|
|
100
|
+
const process = repos.processes.getById(request.params.instanceId);
|
|
101
|
+
if (!process) throw new SettingsError("Process not found", 404);
|
|
102
|
+
const body = request.body;
|
|
103
|
+
if (
|
|
104
|
+
!body ||
|
|
105
|
+
(body.primaryRepositoryKey !== null && typeof body.primaryRepositoryKey !== "string") ||
|
|
106
|
+
(body.expectedPrimaryRepositoryKey !== null &&
|
|
107
|
+
typeof body.expectedPrimaryRepositoryKey !== "string")
|
|
108
|
+
)
|
|
109
|
+
throw new SettingsError(
|
|
110
|
+
"Provide primaryRepositoryKey and expectedPrimaryRepositoryKey",
|
|
111
|
+
400,
|
|
112
|
+
);
|
|
113
|
+
if ((process.metadata?.primaryRepositoryKey ?? null) !== body.expectedPrimaryRepositoryKey)
|
|
114
|
+
throw new SettingsError("Primary repository changed. Reload before saving again.", 409);
|
|
115
|
+
if (
|
|
116
|
+
body.primaryRepositoryKey !== null &&
|
|
117
|
+
!repos.projects
|
|
118
|
+
.listByInstance(process.id)
|
|
119
|
+
.some((project) => project.key === body.primaryRepositoryKey)
|
|
120
|
+
)
|
|
121
|
+
throw new SettingsError("Primary repository must belong to this process");
|
|
122
|
+
repos.processes.update(process.id, {
|
|
123
|
+
metadata: { ...process.metadata, primaryRepositoryKey: body.primaryRepositoryKey },
|
|
124
|
+
});
|
|
125
|
+
repos.events.create({
|
|
126
|
+
instanceId: process.id,
|
|
127
|
+
eventType: "settings.primary_repository_changed",
|
|
128
|
+
data: { primaryRepositoryKey: body.primaryRepositoryKey, actor: actorForRequest(request) },
|
|
129
|
+
});
|
|
130
|
+
return { primaryRepositoryKey: body.primaryRepositoryKey };
|
|
131
|
+
});
|
|
132
|
+
// Future execution coordination must run after releasing the process lock.
|
|
133
|
+
await repos.onSettingsChanged?.();
|
|
134
|
+
repos.broadcaster.sendDurable("settings.updated", { subjectId: "instance" });
|
|
135
|
+
return result;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
app.get<{ Params: { instanceId: string } }>(
|
|
139
|
+
"/api/settings/processes/:instanceId",
|
|
140
|
+
async (request) => {
|
|
141
|
+
const process = repos.processes.getById(request.params.instanceId);
|
|
142
|
+
if (!process) throw new SettingsError("Process not found", 404);
|
|
143
|
+
const context = settings.forProcess(process);
|
|
144
|
+
const future = settings.previewProcess(process);
|
|
145
|
+
return {
|
|
146
|
+
primaryRepositoryKey: process.metadata?.primaryRepositoryKey ?? null,
|
|
147
|
+
future,
|
|
148
|
+
context: context.context,
|
|
149
|
+
explanations: context.explanations,
|
|
150
|
+
repositories: context.subjects.map(({ project, subject }) => ({
|
|
151
|
+
key: project.key,
|
|
152
|
+
subjectId: subject.id,
|
|
153
|
+
label: subject.label,
|
|
154
|
+
})),
|
|
155
|
+
captured: repos.turnStarts.listByInstance(process.id).flatMap((record) =>
|
|
156
|
+
record.state.kind !== "preparation_failed" &&
|
|
157
|
+
record.state.start?.kind === "llm" &&
|
|
158
|
+
record.state.start.scopedSettings
|
|
159
|
+
? [
|
|
160
|
+
{
|
|
161
|
+
startRecordId: record.id,
|
|
162
|
+
turnId: record.turnId,
|
|
163
|
+
createdAt: record.createdAt,
|
|
164
|
+
state: record.state.kind,
|
|
165
|
+
settings: record.state.start.scopedSettings,
|
|
166
|
+
},
|
|
167
|
+
]
|
|
168
|
+
: [],
|
|
169
|
+
),
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
);
|
|
173
|
+
}
|
|
@@ -95,6 +95,9 @@ export function registerTicketCreationRoutes(
|
|
|
95
95
|
tools: registry.ticketCatalog().map((tool) => ({
|
|
96
96
|
name: tool.name,
|
|
97
97
|
displayName: tool.capability.displayName,
|
|
98
|
+
descriptionFormat: tool.capability.descriptionFormat,
|
|
99
|
+
titlePath: tool.capability.titlePath,
|
|
100
|
+
descriptionPath: tool.capability.descriptionPath,
|
|
98
101
|
})),
|
|
99
102
|
}),
|
|
100
103
|
);
|
|
@@ -109,6 +112,23 @@ export function registerTicketCreationRoutes(
|
|
|
109
112
|
statusCode: 400,
|
|
110
113
|
});
|
|
111
114
|
}
|
|
115
|
+
const existing = deps.launchRuns.getByIdempotencyKey(idempotencyKey.trim());
|
|
116
|
+
if (existing?.instanceId) {
|
|
117
|
+
const relation = deps.processRelations.getByChild(existing.instanceId);
|
|
118
|
+
if (
|
|
119
|
+
existing.launcherId !== `ticket:${req.body.toolName}` ||
|
|
120
|
+
relation?.parentInstanceId !== req.params.instanceId ||
|
|
121
|
+
relation.purpose !== "ticket_creation"
|
|
122
|
+
) {
|
|
123
|
+
return reply
|
|
124
|
+
.code(409)
|
|
125
|
+
.send({ error: "This launch key already belongs to another request" });
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
childInstanceId: existing.instanceId,
|
|
129
|
+
relation,
|
|
130
|
+
} satisfies LaunchTicketCreationResponseBody;
|
|
131
|
+
}
|
|
112
132
|
const tool = registry.resolveTicketTool(req.body.toolName);
|
|
113
133
|
const { processId, startTurnId } = tool.capability;
|
|
114
134
|
if (!hasProcessGraph(deps.processGraphs, processId)) {
|
|
@@ -120,6 +140,14 @@ export function registerTicketCreationRoutes(
|
|
|
120
140
|
const destinationList = tool.capability.destinations
|
|
121
141
|
? await registry.listTicketDestinations(req.body.toolName, actor)
|
|
122
142
|
: undefined;
|
|
143
|
+
if (destinationList && destinationList.destinations.length === 0) {
|
|
144
|
+
throw Object.assign(
|
|
145
|
+
new Error(
|
|
146
|
+
`No destinations are available in ${tool.capability.displayName}. Check project access and issue permissions, then try again.${destinationList.warnings?.length ? ` ${destinationList.warnings.join(" ")}` : ""}`,
|
|
147
|
+
),
|
|
148
|
+
{ statusCode: 503 },
|
|
149
|
+
);
|
|
150
|
+
}
|
|
123
151
|
const { parent, context } = assembleContext(deps, req.params.instanceId, req.body);
|
|
124
152
|
const launchPlan: ProcessLaunchPlan = {
|
|
125
153
|
launcherId: `ticket:${req.body.toolName}`,
|
|
@@ -168,11 +196,6 @@ export function registerTicketCreationRoutes(
|
|
|
168
196
|
}
|
|
169
197
|
const relation = deps.processRelations.getByChild(launched.process.id);
|
|
170
198
|
if (!relation) throw new Error("Ticket launch did not create its process relation");
|
|
171
|
-
if (launched.error) {
|
|
172
|
-
return reply
|
|
173
|
-
.code(500)
|
|
174
|
-
.send({ error: launched.error, childInstanceId: launched.process.id });
|
|
175
|
-
}
|
|
176
199
|
return {
|
|
177
200
|
childInstanceId: launched.process.id,
|
|
178
201
|
relation,
|