@leitwerk-dev/ui 0.3.0 → 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/assets/ApiTokensPage-DCmYvZdE.js +1 -0
- package/dist/assets/ChronicleMarkdown-6T_LF-3B.js +1 -0
- package/dist/assets/FutureLaunchDetailPage-D5Gc8YmZ.js +1 -0
- package/dist/assets/GenericLauncher-4BQGl6fT.js +4 -0
- package/dist/assets/GenericLauncher-DRUMMTd7.css +1 -0
- package/dist/assets/HomePage-mb9RzXht.js +1 -0
- package/dist/assets/ProcessActionsMenu-CEzADnZT.js +1 -0
- package/dist/assets/ProcessDetailPage-0c-fMf4Y.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-CVvENTJg.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-CbNM5RWn.js +2 -0
- package/dist/assets/SkillsPage-rCSwSz89.js +2 -0
- package/dist/assets/WatchersPage-D-uT5vWk.js +1 -0
- package/dist/assets/WikiPage-BNdWnJ6L.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-BXXSFKbw.js +1 -0
- package/dist/assets/index-DybyOt1_.css +1 -0
- package/dist/assets/{index-client-BYQviCtQ.js → index-client-BSAA7n1a.js} +2 -2
- package/dist/assets/index-gVt2yBO1.js +21 -0
- 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 +25 -6
- package/src/chronicle/components/ChronicleLiveTail.svelte +54 -25
- 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 +14 -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 +9 -6
- package/src/chronicle/components/ChronicleTurnProgress.svelte +10 -4
- package/src/chronicle/components/ChronicleTurnRail.svelte +10 -2
- package/src/chronicle/components/RecoveryModelControl.svelte +14 -13
- package/src/chronicle/lib/chronicle-projection.ts +82 -383
- package/src/chronicle/lib/chronicle-rail-groups.ts +8 -1
- package/src/chronicle/lib/chronicle-selectable-items.ts +25 -3
- package/src/chronicle/lib/chronicle-view-model.ts +18 -1
- package/src/chronicle/lib/recovery-model.ts +17 -0
- package/src/chronicle/lib/retry-groups.ts +13 -5
- package/src/components/ConversationTreeDiagram.svelte +93 -30
- package/src/components/FormFieldRenderer.svelte +184 -27
- package/src/components/GenericLauncher.svelte +378 -166
- package/src/components/NamedSelectionList.svelte +77 -0
- 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 +89 -43
- 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 +101 -51
- package/src/lib/router.svelte.ts +4 -4
- package/src/lib/settings.ts +114 -0
- package/src/lib/wiki.ts +34 -0
- 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 +5 -0
- package/src/shell/Sidebar.svelte +10 -0
- package/src/test-support/mount.ts +34 -0
- package/dist/assets/ApiTokensPage-ClJp9PYr.js +0 -1
- package/dist/assets/ChronicleMarkdown-lqwX9Ywa.js +0 -16
- package/dist/assets/FutureLaunchDetailPage-CB7mNpYv.js +0 -1
- package/dist/assets/GenericLauncher-CExW6wei.css +0 -1
- package/dist/assets/GenericLauncher-DTyRwWVd.js +0 -1
- package/dist/assets/HomePage-D_OT6OWU.js +0 -1
- package/dist/assets/PageHeader-DPuQInDo.css +0 -1
- package/dist/assets/PageHeader-sphJnWL1.js +0 -1
- package/dist/assets/ProcessActionsMenu-IKG-csM4.js +0 -1
- package/dist/assets/ProcessDetailPage-CiI5T6pN.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-CdnLkrSk.js +0 -1
- package/dist/assets/ScheduleDateTimePicker-DmojMRxN.js +0 -1
- package/dist/assets/ScheduleDateTimePicker-uacJAkIq.css +0 -1
- package/dist/assets/SkillsPage-CmiSWLOW.js +0 -2
- package/dist/assets/WatchersPage-Bu1vfZQI.js +0 -1
- package/dist/assets/http-client-VpPXJwbR.js +0 -2
- package/dist/assets/index-BkfAI7to.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
package/src/lib/http-client.ts
CHANGED
|
@@ -5,6 +5,23 @@ import { getFetchImpl, resolveApiUrl } from "./runtime-config.js";
|
|
|
5
5
|
|
|
6
6
|
export { unknownRecordSchema };
|
|
7
7
|
|
|
8
|
+
/** @internal */
|
|
9
|
+
export class ApiResponseError extends Error {
|
|
10
|
+
constructor(
|
|
11
|
+
message: string,
|
|
12
|
+
readonly status: number,
|
|
13
|
+
) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "ApiResponseError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @internal */
|
|
20
|
+
export function apiResponseError(message: string, preferMessage = false) {
|
|
21
|
+
return (response: Response, body: unknown) =>
|
|
22
|
+
new ApiResponseError(readErrorMessage(body, preferMessage) ?? message, response.status);
|
|
23
|
+
}
|
|
24
|
+
|
|
8
25
|
export async function tryReadJson(response: Response): Promise<unknown> {
|
|
9
26
|
try {
|
|
10
27
|
return await response.json();
|
|
@@ -72,8 +89,10 @@ function readOptionalString(value: unknown): string | null {
|
|
|
72
89
|
return typeof value === "string" ? value : null;
|
|
73
90
|
}
|
|
74
91
|
|
|
75
|
-
export function readErrorMessage(body: unknown): string | null {
|
|
92
|
+
export function readErrorMessage(body: unknown, preferMessage = false): string | null {
|
|
76
93
|
const response = body as (ErrorResponseBody & { message?: unknown }) | null;
|
|
94
|
+
if (preferMessage)
|
|
95
|
+
return readOptionalString(response?.message) ?? readOptionalString(response?.error);
|
|
77
96
|
const error = readOptionalString(response?.error) ?? readOptionalString(response?.message);
|
|
78
97
|
return error && error.trim() !== "" ? error : null;
|
|
79
98
|
}
|
|
@@ -4,12 +4,12 @@ import type {
|
|
|
4
4
|
} from "@leitwerk-dev/protocol/http-contracts";
|
|
5
5
|
|
|
6
6
|
const NODE_WIDTH = 196;
|
|
7
|
-
const NODE_HEIGHT =
|
|
8
|
-
const LANE_LABEL_WIDTH =
|
|
9
|
-
export const INSTANCE_TREE_COLUMN_GAP =
|
|
10
|
-
const LANE_GAP =
|
|
11
|
-
const HORIZONTAL_MARGIN =
|
|
12
|
-
const VERTICAL_MARGIN =
|
|
7
|
+
const NODE_HEIGHT = 48;
|
|
8
|
+
const LANE_LABEL_WIDTH = 112;
|
|
9
|
+
export const INSTANCE_TREE_COLUMN_GAP = 128;
|
|
10
|
+
const LANE_GAP = 48;
|
|
11
|
+
const HORIZONTAL_MARGIN = 16;
|
|
12
|
+
const VERTICAL_MARGIN = 48;
|
|
13
13
|
|
|
14
14
|
export interface InstanceTreeLayoutNode extends InstanceTreeNodeSummary {
|
|
15
15
|
x: number;
|
|
@@ -18,7 +18,7 @@ export interface InstanceTreeLayoutNode extends InstanceTreeNodeSummary {
|
|
|
18
18
|
height: number;
|
|
19
19
|
lane: number;
|
|
20
20
|
startsLane: boolean;
|
|
21
|
-
contextOrigin: "fresh" | "previous" | null;
|
|
21
|
+
contextOrigin: "fresh" | "previous" | "unknown" | "not_applicable" | null;
|
|
22
22
|
childCount: number;
|
|
23
23
|
isCurrent: boolean;
|
|
24
24
|
}
|
|
@@ -94,11 +94,14 @@ export function layoutInstanceTree(
|
|
|
94
94
|
const positioned = new Map<string, InstanceTreeLayoutNode>();
|
|
95
95
|
const ranks = new Map<string, number>();
|
|
96
96
|
let nextLane = 0;
|
|
97
|
+
const visiting = new Set<string>();
|
|
97
98
|
function position(node: InstanceTreeNodeSummary): InstanceTreeLayoutNode {
|
|
98
99
|
const existing = positioned.get(node.id);
|
|
99
100
|
if (existing) return existing;
|
|
100
101
|
const parentNode = node.parentId ? byId.get(node.parentId) : undefined;
|
|
101
|
-
|
|
102
|
+
visiting.add(node.id);
|
|
103
|
+
const parent = parentNode && !visiting.has(parentNode.id) ? position(parentNode) : undefined;
|
|
104
|
+
visiting.delete(node.id);
|
|
102
105
|
const siblings = node.parentId ? (childrenByParent.get(node.parentId) ?? []) : [];
|
|
103
106
|
const startsLane = !parent || node.pathType === "leaf_branch" || siblings[0]?.id !== node.id;
|
|
104
107
|
const lane = startsLane ? nextLane++ : parent.lane;
|
|
@@ -116,7 +119,16 @@ export function layoutInstanceTree(
|
|
|
116
119
|
height: NODE_HEIGHT,
|
|
117
120
|
lane,
|
|
118
121
|
startsLane,
|
|
119
|
-
contextOrigin: startsLane
|
|
122
|
+
contextOrigin: startsLane
|
|
123
|
+
? node.origin?.conversation.state === "not_applicable"
|
|
124
|
+
? "not_applicable"
|
|
125
|
+
: parent
|
|
126
|
+
? "previous"
|
|
127
|
+
: node.origin?.conversation.state === "recorded" &&
|
|
128
|
+
node.origin.conversation.value === null
|
|
129
|
+
? "fresh"
|
|
130
|
+
: "unknown"
|
|
131
|
+
: null,
|
|
120
132
|
childCount: childrenByParent.get(node.id)?.length ?? 0,
|
|
121
133
|
isCurrent: node.id === currentLeafId,
|
|
122
134
|
};
|
|
@@ -124,6 +136,25 @@ export function layoutInstanceTree(
|
|
|
124
136
|
return result;
|
|
125
137
|
}
|
|
126
138
|
const layoutNodes = sorted.map(position);
|
|
139
|
+
// Labelled cross-lane inputs need more headroom than an ordinary context row.
|
|
140
|
+
const laneGaps = Array.from({ length: nextLane }, () => LANE_GAP);
|
|
141
|
+
for (const target of layoutNodes) {
|
|
142
|
+
const labelledInputs = edgeSummaries.filter((edge) => {
|
|
143
|
+
if (edge.targetNodeId !== target.id || (!edge.actionLabel && !edge.productLabels.length))
|
|
144
|
+
return false;
|
|
145
|
+
const source = positioned.get(edge.sourceNodeId);
|
|
146
|
+
return source && (source.lane !== target.lane || edge.productLabels.length > 0);
|
|
147
|
+
}).length;
|
|
148
|
+
if (labelledInputs)
|
|
149
|
+
laneGaps[target.lane] = Math.max(laneGaps[target.lane], labelledInputs * 60 + 12);
|
|
150
|
+
}
|
|
151
|
+
const laneOffsets: number[] = [];
|
|
152
|
+
let nextY = Math.max(VERTICAL_MARGIN, laneGaps[0]);
|
|
153
|
+
for (let lane = 0; lane < nextLane; lane++) {
|
|
154
|
+
laneOffsets[lane] = nextY + NODE_HEIGHT / 2;
|
|
155
|
+
nextY += NODE_HEIGHT + (laneGaps[lane + 1] ?? VERTICAL_MARGIN);
|
|
156
|
+
}
|
|
157
|
+
for (const node of layoutNodes) node.y = laneOffsets[node.lane];
|
|
127
158
|
const edges = edgeSummaries
|
|
128
159
|
.map((edge) => {
|
|
129
160
|
const source = positioned.get(edge.sourceNodeId);
|
|
@@ -150,7 +181,7 @@ export function layoutInstanceTree(
|
|
|
150
181
|
(maxRank + 1) * NODE_WIDTH +
|
|
151
182
|
maxRank * INSTANCE_TREE_COLUMN_GAP +
|
|
152
183
|
(edges.some((edge) => edge.endState) ? 100 : 0),
|
|
153
|
-
height:
|
|
184
|
+
height: nextY,
|
|
154
185
|
laneCount: nextLane,
|
|
155
186
|
nodes: layoutNodes,
|
|
156
187
|
edges,
|
|
@@ -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
|