@leitwerk-dev/server 0.3.0 → 0.3.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-WfwKzrVk.d.ts → app-BuJCdkvy.d.ts} +82 -2
- package/dist/app-MSJXFK33.js +8 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/{chunk-KIOQNNG6.js → chunk-HK6BLLHA.js} +738 -506
- package/dist/chunk-HK6BLLHA.js.map +1 -0
- package/dist/{chunk-LK3RO6C7.js → chunk-QCHS3X33.js} +486 -136
- package/dist/chunk-QCHS3X33.js.map +1 -0
- package/dist/db/database.d.ts.map +1 -1
- 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-turn-record-repo.d.ts +3 -1
- package/dist/db/process-turn-record-repo.d.ts.map +1 -1
- 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 +4 -0
- package/dist/db/repositories.d.ts.map +1 -1
- package/dist/db/schema.d.ts +415 -0
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/turn-start-record-repo.d.ts.map +1 -1
- package/dist/domain-logic/outcome-tools.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/launch-coordinator-test-harness.d.ts.map +1 -1
- package/dist/main.js +3 -3
- package/dist/process-action-presenter.d.ts +16 -0
- package/dist/process-action-presenter.d.ts.map +1 -0
- 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/retry-startup.d.ts.map +1 -1
- package/dist/process-engine/ops/turn-outcome.d.ts.map +1 -1
- package/dist/process-engine/recorder.d.ts.map +1 -1
- package/dist/process-engine/types.d.ts +5 -0
- package/dist/process-engine/types.d.ts.map +1 -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 +8 -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.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 +18 -0
- package/dist/process-engine/writes/writes.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-ui-snapshot-presenter.d.ts +2 -1
- package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
- package/dist/routes/process-actions.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-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 +7 -32
- package/dist/routes/process-route-helpers.d.ts.map +1 -1
- package/dist/supervisor/ipc-handler.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 +2 -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/testing.d.ts +1 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +13 -10
- package/dist/testing.js.map +1 -1
- package/package.json +11 -11
- package/src/app.ts +2 -0
- package/src/db/database.ts +28 -0
- package/src/db/mapped-llm-run-repo.ts +177 -0
- package/src/db/process-turn-record-repo.ts +8 -1
- package/src/db/repo-helpers.ts +11 -1
- package/src/db/repositories.ts +5 -0
- package/src/db/schema.ts +70 -1
- package/src/db/turn-start-record-repo.ts +5 -1
- package/src/domain-logic/outcome-tools.ts +50 -6
- package/src/future-execution-presenter.ts +10 -17
- package/src/launch-coordinator-test-harness.ts +8 -4
- package/src/process-action-presenter.ts +133 -0
- package/src/process-engine/engine.ts +2 -2
- package/src/process-engine/mapped-turns.ts +330 -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/retry-startup.ts +1 -0
- package/src/process-engine/ops/turn-outcome.ts +7 -5
- package/src/process-engine/recorder.ts +12 -0
- package/src/process-engine/runner.ts +8 -8
- package/src/process-engine/types.ts +6 -0
- package/src/process-engine/writes/build-process-abort-writes.ts +1 -0
- package/src/process-engine/writes/build-recovery-start-writes.ts +1 -0
- package/src/process-engine/writes/build-turn-outcome-writes.ts +80 -20
- package/src/process-engine/writes/build-turn-selection-writes.ts +2 -31
- package/src/process-engine/writes/commit-writes.ts +5 -0
- package/src/process-engine/writes/reserve-selected-turn-start.ts +44 -0
- package/src/process-engine/writes/writes.ts +27 -0
- package/src/process-turn-navigation.ts +86 -8
- package/src/process-ui-snapshot-presenter.ts +40 -4
- package/src/routes/process-actions.ts +1 -1
- package/src/routes/process-diagnostics-assembler.ts +32 -6
- package/src/routes/process-primary-path-assembler.ts +17 -33
- package/src/routes/process-route-helpers.ts +8 -165
- package/src/supervisor/ipc-handler.ts +27 -18
- package/src/supervisor/worker-start-payload-builder.ts +25 -0
- package/src/supervisor/worker-supervisor.ts +2 -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/testing.ts +4 -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-MSJXFK33.js.map} +0 -0
|
@@ -1,40 +1,35 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ProcessInstance,
|
|
3
|
-
ProcessTurnAnnotation,
|
|
4
|
-
ProcessTurnRecord,
|
|
5
|
-
} from "@leitwerk-dev/domain";
|
|
6
1
|
import { PRIMARY_PATH_OPERATIONAL_PI_EVENT_TYPES } from "@leitwerk-dev/protocol";
|
|
7
2
|
import {
|
|
8
3
|
buildPrimaryPathSnapshotFromTree,
|
|
9
4
|
type PrimaryPathSnapshotProjectionInput,
|
|
10
5
|
} from "../primary-path-snapshot.js";
|
|
11
6
|
import { resolveCurrentExecutionTurnRecordId } from "../process-execution.js";
|
|
12
|
-
import type { ProcessSessionTreeReadResult } from "../process-session-store.js";
|
|
13
7
|
import {
|
|
14
8
|
mergeProcessEventWindowsAscending,
|
|
15
9
|
PRIMARY_PATH_ACTIVE_TURN_EVENT_LIMIT,
|
|
16
10
|
type RouteDeps,
|
|
17
11
|
} from "./process-route-helpers.js";
|
|
18
12
|
|
|
19
|
-
|
|
13
|
+
type ProcessPrimaryPathDeps = Pick<
|
|
14
|
+
RouteDeps,
|
|
15
|
+
| "processes"
|
|
16
|
+
| "turnRecords"
|
|
17
|
+
| "turnStarts"
|
|
18
|
+
| "events"
|
|
19
|
+
| "leases"
|
|
20
|
+
| "turnAnnotations"
|
|
21
|
+
| "sessionReader"
|
|
22
|
+
>;
|
|
20
23
|
|
|
21
24
|
export class ProcessPrimaryPathAssembler {
|
|
22
|
-
constructor(private readonly deps:
|
|
25
|
+
constructor(private readonly deps: ProcessPrimaryPathDeps) {}
|
|
23
26
|
|
|
24
|
-
capture(
|
|
25
|
-
instanceId
|
|
26
|
-
overrides: {
|
|
27
|
-
process?: ProcessInstance;
|
|
28
|
-
turnRecords?: readonly ProcessTurnRecord[];
|
|
29
|
-
turnAnnotations?: readonly ProcessTurnAnnotation[];
|
|
30
|
-
workerLease?: PrimaryPathSnapshotProjectionInput["workerLease"];
|
|
31
|
-
} = {},
|
|
32
|
-
): CapturedPrimaryPathState | null {
|
|
33
|
-
const process = overrides.process ?? this.deps.processes.getById(instanceId);
|
|
27
|
+
private capture(instanceId: string): PrimaryPathSnapshotProjectionInput | null {
|
|
28
|
+
const process = this.deps.processes.getById(instanceId);
|
|
34
29
|
if (!process) {
|
|
35
30
|
return null;
|
|
36
31
|
}
|
|
37
|
-
const turnRecords =
|
|
32
|
+
const turnRecords = this.deps.turnRecords.listByInstance(process.id);
|
|
38
33
|
const currentTurnRecordId = resolveCurrentExecutionTurnRecordId(process, this.deps.turnStarts);
|
|
39
34
|
const activeTurnRecord = currentTurnRecordId
|
|
40
35
|
? turnRecords.find(
|
|
@@ -63,31 +58,20 @@ export class ProcessPrimaryPathAssembler {
|
|
|
63
58
|
return {
|
|
64
59
|
process,
|
|
65
60
|
currentExecutionTurnRecordId: currentTurnRecordId,
|
|
66
|
-
workerLease:
|
|
67
|
-
overrides.workerLease !== undefined
|
|
68
|
-
? overrides.workerLease
|
|
69
|
-
: this.deps.leases.getByInstance(process.id),
|
|
61
|
+
workerLease: this.deps.leases.getByInstance(process.id),
|
|
70
62
|
turnRecords,
|
|
71
|
-
turnAnnotations:
|
|
72
|
-
overrides.turnAnnotations ?? this.deps.turnAnnotations.listByInstance(process.id),
|
|
63
|
+
turnAnnotations: this.deps.turnAnnotations.listByInstance(process.id),
|
|
73
64
|
events,
|
|
74
65
|
eventWindowTruncated,
|
|
75
66
|
};
|
|
76
67
|
}
|
|
77
68
|
|
|
78
|
-
project(captured: CapturedPrimaryPathState, session: ProcessSessionTreeReadResult) {
|
|
79
|
-
return buildPrimaryPathSnapshotFromTree({
|
|
80
|
-
...captured,
|
|
81
|
-
tree: session.parsedTree,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
69
|
async assemble(instanceId: string) {
|
|
86
70
|
const captured = this.capture(instanceId);
|
|
87
71
|
if (!captured) {
|
|
88
72
|
return null;
|
|
89
73
|
}
|
|
90
74
|
const session = await this.deps.sessionReader.readSessionTree(instanceId);
|
|
91
|
-
return
|
|
75
|
+
return buildPrimaryPathSnapshotFromTree({ ...captured, tree: session.parsedTree });
|
|
92
76
|
}
|
|
93
77
|
}
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
} from "@leitwerk-dev/domain";
|
|
9
9
|
import type { ProcessModelSelectionServiceLike } from "@leitwerk-dev/process-sdk";
|
|
10
10
|
import {
|
|
11
|
-
type FormDefinition,
|
|
12
11
|
findUiLauncherById,
|
|
13
12
|
isLlmTurnDefinition,
|
|
14
13
|
type OutcomeToolParameterSpec,
|
|
@@ -29,12 +28,9 @@ import {
|
|
|
29
28
|
import type {
|
|
30
29
|
LauncherModelConfigSchema,
|
|
31
30
|
LauncherMutationResponseBody,
|
|
32
|
-
ProcessActionPreviewSummary,
|
|
33
|
-
ProcessActionSummary,
|
|
34
31
|
ProcessLaunchConfigurationView,
|
|
35
32
|
ProcessRunDetailsView,
|
|
36
33
|
ProcessRunTurnView,
|
|
37
|
-
ScheduledActionDetail,
|
|
38
34
|
ScheduledActionMutationResponseBody,
|
|
39
35
|
} from "@leitwerk-dev/protocol/http-contracts";
|
|
40
36
|
import type { ToolCallRendererDefinition } from "@leitwerk-dev/protocol/tool-renderer-contract";
|
|
@@ -53,7 +49,7 @@ import type {
|
|
|
53
49
|
} from "../future-execution/index.js";
|
|
54
50
|
import {
|
|
55
51
|
buildFutureExecutionListView,
|
|
56
|
-
getScheduledActionDetailForProcess
|
|
52
|
+
getScheduledActionDetailForProcess,
|
|
57
53
|
} from "../future-execution-presenter.js";
|
|
58
54
|
import type { LaunchCoordinator } from "../launch-coordinator.js";
|
|
59
55
|
import { normalizeSubmittedProcessTitle } from "../launch-title.js";
|
|
@@ -74,11 +70,7 @@ import { getProcessGraph, type ProcessGraphRegistry } from "../process-graph.js"
|
|
|
74
70
|
import type { ServerProcessModelPolicy } from "../process-model-policy/index.js";
|
|
75
71
|
import { presentLauncherModelConfigSchema } from "../process-model-policy-presenter.js";
|
|
76
72
|
import type { ProcessOperationCoordinator } from "../process-operation-coordinator.js";
|
|
77
|
-
import {
|
|
78
|
-
getSelectedTurnSummaryForProcess,
|
|
79
|
-
listCurrentVisibleActions,
|
|
80
|
-
listVisibleActionsForProcess as listVisibleAttentionActionsForProcess,
|
|
81
|
-
} from "../process-operator-attention.js";
|
|
73
|
+
import { getSelectedTurnSummaryForProcess } from "../process-operator-attention.js";
|
|
82
74
|
import type { ProcessQuestionService } from "../process-question-service.js";
|
|
83
75
|
import type { ProcessSessionReader } from "../process-session-store.js";
|
|
84
76
|
import type { ProcessTitleGenerator } from "../process-title-generator.js";
|
|
@@ -117,6 +109,8 @@ export interface RouteDeps
|
|
|
117
109
|
| "transaction"
|
|
118
110
|
> {
|
|
119
111
|
/** @internal */
|
|
112
|
+
mappedRuns?: RepositoryBundle["mappedRuns"];
|
|
113
|
+
/** @internal */
|
|
120
114
|
startupObservations?: RepositoryBundle["startupObservations"];
|
|
121
115
|
/** @public */
|
|
122
116
|
externalSourceService?: Pick<
|
|
@@ -179,7 +173,7 @@ export interface RouteDeps
|
|
|
179
173
|
sessionTransferService?: SessionTransferService;
|
|
180
174
|
}
|
|
181
175
|
|
|
182
|
-
export function routeConfig(deps: RouteDeps): LeitwerkConfig {
|
|
176
|
+
export function routeConfig(deps: Pick<RouteDeps, "config">): LeitwerkConfig {
|
|
183
177
|
return deps.config ?? getDefaultConfig();
|
|
184
178
|
}
|
|
185
179
|
|
|
@@ -256,7 +250,7 @@ export function buildProcessLaunchConfigurationView(
|
|
|
256
250
|
}
|
|
257
251
|
|
|
258
252
|
export function buildProcessRunDetailsView(
|
|
259
|
-
deps: RouteDeps,
|
|
253
|
+
deps: Pick<RouteDeps, "config" | "processActionRegistry" | "processGraphs">,
|
|
260
254
|
process: ProcessInstance,
|
|
261
255
|
projects: readonly ProcessProject[],
|
|
262
256
|
): ProcessRunDetailsView {
|
|
@@ -340,60 +334,10 @@ export function buildProcessRunDetailsView(
|
|
|
340
334
|
};
|
|
341
335
|
}
|
|
342
336
|
|
|
343
|
-
export function
|
|
344
|
-
deps: RouteDeps,
|
|
337
|
+
export function processDefinesLeafOutcome(
|
|
338
|
+
deps: Pick<RouteDeps, "processUiRegistry">,
|
|
345
339
|
process: ProcessInstance,
|
|
346
|
-
actionId: string,
|
|
347
340
|
): boolean {
|
|
348
|
-
const action = deps.processActionRegistry?.getAction(process.processId, actionId);
|
|
349
|
-
return typeof action?.plan === "function";
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
export function buildActionSummaryForProcess(
|
|
353
|
-
deps: RouteDeps,
|
|
354
|
-
process: ProcessInstance,
|
|
355
|
-
actionId: string,
|
|
356
|
-
action: {
|
|
357
|
-
id: string;
|
|
358
|
-
label: string;
|
|
359
|
-
form?: FormDefinition;
|
|
360
|
-
},
|
|
361
|
-
labelOverride?: string | null,
|
|
362
|
-
overrides: { supportsScheduling?: boolean } = {},
|
|
363
|
-
): ProcessActionSummary {
|
|
364
|
-
const visibleAction = listCurrentVisibleActions(deps, process).find(
|
|
365
|
-
(candidate) => candidate.id === actionId,
|
|
366
|
-
);
|
|
367
|
-
const preview =
|
|
368
|
-
visibleAction?.preview ??
|
|
369
|
-
deps.processActionRegistry?.resolveActionPreview(process.processId, process, actionId) ??
|
|
370
|
-
null;
|
|
371
|
-
const supportsScheduling =
|
|
372
|
-
overrides.supportsScheduling ??
|
|
373
|
-
Boolean(
|
|
374
|
-
actionHasPurePlan(deps, process, actionId) &&
|
|
375
|
-
deps.processActionRegistry?.resolveActionScheduling(process.processId, process, actionId),
|
|
376
|
-
);
|
|
377
|
-
return buildProcessActionSummary(action, labelOverride ?? visibleAction?.label ?? action.label, {
|
|
378
|
-
description: visibleAction?.description ?? null,
|
|
379
|
-
preview: buildProcessActionPreviewSummary(deps, preview, process),
|
|
380
|
-
supportsScheduling,
|
|
381
|
-
supportsNextTurnModelOverride: previewSupportsNextTurnModelOverride(
|
|
382
|
-
deps,
|
|
383
|
-
process,
|
|
384
|
-
actionId,
|
|
385
|
-
preview,
|
|
386
|
-
),
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
export function listVisibleActionsForProcess(deps: RouteDeps, process: ProcessInstance) {
|
|
391
|
-
return listVisibleAttentionActionsForProcess(deps, process).map((action) =>
|
|
392
|
-
buildActionSummaryForProcess(deps, process, action.id, action, action.label),
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
export function processDefinesLeafOutcome(deps: RouteDeps, process: ProcessInstance): boolean {
|
|
397
341
|
return deps.processUiRegistry?.getLeafOutcomeDefinition(process.processId) != null;
|
|
398
342
|
}
|
|
399
343
|
|
|
@@ -602,107 +546,6 @@ export function normalizeRecoveryModelRequest(
|
|
|
602
546
|
return parsed.ok ? { ok: true, request: parsed.request } : parsed;
|
|
603
547
|
}
|
|
604
548
|
|
|
605
|
-
export function buildProcessActionPreviewSummary(
|
|
606
|
-
deps: RouteDeps,
|
|
607
|
-
preview: {
|
|
608
|
-
candidateSelectedTurnId: string | null;
|
|
609
|
-
lifecycleStatus?: string | null;
|
|
610
|
-
} | null,
|
|
611
|
-
process: ProcessInstance,
|
|
612
|
-
): ProcessActionPreviewSummary | null {
|
|
613
|
-
if (!preview) {
|
|
614
|
-
return null;
|
|
615
|
-
}
|
|
616
|
-
if (!preview.candidateSelectedTurnId) {
|
|
617
|
-
return {
|
|
618
|
-
kind: "terminal",
|
|
619
|
-
turnId: null,
|
|
620
|
-
turnKind: null,
|
|
621
|
-
description: preview.lifecycleStatus === "aborted" ? "Abort process" : "Complete process",
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
const turnDef = deps.processActionRegistry?.getTurnDefinition(
|
|
625
|
-
process.processId,
|
|
626
|
-
preview.candidateSelectedTurnId,
|
|
627
|
-
);
|
|
628
|
-
if (!turnDef) {
|
|
629
|
-
return null;
|
|
630
|
-
}
|
|
631
|
-
return {
|
|
632
|
-
kind: "turn",
|
|
633
|
-
turnId: preview.candidateSelectedTurnId,
|
|
634
|
-
turnKind: turnDef.kind,
|
|
635
|
-
description: turnDef.description,
|
|
636
|
-
};
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
export function previewSupportsNextTurnModelOverride(
|
|
640
|
-
deps: RouteDeps,
|
|
641
|
-
process: ProcessInstance,
|
|
642
|
-
actionId: string,
|
|
643
|
-
preview: { candidateSelectedTurnId: string | null } | null,
|
|
644
|
-
): boolean {
|
|
645
|
-
if (!preview?.candidateSelectedTurnId) {
|
|
646
|
-
return false;
|
|
647
|
-
}
|
|
648
|
-
if (!actionHasPurePlan(deps, process, actionId)) {
|
|
649
|
-
return false;
|
|
650
|
-
}
|
|
651
|
-
const turnDef = deps.processActionRegistry?.getTurnDefinition(
|
|
652
|
-
process.processId,
|
|
653
|
-
preview.candidateSelectedTurnId,
|
|
654
|
-
);
|
|
655
|
-
return Boolean(turnDef && isLlmTurnDefinition(turnDef));
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
export function buildProcessActionSummary(
|
|
659
|
-
action: {
|
|
660
|
-
id: string;
|
|
661
|
-
label: string;
|
|
662
|
-
form?: FormDefinition;
|
|
663
|
-
},
|
|
664
|
-
labelOverride?: string | null,
|
|
665
|
-
opts: {
|
|
666
|
-
description?: string | null;
|
|
667
|
-
preview?: ProcessActionPreviewSummary | null;
|
|
668
|
-
supportsScheduling?: boolean;
|
|
669
|
-
supportsNextTurnModelOverride?: boolean;
|
|
670
|
-
} = {},
|
|
671
|
-
): ProcessActionSummary {
|
|
672
|
-
return {
|
|
673
|
-
id: action.id,
|
|
674
|
-
label: labelOverride?.trim() ? labelOverride : action.label,
|
|
675
|
-
description: opts.description ?? null,
|
|
676
|
-
preview: opts.preview ?? null,
|
|
677
|
-
supportsScheduling: opts.supportsScheduling === true,
|
|
678
|
-
supportsNextTurnModelOverride: opts.supportsNextTurnModelOverride === true,
|
|
679
|
-
...(action.form
|
|
680
|
-
? {
|
|
681
|
-
form: {
|
|
682
|
-
id: action.form.id,
|
|
683
|
-
title: action.form.title,
|
|
684
|
-
submitLabel: action.form.submitLabel,
|
|
685
|
-
fields: action.form.fields.map((field) => ({ ...field })),
|
|
686
|
-
},
|
|
687
|
-
}
|
|
688
|
-
: {}),
|
|
689
|
-
};
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
export function getScheduledActionDetailForProcess(
|
|
693
|
-
deps: RouteDeps,
|
|
694
|
-
process: ProcessInstance,
|
|
695
|
-
): ScheduledActionDetail | null {
|
|
696
|
-
return getPresentedScheduledActionDetailForProcess(
|
|
697
|
-
{
|
|
698
|
-
...deps,
|
|
699
|
-
buildActionSummaryForProcess: (process, actionId, action, labelOverride, overrides) =>
|
|
700
|
-
buildActionSummaryForProcess(deps, process, actionId, action, labelOverride, overrides),
|
|
701
|
-
},
|
|
702
|
-
process,
|
|
703
|
-
);
|
|
704
|
-
}
|
|
705
|
-
|
|
706
549
|
export function buildLauncherModelConfigSchema(
|
|
707
550
|
deps: RouteDeps,
|
|
708
551
|
processId: string,
|
|
@@ -285,36 +285,45 @@ export function createIpcHandler(deps: IpcHandlerDeps, callbacks: IpcHandlerCall
|
|
|
285
285
|
break;
|
|
286
286
|
}
|
|
287
287
|
case "worker.turn_started": {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
288
|
+
let accepted = false;
|
|
289
|
+
const onRecorded = (turnRecordId: string) => {
|
|
290
|
+
accepted = true;
|
|
291
|
+
eventIngestor.noteTurnStarted(instanceId, turnRecordId);
|
|
292
|
+
callbacks.onWorkerTurnStartAccepted?.(instanceId, workerId, {
|
|
291
293
|
startRecordId: msg.payload.startRecordId,
|
|
292
|
-
|
|
293
|
-
})
|
|
294
|
-
|
|
295
|
-
|
|
294
|
+
turnRecordId,
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
void deps.commands
|
|
298
|
+
.acceptWorkerTurnStart(
|
|
299
|
+
instanceId,
|
|
300
|
+
{
|
|
301
|
+
workerLeaseId: activeLease.id,
|
|
302
|
+
startRecordId: msg.payload.startRecordId,
|
|
303
|
+
proposedTurnRecordId: msg.payload.proposedTurnRecordId,
|
|
304
|
+
},
|
|
305
|
+
{ onRecorded },
|
|
306
|
+
)
|
|
307
|
+
.then(() => {
|
|
308
|
+
if (!accepted) {
|
|
296
309
|
callbacks.onWorkerFailed?.(instanceId, workerId, "Worker turn start was rejected");
|
|
297
310
|
return;
|
|
298
311
|
}
|
|
299
|
-
eventIngestor.noteTurnStarted(instanceId, result.data.turnRecordId);
|
|
300
|
-
// Acceptance persists the correlated turn record before launch projection.
|
|
301
312
|
launchCoordinator?.refresh(instanceId);
|
|
302
|
-
callbacks.onWorkerTurnStartAccepted?.(instanceId, workerId, {
|
|
303
|
-
startRecordId: msg.payload.startRecordId,
|
|
304
|
-
turnRecordId: result.data.turnRecordId,
|
|
305
|
-
});
|
|
306
313
|
})
|
|
307
|
-
.catch(() =>
|
|
308
|
-
|
|
309
|
-
|
|
314
|
+
.catch(() => {
|
|
315
|
+
// Delivery/projection failures do not undo durable acceptance; replay is safe.
|
|
316
|
+
if (!accepted)
|
|
317
|
+
callbacks.onWorkerFailed?.(instanceId, workerId, "Worker turn start failed");
|
|
318
|
+
});
|
|
310
319
|
break;
|
|
311
320
|
}
|
|
312
321
|
case "worker.turn_outcome": {
|
|
313
|
-
turnRecorder.recordTurnOutcome(instanceId, workerId, msg.payload);
|
|
322
|
+
turnRecorder.recordTurnOutcome(instanceId, workerId, activeLease.id, msg.payload);
|
|
314
323
|
break;
|
|
315
324
|
}
|
|
316
325
|
case "worker.turn_failed": {
|
|
317
|
-
turnRecorder.recordTurnFailed(instanceId, workerId, msg.payload);
|
|
326
|
+
turnRecorder.recordTurnFailed(instanceId, workerId, activeLease.id, msg.payload);
|
|
318
327
|
break;
|
|
319
328
|
}
|
|
320
329
|
case "worker.lifecycle_parked": {
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
type PiResourceBundle,
|
|
15
15
|
type ServerToWorkerMessage,
|
|
16
16
|
verifyCanonicalPiResourceBundle,
|
|
17
|
+
type WorkerMappedItem,
|
|
17
18
|
type WorkerRuntimeSettingsSnapshot,
|
|
18
19
|
type WorkerStartPayload,
|
|
19
20
|
} from "@leitwerk-dev/worker-protocol";
|
|
@@ -39,6 +40,8 @@ export interface WorkerStartPayloadBuilderDeps
|
|
|
39
40
|
RepositoryBundle,
|
|
40
41
|
"processes" | "projects" | "inputs" | "turnRecords" | "turnStarts" | "leases" | "events"
|
|
41
42
|
> {
|
|
43
|
+
/** Required for processes that declare mapped LLM turns. @internal */
|
|
44
|
+
mappedRuns?: Pick<RepositoryBundle["mappedRuns"], "getById" | "getItem">;
|
|
42
45
|
/** @internal */
|
|
43
46
|
config: LeitwerkConfig;
|
|
44
47
|
/** @internal */
|
|
@@ -219,6 +222,26 @@ function buildTurnResultMarkdownByProduct(
|
|
|
219
222
|
return Object.keys(byProduct).length > 0 ? byProduct : undefined;
|
|
220
223
|
}
|
|
221
224
|
|
|
225
|
+
function resolveMappedItem(
|
|
226
|
+
start: TurnStartRecord,
|
|
227
|
+
deps: Pick<WorkerStartPayloadBuilderDeps, "mappedRuns">,
|
|
228
|
+
): WorkerMappedItem | undefined {
|
|
229
|
+
if (!start.iteration) return undefined;
|
|
230
|
+
const run = deps.mappedRuns?.getById(start.iteration.runId);
|
|
231
|
+
const item = deps.mappedRuns?.getItem(start.iteration.runId, start.iteration.itemIndex);
|
|
232
|
+
if (!run || !item || item.itemKey !== start.iteration.itemKey) {
|
|
233
|
+
throw new Error(`Mapped item for worker start '${start.id}' is unavailable`);
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
runId: run.id,
|
|
237
|
+
itemKey: item.itemKey,
|
|
238
|
+
itemLabel: item.label,
|
|
239
|
+
itemIndex: item.itemIndex,
|
|
240
|
+
itemCount: run.itemCount,
|
|
241
|
+
item: JSON.parse(item.itemJson) as unknown,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
222
245
|
function resolveLlmPreparation(
|
|
223
246
|
start: TurnStartRecord,
|
|
224
247
|
deps: Pick<WorkerStartPayloadBuilderDeps, "events">,
|
|
@@ -320,6 +343,7 @@ export function createWorkerStartPayloadBuilder(deps: WorkerStartPayloadBuilderD
|
|
|
320
343
|
null)
|
|
321
344
|
: null;
|
|
322
345
|
const contextSnapshot = buildWorkerRuntimeContextSnapshot(process, start);
|
|
346
|
+
const iteration = resolveMappedItem(start, deps);
|
|
323
347
|
const repositoryCredentials =
|
|
324
348
|
deps.resolveRepositoryCredentials?.({
|
|
325
349
|
process,
|
|
@@ -380,6 +404,7 @@ export function createWorkerStartPayloadBuilder(deps: WorkerStartPayloadBuilderD
|
|
|
380
404
|
...(repositoryCredentials.length > 0 ? { repositoryCredentials } : {}),
|
|
381
405
|
...(dockerRegistryCredentials.length > 0 ? { dockerRegistryCredentials } : {}),
|
|
382
406
|
...(integrationTools && integrationTools.length > 0 ? { integrationTools } : {}),
|
|
407
|
+
...(iteration ? { iteration } : {}),
|
|
383
408
|
};
|
|
384
409
|
const payload: WorkerStartPayload =
|
|
385
410
|
bootstrap.kind === "llm"
|
|
@@ -82,6 +82,8 @@ export interface SupervisorDeps
|
|
|
82
82
|
/** @internal */
|
|
83
83
|
startupObservations?: RepositoryBundle["startupObservations"];
|
|
84
84
|
/** @internal */
|
|
85
|
+
mappedRuns?: RepositoryBundle["mappedRuns"];
|
|
86
|
+
/** @internal */
|
|
85
87
|
config: LeitwerkConfig;
|
|
86
88
|
/** @internal */
|
|
87
89
|
getLaunchCoordinator?: () => LaunchCoordinator | undefined;
|
|
@@ -127,6 +127,7 @@ export function createWorkerTurnIpcRecorder(
|
|
|
127
127
|
const recoverRecordingFailure = async (input: {
|
|
128
128
|
instanceId: string;
|
|
129
129
|
workerId: string;
|
|
130
|
+
workerLeaseId: string;
|
|
130
131
|
turnRecordId: string;
|
|
131
132
|
terminalType: TerminalType;
|
|
132
133
|
failure: unknown;
|
|
@@ -147,6 +148,7 @@ export function createWorkerTurnIpcRecorder(
|
|
|
147
148
|
return;
|
|
148
149
|
}
|
|
149
150
|
const fallback = await deps.commands.recordWorkerFailure(input.instanceId, {
|
|
151
|
+
workerLeaseId: input.workerLeaseId,
|
|
150
152
|
errorCode: details.code,
|
|
151
153
|
message: `Server could not durably record worker turn ${input.terminalType}: ${details.message}`,
|
|
152
154
|
errorClass: "infrastructure",
|
|
@@ -180,6 +182,7 @@ export function createWorkerTurnIpcRecorder(
|
|
|
180
182
|
const recordTerminal = async <T>(input: {
|
|
181
183
|
instanceId: string;
|
|
182
184
|
workerId: string;
|
|
185
|
+
workerLeaseId: string;
|
|
183
186
|
turnRecordId: string;
|
|
184
187
|
terminalType: TerminalType;
|
|
185
188
|
record: () => Promise<T>;
|
|
@@ -204,6 +207,7 @@ export function createWorkerTurnIpcRecorder(
|
|
|
204
207
|
recordTurnOutcome(
|
|
205
208
|
instanceId: string,
|
|
206
209
|
workerId: string,
|
|
210
|
+
workerLeaseId: string,
|
|
207
211
|
payload: WorkerTurnOutcomePayload,
|
|
208
212
|
): void {
|
|
209
213
|
const { turnId, ...rest } = payload;
|
|
@@ -217,6 +221,7 @@ export function createWorkerTurnIpcRecorder(
|
|
|
217
221
|
void recordTerminal({
|
|
218
222
|
instanceId,
|
|
219
223
|
workerId,
|
|
224
|
+
workerLeaseId,
|
|
220
225
|
turnRecordId: rest.turnRecordId,
|
|
221
226
|
terminalType: "outcome",
|
|
222
227
|
record: () =>
|
|
@@ -236,12 +241,18 @@ export function createWorkerTurnIpcRecorder(
|
|
|
236
241
|
recoveryContext: createGenericFailedTurnRecoveryContext(),
|
|
237
242
|
});
|
|
238
243
|
},
|
|
239
|
-
recordTurnFailed(
|
|
244
|
+
recordTurnFailed(
|
|
245
|
+
instanceId: string,
|
|
246
|
+
workerId: string,
|
|
247
|
+
workerLeaseId: string,
|
|
248
|
+
payload: WorkerTurnFailedPayload,
|
|
249
|
+
): void {
|
|
240
250
|
const { errorClass, failureCode, failureDetails: details, ...rest } = payload;
|
|
241
251
|
if (errorClass !== undefined && !isWorkerErrorClass(errorClass)) {
|
|
242
252
|
void recoverRecordingFailure({
|
|
243
253
|
instanceId,
|
|
244
254
|
workerId,
|
|
255
|
+
workerLeaseId,
|
|
245
256
|
turnRecordId: rest.turnRecordId,
|
|
246
257
|
terminalType: "failure",
|
|
247
258
|
failure: new Error(`Invalid worker error class '${errorClass}'`),
|
|
@@ -260,6 +271,7 @@ export function createWorkerTurnIpcRecorder(
|
|
|
260
271
|
void recordTerminal({
|
|
261
272
|
instanceId,
|
|
262
273
|
workerId,
|
|
274
|
+
workerLeaseId,
|
|
263
275
|
turnRecordId: rest.turnRecordId,
|
|
264
276
|
terminalType: "failure",
|
|
265
277
|
record: () =>
|
|
@@ -2,15 +2,32 @@ import type { ResolvedTurnStart } from "@leitwerk-dev/domain";
|
|
|
2
2
|
import type { AppContext } from "../app.js";
|
|
3
3
|
|
|
4
4
|
/** @internal */
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
type AcceptedTurnRepos = Pick<
|
|
6
|
+
AppContext["deps"],
|
|
7
|
+
"processes" | "turnRecords" | "turnStarts" | "leases"
|
|
8
|
+
>;
|
|
9
|
+
|
|
10
|
+
/** @internal */
|
|
11
|
+
type AcceptedTurnContext = {
|
|
12
|
+
/** @internal */
|
|
13
|
+
deps: AcceptedTurnRepos;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Compatibility name for existing LLM fixtures. @internal */
|
|
17
|
+
export const createAcceptedLlmTurn = createAcceptedWorkerTurn;
|
|
18
|
+
/** Compatibility name for existing LLM starts. @internal */
|
|
19
|
+
export const createAcceptedLlmTurnStart = createAcceptedWorkerTurnStart;
|
|
20
|
+
|
|
21
|
+
/** @internal */
|
|
22
|
+
export function createAcceptedWorkerTurn(
|
|
23
|
+
ctx: AcceptedTurnContext | null,
|
|
24
|
+
input: Parameters<AcceptedTurnRepos["turnRecords"]["create"]>[0] & {
|
|
8
25
|
/** @internal */
|
|
9
26
|
id: string;
|
|
10
27
|
/** @internal */
|
|
11
|
-
turnType: "llm";
|
|
28
|
+
turnType: "llm" | "automatic";
|
|
12
29
|
},
|
|
13
|
-
options: Parameters<typeof
|
|
30
|
+
options: Parameters<typeof createAcceptedWorkerTurnStart>[3] & {
|
|
14
31
|
/** @internal */
|
|
15
32
|
current?: boolean;
|
|
16
33
|
/** @internal */
|
|
@@ -18,24 +35,25 @@ export function createAcceptedLlmTurn(
|
|
|
18
35
|
} = {},
|
|
19
36
|
) {
|
|
20
37
|
if (!ctx) throw new Error("Server context not initialized");
|
|
38
|
+
const { deps: repos } = ctx;
|
|
21
39
|
const current = options.current ?? input.status === "running";
|
|
22
|
-
const lease =
|
|
40
|
+
const lease = repos.leases.create({
|
|
23
41
|
instanceId: input.instanceId,
|
|
24
42
|
workerId: options.workerId ?? `wkr_${input.id}`,
|
|
25
43
|
state: current ? (input.status === "failed" ? "failed" : "busy") : "exited",
|
|
26
44
|
});
|
|
27
|
-
const start =
|
|
28
|
-
const record =
|
|
45
|
+
const start = createAcceptedWorkerTurnStart(ctx, input, lease.id, options);
|
|
46
|
+
const record = repos.turnRecords.create({
|
|
29
47
|
...input,
|
|
30
48
|
turnStartRecordId: start.id,
|
|
31
49
|
acceptedWorkerLeaseId: lease.id,
|
|
32
50
|
});
|
|
33
51
|
if (current) {
|
|
34
|
-
|
|
52
|
+
repos.processes.update(input.instanceId, {
|
|
35
53
|
currentExecution: { kind: "worker_start", id: start.id },
|
|
36
54
|
});
|
|
37
55
|
} else {
|
|
38
|
-
|
|
56
|
+
repos.leases.update(lease.id, {
|
|
39
57
|
exitedAt: input.endedAt ?? input.startedAt ?? new Date().toISOString(),
|
|
40
58
|
});
|
|
41
59
|
}
|
|
@@ -43,9 +61,11 @@ export function createAcceptedLlmTurn(
|
|
|
43
61
|
}
|
|
44
62
|
|
|
45
63
|
/** @internal */
|
|
46
|
-
|
|
47
|
-
ctx:
|
|
64
|
+
function createAcceptedWorkerTurnStart(
|
|
65
|
+
ctx: AcceptedTurnContext,
|
|
48
66
|
input: {
|
|
67
|
+
/** @internal */
|
|
68
|
+
turnType?: "llm" | "automatic";
|
|
49
69
|
/** @internal */
|
|
50
70
|
id: string;
|
|
51
71
|
/** @internal */
|
|
@@ -80,27 +100,31 @@ export function createAcceptedLlmTurnStart(
|
|
|
80
100
|
id: options.id ?? `tsr_${input.id}`,
|
|
81
101
|
instanceId: input.instanceId,
|
|
82
102
|
turnId: input.turnId,
|
|
83
|
-
turnType: "llm",
|
|
103
|
+
turnType: input.turnType ?? "llm",
|
|
84
104
|
proposedTurnRecordId: input.id,
|
|
85
105
|
startKind: "selected_turn",
|
|
86
106
|
recoveryTurnRecordId: null,
|
|
87
107
|
continuation: null,
|
|
88
108
|
state: {
|
|
89
109
|
kind: "accepted",
|
|
90
|
-
start:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
110
|
+
start:
|
|
111
|
+
input.turnType === "automatic"
|
|
112
|
+
? { kind: "automatic" }
|
|
113
|
+
: (options.preparedStart ?? {
|
|
114
|
+
kind: "llm",
|
|
115
|
+
model: options.model ?? {
|
|
116
|
+
profileId: "fixture-profile",
|
|
117
|
+
providerId: "fixture-provider",
|
|
118
|
+
modelId: "fixture-model",
|
|
119
|
+
thinkingLevel: "off",
|
|
120
|
+
},
|
|
121
|
+
providerOptions: {},
|
|
122
|
+
providerWorkerConfig: null,
|
|
123
|
+
piResourceSnapshotDigest:
|
|
124
|
+
options.piResourceSnapshotDigest ?? "fixture-resource-digest",
|
|
125
|
+
workerRuntimeProfileId: options.workerRuntimeProfileId ?? "local",
|
|
126
|
+
piSettings: {},
|
|
127
|
+
}),
|
|
104
128
|
turnRecordId: input.id,
|
|
105
129
|
acceptedWorkerLeaseId,
|
|
106
130
|
},
|