@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
|
@@ -20,8 +20,9 @@ import {
|
|
|
20
20
|
type ProcessDetailData,
|
|
21
21
|
} from "./api";
|
|
22
22
|
import { upsertFutureExecutionSummary } from "./future-executions-logic.js";
|
|
23
|
-
import { applyPrimaryPathFrame } from "./primary-path-detail.js";
|
|
23
|
+
import { applyPrimaryPathFrame, isFullPrimaryPathDetailFrame } from "./primary-path-detail.js";
|
|
24
24
|
import { replayPrimaryPathFramesAfterSnapshot } from "./primary-path-replay.js";
|
|
25
|
+
import { mergeProcessHistory, mergeUniqueBy } from "./process-history.js";
|
|
25
26
|
import { buildProcessRowView, sortProcessRowViews } from "./process-row-view.js";
|
|
26
27
|
import { classifyWsEvent, createRequestGuard, type WsAction } from "./processes-logic.js";
|
|
27
28
|
|
|
@@ -53,12 +54,29 @@ export const detailState = writable({
|
|
|
53
54
|
|
|
54
55
|
const PROCESS_BROWSE_WS_REFRESH_DELAY_MS = 100;
|
|
55
56
|
|
|
57
|
+
function createReloadScheduler() {
|
|
58
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
59
|
+
return {
|
|
60
|
+
clear() {
|
|
61
|
+
if (timer) clearTimeout(timer);
|
|
62
|
+
timer = null;
|
|
63
|
+
},
|
|
64
|
+
schedule(reload: () => void, delayMs: number) {
|
|
65
|
+
this.clear();
|
|
66
|
+
timer = setTimeout(() => {
|
|
67
|
+
timer = null;
|
|
68
|
+
reload();
|
|
69
|
+
}, delayMs);
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
56
74
|
let browseActive = false;
|
|
57
75
|
let activeBrowseRequest: ProcessBrowseRequest | null = null;
|
|
58
|
-
|
|
59
|
-
|
|
76
|
+
const listReload = createReloadScheduler();
|
|
77
|
+
const browseReload = createReloadScheduler();
|
|
60
78
|
let detailInstanceId: string | null = null;
|
|
61
|
-
|
|
79
|
+
const detailReload = createReloadScheduler();
|
|
62
80
|
const pendingPrimaryPathFramesByInstanceId = new Map<
|
|
63
81
|
string,
|
|
64
82
|
Array<Extract<WsAction, { kind: "apply_primary_path_frame" }>["frame"]>
|
|
@@ -67,39 +85,41 @@ const pendingPrimaryPathFramesByInstanceId = new Map<
|
|
|
67
85
|
const listGuard = createRequestGuard();
|
|
68
86
|
const browseGuard = createRequestGuard();
|
|
69
87
|
const detailGuard = createRequestGuard();
|
|
88
|
+
const historyGuard = createRequestGuard();
|
|
89
|
+
export const historyState = writable({ loading: false, error: null as string | null });
|
|
70
90
|
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
91
|
+
export async function loadEarlierProcessHistory() {
|
|
92
|
+
const current = get(detailState).data;
|
|
93
|
+
const before = current?.timeline.history?.beforeTurnRecordId;
|
|
94
|
+
if (!current || !before || get(historyState).loading) return;
|
|
95
|
+
const generation = historyGuard.next();
|
|
96
|
+
historyState.set({ loading: true, error: null });
|
|
97
|
+
try {
|
|
98
|
+
const older = await fetchProcessDetail(current.process.id, before);
|
|
99
|
+
if (historyGuard.isStale(generation)) return;
|
|
100
|
+
detailState.update((state) =>
|
|
101
|
+
state.data?.process.id === current.process.id
|
|
102
|
+
? { ...state, data: mergeProcessHistory(state.data, older) }
|
|
103
|
+
: state,
|
|
104
|
+
);
|
|
105
|
+
historyState.set({ loading: false, error: null });
|
|
106
|
+
} catch (error) {
|
|
107
|
+
if (historyGuard.isStale(generation)) return;
|
|
108
|
+
historyState.set({
|
|
109
|
+
loading: false,
|
|
110
|
+
error: error instanceof Error ? error.message : "Couldn't load earlier steps",
|
|
111
|
+
});
|
|
82
112
|
}
|
|
83
|
-
clearTimeout(scheduledBrowseReloadTimer);
|
|
84
|
-
scheduledBrowseReloadTimer = null;
|
|
85
113
|
}
|
|
86
114
|
|
|
87
115
|
export function setProcessBrowseActive(active: boolean) {
|
|
88
116
|
browseActive = active;
|
|
89
117
|
if (!active) {
|
|
90
|
-
|
|
118
|
+
browseReload.clear();
|
|
91
119
|
activeBrowseRequest = null;
|
|
92
120
|
}
|
|
93
121
|
}
|
|
94
122
|
|
|
95
|
-
function clearScheduledDetailReload() {
|
|
96
|
-
if (!scheduledDetailReloadTimer) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
clearTimeout(scheduledDetailReloadTimer);
|
|
100
|
-
scheduledDetailReloadTimer = null;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
123
|
function clearPendingPrimaryPathFrames(instanceId?: string) {
|
|
104
124
|
if (typeof instanceId === "string") {
|
|
105
125
|
pendingPrimaryPathFramesByInstanceId.delete(instanceId);
|
|
@@ -129,17 +149,6 @@ function takePendingPrimaryPathFrames(instanceId: string) {
|
|
|
129
149
|
return queuedFrames;
|
|
130
150
|
}
|
|
131
151
|
|
|
132
|
-
function applyPrimaryPathFrameToDetailData(
|
|
133
|
-
data: ProcessDetailData,
|
|
134
|
-
action: Extract<WsAction, { kind: "apply_primary_path_frame" }>,
|
|
135
|
-
): ProcessDetailData {
|
|
136
|
-
const nextData = {
|
|
137
|
-
...data,
|
|
138
|
-
primaryPath: applyPrimaryPathFrame(data.primaryPath, action.frame),
|
|
139
|
-
};
|
|
140
|
-
return nextData;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
152
|
export function setCurrentDetailInstanceId(instanceId: string | null) {
|
|
144
153
|
if (detailInstanceId === instanceId) {
|
|
145
154
|
return;
|
|
@@ -149,7 +158,7 @@ export function setCurrentDetailInstanceId(instanceId: string | null) {
|
|
|
149
158
|
}
|
|
150
159
|
detailInstanceId = instanceId;
|
|
151
160
|
if (!instanceId) {
|
|
152
|
-
|
|
161
|
+
detailReload.clear();
|
|
153
162
|
}
|
|
154
163
|
}
|
|
155
164
|
|
|
@@ -183,20 +192,12 @@ export async function loadProcessesList() {
|
|
|
183
192
|
}
|
|
184
193
|
}
|
|
185
194
|
|
|
186
|
-
function mergeUniqueBy<T>(
|
|
187
|
-
items: readonly T[],
|
|
188
|
-
incoming: readonly T[],
|
|
189
|
-
key: (item: T) => string,
|
|
190
|
-
): T[] {
|
|
191
|
-
return [...new Map([...items, ...incoming].map((item) => [key(item), item])).values()];
|
|
192
|
-
}
|
|
193
|
-
|
|
194
195
|
export async function loadProcessBrowse(
|
|
195
196
|
request: ProcessBrowseRequest = {},
|
|
196
197
|
options: { append?: boolean } = {},
|
|
197
198
|
) {
|
|
198
199
|
if (!options.append) {
|
|
199
|
-
|
|
200
|
+
browseReload.clear();
|
|
200
201
|
activeBrowseRequest = { ...request };
|
|
201
202
|
delete activeBrowseRequest.offset;
|
|
202
203
|
}
|
|
@@ -234,21 +235,14 @@ export async function loadProcessBrowse(
|
|
|
234
235
|
}
|
|
235
236
|
|
|
236
237
|
function scheduleActiveProcessBrowseReload(delayMs = PROCESS_BROWSE_WS_REFRESH_DELAY_MS) {
|
|
237
|
-
if (!browseActive || !activeBrowseRequest)
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
clearScheduledBrowseReload();
|
|
241
|
-
scheduledBrowseReloadTimer = setTimeout(() => {
|
|
242
|
-
scheduledBrowseReloadTimer = null;
|
|
243
|
-
if (!browseActive || !activeBrowseRequest) {
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
void loadProcessBrowse(activeBrowseRequest);
|
|
238
|
+
if (!browseActive || !activeBrowseRequest) return;
|
|
239
|
+
browseReload.schedule(() => {
|
|
240
|
+
if (browseActive && activeBrowseRequest) void loadProcessBrowse(activeBrowseRequest);
|
|
247
241
|
}, delayMs);
|
|
248
242
|
}
|
|
249
243
|
|
|
250
244
|
export async function loadProcessDetail(instanceId: string) {
|
|
251
|
-
|
|
245
|
+
detailReload.clear();
|
|
252
246
|
const gen = detailGuard.next();
|
|
253
247
|
setCurrentDetailInstanceId(instanceId);
|
|
254
248
|
detailState.update((state) => ({ ...state, loading: true, error: null }));
|
|
@@ -256,13 +250,20 @@ export async function loadProcessDetail(instanceId: string) {
|
|
|
256
250
|
const result = await fetchProcessDetail(instanceId);
|
|
257
251
|
if (detailGuard.isStale(gen)) return;
|
|
258
252
|
const loadedAtMs = Date.now();
|
|
253
|
+
const previous = get(detailState).data;
|
|
254
|
+
const retained =
|
|
255
|
+
previous?.process.id === instanceId &&
|
|
256
|
+
previous.timeline.history &&
|
|
257
|
+
previous.timeline.turns.some((turn) => turn.id === result.timeline.turns[0]?.id)
|
|
258
|
+
? mergeProcessHistory(result, previous)
|
|
259
|
+
: result;
|
|
259
260
|
const replayedPrimaryPath = replayPrimaryPathFramesAfterSnapshot(
|
|
260
261
|
result.primaryPath,
|
|
261
262
|
takePendingPrimaryPathFrames(instanceId),
|
|
262
263
|
);
|
|
263
264
|
detailState.set({
|
|
264
265
|
data: {
|
|
265
|
-
...
|
|
266
|
+
...retained,
|
|
266
267
|
primaryPath: replayedPrimaryPath,
|
|
267
268
|
},
|
|
268
269
|
loading: false,
|
|
@@ -280,20 +281,16 @@ export async function loadProcessDetail(instanceId: string) {
|
|
|
280
281
|
}
|
|
281
282
|
|
|
282
283
|
function scheduleLoadProcessDetail(instanceId: string, delayMs = 120) {
|
|
283
|
-
if (detailInstanceId
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
clearScheduledDetailReload();
|
|
287
|
-
scheduledDetailReloadTimer = setTimeout(() => {
|
|
288
|
-
scheduledDetailReloadTimer = null;
|
|
289
|
-
void loadProcessDetail(instanceId);
|
|
290
|
-
}, delayMs);
|
|
284
|
+
if (detailInstanceId === instanceId)
|
|
285
|
+
detailReload.schedule(() => void loadProcessDetail(instanceId), delayMs);
|
|
291
286
|
}
|
|
292
287
|
|
|
293
288
|
export function clearDetail() {
|
|
289
|
+
historyGuard.invalidate();
|
|
290
|
+
historyState.set({ loading: false, error: null });
|
|
294
291
|
setCurrentDetailInstanceId(null);
|
|
295
292
|
clearPendingPrimaryPathFrames();
|
|
296
|
-
|
|
293
|
+
detailReload.clear();
|
|
297
294
|
detailState.set({
|
|
298
295
|
data: null,
|
|
299
296
|
loading: false,
|
|
@@ -313,22 +310,17 @@ export function subscribeReasoningFrames(listener: (frame: WsFrame) => void) {
|
|
|
313
310
|
|
|
314
311
|
function executePrimaryPathFrame(action: WsAction & { kind: "apply_primary_path_frame" }) {
|
|
315
312
|
const current = get(detailState);
|
|
316
|
-
if (
|
|
317
|
-
[
|
|
318
|
-
WS_PRIMARY_PATH_TYPES.ASSISTANT_PARTIAL,
|
|
319
|
-
WS_PRIMARY_PATH_TYPES.USAGE_UPDATED,
|
|
320
|
-
WS_PRIMARY_PATH_TYPES.TOOL_CALL_STARTED,
|
|
321
|
-
WS_PRIMARY_PATH_TYPES.TOOL_CALL_COMPLETED,
|
|
322
|
-
].includes(action.frame.type as typeof WS_PRIMARY_PATH_TYPES.ASSISTANT_PARTIAL)
|
|
323
|
-
)
|
|
324
|
-
return;
|
|
313
|
+
if (isFullPrimaryPathDetailFrame(action.frame)) return;
|
|
325
314
|
if (detailInstanceId === action.instanceId && current.loading) bufferPrimaryPathFrame(action);
|
|
326
315
|
if (current.data?.process.id !== action.instanceId) {
|
|
327
316
|
return;
|
|
328
317
|
}
|
|
329
318
|
detailState.set({
|
|
330
319
|
...current,
|
|
331
|
-
data:
|
|
320
|
+
data: {
|
|
321
|
+
...current.data,
|
|
322
|
+
primaryPath: applyPrimaryPathFrame(current.data.primaryPath, action.frame),
|
|
323
|
+
},
|
|
332
324
|
});
|
|
333
325
|
}
|
|
334
326
|
|
|
@@ -339,7 +331,7 @@ export function handleWsEvent(frame: WsFrame) {
|
|
|
339
331
|
for (const action of actions) {
|
|
340
332
|
switch (action.kind) {
|
|
341
333
|
case "reload_list":
|
|
342
|
-
|
|
334
|
+
listReload.schedule(() => void loadProcessesList(), PROCESS_BROWSE_WS_REFRESH_DELAY_MS);
|
|
343
335
|
break;
|
|
344
336
|
case "refresh_active_browse":
|
|
345
337
|
scheduleActiveProcessBrowseReload();
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { ProcessEvent } from "@leitwerk-dev/domain";
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
snapshotTurnTrace,
|
|
3
|
+
createLiveTurnProjection,
|
|
4
|
+
restoreTurnTraceProjection,
|
|
5
5
|
type TurnReasoningDetailResponseBody,
|
|
6
|
-
type
|
|
6
|
+
type TurnTraceProjection,
|
|
7
7
|
type WsFrame,
|
|
8
8
|
} from "@leitwerk-dev/protocol";
|
|
9
9
|
|
|
@@ -23,12 +23,12 @@ const PI_EVENT_TYPES: Record<string, string> = {
|
|
|
23
23
|
|
|
24
24
|
/** Owns expanded history only. HTTP recovery replaces its base, then replays later frames once. */
|
|
25
25
|
export class ReasoningHistory {
|
|
26
|
-
private
|
|
26
|
+
private inspectionEvents = new Map<number, ProcessEvent>();
|
|
27
|
+
private projection: TurnTraceProjection = createLiveTurnProjection();
|
|
27
28
|
private boundary = 0;
|
|
28
29
|
private buffered = new Map<number, WsFrame>();
|
|
29
30
|
private pending = false;
|
|
30
31
|
private committed = false;
|
|
31
|
-
private piInput: TurnTraceSnapshot["piInput"] = null;
|
|
32
32
|
constructor(
|
|
33
33
|
readonly instanceId: string,
|
|
34
34
|
readonly turnRecordId: string,
|
|
@@ -41,21 +41,16 @@ export class ReasoningHistory {
|
|
|
41
41
|
this.pending = false;
|
|
42
42
|
this.buffered.clear();
|
|
43
43
|
}
|
|
44
|
-
accept(response: TurnReasoningDetailResponseBody
|
|
44
|
+
accept(response: TurnReasoningDetailResponseBody & { events?: ProcessEvent[] }) {
|
|
45
45
|
if (response.instanceId !== this.instanceId || response.turnRecordId !== this.turnRecordId)
|
|
46
46
|
throw new Error("Reasoning response belongs to another turn");
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.projection.toolCallsById = new Map(
|
|
55
|
-
this.projection.toolCalls.map((tool) => [tool.toolCallId, tool]),
|
|
56
|
-
);
|
|
57
|
-
this.projection.usage = response.reasoning.usage;
|
|
58
|
-
this.piInput = response.reasoning.piInput;
|
|
47
|
+
if (response.events)
|
|
48
|
+
this.inspectionEvents = new Map(
|
|
49
|
+
response.events.flatMap((event) =>
|
|
50
|
+
event.eventSequence === undefined ? [] : [[event.eventSequence, event]],
|
|
51
|
+
),
|
|
52
|
+
);
|
|
53
|
+
this.projection = restoreTurnTraceProjection(response.reasoning);
|
|
59
54
|
this.boundary = response.throughEventSequence;
|
|
60
55
|
this.committed = response.state === "committed";
|
|
61
56
|
this.pending = false;
|
|
@@ -66,7 +61,7 @@ export class ReasoningHistory {
|
|
|
66
61
|
this.buffered.clear();
|
|
67
62
|
return this.snapshot();
|
|
68
63
|
}
|
|
69
|
-
push(frame: WsFrame):
|
|
64
|
+
push(frame: WsFrame): ReturnType<ReasoningHistory["snapshot"]> | null {
|
|
70
65
|
if (
|
|
71
66
|
frame.instanceId !== this.instanceId ||
|
|
72
67
|
!("turnRecordId" in frame.payload) ||
|
|
@@ -81,7 +76,15 @@ export class ReasoningHistory {
|
|
|
81
76
|
private apply(frame: WsFrame): boolean {
|
|
82
77
|
if (this.committed || frame.eventSequence === undefined || frame.eventSequence <= this.boundary)
|
|
83
78
|
return false;
|
|
84
|
-
|
|
79
|
+
this.inspectionEvents.set(frame.eventSequence, {
|
|
80
|
+
id: `event:${frame.eventSequence}`,
|
|
81
|
+
instanceId: this.instanceId,
|
|
82
|
+
eventSequence: frame.eventSequence,
|
|
83
|
+
eventType: PI_EVENT_TYPES[frame.type],
|
|
84
|
+
data: frame.payload as Record<string, unknown>,
|
|
85
|
+
createdAt: frame.sentAt,
|
|
86
|
+
});
|
|
87
|
+
this.projection.apply({
|
|
85
88
|
eventType: PI_EVENT_TYPES[frame.type],
|
|
86
89
|
data: frame.payload as Record<string, unknown>,
|
|
87
90
|
fallbackTimestamp: frame.sentAt,
|
|
@@ -89,7 +92,12 @@ export class ReasoningHistory {
|
|
|
89
92
|
this.boundary = frame.eventSequence;
|
|
90
93
|
return true;
|
|
91
94
|
}
|
|
92
|
-
snapshot()
|
|
93
|
-
return
|
|
95
|
+
snapshot() {
|
|
96
|
+
return {
|
|
97
|
+
...this.projection.snapshot(),
|
|
98
|
+
events: [...this.inspectionEvents.values()].sort(
|
|
99
|
+
(a, b) => (a.eventSequence ?? 0) - (b.eventSequence ?? 0),
|
|
100
|
+
),
|
|
101
|
+
};
|
|
94
102
|
}
|
|
95
103
|
}
|
package/src/lib/router-logic.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export type Page =
|
|
2
|
+
| "wiki"
|
|
3
|
+
| "settings"
|
|
2
4
|
| "api-tokens"
|
|
5
|
+
| "dashboard"
|
|
3
6
|
| "home"
|
|
4
7
|
| "processes"
|
|
5
8
|
| "process-detail"
|
|
@@ -12,32 +15,12 @@ export interface Route {
|
|
|
12
15
|
params: Record<string, string>;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
|
-
export type ProcessDetailOverlayState =
|
|
16
|
-
| { kind: "none" }
|
|
17
|
-
| { kind: "process-info" }
|
|
18
|
-
| { kind: "reasoning"; turnRecordId: string | null };
|
|
19
|
-
|
|
20
|
-
export interface ProcessPathOptions {
|
|
21
|
-
overlay?: "process-info" | "reasoning" | null;
|
|
22
|
-
turnRecordId?: string | null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
18
|
function stripSearchAndHash(path: string): string {
|
|
26
|
-
|
|
27
|
-
const hashIndex = path.indexOf("#");
|
|
28
|
-
const endIndexes = [searchIndex, hashIndex].filter((index) => index >= 0);
|
|
29
|
-
const endIndex = endIndexes.length > 0 ? Math.min(...endIndexes) : path.length;
|
|
30
|
-
return path.slice(0, endIndex);
|
|
19
|
+
return path.split(/[?#]/, 1)[0];
|
|
31
20
|
}
|
|
32
21
|
|
|
33
22
|
function readSearchParams(path: string): URLSearchParams {
|
|
34
|
-
|
|
35
|
-
if (searchIndex < 0) {
|
|
36
|
-
return new URLSearchParams();
|
|
37
|
-
}
|
|
38
|
-
const hashIndex = path.indexOf("#", searchIndex);
|
|
39
|
-
const search = path.slice(searchIndex + 1, hashIndex >= 0 ? hashIndex : path.length);
|
|
40
|
-
return new URLSearchParams(search);
|
|
23
|
+
return new URL(path, "http://localhost").searchParams;
|
|
41
24
|
}
|
|
42
25
|
|
|
43
26
|
function decodeFirstSegment(pathname: string, prefix: string): string {
|
|
@@ -45,13 +28,17 @@ function decodeFirstSegment(pathname: string, prefix: string): string {
|
|
|
45
28
|
return segment ? decodeURIComponent(segment) : "";
|
|
46
29
|
}
|
|
47
30
|
|
|
48
|
-
export function buildHomePath(
|
|
31
|
+
export function buildHomePath(): string {
|
|
32
|
+
return "/";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function buildCreateProcessPath(launcherId?: string | null): string {
|
|
49
36
|
if (!launcherId) {
|
|
50
|
-
return "/";
|
|
37
|
+
return "/processes/new";
|
|
51
38
|
}
|
|
52
39
|
const params = new URLSearchParams();
|
|
53
40
|
params.set("launcher", launcherId);
|
|
54
|
-
return
|
|
41
|
+
return `/processes/new?${params.toString()}`;
|
|
55
42
|
}
|
|
56
43
|
|
|
57
44
|
export function buildFutureLaunchPath(futureExecutionId: string): string {
|
|
@@ -62,19 +49,8 @@ export function buildProcessesPath(): string {
|
|
|
62
49
|
return "/processes";
|
|
63
50
|
}
|
|
64
51
|
|
|
65
|
-
export function buildProcessPath(instanceId: string
|
|
66
|
-
|
|
67
|
-
const params = new URLSearchParams();
|
|
68
|
-
if (options.overlay === "process-info") {
|
|
69
|
-
params.set("overlay", "process-info");
|
|
70
|
-
} else if (options.overlay === "reasoning") {
|
|
71
|
-
params.set("overlay", "reasoning");
|
|
72
|
-
if (options.turnRecordId) {
|
|
73
|
-
params.set("turnRecordId", options.turnRecordId);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
const query = params.toString();
|
|
77
|
-
return query ? `${path}?${query}` : path;
|
|
52
|
+
export function buildProcessPath(instanceId: string): string {
|
|
53
|
+
return `/processes/${encodeURIComponent(instanceId)}`;
|
|
78
54
|
}
|
|
79
55
|
|
|
80
56
|
export function buildWatchersPath(): string {
|
|
@@ -93,25 +69,12 @@ export function buildInstalledSkillPath(skillId: string): string {
|
|
|
93
69
|
return `/skills/installed/${encodeURIComponent(skillId)}`;
|
|
94
70
|
}
|
|
95
71
|
|
|
96
|
-
export function readProcessDetailOverlay(path: string): ProcessDetailOverlayState {
|
|
97
|
-
const params = readSearchParams(path);
|
|
98
|
-
const overlay = params.get("overlay");
|
|
99
|
-
if (overlay === "process-info") {
|
|
100
|
-
return { kind: "process-info" };
|
|
101
|
-
}
|
|
102
|
-
if (overlay === "reasoning") {
|
|
103
|
-
return { kind: "reasoning", turnRecordId: params.get("turnRecordId") };
|
|
104
|
-
}
|
|
105
|
-
return { kind: "none" };
|
|
106
|
-
}
|
|
107
|
-
|
|
108
72
|
function matchPrefixedDetailRoute(
|
|
109
|
-
|
|
73
|
+
pathname: string,
|
|
110
74
|
prefix: string,
|
|
111
75
|
page: "process-detail" | "future-launch-detail",
|
|
112
76
|
paramName: "instanceId" | "futureExecutionId",
|
|
113
77
|
): Route | null {
|
|
114
|
-
const pathname = stripSearchAndHash(pathnameWithSearch);
|
|
115
78
|
if (!pathname.startsWith(prefix)) {
|
|
116
79
|
return null;
|
|
117
80
|
}
|
|
@@ -126,10 +89,23 @@ function matchPrefixedDetailRoute(
|
|
|
126
89
|
|
|
127
90
|
export function matchRoute(pathnameWithSearch: string): Route {
|
|
128
91
|
const pathname = stripSearchAndHash(pathnameWithSearch);
|
|
92
|
+
if (pathname === "/wiki" || pathname.startsWith("/wiki/")) {
|
|
93
|
+
const segments = pathname.split("/").filter(Boolean).slice(1).map(decodeURIComponent);
|
|
94
|
+
return { page: "wiki", params: { topicId: segments[0] ?? "", pageId: segments[1] ?? "" } };
|
|
95
|
+
}
|
|
96
|
+
if (pathname === "/settings" || pathname === "/settings/")
|
|
97
|
+
return {
|
|
98
|
+
page: "settings",
|
|
99
|
+
params: { scope: readSearchParams(pathnameWithSearch).get("scope") ?? "instance" },
|
|
100
|
+
};
|
|
129
101
|
if (pathname === "/account/api-tokens" || pathname === "/account/api-tokens/")
|
|
130
102
|
return { page: "api-tokens", params: {} };
|
|
103
|
+
if (pathname === "/processes/new" || pathname === "/processes/new/") {
|
|
104
|
+
const launcher = readSearchParams(pathnameWithSearch).get("launcher");
|
|
105
|
+
return { page: "home", params: launcher ? { launcher } : {} };
|
|
106
|
+
}
|
|
131
107
|
const processDetailRoute = matchPrefixedDetailRoute(
|
|
132
|
-
|
|
108
|
+
pathname,
|
|
133
109
|
"/processes/",
|
|
134
110
|
"process-detail",
|
|
135
111
|
"instanceId",
|
|
@@ -139,7 +115,7 @@ export function matchRoute(pathnameWithSearch: string): Route {
|
|
|
139
115
|
}
|
|
140
116
|
|
|
141
117
|
const futureLaunchDetailRoute = matchPrefixedDetailRoute(
|
|
142
|
-
|
|
118
|
+
pathname,
|
|
143
119
|
"/future-launches/",
|
|
144
120
|
"future-launch-detail",
|
|
145
121
|
"futureExecutionId",
|
|
@@ -186,8 +162,103 @@ export function matchRoute(pathnameWithSearch: string): Route {
|
|
|
186
162
|
|
|
187
163
|
if (pathname === "/" || pathname === "/config" || pathname === "/system") {
|
|
188
164
|
const launcher = readSearchParams(pathnameWithSearch).get("launcher");
|
|
189
|
-
return launcher
|
|
165
|
+
return launcher || pathname !== "/"
|
|
166
|
+
? { page: "home", params: launcher ? { launcher } : {} }
|
|
167
|
+
: { page: "dashboard", params: {} };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return { page: "dashboard", params: {} };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** @internal */
|
|
174
|
+
export const inspectorProcessSections = [
|
|
175
|
+
["overview", "Overview"],
|
|
176
|
+
["workflow", "Workflow"],
|
|
177
|
+
["inputs", "Inputs & configuration"],
|
|
178
|
+
["context-map", "Context map"],
|
|
179
|
+
] as const;
|
|
180
|
+
/** @internal */
|
|
181
|
+
export const inspectorExecutionSections = [
|
|
182
|
+
["trace", "Trace"],
|
|
183
|
+
["context", "Context"],
|
|
184
|
+
["configuration", "Configuration"],
|
|
185
|
+
] as const;
|
|
186
|
+
export type InspectorProcessSection = (typeof inspectorProcessSections)[number][0];
|
|
187
|
+
export type InspectorExecutionSection = (typeof inspectorExecutionSections)[number][0];
|
|
188
|
+
export type InspectorTarget =
|
|
189
|
+
| { scope: "process"; section: InspectorProcessSection; turnRecordId?: string }
|
|
190
|
+
| { scope: "step"; turnId: string }
|
|
191
|
+
| {
|
|
192
|
+
scope: "execution";
|
|
193
|
+
turnRecordId: string;
|
|
194
|
+
section: InspectorExecutionSection;
|
|
195
|
+
entryId?: string;
|
|
196
|
+
itemId?: string;
|
|
197
|
+
boundaryFor?: string;
|
|
198
|
+
};
|
|
199
|
+
export type InspectorRoute = InspectorTarget | { scope: "invalid"; reason: string } | null;
|
|
200
|
+
|
|
201
|
+
export function buildInspectorPath(instanceId: string, target: InspectorTarget): string {
|
|
202
|
+
const params = new URLSearchParams({ inspect: target.scope });
|
|
203
|
+
if (target.scope === "step") params.set("turnId", target.turnId);
|
|
204
|
+
else {
|
|
205
|
+
params.set("section", target.section);
|
|
206
|
+
if (target.turnRecordId) params.set("turnRecordId", target.turnRecordId);
|
|
207
|
+
if (target.scope === "execution") {
|
|
208
|
+
if (target.entryId) params.set("entryId", target.entryId);
|
|
209
|
+
if (target.itemId) params.set("itemId", target.itemId);
|
|
210
|
+
if (target.boundaryFor) params.set("boundaryFor", target.boundaryFor);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return `${buildProcessPath(instanceId)}?${params}`;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function readInspectorTarget(path: string): InspectorRoute {
|
|
217
|
+
const params = readSearchParams(path);
|
|
218
|
+
let scope = params.get("inspect");
|
|
219
|
+
if (!scope && params.get("overlay") === "process-info") scope = "process";
|
|
220
|
+
if (!scope && params.get("overlay") === "reasoning") scope = "execution";
|
|
221
|
+
if (!scope) return null;
|
|
222
|
+
const invalid = {
|
|
223
|
+
scope: "invalid",
|
|
224
|
+
reason: "This inspector link has a missing or unsupported target.",
|
|
225
|
+
} as const;
|
|
226
|
+
const section = params.get("section");
|
|
227
|
+
const turnRecordId = params.get("turnRecordId") || undefined;
|
|
228
|
+
if (scope === "step") {
|
|
229
|
+
const turnId = params.get("turnId");
|
|
230
|
+
return turnId ? { scope, turnId } : invalid;
|
|
231
|
+
}
|
|
232
|
+
if (scope === "process") {
|
|
233
|
+
if (section && !inspectorProcessSections.some(([id]) => id === section)) return invalid;
|
|
234
|
+
return {
|
|
235
|
+
scope,
|
|
236
|
+
section: (section ?? "overview") as InspectorProcessSection,
|
|
237
|
+
...(turnRecordId ? { turnRecordId } : {}),
|
|
238
|
+
};
|
|
190
239
|
}
|
|
240
|
+
if (scope === "execution" && turnRecordId) {
|
|
241
|
+
if (section && !inspectorExecutionSections.some(([id]) => id === section)) return invalid;
|
|
242
|
+
const target: InspectorTarget = {
|
|
243
|
+
scope,
|
|
244
|
+
turnRecordId,
|
|
245
|
+
section: (section ?? "trace") as InspectorExecutionSection,
|
|
246
|
+
};
|
|
247
|
+
for (const key of ["entryId", "itemId", "boundaryFor"] as const) {
|
|
248
|
+
const value = params.get(key);
|
|
249
|
+
if (value) target[key] = value;
|
|
250
|
+
}
|
|
251
|
+
return target;
|
|
252
|
+
}
|
|
253
|
+
return invalid;
|
|
254
|
+
}
|
|
191
255
|
|
|
192
|
-
|
|
256
|
+
/** @internal */
|
|
257
|
+
export function canonicalizeRoutePath(path: string): string {
|
|
258
|
+
const pathname = stripSearchAndHash(path);
|
|
259
|
+
const launcher = readSearchParams(path).get("launcher");
|
|
260
|
+
if (pathname === "/config" || pathname === "/system" || (pathname === "/" && launcher)) {
|
|
261
|
+
return buildCreateProcessPath(launcher);
|
|
262
|
+
}
|
|
263
|
+
return path;
|
|
193
264
|
}
|
package/src/lib/router.svelte.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export type { Page,
|
|
1
|
+
export type { Page, Route } from "./router-logic.js";
|
|
2
2
|
export {
|
|
3
3
|
buildAvailableSkillPath,
|
|
4
|
+
buildCreateProcessPath,
|
|
4
5
|
buildFutureLaunchPath,
|
|
5
6
|
buildHomePath,
|
|
6
7
|
buildInstalledSkillPath,
|
|
@@ -9,18 +10,21 @@ export {
|
|
|
9
10
|
buildSkillsPath,
|
|
10
11
|
buildWatchersPath,
|
|
11
12
|
matchRoute,
|
|
12
|
-
readProcessDetailOverlay,
|
|
13
13
|
} from "./router-logic.js";
|
|
14
14
|
|
|
15
15
|
import { derived, writable } from "svelte/store";
|
|
16
|
-
import { matchRoute } from "./router-logic.js";
|
|
16
|
+
import { canonicalizeRoutePath, matchRoute } from "./router-logic.js";
|
|
17
17
|
|
|
18
18
|
interface NavigateOptions {
|
|
19
19
|
replace?: boolean;
|
|
20
|
+
state?: unknown;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
function readCurrentLocationPath(): string {
|
|
23
|
-
|
|
24
|
+
const path = `${window.location.pathname}${window.location.search}${window.location.hash}`;
|
|
25
|
+
const canonical = canonicalizeRoutePath(path);
|
|
26
|
+
if (canonical !== path) history.replaceState(history.state, "", canonical);
|
|
27
|
+
return canonical;
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
const currentLocationPath = writable(readCurrentLocationPath());
|
|
@@ -44,9 +48,9 @@ export function followLink(event: MouseEvent, to: string): void {
|
|
|
44
48
|
|
|
45
49
|
export function navigate(to: string, options: NavigateOptions = {}) {
|
|
46
50
|
if (options.replace) {
|
|
47
|
-
history.replaceState(null, "", to);
|
|
51
|
+
history.replaceState(options.state ?? null, "", to);
|
|
48
52
|
} else {
|
|
49
|
-
history.pushState(null, "", to);
|
|
53
|
+
history.pushState(options.state ?? null, "", to);
|
|
50
54
|
}
|
|
51
55
|
currentLocationPath.set(readCurrentLocationPath());
|
|
52
56
|
}
|