@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
package/src/lib/api.ts
ADDED
|
@@ -0,0 +1,970 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ProcessInstance,
|
|
3
|
+
ProcessProject,
|
|
4
|
+
ProcessQuestionRequest,
|
|
5
|
+
QuestionAnswerDraft,
|
|
6
|
+
} from "@leitwerk-dev/domain";
|
|
7
|
+
import type { PrimaryPathSnapshot } from "@leitwerk-dev/protocol";
|
|
8
|
+
import type {
|
|
9
|
+
AuthMeResponseBody,
|
|
10
|
+
CronPreviewResponseBody,
|
|
11
|
+
ErrorResponseBody,
|
|
12
|
+
FutureExecutionSummary as FullFutureExecutionSummary,
|
|
13
|
+
FutureExecutionDetailResponseBody,
|
|
14
|
+
FutureExecutionOverviewItem,
|
|
15
|
+
FutureLaunchSummary,
|
|
16
|
+
InstalledSkillCatalogDetail,
|
|
17
|
+
InstalledSkillCatalogDetailResponseBody,
|
|
18
|
+
LauncherDefaultsResponseBody,
|
|
19
|
+
LauncherModelConfigDefaults,
|
|
20
|
+
LauncherModelConfigPreview,
|
|
21
|
+
LauncherModelConfigPreviewResponseBody,
|
|
22
|
+
LauncherMutationResponseBody,
|
|
23
|
+
LauncherOptionsResponseBody,
|
|
24
|
+
LauncherRecentValuesResponseBody,
|
|
25
|
+
LaunchersResponseBody,
|
|
26
|
+
ModelProviderOptionsResponseBody,
|
|
27
|
+
PrimaryPathSnapshotResponseBody,
|
|
28
|
+
ProcessActionModelPreview,
|
|
29
|
+
ProcessActionModelPreviewResponseBody,
|
|
30
|
+
ProcessBrowseResponseBody,
|
|
31
|
+
ProcessDetailUiSnapshotResponseBody,
|
|
32
|
+
ProcessDiagnosticsData,
|
|
33
|
+
ProcessDiagnosticsResponseBody,
|
|
34
|
+
ProcessesOverviewResponseBody,
|
|
35
|
+
ProcessOverviewItem,
|
|
36
|
+
ProcessRetryConfig,
|
|
37
|
+
ProcessRetryConfigResponseBody,
|
|
38
|
+
QuestionRequestMutationResponseBody,
|
|
39
|
+
ScheduleConfigInput,
|
|
40
|
+
ScheduledActionDetail,
|
|
41
|
+
ScheduledActionMutationResponseBody,
|
|
42
|
+
SkillCatalogDetail,
|
|
43
|
+
SkillCatalogDetailResponseBody,
|
|
44
|
+
SkillsCatalogResponseBody,
|
|
45
|
+
TurnReasoningDetailResponseBody,
|
|
46
|
+
UiLauncherSummary,
|
|
47
|
+
WatcherSummary,
|
|
48
|
+
WatchersResponseBody,
|
|
49
|
+
} from "@leitwerk-dev/protocol/http-contracts";
|
|
50
|
+
import type {
|
|
51
|
+
LauncherFieldOptionDefinition,
|
|
52
|
+
LauncherValidationError,
|
|
53
|
+
} from "@leitwerk-dev/protocol/launcher-contract";
|
|
54
|
+
import * as v from "valibot";
|
|
55
|
+
import { formatDefinition } from "./format.js";
|
|
56
|
+
import { getFetchImpl, resolveApiUrl } from "./runtime-config";
|
|
57
|
+
|
|
58
|
+
export class ApiResponseError extends Error {
|
|
59
|
+
readonly status: number;
|
|
60
|
+
|
|
61
|
+
constructor(message: string, status: number) {
|
|
62
|
+
super(message);
|
|
63
|
+
this.name = "ApiResponseError";
|
|
64
|
+
this.status = status;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type {
|
|
69
|
+
ProcessFlowEdge,
|
|
70
|
+
ProcessFlowEdgeKind,
|
|
71
|
+
ProcessFlowEndState,
|
|
72
|
+
ProcessFlowNode,
|
|
73
|
+
ProcessFlowNodeRole,
|
|
74
|
+
ProcessFlowView,
|
|
75
|
+
} from "@leitwerk-dev/domain";
|
|
76
|
+
export type {
|
|
77
|
+
FormFieldDefinition,
|
|
78
|
+
FormFieldOptionDefinition,
|
|
79
|
+
} from "@leitwerk-dev/protocol/form-contract";
|
|
80
|
+
export type {
|
|
81
|
+
FilesystemWatcherSummary,
|
|
82
|
+
FutureExecutionOverviewItem,
|
|
83
|
+
FutureLaunchSummary,
|
|
84
|
+
GitLabMrWatcherSummary,
|
|
85
|
+
InstalledSkillCatalogDetail,
|
|
86
|
+
InstalledSkillCatalogItem,
|
|
87
|
+
InstanceTreeNodeSummary,
|
|
88
|
+
JiraWatcherSummary,
|
|
89
|
+
LauncherDefaultModelPreview,
|
|
90
|
+
LauncherModelConfigDefaults,
|
|
91
|
+
LauncherModelConfigPreview,
|
|
92
|
+
LauncherModelConfigSchema,
|
|
93
|
+
LauncherTurnModelConfigPreview,
|
|
94
|
+
ModelProfileOptionSummary,
|
|
95
|
+
PiSessionContentBlock,
|
|
96
|
+
PiSessionEntry,
|
|
97
|
+
PiSessionImageContentBlock,
|
|
98
|
+
PiSessionMessageRecord,
|
|
99
|
+
PiSessionTextContentBlock,
|
|
100
|
+
PiSessionThinkingContentBlock,
|
|
101
|
+
PiSessionToolCallContentBlock,
|
|
102
|
+
PiSessionUsageSnapshot,
|
|
103
|
+
ProcessActionFieldDefinition,
|
|
104
|
+
ProcessActionFormDefinition,
|
|
105
|
+
ProcessActionModelPreview,
|
|
106
|
+
ProcessActionModelResolutionPreview,
|
|
107
|
+
ProcessActionPreviewSummary,
|
|
108
|
+
ProcessActionSummary,
|
|
109
|
+
ProcessBrowseFacets,
|
|
110
|
+
ProcessBrowseItem,
|
|
111
|
+
ProcessBrowsePagination,
|
|
112
|
+
ProcessBrowseResponseBody,
|
|
113
|
+
ProcessDetailUiSnapshotResponseBody,
|
|
114
|
+
ProcessDiagnosticsData,
|
|
115
|
+
ProcessExternalTriggerSummary,
|
|
116
|
+
ProcessInstanceTreeResponseBody,
|
|
117
|
+
ProcessLaunchConfigurationParameterView,
|
|
118
|
+
ProcessLaunchConfigurationProjectView,
|
|
119
|
+
ProcessLaunchConfigurationView,
|
|
120
|
+
ProcessListItem,
|
|
121
|
+
ProcessModelConfigurationView,
|
|
122
|
+
ProcessOverviewItem,
|
|
123
|
+
ProcessRetryConfig,
|
|
124
|
+
ProcessRunDetailsView,
|
|
125
|
+
ProcessRunToolParameterView,
|
|
126
|
+
ProcessRunToolView,
|
|
127
|
+
ProcessRunTurnView,
|
|
128
|
+
ProcessSelectedTurnSummary,
|
|
129
|
+
ProcessTurnModelConfigurationView,
|
|
130
|
+
ScheduleConfigInput,
|
|
131
|
+
ScheduledActionDetail,
|
|
132
|
+
ScheduleMode,
|
|
133
|
+
SkillCatalogDetail,
|
|
134
|
+
SkillCatalogItem,
|
|
135
|
+
SkillRepositorySummary,
|
|
136
|
+
SkillsCatalogResponseBody,
|
|
137
|
+
SkillUsageProcessSummary,
|
|
138
|
+
SkillUsageSummary,
|
|
139
|
+
TurnReasoningDetailResponseBody,
|
|
140
|
+
TurnTracePreview,
|
|
141
|
+
TurnTraceSnapshot,
|
|
142
|
+
UiLauncherSummary,
|
|
143
|
+
WatcherLaunchModelSummary,
|
|
144
|
+
WatcherSummary,
|
|
145
|
+
} from "@leitwerk-dev/protocol/http-contracts";
|
|
146
|
+
export type {
|
|
147
|
+
LauncherCardMetadata,
|
|
148
|
+
LauncherFieldDefinition,
|
|
149
|
+
LauncherFieldOptionDefinition,
|
|
150
|
+
LauncherSchemaDefinition,
|
|
151
|
+
LauncherValidationError,
|
|
152
|
+
UiLauncherSummaryBase,
|
|
153
|
+
} from "@leitwerk-dev/protocol/launcher-contract";
|
|
154
|
+
export type {
|
|
155
|
+
ToolCallRendererDefinition,
|
|
156
|
+
ToolCallRendererFieldDefinition,
|
|
157
|
+
} from "@leitwerk-dev/protocol/tool-renderer-contract";
|
|
158
|
+
|
|
159
|
+
export type ProcessDetailData = ProcessDetailUiSnapshotResponseBody;
|
|
160
|
+
export type FutureExecutionSummary = FutureExecutionOverviewItem;
|
|
161
|
+
export type FutureActionSummary = Extract<FutureExecutionOverviewItem, { kind: "action" }>;
|
|
162
|
+
export type FutureLaunchOverviewSummary = Extract<FutureExecutionOverviewItem, { kind: "launch" }>;
|
|
163
|
+
export type FullFutureExecution = FullFutureExecutionSummary;
|
|
164
|
+
|
|
165
|
+
export async function submitQuestionAnswers(input: {
|
|
166
|
+
instanceId: string;
|
|
167
|
+
requestId: string;
|
|
168
|
+
draft: QuestionAnswerDraft[];
|
|
169
|
+
}): Promise<ProcessQuestionRequest> {
|
|
170
|
+
const response = await getFetchImpl()(
|
|
171
|
+
resolveApiUrl(
|
|
172
|
+
`/api/processes/${encodeURIComponent(input.instanceId)}/question-requests/${encodeURIComponent(input.requestId)}/answers`,
|
|
173
|
+
),
|
|
174
|
+
{
|
|
175
|
+
method: "POST",
|
|
176
|
+
headers: { "content-type": "application/json" },
|
|
177
|
+
body: JSON.stringify({ draft: input.draft }),
|
|
178
|
+
},
|
|
179
|
+
);
|
|
180
|
+
if (!response.ok) {
|
|
181
|
+
const body = await tryReadJson(response);
|
|
182
|
+
throw new ApiResponseError(readErrorMessage(body) ?? "Couldn't send answers", response.status);
|
|
183
|
+
}
|
|
184
|
+
return (
|
|
185
|
+
await readJsonObject<QuestionRequestMutationResponseBody>(
|
|
186
|
+
response,
|
|
187
|
+
"Malformed question response",
|
|
188
|
+
)
|
|
189
|
+
).request;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export async function fetchAuthMe(): Promise<AuthMeResponseBody> {
|
|
193
|
+
const res = await getFetchImpl()(resolveApiUrl("/api/auth/me"));
|
|
194
|
+
if (res.status === 401) {
|
|
195
|
+
return { authEnabled: true, actor: null };
|
|
196
|
+
}
|
|
197
|
+
if (!res.ok) {
|
|
198
|
+
throw new ApiResponseError(`Couldn't load authentication status: ${res.status}`, res.status);
|
|
199
|
+
}
|
|
200
|
+
return readJsonObject<AuthMeResponseBody>(res, "Malformed auth status response");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export interface AuthMeRetryOptions {
|
|
204
|
+
maxAttempts?: number;
|
|
205
|
+
baseDelayMs?: number;
|
|
206
|
+
maxDelayMs?: number;
|
|
207
|
+
signal?: AbortSignal;
|
|
208
|
+
onRetry?: (error: unknown, attempt: number, delayMs: number) => void;
|
|
209
|
+
sleep?: (delayMs: number, signal?: AbortSignal) => Promise<void>;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function defaultRetrySleep(delayMs: number, signal?: AbortSignal): Promise<void> {
|
|
213
|
+
return new Promise((resolve, reject) => {
|
|
214
|
+
if (signal?.aborted) {
|
|
215
|
+
reject(signal.reason ?? new DOMException("Aborted", "AbortError"));
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const onAbort = () => {
|
|
219
|
+
clearTimeout(timer);
|
|
220
|
+
reject(signal?.reason ?? new DOMException("Aborted", "AbortError"));
|
|
221
|
+
};
|
|
222
|
+
const timer = setTimeout(() => {
|
|
223
|
+
signal?.removeEventListener("abort", onAbort);
|
|
224
|
+
resolve();
|
|
225
|
+
}, delayMs);
|
|
226
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function retryableAuthBootstrapError(error: unknown): boolean {
|
|
231
|
+
return error instanceof ApiResponseError
|
|
232
|
+
? [502, 503, 504].includes(error.status)
|
|
233
|
+
: error instanceof TypeError;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export async function fetchAuthMeWithRetry(
|
|
237
|
+
options: AuthMeRetryOptions = {},
|
|
238
|
+
): Promise<AuthMeResponseBody> {
|
|
239
|
+
const maxAttempts = options.maxAttempts ?? 60;
|
|
240
|
+
const baseDelayMs = options.baseDelayMs ?? 250;
|
|
241
|
+
const maxDelayMs = options.maxDelayMs ?? 2_000;
|
|
242
|
+
const sleep = options.sleep ?? defaultRetrySleep;
|
|
243
|
+
let attempt = 0;
|
|
244
|
+
while (true) {
|
|
245
|
+
attempt += 1;
|
|
246
|
+
try {
|
|
247
|
+
return await fetchAuthMe();
|
|
248
|
+
} catch (error) {
|
|
249
|
+
if (
|
|
250
|
+
options.signal?.aborted ||
|
|
251
|
+
!retryableAuthBootstrapError(error) ||
|
|
252
|
+
attempt >= maxAttempts
|
|
253
|
+
) {
|
|
254
|
+
throw error;
|
|
255
|
+
}
|
|
256
|
+
const delayMs = Math.min(maxDelayMs, baseDelayMs * 2 ** Math.min(attempt - 1, 8));
|
|
257
|
+
options.onRetry?.(error, attempt, delayMs);
|
|
258
|
+
await sleep(delayMs, options.signal);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export type LauncherSubmitResult =
|
|
264
|
+
| {
|
|
265
|
+
kind: "success";
|
|
266
|
+
process: ProcessInstance;
|
|
267
|
+
projects: ProcessProject[];
|
|
268
|
+
}
|
|
269
|
+
| {
|
|
270
|
+
kind: "scheduled";
|
|
271
|
+
futureExecution: FutureLaunchSummary;
|
|
272
|
+
}
|
|
273
|
+
| {
|
|
274
|
+
kind: "partial_success";
|
|
275
|
+
status: number;
|
|
276
|
+
warning: string;
|
|
277
|
+
process: ProcessInstance;
|
|
278
|
+
projects: ProcessProject[];
|
|
279
|
+
}
|
|
280
|
+
| {
|
|
281
|
+
kind: "validation_error";
|
|
282
|
+
status: number;
|
|
283
|
+
errors: LauncherValidationError[];
|
|
284
|
+
}
|
|
285
|
+
| {
|
|
286
|
+
kind: "failure";
|
|
287
|
+
status: number;
|
|
288
|
+
error: string;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const unknownRecordSchema = v.pipe(
|
|
292
|
+
v.unknown(),
|
|
293
|
+
v.check(
|
|
294
|
+
(value) => typeof value === "object" && value !== null && !Array.isArray(value),
|
|
295
|
+
"Expected object",
|
|
296
|
+
),
|
|
297
|
+
v.record(v.string(), v.unknown()),
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
async function tryReadJson(response: Response): Promise<unknown> {
|
|
301
|
+
try {
|
|
302
|
+
return await response.json();
|
|
303
|
+
} catch {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async function readJsonObject<T extends object>(response: Response, context: string): Promise<T> {
|
|
309
|
+
const body = await tryReadJson(response);
|
|
310
|
+
if (!v.safeParse(unknownRecordSchema, body).success) {
|
|
311
|
+
throw new Error(`${context}: response body must be a JSON object`);
|
|
312
|
+
}
|
|
313
|
+
return body as T;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function readOptionalString(value: unknown): string | null {
|
|
317
|
+
return typeof value === "string" ? value : null;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function readErrorMessage(body: unknown): string | null {
|
|
321
|
+
const response = body as (ErrorResponseBody & { message?: unknown }) | null;
|
|
322
|
+
const error = readOptionalString(response?.error) ?? readOptionalString(response?.message);
|
|
323
|
+
return error && error.trim() !== "" ? error : null;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
async function requireSuccessfulMutation(response: Response, fallbackError: string): Promise<void> {
|
|
327
|
+
if (response.ok) return;
|
|
328
|
+
const body = await tryReadJson(response);
|
|
329
|
+
throw new Error(readErrorMessage(body) ?? `${fallbackError}: ${response.status}`);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function isLauncherValidationError(value: unknown): value is LauncherValidationError {
|
|
333
|
+
const parsedValue = v.safeParse(unknownRecordSchema, value);
|
|
334
|
+
if (!parsedValue.success) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
const record = parsedValue.output;
|
|
338
|
+
return (
|
|
339
|
+
typeof record.code === "string" &&
|
|
340
|
+
typeof record.message === "string" &&
|
|
341
|
+
(record.fieldId === undefined || typeof record.fieldId === "string")
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function readLauncherValidationErrors(body: unknown): LauncherValidationError[] {
|
|
346
|
+
const parsedBody = v.safeParse(unknownRecordSchema, body);
|
|
347
|
+
if (!parsedBody.success || !Array.isArray(parsedBody.output.errors)) {
|
|
348
|
+
return [];
|
|
349
|
+
}
|
|
350
|
+
return parsedBody.output.errors.filter(isLauncherValidationError);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export async function fetchProcessesList(): Promise<{
|
|
354
|
+
processes: ProcessOverviewItem[];
|
|
355
|
+
futureExecutions: FutureExecutionOverviewItem[];
|
|
356
|
+
}> {
|
|
357
|
+
const res = await getFetchImpl()(resolveApiUrl("/api/processes/overview"));
|
|
358
|
+
if (!res.ok) throw new Error(`Couldn't load the process list: ${res.status}`);
|
|
359
|
+
return readJsonObject<ProcessesOverviewResponseBody>(res, "Malformed process overview response");
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export interface ProcessBrowseRequest {
|
|
363
|
+
limit?: number;
|
|
364
|
+
offset?: number;
|
|
365
|
+
query?: string;
|
|
366
|
+
processType?: string;
|
|
367
|
+
status?: string;
|
|
368
|
+
sortKey?: "status" | "title" | "timeline";
|
|
369
|
+
sortDirection?: "asc" | "desc";
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export async function fetchProcessBrowse(
|
|
373
|
+
request: ProcessBrowseRequest = {},
|
|
374
|
+
): Promise<ProcessBrowseResponseBody> {
|
|
375
|
+
const params = new URLSearchParams();
|
|
376
|
+
for (const [key, value] of Object.entries(request)) {
|
|
377
|
+
if (value !== undefined && value !== "") {
|
|
378
|
+
params.set(key, String(value));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
const query = params.size > 0 ? `?${params.toString()}` : "";
|
|
382
|
+
const res = await getFetchImpl()(resolveApiUrl(`/api/processes/browse${query}`));
|
|
383
|
+
if (!res.ok) throw new Error(`Couldn't browse processes: ${res.status}`);
|
|
384
|
+
return readJsonObject<ProcessBrowseResponseBody>(res, "Malformed process browse response");
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export async function fetchLaunchers(): Promise<UiLauncherSummary[]> {
|
|
388
|
+
const res = await getFetchImpl()(resolveApiUrl("/api/launchers"));
|
|
389
|
+
if (!res.ok) throw new Error(`Couldn't load available processes: ${res.status}`);
|
|
390
|
+
const body = await readJsonObject<LaunchersResponseBody>(res, "Malformed launchers response");
|
|
391
|
+
return body.launchers;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export async function fetchWatchers(): Promise<WatcherSummary[]> {
|
|
395
|
+
const res = await getFetchImpl()(resolveApiUrl("/api/watchers"));
|
|
396
|
+
if (!res.ok) throw new Error(`Couldn't load registered watchers: ${res.status}`);
|
|
397
|
+
const body = await readJsonObject<WatchersResponseBody>(res, "Malformed watchers response");
|
|
398
|
+
return body.watchers;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export async function fetchSkills(): Promise<SkillsCatalogResponseBody> {
|
|
402
|
+
const res = await getFetchImpl()(resolveApiUrl("/api/skills"));
|
|
403
|
+
if (!res.ok) throw new Error(`Couldn't load the skill catalog: ${res.status}`);
|
|
404
|
+
return readJsonObject<SkillsCatalogResponseBody>(res, "Malformed skill catalog response");
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export async function refreshSkills(): Promise<SkillsCatalogResponseBody> {
|
|
408
|
+
const res = await getFetchImpl()(resolveApiUrl("/api/skills/refresh"), { method: "POST" });
|
|
409
|
+
if (!res.ok) throw new Error(`Couldn't refresh skill repositories: ${res.status}`);
|
|
410
|
+
return readJsonObject<SkillsCatalogResponseBody>(res, "Malformed skill catalog response");
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export async function fetchSkillDetail(
|
|
414
|
+
repositoryId: string,
|
|
415
|
+
skillId: string,
|
|
416
|
+
): Promise<SkillCatalogDetail> {
|
|
417
|
+
const res = await getFetchImpl()(
|
|
418
|
+
resolveApiUrl(
|
|
419
|
+
`/api/skills/available/${encodeURIComponent(repositoryId)}/${encodeURIComponent(skillId)}`,
|
|
420
|
+
),
|
|
421
|
+
);
|
|
422
|
+
if (!res.ok) throw new Error(`Couldn't load skill details: ${res.status}`);
|
|
423
|
+
const body = await readJsonObject<SkillCatalogDetailResponseBody>(
|
|
424
|
+
res,
|
|
425
|
+
"Malformed skill detail response",
|
|
426
|
+
);
|
|
427
|
+
return body.skill;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export async function fetchInstalledSkillDetail(
|
|
431
|
+
skillId: string,
|
|
432
|
+
): Promise<InstalledSkillCatalogDetail> {
|
|
433
|
+
const res = await getFetchImpl()(
|
|
434
|
+
resolveApiUrl(`/api/skills/installed/${encodeURIComponent(skillId)}`),
|
|
435
|
+
);
|
|
436
|
+
if (!res.ok) throw new Error(`Couldn't load installed skill details: ${res.status}`);
|
|
437
|
+
const body = await readJsonObject<InstalledSkillCatalogDetailResponseBody>(
|
|
438
|
+
res,
|
|
439
|
+
"Malformed installed skill detail response",
|
|
440
|
+
);
|
|
441
|
+
return body.skill;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export async function registerSkill(repositoryId: string, skillId: string): Promise<void> {
|
|
445
|
+
const res = await getFetchImpl()(
|
|
446
|
+
resolveApiUrl(
|
|
447
|
+
`/api/skills/available/${encodeURIComponent(repositoryId)}/${encodeURIComponent(skillId)}/register`,
|
|
448
|
+
),
|
|
449
|
+
{ method: "POST" },
|
|
450
|
+
);
|
|
451
|
+
await requireSuccessfulMutation(res, "Couldn't register the skill");
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export async function removeSkill(skillId: string): Promise<void> {
|
|
455
|
+
const res = await getFetchImpl()(
|
|
456
|
+
resolveApiUrl(`/api/skills/installed/${encodeURIComponent(skillId)}`),
|
|
457
|
+
{ method: "DELETE" },
|
|
458
|
+
);
|
|
459
|
+
await requireSuccessfulMutation(res, "Couldn't remove the skill");
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export async function fetchLauncherDefaults(launcherId: string): Promise<{
|
|
463
|
+
defaults: Record<string, unknown>;
|
|
464
|
+
title: string | null;
|
|
465
|
+
modelConfig: LauncherModelConfigDefaults;
|
|
466
|
+
warnings?: LauncherValidationError[];
|
|
467
|
+
}> {
|
|
468
|
+
const res = await getFetchImpl()(
|
|
469
|
+
resolveApiUrl(`/api/launchers/${encodeURIComponent(launcherId)}/defaults`),
|
|
470
|
+
);
|
|
471
|
+
if (!res.ok) throw new Error(`Couldn't load default values: ${res.status}`);
|
|
472
|
+
return readJsonObject<LauncherDefaultsResponseBody>(res, "Malformed launcher defaults response");
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export async function fetchLauncherRecentValues(
|
|
476
|
+
launcherId: string,
|
|
477
|
+
): Promise<Record<string, readonly string[]>> {
|
|
478
|
+
const res = await getFetchImpl()(
|
|
479
|
+
resolveApiUrl(`/api/launchers/${encodeURIComponent(launcherId)}/recent-values`),
|
|
480
|
+
);
|
|
481
|
+
if (!res.ok) throw new Error(`Couldn't load recent launcher values: ${res.status}`);
|
|
482
|
+
const body = await readJsonObject<LauncherRecentValuesResponseBody>(
|
|
483
|
+
res,
|
|
484
|
+
"Malformed launcher recent values response",
|
|
485
|
+
);
|
|
486
|
+
return body.values;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
export async function fetchLauncherOptions(
|
|
490
|
+
launcherId: string,
|
|
491
|
+
launcherInput: Record<string, unknown>,
|
|
492
|
+
): Promise<Record<string, readonly LauncherFieldOptionDefinition[]>> {
|
|
493
|
+
const res = await getFetchImpl()(
|
|
494
|
+
resolveApiUrl(`/api/launchers/${encodeURIComponent(launcherId)}/options`),
|
|
495
|
+
{
|
|
496
|
+
method: "POST",
|
|
497
|
+
headers: { "content-type": "application/json" },
|
|
498
|
+
body: JSON.stringify({ launcherInput }),
|
|
499
|
+
},
|
|
500
|
+
);
|
|
501
|
+
if (!res.ok) throw new Error(`Couldn't refresh the available options: ${res.status}`);
|
|
502
|
+
const body = await readJsonObject<LauncherOptionsResponseBody>(
|
|
503
|
+
res,
|
|
504
|
+
"Malformed launcher options response",
|
|
505
|
+
);
|
|
506
|
+
return body.options;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
export async function fetchLauncherModelConfigPreview(
|
|
510
|
+
launcherId: string,
|
|
511
|
+
launcherInput: Record<string, unknown>,
|
|
512
|
+
modelConfig: LauncherModelConfigDefaults = {},
|
|
513
|
+
): Promise<LauncherModelConfigPreview> {
|
|
514
|
+
const res = await getFetchImpl()(
|
|
515
|
+
resolveApiUrl(`/api/launchers/${encodeURIComponent(launcherId)}/model-config-preview`),
|
|
516
|
+
{
|
|
517
|
+
method: "POST",
|
|
518
|
+
headers: { "content-type": "application/json" },
|
|
519
|
+
body: JSON.stringify({ launcherInput, modelConfig }),
|
|
520
|
+
},
|
|
521
|
+
);
|
|
522
|
+
if (!res.ok) throw new Error(`Couldn't refresh the model preview: ${res.status}`);
|
|
523
|
+
const body = await readJsonObject<LauncherModelConfigPreviewResponseBody>(
|
|
524
|
+
res,
|
|
525
|
+
"Malformed launcher model preview response",
|
|
526
|
+
);
|
|
527
|
+
return body.preview;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
async function parseLauncherErrorResponse(
|
|
531
|
+
res: Response,
|
|
532
|
+
fallbackMessagePrefix: string,
|
|
533
|
+
): Promise<LauncherSubmitResult> {
|
|
534
|
+
const body = await tryReadJson(res);
|
|
535
|
+
const errors = readLauncherValidationErrors(body);
|
|
536
|
+
if (errors.length > 0) {
|
|
537
|
+
return { kind: "validation_error", status: res.status, errors };
|
|
538
|
+
}
|
|
539
|
+
return {
|
|
540
|
+
kind: "failure",
|
|
541
|
+
status: res.status,
|
|
542
|
+
error: readErrorMessage(body) ?? `${fallbackMessagePrefix}: ${res.status}`,
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
export async function launchLauncher(
|
|
547
|
+
launcherId: string,
|
|
548
|
+
title: string | null,
|
|
549
|
+
launcherInput: Record<string, unknown>,
|
|
550
|
+
modelConfig: LauncherModelConfigDefaults = {},
|
|
551
|
+
schedule: ScheduleConfigInput = { mode: "now" },
|
|
552
|
+
skillIds: readonly string[] = [],
|
|
553
|
+
): Promise<LauncherSubmitResult> {
|
|
554
|
+
const res = await getFetchImpl()(
|
|
555
|
+
resolveApiUrl(`/api/launchers/${encodeURIComponent(launcherId)}/launch`),
|
|
556
|
+
{
|
|
557
|
+
method: "POST",
|
|
558
|
+
headers: { "content-type": "application/json" },
|
|
559
|
+
body: JSON.stringify({ title, launcherInput, modelConfig, schedule, skillIds }),
|
|
560
|
+
},
|
|
561
|
+
);
|
|
562
|
+
if (!res.ok) {
|
|
563
|
+
return parseLauncherErrorResponse(res, "Couldn't start this process");
|
|
564
|
+
}
|
|
565
|
+
const body = await readJsonObject<LauncherMutationResponseBody>(
|
|
566
|
+
res,
|
|
567
|
+
"Malformed launcher launch response",
|
|
568
|
+
);
|
|
569
|
+
const projects = body.projects ?? [];
|
|
570
|
+
const errorMessage = body.error ?? `Couldn't start this process: ${res.status}`;
|
|
571
|
+
if (res.status === 201 && body.futureExecution) {
|
|
572
|
+
return { kind: "scheduled", futureExecution: body.futureExecution };
|
|
573
|
+
}
|
|
574
|
+
if (res.status === 201 && body.process) {
|
|
575
|
+
return { kind: "success", process: body.process, projects };
|
|
576
|
+
}
|
|
577
|
+
if (body.process) {
|
|
578
|
+
return {
|
|
579
|
+
kind: "partial_success",
|
|
580
|
+
status: res.status,
|
|
581
|
+
warning: errorMessage,
|
|
582
|
+
process: body.process,
|
|
583
|
+
projects,
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
const errors = body.errors ?? [];
|
|
587
|
+
if (errors.length > 0) {
|
|
588
|
+
return { kind: "validation_error", status: res.status, errors };
|
|
589
|
+
}
|
|
590
|
+
return { kind: "failure", status: res.status, error: errorMessage };
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
export async function fetchProcessDiagnostics(instanceId: string): Promise<ProcessDiagnosticsData> {
|
|
594
|
+
const res = await getFetchImpl()(
|
|
595
|
+
resolveApiUrl(`/api/processes/${encodeURIComponent(instanceId)}/diagnostics`),
|
|
596
|
+
);
|
|
597
|
+
if (!res.ok) throw new Error(`Couldn't load this process: ${res.status}`);
|
|
598
|
+
return readJsonObject<ProcessDiagnosticsResponseBody>(
|
|
599
|
+
res,
|
|
600
|
+
"Malformed process diagnostics response",
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
export async function fetchPrimaryPathSnapshot(instanceId: string): Promise<PrimaryPathSnapshot> {
|
|
605
|
+
const res = await getFetchImpl()(
|
|
606
|
+
resolveApiUrl(`/api/processes/${encodeURIComponent(instanceId)}/primary-path`),
|
|
607
|
+
);
|
|
608
|
+
if (!res.ok) throw new Error(`Couldn't load this process: ${res.status}`);
|
|
609
|
+
return readJsonObject<PrimaryPathSnapshotResponseBody>(
|
|
610
|
+
res,
|
|
611
|
+
"Malformed primary path snapshot response",
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
export async function fetchProcessDetail(instanceId: string): Promise<ProcessDetailData> {
|
|
616
|
+
const res = await getFetchImpl()(
|
|
617
|
+
resolveApiUrl(`/api/processes/${encodeURIComponent(instanceId)}/ui-snapshot`),
|
|
618
|
+
);
|
|
619
|
+
if (!res.ok) throw new Error(`Couldn't load this process: ${res.status}`);
|
|
620
|
+
return readJsonObject<ProcessDetailUiSnapshotResponseBody>(
|
|
621
|
+
res,
|
|
622
|
+
"Malformed process UI snapshot response",
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
export async function fetchTurnReasoningDetail(
|
|
627
|
+
instanceId: string,
|
|
628
|
+
turnRecordId: string,
|
|
629
|
+
sessionSignature: string | null,
|
|
630
|
+
signal?: AbortSignal,
|
|
631
|
+
): Promise<TurnReasoningDetailResponseBody> {
|
|
632
|
+
const params = new URLSearchParams({ sessionSignature: sessionSignature ?? "" });
|
|
633
|
+
const res = await getFetchImpl()(
|
|
634
|
+
resolveApiUrl(
|
|
635
|
+
`/api/processes/${encodeURIComponent(instanceId)}/turn-records/${encodeURIComponent(turnRecordId)}/reasoning?${params.toString()}`,
|
|
636
|
+
),
|
|
637
|
+
{ signal },
|
|
638
|
+
);
|
|
639
|
+
if (res.status === 409) {
|
|
640
|
+
throw new Error(
|
|
641
|
+
"The process changed while reasoning details were loading. Retry with the latest snapshot.",
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
if (!res.ok) throw new Error(`Couldn't load reasoning details: ${res.status}`);
|
|
645
|
+
return readJsonObject<TurnReasoningDetailResponseBody>(
|
|
646
|
+
res,
|
|
647
|
+
"Malformed reasoning detail response",
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
export async function fetchFutureExecution(
|
|
652
|
+
futureExecutionId: string,
|
|
653
|
+
): Promise<FutureExecutionDetailResponseBody> {
|
|
654
|
+
const res = await getFetchImpl()(
|
|
655
|
+
resolveApiUrl(`/api/future-executions/${encodeURIComponent(futureExecutionId)}`),
|
|
656
|
+
);
|
|
657
|
+
if (!res.ok) {
|
|
658
|
+
throw new ApiResponseError(`Couldn't load scheduled item: ${res.status}`, res.status);
|
|
659
|
+
}
|
|
660
|
+
return readJsonObject<FutureExecutionDetailResponseBody>(
|
|
661
|
+
res,
|
|
662
|
+
"Malformed scheduled item response",
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
export async function postProcessRetry(
|
|
667
|
+
instanceId: string,
|
|
668
|
+
nextTurnModelProfileId?: string | null,
|
|
669
|
+
providerOptions?: Readonly<Record<string, string>>,
|
|
670
|
+
): Promise<void> {
|
|
671
|
+
const res = await getFetchImpl()(
|
|
672
|
+
resolveApiUrl(`/api/processes/${encodeURIComponent(instanceId)}/retry`),
|
|
673
|
+
{
|
|
674
|
+
method: "POST",
|
|
675
|
+
headers: { "content-type": "application/json" },
|
|
676
|
+
body: JSON.stringify({
|
|
677
|
+
...(nextTurnModelProfileId === undefined ? {} : { nextTurnModelProfileId }),
|
|
678
|
+
...(providerOptions === undefined ? {} : { providerOptions }),
|
|
679
|
+
}),
|
|
680
|
+
},
|
|
681
|
+
);
|
|
682
|
+
if (!res.ok) {
|
|
683
|
+
throw new Error(`Couldn't retry this process: ${res.status}`);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
export async function fetchModelProviderOptions(
|
|
688
|
+
instanceId: string,
|
|
689
|
+
modelProfileId: string,
|
|
690
|
+
): Promise<ModelProviderOptionsResponseBody> {
|
|
691
|
+
const res = await getFetchImpl()(
|
|
692
|
+
resolveApiUrl(
|
|
693
|
+
`/api/processes/${encodeURIComponent(instanceId)}/model-profiles/${encodeURIComponent(modelProfileId)}/provider-options`,
|
|
694
|
+
),
|
|
695
|
+
);
|
|
696
|
+
if (!res.ok) {
|
|
697
|
+
const body = await tryReadJson(res);
|
|
698
|
+
throw new Error(readErrorMessage(body) ?? `Couldn't load provider options: ${res.status}`);
|
|
699
|
+
}
|
|
700
|
+
return (await res.json()) as ModelProviderOptionsResponseBody;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
export async function postProcessTurnContinue(
|
|
704
|
+
instanceId: string,
|
|
705
|
+
turnRecordId: string,
|
|
706
|
+
prompt?: string | null,
|
|
707
|
+
nextTurnModelProfileId?: string | null,
|
|
708
|
+
providerOptions?: Readonly<Record<string, string>>,
|
|
709
|
+
): Promise<void> {
|
|
710
|
+
const res = await getFetchImpl()(
|
|
711
|
+
resolveApiUrl(
|
|
712
|
+
`/api/processes/${encodeURIComponent(instanceId)}/turn-records/${encodeURIComponent(turnRecordId)}/continue`,
|
|
713
|
+
),
|
|
714
|
+
{
|
|
715
|
+
method: "POST",
|
|
716
|
+
headers: { "content-type": "application/json" },
|
|
717
|
+
body: JSON.stringify({
|
|
718
|
+
...(prompt === undefined ? {} : { prompt }),
|
|
719
|
+
...(nextTurnModelProfileId === undefined ? {} : { nextTurnModelProfileId }),
|
|
720
|
+
...(providerOptions === undefined ? {} : { providerOptions }),
|
|
721
|
+
}),
|
|
722
|
+
},
|
|
723
|
+
);
|
|
724
|
+
if (!res.ok) {
|
|
725
|
+
const body = await tryReadJson(res);
|
|
726
|
+
throw new Error(readErrorMessage(body) ?? `Couldn't continue this failed turn: ${res.status}`);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
export async function postProcessStartupRetry(
|
|
731
|
+
instanceId: string,
|
|
732
|
+
startRecordId: string,
|
|
733
|
+
nextTurnModelProfileId?: string | null,
|
|
734
|
+
providerOptions?: Readonly<Record<string, string>>,
|
|
735
|
+
): Promise<void> {
|
|
736
|
+
const res = await getFetchImpl()(
|
|
737
|
+
resolveApiUrl(
|
|
738
|
+
`/api/processes/${encodeURIComponent(instanceId)}/turn-starts/${encodeURIComponent(startRecordId)}/retry`,
|
|
739
|
+
),
|
|
740
|
+
{
|
|
741
|
+
method: "POST",
|
|
742
|
+
headers: { "content-type": "application/json" },
|
|
743
|
+
body: JSON.stringify({
|
|
744
|
+
...(nextTurnModelProfileId === undefined ? {} : { nextTurnModelProfileId }),
|
|
745
|
+
...(providerOptions === undefined ? {} : { providerOptions }),
|
|
746
|
+
}),
|
|
747
|
+
},
|
|
748
|
+
);
|
|
749
|
+
if (!res.ok) {
|
|
750
|
+
const body = await tryReadJson(res);
|
|
751
|
+
throw new Error(readErrorMessage(body) ?? `Couldn't retry worker startup: ${res.status}`);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
export async function deleteProcess(instanceId: string): Promise<void> {
|
|
756
|
+
const response = await getFetchImpl()(
|
|
757
|
+
resolveApiUrl(`/api/processes/${encodeURIComponent(instanceId)}`),
|
|
758
|
+
{ method: "DELETE" },
|
|
759
|
+
);
|
|
760
|
+
await requireSuccessfulMutation(response, "Couldn't delete this process");
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
export async function postProcessAbort(instanceId: string): Promise<void> {
|
|
764
|
+
const response = await getFetchImpl()(
|
|
765
|
+
resolveApiUrl(`/api/processes/${encodeURIComponent(instanceId)}/abort`),
|
|
766
|
+
{ method: "POST" },
|
|
767
|
+
);
|
|
768
|
+
await requireSuccessfulMutation(response, "Couldn't abort this process");
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
export async function postProcessAbortTurn(instanceId: string): Promise<void> {
|
|
772
|
+
const response = await getFetchImpl()(
|
|
773
|
+
resolveApiUrl(`/api/processes/${encodeURIComponent(instanceId)}/abort-turn`),
|
|
774
|
+
{ method: "POST" },
|
|
775
|
+
);
|
|
776
|
+
await requireSuccessfulMutation(response, "Couldn't stop this turn");
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
export async function fetchProcessRetryConfig(instanceId: string): Promise<ProcessRetryConfig> {
|
|
780
|
+
const res = await getFetchImpl()(
|
|
781
|
+
resolveApiUrl(`/api/processes/${encodeURIComponent(instanceId)}/retry-config`),
|
|
782
|
+
);
|
|
783
|
+
if (!res.ok) {
|
|
784
|
+
throw new Error(`Couldn't load retry config: ${res.status}`);
|
|
785
|
+
}
|
|
786
|
+
return readJsonObject<ProcessRetryConfigResponseBody>(
|
|
787
|
+
res,
|
|
788
|
+
"Malformed process retry config response",
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
export type ProcessActionSubmitResult =
|
|
793
|
+
| { kind: "success" }
|
|
794
|
+
| { kind: "scheduled"; scheduledAction: ScheduledActionDetail | null };
|
|
795
|
+
|
|
796
|
+
export async function fetchProcessActionModelPreview(
|
|
797
|
+
instanceId: string,
|
|
798
|
+
actionId: string,
|
|
799
|
+
input: Record<string, unknown> = {},
|
|
800
|
+
): Promise<ProcessActionModelPreview> {
|
|
801
|
+
const res = await getFetchImpl()(
|
|
802
|
+
resolveApiUrl(
|
|
803
|
+
`/api/processes/${encodeURIComponent(instanceId)}/actions/${encodeURIComponent(actionId)}/model-preview`,
|
|
804
|
+
),
|
|
805
|
+
{
|
|
806
|
+
method: "POST",
|
|
807
|
+
headers: { "content-type": "application/json" },
|
|
808
|
+
body: JSON.stringify({ input }),
|
|
809
|
+
},
|
|
810
|
+
);
|
|
811
|
+
if (!res.ok) {
|
|
812
|
+
const body = await tryReadJson(res);
|
|
813
|
+
throw new Error(
|
|
814
|
+
readErrorMessage(body) ?? `Couldn't refresh the action model preview: ${res.status}`,
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
const body = await readJsonObject<ProcessActionModelPreviewResponseBody>(
|
|
818
|
+
res,
|
|
819
|
+
"Malformed process action model preview response",
|
|
820
|
+
);
|
|
821
|
+
return body.preview;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
export async function postProcessAction(
|
|
825
|
+
instanceId: string,
|
|
826
|
+
actionId: string,
|
|
827
|
+
input: Record<string, unknown> = {},
|
|
828
|
+
opts: {
|
|
829
|
+
nextTurnModelProfileId?: string | null;
|
|
830
|
+
schedule?: ScheduleConfigInput;
|
|
831
|
+
} = {},
|
|
832
|
+
): Promise<ProcessActionSubmitResult> {
|
|
833
|
+
const res = await getFetchImpl()(
|
|
834
|
+
resolveApiUrl(
|
|
835
|
+
`/api/processes/${encodeURIComponent(instanceId)}/actions/${encodeURIComponent(actionId)}`,
|
|
836
|
+
),
|
|
837
|
+
{
|
|
838
|
+
method: "POST",
|
|
839
|
+
headers: { "content-type": "application/json" },
|
|
840
|
+
body: JSON.stringify({
|
|
841
|
+
input,
|
|
842
|
+
schedule: opts.schedule ?? { mode: "now" },
|
|
843
|
+
...(opts.nextTurnModelProfileId !== undefined
|
|
844
|
+
? { nextTurnModelProfileId: opts.nextTurnModelProfileId }
|
|
845
|
+
: {}),
|
|
846
|
+
}),
|
|
847
|
+
},
|
|
848
|
+
);
|
|
849
|
+
if (!res.ok) {
|
|
850
|
+
const body = await tryReadJson(res);
|
|
851
|
+
throw new Error(
|
|
852
|
+
readErrorMessage(body) ?? `Couldn't run "${formatDefinition(actionId)}": ${res.status}`,
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
const body = await readJsonObject<ScheduledActionMutationResponseBody>(
|
|
856
|
+
res,
|
|
857
|
+
"Malformed process action response",
|
|
858
|
+
);
|
|
859
|
+
if (body.scheduledAction) {
|
|
860
|
+
return { kind: "scheduled", scheduledAction: body.scheduledAction };
|
|
861
|
+
}
|
|
862
|
+
return { kind: "success" };
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
export async function updateScheduledLaunch(
|
|
866
|
+
futureExecutionId: string,
|
|
867
|
+
title: string | null,
|
|
868
|
+
launcherInput: Record<string, unknown>,
|
|
869
|
+
modelConfig: LauncherModelConfigDefaults,
|
|
870
|
+
schedule: ScheduleConfigInput,
|
|
871
|
+
skillIds: readonly string[] = [],
|
|
872
|
+
): Promise<LauncherSubmitResult> {
|
|
873
|
+
const res = await getFetchImpl()(
|
|
874
|
+
resolveApiUrl(`/api/future-executions/${encodeURIComponent(futureExecutionId)}/launch`),
|
|
875
|
+
{
|
|
876
|
+
method: "PUT",
|
|
877
|
+
headers: { "content-type": "application/json" },
|
|
878
|
+
body: JSON.stringify({ title, launcherInput, modelConfig, schedule, skillIds }),
|
|
879
|
+
},
|
|
880
|
+
);
|
|
881
|
+
if (!res.ok) {
|
|
882
|
+
return parseLauncherErrorResponse(res, "Couldn't update this scheduled launch");
|
|
883
|
+
}
|
|
884
|
+
const body = await readJsonObject<LauncherMutationResponseBody>(
|
|
885
|
+
res,
|
|
886
|
+
"Malformed scheduled launch update response",
|
|
887
|
+
);
|
|
888
|
+
const projects = body.projects ?? [];
|
|
889
|
+
const errorMessage = body.error ?? `Couldn't update this scheduled launch: ${res.status}`;
|
|
890
|
+
if (body.futureExecution) {
|
|
891
|
+
return { kind: "scheduled", futureExecution: body.futureExecution };
|
|
892
|
+
}
|
|
893
|
+
if (body.process) {
|
|
894
|
+
return { kind: "success", process: body.process, projects };
|
|
895
|
+
}
|
|
896
|
+
const errors = body.errors ?? [];
|
|
897
|
+
if (errors.length > 0) {
|
|
898
|
+
return { kind: "validation_error", status: res.status, errors };
|
|
899
|
+
}
|
|
900
|
+
return { kind: "failure", status: res.status, error: errorMessage };
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
export async function updateScheduledAction(
|
|
904
|
+
futureExecutionId: string,
|
|
905
|
+
input: Record<string, unknown>,
|
|
906
|
+
opts: {
|
|
907
|
+
nextTurnModelProfileId?: string | null;
|
|
908
|
+
schedule: ScheduleConfigInput;
|
|
909
|
+
},
|
|
910
|
+
): Promise<ProcessActionSubmitResult> {
|
|
911
|
+
const res = await getFetchImpl()(
|
|
912
|
+
resolveApiUrl(`/api/future-executions/${encodeURIComponent(futureExecutionId)}/action`),
|
|
913
|
+
{
|
|
914
|
+
method: "PUT",
|
|
915
|
+
headers: { "content-type": "application/json" },
|
|
916
|
+
body: JSON.stringify({
|
|
917
|
+
input,
|
|
918
|
+
schedule: opts.schedule,
|
|
919
|
+
...(opts.nextTurnModelProfileId !== undefined
|
|
920
|
+
? { nextTurnModelProfileId: opts.nextTurnModelProfileId }
|
|
921
|
+
: {}),
|
|
922
|
+
}),
|
|
923
|
+
},
|
|
924
|
+
);
|
|
925
|
+
if (!res.ok) {
|
|
926
|
+
const body = await tryReadJson(res);
|
|
927
|
+
throw new Error(
|
|
928
|
+
readErrorMessage(body) ?? `Couldn't update this scheduled action: ${res.status}`,
|
|
929
|
+
);
|
|
930
|
+
}
|
|
931
|
+
const body = await readJsonObject<ScheduledActionMutationResponseBody>(
|
|
932
|
+
res,
|
|
933
|
+
"Malformed scheduled action update response",
|
|
934
|
+
);
|
|
935
|
+
if (body.scheduledAction) {
|
|
936
|
+
return { kind: "scheduled", scheduledAction: body.scheduledAction };
|
|
937
|
+
}
|
|
938
|
+
return { kind: "success" };
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
export async function deleteFutureExecution(futureExecutionId: string): Promise<void> {
|
|
942
|
+
const res = await getFetchImpl()(
|
|
943
|
+
resolveApiUrl(`/api/future-executions/${encodeURIComponent(futureExecutionId)}`),
|
|
944
|
+
{ method: "DELETE" },
|
|
945
|
+
);
|
|
946
|
+
if (!res.ok) {
|
|
947
|
+
const body = await tryReadJson(res);
|
|
948
|
+
throw new Error(readErrorMessage(body) ?? `Couldn't cancel this scheduled item: ${res.status}`);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
export async function previewCronExpression(expression: string): Promise<string> {
|
|
953
|
+
const res = await getFetchImpl()(resolveApiUrl("/api/future-executions/cron-preview"), {
|
|
954
|
+
method: "POST",
|
|
955
|
+
headers: { "content-type": "application/json" },
|
|
956
|
+
body: JSON.stringify({ expression }),
|
|
957
|
+
});
|
|
958
|
+
if (!res.ok) {
|
|
959
|
+
const body = await tryReadJson(res);
|
|
960
|
+
throw new Error(readErrorMessage(body) ?? `Couldn't preview this cron: ${res.status}`);
|
|
961
|
+
}
|
|
962
|
+
const body = await readJsonObject<CronPreviewResponseBody>(
|
|
963
|
+
res,
|
|
964
|
+
"Malformed cron preview response",
|
|
965
|
+
);
|
|
966
|
+
if (typeof body.nextRunAt !== "string") {
|
|
967
|
+
throw new Error("Malformed cron preview response: nextRunAt must be a string");
|
|
968
|
+
}
|
|
969
|
+
return body.nextRunAt;
|
|
970
|
+
}
|