create-expert 0.0.39 → 0.0.41
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/bin/cli.ts +85 -0
- package/dist/bin/cli.js +62 -116364
- package/dist/bin/cli.js.map +1 -1
- package/dist/package.json +40 -0
- package/dist/perstack.toml +224 -116
- package/package.json +19 -17
- package/LICENSE +0 -202
- package/dist/chunk-D_gEzPfs.js +0 -47
- package/dist/devtools-DaNYFZHF.js +0 -3589
- package/dist/devtools-DaNYFZHF.js.map +0 -1
- package/dist/dist-BSxt_hUE.js +0 -1254
- package/dist/dist-BSxt_hUE.js.map +0 -1
- package/dist/from-D01OR38y.js +0 -3886
- package/dist/from-D01OR38y.js.map +0 -1
- package/dist/multipart-parser-DR1odBAg.js +0 -298
- package/dist/multipart-parser-DR1odBAg.js.map +0 -1
- package/dist/resolve-expert-CTnETi9d.js +0 -1651
- package/dist/resolve-expert-CTnETi9d.js.map +0 -1
- package/dist/src-AFNJ8T_q.js +0 -1192
- package/dist/src-AFNJ8T_q.js.map +0 -1
- package/dist/src-C0pz_C3h.js +0 -7653
- package/dist/src-C0pz_C3h.js.map +0 -1
- package/dist/token-DYCUdnJD.js +0 -51
- package/dist/token-DYCUdnJD.js.map +0 -1
- package/dist/token-error-CfavTss_.js +0 -43
- package/dist/token-error-CfavTss_.js.map +0 -1
- package/dist/token-util-CV5msMnB.js +0 -6
- package/dist/token-util-C_HjEdAu.js +0 -357
- package/dist/token-util-C_HjEdAu.js.map +0 -1
|
@@ -1,1651 +0,0 @@
|
|
|
1
|
-
import { $ as boolean, B as messageSchema, Ft as PerstackError, G as number$1, H as userMessageSchema, I as usageSchema, L as toolResultSchema, Q as array, R as toolCallSchema, U as activityOrGroupSchema, V as toolMessageSchema, W as boolean$1, X as _undefined, ct as object, dt as record, gt as unknown, ht as union, it as literal, pt as string, q as _enum, st as number, tt as discriminatedUnion, ut as preprocess, z as instructionMessageSchema } from "./src-C0pz_C3h.js";
|
|
2
|
-
|
|
3
|
-
//#region ../../node_modules/.pnpm/@perstack+api-client@0.0.55_@perstack+core@packages+core_zod@4.3.6/node_modules/@perstack/api-client/dist/index.mjs
|
|
4
|
-
function createValidationError(error) {
|
|
5
|
-
return {
|
|
6
|
-
errorType: "validation",
|
|
7
|
-
code: 400,
|
|
8
|
-
message: `Validation failed: ${error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join("; ")}`,
|
|
9
|
-
reason: error.issues
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
function createAbortError() {
|
|
13
|
-
return {
|
|
14
|
-
errorType: "abort",
|
|
15
|
-
code: 0,
|
|
16
|
-
message: "Request aborted",
|
|
17
|
-
aborted: true
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function createTimeoutError() {
|
|
21
|
-
return {
|
|
22
|
-
errorType: "timeout",
|
|
23
|
-
code: 0,
|
|
24
|
-
message: "Request timed out"
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function createNetworkError(error) {
|
|
28
|
-
return {
|
|
29
|
-
errorType: "network",
|
|
30
|
-
code: 0,
|
|
31
|
-
message: error instanceof Error ? error.message : "Network error",
|
|
32
|
-
reason: error,
|
|
33
|
-
cause: error instanceof Error ? error : void 0
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
async function handleHttpError(response) {
|
|
37
|
-
let errorBody;
|
|
38
|
-
try {
|
|
39
|
-
errorBody = await response.json();
|
|
40
|
-
} catch {
|
|
41
|
-
errorBody = void 0;
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
ok: false,
|
|
45
|
-
error: createHttpError(response.status, response.statusText, errorBody)
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function createHttpError(status, statusText, body) {
|
|
49
|
-
if (typeof body === "object" && body !== null) {
|
|
50
|
-
const hasReason = "reason" in body;
|
|
51
|
-
if ("error" in body && typeof body.error === "string") return {
|
|
52
|
-
errorType: "http",
|
|
53
|
-
code: status,
|
|
54
|
-
message: body.error,
|
|
55
|
-
reason: hasReason ? body.reason : void 0
|
|
56
|
-
};
|
|
57
|
-
if (hasReason) return {
|
|
58
|
-
errorType: "http",
|
|
59
|
-
code: status,
|
|
60
|
-
message: statusText,
|
|
61
|
-
reason: body.reason
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
errorType: "http",
|
|
66
|
-
code: status,
|
|
67
|
-
message: statusText
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
const DEFAULT_BASE_URL = "https://api.perstack.ai";
|
|
71
|
-
const DEFAULT_TIMEOUT = 3e4;
|
|
72
|
-
function createFetcher(config) {
|
|
73
|
-
const baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
74
|
-
const timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
75
|
-
const useCredentials = "credentials" in config && config.credentials === "include";
|
|
76
|
-
const apiKey = "apiKey" in config ? config.apiKey : void 0;
|
|
77
|
-
function buildUrl(path) {
|
|
78
|
-
return `${baseUrl}${path}`;
|
|
79
|
-
}
|
|
80
|
-
function buildHeaders(options) {
|
|
81
|
-
const headers = {};
|
|
82
|
-
if (options?.hasBody) headers["Content-Type"] = "application/json";
|
|
83
|
-
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
|
|
84
|
-
return headers;
|
|
85
|
-
}
|
|
86
|
-
function getCredentials() {
|
|
87
|
-
return useCredentials ? "include" : void 0;
|
|
88
|
-
}
|
|
89
|
-
function createTimeoutSignal(externalSignal) {
|
|
90
|
-
const controller = new AbortController();
|
|
91
|
-
let timedOut = false;
|
|
92
|
-
const timeoutId = setTimeout(() => {
|
|
93
|
-
timedOut = true;
|
|
94
|
-
controller.abort();
|
|
95
|
-
}, timeout);
|
|
96
|
-
let abortHandler;
|
|
97
|
-
if (externalSignal) if (externalSignal.aborted) controller.abort();
|
|
98
|
-
else {
|
|
99
|
-
abortHandler = () => controller.abort();
|
|
100
|
-
externalSignal.addEventListener("abort", abortHandler);
|
|
101
|
-
}
|
|
102
|
-
return {
|
|
103
|
-
signal: controller.signal,
|
|
104
|
-
cleanup: () => {
|
|
105
|
-
clearTimeout(timeoutId);
|
|
106
|
-
if (abortHandler && externalSignal) externalSignal.removeEventListener("abort", abortHandler);
|
|
107
|
-
},
|
|
108
|
-
isTimeout: () => timedOut
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function wrapStreamWithIdleTimeout(stream, idleTimeoutMs, externalSignal) {
|
|
112
|
-
const reader = stream.getReader();
|
|
113
|
-
const controller = new AbortController();
|
|
114
|
-
let timeoutId;
|
|
115
|
-
let abortHandler;
|
|
116
|
-
if (externalSignal) if (externalSignal.aborted) controller.abort();
|
|
117
|
-
else {
|
|
118
|
-
abortHandler = () => controller.abort();
|
|
119
|
-
externalSignal.addEventListener("abort", abortHandler);
|
|
120
|
-
}
|
|
121
|
-
function resetTimeout() {
|
|
122
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
123
|
-
timeoutId = setTimeout(() => controller.abort(), idleTimeoutMs);
|
|
124
|
-
}
|
|
125
|
-
function cleanup() {
|
|
126
|
-
if (timeoutId) clearTimeout(timeoutId);
|
|
127
|
-
if (abortHandler && externalSignal) externalSignal.removeEventListener("abort", abortHandler);
|
|
128
|
-
}
|
|
129
|
-
return new ReadableStream({
|
|
130
|
-
start() {
|
|
131
|
-
resetTimeout();
|
|
132
|
-
},
|
|
133
|
-
async pull(streamController) {
|
|
134
|
-
try {
|
|
135
|
-
const result = await Promise.race([reader.read(), new Promise((_, reject) => {
|
|
136
|
-
if (controller.signal.aborted) reject(new DOMException("Stream idle timeout", "AbortError"));
|
|
137
|
-
controller.signal.addEventListener("abort", () => {
|
|
138
|
-
reject(new DOMException("Stream idle timeout", "AbortError"));
|
|
139
|
-
});
|
|
140
|
-
})]);
|
|
141
|
-
if (result.done) {
|
|
142
|
-
cleanup();
|
|
143
|
-
streamController.close();
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
resetTimeout();
|
|
147
|
-
streamController.enqueue(result.value);
|
|
148
|
-
} catch (error) {
|
|
149
|
-
cleanup();
|
|
150
|
-
reader.cancel().catch(() => {});
|
|
151
|
-
if (error instanceof DOMException && error.name === "AbortError") streamController.error(new DOMException("Stream idle timeout", "AbortError"));
|
|
152
|
-
else streamController.error(error);
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
cancel(reason) {
|
|
156
|
-
cleanup();
|
|
157
|
-
reader.cancel(reason).catch(() => {});
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
async function request(method, path, body, options) {
|
|
162
|
-
const { signal, cleanup, isTimeout } = createTimeoutSignal(options?.signal);
|
|
163
|
-
try {
|
|
164
|
-
const response = await fetch(buildUrl(path), {
|
|
165
|
-
method,
|
|
166
|
-
headers: buildHeaders(body ? { hasBody: true } : void 0),
|
|
167
|
-
body: body ? JSON.stringify(body) : void 0,
|
|
168
|
-
signal,
|
|
169
|
-
credentials: getCredentials()
|
|
170
|
-
});
|
|
171
|
-
if (!response.ok) return handleHttpError(response);
|
|
172
|
-
return {
|
|
173
|
-
ok: true,
|
|
174
|
-
data: await response.json()
|
|
175
|
-
};
|
|
176
|
-
} catch (error) {
|
|
177
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
178
|
-
if (isTimeout()) return {
|
|
179
|
-
ok: false,
|
|
180
|
-
error: createTimeoutError()
|
|
181
|
-
};
|
|
182
|
-
return {
|
|
183
|
-
ok: false,
|
|
184
|
-
error: createAbortError()
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
return {
|
|
188
|
-
ok: false,
|
|
189
|
-
error: createNetworkError(error)
|
|
190
|
-
};
|
|
191
|
-
} finally {
|
|
192
|
-
cleanup();
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
async function requestBlob(path, options) {
|
|
196
|
-
const { signal, cleanup, isTimeout } = createTimeoutSignal(options?.signal);
|
|
197
|
-
try {
|
|
198
|
-
const response = await fetch(buildUrl(path), {
|
|
199
|
-
method: "GET",
|
|
200
|
-
headers: buildHeaders(),
|
|
201
|
-
signal,
|
|
202
|
-
credentials: getCredentials()
|
|
203
|
-
});
|
|
204
|
-
if (!response.ok) return handleHttpError(response);
|
|
205
|
-
return {
|
|
206
|
-
ok: true,
|
|
207
|
-
data: await response.blob()
|
|
208
|
-
};
|
|
209
|
-
} catch (error) {
|
|
210
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
211
|
-
if (isTimeout()) return {
|
|
212
|
-
ok: false,
|
|
213
|
-
error: createTimeoutError()
|
|
214
|
-
};
|
|
215
|
-
return {
|
|
216
|
-
ok: false,
|
|
217
|
-
error: createAbortError()
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
return {
|
|
221
|
-
ok: false,
|
|
222
|
-
error: createNetworkError(error)
|
|
223
|
-
};
|
|
224
|
-
} finally {
|
|
225
|
-
cleanup();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
async function requestStream(path, options) {
|
|
229
|
-
const { signal, cleanup, isTimeout } = createTimeoutSignal(options?.signal);
|
|
230
|
-
try {
|
|
231
|
-
const response = await fetch(buildUrl(path), {
|
|
232
|
-
method: "GET",
|
|
233
|
-
headers: buildHeaders(),
|
|
234
|
-
signal,
|
|
235
|
-
credentials: getCredentials()
|
|
236
|
-
});
|
|
237
|
-
if (!response.ok) {
|
|
238
|
-
cleanup();
|
|
239
|
-
return handleHttpError(response);
|
|
240
|
-
}
|
|
241
|
-
if (!response.body) {
|
|
242
|
-
cleanup();
|
|
243
|
-
return {
|
|
244
|
-
ok: false,
|
|
245
|
-
error: createNetworkError(/* @__PURE__ */ new Error("Response body is null"))
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
cleanup();
|
|
249
|
-
const idleTimeout = options?.streamIdleTimeout ?? timeout;
|
|
250
|
-
return {
|
|
251
|
-
ok: true,
|
|
252
|
-
data: wrapStreamWithIdleTimeout(response.body, idleTimeout, options?.signal)
|
|
253
|
-
};
|
|
254
|
-
} catch (error) {
|
|
255
|
-
cleanup();
|
|
256
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
257
|
-
if (isTimeout()) return {
|
|
258
|
-
ok: false,
|
|
259
|
-
error: createTimeoutError()
|
|
260
|
-
};
|
|
261
|
-
return {
|
|
262
|
-
ok: false,
|
|
263
|
-
error: createAbortError()
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
return {
|
|
267
|
-
ok: false,
|
|
268
|
-
error: createNetworkError(error)
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
async function requestNoContent(method, path, options) {
|
|
273
|
-
const { signal, cleanup, isTimeout } = createTimeoutSignal(options?.signal);
|
|
274
|
-
try {
|
|
275
|
-
const response = await fetch(buildUrl(path), {
|
|
276
|
-
method,
|
|
277
|
-
headers: buildHeaders(),
|
|
278
|
-
signal,
|
|
279
|
-
credentials: getCredentials()
|
|
280
|
-
});
|
|
281
|
-
if (!response.ok) return handleHttpError(response);
|
|
282
|
-
return {
|
|
283
|
-
ok: true,
|
|
284
|
-
data: void 0
|
|
285
|
-
};
|
|
286
|
-
} catch (error) {
|
|
287
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
288
|
-
if (isTimeout()) return {
|
|
289
|
-
ok: false,
|
|
290
|
-
error: createTimeoutError()
|
|
291
|
-
};
|
|
292
|
-
return {
|
|
293
|
-
ok: false,
|
|
294
|
-
error: createAbortError()
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
return {
|
|
298
|
-
ok: false,
|
|
299
|
-
error: createNetworkError(error)
|
|
300
|
-
};
|
|
301
|
-
} finally {
|
|
302
|
-
cleanup();
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
return {
|
|
306
|
-
get: (path, options) => request("GET", path, void 0, options),
|
|
307
|
-
post: (path, body, options) => request("POST", path, body, options),
|
|
308
|
-
put: (path, body, options) => request("PUT", path, body, options),
|
|
309
|
-
delete: (path, options) => request("DELETE", path, void 0, options),
|
|
310
|
-
deleteNoContent: (path, options) => requestNoContent("DELETE", path, options),
|
|
311
|
-
getBlob: (path, options) => requestBlob(path, options),
|
|
312
|
-
getStream: (path, options) => requestStream(path, options)
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
function buildQueryString(params) {
|
|
316
|
-
if (!params) return "";
|
|
317
|
-
const searchParams = new URLSearchParams();
|
|
318
|
-
for (const [key, value] of Object.entries(params)) if (value !== void 0) searchParams.set(key, String(value));
|
|
319
|
-
const queryString = searchParams.toString();
|
|
320
|
-
return queryString ? `?${queryString}` : "";
|
|
321
|
-
}
|
|
322
|
-
async function* parseSSEEvents(reader) {
|
|
323
|
-
const decoder = new TextDecoder();
|
|
324
|
-
let buffer = "";
|
|
325
|
-
while (true) {
|
|
326
|
-
const { value, done } = await reader.read();
|
|
327
|
-
if (done) break;
|
|
328
|
-
buffer += decoder.decode(value, { stream: true });
|
|
329
|
-
const events = buffer.split("\n\n");
|
|
330
|
-
buffer = events.pop() || "";
|
|
331
|
-
for (const event of events) {
|
|
332
|
-
if (event.trim() === "") continue;
|
|
333
|
-
const lines = event.split("\n");
|
|
334
|
-
const eventType = lines.find((line) => line.startsWith("event:"))?.slice(6).trim();
|
|
335
|
-
const data = lines.find((line) => line.startsWith("data:"))?.slice(5).trim();
|
|
336
|
-
if (!eventType || !data) continue;
|
|
337
|
-
if (eventType !== "message" && eventType !== "error" && eventType !== "complete") continue;
|
|
338
|
-
try {
|
|
339
|
-
yield {
|
|
340
|
-
event: eventType,
|
|
341
|
-
data: JSON.parse(data)
|
|
342
|
-
};
|
|
343
|
-
} catch {}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
const organizationNameRegex = /^[a-z0-9][a-z0-9_.-]*$/;
|
|
348
|
-
const maxOrganizationNameLength = 128;
|
|
349
|
-
const applicationNameRegex = /^[a-z0-9][a-z0-9_.-]*$/;
|
|
350
|
-
const maxApplicationNameLength = 255;
|
|
351
|
-
const maxVariableValueLength = 65536;
|
|
352
|
-
const maxSecretValueLength = 65536;
|
|
353
|
-
const expertKeyRegex = /^((?:@[a-z0-9][a-z0-9_.-]*\/)?[a-z0-9][a-z0-9_.-]*)(?:@((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\w.-]+)?(?:\+[\w.-]+)?)|@([a-z0-9][a-z0-9_.-]*))?$/;
|
|
354
|
-
const expertNameRegex = /^(@[a-z0-9][a-z0-9_-]*\/)?[a-z0-9][a-z0-9_-]*$/;
|
|
355
|
-
const scopeNameRegex = /^[a-z0-9][a-z0-9_-]*$/;
|
|
356
|
-
const scopeNameRefRegex = /^[a-z0-9][a-z0-9_-]*(?:@(?:(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\w.-]+)?(?:\+[\w.-]+)?|[a-z0-9][a-z0-9_-]*))?$/;
|
|
357
|
-
const expertVersionRegex = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\w.-]+)?(?:\+[\w.-]+)?$/;
|
|
358
|
-
const tagNameRegex = /^[a-z0-9][a-z0-9_-]*$/;
|
|
359
|
-
const maxExpertNameLength = 255;
|
|
360
|
-
const maxExpertVersionTagLength = 255;
|
|
361
|
-
const maxExpertKeyLength = 511;
|
|
362
|
-
const maxExpertDescriptionLength = 1024 * 2;
|
|
363
|
-
const maxExpertInstructionLength = 1024 * 20;
|
|
364
|
-
const maxExpertDelegateItems = 255;
|
|
365
|
-
const maxExpertTagItems = 8;
|
|
366
|
-
const maxExpertJobQueryLength = 1024 * 20;
|
|
367
|
-
const packageWithVersionRegex = /^(?:@[a-z0-9][a-z0-9_.-]*\/)?[a-z0-9][a-z0-9_.-]*(?:@(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\w.-]+)?(?:\+[\w.-]+)?|@[a-z0-9][a-z0-9_.-]*)?$/;
|
|
368
|
-
const urlSafeRegex = /^[a-z0-9][a-z0-9_-]*$/;
|
|
369
|
-
const maxSkillNameLength = 255;
|
|
370
|
-
const maxSkillDescriptionLength = 1024 * 2;
|
|
371
|
-
const maxSkillRuleLength = 1024 * 2;
|
|
372
|
-
const maxSkillPickOmitItems = 255;
|
|
373
|
-
const maxSkillRequiredEnvItems = 255;
|
|
374
|
-
const maxSkillToolNameLength = 255;
|
|
375
|
-
const maxSkillEndpointLength = 1024 * 2;
|
|
376
|
-
const maxSkillInputJsonSchemaLength = 1024 * 20;
|
|
377
|
-
const maxCheckpointToolCallIdLength = 255;
|
|
378
|
-
const envNameRegex = /^[a-zA-Z0-9][a-zA-Z0-9_-]*$/;
|
|
379
|
-
const maxEnvNameLength = 255;
|
|
380
|
-
const maxProviderBaseUrlLength = 2048;
|
|
381
|
-
const maxProviderHeaderKeyLength = 255;
|
|
382
|
-
const maxProviderHeaderValueLength = 2048;
|
|
383
|
-
const maxProviderHeadersCount = 50;
|
|
384
|
-
const cuidSchema = string().cuid2();
|
|
385
|
-
string().min(24).cuid2();
|
|
386
|
-
const runtimeVersionSchema = _enum(["v1.0"]);
|
|
387
|
-
const providerSchema = _enum([
|
|
388
|
-
"anthropic",
|
|
389
|
-
"google",
|
|
390
|
-
"openai",
|
|
391
|
-
"deepseek",
|
|
392
|
-
"azure-openai",
|
|
393
|
-
"amazon-bedrock",
|
|
394
|
-
"google-vertex"
|
|
395
|
-
]);
|
|
396
|
-
const datetimeSchema = string().datetime({ offset: true });
|
|
397
|
-
const expertKeyFieldSchema = string().min(1).max(maxExpertKeyLength).regex(expertKeyRegex);
|
|
398
|
-
const expertNameFieldSchema = string().min(1).max(maxExpertNameLength).regex(expertNameRegex);
|
|
399
|
-
const expertVersionFieldSchema = string().min(1).max(maxExpertVersionTagLength).regex(expertVersionRegex);
|
|
400
|
-
const expertTagFieldSchema = string().min(1).max(maxExpertVersionTagLength).regex(tagNameRegex);
|
|
401
|
-
const expertCategoryFieldSchema = _enum([
|
|
402
|
-
"general",
|
|
403
|
-
"coding",
|
|
404
|
-
"research",
|
|
405
|
-
"writing",
|
|
406
|
-
"data",
|
|
407
|
-
"automation"
|
|
408
|
-
]);
|
|
409
|
-
const scopeNameSchema = string().min(1).max(maxExpertNameLength).regex(scopeNameRegex);
|
|
410
|
-
string().min(1).max(maxExpertNameLength + maxExpertVersionTagLength + 1).regex(scopeNameRefRegex);
|
|
411
|
-
string().min(1).max(30);
|
|
412
|
-
const organizationStatusSchema = _enum([
|
|
413
|
-
"active",
|
|
414
|
-
"inactive",
|
|
415
|
-
"deleted"
|
|
416
|
-
]);
|
|
417
|
-
const organizationTypeSchema = _enum([
|
|
418
|
-
"personal",
|
|
419
|
-
"personalPlus",
|
|
420
|
-
"team",
|
|
421
|
-
"serviceAdmin"
|
|
422
|
-
]);
|
|
423
|
-
const organizationSchema = object({
|
|
424
|
-
type: literal("organization"),
|
|
425
|
-
id: cuidSchema,
|
|
426
|
-
createdAt: datetimeSchema,
|
|
427
|
-
updatedAt: datetimeSchema,
|
|
428
|
-
name: string().min(1).max(maxOrganizationNameLength).regex(organizationNameRegex).optional(),
|
|
429
|
-
nameChangedAt: datetimeSchema.optional(),
|
|
430
|
-
status: organizationStatusSchema,
|
|
431
|
-
organizationType: organizationTypeSchema,
|
|
432
|
-
maxApplications: number().int().min(0),
|
|
433
|
-
maxApiKeys: number().int().min(0),
|
|
434
|
-
maxExperts: number().int().min(0)
|
|
435
|
-
});
|
|
436
|
-
/**
|
|
437
|
-
* Dedent function for multi-line template strings.
|
|
438
|
-
* Adapted from ts-dedent (MIT License) to provide pure ESM support.
|
|
439
|
-
*
|
|
440
|
-
* Removes leading indentation from multi-line strings while preserving
|
|
441
|
-
* relative indentation between lines.
|
|
442
|
-
*/
|
|
443
|
-
function dedent(templ, ...values) {
|
|
444
|
-
let strings = Array.from(typeof templ === "string" ? [templ] : templ);
|
|
445
|
-
const lastIndex = strings.length - 1;
|
|
446
|
-
strings[lastIndex] = (strings[lastIndex] ?? "").replace(/\r?\n([\t ]*)$/, "");
|
|
447
|
-
const indentLengths = strings.reduce((arr, str) => {
|
|
448
|
-
const matches = str.match(/\n([\t ]+|(?!\s).)/g);
|
|
449
|
-
if (matches) return arr.concat(matches.map((match) => match.match(/[\t ]/g)?.length ?? 0));
|
|
450
|
-
return arr;
|
|
451
|
-
}, []);
|
|
452
|
-
if (indentLengths.length) {
|
|
453
|
-
const pattern = new RegExp(`\n[\t ]{${Math.min(...indentLengths)}}`, "g");
|
|
454
|
-
strings = strings.map((str) => str.replace(pattern, "\n"));
|
|
455
|
-
}
|
|
456
|
-
strings[0] = (strings[0] ?? "").replace(/^\r?\n/, "");
|
|
457
|
-
let string = strings[0] ?? "";
|
|
458
|
-
values.forEach((value, i) => {
|
|
459
|
-
const endentation = string.match(/(?:^|\n)( *)$/)?.[1] ?? "";
|
|
460
|
-
let indentedValue = value;
|
|
461
|
-
if (typeof value === "string" && value.includes("\n")) indentedValue = String(value).split("\n").map((str, j) => {
|
|
462
|
-
return j === 0 ? str : `${endentation}${str}`;
|
|
463
|
-
}).join("\n");
|
|
464
|
-
string += String(indentedValue) + (strings[i + 1] ?? "");
|
|
465
|
-
});
|
|
466
|
-
return string;
|
|
467
|
-
}
|
|
468
|
-
object({
|
|
469
|
-
code: literal(400),
|
|
470
|
-
error: literal("Bad Request"),
|
|
471
|
-
reason: string()
|
|
472
|
-
}).describe("Bad Request");
|
|
473
|
-
object({
|
|
474
|
-
code: literal(401),
|
|
475
|
-
error: literal("Unauthorized"),
|
|
476
|
-
reason: literal("Failed to authenticate")
|
|
477
|
-
}).describe(dedent`
|
|
478
|
-
Authentication failed. Possible reasons:
|
|
479
|
-
- Authorization header is not provided
|
|
480
|
-
- Invalid API key
|
|
481
|
-
- Session expired
|
|
482
|
-
`);
|
|
483
|
-
object({
|
|
484
|
-
code: literal(403),
|
|
485
|
-
error: literal("Forbidden"),
|
|
486
|
-
reason: string()
|
|
487
|
-
}).describe("Access denied. The authenticated user does not have permission to perform this action.");
|
|
488
|
-
object({
|
|
489
|
-
code: literal(403),
|
|
490
|
-
error: literal("Forbidden"),
|
|
491
|
-
reason: string(),
|
|
492
|
-
details: object({
|
|
493
|
-
minutesUsed: number(),
|
|
494
|
-
limitMinutes: number(),
|
|
495
|
-
upgradeUrl: string()
|
|
496
|
-
})
|
|
497
|
-
}).describe("Usage limit exceeded. Upgrade your plan to continue.");
|
|
498
|
-
object({
|
|
499
|
-
code: literal(404),
|
|
500
|
-
error: literal("Not Found"),
|
|
501
|
-
reason: string()
|
|
502
|
-
}).describe("Resource not found.");
|
|
503
|
-
object({
|
|
504
|
-
code: literal(409),
|
|
505
|
-
error: literal("Conflict"),
|
|
506
|
-
reason: string()
|
|
507
|
-
}).describe("Request conflicts with current state of the resource.");
|
|
508
|
-
object({
|
|
509
|
-
code: literal(503),
|
|
510
|
-
error: literal("Service Unavailable"),
|
|
511
|
-
reason: string()
|
|
512
|
-
}).describe("Service temporarily unavailable. Retry with exponential backoff.");
|
|
513
|
-
object({
|
|
514
|
-
code: literal(422),
|
|
515
|
-
error: literal("Validation Failed"),
|
|
516
|
-
reason: unknown()
|
|
517
|
-
}).describe("Request validation failed. Check the request body, query parameters, or path parameters.");
|
|
518
|
-
const paginationMeta = object({
|
|
519
|
-
total: number().int().min(0),
|
|
520
|
-
take: number().int().min(1),
|
|
521
|
-
skip: number().int().min(0)
|
|
522
|
-
});
|
|
523
|
-
object({
|
|
524
|
-
code: literal(401),
|
|
525
|
-
error: literal("Unauthorized"),
|
|
526
|
-
reason: string()
|
|
527
|
-
}).describe("Unauthorized");
|
|
528
|
-
const applicationNameSchema = string().min(1).max(maxApplicationNameLength).regex(applicationNameRegex);
|
|
529
|
-
const applicationStatusSchema = _enum([
|
|
530
|
-
"active",
|
|
531
|
-
"inactive",
|
|
532
|
-
"deleted"
|
|
533
|
-
]);
|
|
534
|
-
const applicationSchema = object({
|
|
535
|
-
type: literal("application"),
|
|
536
|
-
id: cuidSchema,
|
|
537
|
-
organizationId: cuidSchema,
|
|
538
|
-
organization: organizationSchema,
|
|
539
|
-
createdAt: datetimeSchema,
|
|
540
|
-
updatedAt: datetimeSchema,
|
|
541
|
-
name: applicationNameSchema,
|
|
542
|
-
status: applicationStatusSchema,
|
|
543
|
-
expertCount: number().describe("Number of expert draft scopes associated with this application").optional(),
|
|
544
|
-
providers: array(providerSchema).describe("List of configured providers for this application").optional(),
|
|
545
|
-
totalJobs: number().describe("Total number of jobs executed for this application").optional(),
|
|
546
|
-
lastJobExecutionAt: string().datetime({ offset: true }).nullable().describe("Timestamp of the most recent job execution").optional()
|
|
547
|
-
});
|
|
548
|
-
const request$17 = { body: object({
|
|
549
|
-
name: applicationNameSchema,
|
|
550
|
-
applicationGroupId: cuidSchema.optional()
|
|
551
|
-
}) };
|
|
552
|
-
object({ data: object({ application: applicationSchema }) });
|
|
553
|
-
const request$16 = { query: object({
|
|
554
|
-
name: preprocess((val) => Array.isArray(val) ? val.join(",") : val, string().optional()),
|
|
555
|
-
sort: _enum([
|
|
556
|
-
"name",
|
|
557
|
-
"createdAt",
|
|
558
|
-
"updatedAt"
|
|
559
|
-
]).optional(),
|
|
560
|
-
order: _enum(["asc", "desc"]).optional(),
|
|
561
|
-
take: number$1().min(1).max(100).default(20),
|
|
562
|
-
skip: number$1().min(0).default(0)
|
|
563
|
-
}) };
|
|
564
|
-
object({
|
|
565
|
-
data: object({ applications: array(applicationSchema) }),
|
|
566
|
-
meta: paginationMeta
|
|
567
|
-
});
|
|
568
|
-
const request$15 = {
|
|
569
|
-
params: object({ applicationId: cuidSchema }),
|
|
570
|
-
body: object({
|
|
571
|
-
name: applicationNameSchema.optional(),
|
|
572
|
-
status: applicationStatusSchema.exclude(["deleted"]).optional()
|
|
573
|
-
}).refine((data) => data.name !== void 0 || data.status !== void 0, { message: "At least one field must be provided" })
|
|
574
|
-
};
|
|
575
|
-
object({ data: object({ application: applicationSchema }) });
|
|
576
|
-
const secretNameSchema = string().min(1, "Secret name is required").max(255, "Secret name must be 255 characters or less").regex(/^[A-Z][A-Z0-9_]*$/, "Secret name must start with uppercase letter and contain only uppercase letters, numbers, and underscores");
|
|
577
|
-
const secretValueSchema = string().min(1, "Secret value is required").max(maxSecretValueLength);
|
|
578
|
-
const secretMetadataSchema = object({
|
|
579
|
-
name: string(),
|
|
580
|
-
createdAt: datetimeSchema,
|
|
581
|
-
updatedAt: datetimeSchema
|
|
582
|
-
});
|
|
583
|
-
object({
|
|
584
|
-
type: literal("secret"),
|
|
585
|
-
id: cuidSchema,
|
|
586
|
-
name: secretNameSchema,
|
|
587
|
-
applicationId: cuidSchema,
|
|
588
|
-
createdAt: datetimeSchema,
|
|
589
|
-
updatedAt: datetimeSchema
|
|
590
|
-
});
|
|
591
|
-
const request$14 = { body: object({
|
|
592
|
-
applicationId: cuidSchema,
|
|
593
|
-
name: secretNameSchema,
|
|
594
|
-
value: secretValueSchema
|
|
595
|
-
}) };
|
|
596
|
-
object({ data: object({ secret: secretMetadataSchema }) });
|
|
597
|
-
const request$13 = { query: object({ applicationId: cuidSchema.optional() }) };
|
|
598
|
-
object({ data: object({ secrets: array(secretMetadataSchema) }) });
|
|
599
|
-
const request$12 = {
|
|
600
|
-
params: object({ name: string().min(1) }),
|
|
601
|
-
body: object({
|
|
602
|
-
applicationId: cuidSchema,
|
|
603
|
-
value: secretValueSchema
|
|
604
|
-
})
|
|
605
|
-
};
|
|
606
|
-
object({ data: object({ secret: secretMetadataSchema }) });
|
|
607
|
-
const variableNameSchema = string().min(1).max(255).regex(/^[A-Z][A-Z0-9_]*$/, "Variable name must start with uppercase letter and contain only uppercase letters, digits, and underscores");
|
|
608
|
-
const variableValueSchema = string().max(maxVariableValueLength);
|
|
609
|
-
object({
|
|
610
|
-
type: literal("variable"),
|
|
611
|
-
id: cuidSchema,
|
|
612
|
-
applicationId: cuidSchema,
|
|
613
|
-
createdAt: datetimeSchema,
|
|
614
|
-
updatedAt: datetimeSchema,
|
|
615
|
-
name: variableNameSchema,
|
|
616
|
-
value: variableValueSchema
|
|
617
|
-
});
|
|
618
|
-
const variableResponseSchema = object({
|
|
619
|
-
name: variableNameSchema,
|
|
620
|
-
value: variableValueSchema,
|
|
621
|
-
createdAt: datetimeSchema,
|
|
622
|
-
updatedAt: datetimeSchema
|
|
623
|
-
});
|
|
624
|
-
const request$11 = { body: object({
|
|
625
|
-
applicationId: cuidSchema,
|
|
626
|
-
name: variableNameSchema,
|
|
627
|
-
value: variableValueSchema
|
|
628
|
-
}) };
|
|
629
|
-
object({ data: object({ variable: variableResponseSchema }) });
|
|
630
|
-
const request$10 = { query: object({ applicationId: cuidSchema }) };
|
|
631
|
-
object({ data: object({ variables: array(variableResponseSchema) }) });
|
|
632
|
-
const request$9 = {
|
|
633
|
-
params: object({ name: string().min(1) }),
|
|
634
|
-
body: object({
|
|
635
|
-
applicationId: cuidSchema,
|
|
636
|
-
value: variableValueSchema
|
|
637
|
-
})
|
|
638
|
-
};
|
|
639
|
-
object({ data: object({ variable: variableResponseSchema }) });
|
|
640
|
-
const expertScopeSchema = object({
|
|
641
|
-
id: cuidSchema,
|
|
642
|
-
name: scopeNameSchema,
|
|
643
|
-
organizationId: cuidSchema,
|
|
644
|
-
expertDraftScopeId: cuidSchema,
|
|
645
|
-
published: boolean(),
|
|
646
|
-
publishedAt: datetimeSchema.nullable(),
|
|
647
|
-
category: expertCategoryFieldSchema,
|
|
648
|
-
totalRuns: number().int().min(0),
|
|
649
|
-
totalJobs: number().int().min(0),
|
|
650
|
-
totalStars: number().int().min(0),
|
|
651
|
-
createdAt: datetimeSchema,
|
|
652
|
-
updatedAt: datetimeSchema,
|
|
653
|
-
createdBy: cuidSchema,
|
|
654
|
-
updatedBy: cuidSchema
|
|
655
|
-
});
|
|
656
|
-
const expertVersionSchema = object({
|
|
657
|
-
id: cuidSchema,
|
|
658
|
-
expertScopeId: cuidSchema,
|
|
659
|
-
version: expertVersionFieldSchema,
|
|
660
|
-
public: boolean(),
|
|
661
|
-
yanked: boolean(),
|
|
662
|
-
totalRuns: number().int().min(0),
|
|
663
|
-
totalJobs: number().int().min(0),
|
|
664
|
-
createdAt: datetimeSchema,
|
|
665
|
-
updatedAt: datetimeSchema,
|
|
666
|
-
createdBy: cuidSchema,
|
|
667
|
-
updatedBy: cuidSchema,
|
|
668
|
-
tags: array(expertTagFieldSchema),
|
|
669
|
-
readmeUrl: string().optional()
|
|
670
|
-
});
|
|
671
|
-
expertScopeSchema.extend({ versions: array(expertVersionSchema) });
|
|
672
|
-
function isPrivateOrLocalIP(hostname) {
|
|
673
|
-
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname === "0.0.0.0") return true;
|
|
674
|
-
const ipv4Match = hostname.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/);
|
|
675
|
-
if (ipv4Match) {
|
|
676
|
-
const a = Number(ipv4Match[1]);
|
|
677
|
-
const b = Number(ipv4Match[2]);
|
|
678
|
-
if (a === 10) return true;
|
|
679
|
-
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
680
|
-
if (a === 192 && b === 168) return true;
|
|
681
|
-
if (a === 169 && b === 254) return true;
|
|
682
|
-
if (a === 127) return true;
|
|
683
|
-
}
|
|
684
|
-
if (hostname.includes(":")) {
|
|
685
|
-
if (hostname.startsWith("fe80:") || hostname.startsWith("fc") || hostname.startsWith("fd")) return true;
|
|
686
|
-
}
|
|
687
|
-
if (hostname.startsWith("::ffff:")) {
|
|
688
|
-
if (isPrivateOrLocalIP(hostname.slice(7))) return true;
|
|
689
|
-
}
|
|
690
|
-
return false;
|
|
691
|
-
}
|
|
692
|
-
const sseEndpointSchema = string().max(maxSkillEndpointLength).url().refine((url) => {
|
|
693
|
-
try {
|
|
694
|
-
const parsed = new URL(url);
|
|
695
|
-
if (parsed.protocol !== "https:") return false;
|
|
696
|
-
if (isPrivateOrLocalIP(parsed.hostname)) return false;
|
|
697
|
-
return true;
|
|
698
|
-
} catch {
|
|
699
|
-
return false;
|
|
700
|
-
}
|
|
701
|
-
}, { message: "Endpoint must be a public HTTPS URL" });
|
|
702
|
-
const skillNameSchema = string().min(1).max(maxSkillNameLength).regex(packageWithVersionRegex);
|
|
703
|
-
const mcpStdioSkillCommandSchema = _enum(["npx", "uvx"]);
|
|
704
|
-
const mcpStdioSkillSchema = object({
|
|
705
|
-
type: literal("mcpStdioSkill"),
|
|
706
|
-
name: string().min(1),
|
|
707
|
-
description: string().min(1).max(maxSkillDescriptionLength),
|
|
708
|
-
rule: string().min(1).max(maxSkillRuleLength).optional(),
|
|
709
|
-
pick: array(string().min(1).max(maxSkillToolNameLength)).max(maxSkillPickOmitItems).optional().default([]),
|
|
710
|
-
omit: array(string().min(1).max(maxSkillToolNameLength)).max(maxSkillPickOmitItems).optional().default([]),
|
|
711
|
-
command: mcpStdioSkillCommandSchema,
|
|
712
|
-
packageName: string().min(1).max(maxSkillNameLength).regex(packageWithVersionRegex),
|
|
713
|
-
requiredEnv: array(string().min(1).max(maxEnvNameLength).regex(envNameRegex)).max(maxSkillRequiredEnvItems).optional().default([])
|
|
714
|
-
});
|
|
715
|
-
const mcpSseSkillSchema = object({
|
|
716
|
-
type: literal("mcpSseSkill"),
|
|
717
|
-
name: string().min(1),
|
|
718
|
-
description: string().min(1).max(maxSkillDescriptionLength),
|
|
719
|
-
rule: string().min(1).max(maxSkillRuleLength).optional(),
|
|
720
|
-
pick: array(string().min(1).max(maxSkillToolNameLength)).max(maxSkillPickOmitItems).optional().default([]),
|
|
721
|
-
omit: array(string().min(1).max(maxSkillToolNameLength)).max(maxSkillPickOmitItems).optional().default([]),
|
|
722
|
-
endpoint: sseEndpointSchema
|
|
723
|
-
});
|
|
724
|
-
const interactiveSkillSchema = object({
|
|
725
|
-
type: literal("interactiveSkill"),
|
|
726
|
-
name: string().min(1),
|
|
727
|
-
description: string().min(1).max(maxSkillDescriptionLength),
|
|
728
|
-
rule: string().min(1).max(maxSkillRuleLength).optional(),
|
|
729
|
-
tools: record(string().min(1).max(maxSkillToolNameLength).regex(urlSafeRegex), object({
|
|
730
|
-
description: string().min(1).max(maxSkillDescriptionLength),
|
|
731
|
-
inputJsonSchema: string().min(1).max(maxSkillInputJsonSchemaLength)
|
|
732
|
-
}))
|
|
733
|
-
});
|
|
734
|
-
const skillSchema = discriminatedUnion("type", [
|
|
735
|
-
mcpStdioSkillSchema,
|
|
736
|
-
mcpSseSkillSchema,
|
|
737
|
-
interactiveSkillSchema
|
|
738
|
-
]);
|
|
739
|
-
const expertSchema = object({
|
|
740
|
-
key: expertKeyFieldSchema,
|
|
741
|
-
name: expertNameFieldSchema,
|
|
742
|
-
version: expertVersionFieldSchema,
|
|
743
|
-
description: string().max(maxExpertDescriptionLength).optional(),
|
|
744
|
-
instruction: string().min(1).max(maxExpertInstructionLength),
|
|
745
|
-
skills: record(skillNameSchema, skillSchema).optional().default({}),
|
|
746
|
-
delegates: array(expertKeyFieldSchema).min(0).max(maxExpertDelegateItems).optional().default([]),
|
|
747
|
-
tags: array(expertTagFieldSchema).min(0).max(maxExpertTagItems).optional().default([]),
|
|
748
|
-
minRuntimeVersion: runtimeVersionSchema.optional()
|
|
749
|
-
});
|
|
750
|
-
object({
|
|
751
|
-
scope: expertScopeSchema,
|
|
752
|
-
version: expertVersionSchema
|
|
753
|
-
});
|
|
754
|
-
const expertWithMetadataSchema = expertSchema.extend({
|
|
755
|
-
scope: expertScopeSchema,
|
|
756
|
-
version: expertVersionSchema
|
|
757
|
-
});
|
|
758
|
-
const request$8 = { query: object({
|
|
759
|
-
filter: string().describe("Filter by scope name (partial match)").optional(),
|
|
760
|
-
category: _enum([
|
|
761
|
-
"general",
|
|
762
|
-
"coding",
|
|
763
|
-
"research",
|
|
764
|
-
"writing",
|
|
765
|
-
"data",
|
|
766
|
-
"automation"
|
|
767
|
-
]).describe("Filter by category").optional(),
|
|
768
|
-
includeDrafts: boolean$1().default(false).describe("Include unpublished scopes (owner only)").optional(),
|
|
769
|
-
take: number$1().min(1).max(100).default(20),
|
|
770
|
-
skip: number$1().min(0).default(0)
|
|
771
|
-
}) };
|
|
772
|
-
object({
|
|
773
|
-
data: object({ experts: array(expertScopeSchema.extend({ currentVersion: expertVersionSchema.nullable() })) }),
|
|
774
|
-
meta: paginationMeta
|
|
775
|
-
});
|
|
776
|
-
const anthropicSupportModels = [
|
|
777
|
-
{
|
|
778
|
-
modelId: "claude-opus-4-5",
|
|
779
|
-
default: false,
|
|
780
|
-
provider: "anthropic",
|
|
781
|
-
contextWindow: 2e5
|
|
782
|
-
},
|
|
783
|
-
{
|
|
784
|
-
modelId: "claude-opus-4-1",
|
|
785
|
-
default: false,
|
|
786
|
-
provider: "anthropic",
|
|
787
|
-
contextWindow: 2e5
|
|
788
|
-
},
|
|
789
|
-
{
|
|
790
|
-
modelId: "claude-opus-4-20250514",
|
|
791
|
-
default: false,
|
|
792
|
-
provider: "anthropic",
|
|
793
|
-
contextWindow: 2e5
|
|
794
|
-
},
|
|
795
|
-
{
|
|
796
|
-
modelId: "claude-sonnet-4-5",
|
|
797
|
-
default: true,
|
|
798
|
-
provider: "anthropic",
|
|
799
|
-
contextWindow: 2e5
|
|
800
|
-
},
|
|
801
|
-
{
|
|
802
|
-
modelId: "claude-sonnet-4-20250514",
|
|
803
|
-
default: false,
|
|
804
|
-
provider: "anthropic",
|
|
805
|
-
contextWindow: 2e5
|
|
806
|
-
},
|
|
807
|
-
{
|
|
808
|
-
modelId: "claude-3-7-sonnet-20250219",
|
|
809
|
-
default: false,
|
|
810
|
-
provider: "anthropic",
|
|
811
|
-
contextWindow: 2e5
|
|
812
|
-
},
|
|
813
|
-
{
|
|
814
|
-
modelId: "claude-haiku-4-5",
|
|
815
|
-
default: false,
|
|
816
|
-
provider: "anthropic",
|
|
817
|
-
contextWindow: 2e5
|
|
818
|
-
},
|
|
819
|
-
{
|
|
820
|
-
modelId: "claude-3-5-haiku-latest",
|
|
821
|
-
default: false,
|
|
822
|
-
provider: "anthropic",
|
|
823
|
-
contextWindow: 2e5
|
|
824
|
-
}
|
|
825
|
-
];
|
|
826
|
-
const googleSupportModels = [
|
|
827
|
-
{
|
|
828
|
-
modelId: "gemini-3-pro-preview",
|
|
829
|
-
default: false,
|
|
830
|
-
provider: "google",
|
|
831
|
-
contextWindow: 1e6
|
|
832
|
-
},
|
|
833
|
-
{
|
|
834
|
-
modelId: "gemini-2.5-pro",
|
|
835
|
-
default: true,
|
|
836
|
-
provider: "google",
|
|
837
|
-
contextWindow: 1e6
|
|
838
|
-
},
|
|
839
|
-
{
|
|
840
|
-
modelId: "gemini-2.5-flash",
|
|
841
|
-
default: false,
|
|
842
|
-
provider: "google",
|
|
843
|
-
contextWindow: 1e6
|
|
844
|
-
},
|
|
845
|
-
{
|
|
846
|
-
modelId: "gemini-2.5-flash-lite",
|
|
847
|
-
default: false,
|
|
848
|
-
provider: "google",
|
|
849
|
-
contextWindow: 1e6
|
|
850
|
-
}
|
|
851
|
-
];
|
|
852
|
-
const openAiSupportModels = [
|
|
853
|
-
{
|
|
854
|
-
modelId: "gpt-5",
|
|
855
|
-
default: true,
|
|
856
|
-
provider: "openai",
|
|
857
|
-
contextWindow: 4e5
|
|
858
|
-
},
|
|
859
|
-
{
|
|
860
|
-
modelId: "gpt-5-mini",
|
|
861
|
-
default: false,
|
|
862
|
-
provider: "openai",
|
|
863
|
-
contextWindow: 4e5
|
|
864
|
-
},
|
|
865
|
-
{
|
|
866
|
-
modelId: "gpt-5-nano",
|
|
867
|
-
default: false,
|
|
868
|
-
provider: "openai",
|
|
869
|
-
contextWindow: 4e5
|
|
870
|
-
},
|
|
871
|
-
{
|
|
872
|
-
modelId: "gpt-5-chat-latest",
|
|
873
|
-
default: false,
|
|
874
|
-
provider: "openai",
|
|
875
|
-
contextWindow: 128e3
|
|
876
|
-
},
|
|
877
|
-
{
|
|
878
|
-
modelId: "o4-mini",
|
|
879
|
-
default: false,
|
|
880
|
-
provider: "openai",
|
|
881
|
-
contextWindow: 2e5
|
|
882
|
-
},
|
|
883
|
-
{
|
|
884
|
-
modelId: "o3",
|
|
885
|
-
default: false,
|
|
886
|
-
provider: "openai",
|
|
887
|
-
contextWindow: 2e5
|
|
888
|
-
},
|
|
889
|
-
{
|
|
890
|
-
modelId: "o3-mini",
|
|
891
|
-
default: false,
|
|
892
|
-
provider: "openai",
|
|
893
|
-
contextWindow: 2e5
|
|
894
|
-
},
|
|
895
|
-
{
|
|
896
|
-
modelId: "gpt-4.1",
|
|
897
|
-
default: false,
|
|
898
|
-
provider: "openai",
|
|
899
|
-
contextWindow: 1e6
|
|
900
|
-
}
|
|
901
|
-
];
|
|
902
|
-
const deepseekSupportModels = [{
|
|
903
|
-
modelId: "deepseek-chat",
|
|
904
|
-
default: true,
|
|
905
|
-
provider: "deepseek",
|
|
906
|
-
contextWindow: 128e3
|
|
907
|
-
}, {
|
|
908
|
-
modelId: "deepseek-reasoner",
|
|
909
|
-
default: false,
|
|
910
|
-
provider: "deepseek",
|
|
911
|
-
contextWindow: 128e3
|
|
912
|
-
}];
|
|
913
|
-
const allSupportModels = [
|
|
914
|
-
...anthropicSupportModels,
|
|
915
|
-
...googleSupportModels,
|
|
916
|
-
...openAiSupportModels,
|
|
917
|
-
...deepseekSupportModels
|
|
918
|
-
];
|
|
919
|
-
const supportModels = Object.fromEntries(allSupportModels.map((model) => [model.modelId, model]));
|
|
920
|
-
function getSupportModelNames() {
|
|
921
|
-
return Object.keys(supportModels);
|
|
922
|
-
}
|
|
923
|
-
const reasoningBudgetSchema = union([_enum([
|
|
924
|
-
"none",
|
|
925
|
-
"minimal",
|
|
926
|
-
"low",
|
|
927
|
-
"medium",
|
|
928
|
-
"high"
|
|
929
|
-
]), number().int().min(0)]);
|
|
930
|
-
const jobStatusSchema = _enum([
|
|
931
|
-
"queued",
|
|
932
|
-
"processing",
|
|
933
|
-
"completed",
|
|
934
|
-
"requestInteractiveToolResult",
|
|
935
|
-
"requestDelegateResult",
|
|
936
|
-
"exceededMaxSteps",
|
|
937
|
-
"failed",
|
|
938
|
-
"canceling",
|
|
939
|
-
"canceled",
|
|
940
|
-
"expired"
|
|
941
|
-
]);
|
|
942
|
-
const modelNames = getSupportModelNames();
|
|
943
|
-
const firstModel = modelNames[0];
|
|
944
|
-
if (firstModel === void 0) throw new Error("No support models available");
|
|
945
|
-
const jobModelSchema = _enum([firstModel, ...modelNames.slice(1)]);
|
|
946
|
-
const jobBaseSchema = object({
|
|
947
|
-
type: literal("job"),
|
|
948
|
-
id: cuidSchema,
|
|
949
|
-
organizationId: cuidSchema,
|
|
950
|
-
applicationId: cuidSchema,
|
|
951
|
-
createdAt: datetimeSchema,
|
|
952
|
-
updatedAt: datetimeSchema,
|
|
953
|
-
status: jobStatusSchema,
|
|
954
|
-
currentExecutionId: cuidSchema.optional(),
|
|
955
|
-
coordinatorExpertKey: expertKeyFieldSchema,
|
|
956
|
-
query: string().min(1).max(maxExpertJobQueryLength).optional(),
|
|
957
|
-
expert: expertWithMetadataSchema,
|
|
958
|
-
provider: providerSchema,
|
|
959
|
-
model: jobModelSchema,
|
|
960
|
-
reasoningBudget: reasoningBudgetSchema,
|
|
961
|
-
runtimeVersion: runtimeVersionSchema,
|
|
962
|
-
maxSteps: number().int().min(1),
|
|
963
|
-
maxRetries: number().int().min(0),
|
|
964
|
-
currentStep: number().int().min(0),
|
|
965
|
-
totalSteps: number().int().min(0),
|
|
966
|
-
totalDuration: number().int().min(0),
|
|
967
|
-
usage: usageSchema,
|
|
968
|
-
lastActivity: activityOrGroupSchema.nullable().optional()
|
|
969
|
-
});
|
|
970
|
-
const publishedJobSchema = jobBaseSchema.extend({
|
|
971
|
-
expertVersionId: cuidSchema,
|
|
972
|
-
expertDraftRefId: _undefined()
|
|
973
|
-
});
|
|
974
|
-
const draftJobSchema = jobBaseSchema.extend({
|
|
975
|
-
expertVersionId: _undefined(),
|
|
976
|
-
expertDraftRefId: cuidSchema
|
|
977
|
-
});
|
|
978
|
-
const jobSchema = union([publishedJobSchema, draftJobSchema]);
|
|
979
|
-
const request$7 = {
|
|
980
|
-
params: object({ jobId: cuidSchema }),
|
|
981
|
-
body: object({
|
|
982
|
-
query: string().min(1).max(maxExpertJobQueryLength),
|
|
983
|
-
provider: providerSchema.optional(),
|
|
984
|
-
model: jobModelSchema.optional(),
|
|
985
|
-
reasoningBudget: reasoningBudgetSchema.optional(),
|
|
986
|
-
maxSteps: number$1().optional(),
|
|
987
|
-
maxRetries: number$1().optional()
|
|
988
|
-
})
|
|
989
|
-
};
|
|
990
|
-
object({ data: object({ job: jobSchema }) });
|
|
991
|
-
const request$6 = { body: object({
|
|
992
|
-
applicationId: cuidSchema.describe("Application ID to create the job in"),
|
|
993
|
-
query: string().min(1).max(maxExpertJobQueryLength),
|
|
994
|
-
provider: providerSchema,
|
|
995
|
-
model: jobModelSchema.optional(),
|
|
996
|
-
reasoningBudget: reasoningBudgetSchema.optional(),
|
|
997
|
-
maxSteps: number$1().optional(),
|
|
998
|
-
maxRetries: number$1().optional()
|
|
999
|
-
}).extend({
|
|
1000
|
-
expertKey: expertKeyFieldSchema.optional(),
|
|
1001
|
-
draftRefId: cuidSchema.describe("Draft ref ID to run the job with").optional()
|
|
1002
|
-
}).refine((data) => {
|
|
1003
|
-
const hasExpertKey = data.expertKey !== void 0;
|
|
1004
|
-
const hasDraftRefId = data.draftRefId !== void 0;
|
|
1005
|
-
return hasExpertKey && !hasDraftRefId || !hasExpertKey && hasDraftRefId;
|
|
1006
|
-
}, { message: "Either expertKey or draftRefId must be provided, but not both" }) };
|
|
1007
|
-
object({ data: object({ job: jobSchema }) });
|
|
1008
|
-
const request$5 = { query: object({
|
|
1009
|
-
sort: _enum(["createdAt", "updatedAt"]).optional(),
|
|
1010
|
-
order: _enum(["asc", "desc"]).optional(),
|
|
1011
|
-
take: number$1().min(1).max(100).default(20),
|
|
1012
|
-
skip: number$1().min(0).default(0),
|
|
1013
|
-
expertScopeId: cuidSchema.optional(),
|
|
1014
|
-
expertDraftScopeId: cuidSchema.optional(),
|
|
1015
|
-
applicationId: cuidSchema.optional(),
|
|
1016
|
-
statuses: preprocess((val) => typeof val === "string" ? val.split(",") : val, array(jobStatusSchema).optional()),
|
|
1017
|
-
expertKeyFilter: string().max(100).optional()
|
|
1018
|
-
}) };
|
|
1019
|
-
object({
|
|
1020
|
-
data: object({ jobs: array(jobSchema) }),
|
|
1021
|
-
meta: paginationMeta
|
|
1022
|
-
});
|
|
1023
|
-
const delegationTargetSchema = object({
|
|
1024
|
-
expert: expertSchema,
|
|
1025
|
-
toolCallId: string().min(1).max(maxCheckpointToolCallIdLength),
|
|
1026
|
-
toolName: string().min(1).max(maxSkillToolNameLength),
|
|
1027
|
-
query: string().min(1)
|
|
1028
|
-
});
|
|
1029
|
-
/**
|
|
1030
|
-
* API Checkpoint schema - extended checkpoint format for API responses.
|
|
1031
|
-
* Includes additional fields computed from runtime checkpoint and step data:
|
|
1032
|
-
* - activities: computed via getActivities() from @perstack/core
|
|
1033
|
-
* - inputMessages, newMessages, toolCalls, toolResults: step-related data
|
|
1034
|
-
* - expert: full Expert type (with instruction, skills, etc.)
|
|
1035
|
-
* - startedAt/finishedAt: ISO string format (runtime uses Unix timestamps)
|
|
1036
|
-
*/
|
|
1037
|
-
const apiCheckpointSchema = object({
|
|
1038
|
-
type: literal("checkpoint"),
|
|
1039
|
-
id: cuidSchema,
|
|
1040
|
-
jobId: cuidSchema,
|
|
1041
|
-
runId: cuidSchema,
|
|
1042
|
-
activities: array(activityOrGroupSchema),
|
|
1043
|
-
stepNumber: number().int().min(1),
|
|
1044
|
-
status: _enum([
|
|
1045
|
-
"init",
|
|
1046
|
-
"proceeding",
|
|
1047
|
-
"completed",
|
|
1048
|
-
"stoppedByInteractiveTool",
|
|
1049
|
-
"stoppedByDelegate",
|
|
1050
|
-
"stoppedByExceededMaxSteps",
|
|
1051
|
-
"stoppedByError"
|
|
1052
|
-
]),
|
|
1053
|
-
expert: expertSchema,
|
|
1054
|
-
delegateTo: array(delegationTargetSchema).optional(),
|
|
1055
|
-
delegatedBy: object({
|
|
1056
|
-
expert: expertSchema,
|
|
1057
|
-
toolCallId: string().min(1).max(maxCheckpointToolCallIdLength),
|
|
1058
|
-
toolName: string().min(1).max(maxSkillToolNameLength),
|
|
1059
|
-
checkpointId: cuidSchema,
|
|
1060
|
-
runId: cuidSchema
|
|
1061
|
-
}).optional(),
|
|
1062
|
-
inputMessages: array(union([
|
|
1063
|
-
instructionMessageSchema,
|
|
1064
|
-
userMessageSchema,
|
|
1065
|
-
toolMessageSchema
|
|
1066
|
-
])).optional(),
|
|
1067
|
-
messages: array(messageSchema),
|
|
1068
|
-
newMessages: array(messageSchema),
|
|
1069
|
-
toolCalls: array(toolCallSchema).optional(),
|
|
1070
|
-
toolResults: array(toolResultSchema).optional(),
|
|
1071
|
-
pendingToolCalls: array(toolCallSchema).optional(),
|
|
1072
|
-
partialToolResults: array(toolResultSchema).optional(),
|
|
1073
|
-
usage: usageSchema,
|
|
1074
|
-
contextWindow: number().int().min(0).optional(),
|
|
1075
|
-
contextWindowUsage: number().int().min(0).optional(),
|
|
1076
|
-
error: object({
|
|
1077
|
-
name: string().min(1),
|
|
1078
|
-
message: string().min(1),
|
|
1079
|
-
statusCode: number().int().min(100).max(599).optional(),
|
|
1080
|
-
isRetryable: boolean()
|
|
1081
|
-
}).optional(),
|
|
1082
|
-
retryCount: number().int().min(0).optional(),
|
|
1083
|
-
startedAt: datetimeSchema,
|
|
1084
|
-
finishedAt: datetimeSchema.optional()
|
|
1085
|
-
});
|
|
1086
|
-
const request$4 = {
|
|
1087
|
-
params: object({
|
|
1088
|
-
jobId: cuidSchema,
|
|
1089
|
-
runId: cuidSchema
|
|
1090
|
-
}),
|
|
1091
|
-
query: object({
|
|
1092
|
-
filter: string().min(1).max(256).optional(),
|
|
1093
|
-
sort: _enum(["createdAt", "updatedAt"]).optional(),
|
|
1094
|
-
order: _enum(["asc", "desc"]).optional(),
|
|
1095
|
-
take: number$1().min(1).max(100).default(20),
|
|
1096
|
-
skip: number$1().min(0).default(0)
|
|
1097
|
-
})
|
|
1098
|
-
};
|
|
1099
|
-
object({
|
|
1100
|
-
data: object({ checkpoints: array(apiCheckpointSchema) }),
|
|
1101
|
-
meta: paginationMeta
|
|
1102
|
-
});
|
|
1103
|
-
const runStatusSchema = _enum([
|
|
1104
|
-
"queued",
|
|
1105
|
-
"processing",
|
|
1106
|
-
"completed",
|
|
1107
|
-
"stoppedByInteractiveTool",
|
|
1108
|
-
"stoppedByDelegate",
|
|
1109
|
-
"stoppedByExceededMaxSteps",
|
|
1110
|
-
"stoppedByError"
|
|
1111
|
-
]);
|
|
1112
|
-
const runSchema = object({
|
|
1113
|
-
type: literal("run"),
|
|
1114
|
-
id: cuidSchema,
|
|
1115
|
-
jobId: cuidSchema,
|
|
1116
|
-
executionId: cuidSchema.optional(),
|
|
1117
|
-
parentRunId: cuidSchema.optional(),
|
|
1118
|
-
organizationId: cuidSchema,
|
|
1119
|
-
createdAt: datetimeSchema,
|
|
1120
|
-
updatedAt: datetimeSchema,
|
|
1121
|
-
status: runStatusSchema,
|
|
1122
|
-
expertKey: expertKeyFieldSchema,
|
|
1123
|
-
expert: expertWithMetadataSchema,
|
|
1124
|
-
stepNumber: number().int().min(0),
|
|
1125
|
-
usage: usageSchema
|
|
1126
|
-
});
|
|
1127
|
-
const request$3 = {
|
|
1128
|
-
params: object({ jobId: cuidSchema }),
|
|
1129
|
-
query: object({
|
|
1130
|
-
sort: _enum(["createdAt", "updatedAt"]).optional(),
|
|
1131
|
-
order: _enum(["asc", "desc"]).optional(),
|
|
1132
|
-
take: number$1().min(1).max(100).default(20),
|
|
1133
|
-
skip: number$1().min(0).default(0)
|
|
1134
|
-
})
|
|
1135
|
-
};
|
|
1136
|
-
object({
|
|
1137
|
-
data: object({ runs: array(runSchema) }),
|
|
1138
|
-
meta: paginationMeta
|
|
1139
|
-
});
|
|
1140
|
-
const baseUrlSchema = string().url().max(maxProviderBaseUrlLength).optional();
|
|
1141
|
-
const headersSchema = record(string().min(1).max(maxProviderHeaderKeyLength), string().max(maxProviderHeaderValueLength)).refine((headers) => Object.keys(headers).length <= maxProviderHeadersCount, { message: `Headers must have at most ${maxProviderHeadersCount} entries` }).optional();
|
|
1142
|
-
const anthropicProviderSettingsSchema = object({
|
|
1143
|
-
baseUrl: baseUrlSchema,
|
|
1144
|
-
headers: headersSchema
|
|
1145
|
-
});
|
|
1146
|
-
const googleProviderSettingsSchema = object({
|
|
1147
|
-
baseUrl: baseUrlSchema,
|
|
1148
|
-
headers: headersSchema
|
|
1149
|
-
});
|
|
1150
|
-
const openaiProviderSettingsSchema = object({
|
|
1151
|
-
baseUrl: baseUrlSchema,
|
|
1152
|
-
headers: headersSchema,
|
|
1153
|
-
organization: string().min(1).optional(),
|
|
1154
|
-
project: string().min(1).optional(),
|
|
1155
|
-
name: string().min(1).optional()
|
|
1156
|
-
});
|
|
1157
|
-
const deepseekProviderSettingsSchema = object({
|
|
1158
|
-
baseUrl: baseUrlSchema,
|
|
1159
|
-
headers: headersSchema
|
|
1160
|
-
});
|
|
1161
|
-
const azureOpenaiProviderSettingsSchema = object({
|
|
1162
|
-
baseUrl: baseUrlSchema,
|
|
1163
|
-
headers: headersSchema,
|
|
1164
|
-
resourceName: string().min(1).optional(),
|
|
1165
|
-
apiVersion: string().min(1).optional(),
|
|
1166
|
-
useDeploymentBasedUrls: boolean().optional()
|
|
1167
|
-
});
|
|
1168
|
-
const amazonBedrockProviderSettingsSchema = object({ region: string().min(1).optional() });
|
|
1169
|
-
const googleVertexProviderSettingsSchema = object({
|
|
1170
|
-
baseUrl: baseUrlSchema,
|
|
1171
|
-
headers: headersSchema,
|
|
1172
|
-
project: string().min(1).optional(),
|
|
1173
|
-
location: string().min(1).optional()
|
|
1174
|
-
});
|
|
1175
|
-
const providerSettingsSchema = union([
|
|
1176
|
-
anthropicProviderSettingsSchema,
|
|
1177
|
-
googleProviderSettingsSchema,
|
|
1178
|
-
openaiProviderSettingsSchema,
|
|
1179
|
-
deepseekProviderSettingsSchema,
|
|
1180
|
-
azureOpenaiProviderSettingsSchema,
|
|
1181
|
-
amazonBedrockProviderSettingsSchema,
|
|
1182
|
-
googleVertexProviderSettingsSchema
|
|
1183
|
-
]);
|
|
1184
|
-
object({
|
|
1185
|
-
type: literal("providerSetting"),
|
|
1186
|
-
id: cuidSchema,
|
|
1187
|
-
applicationId: cuidSchema,
|
|
1188
|
-
provider: providerSchema,
|
|
1189
|
-
settings: providerSettingsSchema.optional(),
|
|
1190
|
-
application: applicationSchema,
|
|
1191
|
-
createdAt: datetimeSchema,
|
|
1192
|
-
updatedAt: datetimeSchema
|
|
1193
|
-
});
|
|
1194
|
-
const providerSettingResponseSchema = object({
|
|
1195
|
-
type: literal("providerSetting"),
|
|
1196
|
-
id: cuidSchema,
|
|
1197
|
-
provider: providerSchema,
|
|
1198
|
-
settings: providerSettingsSchema.optional(),
|
|
1199
|
-
createdAt: datetimeSchema,
|
|
1200
|
-
updatedAt: datetimeSchema
|
|
1201
|
-
});
|
|
1202
|
-
const providerApiKeyMetadataSchema = object({
|
|
1203
|
-
id: cuidSchema,
|
|
1204
|
-
name: string(),
|
|
1205
|
-
createdAt: datetimeSchema,
|
|
1206
|
-
updatedAt: datetimeSchema,
|
|
1207
|
-
lastUsedAt: datetimeSchema.nullable(),
|
|
1208
|
-
expiresAt: datetimeSchema.nullable()
|
|
1209
|
-
});
|
|
1210
|
-
const request$2 = {
|
|
1211
|
-
params: object({
|
|
1212
|
-
applicationId: cuidSchema,
|
|
1213
|
-
provider: providerSchema
|
|
1214
|
-
}),
|
|
1215
|
-
body: object({
|
|
1216
|
-
name: string().min(1).max(255),
|
|
1217
|
-
value: string().min(1)
|
|
1218
|
-
})
|
|
1219
|
-
};
|
|
1220
|
-
object({ data: object({ apiKey: providerApiKeyMetadataSchema }) });
|
|
1221
|
-
const request$1 = {
|
|
1222
|
-
params: object({ applicationId: cuidSchema }),
|
|
1223
|
-
body: object({
|
|
1224
|
-
provider: providerSchema,
|
|
1225
|
-
settings: providerSettingsSchema.optional()
|
|
1226
|
-
})
|
|
1227
|
-
};
|
|
1228
|
-
object({ data: object({ providerSetting: providerSettingResponseSchema }) });
|
|
1229
|
-
const request = {
|
|
1230
|
-
params: object({
|
|
1231
|
-
applicationId: cuidSchema,
|
|
1232
|
-
provider: providerSchema
|
|
1233
|
-
}),
|
|
1234
|
-
body: object({ settings: providerSettingsSchema.optional() })
|
|
1235
|
-
};
|
|
1236
|
-
object({ data: object({ providerSetting: providerSettingResponseSchema }) });
|
|
1237
|
-
function createRunCheckpointsApi(fetcher, basePath) {
|
|
1238
|
-
return {
|
|
1239
|
-
async list(jobId, runId, params, options) {
|
|
1240
|
-
if (params) {
|
|
1241
|
-
const result = request$4.query.safeParse(params);
|
|
1242
|
-
if (!result.success) return {
|
|
1243
|
-
ok: false,
|
|
1244
|
-
error: createValidationError(result.error)
|
|
1245
|
-
};
|
|
1246
|
-
}
|
|
1247
|
-
const queryString = buildQueryString(params);
|
|
1248
|
-
return fetcher.get(`${basePath}/${jobId}/runs/${runId}/checkpoints${queryString}`, options);
|
|
1249
|
-
},
|
|
1250
|
-
async get(jobId, runId, checkpointId, options) {
|
|
1251
|
-
return fetcher.get(`${basePath}/${jobId}/runs/${runId}/checkpoints/${checkpointId}`, options);
|
|
1252
|
-
}
|
|
1253
|
-
};
|
|
1254
|
-
}
|
|
1255
|
-
function createRunsApi(fetcher, basePath) {
|
|
1256
|
-
return {
|
|
1257
|
-
async list(jobId, params, options) {
|
|
1258
|
-
if (params) {
|
|
1259
|
-
const result = request$3.query.safeParse(params);
|
|
1260
|
-
if (!result.success) return {
|
|
1261
|
-
ok: false,
|
|
1262
|
-
error: createValidationError(result.error)
|
|
1263
|
-
};
|
|
1264
|
-
}
|
|
1265
|
-
const queryString = buildQueryString(params);
|
|
1266
|
-
return fetcher.get(`${basePath}/${jobId}/runs${queryString}`, options);
|
|
1267
|
-
},
|
|
1268
|
-
async get(jobId, runId, options) {
|
|
1269
|
-
return fetcher.get(`${basePath}/${jobId}/runs/${runId}`, options);
|
|
1270
|
-
},
|
|
1271
|
-
checkpoints: createRunCheckpointsApi(fetcher, basePath)
|
|
1272
|
-
};
|
|
1273
|
-
}
|
|
1274
|
-
const BASE_PATH$5 = "/api/v1/jobs";
|
|
1275
|
-
/**
|
|
1276
|
-
* Error thrown when stream ends abnormally.
|
|
1277
|
-
*/
|
|
1278
|
-
var StreamError = class extends Error {
|
|
1279
|
-
constructor(type, jobId, message) {
|
|
1280
|
-
super(message ?? `Stream error: ${type}`);
|
|
1281
|
-
this.type = type;
|
|
1282
|
-
this.jobId = jobId;
|
|
1283
|
-
this.name = "StreamError";
|
|
1284
|
-
}
|
|
1285
|
-
};
|
|
1286
|
-
/**
|
|
1287
|
-
* Error thrown when stream connection or reading fails.
|
|
1288
|
-
*/
|
|
1289
|
-
var StreamConnectionError = class extends Error {
|
|
1290
|
-
constructor(message) {
|
|
1291
|
-
super(message);
|
|
1292
|
-
this.name = "StreamConnectionError";
|
|
1293
|
-
}
|
|
1294
|
-
};
|
|
1295
|
-
function isErrorEventData(data) {
|
|
1296
|
-
return typeof data === "object" && data !== null && "type" in data && typeof data.type === "string" && "jobId" in data && typeof data.jobId === "string";
|
|
1297
|
-
}
|
|
1298
|
-
function isCompleteEventData(data) {
|
|
1299
|
-
return typeof data === "object" && data !== null && "status" in data && typeof data.status === "string" && "jobId" in data && typeof data.jobId === "string";
|
|
1300
|
-
}
|
|
1301
|
-
function createJobsApi(fetcher) {
|
|
1302
|
-
return {
|
|
1303
|
-
async list(params, options) {
|
|
1304
|
-
if (params) {
|
|
1305
|
-
const result = request$5.query.safeParse(params);
|
|
1306
|
-
if (!result.success) return {
|
|
1307
|
-
ok: false,
|
|
1308
|
-
error: createValidationError(result.error)
|
|
1309
|
-
};
|
|
1310
|
-
}
|
|
1311
|
-
const queryString = buildQueryString(params);
|
|
1312
|
-
return fetcher.get(`${BASE_PATH$5}${queryString}`, options);
|
|
1313
|
-
},
|
|
1314
|
-
async get(id, options) {
|
|
1315
|
-
return fetcher.get(`${BASE_PATH$5}/${id}`, options);
|
|
1316
|
-
},
|
|
1317
|
-
async start(input, options) {
|
|
1318
|
-
const result = request$6.body.safeParse(input);
|
|
1319
|
-
if (!result.success) return {
|
|
1320
|
-
ok: false,
|
|
1321
|
-
error: createValidationError(result.error)
|
|
1322
|
-
};
|
|
1323
|
-
return fetcher.post(BASE_PATH$5, input, options);
|
|
1324
|
-
},
|
|
1325
|
-
async continue(id, input, options) {
|
|
1326
|
-
const result = request$7.body.safeParse(input);
|
|
1327
|
-
if (!result.success) return {
|
|
1328
|
-
ok: false,
|
|
1329
|
-
error: createValidationError(result.error)
|
|
1330
|
-
};
|
|
1331
|
-
return fetcher.post(`${BASE_PATH$5}/${id}/continue`, input, options);
|
|
1332
|
-
},
|
|
1333
|
-
async cancel(id, options) {
|
|
1334
|
-
return fetcher.post(`${BASE_PATH$5}/${id}/cancel`, {}, options);
|
|
1335
|
-
},
|
|
1336
|
-
async *stream(id, options) {
|
|
1337
|
-
const result = await fetcher.getStream(`${BASE_PATH$5}/${id}/stream`, options);
|
|
1338
|
-
if (!result.ok) throw new StreamConnectionError(result.error.message);
|
|
1339
|
-
const reader = result.data.getReader();
|
|
1340
|
-
try {
|
|
1341
|
-
for await (const sseEvent of parseSSEEvents(reader)) if (sseEvent.event === "message") yield sseEvent.data;
|
|
1342
|
-
else if (sseEvent.event === "error" && isErrorEventData(sseEvent.data)) throw new StreamError(sseEvent.data.type, sseEvent.data.jobId, sseEvent.data.message);
|
|
1343
|
-
else if (sseEvent.event === "complete" && isCompleteEventData(sseEvent.data)) return;
|
|
1344
|
-
} catch (error) {
|
|
1345
|
-
if (error instanceof StreamError || error instanceof StreamConnectionError) throw error;
|
|
1346
|
-
if (error instanceof DOMException && error.name === "AbortError") throw error;
|
|
1347
|
-
throw new StreamConnectionError(error instanceof Error ? error.message : "Stream read error");
|
|
1348
|
-
}
|
|
1349
|
-
},
|
|
1350
|
-
runs: createRunsApi(fetcher, BASE_PATH$5)
|
|
1351
|
-
};
|
|
1352
|
-
}
|
|
1353
|
-
const BASE_PATH$4 = "/api/v1/applications";
|
|
1354
|
-
function createApplicationsApi(fetcher) {
|
|
1355
|
-
return {
|
|
1356
|
-
async list(params, options) {
|
|
1357
|
-
if (params) {
|
|
1358
|
-
const result = request$16.query.safeParse(params);
|
|
1359
|
-
if (!result.success) return {
|
|
1360
|
-
ok: false,
|
|
1361
|
-
error: createValidationError(result.error)
|
|
1362
|
-
};
|
|
1363
|
-
}
|
|
1364
|
-
const queryString = buildQueryString(params);
|
|
1365
|
-
return fetcher.get(`${BASE_PATH$4}${queryString}`, options);
|
|
1366
|
-
},
|
|
1367
|
-
async get(id, options) {
|
|
1368
|
-
return fetcher.get(`${BASE_PATH$4}/${id}`, options);
|
|
1369
|
-
},
|
|
1370
|
-
async create(input, options) {
|
|
1371
|
-
const result = request$17.body.safeParse(input);
|
|
1372
|
-
if (!result.success) return {
|
|
1373
|
-
ok: false,
|
|
1374
|
-
error: createValidationError(result.error)
|
|
1375
|
-
};
|
|
1376
|
-
return fetcher.post(BASE_PATH$4, input, options);
|
|
1377
|
-
},
|
|
1378
|
-
async update(id, input, options) {
|
|
1379
|
-
const result = request$15.body.safeParse(input);
|
|
1380
|
-
if (!result.success) return {
|
|
1381
|
-
ok: false,
|
|
1382
|
-
error: createValidationError(result.error)
|
|
1383
|
-
};
|
|
1384
|
-
return fetcher.post(`${BASE_PATH$4}/${id}`, input, options);
|
|
1385
|
-
},
|
|
1386
|
-
async delete(id, options) {
|
|
1387
|
-
return fetcher.delete(`${BASE_PATH$4}/${id}`, options);
|
|
1388
|
-
}
|
|
1389
|
-
};
|
|
1390
|
-
}
|
|
1391
|
-
const BASE_PATH$3 = "/api/v1/env/secrets";
|
|
1392
|
-
function createSecretsApi(fetcher) {
|
|
1393
|
-
return {
|
|
1394
|
-
async list(params, options) {
|
|
1395
|
-
if (params) {
|
|
1396
|
-
const result = request$13.query.safeParse(params);
|
|
1397
|
-
if (!result.success) return {
|
|
1398
|
-
ok: false,
|
|
1399
|
-
error: createValidationError(result.error)
|
|
1400
|
-
};
|
|
1401
|
-
}
|
|
1402
|
-
const queryString = buildQueryString(params);
|
|
1403
|
-
return fetcher.get(`${BASE_PATH$3}${queryString}`, options);
|
|
1404
|
-
},
|
|
1405
|
-
async get(name, options) {
|
|
1406
|
-
const encodedName = encodeURIComponent(name);
|
|
1407
|
-
return fetcher.get(`${BASE_PATH$3}/${encodedName}`, options);
|
|
1408
|
-
},
|
|
1409
|
-
async create(input, options) {
|
|
1410
|
-
const result = request$14.body.safeParse(input);
|
|
1411
|
-
if (!result.success) return {
|
|
1412
|
-
ok: false,
|
|
1413
|
-
error: createValidationError(result.error)
|
|
1414
|
-
};
|
|
1415
|
-
return fetcher.post(BASE_PATH$3, input, options);
|
|
1416
|
-
},
|
|
1417
|
-
async update(name, input, options) {
|
|
1418
|
-
const result = request$12.body.safeParse(input);
|
|
1419
|
-
if (!result.success) return {
|
|
1420
|
-
ok: false,
|
|
1421
|
-
error: createValidationError(result.error)
|
|
1422
|
-
};
|
|
1423
|
-
const encodedName = encodeURIComponent(name);
|
|
1424
|
-
return fetcher.put(`${BASE_PATH$3}/${encodedName}`, input, options);
|
|
1425
|
-
},
|
|
1426
|
-
async delete(name, options) {
|
|
1427
|
-
const encodedName = encodeURIComponent(name);
|
|
1428
|
-
return fetcher.deleteNoContent(`${BASE_PATH$3}/${encodedName}`, options);
|
|
1429
|
-
}
|
|
1430
|
-
};
|
|
1431
|
-
}
|
|
1432
|
-
const BASE_PATH$2 = "/api/v1/env/variables";
|
|
1433
|
-
function createVariablesApi(fetcher) {
|
|
1434
|
-
return {
|
|
1435
|
-
async list(params, options) {
|
|
1436
|
-
const result = request$10.query.safeParse(params);
|
|
1437
|
-
if (!result.success) return {
|
|
1438
|
-
ok: false,
|
|
1439
|
-
error: createValidationError(result.error)
|
|
1440
|
-
};
|
|
1441
|
-
const queryString = buildQueryString(params);
|
|
1442
|
-
return fetcher.get(`${BASE_PATH$2}${queryString}`, options);
|
|
1443
|
-
},
|
|
1444
|
-
async get(name, options) {
|
|
1445
|
-
const encodedName = encodeURIComponent(name);
|
|
1446
|
-
return fetcher.get(`${BASE_PATH$2}/${encodedName}`, options);
|
|
1447
|
-
},
|
|
1448
|
-
async create(input, options) {
|
|
1449
|
-
const result = request$11.body.safeParse(input);
|
|
1450
|
-
if (!result.success) return {
|
|
1451
|
-
ok: false,
|
|
1452
|
-
error: createValidationError(result.error)
|
|
1453
|
-
};
|
|
1454
|
-
return fetcher.post(BASE_PATH$2, input, options);
|
|
1455
|
-
},
|
|
1456
|
-
async update(name, input, options) {
|
|
1457
|
-
const result = request$9.body.safeParse(input);
|
|
1458
|
-
if (!result.success) return {
|
|
1459
|
-
ok: false,
|
|
1460
|
-
error: createValidationError(result.error)
|
|
1461
|
-
};
|
|
1462
|
-
const encodedName = encodeURIComponent(name);
|
|
1463
|
-
return fetcher.put(`${BASE_PATH$2}/${encodedName}`, input, options);
|
|
1464
|
-
},
|
|
1465
|
-
async delete(name, options) {
|
|
1466
|
-
const encodedName = encodeURIComponent(name);
|
|
1467
|
-
return fetcher.deleteNoContent(`${BASE_PATH$2}/${encodedName}`, options);
|
|
1468
|
-
}
|
|
1469
|
-
};
|
|
1470
|
-
}
|
|
1471
|
-
function createEnvApi(fetcher) {
|
|
1472
|
-
return {
|
|
1473
|
-
secrets: createSecretsApi(fetcher),
|
|
1474
|
-
variables: createVariablesApi(fetcher)
|
|
1475
|
-
};
|
|
1476
|
-
}
|
|
1477
|
-
function createVersionsApi(fetcher, basePath) {
|
|
1478
|
-
return { async list(scopeName, options) {
|
|
1479
|
-
const encodedScopeName = encodeURIComponent(scopeName);
|
|
1480
|
-
return fetcher.get(`${basePath}/${encodedScopeName}/versions`, options);
|
|
1481
|
-
} };
|
|
1482
|
-
}
|
|
1483
|
-
const BASE_PATH$1 = "/api/v1/experts";
|
|
1484
|
-
function createExpertsApi(fetcher) {
|
|
1485
|
-
return {
|
|
1486
|
-
async list(params, options) {
|
|
1487
|
-
if (params) {
|
|
1488
|
-
const result = request$8.query.safeParse(params);
|
|
1489
|
-
if (!result.success) return {
|
|
1490
|
-
ok: false,
|
|
1491
|
-
error: createValidationError(result.error)
|
|
1492
|
-
};
|
|
1493
|
-
}
|
|
1494
|
-
const queryString = buildQueryString(params);
|
|
1495
|
-
return fetcher.get(`${BASE_PATH$1}${queryString}`, options);
|
|
1496
|
-
},
|
|
1497
|
-
async get(key, options) {
|
|
1498
|
-
const encodedKey = encodeURIComponent(key);
|
|
1499
|
-
return fetcher.get(`${BASE_PATH$1}/${encodedKey}`, options);
|
|
1500
|
-
},
|
|
1501
|
-
async getFeatured(options) {
|
|
1502
|
-
return fetcher.get(`${BASE_PATH$1}/featured`, options);
|
|
1503
|
-
},
|
|
1504
|
-
async getMeta(key, options) {
|
|
1505
|
-
const encodedKey = encodeURIComponent(key);
|
|
1506
|
-
return fetcher.get(`${BASE_PATH$1}/${encodedKey}/meta`, options);
|
|
1507
|
-
},
|
|
1508
|
-
async publish(scopeName, options) {
|
|
1509
|
-
const encodedScopeName = encodeURIComponent(scopeName);
|
|
1510
|
-
return fetcher.post(`${BASE_PATH$1}/${encodedScopeName}/publish`, {}, options);
|
|
1511
|
-
},
|
|
1512
|
-
async unpublish(scopeName, options) {
|
|
1513
|
-
const encodedScopeName = encodeURIComponent(scopeName);
|
|
1514
|
-
return fetcher.post(`${BASE_PATH$1}/${encodedScopeName}/unpublish`, {}, options);
|
|
1515
|
-
},
|
|
1516
|
-
async yank(key, options) {
|
|
1517
|
-
const encodedKey = encodeURIComponent(key);
|
|
1518
|
-
return fetcher.delete(`${BASE_PATH$1}/${encodedKey}`, options);
|
|
1519
|
-
},
|
|
1520
|
-
versions: createVersionsApi(fetcher, BASE_PATH$1)
|
|
1521
|
-
};
|
|
1522
|
-
}
|
|
1523
|
-
const BASE_PATH = "/api/v1/applications";
|
|
1524
|
-
function createProviderSettingsApi(fetcher) {
|
|
1525
|
-
return {
|
|
1526
|
-
async list(applicationId, options) {
|
|
1527
|
-
return fetcher.get(`${BASE_PATH}/${applicationId}/provider_settings`, options);
|
|
1528
|
-
},
|
|
1529
|
-
async get(applicationId, provider, options) {
|
|
1530
|
-
const encodedProvider = encodeURIComponent(provider);
|
|
1531
|
-
return fetcher.get(`${BASE_PATH}/${applicationId}/provider_settings/${encodedProvider}`, options);
|
|
1532
|
-
},
|
|
1533
|
-
async create(applicationId, input, options) {
|
|
1534
|
-
const result = request$1.body.safeParse(input);
|
|
1535
|
-
if (!result.success) return {
|
|
1536
|
-
ok: false,
|
|
1537
|
-
error: createValidationError(result.error)
|
|
1538
|
-
};
|
|
1539
|
-
return fetcher.post(`${BASE_PATH}/${applicationId}/provider_settings`, input, options);
|
|
1540
|
-
},
|
|
1541
|
-
async update(applicationId, provider, input, options) {
|
|
1542
|
-
const result = request.body.safeParse(input);
|
|
1543
|
-
if (!result.success) return {
|
|
1544
|
-
ok: false,
|
|
1545
|
-
error: createValidationError(result.error)
|
|
1546
|
-
};
|
|
1547
|
-
const encodedProvider = encodeURIComponent(provider);
|
|
1548
|
-
return fetcher.post(`${BASE_PATH}/${applicationId}/provider_settings/${encodedProvider}`, input, options);
|
|
1549
|
-
},
|
|
1550
|
-
async delete(applicationId, provider, options) {
|
|
1551
|
-
const encodedProvider = encodeURIComponent(provider);
|
|
1552
|
-
return fetcher.deleteNoContent(`${BASE_PATH}/${applicationId}/provider_settings/${encodedProvider}`, options);
|
|
1553
|
-
},
|
|
1554
|
-
async listApiKeys(applicationId, provider, options) {
|
|
1555
|
-
const encodedProvider = encodeURIComponent(provider);
|
|
1556
|
-
return fetcher.get(`${BASE_PATH}/${applicationId}/provider_settings/${encodedProvider}/api_keys`, options);
|
|
1557
|
-
},
|
|
1558
|
-
async createApiKey(applicationId, provider, input, options) {
|
|
1559
|
-
const result = request$2.body.safeParse(input);
|
|
1560
|
-
if (!result.success) return {
|
|
1561
|
-
ok: false,
|
|
1562
|
-
error: createValidationError(result.error)
|
|
1563
|
-
};
|
|
1564
|
-
const encodedProvider = encodeURIComponent(provider);
|
|
1565
|
-
return fetcher.post(`${BASE_PATH}/${applicationId}/provider_settings/${encodedProvider}/api_keys`, input, options);
|
|
1566
|
-
},
|
|
1567
|
-
async deleteApiKey(applicationId, provider, apiKeyId, options) {
|
|
1568
|
-
const encodedProvider = encodeURIComponent(provider);
|
|
1569
|
-
const encodedApiKeyId = encodeURIComponent(apiKeyId);
|
|
1570
|
-
return fetcher.deleteNoContent(`${BASE_PATH}/${applicationId}/provider_settings/${encodedProvider}/api_keys/${encodedApiKeyId}`, options);
|
|
1571
|
-
}
|
|
1572
|
-
};
|
|
1573
|
-
}
|
|
1574
|
-
function createApiClient(config) {
|
|
1575
|
-
const fetcher = createFetcher(config);
|
|
1576
|
-
return {
|
|
1577
|
-
applications: createApplicationsApi(fetcher),
|
|
1578
|
-
env: createEnvApi(fetcher),
|
|
1579
|
-
jobs: createJobsApi(fetcher),
|
|
1580
|
-
experts: createExpertsApi(fetcher),
|
|
1581
|
-
providerSettings: createProviderSettingsApi(fetcher)
|
|
1582
|
-
};
|
|
1583
|
-
}
|
|
1584
|
-
|
|
1585
|
-
//#endregion
|
|
1586
|
-
//#region ../../packages/runtime/src/helpers/resolve-expert.ts
|
|
1587
|
-
async function resolveExpertToRun(expertKey, experts, clientOptions) {
|
|
1588
|
-
if (experts[expertKey]) return experts[expertKey];
|
|
1589
|
-
if (!clientOptions.perstackApiKey) throw new PerstackError(`PERSTACK_API_KEY is required to resolve published expert "${expertKey}"`);
|
|
1590
|
-
const result = await createApiClient({
|
|
1591
|
-
baseUrl: clientOptions.perstackApiBaseUrl,
|
|
1592
|
-
apiKey: clientOptions.perstackApiKey
|
|
1593
|
-
}).experts.get(expertKey);
|
|
1594
|
-
if (!result.ok) throw new PerstackError(`Failed to resolve expert "${expertKey}": ${result.error.message}`);
|
|
1595
|
-
const publishedExpert = result.data.data.definition.experts[expertKey];
|
|
1596
|
-
if (!publishedExpert) throw new PerstackError(`Expert "${expertKey}" not found in API response`);
|
|
1597
|
-
return toRuntimeExpert(expertKey, publishedExpert);
|
|
1598
|
-
}
|
|
1599
|
-
function toRuntimeExpert(key, expert) {
|
|
1600
|
-
const skills = Object.fromEntries(Object.entries(expert.skills ?? {}).map(([name, skill]) => {
|
|
1601
|
-
switch (skill.type) {
|
|
1602
|
-
case "mcpStdioSkill": return [name, {
|
|
1603
|
-
type: skill.type,
|
|
1604
|
-
name,
|
|
1605
|
-
description: skill.description,
|
|
1606
|
-
rule: skill.rule,
|
|
1607
|
-
pick: skill.pick ?? [],
|
|
1608
|
-
omit: skill.omit ?? [],
|
|
1609
|
-
command: skill.command,
|
|
1610
|
-
packageName: skill.packageName,
|
|
1611
|
-
requiredEnv: skill.requiredEnv ?? []
|
|
1612
|
-
}];
|
|
1613
|
-
case "mcpSseSkill": return [name, {
|
|
1614
|
-
type: skill.type,
|
|
1615
|
-
name,
|
|
1616
|
-
description: skill.description,
|
|
1617
|
-
rule: skill.rule,
|
|
1618
|
-
pick: skill.pick ?? [],
|
|
1619
|
-
omit: skill.omit ?? [],
|
|
1620
|
-
endpoint: skill.endpoint
|
|
1621
|
-
}];
|
|
1622
|
-
case "interactiveSkill": return [name, {
|
|
1623
|
-
type: skill.type,
|
|
1624
|
-
name,
|
|
1625
|
-
description: skill.description,
|
|
1626
|
-
rule: skill.rule,
|
|
1627
|
-
tools: Object.fromEntries(Object.entries(skill.tools).map(([toolName, tool]) => [toolName, {
|
|
1628
|
-
name: toolName,
|
|
1629
|
-
description: tool.description,
|
|
1630
|
-
inputSchema: JSON.parse(tool.inputJsonSchema)
|
|
1631
|
-
}]))
|
|
1632
|
-
}];
|
|
1633
|
-
default: throw new PerstackError(`Unknown skill type: ${skill.type}`);
|
|
1634
|
-
}
|
|
1635
|
-
}));
|
|
1636
|
-
return {
|
|
1637
|
-
key,
|
|
1638
|
-
name: expert.name,
|
|
1639
|
-
version: expert.version,
|
|
1640
|
-
minRuntimeVersion: expert.minRuntimeVersion ?? "v1.0",
|
|
1641
|
-
description: expert.description ?? "",
|
|
1642
|
-
instruction: expert.instruction,
|
|
1643
|
-
skills,
|
|
1644
|
-
delegates: expert.delegates ?? [],
|
|
1645
|
-
tags: expert.tags ?? []
|
|
1646
|
-
};
|
|
1647
|
-
}
|
|
1648
|
-
|
|
1649
|
-
//#endregion
|
|
1650
|
-
export { resolveExpertToRun };
|
|
1651
|
-
//# sourceMappingURL=resolve-expert-CTnETi9d.js.map
|