@leitwerk-dev/server 0.2.1 → 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-ZSKM25SD.js → chunk-HK6BLLHA.js} +1702 -496
- package/dist/chunk-HK6BLLHA.js.map +1 -0
- package/dist/{chunk-CNITOV76.js → chunk-QCHS3X33.js} +546 -1132
- 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 +23 -4
- package/dist/test-helpers/accepted-turn-start.d.ts.map +1 -1
- package/dist/test-helpers/owned-test-deps.d.ts +18 -0
- package/dist/test-helpers/owned-test-deps.d.ts.map +1 -0
- package/dist/test-helpers/prepared-fixture-start.d.ts +14 -0
- package/dist/test-helpers/prepared-fixture-start.d.ts.map +1 -0
- package/dist/testing.d.ts +2 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +72 -11
- 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 +54 -27
- package/src/test-helpers/owned-test-deps.ts +45 -0
- package/src/test-helpers/prepared-fixture-start.ts +74 -0
- package/src/testing.ts +5 -1
- package/dist/app-7PKX73TU.js +0 -8
- package/dist/chunk-CNITOV76.js.map +0 -1
- package/dist/chunk-ZSKM25SD.js.map +0 -1
- /package/dist/{app-7PKX73TU.js.map → app-MSJXFK33.js.map} +0 -0
|
@@ -562,11 +562,11 @@ function formatValibotPath(issue2) {
|
|
|
562
562
|
return formatted;
|
|
563
563
|
}
|
|
564
564
|
function formatConfigSchemaIssue(issue2) {
|
|
565
|
-
const
|
|
565
|
+
const path6 = formatValibotPath(issue2);
|
|
566
566
|
if (issue2.type === "non_empty") {
|
|
567
|
-
return { path:
|
|
567
|
+
return { path: path6, message: `${path6} must not be empty when specified` };
|
|
568
568
|
}
|
|
569
|
-
return { path:
|
|
569
|
+
return { path: path6, message: `${path6}: ${issue2.message}` };
|
|
570
570
|
}
|
|
571
571
|
function collectConfigSchemaErrors(config) {
|
|
572
572
|
const parsed = v.safeParse(configSchema, config, { abortEarly: false });
|
|
@@ -617,12 +617,12 @@ function collectServerBaseUrlErrors(config) {
|
|
|
617
617
|
function collectWorkerRuntimeProfileErrors(config) {
|
|
618
618
|
const errors = [];
|
|
619
619
|
const profileIds = new Set(Object.keys(config.worker_runtime_profiles ?? {}));
|
|
620
|
-
const checkReference = (value,
|
|
620
|
+
const checkReference = (value, path6) => {
|
|
621
621
|
if (typeof value !== "string" || value.trim() === "") {
|
|
622
622
|
return;
|
|
623
623
|
}
|
|
624
624
|
if (!profileIds.has(value)) {
|
|
625
|
-
errors.push(`Unknown worker runtime profile '${value}' at ${
|
|
625
|
+
errors.push(`Unknown worker runtime profile '${value}' at ${path6}`);
|
|
626
626
|
}
|
|
627
627
|
};
|
|
628
628
|
for (const [id, profile] of Object.entries(config.worker_runtime_profiles ?? {})) {
|
|
@@ -970,12 +970,12 @@ function validateConfig(raw) {
|
|
|
970
970
|
const config = applyConfigDefaults(raw);
|
|
971
971
|
return validateResolvedConfig(config);
|
|
972
972
|
}
|
|
973
|
-
function shouldRedactForLogging(
|
|
974
|
-
return SENSITIVE_CONFIG_KEY_PATTERN.test(key) || key === "url" && (
|
|
973
|
+
function shouldRedactForLogging(path6, key) {
|
|
974
|
+
return SENSITIVE_CONFIG_KEY_PATTERN.test(key) || key === "url" && (path6[0] === "notifications" || path6.some((segment) => /webhook/i.test(segment)));
|
|
975
975
|
}
|
|
976
|
-
function sanitizeConfigForLogging(value,
|
|
976
|
+
function sanitizeConfigForLogging(value, path6 = []) {
|
|
977
977
|
if (Array.isArray(value)) {
|
|
978
|
-
return value.map((entry, index2) => sanitizeConfigForLogging(entry, [...
|
|
978
|
+
return value.map((entry, index2) => sanitizeConfigForLogging(entry, [...path6, String(index2)]));
|
|
979
979
|
}
|
|
980
980
|
const parsedRecord = v.safeParse(unknownRecordSchema, value);
|
|
981
981
|
if (!parsedRecord.success) {
|
|
@@ -983,11 +983,11 @@ function sanitizeConfigForLogging(value, path5 = []) {
|
|
|
983
983
|
}
|
|
984
984
|
const sanitized = {};
|
|
985
985
|
for (const [key, entry] of Object.entries(parsedRecord.output)) {
|
|
986
|
-
if (shouldRedactForLogging(
|
|
986
|
+
if (shouldRedactForLogging(path6, key)) {
|
|
987
987
|
sanitized[key] = entry === "" ? "" : REDACTED_LOG_VALUE;
|
|
988
988
|
continue;
|
|
989
989
|
}
|
|
990
|
-
sanitized[key] = sanitizeConfigForLogging(entry, [...
|
|
990
|
+
sanitized[key] = sanitizeConfigForLogging(entry, [...path6, key]);
|
|
991
991
|
}
|
|
992
992
|
return sanitized;
|
|
993
993
|
}
|
|
@@ -1118,7 +1118,9 @@ import { DatabaseSync } from "node:sqlite";
|
|
|
1118
1118
|
import { drizzle } from "drizzle-orm/node-sqlite";
|
|
1119
1119
|
|
|
1120
1120
|
// src/db/schema.ts
|
|
1121
|
-
import {
|
|
1121
|
+
import {
|
|
1122
|
+
SERIALIZED_SYSTEM_ACTOR
|
|
1123
|
+
} from "@leitwerk-dev/domain";
|
|
1122
1124
|
import { sql } from "drizzle-orm";
|
|
1123
1125
|
import {
|
|
1124
1126
|
blob,
|
|
@@ -1510,7 +1512,10 @@ var turnRecords = sqliteTable(
|
|
|
1510
1512
|
startedAt: text("started_at").notNull(),
|
|
1511
1513
|
endedAt: text("ended_at"),
|
|
1512
1514
|
modelSelectionKind: text("model_selection_kind"),
|
|
1513
|
-
modelSelectionSource: text("model_selection_source")
|
|
1515
|
+
modelSelectionSource: text("model_selection_source"),
|
|
1516
|
+
mappedRunId: text("mapped_run_id"),
|
|
1517
|
+
mappedItemKey: text("mapped_item_key"),
|
|
1518
|
+
mappedItemIndex: integer2("mapped_item_index")
|
|
1514
1519
|
},
|
|
1515
1520
|
(t) => [
|
|
1516
1521
|
uniqueIndex("uq_turn_records_instance_id").on(t.instanceId, t.id),
|
|
@@ -1538,7 +1543,10 @@ var turnStartRecords = sqliteTable(
|
|
|
1538
1543
|
continuationJson: text("continuation_json"),
|
|
1539
1544
|
stateJson: text("state_json").notNull(),
|
|
1540
1545
|
createdAt: text("created_at").notNull(),
|
|
1541
|
-
updatedAt: text("updated_at").notNull()
|
|
1546
|
+
updatedAt: text("updated_at").notNull(),
|
|
1547
|
+
mappedRunId: text("mapped_run_id"),
|
|
1548
|
+
mappedItemKey: text("mapped_item_key"),
|
|
1549
|
+
mappedItemIndex: integer2("mapped_item_index")
|
|
1542
1550
|
},
|
|
1543
1551
|
(t) => [
|
|
1544
1552
|
uniqueIndex("uq_turn_start_records_proposed_turn_record").on(t.proposedTurnRecordId),
|
|
@@ -1815,6 +1823,55 @@ var externalWriteLog = sqliteTable(
|
|
|
1815
1823
|
index("idx_ewl_write_type").on(t.writeType)
|
|
1816
1824
|
]
|
|
1817
1825
|
);
|
|
1826
|
+
var mappedLlmRuns = sqliteTable(
|
|
1827
|
+
"mapped_llm_runs",
|
|
1828
|
+
{
|
|
1829
|
+
id: text("id").primaryKey(),
|
|
1830
|
+
instanceId: text("instance_id").notNull().references(() => processInstances.id, { onDelete: "cascade" }),
|
|
1831
|
+
turnId: text("turn_id").notNull(),
|
|
1832
|
+
status: text("status").$type().notNull(),
|
|
1833
|
+
itemCount: integer2("item_count").notNull(),
|
|
1834
|
+
nextIndex: integer2("next_index").notNull(),
|
|
1835
|
+
createdAt: text("created_at").notNull(),
|
|
1836
|
+
updatedAt: text("updated_at").notNull()
|
|
1837
|
+
},
|
|
1838
|
+
(t) => [
|
|
1839
|
+
index("idx_mapped_llm_runs_instance").on(t.instanceId),
|
|
1840
|
+
uniqueIndex("uq_mapped_llm_runs_active_instance").on(t.instanceId).where(sql`${t.status} = 'active'`),
|
|
1841
|
+
check2("mapped_llm_runs_status", sql`${t.status} in ('active', 'completed', 'aborted')`),
|
|
1842
|
+
check2(
|
|
1843
|
+
"mapped_llm_runs_progress",
|
|
1844
|
+
sql`${t.itemCount} >= 0 and ${t.nextIndex} >= 0 and ${t.nextIndex} <= ${t.itemCount}`
|
|
1845
|
+
)
|
|
1846
|
+
]
|
|
1847
|
+
);
|
|
1848
|
+
var mappedLlmItems = sqliteTable(
|
|
1849
|
+
"mapped_llm_items",
|
|
1850
|
+
{
|
|
1851
|
+
runId: text("run_id").notNull().references(() => mappedLlmRuns.id, { onDelete: "cascade" }),
|
|
1852
|
+
instanceId: text("instance_id").notNull().references(() => processInstances.id, { onDelete: "cascade" }),
|
|
1853
|
+
itemIndex: integer2("item_index").notNull(),
|
|
1854
|
+
itemKey: text("item_key").notNull(),
|
|
1855
|
+
label: text("label").notNull(),
|
|
1856
|
+
itemJson: text("item_json").notNull(),
|
|
1857
|
+
status: text("status").$type().notNull().default("pending"),
|
|
1858
|
+
outcome: text("outcome"),
|
|
1859
|
+
resultJson: text("result_json"),
|
|
1860
|
+
turnRecordId: text("turn_record_id"),
|
|
1861
|
+
completedAt: text("completed_at")
|
|
1862
|
+
},
|
|
1863
|
+
(t) => [
|
|
1864
|
+
uniqueIndex("uq_mapped_llm_items_run_index").on(t.runId, t.itemIndex),
|
|
1865
|
+
uniqueIndex("uq_mapped_llm_items_run_key").on(t.runId, t.itemKey),
|
|
1866
|
+
index("idx_mapped_llm_items_instance").on(t.instanceId),
|
|
1867
|
+
check2("mapped_llm_items_status", sql`${t.status} in ('pending', 'completed')`),
|
|
1868
|
+
check2("mapped_llm_items_item_json", sql`json_valid(${t.itemJson})`),
|
|
1869
|
+
check2(
|
|
1870
|
+
"mapped_llm_items_result",
|
|
1871
|
+
sql`(${t.status} = 'pending' and ${t.resultJson} is null) or (${t.status} = 'completed' and ${t.resultJson} is not null and json_valid(${t.resultJson}))`
|
|
1872
|
+
)
|
|
1873
|
+
]
|
|
1874
|
+
);
|
|
1818
1875
|
var BASELINE_TABLE_CONSTRAINTS = {
|
|
1819
1876
|
skills: [
|
|
1820
1877
|
"CONSTRAINT fk_skills_active_revision FOREIGN KEY (active_revision_id) REFERENCES skill_revisions(id)"
|
|
@@ -2003,6 +2060,8 @@ var ALL_TABLES = [
|
|
|
2003
2060
|
processLeafOutcomeSnapshots,
|
|
2004
2061
|
turnRecords,
|
|
2005
2062
|
turnStartRecords,
|
|
2063
|
+
mappedLlmRuns,
|
|
2064
|
+
mappedLlmItems,
|
|
2006
2065
|
apiTokens,
|
|
2007
2066
|
authSessions,
|
|
2008
2067
|
authLoginFlows,
|
|
@@ -2524,6 +2583,27 @@ var KNOWN_MIGRATIONS = [
|
|
|
2524
2583
|
sqlite.exec("DROP TABLE provider_credentials_before_20260724");
|
|
2525
2584
|
}
|
|
2526
2585
|
},
|
|
2586
|
+
{
|
|
2587
|
+
// Runs before 20260821 so its legacy turn_records validation sees these columns.
|
|
2588
|
+
id: "20260922_add_mapped_llm_runs",
|
|
2589
|
+
tableNames: ["mapped_llm_runs", "mapped_llm_items", "turn_records", "turn_start_records"],
|
|
2590
|
+
matches: (sqlite) => hasExistingSchema(sqlite) && (existingTableSql(sqlite, "mapped_llm_runs") === null || existingTableSql(sqlite, "mapped_llm_items") === null || !tableHasColumn(sqlite, "turn_records", "mapped_run_id") || !tableHasColumn(sqlite, "turn_start_records", "mapped_run_id")),
|
|
2591
|
+
apply(sqlite) {
|
|
2592
|
+
for (const table of ["turn_records", "turn_start_records"]) {
|
|
2593
|
+
if (!tableHasColumn(sqlite, table, "mapped_run_id")) {
|
|
2594
|
+
sqlite.exec(`ALTER TABLE ${table} ADD COLUMN mapped_run_id text;
|
|
2595
|
+
ALTER TABLE ${table} ADD COLUMN mapped_item_key text;
|
|
2596
|
+
ALTER TABLE ${table} ADD COLUMN mapped_item_index integer;`);
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
if (existingTableSql(sqlite, "mapped_llm_runs") === null) {
|
|
2600
|
+
createTableWithIndexes(sqlite, mappedLlmRuns);
|
|
2601
|
+
}
|
|
2602
|
+
if (existingTableSql(sqlite, "mapped_llm_items") === null) {
|
|
2603
|
+
createTableWithIndexes(sqlite, mappedLlmItems);
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
},
|
|
2527
2607
|
{
|
|
2528
2608
|
id: "20260821_remove_server_automatic_execution",
|
|
2529
2609
|
tableNames: ["process_instances", "turn_records"],
|
|
@@ -2905,6 +2985,9 @@ import { and as and2, eq as eq4, gt, lt } from "drizzle-orm";
|
|
|
2905
2985
|
|
|
2906
2986
|
// src/db/repo-helpers.ts
|
|
2907
2987
|
import { asUnknownRecord } from "@leitwerk-dev/domain";
|
|
2988
|
+
function mappedItemRef(row) {
|
|
2989
|
+
return row.mappedRunId !== null && row.mappedItemKey !== null && row.mappedItemIndex !== null ? { runId: row.mappedRunId, itemKey: row.mappedItemKey, itemIndex: row.mappedItemIndex } : null;
|
|
2990
|
+
}
|
|
2908
2991
|
function parsePersistedJson(value, label) {
|
|
2909
2992
|
try {
|
|
2910
2993
|
return JSON.parse(value);
|
|
@@ -3432,8 +3515,111 @@ function createLauncherRecentValueRepo(db) {
|
|
|
3432
3515
|
};
|
|
3433
3516
|
}
|
|
3434
3517
|
|
|
3435
|
-
// src/db/
|
|
3518
|
+
// src/db/mapped-llm-run-repo.ts
|
|
3436
3519
|
import { and as and6, asc as asc3, eq as eq9 } from "drizzle-orm";
|
|
3520
|
+
function createMappedLlmRunRepo(db) {
|
|
3521
|
+
return {
|
|
3522
|
+
/** @internal */
|
|
3523
|
+
create(input) {
|
|
3524
|
+
const ts = now();
|
|
3525
|
+
const run = {
|
|
3526
|
+
id: input.id,
|
|
3527
|
+
instanceId: input.instanceId,
|
|
3528
|
+
turnId: input.turnId,
|
|
3529
|
+
status: input.status,
|
|
3530
|
+
itemCount: input.items.length,
|
|
3531
|
+
nextIndex: input.status === "completed" ? input.items.length : 0,
|
|
3532
|
+
createdAt: ts,
|
|
3533
|
+
updatedAt: ts
|
|
3534
|
+
};
|
|
3535
|
+
db.insert(mappedLlmRuns).values(run).run();
|
|
3536
|
+
for (const item of input.items) {
|
|
3537
|
+
db.insert(mappedLlmItems).values({
|
|
3538
|
+
runId: input.id,
|
|
3539
|
+
instanceId: input.instanceId,
|
|
3540
|
+
itemIndex: item.itemIndex,
|
|
3541
|
+
itemKey: item.itemKey,
|
|
3542
|
+
label: item.label,
|
|
3543
|
+
itemJson: item.itemJson,
|
|
3544
|
+
status: "pending"
|
|
3545
|
+
}).run();
|
|
3546
|
+
}
|
|
3547
|
+
return run;
|
|
3548
|
+
},
|
|
3549
|
+
/** @internal */
|
|
3550
|
+
getById(id) {
|
|
3551
|
+
return db.select().from(mappedLlmRuns).where(eq9(mappedLlmRuns.id, id)).get() ?? null;
|
|
3552
|
+
},
|
|
3553
|
+
/** @internal */
|
|
3554
|
+
getActiveByInstance(instanceId) {
|
|
3555
|
+
return db.select().from(mappedLlmRuns).where(
|
|
3556
|
+
and6(eq9(mappedLlmRuns.instanceId, instanceId), eq9(mappedLlmRuns.status, "active"))
|
|
3557
|
+
).get() ?? null;
|
|
3558
|
+
},
|
|
3559
|
+
/** @internal */
|
|
3560
|
+
listByInstance(instanceId) {
|
|
3561
|
+
return db.select().from(mappedLlmRuns).where(eq9(mappedLlmRuns.instanceId, instanceId)).orderBy(asc3(mappedLlmRuns.createdAt)).all();
|
|
3562
|
+
},
|
|
3563
|
+
/** @internal */
|
|
3564
|
+
listItems(runId) {
|
|
3565
|
+
return db.select().from(mappedLlmItems).where(eq9(mappedLlmItems.runId, runId)).orderBy(asc3(mappedLlmItems.itemIndex)).all();
|
|
3566
|
+
},
|
|
3567
|
+
/** @internal */
|
|
3568
|
+
listItemsByInstance(instanceId) {
|
|
3569
|
+
return db.select().from(mappedLlmItems).where(eq9(mappedLlmItems.instanceId, instanceId)).all();
|
|
3570
|
+
},
|
|
3571
|
+
/** @internal */
|
|
3572
|
+
getItem(runId, itemIndex) {
|
|
3573
|
+
return db.select().from(mappedLlmItems).where(and6(eq9(mappedLlmItems.runId, runId), eq9(mappedLlmItems.itemIndex, itemIndex))).get() ?? null;
|
|
3574
|
+
},
|
|
3575
|
+
/**
|
|
3576
|
+
* Records one item result and advances the run. Fails unless the item is the
|
|
3577
|
+
* run's current pending item, so a replayed outcome cannot complete it twice.
|
|
3578
|
+
* @internal
|
|
3579
|
+
*/
|
|
3580
|
+
completeItem(input) {
|
|
3581
|
+
const run = this.getById(input.runId);
|
|
3582
|
+
if (!run || run.status !== "active" || run.nextIndex !== input.itemIndex) {
|
|
3583
|
+
throw new Error(`Mapped item ${input.itemIndex} of run '${input.runId}' is not current`);
|
|
3584
|
+
}
|
|
3585
|
+
const ts = now();
|
|
3586
|
+
const updated = db.update(mappedLlmItems).set({
|
|
3587
|
+
status: "completed",
|
|
3588
|
+
outcome: input.outcome,
|
|
3589
|
+
resultJson: input.resultJson,
|
|
3590
|
+
turnRecordId: input.turnRecordId,
|
|
3591
|
+
completedAt: ts
|
|
3592
|
+
}).where(
|
|
3593
|
+
and6(
|
|
3594
|
+
eq9(mappedLlmItems.runId, input.runId),
|
|
3595
|
+
eq9(mappedLlmItems.itemIndex, input.itemIndex),
|
|
3596
|
+
eq9(mappedLlmItems.status, "pending")
|
|
3597
|
+
)
|
|
3598
|
+
).run();
|
|
3599
|
+
if (updated.changes !== 1) {
|
|
3600
|
+
throw new Error(`Mapped item ${input.itemIndex} of run '${input.runId}' is not pending`);
|
|
3601
|
+
}
|
|
3602
|
+
const nextIndex = input.itemIndex + 1;
|
|
3603
|
+
db.update(mappedLlmRuns).set({
|
|
3604
|
+
nextIndex,
|
|
3605
|
+
status: nextIndex === run.itemCount ? "completed" : "active",
|
|
3606
|
+
updatedAt: ts
|
|
3607
|
+
}).where(eq9(mappedLlmRuns.id, input.runId)).run();
|
|
3608
|
+
return this.getById(input.runId);
|
|
3609
|
+
},
|
|
3610
|
+
/** @internal */
|
|
3611
|
+
abortActiveByInstance(instanceId) {
|
|
3612
|
+
return Number(
|
|
3613
|
+
db.update(mappedLlmRuns).set({ status: "aborted", updatedAt: now() }).where(
|
|
3614
|
+
and6(eq9(mappedLlmRuns.instanceId, instanceId), eq9(mappedLlmRuns.status, "active"))
|
|
3615
|
+
).run().changes
|
|
3616
|
+
);
|
|
3617
|
+
}
|
|
3618
|
+
};
|
|
3619
|
+
}
|
|
3620
|
+
|
|
3621
|
+
// src/db/pending-external-source-fire-repo.ts
|
|
3622
|
+
import { and as and7, asc as asc4, eq as eq10 } from "drizzle-orm";
|
|
3437
3623
|
function parseRecord(json) {
|
|
3438
3624
|
const value = JSON.parse(json);
|
|
3439
3625
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
@@ -3478,15 +3664,15 @@ function createPendingExternalSourceFireRepo(db) {
|
|
|
3478
3664
|
},
|
|
3479
3665
|
/** @internal */
|
|
3480
3666
|
listByInstance(instanceId) {
|
|
3481
|
-
return db.select().from(pendingExternalSourceFires).where(
|
|
3667
|
+
return db.select().from(pendingExternalSourceFires).where(eq10(pendingExternalSourceFires.instanceId, instanceId)).orderBy(asc4(pendingExternalSourceFires.createdAt)).all().map(rowToPendingExternalSourceFire);
|
|
3482
3668
|
},
|
|
3483
3669
|
/** @internal */
|
|
3484
3670
|
getByMergeKey(instanceId, armingId, mergeKey) {
|
|
3485
3671
|
const row = db.select().from(pendingExternalSourceFires).where(
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3672
|
+
and7(
|
|
3673
|
+
eq10(pendingExternalSourceFires.instanceId, instanceId),
|
|
3674
|
+
eq10(pendingExternalSourceFires.armingId, armingId),
|
|
3675
|
+
eq10(pendingExternalSourceFires.mergeKey, mergeKey)
|
|
3490
3676
|
)
|
|
3491
3677
|
).get();
|
|
3492
3678
|
return row ? rowToPendingExternalSourceFire(row) : null;
|
|
@@ -3499,13 +3685,13 @@ function createPendingExternalSourceFireRepo(db) {
|
|
|
3499
3685
|
};
|
|
3500
3686
|
if (input.input !== void 0) setValues.inputJson = JSON.stringify(input.input);
|
|
3501
3687
|
if (input.event !== void 0) setValues.eventJson = JSON.stringify(input.event);
|
|
3502
|
-
db.update(pendingExternalSourceFires).set(setValues).where(
|
|
3503
|
-
const row = db.select().from(pendingExternalSourceFires).where(
|
|
3688
|
+
db.update(pendingExternalSourceFires).set(setValues).where(eq10(pendingExternalSourceFires.id, id)).run();
|
|
3689
|
+
const row = db.select().from(pendingExternalSourceFires).where(eq10(pendingExternalSourceFires.id, id)).get();
|
|
3504
3690
|
return row ? rowToPendingExternalSourceFire(row) : null;
|
|
3505
3691
|
},
|
|
3506
3692
|
/** @internal */
|
|
3507
3693
|
delete(id) {
|
|
3508
|
-
const result = db.delete(pendingExternalSourceFires).where(
|
|
3694
|
+
const result = db.delete(pendingExternalSourceFires).where(eq10(pendingExternalSourceFires.id, id)).run();
|
|
3509
3695
|
return result.changes > 0;
|
|
3510
3696
|
}
|
|
3511
3697
|
};
|
|
@@ -3513,7 +3699,7 @@ function createPendingExternalSourceFireRepo(db) {
|
|
|
3513
3699
|
|
|
3514
3700
|
// src/db/process-event-repo.ts
|
|
3515
3701
|
import { applyEventToCompactTurnSummary, emptyCompactTurnSummary } from "@leitwerk-dev/protocol";
|
|
3516
|
-
import { and as
|
|
3702
|
+
import { and as and8, asc as asc5, desc as desc5, eq as eq11, gte, inArray as inArray3, like, sql as sql3 } from "drizzle-orm";
|
|
3517
3703
|
function rowToProcessEvent(row) {
|
|
3518
3704
|
return {
|
|
3519
3705
|
id: row.id,
|
|
@@ -3563,24 +3749,24 @@ function createProcessEventRepo(db) {
|
|
|
3563
3749
|
},
|
|
3564
3750
|
/** @internal */
|
|
3565
3751
|
latestSequence(instanceId) {
|
|
3566
|
-
return db.select({ sequence: processEvents.eventSequence }).from(processEvents).where(
|
|
3752
|
+
return db.select({ sequence: processEvents.eventSequence }).from(processEvents).where(eq11(processEvents.instanceId, instanceId)).orderBy(desc5(processEvents.eventSequence)).limit(1).get()?.sequence ?? 0;
|
|
3567
3753
|
},
|
|
3568
3754
|
/** @internal */
|
|
3569
3755
|
listByTurnRecord(instanceId, turnRecordId) {
|
|
3570
3756
|
return db.select().from(processEvents).where(
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3757
|
+
and8(
|
|
3758
|
+
eq11(processEvents.instanceId, instanceId),
|
|
3759
|
+
eq11(processEvents.turnRecordId, turnRecordId)
|
|
3574
3760
|
)
|
|
3575
|
-
).orderBy(
|
|
3761
|
+
).orderBy(asc5(processEvents.eventSequence)).all().map(rowToProcessEvent);
|
|
3576
3762
|
},
|
|
3577
3763
|
/** @internal */
|
|
3578
3764
|
latestByTurnRecordEventType(instanceId, turnRecordId, eventType) {
|
|
3579
3765
|
const row = db.select().from(processEvents).where(
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3766
|
+
and8(
|
|
3767
|
+
eq11(processEvents.instanceId, instanceId),
|
|
3768
|
+
eq11(processEvents.turnRecordId, turnRecordId),
|
|
3769
|
+
eq11(processEvents.eventType, eventType)
|
|
3584
3770
|
)
|
|
3585
3771
|
).orderBy(desc5(processEvents.eventSequence)).limit(1).get();
|
|
3586
3772
|
return row ? rowToProcessEvent(row) : null;
|
|
@@ -3591,7 +3777,7 @@ function createProcessEventRepo(db) {
|
|
|
3591
3777
|
},
|
|
3592
3778
|
/** @internal */
|
|
3593
3779
|
listByInstance(instanceId, limit = 100) {
|
|
3594
|
-
return listNewest(
|
|
3780
|
+
return listNewest(eq11(processEvents.instanceId, instanceId), limit);
|
|
3595
3781
|
},
|
|
3596
3782
|
/** @internal */
|
|
3597
3783
|
listByInstanceEventTypes(instanceId, eventTypes, limit = 100) {
|
|
@@ -3603,7 +3789,7 @@ function createProcessEventRepo(db) {
|
|
|
3603
3789
|
}
|
|
3604
3790
|
const events = filteredEventTypes.flatMap(
|
|
3605
3791
|
(eventType) => listNewest(
|
|
3606
|
-
|
|
3792
|
+
and8(eq11(processEvents.instanceId, instanceId), eq11(processEvents.eventType, eventType)),
|
|
3607
3793
|
limit
|
|
3608
3794
|
)
|
|
3609
3795
|
);
|
|
@@ -3614,8 +3800,8 @@ function createProcessEventRepo(db) {
|
|
|
3614
3800
|
listByInstanceSince(instanceId, sinceCreatedAt, options = {}) {
|
|
3615
3801
|
const prefix = typeof options.eventTypePrefix === "string" ? options.eventTypePrefix.trim() : "";
|
|
3616
3802
|
return listNewest(
|
|
3617
|
-
|
|
3618
|
-
|
|
3803
|
+
and8(
|
|
3804
|
+
eq11(processEvents.instanceId, instanceId),
|
|
3619
3805
|
gte(processEvents.createdAt, sinceCreatedAt),
|
|
3620
3806
|
prefix ? like(processEvents.eventType, `${prefix}%`) : void 0
|
|
3621
3807
|
),
|
|
@@ -3629,12 +3815,12 @@ function createProcessEventRepo(db) {
|
|
|
3629
3815
|
return [];
|
|
3630
3816
|
}
|
|
3631
3817
|
return db.select().from(processEvents).where(
|
|
3632
|
-
|
|
3633
|
-
|
|
3818
|
+
and8(
|
|
3819
|
+
eq11(processEvents.instanceId, instanceId),
|
|
3634
3820
|
inArray3(processEvents.eventType, filteredEventTypes),
|
|
3635
|
-
|
|
3821
|
+
eq11(processEvents.turnRecordId, turnRecordId)
|
|
3636
3822
|
)
|
|
3637
|
-
).orderBy(
|
|
3823
|
+
).orderBy(asc5(processEvents.eventSequence)).all().map(rowToProcessEvent);
|
|
3638
3824
|
},
|
|
3639
3825
|
/** @internal */
|
|
3640
3826
|
listByInstanceSinceEventTypes(instanceId, sinceCreatedAt, eventTypes, limit = 100) {
|
|
@@ -3643,8 +3829,8 @@ function createProcessEventRepo(db) {
|
|
|
3643
3829
|
return [];
|
|
3644
3830
|
}
|
|
3645
3831
|
return listNewest(
|
|
3646
|
-
|
|
3647
|
-
|
|
3832
|
+
and8(
|
|
3833
|
+
eq11(processEvents.instanceId, instanceId),
|
|
3648
3834
|
gte(processEvents.createdAt, sinceCreatedAt),
|
|
3649
3835
|
inArray3(processEvents.eventType, filteredEventTypes)
|
|
3650
3836
|
),
|
|
@@ -3655,7 +3841,7 @@ function createProcessEventRepo(db) {
|
|
|
3655
3841
|
}
|
|
3656
3842
|
|
|
3657
3843
|
// src/db/process-handoff-dedup-key-repo.ts
|
|
3658
|
-
import { eq as
|
|
3844
|
+
import { eq as eq12 } from "drizzle-orm";
|
|
3659
3845
|
function rowToRecord(row) {
|
|
3660
3846
|
return {
|
|
3661
3847
|
key: row.key,
|
|
@@ -3679,7 +3865,7 @@ function createProcessHandoffDedupKeyRepo(db) {
|
|
|
3679
3865
|
},
|
|
3680
3866
|
/** @internal */
|
|
3681
3867
|
getByKey(key) {
|
|
3682
|
-
const row = db.select().from(processHandoffDedupKeys).where(
|
|
3868
|
+
const row = db.select().from(processHandoffDedupKeys).where(eq12(processHandoffDedupKeys.key, key)).get();
|
|
3683
3869
|
return row ? rowToRecord(row) : null;
|
|
3684
3870
|
}
|
|
3685
3871
|
};
|
|
@@ -3687,7 +3873,7 @@ function createProcessHandoffDedupKeyRepo(db) {
|
|
|
3687
3873
|
|
|
3688
3874
|
// src/db/process-input-repo.ts
|
|
3689
3875
|
import { parseActorOrSystem, SYSTEM_ACTOR, serializeActor } from "@leitwerk-dev/domain";
|
|
3690
|
-
import { and as
|
|
3876
|
+
import { and as and9, asc as asc6, eq as eq13, isNull as isNull2, max } from "drizzle-orm";
|
|
3691
3877
|
function toProcessInputTarget(semanticRef, productName) {
|
|
3692
3878
|
if (productName) {
|
|
3693
3879
|
return { productName };
|
|
@@ -3710,11 +3896,11 @@ function rowToProcessInput(row) {
|
|
|
3710
3896
|
}
|
|
3711
3897
|
function createProcessInputRepo(db) {
|
|
3712
3898
|
const list = (instanceId, unconsumed = false) => db.select().from(processInputs).where(
|
|
3713
|
-
|
|
3714
|
-
|
|
3899
|
+
and9(
|
|
3900
|
+
eq13(processInputs.instanceId, instanceId),
|
|
3715
3901
|
unconsumed ? isNull2(processInputs.consumedAt) : void 0
|
|
3716
3902
|
)
|
|
3717
|
-
).orderBy(
|
|
3903
|
+
).orderBy(asc6(processInputs.sequence)).all().map(rowToProcessInput);
|
|
3718
3904
|
return {
|
|
3719
3905
|
/** @internal */
|
|
3720
3906
|
create(input) {
|
|
@@ -3742,17 +3928,17 @@ function createProcessInputRepo(db) {
|
|
|
3742
3928
|
listUnconsumed: (instanceId) => list(instanceId, true),
|
|
3743
3929
|
/** @internal */
|
|
3744
3930
|
markConsumed(id) {
|
|
3745
|
-
const result = db.update(processInputs).set({ consumedAt: now() }).where(
|
|
3931
|
+
const result = db.update(processInputs).set({ consumedAt: now() }).where(eq13(processInputs.id, id)).run();
|
|
3746
3932
|
return result.changes > 0;
|
|
3747
3933
|
},
|
|
3748
3934
|
/** @internal */
|
|
3749
3935
|
delete(id) {
|
|
3750
|
-
const result = db.delete(processInputs).where(
|
|
3936
|
+
const result = db.delete(processInputs).where(eq13(processInputs.id, id)).run();
|
|
3751
3937
|
return result.changes > 0;
|
|
3752
3938
|
},
|
|
3753
3939
|
/** @internal */
|
|
3754
3940
|
getMaxSequence(instanceId) {
|
|
3755
|
-
const row = db.select({ sequence: max(processInputs.sequence) }).from(processInputs).where(
|
|
3941
|
+
const row = db.select({ sequence: max(processInputs.sequence) }).from(processInputs).where(eq13(processInputs.instanceId, instanceId)).get();
|
|
3756
3942
|
return row?.sequence ?? 0;
|
|
3757
3943
|
}
|
|
3758
3944
|
};
|
|
@@ -3762,7 +3948,7 @@ function createProcessInputRepo(db) {
|
|
|
3762
3948
|
import {
|
|
3763
3949
|
isProcessSelectedTurnModelSource
|
|
3764
3950
|
} from "@leitwerk-dev/domain";
|
|
3765
|
-
import { and as
|
|
3951
|
+
import { and as and10, asc as asc7, count as count2, desc as desc6, eq as eq14, inArray as inArray4, notInArray, or as or2, sql as sql4 } from "drizzle-orm";
|
|
3766
3952
|
|
|
3767
3953
|
// src/launch-title.ts
|
|
3768
3954
|
var MAX_PROCESS_TITLE_LENGTH = 80;
|
|
@@ -3809,7 +3995,7 @@ function overviewPredicates2(input) {
|
|
|
3809
3995
|
const predicates = [];
|
|
3810
3996
|
const processType = input.processType?.trim();
|
|
3811
3997
|
if (processType) {
|
|
3812
|
-
predicates.push(
|
|
3998
|
+
predicates.push(eq14(processInstances.processId, processType));
|
|
3813
3999
|
}
|
|
3814
4000
|
switch (input.status ?? "all") {
|
|
3815
4001
|
case "running":
|
|
@@ -3819,10 +4005,10 @@ function overviewPredicates2(input) {
|
|
|
3819
4005
|
predicates.push(inArray4(processInstances.lifecycleStatus, ["waiting", "error"]));
|
|
3820
4006
|
break;
|
|
3821
4007
|
case "completed":
|
|
3822
|
-
predicates.push(
|
|
4008
|
+
predicates.push(eq14(processInstances.lifecycleStatus, "completed"));
|
|
3823
4009
|
break;
|
|
3824
4010
|
case "aborted":
|
|
3825
|
-
predicates.push(
|
|
4011
|
+
predicates.push(eq14(processInstances.lifecycleStatus, "aborted"));
|
|
3826
4012
|
break;
|
|
3827
4013
|
case "scheduled":
|
|
3828
4014
|
predicates.push(sql4`0 = 1`);
|
|
@@ -3844,7 +4030,7 @@ function overviewPredicates2(input) {
|
|
|
3844
4030
|
}
|
|
3845
4031
|
function overviewWhere2(input) {
|
|
3846
4032
|
const predicates = overviewPredicates2(input);
|
|
3847
|
-
return predicates.length ?
|
|
4033
|
+
return predicates.length ? and10(...predicates) : void 0;
|
|
3848
4034
|
}
|
|
3849
4035
|
function parseLaunchIntent(raw) {
|
|
3850
4036
|
if (!raw) return null;
|
|
@@ -3884,7 +4070,7 @@ function createProcessInstanceRepo(db) {
|
|
|
3884
4070
|
return {
|
|
3885
4071
|
/** @internal */
|
|
3886
4072
|
getLaunchIntent(instanceId) {
|
|
3887
|
-
const row = db.select({ launchIntentJson: processInstances.launchIntentJson }).from(processInstances).where(
|
|
4073
|
+
const row = db.select({ launchIntentJson: processInstances.launchIntentJson }).from(processInstances).where(eq14(processInstances.id, instanceId)).get();
|
|
3888
4074
|
return parseLaunchIntent(row?.launchIntentJson ?? null);
|
|
3889
4075
|
},
|
|
3890
4076
|
/** @public */
|
|
@@ -3921,7 +4107,7 @@ function createProcessInstanceRepo(db) {
|
|
|
3921
4107
|
},
|
|
3922
4108
|
/** @public */
|
|
3923
4109
|
getById(id) {
|
|
3924
|
-
const row = db.select().from(processInstances).where(
|
|
4110
|
+
const row = db.select().from(processInstances).where(eq14(processInstances.id, id)).get();
|
|
3925
4111
|
return row ? rowToProcessInstance(row) : null;
|
|
3926
4112
|
},
|
|
3927
4113
|
/** @public */
|
|
@@ -3930,7 +4116,7 @@ function createProcessInstanceRepo(db) {
|
|
|
3930
4116
|
},
|
|
3931
4117
|
/** @internal */
|
|
3932
4118
|
listCurrent(limit) {
|
|
3933
|
-
return db.select().from(processInstances).where(notInArray(processInstances.lifecycleStatus, ["completed", "aborted"])).orderBy(desc6(processInstances.updatedAt),
|
|
4119
|
+
return db.select().from(processInstances).where(notInArray(processInstances.lifecycleStatus, ["completed", "aborted"])).orderBy(desc6(processInstances.updatedAt), asc7(processInstances.id)).limit(limit).all().map(rowToProcessInstance);
|
|
3934
4120
|
},
|
|
3935
4121
|
/** @internal */
|
|
3936
4122
|
countCurrent() {
|
|
@@ -3956,7 +4142,7 @@ function createProcessInstanceRepo(db) {
|
|
|
3956
4142
|
processId: processInstances.processId,
|
|
3957
4143
|
/** @internal */
|
|
3958
4144
|
value: count2()
|
|
3959
|
-
}).from(processInstances).where(overviewWhere2(input)).groupBy(processInstances.processId).orderBy(
|
|
4145
|
+
}).from(processInstances).where(overviewWhere2(input)).groupBy(processInstances.processId).orderBy(asc7(processInstances.processId)).all();
|
|
3960
4146
|
},
|
|
3961
4147
|
/** @internal */
|
|
3962
4148
|
listOverviewWindow(input) {
|
|
@@ -3972,9 +4158,9 @@ function createProcessInstanceRepo(db) {
|
|
|
3972
4158
|
else ${processInstances.updatedAt} end`;
|
|
3973
4159
|
const primary = input.sortKey === "status" ? status : input.sortKey === "title" ? title : timeline;
|
|
3974
4160
|
return db.select().from(processInstances).where(overviewWhere2(input)).orderBy(
|
|
3975
|
-
input.sortDirection === "desc" ? desc6(primary) :
|
|
3976
|
-
|
|
3977
|
-
|
|
4161
|
+
input.sortDirection === "desc" ? desc6(primary) : asc7(primary),
|
|
4162
|
+
asc7(title),
|
|
4163
|
+
asc7(processInstances.id)
|
|
3978
4164
|
).limit(input.limit).all().map(rowToProcessInstance);
|
|
3979
4165
|
},
|
|
3980
4166
|
/** @internal */
|
|
@@ -3984,8 +4170,8 @@ function createProcessInstanceRepo(db) {
|
|
|
3984
4170
|
return null;
|
|
3985
4171
|
}
|
|
3986
4172
|
const result = db.update(processInstances).set({ title: normalizedTitle, updatedAt: now() }).where(
|
|
3987
|
-
|
|
3988
|
-
|
|
4173
|
+
and10(
|
|
4174
|
+
eq14(processInstances.id, id),
|
|
3989
4175
|
sql4`trim(coalesce(${processInstances.title}, '')) = ''`
|
|
3990
4176
|
)
|
|
3991
4177
|
).run();
|
|
@@ -4019,19 +4205,19 @@ function createProcessInstanceRepo(db) {
|
|
|
4019
4205
|
if (isTerminalLifecycleStatus(input.lifecycleStatus)) {
|
|
4020
4206
|
setValues.closedAt = sql4`coalesce(${processInstances.closedAt}, ${ts})`;
|
|
4021
4207
|
}
|
|
4022
|
-
db.update(processInstances).set(setValues).where(
|
|
4208
|
+
db.update(processInstances).set(setValues).where(eq14(processInstances.id, id)).run();
|
|
4023
4209
|
return this.getById(id);
|
|
4024
4210
|
},
|
|
4025
4211
|
/** @internal */
|
|
4026
4212
|
delete(id) {
|
|
4027
|
-
const result = db.delete(processInstances).where(
|
|
4213
|
+
const result = db.delete(processInstances).where(eq14(processInstances.id, id)).run();
|
|
4028
4214
|
return result.changes > 0;
|
|
4029
4215
|
}
|
|
4030
4216
|
};
|
|
4031
4217
|
}
|
|
4032
4218
|
|
|
4033
4219
|
// src/db/process-leaf-outcome-snapshot-repo.ts
|
|
4034
|
-
import { and as
|
|
4220
|
+
import { and as and11, asc as asc8, desc as desc7, eq as eq15, sql as sql5 } from "drizzle-orm";
|
|
4035
4221
|
function rowToProcessLeafOutcomeSnapshot(row) {
|
|
4036
4222
|
return {
|
|
4037
4223
|
id: row.id,
|
|
@@ -4073,17 +4259,17 @@ function createProcessLeafOutcomeSnapshotRepo(db) {
|
|
|
4073
4259
|
},
|
|
4074
4260
|
/** @internal */
|
|
4075
4261
|
listByInstance(instanceId) {
|
|
4076
|
-
return db.select().from(processLeafOutcomeSnapshots).where(
|
|
4077
|
-
|
|
4078
|
-
|
|
4262
|
+
return db.select().from(processLeafOutcomeSnapshots).where(eq15(processLeafOutcomeSnapshots.instanceId, instanceId)).orderBy(
|
|
4263
|
+
asc8(processLeafOutcomeSnapshots.anchoredAt),
|
|
4264
|
+
asc8(processLeafOutcomeSnapshots.createdAt)
|
|
4079
4265
|
).all().map(rowToProcessLeafOutcomeSnapshot);
|
|
4080
4266
|
},
|
|
4081
4267
|
/** @internal */
|
|
4082
4268
|
getByInstanceAndLeafEntryId(instanceId, leafEntryId) {
|
|
4083
4269
|
const row = db.select().from(processLeafOutcomeSnapshots).where(
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4270
|
+
and11(
|
|
4271
|
+
eq15(processLeafOutcomeSnapshots.instanceId, instanceId),
|
|
4272
|
+
eq15(processLeafOutcomeSnapshots.leafEntryId, leafEntryId)
|
|
4087
4273
|
)
|
|
4088
4274
|
).orderBy(desc7(processLeafOutcomeSnapshots.createdAt), desc7(sql5`rowid`)).limit(1).get();
|
|
4089
4275
|
return row ? rowToProcessLeafOutcomeSnapshot(row) : null;
|
|
@@ -4096,7 +4282,7 @@ import {
|
|
|
4096
4282
|
assertRepoLocator,
|
|
4097
4283
|
detectRepoLocatorKind
|
|
4098
4284
|
} from "@leitwerk-dev/domain";
|
|
4099
|
-
import { and as
|
|
4285
|
+
import { and as and12, eq as eq16, inArray as inArray5 } from "drizzle-orm";
|
|
4100
4286
|
function rowToProcessProject(row) {
|
|
4101
4287
|
return {
|
|
4102
4288
|
id: row.id,
|
|
@@ -4142,12 +4328,12 @@ function createProcessProjectRepo(db) {
|
|
|
4142
4328
|
},
|
|
4143
4329
|
/** @internal */
|
|
4144
4330
|
getById(id) {
|
|
4145
|
-
const row = db.select().from(processProjects).where(
|
|
4331
|
+
const row = db.select().from(processProjects).where(eq16(processProjects.id, id)).get();
|
|
4146
4332
|
return row ? rowToProcessProject(row) : null;
|
|
4147
4333
|
},
|
|
4148
4334
|
/** @public */
|
|
4149
4335
|
listByInstance(instanceId) {
|
|
4150
|
-
return db.select().from(processProjects).where(
|
|
4336
|
+
return db.select().from(processProjects).where(eq16(processProjects.instanceId, instanceId)).all().map(rowToProcessProject);
|
|
4151
4337
|
},
|
|
4152
4338
|
/** @internal */
|
|
4153
4339
|
listByInstances(instanceIds) {
|
|
@@ -4158,7 +4344,7 @@ function createProcessProjectRepo(db) {
|
|
|
4158
4344
|
},
|
|
4159
4345
|
/** @internal */
|
|
4160
4346
|
getByInstanceAndKey(instanceId, key) {
|
|
4161
|
-
const row = db.select().from(processProjects).where(
|
|
4347
|
+
const row = db.select().from(processProjects).where(and12(eq16(processProjects.instanceId, instanceId), eq16(processProjects.key, key))).get();
|
|
4162
4348
|
return row ? rowToProcessProject(row) : null;
|
|
4163
4349
|
},
|
|
4164
4350
|
/** @public */
|
|
@@ -4183,15 +4369,15 @@ function createProcessProjectRepo(db) {
|
|
|
4183
4369
|
}
|
|
4184
4370
|
if (input.metadata !== void 0)
|
|
4185
4371
|
setValues.metadata = input.metadata ? JSON.stringify(input.metadata) : null;
|
|
4186
|
-
db.update(processProjects).set(setValues).where(
|
|
4187
|
-
const row = db.select().from(processProjects).where(
|
|
4372
|
+
db.update(processProjects).set(setValues).where(eq16(processProjects.id, id)).run();
|
|
4373
|
+
const row = db.select().from(processProjects).where(eq16(processProjects.id, id)).get();
|
|
4188
4374
|
return row ? rowToProcessProject(row) : null;
|
|
4189
4375
|
}
|
|
4190
4376
|
};
|
|
4191
4377
|
}
|
|
4192
4378
|
|
|
4193
4379
|
// src/db/process-question-request-repo.ts
|
|
4194
|
-
import { and as
|
|
4380
|
+
import { and as and13, asc as asc9, eq as eq17 } from "drizzle-orm";
|
|
4195
4381
|
function map(row) {
|
|
4196
4382
|
return {
|
|
4197
4383
|
id: row.id,
|
|
@@ -4209,15 +4395,15 @@ function map(row) {
|
|
|
4209
4395
|
}
|
|
4210
4396
|
function createProcessQuestionRequestRepo(db) {
|
|
4211
4397
|
const getById = (id) => {
|
|
4212
|
-
const row = db.select().from(processQuestionRequests).where(
|
|
4398
|
+
const row = db.select().from(processQuestionRequests).where(eq17(processQuestionRequests.id, id)).get();
|
|
4213
4399
|
return row ? map(row) : null;
|
|
4214
4400
|
};
|
|
4215
4401
|
const list = (instanceId, openOnly = false) => {
|
|
4216
4402
|
const filters = [
|
|
4217
|
-
...instanceId ? [
|
|
4218
|
-
...openOnly ? [
|
|
4403
|
+
...instanceId ? [eq17(processQuestionRequests.instanceId, instanceId)] : [],
|
|
4404
|
+
...openOnly ? [eq17(processQuestionRequests.status, "open")] : []
|
|
4219
4405
|
];
|
|
4220
|
-
return db.select().from(processQuestionRequests).where(filters.length ?
|
|
4406
|
+
return db.select().from(processQuestionRequests).where(filters.length ? and13(...filters) : void 0).orderBy(asc9(processQuestionRequests.askedAt)).all().map(map);
|
|
4221
4407
|
};
|
|
4222
4408
|
return {
|
|
4223
4409
|
/** @internal */
|
|
@@ -4229,10 +4415,10 @@ function createProcessQuestionRequestRepo(db) {
|
|
|
4229
4415
|
/** @internal */
|
|
4230
4416
|
createIdempotent(input) {
|
|
4231
4417
|
const existingRow = db.select().from(processQuestionRequests).where(
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4418
|
+
and13(
|
|
4419
|
+
eq17(processQuestionRequests.instanceId, input.instanceId),
|
|
4420
|
+
eq17(processQuestionRequests.turnRecordId, input.turnRecordId),
|
|
4421
|
+
eq17(processQuestionRequests.toolCallId, input.toolCallId)
|
|
4236
4422
|
)
|
|
4237
4423
|
).get();
|
|
4238
4424
|
if (existingRow) {
|
|
@@ -4260,9 +4446,9 @@ function createProcessQuestionRequestRepo(db) {
|
|
|
4260
4446
|
answeredAt: input.answeredAt ?? now(),
|
|
4261
4447
|
answeredByJson: JSON.stringify(input.actor)
|
|
4262
4448
|
}).where(
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4449
|
+
and13(
|
|
4450
|
+
eq17(processQuestionRequests.id, input.id),
|
|
4451
|
+
eq17(processQuestionRequests.status, "open")
|
|
4266
4452
|
)
|
|
4267
4453
|
).returning().get();
|
|
4268
4454
|
return row ? map(row) : null;
|
|
@@ -4271,10 +4457,10 @@ function createProcessQuestionRequestRepo(db) {
|
|
|
4271
4457
|
cancelOpenByTurn(instanceId, turnRecordId) {
|
|
4272
4458
|
return Number(
|
|
4273
4459
|
db.update(processQuestionRequests).set({ status: "cancelled", cancelledAt: now() }).where(
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4460
|
+
and13(
|
|
4461
|
+
eq17(processQuestionRequests.instanceId, instanceId),
|
|
4462
|
+
eq17(processQuestionRequests.turnRecordId, turnRecordId),
|
|
4463
|
+
eq17(processQuestionRequests.status, "open")
|
|
4278
4464
|
)
|
|
4279
4465
|
).run().changes
|
|
4280
4466
|
);
|
|
@@ -4283,7 +4469,7 @@ function createProcessQuestionRequestRepo(db) {
|
|
|
4283
4469
|
}
|
|
4284
4470
|
|
|
4285
4471
|
// src/db/process-relation-repo.ts
|
|
4286
|
-
import { asc as
|
|
4472
|
+
import { asc as asc10, eq as eq18 } from "drizzle-orm";
|
|
4287
4473
|
function map2(row) {
|
|
4288
4474
|
return {
|
|
4289
4475
|
parentInstanceId: row.parentInstanceId,
|
|
@@ -4310,18 +4496,18 @@ function createProcessRelationRepo(db) {
|
|
|
4310
4496
|
},
|
|
4311
4497
|
/** @internal */
|
|
4312
4498
|
getByChild(childInstanceId) {
|
|
4313
|
-
const row = db.select().from(processRelations).where(
|
|
4499
|
+
const row = db.select().from(processRelations).where(eq18(processRelations.childInstanceId, childInstanceId)).get();
|
|
4314
4500
|
return row ? map2(row) : null;
|
|
4315
4501
|
},
|
|
4316
4502
|
/** @internal */
|
|
4317
4503
|
listByParent(parentInstanceId) {
|
|
4318
|
-
return db.select().from(processRelations).where(
|
|
4504
|
+
return db.select().from(processRelations).where(eq18(processRelations.parentInstanceId, parentInstanceId)).orderBy(asc10(processRelations.createdAt)).all().map(map2);
|
|
4319
4505
|
}
|
|
4320
4506
|
};
|
|
4321
4507
|
}
|
|
4322
4508
|
|
|
4323
4509
|
// src/db/process-skill-repo.ts
|
|
4324
|
-
import { asc as
|
|
4510
|
+
import { asc as asc11, eq as eq19 } from "drizzle-orm";
|
|
4325
4511
|
|
|
4326
4512
|
// src/pi-resources/resource-collector.ts
|
|
4327
4513
|
import { constants } from "node:fs";
|
|
@@ -4508,7 +4694,7 @@ function createProcessSkillRepo(db) {
|
|
|
4508
4694
|
if (seen.has(selection.skillId))
|
|
4509
4695
|
throw new Error(`Duplicate skill selection '${selection.skillId}'`);
|
|
4510
4696
|
seen.add(selection.skillId);
|
|
4511
|
-
const revision = db.select().from(skillRevisions).where(
|
|
4697
|
+
const revision = db.select().from(skillRevisions).where(eq19(skillRevisions.id, selection.revisionId)).get();
|
|
4512
4698
|
if (!revision || revision.skillId !== selection.skillId)
|
|
4513
4699
|
throw new Error(`Invalid revision for skill '${selection.skillId}'`);
|
|
4514
4700
|
db.insert(processSkills).values({
|
|
@@ -4524,14 +4710,14 @@ function createProcessSkillRepo(db) {
|
|
|
4524
4710
|
return db.select({
|
|
4525
4711
|
skillId: processSkills.skillId,
|
|
4526
4712
|
revisionId: processSkills.skillRevisionId
|
|
4527
|
-
}).from(processSkills).where(
|
|
4713
|
+
}).from(processSkills).where(eq19(processSkills.instanceId, instanceId)).orderBy(asc11(processSkills.position)).all();
|
|
4528
4714
|
},
|
|
4529
4715
|
/** @internal */
|
|
4530
4716
|
listResourceLayers(instanceId) {
|
|
4531
4717
|
return db.select({
|
|
4532
4718
|
digest: skillRevisions.bundleDigest,
|
|
4533
4719
|
bytes: skillRevisions.bundleBytes
|
|
4534
|
-
}).from(processSkills).innerJoin(skillRevisions,
|
|
4720
|
+
}).from(processSkills).innerJoin(skillRevisions, eq19(processSkills.skillRevisionId, skillRevisions.id)).where(eq19(processSkills.instanceId, instanceId)).orderBy(asc11(processSkills.position)).all().map(({ digest, bytes }) => ({
|
|
4535
4721
|
bundle: { digest, bytes },
|
|
4536
4722
|
owner: SKILL_RESOURCE_OWNER
|
|
4537
4723
|
}));
|
|
@@ -4540,10 +4726,10 @@ function createProcessSkillRepo(db) {
|
|
|
4540
4726
|
}
|
|
4541
4727
|
|
|
4542
4728
|
// src/db/process-title-job-repo.ts
|
|
4543
|
-
import { and as
|
|
4729
|
+
import { and as and14, asc as asc12, eq as eq20, inArray as inArray6, lte as lte2, sql as sql6 } from "drizzle-orm";
|
|
4544
4730
|
function createProcessTitleJobRepo(db) {
|
|
4545
4731
|
function transition(id, from, values) {
|
|
4546
|
-
return db.update(processTitleJobs).set({ ...values, updatedAt: now() }).where(
|
|
4732
|
+
return db.update(processTitleJobs).set({ ...values, updatedAt: now() }).where(and14(eq20(processTitleJobs.id, id), inArray6(processTitleJobs.status, from))).returning().get() ?? null;
|
|
4547
4733
|
}
|
|
4548
4734
|
return {
|
|
4549
4735
|
/** @internal */
|
|
@@ -4559,9 +4745,9 @@ function createProcessTitleJobRepo(db) {
|
|
|
4559
4745
|
expectedPayloadJson: input.expectedPayloadJson
|
|
4560
4746
|
};
|
|
4561
4747
|
db.update(processTitleJobs).set({ status: "superseded", updatedAt: ts }).where(
|
|
4562
|
-
|
|
4748
|
+
and14(
|
|
4563
4749
|
inArray6(processTitleJobs.status, ["pending", "running"]),
|
|
4564
|
-
target2.targetKind === "process" ?
|
|
4750
|
+
target2.targetKind === "process" ? eq20(processTitleJobs.processInstanceId, target2.processInstanceId) : eq20(processTitleJobs.futureExecutionId, target2.futureExecutionId)
|
|
4565
4751
|
)
|
|
4566
4752
|
).run();
|
|
4567
4753
|
return db.insert(processTitleJobs).values({
|
|
@@ -4579,22 +4765,22 @@ function createProcessTitleJobRepo(db) {
|
|
|
4579
4765
|
},
|
|
4580
4766
|
/** @internal */
|
|
4581
4767
|
getById(id) {
|
|
4582
|
-
const row = db.select().from(processTitleJobs).where(
|
|
4768
|
+
const row = db.select().from(processTitleJobs).where(eq20(processTitleJobs.id, id)).get();
|
|
4583
4769
|
return row ?? null;
|
|
4584
4770
|
},
|
|
4585
4771
|
/** @internal */
|
|
4586
4772
|
listByProcessInstance(processInstanceId) {
|
|
4587
|
-
return db.select().from(processTitleJobs).where(
|
|
4773
|
+
return db.select().from(processTitleJobs).where(eq20(processTitleJobs.processInstanceId, processInstanceId)).orderBy(asc12(processTitleJobs.createdAt), asc12(processTitleJobs.id)).all();
|
|
4588
4774
|
},
|
|
4589
4775
|
/** @internal */
|
|
4590
4776
|
listAll() {
|
|
4591
|
-
return db.select().from(processTitleJobs).orderBy(
|
|
4777
|
+
return db.select().from(processTitleJobs).orderBy(asc12(processTitleJobs.createdAt), asc12(processTitleJobs.id)).all();
|
|
4592
4778
|
},
|
|
4593
4779
|
/** @internal */
|
|
4594
4780
|
listDuePending(asOf, limit) {
|
|
4595
4781
|
return db.select().from(processTitleJobs).where(
|
|
4596
|
-
|
|
4597
|
-
).orderBy(
|
|
4782
|
+
and14(eq20(processTitleJobs.status, "pending"), lte2(processTitleJobs.nextRunAt, asOf))
|
|
4783
|
+
).orderBy(asc12(processTitleJobs.nextRunAt), asc12(processTitleJobs.createdAt)).limit(Math.max(0, limit)).all();
|
|
4598
4784
|
},
|
|
4599
4785
|
/** @internal */
|
|
4600
4786
|
markRunning(id) {
|
|
@@ -4624,7 +4810,7 @@ function createProcessTitleJobRepo(db) {
|
|
|
4624
4810
|
}
|
|
4625
4811
|
|
|
4626
4812
|
// src/db/process-tool-approval-request-repo.ts
|
|
4627
|
-
import { and as
|
|
4813
|
+
import { and as and15, asc as asc13, eq as eq21 } from "drizzle-orm";
|
|
4628
4814
|
function map3(row) {
|
|
4629
4815
|
return {
|
|
4630
4816
|
id: row.id,
|
|
@@ -4650,10 +4836,10 @@ function map3(row) {
|
|
|
4650
4836
|
function createProcessToolApprovalRequestRepo(db) {
|
|
4651
4837
|
const list = (instanceId, openOnly = false) => {
|
|
4652
4838
|
const filters = [
|
|
4653
|
-
...instanceId ? [
|
|
4654
|
-
...openOnly ? [
|
|
4839
|
+
...instanceId ? [eq21(processToolApprovalRequests.instanceId, instanceId)] : [],
|
|
4840
|
+
...openOnly ? [eq21(processToolApprovalRequests.status, "open")] : []
|
|
4655
4841
|
];
|
|
4656
|
-
return db.select().from(processToolApprovalRequests).where(filters.length ?
|
|
4842
|
+
return db.select().from(processToolApprovalRequests).where(filters.length ? and15(...filters) : void 0).orderBy(asc13(processToolApprovalRequests.requestedAt)).all().map(map3);
|
|
4657
4843
|
};
|
|
4658
4844
|
return {
|
|
4659
4845
|
/** @internal */
|
|
@@ -4663,10 +4849,10 @@ function createProcessToolApprovalRequestRepo(db) {
|
|
|
4663
4849
|
/** @internal */
|
|
4664
4850
|
createIdempotent(input) {
|
|
4665
4851
|
const existing = db.select().from(processToolApprovalRequests).where(
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4852
|
+
and15(
|
|
4853
|
+
eq21(processToolApprovalRequests.instanceId, input.instanceId),
|
|
4854
|
+
eq21(processToolApprovalRequests.turnRecordId, input.turnRecordId),
|
|
4855
|
+
eq21(processToolApprovalRequests.toolCallId, input.toolCallId)
|
|
4670
4856
|
)
|
|
4671
4857
|
).get();
|
|
4672
4858
|
if (existing) {
|
|
@@ -4698,9 +4884,9 @@ function createProcessToolApprovalRequestRepo(db) {
|
|
|
4698
4884
|
resolvedByJson: JSON.stringify(input.actor),
|
|
4699
4885
|
feedback: input.feedback?.trim() ?? null
|
|
4700
4886
|
}).where(
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4887
|
+
and15(
|
|
4888
|
+
eq21(processToolApprovalRequests.id, input.id),
|
|
4889
|
+
eq21(processToolApprovalRequests.status, "open")
|
|
4704
4890
|
)
|
|
4705
4891
|
).returning().get();
|
|
4706
4892
|
return row ? map3(row) : null;
|
|
@@ -4708,10 +4894,10 @@ function createProcessToolApprovalRequestRepo(db) {
|
|
|
4708
4894
|
/** @internal */
|
|
4709
4895
|
cancelOpenByTurn(instanceId, turnRecordId) {
|
|
4710
4896
|
const result = db.update(processToolApprovalRequests).set({ status: "cancelled", resolvedAt: now() }).where(
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4897
|
+
and15(
|
|
4898
|
+
eq21(processToolApprovalRequests.instanceId, instanceId),
|
|
4899
|
+
eq21(processToolApprovalRequests.turnRecordId, turnRecordId),
|
|
4900
|
+
eq21(processToolApprovalRequests.status, "open")
|
|
4715
4901
|
)
|
|
4716
4902
|
).run();
|
|
4717
4903
|
return Number(result.changes);
|
|
@@ -4721,7 +4907,7 @@ function createProcessToolApprovalRequestRepo(db) {
|
|
|
4721
4907
|
|
|
4722
4908
|
// src/db/process-turn-annotation-repo.ts
|
|
4723
4909
|
import { parseTurnAnnotationReferences } from "@leitwerk-dev/domain";
|
|
4724
|
-
import { and as
|
|
4910
|
+
import { and as and16, asc as asc14, eq as eq22 } from "drizzle-orm";
|
|
4725
4911
|
function parseReferences(value) {
|
|
4726
4912
|
try {
|
|
4727
4913
|
return parseTurnAnnotationReferences(JSON.parse(value));
|
|
@@ -4763,7 +4949,7 @@ function createProcessTurnAnnotationRepo(db) {
|
|
|
4763
4949
|
},
|
|
4764
4950
|
/** @internal */
|
|
4765
4951
|
getById(id) {
|
|
4766
|
-
const row = db.select().from(turnAnnotations).where(
|
|
4952
|
+
const row = db.select().from(turnAnnotations).where(eq22(turnAnnotations.id, id)).get();
|
|
4767
4953
|
return row ? rowToProcessTurnAnnotation(row) : null;
|
|
4768
4954
|
},
|
|
4769
4955
|
/** @internal */
|
|
@@ -4773,16 +4959,16 @@ function createProcessTurnAnnotationRepo(db) {
|
|
|
4773
4959
|
return null;
|
|
4774
4960
|
}
|
|
4775
4961
|
const row = db.select().from(turnAnnotations).where(
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4962
|
+
and16(
|
|
4963
|
+
eq22(turnAnnotations.instanceId, instanceId),
|
|
4964
|
+
eq22(turnAnnotations.annotationKey, key)
|
|
4779
4965
|
)
|
|
4780
4966
|
).get();
|
|
4781
4967
|
return row ? rowToProcessTurnAnnotation(row) : null;
|
|
4782
4968
|
},
|
|
4783
4969
|
/** @internal */
|
|
4784
4970
|
listByInstance(instanceId) {
|
|
4785
|
-
return db.select().from(turnAnnotations).where(
|
|
4971
|
+
return db.select().from(turnAnnotations).where(eq22(turnAnnotations.instanceId, instanceId)).orderBy(asc14(turnAnnotations.createdAt)).all().map(rowToProcessTurnAnnotation);
|
|
4786
4972
|
},
|
|
4787
4973
|
/** @internal */
|
|
4788
4974
|
update(id, input) {
|
|
@@ -4794,19 +4980,19 @@ function createProcessTurnAnnotationRepo(db) {
|
|
|
4794
4980
|
if (input.references !== void 0)
|
|
4795
4981
|
setValues.referencesJson = JSON.stringify(input.references);
|
|
4796
4982
|
if (input.payload !== void 0) setValues.payloadJson = JSON.stringify(input.payload);
|
|
4797
|
-
db.update(turnAnnotations).set(setValues).where(
|
|
4983
|
+
db.update(turnAnnotations).set(setValues).where(eq22(turnAnnotations.id, id)).run();
|
|
4798
4984
|
return this.getById(id);
|
|
4799
4985
|
},
|
|
4800
4986
|
/** @internal */
|
|
4801
4987
|
delete(id) {
|
|
4802
|
-
const result = db.delete(turnAnnotations).where(
|
|
4988
|
+
const result = db.delete(turnAnnotations).where(eq22(turnAnnotations.id, id)).run();
|
|
4803
4989
|
return result.changes > 0;
|
|
4804
4990
|
}
|
|
4805
4991
|
};
|
|
4806
4992
|
}
|
|
4807
4993
|
|
|
4808
4994
|
// src/db/process-turn-record-repo.ts
|
|
4809
|
-
import { asc as
|
|
4995
|
+
import { asc as asc15, desc as desc8, eq as eq23 } from "drizzle-orm";
|
|
4810
4996
|
function rowToProcessTurnRecord(row) {
|
|
4811
4997
|
return {
|
|
4812
4998
|
id: row.id,
|
|
@@ -4826,6 +5012,7 @@ function rowToProcessTurnRecord(row) {
|
|
|
4826
5012
|
kind: row.modelSelectionKind,
|
|
4827
5013
|
source: row.modelSelectionSource
|
|
4828
5014
|
} : null,
|
|
5015
|
+
iteration: mappedItemRef(row),
|
|
4829
5016
|
turnResultMarkdown: row.turnResultMarkdown ?? null,
|
|
4830
5017
|
errorSummary: row.errorSummary ?? null,
|
|
4831
5018
|
errorClass: row.errorClass ?? null,
|
|
@@ -4858,23 +5045,26 @@ function createProcessTurnRecordRepo(db) {
|
|
|
4858
5045
|
errorSummary: input.errorSummary ?? null,
|
|
4859
5046
|
errorClass: input.errorClass ?? null,
|
|
4860
5047
|
startedAt: input.startedAt ?? now(),
|
|
4861
|
-
endedAt: input.endedAt ?? null
|
|
5048
|
+
endedAt: input.endedAt ?? null,
|
|
5049
|
+
mappedRunId: input.iteration?.runId ?? null,
|
|
5050
|
+
mappedItemKey: input.iteration?.itemKey ?? null,
|
|
5051
|
+
mappedItemIndex: input.iteration?.itemIndex ?? null
|
|
4862
5052
|
};
|
|
4863
5053
|
db.insert(turnRecords).values(values).run();
|
|
4864
5054
|
return rowToProcessTurnRecord(values);
|
|
4865
5055
|
},
|
|
4866
5056
|
/** @internal */
|
|
4867
5057
|
getById(id) {
|
|
4868
|
-
const row = db.select().from(turnRecords).where(
|
|
5058
|
+
const row = db.select().from(turnRecords).where(eq23(turnRecords.id, id)).get();
|
|
4869
5059
|
return row ? rowToProcessTurnRecord(row) : null;
|
|
4870
5060
|
},
|
|
4871
5061
|
/** @public */
|
|
4872
5062
|
listByInstance(instanceId) {
|
|
4873
|
-
return db.select().from(turnRecords).where(
|
|
5063
|
+
return db.select().from(turnRecords).where(eq23(turnRecords.instanceId, instanceId)).orderBy(asc15(turnRecords.startedAt)).all().map(rowToProcessTurnRecord);
|
|
4874
5064
|
},
|
|
4875
5065
|
/** @internal */
|
|
4876
5066
|
getLatestSucceededPrimaryByInstance(instanceId) {
|
|
4877
|
-
const row = db.select().from(turnRecords).where(
|
|
5067
|
+
const row = db.select().from(turnRecords).where(eq23(turnRecords.instanceId, instanceId)).orderBy(desc8(turnRecords.startedAt)).all().map(rowToProcessTurnRecord).find(
|
|
4878
5068
|
(run) => run.status === "succeeded" && run.pathType === "primary" && typeof run.resultPiEntryId === "string" && run.resultPiEntryId.length > 0
|
|
4879
5069
|
);
|
|
4880
5070
|
return row ?? null;
|
|
@@ -4900,14 +5090,14 @@ function createProcessTurnRecordRepo(db) {
|
|
|
4900
5090
|
setValues.modelSelectionKind = input.modelSelectionProvenance?.kind ?? null;
|
|
4901
5091
|
setValues.modelSelectionSource = input.modelSelectionProvenance?.source ?? null;
|
|
4902
5092
|
}
|
|
4903
|
-
db.update(turnRecords).set(setValues).where(
|
|
5093
|
+
db.update(turnRecords).set(setValues).where(eq23(turnRecords.id, id)).run();
|
|
4904
5094
|
return this.getById(id);
|
|
4905
5095
|
}
|
|
4906
5096
|
};
|
|
4907
5097
|
}
|
|
4908
5098
|
|
|
4909
5099
|
// src/db/provider-credential-repo.ts
|
|
4910
|
-
import { and as
|
|
5100
|
+
import { and as and17, count as count3, eq as eq24 } from "drizzle-orm";
|
|
4911
5101
|
function createProviderCredentialRepo(db, cipher) {
|
|
4912
5102
|
const row = (value) => ({
|
|
4913
5103
|
providerId: value.providerId,
|
|
@@ -4923,7 +5113,7 @@ function createProviderCredentialRepo(db, cipher) {
|
|
|
4923
5113
|
},
|
|
4924
5114
|
/** @internal */
|
|
4925
5115
|
get(providerId) {
|
|
4926
|
-
const value = db.select().from(providerCredentials).where(
|
|
5116
|
+
const value = db.select().from(providerCredentials).where(eq24(providerCredentials.providerId, providerId)).get();
|
|
4927
5117
|
return value ? row(value) : null;
|
|
4928
5118
|
},
|
|
4929
5119
|
/** @internal */
|
|
@@ -4954,9 +5144,9 @@ function createProviderCredentialRepo(db, cipher) {
|
|
|
4954
5144
|
encryptedPayload: cipher.encrypt(input.payload),
|
|
4955
5145
|
updatedAt: ts
|
|
4956
5146
|
}).where(
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
5147
|
+
and17(
|
|
5148
|
+
eq24(providerCredentials.providerId, input.providerId),
|
|
5149
|
+
eq24(providerCredentials.revision, input.expectedRevision)
|
|
4960
5150
|
)
|
|
4961
5151
|
).run();
|
|
4962
5152
|
if (result.changes !== 1) return null;
|
|
@@ -4969,7 +5159,7 @@ function createProviderCredentialRepo(db, cipher) {
|
|
|
4969
5159
|
import {
|
|
4970
5160
|
sessionTransferAttemptStateForPhase
|
|
4971
5161
|
} from "@leitwerk-dev/session-transfer";
|
|
4972
|
-
import { and as
|
|
5162
|
+
import { and as and18, eq as eq25, inArray as inArray7, isNotNull, isNull as isNull3, lt as lt2, notExists, or as or3 } from "drizzle-orm";
|
|
4973
5163
|
|
|
4974
5164
|
// src/auth/auth-tokens.ts
|
|
4975
5165
|
import { createHash, randomBytes as randomBytes2, timingSafeEqual } from "node:crypto";
|
|
@@ -5028,20 +5218,20 @@ function createSessionTransferRepo(db) {
|
|
|
5028
5218
|
},
|
|
5029
5219
|
/** @internal */
|
|
5030
5220
|
getGrant(id) {
|
|
5031
|
-
return db.select().from(sessionTransferGrants).where(
|
|
5221
|
+
return db.select().from(sessionTransferGrants).where(eq25(sessionTransferGrants.id, id)).get() ?? null;
|
|
5032
5222
|
},
|
|
5033
5223
|
/** @internal */
|
|
5034
5224
|
getAttempt(id) {
|
|
5035
5225
|
return toAttempt(
|
|
5036
|
-
db.select().from(sessionTransferAttempts).where(
|
|
5226
|
+
db.select().from(sessionTransferAttempts).where(eq25(sessionTransferAttempts.id, id)).get()
|
|
5037
5227
|
);
|
|
5038
5228
|
},
|
|
5039
5229
|
/** @internal */
|
|
5040
5230
|
getActiveByInstance(instanceId) {
|
|
5041
5231
|
return toAttempt(
|
|
5042
5232
|
db.select().from(sessionTransferAttempts).where(
|
|
5043
|
-
|
|
5044
|
-
|
|
5233
|
+
and18(
|
|
5234
|
+
eq25(sessionTransferAttempts.instanceId, instanceId),
|
|
5045
5235
|
inArray7(sessionTransferAttempts.phase, ACTIVE_PHASES)
|
|
5046
5236
|
)
|
|
5047
5237
|
).get()
|
|
@@ -5095,7 +5285,7 @@ function createSessionTransferRepo(db) {
|
|
|
5095
5285
|
},
|
|
5096
5286
|
/** @internal */
|
|
5097
5287
|
updateAttempt(id, patch) {
|
|
5098
|
-
db.update(sessionTransferAttempts).set(patch).where(
|
|
5288
|
+
db.update(sessionTransferAttempts).set(patch).where(eq25(sessionTransferAttempts.id, id)).run();
|
|
5099
5289
|
return this.getAttempt(id);
|
|
5100
5290
|
},
|
|
5101
5291
|
/** @internal */
|
|
@@ -5117,17 +5307,17 @@ function createSessionTransferRepo(db) {
|
|
|
5117
5307
|
return null;
|
|
5118
5308
|
const completedAt = input.now.toISOString();
|
|
5119
5309
|
db.update(sessionTransferAttempts).set({ phase: "consumed", completedAt }).where(
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5310
|
+
and18(
|
|
5311
|
+
eq25(sessionTransferAttempts.id, attempt.id),
|
|
5312
|
+
eq25(sessionTransferAttempts.phase, "awaiting_ack")
|
|
5123
5313
|
)
|
|
5124
5314
|
).run();
|
|
5125
5315
|
db.update(sessionTransferGrants).set({
|
|
5126
5316
|
consumedAt: completedAt,
|
|
5127
5317
|
tombstoneUntil: new Date(input.now.getTime() + input.tombstoneMs).toISOString()
|
|
5128
5318
|
}).where(
|
|
5129
|
-
|
|
5130
|
-
|
|
5319
|
+
and18(
|
|
5320
|
+
eq25(sessionTransferGrants.id, attempt.grantId),
|
|
5131
5321
|
isNull3(sessionTransferGrants.consumedAt)
|
|
5132
5322
|
)
|
|
5133
5323
|
).run();
|
|
@@ -5135,27 +5325,27 @@ function createSessionTransferRepo(db) {
|
|
|
5135
5325
|
},
|
|
5136
5326
|
/** @internal */
|
|
5137
5327
|
revokeProcess(instanceId) {
|
|
5138
|
-
db.delete(sessionTransferGrants).where(
|
|
5328
|
+
db.delete(sessionTransferGrants).where(eq25(sessionTransferGrants.instanceId, instanceId)).run();
|
|
5139
5329
|
},
|
|
5140
5330
|
/** @internal */
|
|
5141
5331
|
cleanup(now2) {
|
|
5142
5332
|
const cutoff = now2.toISOString();
|
|
5143
5333
|
db.delete(sessionTransferGrants).where(
|
|
5144
|
-
|
|
5334
|
+
and18(
|
|
5145
5335
|
or3(
|
|
5146
|
-
|
|
5336
|
+
and18(
|
|
5147
5337
|
isNull3(sessionTransferGrants.consumedAt),
|
|
5148
5338
|
lt2(sessionTransferGrants.expiresAt, cutoff)
|
|
5149
5339
|
),
|
|
5150
|
-
|
|
5340
|
+
and18(
|
|
5151
5341
|
isNotNull(sessionTransferGrants.tombstoneUntil),
|
|
5152
5342
|
lt2(sessionTransferGrants.tombstoneUntil, cutoff)
|
|
5153
5343
|
)
|
|
5154
5344
|
),
|
|
5155
5345
|
notExists(
|
|
5156
5346
|
db.select({ id: sessionTransferAttempts.id }).from(sessionTransferAttempts).where(
|
|
5157
|
-
|
|
5158
|
-
|
|
5347
|
+
and18(
|
|
5348
|
+
eq25(sessionTransferAttempts.grantId, sessionTransferGrants.id),
|
|
5159
5349
|
inArray7(sessionTransferAttempts.phase, ACTIVE_PHASES)
|
|
5160
5350
|
)
|
|
5161
5351
|
)
|
|
@@ -5168,7 +5358,7 @@ function createSessionTransferRepo(db) {
|
|
|
5168
5358
|
|
|
5169
5359
|
// src/db/skill-repo.ts
|
|
5170
5360
|
import { verifyCanonicalPiResourceBundle as verifyCanonicalPiResourceBundle2 } from "@leitwerk-dev/worker-protocol";
|
|
5171
|
-
import { and as
|
|
5361
|
+
import { and as and19, asc as asc16, count as count4, desc as desc9, eq as eq26, isNotNull as isNotNull2, max as max2, notExists as notExists2, notInArray as notInArray2, sql as sql7 } from "drizzle-orm";
|
|
5172
5362
|
|
|
5173
5363
|
// src/skills/skill-dependencies.ts
|
|
5174
5364
|
var EXPLICIT_SKILL_REFERENCE = /\/([A-Za-z0-9][A-Za-z0-9._-]{0,83})|`([A-Za-z0-9][A-Za-z0-9._-]{0,83})`/g;
|
|
@@ -5205,9 +5395,9 @@ function isSkillModelInvocable(markdown) {
|
|
|
5205
5395
|
// src/db/skill-repo.ts
|
|
5206
5396
|
function revisionForBundle(db, item, timestamp) {
|
|
5207
5397
|
const existing = db.select({ id: skillRevisions.id }).from(skillRevisions).where(
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5398
|
+
and19(
|
|
5399
|
+
eq26(skillRevisions.skillId, item.skillId),
|
|
5400
|
+
eq26(skillRevisions.bundleDigest, item.bundle.digest)
|
|
5211
5401
|
)
|
|
5212
5402
|
).get();
|
|
5213
5403
|
if (existing) return existing.id;
|
|
@@ -5238,7 +5428,7 @@ function usageBySkill(db) {
|
|
|
5238
5428
|
skillId: processSkills.skillId,
|
|
5239
5429
|
allTime: count4(),
|
|
5240
5430
|
last30Days: sql7`sum(case when ${processInstances.createdAt} >= ${cutoff} then 1 else 0 end)`
|
|
5241
|
-
}).from(processSkills).innerJoin(processInstances,
|
|
5431
|
+
}).from(processSkills).innerJoin(processInstances, eq26(processSkills.instanceId, processInstances.id)).groupBy(processSkills.skillId).all()) {
|
|
5242
5432
|
result.set(row.skillId, {
|
|
5243
5433
|
...usage(row.skillId),
|
|
5244
5434
|
attachedAllTime: row.allTime,
|
|
@@ -5265,13 +5455,13 @@ function processUsage(db, skillId) {
|
|
|
5265
5455
|
attachedAt: processInstances.createdAt,
|
|
5266
5456
|
invocationCount: count4(skillInvocations.skillId),
|
|
5267
5457
|
lastInvokedAt: max2(skillInvocations.invokedAt)
|
|
5268
|
-
}).from(processSkills).innerJoin(processInstances,
|
|
5458
|
+
}).from(processSkills).innerJoin(processInstances, eq26(processSkills.instanceId, processInstances.id)).leftJoin(
|
|
5269
5459
|
skillInvocations,
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5460
|
+
and19(
|
|
5461
|
+
eq26(skillInvocations.instanceId, processSkills.instanceId),
|
|
5462
|
+
eq26(skillInvocations.skillId, processSkills.skillId)
|
|
5273
5463
|
)
|
|
5274
|
-
).where(
|
|
5464
|
+
).where(eq26(processSkills.skillId, skillId)).groupBy(
|
|
5275
5465
|
processSkills.instanceId,
|
|
5276
5466
|
processInstances.title,
|
|
5277
5467
|
processInstances.externalId,
|
|
@@ -5287,13 +5477,13 @@ function skillMarkdown(skillId, bytes, digest) {
|
|
|
5287
5477
|
}
|
|
5288
5478
|
function pruneNeverInstalledCatalogEntries(db) {
|
|
5289
5479
|
db.delete(skillCatalogEntries).where(
|
|
5290
|
-
|
|
5291
|
-
|
|
5480
|
+
and19(
|
|
5481
|
+
eq26(skillCatalogEntries.available, false),
|
|
5292
5482
|
notExists2(
|
|
5293
5483
|
db.select({ id: skillRevisions.id }).from(skillRevisions).where(
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5484
|
+
and19(
|
|
5485
|
+
eq26(skillRevisions.skillId, skillCatalogEntries.skillId),
|
|
5486
|
+
eq26(skillRevisions.bundleDigest, skillCatalogEntries.bundleDigest)
|
|
5297
5487
|
)
|
|
5298
5488
|
)
|
|
5299
5489
|
)
|
|
@@ -5301,7 +5491,7 @@ function pruneNeverInstalledCatalogEntries(db) {
|
|
|
5301
5491
|
).run();
|
|
5302
5492
|
}
|
|
5303
5493
|
function recordRevisionDependencies(db, revisionId, markdown) {
|
|
5304
|
-
db.delete(skillRevisionDependencies).where(
|
|
5494
|
+
db.delete(skillRevisionDependencies).where(eq26(skillRevisionDependencies.skillRevisionId, revisionId)).run();
|
|
5305
5495
|
for (const [position, dependencySkillId] of explicitSkillReferenceIds(markdown).entries()) {
|
|
5306
5496
|
db.insert(skillRevisionDependencies).values({ skillRevisionId: revisionId, dependencySkillId, position }).run();
|
|
5307
5497
|
}
|
|
@@ -5324,7 +5514,7 @@ function activateSkill(db, item, registrationKind, timestamp, markdown = skillMa
|
|
|
5324
5514
|
activeRevisionId: revisionId,
|
|
5325
5515
|
registrationKind,
|
|
5326
5516
|
updatedAt: timestamp
|
|
5327
|
-
}).where(
|
|
5517
|
+
}).where(eq26(skills.id, item.skillId)).run();
|
|
5328
5518
|
return revisionId;
|
|
5329
5519
|
}
|
|
5330
5520
|
function catalogView(db) {
|
|
@@ -5339,7 +5529,7 @@ function catalogView(db) {
|
|
|
5339
5529
|
activeDigest: skillRevisions.bundleDigest,
|
|
5340
5530
|
activeBundleBytes: skillRevisions.bundleBytes,
|
|
5341
5531
|
registrationKind: skills.registrationKind
|
|
5342
|
-
}).from(skills).innerJoin(skillRevisions,
|
|
5532
|
+
}).from(skills).innerJoin(skillRevisions, eq26(skills.activeRevisionId, skillRevisions.id)).orderBy(asc16(skills.label), asc16(skills.id)).all();
|
|
5343
5533
|
const installedById = new Map(installedRows.map((row) => [row.id, row]));
|
|
5344
5534
|
const availableSkills = candidates.map((candidate2) => {
|
|
5345
5535
|
const active = installedById.get(candidate2.skillId);
|
|
@@ -5392,11 +5582,11 @@ function createSkillRepo(db) {
|
|
|
5392
5582
|
return {
|
|
5393
5583
|
/** @internal */
|
|
5394
5584
|
listAvailable() {
|
|
5395
|
-
return db.select({ id: skills.id, label: skills.label, description: skills.description }).from(skills).where(isNotNull2(skills.activeRevisionId)).orderBy(
|
|
5585
|
+
return db.select({ id: skills.id, label: skills.label, description: skills.description }).from(skills).where(isNotNull2(skills.activeRevisionId)).orderBy(asc16(skills.label), asc16(skills.id)).all();
|
|
5396
5586
|
},
|
|
5397
5587
|
/** @internal */
|
|
5398
5588
|
resolveActive(ids) {
|
|
5399
|
-
const activeSkills = db.select({ id: skills.id, revisionId: skillRevisions.id }).from(skills).innerJoin(skillRevisions,
|
|
5589
|
+
const activeSkills = db.select({ id: skills.id, revisionId: skillRevisions.id }).from(skills).innerJoin(skillRevisions, eq26(skills.activeRevisionId, skillRevisions.id)).all();
|
|
5400
5590
|
const byId = new Map(activeSkills.map((skill) => [skill.id, skill]));
|
|
5401
5591
|
const dependencies = /* @__PURE__ */ new Map();
|
|
5402
5592
|
for (const dependency of db.select().from(skillRevisionDependencies).all()) {
|
|
@@ -5424,8 +5614,8 @@ function createSkillRepo(db) {
|
|
|
5424
5614
|
reconcile(imported) {
|
|
5425
5615
|
const timestamp = now();
|
|
5426
5616
|
db.update(skills).set({ activeRevisionId: null, updatedAt: timestamp }).where(
|
|
5427
|
-
|
|
5428
|
-
|
|
5617
|
+
and19(
|
|
5618
|
+
eq26(skills.registrationKind, "configuration"),
|
|
5429
5619
|
notInArray2(
|
|
5430
5620
|
skills.id,
|
|
5431
5621
|
imported.map((item) => item.skillId)
|
|
@@ -5452,7 +5642,7 @@ function createSkillRepo(db) {
|
|
|
5452
5642
|
/** @internal */
|
|
5453
5643
|
mergeCatalog(repositoryId, imported) {
|
|
5454
5644
|
const timestamp = now();
|
|
5455
|
-
db.update(skillCatalogEntries).set({ available: false }).where(
|
|
5645
|
+
db.update(skillCatalogEntries).set({ available: false }).where(eq26(skillCatalogEntries.repositoryId, repositoryId)).run();
|
|
5456
5646
|
for (const item of imported) {
|
|
5457
5647
|
const values = {
|
|
5458
5648
|
label: item.label,
|
|
@@ -5473,7 +5663,7 @@ function createSkillRepo(db) {
|
|
|
5473
5663
|
},
|
|
5474
5664
|
/** @internal */
|
|
5475
5665
|
registerCatalogEntry(repositoryId, skillId) {
|
|
5476
|
-
const candidates = db.select().from(skillCatalogEntries).where(
|
|
5666
|
+
const candidates = db.select().from(skillCatalogEntries).where(eq26(skillCatalogEntries.available, true)).all();
|
|
5477
5667
|
const availableIds = new Set(candidates.map((candidate2) => candidate2.skillId));
|
|
5478
5668
|
const installedIds = new Set(
|
|
5479
5669
|
db.select({ id: skills.id }).from(skills).where(isNotNull2(skills.activeRevisionId)).all().map((skill) => skill.id)
|
|
@@ -5493,7 +5683,7 @@ function createSkillRepo(db) {
|
|
|
5493
5683
|
`Remote skill '${requestedRepositoryId ? `${requestedRepositoryId}/` : ""}${id}' is no longer available`
|
|
5494
5684
|
);
|
|
5495
5685
|
}
|
|
5496
|
-
const current = db.select().from(skills).where(
|
|
5686
|
+
const current = db.select().from(skills).where(eq26(skills.id, id)).get();
|
|
5497
5687
|
if (current?.activeRevisionId && current.registrationKind === "configuration") {
|
|
5498
5688
|
throw new Error(`Skill '${id}' is managed by configuration`);
|
|
5499
5689
|
}
|
|
@@ -5526,9 +5716,9 @@ function createSkillRepo(db) {
|
|
|
5526
5716
|
},
|
|
5527
5717
|
/** @internal */
|
|
5528
5718
|
remove(skillId) {
|
|
5529
|
-
const current = db.select().from(skills).where(
|
|
5719
|
+
const current = db.select().from(skills).where(eq26(skills.id, skillId)).get();
|
|
5530
5720
|
if (!current?.activeRevisionId || current.registrationKind !== "catalog") return false;
|
|
5531
|
-
db.update(skills).set({ activeRevisionId: null, updatedAt: now() }).where(
|
|
5721
|
+
db.update(skills).set({ activeRevisionId: null, updatedAt: now() }).where(eq26(skills.id, skillId)).run();
|
|
5532
5722
|
return true;
|
|
5533
5723
|
},
|
|
5534
5724
|
/** @internal */
|
|
@@ -5545,9 +5735,9 @@ function createSkillRepo(db) {
|
|
|
5545
5735
|
bytes: skillCatalogEntries.bundleBytes,
|
|
5546
5736
|
digest: skillCatalogEntries.bundleDigest
|
|
5547
5737
|
}).from(skillCatalogEntries).where(
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5738
|
+
and19(
|
|
5739
|
+
eq26(skillCatalogEntries.repositoryId, repositoryId),
|
|
5740
|
+
eq26(skillCatalogEntries.skillId, skillId)
|
|
5551
5741
|
)
|
|
5552
5742
|
).get();
|
|
5553
5743
|
if (!candidate2) return null;
|
|
@@ -5561,13 +5751,13 @@ function createSkillRepo(db) {
|
|
|
5561
5751
|
getInstalledDetail(skillId) {
|
|
5562
5752
|
const item = catalogView(db).installedSkills.find((candidate2) => candidate2.id === skillId);
|
|
5563
5753
|
if (!item) return null;
|
|
5564
|
-
const revision = db.select({ bytes: skillRevisions.bundleBytes, digest: skillRevisions.bundleDigest }).from(skillRevisions).where(
|
|
5754
|
+
const revision = db.select({ bytes: skillRevisions.bundleBytes, digest: skillRevisions.bundleDigest }).from(skillRevisions).where(eq26(skillRevisions.id, item.activeRevisionId)).get();
|
|
5565
5755
|
if (!revision) return null;
|
|
5566
5756
|
const revisions = db.select({
|
|
5567
5757
|
id: skillRevisions.id,
|
|
5568
5758
|
sourceRevision: skillRevisions.sourceRevision,
|
|
5569
5759
|
importedAt: skillRevisions.importedAt
|
|
5570
|
-
}).from(skillRevisions).where(
|
|
5760
|
+
}).from(skillRevisions).where(eq26(skillRevisions.skillId, skillId)).all().map((candidate2) => ({
|
|
5571
5761
|
...candidate2,
|
|
5572
5762
|
active: candidate2.id === item.activeRevisionId
|
|
5573
5763
|
})).sort((left, right) => right.importedAt.localeCompare(left.importedAt));
|
|
@@ -5580,7 +5770,7 @@ function createSkillRepo(db) {
|
|
|
5580
5770
|
},
|
|
5581
5771
|
/** @internal */
|
|
5582
5772
|
recordInvocations(input) {
|
|
5583
|
-
const selections = db.select().from(processSkills).where(
|
|
5773
|
+
const selections = db.select().from(processSkills).where(eq26(processSkills.instanceId, input.instanceId)).all();
|
|
5584
5774
|
const uniqueInvocations = new Map(
|
|
5585
5775
|
input.invocations.map((invocation) => [invocation.skillId, invocation])
|
|
5586
5776
|
);
|
|
@@ -5600,7 +5790,7 @@ function createSkillRepo(db) {
|
|
|
5600
5790
|
}
|
|
5601
5791
|
|
|
5602
5792
|
// src/db/ticket-destination-recent-repo.ts
|
|
5603
|
-
import { and as
|
|
5793
|
+
import { and as and20, desc as desc10, eq as eq27 } from "drizzle-orm";
|
|
5604
5794
|
function map4(row) {
|
|
5605
5795
|
return { ...row };
|
|
5606
5796
|
}
|
|
@@ -5609,9 +5799,9 @@ function createTicketDestinationRecentRepo(db) {
|
|
|
5609
5799
|
/** @internal */
|
|
5610
5800
|
list(actorKey, toolName, limit = 5) {
|
|
5611
5801
|
return db.select().from(ticketDestinationRecents).where(
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5802
|
+
and20(
|
|
5803
|
+
eq27(ticketDestinationRecents.actorKey, actorKey),
|
|
5804
|
+
eq27(ticketDestinationRecents.toolName, toolName)
|
|
5615
5805
|
)
|
|
5616
5806
|
).orderBy(
|
|
5617
5807
|
desc10(ticketDestinationRecents.updatedAt),
|
|
@@ -5620,10 +5810,10 @@ function createTicketDestinationRecentRepo(db) {
|
|
|
5620
5810
|
},
|
|
5621
5811
|
/** @internal */
|
|
5622
5812
|
record(input) {
|
|
5623
|
-
const match =
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5813
|
+
const match = and20(
|
|
5814
|
+
eq27(ticketDestinationRecents.actorKey, input.actorKey),
|
|
5815
|
+
eq27(ticketDestinationRecents.toolName, input.toolName),
|
|
5816
|
+
eq27(ticketDestinationRecents.destinationId, input.destinationId)
|
|
5627
5817
|
);
|
|
5628
5818
|
const existing = db.select().from(ticketDestinationRecents).where(match).get();
|
|
5629
5819
|
const updatedAt = now();
|
|
@@ -5644,16 +5834,16 @@ function createTicketDestinationRecentRepo(db) {
|
|
|
5644
5834
|
result = row;
|
|
5645
5835
|
}
|
|
5646
5836
|
const stale = db.select({ id: ticketDestinationRecents.id }).from(ticketDestinationRecents).where(
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5837
|
+
and20(
|
|
5838
|
+
eq27(ticketDestinationRecents.actorKey, input.actorKey),
|
|
5839
|
+
eq27(ticketDestinationRecents.toolName, input.toolName)
|
|
5650
5840
|
)
|
|
5651
5841
|
).orderBy(
|
|
5652
5842
|
desc10(ticketDestinationRecents.updatedAt),
|
|
5653
5843
|
desc10(ticketDestinationRecents.createdAt)
|
|
5654
5844
|
).all().slice(input.limit ?? 5);
|
|
5655
5845
|
for (const entry of stale) {
|
|
5656
|
-
db.delete(ticketDestinationRecents).where(
|
|
5846
|
+
db.delete(ticketDestinationRecents).where(eq27(ticketDestinationRecents.id, entry.id)).run();
|
|
5657
5847
|
}
|
|
5658
5848
|
return result;
|
|
5659
5849
|
}
|
|
@@ -5661,7 +5851,7 @@ function createTicketDestinationRecentRepo(db) {
|
|
|
5661
5851
|
}
|
|
5662
5852
|
|
|
5663
5853
|
// src/db/turn-start-record-repo.ts
|
|
5664
|
-
import { and as
|
|
5854
|
+
import { and as and21, eq as eq28 } from "drizzle-orm";
|
|
5665
5855
|
function map5(row) {
|
|
5666
5856
|
return {
|
|
5667
5857
|
id: row.id,
|
|
@@ -5673,6 +5863,7 @@ function map5(row) {
|
|
|
5673
5863
|
recoveryTurnRecordId: row.recoveryTurnRecordId ?? null,
|
|
5674
5864
|
continuation: row.continuationJson ? parsePersistedJson(row.continuationJson, "turn start continuation") : null,
|
|
5675
5865
|
state: parsePersistedJson(row.stateJson, "turn start state"),
|
|
5866
|
+
iteration: mappedItemRef(row),
|
|
5676
5867
|
createdAt: row.createdAt,
|
|
5677
5868
|
updatedAt: row.updatedAt
|
|
5678
5869
|
};
|
|
@@ -5694,28 +5885,31 @@ function createTurnStartRecordRepo(db) {
|
|
|
5694
5885
|
continuationJson: input.continuation ? JSON.stringify(input.continuation) : null,
|
|
5695
5886
|
stateJson: JSON.stringify(input.state),
|
|
5696
5887
|
createdAt: ts,
|
|
5697
|
-
updatedAt: ts
|
|
5888
|
+
updatedAt: ts,
|
|
5889
|
+
mappedRunId: input.iteration?.runId ?? null,
|
|
5890
|
+
mappedItemKey: input.iteration?.itemKey ?? null,
|
|
5891
|
+
mappedItemIndex: input.iteration?.itemIndex ?? null
|
|
5698
5892
|
};
|
|
5699
5893
|
db.insert(turnStartRecords).values(value).run();
|
|
5700
5894
|
return map5(value);
|
|
5701
5895
|
},
|
|
5702
5896
|
/** @internal */
|
|
5703
5897
|
getById(id) {
|
|
5704
|
-
const value = db.select().from(turnStartRecords).where(
|
|
5898
|
+
const value = db.select().from(turnStartRecords).where(eq28(turnStartRecords.id, id)).get();
|
|
5705
5899
|
return value ? map5(value) : null;
|
|
5706
5900
|
},
|
|
5707
5901
|
/** @internal */
|
|
5708
5902
|
listByInstance(instanceId) {
|
|
5709
|
-
return db.select().from(turnStartRecords).where(
|
|
5903
|
+
return db.select().from(turnStartRecords).where(eq28(turnStartRecords.instanceId, instanceId)).all().map(map5);
|
|
5710
5904
|
},
|
|
5711
5905
|
/** @internal */
|
|
5712
5906
|
compareAndSetState(input) {
|
|
5713
5907
|
const current = this.getById(input.id);
|
|
5714
5908
|
if (!current || current.state.kind !== input.expectedKind) return null;
|
|
5715
5909
|
const result = db.update(turnStartRecords).set({ stateJson: JSON.stringify(input.state), updatedAt: now() }).where(
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5910
|
+
and21(
|
|
5911
|
+
eq28(turnStartRecords.id, input.id),
|
|
5912
|
+
eq28(turnStartRecords.stateJson, JSON.stringify(current.state))
|
|
5719
5913
|
)
|
|
5720
5914
|
).run();
|
|
5721
5915
|
return result.changes === 1 ? this.getById(input.id) : null;
|
|
@@ -5724,7 +5918,7 @@ function createTurnStartRecordRepo(db) {
|
|
|
5724
5918
|
}
|
|
5725
5919
|
|
|
5726
5920
|
// src/db/worker-lease-repo.ts
|
|
5727
|
-
import { and as
|
|
5921
|
+
import { and as and22, asc as asc17, eq as eq29, isNull as isNull4 } from "drizzle-orm";
|
|
5728
5922
|
function rowToWorkerLease(row) {
|
|
5729
5923
|
return {
|
|
5730
5924
|
id: row.id,
|
|
@@ -5774,17 +5968,17 @@ function createWorkerLeaseRepo(db) {
|
|
|
5774
5968
|
},
|
|
5775
5969
|
/** @internal */
|
|
5776
5970
|
getByInstance(instanceId) {
|
|
5777
|
-
const row = db.select().from(workerLeases).where(
|
|
5971
|
+
const row = db.select().from(workerLeases).where(and22(eq29(workerLeases.instanceId, instanceId), isNull4(workerLeases.exitedAt))).get();
|
|
5778
5972
|
return row ? rowToWorkerLease(row) : null;
|
|
5779
5973
|
},
|
|
5780
5974
|
/** @internal */
|
|
5781
5975
|
getById(id) {
|
|
5782
|
-
const row = db.select().from(workerLeases).where(
|
|
5976
|
+
const row = db.select().from(workerLeases).where(eq29(workerLeases.id, id)).get();
|
|
5783
5977
|
return row ? rowToWorkerLease(row) : null;
|
|
5784
5978
|
},
|
|
5785
5979
|
/** @internal */
|
|
5786
5980
|
listByInstance(instanceId) {
|
|
5787
|
-
return db.select().from(workerLeases).where(
|
|
5981
|
+
return db.select().from(workerLeases).where(eq29(workerLeases.instanceId, instanceId)).orderBy(asc17(workerLeases.startedAt), asc17(workerLeases.id)).all().map(rowToWorkerLease);
|
|
5788
5982
|
},
|
|
5789
5983
|
/** @internal */
|
|
5790
5984
|
listActive() {
|
|
@@ -5804,29 +5998,29 @@ function createWorkerLeaseRepo(db) {
|
|
|
5804
5998
|
readyAt: input.readyAt,
|
|
5805
5999
|
exitedAt: input.exitedAt
|
|
5806
6000
|
};
|
|
5807
|
-
db.update(workerLeases).set(setValues).where(
|
|
5808
|
-
const row = db.select().from(workerLeases).where(
|
|
6001
|
+
db.update(workerLeases).set(setValues).where(eq29(workerLeases.id, id)).run();
|
|
6002
|
+
const row = db.select().from(workerLeases).where(eq29(workerLeases.id, id)).get();
|
|
5809
6003
|
return row ? rowToWorkerLease(row) : null;
|
|
5810
6004
|
},
|
|
5811
6005
|
/** @internal */
|
|
5812
6006
|
observeTimestamp(id, field) {
|
|
5813
6007
|
const column = workerLeases[field];
|
|
5814
|
-
db.update(workerLeases).set({ [field]: now() }).where(
|
|
6008
|
+
db.update(workerLeases).set({ [field]: now() }).where(and22(eq29(workerLeases.id, id), isNull4(column))).run();
|
|
5815
6009
|
return this.getById(id);
|
|
5816
6010
|
},
|
|
5817
6011
|
/** @internal */
|
|
5818
6012
|
updateHeartbeat(workerId) {
|
|
5819
|
-
const result = db.update(workerLeases).set({ lastHeartbeatAt: now() }).where(
|
|
6013
|
+
const result = db.update(workerLeases).set({ lastHeartbeatAt: now() }).where(eq29(workerLeases.workerId, workerId)).run();
|
|
5820
6014
|
return result.changes > 0;
|
|
5821
6015
|
},
|
|
5822
6016
|
/** Stores the first receipt only. Exact replay is accepted; changed receipts are rejected. @internal */
|
|
5823
6017
|
compareAndSetBootstrapReceipt(id, receipt) {
|
|
5824
|
-
const existing = db.select().from(workerLeases).where(
|
|
6018
|
+
const existing = db.select().from(workerLeases).where(eq29(workerLeases.id, id)).get();
|
|
5825
6019
|
if (!existing) return "missing";
|
|
5826
6020
|
const encoded = JSON.stringify(receipt);
|
|
5827
6021
|
if (existing.bootstrapReceiptJson !== null)
|
|
5828
6022
|
return existing.bootstrapReceiptJson === encoded ? "replay" : "changed";
|
|
5829
|
-
const result = db.update(workerLeases).set({ bootstrapReceiptJson: encoded }).where(
|
|
6023
|
+
const result = db.update(workerLeases).set({ bootstrapReceiptJson: encoded }).where(and22(eq29(workerLeases.id, id), isNull4(workerLeases.bootstrapReceiptJson))).run();
|
|
5830
6024
|
return result.changes === 1 ? "stored" : "changed";
|
|
5831
6025
|
}
|
|
5832
6026
|
};
|
|
@@ -5856,6 +6050,7 @@ function createAllRepos(db, options = {}) {
|
|
|
5856
6050
|
turnRecords: createProcessTurnRecordRepo(db),
|
|
5857
6051
|
turnStarts: createTurnStartRecordRepo(db),
|
|
5858
6052
|
turnAnnotations: createProcessTurnAnnotationRepo(db),
|
|
6053
|
+
mappedRuns: createMappedLlmRunRepo(db),
|
|
5859
6054
|
leases: createWorkerLeaseRepo(db),
|
|
5860
6055
|
providerCredentials: createProviderCredentialRepo(db, credentialCipher),
|
|
5861
6056
|
externalWrites: createExternalWriteLogRepo(db),
|
|
@@ -6872,9 +7067,9 @@ function createLaunchPipeline(deps) {
|
|
|
6872
7067
|
broadcast(run);
|
|
6873
7068
|
return run;
|
|
6874
7069
|
}
|
|
6875
|
-
function fail(id, stepId,
|
|
6876
|
-
mutate(id, (run) => failLaunchRun(run, stepId,
|
|
6877
|
-
return { kind: "failed", failure };
|
|
7070
|
+
function fail(id, stepId, failure2) {
|
|
7071
|
+
mutate(id, (run) => failLaunchRun(run, stepId, failure2.safeSummary));
|
|
7072
|
+
return { kind: "failed", failure: failure2 };
|
|
6878
7073
|
}
|
|
6879
7074
|
return {
|
|
6880
7075
|
open(input) {
|
|
@@ -6950,11 +7145,11 @@ function createLaunchPipeline(deps) {
|
|
|
6950
7145
|
};
|
|
6951
7146
|
} catch (error) {
|
|
6952
7147
|
const run = deps.launchRuns.getById(launchRunId);
|
|
6953
|
-
const
|
|
7148
|
+
const failure2 = adapter.unexpectedFailure?.(error) ?? {
|
|
6954
7149
|
safeSummary: "The launch could not be completed. Try again.",
|
|
6955
7150
|
value: error
|
|
6956
7151
|
};
|
|
6957
|
-
return fail(launchRunId, run ? activeStepId(run) : "validate_request",
|
|
7152
|
+
return fail(launchRunId, run ? activeStepId(run) : "validate_request", failure2);
|
|
6958
7153
|
} finally {
|
|
6959
7154
|
deps.launchRuns.deleteReplay(launchRunId);
|
|
6960
7155
|
}
|
|
@@ -6962,6 +7157,444 @@ function createLaunchPipeline(deps) {
|
|
|
6962
7157
|
};
|
|
6963
7158
|
}
|
|
6964
7159
|
|
|
7160
|
+
// src/pi-resources/bundle-cache.ts
|
|
7161
|
+
import { sha256Digest as sha256Digest2 } from "@leitwerk-dev/worker-protocol";
|
|
7162
|
+
|
|
7163
|
+
// src/model-providers/provider-boundary-utils.ts
|
|
7164
|
+
function positiveBound(value, fallback, name) {
|
|
7165
|
+
const resolved2 = value ?? fallback;
|
|
7166
|
+
if (!Number.isSafeInteger(resolved2) || resolved2 < 1) {
|
|
7167
|
+
throw new Error(`${name} must be a positive safe integer`);
|
|
7168
|
+
}
|
|
7169
|
+
return resolved2;
|
|
7170
|
+
}
|
|
7171
|
+
async function withTimeout(work, timeoutMs, sentinelMessage = "timeout") {
|
|
7172
|
+
let timer;
|
|
7173
|
+
try {
|
|
7174
|
+
return await Promise.race([
|
|
7175
|
+
work,
|
|
7176
|
+
new Promise((_resolve, reject) => {
|
|
7177
|
+
timer = setTimeout(() => reject(new Error(sentinelMessage)), timeoutMs);
|
|
7178
|
+
})
|
|
7179
|
+
]);
|
|
7180
|
+
} finally {
|
|
7181
|
+
if (timer) clearTimeout(timer);
|
|
7182
|
+
}
|
|
7183
|
+
}
|
|
7184
|
+
function validateCredentialStatus(value, message = "invalid credential status") {
|
|
7185
|
+
if (typeof value !== "object" || value === null || typeof value.available !== "boolean" || !(value.revision === null || Number.isSafeInteger(value.revision) && value.revision >= 0)) {
|
|
7186
|
+
throw new Error(message);
|
|
7187
|
+
}
|
|
7188
|
+
return value;
|
|
7189
|
+
}
|
|
7190
|
+
|
|
7191
|
+
// src/pi-resources/bundle-cache.ts
|
|
7192
|
+
var DEFAULT_MAX_ENTRIES = 64;
|
|
7193
|
+
var DEFAULT_MAX_BYTES = 256 * 1024 * 1024;
|
|
7194
|
+
function createPiResourceBundleCache(options = {}) {
|
|
7195
|
+
const maxEntries = positiveBound(options.maxEntries, DEFAULT_MAX_ENTRIES, "maxEntries");
|
|
7196
|
+
const maxBytes = positiveBound(options.maxBytes, DEFAULT_MAX_BYTES, "maxBytes");
|
|
7197
|
+
const entries = /* @__PURE__ */ new Map();
|
|
7198
|
+
let totalBytes = 0;
|
|
7199
|
+
function touch(entry) {
|
|
7200
|
+
entries.delete(entry.digest);
|
|
7201
|
+
entries.set(entry.digest, entry);
|
|
7202
|
+
}
|
|
7203
|
+
function oldestUnpinned(excluding) {
|
|
7204
|
+
for (const entry of entries.values()) {
|
|
7205
|
+
if (entry.digest !== excluding && entry.pins === 0) return entry;
|
|
7206
|
+
}
|
|
7207
|
+
return null;
|
|
7208
|
+
}
|
|
7209
|
+
function remove(entry) {
|
|
7210
|
+
if (!entries.delete(entry.digest)) return;
|
|
7211
|
+
totalBytes -= entry.bytes.byteLength;
|
|
7212
|
+
}
|
|
7213
|
+
function enforceBounds(newDigest) {
|
|
7214
|
+
while (entries.size > maxEntries || totalBytes > maxBytes) {
|
|
7215
|
+
const candidate2 = oldestUnpinned(newDigest);
|
|
7216
|
+
if (!candidate2) {
|
|
7217
|
+
const inserted = entries.get(newDigest);
|
|
7218
|
+
if (inserted?.pins === 0) remove(inserted);
|
|
7219
|
+
throw new Error("Pi resource bundle cache capacity is exhausted by pinned bundles");
|
|
7220
|
+
}
|
|
7221
|
+
remove(candidate2);
|
|
7222
|
+
}
|
|
7223
|
+
}
|
|
7224
|
+
return {
|
|
7225
|
+
put(bundle) {
|
|
7226
|
+
if (typeof bundle.digest !== "string" || sha256Digest2(bundle.bytes) !== bundle.digest) {
|
|
7227
|
+
throw new Error("Pi resource bundle digest does not match its bytes");
|
|
7228
|
+
}
|
|
7229
|
+
if (bundle.bytes.byteLength > maxBytes) {
|
|
7230
|
+
throw new Error(
|
|
7231
|
+
`Pi resource bundle size ${bundle.bytes.byteLength} exceeds cache byte limit ${maxBytes}`
|
|
7232
|
+
);
|
|
7233
|
+
}
|
|
7234
|
+
const existing = entries.get(bundle.digest);
|
|
7235
|
+
if (existing) {
|
|
7236
|
+
touch(existing);
|
|
7237
|
+
return;
|
|
7238
|
+
}
|
|
7239
|
+
const bytes = Uint8Array.from(bundle.bytes);
|
|
7240
|
+
const entry = {
|
|
7241
|
+
digest: bundle.digest,
|
|
7242
|
+
bytes,
|
|
7243
|
+
pins: 0
|
|
7244
|
+
};
|
|
7245
|
+
entries.set(entry.digest, entry);
|
|
7246
|
+
totalBytes += entry.bytes.byteLength;
|
|
7247
|
+
enforceBounds(entry.digest);
|
|
7248
|
+
},
|
|
7249
|
+
get(digest) {
|
|
7250
|
+
const entry = entries.get(digest);
|
|
7251
|
+
if (!entry) return null;
|
|
7252
|
+
touch(entry);
|
|
7253
|
+
return { digest: entry.digest, bytes: Uint8Array.from(entry.bytes) };
|
|
7254
|
+
},
|
|
7255
|
+
has: (digest) => entries.has(digest),
|
|
7256
|
+
pin(digest) {
|
|
7257
|
+
const entry = entries.get(digest);
|
|
7258
|
+
if (!entry) return false;
|
|
7259
|
+
entry.pins += 1;
|
|
7260
|
+
touch(entry);
|
|
7261
|
+
return true;
|
|
7262
|
+
},
|
|
7263
|
+
unpin(digest) {
|
|
7264
|
+
const entry = entries.get(digest);
|
|
7265
|
+
if (!entry || entry.pins === 0) return false;
|
|
7266
|
+
entry.pins -= 1;
|
|
7267
|
+
touch(entry);
|
|
7268
|
+
return true;
|
|
7269
|
+
},
|
|
7270
|
+
gc() {
|
|
7271
|
+
const removed = [...entries.values()].filter((entry) => entry.pins === 0);
|
|
7272
|
+
let removedBytes = 0;
|
|
7273
|
+
for (const entry of removed) {
|
|
7274
|
+
removedBytes += entry.bytes.byteLength;
|
|
7275
|
+
remove(entry);
|
|
7276
|
+
}
|
|
7277
|
+
return {
|
|
7278
|
+
removedDigests: removed.map((entry) => entry.digest),
|
|
7279
|
+
removedBytes
|
|
7280
|
+
};
|
|
7281
|
+
},
|
|
7282
|
+
stats() {
|
|
7283
|
+
const values = [...entries.values()];
|
|
7284
|
+
return {
|
|
7285
|
+
entries: entries.size,
|
|
7286
|
+
bytes: totalBytes,
|
|
7287
|
+
pinnedEntries: values.filter((entry) => entry.pins > 0).length,
|
|
7288
|
+
pins: values.reduce((total, entry) => total + entry.pins, 0)
|
|
7289
|
+
};
|
|
7290
|
+
}
|
|
7291
|
+
};
|
|
7292
|
+
}
|
|
7293
|
+
|
|
7294
|
+
// src/pi-resources/bundle-pin-lifecycle.ts
|
|
7295
|
+
function pinnedDigest(process2, turnStarts, turnRecords2) {
|
|
7296
|
+
if (process2.currentExecution?.kind !== "worker_start") return null;
|
|
7297
|
+
const start = turnStarts.getById(process2.currentExecution.id);
|
|
7298
|
+
if (!start || start.instanceId !== process2.id || start.turnType !== "llm") return null;
|
|
7299
|
+
if (start.state.kind !== "starting" && start.state.kind !== "accepted") return null;
|
|
7300
|
+
if (start.state.start.kind !== "llm") return null;
|
|
7301
|
+
return start.state.kind === "starting" || turnRecords2.getById(start.state.turnRecordId)?.status === "running" ? start.state.start.piResourceSnapshotDigest : null;
|
|
7302
|
+
}
|
|
7303
|
+
function createPiResourceBundlePinReconciler(deps) {
|
|
7304
|
+
const pinnedByInstance = /* @__PURE__ */ new Map();
|
|
7305
|
+
return {
|
|
7306
|
+
reconcile(process2) {
|
|
7307
|
+
const next = pinnedDigest(process2, deps.turnStarts, deps.turnRecords);
|
|
7308
|
+
const previous = pinnedByInstance.get(process2.id) ?? null;
|
|
7309
|
+
if (previous === next) {
|
|
7310
|
+
return { missingDigest: next && !deps.bundleCache.has(next) ? next : null };
|
|
7311
|
+
}
|
|
7312
|
+
if (previous) deps.bundleCache.unpin(previous);
|
|
7313
|
+
pinnedByInstance.delete(process2.id);
|
|
7314
|
+
if (!next) {
|
|
7315
|
+
return { missingDigest: null };
|
|
7316
|
+
}
|
|
7317
|
+
if (!deps.bundleCache.pin(next)) {
|
|
7318
|
+
return { missingDigest: next };
|
|
7319
|
+
}
|
|
7320
|
+
pinnedByInstance.set(process2.id, next);
|
|
7321
|
+
return { missingDigest: null };
|
|
7322
|
+
}
|
|
7323
|
+
};
|
|
7324
|
+
}
|
|
7325
|
+
|
|
7326
|
+
// src/pi-resources/assemble.ts
|
|
7327
|
+
import { lstat as lstat2, realpath as realpath2 } from "node:fs/promises";
|
|
7328
|
+
import path2 from "node:path";
|
|
7329
|
+
import {
|
|
7330
|
+
canonicalizeJson,
|
|
7331
|
+
canonicalJsonStringify,
|
|
7332
|
+
createCanonicalPiResourceBundle,
|
|
7333
|
+
PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION,
|
|
7334
|
+
sha256Digest as sha256Digest3,
|
|
7335
|
+
validateResourceRelativePath as validateResourceRelativePath2
|
|
7336
|
+
} from "@leitwerk-dev/worker-protocol";
|
|
7337
|
+
import { build } from "esbuild";
|
|
7338
|
+
import {
|
|
7339
|
+
PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION as PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION2
|
|
7340
|
+
} from "@leitwerk-dev/worker-protocol";
|
|
7341
|
+
function jsonBytes(value, location) {
|
|
7342
|
+
return Buffer.from(`${canonicalJsonStringify(value, location)}
|
|
7343
|
+
`, "utf8");
|
|
7344
|
+
}
|
|
7345
|
+
var FORBIDDEN_SECRET_KEYS = /* @__PURE__ */ new Set([
|
|
7346
|
+
"apikey",
|
|
7347
|
+
"accesstoken",
|
|
7348
|
+
"refreshtoken",
|
|
7349
|
+
"brokertoken",
|
|
7350
|
+
"clientsecret",
|
|
7351
|
+
"privatekey",
|
|
7352
|
+
"password",
|
|
7353
|
+
"secret",
|
|
7354
|
+
"authorization"
|
|
7355
|
+
]);
|
|
7356
|
+
function assertNoCredentialFields(value, location) {
|
|
7357
|
+
if (Array.isArray(value)) {
|
|
7358
|
+
value.forEach((item, index2) => {
|
|
7359
|
+
assertNoCredentialFields(item, `${location}[${index2}]`);
|
|
7360
|
+
});
|
|
7361
|
+
return;
|
|
7362
|
+
}
|
|
7363
|
+
if (typeof value !== "object" || value === null) return;
|
|
7364
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
7365
|
+
const normalizedKey = key.toLowerCase().replaceAll(/[^a-z0-9]/g, "");
|
|
7366
|
+
if (FORBIDDEN_SECRET_KEYS.has(normalizedKey)) {
|
|
7367
|
+
throw new Error(
|
|
7368
|
+
`${location}.${key} is credential-bearing and cannot enter a Pi resource snapshot`
|
|
7369
|
+
);
|
|
7370
|
+
}
|
|
7371
|
+
assertNoCredentialFields(nested, `${location}.${key}`);
|
|
7372
|
+
}
|
|
7373
|
+
}
|
|
7374
|
+
function safeExtensionSegment(ownerExtensionId) {
|
|
7375
|
+
const normalized = ownerExtensionId.normalize("NFKD").replaceAll(/[^A-Za-z0-9._-]+/g, "-").replaceAll(/^-+|-+$/g, "") || "extension";
|
|
7376
|
+
if (Buffer.byteLength(normalized, "utf8") <= 56) return normalized;
|
|
7377
|
+
return `${normalized.slice(0, 43)}-${sha256Digest3(Buffer.from(ownerExtensionId)).slice(0, 12)}`;
|
|
7378
|
+
}
|
|
7379
|
+
function extensionSnapshotPath(contribution, index2) {
|
|
7380
|
+
const prefix = String(index2 * 10).padStart(3, "0");
|
|
7381
|
+
return validateResourceRelativePath2(
|
|
7382
|
+
`extensions/${prefix}-${safeExtensionSegment(contribution.ownerExtensionId)}.js`
|
|
7383
|
+
);
|
|
7384
|
+
}
|
|
7385
|
+
var PI_CORE_EXTERNALS = ["@earendil-works/pi-ai", "@earendil-works/pi-coding-agent"];
|
|
7386
|
+
async function buildPiExtensionWrapper(entryPath) {
|
|
7387
|
+
const result = await build({
|
|
7388
|
+
absWorkingDir: path2.dirname(entryPath),
|
|
7389
|
+
bundle: true,
|
|
7390
|
+
stdin: {
|
|
7391
|
+
contents: `
|
|
7392
|
+
import contribution from ${JSON.stringify(entryPath)};
|
|
7393
|
+
import { readFileSync } from "node:fs";
|
|
7394
|
+
|
|
7395
|
+
function readGenerated() {
|
|
7396
|
+
return JSON.parse(readFileSync(new URL("../generated.json", import.meta.url), "utf8"));
|
|
7397
|
+
}
|
|
7398
|
+
|
|
7399
|
+
function credentialBag(generated) {
|
|
7400
|
+
let values;
|
|
7401
|
+
const load = () => {
|
|
7402
|
+
if (values) return values;
|
|
7403
|
+
values = {};
|
|
7404
|
+
for (const credentialPath of generated.declaredCredentialPaths) {
|
|
7405
|
+
if (typeof credentialPath !== "string" || credentialPath.startsWith("/") || credentialPath.includes("..") || credentialPath.includes("\\\\")) {
|
|
7406
|
+
throw new Error("Invalid declared Pi credential path");
|
|
7407
|
+
}
|
|
7408
|
+
const credential = JSON.parse(readFileSync(new URL("../" + credentialPath, import.meta.url), "utf8"));
|
|
7409
|
+
if (credential && typeof credential === "object" && !Array.isArray(credential)) Object.assign(values, credential);
|
|
7410
|
+
}
|
|
7411
|
+
return values;
|
|
7412
|
+
};
|
|
7413
|
+
return {
|
|
7414
|
+
get(key) { const value = load()[key]; return typeof value === "string" ? value : undefined; },
|
|
7415
|
+
require(key) { const value = this.get(key); if (value === undefined) throw new Error("Required Pi worker secret '" + key + "' is unavailable"); return value; },
|
|
7416
|
+
keys() { return Object.keys(load()).filter((key) => typeof load()[key] === "string").sort(); },
|
|
7417
|
+
};
|
|
7418
|
+
}
|
|
7419
|
+
|
|
7420
|
+
export default async function leitwerkPiExtension(pi) {
|
|
7421
|
+
if (typeof contribution !== "function") throw new Error("Leitwerk Pi worker entry must default-export a function");
|
|
7422
|
+
const generated = readGenerated();
|
|
7423
|
+
const workerConfig = generated.providerWorkerConfig === null ? null : generated.providerWorkerConfig?.value;
|
|
7424
|
+
const report = (event) => {
|
|
7425
|
+
if (!event || typeof event !== "object" || Array.isArray(event)) throw new Error("Pi worker report must be an object");
|
|
7426
|
+
pi.events?.emit?.("leitwerk:provider-report", event);
|
|
7427
|
+
};
|
|
7428
|
+
await contribution(pi, {
|
|
7429
|
+
model: { providerId: generated.model.providerId, modelId: generated.model.modelId },
|
|
7430
|
+
options: { ...generated.providerOptions },
|
|
7431
|
+
workerConfig,
|
|
7432
|
+
secrets: credentialBag(generated),
|
|
7433
|
+
report,
|
|
7434
|
+
});
|
|
7435
|
+
}
|
|
7436
|
+
`,
|
|
7437
|
+
resolveDir: path2.dirname(entryPath),
|
|
7438
|
+
sourcefile: "leitwerk-pi-wrapper.js"
|
|
7439
|
+
},
|
|
7440
|
+
format: "esm",
|
|
7441
|
+
platform: "node",
|
|
7442
|
+
target: "node22",
|
|
7443
|
+
write: false,
|
|
7444
|
+
minify: true,
|
|
7445
|
+
sourcemap: false,
|
|
7446
|
+
legalComments: "none",
|
|
7447
|
+
external: PI_CORE_EXTERNALS
|
|
7448
|
+
});
|
|
7449
|
+
const output = result.outputFiles[0];
|
|
7450
|
+
if (!output) throw new Error(`Pi extension wrapper did not produce output for '${entryPath}'`);
|
|
7451
|
+
return output.contents;
|
|
7452
|
+
}
|
|
7453
|
+
function normalizeCredentialPaths(paths) {
|
|
7454
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7455
|
+
const normalized = paths.map((credentialPath) => {
|
|
7456
|
+
const result = validateResourceRelativePath2(credentialPath);
|
|
7457
|
+
if (seen.has(result)) throw new Error(`Duplicate declared credential path '${result}'`);
|
|
7458
|
+
seen.add(result);
|
|
7459
|
+
return result;
|
|
7460
|
+
});
|
|
7461
|
+
return normalized.sort(compareResourcePaths);
|
|
7462
|
+
}
|
|
7463
|
+
function assertCredentialPathsDoNotOverlap(credentialPaths, immutablePaths) {
|
|
7464
|
+
const files = [...immutablePaths];
|
|
7465
|
+
for (const credentialPath of credentialPaths) {
|
|
7466
|
+
for (const immutablePath of files) {
|
|
7467
|
+
if (credentialPath === immutablePath || credentialPath.startsWith(`${immutablePath}/`) || immutablePath.startsWith(`${credentialPath}/`)) {
|
|
7468
|
+
throw new Error(
|
|
7469
|
+
`Declared credential path '${credentialPath}' overlaps immutable resource '${immutablePath}'`
|
|
7470
|
+
);
|
|
7471
|
+
}
|
|
7472
|
+
}
|
|
7473
|
+
}
|
|
7474
|
+
}
|
|
7475
|
+
function requireNonEmptyString(value, location) {
|
|
7476
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
7477
|
+
throw new Error(`${location} must be a non-empty string`);
|
|
7478
|
+
}
|
|
7479
|
+
}
|
|
7480
|
+
function validateAssemblyInput(input) {
|
|
7481
|
+
requireNonEmptyString(input.model.profileId, "model.profileId");
|
|
7482
|
+
requireNonEmptyString(input.model.providerId, "model.providerId");
|
|
7483
|
+
requireNonEmptyString(input.model.modelId, "model.modelId");
|
|
7484
|
+
requireNonEmptyString(input.model.thinkingLevel, "model.thinkingLevel");
|
|
7485
|
+
requireNonEmptyString(input.compatibility.workerApiVersion, "compatibility.workerApiVersion");
|
|
7486
|
+
requireNonEmptyString(input.compatibility.piVersion, "compatibility.piVersion");
|
|
7487
|
+
if (input.compatibility.protocolVersion !== void 0) {
|
|
7488
|
+
requireNonEmptyString(input.compatibility.protocolVersion, "compatibility.protocolVersion");
|
|
7489
|
+
}
|
|
7490
|
+
for (const [fieldId, value] of Object.entries(input.providerOptions)) {
|
|
7491
|
+
if (fieldId.trim() === "" || typeof value !== "string") {
|
|
7492
|
+
throw new Error("providerOptions must contain non-empty field ids and string values");
|
|
7493
|
+
}
|
|
7494
|
+
}
|
|
7495
|
+
if (input.providerWorkerConfig && (!Number.isSafeInteger(input.providerWorkerConfig.version) || input.providerWorkerConfig.version < 1)) {
|
|
7496
|
+
throw new Error("providerWorkerConfig.version must be a positive safe integer");
|
|
7497
|
+
}
|
|
7498
|
+
if (input.systemPrompt !== void 0 && input.systemPrompt !== null) {
|
|
7499
|
+
if (typeof input.systemPrompt !== "string") throw new Error("systemPrompt must be a string");
|
|
7500
|
+
}
|
|
7501
|
+
if (input.appendSystemPrompt !== void 0 && input.appendSystemPrompt !== null) {
|
|
7502
|
+
if (typeof input.appendSystemPrompt !== "string") {
|
|
7503
|
+
throw new Error("appendSystemPrompt must be a string");
|
|
7504
|
+
}
|
|
7505
|
+
}
|
|
7506
|
+
}
|
|
7507
|
+
async function assemblePiResourceSnapshot(input) {
|
|
7508
|
+
validateAssemblyInput(input);
|
|
7509
|
+
assertNoCredentialFields(input.piSettings, "piSettings");
|
|
7510
|
+
assertNoCredentialFields(input.piModels ?? {}, "piModels");
|
|
7511
|
+
assertNoCredentialFields(input.providerOptions, "providerOptions");
|
|
7512
|
+
assertNoCredentialFields(input.providerWorkerConfig?.value ?? {}, "providerWorkerConfig.value");
|
|
7513
|
+
const collector = new ResourceCollector(input.limits);
|
|
7514
|
+
const seenOwners = /* @__PURE__ */ new Set();
|
|
7515
|
+
const workerSourceIdentities = /* @__PURE__ */ new Map();
|
|
7516
|
+
const workerSourceRealPaths = /* @__PURE__ */ new Map();
|
|
7517
|
+
const settings = { ...input.piSettings, packages: [], defaultProjectTrust: "never" };
|
|
7518
|
+
collector.addBytes("settings.json", jsonBytes(settings, "settings.json"));
|
|
7519
|
+
collector.addBytes("models.json", jsonBytes(input.piModels ?? { providers: {} }, "models.json"));
|
|
7520
|
+
if (input.systemPrompt !== void 0 && input.systemPrompt !== null) {
|
|
7521
|
+
collector.addBytes("SYSTEM.md", Buffer.from(input.systemPrompt, "utf8"));
|
|
7522
|
+
}
|
|
7523
|
+
if (input.appendSystemPrompt !== void 0 && input.appendSystemPrompt !== null) {
|
|
7524
|
+
collector.addBytes("APPEND_SYSTEM.md", Buffer.from(input.appendSystemPrompt, "utf8"));
|
|
7525
|
+
}
|
|
7526
|
+
for (const layer of input.resourceLayers ?? []) collector.addBundle(layer.bundle, layer.owner);
|
|
7527
|
+
for (const [index2, contribution] of input.piContributions.entries()) {
|
|
7528
|
+
if (seenOwners.has(contribution.ownerExtensionId)) {
|
|
7529
|
+
throw new Error(
|
|
7530
|
+
`Extension '${contribution.ownerExtensionId}' appears more than once in Pi contributions`
|
|
7531
|
+
);
|
|
7532
|
+
}
|
|
7533
|
+
seenOwners.add(contribution.ownerExtensionId);
|
|
7534
|
+
const baseOwner = {
|
|
7535
|
+
ownerExtensionId: contribution.ownerExtensionId,
|
|
7536
|
+
packageName: contribution.packageName
|
|
7537
|
+
};
|
|
7538
|
+
if (contribution.workerEntryPath) {
|
|
7539
|
+
validatePhysicalSourcePath(contribution.workerEntryPath);
|
|
7540
|
+
const source = await lstat2(contribution.workerEntryPath);
|
|
7541
|
+
if (source.isSymbolicLink() || !source.isFile()) {
|
|
7542
|
+
throw new Error(
|
|
7543
|
+
`Pi resource source must be a regular file: ${contribution.workerEntryPath}`
|
|
7544
|
+
);
|
|
7545
|
+
}
|
|
7546
|
+
const identity = `${source.dev}:${source.ino}`;
|
|
7547
|
+
const physicalPath = await realpath2(contribution.workerEntryPath);
|
|
7548
|
+
const first = workerSourceIdentities.get(identity) ?? workerSourceRealPaths.get(physicalPath);
|
|
7549
|
+
if (first) {
|
|
7550
|
+
throw new Error(
|
|
7551
|
+
`Physical Pi resource file is included more than once: ${contribution.workerEntryPath} (first: ${first})`
|
|
7552
|
+
);
|
|
7553
|
+
}
|
|
7554
|
+
workerSourceIdentities.set(identity, contribution.workerEntryPath);
|
|
7555
|
+
workerSourceRealPaths.set(physicalPath, contribution.workerEntryPath);
|
|
7556
|
+
const snapshotPath = extensionSnapshotPath(contribution, index2);
|
|
7557
|
+
collector.addBytes(
|
|
7558
|
+
snapshotPath,
|
|
7559
|
+
await buildPiExtensionWrapper(contribution.workerEntryPath),
|
|
7560
|
+
{ kind: "extension", ...baseOwner }
|
|
7561
|
+
);
|
|
7562
|
+
}
|
|
7563
|
+
for (const skillDirectory of contribution.resources.skillDirectories) {
|
|
7564
|
+
await collector.addDirectory(skillDirectory, "skills", { kind: "skill", ...baseOwner });
|
|
7565
|
+
}
|
|
7566
|
+
for (const promptDirectory of contribution.resources.promptDirectories) {
|
|
7567
|
+
await collector.addDirectory(promptDirectory, "prompts", { kind: "prompt", ...baseOwner });
|
|
7568
|
+
}
|
|
7569
|
+
}
|
|
7570
|
+
const credentialPaths = normalizeCredentialPaths(input.declaredCredentialPaths);
|
|
7571
|
+
assertCredentialPathsDoNotOverlap(credentialPaths, [...collector.files.keys(), "generated.json"]);
|
|
7572
|
+
const provenance = collector.provenance.slice().sort((left, right) => compareResourcePaths(left.snapshotPath, right.snapshotPath));
|
|
7573
|
+
const generated = {
|
|
7574
|
+
schemaVersion: PI_RESOURCE_SNAPSHOT_SCHEMA_VERSION,
|
|
7575
|
+
model: { ...input.model },
|
|
7576
|
+
providerOptions: { ...input.providerOptions },
|
|
7577
|
+
providerWorkerConfig: input.providerWorkerConfig ? {
|
|
7578
|
+
version: input.providerWorkerConfig.version,
|
|
7579
|
+
value: canonicalizeJson(
|
|
7580
|
+
input.providerWorkerConfig.value,
|
|
7581
|
+
"providerWorkerConfig.value"
|
|
7582
|
+
)
|
|
7583
|
+
} : null,
|
|
7584
|
+
declaredCredentialPaths: credentialPaths,
|
|
7585
|
+
compatibility: { ...input.compatibility },
|
|
7586
|
+
provenance
|
|
7587
|
+
};
|
|
7588
|
+
collector.addBytes("generated.json", jsonBytes(generated, "generated.json"));
|
|
7589
|
+
const resourceFiles = collector.toResourceFiles();
|
|
7590
|
+
const bundle = createCanonicalPiResourceBundle(resourceFiles);
|
|
7591
|
+
return {
|
|
7592
|
+
bundle,
|
|
7593
|
+
generated,
|
|
7594
|
+
files: collector.provenance.map(({ snapshotPath, sha256, size }) => ({ path: snapshotPath, sha256, size })).sort((left, right) => compareResourcePaths(left.path, right.path))
|
|
7595
|
+
};
|
|
7596
|
+
}
|
|
7597
|
+
|
|
6965
7598
|
// src/process-operator-attention.ts
|
|
6966
7599
|
import { trimToNull as trimToNull6 } from "@leitwerk-dev/domain";
|
|
6967
7600
|
import { isHumanTurnDefinition } from "@leitwerk-dev/process-sdk";
|
|
@@ -7122,12 +7755,400 @@ function broadcastProcessAttentionToast(deps, input) {
|
|
|
7122
7755
|
return true;
|
|
7123
7756
|
}
|
|
7124
7757
|
|
|
7125
|
-
// src/
|
|
7126
|
-
function
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
|
|
7758
|
+
// src/worker-runtime-profile-selection.ts
|
|
7759
|
+
function trimToUndefined(value) {
|
|
7760
|
+
if (typeof value !== "string") {
|
|
7761
|
+
return void 0;
|
|
7762
|
+
}
|
|
7763
|
+
const trimmed = value.trim();
|
|
7764
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
7765
|
+
}
|
|
7766
|
+
function defaultWorkerRuntimeProfile(config) {
|
|
7767
|
+
if (config.workers.runner === "local") {
|
|
7768
|
+
return config.workers.default_runtime_profile ?? "local";
|
|
7769
|
+
}
|
|
7770
|
+
return (config.workers.runner === "kubernetes" ? config.kubernetes?.default_worker_runtime_profile : void 0) ?? config.workers.default_runtime_profile ?? null;
|
|
7771
|
+
}
|
|
7772
|
+
function selectWorkerRuntimeProfile(input) {
|
|
7773
|
+
const override = trimToUndefined(input.processOverride);
|
|
7774
|
+
if (override) {
|
|
7775
|
+
return resolveProfileImage(override, input.profiles);
|
|
7776
|
+
}
|
|
7777
|
+
const declared = input.componentProfiles.map((entry) => ({ component: entry.component, profile: trimToUndefined(entry.profile) })).filter(
|
|
7778
|
+
(entry) => entry.profile !== void 0
|
|
7779
|
+
);
|
|
7780
|
+
const distinct = new Set(declared.map((entry) => entry.profile));
|
|
7781
|
+
if (distinct.size > 1) {
|
|
7782
|
+
const summary = declared.map((entry) => `${entry.component}=${entry.profile}`).sort().join(", ");
|
|
7783
|
+
return {
|
|
7784
|
+
ok: false,
|
|
7785
|
+
error: `Process '${input.processId}' has conflicting component worker runtime profiles (${summary}); set process_configs.${input.processId}.worker_runtime_profile to resolve`
|
|
7786
|
+
};
|
|
7787
|
+
}
|
|
7788
|
+
if (distinct.size === 1) {
|
|
7789
|
+
const [only] = distinct;
|
|
7790
|
+
return resolveProfileImage(only, input.profiles);
|
|
7791
|
+
}
|
|
7792
|
+
const fallback = trimToUndefined(input.defaultProfile);
|
|
7793
|
+
if (!fallback) {
|
|
7794
|
+
return {
|
|
7795
|
+
ok: false,
|
|
7796
|
+
error: `Process '${input.processId}' selects no worker runtime profile and no default worker runtime profile is configured`
|
|
7797
|
+
};
|
|
7798
|
+
}
|
|
7799
|
+
return resolveProfileImage(fallback, input.profiles);
|
|
7800
|
+
}
|
|
7801
|
+
function resolveProfileImage(runtimeProfile, profiles) {
|
|
7802
|
+
const profile = profiles[runtimeProfile];
|
|
7803
|
+
if (!profile) {
|
|
7804
|
+
return {
|
|
7805
|
+
ok: false,
|
|
7806
|
+
error: `Unknown worker runtime profile '${runtimeProfile}'; configure it under worker_runtime_profiles`
|
|
7807
|
+
};
|
|
7808
|
+
}
|
|
7809
|
+
return {
|
|
7810
|
+
ok: true,
|
|
7811
|
+
runtimeProfile,
|
|
7812
|
+
image: { reference: profile.image }
|
|
7813
|
+
};
|
|
7814
|
+
}
|
|
7815
|
+
function buildRuntimeProfileSelectionInput(args) {
|
|
7816
|
+
const { config, processId, componentKeys } = args;
|
|
7817
|
+
const componentProfiles = componentKeys.map((component) => ({
|
|
7818
|
+
component,
|
|
7819
|
+
profile: config.components[component]?.worker_runtime_profile
|
|
7820
|
+
}));
|
|
7821
|
+
return {
|
|
7822
|
+
processId,
|
|
7823
|
+
processOverride: config.process_configs?.[processId]?.worker_runtime_profile,
|
|
7824
|
+
componentProfiles,
|
|
7825
|
+
defaultProfile: defaultWorkerRuntimeProfile(config) ?? void 0,
|
|
7826
|
+
profiles: config.worker_runtime_profiles ?? {}
|
|
7827
|
+
};
|
|
7828
|
+
}
|
|
7829
|
+
|
|
7830
|
+
// src/process-engine/turn-start-preflight.ts
|
|
7831
|
+
import { filterProviderOptionsForDefinition } from "@leitwerk-dev/process-sdk";
|
|
7832
|
+
import { IPC_PROTOCOL_VERSION, WORKER_API_VERSION } from "@leitwerk-dev/worker-protocol";
|
|
7833
|
+
|
|
7834
|
+
// src/model-providers/provider-options.ts
|
|
7835
|
+
import {
|
|
7836
|
+
resolveProviderOptions
|
|
7837
|
+
} from "@leitwerk-dev/process-sdk";
|
|
7838
|
+
var DEFAULT_OPTION_CHOICE_TIMEOUT_MS = 5e3;
|
|
7839
|
+
var DEFAULT_MAX_CHOICE_FIELDS = 64;
|
|
7840
|
+
var DEFAULT_MAX_CHOICES_PER_FIELD = 256;
|
|
7841
|
+
var DEFAULT_MAX_CHOICE_TEXT_LENGTH = 512;
|
|
7842
|
+
function resolveRegisteredProviderOptions(input) {
|
|
7843
|
+
return resolveProviderOptions({
|
|
7844
|
+
definition: input.provider.definition.options,
|
|
7845
|
+
config: input.provider.config,
|
|
7846
|
+
explicit: input.explicit,
|
|
7847
|
+
profileDefaults: input.profileDefaults
|
|
7848
|
+
});
|
|
7849
|
+
}
|
|
7850
|
+
function validateConfiguredProviderOptions(input) {
|
|
7851
|
+
const result = resolveRegisteredProviderOptions({
|
|
7852
|
+
provider: input.provider,
|
|
7853
|
+
profileDefaults: input.values
|
|
7854
|
+
});
|
|
7855
|
+
if (result.ok) {
|
|
7856
|
+
return [];
|
|
7857
|
+
}
|
|
7858
|
+
return result.issues.filter((issue2) => issue2.code !== "required");
|
|
7859
|
+
}
|
|
7860
|
+
async function loadProviderOptionChoices(input) {
|
|
7861
|
+
const choicesLoader = input.provider.definition.options?.choices;
|
|
7862
|
+
if (!choicesLoader) {
|
|
7863
|
+
return { ok: true, choices: {} };
|
|
7864
|
+
}
|
|
7865
|
+
const timeoutMs = positiveBound(
|
|
7866
|
+
input.timeoutMs,
|
|
7867
|
+
DEFAULT_OPTION_CHOICE_TIMEOUT_MS,
|
|
7868
|
+
"Provider option choice timeout"
|
|
7869
|
+
);
|
|
7870
|
+
const maxFields = positiveBound(
|
|
7871
|
+
input.maxFields,
|
|
7872
|
+
DEFAULT_MAX_CHOICE_FIELDS,
|
|
7873
|
+
"Maximum choice fields"
|
|
7874
|
+
);
|
|
7875
|
+
const maxChoices = positiveBound(
|
|
7876
|
+
input.maxChoicesPerField,
|
|
7877
|
+
DEFAULT_MAX_CHOICES_PER_FIELD,
|
|
7878
|
+
"Maximum choices per field"
|
|
7879
|
+
);
|
|
7880
|
+
const maxTextLength = positiveBound(
|
|
7881
|
+
input.maxTextLength,
|
|
7882
|
+
DEFAULT_MAX_CHOICE_TEXT_LENGTH,
|
|
7883
|
+
"Maximum choice text length"
|
|
7884
|
+
);
|
|
7885
|
+
try {
|
|
7886
|
+
const credentialStatus = validateCredentialStatus(
|
|
7887
|
+
await withTimeout(Promise.resolve(input.credentialStatus(input.provider)), timeoutMs)
|
|
7888
|
+
);
|
|
7889
|
+
const raw = await withTimeout(
|
|
7890
|
+
Promise.resolve(choicesLoader({ config: input.provider.config, credentialStatus })),
|
|
7891
|
+
timeoutMs
|
|
7892
|
+
);
|
|
7893
|
+
const entries = Object.entries(raw);
|
|
7894
|
+
if (entries.length > maxFields) {
|
|
7895
|
+
throw new Error("too many fields");
|
|
7896
|
+
}
|
|
7897
|
+
const fields = input.provider.definition.options?.fields ?? {};
|
|
7898
|
+
const bounded = {};
|
|
7899
|
+
for (const [fieldId, choices] of entries) {
|
|
7900
|
+
if (!(fieldId in fields) || !Array.isArray(choices) || choices.length > maxChoices) {
|
|
7901
|
+
throw new Error("invalid field choices");
|
|
7902
|
+
}
|
|
7903
|
+
bounded[fieldId] = choices.map((choice) => {
|
|
7904
|
+
if (typeof choice?.value !== "string" || typeof choice?.label !== "string" || choice.value.length > maxTextLength || choice.label.length > maxTextLength) {
|
|
7905
|
+
throw new Error("invalid choice");
|
|
7906
|
+
}
|
|
7907
|
+
return { value: choice.value, label: choice.label };
|
|
7908
|
+
});
|
|
7909
|
+
}
|
|
7910
|
+
return { ok: true, choices: bounded };
|
|
7911
|
+
} catch (error) {
|
|
7912
|
+
return {
|
|
7913
|
+
ok: false,
|
|
7914
|
+
safeReason: error instanceof Error && error.message === "timeout" ? "Provider option choices timed out" : "Provider option choices are temporarily unavailable"
|
|
7915
|
+
};
|
|
7916
|
+
}
|
|
7917
|
+
}
|
|
7918
|
+
|
|
7919
|
+
// src/process-engine/turn-start-preflight.ts
|
|
7920
|
+
var PI_RUNTIME_VERSION = "0.81.1";
|
|
7921
|
+
function failure(requestedModelProfileId, providerOptions, code, safeSummary, modelSelectionProvenance, availabilityRevision) {
|
|
7922
|
+
return {
|
|
7923
|
+
kind: "preparation_failed",
|
|
7924
|
+
requestedModelProfileId,
|
|
7925
|
+
providerOptions,
|
|
7926
|
+
code,
|
|
7927
|
+
safeSummary,
|
|
7928
|
+
...modelSelectionProvenance ? { modelSelectionProvenance } : {},
|
|
7929
|
+
...availabilityRevision !== void 0 ? { availabilityRevision } : {}
|
|
7930
|
+
};
|
|
7931
|
+
}
|
|
7932
|
+
function previousProviderOptions(state) {
|
|
7933
|
+
if (state.kind === "preparation_failed") return { ...state.providerOptions };
|
|
7934
|
+
if (state.kind === "superseded" || state.kind === "starting" || state.kind === "accepted") {
|
|
7935
|
+
return state.start?.kind === "llm" ? { ...state.start.providerOptions } : {};
|
|
7936
|
+
}
|
|
7937
|
+
return state.start.kind === "llm" ? { ...state.start.providerOptions } : {};
|
|
7938
|
+
}
|
|
7939
|
+
function previousProviderId(deps, state) {
|
|
7940
|
+
if (state.kind !== "preparation_failed") {
|
|
7941
|
+
return state.start?.kind === "llm" ? state.start.model.providerId : null;
|
|
7942
|
+
}
|
|
7943
|
+
const profileId = state.requestedModelProfileId;
|
|
7944
|
+
return profileId ? deps.config.pi.model_profiles.find((profile) => profile.id === profileId)?.provider ?? null : null;
|
|
7945
|
+
}
|
|
7946
|
+
function parkPreparationFailure(writes, write, state) {
|
|
7947
|
+
write.input.state = state;
|
|
7948
|
+
writes.processPatch.lifecycleStatus = "error";
|
|
7949
|
+
writes.workerIntent = { kind: "reconcile" };
|
|
7950
|
+
}
|
|
7951
|
+
function candidateProcess(process2, writes) {
|
|
7952
|
+
return { ...process2, ...writes.processPatch };
|
|
7953
|
+
}
|
|
7954
|
+
function resolveRuntimeProfile(deps, process2) {
|
|
7955
|
+
if (deps.config.workers.runner === "local") {
|
|
7956
|
+
return { ok: true, id: defaultWorkerRuntimeProfile(deps.config) ?? "local" };
|
|
7957
|
+
}
|
|
7958
|
+
const selection = selectWorkerRuntimeProfile(
|
|
7959
|
+
buildRuntimeProfileSelectionInput({
|
|
7960
|
+
config: deps.config,
|
|
7961
|
+
processId: process2.processId,
|
|
7962
|
+
componentKeys: deps.projects.listByInstance(process2.id).map((project) => project.key)
|
|
7963
|
+
})
|
|
7964
|
+
);
|
|
7965
|
+
return selection.ok ? { ok: true, id: selection.runtimeProfile } : { ok: false, message: selection.error };
|
|
7966
|
+
}
|
|
7967
|
+
function resolveProviderWorkerConfig(provider, options) {
|
|
7968
|
+
if (provider.definition.worker.kind !== "extension_pi_worker") return null;
|
|
7969
|
+
const definition = provider.definition.worker.config;
|
|
7970
|
+
if (!definition) return null;
|
|
7971
|
+
const projected = definition.resolve({ config: provider.config, options });
|
|
7972
|
+
const value = definition.schema.parse(projected);
|
|
7973
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
7974
|
+
throw new Error("Provider worker configuration must be a JSON object");
|
|
7975
|
+
}
|
|
7976
|
+
return { version: definition.version, value };
|
|
7977
|
+
}
|
|
7978
|
+
function resolveProviderPiModels(provider) {
|
|
7979
|
+
const worker = provider.definition.worker;
|
|
7980
|
+
return worker.kind === "configured_pi_provider" ? worker.resolveModels({ config: provider.config }) : { providers: {} };
|
|
7981
|
+
}
|
|
7982
|
+
function buildPiSettings(config) {
|
|
7983
|
+
return {
|
|
7984
|
+
retry: {
|
|
7985
|
+
enabled: config.pi.retry.enabled,
|
|
7986
|
+
maxRetries: config.pi.retry.max_retries,
|
|
7987
|
+
baseDelay: config.pi.retry.base_delay,
|
|
7988
|
+
provider: {
|
|
7989
|
+
timeout: config.pi.retry.provider.timeout,
|
|
7990
|
+
maxRetries: config.pi.retry.provider.max_retries,
|
|
7991
|
+
maxRetryDelay: config.pi.retry.provider.max_retry_delay
|
|
7992
|
+
}
|
|
7993
|
+
}
|
|
7994
|
+
};
|
|
7995
|
+
}
|
|
7996
|
+
async function prepareCreatedTurnStarts(deps, process2, writes, explicitProviderOptions, availabilitySnapshot) {
|
|
7997
|
+
const nextProcess = candidateProcess(process2, writes);
|
|
7998
|
+
const availability = availabilitySnapshot ?? deps.modelStatusCache.snapshot();
|
|
7999
|
+
const provenance = nextProcess.selectedTurnModelKind && nextProcess.selectedTurnModelSource ? {
|
|
8000
|
+
kind: nextProcess.selectedTurnModelKind,
|
|
8001
|
+
source: nextProcess.selectedTurnModelSource
|
|
8002
|
+
} : void 0;
|
|
8003
|
+
for (let index2 = 0; index2 < writes.turnStartWrites.length; index2 += 1) {
|
|
8004
|
+
const write = writes.turnStartWrites[index2];
|
|
8005
|
+
if (!write || write.kind !== "create" || write.input.turnType !== "llm") continue;
|
|
8006
|
+
const requestedProfileId = nextProcess.selectedTurnModelProfileId?.trim() || null;
|
|
8007
|
+
const retainedState = write.input.state;
|
|
8008
|
+
const retainedOptions = previousProviderOptions(retainedState);
|
|
8009
|
+
if (retainedState.kind === "preparation_failed" && retainedState.code === "invalid_model_configuration") {
|
|
8010
|
+
parkPreparationFailure(writes, write, retainedState);
|
|
8011
|
+
continue;
|
|
8012
|
+
}
|
|
8013
|
+
if (!requestedProfileId) {
|
|
8014
|
+
parkPreparationFailure(
|
|
8015
|
+
writes,
|
|
8016
|
+
write,
|
|
8017
|
+
failure(
|
|
8018
|
+
null,
|
|
8019
|
+
retainedOptions,
|
|
8020
|
+
"model_required",
|
|
8021
|
+
"Choose a model before retrying startup",
|
|
8022
|
+
void 0,
|
|
8023
|
+
availability.revision
|
|
8024
|
+
)
|
|
8025
|
+
);
|
|
8026
|
+
continue;
|
|
8027
|
+
}
|
|
8028
|
+
const profile = deps.config.pi.model_profiles.find((item) => item.id === requestedProfileId);
|
|
8029
|
+
if (!profile) {
|
|
8030
|
+
return {
|
|
8031
|
+
ok: false,
|
|
8032
|
+
code: "invalid_model_profile",
|
|
8033
|
+
message: `Unknown model profile '${requestedProfileId}'`
|
|
8034
|
+
};
|
|
8035
|
+
}
|
|
8036
|
+
const provider = deps.registry.require(profile.provider);
|
|
8037
|
+
const retainedProviderId = previousProviderId(deps, retainedState);
|
|
8038
|
+
const recoveryOptions = explicitProviderOptions ? { ...explicitProviderOptions } : retainedProviderId !== null && retainedProviderId !== provider.id ? {
|
|
8039
|
+
...filterProviderOptionsForDefinition(provider.definition.options, retainedOptions)
|
|
8040
|
+
} : retainedOptions;
|
|
8041
|
+
const optionResult = resolveRegisteredProviderOptions({
|
|
8042
|
+
provider,
|
|
8043
|
+
explicit: recoveryOptions,
|
|
8044
|
+
profileDefaults: profile.provider_options ?? {}
|
|
8045
|
+
});
|
|
8046
|
+
if (!optionResult.ok) {
|
|
8047
|
+
const onlyRequired = optionResult.issues.every((issue2) => issue2.code === "required");
|
|
8048
|
+
if (!onlyRequired) {
|
|
8049
|
+
return {
|
|
8050
|
+
ok: false,
|
|
8051
|
+
code: "invalid_provider_options",
|
|
8052
|
+
message: optionResult.issues.map((issue2) => issue2.message).join("; ")
|
|
8053
|
+
};
|
|
8054
|
+
}
|
|
8055
|
+
parkPreparationFailure(
|
|
8056
|
+
writes,
|
|
8057
|
+
write,
|
|
8058
|
+
failure(
|
|
8059
|
+
profile.id,
|
|
8060
|
+
recoveryOptions,
|
|
8061
|
+
"provider_options_required",
|
|
8062
|
+
optionResult.issues.map((issue2) => issue2.message).join("; ")
|
|
8063
|
+
)
|
|
8064
|
+
);
|
|
8065
|
+
continue;
|
|
8066
|
+
}
|
|
8067
|
+
const status = availability.profiles.find((candidate2) => candidate2.profileId === profile.id);
|
|
8068
|
+
if (!status || status.availability !== "available") {
|
|
8069
|
+
parkPreparationFailure(
|
|
8070
|
+
writes,
|
|
8071
|
+
write,
|
|
8072
|
+
failure(
|
|
8073
|
+
profile.id,
|
|
8074
|
+
recoveryOptions,
|
|
8075
|
+
!status || status.availability === "stale" ? "model_stale" : "model_unavailable",
|
|
8076
|
+
status?.safeReason ?? "The selected model status is stale",
|
|
8077
|
+
provenance,
|
|
8078
|
+
availability.revision
|
|
8079
|
+
)
|
|
8080
|
+
);
|
|
8081
|
+
continue;
|
|
8082
|
+
}
|
|
8083
|
+
try {
|
|
8084
|
+
const runtimeProfile = resolveRuntimeProfile(deps, nextProcess);
|
|
8085
|
+
if (!runtimeProfile.ok) throw new Error(runtimeProfile.message);
|
|
8086
|
+
const providerWorkerConfig = resolveProviderWorkerConfig(provider, optionResult.value);
|
|
8087
|
+
const piSettings = buildPiSettings(deps.config);
|
|
8088
|
+
const model = {
|
|
8089
|
+
profileId: profile.id,
|
|
8090
|
+
providerId: profile.provider,
|
|
8091
|
+
modelId: profile.model_id,
|
|
8092
|
+
thinkingLevel: profile.thinking_level ?? "off"
|
|
8093
|
+
};
|
|
8094
|
+
const resourceLayers = deps.processSkills.listResourceLayers(nextProcess.id);
|
|
8095
|
+
const assembled = await assemblePiResourceSnapshot({
|
|
8096
|
+
resourceLayers,
|
|
8097
|
+
piContributions: deps.piContributions,
|
|
8098
|
+
model,
|
|
8099
|
+
providerOptions: optionResult.value,
|
|
8100
|
+
providerWorkerConfig,
|
|
8101
|
+
piSettings,
|
|
8102
|
+
piModels: resolveProviderPiModels(provider),
|
|
8103
|
+
declaredCredentialPaths: [
|
|
8104
|
+
"auth.json",
|
|
8105
|
+
...provider.definition.worker.kind === "extension_pi_worker" ? provider.definition.worker.credentialFiles ?? [] : []
|
|
8106
|
+
],
|
|
8107
|
+
compatibility: {
|
|
8108
|
+
workerApiVersion: WORKER_API_VERSION,
|
|
8109
|
+
piVersion: PI_RUNTIME_VERSION,
|
|
8110
|
+
protocolVersion: IPC_PROTOCOL_VERSION
|
|
8111
|
+
}
|
|
8112
|
+
});
|
|
8113
|
+
deps.bundleCache.put(assembled.bundle);
|
|
8114
|
+
write.input.state = {
|
|
8115
|
+
kind: "starting",
|
|
8116
|
+
start: {
|
|
8117
|
+
kind: "llm",
|
|
8118
|
+
model,
|
|
8119
|
+
...provenance ? { modelSelectionProvenance: provenance } : {},
|
|
8120
|
+
availabilityRevision: availability.revision,
|
|
8121
|
+
providerOptions: { ...optionResult.value },
|
|
8122
|
+
providerWorkerConfig,
|
|
8123
|
+
piResourceSnapshotDigest: assembled.bundle.digest,
|
|
8124
|
+
workerRuntimeProfileId: runtimeProfile.id,
|
|
8125
|
+
piSettings
|
|
8126
|
+
}
|
|
8127
|
+
};
|
|
8128
|
+
writes.processPatch.lifecycleStatus = "active";
|
|
8129
|
+
writes.workerIntent = { kind: "restart_worker" };
|
|
8130
|
+
} catch {
|
|
8131
|
+
parkPreparationFailure(
|
|
8132
|
+
writes,
|
|
8133
|
+
write,
|
|
8134
|
+
failure(
|
|
8135
|
+
profile.id,
|
|
8136
|
+
{ ...optionResult.value },
|
|
8137
|
+
"provider_preflight_failed",
|
|
8138
|
+
"The provider could not prepare this worker start"
|
|
8139
|
+
)
|
|
8140
|
+
);
|
|
8141
|
+
}
|
|
8142
|
+
}
|
|
8143
|
+
return { ok: true };
|
|
8144
|
+
}
|
|
8145
|
+
|
|
8146
|
+
// src/process-operation-coordinator.ts
|
|
8147
|
+
function createProcessOperationCoordinator() {
|
|
8148
|
+
const tails = /* @__PURE__ */ new Map();
|
|
8149
|
+
return {
|
|
8150
|
+
async runExclusive(instanceId, operation) {
|
|
8151
|
+
const previous = tails.get(instanceId) ?? Promise.resolve();
|
|
7131
8152
|
const { promise: current, resolve: release } = Promise.withResolvers();
|
|
7132
8153
|
tails.set(instanceId, current);
|
|
7133
8154
|
await previous;
|
|
@@ -7152,7 +8173,7 @@ import {
|
|
|
7152
8173
|
stat,
|
|
7153
8174
|
unlink
|
|
7154
8175
|
} from "node:fs/promises";
|
|
7155
|
-
import
|
|
8176
|
+
import path3 from "node:path";
|
|
7156
8177
|
import { atomicWriteUtf8, isEnoent } from "@leitwerk-dev/process-sdk";
|
|
7157
8178
|
|
|
7158
8179
|
// src/pi-session-tree.ts
|
|
@@ -7376,13 +8397,13 @@ function assertSafeSessionInstanceId(instanceId) {
|
|
|
7376
8397
|
}
|
|
7377
8398
|
function resolveSessionSnapshotPath(rootDir, instanceId) {
|
|
7378
8399
|
assertSafeSessionInstanceId(instanceId);
|
|
7379
|
-
return
|
|
8400
|
+
return path3.join(rootDir, `${instanceId}.jsonl`);
|
|
7380
8401
|
}
|
|
7381
8402
|
async function atomicCopyFile(sourcePath, targetPath) {
|
|
7382
|
-
await mkdir(
|
|
7383
|
-
const tempPath =
|
|
7384
|
-
|
|
7385
|
-
`.${
|
|
8403
|
+
await mkdir(path3.dirname(targetPath), { recursive: true });
|
|
8404
|
+
const tempPath = path3.join(
|
|
8405
|
+
path3.dirname(targetPath),
|
|
8406
|
+
`.${path3.basename(targetPath)}.${randomUUID()}.tmp`
|
|
7386
8407
|
);
|
|
7387
8408
|
try {
|
|
7388
8409
|
await copyFile(sourcePath, tempPath);
|
|
@@ -7425,7 +8446,7 @@ async function loadSnapshotGeneration(treeFile, expectedSignature) {
|
|
|
7425
8446
|
}
|
|
7426
8447
|
}
|
|
7427
8448
|
function createFileBackedProcessSessionSnapshotStore(treeFilesDir) {
|
|
7428
|
-
const rootDir =
|
|
8449
|
+
const rootDir = path3.resolve(treeFilesDir);
|
|
7429
8450
|
const resolveTreeFile = (instanceId) => resolveSessionSnapshotPath(rootDir, instanceId);
|
|
7430
8451
|
return {
|
|
7431
8452
|
async readSnapshotHandle(instanceId) {
|
|
@@ -7857,7 +8878,7 @@ function buildTurnTraceIndexFromSession(input) {
|
|
|
7857
8878
|
|
|
7858
8879
|
// src/session-transfer-service.ts
|
|
7859
8880
|
import { createHash as createHash3 } from "node:crypto";
|
|
7860
|
-
import
|
|
8881
|
+
import path5 from "node:path";
|
|
7861
8882
|
import { Transform } from "node:stream";
|
|
7862
8883
|
import { pipeline } from "node:stream/promises";
|
|
7863
8884
|
import { setTimeout as delay } from "node:timers/promises";
|
|
@@ -7868,7 +8889,7 @@ import {
|
|
|
7868
8889
|
|
|
7869
8890
|
// src/supervisor/worker-storage-layout.ts
|
|
7870
8891
|
import { existsSync as existsSync3, mkdirSync as mkdirSync2 } from "node:fs";
|
|
7871
|
-
import
|
|
8892
|
+
import path4 from "node:path";
|
|
7872
8893
|
import { expandPiAgentDir } from "@leitwerk-dev/process-sdk/pi-config";
|
|
7873
8894
|
function normalizeContainerMountPath(mountPath) {
|
|
7874
8895
|
const trimmed = mountPath.trim();
|
|
@@ -7876,18 +8897,18 @@ function normalizeContainerMountPath(mountPath) {
|
|
|
7876
8897
|
return "/state";
|
|
7877
8898
|
}
|
|
7878
8899
|
const withLeadingSlash = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
7879
|
-
return
|
|
8900
|
+
return path4.posix.normalize(withLeadingSlash);
|
|
7880
8901
|
}
|
|
7881
8902
|
function joinContainerPath(mountPath, ...segments) {
|
|
7882
8903
|
const normalized = normalizeContainerMountPath(mountPath);
|
|
7883
|
-
return
|
|
8904
|
+
return path4.posix.join(normalized, ...segments);
|
|
7884
8905
|
}
|
|
7885
8906
|
function createLocalWorkerStorageLayout(input) {
|
|
7886
8907
|
return (instanceId) => {
|
|
7887
|
-
const processWorkspacesDir =
|
|
7888
|
-
const treeFilesDir =
|
|
7889
|
-
const workspaceRoot =
|
|
7890
|
-
const primaryTreeFile =
|
|
8908
|
+
const processWorkspacesDir = path4.resolve(input.processWorkspacesDir);
|
|
8909
|
+
const treeFilesDir = path4.resolve(input.treeFilesDir);
|
|
8910
|
+
const workspaceRoot = path4.join(processWorkspacesDir, instanceId);
|
|
8911
|
+
const primaryTreeFile = path4.join(treeFilesDir, `${instanceId}.jsonl`);
|
|
7891
8912
|
const resume = existsSync3(workspaceRoot) || existsSync3(primaryTreeFile);
|
|
7892
8913
|
mkdirSync2(processWorkspacesDir, { recursive: true });
|
|
7893
8914
|
mkdirSync2(treeFilesDir, { recursive: true });
|
|
@@ -7895,7 +8916,7 @@ function createLocalWorkerStorageLayout(input) {
|
|
|
7895
8916
|
return {
|
|
7896
8917
|
primaryTreeFile,
|
|
7897
8918
|
workspaceRoot,
|
|
7898
|
-
piResourceBundlesDir:
|
|
8919
|
+
piResourceBundlesDir: path4.join(workspaceRoot, ".leitwerk", "pi-resource-bundles"),
|
|
7899
8920
|
resume
|
|
7900
8921
|
};
|
|
7901
8922
|
};
|
|
@@ -7946,12 +8967,12 @@ function presentSessionTransferOperation(attempt) {
|
|
|
7946
8967
|
}
|
|
7947
8968
|
function relativeSessionCwd(input) {
|
|
7948
8969
|
if (!input.repositoryBacked) return null;
|
|
7949
|
-
const relative =
|
|
8970
|
+
const relative = path5.relative(path5.resolve(input.workspaceRoot), path5.resolve(input.sourceCwd));
|
|
7950
8971
|
if (relative === "") return ".";
|
|
7951
|
-
if (relative === ".." || relative.startsWith(`..${
|
|
8972
|
+
if (relative === ".." || relative.startsWith(`..${path5.sep}`) || path5.isAbsolute(relative)) {
|
|
7952
8973
|
throw new Error("Repository-backed Pi session cwd is outside the process workspace");
|
|
7953
8974
|
}
|
|
7954
|
-
return relative.split(
|
|
8975
|
+
return relative.split(path5.sep).join("/");
|
|
7955
8976
|
}
|
|
7956
8977
|
function createSessionTransferService(deps) {
|
|
7957
8978
|
const now2 = deps.now ?? (() => /* @__PURE__ */ new Date());
|
|
@@ -8469,11 +9490,204 @@ function normalizeExternalObservation(value) {
|
|
|
8469
9490
|
if (typeof raw.observedAt !== "string" || !Number.isFinite(Date.parse(raw.observedAt)) || typeof raw.subject !== "string" || !raw.subject.trim() || typeof raw.revision !== "string")
|
|
8470
9491
|
return null;
|
|
8471
9492
|
return {
|
|
8472
|
-
summary: description.summary,
|
|
8473
|
-
...description.links ? { links: description.links } : {},
|
|
8474
|
-
observedAt: raw.observedAt,
|
|
8475
|
-
subject: raw.subject,
|
|
8476
|
-
revision: raw.revision
|
|
9493
|
+
summary: description.summary,
|
|
9494
|
+
...description.links ? { links: description.links } : {},
|
|
9495
|
+
observedAt: raw.observedAt,
|
|
9496
|
+
subject: raw.subject,
|
|
9497
|
+
revision: raw.revision
|
|
9498
|
+
};
|
|
9499
|
+
}
|
|
9500
|
+
|
|
9501
|
+
// src/future-execution-presenter.ts
|
|
9502
|
+
import { parseFutureActionPayloadJson, parseFutureLaunchPayloadJson } from "@leitwerk-dev/protocol";
|
|
9503
|
+
|
|
9504
|
+
// src/process-action-presenter.ts
|
|
9505
|
+
import { isLlmTurnDefinition as isLlmTurnDefinition2 } from "@leitwerk-dev/process-sdk";
|
|
9506
|
+
function actionHasPurePlan(deps, process2, actionId) {
|
|
9507
|
+
const action = deps.processActionRegistry?.getAction(process2.processId, actionId);
|
|
9508
|
+
return typeof action?.plan === "function";
|
|
9509
|
+
}
|
|
9510
|
+
function buildActionSummaryForProcess(deps, process2, action, visibleAction, labelOverride, overrides = {}) {
|
|
9511
|
+
const actionId = action.id;
|
|
9512
|
+
const preview = visibleAction?.preview ?? deps.processActionRegistry?.resolveActionPreview(process2.processId, process2, actionId) ?? null;
|
|
9513
|
+
const supportsScheduling = overrides.supportsScheduling ?? Boolean(
|
|
9514
|
+
actionHasPurePlan(deps, process2, actionId) && deps.processActionRegistry?.resolveActionScheduling(process2.processId, process2, actionId)
|
|
9515
|
+
);
|
|
9516
|
+
const label = labelOverride ?? visibleAction?.label ?? action.label;
|
|
9517
|
+
return {
|
|
9518
|
+
id: action.id,
|
|
9519
|
+
label: label.trim() ? label : action.label,
|
|
9520
|
+
description: visibleAction?.description ?? null,
|
|
9521
|
+
preview: buildProcessActionPreviewSummary(deps, preview, process2),
|
|
9522
|
+
supportsScheduling,
|
|
9523
|
+
supportsNextTurnModelOverride: previewSupportsNextTurnModelOverride(
|
|
9524
|
+
deps,
|
|
9525
|
+
process2,
|
|
9526
|
+
actionId,
|
|
9527
|
+
preview
|
|
9528
|
+
),
|
|
9529
|
+
...action.form ? {
|
|
9530
|
+
form: {
|
|
9531
|
+
id: action.form.id,
|
|
9532
|
+
title: action.form.title,
|
|
9533
|
+
submitLabel: action.form.submitLabel,
|
|
9534
|
+
fields: action.form.fields.map((field) => ({ ...field }))
|
|
9535
|
+
}
|
|
9536
|
+
} : {}
|
|
9537
|
+
};
|
|
9538
|
+
}
|
|
9539
|
+
function listVisibleActionsForProcess2(deps, process2) {
|
|
9540
|
+
return listVisibleActionsForProcess(deps, process2).map(
|
|
9541
|
+
(action) => buildActionSummaryForProcess(deps, process2, action, action, action.label)
|
|
9542
|
+
);
|
|
9543
|
+
}
|
|
9544
|
+
function buildProcessActionPreviewSummary(deps, preview, process2) {
|
|
9545
|
+
if (!preview) {
|
|
9546
|
+
return null;
|
|
9547
|
+
}
|
|
9548
|
+
if (!preview.candidateSelectedTurnId) {
|
|
9549
|
+
return {
|
|
9550
|
+
kind: "terminal",
|
|
9551
|
+
turnId: null,
|
|
9552
|
+
turnKind: null,
|
|
9553
|
+
description: preview.lifecycleStatus === "aborted" ? "Abort process" : "Complete process"
|
|
9554
|
+
};
|
|
9555
|
+
}
|
|
9556
|
+
const turnDef = deps.processActionRegistry?.getTurnDefinition(
|
|
9557
|
+
process2.processId,
|
|
9558
|
+
preview.candidateSelectedTurnId
|
|
9559
|
+
);
|
|
9560
|
+
if (!turnDef) {
|
|
9561
|
+
return null;
|
|
9562
|
+
}
|
|
9563
|
+
return {
|
|
9564
|
+
kind: "turn",
|
|
9565
|
+
turnId: preview.candidateSelectedTurnId,
|
|
9566
|
+
turnKind: turnDef.kind,
|
|
9567
|
+
description: turnDef.description
|
|
9568
|
+
};
|
|
9569
|
+
}
|
|
9570
|
+
function previewSupportsNextTurnModelOverride(deps, process2, actionId, preview) {
|
|
9571
|
+
if (!preview?.candidateSelectedTurnId) {
|
|
9572
|
+
return false;
|
|
9573
|
+
}
|
|
9574
|
+
if (!actionHasPurePlan(deps, process2, actionId)) {
|
|
9575
|
+
return false;
|
|
9576
|
+
}
|
|
9577
|
+
const turnDef = deps.processActionRegistry?.getTurnDefinition(
|
|
9578
|
+
process2.processId,
|
|
9579
|
+
preview.candidateSelectedTurnId
|
|
9580
|
+
);
|
|
9581
|
+
return Boolean(turnDef && isLlmTurnDefinition2(turnDef));
|
|
9582
|
+
}
|
|
9583
|
+
|
|
9584
|
+
// src/future-execution-presenter.ts
|
|
9585
|
+
function futureSummaryState(execution) {
|
|
9586
|
+
return {
|
|
9587
|
+
id: execution.id,
|
|
9588
|
+
nextRunAt: execution.nextRunAt,
|
|
9589
|
+
status: execution.blockedReason ? "blocked" : "scheduled",
|
|
9590
|
+
modelSelection: execution.modelSelection ?? null,
|
|
9591
|
+
blockedReason: execution.blockedReason ?? null
|
|
9592
|
+
};
|
|
9593
|
+
}
|
|
9594
|
+
function futureActionLabel(label, fallback) {
|
|
9595
|
+
return typeof label === "string" && label.trim() !== "" ? label : fallback;
|
|
9596
|
+
}
|
|
9597
|
+
function buildFutureExecutionListView(deps, execution) {
|
|
9598
|
+
const summary = {
|
|
9599
|
+
...futureSummaryState(execution),
|
|
9600
|
+
scheduleKind: execution.scheduleKind,
|
|
9601
|
+
processId: execution.processId,
|
|
9602
|
+
cronExpression: execution.cronExpression
|
|
9603
|
+
};
|
|
9604
|
+
if (execution.kind === "launch") {
|
|
9605
|
+
const launcher = deps.launcherService.listUiLaunchers().find((candidate2) => candidate2.id === execution.launcherId);
|
|
9606
|
+
const parsedPayload2 = parseFutureLaunchPayloadJson(execution.payloadJson);
|
|
9607
|
+
if (!parsedPayload2.ok) {
|
|
9608
|
+
const launcherLabel = launcher?.label ?? execution.launcherId ?? execution.processId;
|
|
9609
|
+
return {
|
|
9610
|
+
...summary,
|
|
9611
|
+
kind: "launch",
|
|
9612
|
+
title: launcher?.card.title ?? launcherLabel,
|
|
9613
|
+
subtitle: `${launcherLabel} \xB7 invalid scheduled start`,
|
|
9614
|
+
launcherId: execution.launcherId ?? execution.processId,
|
|
9615
|
+
launcherLabel,
|
|
9616
|
+
launchTitle: null,
|
|
9617
|
+
launcherInput: {},
|
|
9618
|
+
skillIds: [],
|
|
9619
|
+
modelConfig: {}
|
|
9620
|
+
};
|
|
9621
|
+
}
|
|
9622
|
+
const payload2 = parsedPayload2.value;
|
|
9623
|
+
const title = typeof payload2.launchPlan.processInput.title === "string" && payload2.launchPlan.processInput.title.trim() !== "" ? payload2.launchPlan.processInput.title : typeof payload2.launchPlan.processInput.externalId === "string" && payload2.launchPlan.processInput.externalId.trim() !== "" ? payload2.launchPlan.processInput.externalId : launcher?.card.title ?? launcher?.label ?? payload2.launchPlan.processId;
|
|
9624
|
+
const subtitle = execution.scheduleKind === "cron" ? `${launcher?.label ?? payload2.launchPlan.processId} \xB7 recurring cron` : `${launcher?.label ?? payload2.launchPlan.processId} \xB7 scheduled start`;
|
|
9625
|
+
return {
|
|
9626
|
+
...summary,
|
|
9627
|
+
kind: "launch",
|
|
9628
|
+
title,
|
|
9629
|
+
subtitle,
|
|
9630
|
+
launcherId: execution.launcherId ?? payload2.launchPlan.launcherId,
|
|
9631
|
+
launcherLabel: launcher?.label ?? payload2.launchPlan.launcherId,
|
|
9632
|
+
launchTitle: payload2.launchPlan.processInput.title,
|
|
9633
|
+
launcherInput: payload2.launcherInput,
|
|
9634
|
+
skillIds: [...payload2.selectedSkillIds],
|
|
9635
|
+
modelConfig: payload2.modelConfig
|
|
9636
|
+
};
|
|
9637
|
+
}
|
|
9638
|
+
if (!execution.instanceId || !execution.actionId) {
|
|
9639
|
+
return null;
|
|
9640
|
+
}
|
|
9641
|
+
const process2 = deps.processes.getById(execution.instanceId);
|
|
9642
|
+
const parsedPayload = parseFutureActionPayloadJson(execution.payloadJson);
|
|
9643
|
+
const payload = parsedPayload.ok ? parsedPayload.value : null;
|
|
9644
|
+
const actionLabel = futureActionLabel(payload?.actionLabel ?? null, execution.actionId);
|
|
9645
|
+
return {
|
|
9646
|
+
...summary,
|
|
9647
|
+
kind: "action",
|
|
9648
|
+
title: process2?.title ?? process2?.externalId ?? actionLabel,
|
|
9649
|
+
subtitle: `${actionLabel} \xB7 ${payload ? "scheduled action" : "invalid scheduled action"}`,
|
|
9650
|
+
instanceId: execution.instanceId,
|
|
9651
|
+
actionId: execution.actionId,
|
|
9652
|
+
actionLabel,
|
|
9653
|
+
nextTurnModelProfileId: payload?.nextTurnModelProfileId ?? null
|
|
9654
|
+
};
|
|
9655
|
+
}
|
|
9656
|
+
function buildFutureExecutionSummaries(deps, executions) {
|
|
9657
|
+
return executions.map((execution) => buildFutureExecutionListView(deps, execution)).filter((execution) => execution !== null);
|
|
9658
|
+
}
|
|
9659
|
+
function getScheduledActionDetailForProcess(deps, process2) {
|
|
9660
|
+
if (!deps.processActionRegistry) {
|
|
9661
|
+
return null;
|
|
9662
|
+
}
|
|
9663
|
+
const scheduledAction = deps.futureExecutions.getScheduledActionByInstance(process2.id);
|
|
9664
|
+
if (!scheduledAction?.actionId) {
|
|
9665
|
+
return null;
|
|
9666
|
+
}
|
|
9667
|
+
const action = deps.processActionRegistry.getAction(process2.processId, scheduledAction.actionId);
|
|
9668
|
+
if (!action) {
|
|
9669
|
+
return null;
|
|
9670
|
+
}
|
|
9671
|
+
const parsedPayload = parseFutureActionPayloadJson(scheduledAction.payloadJson);
|
|
9672
|
+
if (!parsedPayload.ok) {
|
|
9673
|
+
return null;
|
|
9674
|
+
}
|
|
9675
|
+
const payload = parsedPayload.value;
|
|
9676
|
+
const actionLabel = futureActionLabel(payload.actionLabel, action.label);
|
|
9677
|
+
return {
|
|
9678
|
+
...futureSummaryState(scheduledAction),
|
|
9679
|
+
actionId: scheduledAction.actionId,
|
|
9680
|
+
actionLabel,
|
|
9681
|
+
input: payload.input,
|
|
9682
|
+
nextTurnModelProfileId: payload.nextTurnModelProfileId,
|
|
9683
|
+
action: buildActionSummaryForProcess(
|
|
9684
|
+
deps,
|
|
9685
|
+
process2,
|
|
9686
|
+
action,
|
|
9687
|
+
listCurrentVisibleActions(deps, process2).find((candidate2) => candidate2.id === action.id),
|
|
9688
|
+
actionLabel,
|
|
9689
|
+
{ supportsScheduling: true }
|
|
9690
|
+
)
|
|
8477
9691
|
};
|
|
8478
9692
|
}
|
|
8479
9693
|
|
|
@@ -8703,20 +9917,20 @@ function presentLaunchPlanPreparationIssues(issues) {
|
|
|
8703
9917
|
message: issue2.message
|
|
8704
9918
|
}));
|
|
8705
9919
|
}
|
|
8706
|
-
function presentProcessModelPolicyFailure(
|
|
8707
|
-
switch (
|
|
9920
|
+
function presentProcessModelPolicyFailure(failure2) {
|
|
9921
|
+
switch (failure2.code) {
|
|
8708
9922
|
case "model_required":
|
|
8709
9923
|
return "Choose a model before starting this turn";
|
|
8710
9924
|
case "unknown_model_profile":
|
|
8711
|
-
return `Unknown model profile '${
|
|
9925
|
+
return `Unknown model profile '${failure2.modelProfileId}'`;
|
|
8712
9926
|
case "model_profile_not_allowed":
|
|
8713
|
-
return `Model profile '${
|
|
9927
|
+
return `Model profile '${failure2.modelProfileId}' is not allowed for process '${failure2.processId}'`;
|
|
8714
9928
|
case "model_stale":
|
|
8715
|
-
return
|
|
9929
|
+
return failure2.reason ?? "Model status has not been refreshed";
|
|
8716
9930
|
case "model_unavailable":
|
|
8717
|
-
return
|
|
9931
|
+
return failure2.reason ?? "The selected model is unavailable";
|
|
8718
9932
|
case "invalid_model_configuration":
|
|
8719
|
-
return
|
|
9933
|
+
return failure2.source === "selection_provenance" ? "Persisted model selection provenance is invalid" : "Persisted model configuration is invalid";
|
|
8720
9934
|
case "stale_evaluation_snapshot":
|
|
8721
9935
|
return "Model availability changed repeatedly during evaluation";
|
|
8722
9936
|
}
|
|
@@ -8765,17 +9979,58 @@ function presentProcessModelConfiguration(projection) {
|
|
|
8765
9979
|
}
|
|
8766
9980
|
|
|
8767
9981
|
// src/process-turn-navigation.ts
|
|
9982
|
+
function iterationFor(run, item, index2, itemKey) {
|
|
9983
|
+
return {
|
|
9984
|
+
runId: run.id,
|
|
9985
|
+
itemKey,
|
|
9986
|
+
index: index2,
|
|
9987
|
+
count: run.itemCount,
|
|
9988
|
+
label: item?.label ?? itemKey
|
|
9989
|
+
};
|
|
9990
|
+
}
|
|
9991
|
+
function withItemLabel(description, iteration) {
|
|
9992
|
+
return `${description}: ${iteration.label}`;
|
|
9993
|
+
}
|
|
8768
9994
|
function presentProcessTurnNavigation(input) {
|
|
8769
|
-
const
|
|
8770
|
-
const
|
|
8771
|
-
|
|
9995
|
+
const runs = new Map(input.mapped?.runs.map((run) => [run.id, run]) ?? []);
|
|
9996
|
+
const items = new Map(
|
|
9997
|
+
input.mapped?.items.map((item) => [`${item.runId}:${item.itemIndex}`, item]) ?? []
|
|
9998
|
+
);
|
|
9999
|
+
const iterationsByRecordId = /* @__PURE__ */ new Map();
|
|
10000
|
+
for (const record3 of input.turnRecords ?? []) {
|
|
10001
|
+
const ref = record3.iteration;
|
|
10002
|
+
const run = ref ? runs.get(ref.runId) : void 0;
|
|
10003
|
+
if (!ref || !run) continue;
|
|
10004
|
+
iterationsByRecordId.set(
|
|
10005
|
+
record3.id,
|
|
10006
|
+
iterationFor(run, items.get(`${ref.runId}:${ref.itemIndex}`), ref.itemIndex, ref.itemKey)
|
|
10007
|
+
);
|
|
10008
|
+
}
|
|
10009
|
+
const describe = (turnId) => input.graph.turns.get(turnId)?.description.trim();
|
|
10010
|
+
const activeRun = input.mapped?.runs.find(
|
|
10011
|
+
(run) => run.status === "active" && run.turnId === input.selectedTurnId
|
|
10012
|
+
);
|
|
10013
|
+
const nextItem = input.lifecycleStatus === "active" && activeRun ? items.get(`${activeRun.id}:${activeRun.nextIndex + 1}`) : void 0;
|
|
10014
|
+
const path6 = input.graph.happyPath ?? [];
|
|
10015
|
+
const currentIndex = path6.indexOf(input.selectedTurnId ?? "");
|
|
10016
|
+
const nextId = input.lifecycleStatus === "active" && currentIndex >= 0 ? path6[currentIndex + 1] : void 0;
|
|
8772
10017
|
const next = nextId ? input.graph.turns.get(nextId) : void 0;
|
|
10018
|
+
let plannedNextTurn = next && nextId ? { turnId: nextId, description: next.description } : null;
|
|
10019
|
+
if (activeRun && nextItem) {
|
|
10020
|
+
const iteration = iterationFor(activeRun, nextItem, nextItem.itemIndex, nextItem.itemKey);
|
|
10021
|
+
plannedNextTurn = {
|
|
10022
|
+
turnId: activeRun.turnId,
|
|
10023
|
+
description: withItemLabel(describe(activeRun.turnId) || activeRun.turnId, iteration),
|
|
10024
|
+
iteration
|
|
10025
|
+
};
|
|
10026
|
+
}
|
|
8773
10027
|
return {
|
|
8774
|
-
turns: input.turns.map((turn) =>
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
10028
|
+
turns: input.turns.map((turn) => {
|
|
10029
|
+
const displayTurn = describe(turn.turnId) || turn.displayTurn;
|
|
10030
|
+
const iteration = iterationsByRecordId.get(turn.id);
|
|
10031
|
+
return iteration ? { ...turn, displayTurn: withItemLabel(displayTurn, iteration), iteration } : { ...turn, displayTurn };
|
|
10032
|
+
}),
|
|
10033
|
+
plannedNextTurn
|
|
8779
10034
|
};
|
|
8780
10035
|
}
|
|
8781
10036
|
|
|
@@ -8787,7 +10042,7 @@ import {
|
|
|
8787
10042
|
} from "@leitwerk-dev/domain";
|
|
8788
10043
|
import {
|
|
8789
10044
|
findUiLauncherById,
|
|
8790
|
-
isLlmTurnDefinition as
|
|
10045
|
+
isLlmTurnDefinition as isLlmTurnDefinition3
|
|
8791
10046
|
} from "@leitwerk-dev/process-sdk";
|
|
8792
10047
|
import {
|
|
8793
10048
|
createTemplateContext,
|
|
@@ -8801,116 +10056,6 @@ import {
|
|
|
8801
10056
|
} from "@leitwerk-dev/protocol";
|
|
8802
10057
|
import * as v2 from "valibot";
|
|
8803
10058
|
|
|
8804
|
-
// src/future-execution-presenter.ts
|
|
8805
|
-
import { parseFutureActionPayloadJson, parseFutureLaunchPayloadJson } from "@leitwerk-dev/protocol";
|
|
8806
|
-
function futureSummaryState(execution) {
|
|
8807
|
-
return {
|
|
8808
|
-
id: execution.id,
|
|
8809
|
-
nextRunAt: execution.nextRunAt,
|
|
8810
|
-
status: execution.blockedReason ? "blocked" : "scheduled",
|
|
8811
|
-
modelSelection: execution.modelSelection ?? null,
|
|
8812
|
-
blockedReason: execution.blockedReason ?? null
|
|
8813
|
-
};
|
|
8814
|
-
}
|
|
8815
|
-
function futureActionLabel(label, fallback) {
|
|
8816
|
-
return typeof label === "string" && label.trim() !== "" ? label : fallback;
|
|
8817
|
-
}
|
|
8818
|
-
function buildFutureExecutionListView(deps, execution) {
|
|
8819
|
-
const summary = {
|
|
8820
|
-
...futureSummaryState(execution),
|
|
8821
|
-
scheduleKind: execution.scheduleKind,
|
|
8822
|
-
processId: execution.processId,
|
|
8823
|
-
cronExpression: execution.cronExpression
|
|
8824
|
-
};
|
|
8825
|
-
if (execution.kind === "launch") {
|
|
8826
|
-
const launcher = deps.launcherService.listUiLaunchers().find((candidate2) => candidate2.id === execution.launcherId);
|
|
8827
|
-
const parsedPayload2 = parseFutureLaunchPayloadJson(execution.payloadJson);
|
|
8828
|
-
if (!parsedPayload2.ok) {
|
|
8829
|
-
const launcherLabel = launcher?.label ?? execution.launcherId ?? execution.processId;
|
|
8830
|
-
return {
|
|
8831
|
-
...summary,
|
|
8832
|
-
kind: "launch",
|
|
8833
|
-
title: launcher?.card.title ?? launcherLabel,
|
|
8834
|
-
subtitle: `${launcherLabel} \xB7 invalid scheduled start`,
|
|
8835
|
-
launcherId: execution.launcherId ?? execution.processId,
|
|
8836
|
-
launcherLabel,
|
|
8837
|
-
launchTitle: null,
|
|
8838
|
-
launcherInput: {},
|
|
8839
|
-
skillIds: [],
|
|
8840
|
-
modelConfig: {}
|
|
8841
|
-
};
|
|
8842
|
-
}
|
|
8843
|
-
const payload2 = parsedPayload2.value;
|
|
8844
|
-
const title = typeof payload2.launchPlan.processInput.title === "string" && payload2.launchPlan.processInput.title.trim() !== "" ? payload2.launchPlan.processInput.title : typeof payload2.launchPlan.processInput.externalId === "string" && payload2.launchPlan.processInput.externalId.trim() !== "" ? payload2.launchPlan.processInput.externalId : launcher?.card.title ?? launcher?.label ?? payload2.launchPlan.processId;
|
|
8845
|
-
const subtitle = execution.scheduleKind === "cron" ? `${launcher?.label ?? payload2.launchPlan.processId} \xB7 recurring cron` : `${launcher?.label ?? payload2.launchPlan.processId} \xB7 scheduled start`;
|
|
8846
|
-
return {
|
|
8847
|
-
...summary,
|
|
8848
|
-
kind: "launch",
|
|
8849
|
-
title,
|
|
8850
|
-
subtitle,
|
|
8851
|
-
launcherId: execution.launcherId ?? payload2.launchPlan.launcherId,
|
|
8852
|
-
launcherLabel: launcher?.label ?? payload2.launchPlan.launcherId,
|
|
8853
|
-
launchTitle: payload2.launchPlan.processInput.title,
|
|
8854
|
-
launcherInput: payload2.launcherInput,
|
|
8855
|
-
skillIds: [...payload2.selectedSkillIds],
|
|
8856
|
-
modelConfig: payload2.modelConfig
|
|
8857
|
-
};
|
|
8858
|
-
}
|
|
8859
|
-
if (!execution.instanceId || !execution.actionId) {
|
|
8860
|
-
return null;
|
|
8861
|
-
}
|
|
8862
|
-
const process2 = deps.processes.getById(execution.instanceId);
|
|
8863
|
-
const parsedPayload = parseFutureActionPayloadJson(execution.payloadJson);
|
|
8864
|
-
const payload = parsedPayload.ok ? parsedPayload.value : null;
|
|
8865
|
-
const actionLabel = futureActionLabel(payload?.actionLabel ?? null, execution.actionId);
|
|
8866
|
-
return {
|
|
8867
|
-
...summary,
|
|
8868
|
-
kind: "action",
|
|
8869
|
-
title: process2?.title ?? process2?.externalId ?? actionLabel,
|
|
8870
|
-
subtitle: `${actionLabel} \xB7 ${payload ? "scheduled action" : "invalid scheduled action"}`,
|
|
8871
|
-
instanceId: execution.instanceId,
|
|
8872
|
-
actionId: execution.actionId,
|
|
8873
|
-
actionLabel,
|
|
8874
|
-
nextTurnModelProfileId: payload?.nextTurnModelProfileId ?? null
|
|
8875
|
-
};
|
|
8876
|
-
}
|
|
8877
|
-
function buildFutureExecutionSummaries(deps, executions) {
|
|
8878
|
-
return executions.map((execution) => buildFutureExecutionListView(deps, execution)).filter((execution) => execution !== null);
|
|
8879
|
-
}
|
|
8880
|
-
function getScheduledActionDetailForProcess(deps, process2) {
|
|
8881
|
-
if (!deps.processActionRegistry) {
|
|
8882
|
-
return null;
|
|
8883
|
-
}
|
|
8884
|
-
const scheduledAction = deps.futureExecutions.getScheduledActionByInstance(process2.id);
|
|
8885
|
-
if (!scheduledAction?.actionId) {
|
|
8886
|
-
return null;
|
|
8887
|
-
}
|
|
8888
|
-
const action = deps.processActionRegistry.getAction(process2.processId, scheduledAction.actionId);
|
|
8889
|
-
if (!action) {
|
|
8890
|
-
return null;
|
|
8891
|
-
}
|
|
8892
|
-
const parsedPayload = parseFutureActionPayloadJson(scheduledAction.payloadJson);
|
|
8893
|
-
if (!parsedPayload.ok) {
|
|
8894
|
-
return null;
|
|
8895
|
-
}
|
|
8896
|
-
const payload = parsedPayload.value;
|
|
8897
|
-
const actionLabel = futureActionLabel(payload.actionLabel, action.label);
|
|
8898
|
-
return {
|
|
8899
|
-
...futureSummaryState(scheduledAction),
|
|
8900
|
-
actionId: scheduledAction.actionId,
|
|
8901
|
-
actionLabel,
|
|
8902
|
-
input: payload.input,
|
|
8903
|
-
nextTurnModelProfileId: payload.nextTurnModelProfileId,
|
|
8904
|
-
action: deps.buildActionSummaryForProcess(
|
|
8905
|
-
process2,
|
|
8906
|
-
scheduledAction.actionId,
|
|
8907
|
-
action,
|
|
8908
|
-
actionLabel,
|
|
8909
|
-
{ supportsScheduling: true }
|
|
8910
|
-
)
|
|
8911
|
-
};
|
|
8912
|
-
}
|
|
8913
|
-
|
|
8914
10059
|
// src/process-engine/internal-failures.ts
|
|
8915
10060
|
function isInternalEngineFailureCode(code) {
|
|
8916
10061
|
return code === "operation_failed" || code === "record_failed" || code === "post_commit_failed";
|
|
@@ -9083,7 +10228,7 @@ function buildProcessRunDetailsView(deps, process2, projects) {
|
|
|
9083
10228
|
continue;
|
|
9084
10229
|
}
|
|
9085
10230
|
const turnDef = deps.processActionRegistry?.getTurnDefinition(process2.processId, turnId);
|
|
9086
|
-
if (!turnDef || !
|
|
10231
|
+
if (!turnDef || !isLlmTurnDefinition3(turnDef)) {
|
|
9087
10232
|
continue;
|
|
9088
10233
|
}
|
|
9089
10234
|
turns.push({
|
|
@@ -9123,35 +10268,6 @@ function buildProcessRunDetailsView(deps, process2, projects) {
|
|
|
9123
10268
|
turns
|
|
9124
10269
|
};
|
|
9125
10270
|
}
|
|
9126
|
-
function actionHasPurePlan(deps, process2, actionId) {
|
|
9127
|
-
const action = deps.processActionRegistry?.getAction(process2.processId, actionId);
|
|
9128
|
-
return typeof action?.plan === "function";
|
|
9129
|
-
}
|
|
9130
|
-
function buildActionSummaryForProcess(deps, process2, actionId, action, labelOverride, overrides = {}) {
|
|
9131
|
-
const visibleAction = listCurrentVisibleActions(deps, process2).find(
|
|
9132
|
-
(candidate2) => candidate2.id === actionId
|
|
9133
|
-
);
|
|
9134
|
-
const preview = visibleAction?.preview ?? deps.processActionRegistry?.resolveActionPreview(process2.processId, process2, actionId) ?? null;
|
|
9135
|
-
const supportsScheduling = overrides.supportsScheduling ?? Boolean(
|
|
9136
|
-
actionHasPurePlan(deps, process2, actionId) && deps.processActionRegistry?.resolveActionScheduling(process2.processId, process2, actionId)
|
|
9137
|
-
);
|
|
9138
|
-
return buildProcessActionSummary(action, labelOverride ?? visibleAction?.label ?? action.label, {
|
|
9139
|
-
description: visibleAction?.description ?? null,
|
|
9140
|
-
preview: buildProcessActionPreviewSummary(deps, preview, process2),
|
|
9141
|
-
supportsScheduling,
|
|
9142
|
-
supportsNextTurnModelOverride: previewSupportsNextTurnModelOverride(
|
|
9143
|
-
deps,
|
|
9144
|
-
process2,
|
|
9145
|
-
actionId,
|
|
9146
|
-
preview
|
|
9147
|
-
)
|
|
9148
|
-
});
|
|
9149
|
-
}
|
|
9150
|
-
function listVisibleActionsForProcess2(deps, process2) {
|
|
9151
|
-
return listVisibleActionsForProcess(deps, process2).map(
|
|
9152
|
-
(action) => buildActionSummaryForProcess(deps, process2, action.id, action, action.label)
|
|
9153
|
-
);
|
|
9154
|
-
}
|
|
9155
10271
|
function processDefinesLeafOutcome(deps, process2) {
|
|
9156
10272
|
return deps.processUiRegistry?.getLeafOutcomeDefinition(process2.processId) != null;
|
|
9157
10273
|
}
|
|
@@ -9284,72 +10400,6 @@ function normalizeRecoveryModelRequest(value) {
|
|
|
9284
10400
|
});
|
|
9285
10401
|
return parsed.ok ? { ok: true, request: parsed.request } : parsed;
|
|
9286
10402
|
}
|
|
9287
|
-
function buildProcessActionPreviewSummary(deps, preview, process2) {
|
|
9288
|
-
if (!preview) {
|
|
9289
|
-
return null;
|
|
9290
|
-
}
|
|
9291
|
-
if (!preview.candidateSelectedTurnId) {
|
|
9292
|
-
return {
|
|
9293
|
-
kind: "terminal",
|
|
9294
|
-
turnId: null,
|
|
9295
|
-
turnKind: null,
|
|
9296
|
-
description: preview.lifecycleStatus === "aborted" ? "Abort process" : "Complete process"
|
|
9297
|
-
};
|
|
9298
|
-
}
|
|
9299
|
-
const turnDef = deps.processActionRegistry?.getTurnDefinition(
|
|
9300
|
-
process2.processId,
|
|
9301
|
-
preview.candidateSelectedTurnId
|
|
9302
|
-
);
|
|
9303
|
-
if (!turnDef) {
|
|
9304
|
-
return null;
|
|
9305
|
-
}
|
|
9306
|
-
return {
|
|
9307
|
-
kind: "turn",
|
|
9308
|
-
turnId: preview.candidateSelectedTurnId,
|
|
9309
|
-
turnKind: turnDef.kind,
|
|
9310
|
-
description: turnDef.description
|
|
9311
|
-
};
|
|
9312
|
-
}
|
|
9313
|
-
function previewSupportsNextTurnModelOverride(deps, process2, actionId, preview) {
|
|
9314
|
-
if (!preview?.candidateSelectedTurnId) {
|
|
9315
|
-
return false;
|
|
9316
|
-
}
|
|
9317
|
-
if (!actionHasPurePlan(deps, process2, actionId)) {
|
|
9318
|
-
return false;
|
|
9319
|
-
}
|
|
9320
|
-
const turnDef = deps.processActionRegistry?.getTurnDefinition(
|
|
9321
|
-
process2.processId,
|
|
9322
|
-
preview.candidateSelectedTurnId
|
|
9323
|
-
);
|
|
9324
|
-
return Boolean(turnDef && isLlmTurnDefinition2(turnDef));
|
|
9325
|
-
}
|
|
9326
|
-
function buildProcessActionSummary(action, labelOverride, opts = {}) {
|
|
9327
|
-
return {
|
|
9328
|
-
id: action.id,
|
|
9329
|
-
label: labelOverride?.trim() ? labelOverride : action.label,
|
|
9330
|
-
description: opts.description ?? null,
|
|
9331
|
-
preview: opts.preview ?? null,
|
|
9332
|
-
supportsScheduling: opts.supportsScheduling === true,
|
|
9333
|
-
supportsNextTurnModelOverride: opts.supportsNextTurnModelOverride === true,
|
|
9334
|
-
...action.form ? {
|
|
9335
|
-
form: {
|
|
9336
|
-
id: action.form.id,
|
|
9337
|
-
title: action.form.title,
|
|
9338
|
-
submitLabel: action.form.submitLabel,
|
|
9339
|
-
fields: action.form.fields.map((field) => ({ ...field }))
|
|
9340
|
-
}
|
|
9341
|
-
} : {}
|
|
9342
|
-
};
|
|
9343
|
-
}
|
|
9344
|
-
function getScheduledActionDetailForProcess2(deps, process2) {
|
|
9345
|
-
return getScheduledActionDetailForProcess(
|
|
9346
|
-
{
|
|
9347
|
-
...deps,
|
|
9348
|
-
buildActionSummaryForProcess: (process3, actionId, action, labelOverride, overrides) => buildActionSummaryForProcess(deps, process3, actionId, action, labelOverride, overrides)
|
|
9349
|
-
},
|
|
9350
|
-
process2
|
|
9351
|
-
);
|
|
9352
|
-
}
|
|
9353
10403
|
function buildLauncherModelConfigSchema(deps, processId) {
|
|
9354
10404
|
return presentLauncherModelConfigSchema(
|
|
9355
10405
|
deps.processModelPolicy.project({
|
|
@@ -9417,7 +10467,7 @@ function sendScheduledActionMutationResponse(reply, deps, outcome) {
|
|
|
9417
10467
|
const lockedProcess = deps.processes.getById(outcome.instanceId);
|
|
9418
10468
|
const body = {
|
|
9419
10469
|
kind: "scheduled",
|
|
9420
|
-
scheduledAction: lockedProcess ?
|
|
10470
|
+
scheduledAction: lockedProcess ? getScheduledActionDetailForProcess(deps, lockedProcess) : null,
|
|
9421
10471
|
...outcome.kind === "committed_with_reaction_error" ? { error: outcome.error, code: outcome.code } : {}
|
|
9422
10472
|
};
|
|
9423
10473
|
return reply.code(outcome.kind === "scheduled" && outcome.operation === "created" ? 201 : 200).send(body);
|
|
@@ -10113,13 +11163,13 @@ function setupDetail(event) {
|
|
|
10113
11163
|
return null;
|
|
10114
11164
|
}
|
|
10115
11165
|
const provider = asRecord(event.data.provider) ?? {};
|
|
10116
|
-
const
|
|
11166
|
+
const path6 = stringValueOrNull(event.data.path) ?? stringValueOrNull(provider.path);
|
|
10117
11167
|
const pollInterval = stringValueOrNull(event.data.pollInterval) ?? stringValueOrNull(provider.pollInterval);
|
|
10118
|
-
if (
|
|
10119
|
-
return `Watching ${
|
|
11168
|
+
if (path6 && pollInterval) {
|
|
11169
|
+
return `Watching ${path6} \xB7 polling every ${pollInterval}.`;
|
|
10120
11170
|
}
|
|
10121
|
-
if (
|
|
10122
|
-
return `Watching ${
|
|
11171
|
+
if (path6) {
|
|
11172
|
+
return `Watching ${path6}.`;
|
|
10123
11173
|
}
|
|
10124
11174
|
if (pollInterval) {
|
|
10125
11175
|
return `Polling every ${pollInterval}.`;
|
|
@@ -10449,6 +11499,10 @@ var ProcessUiSnapshotAssembler = class {
|
|
|
10449
11499
|
}
|
|
10450
11500
|
const projects = this.deps.projects.listByInstance(instanceId);
|
|
10451
11501
|
const turnRecords2 = this.deps.turnRecords.listByInstance(instanceId);
|
|
11502
|
+
const mapped = {
|
|
11503
|
+
runs: this.deps.mappedRuns?.listByInstance(instanceId) ?? [],
|
|
11504
|
+
items: this.deps.mappedRuns?.listItemsByInstance(instanceId) ?? []
|
|
11505
|
+
};
|
|
10452
11506
|
const events = compactDetailEvents(this.deps, instanceId, turnRecords2);
|
|
10453
11507
|
const turnAnnotations2 = this.deps.turnAnnotations.listByInstance(instanceId);
|
|
10454
11508
|
const inputs = this.deps.inputs.listByInstance(instanceId);
|
|
@@ -10547,7 +11601,9 @@ var ProcessUiSnapshotAssembler = class {
|
|
|
10547
11601
|
graph: getProcessGraph2(this.deps.processGraphs, process2.processId),
|
|
10548
11602
|
turns: projections.timeline.turns,
|
|
10549
11603
|
selectedTurnId: process2.selectedTurnId,
|
|
10550
|
-
lifecycleStatus: process2.lifecycleStatus
|
|
11604
|
+
lifecycleStatus: process2.lifecycleStatus,
|
|
11605
|
+
turnRecords: turnRecords2,
|
|
11606
|
+
mapped
|
|
10551
11607
|
});
|
|
10552
11608
|
return {
|
|
10553
11609
|
...projections,
|
|
@@ -10567,7 +11623,7 @@ var ProcessUiSnapshotAssembler = class {
|
|
|
10567
11623
|
processFlow: buildProcessFlowViewForProcess(this.deps.processGraphs, process2.processId),
|
|
10568
11624
|
definesLeafOutcome: processDefinesLeafOutcome(this.deps, process2),
|
|
10569
11625
|
selectedTurn,
|
|
10570
|
-
scheduledAction:
|
|
11626
|
+
scheduledAction: getScheduledActionDetailForProcess(this.deps, process2),
|
|
10571
11627
|
modelConfiguration,
|
|
10572
11628
|
runDetails,
|
|
10573
11629
|
launchConfiguration: buildProcessLaunchConfigurationView(this.deps, process2, projects),
|
|
@@ -11004,6 +12060,138 @@ function createBroadcaster() {
|
|
|
11004
12060
|
};
|
|
11005
12061
|
}
|
|
11006
12062
|
|
|
12063
|
+
// src/process-engine/writes/writes.ts
|
|
12064
|
+
import {
|
|
12065
|
+
CONTINUE_PROMPT_METADATA_KEY as CONTINUE_PROMPT_METADATA_KEY2,
|
|
12066
|
+
FAILED_TURN_RECOVERY_METADATA_KEY,
|
|
12067
|
+
SYSTEM_ACTOR as SYSTEM_ACTOR2
|
|
12068
|
+
} from "@leitwerk-dev/domain";
|
|
12069
|
+
var METADATA_KEY_GROUPS = {
|
|
12070
|
+
retry: ["retryForkPiEntryId", "retryFromTurnRecordId"],
|
|
12071
|
+
continuation: [
|
|
12072
|
+
"continueFromPiEntryId",
|
|
12073
|
+
"continueFromTurnRecordId",
|
|
12074
|
+
"continueSavedPrimaryLeafEntryId",
|
|
12075
|
+
CONTINUE_PROMPT_METADATA_KEY2,
|
|
12076
|
+
FAILED_TURN_RECOVERY_METADATA_KEY
|
|
12077
|
+
]
|
|
12078
|
+
};
|
|
12079
|
+
function createWrites(init = {}) {
|
|
12080
|
+
return {
|
|
12081
|
+
processPatch: init.processPatch ?? {},
|
|
12082
|
+
changedFields: [...init.changedFields ?? []],
|
|
12083
|
+
...init.projectWrite ? { projectWrite: init.projectWrite } : {},
|
|
12084
|
+
turnRecordWrites: [...init.turnRecordWrites ?? []],
|
|
12085
|
+
turnStartWrites: [...init.turnStartWrites ?? []],
|
|
12086
|
+
mappedRunWrites: [...init.mappedRunWrites ?? []],
|
|
12087
|
+
turnAnnotationWrites: [...init.turnAnnotationWrites ?? []],
|
|
12088
|
+
leafOutcomeSnapshotWrites: [...init.leafOutcomeSnapshotWrites ?? []],
|
|
12089
|
+
events: [...init.events ?? []],
|
|
12090
|
+
broadcasts: [...init.broadcasts ?? []],
|
|
12091
|
+
queuedInputs: [...init.queuedInputs ?? []],
|
|
12092
|
+
extensionEvents: [...init.extensionEvents ?? []],
|
|
12093
|
+
futureExecutionPlans: [...init.futureExecutionPlans ?? []],
|
|
12094
|
+
pendingExternalSourceFireWrites: [...init.pendingExternalSourceFireWrites ?? []],
|
|
12095
|
+
...init.workerIntent ? { workerIntent: init.workerIntent } : {}
|
|
12096
|
+
};
|
|
12097
|
+
}
|
|
12098
|
+
function mergeWrites(...writesList) {
|
|
12099
|
+
const merged = createWrites();
|
|
12100
|
+
for (const writes of writesList) {
|
|
12101
|
+
if (!writes) continue;
|
|
12102
|
+
Object.assign(merged.processPatch, writes.processPatch);
|
|
12103
|
+
for (const field of writes.changedFields) {
|
|
12104
|
+
if (!merged.changedFields.includes(field)) {
|
|
12105
|
+
merged.changedFields.push(field);
|
|
12106
|
+
}
|
|
12107
|
+
}
|
|
12108
|
+
if (writes.projectWrite) {
|
|
12109
|
+
if (merged.projectWrite) throw new Error("Cannot merge multiple process-project writes");
|
|
12110
|
+
merged.projectWrite = writes.projectWrite;
|
|
12111
|
+
}
|
|
12112
|
+
merged.turnRecordWrites.push(...writes.turnRecordWrites);
|
|
12113
|
+
merged.turnStartWrites.push(...writes.turnStartWrites);
|
|
12114
|
+
merged.mappedRunWrites.push(...writes.mappedRunWrites);
|
|
12115
|
+
merged.turnAnnotationWrites.push(...writes.turnAnnotationWrites);
|
|
12116
|
+
merged.leafOutcomeSnapshotWrites.push(...writes.leafOutcomeSnapshotWrites);
|
|
12117
|
+
merged.events.push(...writes.events);
|
|
12118
|
+
merged.broadcasts.push(...writes.broadcasts);
|
|
12119
|
+
merged.queuedInputs.push(...writes.queuedInputs);
|
|
12120
|
+
merged.extensionEvents.push(...writes.extensionEvents);
|
|
12121
|
+
merged.futureExecutionPlans.push(...writes.futureExecutionPlans);
|
|
12122
|
+
merged.pendingExternalSourceFireWrites.push(...writes.pendingExternalSourceFireWrites);
|
|
12123
|
+
if (writes.workerIntent) {
|
|
12124
|
+
merged.workerIntent = writes.workerIntent;
|
|
12125
|
+
}
|
|
12126
|
+
}
|
|
12127
|
+
return merged;
|
|
12128
|
+
}
|
|
12129
|
+
function isWriteBuildFailure(value) {
|
|
12130
|
+
return typeof value === "object" && value !== null && "ok" in value && value.ok === false;
|
|
12131
|
+
}
|
|
12132
|
+
function applyProcessPatchField(writes, process2, field, value) {
|
|
12133
|
+
if (process2[field] === value) {
|
|
12134
|
+
return;
|
|
12135
|
+
}
|
|
12136
|
+
writes.processPatch[field] = value;
|
|
12137
|
+
if (!writes.changedFields.includes(field)) {
|
|
12138
|
+
writes.changedFields.push(field);
|
|
12139
|
+
}
|
|
12140
|
+
}
|
|
12141
|
+
function applyMetadataPatch(writes, process2, nextMetadata) {
|
|
12142
|
+
if (JSON.stringify(process2.metadata ?? null) === JSON.stringify(nextMetadata)) {
|
|
12143
|
+
return;
|
|
12144
|
+
}
|
|
12145
|
+
writes.processPatch.metadata = nextMetadata;
|
|
12146
|
+
if (!writes.changedFields.includes("metadata")) {
|
|
12147
|
+
writes.changedFields.push("metadata");
|
|
12148
|
+
}
|
|
12149
|
+
}
|
|
12150
|
+
function updateProcessMetadata(writes, process2, clearGroups = [], update = () => {
|
|
12151
|
+
}) {
|
|
12152
|
+
const nextMetadata = process2.metadata ? { ...process2.metadata } : {};
|
|
12153
|
+
for (const group of clearGroups) {
|
|
12154
|
+
for (const key of METADATA_KEY_GROUPS[group]) delete nextMetadata[key];
|
|
12155
|
+
}
|
|
12156
|
+
update(nextMetadata);
|
|
12157
|
+
applyMetadataPatch(writes, process2, Object.keys(nextMetadata).length > 0 ? nextMetadata : null);
|
|
12158
|
+
}
|
|
12159
|
+
function appendProcessEvent(writes, process2, input) {
|
|
12160
|
+
writes.events.push({
|
|
12161
|
+
instanceId: process2.id,
|
|
12162
|
+
eventType: input.eventType,
|
|
12163
|
+
...input.data ? { data: input.data } : {}
|
|
12164
|
+
});
|
|
12165
|
+
writes.broadcasts.push({
|
|
12166
|
+
type: "process.event",
|
|
12167
|
+
payload: {
|
|
12168
|
+
eventType: input.eventType,
|
|
12169
|
+
level: input.level,
|
|
12170
|
+
message: input.message
|
|
12171
|
+
},
|
|
12172
|
+
instanceId: process2.id
|
|
12173
|
+
});
|
|
12174
|
+
}
|
|
12175
|
+
function stampActorOnEvents(writes, actor, eventType) {
|
|
12176
|
+
const resolvedActor = actor ?? SYSTEM_ACTOR2;
|
|
12177
|
+
let stamped = 0;
|
|
12178
|
+
for (const event of writes.events) {
|
|
12179
|
+
if (event.eventType === eventType) {
|
|
12180
|
+
event.data = { ...event.data ?? {}, actor: resolvedActor };
|
|
12181
|
+
stamped += 1;
|
|
12182
|
+
}
|
|
12183
|
+
}
|
|
12184
|
+
return stamped;
|
|
12185
|
+
}
|
|
12186
|
+
function stampActorOnQueuedInputs(writes, actor) {
|
|
12187
|
+
if (!actor) {
|
|
12188
|
+
return;
|
|
12189
|
+
}
|
|
12190
|
+
writes.queuedInputs = writes.queuedInputs.map(
|
|
12191
|
+
(queuedInput) => queuedInput.actor ? queuedInput : { ...queuedInput, actor }
|
|
12192
|
+
);
|
|
12193
|
+
}
|
|
12194
|
+
|
|
11007
12195
|
export {
|
|
11008
12196
|
resolveApiTokenPolicy,
|
|
11009
12197
|
ApiTokenValidationError,
|
|
@@ -11034,13 +12222,19 @@ export {
|
|
|
11034
12222
|
normalizeProcessTitleInput,
|
|
11035
12223
|
applySubmittedProcessTitleToLaunchPlan,
|
|
11036
12224
|
SKILL_RESOURCE_OWNER,
|
|
11037
|
-
compareResourcePaths,
|
|
11038
|
-
validatePhysicalSourcePath,
|
|
11039
12225
|
ResourceCollector,
|
|
11040
12226
|
createAllRepos,
|
|
11041
12227
|
recordTurnProgress,
|
|
11042
12228
|
normalizeExternalEventDescription,
|
|
11043
12229
|
normalizeExternalObservation,
|
|
12230
|
+
createWrites,
|
|
12231
|
+
mergeWrites,
|
|
12232
|
+
isWriteBuildFailure,
|
|
12233
|
+
applyProcessPatchField,
|
|
12234
|
+
updateProcessMetadata,
|
|
12235
|
+
appendProcessEvent,
|
|
12236
|
+
stampActorOnEvents,
|
|
12237
|
+
stampActorOnQueuedInputs,
|
|
11044
12238
|
buildProcessFlowViewForProcess,
|
|
11045
12239
|
getProcessGraph2 as getProcessGraph,
|
|
11046
12240
|
getProcessTurnGraph,
|
|
@@ -11068,10 +12262,22 @@ export {
|
|
|
11068
12262
|
createLaunchPipeline,
|
|
11069
12263
|
buildStartupEvidence,
|
|
11070
12264
|
projectLaunchRunStartup,
|
|
12265
|
+
positiveBound,
|
|
12266
|
+
withTimeout,
|
|
12267
|
+
validateCredentialStatus,
|
|
12268
|
+
resolveRegisteredProviderOptions,
|
|
12269
|
+
validateConfiguredProviderOptions,
|
|
12270
|
+
loadProviderOptionChoices,
|
|
12271
|
+
createPiResourceBundleCache,
|
|
12272
|
+
createPiResourceBundlePinReconciler,
|
|
11071
12273
|
getProcessDisplayName,
|
|
11072
12274
|
listVisibleActionsForProcess,
|
|
11073
12275
|
getSelectedTurnSummaryForProcess,
|
|
11074
12276
|
broadcastProcessAttentionToast,
|
|
12277
|
+
defaultWorkerRuntimeProfile,
|
|
12278
|
+
selectWorkerRuntimeProfile,
|
|
12279
|
+
buildRuntimeProfileSelectionInput,
|
|
12280
|
+
prepareCreatedTurnStarts,
|
|
11075
12281
|
createProcessOperationCoordinator,
|
|
11076
12282
|
ProcessSessionReader,
|
|
11077
12283
|
isSafeSessionInstanceId,
|
|
@@ -11081,13 +12287,14 @@ export {
|
|
|
11081
12287
|
authenticateBrowserRequest,
|
|
11082
12288
|
authenticateRequest,
|
|
11083
12289
|
requireApiActor,
|
|
12290
|
+
listVisibleActionsForProcess2,
|
|
11084
12291
|
buildFutureExecutionListView,
|
|
11085
12292
|
buildFutureExecutionSummaries,
|
|
12293
|
+
getScheduledActionDetailForProcess,
|
|
11086
12294
|
PRIMARY_PATH_ACTIVE_TURN_EVENT_LIMIT,
|
|
11087
12295
|
routeConfig,
|
|
11088
12296
|
buildProcessLaunchConfigurationView,
|
|
11089
12297
|
buildProcessRunDetailsView,
|
|
11090
|
-
listVisibleActionsForProcess2,
|
|
11091
12298
|
processDefinesLeafOutcome,
|
|
11092
12299
|
getProcessOrReply,
|
|
11093
12300
|
normalizeLauncherRequest,
|
|
@@ -11096,7 +12303,6 @@ export {
|
|
|
11096
12303
|
sendActionRequestNormalizationError,
|
|
11097
12304
|
normalizeContinueRequest,
|
|
11098
12305
|
normalizeRecoveryModelRequest,
|
|
11099
|
-
getScheduledActionDetailForProcess2 as getScheduledActionDetailForProcess,
|
|
11100
12306
|
buildLauncherModelConfigSchema,
|
|
11101
12307
|
sendLauncherLookupFailure,
|
|
11102
12308
|
sendLauncherMutationResponse,
|
|
@@ -11112,4 +12318,4 @@ export {
|
|
|
11112
12318
|
createProjectedSessionSnapshotStore,
|
|
11113
12319
|
createBroadcaster
|
|
11114
12320
|
};
|
|
11115
|
-
//# sourceMappingURL=chunk-
|
|
12321
|
+
//# sourceMappingURL=chunk-HK6BLLHA.js.map
|