@leitwerk-dev/ui 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/ApiTokensPage-DCmYvZdE.js +1 -0
- package/dist/assets/ChronicleMarkdown-CDe1jngc.js +1 -0
- package/dist/assets/DashboardPage-BRxe3uuy.css +1 -0
- package/dist/assets/DashboardPage-LiQ0_72g.js +1 -0
- package/dist/assets/FutureLaunchDetailPage-DvyW_J5d.js +1 -0
- package/dist/assets/GenericLauncher-D1qQy9hq.js +4 -0
- package/dist/assets/GenericLauncher-DRUMMTd7.css +1 -0
- package/dist/assets/HomePage-Cnmp6osB.js +1 -0
- package/dist/assets/ProcessActionsMenu-DEQynjFa.js +1 -0
- package/dist/assets/ProcessDetailPage-DvjQQTDj.js +14 -0
- package/dist/assets/ProcessDetailPage-km76G8wj.css +1 -0
- package/dist/assets/ProcessFlowDiagram-DI5KZ2Qj.js +1 -0
- package/dist/assets/ProcessFlowDiagram-NQ6oEZi7.css +1 -0
- package/dist/assets/ProcessesPage-B4BMXJT7.js +1 -0
- package/dist/assets/ScheduleDateTimePicker-2eJ0jBQ-.css +1 -0
- package/dist/assets/ScheduleDateTimePicker-fg0Vau5Z.js +3 -0
- package/dist/assets/SettingsPage-BHSV4rl7.css +1 -0
- package/dist/assets/SettingsPage-w1RHZ2l6.js +2 -0
- package/dist/assets/SkillsPage-Ber36rAD.js +2 -0
- package/dist/assets/WatchersPage-Btq_SIk3.js +1 -0
- package/dist/assets/WikiPage-BjncVYf1.js +1 -0
- package/dist/assets/WikiPage-Bvnhxl3m.css +1 -0
- package/dist/assets/http-client-Cvi3zOou.js +2 -0
- package/dist/assets/http-contracts-public-BUgTIHYG.js +1 -0
- package/dist/assets/index-Dz0T5gKc.js +21 -0
- package/dist/assets/index-DzKWCM-z.css +1 -0
- package/dist/assets/{index-client-BYQviCtQ.js → index-client-BSAA7n1a.js} +2 -2
- package/dist/assets/mermaid-render.worker-BN0bcvGc.js +6398 -0
- package/dist/assets/retry-config.svelte-HNNF65qc.js +1 -0
- package/dist/assets/settings-Dk5UoSQa.js +1 -0
- package/dist/index.html +4 -7
- package/package.json +10 -9
- package/src/App.svelte +9 -0
- package/src/chronicle/components/ChronicleActionSection.svelte +10 -2
- package/src/chronicle/components/ChronicleEntryHeader.svelte +4 -16
- package/src/chronicle/components/ChronicleFlow.svelte +24 -6
- package/src/chronicle/components/ChronicleLiveTail.svelte +52 -24
- package/src/chronicle/components/ChronicleProcessErrorSection.svelte +14 -0
- package/src/chronicle/components/ChronicleQuestionRequest.svelte +1 -1
- package/src/chronicle/components/ChronicleRecoverySection.svelte +14 -10
- package/src/chronicle/components/ChronicleStartupRecoverySection.svelte +22 -10
- package/src/chronicle/components/ChronicleThinkingSection.svelte +8 -2
- package/src/chronicle/components/ChronicleToolApproval.svelte +120 -17
- package/src/chronicle/components/ChronicleToolCallItem.svelte +32 -6
- package/src/chronicle/components/ChronicleTurnCluster.svelte +6 -6
- package/src/chronicle/components/ChronicleTurnProgress.svelte +10 -4
- package/src/chronicle/components/ChronicleTurnRail.svelte +1 -0
- package/src/chronicle/components/RecoveryModelControl.svelte +14 -13
- package/src/chronicle/lib/chronicle-projection.ts +74 -376
- package/src/chronicle/lib/chronicle-selectable-items.ts +23 -3
- package/src/chronicle/lib/recovery-model.ts +17 -0
- package/src/components/ConversationTreeDiagram.svelte +93 -30
- package/src/components/FormFieldRenderer.svelte +184 -27
- package/src/components/GenericLauncher.svelte +438 -259
- package/src/components/NamedSelectionList.svelte +77 -0
- package/src/components/ProcessActionsMenu.svelte +37 -59
- package/src/components/ProcessSettings.svelte +110 -0
- package/src/components/ScheduleDateTimePicker.svelte +9 -4
- package/src/components/SettingsField.svelte +317 -0
- package/src/components/SettingsOverview.svelte +237 -0
- package/src/components/SkillSelector.svelte +15 -3
- package/src/components/launcher-form-copy.ts +2 -1
- package/src/components/launcher-model-config.ts +8 -7
- package/src/components/launcher-selections.ts +123 -0
- package/src/lib/api.ts +100 -43
- package/src/lib/dashboard-refresh.ts +47 -0
- package/src/lib/http-client.ts +20 -1
- package/src/lib/instance-tree-layout.ts +41 -10
- package/src/lib/primary-path-detail.ts +56 -341
- package/src/lib/primary-path-replay.ts +8 -9
- package/src/lib/process-history.ts +57 -0
- package/src/lib/processes.svelte.ts +71 -79
- package/src/lib/reasoning-history.ts +31 -23
- package/src/lib/router-logic.ts +127 -56
- package/src/lib/router.svelte.ts +10 -6
- package/src/lib/settings.ts +114 -0
- package/src/lib/wiki.ts +34 -0
- package/src/pages/DashboardPage.svelte +194 -0
- package/src/pages/FutureLaunchDetailPage.svelte +2 -2
- package/src/pages/HomePage.svelte +4 -4
- package/src/pages/ProcessDetailPage.svelte +55 -344
- package/src/pages/ProcessFlowDiagram.svelte +39 -684
- package/src/pages/SettingsPage.svelte +265 -0
- package/src/pages/SkillsPage.svelte +26 -12
- package/src/pages/WikiPage.svelte +9 -0
- package/src/pages/process-detail/ProcessDetailChronicle.svelte +57 -13
- package/src/pages/process-detail/ProcessDetailHeader.svelte +9 -3
- package/src/pages/process-detail/TicketCreationComposer.svelte +49 -10
- package/src/pages/process-detail/inspector/ExecutionDetails.svelte +210 -0
- package/src/pages/process-detail/inspector/InspectionEvidence.svelte +48 -0
- package/src/pages/process-detail/inspector/InspectionMessage.svelte +71 -0
- package/src/pages/process-detail/inspector/ProcessInspector.svelte +144 -0
- package/src/pages/process-detail/inspector/ProcessModelEditor.svelte +161 -0
- package/src/pages/process-detail/inspector/ProcessReference.svelte +166 -0
- package/src/pages/process-detail/inspector/inspection-activity.ts +118 -0
- package/src/pages/process-detail/inspector/inspection-data.svelte.ts +107 -0
- package/src/pages/process-detail/inspector/inspection-tool-call.ts +30 -0
- package/src/pages/process-detail/inspector/inspector-navigation.ts +190 -0
- package/src/pages/process-detail/inspector/model-source-label.ts +17 -0
- package/src/pages/process-detail/process-detail-actions.svelte.ts +10 -0
- package/src/pages/process-detail/process-detail-chronicle-scroll.svelte.ts +18 -2
- package/src/pages/process-detail/process-detail-view-model.ts +2 -2
- package/src/shell/AppShell.svelte +55 -56
- package/src/shell/Sidebar.svelte +136 -232
- package/src/test-support/mount.ts +34 -0
- package/src/test-support/wait.ts +19 -0
- package/dist/assets/ApiTokensPage-ClJp9PYr.js +0 -1
- package/dist/assets/ChronicleMarkdown-lqwX9Ywa.js +0 -16
- package/dist/assets/FutureLaunchDetailPage-ygp-IdXC.js +0 -1
- package/dist/assets/GenericLauncher-CExW6wei.css +0 -1
- package/dist/assets/GenericLauncher-DOwsERpB.js +0 -1
- package/dist/assets/HomePage-D1J-Rmsw.js +0 -1
- package/dist/assets/PageHeader-DPuQInDo.css +0 -1
- package/dist/assets/PageHeader-sphJnWL1.js +0 -1
- package/dist/assets/ProcessActionsMenu-DV9zaxNS.js +0 -1
- package/dist/assets/ProcessDetailPage-BW1M2IH8.js +0 -14
- package/dist/assets/ProcessDetailPage-Cth6A0DN.css +0 -1
- package/dist/assets/ProcessFlowDiagram-Cz8wNicU.css +0 -1
- package/dist/assets/ProcessFlowDiagram-Dx2wheGN.js +0 -2
- package/dist/assets/ProcessesPage-CSPH5L7E.js +0 -1
- package/dist/assets/ScheduleDateTimePicker-DmojMRxN.js +0 -1
- package/dist/assets/ScheduleDateTimePicker-uacJAkIq.css +0 -1
- package/dist/assets/SkillsPage-KnLql0n1.js +0 -2
- package/dist/assets/WatchersPage-B4jf3Ywp.js +0 -1
- package/dist/assets/http-client-VpPXJwbR.js +0 -2
- package/dist/assets/index-DPCokDbS.js +0 -6
- package/dist/assets/index-DtEI5gsQ.css +0 -1
- package/dist/assets/mermaid-render.worker-QW2WZpEE.js +0 -6393
- package/dist/assets/process-terminal-display-BQRQwGod.js +0 -1
- package/dist/assets/router.svelte-EEldxHlO.js +0 -1
- package/src/chronicle/components/ChronicleReasoningDetailsOverlay.svelte +0 -855
- package/src/components/ProcessInfoOverlay.svelte +0 -1221
- package/src/lib/flow-layout.ts +0 -319
- package/src/pages/process-detail/OverlayFrame.svelte +0 -58
|
@@ -1,55 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
+
type CompactActiveTurnSnapshot,
|
|
2
3
|
emptyCompactTurnSummary,
|
|
3
|
-
type PrimaryPathActiveTurnSnapshot,
|
|
4
|
-
type PrimaryPathSnapshot,
|
|
5
|
-
type PrimaryPathToolCallSnapshot,
|
|
6
|
-
type PrimaryPathTraceItemSnapshot,
|
|
7
4
|
type PrimaryPathUiSnapshot,
|
|
8
5
|
type PrimaryPathWsFrame,
|
|
9
6
|
WS_PRIMARY_PATH_TYPES,
|
|
10
7
|
} from "@leitwerk-dev/protocol";
|
|
11
|
-
import { cloneTurnUsageSnapshot } from "./usage-snapshot.js";
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return traceItems.map((traceItem) => ({ ...traceItem }));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function createActiveTurnSnapshot(
|
|
25
|
-
turnRecord: Extract<
|
|
26
|
-
PrimaryPathWsFrame,
|
|
27
|
-
{ type: typeof WS_PRIMARY_PATH_TYPES.TURN_STARTED }
|
|
28
|
-
>["payload"]["turnRecord"],
|
|
29
|
-
): PrimaryPathActiveTurnSnapshot {
|
|
30
|
-
return {
|
|
31
|
-
turnRecordId: turnRecord.id,
|
|
32
|
-
turnId: turnRecord.turnId,
|
|
33
|
-
turnType: turnRecord.turnType,
|
|
34
|
-
pathType: turnRecord.pathType,
|
|
35
|
-
startedAt: turnRecord.startedAt,
|
|
36
|
-
assistant: {
|
|
37
|
-
text: "",
|
|
38
|
-
thinking: "",
|
|
39
|
-
lastUpdatedAt: null,
|
|
40
|
-
},
|
|
41
|
-
toolCalls: [],
|
|
42
|
-
traceItems: [],
|
|
43
|
-
usage: null,
|
|
44
|
-
eventWindowTruncated: false,
|
|
45
|
-
};
|
|
9
|
+
/** @internal */
|
|
10
|
+
export function isFullPrimaryPathDetailFrame(frame: PrimaryPathWsFrame): boolean {
|
|
11
|
+
return (
|
|
12
|
+
frame.type === WS_PRIMARY_PATH_TYPES.ASSISTANT_PARTIAL ||
|
|
13
|
+
frame.type === WS_PRIMARY_PATH_TYPES.USAGE_UPDATED ||
|
|
14
|
+
frame.type === WS_PRIMARY_PATH_TYPES.TOOL_CALL_STARTED ||
|
|
15
|
+
frame.type === WS_PRIMARY_PATH_TYPES.TOOL_CALL_COMPLETED
|
|
16
|
+
);
|
|
46
17
|
}
|
|
47
18
|
|
|
48
|
-
function updateSemanticLeafRefs
|
|
49
|
-
snapshot:
|
|
50
|
-
rootEntry:
|
|
51
|
-
currentLeaf:
|
|
52
|
-
):
|
|
19
|
+
function updateSemanticLeafRefs(
|
|
20
|
+
snapshot: PrimaryPathUiSnapshot,
|
|
21
|
+
rootEntry: PrimaryPathUiSnapshot["semanticEntryRefs"]["rootEntry"],
|
|
22
|
+
currentLeaf: PrimaryPathUiSnapshot["semanticEntryRefs"]["currentPrimaryPathLeaf"],
|
|
23
|
+
): PrimaryPathUiSnapshot {
|
|
53
24
|
return {
|
|
54
25
|
...snapshot,
|
|
55
26
|
currentLeaf,
|
|
@@ -61,246 +32,48 @@ function updateSemanticLeafRefs<TSnapshot extends PrimaryPathSnapshot>(
|
|
|
61
32
|
};
|
|
62
33
|
}
|
|
63
34
|
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
nextToolCall: PrimaryPathToolCallSnapshot,
|
|
67
|
-
): PrimaryPathToolCallSnapshot[] {
|
|
68
|
-
const existingIndex = toolCalls.findIndex(
|
|
69
|
-
(toolCall) => toolCall.toolCallId === nextToolCall.toolCallId,
|
|
70
|
-
);
|
|
71
|
-
if (existingIndex === -1) {
|
|
72
|
-
return [...toolCalls, nextToolCall];
|
|
73
|
-
}
|
|
74
|
-
return toolCalls.map((toolCall, index) =>
|
|
75
|
-
index === existingIndex
|
|
76
|
-
? {
|
|
77
|
-
...toolCall,
|
|
78
|
-
...nextToolCall,
|
|
79
|
-
arguments: nextToolCall.arguments ?? toolCall.arguments,
|
|
80
|
-
}
|
|
81
|
-
: toolCall,
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function appendThinkingTraceItems(
|
|
86
|
-
traceItems: readonly PrimaryPathTraceItemSnapshot[],
|
|
87
|
-
text: string,
|
|
88
|
-
): PrimaryPathTraceItemSnapshot[] {
|
|
89
|
-
if (text.length === 0) {
|
|
90
|
-
return [...traceItems];
|
|
91
|
-
}
|
|
92
|
-
const lastTraceItem = traceItems.at(-1);
|
|
93
|
-
if (lastTraceItem?.kind === "thinking") {
|
|
94
|
-
return [
|
|
95
|
-
...traceItems.slice(0, -1),
|
|
96
|
-
{
|
|
97
|
-
...lastTraceItem,
|
|
98
|
-
text: lastTraceItem.text + text,
|
|
99
|
-
},
|
|
100
|
-
];
|
|
101
|
-
}
|
|
102
|
-
return [...traceItems, { kind: "thinking", text }];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function ensureToolTraceItem(
|
|
106
|
-
traceItems: readonly PrimaryPathTraceItemSnapshot[],
|
|
107
|
-
toolCallId: string,
|
|
108
|
-
): PrimaryPathTraceItemSnapshot[] {
|
|
109
|
-
if (
|
|
110
|
-
traceItems.some(
|
|
111
|
-
(traceItem) => traceItem.kind === "tool_call" && traceItem.toolCallId === toolCallId,
|
|
112
|
-
)
|
|
113
|
-
) {
|
|
114
|
-
return [...traceItems];
|
|
115
|
-
}
|
|
116
|
-
return [...traceItems, { kind: "tool_call", toolCallId }];
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export function getPrimaryPathActiveTurnOutput(
|
|
120
|
-
activeTurn: Pick<PrimaryPathActiveTurnSnapshot, "assistant"> | null | undefined,
|
|
121
|
-
): string {
|
|
122
|
-
if (!activeTurn) {
|
|
123
|
-
return "";
|
|
124
|
-
}
|
|
125
|
-
return activeTurn.assistant.text.trim();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function applyFullPrimaryPathFrame<TSnapshot extends PrimaryPathSnapshot>(
|
|
129
|
-
snapshot: TSnapshot,
|
|
35
|
+
function applyMetadataFrame(
|
|
36
|
+
snapshot: PrimaryPathUiSnapshot,
|
|
130
37
|
frame: PrimaryPathWsFrame,
|
|
131
|
-
):
|
|
38
|
+
): PrimaryPathUiSnapshot {
|
|
132
39
|
switch (frame.type) {
|
|
133
|
-
case WS_PRIMARY_PATH_TYPES.TURN_STARTED:
|
|
134
|
-
return {
|
|
135
|
-
...snapshot,
|
|
136
|
-
turnState: {
|
|
137
|
-
...snapshot.turnState,
|
|
138
|
-
currentTurnRecordId: frame.payload.turnRecord.id,
|
|
139
|
-
isStreaming: true,
|
|
140
|
-
activeTurn: createActiveTurnSnapshot(frame.payload.turnRecord),
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
case WS_PRIMARY_PATH_TYPES.ASSISTANT_PARTIAL: {
|
|
144
|
-
const activeTurn = snapshot.turnState.activeTurn;
|
|
145
|
-
if (
|
|
146
|
-
!activeTurn ||
|
|
147
|
-
(frame.payload.turnRecordId && activeTurn.turnRecordId !== frame.payload.turnRecordId)
|
|
148
|
-
) {
|
|
149
|
-
return snapshot;
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
...snapshot,
|
|
153
|
-
turnState: {
|
|
154
|
-
...snapshot.turnState,
|
|
155
|
-
isStreaming: true,
|
|
156
|
-
activeTurn: {
|
|
157
|
-
...activeTurn,
|
|
158
|
-
assistant: {
|
|
159
|
-
...activeTurn.assistant,
|
|
160
|
-
text:
|
|
161
|
-
frame.payload.streamType === "thinking"
|
|
162
|
-
? activeTurn.assistant.text
|
|
163
|
-
: activeTurn.assistant.text + frame.payload.text,
|
|
164
|
-
thinking:
|
|
165
|
-
frame.payload.streamType === "thinking"
|
|
166
|
-
? activeTurn.assistant.thinking + frame.payload.text
|
|
167
|
-
: activeTurn.assistant.thinking,
|
|
168
|
-
lastUpdatedAt: frame.payload.timestamp,
|
|
169
|
-
},
|
|
170
|
-
traceItems:
|
|
171
|
-
frame.payload.streamType === "thinking"
|
|
172
|
-
? appendThinkingTraceItems(activeTurn.traceItems, frame.payload.text)
|
|
173
|
-
: cloneTraceItems(activeTurn.traceItems),
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
case WS_PRIMARY_PATH_TYPES.USAGE_UPDATED: {
|
|
179
|
-
const activeTurn = snapshot.turnState.activeTurn;
|
|
180
|
-
if (
|
|
181
|
-
!activeTurn ||
|
|
182
|
-
(frame.payload.turnRecordId && activeTurn.turnRecordId !== frame.payload.turnRecordId)
|
|
183
|
-
) {
|
|
184
|
-
return snapshot;
|
|
185
|
-
}
|
|
186
|
-
return {
|
|
187
|
-
...snapshot,
|
|
188
|
-
turnState: {
|
|
189
|
-
...snapshot.turnState,
|
|
190
|
-
activeTurn: {
|
|
191
|
-
...activeTurn,
|
|
192
|
-
usage: cloneTurnUsageSnapshot(frame.payload.usage),
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
case WS_PRIMARY_PATH_TYPES.TOOL_CALL_STARTED: {
|
|
198
|
-
const activeTurn = snapshot.turnState.activeTurn;
|
|
199
|
-
if (
|
|
200
|
-
!activeTurn ||
|
|
201
|
-
(frame.payload.turnRecordId && activeTurn.turnRecordId !== frame.payload.turnRecordId)
|
|
202
|
-
) {
|
|
203
|
-
return snapshot;
|
|
204
|
-
}
|
|
205
|
-
return {
|
|
206
|
-
...snapshot,
|
|
207
|
-
turnState: {
|
|
208
|
-
...snapshot.turnState,
|
|
209
|
-
activeTurn: {
|
|
210
|
-
...activeTurn,
|
|
211
|
-
toolCalls: upsertToolCall(activeTurn.toolCalls, {
|
|
212
|
-
toolCallId: frame.payload.toolCallId,
|
|
213
|
-
toolName: frame.payload.toolName,
|
|
214
|
-
status: "running",
|
|
215
|
-
startedAt: frame.payload.timestamp,
|
|
216
|
-
completedAt: null,
|
|
217
|
-
arguments: frame.payload.arguments,
|
|
218
|
-
result: null,
|
|
219
|
-
isError: false,
|
|
220
|
-
}),
|
|
221
|
-
traceItems: ensureToolTraceItem(activeTurn.traceItems, frame.payload.toolCallId),
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
case WS_PRIMARY_PATH_TYPES.TOOL_CALL_COMPLETED: {
|
|
227
|
-
const activeTurn = snapshot.turnState.activeTurn;
|
|
228
|
-
if (
|
|
229
|
-
!activeTurn ||
|
|
230
|
-
(frame.payload.turnRecordId && activeTurn.turnRecordId !== frame.payload.turnRecordId)
|
|
231
|
-
) {
|
|
232
|
-
return snapshot;
|
|
233
|
-
}
|
|
234
|
-
const existingToolCall = activeTurn.toolCalls.find(
|
|
235
|
-
(toolCall) => toolCall.toolCallId === frame.payload.toolCallId,
|
|
236
|
-
);
|
|
237
|
-
return {
|
|
238
|
-
...snapshot,
|
|
239
|
-
turnState: {
|
|
240
|
-
...snapshot.turnState,
|
|
241
|
-
activeTurn: {
|
|
242
|
-
...activeTurn,
|
|
243
|
-
toolCalls: upsertToolCall(activeTurn.toolCalls, {
|
|
244
|
-
toolCallId: frame.payload.toolCallId,
|
|
245
|
-
toolName: frame.payload.toolName,
|
|
246
|
-
status: "completed",
|
|
247
|
-
startedAt: existingToolCall?.startedAt ?? frame.payload.timestamp,
|
|
248
|
-
completedAt: frame.payload.timestamp,
|
|
249
|
-
arguments: existingToolCall?.arguments ?? null,
|
|
250
|
-
result: frame.payload.result,
|
|
251
|
-
isError: frame.payload.isError,
|
|
252
|
-
}),
|
|
253
|
-
traceItems: ensureToolTraceItem(activeTurn.traceItems, frame.payload.toolCallId),
|
|
254
|
-
},
|
|
255
|
-
},
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
40
|
case WS_PRIMARY_PATH_TYPES.ASSISTANT_COMMITTED: {
|
|
259
|
-
const
|
|
41
|
+
const next = updateSemanticLeafRefs(
|
|
260
42
|
snapshot,
|
|
261
43
|
frame.payload.rootEntry,
|
|
262
44
|
frame.payload.currentLeaf,
|
|
263
45
|
);
|
|
264
46
|
return {
|
|
265
|
-
...
|
|
47
|
+
...next,
|
|
266
48
|
turnState: {
|
|
267
|
-
...
|
|
49
|
+
...next.turnState,
|
|
268
50
|
currentTurnRecordId: null,
|
|
269
51
|
isStreaming: false,
|
|
270
52
|
activeTurn: null,
|
|
271
53
|
},
|
|
272
54
|
};
|
|
273
55
|
}
|
|
274
|
-
case WS_PRIMARY_PATH_TYPES.TURN_ANNOTATION_CHANGED:
|
|
275
|
-
const nextAnnotations = snapshot.turnAnnotations.some(
|
|
276
|
-
(annotation) => annotation.id === frame.payload.annotation.id,
|
|
277
|
-
)
|
|
278
|
-
? snapshot.turnAnnotations.map((annotation) =>
|
|
279
|
-
annotation.id === frame.payload.annotation.id ? frame.payload.annotation : annotation,
|
|
280
|
-
)
|
|
281
|
-
: [...snapshot.turnAnnotations, frame.payload.annotation];
|
|
56
|
+
case WS_PRIMARY_PATH_TYPES.TURN_ANNOTATION_CHANGED:
|
|
282
57
|
return {
|
|
283
58
|
...snapshot,
|
|
284
|
-
turnAnnotations:
|
|
59
|
+
turnAnnotations: snapshot.turnAnnotations.some(
|
|
60
|
+
(annotation) => annotation.id === frame.payload.annotation.id,
|
|
61
|
+
)
|
|
62
|
+
? snapshot.turnAnnotations.map((annotation) =>
|
|
63
|
+
annotation.id === frame.payload.annotation.id ? frame.payload.annotation : annotation,
|
|
64
|
+
)
|
|
65
|
+
: [...snapshot.turnAnnotations, frame.payload.annotation],
|
|
285
66
|
};
|
|
286
|
-
}
|
|
287
67
|
case WS_PRIMARY_PATH_TYPES.LABEL_CHANGED: {
|
|
288
68
|
if (
|
|
289
69
|
!frame.payload.targetId ||
|
|
290
70
|
!snapshot.primaryPathEntries.some((entry) => entry.id === frame.payload.targetId)
|
|
291
|
-
)
|
|
71
|
+
)
|
|
292
72
|
return snapshot;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
} else {
|
|
298
|
-
delete nextLabels[frame.payload.targetId];
|
|
299
|
-
}
|
|
300
|
-
return {
|
|
301
|
-
...snapshot,
|
|
302
|
-
labels: nextLabels,
|
|
303
|
-
};
|
|
73
|
+
const labels = { ...snapshot.labels };
|
|
74
|
+
if (frame.payload.label) labels[frame.payload.targetId] = frame.payload.label;
|
|
75
|
+
else delete labels[frame.payload.targetId];
|
|
76
|
+
return { ...snapshot, labels };
|
|
304
77
|
}
|
|
305
78
|
case WS_PRIMARY_PATH_TYPES.CHANGED:
|
|
306
79
|
return updateSemanticLeafRefs(snapshot, frame.payload.rootEntry, frame.payload.currentLeaf);
|
|
@@ -309,46 +82,20 @@ function applyFullPrimaryPathFrame<TSnapshot extends PrimaryPathSnapshot>(
|
|
|
309
82
|
}
|
|
310
83
|
}
|
|
311
84
|
|
|
312
|
-
function
|
|
313
|
-
|
|
314
|
-
):
|
|
315
|
-
return
|
|
316
|
-
...snapshot,
|
|
317
|
-
rebuiltAt: snapshot.rebuiltAt,
|
|
318
|
-
primaryPathEntries: snapshot.primaryPathEntries.map((entry) => ({ ...entry })),
|
|
319
|
-
semanticEntryRefs: { ...snapshot.semanticEntryRefs },
|
|
320
|
-
labels: { ...snapshot.labels },
|
|
321
|
-
turnAnnotations: snapshot.turnAnnotations.map((annotation) => ({
|
|
322
|
-
...annotation,
|
|
323
|
-
references: [...annotation.references],
|
|
324
|
-
payload: { ...annotation.payload },
|
|
325
|
-
})),
|
|
326
|
-
turnState: {
|
|
327
|
-
...snapshot.turnState,
|
|
328
|
-
activeTurn: snapshot.turnState.activeTurn
|
|
329
|
-
? {
|
|
330
|
-
...snapshot.turnState.activeTurn,
|
|
331
|
-
assistant: { ...snapshot.turnState.activeTurn.assistant },
|
|
332
|
-
toolCalls: cloneToolCalls(snapshot.turnState.activeTurn.toolCalls),
|
|
333
|
-
traceItems: cloneTraceItems(snapshot.turnState.activeTurn.traceItems),
|
|
334
|
-
usage: cloneTurnUsageSnapshot(snapshot.turnState.activeTurn.usage),
|
|
335
|
-
}
|
|
336
|
-
: null,
|
|
337
|
-
},
|
|
338
|
-
};
|
|
85
|
+
export function getPrimaryPathActiveTurnOutput(
|
|
86
|
+
activeTurn: Pick<CompactActiveTurnSnapshot, "assistant"> | null | undefined,
|
|
87
|
+
): string {
|
|
88
|
+
return activeTurn?.assistant.text.trim() ?? "";
|
|
339
89
|
}
|
|
340
90
|
|
|
341
|
-
export function applyPrimaryPathFrame
|
|
342
|
-
snapshot:
|
|
91
|
+
export function applyPrimaryPathFrame(
|
|
92
|
+
snapshot: PrimaryPathUiSnapshot,
|
|
343
93
|
frame: PrimaryPathWsFrame,
|
|
344
|
-
):
|
|
345
|
-
if (
|
|
346
|
-
return applyFullPrimaryPathFrame(snapshot as PrimaryPathSnapshot, frame) as T;
|
|
347
|
-
const compact = snapshot as PrimaryPathUiSnapshot;
|
|
348
|
-
if (frame.eventSequence !== undefined && frame.eventSequence <= compact.throughEventSequence)
|
|
94
|
+
): PrimaryPathUiSnapshot {
|
|
95
|
+
if (frame.eventSequence !== undefined && frame.eventSequence <= snapshot.throughEventSequence)
|
|
349
96
|
return snapshot;
|
|
97
|
+
const active = snapshot.turnState.activeTurn;
|
|
350
98
|
if (frame.type === WS_PRIMARY_PATH_TYPES.SUMMARY_UPDATED) {
|
|
351
|
-
const active = compact.turnState.activeTurn;
|
|
352
99
|
if (
|
|
353
100
|
!active ||
|
|
354
101
|
active.turnRecordId !== frame.payload.turnRecordId ||
|
|
@@ -356,21 +103,21 @@ export function applyPrimaryPathFrame<T extends PrimaryPathSnapshot | PrimaryPat
|
|
|
356
103
|
)
|
|
357
104
|
return snapshot;
|
|
358
105
|
return {
|
|
359
|
-
...
|
|
360
|
-
throughEventSequence: frame.eventSequence ??
|
|
106
|
+
...snapshot,
|
|
107
|
+
throughEventSequence: frame.eventSequence ?? snapshot.throughEventSequence,
|
|
361
108
|
turnState: {
|
|
362
|
-
...
|
|
109
|
+
...snapshot.turnState,
|
|
363
110
|
activeTurn: { ...active, ...frame.payload.summary, summaryPending: false },
|
|
364
111
|
},
|
|
365
|
-
}
|
|
112
|
+
};
|
|
366
113
|
}
|
|
367
114
|
if (frame.type === WS_PRIMARY_PATH_TYPES.TURN_STARTED) {
|
|
368
115
|
const turn = frame.payload.turnRecord;
|
|
369
116
|
return {
|
|
370
|
-
...
|
|
371
|
-
throughEventSequence: frame.eventSequence ??
|
|
117
|
+
...snapshot,
|
|
118
|
+
throughEventSequence: frame.eventSequence ?? snapshot.throughEventSequence,
|
|
372
119
|
turnState: {
|
|
373
|
-
...
|
|
120
|
+
...snapshot.turnState,
|
|
374
121
|
currentTurnRecordId: turn.id,
|
|
375
122
|
isStreaming: true,
|
|
376
123
|
activeTurn: {
|
|
@@ -383,49 +130,17 @@ export function applyPrimaryPathFrame<T extends PrimaryPathSnapshot | PrimaryPat
|
|
|
383
130
|
summaryPending: true,
|
|
384
131
|
},
|
|
385
132
|
},
|
|
386
|
-
}
|
|
133
|
+
};
|
|
387
134
|
}
|
|
388
|
-
if (
|
|
389
|
-
[
|
|
390
|
-
WS_PRIMARY_PATH_TYPES.ASSISTANT_PARTIAL,
|
|
391
|
-
WS_PRIMARY_PATH_TYPES.USAGE_UPDATED,
|
|
392
|
-
WS_PRIMARY_PATH_TYPES.TOOL_CALL_STARTED,
|
|
393
|
-
WS_PRIMARY_PATH_TYPES.TOOL_CALL_COMPLETED,
|
|
394
|
-
].includes(frame.type as typeof WS_PRIMARY_PATH_TYPES.ASSISTANT_PARTIAL)
|
|
395
|
-
)
|
|
396
|
-
return snapshot;
|
|
135
|
+
if (isFullPrimaryPathDetailFrame(frame)) return snapshot;
|
|
397
136
|
if (
|
|
398
137
|
frame.type === WS_PRIMARY_PATH_TYPES.ASSISTANT_COMMITTED &&
|
|
399
|
-
|
|
400
|
-
|
|
138
|
+
active &&
|
|
139
|
+
active.turnRecordId !== frame.payload.turnRecord.id
|
|
401
140
|
)
|
|
402
141
|
return snapshot;
|
|
403
|
-
const metadata = applyFullPrimaryPathFrame(
|
|
404
|
-
{ ...compact, turnState: { ...compact.turnState, activeTurn: null } },
|
|
405
|
-
frame,
|
|
406
|
-
);
|
|
407
142
|
return {
|
|
408
|
-
...
|
|
409
|
-
throughEventSequence: frame.eventSequence ??
|
|
410
|
-
|
|
411
|
-
frame.type === WS_PRIMARY_PATH_TYPES.ASSISTANT_COMMITTED
|
|
412
|
-
? metadata.turnState
|
|
413
|
-
: compact.turnState,
|
|
414
|
-
} as T;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
export function clonePrimaryPathSnapshot<T extends PrimaryPathSnapshot | PrimaryPathUiSnapshot>(
|
|
418
|
-
snapshot: T,
|
|
419
|
-
): T {
|
|
420
|
-
if ("entriesOmitted" in snapshot)
|
|
421
|
-
return {
|
|
422
|
-
...snapshot,
|
|
423
|
-
turnState: {
|
|
424
|
-
...snapshot.turnState,
|
|
425
|
-
activeTurn: snapshot.turnState.activeTurn
|
|
426
|
-
? structuredClone(snapshot.turnState.activeTurn)
|
|
427
|
-
: null,
|
|
428
|
-
},
|
|
429
|
-
};
|
|
430
|
-
return cloneFullPrimaryPathSnapshot(snapshot as PrimaryPathSnapshot) as T;
|
|
143
|
+
...applyMetadataFrame(snapshot, frame),
|
|
144
|
+
throughEventSequence: frame.eventSequence ?? snapshot.throughEventSequence,
|
|
145
|
+
};
|
|
431
146
|
}
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
compareTimestampStrings,
|
|
3
|
-
type PrimaryPathSnapshot,
|
|
4
3
|
type PrimaryPathUiSnapshot,
|
|
5
4
|
type PrimaryPathWsFrame,
|
|
6
5
|
} from "@leitwerk-dev/protocol";
|
|
7
|
-
import { applyPrimaryPathFrame
|
|
6
|
+
import { applyPrimaryPathFrame } from "./primary-path-detail.js";
|
|
8
7
|
|
|
9
8
|
export function shouldReplayPrimaryPathFrameAfterSnapshot(
|
|
10
9
|
frame: Pick<PrimaryPathWsFrame, "sentAt" | "eventSequence">,
|
|
11
|
-
snapshot: Pick<
|
|
10
|
+
snapshot: Pick<PrimaryPathUiSnapshot, "rebuiltAt" | "throughEventSequence">,
|
|
12
11
|
): boolean {
|
|
13
|
-
if (frame.eventSequence !== undefined
|
|
14
|
-
return frame.eventSequence > snapshot.throughEventSequence;
|
|
12
|
+
if (frame.eventSequence !== undefined) return frame.eventSequence > snapshot.throughEventSequence;
|
|
15
13
|
return compareTimestampStrings(frame.sentAt, snapshot.rebuiltAt) > 0;
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
export function replayPrimaryPathFramesAfterSnapshot
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
export function replayPrimaryPathFramesAfterSnapshot(
|
|
17
|
+
snapshot: PrimaryPathUiSnapshot,
|
|
18
|
+
frames: readonly PrimaryPathWsFrame[],
|
|
19
|
+
): PrimaryPathUiSnapshot {
|
|
20
|
+
let nextSnapshot = structuredClone(snapshot);
|
|
22
21
|
for (const frame of [...frames].sort((a, b) =>
|
|
23
22
|
a.eventSequence !== undefined && b.eventSequence !== undefined
|
|
24
23
|
? a.eventSequence - b.eventSequence
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ProcessDetailData } from "./api.js";
|
|
2
|
+
|
|
3
|
+
/** @internal */
|
|
4
|
+
export function mergeUniqueBy<T>(
|
|
5
|
+
items: readonly T[],
|
|
6
|
+
incoming: readonly T[],
|
|
7
|
+
key: (item: T) => string,
|
|
8
|
+
): T[] {
|
|
9
|
+
return [...new Map([...items, ...incoming].map((item) => [key(item), item])).values()];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Add older evidence without replacing live process state or newer versions of records. */
|
|
13
|
+
export function mergeProcessHistory(
|
|
14
|
+
current: ProcessDetailData,
|
|
15
|
+
older: ProcessDetailData,
|
|
16
|
+
): ProcessDetailData {
|
|
17
|
+
const byId = <T extends { id: string }>(a: readonly T[], b: readonly T[]) =>
|
|
18
|
+
mergeUniqueBy(a, b, (item) => item.id);
|
|
19
|
+
return {
|
|
20
|
+
...current,
|
|
21
|
+
timeline: {
|
|
22
|
+
...current.timeline,
|
|
23
|
+
history: older.timeline.history,
|
|
24
|
+
// Only the current snapshot owns live rows, including temporary current: IDs.
|
|
25
|
+
turns: byId(
|
|
26
|
+
older.timeline.turns.filter((turn) => turn.status !== "in_progress"),
|
|
27
|
+
current.timeline.turns,
|
|
28
|
+
).sort((a, b) => a.startedAt.localeCompare(b.startedAt) || a.id.localeCompare(b.id)),
|
|
29
|
+
inputs: byId(older.timeline.inputs, current.timeline.inputs),
|
|
30
|
+
tracePreviewsByTurnRecordId: {
|
|
31
|
+
...older.timeline.tracePreviewsByTurnRecordId,
|
|
32
|
+
...current.timeline.tracePreviewsByTurnRecordId,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
leafOutcomeSnapshots: byId(older.leafOutcomeSnapshots, current.leafOutcomeSnapshots),
|
|
36
|
+
questionRequests: byId(older.questionRequests, current.questionRequests),
|
|
37
|
+
toolApprovalRequests: byId(older.toolApprovalRequests, current.toolApprovalRequests),
|
|
38
|
+
instanceTree: {
|
|
39
|
+
...current.instanceTree,
|
|
40
|
+
nodes: byId(older.instanceTree.nodes, current.instanceTree.nodes),
|
|
41
|
+
edges: byId(older.instanceTree.edges, current.instanceTree.edges),
|
|
42
|
+
},
|
|
43
|
+
startup: {
|
|
44
|
+
...current.startup,
|
|
45
|
+
attempts: mergeUniqueBy(
|
|
46
|
+
older.startup.attempts,
|
|
47
|
+
current.startup.attempts,
|
|
48
|
+
(item) => item.startRecordId,
|
|
49
|
+
),
|
|
50
|
+
workerStarts: mergeUniqueBy(
|
|
51
|
+
older.startup.workerStarts ?? [],
|
|
52
|
+
current.startup.workerStarts ?? [],
|
|
53
|
+
(item) => item.workerLeaseId,
|
|
54
|
+
),
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|