create-expert 0.0.19 → 0.0.21

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