@gpt-core/admin 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1606 -0
- package/dist/index.d.mts +1346 -1080
- package/dist/index.d.ts +1346 -1080
- package/llms.txt +29 -2
- package/package.json +11 -11
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1606 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AccountCreditSchema: () => AccountCreditSchema,
|
|
24
|
+
AccountDebitSchema: () => AccountDebitSchema,
|
|
25
|
+
AgentAdminCreateSchema: () => AgentAdminCreateSchema,
|
|
26
|
+
ApiKeyAllocateSchema: () => ApiKeyAllocateSchema,
|
|
27
|
+
AuthenticationError: () => AuthenticationError,
|
|
28
|
+
AuthorizationError: () => AuthorizationError,
|
|
29
|
+
DocumentBulkDeleteSchema: () => DocumentBulkDeleteSchema,
|
|
30
|
+
DocumentBulkReprocessSchema: () => DocumentBulkReprocessSchema,
|
|
31
|
+
GptAdmin: () => GptAdmin,
|
|
32
|
+
GptCoreError: () => GptCoreError,
|
|
33
|
+
NetworkError: () => NetworkError,
|
|
34
|
+
NotFoundError: () => NotFoundError,
|
|
35
|
+
RateLimitError: () => RateLimitError,
|
|
36
|
+
ServerError: () => ServerError,
|
|
37
|
+
StorageStatsRequestSchema: () => StorageStatsRequestSchema,
|
|
38
|
+
TimeoutError: () => TimeoutError,
|
|
39
|
+
ValidationError: () => ValidationError,
|
|
40
|
+
WebhookBulkDisableSchema: () => WebhookBulkDisableSchema,
|
|
41
|
+
WebhookBulkEnableSchema: () => WebhookBulkEnableSchema,
|
|
42
|
+
WebhookConfigCreateSchema: () => WebhookConfigCreateSchema,
|
|
43
|
+
WebhookDeliveryBulkRetrySchema: () => WebhookDeliveryBulkRetrySchema,
|
|
44
|
+
handleApiError: () => handleApiError
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(index_exports);
|
|
47
|
+
|
|
48
|
+
// src/_internal/core/bodySerializer.gen.ts
|
|
49
|
+
var jsonBodySerializer = {
|
|
50
|
+
bodySerializer: (body) => JSON.stringify(
|
|
51
|
+
body,
|
|
52
|
+
(_key, value) => typeof value === "bigint" ? value.toString() : value
|
|
53
|
+
)
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/_internal/core/params.gen.ts
|
|
57
|
+
var extraPrefixesMap = {
|
|
58
|
+
$body_: "body",
|
|
59
|
+
$headers_: "headers",
|
|
60
|
+
$path_: "path",
|
|
61
|
+
$query_: "query"
|
|
62
|
+
};
|
|
63
|
+
var extraPrefixes = Object.entries(extraPrefixesMap);
|
|
64
|
+
|
|
65
|
+
// src/_internal/core/serverSentEvents.gen.ts
|
|
66
|
+
var createSseClient = ({
|
|
67
|
+
onRequest,
|
|
68
|
+
onSseError,
|
|
69
|
+
onSseEvent,
|
|
70
|
+
responseTransformer,
|
|
71
|
+
responseValidator,
|
|
72
|
+
sseDefaultRetryDelay,
|
|
73
|
+
sseMaxRetryAttempts,
|
|
74
|
+
sseMaxRetryDelay,
|
|
75
|
+
sseSleepFn,
|
|
76
|
+
url,
|
|
77
|
+
...options
|
|
78
|
+
}) => {
|
|
79
|
+
let lastEventId;
|
|
80
|
+
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
81
|
+
const createStream = async function* () {
|
|
82
|
+
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
83
|
+
let attempt = 0;
|
|
84
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
85
|
+
while (true) {
|
|
86
|
+
if (signal.aborted) break;
|
|
87
|
+
attempt++;
|
|
88
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
89
|
+
if (lastEventId !== void 0) {
|
|
90
|
+
headers.set("Last-Event-ID", lastEventId);
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
const requestInit = {
|
|
94
|
+
redirect: "follow",
|
|
95
|
+
...options,
|
|
96
|
+
body: options.serializedBody,
|
|
97
|
+
headers,
|
|
98
|
+
signal
|
|
99
|
+
};
|
|
100
|
+
let request = new Request(url, requestInit);
|
|
101
|
+
if (onRequest) {
|
|
102
|
+
request = await onRequest(url, requestInit);
|
|
103
|
+
}
|
|
104
|
+
const _fetch = options.fetch ?? globalThis.fetch;
|
|
105
|
+
const response = await _fetch(request);
|
|
106
|
+
if (!response.ok)
|
|
107
|
+
throw new Error(
|
|
108
|
+
`SSE failed: ${response.status} ${response.statusText}`
|
|
109
|
+
);
|
|
110
|
+
if (!response.body) throw new Error("No body in SSE response");
|
|
111
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
112
|
+
let buffer = "";
|
|
113
|
+
const abortHandler = () => {
|
|
114
|
+
try {
|
|
115
|
+
reader.cancel();
|
|
116
|
+
} catch {
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
signal.addEventListener("abort", abortHandler);
|
|
120
|
+
try {
|
|
121
|
+
while (true) {
|
|
122
|
+
const { done, value } = await reader.read();
|
|
123
|
+
if (done) break;
|
|
124
|
+
buffer += value;
|
|
125
|
+
buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
126
|
+
const chunks = buffer.split("\n\n");
|
|
127
|
+
buffer = chunks.pop() ?? "";
|
|
128
|
+
for (const chunk of chunks) {
|
|
129
|
+
const lines = chunk.split("\n");
|
|
130
|
+
const dataLines = [];
|
|
131
|
+
let eventName;
|
|
132
|
+
for (const line of lines) {
|
|
133
|
+
if (line.startsWith("data:")) {
|
|
134
|
+
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
135
|
+
} else if (line.startsWith("event:")) {
|
|
136
|
+
eventName = line.replace(/^event:\s*/, "");
|
|
137
|
+
} else if (line.startsWith("id:")) {
|
|
138
|
+
lastEventId = line.replace(/^id:\s*/, "");
|
|
139
|
+
} else if (line.startsWith("retry:")) {
|
|
140
|
+
const parsed = Number.parseInt(
|
|
141
|
+
line.replace(/^retry:\s*/, ""),
|
|
142
|
+
10
|
|
143
|
+
);
|
|
144
|
+
if (!Number.isNaN(parsed)) {
|
|
145
|
+
retryDelay = parsed;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
let data;
|
|
150
|
+
let parsedJson = false;
|
|
151
|
+
if (dataLines.length) {
|
|
152
|
+
const rawData = dataLines.join("\n");
|
|
153
|
+
try {
|
|
154
|
+
data = JSON.parse(rawData);
|
|
155
|
+
parsedJson = true;
|
|
156
|
+
} catch {
|
|
157
|
+
data = rawData;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (parsedJson) {
|
|
161
|
+
if (responseValidator) {
|
|
162
|
+
await responseValidator(data);
|
|
163
|
+
}
|
|
164
|
+
if (responseTransformer) {
|
|
165
|
+
data = await responseTransformer(data);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
onSseEvent?.({
|
|
169
|
+
data,
|
|
170
|
+
event: eventName,
|
|
171
|
+
id: lastEventId,
|
|
172
|
+
retry: retryDelay
|
|
173
|
+
});
|
|
174
|
+
if (dataLines.length) {
|
|
175
|
+
yield data;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
} finally {
|
|
180
|
+
signal.removeEventListener("abort", abortHandler);
|
|
181
|
+
reader.releaseLock();
|
|
182
|
+
}
|
|
183
|
+
break;
|
|
184
|
+
} catch (error) {
|
|
185
|
+
onSseError?.(error);
|
|
186
|
+
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
const backoff = Math.min(
|
|
190
|
+
retryDelay * 2 ** (attempt - 1),
|
|
191
|
+
sseMaxRetryDelay ?? 3e4
|
|
192
|
+
);
|
|
193
|
+
await sleep(backoff);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
const stream = createStream();
|
|
198
|
+
return { stream };
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// src/_internal/core/pathSerializer.gen.ts
|
|
202
|
+
var separatorArrayExplode = (style) => {
|
|
203
|
+
switch (style) {
|
|
204
|
+
case "label":
|
|
205
|
+
return ".";
|
|
206
|
+
case "matrix":
|
|
207
|
+
return ";";
|
|
208
|
+
case "simple":
|
|
209
|
+
return ",";
|
|
210
|
+
default:
|
|
211
|
+
return "&";
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
var separatorArrayNoExplode = (style) => {
|
|
215
|
+
switch (style) {
|
|
216
|
+
case "form":
|
|
217
|
+
return ",";
|
|
218
|
+
case "pipeDelimited":
|
|
219
|
+
return "|";
|
|
220
|
+
case "spaceDelimited":
|
|
221
|
+
return "%20";
|
|
222
|
+
default:
|
|
223
|
+
return ",";
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
var separatorObjectExplode = (style) => {
|
|
227
|
+
switch (style) {
|
|
228
|
+
case "label":
|
|
229
|
+
return ".";
|
|
230
|
+
case "matrix":
|
|
231
|
+
return ";";
|
|
232
|
+
case "simple":
|
|
233
|
+
return ",";
|
|
234
|
+
default:
|
|
235
|
+
return "&";
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
var serializeArrayParam = ({
|
|
239
|
+
allowReserved,
|
|
240
|
+
explode,
|
|
241
|
+
name,
|
|
242
|
+
style,
|
|
243
|
+
value
|
|
244
|
+
}) => {
|
|
245
|
+
if (!explode) {
|
|
246
|
+
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
247
|
+
switch (style) {
|
|
248
|
+
case "label":
|
|
249
|
+
return `.${joinedValues2}`;
|
|
250
|
+
case "matrix":
|
|
251
|
+
return `;${name}=${joinedValues2}`;
|
|
252
|
+
case "simple":
|
|
253
|
+
return joinedValues2;
|
|
254
|
+
default:
|
|
255
|
+
return `${name}=${joinedValues2}`;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const separator = separatorArrayExplode(style);
|
|
259
|
+
const joinedValues = value.map((v) => {
|
|
260
|
+
if (style === "label" || style === "simple") {
|
|
261
|
+
return allowReserved ? v : encodeURIComponent(v);
|
|
262
|
+
}
|
|
263
|
+
return serializePrimitiveParam({
|
|
264
|
+
allowReserved,
|
|
265
|
+
name,
|
|
266
|
+
value: v
|
|
267
|
+
});
|
|
268
|
+
}).join(separator);
|
|
269
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
270
|
+
};
|
|
271
|
+
var serializePrimitiveParam = ({
|
|
272
|
+
allowReserved,
|
|
273
|
+
name,
|
|
274
|
+
value
|
|
275
|
+
}) => {
|
|
276
|
+
if (value === void 0 || value === null) {
|
|
277
|
+
return "";
|
|
278
|
+
}
|
|
279
|
+
if (typeof value === "object") {
|
|
280
|
+
throw new Error(
|
|
281
|
+
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
285
|
+
};
|
|
286
|
+
var serializeObjectParam = ({
|
|
287
|
+
allowReserved,
|
|
288
|
+
explode,
|
|
289
|
+
name,
|
|
290
|
+
style,
|
|
291
|
+
value,
|
|
292
|
+
valueOnly
|
|
293
|
+
}) => {
|
|
294
|
+
if (value instanceof Date) {
|
|
295
|
+
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
296
|
+
}
|
|
297
|
+
if (style !== "deepObject" && !explode) {
|
|
298
|
+
let values = [];
|
|
299
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
300
|
+
values = [
|
|
301
|
+
...values,
|
|
302
|
+
key,
|
|
303
|
+
allowReserved ? v : encodeURIComponent(v)
|
|
304
|
+
];
|
|
305
|
+
});
|
|
306
|
+
const joinedValues2 = values.join(",");
|
|
307
|
+
switch (style) {
|
|
308
|
+
case "form":
|
|
309
|
+
return `${name}=${joinedValues2}`;
|
|
310
|
+
case "label":
|
|
311
|
+
return `.${joinedValues2}`;
|
|
312
|
+
case "matrix":
|
|
313
|
+
return `;${name}=${joinedValues2}`;
|
|
314
|
+
default:
|
|
315
|
+
return joinedValues2;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const separator = separatorObjectExplode(style);
|
|
319
|
+
const joinedValues = Object.entries(value).map(
|
|
320
|
+
([key, v]) => serializePrimitiveParam({
|
|
321
|
+
allowReserved,
|
|
322
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
323
|
+
value: v
|
|
324
|
+
})
|
|
325
|
+
).join(separator);
|
|
326
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
// src/_internal/core/utils.gen.ts
|
|
330
|
+
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
331
|
+
var defaultPathSerializer = ({ path, url: _url }) => {
|
|
332
|
+
let url = _url;
|
|
333
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
334
|
+
if (matches) {
|
|
335
|
+
for (const match of matches) {
|
|
336
|
+
let explode = false;
|
|
337
|
+
let name = match.substring(1, match.length - 1);
|
|
338
|
+
let style = "simple";
|
|
339
|
+
if (name.endsWith("*")) {
|
|
340
|
+
explode = true;
|
|
341
|
+
name = name.substring(0, name.length - 1);
|
|
342
|
+
}
|
|
343
|
+
if (name.startsWith(".")) {
|
|
344
|
+
name = name.substring(1);
|
|
345
|
+
style = "label";
|
|
346
|
+
} else if (name.startsWith(";")) {
|
|
347
|
+
name = name.substring(1);
|
|
348
|
+
style = "matrix";
|
|
349
|
+
}
|
|
350
|
+
const value = path[name];
|
|
351
|
+
if (value === void 0 || value === null) {
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (Array.isArray(value)) {
|
|
355
|
+
url = url.replace(
|
|
356
|
+
match,
|
|
357
|
+
serializeArrayParam({ explode, name, style, value })
|
|
358
|
+
);
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
if (typeof value === "object") {
|
|
362
|
+
url = url.replace(
|
|
363
|
+
match,
|
|
364
|
+
serializeObjectParam({
|
|
365
|
+
explode,
|
|
366
|
+
name,
|
|
367
|
+
style,
|
|
368
|
+
value,
|
|
369
|
+
valueOnly: true
|
|
370
|
+
})
|
|
371
|
+
);
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
if (style === "matrix") {
|
|
375
|
+
url = url.replace(
|
|
376
|
+
match,
|
|
377
|
+
`;${serializePrimitiveParam({
|
|
378
|
+
name,
|
|
379
|
+
value
|
|
380
|
+
})}`
|
|
381
|
+
);
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
const replaceValue = encodeURIComponent(
|
|
385
|
+
style === "label" ? `.${value}` : value
|
|
386
|
+
);
|
|
387
|
+
url = url.replace(match, replaceValue);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return url;
|
|
391
|
+
};
|
|
392
|
+
var getUrl = ({
|
|
393
|
+
baseUrl,
|
|
394
|
+
path,
|
|
395
|
+
query,
|
|
396
|
+
querySerializer,
|
|
397
|
+
url: _url
|
|
398
|
+
}) => {
|
|
399
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
400
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
401
|
+
if (path) {
|
|
402
|
+
url = defaultPathSerializer({ path, url });
|
|
403
|
+
}
|
|
404
|
+
let search = query ? querySerializer(query) : "";
|
|
405
|
+
if (search.startsWith("?")) {
|
|
406
|
+
search = search.substring(1);
|
|
407
|
+
}
|
|
408
|
+
if (search) {
|
|
409
|
+
url += `?${search}`;
|
|
410
|
+
}
|
|
411
|
+
return url;
|
|
412
|
+
};
|
|
413
|
+
function getValidRequestBody(options) {
|
|
414
|
+
const hasBody = options.body !== void 0;
|
|
415
|
+
const isSerializedBody = hasBody && options.bodySerializer;
|
|
416
|
+
if (isSerializedBody) {
|
|
417
|
+
if ("serializedBody" in options) {
|
|
418
|
+
const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
|
|
419
|
+
return hasSerializedBody ? options.serializedBody : null;
|
|
420
|
+
}
|
|
421
|
+
return options.body !== "" ? options.body : null;
|
|
422
|
+
}
|
|
423
|
+
if (hasBody) {
|
|
424
|
+
return options.body;
|
|
425
|
+
}
|
|
426
|
+
return void 0;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// src/_internal/core/auth.gen.ts
|
|
430
|
+
var getAuthToken = async (auth, callback) => {
|
|
431
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
432
|
+
if (!token) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
if (auth.scheme === "bearer") {
|
|
436
|
+
return `Bearer ${token}`;
|
|
437
|
+
}
|
|
438
|
+
if (auth.scheme === "basic") {
|
|
439
|
+
return `Basic ${btoa(token)}`;
|
|
440
|
+
}
|
|
441
|
+
return token;
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
// src/_internal/client/utils.gen.ts
|
|
445
|
+
var createQuerySerializer = ({
|
|
446
|
+
parameters = {},
|
|
447
|
+
...args
|
|
448
|
+
} = {}) => {
|
|
449
|
+
const querySerializer = (queryParams) => {
|
|
450
|
+
const search = [];
|
|
451
|
+
if (queryParams && typeof queryParams === "object") {
|
|
452
|
+
for (const name in queryParams) {
|
|
453
|
+
const value = queryParams[name];
|
|
454
|
+
if (value === void 0 || value === null) {
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
const options = parameters[name] || args;
|
|
458
|
+
if (Array.isArray(value)) {
|
|
459
|
+
const serializedArray = serializeArrayParam({
|
|
460
|
+
allowReserved: options.allowReserved,
|
|
461
|
+
explode: true,
|
|
462
|
+
name,
|
|
463
|
+
style: "form",
|
|
464
|
+
value,
|
|
465
|
+
...options.array
|
|
466
|
+
});
|
|
467
|
+
if (serializedArray) search.push(serializedArray);
|
|
468
|
+
} else if (typeof value === "object") {
|
|
469
|
+
const serializedObject = serializeObjectParam({
|
|
470
|
+
allowReserved: options.allowReserved,
|
|
471
|
+
explode: true,
|
|
472
|
+
name,
|
|
473
|
+
style: "deepObject",
|
|
474
|
+
value,
|
|
475
|
+
...options.object
|
|
476
|
+
});
|
|
477
|
+
if (serializedObject) search.push(serializedObject);
|
|
478
|
+
} else {
|
|
479
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
480
|
+
allowReserved: options.allowReserved,
|
|
481
|
+
name,
|
|
482
|
+
value
|
|
483
|
+
});
|
|
484
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
return search.join("&");
|
|
489
|
+
};
|
|
490
|
+
return querySerializer;
|
|
491
|
+
};
|
|
492
|
+
var getParseAs = (contentType) => {
|
|
493
|
+
if (!contentType) {
|
|
494
|
+
return "stream";
|
|
495
|
+
}
|
|
496
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
497
|
+
if (!cleanContent) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
501
|
+
return "json";
|
|
502
|
+
}
|
|
503
|
+
if (cleanContent === "multipart/form-data") {
|
|
504
|
+
return "formData";
|
|
505
|
+
}
|
|
506
|
+
if (["application/", "audio/", "image/", "video/"].some(
|
|
507
|
+
(type) => cleanContent.startsWith(type)
|
|
508
|
+
)) {
|
|
509
|
+
return "blob";
|
|
510
|
+
}
|
|
511
|
+
if (cleanContent.startsWith("text/")) {
|
|
512
|
+
return "text";
|
|
513
|
+
}
|
|
514
|
+
return;
|
|
515
|
+
};
|
|
516
|
+
var checkForExistence = (options, name) => {
|
|
517
|
+
if (!name) {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
return false;
|
|
524
|
+
};
|
|
525
|
+
var setAuthParams = async ({
|
|
526
|
+
security,
|
|
527
|
+
...options
|
|
528
|
+
}) => {
|
|
529
|
+
for (const auth of security) {
|
|
530
|
+
if (checkForExistence(options, auth.name)) {
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
const token = await getAuthToken(auth, options.auth);
|
|
534
|
+
if (!token) {
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
const name = auth.name ?? "Authorization";
|
|
538
|
+
switch (auth.in) {
|
|
539
|
+
case "query":
|
|
540
|
+
if (!options.query) {
|
|
541
|
+
options.query = {};
|
|
542
|
+
}
|
|
543
|
+
options.query[name] = token;
|
|
544
|
+
break;
|
|
545
|
+
case "cookie":
|
|
546
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
547
|
+
break;
|
|
548
|
+
case "header":
|
|
549
|
+
default:
|
|
550
|
+
options.headers.set(name, token);
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
var buildUrl = (options) => getUrl({
|
|
556
|
+
baseUrl: options.baseUrl,
|
|
557
|
+
path: options.path,
|
|
558
|
+
query: options.query,
|
|
559
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
560
|
+
url: options.url
|
|
561
|
+
});
|
|
562
|
+
var mergeConfigs = (a, b) => {
|
|
563
|
+
const config = { ...a, ...b };
|
|
564
|
+
if (config.baseUrl?.endsWith("/")) {
|
|
565
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
566
|
+
}
|
|
567
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
568
|
+
return config;
|
|
569
|
+
};
|
|
570
|
+
var headersEntries = (headers) => {
|
|
571
|
+
const entries = [];
|
|
572
|
+
headers.forEach((value, key) => {
|
|
573
|
+
entries.push([key, value]);
|
|
574
|
+
});
|
|
575
|
+
return entries;
|
|
576
|
+
};
|
|
577
|
+
var mergeHeaders = (...headers) => {
|
|
578
|
+
const mergedHeaders = new Headers();
|
|
579
|
+
for (const header of headers) {
|
|
580
|
+
if (!header) {
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
583
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
584
|
+
for (const [key, value] of iterator) {
|
|
585
|
+
if (value === null) {
|
|
586
|
+
mergedHeaders.delete(key);
|
|
587
|
+
} else if (Array.isArray(value)) {
|
|
588
|
+
for (const v of value) {
|
|
589
|
+
mergedHeaders.append(key, v);
|
|
590
|
+
}
|
|
591
|
+
} else if (value !== void 0) {
|
|
592
|
+
mergedHeaders.set(
|
|
593
|
+
key,
|
|
594
|
+
typeof value === "object" ? JSON.stringify(value) : value
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return mergedHeaders;
|
|
600
|
+
};
|
|
601
|
+
var Interceptors = class {
|
|
602
|
+
constructor() {
|
|
603
|
+
this.fns = [];
|
|
604
|
+
}
|
|
605
|
+
clear() {
|
|
606
|
+
this.fns = [];
|
|
607
|
+
}
|
|
608
|
+
eject(id) {
|
|
609
|
+
const index = this.getInterceptorIndex(id);
|
|
610
|
+
if (this.fns[index]) {
|
|
611
|
+
this.fns[index] = null;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
exists(id) {
|
|
615
|
+
const index = this.getInterceptorIndex(id);
|
|
616
|
+
return Boolean(this.fns[index]);
|
|
617
|
+
}
|
|
618
|
+
getInterceptorIndex(id) {
|
|
619
|
+
if (typeof id === "number") {
|
|
620
|
+
return this.fns[id] ? id : -1;
|
|
621
|
+
}
|
|
622
|
+
return this.fns.indexOf(id);
|
|
623
|
+
}
|
|
624
|
+
update(id, fn) {
|
|
625
|
+
const index = this.getInterceptorIndex(id);
|
|
626
|
+
if (this.fns[index]) {
|
|
627
|
+
this.fns[index] = fn;
|
|
628
|
+
return id;
|
|
629
|
+
}
|
|
630
|
+
return false;
|
|
631
|
+
}
|
|
632
|
+
use(fn) {
|
|
633
|
+
this.fns.push(fn);
|
|
634
|
+
return this.fns.length - 1;
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
var createInterceptors = () => ({
|
|
638
|
+
error: new Interceptors(),
|
|
639
|
+
request: new Interceptors(),
|
|
640
|
+
response: new Interceptors()
|
|
641
|
+
});
|
|
642
|
+
var defaultQuerySerializer = createQuerySerializer({
|
|
643
|
+
allowReserved: false,
|
|
644
|
+
array: {
|
|
645
|
+
explode: true,
|
|
646
|
+
style: "form"
|
|
647
|
+
},
|
|
648
|
+
object: {
|
|
649
|
+
explode: true,
|
|
650
|
+
style: "deepObject"
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
var defaultHeaders = {
|
|
654
|
+
"Content-Type": "application/json"
|
|
655
|
+
};
|
|
656
|
+
var createConfig = (override = {}) => ({
|
|
657
|
+
...jsonBodySerializer,
|
|
658
|
+
headers: defaultHeaders,
|
|
659
|
+
parseAs: "auto",
|
|
660
|
+
querySerializer: defaultQuerySerializer,
|
|
661
|
+
...override
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
// src/_internal/client/client.gen.ts
|
|
665
|
+
var createClient = (config = {}) => {
|
|
666
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
667
|
+
const getConfig = () => ({ ..._config });
|
|
668
|
+
const setConfig = (config2) => {
|
|
669
|
+
_config = mergeConfigs(_config, config2);
|
|
670
|
+
return getConfig();
|
|
671
|
+
};
|
|
672
|
+
const interceptors = createInterceptors();
|
|
673
|
+
const beforeRequest = async (options) => {
|
|
674
|
+
const opts = {
|
|
675
|
+
..._config,
|
|
676
|
+
...options,
|
|
677
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
678
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
679
|
+
serializedBody: void 0
|
|
680
|
+
};
|
|
681
|
+
if (opts.security) {
|
|
682
|
+
await setAuthParams({
|
|
683
|
+
...opts,
|
|
684
|
+
security: opts.security
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
if (opts.requestValidator) {
|
|
688
|
+
await opts.requestValidator(opts);
|
|
689
|
+
}
|
|
690
|
+
if (opts.body !== void 0 && opts.bodySerializer) {
|
|
691
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
692
|
+
}
|
|
693
|
+
if (opts.body === void 0 || opts.serializedBody === "") {
|
|
694
|
+
opts.headers.delete("Content-Type");
|
|
695
|
+
}
|
|
696
|
+
const url = buildUrl(opts);
|
|
697
|
+
return { opts, url };
|
|
698
|
+
};
|
|
699
|
+
const request = async (options) => {
|
|
700
|
+
const { opts, url } = await beforeRequest(options);
|
|
701
|
+
const requestInit = {
|
|
702
|
+
redirect: "follow",
|
|
703
|
+
...opts,
|
|
704
|
+
body: getValidRequestBody(opts)
|
|
705
|
+
};
|
|
706
|
+
let request2 = new Request(url, requestInit);
|
|
707
|
+
for (const fn of interceptors.request.fns) {
|
|
708
|
+
if (fn) {
|
|
709
|
+
request2 = await fn(request2, opts);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
const _fetch = opts.fetch;
|
|
713
|
+
let response;
|
|
714
|
+
try {
|
|
715
|
+
response = await _fetch(request2);
|
|
716
|
+
} catch (error2) {
|
|
717
|
+
let finalError2 = error2;
|
|
718
|
+
for (const fn of interceptors.error.fns) {
|
|
719
|
+
if (fn) {
|
|
720
|
+
finalError2 = await fn(
|
|
721
|
+
error2,
|
|
722
|
+
void 0,
|
|
723
|
+
request2,
|
|
724
|
+
opts
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
finalError2 = finalError2 || {};
|
|
729
|
+
if (opts.throwOnError) {
|
|
730
|
+
throw finalError2;
|
|
731
|
+
}
|
|
732
|
+
return opts.responseStyle === "data" ? void 0 : {
|
|
733
|
+
error: finalError2,
|
|
734
|
+
request: request2,
|
|
735
|
+
response: void 0
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
for (const fn of interceptors.response.fns) {
|
|
739
|
+
if (fn) {
|
|
740
|
+
response = await fn(response, request2, opts);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
const result = {
|
|
744
|
+
request: request2,
|
|
745
|
+
response
|
|
746
|
+
};
|
|
747
|
+
if (response.ok) {
|
|
748
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
749
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
750
|
+
let emptyData;
|
|
751
|
+
switch (parseAs) {
|
|
752
|
+
case "arrayBuffer":
|
|
753
|
+
case "blob":
|
|
754
|
+
case "text":
|
|
755
|
+
emptyData = await response[parseAs]();
|
|
756
|
+
break;
|
|
757
|
+
case "formData":
|
|
758
|
+
emptyData = new FormData();
|
|
759
|
+
break;
|
|
760
|
+
case "stream":
|
|
761
|
+
emptyData = response.body;
|
|
762
|
+
break;
|
|
763
|
+
case "json":
|
|
764
|
+
default:
|
|
765
|
+
emptyData = {};
|
|
766
|
+
break;
|
|
767
|
+
}
|
|
768
|
+
return opts.responseStyle === "data" ? emptyData : {
|
|
769
|
+
data: emptyData,
|
|
770
|
+
...result
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
let data;
|
|
774
|
+
switch (parseAs) {
|
|
775
|
+
case "arrayBuffer":
|
|
776
|
+
case "blob":
|
|
777
|
+
case "formData":
|
|
778
|
+
case "json":
|
|
779
|
+
case "text":
|
|
780
|
+
data = await response[parseAs]();
|
|
781
|
+
break;
|
|
782
|
+
case "stream":
|
|
783
|
+
return opts.responseStyle === "data" ? response.body : {
|
|
784
|
+
data: response.body,
|
|
785
|
+
...result
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
if (parseAs === "json") {
|
|
789
|
+
if (opts.responseValidator) {
|
|
790
|
+
await opts.responseValidator(data);
|
|
791
|
+
}
|
|
792
|
+
if (opts.responseTransformer) {
|
|
793
|
+
data = await opts.responseTransformer(data);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
return opts.responseStyle === "data" ? data : {
|
|
797
|
+
data,
|
|
798
|
+
...result
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
const textError = await response.text();
|
|
802
|
+
let jsonError;
|
|
803
|
+
try {
|
|
804
|
+
jsonError = JSON.parse(textError);
|
|
805
|
+
} catch {
|
|
806
|
+
}
|
|
807
|
+
const error = jsonError ?? textError;
|
|
808
|
+
let finalError = error;
|
|
809
|
+
for (const fn of interceptors.error.fns) {
|
|
810
|
+
if (fn) {
|
|
811
|
+
finalError = await fn(error, response, request2, opts);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
finalError = finalError || {};
|
|
815
|
+
if (opts.throwOnError) {
|
|
816
|
+
throw finalError;
|
|
817
|
+
}
|
|
818
|
+
return opts.responseStyle === "data" ? void 0 : {
|
|
819
|
+
error: finalError,
|
|
820
|
+
...result
|
|
821
|
+
};
|
|
822
|
+
};
|
|
823
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
824
|
+
const makeSseFn = (method) => async (options) => {
|
|
825
|
+
const { opts, url } = await beforeRequest(options);
|
|
826
|
+
return createSseClient({
|
|
827
|
+
...opts,
|
|
828
|
+
body: opts.body,
|
|
829
|
+
headers: opts.headers,
|
|
830
|
+
method,
|
|
831
|
+
onRequest: async (url2, init) => {
|
|
832
|
+
let request2 = new Request(url2, init);
|
|
833
|
+
for (const fn of interceptors.request.fns) {
|
|
834
|
+
if (fn) {
|
|
835
|
+
request2 = await fn(request2, opts);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
return request2;
|
|
839
|
+
},
|
|
840
|
+
url
|
|
841
|
+
});
|
|
842
|
+
};
|
|
843
|
+
return {
|
|
844
|
+
buildUrl,
|
|
845
|
+
connect: makeMethodFn("CONNECT"),
|
|
846
|
+
delete: makeMethodFn("DELETE"),
|
|
847
|
+
get: makeMethodFn("GET"),
|
|
848
|
+
getConfig,
|
|
849
|
+
head: makeMethodFn("HEAD"),
|
|
850
|
+
interceptors,
|
|
851
|
+
options: makeMethodFn("OPTIONS"),
|
|
852
|
+
patch: makeMethodFn("PATCH"),
|
|
853
|
+
post: makeMethodFn("POST"),
|
|
854
|
+
put: makeMethodFn("PUT"),
|
|
855
|
+
request,
|
|
856
|
+
setConfig,
|
|
857
|
+
sse: {
|
|
858
|
+
connect: makeSseFn("CONNECT"),
|
|
859
|
+
delete: makeSseFn("DELETE"),
|
|
860
|
+
get: makeSseFn("GET"),
|
|
861
|
+
head: makeSseFn("HEAD"),
|
|
862
|
+
options: makeSseFn("OPTIONS"),
|
|
863
|
+
patch: makeSseFn("PATCH"),
|
|
864
|
+
post: makeSseFn("POST"),
|
|
865
|
+
put: makeSseFn("PUT"),
|
|
866
|
+
trace: makeSseFn("TRACE")
|
|
867
|
+
},
|
|
868
|
+
trace: makeMethodFn("TRACE")
|
|
869
|
+
};
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
// src/_internal/client.gen.ts
|
|
873
|
+
var client = createClient(
|
|
874
|
+
createConfig({ baseUrl: "http://localhost:22222" })
|
|
875
|
+
);
|
|
876
|
+
|
|
877
|
+
// src/base-client.ts
|
|
878
|
+
var BaseClient = class {
|
|
879
|
+
constructor(config = {}) {
|
|
880
|
+
this.config = config;
|
|
881
|
+
if (config.baseUrl) {
|
|
882
|
+
client.setConfig({ baseUrl: config.baseUrl });
|
|
883
|
+
}
|
|
884
|
+
client.interceptors.request.use((req) => {
|
|
885
|
+
req.headers.set("Accept", "application/vnd.api+json");
|
|
886
|
+
req.headers.set("Content-Type", "application/vnd.api+json");
|
|
887
|
+
if (config.apiKey) {
|
|
888
|
+
req.headers.set("x-application-key", config.apiKey);
|
|
889
|
+
}
|
|
890
|
+
if (config.applicationId) {
|
|
891
|
+
req.headers.set("x-application-id", config.applicationId);
|
|
892
|
+
}
|
|
893
|
+
if (config.token) {
|
|
894
|
+
req.headers.set("Authorization", `Bearer ${config.token}`);
|
|
895
|
+
}
|
|
896
|
+
return req;
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
unwrap(resource) {
|
|
900
|
+
if (!resource) return null;
|
|
901
|
+
const obj = resource;
|
|
902
|
+
if (obj.data && !obj.id && !obj.type) {
|
|
903
|
+
return obj.data;
|
|
904
|
+
}
|
|
905
|
+
return resource;
|
|
906
|
+
}
|
|
907
|
+
getHeaders() {
|
|
908
|
+
return {
|
|
909
|
+
"x-application-key": this.config.apiKey || ""
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
|
|
914
|
+
// src/_internal/sdk.gen.ts
|
|
915
|
+
var patchAdminAccountsByIdCredit = (options) => (options.client ?? client).patch({
|
|
916
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
917
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
918
|
+
url: "/admin/accounts/{id}/credit",
|
|
919
|
+
...options,
|
|
920
|
+
headers: {
|
|
921
|
+
"Content-Type": "application/vnd.api+json",
|
|
922
|
+
...options.headers
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
var patchAdminApiKeysByIdRotate = (options) => (options.client ?? client).patch({
|
|
926
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
927
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
928
|
+
url: "/admin/api_keys/{id}/rotate",
|
|
929
|
+
...options,
|
|
930
|
+
headers: {
|
|
931
|
+
"Content-Type": "application/vnd.api+json",
|
|
932
|
+
...options.headers
|
|
933
|
+
}
|
|
934
|
+
});
|
|
935
|
+
var getAdminWebhookConfigs = (options) => (options.client ?? client).get({
|
|
936
|
+
querySerializer: {
|
|
937
|
+
parameters: {
|
|
938
|
+
filter: { object: { style: "form" } },
|
|
939
|
+
page: { object: { style: "form" } },
|
|
940
|
+
fields: { object: { style: "form" } }
|
|
941
|
+
}
|
|
942
|
+
},
|
|
943
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
944
|
+
url: "/admin/webhook_configs",
|
|
945
|
+
...options
|
|
946
|
+
});
|
|
947
|
+
var postAdminWebhookConfigs = (options) => (options.client ?? client).post({
|
|
948
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
949
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
950
|
+
url: "/admin/webhook_configs",
|
|
951
|
+
...options,
|
|
952
|
+
headers: {
|
|
953
|
+
"Content-Type": "application/vnd.api+json",
|
|
954
|
+
...options.headers
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
var deleteAdminWebhookConfigsById = (options) => (options.client ?? client).delete({
|
|
958
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
959
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
960
|
+
url: "/admin/webhook_configs/{id}",
|
|
961
|
+
...options
|
|
962
|
+
});
|
|
963
|
+
var getAdminWebhookConfigsById = (options) => (options.client ?? client).get({
|
|
964
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
965
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
966
|
+
url: "/admin/webhook_configs/{id}",
|
|
967
|
+
...options
|
|
968
|
+
});
|
|
969
|
+
var patchAdminWebhookConfigsById = (options) => (options.client ?? client).patch({
|
|
970
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
971
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
972
|
+
url: "/admin/webhook_configs/{id}",
|
|
973
|
+
...options,
|
|
974
|
+
headers: {
|
|
975
|
+
"Content-Type": "application/vnd.api+json",
|
|
976
|
+
...options.headers
|
|
977
|
+
}
|
|
978
|
+
});
|
|
979
|
+
var postAdminWebhookConfigsByIdTest = (options) => (options.client ?? client).post({
|
|
980
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
981
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
982
|
+
url: "/admin/webhook_configs/{id}/test",
|
|
983
|
+
...options,
|
|
984
|
+
headers: {
|
|
985
|
+
"Content-Type": "application/vnd.api+json",
|
|
986
|
+
...options.headers
|
|
987
|
+
}
|
|
988
|
+
});
|
|
989
|
+
var patchAdminAccountsByIdDebit = (options) => (options.client ?? client).patch({
|
|
990
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
991
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
992
|
+
url: "/admin/accounts/{id}/debit",
|
|
993
|
+
...options,
|
|
994
|
+
headers: {
|
|
995
|
+
"Content-Type": "application/vnd.api+json",
|
|
996
|
+
...options.headers
|
|
997
|
+
}
|
|
998
|
+
});
|
|
999
|
+
var getAdminExtractionDocumentsById = (options) => (options.client ?? client).get({
|
|
1000
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
1001
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1002
|
+
url: "/admin/extraction/documents/{id}",
|
|
1003
|
+
...options
|
|
1004
|
+
});
|
|
1005
|
+
var getAdminAccounts = (options) => (options.client ?? client).get({
|
|
1006
|
+
querySerializer: {
|
|
1007
|
+
parameters: {
|
|
1008
|
+
filter: { object: { style: "form" } },
|
|
1009
|
+
page: { object: { style: "form" } },
|
|
1010
|
+
fields: { object: { style: "form" } }
|
|
1011
|
+
}
|
|
1012
|
+
},
|
|
1013
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1014
|
+
url: "/admin/accounts",
|
|
1015
|
+
...options
|
|
1016
|
+
});
|
|
1017
|
+
var getAdminStorageStats = (options) => (options.client ?? client).get({
|
|
1018
|
+
querySerializer: {
|
|
1019
|
+
parameters: {
|
|
1020
|
+
filter: { object: { style: "form" } },
|
|
1021
|
+
fields: { object: { style: "form" } }
|
|
1022
|
+
}
|
|
1023
|
+
},
|
|
1024
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1025
|
+
url: "/admin/storage/stats",
|
|
1026
|
+
...options
|
|
1027
|
+
});
|
|
1028
|
+
var getAdminAccountsById = (options) => (options.client ?? client).get({
|
|
1029
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
1030
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1031
|
+
url: "/admin/accounts/{id}",
|
|
1032
|
+
...options
|
|
1033
|
+
});
|
|
1034
|
+
var postAdminDocumentsBulkDelete = (options) => (options.client ?? client).post({
|
|
1035
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
1036
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1037
|
+
url: "/admin/documents/bulk_delete",
|
|
1038
|
+
...options,
|
|
1039
|
+
headers: {
|
|
1040
|
+
"Content-Type": "application/vnd.api+json",
|
|
1041
|
+
...options.headers
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
var patchAdminApiKeysByIdAllocate = (options) => (options.client ?? client).patch({
|
|
1045
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
1046
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1047
|
+
url: "/admin/api_keys/{id}/allocate",
|
|
1048
|
+
...options,
|
|
1049
|
+
headers: {
|
|
1050
|
+
"Content-Type": "application/vnd.api+json",
|
|
1051
|
+
...options.headers
|
|
1052
|
+
}
|
|
1053
|
+
});
|
|
1054
|
+
var getAdminBucketsByIdStats = (options) => (options.client ?? client).get({
|
|
1055
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
1056
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1057
|
+
url: "/admin/buckets/{id}/stats",
|
|
1058
|
+
...options
|
|
1059
|
+
});
|
|
1060
|
+
var patchAdminApiKeysByIdRevoke = (options) => (options.client ?? client).patch({
|
|
1061
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
1062
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1063
|
+
url: "/admin/api_keys/{id}/revoke",
|
|
1064
|
+
...options,
|
|
1065
|
+
headers: {
|
|
1066
|
+
"Content-Type": "application/vnd.api+json",
|
|
1067
|
+
...options.headers
|
|
1068
|
+
}
|
|
1069
|
+
});
|
|
1070
|
+
var getAdminWebhookDeliveriesById = (options) => (options.client ?? client).get({
|
|
1071
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
1072
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1073
|
+
url: "/admin/webhook_deliveries/{id}",
|
|
1074
|
+
...options
|
|
1075
|
+
});
|
|
1076
|
+
var getAdminDocumentsStats = (options) => (options.client ?? client).get({
|
|
1077
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
1078
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1079
|
+
url: "/admin/documents/stats",
|
|
1080
|
+
...options
|
|
1081
|
+
});
|
|
1082
|
+
var getAdminExtractionDocuments = (options) => (options.client ?? client).get({
|
|
1083
|
+
querySerializer: {
|
|
1084
|
+
parameters: {
|
|
1085
|
+
filter: { object: { style: "form" } },
|
|
1086
|
+
fields: { object: { style: "form" } }
|
|
1087
|
+
}
|
|
1088
|
+
},
|
|
1089
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1090
|
+
url: "/admin/extraction/documents",
|
|
1091
|
+
...options
|
|
1092
|
+
});
|
|
1093
|
+
var getAdminBucketsByIdObjects = (options) => (options.client ?? client).get({
|
|
1094
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
1095
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1096
|
+
url: "/admin/buckets/{id}/objects",
|
|
1097
|
+
...options
|
|
1098
|
+
});
|
|
1099
|
+
var getAdminApiKeys = (options) => (options.client ?? client).get({
|
|
1100
|
+
querySerializer: {
|
|
1101
|
+
parameters: {
|
|
1102
|
+
filter: { object: { style: "form" } },
|
|
1103
|
+
page: { object: { style: "form" } },
|
|
1104
|
+
fields: { object: { style: "form" } }
|
|
1105
|
+
}
|
|
1106
|
+
},
|
|
1107
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1108
|
+
url: "/admin/api_keys",
|
|
1109
|
+
...options
|
|
1110
|
+
});
|
|
1111
|
+
var getAdminApiKeysById = (options) => (options.client ?? client).get({
|
|
1112
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
1113
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1114
|
+
url: "/admin/api_keys/{id}",
|
|
1115
|
+
...options
|
|
1116
|
+
});
|
|
1117
|
+
var getAdminBuckets = (options) => (options.client ?? client).get({
|
|
1118
|
+
querySerializer: {
|
|
1119
|
+
parameters: {
|
|
1120
|
+
filter: { object: { style: "form" } },
|
|
1121
|
+
page: { object: { style: "form" } },
|
|
1122
|
+
fields: { object: { style: "form" } }
|
|
1123
|
+
}
|
|
1124
|
+
},
|
|
1125
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1126
|
+
url: "/admin/buckets",
|
|
1127
|
+
...options
|
|
1128
|
+
});
|
|
1129
|
+
var getAdminBucketsById = (options) => (options.client ?? client).get({
|
|
1130
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
1131
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1132
|
+
url: "/admin/buckets/{id}",
|
|
1133
|
+
...options
|
|
1134
|
+
});
|
|
1135
|
+
var postAdminWebhookDeliveriesByIdRetry = (options) => (options.client ?? client).post({
|
|
1136
|
+
querySerializer: { parameters: { fields: { object: { style: "form" } } } },
|
|
1137
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1138
|
+
url: "/admin/webhook_deliveries/{id}/retry",
|
|
1139
|
+
...options,
|
|
1140
|
+
headers: {
|
|
1141
|
+
"Content-Type": "application/vnd.api+json",
|
|
1142
|
+
...options.headers
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
var getAdminWebhookDeliveries = (options) => (options.client ?? client).get({
|
|
1146
|
+
querySerializer: {
|
|
1147
|
+
parameters: {
|
|
1148
|
+
filter: { object: { style: "form" } },
|
|
1149
|
+
page: { object: { style: "form" } },
|
|
1150
|
+
fields: { object: { style: "form" } }
|
|
1151
|
+
}
|
|
1152
|
+
},
|
|
1153
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1154
|
+
url: "/admin/webhook_deliveries",
|
|
1155
|
+
...options
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
// src/schemas/requests.ts
|
|
1159
|
+
var import_zod = require("zod");
|
|
1160
|
+
var StorageStatsRequestSchema = import_zod.z.object({
|
|
1161
|
+
workspace_id: import_zod.z.string().optional()
|
|
1162
|
+
});
|
|
1163
|
+
var WebhookConfigCreateSchema = import_zod.z.object({
|
|
1164
|
+
url: import_zod.z.string().url(),
|
|
1165
|
+
events: import_zod.z.array(import_zod.z.string()).min(1),
|
|
1166
|
+
secret: import_zod.z.string().optional(),
|
|
1167
|
+
enabled: import_zod.z.boolean().default(true)
|
|
1168
|
+
});
|
|
1169
|
+
var WebhookBulkEnableSchema = import_zod.z.object({
|
|
1170
|
+
config_ids: import_zod.z.array(import_zod.z.string()).min(1).max(100)
|
|
1171
|
+
});
|
|
1172
|
+
var WebhookBulkDisableSchema = import_zod.z.object({
|
|
1173
|
+
config_ids: import_zod.z.array(import_zod.z.string()).min(1).max(100)
|
|
1174
|
+
});
|
|
1175
|
+
var WebhookDeliveryBulkRetrySchema = import_zod.z.object({
|
|
1176
|
+
delivery_ids: import_zod.z.array(import_zod.z.string()).min(1).max(100)
|
|
1177
|
+
});
|
|
1178
|
+
var AgentAdminCreateSchema = import_zod.z.object({
|
|
1179
|
+
name: import_zod.z.string().min(1).max(255),
|
|
1180
|
+
prompt_template: import_zod.z.string().min(1),
|
|
1181
|
+
system_wide: import_zod.z.boolean().default(false)
|
|
1182
|
+
});
|
|
1183
|
+
var AccountCreditSchema = import_zod.z.object({
|
|
1184
|
+
amount: import_zod.z.number().positive(),
|
|
1185
|
+
description: import_zod.z.string().optional()
|
|
1186
|
+
});
|
|
1187
|
+
var AccountDebitSchema = import_zod.z.object({
|
|
1188
|
+
amount: import_zod.z.number().positive(),
|
|
1189
|
+
description: import_zod.z.string().optional()
|
|
1190
|
+
});
|
|
1191
|
+
var ApiKeyAllocateSchema = import_zod.z.object({
|
|
1192
|
+
rate_limit: import_zod.z.number().int().positive().optional(),
|
|
1193
|
+
expires_at: import_zod.z.string().datetime().optional()
|
|
1194
|
+
});
|
|
1195
|
+
var DocumentBulkDeleteSchema = import_zod.z.object({
|
|
1196
|
+
document_ids: import_zod.z.array(import_zod.z.string()).min(1).max(100)
|
|
1197
|
+
});
|
|
1198
|
+
var DocumentBulkReprocessSchema = import_zod.z.object({
|
|
1199
|
+
document_ids: import_zod.z.array(import_zod.z.string()).min(1).max(100)
|
|
1200
|
+
});
|
|
1201
|
+
|
|
1202
|
+
// src/gpt-admin.ts
|
|
1203
|
+
var GptAdmin = class extends BaseClient {
|
|
1204
|
+
constructor(config) {
|
|
1205
|
+
super(config);
|
|
1206
|
+
/**
|
|
1207
|
+
* Storage administration
|
|
1208
|
+
*/
|
|
1209
|
+
this.storage = {
|
|
1210
|
+
/**
|
|
1211
|
+
* Get storage statistics
|
|
1212
|
+
*/
|
|
1213
|
+
stats: async (workspaceId) => {
|
|
1214
|
+
const validated = StorageStatsRequestSchema.parse({ workspace_id: workspaceId });
|
|
1215
|
+
const { data } = await getAdminStorageStats({
|
|
1216
|
+
headers: this.getHeaders(),
|
|
1217
|
+
query: validated.workspace_id ? { filter: { workspace_id: validated.workspace_id } } : void 0
|
|
1218
|
+
});
|
|
1219
|
+
return this.unwrap(data?.data);
|
|
1220
|
+
},
|
|
1221
|
+
/**
|
|
1222
|
+
* Bucket management
|
|
1223
|
+
*/
|
|
1224
|
+
buckets: {
|
|
1225
|
+
list: async () => {
|
|
1226
|
+
const { data } = await getAdminBuckets({ headers: this.getHeaders() });
|
|
1227
|
+
return this.unwrap(data?.data);
|
|
1228
|
+
},
|
|
1229
|
+
get: async (id) => {
|
|
1230
|
+
const { data } = await getAdminBucketsById({
|
|
1231
|
+
headers: this.getHeaders(),
|
|
1232
|
+
path: { id }
|
|
1233
|
+
});
|
|
1234
|
+
return this.unwrap(data?.data);
|
|
1235
|
+
},
|
|
1236
|
+
stats: async (id) => {
|
|
1237
|
+
const { data } = await getAdminBucketsByIdStats({
|
|
1238
|
+
headers: this.getHeaders(),
|
|
1239
|
+
path: { id }
|
|
1240
|
+
});
|
|
1241
|
+
return this.unwrap(data?.data);
|
|
1242
|
+
},
|
|
1243
|
+
objects: async (id) => {
|
|
1244
|
+
const { data } = await getAdminBucketsByIdObjects({
|
|
1245
|
+
headers: this.getHeaders(),
|
|
1246
|
+
path: { id }
|
|
1247
|
+
});
|
|
1248
|
+
return this.unwrap(data?.data);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1252
|
+
/**
|
|
1253
|
+
* Account management
|
|
1254
|
+
*/
|
|
1255
|
+
this.accounts = {
|
|
1256
|
+
list: async () => {
|
|
1257
|
+
const { data } = await getAdminAccounts({ headers: this.getHeaders() });
|
|
1258
|
+
return this.unwrap(data?.data);
|
|
1259
|
+
},
|
|
1260
|
+
get: async (id) => {
|
|
1261
|
+
const { data } = await getAdminAccountsById({
|
|
1262
|
+
headers: this.getHeaders(),
|
|
1263
|
+
path: { id }
|
|
1264
|
+
});
|
|
1265
|
+
return this.unwrap(data?.data);
|
|
1266
|
+
},
|
|
1267
|
+
credit: async (id, amount, description) => {
|
|
1268
|
+
const validated = AccountCreditSchema.parse({ amount, description });
|
|
1269
|
+
const { data } = await patchAdminAccountsByIdCredit({
|
|
1270
|
+
headers: this.getHeaders(),
|
|
1271
|
+
path: { id },
|
|
1272
|
+
body: {
|
|
1273
|
+
data: {
|
|
1274
|
+
id,
|
|
1275
|
+
type: "account",
|
|
1276
|
+
attributes: validated
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
});
|
|
1280
|
+
return this.unwrap(data?.data);
|
|
1281
|
+
},
|
|
1282
|
+
debit: async (id, amount, description) => {
|
|
1283
|
+
const validated = AccountDebitSchema.parse({ amount, description });
|
|
1284
|
+
const { data } = await patchAdminAccountsByIdDebit({
|
|
1285
|
+
headers: this.getHeaders(),
|
|
1286
|
+
path: { id },
|
|
1287
|
+
body: {
|
|
1288
|
+
data: {
|
|
1289
|
+
id,
|
|
1290
|
+
type: "account",
|
|
1291
|
+
attributes: validated
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
});
|
|
1295
|
+
return this.unwrap(data?.data);
|
|
1296
|
+
}
|
|
1297
|
+
};
|
|
1298
|
+
/**
|
|
1299
|
+
* Webhook management
|
|
1300
|
+
*/
|
|
1301
|
+
this.webhooks = {
|
|
1302
|
+
configs: {
|
|
1303
|
+
list: async () => {
|
|
1304
|
+
const { data } = await getAdminWebhookConfigs({ headers: this.getHeaders() });
|
|
1305
|
+
return this.unwrap(data?.data);
|
|
1306
|
+
},
|
|
1307
|
+
create: async (name, url, events, applicationId, secret, enabled = true) => {
|
|
1308
|
+
const { data } = await postAdminWebhookConfigs({
|
|
1309
|
+
headers: this.getHeaders(),
|
|
1310
|
+
body: {
|
|
1311
|
+
data: {
|
|
1312
|
+
type: "webhook_config",
|
|
1313
|
+
attributes: {
|
|
1314
|
+
name,
|
|
1315
|
+
url,
|
|
1316
|
+
events,
|
|
1317
|
+
application_id: applicationId,
|
|
1318
|
+
secret,
|
|
1319
|
+
enabled
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
return this.unwrap(data?.data);
|
|
1325
|
+
},
|
|
1326
|
+
get: async (id) => {
|
|
1327
|
+
const { data } = await getAdminWebhookConfigsById({
|
|
1328
|
+
headers: this.getHeaders(),
|
|
1329
|
+
path: { id }
|
|
1330
|
+
});
|
|
1331
|
+
return this.unwrap(data?.data);
|
|
1332
|
+
},
|
|
1333
|
+
update: async (id, updates) => {
|
|
1334
|
+
const { data } = await patchAdminWebhookConfigsById({
|
|
1335
|
+
headers: this.getHeaders(),
|
|
1336
|
+
path: { id },
|
|
1337
|
+
body: {
|
|
1338
|
+
data: {
|
|
1339
|
+
id,
|
|
1340
|
+
type: "webhook_config",
|
|
1341
|
+
attributes: updates
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
});
|
|
1345
|
+
return this.unwrap(data?.data);
|
|
1346
|
+
},
|
|
1347
|
+
delete: async (id) => {
|
|
1348
|
+
await deleteAdminWebhookConfigsById({
|
|
1349
|
+
headers: this.getHeaders(),
|
|
1350
|
+
path: { id }
|
|
1351
|
+
});
|
|
1352
|
+
return true;
|
|
1353
|
+
},
|
|
1354
|
+
test: async (id) => {
|
|
1355
|
+
const { data } = await postAdminWebhookConfigsByIdTest({
|
|
1356
|
+
headers: this.getHeaders(),
|
|
1357
|
+
path: { id }
|
|
1358
|
+
});
|
|
1359
|
+
return this.unwrap(data?.data);
|
|
1360
|
+
}
|
|
1361
|
+
},
|
|
1362
|
+
deliveries: {
|
|
1363
|
+
list: async () => {
|
|
1364
|
+
const { data } = await getAdminWebhookDeliveries({ headers: this.getHeaders() });
|
|
1365
|
+
return this.unwrap(data?.data);
|
|
1366
|
+
},
|
|
1367
|
+
get: async (id) => {
|
|
1368
|
+
const { data } = await getAdminWebhookDeliveriesById({
|
|
1369
|
+
headers: this.getHeaders(),
|
|
1370
|
+
path: { id }
|
|
1371
|
+
});
|
|
1372
|
+
return this.unwrap(data?.data);
|
|
1373
|
+
},
|
|
1374
|
+
retry: async (id) => {
|
|
1375
|
+
const { data } = await postAdminWebhookDeliveriesByIdRetry({
|
|
1376
|
+
headers: this.getHeaders(),
|
|
1377
|
+
path: { id }
|
|
1378
|
+
});
|
|
1379
|
+
return this.unwrap(data?.data);
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
};
|
|
1383
|
+
/**
|
|
1384
|
+
* Document administration
|
|
1385
|
+
*/
|
|
1386
|
+
this.documents = {
|
|
1387
|
+
list: async () => {
|
|
1388
|
+
const { data } = await getAdminExtractionDocuments({ headers: this.getHeaders() });
|
|
1389
|
+
return this.unwrap(data?.data);
|
|
1390
|
+
},
|
|
1391
|
+
get: async (id) => {
|
|
1392
|
+
const { data } = await getAdminExtractionDocumentsById({
|
|
1393
|
+
headers: this.getHeaders(),
|
|
1394
|
+
path: { id }
|
|
1395
|
+
});
|
|
1396
|
+
return this.unwrap(data?.data);
|
|
1397
|
+
},
|
|
1398
|
+
stats: async () => {
|
|
1399
|
+
const { data } = await getAdminDocumentsStats({ headers: this.getHeaders() });
|
|
1400
|
+
return this.unwrap(data?.data);
|
|
1401
|
+
},
|
|
1402
|
+
bulkDelete: async (documentIds) => {
|
|
1403
|
+
const validated = DocumentBulkDeleteSchema.parse({ document_ids: documentIds });
|
|
1404
|
+
const { data } = await postAdminDocumentsBulkDelete({
|
|
1405
|
+
headers: this.getHeaders(),
|
|
1406
|
+
body: {
|
|
1407
|
+
data: {
|
|
1408
|
+
type: "operation_success",
|
|
1409
|
+
attributes: {
|
|
1410
|
+
ids: validated.document_ids
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
});
|
|
1415
|
+
return this.unwrap(data?.data);
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
/**
|
|
1419
|
+
* API Key management
|
|
1420
|
+
*/
|
|
1421
|
+
this.apiKeys = {
|
|
1422
|
+
list: async () => {
|
|
1423
|
+
const { data } = await getAdminApiKeys({ headers: this.getHeaders() });
|
|
1424
|
+
return this.unwrap(data?.data);
|
|
1425
|
+
},
|
|
1426
|
+
get: async (id) => {
|
|
1427
|
+
const { data } = await getAdminApiKeysById({
|
|
1428
|
+
headers: this.getHeaders(),
|
|
1429
|
+
path: { id }
|
|
1430
|
+
});
|
|
1431
|
+
return this.unwrap(data?.data);
|
|
1432
|
+
},
|
|
1433
|
+
allocate: async (id, amount, description) => {
|
|
1434
|
+
const { data } = await patchAdminApiKeysByIdAllocate({
|
|
1435
|
+
headers: this.getHeaders(),
|
|
1436
|
+
path: { id },
|
|
1437
|
+
body: {
|
|
1438
|
+
data: {
|
|
1439
|
+
id,
|
|
1440
|
+
type: "api_key",
|
|
1441
|
+
attributes: {
|
|
1442
|
+
amount,
|
|
1443
|
+
description
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
});
|
|
1448
|
+
return this.unwrap(data?.data);
|
|
1449
|
+
},
|
|
1450
|
+
revoke: async (id) => {
|
|
1451
|
+
const { data } = await patchAdminApiKeysByIdRevoke({
|
|
1452
|
+
headers: this.getHeaders(),
|
|
1453
|
+
path: { id }
|
|
1454
|
+
});
|
|
1455
|
+
return this.unwrap(data?.data);
|
|
1456
|
+
},
|
|
1457
|
+
rotate: async (id) => {
|
|
1458
|
+
const { data } = await patchAdminApiKeysByIdRotate({
|
|
1459
|
+
headers: this.getHeaders(),
|
|
1460
|
+
path: { id }
|
|
1461
|
+
});
|
|
1462
|
+
return this.unwrap(data?.data);
|
|
1463
|
+
}
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
|
|
1468
|
+
// src/errors/index.ts
|
|
1469
|
+
var GptCoreError = class extends Error {
|
|
1470
|
+
constructor(message, options) {
|
|
1471
|
+
super(message);
|
|
1472
|
+
this.name = this.constructor.name;
|
|
1473
|
+
this.statusCode = options?.statusCode;
|
|
1474
|
+
this.code = options?.code;
|
|
1475
|
+
this.requestId = options?.requestId;
|
|
1476
|
+
this.headers = options?.headers;
|
|
1477
|
+
this.body = options?.body;
|
|
1478
|
+
if (options?.cause) {
|
|
1479
|
+
this.cause = options.cause;
|
|
1480
|
+
}
|
|
1481
|
+
if (Error.captureStackTrace) {
|
|
1482
|
+
Error.captureStackTrace(this, this.constructor);
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1486
|
+
var AuthenticationError = class extends GptCoreError {
|
|
1487
|
+
constructor(message = "Authentication failed", options) {
|
|
1488
|
+
super(message, { statusCode: 401, ...options });
|
|
1489
|
+
}
|
|
1490
|
+
};
|
|
1491
|
+
var AuthorizationError = class extends GptCoreError {
|
|
1492
|
+
constructor(message = "Permission denied", options) {
|
|
1493
|
+
super(message, { statusCode: 403, ...options });
|
|
1494
|
+
}
|
|
1495
|
+
};
|
|
1496
|
+
var NotFoundError = class extends GptCoreError {
|
|
1497
|
+
constructor(message = "Resource not found", options) {
|
|
1498
|
+
super(message, { statusCode: 404, ...options });
|
|
1499
|
+
}
|
|
1500
|
+
};
|
|
1501
|
+
var ValidationError = class extends GptCoreError {
|
|
1502
|
+
constructor(message = "Validation failed", errors, options) {
|
|
1503
|
+
super(message, { statusCode: 422, ...options });
|
|
1504
|
+
this.errors = errors;
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1507
|
+
var RateLimitError = class extends GptCoreError {
|
|
1508
|
+
constructor(message = "Rate limit exceeded", retryAfter, options) {
|
|
1509
|
+
super(message, { statusCode: 429, ...options });
|
|
1510
|
+
this.retryAfter = retryAfter;
|
|
1511
|
+
}
|
|
1512
|
+
};
|
|
1513
|
+
var NetworkError = class extends GptCoreError {
|
|
1514
|
+
constructor(message = "Network request failed", options) {
|
|
1515
|
+
super(message, options);
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
var TimeoutError = class extends GptCoreError {
|
|
1519
|
+
constructor(message = "Request timeout", options) {
|
|
1520
|
+
super(message, options);
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
var ServerError = class extends GptCoreError {
|
|
1524
|
+
constructor(message = "Internal server error", options) {
|
|
1525
|
+
super(message, { statusCode: 500, ...options });
|
|
1526
|
+
}
|
|
1527
|
+
};
|
|
1528
|
+
function handleApiError(error) {
|
|
1529
|
+
const response = error?.response || error;
|
|
1530
|
+
const statusCode = response?.status || error?.status || error?.statusCode;
|
|
1531
|
+
const headers = response?.headers || error?.headers;
|
|
1532
|
+
const requestId = headers?.get?.("x-request-id") || headers?.["x-request-id"];
|
|
1533
|
+
const body = response?.body || response?.data || error?.body || error?.data || error;
|
|
1534
|
+
let message = "An error occurred";
|
|
1535
|
+
let errors;
|
|
1536
|
+
if (body?.errors && Array.isArray(body.errors)) {
|
|
1537
|
+
const firstError = body.errors[0];
|
|
1538
|
+
message = firstError?.title || firstError?.detail || message;
|
|
1539
|
+
errors = body.errors.map((err) => ({
|
|
1540
|
+
field: err.source?.pointer?.split("/").pop(),
|
|
1541
|
+
message: err.detail || err.title || "Unknown error"
|
|
1542
|
+
}));
|
|
1543
|
+
} else if (body?.message) {
|
|
1544
|
+
message = body.message;
|
|
1545
|
+
} else if (typeof body === "string") {
|
|
1546
|
+
message = body;
|
|
1547
|
+
} else if (error?.message) {
|
|
1548
|
+
message = error.message;
|
|
1549
|
+
}
|
|
1550
|
+
const errorOptions = {
|
|
1551
|
+
statusCode,
|
|
1552
|
+
requestId,
|
|
1553
|
+
headers: headers ? headers.entries ? Object.fromEntries(headers.entries()) : Object.fromEntries(Object.entries(headers)) : void 0,
|
|
1554
|
+
body,
|
|
1555
|
+
cause: error
|
|
1556
|
+
};
|
|
1557
|
+
switch (statusCode) {
|
|
1558
|
+
case 401:
|
|
1559
|
+
throw new AuthenticationError(message, errorOptions);
|
|
1560
|
+
case 403:
|
|
1561
|
+
throw new AuthorizationError(message, errorOptions);
|
|
1562
|
+
case 404:
|
|
1563
|
+
throw new NotFoundError(message, errorOptions);
|
|
1564
|
+
case 400:
|
|
1565
|
+
case 422:
|
|
1566
|
+
throw new ValidationError(message, errors, errorOptions);
|
|
1567
|
+
case 429:
|
|
1568
|
+
const retryAfter = headers?.get?.("retry-after") || headers?.["retry-after"];
|
|
1569
|
+
throw new RateLimitError(message, retryAfter ? parseInt(retryAfter, 10) : void 0, errorOptions);
|
|
1570
|
+
case 500:
|
|
1571
|
+
case 502:
|
|
1572
|
+
case 503:
|
|
1573
|
+
case 504:
|
|
1574
|
+
throw new ServerError(message, errorOptions);
|
|
1575
|
+
default:
|
|
1576
|
+
if (statusCode && statusCode >= 400) {
|
|
1577
|
+
throw new GptCoreError(message, errorOptions);
|
|
1578
|
+
}
|
|
1579
|
+
throw new NetworkError(message, errorOptions);
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1583
|
+
0 && (module.exports = {
|
|
1584
|
+
AccountCreditSchema,
|
|
1585
|
+
AccountDebitSchema,
|
|
1586
|
+
AgentAdminCreateSchema,
|
|
1587
|
+
ApiKeyAllocateSchema,
|
|
1588
|
+
AuthenticationError,
|
|
1589
|
+
AuthorizationError,
|
|
1590
|
+
DocumentBulkDeleteSchema,
|
|
1591
|
+
DocumentBulkReprocessSchema,
|
|
1592
|
+
GptAdmin,
|
|
1593
|
+
GptCoreError,
|
|
1594
|
+
NetworkError,
|
|
1595
|
+
NotFoundError,
|
|
1596
|
+
RateLimitError,
|
|
1597
|
+
ServerError,
|
|
1598
|
+
StorageStatsRequestSchema,
|
|
1599
|
+
TimeoutError,
|
|
1600
|
+
ValidationError,
|
|
1601
|
+
WebhookBulkDisableSchema,
|
|
1602
|
+
WebhookBulkEnableSchema,
|
|
1603
|
+
WebhookConfigCreateSchema,
|
|
1604
|
+
WebhookDeliveryBulkRetrySchema,
|
|
1605
|
+
handleApiError
|
|
1606
|
+
});
|