@leitwerk-dev/server 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{app-BuJCdkvy.d.ts → app-CsuxFZT5.d.ts} +262 -121
- package/dist/app-JM4CBTND.js +8 -0
- package/dist/app.d.ts +9 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/auth/fastify-auth.d.ts +9 -0
- package/dist/auth/fastify-auth.d.ts.map +1 -1
- package/dist/{chunk-QCHS3X33.js → chunk-FPMDWQF7.js} +2617 -562
- package/dist/chunk-FPMDWQF7.js.map +1 -0
- package/dist/{chunk-HK6BLLHA.js → chunk-MBHRCQFE.js} +2303 -1576
- package/dist/chunk-MBHRCQFE.js.map +1 -0
- package/dist/config/config-loader.d.ts +1 -1
- package/dist/config/config-loader.d.ts.map +1 -1
- package/dist/config/config-types.d.ts +14 -1
- package/dist/config/config-types.d.ts.map +1 -1
- package/dist/config/kubernetes-docker-isolation.d.ts +7 -0
- package/dist/config/kubernetes-docker-isolation.d.ts.map +1 -0
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/execution-inspection-repo.d.ts +15 -0
- package/dist/db/execution-inspection-repo.d.ts.map +1 -0
- package/dist/db/history-window.d.ts +11 -0
- package/dist/db/history-window.d.ts.map +1 -0
- package/dist/db/process-event-repo.d.ts +2 -0
- package/dist/db/process-event-repo.d.ts.map +1 -1
- package/dist/db/process-instance-repo.d.ts +4 -1
- package/dist/db/process-instance-repo.d.ts.map +1 -1
- package/dist/db/process-leaf-outcome-snapshot-repo.d.ts +2 -1
- package/dist/db/process-leaf-outcome-snapshot-repo.d.ts.map +1 -1
- package/dist/db/process-project-repo.d.ts +2 -0
- package/dist/db/process-project-repo.d.ts.map +1 -1
- package/dist/db/process-skill-repo.d.ts.map +1 -1
- package/dist/db/process-turn-annotation-repo.d.ts +4 -1
- package/dist/db/process-turn-annotation-repo.d.ts.map +1 -1
- package/dist/db/process-turn-record-repo.d.ts +4 -0
- package/dist/db/process-turn-record-repo.d.ts.map +1 -1
- package/dist/db/publication-repo.d.ts +5 -0
- package/dist/db/publication-repo.d.ts.map +1 -0
- package/dist/db/repositories.d.ts +12 -0
- package/dist/db/repositories.d.ts.map +1 -1
- package/dist/db/schema.d.ts +693 -2
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/scoped-settings-repo.d.ts +37 -0
- package/dist/db/scoped-settings-repo.d.ts.map +1 -0
- package/dist/db/skill-repo.d.ts +3 -0
- package/dist/db/skill-repo.d.ts.map +1 -1
- package/dist/db/turn-start-record-repo.d.ts +2 -1
- package/dist/db/turn-start-record-repo.d.ts.map +1 -1
- package/dist/db/turn-summary-repo.d.ts +1 -1
- package/dist/db/turn-summary-repo.d.ts.map +1 -1
- package/dist/db/worker-lease-repo.d.ts +2 -1
- package/dist/db/worker-lease-repo.d.ts.map +1 -1
- package/dist/domain-logic/outcome-tools.d.ts.map +1 -1
- package/dist/external-source-service.d.ts.map +1 -1
- package/dist/future-execution/execution.d.ts +4 -1
- package/dist/future-execution/execution.d.ts.map +1 -1
- package/dist/future-execution/launch-lifecycle.d.ts +9 -25
- package/dist/future-execution/launch-lifecycle.d.ts.map +1 -1
- package/dist/future-execution/lifecycle.d.ts +3 -28
- package/dist/future-execution/lifecycle.d.ts.map +1 -1
- package/dist/future-execution/model-projection.d.ts.map +1 -1
- package/dist/future-execution/reconciliation.d.ts +1 -0
- package/dist/future-execution/reconciliation.d.ts.map +1 -1
- package/dist/future-execution-presenter.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/integration-tool-registry.d.ts +11 -2
- package/dist/integration-tool-registry.d.ts.map +1 -1
- package/dist/launch-coordinator.d.ts.map +1 -1
- package/dist/launcher-model-config-service.d.ts +7 -1
- package/dist/launcher-model-config-service.d.ts.map +1 -1
- package/dist/leaf-outcome-snapshot-capture.d.ts +1 -0
- package/dist/leaf-outcome-snapshot-capture.d.ts.map +1 -1
- package/dist/main.js +3 -3
- package/dist/primary-path-snapshot.d.ts.map +1 -1
- package/dist/process-action-presenter.d.ts +1 -6
- package/dist/process-action-presenter.d.ts.map +1 -1
- package/dist/process-action-registry.d.ts.map +1 -1
- package/dist/process-engine/decision.d.ts +2 -0
- package/dist/process-engine/decision.d.ts.map +1 -1
- package/dist/process-engine/engine.d.ts.map +1 -1
- package/dist/process-engine/mapped-turns.d.ts.map +1 -1
- package/dist/process-engine/ops/continue-failed-turn.d.ts.map +1 -1
- package/dist/process-engine/ops/process-observation.d.ts +6 -0
- package/dist/process-engine/ops/process-observation.d.ts.map +1 -0
- package/dist/process-engine/ops/retry-failed-turn.d.ts.map +1 -1
- package/dist/process-engine/ops/retry-startup.d.ts.map +1 -1
- package/dist/process-engine/ops/start-process.d.ts +2 -0
- package/dist/process-engine/ops/start-process.d.ts.map +1 -1
- package/dist/process-engine/ops/turn-outcome.d.ts.map +1 -1
- package/dist/process-engine/ops/turn-wait.d.ts +30 -0
- package/dist/process-engine/ops/turn-wait.d.ts.map +1 -0
- package/dist/process-engine/ops/update-model-config.d.ts +9 -0
- package/dist/process-engine/ops/update-model-config.d.ts.map +1 -0
- package/dist/process-engine/recorder.d.ts.map +1 -1
- package/dist/process-engine/turn-start-preflight.d.ts +6 -0
- package/dist/process-engine/turn-start-preflight.d.ts.map +1 -1
- package/dist/process-engine/turn-wait-state.d.ts +24 -0
- package/dist/process-engine/turn-wait-state.d.ts.map +1 -0
- package/dist/process-engine/turn-worker-requirement.d.ts +2 -0
- package/dist/process-engine/turn-worker-requirement.d.ts.map +1 -1
- package/dist/process-engine/types.d.ts +5 -1
- package/dist/process-engine/types.d.ts.map +1 -1
- package/dist/process-engine/writes/build-process-abort-writes.d.ts +3 -1
- package/dist/process-engine/writes/build-process-abort-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts +2 -0
- package/dist/process-engine/writes/build-turn-outcome-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/commit-writes.d.ts +2 -0
- package/dist/process-engine/writes/commit-writes.d.ts.map +1 -1
- package/dist/process-engine/writes/writes.d.ts +28 -60
- package/dist/process-engine/writes/writes.d.ts.map +1 -1
- package/dist/process-graph.d.ts +1 -1
- package/dist/process-graph.d.ts.map +1 -1
- package/dist/process-inspection-reader.d.ts +21 -0
- package/dist/process-inspection-reader.d.ts.map +1 -0
- package/dist/process-inspection-trace.d.ts +13 -0
- package/dist/process-inspection-trace.d.ts.map +1 -0
- package/dist/process-inspection.d.ts +22 -0
- package/dist/process-inspection.d.ts.map +1 -0
- package/dist/process-instance-tree-presenter.d.ts +4 -3
- package/dist/process-instance-tree-presenter.d.ts.map +1 -1
- package/dist/process-launch-executor.d.ts +2 -0
- package/dist/process-launch-executor.d.ts.map +1 -1
- package/dist/process-launch-plan.d.ts +1 -0
- package/dist/process-launch-plan.d.ts.map +1 -1
- package/dist/process-launcher-registry.d.ts.map +1 -1
- package/dist/process-model-config.d.ts +19 -0
- package/dist/process-model-config.d.ts.map +1 -0
- package/dist/process-model-policy/construct.d.ts.map +1 -1
- package/dist/process-model-policy/evaluate.d.ts.map +1 -1
- package/dist/process-model-policy/index.d.ts +4 -1
- package/dist/process-model-policy/index.d.ts.map +1 -1
- package/dist/process-model-policy/project.d.ts.map +1 -1
- package/dist/process-model-policy/types.d.ts +18 -0
- package/dist/process-model-policy/types.d.ts.map +1 -1
- package/dist/process-model-policy-presenter.d.ts.map +1 -1
- package/dist/process-runtime-availability.d.ts +2 -1
- package/dist/process-runtime-availability.d.ts.map +1 -1
- package/dist/process-turn-trace.d.ts.map +1 -1
- package/dist/process-ui-snapshot-presenter.d.ts +14 -3
- package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
- package/dist/routes/future-executions.d.ts.map +1 -1
- package/dist/routes/launchers.d.ts.map +1 -1
- package/dist/routes/process-actions.d.ts.map +1 -1
- package/dist/routes/process-detail.d.ts.map +1 -1
- package/dist/routes/process-model-config.d.ts +4 -0
- package/dist/routes/process-model-config.d.ts.map +1 -0
- package/dist/routes/process-route-helpers.d.ts +8 -9
- package/dist/routes/process-route-helpers.d.ts.map +1 -1
- package/dist/routes/processes.d.ts.map +1 -1
- package/dist/routes/settings.d.ts +11 -0
- package/dist/routes/settings.d.ts.map +1 -0
- package/dist/routes/ticket-creation.d.ts.map +1 -1
- package/dist/scoped-settings-service.d.ts +83 -0
- package/dist/scoped-settings-service.d.ts.map +1 -0
- package/dist/server-bootstrap/build-host-capabilities.d.ts +2 -0
- package/dist/server-bootstrap/build-host-capabilities.d.ts.map +1 -1
- package/dist/server-bootstrap/register-http.d.ts.map +1 -1
- package/dist/session-summary-projection.d.ts.map +1 -1
- package/dist/skills/bundled-skills.d.ts +5 -0
- package/dist/skills/bundled-skills.d.ts.map +1 -0
- package/dist/skills/catalog-service.d.ts +1 -0
- package/dist/skills/catalog-service.d.ts.map +1 -1
- package/dist/skills/extension-importer.d.ts +11 -0
- package/dist/skills/extension-importer.d.ts.map +1 -0
- package/dist/skills/launch-skills.d.ts +11 -0
- package/dist/skills/launch-skills.d.ts.map +1 -0
- package/dist/skills/skill-frontmatter.d.ts +5 -0
- package/dist/skills/skill-frontmatter.d.ts.map +1 -1
- package/dist/skills/source-importer.d.ts +3 -0
- package/dist/skills/source-importer.d.ts.map +1 -1
- package/dist/startup-evidence.d.ts +3 -0
- package/dist/startup-evidence.d.ts.map +1 -1
- package/dist/supervisor/execution-inspection-ingestor.d.ts +9 -0
- package/dist/supervisor/execution-inspection-ingestor.d.ts.map +1 -0
- package/dist/supervisor/ipc-handler.d.ts +2 -0
- package/dist/supervisor/ipc-handler.d.ts.map +1 -1
- package/dist/supervisor/worker-event-ingestor.d.ts +1 -0
- package/dist/supervisor/worker-event-ingestor.d.ts.map +1 -1
- package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
- package/dist/supervisor/worker-supervisor.d.ts +2 -0
- package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
- package/dist/test-helpers/prepared-fixture-start.d.ts.map +1 -1
- package/dist/test-helpers/process-model-fixtures.d.ts +1 -0
- package/dist/test-helpers/process-model-fixtures.d.ts.map +1 -1
- package/dist/test-helpers/scoped-settings-fixtures.d.ts +16 -0
- package/dist/test-helpers/scoped-settings-fixtures.d.ts.map +1 -0
- package/dist/test-helpers/skill-fixtures.d.ts +4 -0
- package/dist/test-helpers/skill-fixtures.d.ts.map +1 -0
- package/dist/testing.js +2 -1
- package/dist/testing.js.map +1 -1
- package/dist/tool-approval-gate.d.ts +3 -0
- package/dist/tool-approval-gate.d.ts.map +1 -1
- package/dist/turn-progress.d.ts.map +1 -1
- package/dist/turn-wait-service.d.ts +28 -0
- package/dist/turn-wait-service.d.ts.map +1 -0
- package/dist/worker-runtime-profile-selection.d.ts +2 -0
- package/dist/worker-runtime-profile-selection.d.ts.map +1 -1
- package/package.json +20 -19
- package/src/app.ts +115 -5
- package/src/auth/fastify-auth.ts +13 -0
- package/src/config/config-loader.ts +40 -2
- package/src/config/config-types.ts +14 -1
- package/src/config/kubernetes-docker-isolation.ts +21 -0
- package/src/db/database.ts +131 -40
- package/src/db/execution-inspection-repo.ts +163 -0
- package/src/db/history-window.ts +18 -0
- package/src/db/process-event-repo.ts +88 -10
- package/src/db/process-instance-repo.ts +9 -2
- package/src/db/process-leaf-outcome-snapshot-repo.ts +8 -2
- package/src/db/process-project-repo.ts +4 -0
- package/src/db/process-skill-repo.ts +9 -2
- package/src/db/process-turn-annotation-repo.ts +27 -9
- package/src/db/process-turn-record-repo.ts +45 -12
- package/src/db/publication-repo.ts +63 -0
- package/src/db/repositories.ts +17 -0
- package/src/db/schema.ts +103 -1
- package/src/db/scoped-settings-repo.ts +234 -0
- package/src/db/skill-repo.ts +89 -27
- package/src/db/turn-start-record-repo.ts +8 -2
- package/src/db/turn-summary-repo.ts +12 -3
- package/src/db/worker-lease-repo.ts +8 -2
- package/src/domain-logic/outcome-tools.ts +4 -193
- package/src/external-source-service.ts +33 -7
- package/src/future-execution/execution.ts +9 -2
- package/src/future-execution/launch-lifecycle.ts +87 -78
- package/src/future-execution/lifecycle.ts +5 -34
- package/src/future-execution/model-projection.ts +2 -0
- package/src/future-execution/reconciliation.ts +7 -0
- package/src/future-execution-presenter.ts +7 -8
- package/src/integration-tool-registry.ts +59 -26
- package/src/launch-coordinator.ts +10 -1
- package/src/launcher-model-config-service.ts +24 -3
- package/src/leaf-outcome-snapshot-capture.ts +2 -0
- package/src/primary-path-snapshot.ts +3 -4
- package/src/process-action-presenter.ts +22 -57
- package/src/process-action-registry.ts +31 -39
- package/src/process-engine/decision.ts +10 -0
- package/src/process-engine/engine.ts +11 -2
- package/src/process-engine/mapped-turns.ts +5 -7
- package/src/process-engine/ops/continue-failed-turn.ts +2 -13
- package/src/process-engine/ops/process-observation.ts +119 -0
- package/src/process-engine/ops/retry-failed-turn.ts +2 -12
- package/src/process-engine/ops/retry-startup.ts +9 -13
- package/src/process-engine/ops/start-process.ts +34 -2
- package/src/process-engine/ops/turn-outcome.ts +61 -60
- package/src/process-engine/ops/turn-wait.ts +225 -0
- package/src/process-engine/ops/update-model-config.ts +66 -0
- package/src/process-engine/recorder.ts +21 -5
- package/src/process-engine/turn-start-preflight.ts +168 -105
- package/src/process-engine/turn-wait-state.ts +126 -0
- package/src/process-engine/turn-worker-requirement.ts +4 -0
- package/src/process-engine/types.ts +9 -0
- package/src/process-engine/writes/build-process-abort-writes.ts +30 -20
- package/src/process-engine/writes/build-turn-outcome-writes.ts +39 -2
- package/src/process-engine/writes/commit-writes.ts +15 -2
- package/src/process-engine/writes/writes.ts +59 -74
- package/src/process-graph.ts +0 -1
- package/src/process-inspection-reader.ts +305 -0
- package/src/process-inspection-trace.ts +176 -0
- package/src/process-inspection.ts +169 -0
- package/src/process-instance-tree-presenter.ts +56 -216
- package/src/process-launch-executor.ts +5 -2
- package/src/process-launch-plan.ts +17 -2
- package/src/process-launcher-registry.ts +28 -16
- package/src/process-model-config.ts +100 -0
- package/src/process-model-policy/construct.ts +1 -0
- package/src/process-model-policy/evaluate.ts +34 -32
- package/src/process-model-policy/index.ts +45 -3
- package/src/process-model-policy/project.ts +62 -76
- package/src/process-model-policy/types.ts +26 -0
- package/src/process-model-policy-presenter.ts +7 -3
- package/src/process-runtime-availability.ts +9 -4
- package/src/process-turn-trace.ts +12 -24
- package/src/process-ui-snapshot-presenter.ts +210 -295
- package/src/routes/future-executions.ts +5 -5
- package/src/routes/launchers.ts +51 -1
- package/src/routes/process-actions.ts +9 -9
- package/src/routes/process-detail.ts +25 -2
- package/src/routes/process-model-config.ts +70 -0
- package/src/routes/process-route-helpers.ts +153 -162
- package/src/routes/processes.ts +2 -0
- package/src/routes/settings.ts +173 -0
- package/src/routes/ticket-creation.ts +28 -5
- package/src/scoped-settings-service.ts +736 -0
- package/src/server-bootstrap/build-host-capabilities.ts +42 -0
- package/src/server-bootstrap/register-http.ts +7 -1
- package/src/session-summary-projection.ts +1 -2
- package/src/skills/bundled-skills.ts +64 -0
- package/src/skills/catalog-service.ts +35 -6
- package/src/skills/extension-importer.ts +97 -0
- package/src/skills/launch-skills.ts +19 -0
- package/src/skills/skill-frontmatter.ts +13 -0
- package/src/skills/source-importer.ts +3 -0
- package/src/startup-evidence.ts +20 -0
- package/src/supervisor/execution-inspection-ingestor.ts +55 -0
- package/src/supervisor/ipc-handler.ts +2 -0
- package/src/supervisor/worker-event-ingestor.ts +30 -14
- package/src/supervisor/worker-start-payload-builder.ts +17 -0
- package/src/supervisor/worker-supervisor.ts +3 -0
- package/src/test-helpers/prepared-fixture-start.ts +1 -0
- package/src/test-helpers/process-model-fixtures.ts +2 -0
- package/src/test-helpers/scoped-settings-fixtures.ts +126 -0
- package/src/test-helpers/skill-fixtures.ts +28 -0
- package/src/tool-approval-gate.ts +16 -0
- package/src/turn-progress.ts +3 -2
- package/src/turn-wait-service.ts +228 -0
- package/src/worker-runtime-profile-selection.ts +8 -1
- package/dist/app-MSJXFK33.js +0 -8
- package/dist/chunk-HK6BLLHA.js.map +0 -1
- package/dist/chunk-QCHS3X33.js.map +0 -1
- /package/dist/{app-MSJXFK33.js.map → app-JM4CBTND.js.map} +0 -0
|
@@ -57,6 +57,8 @@ export interface RecordCommit {
|
|
|
57
57
|
/** @internal */
|
|
58
58
|
committedProject: ProcessProject | null;
|
|
59
59
|
/** @internal */
|
|
60
|
+
initialProjects?: ProcessProject[];
|
|
61
|
+
/** @internal */
|
|
60
62
|
committedTurnRecords: ProcessTurnRecord[];
|
|
61
63
|
/** @internal */
|
|
62
64
|
committedLeafOutcomeSnapshots: ProcessLeafOutcomeSnapshot[];
|
|
@@ -250,7 +252,9 @@ export function commitWrites(
|
|
|
250
252
|
|
|
251
253
|
const processAfter =
|
|
252
254
|
writes.changedFields.length > 0
|
|
253
|
-
? repos.processes.update(instanceId, writes.processPatch
|
|
255
|
+
? repos.processes.update(instanceId, writes.processPatch, {
|
|
256
|
+
preserveUpdatedAt: writes.preserveUpdatedAt,
|
|
257
|
+
})
|
|
254
258
|
: repos.processes.getById(instanceId);
|
|
255
259
|
const committedProject = writes.projectWrite
|
|
256
260
|
? repos.projects.update(writes.projectWrite.id, writes.projectWrite.input)
|
|
@@ -263,6 +267,11 @@ export function commitWrites(
|
|
|
263
267
|
`Process project '${committedProject.id}' does not belong to '${instanceId}'`,
|
|
264
268
|
);
|
|
265
269
|
}
|
|
270
|
+
const initialProjects = (writes.initialProjects ?? []).map((project) => {
|
|
271
|
+
if (project.instanceId !== instanceId)
|
|
272
|
+
throw new Error("Initial repository belongs to another process");
|
|
273
|
+
return repos.projects.create(project);
|
|
274
|
+
});
|
|
266
275
|
|
|
267
276
|
for (const write of writes.pendingExternalSourceFireWrites) {
|
|
268
277
|
if (write.kind === "create") {
|
|
@@ -303,6 +312,7 @@ export function commitWrites(
|
|
|
303
312
|
processBefore,
|
|
304
313
|
processAfter,
|
|
305
314
|
committedProject,
|
|
315
|
+
initialProjects,
|
|
306
316
|
committedTurnRecords,
|
|
307
317
|
turnEventSequences,
|
|
308
318
|
committedLeafOutcomeSnapshots,
|
|
@@ -325,6 +335,8 @@ export function deriveReactions(
|
|
|
325
335
|
effects.push({ kind: "broadcast", frame });
|
|
326
336
|
}
|
|
327
337
|
if (commit.committedProject) effects.push(buildProjectUpdatedEffect(commit.committedProject));
|
|
338
|
+
for (const project of commit.initialProjects ?? [])
|
|
339
|
+
effects.push(buildProjectUpdatedEffect(project));
|
|
328
340
|
if (writes.changedFields.length > 0) {
|
|
329
341
|
const includeClosedAt =
|
|
330
342
|
commit.processAfter !== null &&
|
|
@@ -335,7 +347,8 @@ export function deriveReactions(
|
|
|
335
347
|
...(includeClosedAt ? { closedAt: commit.processAfter?.closedAt ?? null } : {}),
|
|
336
348
|
};
|
|
337
349
|
let changedFields =
|
|
338
|
-
commit.processAfter?.updatedAt
|
|
350
|
+
commit.processAfter?.updatedAt !== commit.processBefore?.updatedAt &&
|
|
351
|
+
!writes.changedFields.includes("updatedAt")
|
|
339
352
|
? [...writes.changedFields, "updatedAt"]
|
|
340
353
|
: writes.changedFields;
|
|
341
354
|
if (includeClosedAt && !changedFields.includes("closedAt")) {
|
|
@@ -18,7 +18,10 @@ import type {
|
|
|
18
18
|
import type { CreateProcessEventInput } from "../../db/process-event-repo.js";
|
|
19
19
|
import type { UpdateProcessInstanceInput } from "../../db/process-instance-repo.js";
|
|
20
20
|
import type { CreateProcessLeafOutcomeSnapshotInput } from "../../db/process-leaf-outcome-snapshot-repo.js";
|
|
21
|
-
import type {
|
|
21
|
+
import type {
|
|
22
|
+
CreateProcessProjectInput,
|
|
23
|
+
UpdateProcessProjectInput,
|
|
24
|
+
} from "../../db/process-project-repo.js";
|
|
22
25
|
import type {
|
|
23
26
|
CreateProcessTurnAnnotationInput,
|
|
24
27
|
UpdateProcessTurnAnnotationInput,
|
|
@@ -34,34 +37,45 @@ import type { DeferredProcessExtensionEvent } from "./deferred-extension-events.
|
|
|
34
37
|
/** @internal */
|
|
35
38
|
export type DurableBroadcast = DurableWsFrameInput;
|
|
36
39
|
|
|
40
|
+
/** @internal */
|
|
41
|
+
type CreateWrite<T> = {
|
|
42
|
+
/** @internal */
|
|
43
|
+
kind: "create";
|
|
44
|
+
/** @internal */
|
|
45
|
+
input: T;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** @internal */
|
|
49
|
+
type UpdateWrite<T> = {
|
|
50
|
+
/** @internal */
|
|
51
|
+
kind: "update";
|
|
52
|
+
/** @internal */
|
|
53
|
+
id: string;
|
|
54
|
+
/** @internal */
|
|
55
|
+
input: T;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** @internal */
|
|
59
|
+
type DeleteWrite = {
|
|
60
|
+
/** @internal */
|
|
61
|
+
kind: "delete";
|
|
62
|
+
/** @internal */
|
|
63
|
+
id: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
37
66
|
/** @internal */
|
|
38
67
|
export type TurnRecordWrite =
|
|
39
|
-
|
|
|
40
|
-
|
|
41
|
-
kind: "create";
|
|
42
|
-
/** @internal */
|
|
43
|
-
input: CreateProcessTurnRecordInput;
|
|
44
|
-
}
|
|
45
|
-
| {
|
|
46
|
-
/** @internal */
|
|
47
|
-
kind: "update";
|
|
48
|
-
/** @internal */
|
|
49
|
-
id: string;
|
|
50
|
-
/** @internal */
|
|
51
|
-
input: UpdateProcessTurnRecordInput;
|
|
52
|
-
};
|
|
68
|
+
| CreateWrite<CreateProcessTurnRecordInput>
|
|
69
|
+
| UpdateWrite<UpdateProcessTurnRecordInput>;
|
|
53
70
|
|
|
54
71
|
/** @internal */
|
|
55
72
|
export type TurnStartWrite =
|
|
56
|
-
|
|
|
57
|
-
|
|
58
|
-
kind: "create";
|
|
59
|
-
/** @internal */
|
|
60
|
-
input: Omit<TurnStartRecord, "id" | "createdAt" | "updatedAt"> & {
|
|
73
|
+
| CreateWrite<
|
|
74
|
+
Omit<TurnStartRecord, "id" | "createdAt" | "updatedAt"> & {
|
|
61
75
|
/** @internal */
|
|
62
76
|
id?: string;
|
|
63
|
-
}
|
|
64
|
-
|
|
77
|
+
}
|
|
78
|
+
>
|
|
65
79
|
| {
|
|
66
80
|
/** @internal */
|
|
67
81
|
kind: "cas_state";
|
|
@@ -75,35 +89,13 @@ export type TurnStartWrite =
|
|
|
75
89
|
|
|
76
90
|
/** @internal */
|
|
77
91
|
export type TurnAnnotationWrite =
|
|
78
|
-
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
/** @internal */
|
|
82
|
-
input: CreateProcessTurnAnnotationInput;
|
|
83
|
-
}
|
|
84
|
-
| {
|
|
85
|
-
/** @internal */
|
|
86
|
-
kind: "update";
|
|
87
|
-
/** @internal */
|
|
88
|
-
id: string;
|
|
89
|
-
/** @internal */
|
|
90
|
-
input: UpdateProcessTurnAnnotationInput;
|
|
91
|
-
}
|
|
92
|
-
| {
|
|
93
|
-
/** @internal */
|
|
94
|
-
kind: "delete";
|
|
95
|
-
/** @internal */
|
|
96
|
-
id: string;
|
|
97
|
-
};
|
|
92
|
+
| CreateWrite<CreateProcessTurnAnnotationInput>
|
|
93
|
+
| UpdateWrite<UpdateProcessTurnAnnotationInput>
|
|
94
|
+
| DeleteWrite;
|
|
98
95
|
|
|
99
96
|
/** Mapped-run writes, committed in order before turn starts. @internal */
|
|
100
97
|
export type MappedRunWrite =
|
|
101
|
-
|
|
|
102
|
-
/** @internal */
|
|
103
|
-
kind: "create";
|
|
104
|
-
/** @internal */
|
|
105
|
-
input: CreateMappedRunInput;
|
|
106
|
-
}
|
|
98
|
+
| CreateWrite<CreateMappedRunInput>
|
|
107
99
|
| {
|
|
108
100
|
/** @internal */
|
|
109
101
|
kind: "complete_item";
|
|
@@ -116,12 +108,7 @@ export type MappedRunWrite =
|
|
|
116
108
|
};
|
|
117
109
|
|
|
118
110
|
/** @internal */
|
|
119
|
-
export type LeafOutcomeSnapshotWrite =
|
|
120
|
-
/** @internal */
|
|
121
|
-
kind: "create";
|
|
122
|
-
/** @internal */
|
|
123
|
-
input: CreateProcessLeafOutcomeSnapshotInput;
|
|
124
|
-
};
|
|
111
|
+
export type LeafOutcomeSnapshotWrite = CreateWrite<CreateProcessLeafOutcomeSnapshotInput>;
|
|
125
112
|
|
|
126
113
|
/** @internal */
|
|
127
114
|
export type WorkerIntent =
|
|
@@ -152,26 +139,9 @@ export type WorkerIntent =
|
|
|
152
139
|
|
|
153
140
|
/** @internal */
|
|
154
141
|
export type PendingExternalSourceFireWrite =
|
|
155
|
-
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
/** @internal */
|
|
159
|
-
input: CreatePendingExternalSourceFireInput;
|
|
160
|
-
}
|
|
161
|
-
| {
|
|
162
|
-
/** @internal */
|
|
163
|
-
kind: "update";
|
|
164
|
-
/** @internal */
|
|
165
|
-
id: string;
|
|
166
|
-
/** @internal */
|
|
167
|
-
input: UpdatePendingExternalSourceFireInput;
|
|
168
|
-
}
|
|
169
|
-
| {
|
|
170
|
-
/** @internal */
|
|
171
|
-
kind: "delete";
|
|
172
|
-
/** @internal */
|
|
173
|
-
id: string;
|
|
174
|
-
};
|
|
142
|
+
| CreateWrite<CreatePendingExternalSourceFireInput>
|
|
143
|
+
| UpdateWrite<UpdatePendingExternalSourceFireInput>
|
|
144
|
+
| DeleteWrite;
|
|
175
145
|
|
|
176
146
|
/** @internal */
|
|
177
147
|
export interface DecisionMetadata {
|
|
@@ -194,6 +164,10 @@ const METADATA_KEY_GROUPS = {
|
|
|
194
164
|
|
|
195
165
|
/** @internal */
|
|
196
166
|
export interface Writes {
|
|
167
|
+
/** Internal scheduling writes do not count as process activity. @internal */
|
|
168
|
+
preserveUpdatedAt?: boolean;
|
|
169
|
+
/** A fenced, successful server-side wait check. Never supplied by extensions. @internal */
|
|
170
|
+
waitForAdmission?: string;
|
|
197
171
|
/** @internal */
|
|
198
172
|
processPatch: UpdateProcessInstanceInput;
|
|
199
173
|
/** @internal */
|
|
@@ -205,6 +179,8 @@ export interface Writes {
|
|
|
205
179
|
/** @internal */
|
|
206
180
|
input: UpdateProcessProjectInput;
|
|
207
181
|
};
|
|
182
|
+
/** Initial bindings, committed before the first worker start. @internal */
|
|
183
|
+
initialProjects?: CreateProcessProjectInput[];
|
|
208
184
|
/** @internal */
|
|
209
185
|
turnRecordWrites: TurnRecordWrite[];
|
|
210
186
|
/** @internal */
|
|
@@ -246,9 +222,12 @@ export type WriteBuildResult = Writes | WriteBuildFailure;
|
|
|
246
222
|
|
|
247
223
|
export function createWrites(init: Partial<Writes> = {}): Writes {
|
|
248
224
|
return {
|
|
225
|
+
...(init.preserveUpdatedAt ? { preserveUpdatedAt: true } : {}),
|
|
226
|
+
...(init.waitForAdmission ? { waitForAdmission: init.waitForAdmission } : {}),
|
|
249
227
|
processPatch: init.processPatch ?? {},
|
|
250
228
|
changedFields: [...(init.changedFields ?? [])],
|
|
251
229
|
...(init.projectWrite ? { projectWrite: init.projectWrite } : {}),
|
|
230
|
+
...(init.initialProjects ? { initialProjects: [...init.initialProjects] } : {}),
|
|
252
231
|
turnRecordWrites: [...(init.turnRecordWrites ?? [])],
|
|
253
232
|
turnStartWrites: [...(init.turnStartWrites ?? [])],
|
|
254
233
|
mappedRunWrites: [...(init.mappedRunWrites ?? [])],
|
|
@@ -269,6 +248,7 @@ export function mergeWrites(...writesList: Array<Writes | undefined>): Writes {
|
|
|
269
248
|
for (const writes of writesList) {
|
|
270
249
|
if (!writes) continue;
|
|
271
250
|
Object.assign(merged.processPatch, writes.processPatch);
|
|
251
|
+
if (writes.waitForAdmission) merged.waitForAdmission = writes.waitForAdmission;
|
|
272
252
|
for (const field of writes.changedFields) {
|
|
273
253
|
if (!merged.changedFields.includes(field)) {
|
|
274
254
|
merged.changedFields.push(field);
|
|
@@ -278,6 +258,11 @@ export function mergeWrites(...writesList: Array<Writes | undefined>): Writes {
|
|
|
278
258
|
if (merged.projectWrite) throw new Error("Cannot merge multiple process-project writes");
|
|
279
259
|
merged.projectWrite = writes.projectWrite;
|
|
280
260
|
}
|
|
261
|
+
if (writes.initialProjects) {
|
|
262
|
+
if (merged.initialProjects)
|
|
263
|
+
throw new Error("Cannot merge multiple initial repository bindings");
|
|
264
|
+
merged.initialProjects = writes.initialProjects;
|
|
265
|
+
}
|
|
281
266
|
merged.turnRecordWrites.push(...writes.turnRecordWrites);
|
|
282
267
|
merged.turnStartWrites.push(...writes.turnStartWrites);
|
|
283
268
|
merged.mappedRunWrites.push(...writes.mappedRunWrites);
|
package/src/process-graph.ts
CHANGED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
InspectionEvidence,
|
|
3
|
+
InspectionModelInput,
|
|
4
|
+
ProcessTurnRecord,
|
|
5
|
+
} from "@leitwerk-dev/domain";
|
|
6
|
+
import type {
|
|
7
|
+
ExecutionInspectionConfiguration,
|
|
8
|
+
ExecutionInspectionContext,
|
|
9
|
+
ExecutionInspectionSummary,
|
|
10
|
+
ExecutionInspectionTrace,
|
|
11
|
+
InspectionTargetState,
|
|
12
|
+
} from "@leitwerk-dev/protocol";
|
|
13
|
+
import { createInspectionLineage } from "./process-inspection.js";
|
|
14
|
+
import { buildInspectionTraceMessages } from "./process-inspection-trace.js";
|
|
15
|
+
import { ProcessUiSnapshotAssembler } from "./process-ui-snapshot-presenter.js";
|
|
16
|
+
|
|
17
|
+
/** One server-owned adapter for compact facts and on-demand inspection evidence. @internal */
|
|
18
|
+
export class ProcessInspectionReader {
|
|
19
|
+
private readonly history: ProcessUiSnapshotAssembler;
|
|
20
|
+
constructor(private readonly deps: ConstructorParameters<typeof ProcessUiSnapshotAssembler>[0]) {
|
|
21
|
+
this.history = new ProcessUiSnapshotAssembler(deps);
|
|
22
|
+
}
|
|
23
|
+
private selected(instanceId: string, turnRecordId: string) {
|
|
24
|
+
if (!this.deps.processes.getById(instanceId)) return null;
|
|
25
|
+
const record = this.deps.turnRecords.getById(turnRecordId);
|
|
26
|
+
return record?.instanceId === instanceId ? record : null;
|
|
27
|
+
}
|
|
28
|
+
private lineageSnapshot(instanceId: string) {
|
|
29
|
+
return {
|
|
30
|
+
records: this.deps.turnRecords.listByInstance(instanceId),
|
|
31
|
+
leases: this.deps.leases.listByInstance(instanceId),
|
|
32
|
+
observations: this.deps.executionInspections.listContextFacts(instanceId),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** No session or immutable-content reads are needed to open the shell. */
|
|
36
|
+
summary(instanceId: string, turnRecordId: string): ExecutionInspectionSummary | null {
|
|
37
|
+
const record = this.selected(instanceId, turnRecordId);
|
|
38
|
+
if (!record) return null;
|
|
39
|
+
const records = this.deps.turnRecords
|
|
40
|
+
.listByInstance(instanceId)
|
|
41
|
+
.sort((a, b) => a.startedAt.localeCompare(b.startedAt) || a.id.localeCompare(b.id));
|
|
42
|
+
const index = records.findIndex((candidate) => candidate.id === turnRecordId);
|
|
43
|
+
const start = record.turnStartRecordId
|
|
44
|
+
? this.deps.turnStarts.getById(record.turnStartRecordId)
|
|
45
|
+
: null;
|
|
46
|
+
const inputs = this.deps.executionInspections.modelInputs(instanceId, turnRecordId);
|
|
47
|
+
const accepted =
|
|
48
|
+
start && "start" in start.state && start.state.start?.kind === "llm"
|
|
49
|
+
? start.state.start.model
|
|
50
|
+
: null;
|
|
51
|
+
let model: InspectionEvidence<InspectionModelInput["model"]> =
|
|
52
|
+
record.turnType === "llm"
|
|
53
|
+
? { state: "not_recorded", reason: "The historical model was not recorded" }
|
|
54
|
+
: {
|
|
55
|
+
state: "not_applicable",
|
|
56
|
+
reason: `This ${record.turnType} execution does not invoke a model`,
|
|
57
|
+
};
|
|
58
|
+
const effective = inputs.at(-1)?.model;
|
|
59
|
+
if (effective) model = { state: "recorded", value: effective };
|
|
60
|
+
else if (accepted)
|
|
61
|
+
model = {
|
|
62
|
+
state: "recorded",
|
|
63
|
+
value: {
|
|
64
|
+
provider: accepted.providerId,
|
|
65
|
+
id: accepted.modelId,
|
|
66
|
+
thinkingLevel: accepted.thinkingLevel,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
const { turnResultMarkdown: _output, ...execution } = record;
|
|
70
|
+
return {
|
|
71
|
+
instanceId,
|
|
72
|
+
execution,
|
|
73
|
+
origin: createInspectionLineage(this.lineageSnapshot(instanceId)).origin(record),
|
|
74
|
+
startKind: start
|
|
75
|
+
? { state: "recorded", value: start.startKind }
|
|
76
|
+
: { state: "not_recorded", reason: "Execution start kind was not recorded" },
|
|
77
|
+
model,
|
|
78
|
+
modelInputCount: inputs.length,
|
|
79
|
+
usage: this.deps.turnSummaries.get(turnRecordId)?.usage ?? null,
|
|
80
|
+
previousTurnRecordId: records[index - 1]?.id ?? null,
|
|
81
|
+
nextTurnRecordId: records[index + 1]?.id ?? null,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
private missingModelEvidence<T>(record: ProcessTurnRecord): InspectionEvidence<T> {
|
|
85
|
+
return record.turnType === "llm"
|
|
86
|
+
? {
|
|
87
|
+
state: "not_recorded",
|
|
88
|
+
reason:
|
|
89
|
+
"No model input was recorded for this execution. Historical instructions cannot be reconstructed from current settings.",
|
|
90
|
+
}
|
|
91
|
+
: {
|
|
92
|
+
state: "not_applicable",
|
|
93
|
+
reason: `This ${record.turnType} execution does not invoke a model`,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
configuration(instanceId: string, turnRecordId: string): ExecutionInspectionConfiguration | null {
|
|
97
|
+
const record = this.selected(instanceId, turnRecordId);
|
|
98
|
+
if (!record) return null;
|
|
99
|
+
const revisions = this.deps.executionInspections
|
|
100
|
+
.list(instanceId, turnRecordId)
|
|
101
|
+
.flatMap((capture) => {
|
|
102
|
+
if (capture.fact.kind !== "model_input") return [];
|
|
103
|
+
const { messages: _messages, kind: _kind, ...configuration } = capture.fact;
|
|
104
|
+
return [{ id: capture.id, timestamp: capture.timestamp, ...configuration }];
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
instanceId,
|
|
108
|
+
turnRecordId,
|
|
109
|
+
revisions: revisions.length
|
|
110
|
+
? { state: "recorded", value: revisions }
|
|
111
|
+
: this.missingModelEvidence(record),
|
|
112
|
+
currentWorkflowTurnId: record.turnId,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async context(
|
|
116
|
+
instanceId: string,
|
|
117
|
+
turnRecordId: string,
|
|
118
|
+
): Promise<ExecutionInspectionContext | null> {
|
|
119
|
+
const record = this.selected(instanceId, turnRecordId);
|
|
120
|
+
if (!record) return null;
|
|
121
|
+
const lineageSnapshot = this.lineageSnapshot(instanceId);
|
|
122
|
+
const captures = this.deps.executionInspections.list(instanceId, turnRecordId);
|
|
123
|
+
const session = await this.deps.sessionReader.readSessionTree(instanceId);
|
|
124
|
+
const lineage = createInspectionLineage({ ...lineageSnapshot, tree: session.piTree });
|
|
125
|
+
const supplies = captures.filter((capture) => capture.fact.kind === "supplied_context");
|
|
126
|
+
const products = supplies.flatMap((capture) =>
|
|
127
|
+
capture.fact.kind === "supplied_context"
|
|
128
|
+
? capture.fact.products.map((product) => ({
|
|
129
|
+
...product,
|
|
130
|
+
supplyId: capture.id,
|
|
131
|
+
consumed: captures.some(
|
|
132
|
+
(candidate) =>
|
|
133
|
+
candidate.fact.kind === "product_consumed" &&
|
|
134
|
+
`${turnRecordId}:${candidate.fact.supplyId}` === capture.id &&
|
|
135
|
+
candidate.fact.name === product.name,
|
|
136
|
+
),
|
|
137
|
+
}))
|
|
138
|
+
: [],
|
|
139
|
+
);
|
|
140
|
+
const modelInputs = captures.flatMap((capture) =>
|
|
141
|
+
capture.fact.kind === "model_input"
|
|
142
|
+
? [
|
|
143
|
+
{
|
|
144
|
+
id: capture.id,
|
|
145
|
+
timestamp: capture.timestamp,
|
|
146
|
+
boundaryEntryId: capture.fact.boundaryEntryId,
|
|
147
|
+
model: capture.fact.model,
|
|
148
|
+
messages: capture.fact.messages.map((message) => {
|
|
149
|
+
const sourceTurnRecordId = message.entryId ? lineage.owner(message.entryId) : null;
|
|
150
|
+
return {
|
|
151
|
+
entryId: message.entryId,
|
|
152
|
+
sourceTurnRecordId,
|
|
153
|
+
role: message.role,
|
|
154
|
+
content:
|
|
155
|
+
sourceTurnRecordId && sourceTurnRecordId !== turnRecordId
|
|
156
|
+
? null
|
|
157
|
+
: message.content,
|
|
158
|
+
};
|
|
159
|
+
}),
|
|
160
|
+
},
|
|
161
|
+
]
|
|
162
|
+
: [],
|
|
163
|
+
);
|
|
164
|
+
const boundaries = new Set(
|
|
165
|
+
modelInputs
|
|
166
|
+
.map((revision) => revision.boundaryEntryId)
|
|
167
|
+
.filter((id): id is string => id !== null),
|
|
168
|
+
);
|
|
169
|
+
if (record.resultPiEntryId) boundaries.add(record.resultPiEntryId);
|
|
170
|
+
const contextEntries = new Map(
|
|
171
|
+
[...boundaries].flatMap((boundary) =>
|
|
172
|
+
session.piTree.getBranch(boundary).map((entry) => [entry.id, entry] as const),
|
|
173
|
+
),
|
|
174
|
+
);
|
|
175
|
+
const compactions = [...contextEntries.values()].flatMap((entry) =>
|
|
176
|
+
entry.type === "compaction"
|
|
177
|
+
? [{ entryId: entry.id, firstKeptEntryId: entry.firstKeptEntryId, summary: entry.summary }]
|
|
178
|
+
: [],
|
|
179
|
+
);
|
|
180
|
+
const inputMessages = buildInspectionTraceMessages({
|
|
181
|
+
tree: session.piTree,
|
|
182
|
+
record,
|
|
183
|
+
captures,
|
|
184
|
+
events: [],
|
|
185
|
+
owner: lineage.owner,
|
|
186
|
+
}).filter((message) => message.role === "user" || message.role === "system");
|
|
187
|
+
return {
|
|
188
|
+
instanceId,
|
|
189
|
+
turnRecordId,
|
|
190
|
+
origin: lineage.origin(record),
|
|
191
|
+
ancestry: lineage.ancestry(record),
|
|
192
|
+
products: supplies.length
|
|
193
|
+
? { state: "recorded", value: products }
|
|
194
|
+
: { state: "not_recorded", reason: "Supplied product versions were not recorded" },
|
|
195
|
+
modelInputs: modelInputs.length
|
|
196
|
+
? { state: "recorded", value: modelInputs }
|
|
197
|
+
: this.missingModelEvidence(record),
|
|
198
|
+
compactions,
|
|
199
|
+
inputMessages,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
async trace(
|
|
203
|
+
instanceId: string,
|
|
204
|
+
turnRecordId: string,
|
|
205
|
+
target: { entryId?: string; itemId?: string; boundaryFor?: string } = {},
|
|
206
|
+
): Promise<ExecutionInspectionTrace | null> {
|
|
207
|
+
// Keep every durable fact at the same boundary as the reasoning history.
|
|
208
|
+
// Session storage is asynchronous and can advance independently.
|
|
209
|
+
const lineageSnapshot = this.lineageSnapshot(instanceId);
|
|
210
|
+
const captures = this.deps.executionInspections.list(instanceId, turnRecordId);
|
|
211
|
+
const annotations = this.deps.turnAnnotations
|
|
212
|
+
.listByInstance(instanceId)
|
|
213
|
+
.filter((annotation) =>
|
|
214
|
+
annotation.references.some(
|
|
215
|
+
(reference) =>
|
|
216
|
+
reference.kind === "turn_record" && reference.turnRecordId === turnRecordId,
|
|
217
|
+
),
|
|
218
|
+
);
|
|
219
|
+
const evidence = await this.history.readReasoningEvidence({
|
|
220
|
+
instanceId,
|
|
221
|
+
turnRecordId,
|
|
222
|
+
includeSession: true,
|
|
223
|
+
});
|
|
224
|
+
if (!evidence?.session) return null;
|
|
225
|
+
const { detail: history, turnRecord: record, events, session } = evidence;
|
|
226
|
+
const lineage = createInspectionLineage({ ...lineageSnapshot, tree: session.piTree });
|
|
227
|
+
const messages = buildInspectionTraceMessages({
|
|
228
|
+
tree: session.piTree,
|
|
229
|
+
record,
|
|
230
|
+
captures,
|
|
231
|
+
events,
|
|
232
|
+
owner: lineage.owner,
|
|
233
|
+
});
|
|
234
|
+
let targetState: InspectionTargetState | null = null;
|
|
235
|
+
let inheritedBoundary: ExecutionInspectionTrace["inheritedBoundary"] = null;
|
|
236
|
+
const unavailable = {
|
|
237
|
+
state: "unavailable",
|
|
238
|
+
reason: "The requested item is unavailable or does not belong to this execution",
|
|
239
|
+
} as const;
|
|
240
|
+
let itemId = target.entryId ? `entry:${target.entryId}` : target.itemId;
|
|
241
|
+
if (itemId === "input")
|
|
242
|
+
itemId =
|
|
243
|
+
messages.find((message) => message.role === "user" || message.role === "system")?.id ??
|
|
244
|
+
itemId;
|
|
245
|
+
if (itemId === "reasoning")
|
|
246
|
+
itemId =
|
|
247
|
+
messages
|
|
248
|
+
.flatMap((message) => message.blocks)
|
|
249
|
+
.find((block) => block.content.type === "thinking")?.id ??
|
|
250
|
+
events
|
|
251
|
+
.filter(
|
|
252
|
+
(event) =>
|
|
253
|
+
event.eventType === "pi.stream.delta" && event.data.streamType === "thinking",
|
|
254
|
+
)
|
|
255
|
+
.map((event) => `event:${event.eventSequence}`)[0] ??
|
|
256
|
+
itemId;
|
|
257
|
+
if (itemId) {
|
|
258
|
+
const message = messages.find(
|
|
259
|
+
(message) =>
|
|
260
|
+
message.id === itemId ||
|
|
261
|
+
message.aliases.includes(itemId) ||
|
|
262
|
+
message.blocks.some((block) => block.id === itemId),
|
|
263
|
+
);
|
|
264
|
+
const event = events.find((event) => `event:${event.eventSequence}` === itemId);
|
|
265
|
+
targetState =
|
|
266
|
+
message || event
|
|
267
|
+
? { state: "available", itemId: message?.aliases.includes(itemId) ? message.id : itemId }
|
|
268
|
+
: unavailable;
|
|
269
|
+
}
|
|
270
|
+
if (target.boundaryFor) {
|
|
271
|
+
const child = lineageSnapshot.records.find((record) => record.id === target.boundaryFor);
|
|
272
|
+
const context = child ? lineage.origin(child).conversation : null;
|
|
273
|
+
const boundary = context?.state === "recorded" ? context.value : null;
|
|
274
|
+
if (
|
|
275
|
+
boundary?.turnRecordId === turnRecordId &&
|
|
276
|
+
(!target.entryId || boundary.entryId === target.entryId)
|
|
277
|
+
) {
|
|
278
|
+
inheritedBoundary = boundary;
|
|
279
|
+
targetState = messages.some((message) => message.entryId === boundary.entryId)
|
|
280
|
+
? { state: "available", itemId: `entry:${boundary.entryId}` }
|
|
281
|
+
: {
|
|
282
|
+
state: "unavailable",
|
|
283
|
+
reason: "The inheritance boundary is recorded, but its source entry is unavailable",
|
|
284
|
+
};
|
|
285
|
+
} else targetState = unavailable;
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
...history,
|
|
289
|
+
messages,
|
|
290
|
+
unassignedMessages: buildInspectionTraceMessages({
|
|
291
|
+
tree: session.piTree,
|
|
292
|
+
record,
|
|
293
|
+
scope: "unassigned_branch",
|
|
294
|
+
captures: [],
|
|
295
|
+
events: [],
|
|
296
|
+
owner: lineage.owner,
|
|
297
|
+
}),
|
|
298
|
+
events,
|
|
299
|
+
annotations,
|
|
300
|
+
output: record.turnResultMarkdown,
|
|
301
|
+
target: targetState,
|
|
302
|
+
inheritedBoundary,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
}
|