@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.
Files changed (170) hide show
  1. package/dist/LICENSE +13 -0
  2. package/dist/assets/ChronicleMarkdown-BLgtHeEE.js +16 -0
  3. package/dist/assets/ChronicleMarkdown-D6hFzERy.css +1 -0
  4. package/dist/assets/FutureLaunchDetailPage-KrXSGzHM.js +1 -0
  5. package/dist/assets/FutureLaunchDetailPage-VPMBtpYc.css +1 -0
  6. package/dist/assets/GenericLauncher-Cv38FByt.js +1 -0
  7. package/dist/assets/GenericLauncher-D_GMtsQ5.css +1 -0
  8. package/dist/assets/HomePage-Cd3lEtwZ.js +1 -0
  9. package/dist/assets/HomePage-DYh_QHXv.css +1 -0
  10. package/dist/assets/PageHeader-6PdvYODN.css +1 -0
  11. package/dist/assets/PageHeader-D6pP4hIh.js +1 -0
  12. package/dist/assets/ProcessActionsMenu-1QySGNy9.js +1 -0
  13. package/dist/assets/ProcessActionsMenu-BT2r9vO8.css +1 -0
  14. package/dist/assets/ProcessDetailPage-BLuc7sjV.js +12 -0
  15. package/dist/assets/ProcessDetailPage-CSrjzajF.css +1 -0
  16. package/dist/assets/ProcessFlowDiagram-BAh_M_rb.js +2 -0
  17. package/dist/assets/ProcessFlowDiagram-Cz8wNicU.css +1 -0
  18. package/dist/assets/ProcessesPage-BcM38HMs.css +1 -0
  19. package/dist/assets/ProcessesPage-DtPweRU-.js +1 -0
  20. package/dist/assets/ScheduleDateTimePicker-CQGvY-Rc.js +1 -0
  21. package/dist/assets/ScheduleDateTimePicker-CadXN9z7.css +1 -0
  22. package/dist/assets/SkillsPage-B30FAFia.css +1 -0
  23. package/dist/assets/SkillsPage-bXuv0kEE.js +2 -0
  24. package/dist/assets/WatchersPage-DNyUsU1y.js +1 -0
  25. package/dist/assets/WatchersPage-Dnfi1zUK.css +1 -0
  26. package/dist/assets/api-CqECFdii.js +1 -0
  27. package/dist/assets/browser-storage-LbKCyf_w.js +1 -0
  28. package/dist/assets/dist-B7WNbObw.js +2 -0
  29. package/dist/assets/index-66T4Gmbl.css +1 -0
  30. package/dist/assets/index-C8qCggeq.js +7 -0
  31. package/dist/assets/index-client-BqF3_t3P.js +2 -0
  32. package/dist/assets/mermaid-render.worker-DAVgiVRG.js +6393 -0
  33. package/dist/assets/retry-config.svelte-DFKCJtCe.js +1 -0
  34. package/dist/assets/router.svelte-COr45o9R.js +1 -0
  35. package/dist/fonts/OFL-Public-Sans.txt +115 -0
  36. package/dist/fonts/OFL-Spectral.txt +93 -0
  37. package/dist/fonts/README.md +38 -0
  38. package/dist/fonts/fonts.css +85 -0
  39. package/dist/fonts/public-sans-latin-cd00287f.woff2 +0 -0
  40. package/dist/fonts/public-sans-latin-ext-d025d4ba.woff2 +0 -0
  41. package/dist/fonts/spectral-latin-89d48951.woff2 +0 -0
  42. package/dist/fonts/spectral-latin-b7578f14.woff2 +0 -0
  43. package/dist/fonts/spectral-latin-c4e0a00d.woff2 +0 -0
  44. package/dist/fonts/spectral-latin-ext-260738f4.woff2 +0 -0
  45. package/dist/fonts/spectral-latin-ext-ab18ac17.woff2 +0 -0
  46. package/dist/fonts/spectral-latin-ext-f58c1db3.woff2 +0 -0
  47. package/dist/index.html +32 -0
  48. package/package.json +47 -0
  49. package/src/App.svelte +257 -0
  50. package/src/chronicle/components/ChronicleActionSection.svelte +1035 -0
  51. package/src/chronicle/components/ChronicleExpandButton.svelte +70 -0
  52. package/src/chronicle/components/ChronicleFlow.svelte +289 -0
  53. package/src/chronicle/components/ChronicleLeafOutcomePlaceholder.svelte +44 -0
  54. package/src/chronicle/components/ChronicleLeafOutcomeRendererHost.svelte +408 -0
  55. package/src/chronicle/components/ChronicleLeafOutcomeSection.svelte +253 -0
  56. package/src/chronicle/components/ChronicleLiveChip.svelte +96 -0
  57. package/src/chronicle/components/ChronicleLiveTail.svelte +376 -0
  58. package/src/chronicle/components/ChronicleMarkdown.svelte +168 -0
  59. package/src/chronicle/components/ChronicleOperatorInputSection.svelte +41 -0
  60. package/src/chronicle/components/ChronicleProcessErrorSection.svelte +131 -0
  61. package/src/chronicle/components/ChroniclePromptSection.svelte +54 -0
  62. package/src/chronicle/components/ChronicleQuestionRequest.svelte +167 -0
  63. package/src/chronicle/components/ChronicleReasoningDetailsOverlay.svelte +893 -0
  64. package/src/chronicle/components/ChronicleRecoverySection.svelte +338 -0
  65. package/src/chronicle/components/ChronicleScheduledActionSection.svelte +192 -0
  66. package/src/chronicle/components/ChronicleSectionHeader.svelte +135 -0
  67. package/src/chronicle/components/ChronicleStartupRecoverySection.svelte +138 -0
  68. package/src/chronicle/components/ChronicleTerminalSummary.svelte +127 -0
  69. package/src/chronicle/components/ChronicleThinkingSection.svelte +191 -0
  70. package/src/chronicle/components/ChronicleThinkingText.svelte +46 -0
  71. package/src/chronicle/components/ChronicleToolCallItem.svelte +477 -0
  72. package/src/chronicle/components/ChronicleTurnCluster.svelte +325 -0
  73. package/src/chronicle/components/ChronicleTurnRail.svelte +584 -0
  74. package/src/chronicle/components/ChronicleUsageStats.svelte +107 -0
  75. package/src/chronicle/components/CompactActionComposer.svelte +417 -0
  76. package/src/chronicle/components/ModelProfileOptions.svelte +20 -0
  77. package/src/chronicle/components/ProviderOptionsEditor.svelte +171 -0
  78. package/src/chronicle/components/RecoveryModelControl.svelte +95 -0
  79. package/src/chronicle/lib/action-bindings.ts +90 -0
  80. package/src/chronicle/lib/action-model-display.ts +133 -0
  81. package/src/chronicle/lib/action-preview.ts +16 -0
  82. package/src/chronicle/lib/chronicle-projection.ts +1342 -0
  83. package/src/chronicle/lib/chronicle-selectable-items.ts +352 -0
  84. package/src/chronicle/lib/chronicle-view-model.ts +121 -0
  85. package/src/chronicle/lib/formatting.ts +18 -0
  86. package/src/chronicle/lib/leaf-outcome-loader.ts +214 -0
  87. package/src/chronicle/lib/leaf-outcome-runtime.ts +37 -0
  88. package/src/chronicle/lib/prompt-highlighting.ts +78 -0
  89. package/src/chronicle/lib/scroll-sync.ts +88 -0
  90. package/src/chronicle/lib/tool-call-summary.ts +64 -0
  91. package/src/components/BrowserUiExtensionIndicatorHost.svelte +34 -0
  92. package/src/components/ConversationTreeDiagram.svelte +393 -0
  93. package/src/components/FormFieldRenderer.svelte +359 -0
  94. package/src/components/GenericLauncher.svelte +1970 -0
  95. package/src/components/KeyboardShortcutsModal.svelte +52 -0
  96. package/src/components/ModalShell.svelte +105 -0
  97. package/src/components/PageHeader.svelte +146 -0
  98. package/src/components/ProcessActionsMenu.svelte +514 -0
  99. package/src/components/ProcessInfoOverlay.svelte +1229 -0
  100. package/src/components/ScheduleDateTimePicker.svelte +155 -0
  101. package/src/components/SkillSelector.svelte +45 -0
  102. package/src/components/ToastContainer.svelte +192 -0
  103. package/src/components/launcher-form-copy.ts +172 -0
  104. package/src/components/launcher-model-config.ts +263 -0
  105. package/src/components/launcher-schedule.ts +127 -0
  106. package/src/extension-ui-dev-server.ts +98 -0
  107. package/src/lib/api.ts +970 -0
  108. package/src/lib/beautiful-mermaid-elk-instance.ts +54 -0
  109. package/src/lib/browser-storage.ts +11 -0
  110. package/src/lib/cost-estimates.ts +41 -0
  111. package/src/lib/elk-bundled-worker.ts +41 -0
  112. package/src/lib/flow-layout.ts +326 -0
  113. package/src/lib/format.ts +96 -0
  114. package/src/lib/future-executions-logic.ts +12 -0
  115. package/src/lib/future-launch-detail.ts +145 -0
  116. package/src/lib/instance-tree-layout.ts +158 -0
  117. package/src/lib/keyboard-shortcuts-help.ts +20 -0
  118. package/src/lib/keyboard.ts +40 -0
  119. package/src/lib/launcher-recent-values.ts +68 -0
  120. package/src/lib/markdown.ts +94 -0
  121. package/src/lib/mermaid-render.worker.ts +36 -0
  122. package/src/lib/pi-stream.ts +3 -0
  123. package/src/lib/primary-path-detail.ts +337 -0
  124. package/src/lib/primary-path-replay.ts +27 -0
  125. package/src/lib/process-browser.ts +179 -0
  126. package/src/lib/process-initial-prompt.ts +7 -0
  127. package/src/lib/process-launch-notices.svelte.ts +25 -0
  128. package/src/lib/process-row-view.ts +60 -0
  129. package/src/lib/process-terminal-display.ts +17 -0
  130. package/src/lib/process-toast-focus.svelte.ts +18 -0
  131. package/src/lib/processes-logic.ts +2 -0
  132. package/src/lib/processes.svelte.ts +334 -0
  133. package/src/lib/request-guard.ts +20 -0
  134. package/src/lib/retry-config.svelte.ts +19 -0
  135. package/src/lib/rich-markdown-elements.ts +173 -0
  136. package/src/lib/router-logic.ts +190 -0
  137. package/src/lib/router.svelte.ts +56 -0
  138. package/src/lib/runtime-config.ts +96 -0
  139. package/src/lib/test-fixtures.ts +13 -0
  140. package/src/lib/toasts.svelte.ts +104 -0
  141. package/src/lib/tool-call-rendering.ts +66 -0
  142. package/src/lib/ui-extensions.svelte.ts +381 -0
  143. package/src/lib/usage-snapshot.ts +9 -0
  144. package/src/lib/ws-classifier.ts +80 -0
  145. package/src/lib/ws.svelte.ts +281 -0
  146. package/src/main.ts +8 -0
  147. package/src/pages/FutureLaunchDetailPage.svelte +479 -0
  148. package/src/pages/HomePage.svelte +306 -0
  149. package/src/pages/ProcessCard.svelte +99 -0
  150. package/src/pages/ProcessDetailPage.svelte +599 -0
  151. package/src/pages/ProcessFlowDiagram.svelte +696 -0
  152. package/src/pages/ProcessGallery.svelte +252 -0
  153. package/src/pages/ProcessesPage.svelte +994 -0
  154. package/src/pages/SkillsPage.svelte +665 -0
  155. package/src/pages/WatchersPage.svelte +330 -0
  156. package/src/pages/process-detail/OverlayFrame.svelte +58 -0
  157. package/src/pages/process-detail/ProcessDetailChronicle.svelte +460 -0
  158. package/src/pages/process-detail/ProcessDetailHeader.svelte +167 -0
  159. package/src/pages/process-detail/process-detail-action-drafts.svelte.ts +211 -0
  160. package/src/pages/process-detail/process-detail-actions.svelte.ts +548 -0
  161. package/src/pages/process-detail/process-detail-chronicle-dom.ts +102 -0
  162. package/src/pages/process-detail/process-detail-chronicle-scroll.svelte.ts +711 -0
  163. package/src/pages/process-detail/process-detail-mutations.svelte.ts +91 -0
  164. package/src/pages/process-detail/process-detail-view-model.ts +149 -0
  165. package/src/shell/AppShell.svelte +249 -0
  166. package/src/shell/RouteLoadBoundary.svelte +43 -0
  167. package/src/shell/Sidebar.svelte +1358 -0
  168. package/src/shell/test-fixtures/RouteLoadTestComponent.svelte +5 -0
  169. package/src/vite-env.d.ts +2 -0
  170. package/src/vite-server-config.ts +27 -0
