@leitwerk-dev/ui 0.1.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/LICENSE +13 -0
- package/dist/assets/ChronicleMarkdown-BLgtHeEE.js +16 -0
- package/dist/assets/ChronicleMarkdown-D6hFzERy.css +1 -0
- package/dist/assets/FutureLaunchDetailPage-KrXSGzHM.js +1 -0
- package/dist/assets/FutureLaunchDetailPage-VPMBtpYc.css +1 -0
- package/dist/assets/GenericLauncher-Cv38FByt.js +1 -0
- package/dist/assets/GenericLauncher-D_GMtsQ5.css +1 -0
- package/dist/assets/HomePage-Cd3lEtwZ.js +1 -0
- package/dist/assets/HomePage-DYh_QHXv.css +1 -0
- package/dist/assets/PageHeader-6PdvYODN.css +1 -0
- package/dist/assets/PageHeader-D6pP4hIh.js +1 -0
- package/dist/assets/ProcessActionsMenu-1QySGNy9.js +1 -0
- package/dist/assets/ProcessActionsMenu-BT2r9vO8.css +1 -0
- package/dist/assets/ProcessDetailPage-BLuc7sjV.js +12 -0
- package/dist/assets/ProcessDetailPage-CSrjzajF.css +1 -0
- package/dist/assets/ProcessFlowDiagram-BAh_M_rb.js +2 -0
- package/dist/assets/ProcessFlowDiagram-Cz8wNicU.css +1 -0
- package/dist/assets/ProcessesPage-BcM38HMs.css +1 -0
- package/dist/assets/ProcessesPage-DtPweRU-.js +1 -0
- package/dist/assets/ScheduleDateTimePicker-CQGvY-Rc.js +1 -0
- package/dist/assets/ScheduleDateTimePicker-CadXN9z7.css +1 -0
- package/dist/assets/SkillsPage-B30FAFia.css +1 -0
- package/dist/assets/SkillsPage-bXuv0kEE.js +2 -0
- package/dist/assets/WatchersPage-DNyUsU1y.js +1 -0
- package/dist/assets/WatchersPage-Dnfi1zUK.css +1 -0
- package/dist/assets/api-CqECFdii.js +1 -0
- package/dist/assets/browser-storage-LbKCyf_w.js +1 -0
- package/dist/assets/dist-B7WNbObw.js +2 -0
- package/dist/assets/index-66T4Gmbl.css +1 -0
- package/dist/assets/index-C8qCggeq.js +7 -0
- package/dist/assets/index-client-BqF3_t3P.js +2 -0
- package/dist/assets/mermaid-render.worker-DAVgiVRG.js +6393 -0
- package/dist/assets/retry-config.svelte-DFKCJtCe.js +1 -0
- package/dist/assets/router.svelte-COr45o9R.js +1 -0
- package/dist/fonts/OFL-Public-Sans.txt +115 -0
- package/dist/fonts/OFL-Spectral.txt +93 -0
- package/dist/fonts/README.md +38 -0
- package/dist/fonts/fonts.css +85 -0
- package/dist/fonts/public-sans-latin-cd00287f.woff2 +0 -0
- package/dist/fonts/public-sans-latin-ext-d025d4ba.woff2 +0 -0
- package/dist/fonts/spectral-latin-89d48951.woff2 +0 -0
- package/dist/fonts/spectral-latin-b7578f14.woff2 +0 -0
- package/dist/fonts/spectral-latin-c4e0a00d.woff2 +0 -0
- package/dist/fonts/spectral-latin-ext-260738f4.woff2 +0 -0
- package/dist/fonts/spectral-latin-ext-ab18ac17.woff2 +0 -0
- package/dist/fonts/spectral-latin-ext-f58c1db3.woff2 +0 -0
- package/dist/index.html +32 -0
- package/package.json +47 -0
- package/src/App.svelte +257 -0
- package/src/chronicle/components/ChronicleActionSection.svelte +1035 -0
- package/src/chronicle/components/ChronicleExpandButton.svelte +70 -0
- package/src/chronicle/components/ChronicleFlow.svelte +289 -0
- package/src/chronicle/components/ChronicleLeafOutcomePlaceholder.svelte +44 -0
- package/src/chronicle/components/ChronicleLeafOutcomeRendererHost.svelte +408 -0
- package/src/chronicle/components/ChronicleLeafOutcomeSection.svelte +253 -0
- package/src/chronicle/components/ChronicleLiveChip.svelte +96 -0
- package/src/chronicle/components/ChronicleLiveTail.svelte +376 -0
- package/src/chronicle/components/ChronicleMarkdown.svelte +168 -0
- package/src/chronicle/components/ChronicleOperatorInputSection.svelte +41 -0
- package/src/chronicle/components/ChronicleProcessErrorSection.svelte +131 -0
- package/src/chronicle/components/ChroniclePromptSection.svelte +54 -0
- package/src/chronicle/components/ChronicleQuestionRequest.svelte +167 -0
- package/src/chronicle/components/ChronicleReasoningDetailsOverlay.svelte +893 -0
- package/src/chronicle/components/ChronicleRecoverySection.svelte +338 -0
- package/src/chronicle/components/ChronicleScheduledActionSection.svelte +192 -0
- package/src/chronicle/components/ChronicleSectionHeader.svelte +135 -0
- package/src/chronicle/components/ChronicleStartupRecoverySection.svelte +138 -0
- package/src/chronicle/components/ChronicleTerminalSummary.svelte +127 -0
- package/src/chronicle/components/ChronicleThinkingSection.svelte +191 -0
- package/src/chronicle/components/ChronicleThinkingText.svelte +46 -0
- package/src/chronicle/components/ChronicleToolCallItem.svelte +477 -0
- package/src/chronicle/components/ChronicleTurnCluster.svelte +325 -0
- package/src/chronicle/components/ChronicleTurnRail.svelte +584 -0
- package/src/chronicle/components/ChronicleUsageStats.svelte +107 -0
- package/src/chronicle/components/CompactActionComposer.svelte +417 -0
- package/src/chronicle/components/ModelProfileOptions.svelte +20 -0
- package/src/chronicle/components/ProviderOptionsEditor.svelte +171 -0
- package/src/chronicle/components/RecoveryModelControl.svelte +95 -0
- package/src/chronicle/lib/action-bindings.ts +90 -0
- package/src/chronicle/lib/action-model-display.ts +133 -0
- package/src/chronicle/lib/action-preview.ts +16 -0
- package/src/chronicle/lib/chronicle-projection.ts +1342 -0
- package/src/chronicle/lib/chronicle-selectable-items.ts +352 -0
- package/src/chronicle/lib/chronicle-view-model.ts +121 -0
- package/src/chronicle/lib/formatting.ts +18 -0
- package/src/chronicle/lib/leaf-outcome-loader.ts +214 -0
- package/src/chronicle/lib/leaf-outcome-runtime.ts +37 -0
- package/src/chronicle/lib/prompt-highlighting.ts +78 -0
- package/src/chronicle/lib/scroll-sync.ts +88 -0
- package/src/chronicle/lib/tool-call-summary.ts +64 -0
- package/src/components/BrowserUiExtensionIndicatorHost.svelte +34 -0
- package/src/components/ConversationTreeDiagram.svelte +393 -0
- package/src/components/FormFieldRenderer.svelte +359 -0
- package/src/components/GenericLauncher.svelte +1970 -0
- package/src/components/KeyboardShortcutsModal.svelte +52 -0
- package/src/components/ModalShell.svelte +105 -0
- package/src/components/PageHeader.svelte +146 -0
- package/src/components/ProcessActionsMenu.svelte +514 -0
- package/src/components/ProcessInfoOverlay.svelte +1229 -0
- package/src/components/ScheduleDateTimePicker.svelte +155 -0
- package/src/components/SkillSelector.svelte +45 -0
- package/src/components/ToastContainer.svelte +192 -0
- package/src/components/launcher-form-copy.ts +172 -0
- package/src/components/launcher-model-config.ts +263 -0
- package/src/components/launcher-schedule.ts +127 -0
- package/src/extension-ui-dev-server.ts +98 -0
- package/src/lib/api.ts +970 -0
- package/src/lib/beautiful-mermaid-elk-instance.ts +54 -0
- package/src/lib/browser-storage.ts +11 -0
- package/src/lib/cost-estimates.ts +41 -0
- package/src/lib/elk-bundled-worker.ts +41 -0
- package/src/lib/flow-layout.ts +326 -0
- package/src/lib/format.ts +96 -0
- package/src/lib/future-executions-logic.ts +12 -0
- package/src/lib/future-launch-detail.ts +145 -0
- package/src/lib/instance-tree-layout.ts +158 -0
- package/src/lib/keyboard-shortcuts-help.ts +20 -0
- package/src/lib/keyboard.ts +40 -0
- package/src/lib/launcher-recent-values.ts +68 -0
- package/src/lib/markdown.ts +94 -0
- package/src/lib/mermaid-render.worker.ts +36 -0
- package/src/lib/pi-stream.ts +3 -0
- package/src/lib/primary-path-detail.ts +337 -0
- package/src/lib/primary-path-replay.ts +27 -0
- package/src/lib/process-browser.ts +179 -0
- package/src/lib/process-initial-prompt.ts +7 -0
- package/src/lib/process-launch-notices.svelte.ts +25 -0
- package/src/lib/process-row-view.ts +60 -0
- package/src/lib/process-terminal-display.ts +17 -0
- package/src/lib/process-toast-focus.svelte.ts +18 -0
- package/src/lib/processes-logic.ts +2 -0
- package/src/lib/processes.svelte.ts +334 -0
- package/src/lib/request-guard.ts +20 -0
- package/src/lib/retry-config.svelte.ts +19 -0
- package/src/lib/rich-markdown-elements.ts +173 -0
- package/src/lib/router-logic.ts +190 -0
- package/src/lib/router.svelte.ts +56 -0
- package/src/lib/runtime-config.ts +96 -0
- package/src/lib/test-fixtures.ts +13 -0
- package/src/lib/toasts.svelte.ts +104 -0
- package/src/lib/tool-call-rendering.ts +66 -0
- package/src/lib/ui-extensions.svelte.ts +381 -0
- package/src/lib/usage-snapshot.ts +9 -0
- package/src/lib/ws-classifier.ts +80 -0
- package/src/lib/ws.svelte.ts +281 -0
- package/src/main.ts +8 -0
- package/src/pages/FutureLaunchDetailPage.svelte +479 -0
- package/src/pages/HomePage.svelte +306 -0
- package/src/pages/ProcessCard.svelte +99 -0
- package/src/pages/ProcessDetailPage.svelte +599 -0
- package/src/pages/ProcessFlowDiagram.svelte +696 -0
- package/src/pages/ProcessGallery.svelte +252 -0
- package/src/pages/ProcessesPage.svelte +994 -0
- package/src/pages/SkillsPage.svelte +665 -0
- package/src/pages/WatchersPage.svelte +330 -0
- package/src/pages/process-detail/OverlayFrame.svelte +58 -0
- package/src/pages/process-detail/ProcessDetailChronicle.svelte +460 -0
- package/src/pages/process-detail/ProcessDetailHeader.svelte +167 -0
- package/src/pages/process-detail/process-detail-action-drafts.svelte.ts +211 -0
- package/src/pages/process-detail/process-detail-actions.svelte.ts +548 -0
- package/src/pages/process-detail/process-detail-chronicle-dom.ts +102 -0
- package/src/pages/process-detail/process-detail-chronicle-scroll.svelte.ts +711 -0
- package/src/pages/process-detail/process-detail-mutations.svelte.ts +91 -0
- package/src/pages/process-detail/process-detail-view-model.ts +149 -0
- package/src/shell/AppShell.svelte +249 -0
- package/src/shell/RouteLoadBoundary.svelte +43 -0
- package/src/shell/Sidebar.svelte +1358 -0
- package/src/shell/test-fixtures/RouteLoadTestComponent.svelte +5 -0
- package/src/vite-env.d.ts +2 -0
- package/src/vite-server-config.ts +27 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ElkNode } from "elkjs";
|
|
2
|
+
import ElkBundledWorker from "./elk-bundled-worker.js";
|
|
3
|
+
|
|
4
|
+
interface RawFakeWorker {
|
|
5
|
+
onmessage: ((event: { data: Record<string, unknown> }) => void) | null;
|
|
6
|
+
dispatcher: {
|
|
7
|
+
saveDispatch(message: { data: Record<string, unknown> }): void;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let elk: ElkBundledWorker | null = null;
|
|
12
|
+
let rawWorker: RawFakeWorker | null = null;
|
|
13
|
+
|
|
14
|
+
function ensureElk(): void {
|
|
15
|
+
if (elk) return;
|
|
16
|
+
const pending: Array<() => void> = [];
|
|
17
|
+
const originalSetTimeout = globalThis.setTimeout;
|
|
18
|
+
globalThis.setTimeout = ((callback: () => void, delay?: number) => {
|
|
19
|
+
if (delay === 0) {
|
|
20
|
+
pending.push(callback);
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
return originalSetTimeout(callback, delay);
|
|
24
|
+
}) as typeof globalThis.setTimeout;
|
|
25
|
+
try {
|
|
26
|
+
elk = new ElkBundledWorker();
|
|
27
|
+
} finally {
|
|
28
|
+
globalThis.setTimeout = originalSetTimeout;
|
|
29
|
+
}
|
|
30
|
+
for (const callback of pending) callback();
|
|
31
|
+
rawWorker = elk.worker.worker;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function elkLayoutSync(graph: ElkNode): ElkNode {
|
|
35
|
+
ensureElk();
|
|
36
|
+
if (!rawWorker) throw new Error("ELK in-process worker is unavailable");
|
|
37
|
+
let result: ElkNode | undefined;
|
|
38
|
+
let error: unknown;
|
|
39
|
+
const originalOnMessage = rawWorker.onmessage;
|
|
40
|
+
rawWorker.onmessage = (answer) => {
|
|
41
|
+
if (answer.data.error) error = answer.data.error;
|
|
42
|
+
else result = answer.data.data as ElkNode;
|
|
43
|
+
};
|
|
44
|
+
try {
|
|
45
|
+
rawWorker.dispatcher.saveDispatch({
|
|
46
|
+
data: { id: 0, cmd: "layout", graph } as unknown as Record<string, unknown>,
|
|
47
|
+
});
|
|
48
|
+
} finally {
|
|
49
|
+
rawWorker.onmessage = originalOnMessage;
|
|
50
|
+
}
|
|
51
|
+
if (error) throw error;
|
|
52
|
+
if (!result) throw new Error("ELK layout did not return synchronously");
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type StorageLike = Pick<Storage, "getItem" | "setItem"> &
|
|
2
|
+
Partial<Pick<Storage, "removeItem">>;
|
|
3
|
+
|
|
4
|
+
export function getBrowserStorage(): StorageLike | null {
|
|
5
|
+
if (typeof window === "undefined") return null;
|
|
6
|
+
try {
|
|
7
|
+
return window.localStorage;
|
|
8
|
+
} catch {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { TurnUsageSnapshot } from "@leitwerk-dev/protocol";
|
|
2
|
+
|
|
3
|
+
const usdEstimateFormatter = new Intl.NumberFormat(undefined, {
|
|
4
|
+
style: "currency",
|
|
5
|
+
currency: "USD",
|
|
6
|
+
minimumFractionDigits: 4,
|
|
7
|
+
maximumFractionDigits: 4,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export function formatUsdEstimate(value: number): string {
|
|
11
|
+
return usdEstimateFormatter.format(value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function formatUsageSummaryTitle(usage: TurnUsageSnapshot): string {
|
|
15
|
+
const parts = [
|
|
16
|
+
"Aggregate across model calls for this turn.",
|
|
17
|
+
`Input: ${usage.input}`,
|
|
18
|
+
`Output: ${usage.output}`,
|
|
19
|
+
...(usage.reasoning !== undefined ? [`Reported reasoning: ${usage.reasoning}`] : []),
|
|
20
|
+
`Cache Read: ${usage.cacheRead}`,
|
|
21
|
+
`Cache Write: ${usage.cacheWrite}`,
|
|
22
|
+
`Total tokens: ${usage.totalTokens}`,
|
|
23
|
+
...(usage.requestCount !== undefined ? [`Requests: ${usage.requestCount}`] : []),
|
|
24
|
+
...(usage.maxInputTokens !== undefined
|
|
25
|
+
? [`Max single-request input: ${usage.maxInputTokens}`]
|
|
26
|
+
: []),
|
|
27
|
+
"Context source: Pi request context includes the active branch, including hidden prior branch entries and tool results that may not be rendered in the summary.",
|
|
28
|
+
];
|
|
29
|
+
if (usage.cost) {
|
|
30
|
+
parts.push(
|
|
31
|
+
[
|
|
32
|
+
`Estimated total: ${formatUsdEstimate(usage.cost.total)}`,
|
|
33
|
+
`input ${formatUsdEstimate(usage.cost.input)}`,
|
|
34
|
+
`output ${formatUsdEstimate(usage.cost.output)}`,
|
|
35
|
+
`cache read ${formatUsdEstimate(usage.cost.cacheRead)}`,
|
|
36
|
+
`cache write ${formatUsdEstimate(usage.cost.cacheWrite)}`,
|
|
37
|
+
].join(", "),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return parts.join(", ");
|
|
41
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import ElkApi, { type ELKConstructorArguments } from "elkjs/lib/elk-api.js";
|
|
2
|
+
import elkWorkerSource from "elkjs/lib/elk-worker.min.js?raw";
|
|
3
|
+
|
|
4
|
+
interface ElkInProcessWorker {
|
|
5
|
+
postMessage(message: unknown): void;
|
|
6
|
+
onmessage: ((event: { data: Record<string, unknown> }) => void) | null;
|
|
7
|
+
dispatcher: {
|
|
8
|
+
saveDispatch(message: { data: Record<string, unknown> }): void;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface ElkInProcessWorkerConstructor {
|
|
13
|
+
new (): ElkInProcessWorker;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function loadInProcessWorker(): ElkInProcessWorkerConstructor {
|
|
17
|
+
// Evaluate the trusted bundled dependency with CommonJS bindings and a fake
|
|
18
|
+
// document so it exports its synchronous FakeWorker instead of taking over
|
|
19
|
+
// this outer worker's message handler.
|
|
20
|
+
const module = { exports: {} as { Worker?: ElkInProcessWorkerConstructor } };
|
|
21
|
+
const evaluate = new Function("module", "exports", "self", "document", elkWorkerSource);
|
|
22
|
+
evaluate(module, module.exports, globalThis, {});
|
|
23
|
+
if (!module.exports.Worker) throw new Error("ELK in-process worker did not initialize");
|
|
24
|
+
return module.exports.Worker;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const InProcessWorker = loadInProcessWorker();
|
|
28
|
+
const ElkBase = ElkApi as unknown as new (
|
|
29
|
+
args?: ELKConstructorArguments,
|
|
30
|
+
) => {
|
|
31
|
+
worker: { worker: ElkInProcessWorker };
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default class ElkBundledWorker extends ElkBase {
|
|
35
|
+
constructor(args: ELKConstructorArguments = {}) {
|
|
36
|
+
super({
|
|
37
|
+
...args,
|
|
38
|
+
workerFactory: args.workerFactory ?? (() => new InProcessWorker() as unknown as Worker),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import dagre from "@dagrejs/dagre";
|
|
2
|
+
import type {
|
|
3
|
+
ProcessFlowEdge,
|
|
4
|
+
ProcessFlowNode,
|
|
5
|
+
ProcessFlowView,
|
|
6
|
+
ProcessTurnTerminalLifecycleStatus,
|
|
7
|
+
ProcessTurnType,
|
|
8
|
+
} from "@leitwerk-dev/domain";
|
|
9
|
+
|
|
10
|
+
export type FlowLayoutNodeKind = "turn" | "end";
|
|
11
|
+
|
|
12
|
+
export interface FlowLayoutPoint {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface FlowLayoutNode {
|
|
18
|
+
id: string;
|
|
19
|
+
kind: FlowLayoutNodeKind;
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
title: string;
|
|
25
|
+
subtitle: string;
|
|
26
|
+
role: ProcessFlowNode["role"] | null;
|
|
27
|
+
turnType: ProcessTurnType | null;
|
|
28
|
+
lifecycleStatus: ProcessTurnTerminalLifecycleStatus | null;
|
|
29
|
+
isEntry: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface FlowLayoutEdge {
|
|
33
|
+
id: string;
|
|
34
|
+
from: string;
|
|
35
|
+
to: string;
|
|
36
|
+
kind: ProcessFlowEdge["kind"];
|
|
37
|
+
/**
|
|
38
|
+
* All transition labels merged into this single visual edge. Parallel
|
|
39
|
+
* transitions between the same two boxes (same kind) are combined into one
|
|
40
|
+
* drawn edge, so this holds every underlying transition label.
|
|
41
|
+
*/
|
|
42
|
+
labels: string[];
|
|
43
|
+
points: FlowLayoutPoint[];
|
|
44
|
+
labelX: number | null;
|
|
45
|
+
labelY: number | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface FlowLayout {
|
|
49
|
+
width: number;
|
|
50
|
+
height: number;
|
|
51
|
+
nodes: FlowLayoutNode[];
|
|
52
|
+
edges: FlowLayoutEdge[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface FlowLayoutOptions {
|
|
56
|
+
/** Average glyph advance used to estimate box width without DOM measurement. */
|
|
57
|
+
charWidth?: number;
|
|
58
|
+
minNodeWidth?: number;
|
|
59
|
+
maxNodeWidth?: number;
|
|
60
|
+
nodeHeight?: number;
|
|
61
|
+
endNodeHeight?: number;
|
|
62
|
+
/** Horizontal padding inside a box. */
|
|
63
|
+
nodePaddingX?: number;
|
|
64
|
+
rankSep?: number;
|
|
65
|
+
nodeSep?: number;
|
|
66
|
+
edgeSep?: number;
|
|
67
|
+
edgeLabelCharWidth?: number;
|
|
68
|
+
edgeLabelHeight?: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const DEFAULTS = {
|
|
72
|
+
charWidth: 7.2,
|
|
73
|
+
minNodeWidth: 132,
|
|
74
|
+
maxNodeWidth: 280,
|
|
75
|
+
nodeHeight: 56,
|
|
76
|
+
endNodeHeight: 44,
|
|
77
|
+
nodePaddingX: 28,
|
|
78
|
+
rankSep: 56,
|
|
79
|
+
nodeSep: 36,
|
|
80
|
+
edgeSep: 18,
|
|
81
|
+
edgeLabelCharWidth: 6,
|
|
82
|
+
edgeLabelHeight: 18,
|
|
83
|
+
} as const;
|
|
84
|
+
|
|
85
|
+
const END_NODE_PREFIX = "__end__";
|
|
86
|
+
|
|
87
|
+
export function endNodeId(status: ProcessTurnTerminalLifecycleStatus): string {
|
|
88
|
+
return `${END_NODE_PREFIX}${status}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function endNodeTitle(status: ProcessTurnTerminalLifecycleStatus): string {
|
|
92
|
+
return status === "completed" ? "Completed" : "Aborted";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Short text drawn on a merged edge: the single label when only one transition
|
|
97
|
+
* was merged, or a self-describing `N transitions` count when several share the
|
|
98
|
+
* edge. The full list is exposed separately for a hover tooltip.
|
|
99
|
+
*/
|
|
100
|
+
export function edgeDisplayLabel(labels: readonly string[]): string {
|
|
101
|
+
if (labels.length === 0) {
|
|
102
|
+
return "";
|
|
103
|
+
}
|
|
104
|
+
if (labels.length === 1) {
|
|
105
|
+
return labels[0];
|
|
106
|
+
}
|
|
107
|
+
return `${labels.length} transitions`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Short operator-facing name for a turn type, used as a node subtitle and in summaries. */
|
|
111
|
+
export function turnTypeLabel(turnType: ProcessTurnType): string {
|
|
112
|
+
switch (turnType) {
|
|
113
|
+
case "llm":
|
|
114
|
+
return "Agent turn";
|
|
115
|
+
case "human":
|
|
116
|
+
return "Operator decision";
|
|
117
|
+
case "external":
|
|
118
|
+
return "External wait";
|
|
119
|
+
case "automatic":
|
|
120
|
+
return "Automatic";
|
|
121
|
+
case "server_automatic":
|
|
122
|
+
return "Server step";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Single source of truth for the operator-facing explanation of each turn type,
|
|
128
|
+
* surfaced as a hover tooltip on flow-diagram nodes. Keep these aligned with the
|
|
129
|
+
* short {@link turnTypeLabel} names.
|
|
130
|
+
*/
|
|
131
|
+
export function turnTypeDescription(turnType: ProcessTurnType): string {
|
|
132
|
+
switch (turnType) {
|
|
133
|
+
case "llm":
|
|
134
|
+
return "An AI agent does the work in this step, using its tools to plan, edit, or review.";
|
|
135
|
+
case "human":
|
|
136
|
+
return "You decide how the process continues by choosing one of the available actions.";
|
|
137
|
+
case "external":
|
|
138
|
+
return "The process pauses until an outside system or event reports back.";
|
|
139
|
+
case "automatic":
|
|
140
|
+
return "A deterministic step runs automatically in the workspace, with no AI or operator input.";
|
|
141
|
+
case "server_automatic":
|
|
142
|
+
return "The server runs this step automatically to prepare or finalize process state.";
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function estimateWidth(
|
|
147
|
+
text: string,
|
|
148
|
+
options: Required<FlowLayoutOptions>,
|
|
149
|
+
charWidth = options.charWidth,
|
|
150
|
+
): number {
|
|
151
|
+
const raw = text.length * charWidth + options.nodePaddingX * 2;
|
|
152
|
+
return Math.max(options.minNodeWidth, Math.min(options.maxNodeWidth, Math.round(raw)));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Computes a layered graph layout for a process flow view using dagre.
|
|
157
|
+
* Every node and every edge in the view is laid out — including loops, branch
|
|
158
|
+
* offshoots, and multiple edges into or out of a single box — so the result can
|
|
159
|
+
* be rendered as a real directed flow chart rather than a linear list.
|
|
160
|
+
* The layout is deterministic for a given input and option set, so it can be
|
|
161
|
+
* asserted in unit tests without a DOM.
|
|
162
|
+
*/
|
|
163
|
+
export function computeFlowLayout(
|
|
164
|
+
view: ProcessFlowView,
|
|
165
|
+
options: FlowLayoutOptions = {},
|
|
166
|
+
): FlowLayout {
|
|
167
|
+
const opts: Required<FlowLayoutOptions> = { ...DEFAULTS, ...options };
|
|
168
|
+
|
|
169
|
+
const graph = new dagre.graphlib.Graph({ multigraph: true });
|
|
170
|
+
graph.setGraph({
|
|
171
|
+
rankdir: "TB",
|
|
172
|
+
ranksep: opts.rankSep,
|
|
173
|
+
nodesep: opts.nodeSep,
|
|
174
|
+
edgesep: opts.edgeSep,
|
|
175
|
+
marginx: 12,
|
|
176
|
+
marginy: 12,
|
|
177
|
+
});
|
|
178
|
+
graph.setDefaultEdgeLabel(() => ({}));
|
|
179
|
+
|
|
180
|
+
const turnNodes = new Map<string, ProcessFlowNode>();
|
|
181
|
+
for (const node of view.nodes) {
|
|
182
|
+
turnNodes.set(node.turnId, node);
|
|
183
|
+
const width = estimateWidth(node.description, opts);
|
|
184
|
+
graph.setNode(node.turnId, { width, height: opts.nodeHeight });
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Terminal end-state boxes that real transitions point into.
|
|
188
|
+
const endStatuses = new Set<ProcessTurnTerminalLifecycleStatus>();
|
|
189
|
+
for (const edge of view.edges) {
|
|
190
|
+
if (edge.lifecycleStatus !== null) {
|
|
191
|
+
endStatuses.add(edge.lifecycleStatus);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
for (const status of endStatuses) {
|
|
195
|
+
const title = endNodeTitle(status);
|
|
196
|
+
graph.setNode(endNodeId(status), {
|
|
197
|
+
width: estimateWidth(title, opts),
|
|
198
|
+
height: opts.endNodeHeight,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Merge parallel transitions between the same two boxes (same kind) into a
|
|
203
|
+
// single drawn edge, collecting every underlying label. This keeps the chart
|
|
204
|
+
// readable: N transitions from A to B become one arrow, not N overlapping ones.
|
|
205
|
+
type EdgeGroup = {
|
|
206
|
+
from: string;
|
|
207
|
+
target: string;
|
|
208
|
+
kind: ProcessFlowEdge["kind"];
|
|
209
|
+
labels: string[];
|
|
210
|
+
};
|
|
211
|
+
const edgeGroups = new Map<string, EdgeGroup>();
|
|
212
|
+
for (const edge of view.edges) {
|
|
213
|
+
const target = edge.to ?? (edge.lifecycleStatus ? endNodeId(edge.lifecycleStatus) : null);
|
|
214
|
+
if (target === null || !graph.hasNode(edge.from) || !graph.hasNode(target)) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const key = `${edge.from}|${target}|${edge.kind}`;
|
|
218
|
+
const existing = edgeGroups.get(key);
|
|
219
|
+
if (existing) {
|
|
220
|
+
if (edge.label && !existing.labels.includes(edge.label)) {
|
|
221
|
+
existing.labels.push(edge.label);
|
|
222
|
+
}
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
edgeGroups.set(key, {
|
|
226
|
+
from: edge.from,
|
|
227
|
+
target,
|
|
228
|
+
kind: edge.kind,
|
|
229
|
+
labels: edge.label ? [edge.label] : [],
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
type EdgeMeta = { kind: ProcessFlowEdge["kind"]; labels: string[] };
|
|
234
|
+
const edgeMeta = new Map<string, EdgeMeta>();
|
|
235
|
+
let edgeIndex = 0;
|
|
236
|
+
for (const group of edgeGroups.values()) {
|
|
237
|
+
const name = `e${edgeIndex}`;
|
|
238
|
+
edgeIndex += 1;
|
|
239
|
+
const display = edgeDisplayLabel(group.labels);
|
|
240
|
+
const labelConfig = display
|
|
241
|
+
? {
|
|
242
|
+
width: Math.round(display.length * opts.edgeLabelCharWidth),
|
|
243
|
+
height: opts.edgeLabelHeight,
|
|
244
|
+
labelpos: "c" as const,
|
|
245
|
+
}
|
|
246
|
+
: {};
|
|
247
|
+
graph.setEdge(group.from, group.target, labelConfig, name);
|
|
248
|
+
edgeMeta.set(`${group.from}|${group.target}|${name}`, {
|
|
249
|
+
kind: group.kind,
|
|
250
|
+
labels: group.labels,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
dagre.layout(graph);
|
|
255
|
+
|
|
256
|
+
const graphLabel = graph.graph();
|
|
257
|
+
const layoutNodes: FlowLayoutNode[] = [];
|
|
258
|
+
for (const id of graph.nodes()) {
|
|
259
|
+
const dagreNode = graph.node(id);
|
|
260
|
+
if (!dagreNode) {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const turn = turnNodes.get(id);
|
|
264
|
+
if (turn) {
|
|
265
|
+
layoutNodes.push({
|
|
266
|
+
id,
|
|
267
|
+
kind: "turn",
|
|
268
|
+
x: dagreNode.x,
|
|
269
|
+
y: dagreNode.y,
|
|
270
|
+
width: dagreNode.width,
|
|
271
|
+
height: dagreNode.height,
|
|
272
|
+
title: turn.description,
|
|
273
|
+
subtitle: turnTypeLabel(turn.turnType),
|
|
274
|
+
role: turn.role,
|
|
275
|
+
turnType: turn.turnType,
|
|
276
|
+
lifecycleStatus: null,
|
|
277
|
+
isEntry: turn.isEntry,
|
|
278
|
+
});
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
const status: ProcessTurnTerminalLifecycleStatus = id.endsWith("completed")
|
|
282
|
+
? "completed"
|
|
283
|
+
: "aborted";
|
|
284
|
+
layoutNodes.push({
|
|
285
|
+
id,
|
|
286
|
+
kind: "end",
|
|
287
|
+
x: dagreNode.x,
|
|
288
|
+
y: dagreNode.y,
|
|
289
|
+
width: dagreNode.width,
|
|
290
|
+
height: dagreNode.height,
|
|
291
|
+
title: endNodeTitle(status),
|
|
292
|
+
subtitle: "End state",
|
|
293
|
+
role: null,
|
|
294
|
+
turnType: null,
|
|
295
|
+
lifecycleStatus: status,
|
|
296
|
+
isEntry: false,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const layoutEdges: FlowLayoutEdge[] = [];
|
|
301
|
+
for (const edgeObj of graph.edges()) {
|
|
302
|
+
const dagreEdge = graph.edge(edgeObj);
|
|
303
|
+
if (!dagreEdge) {
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
const meta = edgeMeta.get(`${edgeObj.v}|${edgeObj.w}|${edgeObj.name}`);
|
|
307
|
+
const points = (dagreEdge.points ?? []).map((point) => ({ x: point.x, y: point.y }));
|
|
308
|
+
layoutEdges.push({
|
|
309
|
+
id: edgeObj.name ?? `${edgeObj.v}-${edgeObj.w}`,
|
|
310
|
+
from: edgeObj.v,
|
|
311
|
+
to: edgeObj.w,
|
|
312
|
+
kind: meta?.kind ?? "forward",
|
|
313
|
+
labels: meta?.labels ?? [],
|
|
314
|
+
points,
|
|
315
|
+
labelX: typeof dagreEdge.x === "number" ? dagreEdge.x : null,
|
|
316
|
+
labelY: typeof dagreEdge.y === "number" ? dagreEdge.y : null,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return {
|
|
321
|
+
width: typeof graphLabel.width === "number" ? graphLabel.width : 0,
|
|
322
|
+
height: typeof graphLabel.height === "number" ? graphLabel.height : 0,
|
|
323
|
+
nodes: layoutNodes,
|
|
324
|
+
edges: layoutEdges,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { ProcessLifecycleStatus } from "@leitwerk-dev/domain";
|
|
2
|
+
|
|
3
|
+
const STATUS_LABELS: Record<ProcessLifecycleStatus, string> = {
|
|
4
|
+
discovered: "Queued",
|
|
5
|
+
active: "Running",
|
|
6
|
+
waiting: "Waiting",
|
|
7
|
+
error: "Error",
|
|
8
|
+
completed: "Completed",
|
|
9
|
+
aborted: "Aborted",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const IDENTIFIER_WORD_LABELS: Record<string, string> = {
|
|
13
|
+
api: "API",
|
|
14
|
+
gitlab: "GitLab",
|
|
15
|
+
id: "ID",
|
|
16
|
+
jira: "Jira",
|
|
17
|
+
llm: "LLM",
|
|
18
|
+
mr: "MR",
|
|
19
|
+
pi: "Pi",
|
|
20
|
+
ui: "UI",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function formatIdentifier(value: string): string {
|
|
24
|
+
return value
|
|
25
|
+
.split(/[_-]+/)
|
|
26
|
+
.filter((part) => part.length > 0)
|
|
27
|
+
.map((part) => {
|
|
28
|
+
const normalizedPart = part.toLowerCase();
|
|
29
|
+
return IDENTIFIER_WORD_LABELS[normalizedPart] ?? part.charAt(0).toUpperCase() + part.slice(1);
|
|
30
|
+
})
|
|
31
|
+
.join(" ");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function formatStatus(status: ProcessLifecycleStatus): string {
|
|
35
|
+
return STATUS_LABELS[status] ?? status;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function formatTurnId(turnId: string | null): string {
|
|
39
|
+
if (!turnId) return "Unknown";
|
|
40
|
+
return formatIdentifier(turnId);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function formatDefinition(id: string): string {
|
|
44
|
+
return formatIdentifier(id);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function formatRelativeTime(iso: string): string {
|
|
48
|
+
const diffMs = Date.now() - new Date(iso).getTime();
|
|
49
|
+
if (diffMs < 0) return "just now";
|
|
50
|
+
const seconds = Math.floor(diffMs / 1000);
|
|
51
|
+
if (seconds < 60) return `${seconds}s ago`;
|
|
52
|
+
const minutes = Math.floor(seconds / 60);
|
|
53
|
+
if (minutes < 60) return `${minutes}m ago`;
|
|
54
|
+
const hours = Math.floor(minutes / 60);
|
|
55
|
+
if (hours < 24) return `${hours}h ago`;
|
|
56
|
+
const days = Math.floor(hours / 24);
|
|
57
|
+
return `${days}d ago`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function formatLocalDateTime(iso: string): string {
|
|
61
|
+
return new Intl.DateTimeFormat(undefined, {
|
|
62
|
+
dateStyle: "medium",
|
|
63
|
+
timeStyle: "short",
|
|
64
|
+
}).format(new Date(iso));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function formatUtcDateTime(iso: string): string {
|
|
68
|
+
return `${new Intl.DateTimeFormat(undefined, {
|
|
69
|
+
dateStyle: "medium",
|
|
70
|
+
timeStyle: "short",
|
|
71
|
+
timeZone: "UTC",
|
|
72
|
+
}).format(new Date(iso))} UTC`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function formatLocalDateTime24Hour(iso: string): string {
|
|
76
|
+
return new Intl.DateTimeFormat(undefined, {
|
|
77
|
+
year: "numeric",
|
|
78
|
+
month: "short",
|
|
79
|
+
day: "numeric",
|
|
80
|
+
hour: "2-digit",
|
|
81
|
+
minute: "2-digit",
|
|
82
|
+
hourCycle: "h23",
|
|
83
|
+
}).format(new Date(iso));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function formatUtcDateTime24Hour(iso: string): string {
|
|
87
|
+
return `${new Intl.DateTimeFormat(undefined, {
|
|
88
|
+
year: "numeric",
|
|
89
|
+
month: "short",
|
|
90
|
+
day: "numeric",
|
|
91
|
+
hour: "2-digit",
|
|
92
|
+
minute: "2-digit",
|
|
93
|
+
hourCycle: "h23",
|
|
94
|
+
timeZone: "UTC",
|
|
95
|
+
}).format(new Date(iso))} UTC`;
|
|
96
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FutureExecutionSummary } from "./api.js";
|
|
2
|
+
|
|
3
|
+
export function upsertFutureExecutionSummary(
|
|
4
|
+
items: readonly FutureExecutionSummary[],
|
|
5
|
+
item: FutureExecutionSummary,
|
|
6
|
+
): FutureExecutionSummary[] {
|
|
7
|
+
const index = items.findIndex((candidate) => candidate.id === item.id);
|
|
8
|
+
if (index < 0) {
|
|
9
|
+
return [item, ...items];
|
|
10
|
+
}
|
|
11
|
+
return items.map((candidate, candidateIndex) => (candidateIndex === index ? item : candidate));
|
|
12
|
+
}
|