@perstack/api-client 0.0.45 → 0.0.48
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/README.md +676 -77
- package/dist/bundle.d.mts +11863 -0
- package/dist/bundle.d.mts.map +1 -0
- package/dist/bundle.mjs +2261 -0
- package/dist/bundle.mjs.map +1 -0
- package/dist/chunk-Bdv87wj9.mjs +42 -0
- package/package.json +29 -21
- package/LICENSE +0 -202
- package/dist/index.d.ts +0 -438
- package/dist/index.js +0 -967
- package/dist/index.js.map +0 -1
package/dist/bundle.mjs
ADDED
|
@@ -0,0 +1,2261 @@
|
|
|
1
|
+
import { r as __toESM, t as __commonJSMin } from "./chunk-Bdv87wj9.mjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { activityOrGroupSchema, checkpointSchema as perstackCheckpointSchema, instructionMessageSchema, messageSchema, stepSchema, toolCallSchema, toolMessageSchema, toolResultSchema, usageSchema, userMessageSchema } from "@perstack/core";
|
|
4
|
+
|
|
5
|
+
//#region ../constants/index.ts
|
|
6
|
+
const organizationNameRegex = /^[a-z0-9][a-z0-9_.-]*$/;
|
|
7
|
+
const maxOrganizationNameLength = 128;
|
|
8
|
+
const applicationNameRegex = /^[a-z0-9][a-z0-9_.-]*$/;
|
|
9
|
+
const maxApplicationNameLength = 255;
|
|
10
|
+
const maxVariableValueLength = 65536;
|
|
11
|
+
const maxSecretValueLength = 65536;
|
|
12
|
+
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_.-]*))?$/;
|
|
13
|
+
const expertNameRegex = /^(@[a-z0-9][a-z0-9_-]*\/)?[a-z0-9][a-z0-9_-]*$/;
|
|
14
|
+
const scopeNameRegex = /^[a-z0-9][a-z0-9_-]*$/;
|
|
15
|
+
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_-]*))?$/;
|
|
16
|
+
const expertVersionRegex = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\w.-]+)?(?:\+[\w.-]+)?$/;
|
|
17
|
+
const tagNameRegex = /^[a-z0-9][a-z0-9_-]*$/;
|
|
18
|
+
const maxExpertNameLength = 255;
|
|
19
|
+
const maxExpertVersionTagLength = 255;
|
|
20
|
+
const maxExpertKeyLength = 511;
|
|
21
|
+
const maxExpertDescriptionLength = 1024 * 2;
|
|
22
|
+
const maxExpertInstructionLength = 1024 * 20;
|
|
23
|
+
const maxExpertDelegateItems = 255;
|
|
24
|
+
const maxExpertTagItems = 8;
|
|
25
|
+
const maxExpertJobQueryLength = 1024 * 20;
|
|
26
|
+
const maxExpertJobFileNameLength = 1024 * 10;
|
|
27
|
+
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_.-]*)?$/;
|
|
28
|
+
const urlSafeRegex = /^[a-z0-9][a-z0-9_-]*$/;
|
|
29
|
+
const maxSkillNameLength = 255;
|
|
30
|
+
const maxSkillDescriptionLength = 1024 * 2;
|
|
31
|
+
const maxSkillRuleLength = 1024 * 2;
|
|
32
|
+
const maxSkillPickOmitItems = 255;
|
|
33
|
+
const maxSkillRequiredEnvItems = 255;
|
|
34
|
+
const maxSkillToolNameLength = 255;
|
|
35
|
+
const maxSkillEndpointLength = 1024 * 2;
|
|
36
|
+
const maxSkillInputJsonSchemaLength = 1024 * 20;
|
|
37
|
+
const maxCheckpointToolCallIdLength = 255;
|
|
38
|
+
const envNameRegex = /^[a-zA-Z0-9][a-zA-Z0-9_-]*$/;
|
|
39
|
+
const maxEnvNameLength = 255;
|
|
40
|
+
const maxProviderBaseUrlLength = 2048;
|
|
41
|
+
const maxProviderHeaderKeyLength = 255;
|
|
42
|
+
const maxProviderHeaderValueLength = 2048;
|
|
43
|
+
const maxProviderHeadersCount = 50;
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region ../models/src/domain/common.ts
|
|
47
|
+
const cuidSchema = z.cuid2();
|
|
48
|
+
const runtimeVersionSchema = z.enum(["v1.0"]);
|
|
49
|
+
const providerSchema = z.enum([
|
|
50
|
+
"anthropic",
|
|
51
|
+
"google",
|
|
52
|
+
"openai",
|
|
53
|
+
"ollama",
|
|
54
|
+
"deepseek",
|
|
55
|
+
"azure-openai",
|
|
56
|
+
"amazon-bedrock",
|
|
57
|
+
"google-vertex"
|
|
58
|
+
]);
|
|
59
|
+
const datetimeSchema = z.string().datetime({ offset: true });
|
|
60
|
+
const expertKeyFieldSchema = z.string().min(1).max(maxExpertKeyLength).regex(expertKeyRegex);
|
|
61
|
+
const expertNameFieldSchema = z.string().min(1).max(maxExpertNameLength).regex(expertNameRegex);
|
|
62
|
+
const expertVersionFieldSchema = z.string().min(1).max(maxExpertVersionTagLength).regex(expertVersionRegex);
|
|
63
|
+
const expertTagFieldSchema = z.string().min(1).max(maxExpertVersionTagLength).regex(tagNameRegex);
|
|
64
|
+
const expertCategoryFieldSchema = z.enum([
|
|
65
|
+
"general",
|
|
66
|
+
"coding",
|
|
67
|
+
"research",
|
|
68
|
+
"writing",
|
|
69
|
+
"data",
|
|
70
|
+
"automation"
|
|
71
|
+
]);
|
|
72
|
+
const scopeNameSchema = z.string().min(1).max(maxExpertNameLength).regex(scopeNameRegex);
|
|
73
|
+
const scopeNameRefSchema = z.string().min(1).max(maxExpertNameLength + maxExpertVersionTagLength + 1).regex(scopeNameRefRegex);
|
|
74
|
+
const draftRefFieldSchema = z.string().min(1).max(30);
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region ../models/src/domain/organization.ts
|
|
78
|
+
const organizationStatusSchema = z.enum([
|
|
79
|
+
"active",
|
|
80
|
+
"inactive",
|
|
81
|
+
"deleted"
|
|
82
|
+
]);
|
|
83
|
+
const organizationTypeSchema = z.enum([
|
|
84
|
+
"personal",
|
|
85
|
+
"personalPlus",
|
|
86
|
+
"team",
|
|
87
|
+
"serviceAdmin"
|
|
88
|
+
]);
|
|
89
|
+
const organizationSchema = z.object({
|
|
90
|
+
type: z.literal("organization"),
|
|
91
|
+
id: cuidSchema,
|
|
92
|
+
createdAt: datetimeSchema,
|
|
93
|
+
updatedAt: datetimeSchema,
|
|
94
|
+
name: z.string().min(1).max(maxOrganizationNameLength).regex(organizationNameRegex).optional(),
|
|
95
|
+
nameChangedAt: datetimeSchema.optional(),
|
|
96
|
+
status: organizationStatusSchema,
|
|
97
|
+
organizationType: organizationTypeSchema,
|
|
98
|
+
maxApplications: z.number().int().min(0),
|
|
99
|
+
maxApiKeys: z.number().int().min(0),
|
|
100
|
+
maxExperts: z.number().int().min(0)
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region ../models/src/domain/user.ts
|
|
105
|
+
const userStatusSchema = z.enum([
|
|
106
|
+
"active",
|
|
107
|
+
"inactive",
|
|
108
|
+
"deleted"
|
|
109
|
+
]);
|
|
110
|
+
const userSchema = z.object({
|
|
111
|
+
type: z.literal("user"),
|
|
112
|
+
id: cuidSchema,
|
|
113
|
+
email: z.string().email(),
|
|
114
|
+
emailVerified: z.boolean(),
|
|
115
|
+
name: z.string().min(1).max(255).optional(),
|
|
116
|
+
image: z.string().url().optional(),
|
|
117
|
+
status: userStatusSchema,
|
|
118
|
+
organizations: z.array(organizationSchema),
|
|
119
|
+
createdAt: datetimeSchema,
|
|
120
|
+
updatedAt: datetimeSchema
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region ../models/src/domain/apiKey.ts
|
|
125
|
+
const apiKeyPermissionsSchema = z.object({
|
|
126
|
+
operations: z.array(z.string()),
|
|
127
|
+
experts: z.union([z.array(z.string()), z.literal("*")]).optional()
|
|
128
|
+
});
|
|
129
|
+
const apiKeySchema = z.object({
|
|
130
|
+
type: z.literal("apiKey"),
|
|
131
|
+
id: cuidSchema,
|
|
132
|
+
name: z.string().min(1).max(255).optional(),
|
|
133
|
+
start: z.string().optional(),
|
|
134
|
+
prefix: z.string().optional(),
|
|
135
|
+
user: userSchema.optional(),
|
|
136
|
+
enabled: z.boolean(),
|
|
137
|
+
expiresAt: datetimeSchema.optional(),
|
|
138
|
+
permissions: apiKeyPermissionsSchema.optional(),
|
|
139
|
+
lastRequest: datetimeSchema.optional(),
|
|
140
|
+
createdAt: datetimeSchema,
|
|
141
|
+
updatedAt: datetimeSchema
|
|
142
|
+
});
|
|
143
|
+
const createApiKeyInputSchema = z.object({
|
|
144
|
+
name: z.string().min(1).max(255).optional(),
|
|
145
|
+
organizationId: cuidSchema,
|
|
146
|
+
operations: z.array(z.string()).optional(),
|
|
147
|
+
experts: z.union([z.array(z.string()), z.literal("*")]).optional(),
|
|
148
|
+
expiresIn: z.number().min(60).optional()
|
|
149
|
+
});
|
|
150
|
+
const createApiKeyResponseSchema = z.object({
|
|
151
|
+
apiKey: apiKeySchema,
|
|
152
|
+
key: z.string()
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region ../models/src/api/api-keys/create.ts
|
|
157
|
+
const request$49 = { body: z.object({
|
|
158
|
+
name: z.string().min(1).max(255).optional(),
|
|
159
|
+
operations: z.array(z.string()).optional(),
|
|
160
|
+
experts: z.union([z.array(z.string()), z.literal("*")]).optional(),
|
|
161
|
+
wildcardApplicationAccess: z.boolean().optional(),
|
|
162
|
+
applicationIds: z.array(cuidSchema).optional(),
|
|
163
|
+
expiresIn: z.number().min(60).optional()
|
|
164
|
+
}) };
|
|
165
|
+
const response$51 = z.object({ data: z.object({
|
|
166
|
+
apiKey: apiKeySchema.extend({
|
|
167
|
+
permissions: apiKeyPermissionsSchema.optional(),
|
|
168
|
+
wildcardApplicationAccess: z.boolean(),
|
|
169
|
+
applicationIds: z.array(cuidSchema)
|
|
170
|
+
}),
|
|
171
|
+
key: z.string()
|
|
172
|
+
}) });
|
|
173
|
+
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region ../models/src/api/api-keys/get.ts
|
|
176
|
+
const request$48 = { params: z.object({ apiKeyId: cuidSchema }) };
|
|
177
|
+
const response$50 = z.object({ data: z.object({ apiKey: apiKeySchema.extend({
|
|
178
|
+
permissions: apiKeyPermissionsSchema.optional(),
|
|
179
|
+
wildcardApplicationAccess: z.boolean(),
|
|
180
|
+
applicationIds: z.array(cuidSchema)
|
|
181
|
+
}) }) });
|
|
182
|
+
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region ../../node_modules/ts-dedent/dist/index.js
|
|
185
|
+
var require_dist = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
186
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
187
|
+
exports.dedent = void 0;
|
|
188
|
+
function dedent(templ) {
|
|
189
|
+
var values = [];
|
|
190
|
+
for (var _i = 1; _i < arguments.length; _i++) values[_i - 1] = arguments[_i];
|
|
191
|
+
var strings = Array.from(typeof templ === "string" ? [templ] : templ);
|
|
192
|
+
strings[strings.length - 1] = strings[strings.length - 1].replace(/\r?\n([\t ]*)$/, "");
|
|
193
|
+
var indentLengths = strings.reduce(function(arr, str) {
|
|
194
|
+
var matches = str.match(/\n([\t ]+|(?!\s).)/g);
|
|
195
|
+
if (matches) return arr.concat(matches.map(function(match) {
|
|
196
|
+
var _a, _b;
|
|
197
|
+
return (_b = (_a = match.match(/[\t ]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
198
|
+
}));
|
|
199
|
+
return arr;
|
|
200
|
+
}, []);
|
|
201
|
+
if (indentLengths.length) {
|
|
202
|
+
var pattern_1 = new RegExp("\n[ ]{" + Math.min.apply(Math, indentLengths) + "}", "g");
|
|
203
|
+
strings = strings.map(function(str) {
|
|
204
|
+
return str.replace(pattern_1, "\n");
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
strings[0] = strings[0].replace(/^\r?\n/, "");
|
|
208
|
+
var string = strings[0];
|
|
209
|
+
values.forEach(function(value, i) {
|
|
210
|
+
var endentations = string.match(/(?:^|\n)( *)$/);
|
|
211
|
+
var endentation = endentations ? endentations[1] : "";
|
|
212
|
+
var indentedValue = value;
|
|
213
|
+
if (typeof value === "string" && value.includes("\n")) indentedValue = String(value).split("\n").map(function(str, i$1) {
|
|
214
|
+
return i$1 === 0 ? str : "" + endentation + str;
|
|
215
|
+
}).join("\n");
|
|
216
|
+
string += indentedValue + strings[i + 1];
|
|
217
|
+
});
|
|
218
|
+
return string;
|
|
219
|
+
}
|
|
220
|
+
exports.dedent = dedent;
|
|
221
|
+
exports.default = dedent;
|
|
222
|
+
}));
|
|
223
|
+
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region ../models/src/api/common.ts
|
|
226
|
+
var import_dist = /* @__PURE__ */ __toESM(require_dist(), 1);
|
|
227
|
+
const errorBadRequest = z.object({
|
|
228
|
+
code: z.literal(400),
|
|
229
|
+
error: z.literal("Bad Request"),
|
|
230
|
+
reason: z.string()
|
|
231
|
+
}).describe("Bad Request");
|
|
232
|
+
const errorUnauthorized = z.object({
|
|
233
|
+
code: z.literal(401),
|
|
234
|
+
error: z.literal("Unauthorized"),
|
|
235
|
+
reason: z.literal("Failed to authenticate")
|
|
236
|
+
}).describe(import_dist.default`
|
|
237
|
+
Authentication failed. Possible reasons:
|
|
238
|
+
- Authorization header is not provided
|
|
239
|
+
- Invalid API key
|
|
240
|
+
- Session expired
|
|
241
|
+
`);
|
|
242
|
+
const errorForbidden = z.object({
|
|
243
|
+
code: z.literal(403),
|
|
244
|
+
error: z.literal("Forbidden"),
|
|
245
|
+
reason: z.string()
|
|
246
|
+
}).describe("Access denied. The authenticated user does not have permission to perform this action.");
|
|
247
|
+
const errorNotFound = z.object({
|
|
248
|
+
code: z.literal(404),
|
|
249
|
+
error: z.literal("Not Found"),
|
|
250
|
+
reason: z.string()
|
|
251
|
+
}).describe("Resource not found.");
|
|
252
|
+
const errorValidationFailed = z.object({
|
|
253
|
+
code: z.literal(422),
|
|
254
|
+
error: z.literal("Validation Failed"),
|
|
255
|
+
reason: z.unknown()
|
|
256
|
+
}).describe("Request validation failed. Check the request body, query parameters, or path parameters.");
|
|
257
|
+
const paginationMeta = z.object({
|
|
258
|
+
total: z.number().int().min(0),
|
|
259
|
+
take: z.number().int().min(1),
|
|
260
|
+
skip: z.number().int().min(0)
|
|
261
|
+
});
|
|
262
|
+
const errorUnauthorizedFlexible = z.object({
|
|
263
|
+
code: z.literal(401),
|
|
264
|
+
error: z.literal("Unauthorized"),
|
|
265
|
+
reason: z.string()
|
|
266
|
+
}).describe("Unauthorized");
|
|
267
|
+
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region ../models/src/api/api-keys/getAll.ts
|
|
270
|
+
const request$47 = { query: z.object({
|
|
271
|
+
take: z.coerce.number().min(1).max(100).default(20),
|
|
272
|
+
skip: z.coerce.number().min(0).default(0)
|
|
273
|
+
}) };
|
|
274
|
+
const apiKeyWithApplicationsSchema = apiKeySchema.extend({
|
|
275
|
+
permissions: apiKeyPermissionsSchema.optional(),
|
|
276
|
+
wildcardApplicationAccess: z.boolean(),
|
|
277
|
+
applicationIds: z.array(cuidSchema)
|
|
278
|
+
});
|
|
279
|
+
const response$49 = z.object({
|
|
280
|
+
data: z.object({ apiKeys: z.array(apiKeyWithApplicationsSchema) }),
|
|
281
|
+
meta: paginationMeta
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region ../models/src/api/api-keys/revoke.ts
|
|
286
|
+
const request$46 = { params: z.object({ apiKeyId: cuidSchema }) };
|
|
287
|
+
const response$48 = z.object({ data: z.object({ apiKey: apiKeySchema.extend({
|
|
288
|
+
permissions: apiKeyPermissionsSchema.optional(),
|
|
289
|
+
wildcardApplicationAccess: z.boolean(),
|
|
290
|
+
applicationIds: z.array(cuidSchema)
|
|
291
|
+
}) }) });
|
|
292
|
+
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region ../models/src/domain/application.ts
|
|
295
|
+
const applicationNameSchema = z.string().min(1).max(maxApplicationNameLength).regex(applicationNameRegex);
|
|
296
|
+
const applicationStatusSchema = z.enum([
|
|
297
|
+
"active",
|
|
298
|
+
"inactive",
|
|
299
|
+
"deleted"
|
|
300
|
+
]);
|
|
301
|
+
const applicationSchema = z.object({
|
|
302
|
+
type: z.literal("application"),
|
|
303
|
+
id: cuidSchema,
|
|
304
|
+
organizationId: cuidSchema,
|
|
305
|
+
organization: organizationSchema,
|
|
306
|
+
createdAt: datetimeSchema,
|
|
307
|
+
updatedAt: datetimeSchema,
|
|
308
|
+
name: applicationNameSchema,
|
|
309
|
+
status: applicationStatusSchema,
|
|
310
|
+
expertCount: z.number().describe("Number of expert draft scopes associated with this application").optional(),
|
|
311
|
+
providers: z.array(providerSchema).describe("List of configured providers for this application").optional()
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region ../models/src/api/applications/create.ts
|
|
316
|
+
const request$45 = { body: z.object({
|
|
317
|
+
name: applicationNameSchema,
|
|
318
|
+
applicationGroupId: cuidSchema.optional()
|
|
319
|
+
}) };
|
|
320
|
+
const response$47 = z.object({ data: z.object({ application: applicationSchema }) });
|
|
321
|
+
|
|
322
|
+
//#endregion
|
|
323
|
+
//#region ../models/src/api/applications/delete.ts
|
|
324
|
+
const request$44 = { params: z.object({ applicationId: cuidSchema }) };
|
|
325
|
+
const response$46 = z.object({ data: z.object({ application: applicationSchema }) });
|
|
326
|
+
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region ../models/src/api/applications/get.ts
|
|
329
|
+
const request$43 = { params: z.object({ applicationId: cuidSchema }) };
|
|
330
|
+
const response$45 = z.object({ data: z.object({ application: applicationSchema }) });
|
|
331
|
+
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region ../models/src/api/applications/getAll.ts
|
|
334
|
+
const request$42 = { query: z.object({
|
|
335
|
+
name: z.union([z.string(), z.array(z.string())]).optional().transform((v) => Array.isArray(v) ? v.join(",") : v),
|
|
336
|
+
sort: z.enum([
|
|
337
|
+
"name",
|
|
338
|
+
"createdAt",
|
|
339
|
+
"updatedAt"
|
|
340
|
+
]).optional(),
|
|
341
|
+
order: z.enum(["asc", "desc"]).optional(),
|
|
342
|
+
take: z.coerce.number().min(1).max(100).default(20),
|
|
343
|
+
skip: z.coerce.number().min(0).default(0)
|
|
344
|
+
}) };
|
|
345
|
+
const response$44 = z.object({
|
|
346
|
+
data: z.object({ applications: z.array(applicationSchema) }),
|
|
347
|
+
meta: paginationMeta
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region ../models/src/api/applications/update.ts
|
|
352
|
+
const request$41 = {
|
|
353
|
+
params: z.object({ applicationId: cuidSchema }),
|
|
354
|
+
body: z.object({
|
|
355
|
+
name: applicationNameSchema.optional(),
|
|
356
|
+
status: applicationStatusSchema.exclude(["deleted"]).optional()
|
|
357
|
+
}).refine((data) => data.name !== void 0 || data.status !== void 0, { message: "At least one field must be provided" })
|
|
358
|
+
};
|
|
359
|
+
const response$43 = z.object({ data: z.object({ application: applicationSchema }) });
|
|
360
|
+
|
|
361
|
+
//#endregion
|
|
362
|
+
//#region ../models/src/domain/secret.ts
|
|
363
|
+
const secretNameSchema = z.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");
|
|
364
|
+
const secretValueSchema = z.string().min(1, "Secret value is required").max(maxSecretValueLength);
|
|
365
|
+
const secretMetadataSchema = z.object({
|
|
366
|
+
name: z.string(),
|
|
367
|
+
createdAt: datetimeSchema,
|
|
368
|
+
updatedAt: datetimeSchema
|
|
369
|
+
});
|
|
370
|
+
const secretSchema = z.object({
|
|
371
|
+
type: z.literal("secret"),
|
|
372
|
+
id: cuidSchema,
|
|
373
|
+
name: secretNameSchema,
|
|
374
|
+
applicationId: cuidSchema,
|
|
375
|
+
createdAt: datetimeSchema,
|
|
376
|
+
updatedAt: datetimeSchema
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region ../models/src/api/env/secrets/create.ts
|
|
381
|
+
const request$40 = { body: z.object({
|
|
382
|
+
applicationId: cuidSchema,
|
|
383
|
+
name: secretNameSchema,
|
|
384
|
+
value: secretValueSchema
|
|
385
|
+
}) };
|
|
386
|
+
const response$42 = z.object({ data: z.object({ secret: secretMetadataSchema }) });
|
|
387
|
+
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region ../models/src/api/env/secrets/delete.ts
|
|
390
|
+
const request$39 = {
|
|
391
|
+
params: z.object({ name: z.string().min(1) }),
|
|
392
|
+
query: z.object({ applicationId: cuidSchema })
|
|
393
|
+
};
|
|
394
|
+
const response$41 = z.null();
|
|
395
|
+
|
|
396
|
+
//#endregion
|
|
397
|
+
//#region ../models/src/api/env/secrets/get.ts
|
|
398
|
+
const request$38 = {
|
|
399
|
+
params: z.object({ name: z.string().min(1) }),
|
|
400
|
+
query: z.object({ applicationId: cuidSchema })
|
|
401
|
+
};
|
|
402
|
+
const response$40 = z.object({ data: z.object({ secret: secretMetadataSchema }) });
|
|
403
|
+
|
|
404
|
+
//#endregion
|
|
405
|
+
//#region ../models/src/api/env/secrets/getAll.ts
|
|
406
|
+
const request$37 = { query: z.object({ applicationId: cuidSchema.optional() }) };
|
|
407
|
+
const response$39 = z.object({ data: z.object({ secrets: z.array(secretMetadataSchema) }) });
|
|
408
|
+
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region ../models/src/api/env/secrets/update.ts
|
|
411
|
+
const request$36 = {
|
|
412
|
+
params: z.object({ name: z.string().min(1) }),
|
|
413
|
+
body: z.object({
|
|
414
|
+
applicationId: cuidSchema,
|
|
415
|
+
value: secretValueSchema
|
|
416
|
+
})
|
|
417
|
+
};
|
|
418
|
+
const response$38 = z.object({ data: z.object({ secret: secretMetadataSchema }) });
|
|
419
|
+
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region ../models/src/domain/variable.ts
|
|
422
|
+
const variableNameSchema = z.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");
|
|
423
|
+
const variableValueSchema = z.string().max(maxVariableValueLength);
|
|
424
|
+
const variableSchema = z.object({
|
|
425
|
+
type: z.literal("variable"),
|
|
426
|
+
id: cuidSchema,
|
|
427
|
+
applicationId: cuidSchema,
|
|
428
|
+
createdAt: datetimeSchema,
|
|
429
|
+
updatedAt: datetimeSchema,
|
|
430
|
+
name: variableNameSchema,
|
|
431
|
+
value: variableValueSchema
|
|
432
|
+
});
|
|
433
|
+
const variableResponseSchema = z.object({
|
|
434
|
+
name: variableNameSchema,
|
|
435
|
+
value: variableValueSchema,
|
|
436
|
+
createdAt: datetimeSchema,
|
|
437
|
+
updatedAt: datetimeSchema
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
//#endregion
|
|
441
|
+
//#region ../models/src/api/env/variables/create.ts
|
|
442
|
+
const request$35 = { body: z.object({
|
|
443
|
+
applicationId: cuidSchema,
|
|
444
|
+
name: variableNameSchema,
|
|
445
|
+
value: variableValueSchema
|
|
446
|
+
}) };
|
|
447
|
+
const response$37 = z.object({ data: z.object({ variable: variableResponseSchema }) });
|
|
448
|
+
|
|
449
|
+
//#endregion
|
|
450
|
+
//#region ../models/src/api/env/variables/delete.ts
|
|
451
|
+
const request$34 = {
|
|
452
|
+
params: z.object({ name: z.string().min(1) }),
|
|
453
|
+
query: z.object({ applicationId: cuidSchema })
|
|
454
|
+
};
|
|
455
|
+
const response$36 = z.null();
|
|
456
|
+
|
|
457
|
+
//#endregion
|
|
458
|
+
//#region ../models/src/api/env/variables/get.ts
|
|
459
|
+
const request$33 = {
|
|
460
|
+
params: z.object({ name: z.string().min(1) }),
|
|
461
|
+
query: z.object({ applicationId: cuidSchema })
|
|
462
|
+
};
|
|
463
|
+
const response$35 = z.object({ data: z.object({ variable: variableResponseSchema }) });
|
|
464
|
+
|
|
465
|
+
//#endregion
|
|
466
|
+
//#region ../models/src/api/env/variables/getAll.ts
|
|
467
|
+
const request$32 = { query: z.object({ applicationId: cuidSchema }) };
|
|
468
|
+
const response$34 = z.object({ data: z.object({ variables: z.array(variableResponseSchema) }) });
|
|
469
|
+
|
|
470
|
+
//#endregion
|
|
471
|
+
//#region ../models/src/api/env/variables/update.ts
|
|
472
|
+
const request$31 = {
|
|
473
|
+
params: z.object({ name: z.string().min(1) }),
|
|
474
|
+
body: z.object({
|
|
475
|
+
applicationId: cuidSchema,
|
|
476
|
+
value: variableValueSchema
|
|
477
|
+
})
|
|
478
|
+
};
|
|
479
|
+
const response$33 = z.object({ data: z.object({ variable: variableResponseSchema }) });
|
|
480
|
+
|
|
481
|
+
//#endregion
|
|
482
|
+
//#region ../models/src/domain/expertScope.ts
|
|
483
|
+
const expertScopeSchema = z.object({
|
|
484
|
+
id: cuidSchema,
|
|
485
|
+
name: scopeNameSchema,
|
|
486
|
+
organizationId: cuidSchema,
|
|
487
|
+
published: z.boolean(),
|
|
488
|
+
publishedAt: datetimeSchema.optional(),
|
|
489
|
+
category: expertCategoryFieldSchema,
|
|
490
|
+
totalRuns: z.number().int().min(0),
|
|
491
|
+
totalJobs: z.number().int().min(0),
|
|
492
|
+
totalStars: z.number().int().min(0),
|
|
493
|
+
createdAt: datetimeSchema,
|
|
494
|
+
updatedAt: datetimeSchema,
|
|
495
|
+
createdBy: cuidSchema,
|
|
496
|
+
updatedBy: cuidSchema
|
|
497
|
+
});
|
|
498
|
+
const expertVersionSchema = z.object({
|
|
499
|
+
id: cuidSchema,
|
|
500
|
+
expertScopeId: cuidSchema,
|
|
501
|
+
version: expertVersionFieldSchema,
|
|
502
|
+
public: z.boolean(),
|
|
503
|
+
yanked: z.boolean(),
|
|
504
|
+
totalRuns: z.number().int().min(0),
|
|
505
|
+
totalJobs: z.number().int().min(0),
|
|
506
|
+
createdAt: datetimeSchema,
|
|
507
|
+
updatedAt: datetimeSchema,
|
|
508
|
+
createdBy: cuidSchema,
|
|
509
|
+
updatedBy: cuidSchema,
|
|
510
|
+
tags: z.array(expertTagFieldSchema)
|
|
511
|
+
});
|
|
512
|
+
const expertScopeWithVersionsSchema = expertScopeSchema.extend({ versions: z.array(expertVersionSchema) });
|
|
513
|
+
|
|
514
|
+
//#endregion
|
|
515
|
+
//#region ../models/src/domain/skill.ts
|
|
516
|
+
function isPrivateOrLocalIP(hostname) {
|
|
517
|
+
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname === "0.0.0.0") return true;
|
|
518
|
+
const ipv4Match = hostname.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/);
|
|
519
|
+
if (ipv4Match) {
|
|
520
|
+
const a = Number(ipv4Match[1]);
|
|
521
|
+
const b = Number(ipv4Match[2]);
|
|
522
|
+
if (a === 10) return true;
|
|
523
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
524
|
+
if (a === 192 && b === 168) return true;
|
|
525
|
+
if (a === 169 && b === 254) return true;
|
|
526
|
+
if (a === 127) return true;
|
|
527
|
+
}
|
|
528
|
+
if (hostname.includes(":")) {
|
|
529
|
+
if (hostname.startsWith("fe80:") || hostname.startsWith("fc") || hostname.startsWith("fd")) return true;
|
|
530
|
+
}
|
|
531
|
+
if (hostname.startsWith("::ffff:")) {
|
|
532
|
+
if (isPrivateOrLocalIP(hostname.slice(7))) return true;
|
|
533
|
+
}
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
const sseEndpointSchema = z.string().max(maxSkillEndpointLength).url().refine((url) => {
|
|
537
|
+
try {
|
|
538
|
+
const parsed = new URL(url);
|
|
539
|
+
if (parsed.protocol !== "https:") return false;
|
|
540
|
+
if (isPrivateOrLocalIP(parsed.hostname)) return false;
|
|
541
|
+
return true;
|
|
542
|
+
} catch {
|
|
543
|
+
return false;
|
|
544
|
+
}
|
|
545
|
+
}, { message: "Endpoint must be a public HTTPS URL" });
|
|
546
|
+
const skillNameSchema = z.string().min(1).max(maxSkillNameLength).regex(packageWithVersionRegex);
|
|
547
|
+
const mcpStdioSkillCommandSchema = z.enum(["npx", "uvx"]);
|
|
548
|
+
const mcpStdioSkillSchema = z.object({
|
|
549
|
+
type: z.literal("mcpStdioSkill"),
|
|
550
|
+
name: z.string(),
|
|
551
|
+
description: z.string().min(1).max(maxSkillDescriptionLength),
|
|
552
|
+
rule: z.string().min(1).max(maxSkillRuleLength).optional(),
|
|
553
|
+
pick: z.array(z.string().min(1).max(maxSkillToolNameLength)).max(maxSkillPickOmitItems).optional().default([]),
|
|
554
|
+
omit: z.array(z.string().min(1).max(maxSkillToolNameLength)).max(maxSkillPickOmitItems).optional().default([]),
|
|
555
|
+
command: mcpStdioSkillCommandSchema,
|
|
556
|
+
packageName: z.string().min(1).max(maxSkillNameLength).regex(packageWithVersionRegex),
|
|
557
|
+
requiredEnv: z.array(z.string().min(1).max(maxEnvNameLength).regex(envNameRegex)).min(0).max(maxSkillRequiredEnvItems).optional()
|
|
558
|
+
});
|
|
559
|
+
const mcpSseSkillSchema = z.object({
|
|
560
|
+
type: z.literal("mcpSseSkill"),
|
|
561
|
+
name: z.string(),
|
|
562
|
+
description: z.string().min(1).max(maxSkillDescriptionLength),
|
|
563
|
+
rule: z.string().min(1).max(maxSkillRuleLength).optional(),
|
|
564
|
+
pick: z.array(z.string().min(1).max(maxSkillToolNameLength)).max(maxSkillPickOmitItems).optional().default([]),
|
|
565
|
+
omit: z.array(z.string().min(1).max(maxSkillToolNameLength)).max(maxSkillPickOmitItems).optional().default([]),
|
|
566
|
+
endpoint: sseEndpointSchema
|
|
567
|
+
});
|
|
568
|
+
const interactiveSkillSchema = z.object({
|
|
569
|
+
type: z.literal("interactiveSkill"),
|
|
570
|
+
name: z.string(),
|
|
571
|
+
description: z.string().min(1).max(maxSkillDescriptionLength),
|
|
572
|
+
rule: z.string().min(1).max(maxSkillRuleLength).optional(),
|
|
573
|
+
tools: z.record(z.string().min(1).max(maxSkillToolNameLength).regex(urlSafeRegex), z.object({
|
|
574
|
+
description: z.string().min(1).max(maxSkillDescriptionLength),
|
|
575
|
+
inputJsonSchema: z.string().min(1).max(maxSkillInputJsonSchemaLength)
|
|
576
|
+
}))
|
|
577
|
+
});
|
|
578
|
+
const skillSchema = z.discriminatedUnion("type", [
|
|
579
|
+
mcpStdioSkillSchema,
|
|
580
|
+
mcpSseSkillSchema,
|
|
581
|
+
interactiveSkillSchema
|
|
582
|
+
]);
|
|
583
|
+
|
|
584
|
+
//#endregion
|
|
585
|
+
//#region ../models/src/domain/expert.ts
|
|
586
|
+
const expertSchema = z.object({
|
|
587
|
+
key: expertKeyFieldSchema,
|
|
588
|
+
name: expertNameFieldSchema,
|
|
589
|
+
version: expertVersionFieldSchema,
|
|
590
|
+
description: z.string().min(1).max(maxExpertDescriptionLength).optional(),
|
|
591
|
+
instruction: z.string().min(1).max(maxExpertInstructionLength),
|
|
592
|
+
skills: z.record(skillNameSchema, skillSchema).optional().default({}),
|
|
593
|
+
delegates: z.array(expertKeyFieldSchema).min(0).max(maxExpertDelegateItems).optional().default([]),
|
|
594
|
+
tags: z.array(expertTagFieldSchema).min(0).max(maxExpertTagItems).optional().default([])
|
|
595
|
+
});
|
|
596
|
+
const expertMetadataSchema = z.object({
|
|
597
|
+
scope: expertScopeSchema,
|
|
598
|
+
version: expertVersionSchema
|
|
599
|
+
});
|
|
600
|
+
const expertWithMetadataSchema = expertSchema.extend({
|
|
601
|
+
scope: expertScopeSchema,
|
|
602
|
+
version: expertVersionSchema
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
//#endregion
|
|
606
|
+
//#region ../models/src/api/experts/definition.ts
|
|
607
|
+
const expertDefinitionSchema = z.object({
|
|
608
|
+
name: expertNameFieldSchema,
|
|
609
|
+
version: expertVersionFieldSchema,
|
|
610
|
+
organizationId: cuidSchema,
|
|
611
|
+
createdAt: datetimeSchema,
|
|
612
|
+
updatedAt: datetimeSchema,
|
|
613
|
+
createdBy: cuidSchema,
|
|
614
|
+
updatedBy: cuidSchema,
|
|
615
|
+
experts: z.record(expertKeyFieldSchema, expertSchema.omit({ key: true }))
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
//#endregion
|
|
619
|
+
//#region ../models/src/api/experts/delete.ts
|
|
620
|
+
const request$30 = { params: z.object({ scopeName: scopeNameRefSchema }) };
|
|
621
|
+
const response$32 = z.object({ data: expertMetadataSchema.extend({
|
|
622
|
+
yanked: z.literal(true),
|
|
623
|
+
latestTagUpdated: z.boolean()
|
|
624
|
+
}) });
|
|
625
|
+
|
|
626
|
+
//#endregion
|
|
627
|
+
//#region ../models/src/domain/expertDraftScope.ts
|
|
628
|
+
const expertDraftScopeSchema = z.object({
|
|
629
|
+
id: cuidSchema,
|
|
630
|
+
name: scopeNameSchema,
|
|
631
|
+
organizationId: cuidSchema,
|
|
632
|
+
applicationId: cuidSchema,
|
|
633
|
+
totalRuns: z.number().int().min(0),
|
|
634
|
+
totalJobs: z.number().int().min(0),
|
|
635
|
+
createdAt: datetimeSchema,
|
|
636
|
+
updatedAt: datetimeSchema,
|
|
637
|
+
createdBy: cuidSchema,
|
|
638
|
+
updatedBy: cuidSchema
|
|
639
|
+
});
|
|
640
|
+
const expertDraftRefSchema = z.object({
|
|
641
|
+
id: cuidSchema,
|
|
642
|
+
expertDraftScopeId: cuidSchema,
|
|
643
|
+
totalRuns: z.number().int().min(0),
|
|
644
|
+
totalJobs: z.number().int().min(0),
|
|
645
|
+
createdAt: datetimeSchema,
|
|
646
|
+
updatedAt: datetimeSchema,
|
|
647
|
+
createdBy: cuidSchema,
|
|
648
|
+
updatedBy: cuidSchema
|
|
649
|
+
});
|
|
650
|
+
const expertDraftScopeWithRefsSchema = expertDraftScopeSchema.extend({ draftRefs: z.array(expertDraftRefSchema) });
|
|
651
|
+
|
|
652
|
+
//#endregion
|
|
653
|
+
//#region ../models/src/api/experts/drafts/definition.ts
|
|
654
|
+
const expertDefinitionContentSchema = z.object({
|
|
655
|
+
name: expertNameFieldSchema,
|
|
656
|
+
version: z.literal("0.0.0-draft"),
|
|
657
|
+
applicationId: cuidSchema,
|
|
658
|
+
createdAt: datetimeSchema,
|
|
659
|
+
updatedAt: datetimeSchema,
|
|
660
|
+
createdBy: cuidSchema,
|
|
661
|
+
updatedBy: cuidSchema,
|
|
662
|
+
experts: z.record(expertKeyFieldSchema, expertSchema.omit({ key: true }))
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
//#endregion
|
|
666
|
+
//#region ../models/src/api/experts/drafts/create.ts
|
|
667
|
+
const request$29 = {
|
|
668
|
+
params: z.object({ scopeName: scopeNameSchema }),
|
|
669
|
+
body: z.object({
|
|
670
|
+
applicationId: cuidSchema,
|
|
671
|
+
experts: z.array(expertSchema)
|
|
672
|
+
})
|
|
673
|
+
};
|
|
674
|
+
const response$31 = z.object({ data: z.object({
|
|
675
|
+
scope: expertDraftScopeSchema,
|
|
676
|
+
draftRef: expertDraftRefSchema,
|
|
677
|
+
definition: expertDefinitionContentSchema
|
|
678
|
+
}) });
|
|
679
|
+
|
|
680
|
+
//#endregion
|
|
681
|
+
//#region ../models/src/api/experts/drafts/delete.ts
|
|
682
|
+
const request$28 = { params: z.object({
|
|
683
|
+
scopeName: scopeNameSchema,
|
|
684
|
+
draftRef: expertDraftRefSchema.shape.id
|
|
685
|
+
}) };
|
|
686
|
+
const response$30 = z.object({ data: z.object({
|
|
687
|
+
deleted: z.boolean(),
|
|
688
|
+
draftRef: z.string()
|
|
689
|
+
}) });
|
|
690
|
+
|
|
691
|
+
//#endregion
|
|
692
|
+
//#region ../models/src/api/experts/drafts/get.ts
|
|
693
|
+
const request$27 = { params: z.object({
|
|
694
|
+
scopeName: scopeNameSchema,
|
|
695
|
+
draftRef: expertDraftRefSchema.shape.id
|
|
696
|
+
}) };
|
|
697
|
+
const response$29 = z.object({ data: z.object({
|
|
698
|
+
scope: expertDraftScopeSchema,
|
|
699
|
+
draftRef: expertDraftRefSchema,
|
|
700
|
+
definition: expertDefinitionContentSchema
|
|
701
|
+
}) });
|
|
702
|
+
|
|
703
|
+
//#endregion
|
|
704
|
+
//#region ../models/src/api/experts/drafts/getAll.ts
|
|
705
|
+
const request$26 = {
|
|
706
|
+
params: z.object({ scopeName: expertDraftScopeSchema.shape.name }),
|
|
707
|
+
query: z.object({
|
|
708
|
+
take: z.coerce.number().int().min(1).max(100).default(20),
|
|
709
|
+
skip: z.coerce.number().int().min(0).default(0)
|
|
710
|
+
})
|
|
711
|
+
};
|
|
712
|
+
const response$28 = z.object({
|
|
713
|
+
data: z.object({ draftRefs: z.array(expertDraftRefSchema) }),
|
|
714
|
+
meta: paginationMeta
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
//#endregion
|
|
718
|
+
//#region ../models/src/api/experts/drafts/update.ts
|
|
719
|
+
const request$25 = {
|
|
720
|
+
params: z.object({
|
|
721
|
+
scopeName: scopeNameSchema,
|
|
722
|
+
draftRef: expertDraftRefSchema.shape.id
|
|
723
|
+
}),
|
|
724
|
+
body: z.object({ experts: z.array(expertSchema) })
|
|
725
|
+
};
|
|
726
|
+
const response$27 = z.object({ data: z.object({
|
|
727
|
+
scope: expertDraftScopeSchema,
|
|
728
|
+
draftRef: expertDraftRefSchema,
|
|
729
|
+
definition: expertDefinitionContentSchema
|
|
730
|
+
}) });
|
|
731
|
+
|
|
732
|
+
//#endregion
|
|
733
|
+
//#region ../models/src/api/experts/drafts/version.ts
|
|
734
|
+
const request$24 = {
|
|
735
|
+
params: z.object({
|
|
736
|
+
scopeName: scopeNameSchema,
|
|
737
|
+
draftRef: z.string().min(1)
|
|
738
|
+
}),
|
|
739
|
+
body: z.object({
|
|
740
|
+
version: z.string().min(1, "Version is required.").max(maxExpertVersionTagLength, "Version is too long.").regex(expertVersionRegex, "Invalid version format. (e.g. 1.0.0)"),
|
|
741
|
+
tag: z.string().max(maxExpertVersionTagLength, "Tag is too long.").regex(tagNameRegex, "Invalid tag format. (e.g. latest)").optional()
|
|
742
|
+
})
|
|
743
|
+
};
|
|
744
|
+
const response$26 = z.object({ data: z.object({
|
|
745
|
+
scope: expertScopeSchema,
|
|
746
|
+
version: expertVersionSchema,
|
|
747
|
+
definitionUrl: z.string()
|
|
748
|
+
}) });
|
|
749
|
+
|
|
750
|
+
//#endregion
|
|
751
|
+
//#region ../models/src/api/experts/featured.ts
|
|
752
|
+
const response$25 = z.object({ data: z.object({ featuredExperts: z.array(z.object({
|
|
753
|
+
scope: expertScopeSchema,
|
|
754
|
+
currentVersion: expertVersionSchema,
|
|
755
|
+
displayOrder: z.number().int().min(0).max(2),
|
|
756
|
+
featuredAt: z.string().datetime()
|
|
757
|
+
})) }) });
|
|
758
|
+
|
|
759
|
+
//#endregion
|
|
760
|
+
//#region ../models/src/api/experts/get.ts
|
|
761
|
+
const request$23 = { params: z.object({ scopeName: scopeNameRefSchema }) };
|
|
762
|
+
const response$24 = z.object({ data: z.object({
|
|
763
|
+
definition: expertDefinitionSchema,
|
|
764
|
+
yanked: z.boolean().optional()
|
|
765
|
+
}) });
|
|
766
|
+
|
|
767
|
+
//#endregion
|
|
768
|
+
//#region ../models/src/api/experts/getAll.ts
|
|
769
|
+
const request$22 = { query: z.object({
|
|
770
|
+
filter: z.string().describe("Filter by scope name (partial match)").optional(),
|
|
771
|
+
category: z.enum([
|
|
772
|
+
"general",
|
|
773
|
+
"coding",
|
|
774
|
+
"research",
|
|
775
|
+
"writing",
|
|
776
|
+
"data",
|
|
777
|
+
"automation"
|
|
778
|
+
]).describe("Filter by category").optional(),
|
|
779
|
+
includeDrafts: z.coerce.boolean().default(false).describe("Include unpublished scopes (owner only)").optional(),
|
|
780
|
+
take: z.coerce.number().min(1).max(100).default(20),
|
|
781
|
+
skip: z.coerce.number().min(0).default(0)
|
|
782
|
+
}) };
|
|
783
|
+
const response$23 = z.object({
|
|
784
|
+
data: z.object({ experts: z.array(expertScopeSchema.extend({ currentVersion: expertVersionSchema })) }),
|
|
785
|
+
meta: paginationMeta
|
|
786
|
+
});
|
|
787
|
+
|
|
788
|
+
//#endregion
|
|
789
|
+
//#region ../models/src/api/experts/meta.ts
|
|
790
|
+
const request$21 = {
|
|
791
|
+
params: z.object({ scopeName: scopeNameRefSchema }),
|
|
792
|
+
query: z.object({ public: z.enum(["true", "false"]).transform((val) => val === "true").optional().default(false).describe("Public access check (no auth)") })
|
|
793
|
+
};
|
|
794
|
+
const response$22 = z.object({ data: expertMetadataSchema.extend({ definitionUrl: z.string() }) });
|
|
795
|
+
|
|
796
|
+
//#endregion
|
|
797
|
+
//#region ../models/src/api/experts/publish.ts
|
|
798
|
+
const request$20 = { params: z.object({ scopeName: scopeNameSchema }) };
|
|
799
|
+
const response$21 = z.object({ data: z.object({ scope: expertScopeSchema }) });
|
|
800
|
+
|
|
801
|
+
//#endregion
|
|
802
|
+
//#region ../models/src/api/experts/unpublish.ts
|
|
803
|
+
const request$19 = { params: z.object({ scopeName: scopeNameSchema }) };
|
|
804
|
+
const response$20 = z.object({ data: z.object({ scope: expertScopeSchema }) });
|
|
805
|
+
|
|
806
|
+
//#endregion
|
|
807
|
+
//#region ../models/src/api/experts/versions.ts
|
|
808
|
+
const request$18 = { params: z.object({ scopeName: scopeNameSchema }) };
|
|
809
|
+
const response$19 = z.object({ data: z.object({ versions: z.array(expertVersionSchema) }) });
|
|
810
|
+
|
|
811
|
+
//#endregion
|
|
812
|
+
//#region ../models/src/domain/checkpoint.ts
|
|
813
|
+
const delegationTargetSchema = z.object({
|
|
814
|
+
expert: expertSchema,
|
|
815
|
+
toolCallId: z.string().min(1).max(maxCheckpointToolCallIdLength),
|
|
816
|
+
toolName: z.string().min(1).max(maxSkillToolNameLength),
|
|
817
|
+
query: z.string()
|
|
818
|
+
});
|
|
819
|
+
/**
|
|
820
|
+
* API Checkpoint schema - extended checkpoint format for API responses.
|
|
821
|
+
* Includes additional fields computed from runtime checkpoint and step data:
|
|
822
|
+
* - activities: computed via getActivities() from @perstack/core
|
|
823
|
+
* - inputMessages, newMessages, toolCalls, toolResults: step-related data
|
|
824
|
+
* - expert: full Expert type (with instruction, skills, etc.)
|
|
825
|
+
* - startedAt/finishedAt: ISO string format (runtime uses Unix timestamps)
|
|
826
|
+
*/
|
|
827
|
+
const apiCheckpointSchema = z.object({
|
|
828
|
+
type: z.literal("checkpoint"),
|
|
829
|
+
id: cuidSchema,
|
|
830
|
+
jobId: cuidSchema,
|
|
831
|
+
runId: cuidSchema,
|
|
832
|
+
activities: z.array(activityOrGroupSchema),
|
|
833
|
+
stepNumber: z.number().int().min(1),
|
|
834
|
+
status: z.enum([
|
|
835
|
+
"init",
|
|
836
|
+
"proceeding",
|
|
837
|
+
"completed",
|
|
838
|
+
"stoppedByInteractiveTool",
|
|
839
|
+
"stoppedByDelegate",
|
|
840
|
+
"stoppedByExceededMaxSteps",
|
|
841
|
+
"stoppedByError"
|
|
842
|
+
]),
|
|
843
|
+
expert: expertSchema,
|
|
844
|
+
delegateTo: z.array(delegationTargetSchema).optional(),
|
|
845
|
+
delegatedBy: z.object({
|
|
846
|
+
expert: expertSchema,
|
|
847
|
+
toolCallId: z.string().min(1).max(maxCheckpointToolCallIdLength),
|
|
848
|
+
toolName: z.string().min(1).max(maxSkillToolNameLength),
|
|
849
|
+
checkpointId: cuidSchema,
|
|
850
|
+
runId: cuidSchema
|
|
851
|
+
}).optional(),
|
|
852
|
+
inputMessages: z.array(z.union([
|
|
853
|
+
instructionMessageSchema,
|
|
854
|
+
userMessageSchema,
|
|
855
|
+
toolMessageSchema
|
|
856
|
+
])).optional(),
|
|
857
|
+
messages: z.array(messageSchema),
|
|
858
|
+
newMessages: z.array(messageSchema),
|
|
859
|
+
toolCalls: z.array(toolCallSchema).optional(),
|
|
860
|
+
toolResults: z.array(toolResultSchema).optional(),
|
|
861
|
+
pendingToolCalls: z.array(toolCallSchema).optional(),
|
|
862
|
+
partialToolResults: z.array(toolResultSchema).optional(),
|
|
863
|
+
usage: usageSchema,
|
|
864
|
+
contextWindow: z.number().int().min(0).optional(),
|
|
865
|
+
contextWindowUsage: z.number().int().min(0).optional(),
|
|
866
|
+
error: z.object({
|
|
867
|
+
name: z.string(),
|
|
868
|
+
message: z.string(),
|
|
869
|
+
statusCode: z.number().optional(),
|
|
870
|
+
isRetryable: z.boolean()
|
|
871
|
+
}).optional(),
|
|
872
|
+
retryCount: z.number().optional(),
|
|
873
|
+
startedAt: datetimeSchema,
|
|
874
|
+
finishedAt: datetimeSchema.optional()
|
|
875
|
+
});
|
|
876
|
+
|
|
877
|
+
//#endregion
|
|
878
|
+
//#region ../models/src/api/jobs/checkpoints/create.ts
|
|
879
|
+
/**
|
|
880
|
+
* Request checkpoint schema - `id` and `runId` are omitted because:
|
|
881
|
+
* - `id` is server-generated (CUID)
|
|
882
|
+
* - `runId` is optional in request, server will use job's run ID
|
|
883
|
+
*/
|
|
884
|
+
const requestCheckpointSchema = perstackCheckpointSchema.omit({
|
|
885
|
+
id: true,
|
|
886
|
+
runId: true
|
|
887
|
+
}).extend({ runId: z.string().optional() });
|
|
888
|
+
const request$17 = {
|
|
889
|
+
params: z.object({ jobId: cuidSchema }),
|
|
890
|
+
body: z.object({
|
|
891
|
+
checkpoint: requestCheckpointSchema,
|
|
892
|
+
step: stepSchema
|
|
893
|
+
})
|
|
894
|
+
};
|
|
895
|
+
const response$18 = z.object({ data: z.object({ checkpoint: apiCheckpointSchema }) });
|
|
896
|
+
|
|
897
|
+
//#endregion
|
|
898
|
+
//#region ../models/src/api/jobs/checkpoints/get.ts
|
|
899
|
+
const request$16 = { params: z.object({
|
|
900
|
+
jobId: cuidSchema,
|
|
901
|
+
checkpointId: cuidSchema
|
|
902
|
+
}) };
|
|
903
|
+
const response$17 = z.object({ data: z.object({ checkpoint: apiCheckpointSchema }) });
|
|
904
|
+
|
|
905
|
+
//#endregion
|
|
906
|
+
//#region ../models/src/api/jobs/checkpoints/getAll.ts
|
|
907
|
+
const request$15 = {
|
|
908
|
+
params: z.object({ jobId: cuidSchema }),
|
|
909
|
+
query: z.object({
|
|
910
|
+
filter: z.string().min(1).max(256).optional(),
|
|
911
|
+
sort: z.enum(["createdAt", "updatedAt"]).optional(),
|
|
912
|
+
order: z.enum(["asc", "desc"]).optional(),
|
|
913
|
+
take: z.coerce.number().min(1).max(100).default(20),
|
|
914
|
+
skip: z.coerce.number().min(0).default(0)
|
|
915
|
+
})
|
|
916
|
+
};
|
|
917
|
+
const response$16 = z.object({
|
|
918
|
+
data: z.object({ checkpoints: z.array(apiCheckpointSchema) }),
|
|
919
|
+
meta: paginationMeta
|
|
920
|
+
});
|
|
921
|
+
|
|
922
|
+
//#endregion
|
|
923
|
+
//#region ../models/src/api/jobs/checkpoints/stream.ts
|
|
924
|
+
const request$14 = { params: z.object({ jobId: cuidSchema }) };
|
|
925
|
+
const response$15 = z.object({ data: apiCheckpointSchema });
|
|
926
|
+
|
|
927
|
+
//#endregion
|
|
928
|
+
//#region ../support-models/src/index.ts
|
|
929
|
+
const anthropicSupportModels = [
|
|
930
|
+
{
|
|
931
|
+
modelId: "claude-opus-4-5",
|
|
932
|
+
default: false,
|
|
933
|
+
provider: "anthropic",
|
|
934
|
+
contextWindow: 2e5
|
|
935
|
+
},
|
|
936
|
+
{
|
|
937
|
+
modelId: "claude-opus-4-1",
|
|
938
|
+
default: false,
|
|
939
|
+
provider: "anthropic",
|
|
940
|
+
contextWindow: 2e5
|
|
941
|
+
},
|
|
942
|
+
{
|
|
943
|
+
modelId: "claude-opus-4-20250514",
|
|
944
|
+
default: false,
|
|
945
|
+
provider: "anthropic",
|
|
946
|
+
contextWindow: 2e5
|
|
947
|
+
},
|
|
948
|
+
{
|
|
949
|
+
modelId: "claude-sonnet-4-5",
|
|
950
|
+
default: true,
|
|
951
|
+
provider: "anthropic",
|
|
952
|
+
contextWindow: 2e5
|
|
953
|
+
},
|
|
954
|
+
{
|
|
955
|
+
modelId: "claude-sonnet-4-20250514",
|
|
956
|
+
default: false,
|
|
957
|
+
provider: "anthropic",
|
|
958
|
+
contextWindow: 2e5
|
|
959
|
+
},
|
|
960
|
+
{
|
|
961
|
+
modelId: "claude-3-7-sonnet-20250219",
|
|
962
|
+
default: false,
|
|
963
|
+
provider: "anthropic",
|
|
964
|
+
contextWindow: 2e5
|
|
965
|
+
},
|
|
966
|
+
{
|
|
967
|
+
modelId: "claude-haiku-4-5",
|
|
968
|
+
default: false,
|
|
969
|
+
provider: "anthropic",
|
|
970
|
+
contextWindow: 2e5
|
|
971
|
+
},
|
|
972
|
+
{
|
|
973
|
+
modelId: "claude-3-5-haiku-latest",
|
|
974
|
+
default: false,
|
|
975
|
+
provider: "anthropic",
|
|
976
|
+
contextWindow: 2e5
|
|
977
|
+
}
|
|
978
|
+
];
|
|
979
|
+
const googleSupportModels = [
|
|
980
|
+
{
|
|
981
|
+
modelId: "gemini-3-pro-preview",
|
|
982
|
+
default: false,
|
|
983
|
+
provider: "google",
|
|
984
|
+
contextWindow: 1e6
|
|
985
|
+
},
|
|
986
|
+
{
|
|
987
|
+
modelId: "gemini-2.5-pro",
|
|
988
|
+
default: true,
|
|
989
|
+
provider: "google",
|
|
990
|
+
contextWindow: 1e6
|
|
991
|
+
},
|
|
992
|
+
{
|
|
993
|
+
modelId: "gemini-2.5-flash",
|
|
994
|
+
default: false,
|
|
995
|
+
provider: "google",
|
|
996
|
+
contextWindow: 1e6
|
|
997
|
+
},
|
|
998
|
+
{
|
|
999
|
+
modelId: "gemini-2.5-flash-lite",
|
|
1000
|
+
default: false,
|
|
1001
|
+
provider: "google",
|
|
1002
|
+
contextWindow: 1e6
|
|
1003
|
+
}
|
|
1004
|
+
];
|
|
1005
|
+
const openAiSupportModels = [
|
|
1006
|
+
{
|
|
1007
|
+
modelId: "gpt-5",
|
|
1008
|
+
default: true,
|
|
1009
|
+
provider: "openai",
|
|
1010
|
+
contextWindow: 4e5
|
|
1011
|
+
},
|
|
1012
|
+
{
|
|
1013
|
+
modelId: "gpt-5-mini",
|
|
1014
|
+
default: false,
|
|
1015
|
+
provider: "openai",
|
|
1016
|
+
contextWindow: 4e5
|
|
1017
|
+
},
|
|
1018
|
+
{
|
|
1019
|
+
modelId: "gpt-5-nano",
|
|
1020
|
+
default: false,
|
|
1021
|
+
provider: "openai",
|
|
1022
|
+
contextWindow: 4e5
|
|
1023
|
+
},
|
|
1024
|
+
{
|
|
1025
|
+
modelId: "gpt-5-chat-latest",
|
|
1026
|
+
default: false,
|
|
1027
|
+
provider: "openai",
|
|
1028
|
+
contextWindow: 128e3
|
|
1029
|
+
},
|
|
1030
|
+
{
|
|
1031
|
+
modelId: "o4-mini",
|
|
1032
|
+
default: false,
|
|
1033
|
+
provider: "openai",
|
|
1034
|
+
contextWindow: 2e5
|
|
1035
|
+
},
|
|
1036
|
+
{
|
|
1037
|
+
modelId: "o3",
|
|
1038
|
+
default: false,
|
|
1039
|
+
provider: "openai",
|
|
1040
|
+
contextWindow: 2e5
|
|
1041
|
+
},
|
|
1042
|
+
{
|
|
1043
|
+
modelId: "o3-mini",
|
|
1044
|
+
default: false,
|
|
1045
|
+
provider: "openai",
|
|
1046
|
+
contextWindow: 2e5
|
|
1047
|
+
},
|
|
1048
|
+
{
|
|
1049
|
+
modelId: "gpt-4.1",
|
|
1050
|
+
default: false,
|
|
1051
|
+
provider: "openai",
|
|
1052
|
+
contextWindow: 1e6
|
|
1053
|
+
}
|
|
1054
|
+
];
|
|
1055
|
+
const deepseekSupportModels = [{
|
|
1056
|
+
modelId: "deepseek-chat",
|
|
1057
|
+
default: true,
|
|
1058
|
+
provider: "deepseek",
|
|
1059
|
+
contextWindow: 128e3
|
|
1060
|
+
}, {
|
|
1061
|
+
modelId: "deepseek-reasoner",
|
|
1062
|
+
default: false,
|
|
1063
|
+
provider: "deepseek",
|
|
1064
|
+
contextWindow: 128e3
|
|
1065
|
+
}];
|
|
1066
|
+
const allSupportModels = [
|
|
1067
|
+
...anthropicSupportModels,
|
|
1068
|
+
...googleSupportModels,
|
|
1069
|
+
...openAiSupportModels,
|
|
1070
|
+
...deepseekSupportModels
|
|
1071
|
+
];
|
|
1072
|
+
const supportModels = Object.fromEntries(allSupportModels.map((model) => [model.modelId, model]));
|
|
1073
|
+
function getSupportModelNames() {
|
|
1074
|
+
return Object.keys(supportModels);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
//#endregion
|
|
1078
|
+
//#region ../models/src/domain/job.ts
|
|
1079
|
+
const reasoningBudgetSchema = z.union([z.enum([
|
|
1080
|
+
"none",
|
|
1081
|
+
"minimal",
|
|
1082
|
+
"low",
|
|
1083
|
+
"medium",
|
|
1084
|
+
"high"
|
|
1085
|
+
]), z.number().min(0)]);
|
|
1086
|
+
const jobStatusSchema = z.enum([
|
|
1087
|
+
"queued",
|
|
1088
|
+
"processing",
|
|
1089
|
+
"completed",
|
|
1090
|
+
"requestInteractiveToolResult",
|
|
1091
|
+
"requestDelegateResult",
|
|
1092
|
+
"exceededMaxSteps",
|
|
1093
|
+
"failed",
|
|
1094
|
+
"canceling",
|
|
1095
|
+
"canceled",
|
|
1096
|
+
"expired"
|
|
1097
|
+
]);
|
|
1098
|
+
const modelNames = getSupportModelNames();
|
|
1099
|
+
const firstModel = modelNames[0];
|
|
1100
|
+
if (firstModel === void 0) throw new Error("No support models available");
|
|
1101
|
+
const modelEnum = z.enum([firstModel, ...modelNames.slice(1)]);
|
|
1102
|
+
const jobSchema = z.object({
|
|
1103
|
+
type: z.literal("job"),
|
|
1104
|
+
id: cuidSchema,
|
|
1105
|
+
organizationId: cuidSchema,
|
|
1106
|
+
applicationId: cuidSchema,
|
|
1107
|
+
createdAt: datetimeSchema,
|
|
1108
|
+
updatedAt: datetimeSchema,
|
|
1109
|
+
status: jobStatusSchema,
|
|
1110
|
+
coordinatorExpertKey: expertKeyFieldSchema,
|
|
1111
|
+
query: z.string().min(1).max(maxExpertJobQueryLength).optional(),
|
|
1112
|
+
files: z.array(z.string().min(1).max(maxExpertJobFileNameLength)),
|
|
1113
|
+
expert: expertWithMetadataSchema,
|
|
1114
|
+
provider: providerSchema,
|
|
1115
|
+
model: modelEnum,
|
|
1116
|
+
reasoningBudget: reasoningBudgetSchema,
|
|
1117
|
+
maxSteps: z.number().int().min(1),
|
|
1118
|
+
maxRetries: z.number().int().min(0),
|
|
1119
|
+
currentStep: z.number().int().min(0),
|
|
1120
|
+
totalSteps: z.number().int().min(0),
|
|
1121
|
+
totalDuration: z.number().min(0),
|
|
1122
|
+
usage: usageSchema
|
|
1123
|
+
});
|
|
1124
|
+
|
|
1125
|
+
//#endregion
|
|
1126
|
+
//#region ../models/src/api/jobs/continue.ts
|
|
1127
|
+
const request$13 = {
|
|
1128
|
+
params: z.object({ jobId: cuidSchema }),
|
|
1129
|
+
body: z.object({
|
|
1130
|
+
query: jobSchema.shape.query.optional(),
|
|
1131
|
+
interactiveToolCallResult: z.boolean().optional(),
|
|
1132
|
+
files: z.union([z.instanceof(File), z.array(z.instanceof(File))]).optional(),
|
|
1133
|
+
provider: providerSchema.optional(),
|
|
1134
|
+
model: jobSchema.shape.model.optional(),
|
|
1135
|
+
reasoningBudget: reasoningBudgetSchema.optional(),
|
|
1136
|
+
maxSteps: z.coerce.number().optional(),
|
|
1137
|
+
maxRetries: z.coerce.number().optional()
|
|
1138
|
+
})
|
|
1139
|
+
};
|
|
1140
|
+
const response$14 = z.object({ data: z.object({ job: jobSchema }) });
|
|
1141
|
+
|
|
1142
|
+
//#endregion
|
|
1143
|
+
//#region ../models/src/api/jobs/create.ts
|
|
1144
|
+
const request$12 = { body: z.object({
|
|
1145
|
+
applicationId: cuidSchema.describe("Application ID to create the job in"),
|
|
1146
|
+
expertKey: expertKeyFieldSchema,
|
|
1147
|
+
query: jobSchema.shape.query.optional(),
|
|
1148
|
+
files: z.union([z.instanceof(File), z.array(z.instanceof(File))]).optional(),
|
|
1149
|
+
provider: providerSchema,
|
|
1150
|
+
model: jobSchema.shape.model.optional(),
|
|
1151
|
+
reasoningBudget: reasoningBudgetSchema.optional(),
|
|
1152
|
+
maxSteps: z.coerce.number().optional(),
|
|
1153
|
+
maxRetries: z.coerce.number().optional()
|
|
1154
|
+
}) };
|
|
1155
|
+
const response$13 = z.object({ data: z.object({ job: jobSchema }) });
|
|
1156
|
+
|
|
1157
|
+
//#endregion
|
|
1158
|
+
//#region ../models/src/api/jobs/get.ts
|
|
1159
|
+
const request$11 = { params: z.object({ jobId: cuidSchema }) };
|
|
1160
|
+
const response$12 = z.object({ data: z.object({ job: jobSchema }) });
|
|
1161
|
+
|
|
1162
|
+
//#endregion
|
|
1163
|
+
//#region ../models/src/api/jobs/getAll.ts
|
|
1164
|
+
const request$10 = { query: z.object({
|
|
1165
|
+
sort: z.enum(["createdAt", "updatedAt"]).optional(),
|
|
1166
|
+
order: z.enum(["asc", "desc"]).optional(),
|
|
1167
|
+
take: z.coerce.number().min(1).max(100).default(20),
|
|
1168
|
+
skip: z.coerce.number().min(0).default(0)
|
|
1169
|
+
}) };
|
|
1170
|
+
const response$11 = z.object({
|
|
1171
|
+
data: z.object({ jobs: z.array(jobSchema) }),
|
|
1172
|
+
meta: paginationMeta
|
|
1173
|
+
});
|
|
1174
|
+
|
|
1175
|
+
//#endregion
|
|
1176
|
+
//#region ../models/src/api/jobs/update.ts
|
|
1177
|
+
const request$9 = {
|
|
1178
|
+
params: z.object({ jobId: cuidSchema }),
|
|
1179
|
+
body: z.object({ status: jobStatusSchema })
|
|
1180
|
+
};
|
|
1181
|
+
const response$10 = z.object({ data: z.object({ job: jobSchema }) });
|
|
1182
|
+
|
|
1183
|
+
//#endregion
|
|
1184
|
+
//#region ../models/src/domain/providerSetting.ts
|
|
1185
|
+
const baseUrlSchema = z.string().url().max(maxProviderBaseUrlLength).optional();
|
|
1186
|
+
const headersSchema = z.record(z.string().min(1).max(maxProviderHeaderKeyLength), z.string().max(maxProviderHeaderValueLength)).refine((headers) => Object.keys(headers).length <= maxProviderHeadersCount, { message: `Headers must have at most ${maxProviderHeadersCount} entries` }).optional();
|
|
1187
|
+
const anthropicProviderSettingsSchema = z.object({
|
|
1188
|
+
baseUrl: baseUrlSchema,
|
|
1189
|
+
headers: headersSchema
|
|
1190
|
+
});
|
|
1191
|
+
const googleProviderSettingsSchema = z.object({
|
|
1192
|
+
baseUrl: baseUrlSchema,
|
|
1193
|
+
headers: headersSchema
|
|
1194
|
+
});
|
|
1195
|
+
const openaiProviderSettingsSchema = z.object({
|
|
1196
|
+
baseUrl: baseUrlSchema,
|
|
1197
|
+
headers: headersSchema,
|
|
1198
|
+
organization: z.string().optional(),
|
|
1199
|
+
project: z.string().optional(),
|
|
1200
|
+
name: z.string().optional()
|
|
1201
|
+
});
|
|
1202
|
+
const deepseekProviderSettingsSchema = z.object({
|
|
1203
|
+
baseUrl: baseUrlSchema,
|
|
1204
|
+
headers: headersSchema
|
|
1205
|
+
});
|
|
1206
|
+
const azureOpenaiProviderSettingsSchema = z.object({
|
|
1207
|
+
baseUrl: baseUrlSchema,
|
|
1208
|
+
headers: headersSchema,
|
|
1209
|
+
resourceName: z.string().optional(),
|
|
1210
|
+
apiVersion: z.string().optional(),
|
|
1211
|
+
useDeploymentBasedUrls: z.boolean().optional()
|
|
1212
|
+
});
|
|
1213
|
+
const amazonBedrockProviderSettingsSchema = z.object({ region: z.string().optional() });
|
|
1214
|
+
const googleVertexProviderSettingsSchema = z.object({
|
|
1215
|
+
baseUrl: baseUrlSchema,
|
|
1216
|
+
headers: headersSchema,
|
|
1217
|
+
project: z.string().optional(),
|
|
1218
|
+
location: z.string().optional()
|
|
1219
|
+
});
|
|
1220
|
+
const providerSettingsSchema = z.union([
|
|
1221
|
+
anthropicProviderSettingsSchema,
|
|
1222
|
+
googleProviderSettingsSchema,
|
|
1223
|
+
openaiProviderSettingsSchema,
|
|
1224
|
+
deepseekProviderSettingsSchema,
|
|
1225
|
+
azureOpenaiProviderSettingsSchema,
|
|
1226
|
+
amazonBedrockProviderSettingsSchema,
|
|
1227
|
+
googleVertexProviderSettingsSchema
|
|
1228
|
+
]);
|
|
1229
|
+
const providerSettingSchema = z.object({
|
|
1230
|
+
type: z.literal("providerSetting"),
|
|
1231
|
+
id: cuidSchema,
|
|
1232
|
+
applicationId: cuidSchema,
|
|
1233
|
+
provider: providerSchema,
|
|
1234
|
+
settings: providerSettingsSchema.optional(),
|
|
1235
|
+
application: applicationSchema,
|
|
1236
|
+
createdAt: datetimeSchema,
|
|
1237
|
+
updatedAt: datetimeSchema
|
|
1238
|
+
});
|
|
1239
|
+
const providerSettingResponseSchema = z.object({
|
|
1240
|
+
type: z.literal("providerSetting"),
|
|
1241
|
+
id: cuidSchema,
|
|
1242
|
+
provider: providerSchema,
|
|
1243
|
+
settings: providerSettingsSchema.optional(),
|
|
1244
|
+
createdAt: datetimeSchema,
|
|
1245
|
+
updatedAt: datetimeSchema
|
|
1246
|
+
});
|
|
1247
|
+
const providerApiKeyMetadataSchema = z.object({
|
|
1248
|
+
id: cuidSchema,
|
|
1249
|
+
name: z.string(),
|
|
1250
|
+
createdAt: datetimeSchema,
|
|
1251
|
+
updatedAt: datetimeSchema,
|
|
1252
|
+
lastUsedAt: datetimeSchema.nullable(),
|
|
1253
|
+
expiresAt: datetimeSchema.nullable()
|
|
1254
|
+
});
|
|
1255
|
+
|
|
1256
|
+
//#endregion
|
|
1257
|
+
//#region ../models/src/api/provider-settings/api-keys/create.ts
|
|
1258
|
+
const request$8 = {
|
|
1259
|
+
params: z.object({
|
|
1260
|
+
applicationId: cuidSchema,
|
|
1261
|
+
provider: providerSchema
|
|
1262
|
+
}),
|
|
1263
|
+
body: z.object({
|
|
1264
|
+
name: z.string().min(1).max(255),
|
|
1265
|
+
value: z.string().min(1)
|
|
1266
|
+
})
|
|
1267
|
+
};
|
|
1268
|
+
const response$9 = z.object({ data: z.object({ apiKey: providerApiKeyMetadataSchema }) });
|
|
1269
|
+
|
|
1270
|
+
//#endregion
|
|
1271
|
+
//#region ../models/src/api/provider-settings/api-keys/delete.ts
|
|
1272
|
+
const request$7 = { params: z.object({
|
|
1273
|
+
applicationId: cuidSchema,
|
|
1274
|
+
provider: providerSchema,
|
|
1275
|
+
apiKeyId: cuidSchema
|
|
1276
|
+
}) };
|
|
1277
|
+
const response$8 = z.null();
|
|
1278
|
+
|
|
1279
|
+
//#endregion
|
|
1280
|
+
//#region ../models/src/api/provider-settings/api-keys/getAll.ts
|
|
1281
|
+
const request$6 = { params: z.object({
|
|
1282
|
+
applicationId: cuidSchema,
|
|
1283
|
+
provider: providerSchema
|
|
1284
|
+
}) };
|
|
1285
|
+
const response$7 = z.object({ data: z.object({ apiKeys: z.array(providerApiKeyMetadataSchema) }) });
|
|
1286
|
+
|
|
1287
|
+
//#endregion
|
|
1288
|
+
//#region ../models/src/api/provider-settings/create.ts
|
|
1289
|
+
const request$5 = {
|
|
1290
|
+
params: z.object({ applicationId: cuidSchema }),
|
|
1291
|
+
body: z.object({
|
|
1292
|
+
provider: providerSchema,
|
|
1293
|
+
settings: providerSettingsSchema.optional()
|
|
1294
|
+
})
|
|
1295
|
+
};
|
|
1296
|
+
const response$6 = z.object({ data: z.object({ providerSetting: providerSettingResponseSchema }) });
|
|
1297
|
+
|
|
1298
|
+
//#endregion
|
|
1299
|
+
//#region ../models/src/api/provider-settings/delete.ts
|
|
1300
|
+
const request$4 = { params: z.object({
|
|
1301
|
+
applicationId: cuidSchema,
|
|
1302
|
+
provider: providerSchema
|
|
1303
|
+
}) };
|
|
1304
|
+
const response$5 = z.null();
|
|
1305
|
+
|
|
1306
|
+
//#endregion
|
|
1307
|
+
//#region ../models/src/api/provider-settings/get.ts
|
|
1308
|
+
const request$3 = { params: z.object({
|
|
1309
|
+
applicationId: cuidSchema,
|
|
1310
|
+
provider: providerSchema
|
|
1311
|
+
}) };
|
|
1312
|
+
const response$4 = z.object({ data: z.object({
|
|
1313
|
+
providerSetting: providerSettingResponseSchema,
|
|
1314
|
+
apiKeys: z.array(providerApiKeyMetadataSchema)
|
|
1315
|
+
}) });
|
|
1316
|
+
|
|
1317
|
+
//#endregion
|
|
1318
|
+
//#region ../models/src/api/provider-settings/getAll.ts
|
|
1319
|
+
const request$2 = { params: z.object({ applicationId: cuidSchema }) };
|
|
1320
|
+
const response$3 = z.object({ data: z.object({ providerSettings: z.array(providerSettingResponseSchema) }) });
|
|
1321
|
+
|
|
1322
|
+
//#endregion
|
|
1323
|
+
//#region ../models/src/api/provider-settings/update.ts
|
|
1324
|
+
const request$1 = {
|
|
1325
|
+
params: z.object({
|
|
1326
|
+
applicationId: cuidSchema,
|
|
1327
|
+
provider: providerSchema
|
|
1328
|
+
}),
|
|
1329
|
+
body: z.object({ settings: providerSettingsSchema.optional() })
|
|
1330
|
+
};
|
|
1331
|
+
const response$2 = z.object({ data: z.object({ providerSetting: providerSettingResponseSchema }) });
|
|
1332
|
+
|
|
1333
|
+
//#endregion
|
|
1334
|
+
//#region ../models/src/api/session/get.ts
|
|
1335
|
+
const response$1 = z.object({ data: z.object({
|
|
1336
|
+
user: userSchema,
|
|
1337
|
+
organization: organizationSchema,
|
|
1338
|
+
application: applicationSchema.nullable()
|
|
1339
|
+
}) });
|
|
1340
|
+
|
|
1341
|
+
//#endregion
|
|
1342
|
+
//#region ../models/src/api/session/setApplication.ts
|
|
1343
|
+
const request = { body: z.object({ applicationId: z.string().min(1, "Application ID is required") }) };
|
|
1344
|
+
const response = z.object({ data: z.object({ success: z.literal(true) }) });
|
|
1345
|
+
|
|
1346
|
+
//#endregion
|
|
1347
|
+
//#region ../models/src/domain/providerApiKey.ts
|
|
1348
|
+
const providerApiKeyNameSchema = z.string().min(1).max(255);
|
|
1349
|
+
const providerApiKeyValueSchema = z.string().min(1);
|
|
1350
|
+
const providerApiKeySchema = z.object({
|
|
1351
|
+
type: z.literal("providerApiKey"),
|
|
1352
|
+
id: cuidSchema,
|
|
1353
|
+
providerSettingId: cuidSchema,
|
|
1354
|
+
name: providerApiKeyNameSchema,
|
|
1355
|
+
lastUsedAt: datetimeSchema.optional(),
|
|
1356
|
+
expiresAt: datetimeSchema.optional(),
|
|
1357
|
+
providerSetting: providerSettingSchema,
|
|
1358
|
+
createdAt: datetimeSchema,
|
|
1359
|
+
updatedAt: datetimeSchema
|
|
1360
|
+
});
|
|
1361
|
+
|
|
1362
|
+
//#endregion
|
|
1363
|
+
//#region ../models/src/domain/run.ts
|
|
1364
|
+
const runStatusSchema = z.enum([
|
|
1365
|
+
"queued",
|
|
1366
|
+
"processing",
|
|
1367
|
+
"completed",
|
|
1368
|
+
"stoppedByInteractiveTool",
|
|
1369
|
+
"stoppedByDelegate",
|
|
1370
|
+
"stoppedByExceededMaxSteps",
|
|
1371
|
+
"stoppedByError"
|
|
1372
|
+
]);
|
|
1373
|
+
const runSchema = z.object({
|
|
1374
|
+
type: z.literal("run"),
|
|
1375
|
+
id: cuidSchema,
|
|
1376
|
+
jobId: cuidSchema,
|
|
1377
|
+
parentRunId: cuidSchema.optional(),
|
|
1378
|
+
organizationId: cuidSchema,
|
|
1379
|
+
createdAt: datetimeSchema,
|
|
1380
|
+
updatedAt: datetimeSchema,
|
|
1381
|
+
status: runStatusSchema,
|
|
1382
|
+
runtimeVersion: runtimeVersionSchema,
|
|
1383
|
+
expertKey: expertKeyFieldSchema,
|
|
1384
|
+
interactiveToolCallResult: z.boolean().optional(),
|
|
1385
|
+
expert: expertWithMetadataSchema,
|
|
1386
|
+
stepNumber: z.number().int().min(0),
|
|
1387
|
+
usage: usageSchema,
|
|
1388
|
+
machineId: z.string().optional()
|
|
1389
|
+
});
|
|
1390
|
+
|
|
1391
|
+
//#endregion
|
|
1392
|
+
//#region src/lib/errors.ts
|
|
1393
|
+
function createValidationError(error) {
|
|
1394
|
+
return {
|
|
1395
|
+
errorType: "validation",
|
|
1396
|
+
code: 400,
|
|
1397
|
+
message: `Validation failed: ${error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join("; ")}`,
|
|
1398
|
+
reason: error.issues
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
function createAbortError() {
|
|
1402
|
+
return {
|
|
1403
|
+
errorType: "abort",
|
|
1404
|
+
code: 0,
|
|
1405
|
+
message: "Request aborted",
|
|
1406
|
+
aborted: true
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
function createTimeoutError() {
|
|
1410
|
+
return {
|
|
1411
|
+
errorType: "timeout",
|
|
1412
|
+
code: 0,
|
|
1413
|
+
message: "Request timed out"
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
function createNetworkError(error) {
|
|
1417
|
+
return {
|
|
1418
|
+
errorType: "network",
|
|
1419
|
+
code: 0,
|
|
1420
|
+
message: error instanceof Error ? error.message : "Network error",
|
|
1421
|
+
reason: error,
|
|
1422
|
+
cause: error instanceof Error ? error : void 0
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
async function handleHttpError(response$52) {
|
|
1426
|
+
let errorBody;
|
|
1427
|
+
try {
|
|
1428
|
+
errorBody = await response$52.json();
|
|
1429
|
+
} catch {
|
|
1430
|
+
errorBody = void 0;
|
|
1431
|
+
}
|
|
1432
|
+
return {
|
|
1433
|
+
ok: false,
|
|
1434
|
+
error: createHttpError(response$52.status, response$52.statusText, errorBody)
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
function createHttpError(status, statusText, body) {
|
|
1438
|
+
if (typeof body === "object" && body !== null) {
|
|
1439
|
+
const hasReason = "reason" in body;
|
|
1440
|
+
if ("error" in body && typeof body.error === "string") return {
|
|
1441
|
+
errorType: "http",
|
|
1442
|
+
code: status,
|
|
1443
|
+
message: body.error,
|
|
1444
|
+
reason: hasReason ? body.reason : void 0
|
|
1445
|
+
};
|
|
1446
|
+
if (hasReason) return {
|
|
1447
|
+
errorType: "http",
|
|
1448
|
+
code: status,
|
|
1449
|
+
message: statusText,
|
|
1450
|
+
reason: body.reason
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
return {
|
|
1454
|
+
errorType: "http",
|
|
1455
|
+
code: status,
|
|
1456
|
+
message: statusText
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
function isHttpError(error) {
|
|
1460
|
+
return error.errorType === "http";
|
|
1461
|
+
}
|
|
1462
|
+
function isNetworkError(error) {
|
|
1463
|
+
return error.errorType === "network";
|
|
1464
|
+
}
|
|
1465
|
+
function isTimeoutError(error) {
|
|
1466
|
+
return error.errorType === "timeout";
|
|
1467
|
+
}
|
|
1468
|
+
function isValidationError(error) {
|
|
1469
|
+
return error.errorType === "validation";
|
|
1470
|
+
}
|
|
1471
|
+
function isAbortError(error) {
|
|
1472
|
+
return error.errorType === "abort";
|
|
1473
|
+
}
|
|
1474
|
+
function isClientError(error) {
|
|
1475
|
+
return error.errorType !== "http";
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
//#endregion
|
|
1479
|
+
//#region src/endpoints/api-keys.ts
|
|
1480
|
+
const BASE_PATH$6 = "/api/v1/api_keys";
|
|
1481
|
+
function createApiKeysApi(fetcher) {
|
|
1482
|
+
return {
|
|
1483
|
+
async create(input, options) {
|
|
1484
|
+
const result = request$49.body.safeParse(input);
|
|
1485
|
+
if (!result.success) return {
|
|
1486
|
+
ok: false,
|
|
1487
|
+
error: createValidationError(result.error)
|
|
1488
|
+
};
|
|
1489
|
+
return fetcher.post(BASE_PATH$6, input, options);
|
|
1490
|
+
},
|
|
1491
|
+
async list(input, options) {
|
|
1492
|
+
const queryParams = new URLSearchParams();
|
|
1493
|
+
if (input?.take !== void 0) queryParams.set("take", String(input.take));
|
|
1494
|
+
if (input?.skip !== void 0) queryParams.set("skip", String(input.skip));
|
|
1495
|
+
const queryString = queryParams.toString();
|
|
1496
|
+
const url = queryString ? `${BASE_PATH$6}?${queryString}` : BASE_PATH$6;
|
|
1497
|
+
return fetcher.get(url, options);
|
|
1498
|
+
},
|
|
1499
|
+
async get(id, options) {
|
|
1500
|
+
const result = request$48.params.safeParse({ apiKeyId: id });
|
|
1501
|
+
if (!result.success) return {
|
|
1502
|
+
ok: false,
|
|
1503
|
+
error: createValidationError(result.error)
|
|
1504
|
+
};
|
|
1505
|
+
return fetcher.get(`${BASE_PATH$6}/${id}`, options);
|
|
1506
|
+
},
|
|
1507
|
+
async revoke(id, options) {
|
|
1508
|
+
const result = request$46.params.safeParse({ apiKeyId: id });
|
|
1509
|
+
if (!result.success) return {
|
|
1510
|
+
ok: false,
|
|
1511
|
+
error: createValidationError(result.error)
|
|
1512
|
+
};
|
|
1513
|
+
return fetcher.post(`${BASE_PATH$6}/${id}/revoke`, {}, options);
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
//#endregion
|
|
1519
|
+
//#region src/lib/query-string.ts
|
|
1520
|
+
function buildQueryString(params) {
|
|
1521
|
+
if (!params) return "";
|
|
1522
|
+
const searchParams = new URLSearchParams();
|
|
1523
|
+
for (const [key, value] of Object.entries(params)) if (value !== void 0) searchParams.set(key, String(value));
|
|
1524
|
+
const queryString = searchParams.toString();
|
|
1525
|
+
return queryString ? `?${queryString}` : "";
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
//#endregion
|
|
1529
|
+
//#region src/endpoints/applications.ts
|
|
1530
|
+
const BASE_PATH$5 = "/api/v1/applications";
|
|
1531
|
+
function createApplicationsApi(fetcher) {
|
|
1532
|
+
return {
|
|
1533
|
+
async list(params, options) {
|
|
1534
|
+
if (params) {
|
|
1535
|
+
const result = request$42.query.safeParse(params);
|
|
1536
|
+
if (!result.success) return {
|
|
1537
|
+
ok: false,
|
|
1538
|
+
error: createValidationError(result.error)
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
const queryString = buildQueryString(params);
|
|
1542
|
+
return fetcher.get(`${BASE_PATH$5}${queryString}`, options);
|
|
1543
|
+
},
|
|
1544
|
+
async get(id, options) {
|
|
1545
|
+
return fetcher.get(`${BASE_PATH$5}/${id}`, options);
|
|
1546
|
+
},
|
|
1547
|
+
async create(input, options) {
|
|
1548
|
+
const result = request$45.body.safeParse(input);
|
|
1549
|
+
if (!result.success) return {
|
|
1550
|
+
ok: false,
|
|
1551
|
+
error: createValidationError(result.error)
|
|
1552
|
+
};
|
|
1553
|
+
return fetcher.post(BASE_PATH$5, input, options);
|
|
1554
|
+
},
|
|
1555
|
+
async update(id, input, options) {
|
|
1556
|
+
const result = request$41.body.safeParse(input);
|
|
1557
|
+
if (!result.success) return {
|
|
1558
|
+
ok: false,
|
|
1559
|
+
error: createValidationError(result.error)
|
|
1560
|
+
};
|
|
1561
|
+
return fetcher.post(`${BASE_PATH$5}/${id}`, input, options);
|
|
1562
|
+
},
|
|
1563
|
+
async delete(id, options) {
|
|
1564
|
+
return fetcher.delete(`${BASE_PATH$5}/${id}`, options);
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
//#endregion
|
|
1570
|
+
//#region src/endpoints/env-secrets.ts
|
|
1571
|
+
const BASE_PATH$4 = "/api/v1/env/secrets";
|
|
1572
|
+
function createSecretsApi(fetcher) {
|
|
1573
|
+
return {
|
|
1574
|
+
async list(params, options) {
|
|
1575
|
+
if (params) {
|
|
1576
|
+
const result = request$37.query.safeParse(params);
|
|
1577
|
+
if (!result.success) return {
|
|
1578
|
+
ok: false,
|
|
1579
|
+
error: createValidationError(result.error)
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
const queryString = buildQueryString(params);
|
|
1583
|
+
return fetcher.get(`${BASE_PATH$4}${queryString}`, options);
|
|
1584
|
+
},
|
|
1585
|
+
async get(name, options) {
|
|
1586
|
+
const encodedName = encodeURIComponent(name);
|
|
1587
|
+
return fetcher.get(`${BASE_PATH$4}/${encodedName}`, options);
|
|
1588
|
+
},
|
|
1589
|
+
async create(input, options) {
|
|
1590
|
+
const result = request$40.body.safeParse(input);
|
|
1591
|
+
if (!result.success) return {
|
|
1592
|
+
ok: false,
|
|
1593
|
+
error: createValidationError(result.error)
|
|
1594
|
+
};
|
|
1595
|
+
return fetcher.post(BASE_PATH$4, input, options);
|
|
1596
|
+
},
|
|
1597
|
+
async update(name, input, options) {
|
|
1598
|
+
const result = request$36.body.safeParse(input);
|
|
1599
|
+
if (!result.success) return {
|
|
1600
|
+
ok: false,
|
|
1601
|
+
error: createValidationError(result.error)
|
|
1602
|
+
};
|
|
1603
|
+
const encodedName = encodeURIComponent(name);
|
|
1604
|
+
return fetcher.put(`${BASE_PATH$4}/${encodedName}`, input, options);
|
|
1605
|
+
},
|
|
1606
|
+
async delete(name, options) {
|
|
1607
|
+
const encodedName = encodeURIComponent(name);
|
|
1608
|
+
return fetcher.deleteNoContent(`${BASE_PATH$4}/${encodedName}`, options);
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
//#endregion
|
|
1614
|
+
//#region src/endpoints/env-variables.ts
|
|
1615
|
+
const BASE_PATH$3 = "/api/v1/env/variables";
|
|
1616
|
+
function createVariablesApi(fetcher) {
|
|
1617
|
+
return {
|
|
1618
|
+
async list(params, options) {
|
|
1619
|
+
const result = request$32.query.safeParse(params);
|
|
1620
|
+
if (!result.success) return {
|
|
1621
|
+
ok: false,
|
|
1622
|
+
error: createValidationError(result.error)
|
|
1623
|
+
};
|
|
1624
|
+
const queryString = buildQueryString(params);
|
|
1625
|
+
return fetcher.get(`${BASE_PATH$3}${queryString}`, options);
|
|
1626
|
+
},
|
|
1627
|
+
async get(name, options) {
|
|
1628
|
+
const encodedName = encodeURIComponent(name);
|
|
1629
|
+
return fetcher.get(`${BASE_PATH$3}/${encodedName}`, options);
|
|
1630
|
+
},
|
|
1631
|
+
async create(input, options) {
|
|
1632
|
+
const result = request$35.body.safeParse(input);
|
|
1633
|
+
if (!result.success) return {
|
|
1634
|
+
ok: false,
|
|
1635
|
+
error: createValidationError(result.error)
|
|
1636
|
+
};
|
|
1637
|
+
return fetcher.post(BASE_PATH$3, input, options);
|
|
1638
|
+
},
|
|
1639
|
+
async update(name, input, options) {
|
|
1640
|
+
const result = request$31.body.safeParse(input);
|
|
1641
|
+
if (!result.success) return {
|
|
1642
|
+
ok: false,
|
|
1643
|
+
error: createValidationError(result.error)
|
|
1644
|
+
};
|
|
1645
|
+
const encodedName = encodeURIComponent(name);
|
|
1646
|
+
return fetcher.put(`${BASE_PATH$3}/${encodedName}`, input, options);
|
|
1647
|
+
},
|
|
1648
|
+
async delete(name, options) {
|
|
1649
|
+
const encodedName = encodeURIComponent(name);
|
|
1650
|
+
return fetcher.deleteNoContent(`${BASE_PATH$3}/${encodedName}`, options);
|
|
1651
|
+
}
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
//#endregion
|
|
1656
|
+
//#region src/endpoints/env.ts
|
|
1657
|
+
function createEnvApi(fetcher) {
|
|
1658
|
+
return {
|
|
1659
|
+
secrets: createSecretsApi(fetcher),
|
|
1660
|
+
variables: createVariablesApi(fetcher)
|
|
1661
|
+
};
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
//#endregion
|
|
1665
|
+
//#region src/endpoints/experts-drafts.ts
|
|
1666
|
+
function createDraftsApi(fetcher, basePath) {
|
|
1667
|
+
return {
|
|
1668
|
+
async list(scopeName, params, options) {
|
|
1669
|
+
if (params) {
|
|
1670
|
+
const result = request$26.query.safeParse(params);
|
|
1671
|
+
if (!result.success) return {
|
|
1672
|
+
ok: false,
|
|
1673
|
+
error: createValidationError(result.error)
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
const encodedScopeName = encodeURIComponent(scopeName);
|
|
1677
|
+
const queryString = buildQueryString(params);
|
|
1678
|
+
return fetcher.get(`${basePath}/${encodedScopeName}/drafts${queryString}`, options);
|
|
1679
|
+
},
|
|
1680
|
+
async get(scopeName, draftRef, options) {
|
|
1681
|
+
const encodedScopeName = encodeURIComponent(scopeName);
|
|
1682
|
+
const encodedDraftRef = encodeURIComponent(draftRef);
|
|
1683
|
+
return fetcher.get(`${basePath}/${encodedScopeName}/drafts/${encodedDraftRef}`, options);
|
|
1684
|
+
},
|
|
1685
|
+
async create(scopeName, input, options) {
|
|
1686
|
+
const result = request$29.body.safeParse(input);
|
|
1687
|
+
if (!result.success) return {
|
|
1688
|
+
ok: false,
|
|
1689
|
+
error: createValidationError(result.error)
|
|
1690
|
+
};
|
|
1691
|
+
const encodedScopeName = encodeURIComponent(scopeName);
|
|
1692
|
+
return fetcher.post(`${basePath}/${encodedScopeName}/drafts`, input, options);
|
|
1693
|
+
},
|
|
1694
|
+
async update(scopeName, draftRef, input, options) {
|
|
1695
|
+
const result = request$25.body.safeParse(input);
|
|
1696
|
+
if (!result.success) return {
|
|
1697
|
+
ok: false,
|
|
1698
|
+
error: createValidationError(result.error)
|
|
1699
|
+
};
|
|
1700
|
+
const encodedScopeName = encodeURIComponent(scopeName);
|
|
1701
|
+
const encodedDraftRef = encodeURIComponent(draftRef);
|
|
1702
|
+
return fetcher.post(`${basePath}/${encodedScopeName}/drafts/${encodedDraftRef}`, input, options);
|
|
1703
|
+
},
|
|
1704
|
+
async delete(scopeName, draftRef, options) {
|
|
1705
|
+
const encodedScopeName = encodeURIComponent(scopeName);
|
|
1706
|
+
const encodedDraftRef = encodeURIComponent(draftRef);
|
|
1707
|
+
return fetcher.delete(`${basePath}/${encodedScopeName}/drafts/${encodedDraftRef}`, options);
|
|
1708
|
+
},
|
|
1709
|
+
async assignVersion(scopeName, draftRef, input, options) {
|
|
1710
|
+
const result = request$24.body.safeParse(input);
|
|
1711
|
+
if (!result.success) return {
|
|
1712
|
+
ok: false,
|
|
1713
|
+
error: createValidationError(result.error)
|
|
1714
|
+
};
|
|
1715
|
+
const encodedScopeName = encodeURIComponent(scopeName);
|
|
1716
|
+
const encodedDraftRef = encodeURIComponent(draftRef);
|
|
1717
|
+
return fetcher.post(`${basePath}/${encodedScopeName}/drafts/${encodedDraftRef}/version`, input, options);
|
|
1718
|
+
}
|
|
1719
|
+
};
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
//#endregion
|
|
1723
|
+
//#region src/endpoints/experts-versions.ts
|
|
1724
|
+
function createVersionsApi(fetcher, basePath) {
|
|
1725
|
+
return { async list(scopeName, options) {
|
|
1726
|
+
const encodedScopeName = encodeURIComponent(scopeName);
|
|
1727
|
+
return fetcher.get(`${basePath}/${encodedScopeName}/versions`, options);
|
|
1728
|
+
} };
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
//#endregion
|
|
1732
|
+
//#region src/endpoints/experts.ts
|
|
1733
|
+
const BASE_PATH$2 = "/api/v1/experts";
|
|
1734
|
+
function createExpertsApi(fetcher) {
|
|
1735
|
+
return {
|
|
1736
|
+
async list(params, options) {
|
|
1737
|
+
if (params) {
|
|
1738
|
+
const result = request$22.query.safeParse(params);
|
|
1739
|
+
if (!result.success) return {
|
|
1740
|
+
ok: false,
|
|
1741
|
+
error: createValidationError(result.error)
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
const queryString = buildQueryString(params);
|
|
1745
|
+
return fetcher.get(`${BASE_PATH$2}${queryString}`, options);
|
|
1746
|
+
},
|
|
1747
|
+
async get(key, options) {
|
|
1748
|
+
const encodedKey = encodeURIComponent(key);
|
|
1749
|
+
return fetcher.get(`${BASE_PATH$2}/${encodedKey}`, options);
|
|
1750
|
+
},
|
|
1751
|
+
async getFeatured(options) {
|
|
1752
|
+
return fetcher.get(`${BASE_PATH$2}/featured`, options);
|
|
1753
|
+
},
|
|
1754
|
+
async getMeta(key, options) {
|
|
1755
|
+
const encodedKey = encodeURIComponent(key);
|
|
1756
|
+
return fetcher.get(`${BASE_PATH$2}/${encodedKey}/meta`, options);
|
|
1757
|
+
},
|
|
1758
|
+
async publish(scopeName, options) {
|
|
1759
|
+
const encodedScopeName = encodeURIComponent(scopeName);
|
|
1760
|
+
return fetcher.post(`${BASE_PATH$2}/${encodedScopeName}/publish`, {}, options);
|
|
1761
|
+
},
|
|
1762
|
+
async unpublish(scopeName, options) {
|
|
1763
|
+
const encodedScopeName = encodeURIComponent(scopeName);
|
|
1764
|
+
return fetcher.post(`${BASE_PATH$2}/${encodedScopeName}/unpublish`, {}, options);
|
|
1765
|
+
},
|
|
1766
|
+
async yank(key, options) {
|
|
1767
|
+
const encodedKey = encodeURIComponent(key);
|
|
1768
|
+
return fetcher.delete(`${BASE_PATH$2}/${encodedKey}`, options);
|
|
1769
|
+
},
|
|
1770
|
+
drafts: createDraftsApi(fetcher, BASE_PATH$2),
|
|
1771
|
+
versions: createVersionsApi(fetcher, BASE_PATH$2)
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
//#endregion
|
|
1776
|
+
//#region src/lib/sse.ts
|
|
1777
|
+
async function* parseSSE(reader) {
|
|
1778
|
+
const decoder = new TextDecoder();
|
|
1779
|
+
let buffer = "";
|
|
1780
|
+
while (true) {
|
|
1781
|
+
const { value, done } = await reader.read();
|
|
1782
|
+
if (done) break;
|
|
1783
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1784
|
+
const events = buffer.split("\n\n");
|
|
1785
|
+
buffer = events.pop() || "";
|
|
1786
|
+
for (const event of events) {
|
|
1787
|
+
if (event.trim() === "") continue;
|
|
1788
|
+
const lines = event.split("\n");
|
|
1789
|
+
const eventType = lines.find((line) => line.startsWith("event:"))?.slice(6).trim();
|
|
1790
|
+
const data = lines.find((line) => line.startsWith("data:"))?.slice(5).trim();
|
|
1791
|
+
if (eventType !== "message" || !data) continue;
|
|
1792
|
+
try {
|
|
1793
|
+
yield JSON.parse(data);
|
|
1794
|
+
} catch {}
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
//#endregion
|
|
1800
|
+
//#region src/endpoints/jobs-checkpoints.ts
|
|
1801
|
+
function createCheckpointsApi(fetcher, basePath) {
|
|
1802
|
+
return {
|
|
1803
|
+
async list(jobId, params, options) {
|
|
1804
|
+
if (params) {
|
|
1805
|
+
const result = request$15.query.safeParse(params);
|
|
1806
|
+
if (!result.success) return {
|
|
1807
|
+
ok: false,
|
|
1808
|
+
error: createValidationError(result.error)
|
|
1809
|
+
};
|
|
1810
|
+
}
|
|
1811
|
+
const queryString = buildQueryString(params);
|
|
1812
|
+
return fetcher.get(`${basePath}/${jobId}/checkpoints${queryString}`, options);
|
|
1813
|
+
},
|
|
1814
|
+
async get(jobId, checkpointId, options) {
|
|
1815
|
+
return fetcher.get(`${basePath}/${jobId}/checkpoints/${checkpointId}`, options);
|
|
1816
|
+
},
|
|
1817
|
+
async create(jobId, input, options) {
|
|
1818
|
+
const result = request$17.body.safeParse(input);
|
|
1819
|
+
if (!result.success) return {
|
|
1820
|
+
ok: false,
|
|
1821
|
+
error: createValidationError(result.error)
|
|
1822
|
+
};
|
|
1823
|
+
return fetcher.post(`${basePath}/${jobId}/checkpoints`, input, options);
|
|
1824
|
+
},
|
|
1825
|
+
async *stream(jobId, options) {
|
|
1826
|
+
const result = await fetcher.getStream(`${basePath}/${jobId}/checkpoints/stream`, options);
|
|
1827
|
+
if (!result.ok) {
|
|
1828
|
+
yield {
|
|
1829
|
+
ok: false,
|
|
1830
|
+
error: result.error
|
|
1831
|
+
};
|
|
1832
|
+
return;
|
|
1833
|
+
}
|
|
1834
|
+
const reader = result.data.getReader();
|
|
1835
|
+
try {
|
|
1836
|
+
for await (const checkpoint of parseSSE(reader)) yield {
|
|
1837
|
+
ok: true,
|
|
1838
|
+
data: checkpoint
|
|
1839
|
+
};
|
|
1840
|
+
} catch (error) {
|
|
1841
|
+
if (error instanceof DOMException && error.name === "AbortError") yield {
|
|
1842
|
+
ok: false,
|
|
1843
|
+
error: createAbortError()
|
|
1844
|
+
};
|
|
1845
|
+
else yield {
|
|
1846
|
+
ok: false,
|
|
1847
|
+
error: createNetworkError(error)
|
|
1848
|
+
};
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
};
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
//#endregion
|
|
1855
|
+
//#region src/endpoints/jobs.ts
|
|
1856
|
+
const BASE_PATH$1 = "/api/v1/jobs";
|
|
1857
|
+
function createJobsApi(fetcher) {
|
|
1858
|
+
return {
|
|
1859
|
+
async list(params, options) {
|
|
1860
|
+
if (params) {
|
|
1861
|
+
const result = request$10.query.safeParse(params);
|
|
1862
|
+
if (!result.success) return {
|
|
1863
|
+
ok: false,
|
|
1864
|
+
error: createValidationError(result.error)
|
|
1865
|
+
};
|
|
1866
|
+
}
|
|
1867
|
+
const queryString = buildQueryString(params);
|
|
1868
|
+
return fetcher.get(`${BASE_PATH$1}${queryString}`, options);
|
|
1869
|
+
},
|
|
1870
|
+
async get(id, options) {
|
|
1871
|
+
return fetcher.get(`${BASE_PATH$1}/${id}`, options);
|
|
1872
|
+
},
|
|
1873
|
+
async start(input, options) {
|
|
1874
|
+
const result = request$12.body.safeParse(input);
|
|
1875
|
+
if (!result.success) return {
|
|
1876
|
+
ok: false,
|
|
1877
|
+
error: createValidationError(result.error)
|
|
1878
|
+
};
|
|
1879
|
+
return fetcher.post(BASE_PATH$1, input, options);
|
|
1880
|
+
},
|
|
1881
|
+
async update(id, input, options) {
|
|
1882
|
+
const result = request$9.body.safeParse(input);
|
|
1883
|
+
if (!result.success) return {
|
|
1884
|
+
ok: false,
|
|
1885
|
+
error: createValidationError(result.error)
|
|
1886
|
+
};
|
|
1887
|
+
return fetcher.post(`${BASE_PATH$1}/${id}`, input, options);
|
|
1888
|
+
},
|
|
1889
|
+
async continue(id, input, options) {
|
|
1890
|
+
const result = request$13.body.safeParse(input);
|
|
1891
|
+
if (!result.success) return {
|
|
1892
|
+
ok: false,
|
|
1893
|
+
error: createValidationError(result.error)
|
|
1894
|
+
};
|
|
1895
|
+
return fetcher.post(`${BASE_PATH$1}/${id}/continue`, input, options);
|
|
1896
|
+
},
|
|
1897
|
+
async cancel(id, options) {
|
|
1898
|
+
return fetcher.post(`${BASE_PATH$1}/${id}/cancel`, {}, options);
|
|
1899
|
+
},
|
|
1900
|
+
checkpoints: createCheckpointsApi(fetcher, BASE_PATH$1)
|
|
1901
|
+
};
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1904
|
+
//#endregion
|
|
1905
|
+
//#region src/endpoints/provider-settings.ts
|
|
1906
|
+
const BASE_PATH = "/api/v1/applications";
|
|
1907
|
+
function createProviderSettingsApi(fetcher) {
|
|
1908
|
+
return {
|
|
1909
|
+
async list(applicationId, options) {
|
|
1910
|
+
return fetcher.get(`${BASE_PATH}/${applicationId}/provider_settings`, options);
|
|
1911
|
+
},
|
|
1912
|
+
async get(applicationId, provider, options) {
|
|
1913
|
+
const encodedProvider = encodeURIComponent(provider);
|
|
1914
|
+
return fetcher.get(`${BASE_PATH}/${applicationId}/provider_settings/${encodedProvider}`, options);
|
|
1915
|
+
},
|
|
1916
|
+
async create(applicationId, input, options) {
|
|
1917
|
+
const result = request$5.body.safeParse(input);
|
|
1918
|
+
if (!result.success) return {
|
|
1919
|
+
ok: false,
|
|
1920
|
+
error: createValidationError(result.error)
|
|
1921
|
+
};
|
|
1922
|
+
return fetcher.post(`${BASE_PATH}/${applicationId}/provider_settings`, input, options);
|
|
1923
|
+
},
|
|
1924
|
+
async update(applicationId, provider, input, options) {
|
|
1925
|
+
const result = request$1.body.safeParse(input);
|
|
1926
|
+
if (!result.success) return {
|
|
1927
|
+
ok: false,
|
|
1928
|
+
error: createValidationError(result.error)
|
|
1929
|
+
};
|
|
1930
|
+
const encodedProvider = encodeURIComponent(provider);
|
|
1931
|
+
return fetcher.post(`${BASE_PATH}/${applicationId}/provider_settings/${encodedProvider}`, input, options);
|
|
1932
|
+
},
|
|
1933
|
+
async delete(applicationId, provider, options) {
|
|
1934
|
+
const encodedProvider = encodeURIComponent(provider);
|
|
1935
|
+
return fetcher.deleteNoContent(`${BASE_PATH}/${applicationId}/provider_settings/${encodedProvider}`, options);
|
|
1936
|
+
},
|
|
1937
|
+
async listApiKeys(applicationId, provider, options) {
|
|
1938
|
+
const encodedProvider = encodeURIComponent(provider);
|
|
1939
|
+
return fetcher.get(`${BASE_PATH}/${applicationId}/provider_settings/${encodedProvider}/api_keys`, options);
|
|
1940
|
+
},
|
|
1941
|
+
async createApiKey(applicationId, provider, input, options) {
|
|
1942
|
+
const result = request$8.body.safeParse(input);
|
|
1943
|
+
if (!result.success) return {
|
|
1944
|
+
ok: false,
|
|
1945
|
+
error: createValidationError(result.error)
|
|
1946
|
+
};
|
|
1947
|
+
const encodedProvider = encodeURIComponent(provider);
|
|
1948
|
+
return fetcher.post(`${BASE_PATH}/${applicationId}/provider_settings/${encodedProvider}/api_keys`, input, options);
|
|
1949
|
+
},
|
|
1950
|
+
async deleteApiKey(applicationId, provider, apiKeyId, options) {
|
|
1951
|
+
const encodedProvider = encodeURIComponent(provider);
|
|
1952
|
+
const encodedApiKeyId = encodeURIComponent(apiKeyId);
|
|
1953
|
+
return fetcher.deleteNoContent(`${BASE_PATH}/${applicationId}/provider_settings/${encodedProvider}/api_keys/${encodedApiKeyId}`, options);
|
|
1954
|
+
}
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
//#endregion
|
|
1959
|
+
//#region src/lib/fetcher.ts
|
|
1960
|
+
const DEFAULT_BASE_URL = "https://api.perstack.ai";
|
|
1961
|
+
const DEFAULT_TIMEOUT = 3e4;
|
|
1962
|
+
function createFetcher(config) {
|
|
1963
|
+
const baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
1964
|
+
const timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
1965
|
+
const useCredentials = "credentials" in config && config.credentials === "include";
|
|
1966
|
+
const apiKey = "apiKey" in config ? config.apiKey : void 0;
|
|
1967
|
+
function buildUrl(path) {
|
|
1968
|
+
return `${baseUrl}${path}`;
|
|
1969
|
+
}
|
|
1970
|
+
function buildHeaders(options) {
|
|
1971
|
+
const headers = {};
|
|
1972
|
+
if (options?.hasBody) headers["Content-Type"] = "application/json";
|
|
1973
|
+
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
|
|
1974
|
+
return headers;
|
|
1975
|
+
}
|
|
1976
|
+
function getCredentials() {
|
|
1977
|
+
return useCredentials ? "include" : void 0;
|
|
1978
|
+
}
|
|
1979
|
+
function createTimeoutSignal(externalSignal) {
|
|
1980
|
+
const controller = new AbortController();
|
|
1981
|
+
let timedOut = false;
|
|
1982
|
+
const timeoutId = setTimeout(() => {
|
|
1983
|
+
timedOut = true;
|
|
1984
|
+
controller.abort();
|
|
1985
|
+
}, timeout);
|
|
1986
|
+
let abortHandler;
|
|
1987
|
+
if (externalSignal) if (externalSignal.aborted) controller.abort();
|
|
1988
|
+
else {
|
|
1989
|
+
abortHandler = () => controller.abort();
|
|
1990
|
+
externalSignal.addEventListener("abort", abortHandler);
|
|
1991
|
+
}
|
|
1992
|
+
return {
|
|
1993
|
+
signal: controller.signal,
|
|
1994
|
+
cleanup: () => {
|
|
1995
|
+
clearTimeout(timeoutId);
|
|
1996
|
+
if (abortHandler && externalSignal) externalSignal.removeEventListener("abort", abortHandler);
|
|
1997
|
+
},
|
|
1998
|
+
isTimeout: () => timedOut
|
|
1999
|
+
};
|
|
2000
|
+
}
|
|
2001
|
+
function wrapStreamWithIdleTimeout(stream, idleTimeoutMs, externalSignal) {
|
|
2002
|
+
const reader = stream.getReader();
|
|
2003
|
+
const controller = new AbortController();
|
|
2004
|
+
let timeoutId;
|
|
2005
|
+
let abortHandler;
|
|
2006
|
+
if (externalSignal) if (externalSignal.aborted) controller.abort();
|
|
2007
|
+
else {
|
|
2008
|
+
abortHandler = () => controller.abort();
|
|
2009
|
+
externalSignal.addEventListener("abort", abortHandler);
|
|
2010
|
+
}
|
|
2011
|
+
function resetTimeout() {
|
|
2012
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
2013
|
+
timeoutId = setTimeout(() => controller.abort(), idleTimeoutMs);
|
|
2014
|
+
}
|
|
2015
|
+
function cleanup() {
|
|
2016
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
2017
|
+
if (abortHandler && externalSignal) externalSignal.removeEventListener("abort", abortHandler);
|
|
2018
|
+
}
|
|
2019
|
+
return new ReadableStream({
|
|
2020
|
+
start() {
|
|
2021
|
+
resetTimeout();
|
|
2022
|
+
},
|
|
2023
|
+
async pull(streamController) {
|
|
2024
|
+
try {
|
|
2025
|
+
const result = await Promise.race([reader.read(), new Promise((_, reject) => {
|
|
2026
|
+
if (controller.signal.aborted) reject(new DOMException("Stream idle timeout", "AbortError"));
|
|
2027
|
+
controller.signal.addEventListener("abort", () => {
|
|
2028
|
+
reject(new DOMException("Stream idle timeout", "AbortError"));
|
|
2029
|
+
});
|
|
2030
|
+
})]);
|
|
2031
|
+
if (result.done) {
|
|
2032
|
+
cleanup();
|
|
2033
|
+
streamController.close();
|
|
2034
|
+
return;
|
|
2035
|
+
}
|
|
2036
|
+
resetTimeout();
|
|
2037
|
+
streamController.enqueue(result.value);
|
|
2038
|
+
} catch (error) {
|
|
2039
|
+
cleanup();
|
|
2040
|
+
reader.cancel().catch(() => {});
|
|
2041
|
+
if (error instanceof DOMException && error.name === "AbortError") streamController.error(new DOMException("Stream idle timeout", "AbortError"));
|
|
2042
|
+
else streamController.error(error);
|
|
2043
|
+
}
|
|
2044
|
+
},
|
|
2045
|
+
cancel(reason) {
|
|
2046
|
+
cleanup();
|
|
2047
|
+
reader.cancel(reason).catch(() => {});
|
|
2048
|
+
}
|
|
2049
|
+
});
|
|
2050
|
+
}
|
|
2051
|
+
async function request$50(method, path, body, options) {
|
|
2052
|
+
const { signal, cleanup, isTimeout } = createTimeoutSignal(options?.signal);
|
|
2053
|
+
try {
|
|
2054
|
+
const response$52 = await fetch(buildUrl(path), {
|
|
2055
|
+
method,
|
|
2056
|
+
headers: buildHeaders(body ? { hasBody: true } : void 0),
|
|
2057
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
2058
|
+
signal,
|
|
2059
|
+
credentials: getCredentials()
|
|
2060
|
+
});
|
|
2061
|
+
if (!response$52.ok) return handleHttpError(response$52);
|
|
2062
|
+
return {
|
|
2063
|
+
ok: true,
|
|
2064
|
+
data: await response$52.json()
|
|
2065
|
+
};
|
|
2066
|
+
} catch (error) {
|
|
2067
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
2068
|
+
if (isTimeout()) return {
|
|
2069
|
+
ok: false,
|
|
2070
|
+
error: createTimeoutError()
|
|
2071
|
+
};
|
|
2072
|
+
return {
|
|
2073
|
+
ok: false,
|
|
2074
|
+
error: createAbortError()
|
|
2075
|
+
};
|
|
2076
|
+
}
|
|
2077
|
+
return {
|
|
2078
|
+
ok: false,
|
|
2079
|
+
error: createNetworkError(error)
|
|
2080
|
+
};
|
|
2081
|
+
} finally {
|
|
2082
|
+
cleanup();
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
async function requestBlob(path, options) {
|
|
2086
|
+
const { signal, cleanup, isTimeout } = createTimeoutSignal(options?.signal);
|
|
2087
|
+
try {
|
|
2088
|
+
const response$52 = await fetch(buildUrl(path), {
|
|
2089
|
+
method: "GET",
|
|
2090
|
+
headers: buildHeaders(),
|
|
2091
|
+
signal,
|
|
2092
|
+
credentials: getCredentials()
|
|
2093
|
+
});
|
|
2094
|
+
if (!response$52.ok) return handleHttpError(response$52);
|
|
2095
|
+
return {
|
|
2096
|
+
ok: true,
|
|
2097
|
+
data: await response$52.blob()
|
|
2098
|
+
};
|
|
2099
|
+
} catch (error) {
|
|
2100
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
2101
|
+
if (isTimeout()) return {
|
|
2102
|
+
ok: false,
|
|
2103
|
+
error: createTimeoutError()
|
|
2104
|
+
};
|
|
2105
|
+
return {
|
|
2106
|
+
ok: false,
|
|
2107
|
+
error: createAbortError()
|
|
2108
|
+
};
|
|
2109
|
+
}
|
|
2110
|
+
return {
|
|
2111
|
+
ok: false,
|
|
2112
|
+
error: createNetworkError(error)
|
|
2113
|
+
};
|
|
2114
|
+
} finally {
|
|
2115
|
+
cleanup();
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
async function requestStream(path, options) {
|
|
2119
|
+
const { signal, cleanup, isTimeout } = createTimeoutSignal(options?.signal);
|
|
2120
|
+
try {
|
|
2121
|
+
const response$52 = await fetch(buildUrl(path), {
|
|
2122
|
+
method: "GET",
|
|
2123
|
+
headers: buildHeaders(),
|
|
2124
|
+
signal,
|
|
2125
|
+
credentials: getCredentials()
|
|
2126
|
+
});
|
|
2127
|
+
if (!response$52.ok) {
|
|
2128
|
+
cleanup();
|
|
2129
|
+
return handleHttpError(response$52);
|
|
2130
|
+
}
|
|
2131
|
+
if (!response$52.body) {
|
|
2132
|
+
cleanup();
|
|
2133
|
+
return {
|
|
2134
|
+
ok: false,
|
|
2135
|
+
error: createNetworkError(/* @__PURE__ */ new Error("Response body is null"))
|
|
2136
|
+
};
|
|
2137
|
+
}
|
|
2138
|
+
cleanup();
|
|
2139
|
+
const idleTimeout = options?.streamIdleTimeout ?? timeout;
|
|
2140
|
+
return {
|
|
2141
|
+
ok: true,
|
|
2142
|
+
data: wrapStreamWithIdleTimeout(response$52.body, idleTimeout, options?.signal)
|
|
2143
|
+
};
|
|
2144
|
+
} catch (error) {
|
|
2145
|
+
cleanup();
|
|
2146
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
2147
|
+
if (isTimeout()) return {
|
|
2148
|
+
ok: false,
|
|
2149
|
+
error: createTimeoutError()
|
|
2150
|
+
};
|
|
2151
|
+
return {
|
|
2152
|
+
ok: false,
|
|
2153
|
+
error: createAbortError()
|
|
2154
|
+
};
|
|
2155
|
+
}
|
|
2156
|
+
return {
|
|
2157
|
+
ok: false,
|
|
2158
|
+
error: createNetworkError(error)
|
|
2159
|
+
};
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
async function requestNoContent(method, path, options) {
|
|
2163
|
+
const { signal, cleanup, isTimeout } = createTimeoutSignal(options?.signal);
|
|
2164
|
+
try {
|
|
2165
|
+
const response$52 = await fetch(buildUrl(path), {
|
|
2166
|
+
method,
|
|
2167
|
+
headers: buildHeaders(),
|
|
2168
|
+
signal,
|
|
2169
|
+
credentials: getCredentials()
|
|
2170
|
+
});
|
|
2171
|
+
if (!response$52.ok) return handleHttpError(response$52);
|
|
2172
|
+
return {
|
|
2173
|
+
ok: true,
|
|
2174
|
+
data: void 0
|
|
2175
|
+
};
|
|
2176
|
+
} catch (error) {
|
|
2177
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
2178
|
+
if (isTimeout()) return {
|
|
2179
|
+
ok: false,
|
|
2180
|
+
error: createTimeoutError()
|
|
2181
|
+
};
|
|
2182
|
+
return {
|
|
2183
|
+
ok: false,
|
|
2184
|
+
error: createAbortError()
|
|
2185
|
+
};
|
|
2186
|
+
}
|
|
2187
|
+
return {
|
|
2188
|
+
ok: false,
|
|
2189
|
+
error: createNetworkError(error)
|
|
2190
|
+
};
|
|
2191
|
+
} finally {
|
|
2192
|
+
cleanup();
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
return {
|
|
2196
|
+
get: (path, options) => request$50("GET", path, void 0, options),
|
|
2197
|
+
post: (path, body, options) => request$50("POST", path, body, options),
|
|
2198
|
+
put: (path, body, options) => request$50("PUT", path, body, options),
|
|
2199
|
+
delete: (path, options) => request$50("DELETE", path, void 0, options),
|
|
2200
|
+
deleteNoContent: (path, options) => requestNoContent("DELETE", path, options),
|
|
2201
|
+
getBlob: (path, options) => requestBlob(path, options),
|
|
2202
|
+
getStream: (path, options) => requestStream(path, options)
|
|
2203
|
+
};
|
|
2204
|
+
}
|
|
2205
|
+
|
|
2206
|
+
//#endregion
|
|
2207
|
+
//#region src/client-public.ts
|
|
2208
|
+
function createApiClient(config) {
|
|
2209
|
+
const fetcher = createFetcher(config);
|
|
2210
|
+
return {
|
|
2211
|
+
apiKeys: createApiKeysApi(fetcher),
|
|
2212
|
+
applications: createApplicationsApi(fetcher),
|
|
2213
|
+
env: createEnvApi(fetcher),
|
|
2214
|
+
jobs: createJobsApi(fetcher),
|
|
2215
|
+
experts: createExpertsApi(fetcher),
|
|
2216
|
+
providerSettings: createProviderSettingsApi(fetcher)
|
|
2217
|
+
};
|
|
2218
|
+
}
|
|
2219
|
+
|
|
2220
|
+
//#endregion
|
|
2221
|
+
//#region src/lib/api-key.ts
|
|
2222
|
+
function matchWildcard(value, pattern) {
|
|
2223
|
+
if (pattern === "*") return true;
|
|
2224
|
+
if (pattern.endsWith("*")) return value.startsWith(pattern.slice(0, -1));
|
|
2225
|
+
if (pattern.startsWith("*")) return value.endsWith(pattern.slice(1));
|
|
2226
|
+
return value === pattern;
|
|
2227
|
+
}
|
|
2228
|
+
function matchOperations(operations, requiredOperation) {
|
|
2229
|
+
return operations.some((pattern) => matchWildcard(requiredOperation, pattern));
|
|
2230
|
+
}
|
|
2231
|
+
function matchExperts(experts, expertId) {
|
|
2232
|
+
if (experts === void 0 || experts === "*") return true;
|
|
2233
|
+
return experts.some((pattern) => matchWildcard(expertId, pattern));
|
|
2234
|
+
}
|
|
2235
|
+
function isApiKeyPermissions(parsed) {
|
|
2236
|
+
return typeof parsed === "object" && parsed !== null && "operations" in parsed && Array.isArray(parsed.operations);
|
|
2237
|
+
}
|
|
2238
|
+
function parseApiKeyPermissions(permissionsJson) {
|
|
2239
|
+
if (!permissionsJson) return null;
|
|
2240
|
+
try {
|
|
2241
|
+
const parsed = JSON.parse(permissionsJson);
|
|
2242
|
+
if (!isApiKeyPermissions(parsed)) return null;
|
|
2243
|
+
return parsed;
|
|
2244
|
+
} catch {
|
|
2245
|
+
return null;
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
function stringifyApiKeyPermissions(permissions) {
|
|
2249
|
+
return JSON.stringify(permissions);
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
//#endregion
|
|
2253
|
+
//#region src/lib/auth.ts
|
|
2254
|
+
function buildAuthHeaders(auth) {
|
|
2255
|
+
if (auth.type === "apiKey") return { Authorization: `Bearer ${auth.apiKey}` };
|
|
2256
|
+
return { Cookie: auth.cookie };
|
|
2257
|
+
}
|
|
2258
|
+
|
|
2259
|
+
//#endregion
|
|
2260
|
+
export { buildAuthHeaders, buildQueryString, createAbortError, createApiClient, createFetcher, createHttpError, createNetworkError, createTimeoutError, createValidationError, handleHttpError, isAbortError, isClientError, isHttpError, isNetworkError, isTimeoutError, isValidationError, matchExperts, matchOperations, matchWildcard, parseApiKeyPermissions, parseSSE, stringifyApiKeyPermissions };
|
|
2261
|
+
//# sourceMappingURL=bundle.mjs.map
|