@@ -0,0 +1,37 @@
1
+ import type {
2
+ LeafOutcomeRendererMeta,
3
+ LeafOutcomeRendererRuntime,
4
+ } from "@leitwerk-dev/process-sdk/leaf-outcome-renderer";
5
+ import { formatRelativeTime } from "../../lib/format.js";
6
+ import { renderMarkdownToHtml } from "../../lib/markdown.js";
7
+ import { getFetchImpl, resolveApiUrl } from "../../lib/runtime-config.js";
8
+
9
+ export type { LeafOutcomeRendererMeta, LeafOutcomeRendererRuntime };
10
+
11
+ function renderMarkdown(markdown: string): string {
12
+ return renderMarkdownToHtml(markdown);
13
+ }
14
+
15
+ const runtime: LeafOutcomeRendererRuntime = {
16
+ apiVersion: 1,
17
+ markdown: {
18
+ render(markdown) {
19
+ return renderMarkdown(markdown);
20
+ },
21
+ },
22
+ server: {
23
+ resolveUrl(path) {
24
+ return resolveApiUrl(path);
25
+ },
26
+ fetch(path, init) {
27
+ return getFetchImpl()(resolveApiUrl(path), init);
28
+ },
29
+ },
30
+ formatRelativeTime(iso) {
31
+ return formatRelativeTime(iso);
32
+ },
33
+ };
34
+
35
+ export function getLeafOutcomeRendererRuntime(): LeafOutcomeRendererRuntime {
36
+ return runtime;
37
+ }
@@ -0,0 +1,78 @@
1
+ export type PromptHighlightSegmentKind = "context" | "user_input";
2
+
3
+ export interface PromptHighlightSegment {
4
+ kind: PromptHighlightSegmentKind;
5
+ text: string;
6
+ start: number;
7
+ end: number;
8
+ }
9
+
10
+ export type PromptHighlightMatchState = "matched" | "not_found" | "skipped";
11
+
12
+ export interface PromptHighlightResult {
13
+ segments: PromptHighlightSegment[];
14
+ matchState: PromptHighlightMatchState;
15
+ }
16
+
17
+ export const MIN_USER_INPUT_HIGHLIGHT_LENGTH = 4;
18
+
19
+ function isMeaningfulUserInput(value: string | null | undefined): value is string {
20
+ return typeof value === "string" && value.trim().length >= MIN_USER_INPUT_HIGHLIGHT_LENGTH;
21
+ }
22
+
23
+ function contextSegment(text: string, start: number, end: number): PromptHighlightSegment | null {
24
+ if (start >= end) {
25
+ return null;
26
+ }
27
+ return { kind: "context", text, start, end };
28
+ }
29
+
30
+ export function buildPromptHighlightSegments(input: {
31
+ fullPrompt: string;
32
+ userInput?: string | null;
33
+ }): PromptHighlightResult {
34
+ const { fullPrompt, userInput } = input;
35
+ if (!isMeaningfulUserInput(userInput)) {
36
+ return {
37
+ segments: [{ kind: "context", text: fullPrompt, start: 0, end: fullPrompt.length }],
38
+ matchState: "skipped",
39
+ };
40
+ }
41
+
42
+ const segments: PromptHighlightSegment[] = [];
43
+ let searchFrom = 0;
44
+ let matchStart = fullPrompt.indexOf(userInput, searchFrom);
45
+ while (matchStart >= 0) {
46
+ const preceding = contextSegment(
47
+ fullPrompt.slice(searchFrom, matchStart),
48
+ searchFrom,
49
+ matchStart,
50
+ );
51
+ if (preceding) {
52
+ segments.push(preceding);
53
+ }
54
+ const matchEnd = matchStart + userInput.length;
55
+ segments.push({
56
+ kind: "user_input",
57
+ text: fullPrompt.slice(matchStart, matchEnd),
58
+ start: matchStart,
59
+ end: matchEnd,
60
+ });
61
+ searchFrom = matchEnd;
62
+ matchStart = fullPrompt.indexOf(userInput, searchFrom);
63
+ }
64
+
65
+ if (segments.length === 0) {
66
+ return {
67
+ segments: [{ kind: "context", text: fullPrompt, start: 0, end: fullPrompt.length }],
68
+ matchState: "not_found",
69
+ };
70
+ }
71
+
72
+ const trailing = contextSegment(fullPrompt.slice(searchFrom), searchFrom, fullPrompt.length);
73
+ if (trailing) {
74
+ segments.push(trailing);
75
+ }
76
+
77
+ return { segments, matchState: "matched" };
78
+ }
@@ -0,0 +1,88 @@
1
+ export interface ChronicleAnchorLayout {
2
+ anchorId: string;
3
+ top: number;
4
+ height: number;
5
+ }
6
+
7
+ export interface ChronicleViewportMetrics {
8
+ scrollTop: number;
9
+ clientHeight: number;
10
+ scrollHeight: number;
11
+ }
12
+
13
+ const CHRONICLE_ACTIVE_FOCUS_RATIO = 0.76;
14
+
15
+ export function collectAnchorLayouts(
16
+ container: ParentNode,
17
+ selector = "[data-anchor-id]",
18
+ ): ChronicleAnchorLayout[] {
19
+ return [...container.querySelectorAll<HTMLElement>(selector)]
20
+ .map((element) => ({
21
+ anchorId: element.dataset.anchorId ?? element.id,
22
+ top: element.offsetTop,
23
+ height: element.offsetHeight,
24
+ }))
25
+ .filter(
26
+ (layout) =>
27
+ layout.anchorId.length > 0 && Number.isFinite(layout.top) && Number.isFinite(layout.height),
28
+ );
29
+ }
30
+
31
+ export function scrollTopForAnchor(
32
+ layout: Pick<ChronicleAnchorLayout, "top"> & Partial<Pick<ChronicleAnchorLayout, "height">>,
33
+ clientHeight: number,
34
+ options: {
35
+ focusRatio?: number;
36
+ scrollHeight?: number;
37
+ align?: "focus" | "start";
38
+ startPaddingPx?: number;
39
+ } = {},
40
+ ): number {
41
+ const align = options.align ?? "focus";
42
+ let targetTop = 0;
43
+ if (align === "start") {
44
+ targetTop = Math.max(layout.top - Math.max(options.startPaddingPx ?? 0, 0), 0);
45
+ } else {
46
+ const focusRatio = options.focusRatio ?? CHRONICLE_ACTIVE_FOCUS_RATIO;
47
+ const sectionHeight = Math.max(layout.height ?? 0, 0);
48
+ const focusTargetTop = Math.max(layout.top - clientHeight * focusRatio, 0);
49
+ const visibilityTargetTop = Math.max(layout.top + sectionHeight - clientHeight, 0);
50
+ const sectionFitsWithinViewport = sectionHeight > 0 && sectionHeight <= clientHeight;
51
+ targetTop = sectionFitsWithinViewport
52
+ ? Math.max(focusTargetTop, visibilityTargetTop)
53
+ : focusTargetTop;
54
+ }
55
+ if (options.scrollHeight !== undefined && Number.isFinite(options.scrollHeight)) {
56
+ targetTop = Math.min(targetTop, Math.max(options.scrollHeight - clientHeight, 0));
57
+ }
58
+ return targetTop;
59
+ }
60
+
61
+ export function selectActiveAnchorId(
62
+ layouts: readonly ChronicleAnchorLayout[],
63
+ viewport: Pick<ChronicleViewportMetrics, "scrollTop" | "clientHeight">,
64
+ ): string | null {
65
+ if (layouts.length === 0) {
66
+ return null;
67
+ }
68
+ const focusLine = viewport.scrollTop + viewport.clientHeight * CHRONICLE_ACTIVE_FOCUS_RATIO;
69
+ let activeAnchorId = layouts[0]?.anchorId ?? null;
70
+ for (const layout of layouts) {
71
+ if (focusLine >= layout.top - 1) {
72
+ activeAnchorId = layout.anchorId;
73
+ continue;
74
+ }
75
+ break;
76
+ }
77
+ return activeAnchorId;
78
+ }
79
+
80
+ export function isNearChronicleBottom(
81
+ viewport: ChronicleViewportMetrics,
82
+ thresholdPx = 120,
83
+ ): boolean {
84
+ if (!Number.isFinite(viewport.scrollHeight) || viewport.scrollHeight <= 0) {
85
+ return false;
86
+ }
87
+ return viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop <= thresholdPx;
88
+ }
@@ -0,0 +1,64 @@
1
+ import * as v from "valibot";
2
+ import { truncateText } from "../../lib/markdown";
3
+
4
+ const unknownRecordSchema = v.pipe(
5
+ v.unknown(),
6
+ v.check(
7
+ (value) => typeof value === "object" && value !== null && !Array.isArray(value),
8
+ "Expected object",
9
+ ),
10
+ v.record(v.string(), v.unknown()),
11
+ );
12
+
13
+ function isScalar(value: unknown): value is string | number | boolean {
14
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
15
+ }
16
+
17
+ function formatScalar(value: string | number | boolean): string {
18
+ return typeof value === "string" ? truncateText(value, 80) : String(value);
19
+ }
20
+
21
+ export function summarizeToolPayload(value: unknown, maxFields = 2): string | null {
22
+ if (value === null || value === undefined) {
23
+ return null;
24
+ }
25
+ if (isScalar(value)) {
26
+ return formatScalar(value);
27
+ }
28
+ if (Array.isArray(value)) {
29
+ if (value.length === 0) {
30
+ return "Empty list";
31
+ }
32
+ const scalarItems = value.filter(isScalar).slice(0, maxFields).map(formatScalar);
33
+ return scalarItems.length > 0
34
+ ? `${scalarItems.join(", ")} · ${value.length} item${value.length === 1 ? "" : "s"}`
35
+ : `List with ${value.length} item${value.length === 1 ? "" : "s"}`;
36
+ }
37
+ const parsedRecord = v.safeParse(unknownRecordSchema, value);
38
+ if (parsedRecord.success) {
39
+ const scalarEntries = Object.entries(parsedRecord.output)
40
+ .filter(([, entryValue]) => isScalar(entryValue))
41
+ .slice(0, maxFields)
42
+ .map(([key, entryValue]) => `${key}: ${formatScalar(entryValue)}`);
43
+ if (scalarEntries.length > 0) {
44
+ return scalarEntries.join(" · ");
45
+ }
46
+ const keys = Object.keys(parsedRecord.output);
47
+ return `${keys.length} field${keys.length === 1 ? "" : "s"} captured`;
48
+ }
49
+ return truncateText(String(value), 80);
50
+ }
51
+
52
+ export function formatStructuredValue(value: unknown): string {
53
+ if (typeof value === "string") {
54
+ return value;
55
+ }
56
+ if (value === null || value === undefined) {
57
+ return "";
58
+ }
59
+ try {
60
+ return JSON.stringify(value, null, 2);
61
+ } catch {
62
+ return String(value);
63
+ }
64
+ }
@@ -0,0 +1,34 @@
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+ import type { RegisteredBrowserUiShellIndicator } from "../lib/ui-extensions.svelte.js";
4
+
5
+ interface Props {
6
+ indicator: RegisteredBrowserUiShellIndicator;
7
+ }
8
+
9
+ let { indicator }: Props = $props();
10
+ let host: HTMLDivElement;
11
+
12
+ onMount(() => {
13
+ const cleanup = indicator.mount(host);
14
+ return () => {
15
+ if (typeof cleanup === "function") {
16
+ cleanup();
17
+ }
18
+ };
19
+ });
20
+ </script>
21
+
22
+ <div
23
+ class="browser-ui-extension-indicator"
24
+ data-extension-manifest-id={indicator.extensionManifestId}
25
+ data-extension-indicator-id={indicator.id}
26
+ aria-label={indicator.label}
27
+ bind:this={host}
28
+ ></div>
29
+
30
+ <style>
31
+ .browser-ui-extension-indicator {
32
+ display: contents;
33
+ }
34
+ </style>
@@ -0,0 +1,393 @@
1
+ <script module lang="ts">
2
+ let nextTreeDiagramId = 0;
3
+ </script>
4
+
5
+ <script lang="ts">
6
+ import type { ProcessInstanceTreeResponseBody } from "@leitwerk-dev/protocol/http-contracts";
7
+ import type { ChronicleSelectableItem } from "../chronicle/lib/chronicle-selectable-items.js";
8
+ import {
9
+ INSTANCE_TREE_COLUMN_GAP,
10
+ layoutInstanceTree,
11
+ type InstanceTreeLayoutEdge,
12
+ } from "../lib/instance-tree-layout";
13
+
14
+ interface Props {
15
+ tree: ProcessInstanceTreeResponseBody;
16
+ railItems: readonly ChronicleSelectableItem[];
17
+ }
18
+
19
+ let { tree, railItems }: Props = $props();
20
+ const railByRecord = $derived(
21
+ new Map(
22
+ railItems
23
+ .filter((item) => item.kind === "turn")
24
+ .map((item) => [item.turnRecordId, item]),
25
+ ),
26
+ );
27
+ const markerId = `tree-arrow-${nextTreeDiagramId++}`;
28
+ const layout = $derived(layoutInstanceTree(tree.nodes, tree.currentLeafId, tree.edges));
29
+ const laneStarts = $derived(layout?.nodes.filter((node) => node.startsLane) ?? []);
30
+ const branchPoints = $derived(
31
+ layout?.nodes.filter((node) => node.childCount > 1).length ?? 0,
32
+ );
33
+
34
+ function path(points: readonly { x: number; y: number }[]): string {
35
+ return points
36
+ .map((point, index) => `${index === 0 ? "M" : "L"} ${point.x} ${point.y}`)
37
+ .join(" ");
38
+ }
39
+
40
+ function marker(node: NonNullable<typeof layout>["nodes"][number]): string {
41
+ const parts = [railByRecord.get(node.id)?.title ?? node.label];
42
+ if (node.contextOrigin === "fresh") parts.push("fresh context");
43
+ if (node.contextOrigin === "previous") parts.push("branch with previous context");
44
+ if (node.childCount > 1) parts.push("branch point");
45
+ if (node.isCurrent) parts.push("current input");
46
+ if (node.resultState === "failed") parts.push("failed");
47
+ return parts.join(", ");
48
+ }
49
+
50
+ function edgeLabels(edge: InstanceTreeLayoutEdge): string[] {
51
+ return [edge.actionLabel, ...edge.productLabels.map((label) => `${label} input`)].filter(
52
+ (label): label is string => Boolean(label),
53
+ );
54
+ }
55
+
56
+ function isInlineContextEdge(edge: InstanceTreeLayoutEdge): boolean {
57
+ const source = layout?.nodes.find((node) => node.id === edge.sourceNodeId);
58
+ const target = layout?.nodes.find((node) => node.id === edge.targetNodeId);
59
+ return Boolean(source && target && source.lane === target.lane && !edge.productLabels.length);
60
+ }
61
+
62
+ function edgeLabelPosition(edge: InstanceTreeLayoutEdge): { x: number; y: number } {
63
+ const last = edge.points.at(-1) ?? { x: 0, y: 0 };
64
+ const previous = edge.points.at(-2) ?? last;
65
+ const source = layout?.nodes.find((node) => node.id === edge.sourceNodeId);
66
+ const target = layout?.nodes.find((node) => node.id === edge.targetNodeId);
67
+ if (source && target && isInlineContextEdge(edge)) {
68
+ return { x: (source.x + target.x) / 2, y: source.y - 7 };
69
+ }
70
+ const peers =
71
+ layout?.edges.filter(
72
+ (candidate) =>
73
+ candidate.targetNodeId === edge.targetNodeId &&
74
+ !isInlineContextEdge(candidate) &&
75
+ edgeLabels(candidate).length,
76
+ ) ?? [];
77
+ const peerIndex = Math.max(0, peers.findIndex((candidate) => candidate.id === edge.id));
78
+ return {
79
+ x: (previous.x + last.x) / 2,
80
+ y: target ? target.y - target.height / 2 - 9 - peerIndex * 60 : last.y - 11,
81
+ };
82
+ }
83
+
84
+ const accessibleDescription = $derived.by(() => {
85
+ if (!layout) return "No conversation input lineage.";
86
+ const nodes = layout.nodes.map((node) => marker(node)).join("; ");
87
+ const edges = layout.edges
88
+ .map((edge) => {
89
+ const target = edge.targetNodeId ?? edge.endState ?? "no target";
90
+ const label = edgeLabels(edge).join(" ") || (edge.hasContext ? "context" : "decision");
91
+ return `${edge.sourceNodeId} to ${target}: ${label}`;
92
+ })
93
+ .join("; ");
94
+ return `Inputs: ${nodes}. Connections: ${edges || "none"}.`;
95
+ });
96
+ </script>
97
+
98
+ {#if layout}
99
+ <p class="summary-detail">
100
+ {layout.nodes.length} model inputs · {layout.laneCount} contexts · {branchPoints} branch
101
+ {branchPoints === 1 ? "point" : "points"}
102
+ </p>
103
+ <div class="tree-viewport" data-section="conversation-tree-diagram">
104
+ <svg
105
+ width={layout.width}
106
+ height={layout.height}
107
+ viewBox={`0 0 ${layout.width} ${layout.height}`}
108
+ role="img"
109
+ aria-labelledby={`${markerId}-title ${markerId}-description`}
110
+ >
111
+ <title id={`${markerId}-title`}>Conversation input lineage</title>
112
+ <desc id={`${markerId}-description`}>{accessibleDescription}</desc>
113
+ <defs>
114
+ <marker
115
+ id={`${markerId}-context`}
116
+ viewBox="0 0 10 10"
117
+ refX="9"
118
+ refY="5"
119
+ markerWidth="6"
120
+ markerHeight="6"
121
+ orient="auto-start-reverse"
122
+ >
123
+ <path class="context-arrowhead" d="M 0 0 L 10 5 L 0 10 z" />
124
+ </marker>
125
+ <marker
126
+ id={`${markerId}-product`}
127
+ viewBox="0 0 10 10"
128
+ refX="9"
129
+ refY="5"
130
+ markerWidth="6"
131
+ markerHeight="6"
132
+ orient="auto-start-reverse"
133
+ >
134
+ <path class="product-arrowhead" d="M 0 0 L 10 5 L 0 10 z" />
135
+ </marker>
136
+ </defs>
137
+
138
+ {#each laneStarts as node, index (node.id)}
139
+ <g class="lane-label" transform={`translate(16 ${node.y - 13})`}>
140
+ <text class="lane-number" y="0">Context {index + 1}</text>
141
+ <text class:previous={node.contextOrigin === "previous"} y="20">
142
+ {node.contextOrigin === "previous" ? "Previous context" : "Fresh context"}
143
+ </text>
144
+ </g>
145
+ {/each}
146
+
147
+ {#each layout.nodes as node (node.id)}
148
+ {@const rail = railByRecord.get(node.id)}
149
+ <g
150
+ class="tree-node"
151
+ class:branch={node.childCount > 1}
152
+ class:current={node.isCurrent}
153
+ class:failed={node.resultState === "failed"}
154
+ transform={`translate(${node.x - node.width / 2} ${node.y - node.height / 2})`}
155
+ data-tree-node="turn"
156
+ data-context-origin={node.contextOrigin}
157
+ data-rail-tone={rail?.tone}
158
+ >
159
+ <title>{marker(node)}</title>
160
+ <rect width={node.width} height={node.height} rx="9" />
161
+ <text class="node-title" x={node.width / 2} y="38" text-anchor="middle">
162
+ {rail?.title ?? node.label}
163
+ </text>
164
+ {#if node.childCount > 1}
165
+ <text class="badge branch-badge" x={node.width - 58} y="-8">Branch</text>
166
+ {/if}
167
+ {#if node.isCurrent}
168
+ <text class="badge current-badge" x={node.width - 62} y={node.height + 17}>Current</text>
169
+ {:else if node.resultState === "failed"}
170
+ <text class="badge failed-badge" x={node.width - 52} y={node.height + 17}>Failed</text>
171
+ {/if}
172
+ </g>
173
+ {/each}
174
+
175
+ {#each layout.edges as edge (edge.id)}
176
+ <path
177
+ class="edge"
178
+ class:product={edge.productLabels.length}
179
+ class:decision={!edge.hasContext && !edge.productLabels.length}
180
+ class:dead-end={edge.endState === "not_applied"}
181
+ class:completed-end={edge.endState === "completed"}
182
+ d={path(edge.points)}
183
+ marker-end={edge.endState
184
+ ? undefined
185
+ : `url(#${markerId}-${edge.productLabels.length ? "product" : "context"})`}
186
+ />
187
+ {#if edge.endState}
188
+ {@const endpoint = edge.points.at(-1) ?? { x: 0, y: 0 }}
189
+ {#if edge.endState === "not_applied"}
190
+ <g class="dead-end-marker" transform={`translate(${endpoint.x} ${endpoint.y})`}>
191
+ <line x1="-5" y1="-5" x2="5" y2="5" />
192
+ <line x1="5" y1="-5" x2="-5" y2="5" />
193
+ </g>
194
+ {:else}
195
+ <g class="completed-end-marker" transform={`translate(${endpoint.x} ${endpoint.y})`}>
196
+ <path d="M -6 0 L -2 5 L 7 -6" />
197
+ </g>
198
+ {/if}
199
+ {/if}
200
+ {/each}
201
+
202
+ {#each layout.edges as edge (`label:${edge.id}`)}
203
+ {@const labels = edgeLabels(edge)}
204
+ {#if labels.length}
205
+ {@const position = edgeLabelPosition(edge)}
206
+ <foreignObject
207
+ class="edge-label-group"
208
+ class:product={edge.productLabels.length}
209
+ x={position.x - INSTANCE_TREE_COLUMN_GAP / 2}
210
+ y={position.y - 60}
211
+ width={INSTANCE_TREE_COLUMN_GAP}
212
+ height="60"
213
+ >
214
+ <div class="edge-label-box">
215
+ <div class="edge-label">
216
+ {#each labels as label (`${edge.id}:${label}`)}<span>{label}</span>{/each}
217
+ </div>
218
+ </div>
219
+ </foreignObject>
220
+ {/if}
221
+ {/each}
222
+ </svg>
223
+ </div>
224
+ {/if}
225
+
226
+ <style>
227
+ .summary-detail {
228
+ margin: 0;
229
+ color: var(--chronicle-text-muted);
230
+ font-size: var(--type-caption);
231
+ font-weight: 560;
232
+ text-align: left;
233
+ }
234
+
235
+ .tree-viewport {
236
+ overflow: auto;
237
+ max-height: 58vh;
238
+ min-height: 240px;
239
+ border: 1px solid var(--chronicle-border);
240
+ border-radius: var(--radius-md);
241
+ background: color-mix(in srgb, var(--chronicle-panel-muted) 45%, white);
242
+ }
243
+
244
+ svg {
245
+ display: block;
246
+ min-width: 100%;
247
+ }
248
+
249
+ .edge {
250
+ fill: none;
251
+ stroke: var(--chronicle-text-faint);
252
+ stroke-width: 1.6;
253
+ stroke-linejoin: round;
254
+ }
255
+
256
+ .edge.product {
257
+ stroke: var(--chronicle-success);
258
+ stroke-dasharray: 5 4;
259
+ }
260
+
261
+ .edge.decision {
262
+ stroke: var(--chronicle-accent);
263
+ }
264
+
265
+ .edge.dead-end {
266
+ stroke: var(--chronicle-danger);
267
+ }
268
+
269
+ .edge.completed-end {
270
+ stroke: var(--chronicle-success);
271
+ }
272
+
273
+ .dead-end-marker,
274
+ .completed-end-marker {
275
+ stroke-width: 2;
276
+ stroke-linecap: round;
277
+ }
278
+
279
+ .dead-end-marker {
280
+ stroke: var(--chronicle-danger);
281
+ }
282
+
283
+ .completed-end-marker {
284
+ fill: none;
285
+ stroke: var(--chronicle-success);
286
+ stroke-linejoin: round;
287
+ }
288
+
289
+ .context-arrowhead {
290
+ fill: var(--chronicle-text-faint);
291
+ }
292
+
293
+ .product-arrowhead {
294
+ fill: var(--chronicle-success);
295
+ }
296
+
297
+ .edge-label-group {
298
+ pointer-events: none;
299
+ overflow: visible;
300
+ }
301
+
302
+ .edge-label-box {
303
+ display: flex;
304
+ align-items: end;
305
+ justify-content: center;
306
+ height: 100%;
307
+ text-align: center;
308
+ }
309
+
310
+ .edge-label {
311
+ display: flex;
312
+ flex-direction: column;
313
+ padding: 4px 8px;
314
+ border: 1px solid color-mix(in srgb, var(--chronicle-border) 72%, white 28%);
315
+ border-radius: var(--radius-sm);
316
+ background: var(--chronicle-card-surface);
317
+ color: var(--chronicle-text-muted);
318
+ font: 650 var(--type-label) system-ui, sans-serif;
319
+ line-height: 14px;
320
+ }
321
+
322
+ .edge-label-group.product .edge-label {
323
+ border-color: color-mix(in srgb, var(--chronicle-success) 48%, var(--chronicle-border) 52%);
324
+ background: var(--chronicle-success-surface);
325
+ color: var(--chronicle-success);
326
+ }
327
+
328
+ .tree-node rect {
329
+ fill: white;
330
+ stroke: var(--chronicle-border-strong);
331
+ stroke-width: 1.5;
332
+ }
333
+
334
+ .tree-node text {
335
+ fill: var(--chronicle-text);
336
+ font-family: system-ui, sans-serif;
337
+ }
338
+
339
+ .tree-node .node-title {
340
+ font-size: var(--type-caption);
341
+ font-weight: 650;
342
+ }
343
+
344
+ .tree-node.branch rect {
345
+ stroke: var(--chronicle-attention);
346
+ stroke-width: 2;
347
+ }
348
+
349
+ .tree-node.current rect {
350
+ fill: var(--chronicle-success-surface);
351
+ stroke: var(--chronicle-success);
352
+ stroke-width: 2.5;
353
+ }
354
+
355
+ .tree-node.failed rect {
356
+ fill: var(--chronicle-danger-surface-soft);
357
+ stroke: var(--chronicle-danger);
358
+ stroke-width: 2;
359
+ }
360
+
361
+ .badge {
362
+ font-size: var(--type-label);
363
+ font-weight: 700;
364
+ }
365
+
366
+ .branch-badge {
367
+ fill: var(--chronicle-attention) !important;
368
+ }
369
+
370
+ .current-badge {
371
+ fill: var(--chronicle-success) !important;
372
+ }
373
+
374
+ .failed-badge {
375
+ fill: var(--chronicle-danger) !important;
376
+ }
377
+
378
+ .lane-label text {
379
+ fill: var(--chronicle-text-muted);
380
+ font: 600 var(--type-label) system-ui, sans-serif;
381
+ }
382
+
383
+ .lane-label .lane-number {
384
+ fill: var(--chronicle-text);
385
+ font-size: var(--type-label);
386
+ font-weight: 700;
387
+ }
388
+
389
+ .lane-label text.previous {
390
+ fill: var(--chronicle-attention);
391
+ }
392
+
393
+ </style>