@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,190 @@
1
+ export type Page =
2
+ | "home"
3
+ | "processes"
4
+ | "process-detail"
5
+ | "future-launch-detail"
6
+ | "watchers"
7
+ | "skills";
8
+
9
+ export interface Route {
10
+ page: Page;
11
+ params: Record<string, string>;
12
+ }
13
+
14
+ export type ProcessDetailOverlayState =
15
+ | { kind: "none" }
16
+ | { kind: "process-info" }
17
+ | { kind: "reasoning"; turnRecordId: string | null };
18
+
19
+ export interface ProcessPathOptions {
20
+ overlay?: "process-info" | "reasoning" | null;
21
+ turnRecordId?: string | null;
22
+ }
23
+
24
+ function stripSearchAndHash(path: string): string {
25
+ const searchIndex = path.indexOf("?");
26
+ const hashIndex = path.indexOf("#");
27
+ const endIndexes = [searchIndex, hashIndex].filter((index) => index >= 0);
28
+ const endIndex = endIndexes.length > 0 ? Math.min(...endIndexes) : path.length;
29
+ return path.slice(0, endIndex);
30
+ }
31
+
32
+ function readSearchParams(path: string): URLSearchParams {
33
+ const searchIndex = path.indexOf("?");
34
+ if (searchIndex < 0) {
35
+ return new URLSearchParams();
36
+ }
37
+ const hashIndex = path.indexOf("#", searchIndex);
38
+ const search = path.slice(searchIndex + 1, hashIndex >= 0 ? hashIndex : path.length);
39
+ return new URLSearchParams(search);
40
+ }
41
+
42
+ function decodeFirstSegment(pathname: string, prefix: string): string {
43
+ const segment = pathname.slice(prefix.length).split("/")[0];
44
+ return segment ? decodeURIComponent(segment) : "";
45
+ }
46
+
47
+ export function buildHomePath(launcherId?: string | null): string {
48
+ if (!launcherId) {
49
+ return "/";
50
+ }
51
+ const params = new URLSearchParams();
52
+ params.set("launcher", launcherId);
53
+ return `/?${params.toString()}`;
54
+ }
55
+
56
+ export function buildFutureLaunchPath(futureExecutionId: string): string {
57
+ return `/future-launches/${encodeURIComponent(futureExecutionId)}`;
58
+ }
59
+
60
+ export function buildProcessesPath(): string {
61
+ return "/processes";
62
+ }
63
+
64
+ export function buildProcessPath(instanceId: string, options: ProcessPathOptions = {}): string {
65
+ const path = `/processes/${encodeURIComponent(instanceId)}`;
66
+ const params = new URLSearchParams();
67
+ if (options.overlay === "process-info") {
68
+ params.set("overlay", "process-info");
69
+ } else if (options.overlay === "reasoning") {
70
+ params.set("overlay", "reasoning");
71
+ if (options.turnRecordId) {
72
+ params.set("turnRecordId", options.turnRecordId);
73
+ }
74
+ }
75
+ const query = params.toString();
76
+ return query ? `${path}?${query}` : path;
77
+ }
78
+
79
+ export function buildWatchersPath(): string {
80
+ return "/watchers";
81
+ }
82
+
83
+ export function buildSkillsPath(): string {
84
+ return "/skills";
85
+ }
86
+
87
+ export function buildAvailableSkillPath(repositoryId: string, skillId: string): string {
88
+ return `/skills/available/${encodeURIComponent(repositoryId)}/${encodeURIComponent(skillId)}`;
89
+ }
90
+
91
+ export function buildInstalledSkillPath(skillId: string): string {
92
+ return `/skills/installed/${encodeURIComponent(skillId)}`;
93
+ }
94
+
95
+ export function readProcessDetailOverlay(path: string): ProcessDetailOverlayState {
96
+ const params = readSearchParams(path);
97
+ const overlay = params.get("overlay");
98
+ if (overlay === "process-info") {
99
+ return { kind: "process-info" };
100
+ }
101
+ if (overlay === "reasoning") {
102
+ return { kind: "reasoning", turnRecordId: params.get("turnRecordId") };
103
+ }
104
+ return { kind: "none" };
105
+ }
106
+
107
+ function matchPrefixedDetailRoute(
108
+ pathnameWithSearch: string,
109
+ prefix: string,
110
+ page: "process-detail" | "future-launch-detail",
111
+ paramName: "instanceId" | "futureExecutionId",
112
+ ): Route | null {
113
+ const pathname = stripSearchAndHash(pathnameWithSearch);
114
+ if (!pathname.startsWith(prefix)) {
115
+ return null;
116
+ }
117
+
118
+ const id = decodeFirstSegment(pathname, prefix);
119
+ if (!id) {
120
+ return null;
121
+ }
122
+
123
+ return { page, params: { [paramName]: id } };
124
+ }
125
+
126
+ export function matchRoute(pathnameWithSearch: string): Route {
127
+ const pathname = stripSearchAndHash(pathnameWithSearch);
128
+ const processDetailRoute = matchPrefixedDetailRoute(
129
+ pathnameWithSearch,
130
+ "/processes/",
131
+ "process-detail",
132
+ "instanceId",
133
+ );
134
+ if (processDetailRoute) {
135
+ return processDetailRoute;
136
+ }
137
+
138
+ const futureLaunchDetailRoute = matchPrefixedDetailRoute(
139
+ pathnameWithSearch,
140
+ "/future-launches/",
141
+ "future-launch-detail",
142
+ "futureExecutionId",
143
+ );
144
+ if (futureLaunchDetailRoute) {
145
+ return futureLaunchDetailRoute;
146
+ }
147
+
148
+ if (pathname.startsWith("/skills/available/")) {
149
+ const segments = pathname.slice("/skills/available/".length).split("/").filter(Boolean);
150
+ if (segments.length >= 2) {
151
+ return {
152
+ page: "skills",
153
+ params: {
154
+ detailKind: "available",
155
+ repositoryId: decodeURIComponent(segments[0] ?? ""),
156
+ skillId: decodeURIComponent(segments[1] ?? ""),
157
+ },
158
+ };
159
+ }
160
+ }
161
+
162
+ if (pathname.startsWith("/skills/installed/")) {
163
+ const skillId = pathname.slice("/skills/installed/".length).split("/").filter(Boolean)[0];
164
+ if (skillId) {
165
+ return {
166
+ page: "skills",
167
+ params: { detailKind: "installed", skillId: decodeURIComponent(skillId) },
168
+ };
169
+ }
170
+ }
171
+
172
+ if (pathname === "/skills" || pathname === "/skills/") {
173
+ return { page: "skills", params: {} };
174
+ }
175
+
176
+ if (pathname === "/watchers" || pathname === "/watchers/") {
177
+ return { page: "watchers", params: {} };
178
+ }
179
+
180
+ if (pathname === "/processes" || pathname === "/processes/") {
181
+ return { page: "processes", params: {} };
182
+ }
183
+
184
+ if (pathname === "/" || pathname === "/config" || pathname === "/system") {
185
+ const launcher = readSearchParams(pathnameWithSearch).get("launcher");
186
+ return launcher ? { page: "home", params: { launcher } } : { page: "home", params: {} };
187
+ }
188
+
189
+ return { page: "home", params: {} };
190
+ }
@@ -0,0 +1,56 @@
1
+ export type { Page, ProcessDetailOverlayState, ProcessPathOptions, Route } from "./router-logic.js";
2
+ export {
3
+ buildAvailableSkillPath,
4
+ buildFutureLaunchPath,
5
+ buildHomePath,
6
+ buildInstalledSkillPath,
7
+ buildProcessesPath,
8
+ buildProcessPath,
9
+ buildSkillsPath,
10
+ buildWatchersPath,
11
+ matchRoute,
12
+ readProcessDetailOverlay,
13
+ } from "./router-logic.js";
14
+
15
+ import { derived, writable } from "svelte/store";
16
+ import { matchRoute } from "./router-logic.js";
17
+
18
+ interface NavigateOptions {
19
+ replace?: boolean;
20
+ }
21
+
22
+ function readCurrentLocationPath(): string {
23
+ return `${window.location.pathname}${window.location.search}${window.location.hash}`;
24
+ }
25
+
26
+ const currentLocationPath = writable(readCurrentLocationPath());
27
+ export const locationStore = derived(currentLocationPath, (locationPath) => locationPath);
28
+ export const routeStore = derived(currentLocationPath, (locationPath) => matchRoute(locationPath));
29
+
30
+ export function followLink(event: MouseEvent, to: string): void {
31
+ if (
32
+ event.defaultPrevented ||
33
+ event.button !== 0 ||
34
+ event.metaKey ||
35
+ event.ctrlKey ||
36
+ event.shiftKey ||
37
+ event.altKey
38
+ ) {
39
+ return;
40
+ }
41
+ event.preventDefault();
42
+ navigate(to);
43
+ }
44
+
45
+ export function navigate(to: string, options: NavigateOptions = {}) {
46
+ if (options.replace) {
47
+ history.replaceState(null, "", to);
48
+ } else {
49
+ history.pushState(null, "", to);
50
+ }
51
+ currentLocationPath.set(readCurrentLocationPath());
52
+ }
53
+
54
+ window.addEventListener("popstate", () => {
55
+ currentLocationPath.set(readCurrentLocationPath());
56
+ });
@@ -0,0 +1,96 @@
1
+ export interface UiWebSocketLike {
2
+ readyState: number;
3
+ onopen: ((event: Event) => void) | null;
4
+ onmessage: ((event: MessageEvent<unknown>) => void) | null;
5
+ onclose: ((event: Event) => void) | null;
6
+ onerror: ((event: Event) => void) | null;
7
+ send(data: string): void;
8
+ close(): void;
9
+ }
10
+
11
+ export type UiWebSocketCtor = new (url: string) => UiWebSocketLike;
12
+
13
+ export type UiModuleImporter = (url: string) => Promise<unknown>;
14
+
15
+ export interface UiRuntimeTransportConfig {
16
+ apiBaseUrl?: string | null;
17
+ wsUrl?: string | null;
18
+ reconnectDelayMs?: number;
19
+ heartbeatIntervalMs?: number;
20
+ heartbeatTimeoutMs?: number;
21
+ fetchImpl?: typeof fetch;
22
+ webSocketCtor?: UiWebSocketCtor | null;
23
+ moduleImporter?: UiModuleImporter | null;
24
+ }
25
+
26
+ const DEFAULT_RECONNECT_DELAY_MS = 3_000;
27
+ // How often the client sends a {type:"ping"} liveness probe once connected.
28
+ const DEFAULT_HEARTBEAT_INTERVAL_MS = 15_000;
29
+ // How long the client waits for any inbound frame after a ping before it
30
+ // treats the socket as dead and forces a reconnect.
31
+ const DEFAULT_HEARTBEAT_TIMEOUT_MS = 10_000;
32
+ const UI_RUNTIME_TRANSPORT_CONFIG_KEY = Symbol.for("leitwerk.uiRuntimeTransportConfig");
33
+
34
+ type GlobalWithUiRuntimeTransportConfig = typeof globalThis & {
35
+ [UI_RUNTIME_TRANSPORT_CONFIG_KEY]?: UiRuntimeTransportConfig;
36
+ };
37
+
38
+ function getUiRuntimeTransportConfig(): UiRuntimeTransportConfig {
39
+ return (globalThis as GlobalWithUiRuntimeTransportConfig)[UI_RUNTIME_TRANSPORT_CONFIG_KEY] ?? {};
40
+ }
41
+
42
+ export function resolveServerUrl(path: string): string {
43
+ const { apiBaseUrl } = getUiRuntimeTransportConfig();
44
+ if (!apiBaseUrl) {
45
+ return path;
46
+ }
47
+ return new URL(path, apiBaseUrl).toString();
48
+ }
49
+
50
+ export function resolveApiUrl(path: string): string {
51
+ return resolveServerUrl(path);
52
+ }
53
+
54
+ export function resolveWsUrl(): string {
55
+ const { wsUrl } = getUiRuntimeTransportConfig();
56
+ if (wsUrl) {
57
+ return wsUrl;
58
+ }
59
+ const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
60
+ return `${protocol}//${window.location.host}/ws`;
61
+ }
62
+
63
+ export function getReconnectDelayMs(): number {
64
+ return getUiRuntimeTransportConfig().reconnectDelayMs ?? DEFAULT_RECONNECT_DELAY_MS;
65
+ }
66
+
67
+ export function getHeartbeatIntervalMs(): number {
68
+ return getUiRuntimeTransportConfig().heartbeatIntervalMs ?? DEFAULT_HEARTBEAT_INTERVAL_MS;
69
+ }
70
+
71
+ export function getHeartbeatTimeoutMs(): number {
72
+ return getUiRuntimeTransportConfig().heartbeatTimeoutMs ?? DEFAULT_HEARTBEAT_TIMEOUT_MS;
73
+ }
74
+
75
+ export function getFetchImpl(): typeof fetch {
76
+ return getUiRuntimeTransportConfig().fetchImpl ?? globalThis.fetch.bind(globalThis);
77
+ }
78
+
79
+ export function getWebSocketCtor(): UiWebSocketCtor {
80
+ const { webSocketCtor } = getUiRuntimeTransportConfig();
81
+ if (webSocketCtor) {
82
+ return webSocketCtor;
83
+ }
84
+ if (typeof WebSocket !== "undefined") {
85
+ return WebSocket as unknown as UiWebSocketCtor;
86
+ }
87
+ throw new Error("Missing WebSocket implementation");
88
+ }
89
+
90
+ export function getModuleImporter(): UiModuleImporter {
91
+ const { moduleImporter } = getUiRuntimeTransportConfig();
92
+ if (moduleImporter) {
93
+ return moduleImporter;
94
+ }
95
+ return (url: string) => import(/* @vite-ignore */ url);
96
+ }
@@ -0,0 +1,13 @@
1
+ import type { ProcessLaunchConfigurationView } from "./api.js";
2
+
3
+ /** Empty launch configuration read model for process-detail test fixtures. */
4
+ export function emptyLaunchConfiguration(): ProcessLaunchConfigurationView {
5
+ return {
6
+ launcherId: null,
7
+ launcherLabel: null,
8
+ launcherSchemaTitle: null,
9
+ paramsParseError: null,
10
+ parameters: [],
11
+ projects: [],
12
+ };
13
+ }
@@ -0,0 +1,104 @@
1
+ import {
2
+ type ProcessAttentionTarget,
3
+ WS_PROCESS_TYPES,
4
+ type WsFrame,
5
+ type WsPayloadByType,
6
+ } from "@leitwerk-dev/protocol";
7
+ import { get, writable } from "svelte/store";
8
+ import { queuePendingProcessToastFocus } from "./process-toast-focus.svelte.js";
9
+ import { buildProcessPath, navigate } from "./router.svelte.js";
10
+
11
+ export type ToastItem = WsPayloadByType[typeof WS_PROCESS_TYPES.TOAST] & {
12
+ id: string;
13
+ createdAt: string;
14
+ };
15
+
16
+ const FALLBACK_TOAST_TTL_MS = 6_000;
17
+
18
+ export const toastStore = writable<ToastItem[]>([]);
19
+
20
+ const toastTimers = new Map<string, ReturnType<typeof setTimeout>>();
21
+
22
+ function nextToastId(): string {
23
+ return `toast_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
24
+ }
25
+
26
+ function clearToastTimer(id: string) {
27
+ const timer = toastTimers.get(id);
28
+ if (!timer) {
29
+ return;
30
+ }
31
+ clearTimeout(timer);
32
+ toastTimers.delete(id);
33
+ }
34
+
35
+ export function dismissToast(id: string): void {
36
+ clearToastTimer(id);
37
+ toastStore.update((items) => items.filter((toast) => toast.id !== id));
38
+ }
39
+
40
+ export function resolveToastFocusTarget(eventType: string): ProcessAttentionTarget | null {
41
+ switch (eventType) {
42
+ case "action_required":
43
+ case "turn_failed":
44
+ case "worker_failed":
45
+ return { kind: eventType };
46
+ default:
47
+ return null;
48
+ }
49
+ }
50
+
51
+ export function openToast(id: string): void {
52
+ const toast = get(toastStore).find((item) => item.id === id);
53
+ if (!toast) {
54
+ return;
55
+ }
56
+ const target = toast.focusTarget ?? resolveToastFocusTarget(toast.eventType);
57
+ if (target) {
58
+ queuePendingProcessToastFocus({
59
+ instanceId: toast.instanceId,
60
+ target,
61
+ queuedAt: new Date().toISOString(),
62
+ });
63
+ }
64
+ navigate(buildProcessPath(toast.instanceId));
65
+ dismissToast(id);
66
+ }
67
+
68
+ export function dismissLatestToast(): void {
69
+ const latestToast = get(toastStore).at(-1);
70
+ if (!latestToast) {
71
+ return;
72
+ }
73
+ dismissToast(latestToast.id);
74
+ }
75
+
76
+ export function pushToast(
77
+ payload: WsPayloadByType[typeof WS_PROCESS_TYPES.TOAST],
78
+ ttlMs = Number.isFinite(payload.ttlMs) ? Math.max(0, payload.ttlMs) : FALLBACK_TOAST_TTL_MS,
79
+ ): void {
80
+ if (get(toastStore).some((toast) => toast.dedupeKey === payload.dedupeKey)) {
81
+ return;
82
+ }
83
+
84
+ const item: ToastItem = {
85
+ id: nextToastId(),
86
+ createdAt: new Date().toISOString(),
87
+ ...payload,
88
+ };
89
+ toastStore.update((items) => [...items, item]);
90
+ toastTimers.set(
91
+ item.id,
92
+ setTimeout(() => {
93
+ dismissToast(item.id);
94
+ }, ttlMs),
95
+ );
96
+ }
97
+
98
+ export function handleToastFrame(frame: WsFrame): boolean {
99
+ if (frame.type !== WS_PROCESS_TYPES.TOAST) {
100
+ return false;
101
+ }
102
+ pushToast(frame.payload);
103
+ return true;
104
+ }
@@ -0,0 +1,66 @@
1
+ import { type PrimaryPathToolCallSnapshot, readValueAtPath } from "@leitwerk-dev/protocol";
2
+ import type { ToolCallRendererDefinition, ToolCallRendererFieldDefinition } from "./api";
3
+
4
+ export interface ResolvedToolCallRendererField {
5
+ id: string;
6
+ label: string;
7
+ kind: ToolCallRendererFieldDefinition["kind"];
8
+ value: unknown;
9
+ }
10
+
11
+ function sourceValue(
12
+ toolCall: Pick<PrimaryPathToolCallSnapshot, "arguments" | "result">,
13
+ source: ToolCallRendererFieldDefinition["source"],
14
+ ): unknown {
15
+ return source === "arguments" ? toolCall.arguments : toolCall.result;
16
+ }
17
+
18
+ function normalizeRenderableValue(
19
+ field: ToolCallRendererFieldDefinition,
20
+ value: unknown,
21
+ ): unknown | null {
22
+ if (field.kind === "json") {
23
+ return value === undefined ? null : value;
24
+ }
25
+ if (typeof value !== "string") {
26
+ return null;
27
+ }
28
+ return value.trim() === "" ? null : value;
29
+ }
30
+
31
+ export function createToolRendererIndex(
32
+ definitions: readonly ToolCallRendererDefinition[],
33
+ ): Record<string, ToolCallRendererDefinition> {
34
+ return Object.fromEntries(definitions.map((definition) => [definition.toolName, definition]));
35
+ }
36
+
37
+ export function resolveToolRenderer(
38
+ index: Record<string, ToolCallRendererDefinition>,
39
+ toolName: string,
40
+ ): ToolCallRendererDefinition | null {
41
+ return index[toolName] ?? null;
42
+ }
43
+
44
+ export function resolveToolRendererFields(
45
+ toolCall: Pick<PrimaryPathToolCallSnapshot, "arguments" | "result">,
46
+ renderer: ToolCallRendererDefinition | null | undefined,
47
+ ): ResolvedToolCallRendererField[] {
48
+ if (!renderer) {
49
+ return [];
50
+ }
51
+ const resolved: ResolvedToolCallRendererField[] = [];
52
+ for (const field of renderer.fields) {
53
+ const rawValue = readValueAtPath(sourceValue(toolCall, field.source), field.path);
54
+ const normalizedValue = normalizeRenderableValue(field, rawValue);
55
+ if (normalizedValue === null) {
56
+ continue;
57
+ }
58
+ resolved.push({
59
+ id: field.id,
60
+ label: field.label,
61
+ kind: field.kind,
62
+ value: normalizedValue,
63
+ });
64
+ }
65
+ return resolved;
66
+ }