@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
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
LauncherFieldDefinition,
|
|
3
|
+
LauncherFieldOptionDefinition,
|
|
4
|
+
} from "@leitwerk-dev/protocol/launcher-contract";
|
|
5
|
+
|
|
6
|
+
type Values = Record<string, string | boolean>;
|
|
7
|
+
type Options = Record<string, readonly LauncherFieldOptionDefinition[]>;
|
|
8
|
+
|
|
9
|
+
interface SelectionOverride {
|
|
10
|
+
initialValue?: string;
|
|
11
|
+
included: string[];
|
|
12
|
+
excluded: string[];
|
|
13
|
+
/** Retain known membership if a selected preset becomes unavailable. */
|
|
14
|
+
members: Record<string, readonly string[]>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type LauncherSelections = Record<string, SelectionOverride>;
|
|
18
|
+
|
|
19
|
+
export const selectionValues = (value: unknown): string[] =>
|
|
20
|
+
typeof value === "string" ? [...new Set(value.split("\n").filter(Boolean))] : [];
|
|
21
|
+
|
|
22
|
+
export function initializeLauncherSelections(
|
|
23
|
+
fields: readonly LauncherFieldDefinition[],
|
|
24
|
+
input: Record<string, unknown>,
|
|
25
|
+
): LauncherSelections {
|
|
26
|
+
return Object.fromEntries(
|
|
27
|
+
fields
|
|
28
|
+
.filter((field) => field.multiple && field.presetsFrom)
|
|
29
|
+
.map((field) => [
|
|
30
|
+
field.id,
|
|
31
|
+
{
|
|
32
|
+
initialValue: typeof input[field.id] === "string" ? input[field.id] : undefined,
|
|
33
|
+
included: [],
|
|
34
|
+
excluded: [],
|
|
35
|
+
members: {},
|
|
36
|
+
},
|
|
37
|
+
]),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function reconcileLauncherSelections(
|
|
42
|
+
fields: readonly LauncherFieldDefinition[],
|
|
43
|
+
values: Values,
|
|
44
|
+
options: Options,
|
|
45
|
+
selections: LauncherSelections,
|
|
46
|
+
): { values: Values; selections: LauncherSelections } {
|
|
47
|
+
const nextValues = { ...values };
|
|
48
|
+
const nextSelections = { ...selections };
|
|
49
|
+
for (const field of fields) {
|
|
50
|
+
if (!field.presetsFrom || !field.multiple) continue;
|
|
51
|
+
const presetOptions =
|
|
52
|
+
options[field.presetsFrom] ??
|
|
53
|
+
fields.find((source) => source.id === field.presetsFrom)?.options;
|
|
54
|
+
if (!presetOptions) continue;
|
|
55
|
+
const previous = selections[field.id];
|
|
56
|
+
if (!previous) continue;
|
|
57
|
+
const members = { ...previous.members };
|
|
58
|
+
for (const option of presetOptions) members[option.value] = option.selectionValues ?? [];
|
|
59
|
+
const preset = new Set(
|
|
60
|
+
selectionValues(values[field.presetsFrom]).flatMap((id) => members[id] ?? []),
|
|
61
|
+
);
|
|
62
|
+
const initial =
|
|
63
|
+
previous.initialValue === undefined ? null : selectionValues(previous.initialValue);
|
|
64
|
+
const included = initial ? initial.filter((id) => !preset.has(id)) : previous.included;
|
|
65
|
+
const excluded = initial
|
|
66
|
+
? [...preset].filter((id) => !initial.includes(id))
|
|
67
|
+
: previous.excluded;
|
|
68
|
+
nextValues[field.id] = [...new Set([...preset, ...included])]
|
|
69
|
+
.filter((id) => !excluded.includes(id))
|
|
70
|
+
.join("\n");
|
|
71
|
+
nextSelections[field.id] = { included, excluded, members };
|
|
72
|
+
}
|
|
73
|
+
return { values: nextValues, selections: nextSelections };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function changeLauncherSelection(
|
|
77
|
+
fields: readonly LauncherFieldDefinition[],
|
|
78
|
+
values: Values,
|
|
79
|
+
options: Options,
|
|
80
|
+
selections: LauncherSelections,
|
|
81
|
+
fieldId: string,
|
|
82
|
+
value: string | boolean,
|
|
83
|
+
): { values: Values; selections: LauncherSelections; resetFields: string[] } {
|
|
84
|
+
const nextValues = { ...values, [fieldId]: value };
|
|
85
|
+
const nextSelections = { ...selections };
|
|
86
|
+
const previous = selections[fieldId];
|
|
87
|
+
if (previous) {
|
|
88
|
+
const before = selectionValues(values[fieldId]);
|
|
89
|
+
const after = selectionValues(value);
|
|
90
|
+
const added = after.filter((id) => !before.includes(id));
|
|
91
|
+
const removed = before.filter((id) => !after.includes(id));
|
|
92
|
+
nextSelections[fieldId] = {
|
|
93
|
+
...previous,
|
|
94
|
+
...(previous.initialValue === undefined ? {} : { initialValue: String(value) }),
|
|
95
|
+
included: [...new Set([...previous.included, ...added])].filter(
|
|
96
|
+
(id) => !removed.includes(id),
|
|
97
|
+
),
|
|
98
|
+
excluded: [...new Set([...previous.excluded, ...removed])].filter(
|
|
99
|
+
(id) => !added.includes(id),
|
|
100
|
+
),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const changed = new Set(values[fieldId] === value ? [] : [fieldId]);
|
|
104
|
+
const resetFields: string[] = [];
|
|
105
|
+
for (let size = -1; size !== changed.size; ) {
|
|
106
|
+
size = changed.size;
|
|
107
|
+
for (const field of fields) {
|
|
108
|
+
if (changed.has(field.id) || !field.resetOn?.some((id) => changed.has(id))) continue;
|
|
109
|
+
changed.add(field.id);
|
|
110
|
+
resetFields.push(field.id);
|
|
111
|
+
nextValues[field.id] = field.kind === "boolean" ? false : "";
|
|
112
|
+
if (nextSelections[field.id])
|
|
113
|
+
nextSelections[field.id] = { included: [], excluded: [], members: {} };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const nextOptions = Object.fromEntries(
|
|
117
|
+
Object.entries(options).filter(([id]) => !resetFields.includes(id)),
|
|
118
|
+
);
|
|
119
|
+
return {
|
|
120
|
+
...reconcileLauncherSelections(fields, nextValues, nextOptions, nextSelections),
|
|
121
|
+
resetFields,
|
|
122
|
+
};
|
|
123
|
+
}
|
package/src/lib/api.ts
CHANGED
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
import type {
|
|
16
16
|
AuthMeResponseBody,
|
|
17
17
|
CronPreviewResponseBody,
|
|
18
|
+
DashboardResponseBody,
|
|
18
19
|
FutureExecutionSummary as FullFutureExecutionSummary,
|
|
19
20
|
FutureExecutionDetailResponseBody,
|
|
20
21
|
FutureExecutionOverviewItem,
|
|
@@ -30,6 +31,7 @@ import type {
|
|
|
30
31
|
LauncherOptionsResponseBody,
|
|
31
32
|
LauncherRecentValuesResponseBody,
|
|
32
33
|
LaunchersResponseBody,
|
|
34
|
+
LauncherValidationResponseBody,
|
|
33
35
|
LaunchRunResponseBody,
|
|
34
36
|
ModelProviderOptionsResponseBody,
|
|
35
37
|
PrimaryPathSnapshotResponseBody,
|
|
@@ -41,6 +43,8 @@ import type {
|
|
|
41
43
|
ProcessDiagnosticsResponseBody,
|
|
42
44
|
ProcessesOverviewResponseBody,
|
|
43
45
|
ProcessLaunchRunsResponseBody,
|
|
46
|
+
ProcessModelConfigPatch,
|
|
47
|
+
ProcessModelConfigResponseBody,
|
|
44
48
|
ProcessOverviewItem,
|
|
45
49
|
ProcessRetryConfig,
|
|
46
50
|
ProcessRetryConfigResponseBody,
|
|
@@ -52,7 +56,6 @@ import type {
|
|
|
52
56
|
SkillCatalogDetailResponseBody,
|
|
53
57
|
SkillsCatalogResponseBody,
|
|
54
58
|
StartLaunchRunResponseBody,
|
|
55
|
-
TurnReasoningDetailResponseBody,
|
|
56
59
|
UiLauncherSummary,
|
|
57
60
|
WatcherSummary,
|
|
58
61
|
WatchersResponseBody,
|
|
@@ -64,6 +67,8 @@ import type {
|
|
|
64
67
|
import * as v from "valibot";
|
|
65
68
|
import { formatDefinition } from "./format.js";
|
|
66
69
|
import {
|
|
70
|
+
ApiResponseError,
|
|
71
|
+
apiResponseError,
|
|
67
72
|
jsonRequestInit,
|
|
68
73
|
readErrorMessage,
|
|
69
74
|
readJsonObject,
|
|
@@ -75,15 +80,7 @@ import {
|
|
|
75
80
|
} from "./http-client.js";
|
|
76
81
|
import { getFetchImpl, resolveApiUrl } from "./runtime-config";
|
|
77
82
|
|
|
78
|
-
export
|
|
79
|
-
readonly status: number;
|
|
80
|
-
|
|
81
|
-
constructor(message: string, status: number) {
|
|
82
|
-
super(message);
|
|
83
|
-
this.name = "ApiResponseError";
|
|
84
|
-
this.status = status;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
83
|
+
export { ApiResponseError } from "./http-client.js";
|
|
87
84
|
|
|
88
85
|
function requestStatusJson<T extends object>(
|
|
89
86
|
path: string,
|
|
@@ -99,11 +96,6 @@ function requestStatusJson<T extends object>(
|
|
|
99
96
|
});
|
|
100
97
|
}
|
|
101
98
|
|
|
102
|
-
function apiResponseError(message: string) {
|
|
103
|
-
return (response: Response, body: unknown) =>
|
|
104
|
-
new ApiResponseError(readErrorMessage(body) ?? message, response.status);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
99
|
export type ProcessDetailData = ProcessDetailUiSnapshotResponseBody;
|
|
108
100
|
export type FutureExecutionSummary = FutureExecutionOverviewItem;
|
|
109
101
|
export type FutureActionSummary = Extract<FutureExecutionOverviewItem, { kind: "action" }>;
|
|
@@ -138,9 +130,10 @@ export async function fetchTicketCreationTools(): Promise<TicketCreationToolSumm
|
|
|
138
130
|
export function launchTicketCreation(
|
|
139
131
|
instanceId: string,
|
|
140
132
|
body: LaunchTicketCreationRequestBody,
|
|
133
|
+
idempotencyKey = crypto.randomUUID(),
|
|
141
134
|
): Promise<LaunchTicketCreationResponseBody> {
|
|
142
135
|
const init = jsonRequestInit("POST", body);
|
|
143
|
-
init.headers = { ...init.headers, "idempotency-key":
|
|
136
|
+
init.headers = { ...init.headers, "idempotency-key": idempotencyKey };
|
|
144
137
|
return requestJson({
|
|
145
138
|
path: `/api/processes/${encodeURIComponent(instanceId)}/ticket-creation`,
|
|
146
139
|
init,
|
|
@@ -448,6 +441,38 @@ export async function fetchLauncherModelConfigPreview(
|
|
|
448
441
|
return body.preview;
|
|
449
442
|
}
|
|
450
443
|
|
|
444
|
+
export async function validateLauncher(
|
|
445
|
+
launcherId: string,
|
|
446
|
+
request: {
|
|
447
|
+
title: string | null;
|
|
448
|
+
launcherInput: Record<string, unknown>;
|
|
449
|
+
modelConfig: LauncherModelConfigDefaults;
|
|
450
|
+
schedule: ScheduleConfigInput;
|
|
451
|
+
skillIds: readonly string[];
|
|
452
|
+
futureExecutionId?: string;
|
|
453
|
+
},
|
|
454
|
+
signal?: AbortSignal,
|
|
455
|
+
): Promise<readonly LauncherValidationError[]> {
|
|
456
|
+
const { futureExecutionId, ...launchRequest } = request;
|
|
457
|
+
const query = futureExecutionId
|
|
458
|
+
? `?futureExecutionId=${encodeURIComponent(futureExecutionId)}`
|
|
459
|
+
: "";
|
|
460
|
+
const body = await requestJson<LauncherValidationResponseBody>({
|
|
461
|
+
path: `/api/launchers/${encodeURIComponent(launcherId)}/validate${query}`,
|
|
462
|
+
init: { ...jsonRequestInit("POST", launchRequest), signal },
|
|
463
|
+
malformed: "Malformed launcher validation response",
|
|
464
|
+
onError: (response, body) => {
|
|
465
|
+
const errors = readLauncherValidationErrors(body);
|
|
466
|
+
if (response.status === 400 && errors.length > 0) return { errors };
|
|
467
|
+
throw new Error(readErrorMessage(body) ?? "Couldn't validate the launch values. Try again.");
|
|
468
|
+
},
|
|
469
|
+
});
|
|
470
|
+
if (!Array.isArray(body.errors) || !body.errors.every(isLauncherValidationError)) {
|
|
471
|
+
throw new Error("Malformed launcher validation response");
|
|
472
|
+
}
|
|
473
|
+
return body.errors;
|
|
474
|
+
}
|
|
475
|
+
|
|
451
476
|
async function parseLauncherErrorResponse(
|
|
452
477
|
res: Response,
|
|
453
478
|
fallbackMessagePrefix: string,
|
|
@@ -564,39 +589,17 @@ export async function fetchPrimaryPathSnapshot(instanceId: string): Promise<Prim
|
|
|
564
589
|
);
|
|
565
590
|
}
|
|
566
591
|
|
|
567
|
-
export async function fetchProcessDetail(
|
|
592
|
+
export async function fetchProcessDetail(
|
|
593
|
+
instanceId: string,
|
|
594
|
+
beforeTurnRecordId?: string,
|
|
595
|
+
): Promise<ProcessDetailData> {
|
|
568
596
|
return requestStatusJson(
|
|
569
|
-
`/api/processes/${encodeURIComponent(instanceId)}/ui-snapshot`,
|
|
597
|
+
`/api/processes/${encodeURIComponent(instanceId)}/ui-snapshot${beforeTurnRecordId ? `?beforeTurnRecordId=${encodeURIComponent(beforeTurnRecordId)}` : ""}`,
|
|
570
598
|
"Couldn't load this process",
|
|
571
599
|
"Malformed process UI snapshot response",
|
|
572
600
|
);
|
|
573
601
|
}
|
|
574
602
|
|
|
575
|
-
export async function fetchTurnReasoningDetail(
|
|
576
|
-
instanceId: string,
|
|
577
|
-
turnRecordId: string,
|
|
578
|
-
sessionSignature: string | null,
|
|
579
|
-
signal?: AbortSignal,
|
|
580
|
-
): Promise<TurnReasoningDetailResponseBody> {
|
|
581
|
-
const params = new URLSearchParams(sessionSignature === null ? {} : { sessionSignature });
|
|
582
|
-
const res = await getFetchImpl()(
|
|
583
|
-
resolveApiUrl(
|
|
584
|
-
`/api/processes/${encodeURIComponent(instanceId)}/turn-records/${encodeURIComponent(turnRecordId)}/reasoning?${params.toString()}`,
|
|
585
|
-
),
|
|
586
|
-
{ signal },
|
|
587
|
-
);
|
|
588
|
-
if (res.status === 409) {
|
|
589
|
-
throw new Error(
|
|
590
|
-
"The process changed while reasoning details were loading. Retry with the latest snapshot.",
|
|
591
|
-
);
|
|
592
|
-
}
|
|
593
|
-
if (!res.ok) throw new Error(`Couldn't load reasoning details: ${res.status}`);
|
|
594
|
-
return readJsonObject<TurnReasoningDetailResponseBody>(
|
|
595
|
-
res,
|
|
596
|
-
"Malformed reasoning detail response",
|
|
597
|
-
);
|
|
598
|
-
}
|
|
599
|
-
|
|
600
603
|
export async function fetchFutureExecution(
|
|
601
604
|
futureExecutionId: string,
|
|
602
605
|
): Promise<FutureExecutionDetailResponseBody> {
|
|
@@ -840,3 +843,57 @@ export async function previewCronExpression(expression: string): Promise<string>
|
|
|
840
843
|
}
|
|
841
844
|
return body.nextRunAt;
|
|
842
845
|
}
|
|
846
|
+
|
|
847
|
+
export interface InspectionSections {
|
|
848
|
+
summary: import("@leitwerk-dev/protocol").ExecutionInspectionSummary;
|
|
849
|
+
trace: import("@leitwerk-dev/protocol").ExecutionInspectionTrace;
|
|
850
|
+
context: import("@leitwerk-dev/protocol").ExecutionInspectionContext;
|
|
851
|
+
configuration: import("@leitwerk-dev/protocol").ExecutionInspectionConfiguration;
|
|
852
|
+
}
|
|
853
|
+
export async function fetchExecutionInspection<S extends keyof InspectionSections>(
|
|
854
|
+
instanceId: string,
|
|
855
|
+
turnRecordId: string,
|
|
856
|
+
section: S,
|
|
857
|
+
target: { entryId?: string; itemId?: string; boundaryFor?: string } = {},
|
|
858
|
+
signal?: AbortSignal,
|
|
859
|
+
): Promise<InspectionSections[S]> {
|
|
860
|
+
const params = new URLSearchParams({ section });
|
|
861
|
+
for (const key of ["entryId", "itemId", "boundaryFor"] as const)
|
|
862
|
+
if (target[key]) params.set(key, target[key]);
|
|
863
|
+
const response = await getFetchImpl()(
|
|
864
|
+
resolveApiUrl(
|
|
865
|
+
`/api/processes/${encodeURIComponent(instanceId)}/turn-records/${encodeURIComponent(turnRecordId)}/inspection?${params}`,
|
|
866
|
+
),
|
|
867
|
+
{ signal },
|
|
868
|
+
);
|
|
869
|
+
if (!response.ok)
|
|
870
|
+
throw new Error(
|
|
871
|
+
response.status === 404
|
|
872
|
+
? "This execution is unavailable or does not belong to this process."
|
|
873
|
+
: `Couldn't load ${section}: ${response.status}`,
|
|
874
|
+
);
|
|
875
|
+
return readJsonObject<InspectionSections[S]>(response, "Malformed inspection response");
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
export async function updateProcessModelConfig(
|
|
879
|
+
instanceId: string,
|
|
880
|
+
patch: ProcessModelConfigPatch,
|
|
881
|
+
preview = false,
|
|
882
|
+
) {
|
|
883
|
+
return requestStatusJson<ProcessModelConfigResponseBody>(
|
|
884
|
+
`/api/processes/${encodeURIComponent(instanceId)}/model-config${preview ? "/preview" : ""}`,
|
|
885
|
+
preview ? "Couldn't preview model settings" : "Couldn't save model settings",
|
|
886
|
+
"Malformed model configuration response",
|
|
887
|
+
jsonRequestInit(preview ? "POST" : "PATCH", patch),
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/** Fetch the server-owned installation overview. @internal */
|
|
892
|
+
export function fetchDashboard(signal?: AbortSignal): Promise<DashboardResponseBody> {
|
|
893
|
+
return requestStatusJson(
|
|
894
|
+
"/api/dashboard",
|
|
895
|
+
"Couldn't load the dashboard",
|
|
896
|
+
"Malformed dashboard response",
|
|
897
|
+
{ signal },
|
|
898
|
+
);
|
|
899
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { DashboardResponseBody } from "@leitwerk-dev/protocol/http-contracts";
|
|
2
|
+
|
|
3
|
+
/** Snapshot state retained across refresh failures. @internal */
|
|
4
|
+
export interface DashboardLoadState {
|
|
5
|
+
data: DashboardResponseBody | null;
|
|
6
|
+
loading: boolean;
|
|
7
|
+
error: string | null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Coalesces refresh triggers and invalidates responses after disposal. @internal */
|
|
11
|
+
export function createDashboardRefresh(
|
|
12
|
+
fetchSnapshot: (signal: AbortSignal) => Promise<DashboardResponseBody>,
|
|
13
|
+
publish: (state: DashboardLoadState) => void,
|
|
14
|
+
) {
|
|
15
|
+
let state: DashboardLoadState = { data: null, loading: false, error: null };
|
|
16
|
+
let active: Promise<void> | null = null;
|
|
17
|
+
let disposed = false;
|
|
18
|
+
let controller: AbortController | null = null;
|
|
19
|
+
return {
|
|
20
|
+
refresh(): Promise<void> {
|
|
21
|
+
if (disposed) return Promise.resolve();
|
|
22
|
+
if (active) return active;
|
|
23
|
+
controller = new AbortController();
|
|
24
|
+
const signal = controller.signal;
|
|
25
|
+
state = { ...state, loading: true, error: null };
|
|
26
|
+
publish(state);
|
|
27
|
+
active = Promise.resolve()
|
|
28
|
+
.then(() => fetchSnapshot(signal))
|
|
29
|
+
.then(
|
|
30
|
+
(data) => ({ data, error: null }),
|
|
31
|
+
() => ({ data: state.data, error: "Couldn't refresh the dashboard. Try again." }),
|
|
32
|
+
)
|
|
33
|
+
.then((next) => {
|
|
34
|
+
active = null;
|
|
35
|
+
if (!disposed) {
|
|
36
|
+
state = { data: next.data, loading: false, error: next.error };
|
|
37
|
+
publish(state);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return active;
|
|
41
|
+
},
|
|
42
|
+
dispose() {
|
|
43
|
+
disposed = true;
|
|
44
|
+
controller?.abort();
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
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,
|