@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
package/src/db/database.ts
CHANGED
|
@@ -68,6 +68,8 @@ const ALL_TABLES = [
|
|
|
68
68
|
schema.processLeafOutcomeSnapshots,
|
|
69
69
|
schema.turnRecords,
|
|
70
70
|
schema.turnStartRecords,
|
|
71
|
+
schema.mappedLlmRuns,
|
|
72
|
+
schema.mappedLlmItems,
|
|
71
73
|
schema.apiTokens,
|
|
72
74
|
schema.authSessions,
|
|
73
75
|
schema.authLoginFlows,
|
|
@@ -704,6 +706,32 @@ const KNOWN_MIGRATIONS: readonly KnownMigration[] = [
|
|
|
704
706
|
sqlite.exec("DROP TABLE provider_credentials_before_20260724");
|
|
705
707
|
},
|
|
706
708
|
},
|
|
709
|
+
{
|
|
710
|
+
// Runs before 20260821 so its legacy turn_records validation sees these columns.
|
|
711
|
+
id: "20260922_add_mapped_llm_runs",
|
|
712
|
+
tableNames: ["mapped_llm_runs", "mapped_llm_items", "turn_records", "turn_start_records"],
|
|
713
|
+
matches: (sqlite) =>
|
|
714
|
+
hasExistingSchema(sqlite) &&
|
|
715
|
+
(existingTableSql(sqlite, "mapped_llm_runs") === null ||
|
|
716
|
+
existingTableSql(sqlite, "mapped_llm_items") === null ||
|
|
717
|
+
!tableHasColumn(sqlite, "turn_records", "mapped_run_id") ||
|
|
718
|
+
!tableHasColumn(sqlite, "turn_start_records", "mapped_run_id")),
|
|
719
|
+
apply(sqlite) {
|
|
720
|
+
for (const table of ["turn_records", "turn_start_records"]) {
|
|
721
|
+
if (!tableHasColumn(sqlite, table, "mapped_run_id")) {
|
|
722
|
+
sqlite.exec(`ALTER TABLE ${table} ADD COLUMN mapped_run_id text;
|
|
723
|
+
ALTER TABLE ${table} ADD COLUMN mapped_item_key text;
|
|
724
|
+
ALTER TABLE ${table} ADD COLUMN mapped_item_index integer;`);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
if (existingTableSql(sqlite, "mapped_llm_runs") === null) {
|
|
728
|
+
createTableWithIndexes(sqlite, schema.mappedLlmRuns);
|
|
729
|
+
}
|
|
730
|
+
if (existingTableSql(sqlite, "mapped_llm_items") === null) {
|
|
731
|
+
createTableWithIndexes(sqlite, schema.mappedLlmItems);
|
|
732
|
+
}
|
|
733
|
+
},
|
|
734
|
+
},
|
|
707
735
|
{
|
|
708
736
|
id: "20260821_remove_server_automatic_execution",
|
|
709
737
|
tableNames: ["process_instances", "turn_records"],
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { MappedItem, MappedRun, MappedRunStatus, TurnId } from "@leitwerk-dev/domain";
|
|
2
|
+
import { and, asc, eq } from "drizzle-orm";
|
|
3
|
+
import type { LeitwerkDb } from "./database.js";
|
|
4
|
+
import { now } from "./repo-helpers.js";
|
|
5
|
+
import * as s from "./schema.js";
|
|
6
|
+
|
|
7
|
+
/** @internal */
|
|
8
|
+
export interface CreateMappedRunInput {
|
|
9
|
+
/** @internal */
|
|
10
|
+
id: string;
|
|
11
|
+
/** @internal */
|
|
12
|
+
instanceId: string;
|
|
13
|
+
/** @internal */
|
|
14
|
+
turnId: TurnId;
|
|
15
|
+
/** @internal */
|
|
16
|
+
status: MappedRunStatus;
|
|
17
|
+
/** @internal */
|
|
18
|
+
items: ReadonlyArray<Pick<MappedItem, "itemIndex" | "itemKey" | "label" | "itemJson">>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** @internal */
|
|
22
|
+
export interface CompleteMappedItemInput {
|
|
23
|
+
/** @internal */
|
|
24
|
+
runId: string;
|
|
25
|
+
/** @internal */
|
|
26
|
+
itemIndex: number;
|
|
27
|
+
/** @internal */
|
|
28
|
+
outcome: string;
|
|
29
|
+
/** @internal */
|
|
30
|
+
resultJson: string;
|
|
31
|
+
/** @internal */
|
|
32
|
+
turnRecordId: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** @internal */
|
|
36
|
+
export function createMappedLlmRunRepo(db: LeitwerkDb) {
|
|
37
|
+
return {
|
|
38
|
+
/** @internal */
|
|
39
|
+
create(input: CreateMappedRunInput): MappedRun {
|
|
40
|
+
const ts = now();
|
|
41
|
+
const run = {
|
|
42
|
+
id: input.id,
|
|
43
|
+
instanceId: input.instanceId,
|
|
44
|
+
turnId: input.turnId,
|
|
45
|
+
status: input.status,
|
|
46
|
+
itemCount: input.items.length,
|
|
47
|
+
nextIndex: input.status === "completed" ? input.items.length : 0,
|
|
48
|
+
createdAt: ts,
|
|
49
|
+
updatedAt: ts,
|
|
50
|
+
};
|
|
51
|
+
db.insert(s.mappedLlmRuns).values(run).run();
|
|
52
|
+
for (const item of input.items) {
|
|
53
|
+
db.insert(s.mappedLlmItems)
|
|
54
|
+
.values({
|
|
55
|
+
runId: input.id,
|
|
56
|
+
instanceId: input.instanceId,
|
|
57
|
+
itemIndex: item.itemIndex,
|
|
58
|
+
itemKey: item.itemKey,
|
|
59
|
+
label: item.label,
|
|
60
|
+
itemJson: item.itemJson,
|
|
61
|
+
status: "pending",
|
|
62
|
+
})
|
|
63
|
+
.run();
|
|
64
|
+
}
|
|
65
|
+
return run;
|
|
66
|
+
},
|
|
67
|
+
/** @internal */
|
|
68
|
+
getById(id: string): MappedRun | null {
|
|
69
|
+
return db.select().from(s.mappedLlmRuns).where(eq(s.mappedLlmRuns.id, id)).get() ?? null;
|
|
70
|
+
},
|
|
71
|
+
/** @internal */
|
|
72
|
+
getActiveByInstance(instanceId: string): MappedRun | null {
|
|
73
|
+
return (
|
|
74
|
+
db
|
|
75
|
+
.select()
|
|
76
|
+
.from(s.mappedLlmRuns)
|
|
77
|
+
.where(
|
|
78
|
+
and(eq(s.mappedLlmRuns.instanceId, instanceId), eq(s.mappedLlmRuns.status, "active")),
|
|
79
|
+
)
|
|
80
|
+
.get() ?? null
|
|
81
|
+
);
|
|
82
|
+
},
|
|
83
|
+
/** @internal */
|
|
84
|
+
listByInstance(instanceId: string): MappedRun[] {
|
|
85
|
+
return db
|
|
86
|
+
.select()
|
|
87
|
+
.from(s.mappedLlmRuns)
|
|
88
|
+
.where(eq(s.mappedLlmRuns.instanceId, instanceId))
|
|
89
|
+
.orderBy(asc(s.mappedLlmRuns.createdAt))
|
|
90
|
+
.all();
|
|
91
|
+
},
|
|
92
|
+
/** @internal */
|
|
93
|
+
listItems(runId: string): MappedItem[] {
|
|
94
|
+
return db
|
|
95
|
+
.select()
|
|
96
|
+
.from(s.mappedLlmItems)
|
|
97
|
+
.where(eq(s.mappedLlmItems.runId, runId))
|
|
98
|
+
.orderBy(asc(s.mappedLlmItems.itemIndex))
|
|
99
|
+
.all();
|
|
100
|
+
},
|
|
101
|
+
/** @internal */
|
|
102
|
+
listItemsByInstance(instanceId: string): MappedItem[] {
|
|
103
|
+
return db
|
|
104
|
+
.select()
|
|
105
|
+
.from(s.mappedLlmItems)
|
|
106
|
+
.where(eq(s.mappedLlmItems.instanceId, instanceId))
|
|
107
|
+
.all();
|
|
108
|
+
},
|
|
109
|
+
/** @internal */
|
|
110
|
+
getItem(runId: string, itemIndex: number): MappedItem | null {
|
|
111
|
+
return (
|
|
112
|
+
db
|
|
113
|
+
.select()
|
|
114
|
+
.from(s.mappedLlmItems)
|
|
115
|
+
.where(and(eq(s.mappedLlmItems.runId, runId), eq(s.mappedLlmItems.itemIndex, itemIndex)))
|
|
116
|
+
.get() ?? null
|
|
117
|
+
);
|
|
118
|
+
},
|
|
119
|
+
/**
|
|
120
|
+
* Records one item result and advances the run. Fails unless the item is the
|
|
121
|
+
* run's current pending item, so a replayed outcome cannot complete it twice.
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
completeItem(input: CompleteMappedItemInput): MappedRun {
|
|
125
|
+
const run = this.getById(input.runId);
|
|
126
|
+
if (!run || run.status !== "active" || run.nextIndex !== input.itemIndex) {
|
|
127
|
+
throw new Error(`Mapped item ${input.itemIndex} of run '${input.runId}' is not current`);
|
|
128
|
+
}
|
|
129
|
+
const ts = now();
|
|
130
|
+
const updated = db
|
|
131
|
+
.update(s.mappedLlmItems)
|
|
132
|
+
.set({
|
|
133
|
+
status: "completed",
|
|
134
|
+
outcome: input.outcome,
|
|
135
|
+
resultJson: input.resultJson,
|
|
136
|
+
turnRecordId: input.turnRecordId,
|
|
137
|
+
completedAt: ts,
|
|
138
|
+
})
|
|
139
|
+
.where(
|
|
140
|
+
and(
|
|
141
|
+
eq(s.mappedLlmItems.runId, input.runId),
|
|
142
|
+
eq(s.mappedLlmItems.itemIndex, input.itemIndex),
|
|
143
|
+
eq(s.mappedLlmItems.status, "pending"),
|
|
144
|
+
),
|
|
145
|
+
)
|
|
146
|
+
.run();
|
|
147
|
+
if (updated.changes !== 1) {
|
|
148
|
+
throw new Error(`Mapped item ${input.itemIndex} of run '${input.runId}' is not pending`);
|
|
149
|
+
}
|
|
150
|
+
const nextIndex = input.itemIndex + 1;
|
|
151
|
+
db.update(s.mappedLlmRuns)
|
|
152
|
+
.set({
|
|
153
|
+
nextIndex,
|
|
154
|
+
status: nextIndex === run.itemCount ? "completed" : "active",
|
|
155
|
+
updatedAt: ts,
|
|
156
|
+
})
|
|
157
|
+
.where(eq(s.mappedLlmRuns.id, input.runId))
|
|
158
|
+
.run();
|
|
159
|
+
return this.getById(input.runId) as MappedRun;
|
|
160
|
+
},
|
|
161
|
+
/** @internal */
|
|
162
|
+
abortActiveByInstance(instanceId: string): number {
|
|
163
|
+
return Number(
|
|
164
|
+
db
|
|
165
|
+
.update(s.mappedLlmRuns)
|
|
166
|
+
.set({ status: "aborted", updatedAt: now() })
|
|
167
|
+
.where(
|
|
168
|
+
and(eq(s.mappedLlmRuns.instanceId, instanceId), eq(s.mappedLlmRuns.status, "active")),
|
|
169
|
+
)
|
|
170
|
+
.run().changes,
|
|
171
|
+
);
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** @internal */
|
|
177
|
+
export type MappedLlmRunRepo = ReturnType<typeof createMappedLlmRunRepo>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
MappedTurnItemRef,
|
|
2
3
|
ModelSelectionProvenance,
|
|
3
4
|
ProcessTurnRecord,
|
|
4
5
|
ProcessTurnRecordPathType,
|
|
@@ -10,7 +11,7 @@ import type {
|
|
|
10
11
|
import { asc, desc, eq } from "drizzle-orm";
|
|
11
12
|
import type { SQLiteUpdateSetSource } from "drizzle-orm/sqlite-core";
|
|
12
13
|
import type { LeitwerkDb } from "./database.js";
|
|
13
|
-
import { generateId, now } from "./repo-helpers.js";
|
|
14
|
+
import { generateId, mappedItemRef, now } from "./repo-helpers.js";
|
|
14
15
|
import * as s from "./schema.js";
|
|
15
16
|
|
|
16
17
|
/** @internal */
|
|
@@ -50,6 +51,8 @@ export interface UpdateProcessTurnRecordInput {
|
|
|
50
51
|
/** @internal */
|
|
51
52
|
modelSelectionProvenance?: ModelSelectionProvenance | null;
|
|
52
53
|
/** @internal */
|
|
54
|
+
iteration?: MappedTurnItemRef | null;
|
|
55
|
+
/** @internal */
|
|
53
56
|
turnResultMarkdown?: string | null;
|
|
54
57
|
/** @internal */
|
|
55
58
|
errorSummary?: string | null;
|
|
@@ -81,6 +84,7 @@ function rowToProcessTurnRecord(row: typeof s.turnRecords.$inferSelect): Process
|
|
|
81
84
|
source: row.modelSelectionSource as ModelSelectionProvenance["source"],
|
|
82
85
|
}
|
|
83
86
|
: null,
|
|
87
|
+
iteration: mappedItemRef(row),
|
|
84
88
|
turnResultMarkdown: row.turnResultMarkdown ?? null,
|
|
85
89
|
errorSummary: row.errorSummary ?? null,
|
|
86
90
|
errorClass: (row.errorClass as WorkerErrorClass | null | undefined) ?? null,
|
|
@@ -116,6 +120,9 @@ export function createProcessTurnRecordRepo(db: LeitwerkDb) {
|
|
|
116
120
|
errorClass: input.errorClass ?? null,
|
|
117
121
|
startedAt: input.startedAt ?? now(),
|
|
118
122
|
endedAt: input.endedAt ?? null,
|
|
123
|
+
mappedRunId: input.iteration?.runId ?? null,
|
|
124
|
+
mappedItemKey: input.iteration?.itemKey ?? null,
|
|
125
|
+
mappedItemIndex: input.iteration?.itemIndex ?? null,
|
|
119
126
|
};
|
|
120
127
|
db.insert(s.turnRecords).values(values).run();
|
|
121
128
|
return rowToProcessTurnRecord(values);
|
package/src/db/repo-helpers.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import { asUnknownRecord } from "@leitwerk-dev/domain";
|
|
1
|
+
import { asUnknownRecord, type MappedTurnItemRef } from "@leitwerk-dev/domain";
|
|
2
|
+
|
|
3
|
+
export function mappedItemRef(row: {
|
|
4
|
+
mappedRunId: string | null;
|
|
5
|
+
mappedItemKey: string | null;
|
|
6
|
+
mappedItemIndex: number | null;
|
|
7
|
+
}): MappedTurnItemRef | null {
|
|
8
|
+
return row.mappedRunId !== null && row.mappedItemKey !== null && row.mappedItemIndex !== null
|
|
9
|
+
? { runId: row.mappedRunId, itemKey: row.mappedItemKey, itemIndex: row.mappedItemIndex }
|
|
10
|
+
: null;
|
|
11
|
+
}
|
|
2
12
|
|
|
3
13
|
export function parsePersistedJson<T>(value: string, label: string): T {
|
|
4
14
|
try {
|
package/src/db/repositories.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from "./external-write-log-repo.js";
|
|
|
15
15
|
export * from "./future-execution-repo.js";
|
|
16
16
|
export * from "./launch-run-repo.js";
|
|
17
17
|
export * from "./launcher-recent-value-repo.js";
|
|
18
|
+
export * from "./mapped-llm-run-repo.js";
|
|
18
19
|
export * from "./pending-external-source-fire-repo.js";
|
|
19
20
|
export * from "./process-event-repo.js";
|
|
20
21
|
export * from "./process-handoff-dedup-key-repo.js";
|
|
@@ -39,6 +40,7 @@ export * from "./worker-lease-repo.js";
|
|
|
39
40
|
import { createFutureExecutionRepo } from "./future-execution-repo.js";
|
|
40
41
|
import { createLaunchRunRepo } from "./launch-run-repo.js";
|
|
41
42
|
import { createLauncherRecentValueRepo } from "./launcher-recent-value-repo.js";
|
|
43
|
+
import { createMappedLlmRunRepo } from "./mapped-llm-run-repo.js";
|
|
42
44
|
import { createPendingExternalSourceFireRepo } from "./pending-external-source-fire-repo.js";
|
|
43
45
|
import { createProcessEventRepo } from "./process-event-repo.js";
|
|
44
46
|
import { createProcessHandoffDedupKeyRepo } from "./process-handoff-dedup-key-repo.js";
|
|
@@ -105,6 +107,8 @@ export interface RepositoryBundle {
|
|
|
105
107
|
/** @internal */
|
|
106
108
|
turnAnnotations: ReturnType<typeof createProcessTurnAnnotationRepo>;
|
|
107
109
|
/** @internal */
|
|
110
|
+
mappedRuns: ReturnType<typeof createMappedLlmRunRepo>;
|
|
111
|
+
/** @internal */
|
|
108
112
|
leases: ReturnType<typeof createWorkerLeaseRepo>;
|
|
109
113
|
/** @internal */
|
|
110
114
|
providerCredentials: ReturnType<typeof createProviderCredentialRepo>;
|
|
@@ -156,6 +160,7 @@ export function createAllRepos(
|
|
|
156
160
|
turnRecords: createProcessTurnRecordRepo(db),
|
|
157
161
|
turnStarts: createTurnStartRecordRepo(db),
|
|
158
162
|
turnAnnotations: createProcessTurnAnnotationRepo(db),
|
|
163
|
+
mappedRuns: createMappedLlmRunRepo(db),
|
|
159
164
|
leases: createWorkerLeaseRepo(db),
|
|
160
165
|
providerCredentials: createProviderCredentialRepo(db, credentialCipher),
|
|
161
166
|
externalWrites: createExternalWriteLogRepo(db),
|
package/src/db/schema.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type MappedItem,
|
|
3
|
+
type MappedRunStatus,
|
|
4
|
+
SERIALIZED_SYSTEM_ACTOR,
|
|
5
|
+
} from "@leitwerk-dev/domain";
|
|
2
6
|
import type { SessionTransferPhase } from "@leitwerk-dev/session-transfer";
|
|
3
7
|
import { sql } from "drizzle-orm";
|
|
4
8
|
import {
|
|
@@ -448,6 +452,9 @@ export const turnRecords = sqliteTable(
|
|
|
448
452
|
endedAt: text("ended_at"),
|
|
449
453
|
modelSelectionKind: text("model_selection_kind"),
|
|
450
454
|
modelSelectionSource: text("model_selection_source"),
|
|
455
|
+
mappedRunId: text("mapped_run_id"),
|
|
456
|
+
mappedItemKey: text("mapped_item_key"),
|
|
457
|
+
mappedItemIndex: integer("mapped_item_index"),
|
|
451
458
|
},
|
|
452
459
|
(t) => [
|
|
453
460
|
uniqueIndex("uq_turn_records_instance_id").on(t.instanceId, t.id),
|
|
@@ -479,6 +486,9 @@ export const turnStartRecords = sqliteTable(
|
|
|
479
486
|
stateJson: text("state_json").notNull(),
|
|
480
487
|
createdAt: text("created_at").notNull(),
|
|
481
488
|
updatedAt: text("updated_at").notNull(),
|
|
489
|
+
mappedRunId: text("mapped_run_id"),
|
|
490
|
+
mappedItemKey: text("mapped_item_key"),
|
|
491
|
+
mappedItemIndex: integer("mapped_item_index"),
|
|
482
492
|
},
|
|
483
493
|
(t) => [
|
|
484
494
|
uniqueIndex("uq_turn_start_records_proposed_turn_record").on(t.proposedTurnRecordId),
|
|
@@ -794,6 +804,65 @@ export const externalWriteLog = sqliteTable(
|
|
|
794
804
|
],
|
|
795
805
|
);
|
|
796
806
|
|
|
807
|
+
export const mappedLlmRuns = sqliteTable(
|
|
808
|
+
"mapped_llm_runs",
|
|
809
|
+
{
|
|
810
|
+
id: text("id").primaryKey(),
|
|
811
|
+
instanceId: text("instance_id")
|
|
812
|
+
.notNull()
|
|
813
|
+
.references(() => processInstances.id, { onDelete: "cascade" }),
|
|
814
|
+
turnId: text("turn_id").notNull(),
|
|
815
|
+
status: text("status").$type<MappedRunStatus>().notNull(),
|
|
816
|
+
itemCount: integer("item_count").notNull(),
|
|
817
|
+
nextIndex: integer("next_index").notNull(),
|
|
818
|
+
createdAt: text("created_at").notNull(),
|
|
819
|
+
updatedAt: text("updated_at").notNull(),
|
|
820
|
+
},
|
|
821
|
+
(t) => [
|
|
822
|
+
index("idx_mapped_llm_runs_instance").on(t.instanceId),
|
|
823
|
+
uniqueIndex("uq_mapped_llm_runs_active_instance")
|
|
824
|
+
.on(t.instanceId)
|
|
825
|
+
.where(sql`${t.status} = 'active'`),
|
|
826
|
+
check("mapped_llm_runs_status", sql`${t.status} in ('active', 'completed', 'aborted')`),
|
|
827
|
+
check(
|
|
828
|
+
"mapped_llm_runs_progress",
|
|
829
|
+
sql`${t.itemCount} >= 0 and ${t.nextIndex} >= 0 and ${t.nextIndex} <= ${t.itemCount}`,
|
|
830
|
+
),
|
|
831
|
+
],
|
|
832
|
+
);
|
|
833
|
+
|
|
834
|
+
export const mappedLlmItems = sqliteTable(
|
|
835
|
+
"mapped_llm_items",
|
|
836
|
+
{
|
|
837
|
+
runId: text("run_id")
|
|
838
|
+
.notNull()
|
|
839
|
+
.references(() => mappedLlmRuns.id, { onDelete: "cascade" }),
|
|
840
|
+
instanceId: text("instance_id")
|
|
841
|
+
.notNull()
|
|
842
|
+
.references(() => processInstances.id, { onDelete: "cascade" }),
|
|
843
|
+
itemIndex: integer("item_index").notNull(),
|
|
844
|
+
itemKey: text("item_key").notNull(),
|
|
845
|
+
label: text("label").notNull(),
|
|
846
|
+
itemJson: text("item_json").notNull(),
|
|
847
|
+
status: text("status").$type<MappedItem["status"]>().notNull().default("pending"),
|
|
848
|
+
outcome: text("outcome"),
|
|
849
|
+
resultJson: text("result_json"),
|
|
850
|
+
turnRecordId: text("turn_record_id"),
|
|
851
|
+
completedAt: text("completed_at"),
|
|
852
|
+
},
|
|
853
|
+
(t) => [
|
|
854
|
+
uniqueIndex("uq_mapped_llm_items_run_index").on(t.runId, t.itemIndex),
|
|
855
|
+
uniqueIndex("uq_mapped_llm_items_run_key").on(t.runId, t.itemKey),
|
|
856
|
+
index("idx_mapped_llm_items_instance").on(t.instanceId),
|
|
857
|
+
check("mapped_llm_items_status", sql`${t.status} in ('pending', 'completed')`),
|
|
858
|
+
check("mapped_llm_items_item_json", sql`json_valid(${t.itemJson})`),
|
|
859
|
+
check(
|
|
860
|
+
"mapped_llm_items_result",
|
|
861
|
+
sql`(${t.status} = 'pending' and ${t.resultJson} is null) or (${t.status} = 'completed' and ${t.resultJson} is not null and json_valid(${t.resultJson}))`,
|
|
862
|
+
),
|
|
863
|
+
],
|
|
864
|
+
);
|
|
865
|
+
|
|
797
866
|
/**
|
|
798
867
|
* Composite foreign keys for the cyclic execution graph. Drizzle cannot infer
|
|
799
868
|
* these mutually recursive table types without degrading declarations to any,
|
|
@@ -6,7 +6,7 @@ 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 { generateId, now, parsePersistedJson } from "./repo-helpers.js";
|
|
9
|
+
import { generateId, mappedItemRef, now, parsePersistedJson } from "./repo-helpers.js";
|
|
10
10
|
import * as s from "./schema.js";
|
|
11
11
|
|
|
12
12
|
function map(row: typeof s.turnStartRecords.$inferSelect): TurnStartRecord {
|
|
@@ -22,6 +22,7 @@ function map(row: typeof s.turnStartRecords.$inferSelect): TurnStartRecord {
|
|
|
22
22
|
? parsePersistedJson(row.continuationJson, "turn start continuation")
|
|
23
23
|
: null,
|
|
24
24
|
state: parsePersistedJson<TurnStartRecordState>(row.stateJson, "turn start state"),
|
|
25
|
+
iteration: mappedItemRef(row),
|
|
25
26
|
createdAt: row.createdAt,
|
|
26
27
|
updatedAt: row.updatedAt,
|
|
27
28
|
};
|
|
@@ -51,6 +52,9 @@ export function createTurnStartRecordRepo(db: LeitwerkDb) {
|
|
|
51
52
|
stateJson: JSON.stringify(input.state),
|
|
52
53
|
createdAt: ts,
|
|
53
54
|
updatedAt: ts,
|
|
55
|
+
mappedRunId: input.iteration?.runId ?? null,
|
|
56
|
+
mappedItemKey: input.iteration?.itemKey ?? null,
|
|
57
|
+
mappedItemIndex: input.iteration?.itemIndex ?? null,
|
|
54
58
|
};
|
|
55
59
|
db.insert(s.turnStartRecords).values(value).run();
|
|
56
60
|
return map(value);
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
isAutomaticTurnDefinition,
|
|
9
9
|
isLlmTurnDefinition,
|
|
10
|
+
type OutcomeToolArrayItemSpec,
|
|
10
11
|
type OutcomeToolParameterSpec,
|
|
11
12
|
type TurnDefinition,
|
|
12
13
|
} from "@leitwerk-dev/process-sdk";
|
|
@@ -113,10 +114,49 @@ const scalarParameters = {
|
|
|
113
114
|
},
|
|
114
115
|
};
|
|
115
116
|
|
|
117
|
+
function matchesNestedOutcomeSpec(spec: OutcomeToolArrayItemSpec, value: unknown): boolean {
|
|
118
|
+
switch (spec.type) {
|
|
119
|
+
case "string":
|
|
120
|
+
return typeof value === "string";
|
|
121
|
+
case "number":
|
|
122
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
123
|
+
case "boolean":
|
|
124
|
+
return typeof value === "boolean";
|
|
125
|
+
case "array": {
|
|
126
|
+
const itemSpec = spec.items;
|
|
127
|
+
return (
|
|
128
|
+
Array.isArray(value) &&
|
|
129
|
+
(spec.minItems === undefined || value.length >= spec.minItems) &&
|
|
130
|
+
(!itemSpec || value.every((item) => matchesNestedOutcomeSpec(itemSpec, item)))
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
case "object": {
|
|
134
|
+
if (!isJsonObject(value)) return false;
|
|
135
|
+
const properties = spec.properties ?? {};
|
|
136
|
+
if ((spec.required ?? []).some((key) => !Object.hasOwn(value, key))) return false;
|
|
137
|
+
if (
|
|
138
|
+
spec.additionalProperties === false &&
|
|
139
|
+
Object.keys(value).some((key) => !Object.hasOwn(properties, key))
|
|
140
|
+
)
|
|
141
|
+
return false;
|
|
142
|
+
return Object.entries(properties).every(
|
|
143
|
+
([key, property]) =>
|
|
144
|
+
!Object.hasOwn(value, key) || matchesNestedOutcomeSpec(property, value[key]),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
default:
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
116
152
|
function compileOutcomeParameterSchema(spec: OutcomeToolParameterSpec): OutcomeParameterSchema {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
153
|
+
if (spec.type !== "array") return scalarParameters[spec.type].schema;
|
|
154
|
+
const itemSpec = spec.items ?? { type: "string" };
|
|
155
|
+
return v.custom(
|
|
156
|
+
(value) =>
|
|
157
|
+
Array.isArray(value) && value.every((item) => matchesNestedOutcomeSpec(itemSpec, item)),
|
|
158
|
+
"Expected an array matching its declared item schema",
|
|
159
|
+
);
|
|
120
160
|
}
|
|
121
161
|
|
|
122
162
|
function effectiveArrayItemCount(
|
|
@@ -129,9 +169,13 @@ function effectiveArrayItemCount(
|
|
|
129
169
|
}
|
|
130
170
|
|
|
131
171
|
function expectedParameterLabel(spec: OutcomeToolParameterSpec): string {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
172
|
+
if (spec.type !== "array") return scalarParameters[spec.type].label;
|
|
173
|
+
if (spec.items?.type === "object")
|
|
174
|
+
return spec.items.properties
|
|
175
|
+
? "an array of objects matching the declared schema"
|
|
176
|
+
: "an array of objects";
|
|
177
|
+
if (spec.items?.type === "array") return "an array of arrays matching the declared schema";
|
|
178
|
+
return `an array of ${scalarParameters[spec.items?.type ?? "string"].plural}`;
|
|
135
179
|
}
|
|
136
180
|
|
|
137
181
|
function jsonValuesEqual(left: unknown, right: unknown): boolean {
|
|
@@ -1,30 +1,22 @@
|
|
|
1
1
|
import type { FutureExecution, ProcessInstance } from "@leitwerk-dev/domain";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ProcessLauncherService } from "@leitwerk-dev/process-sdk";
|
|
3
3
|
import { parseFutureActionPayloadJson, parseFutureLaunchPayloadJson } from "@leitwerk-dev/protocol";
|
|
4
4
|
import type {
|
|
5
5
|
FutureActionSummary,
|
|
6
6
|
FutureExecutionSummary,
|
|
7
7
|
FutureLaunchSummary,
|
|
8
|
-
ProcessActionSummary as HttpProcessActionSummary,
|
|
9
8
|
ScheduledActionDetail,
|
|
10
9
|
} from "@leitwerk-dev/protocol/http-contracts";
|
|
11
10
|
import type { RepositoryBundle } from "./db/repositories.js";
|
|
12
|
-
import
|
|
11
|
+
import { buildActionSummaryForProcess } from "./process-action-presenter.js";
|
|
12
|
+
import {
|
|
13
|
+
listCurrentVisibleActions,
|
|
14
|
+
type ProcessOperatorAttentionDeps,
|
|
15
|
+
} from "./process-operator-attention.js";
|
|
13
16
|
|
|
14
17
|
export interface FutureExecutionPresenterDeps
|
|
15
18
|
extends Pick<RepositoryBundle, "futureExecutions" | "processes"> {
|
|
16
19
|
launcherService: ProcessLauncherService;
|
|
17
|
-
processActionRegistry?: ProcessActionRegistry;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface BuildScheduledActionSummaryDeps extends FutureExecutionPresenterDeps {
|
|
21
|
-
buildActionSummaryForProcess: (
|
|
22
|
-
process: ProcessInstance,
|
|
23
|
-
actionId: string,
|
|
24
|
-
action: { id: string; label: string; form?: FormDefinition },
|
|
25
|
-
labelOverride?: string | null,
|
|
26
|
-
overrides?: { supportsScheduling?: boolean },
|
|
27
|
-
) => HttpProcessActionSummary;
|
|
28
20
|
}
|
|
29
21
|
|
|
30
22
|
function futureSummaryState(execution: FutureExecution) {
|
|
@@ -126,7 +118,7 @@ export function buildFutureExecutionSummaries(
|
|
|
126
118
|
}
|
|
127
119
|
|
|
128
120
|
export function getScheduledActionDetailForProcess(
|
|
129
|
-
deps:
|
|
121
|
+
deps: ProcessOperatorAttentionDeps,
|
|
130
122
|
process: ProcessInstance,
|
|
131
123
|
): ScheduledActionDetail | null {
|
|
132
124
|
if (!deps.processActionRegistry) {
|
|
@@ -152,10 +144,11 @@ export function getScheduledActionDetailForProcess(
|
|
|
152
144
|
actionLabel,
|
|
153
145
|
input: payload.input,
|
|
154
146
|
nextTurnModelProfileId: payload.nextTurnModelProfileId,
|
|
155
|
-
action:
|
|
147
|
+
action: buildActionSummaryForProcess(
|
|
148
|
+
deps,
|
|
156
149
|
process,
|
|
157
|
-
scheduledAction.actionId,
|
|
158
150
|
action,
|
|
151
|
+
listCurrentVisibleActions(deps, process).find((candidate) => candidate.id === action.id),
|
|
159
152
|
actionLabel,
|
|
160
153
|
{ supportsScheduling: true },
|
|
161
154
|
),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type LaunchRun, SYSTEM_ACTOR } from "@leitwerk-dev/domain";
|
|
2
|
-
import { expect, vi } from "vitest";
|
|
3
|
-
import { createInMemoryDatabase } from "./db/database.js";
|
|
2
|
+
import { expect, onTestFinished, vi } from "vitest";
|
|
3
|
+
import { closeDatabase, createInMemoryDatabase } from "./db/database.js";
|
|
4
4
|
import { createAllRepos } from "./db/repositories.js";
|
|
5
5
|
import { createLaunchCoordinator } from "./launch-coordinator.js";
|
|
6
6
|
import { createLaunchPipeline, initialLaunchSteps } from "./launch-pipeline.js";
|
|
@@ -48,7 +48,9 @@ export function createCoordinatorHarness(
|
|
|
48
48
|
processLaunches?: Record<string, unknown>;
|
|
49
49
|
} = {},
|
|
50
50
|
) {
|
|
51
|
-
const
|
|
51
|
+
const db = createInMemoryDatabase();
|
|
52
|
+
onTestFinished(() => closeDatabase(db));
|
|
53
|
+
const repos = createAllRepos(db);
|
|
52
54
|
const broadcaster = { sendDurable: vi.fn() } as never;
|
|
53
55
|
const resolvedLauncher = {
|
|
54
56
|
processId: "demo",
|
|
@@ -121,7 +123,9 @@ export function createCoordinatorHarness(
|
|
|
121
123
|
export function createWatcherHarness(
|
|
122
124
|
overrides: { launchPlans?: unknown; processLaunches?: unknown } = {},
|
|
123
125
|
) {
|
|
124
|
-
const
|
|
126
|
+
const db = createInMemoryDatabase();
|
|
127
|
+
onTestFinished(() => closeDatabase(db));
|
|
128
|
+
const repos = createAllRepos(db);
|
|
125
129
|
const process = repos.processes.create({
|
|
126
130
|
processId: "demo",
|
|
127
131
|
selectedTurnId: "start",
|