@gpt-core/admin 0.1.0-alpha.1 → 0.1.0-alpha.2

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