@llmgateway/ai-sdk-provider 2.5.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/index.d.mts +24 -45
- package/dist/index.d.ts +24 -45
- package/dist/index.js +1456 -171
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1456 -169
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +25 -46
- package/dist/internal/index.d.ts +25 -46
- package/dist/internal/index.js +1484 -189
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +1484 -187
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -22,9 +22,21 @@ var __spreadValues = (a, b) => {
|
|
|
22
22
|
return a;
|
|
23
23
|
};
|
|
24
24
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
25
37
|
var __export = (target, all) => {
|
|
26
|
-
for (var
|
|
27
|
-
__defProp(target,
|
|
38
|
+
for (var name15 in all)
|
|
39
|
+
__defProp(target, name15, { get: all[name15], enumerable: true });
|
|
28
40
|
};
|
|
29
41
|
var __copyProps = (to, from, except, desc) => {
|
|
30
42
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -53,11 +65,12 @@ __export(index_exports, {
|
|
|
53
65
|
});
|
|
54
66
|
module.exports = __toCommonJS(index_exports);
|
|
55
67
|
|
|
56
|
-
// node_modules/.pnpm/@ai-sdk+provider@
|
|
68
|
+
// node_modules/.pnpm/@ai-sdk+provider@3.0.2/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
57
69
|
var marker = "vercel.ai.error";
|
|
58
70
|
var symbol = Symbol.for(marker);
|
|
59
71
|
var _a;
|
|
60
|
-
var
|
|
72
|
+
var _b;
|
|
73
|
+
var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
|
|
61
74
|
/**
|
|
62
75
|
* Creates an AI SDK Error.
|
|
63
76
|
*
|
|
@@ -67,13 +80,13 @@ var _AISDKError = class _AISDKError2 extends Error {
|
|
|
67
80
|
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
68
81
|
*/
|
|
69
82
|
constructor({
|
|
70
|
-
name:
|
|
83
|
+
name: name142,
|
|
71
84
|
message,
|
|
72
85
|
cause
|
|
73
86
|
}) {
|
|
74
87
|
super(message);
|
|
75
88
|
this[_a] = true;
|
|
76
|
-
this.name =
|
|
89
|
+
this.name = name142;
|
|
77
90
|
this.cause = cause;
|
|
78
91
|
}
|
|
79
92
|
/**
|
|
@@ -82,20 +95,19 @@ var _AISDKError = class _AISDKError2 extends Error {
|
|
|
82
95
|
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
83
96
|
*/
|
|
84
97
|
static isInstance(error) {
|
|
85
|
-
return
|
|
98
|
+
return _AISDKError.hasMarker(error, marker);
|
|
86
99
|
}
|
|
87
|
-
static hasMarker(error,
|
|
88
|
-
const markerSymbol = Symbol.for(
|
|
100
|
+
static hasMarker(error, marker152) {
|
|
101
|
+
const markerSymbol = Symbol.for(marker152);
|
|
89
102
|
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
90
103
|
}
|
|
91
104
|
};
|
|
92
|
-
_a = symbol;
|
|
93
|
-
var AISDKError = _AISDKError;
|
|
94
105
|
var name = "AI_APICallError";
|
|
95
106
|
var marker2 = `vercel.ai.error.${name}`;
|
|
96
107
|
var symbol2 = Symbol.for(marker2);
|
|
97
108
|
var _a2;
|
|
98
|
-
var
|
|
109
|
+
var _b2;
|
|
110
|
+
var APICallError = class extends (_b2 = AISDKError, _a2 = symbol2, _b2) {
|
|
99
111
|
constructor({
|
|
100
112
|
message,
|
|
101
113
|
url,
|
|
@@ -125,12 +137,12 @@ var APICallError = class extends AISDKError {
|
|
|
125
137
|
return AISDKError.hasMarker(error, marker2);
|
|
126
138
|
}
|
|
127
139
|
};
|
|
128
|
-
_a2 = symbol2;
|
|
129
140
|
var name2 = "AI_EmptyResponseBodyError";
|
|
130
141
|
var marker3 = `vercel.ai.error.${name2}`;
|
|
131
142
|
var symbol3 = Symbol.for(marker3);
|
|
132
143
|
var _a3;
|
|
133
|
-
var
|
|
144
|
+
var _b3;
|
|
145
|
+
var EmptyResponseBodyError = class extends (_b3 = AISDKError, _a3 = symbol3, _b3) {
|
|
134
146
|
// used in isInstance
|
|
135
147
|
constructor({ message = "Empty response body" } = {}) {
|
|
136
148
|
super({ name: name2, message });
|
|
@@ -140,7 +152,6 @@ var EmptyResponseBodyError = class extends AISDKError {
|
|
|
140
152
|
return AISDKError.hasMarker(error, marker3);
|
|
141
153
|
}
|
|
142
154
|
};
|
|
143
|
-
_a3 = symbol3;
|
|
144
155
|
function getErrorMessage(error) {
|
|
145
156
|
if (error == null) {
|
|
146
157
|
return "unknown error";
|
|
@@ -157,7 +168,8 @@ var name3 = "AI_InvalidArgumentError";
|
|
|
157
168
|
var marker4 = `vercel.ai.error.${name3}`;
|
|
158
169
|
var symbol4 = Symbol.for(marker4);
|
|
159
170
|
var _a4;
|
|
160
|
-
var
|
|
171
|
+
var _b4;
|
|
172
|
+
var InvalidArgumentError = class extends (_b4 = AISDKError, _a4 = symbol4, _b4) {
|
|
161
173
|
constructor({
|
|
162
174
|
message,
|
|
163
175
|
cause,
|
|
@@ -171,12 +183,12 @@ var InvalidArgumentError = class extends AISDKError {
|
|
|
171
183
|
return AISDKError.hasMarker(error, marker4);
|
|
172
184
|
}
|
|
173
185
|
};
|
|
174
|
-
_a4 = symbol4;
|
|
175
186
|
var name4 = "AI_InvalidPromptError";
|
|
176
187
|
var marker5 = `vercel.ai.error.${name4}`;
|
|
177
188
|
var symbol5 = Symbol.for(marker5);
|
|
178
189
|
var _a5;
|
|
179
|
-
var
|
|
190
|
+
var _b5;
|
|
191
|
+
var InvalidPromptError = class extends (_b5 = AISDKError, _a5 = symbol5, _b5) {
|
|
180
192
|
constructor({
|
|
181
193
|
prompt,
|
|
182
194
|
message,
|
|
@@ -190,12 +202,12 @@ var InvalidPromptError = class extends AISDKError {
|
|
|
190
202
|
return AISDKError.hasMarker(error, marker5);
|
|
191
203
|
}
|
|
192
204
|
};
|
|
193
|
-
_a5 = symbol5;
|
|
194
205
|
var name5 = "AI_InvalidResponseDataError";
|
|
195
206
|
var marker6 = `vercel.ai.error.${name5}`;
|
|
196
207
|
var symbol6 = Symbol.for(marker6);
|
|
197
208
|
var _a6;
|
|
198
|
-
var
|
|
209
|
+
var _b6;
|
|
210
|
+
var InvalidResponseDataError = class extends (_b6 = AISDKError, _a6 = symbol6, _b6) {
|
|
199
211
|
constructor({
|
|
200
212
|
data,
|
|
201
213
|
message = `Invalid response data: ${JSON.stringify(data)}.`
|
|
@@ -208,12 +220,12 @@ var InvalidResponseDataError = class extends AISDKError {
|
|
|
208
220
|
return AISDKError.hasMarker(error, marker6);
|
|
209
221
|
}
|
|
210
222
|
};
|
|
211
|
-
_a6 = symbol6;
|
|
212
223
|
var name6 = "AI_JSONParseError";
|
|
213
224
|
var marker7 = `vercel.ai.error.${name6}`;
|
|
214
225
|
var symbol7 = Symbol.for(marker7);
|
|
215
226
|
var _a7;
|
|
216
|
-
var
|
|
227
|
+
var _b7;
|
|
228
|
+
var JSONParseError = class extends (_b7 = AISDKError, _a7 = symbol7, _b7) {
|
|
217
229
|
constructor({ text, cause }) {
|
|
218
230
|
super({
|
|
219
231
|
name: name6,
|
|
@@ -228,12 +240,12 @@ Error message: ${getErrorMessage(cause)}`,
|
|
|
228
240
|
return AISDKError.hasMarker(error, marker7);
|
|
229
241
|
}
|
|
230
242
|
};
|
|
231
|
-
_a7 = symbol7;
|
|
232
243
|
var name7 = "AI_LoadAPIKeyError";
|
|
233
244
|
var marker8 = `vercel.ai.error.${name7}`;
|
|
234
245
|
var symbol8 = Symbol.for(marker8);
|
|
235
246
|
var _a8;
|
|
236
|
-
var
|
|
247
|
+
var _b8;
|
|
248
|
+
var LoadAPIKeyError = class extends (_b8 = AISDKError, _a8 = symbol8, _b8) {
|
|
237
249
|
// used in isInstance
|
|
238
250
|
constructor({ message }) {
|
|
239
251
|
super({ name: name7, message });
|
|
@@ -243,32 +255,86 @@ var LoadAPIKeyError = class extends AISDKError {
|
|
|
243
255
|
return AISDKError.hasMarker(error, marker8);
|
|
244
256
|
}
|
|
245
257
|
};
|
|
246
|
-
_a8 = symbol8;
|
|
247
258
|
var name8 = "AI_LoadSettingError";
|
|
248
259
|
var marker9 = `vercel.ai.error.${name8}`;
|
|
249
260
|
var symbol9 = Symbol.for(marker9);
|
|
250
261
|
var _a9;
|
|
251
|
-
|
|
262
|
+
var _b9;
|
|
263
|
+
var LoadSettingError = class extends (_b9 = AISDKError, _a9 = symbol9, _b9) {
|
|
264
|
+
// used in isInstance
|
|
265
|
+
constructor({ message }) {
|
|
266
|
+
super({ name: name8, message });
|
|
267
|
+
this[_a9] = true;
|
|
268
|
+
}
|
|
269
|
+
static isInstance(error) {
|
|
270
|
+
return AISDKError.hasMarker(error, marker9);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
252
273
|
var name9 = "AI_NoContentGeneratedError";
|
|
253
274
|
var marker10 = `vercel.ai.error.${name9}`;
|
|
254
275
|
var symbol10 = Symbol.for(marker10);
|
|
255
276
|
var _a10;
|
|
256
|
-
|
|
277
|
+
var _b10;
|
|
278
|
+
var NoContentGeneratedError = class extends (_b10 = AISDKError, _a10 = symbol10, _b10) {
|
|
279
|
+
// used in isInstance
|
|
280
|
+
constructor({
|
|
281
|
+
message = "No content generated."
|
|
282
|
+
} = {}) {
|
|
283
|
+
super({ name: name9, message });
|
|
284
|
+
this[_a10] = true;
|
|
285
|
+
}
|
|
286
|
+
static isInstance(error) {
|
|
287
|
+
return AISDKError.hasMarker(error, marker10);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
257
290
|
var name10 = "AI_NoSuchModelError";
|
|
258
291
|
var marker11 = `vercel.ai.error.${name10}`;
|
|
259
292
|
var symbol11 = Symbol.for(marker11);
|
|
260
293
|
var _a11;
|
|
261
|
-
|
|
294
|
+
var _b11;
|
|
295
|
+
var NoSuchModelError = class extends (_b11 = AISDKError, _a11 = symbol11, _b11) {
|
|
296
|
+
constructor({
|
|
297
|
+
errorName = name10,
|
|
298
|
+
modelId,
|
|
299
|
+
modelType,
|
|
300
|
+
message = `No such ${modelType}: ${modelId}`
|
|
301
|
+
}) {
|
|
302
|
+
super({ name: errorName, message });
|
|
303
|
+
this[_a11] = true;
|
|
304
|
+
this.modelId = modelId;
|
|
305
|
+
this.modelType = modelType;
|
|
306
|
+
}
|
|
307
|
+
static isInstance(error) {
|
|
308
|
+
return AISDKError.hasMarker(error, marker11);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
262
311
|
var name11 = "AI_TooManyEmbeddingValuesForCallError";
|
|
263
312
|
var marker12 = `vercel.ai.error.${name11}`;
|
|
264
313
|
var symbol12 = Symbol.for(marker12);
|
|
265
314
|
var _a12;
|
|
266
|
-
|
|
315
|
+
var _b12;
|
|
316
|
+
var TooManyEmbeddingValuesForCallError = class extends (_b12 = AISDKError, _a12 = symbol12, _b12) {
|
|
317
|
+
constructor(options) {
|
|
318
|
+
super({
|
|
319
|
+
name: name11,
|
|
320
|
+
message: `Too many values for a single embedding call. The ${options.provider} model "${options.modelId}" can only embed up to ${options.maxEmbeddingsPerCall} values per call, but ${options.values.length} values were provided.`
|
|
321
|
+
});
|
|
322
|
+
this[_a12] = true;
|
|
323
|
+
this.provider = options.provider;
|
|
324
|
+
this.modelId = options.modelId;
|
|
325
|
+
this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
|
|
326
|
+
this.values = options.values;
|
|
327
|
+
}
|
|
328
|
+
static isInstance(error) {
|
|
329
|
+
return AISDKError.hasMarker(error, marker12);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
267
332
|
var name12 = "AI_TypeValidationError";
|
|
268
333
|
var marker13 = `vercel.ai.error.${name12}`;
|
|
269
334
|
var symbol13 = Symbol.for(marker13);
|
|
270
335
|
var _a13;
|
|
271
|
-
var
|
|
336
|
+
var _b13;
|
|
337
|
+
var TypeValidationError = class _TypeValidationError extends (_b13 = AISDKError, _a13 = symbol13, _b13) {
|
|
272
338
|
constructor({ value, cause }) {
|
|
273
339
|
super({
|
|
274
340
|
name: name12,
|
|
@@ -296,16 +362,15 @@ Error message: ${getErrorMessage(cause)}`,
|
|
|
296
362
|
value,
|
|
297
363
|
cause
|
|
298
364
|
}) {
|
|
299
|
-
return
|
|
365
|
+
return _TypeValidationError.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError({ value, cause });
|
|
300
366
|
}
|
|
301
367
|
};
|
|
302
|
-
_a13 = symbol13;
|
|
303
|
-
var TypeValidationError = _TypeValidationError;
|
|
304
368
|
var name13 = "AI_UnsupportedFunctionalityError";
|
|
305
369
|
var marker14 = `vercel.ai.error.${name13}`;
|
|
306
370
|
var symbol14 = Symbol.for(marker14);
|
|
307
371
|
var _a14;
|
|
308
|
-
var
|
|
372
|
+
var _b14;
|
|
373
|
+
var UnsupportedFunctionalityError = class extends (_b14 = AISDKError, _a14 = symbol14, _b14) {
|
|
309
374
|
constructor({
|
|
310
375
|
functionality,
|
|
311
376
|
message = `'${functionality}' functionality not supported.`
|
|
@@ -318,9 +383,14 @@ var UnsupportedFunctionalityError = class extends AISDKError {
|
|
|
318
383
|
return AISDKError.hasMarker(error, marker14);
|
|
319
384
|
}
|
|
320
385
|
};
|
|
321
|
-
_a14 = symbol14;
|
|
322
386
|
|
|
323
|
-
// node_modules/.pnpm
|
|
387
|
+
// node_modules/.pnpm/@ai-sdk+provider-utils@4.0.4_zod@3.25.34/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
388
|
+
var z4 = __toESM(require("zod/v4"), 1);
|
|
389
|
+
var import_v3 = require("zod/v3");
|
|
390
|
+
var import_v32 = require("zod/v3");
|
|
391
|
+
var import_v33 = require("zod/v3");
|
|
392
|
+
|
|
393
|
+
// node_modules/.pnpm/eventsource-parser@3.0.6/node_modules/eventsource-parser/dist/index.js
|
|
324
394
|
var ParseError = class extends Error {
|
|
325
395
|
constructor(message, options) {
|
|
326
396
|
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
@@ -411,7 +481,7 @@ function splitLines(chunk) {
|
|
|
411
481
|
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
412
482
|
`, searchIndex);
|
|
413
483
|
let lineEnd = -1;
|
|
414
|
-
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
|
|
484
|
+
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
|
|
415
485
|
incompleteLine = chunk.slice(searchIndex);
|
|
416
486
|
break;
|
|
417
487
|
} else {
|
|
@@ -423,7 +493,7 @@ function splitLines(chunk) {
|
|
|
423
493
|
return [lines, incompleteLine];
|
|
424
494
|
}
|
|
425
495
|
|
|
426
|
-
// node_modules/.pnpm/eventsource-parser@3.0.
|
|
496
|
+
// node_modules/.pnpm/eventsource-parser@3.0.6/node_modules/eventsource-parser/dist/stream.js
|
|
427
497
|
var EventSourceParserStream = class extends TransformStream {
|
|
428
498
|
constructor({ onError, onRetry, onComment } = {}) {
|
|
429
499
|
let parser;
|
|
@@ -447,28 +517,7 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
447
517
|
}
|
|
448
518
|
};
|
|
449
519
|
|
|
450
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@
|
|
451
|
-
var z4 = __toESM(require("zod/v4"), 1);
|
|
452
|
-
|
|
453
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.34/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
454
|
-
var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
455
|
-
|
|
456
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.34/node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
457
|
-
var import_zod4 = require("zod");
|
|
458
|
-
|
|
459
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.34/node_modules/zod-to-json-schema/dist/esm/parsers/array.js
|
|
460
|
-
var import_zod = require("zod");
|
|
461
|
-
|
|
462
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.34/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
463
|
-
var import_zod2 = require("zod");
|
|
464
|
-
|
|
465
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.34/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
|
|
466
|
-
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
467
|
-
|
|
468
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.34/node_modules/zod-to-json-schema/dist/esm/parsers/object.js
|
|
469
|
-
var import_zod3 = require("zod");
|
|
470
|
-
|
|
471
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.0-beta.5_zod@3.25.34/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
520
|
+
// node_modules/.pnpm/@ai-sdk+provider-utils@4.0.4_zod@3.25.34/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
472
521
|
function combineHeaders(...headers) {
|
|
473
522
|
return headers.reduce(
|
|
474
523
|
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
@@ -478,6 +527,37 @@ function combineHeaders(...headers) {
|
|
|
478
527
|
function extractResponseHeaders(response) {
|
|
479
528
|
return Object.fromEntries([...response.headers]);
|
|
480
529
|
}
|
|
530
|
+
var { btoa, atob } = globalThis;
|
|
531
|
+
function convertUint8ArrayToBase64(array) {
|
|
532
|
+
let latin1string = "";
|
|
533
|
+
for (let i = 0; i < array.length; i++) {
|
|
534
|
+
latin1string += String.fromCodePoint(array[i]);
|
|
535
|
+
}
|
|
536
|
+
return btoa(latin1string);
|
|
537
|
+
}
|
|
538
|
+
var name14 = "AI_DownloadError";
|
|
539
|
+
var marker15 = `vercel.ai.error.${name14}`;
|
|
540
|
+
var symbol15 = Symbol.for(marker15);
|
|
541
|
+
var _a15;
|
|
542
|
+
var _b15;
|
|
543
|
+
var DownloadError = class extends (_b15 = AISDKError, _a15 = symbol15, _b15) {
|
|
544
|
+
constructor({
|
|
545
|
+
url,
|
|
546
|
+
statusCode,
|
|
547
|
+
statusText,
|
|
548
|
+
cause,
|
|
549
|
+
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
|
550
|
+
}) {
|
|
551
|
+
super({ name: name14, message, cause });
|
|
552
|
+
this[_a15] = true;
|
|
553
|
+
this.url = url;
|
|
554
|
+
this.statusCode = statusCode;
|
|
555
|
+
this.statusText = statusText;
|
|
556
|
+
}
|
|
557
|
+
static isInstance(error) {
|
|
558
|
+
return AISDKError.hasMarker(error, marker15);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
481
561
|
var createIdGenerator = ({
|
|
482
562
|
prefix,
|
|
483
563
|
size = 16,
|
|
@@ -505,7 +585,7 @@ var createIdGenerator = ({
|
|
|
505
585
|
};
|
|
506
586
|
var generateId = createIdGenerator();
|
|
507
587
|
function isAbortError(error) {
|
|
508
|
-
return error instanceof Error && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
588
|
+
return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
509
589
|
error.name === "TimeoutError");
|
|
510
590
|
}
|
|
511
591
|
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
@@ -532,11 +612,53 @@ function handleFetchError({
|
|
|
532
612
|
}
|
|
533
613
|
return error;
|
|
534
614
|
}
|
|
535
|
-
function
|
|
536
|
-
|
|
537
|
-
|
|
615
|
+
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
616
|
+
var _a22, _b22, _c;
|
|
617
|
+
if (globalThisAny.window) {
|
|
618
|
+
return `runtime/browser`;
|
|
619
|
+
}
|
|
620
|
+
if ((_a22 = globalThisAny.navigator) == null ? void 0 : _a22.userAgent) {
|
|
621
|
+
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
622
|
+
}
|
|
623
|
+
if ((_c = (_b22 = globalThisAny.process) == null ? void 0 : _b22.versions) == null ? void 0 : _c.node) {
|
|
624
|
+
return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
|
625
|
+
}
|
|
626
|
+
if (globalThisAny.EdgeRuntime) {
|
|
627
|
+
return `runtime/vercel-edge`;
|
|
628
|
+
}
|
|
629
|
+
return "runtime/unknown";
|
|
630
|
+
}
|
|
631
|
+
function normalizeHeaders(headers) {
|
|
632
|
+
if (headers == null) {
|
|
633
|
+
return {};
|
|
634
|
+
}
|
|
635
|
+
const normalized = {};
|
|
636
|
+
if (headers instanceof Headers) {
|
|
637
|
+
headers.forEach((value, key) => {
|
|
638
|
+
normalized[key.toLowerCase()] = value;
|
|
639
|
+
});
|
|
640
|
+
} else {
|
|
641
|
+
if (!Array.isArray(headers)) {
|
|
642
|
+
headers = Object.entries(headers);
|
|
643
|
+
}
|
|
644
|
+
for (const [key, value] of headers) {
|
|
645
|
+
if (value != null) {
|
|
646
|
+
normalized[key.toLowerCase()] = value;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
return normalized;
|
|
651
|
+
}
|
|
652
|
+
function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
653
|
+
const normalizedHeaders = new Headers(normalizeHeaders(headers));
|
|
654
|
+
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
|
655
|
+
normalizedHeaders.set(
|
|
656
|
+
"user-agent",
|
|
657
|
+
[currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ")
|
|
538
658
|
);
|
|
659
|
+
return Object.fromEntries(normalizedHeaders.entries());
|
|
539
660
|
}
|
|
661
|
+
var VERSION = true ? "4.0.4" : "0.0.0-test";
|
|
540
662
|
function loadApiKey({
|
|
541
663
|
apiKey,
|
|
542
664
|
environmentVariableName,
|
|
@@ -605,35 +727,1205 @@ function filter(obj) {
|
|
|
605
727
|
}
|
|
606
728
|
function secureJsonParse(text) {
|
|
607
729
|
const { stackTraceLimit } = Error;
|
|
608
|
-
|
|
730
|
+
try {
|
|
731
|
+
Error.stackTraceLimit = 0;
|
|
732
|
+
} catch (e) {
|
|
733
|
+
return _parse(text);
|
|
734
|
+
}
|
|
609
735
|
try {
|
|
610
736
|
return _parse(text);
|
|
611
737
|
} finally {
|
|
612
738
|
Error.stackTraceLimit = stackTraceLimit;
|
|
613
739
|
}
|
|
614
740
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
741
|
+
function addAdditionalPropertiesToJsonSchema(jsonSchema2) {
|
|
742
|
+
if (jsonSchema2.type === "object" || Array.isArray(jsonSchema2.type) && jsonSchema2.type.includes("object")) {
|
|
743
|
+
jsonSchema2.additionalProperties = false;
|
|
744
|
+
const { properties } = jsonSchema2;
|
|
745
|
+
if (properties != null) {
|
|
746
|
+
for (const key of Object.keys(properties)) {
|
|
747
|
+
properties[key] = visit(properties[key]);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
if (jsonSchema2.items != null) {
|
|
752
|
+
jsonSchema2.items = Array.isArray(jsonSchema2.items) ? jsonSchema2.items.map(visit) : visit(jsonSchema2.items);
|
|
753
|
+
}
|
|
754
|
+
if (jsonSchema2.anyOf != null) {
|
|
755
|
+
jsonSchema2.anyOf = jsonSchema2.anyOf.map(visit);
|
|
756
|
+
}
|
|
757
|
+
if (jsonSchema2.allOf != null) {
|
|
758
|
+
jsonSchema2.allOf = jsonSchema2.allOf.map(visit);
|
|
759
|
+
}
|
|
760
|
+
if (jsonSchema2.oneOf != null) {
|
|
761
|
+
jsonSchema2.oneOf = jsonSchema2.oneOf.map(visit);
|
|
762
|
+
}
|
|
763
|
+
const { definitions } = jsonSchema2;
|
|
764
|
+
if (definitions != null) {
|
|
765
|
+
for (const key of Object.keys(definitions)) {
|
|
766
|
+
definitions[key] = visit(definitions[key]);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
return jsonSchema2;
|
|
618
770
|
}
|
|
619
|
-
function
|
|
620
|
-
|
|
771
|
+
function visit(def) {
|
|
772
|
+
if (typeof def === "boolean") return def;
|
|
773
|
+
return addAdditionalPropertiesToJsonSchema(def);
|
|
621
774
|
}
|
|
622
|
-
|
|
623
|
-
|
|
775
|
+
var ignoreOverride = Symbol(
|
|
776
|
+
"Let zodToJsonSchema decide on which parser to use"
|
|
777
|
+
);
|
|
778
|
+
var defaultOptions = {
|
|
779
|
+
name: void 0,
|
|
780
|
+
$refStrategy: "root",
|
|
781
|
+
basePath: ["#"],
|
|
782
|
+
effectStrategy: "input",
|
|
783
|
+
pipeStrategy: "all",
|
|
784
|
+
dateStrategy: "format:date-time",
|
|
785
|
+
mapStrategy: "entries",
|
|
786
|
+
removeAdditionalStrategy: "passthrough",
|
|
787
|
+
allowedAdditionalProperties: true,
|
|
788
|
+
rejectedAdditionalProperties: false,
|
|
789
|
+
definitionPath: "definitions",
|
|
790
|
+
strictUnions: false,
|
|
791
|
+
definitions: {},
|
|
792
|
+
errorMessages: false,
|
|
793
|
+
patternStrategy: "escape",
|
|
794
|
+
applyRegexFlags: false,
|
|
795
|
+
emailStrategy: "format:email",
|
|
796
|
+
base64Strategy: "contentEncoding:base64",
|
|
797
|
+
nameStrategy: "ref"
|
|
798
|
+
};
|
|
799
|
+
var getDefaultOptions = (options) => typeof options === "string" ? __spreadProps(__spreadValues({}, defaultOptions), {
|
|
800
|
+
name: options
|
|
801
|
+
}) : __spreadValues(__spreadValues({}, defaultOptions), options);
|
|
802
|
+
function parseAnyDef() {
|
|
803
|
+
return {};
|
|
624
804
|
}
|
|
625
|
-
function
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
805
|
+
function parseArrayDef(def, refs) {
|
|
806
|
+
var _a22, _b22, _c;
|
|
807
|
+
const res = {
|
|
808
|
+
type: "array"
|
|
809
|
+
};
|
|
810
|
+
if (((_a22 = def.type) == null ? void 0 : _a22._def) && ((_c = (_b22 = def.type) == null ? void 0 : _b22._def) == null ? void 0 : _c.typeName) !== import_v32.ZodFirstPartyTypeKind.ZodAny) {
|
|
811
|
+
res.items = parseDef(def.type._def, __spreadProps(__spreadValues({}, refs), {
|
|
812
|
+
currentPath: [...refs.currentPath, "items"]
|
|
813
|
+
}));
|
|
814
|
+
}
|
|
815
|
+
if (def.minLength) {
|
|
816
|
+
res.minItems = def.minLength.value;
|
|
817
|
+
}
|
|
818
|
+
if (def.maxLength) {
|
|
819
|
+
res.maxItems = def.maxLength.value;
|
|
820
|
+
}
|
|
821
|
+
if (def.exactLength) {
|
|
822
|
+
res.minItems = def.exactLength.value;
|
|
823
|
+
res.maxItems = def.exactLength.value;
|
|
824
|
+
}
|
|
825
|
+
return res;
|
|
826
|
+
}
|
|
827
|
+
function parseBigintDef(def) {
|
|
828
|
+
const res = {
|
|
829
|
+
type: "integer",
|
|
830
|
+
format: "int64"
|
|
831
|
+
};
|
|
832
|
+
if (!def.checks) return res;
|
|
833
|
+
for (const check of def.checks) {
|
|
834
|
+
switch (check.kind) {
|
|
835
|
+
case "min":
|
|
836
|
+
if (check.inclusive) {
|
|
837
|
+
res.minimum = check.value;
|
|
838
|
+
} else {
|
|
839
|
+
res.exclusiveMinimum = check.value;
|
|
840
|
+
}
|
|
841
|
+
break;
|
|
842
|
+
case "max":
|
|
843
|
+
if (check.inclusive) {
|
|
844
|
+
res.maximum = check.value;
|
|
845
|
+
} else {
|
|
846
|
+
res.exclusiveMaximum = check.value;
|
|
847
|
+
}
|
|
848
|
+
break;
|
|
849
|
+
case "multipleOf":
|
|
850
|
+
res.multipleOf = check.value;
|
|
851
|
+
break;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return res;
|
|
855
|
+
}
|
|
856
|
+
function parseBooleanDef() {
|
|
857
|
+
return { type: "boolean" };
|
|
858
|
+
}
|
|
859
|
+
function parseBrandedDef(_def, refs) {
|
|
860
|
+
return parseDef(_def.type._def, refs);
|
|
861
|
+
}
|
|
862
|
+
var parseCatchDef = (def, refs) => {
|
|
863
|
+
return parseDef(def.innerType._def, refs);
|
|
864
|
+
};
|
|
865
|
+
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
866
|
+
const strategy = overrideDateStrategy != null ? overrideDateStrategy : refs.dateStrategy;
|
|
867
|
+
if (Array.isArray(strategy)) {
|
|
868
|
+
return {
|
|
869
|
+
anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
|
|
634
870
|
};
|
|
871
|
+
}
|
|
872
|
+
switch (strategy) {
|
|
873
|
+
case "string":
|
|
874
|
+
case "format:date-time":
|
|
875
|
+
return {
|
|
876
|
+
type: "string",
|
|
877
|
+
format: "date-time"
|
|
878
|
+
};
|
|
879
|
+
case "format:date":
|
|
880
|
+
return {
|
|
881
|
+
type: "string",
|
|
882
|
+
format: "date"
|
|
883
|
+
};
|
|
884
|
+
case "integer":
|
|
885
|
+
return integerDateParser(def);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
var integerDateParser = (def) => {
|
|
889
|
+
const res = {
|
|
890
|
+
type: "integer",
|
|
891
|
+
format: "unix-time"
|
|
892
|
+
};
|
|
893
|
+
for (const check of def.checks) {
|
|
894
|
+
switch (check.kind) {
|
|
895
|
+
case "min":
|
|
896
|
+
res.minimum = check.value;
|
|
897
|
+
break;
|
|
898
|
+
case "max":
|
|
899
|
+
res.maximum = check.value;
|
|
900
|
+
break;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
return res;
|
|
904
|
+
};
|
|
905
|
+
function parseDefaultDef(_def, refs) {
|
|
906
|
+
return __spreadProps(__spreadValues({}, parseDef(_def.innerType._def, refs)), {
|
|
907
|
+
default: _def.defaultValue()
|
|
635
908
|
});
|
|
636
909
|
}
|
|
910
|
+
function parseEffectsDef(_def, refs) {
|
|
911
|
+
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : parseAnyDef();
|
|
912
|
+
}
|
|
913
|
+
function parseEnumDef(def) {
|
|
914
|
+
return {
|
|
915
|
+
type: "string",
|
|
916
|
+
enum: Array.from(def.values)
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
var isJsonSchema7AllOfType = (type) => {
|
|
920
|
+
if ("type" in type && type.type === "string") return false;
|
|
921
|
+
return "allOf" in type;
|
|
922
|
+
};
|
|
923
|
+
function parseIntersectionDef(def, refs) {
|
|
924
|
+
const allOf = [
|
|
925
|
+
parseDef(def.left._def, __spreadProps(__spreadValues({}, refs), {
|
|
926
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
927
|
+
})),
|
|
928
|
+
parseDef(def.right._def, __spreadProps(__spreadValues({}, refs), {
|
|
929
|
+
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
930
|
+
}))
|
|
931
|
+
].filter((x) => !!x);
|
|
932
|
+
const mergedAllOf = [];
|
|
933
|
+
allOf.forEach((schema) => {
|
|
934
|
+
if (isJsonSchema7AllOfType(schema)) {
|
|
935
|
+
mergedAllOf.push(...schema.allOf);
|
|
936
|
+
} else {
|
|
937
|
+
let nestedSchema = schema;
|
|
938
|
+
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
939
|
+
const _a16 = schema, { additionalProperties } = _a16, rest = __objRest(_a16, ["additionalProperties"]);
|
|
940
|
+
nestedSchema = rest;
|
|
941
|
+
}
|
|
942
|
+
mergedAllOf.push(nestedSchema);
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
return mergedAllOf.length ? { allOf: mergedAllOf } : void 0;
|
|
946
|
+
}
|
|
947
|
+
function parseLiteralDef(def) {
|
|
948
|
+
const parsedType = typeof def.value;
|
|
949
|
+
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
950
|
+
return {
|
|
951
|
+
type: Array.isArray(def.value) ? "array" : "object"
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
return {
|
|
955
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
956
|
+
const: def.value
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
var emojiRegex = void 0;
|
|
960
|
+
var zodPatterns = {
|
|
961
|
+
/**
|
|
962
|
+
* `c` was changed to `[cC]` to replicate /i flag
|
|
963
|
+
*/
|
|
964
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
965
|
+
cuid2: /^[0-9a-z]+$/,
|
|
966
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
967
|
+
/**
|
|
968
|
+
* `a-z` was added to replicate /i flag
|
|
969
|
+
*/
|
|
970
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
971
|
+
/**
|
|
972
|
+
* Constructed a valid Unicode RegExp
|
|
973
|
+
*
|
|
974
|
+
* Lazily instantiate since this type of regex isn't supported
|
|
975
|
+
* in all envs (e.g. React Native).
|
|
976
|
+
*
|
|
977
|
+
* See:
|
|
978
|
+
* https://github.com/colinhacks/zod/issues/2433
|
|
979
|
+
* Fix in Zod:
|
|
980
|
+
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
981
|
+
*/
|
|
982
|
+
emoji: () => {
|
|
983
|
+
if (emojiRegex === void 0) {
|
|
984
|
+
emojiRegex = RegExp(
|
|
985
|
+
"^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",
|
|
986
|
+
"u"
|
|
987
|
+
);
|
|
988
|
+
}
|
|
989
|
+
return emojiRegex;
|
|
990
|
+
},
|
|
991
|
+
/**
|
|
992
|
+
* Unused
|
|
993
|
+
*/
|
|
994
|
+
uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
|
|
995
|
+
/**
|
|
996
|
+
* Unused
|
|
997
|
+
*/
|
|
998
|
+
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
|
|
999
|
+
ipv4Cidr: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,
|
|
1000
|
+
/**
|
|
1001
|
+
* Unused
|
|
1002
|
+
*/
|
|
1003
|
+
ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
|
|
1004
|
+
ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
|
|
1005
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
1006
|
+
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
1007
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
1008
|
+
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
1009
|
+
};
|
|
1010
|
+
function parseStringDef(def, refs) {
|
|
1011
|
+
const res = {
|
|
1012
|
+
type: "string"
|
|
1013
|
+
};
|
|
1014
|
+
if (def.checks) {
|
|
1015
|
+
for (const check of def.checks) {
|
|
1016
|
+
switch (check.kind) {
|
|
1017
|
+
case "min":
|
|
1018
|
+
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
|
|
1019
|
+
break;
|
|
1020
|
+
case "max":
|
|
1021
|
+
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
|
|
1022
|
+
break;
|
|
1023
|
+
case "email":
|
|
1024
|
+
switch (refs.emailStrategy) {
|
|
1025
|
+
case "format:email":
|
|
1026
|
+
addFormat(res, "email", check.message, refs);
|
|
1027
|
+
break;
|
|
1028
|
+
case "format:idn-email":
|
|
1029
|
+
addFormat(res, "idn-email", check.message, refs);
|
|
1030
|
+
break;
|
|
1031
|
+
case "pattern:zod":
|
|
1032
|
+
addPattern(res, zodPatterns.email, check.message, refs);
|
|
1033
|
+
break;
|
|
1034
|
+
}
|
|
1035
|
+
break;
|
|
1036
|
+
case "url":
|
|
1037
|
+
addFormat(res, "uri", check.message, refs);
|
|
1038
|
+
break;
|
|
1039
|
+
case "uuid":
|
|
1040
|
+
addFormat(res, "uuid", check.message, refs);
|
|
1041
|
+
break;
|
|
1042
|
+
case "regex":
|
|
1043
|
+
addPattern(res, check.regex, check.message, refs);
|
|
1044
|
+
break;
|
|
1045
|
+
case "cuid":
|
|
1046
|
+
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
1047
|
+
break;
|
|
1048
|
+
case "cuid2":
|
|
1049
|
+
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
1050
|
+
break;
|
|
1051
|
+
case "startsWith":
|
|
1052
|
+
addPattern(
|
|
1053
|
+
res,
|
|
1054
|
+
RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`),
|
|
1055
|
+
check.message,
|
|
1056
|
+
refs
|
|
1057
|
+
);
|
|
1058
|
+
break;
|
|
1059
|
+
case "endsWith":
|
|
1060
|
+
addPattern(
|
|
1061
|
+
res,
|
|
1062
|
+
RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`),
|
|
1063
|
+
check.message,
|
|
1064
|
+
refs
|
|
1065
|
+
);
|
|
1066
|
+
break;
|
|
1067
|
+
case "datetime":
|
|
1068
|
+
addFormat(res, "date-time", check.message, refs);
|
|
1069
|
+
break;
|
|
1070
|
+
case "date":
|
|
1071
|
+
addFormat(res, "date", check.message, refs);
|
|
1072
|
+
break;
|
|
1073
|
+
case "time":
|
|
1074
|
+
addFormat(res, "time", check.message, refs);
|
|
1075
|
+
break;
|
|
1076
|
+
case "duration":
|
|
1077
|
+
addFormat(res, "duration", check.message, refs);
|
|
1078
|
+
break;
|
|
1079
|
+
case "length":
|
|
1080
|
+
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
|
|
1081
|
+
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
|
|
1082
|
+
break;
|
|
1083
|
+
case "includes": {
|
|
1084
|
+
addPattern(
|
|
1085
|
+
res,
|
|
1086
|
+
RegExp(escapeLiteralCheckValue(check.value, refs)),
|
|
1087
|
+
check.message,
|
|
1088
|
+
refs
|
|
1089
|
+
);
|
|
1090
|
+
break;
|
|
1091
|
+
}
|
|
1092
|
+
case "ip": {
|
|
1093
|
+
if (check.version !== "v6") {
|
|
1094
|
+
addFormat(res, "ipv4", check.message, refs);
|
|
1095
|
+
}
|
|
1096
|
+
if (check.version !== "v4") {
|
|
1097
|
+
addFormat(res, "ipv6", check.message, refs);
|
|
1098
|
+
}
|
|
1099
|
+
break;
|
|
1100
|
+
}
|
|
1101
|
+
case "base64url":
|
|
1102
|
+
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
1103
|
+
break;
|
|
1104
|
+
case "jwt":
|
|
1105
|
+
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
1106
|
+
break;
|
|
1107
|
+
case "cidr": {
|
|
1108
|
+
if (check.version !== "v6") {
|
|
1109
|
+
addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
1110
|
+
}
|
|
1111
|
+
if (check.version !== "v4") {
|
|
1112
|
+
addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
1113
|
+
}
|
|
1114
|
+
break;
|
|
1115
|
+
}
|
|
1116
|
+
case "emoji":
|
|
1117
|
+
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
1118
|
+
break;
|
|
1119
|
+
case "ulid": {
|
|
1120
|
+
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
1121
|
+
break;
|
|
1122
|
+
}
|
|
1123
|
+
case "base64": {
|
|
1124
|
+
switch (refs.base64Strategy) {
|
|
1125
|
+
case "format:binary": {
|
|
1126
|
+
addFormat(res, "binary", check.message, refs);
|
|
1127
|
+
break;
|
|
1128
|
+
}
|
|
1129
|
+
case "contentEncoding:base64": {
|
|
1130
|
+
res.contentEncoding = "base64";
|
|
1131
|
+
break;
|
|
1132
|
+
}
|
|
1133
|
+
case "pattern:zod": {
|
|
1134
|
+
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
1135
|
+
break;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
break;
|
|
1139
|
+
}
|
|
1140
|
+
case "nanoid": {
|
|
1141
|
+
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
1142
|
+
}
|
|
1143
|
+
case "toLowerCase":
|
|
1144
|
+
case "toUpperCase":
|
|
1145
|
+
case "trim":
|
|
1146
|
+
break;
|
|
1147
|
+
default:
|
|
1148
|
+
/* @__PURE__ */ ((_) => {
|
|
1149
|
+
})(check);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
return res;
|
|
1154
|
+
}
|
|
1155
|
+
function escapeLiteralCheckValue(literal, refs) {
|
|
1156
|
+
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
1157
|
+
}
|
|
1158
|
+
var ALPHA_NUMERIC = new Set(
|
|
1159
|
+
"ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789"
|
|
1160
|
+
);
|
|
1161
|
+
function escapeNonAlphaNumeric(source) {
|
|
1162
|
+
let result = "";
|
|
1163
|
+
for (let i = 0; i < source.length; i++) {
|
|
1164
|
+
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
1165
|
+
result += "\\";
|
|
1166
|
+
}
|
|
1167
|
+
result += source[i];
|
|
1168
|
+
}
|
|
1169
|
+
return result;
|
|
1170
|
+
}
|
|
1171
|
+
function addFormat(schema, value, message, refs) {
|
|
1172
|
+
var _a22;
|
|
1173
|
+
if (schema.format || ((_a22 = schema.anyOf) == null ? void 0 : _a22.some((x) => x.format))) {
|
|
1174
|
+
if (!schema.anyOf) {
|
|
1175
|
+
schema.anyOf = [];
|
|
1176
|
+
}
|
|
1177
|
+
if (schema.format) {
|
|
1178
|
+
schema.anyOf.push({
|
|
1179
|
+
format: schema.format
|
|
1180
|
+
});
|
|
1181
|
+
delete schema.format;
|
|
1182
|
+
}
|
|
1183
|
+
schema.anyOf.push(__spreadValues({
|
|
1184
|
+
format: value
|
|
1185
|
+
}, message && refs.errorMessages && { errorMessage: { format: message } }));
|
|
1186
|
+
} else {
|
|
1187
|
+
schema.format = value;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
function addPattern(schema, regex, message, refs) {
|
|
1191
|
+
var _a22;
|
|
1192
|
+
if (schema.pattern || ((_a22 = schema.allOf) == null ? void 0 : _a22.some((x) => x.pattern))) {
|
|
1193
|
+
if (!schema.allOf) {
|
|
1194
|
+
schema.allOf = [];
|
|
1195
|
+
}
|
|
1196
|
+
if (schema.pattern) {
|
|
1197
|
+
schema.allOf.push({
|
|
1198
|
+
pattern: schema.pattern
|
|
1199
|
+
});
|
|
1200
|
+
delete schema.pattern;
|
|
1201
|
+
}
|
|
1202
|
+
schema.allOf.push(__spreadValues({
|
|
1203
|
+
pattern: stringifyRegExpWithFlags(regex, refs)
|
|
1204
|
+
}, message && refs.errorMessages && { errorMessage: { pattern: message } }));
|
|
1205
|
+
} else {
|
|
1206
|
+
schema.pattern = stringifyRegExpWithFlags(regex, refs);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
function stringifyRegExpWithFlags(regex, refs) {
|
|
1210
|
+
var _a22;
|
|
1211
|
+
if (!refs.applyRegexFlags || !regex.flags) {
|
|
1212
|
+
return regex.source;
|
|
1213
|
+
}
|
|
1214
|
+
const flags = {
|
|
1215
|
+
i: regex.flags.includes("i"),
|
|
1216
|
+
// Case-insensitive
|
|
1217
|
+
m: regex.flags.includes("m"),
|
|
1218
|
+
// `^` and `$` matches adjacent to newline characters
|
|
1219
|
+
s: regex.flags.includes("s")
|
|
1220
|
+
// `.` matches newlines
|
|
1221
|
+
};
|
|
1222
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
1223
|
+
let pattern = "";
|
|
1224
|
+
let isEscaped = false;
|
|
1225
|
+
let inCharGroup = false;
|
|
1226
|
+
let inCharRange = false;
|
|
1227
|
+
for (let i = 0; i < source.length; i++) {
|
|
1228
|
+
if (isEscaped) {
|
|
1229
|
+
pattern += source[i];
|
|
1230
|
+
isEscaped = false;
|
|
1231
|
+
continue;
|
|
1232
|
+
}
|
|
1233
|
+
if (flags.i) {
|
|
1234
|
+
if (inCharGroup) {
|
|
1235
|
+
if (source[i].match(/[a-z]/)) {
|
|
1236
|
+
if (inCharRange) {
|
|
1237
|
+
pattern += source[i];
|
|
1238
|
+
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
1239
|
+
inCharRange = false;
|
|
1240
|
+
} else if (source[i + 1] === "-" && ((_a22 = source[i + 2]) == null ? void 0 : _a22.match(/[a-z]/))) {
|
|
1241
|
+
pattern += source[i];
|
|
1242
|
+
inCharRange = true;
|
|
1243
|
+
} else {
|
|
1244
|
+
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
1245
|
+
}
|
|
1246
|
+
continue;
|
|
1247
|
+
}
|
|
1248
|
+
} else if (source[i].match(/[a-z]/)) {
|
|
1249
|
+
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
1250
|
+
continue;
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
if (flags.m) {
|
|
1254
|
+
if (source[i] === "^") {
|
|
1255
|
+
pattern += `(^|(?<=[\r
|
|
1256
|
+
]))`;
|
|
1257
|
+
continue;
|
|
1258
|
+
} else if (source[i] === "$") {
|
|
1259
|
+
pattern += `($|(?=[\r
|
|
1260
|
+
]))`;
|
|
1261
|
+
continue;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
if (flags.s && source[i] === ".") {
|
|
1265
|
+
pattern += inCharGroup ? `${source[i]}\r
|
|
1266
|
+
` : `[${source[i]}\r
|
|
1267
|
+
]`;
|
|
1268
|
+
continue;
|
|
1269
|
+
}
|
|
1270
|
+
pattern += source[i];
|
|
1271
|
+
if (source[i] === "\\") {
|
|
1272
|
+
isEscaped = true;
|
|
1273
|
+
} else if (inCharGroup && source[i] === "]") {
|
|
1274
|
+
inCharGroup = false;
|
|
1275
|
+
} else if (!inCharGroup && source[i] === "[") {
|
|
1276
|
+
inCharGroup = true;
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
try {
|
|
1280
|
+
new RegExp(pattern);
|
|
1281
|
+
} catch (e) {
|
|
1282
|
+
console.warn(
|
|
1283
|
+
`Could not convert regex pattern at ${refs.currentPath.join(
|
|
1284
|
+
"/"
|
|
1285
|
+
)} to a flag-independent form! Falling back to the flag-ignorant source`
|
|
1286
|
+
);
|
|
1287
|
+
return regex.source;
|
|
1288
|
+
}
|
|
1289
|
+
return pattern;
|
|
1290
|
+
}
|
|
1291
|
+
function parseRecordDef(def, refs) {
|
|
1292
|
+
var _a22, _b22, _c, _d, _e, _f;
|
|
1293
|
+
const schema = {
|
|
1294
|
+
type: "object",
|
|
1295
|
+
additionalProperties: (_a22 = parseDef(def.valueType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1296
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1297
|
+
}))) != null ? _a22 : refs.allowedAdditionalProperties
|
|
1298
|
+
};
|
|
1299
|
+
if (((_b22 = def.keyType) == null ? void 0 : _b22._def.typeName) === import_v33.ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
1300
|
+
const _a16 = parseStringDef(def.keyType._def, refs), { type } = _a16, keyType = __objRest(_a16, ["type"]);
|
|
1301
|
+
return __spreadProps(__spreadValues({}, schema), {
|
|
1302
|
+
propertyNames: keyType
|
|
1303
|
+
});
|
|
1304
|
+
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) === import_v33.ZodFirstPartyTypeKind.ZodEnum) {
|
|
1305
|
+
return __spreadProps(__spreadValues({}, schema), {
|
|
1306
|
+
propertyNames: {
|
|
1307
|
+
enum: def.keyType._def.values
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1310
|
+
} else if (((_e = def.keyType) == null ? void 0 : _e._def.typeName) === import_v33.ZodFirstPartyTypeKind.ZodBranded && def.keyType._def.type._def.typeName === import_v33.ZodFirstPartyTypeKind.ZodString && ((_f = def.keyType._def.type._def.checks) == null ? void 0 : _f.length)) {
|
|
1311
|
+
const _b16 = parseBrandedDef(
|
|
1312
|
+
def.keyType._def,
|
|
1313
|
+
refs
|
|
1314
|
+
), { type } = _b16, keyType = __objRest(_b16, ["type"]);
|
|
1315
|
+
return __spreadProps(__spreadValues({}, schema), {
|
|
1316
|
+
propertyNames: keyType
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
return schema;
|
|
1320
|
+
}
|
|
1321
|
+
function parseMapDef(def, refs) {
|
|
1322
|
+
if (refs.mapStrategy === "record") {
|
|
1323
|
+
return parseRecordDef(def, refs);
|
|
1324
|
+
}
|
|
1325
|
+
const keys = parseDef(def.keyType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1326
|
+
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
1327
|
+
})) || parseAnyDef();
|
|
1328
|
+
const values = parseDef(def.valueType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1329
|
+
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
1330
|
+
})) || parseAnyDef();
|
|
1331
|
+
return {
|
|
1332
|
+
type: "array",
|
|
1333
|
+
maxItems: 125,
|
|
1334
|
+
items: {
|
|
1335
|
+
type: "array",
|
|
1336
|
+
items: [keys, values],
|
|
1337
|
+
minItems: 2,
|
|
1338
|
+
maxItems: 2
|
|
1339
|
+
}
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
function parseNativeEnumDef(def) {
|
|
1343
|
+
const object = def.values;
|
|
1344
|
+
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
1345
|
+
return typeof object[object[key]] !== "number";
|
|
1346
|
+
});
|
|
1347
|
+
const actualValues = actualKeys.map((key) => object[key]);
|
|
1348
|
+
const parsedTypes = Array.from(
|
|
1349
|
+
new Set(actualValues.map((values) => typeof values))
|
|
1350
|
+
);
|
|
1351
|
+
return {
|
|
1352
|
+
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
1353
|
+
enum: actualValues
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
function parseNeverDef() {
|
|
1357
|
+
return { not: parseAnyDef() };
|
|
1358
|
+
}
|
|
1359
|
+
function parseNullDef() {
|
|
1360
|
+
return {
|
|
1361
|
+
type: "null"
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
var primitiveMappings = {
|
|
1365
|
+
ZodString: "string",
|
|
1366
|
+
ZodNumber: "number",
|
|
1367
|
+
ZodBigInt: "integer",
|
|
1368
|
+
ZodBoolean: "boolean",
|
|
1369
|
+
ZodNull: "null"
|
|
1370
|
+
};
|
|
1371
|
+
function parseUnionDef(def, refs) {
|
|
1372
|
+
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
1373
|
+
if (options.every(
|
|
1374
|
+
(x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length)
|
|
1375
|
+
)) {
|
|
1376
|
+
const types = options.reduce((types2, x) => {
|
|
1377
|
+
const type = primitiveMappings[x._def.typeName];
|
|
1378
|
+
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
1379
|
+
}, []);
|
|
1380
|
+
return {
|
|
1381
|
+
type: types.length > 1 ? types : types[0]
|
|
1382
|
+
};
|
|
1383
|
+
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
1384
|
+
const types = options.reduce(
|
|
1385
|
+
(acc, x) => {
|
|
1386
|
+
const type = typeof x._def.value;
|
|
1387
|
+
switch (type) {
|
|
1388
|
+
case "string":
|
|
1389
|
+
case "number":
|
|
1390
|
+
case "boolean":
|
|
1391
|
+
return [...acc, type];
|
|
1392
|
+
case "bigint":
|
|
1393
|
+
return [...acc, "integer"];
|
|
1394
|
+
case "object":
|
|
1395
|
+
if (x._def.value === null) return [...acc, "null"];
|
|
1396
|
+
case "symbol":
|
|
1397
|
+
case "undefined":
|
|
1398
|
+
case "function":
|
|
1399
|
+
default:
|
|
1400
|
+
return acc;
|
|
1401
|
+
}
|
|
1402
|
+
},
|
|
1403
|
+
[]
|
|
1404
|
+
);
|
|
1405
|
+
if (types.length === options.length) {
|
|
1406
|
+
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
1407
|
+
return {
|
|
1408
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
1409
|
+
enum: options.reduce(
|
|
1410
|
+
(acc, x) => {
|
|
1411
|
+
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
1412
|
+
},
|
|
1413
|
+
[]
|
|
1414
|
+
)
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
1418
|
+
return {
|
|
1419
|
+
type: "string",
|
|
1420
|
+
enum: options.reduce(
|
|
1421
|
+
(acc, x) => [
|
|
1422
|
+
...acc,
|
|
1423
|
+
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
1424
|
+
],
|
|
1425
|
+
[]
|
|
1426
|
+
)
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
return asAnyOf(def, refs);
|
|
1430
|
+
}
|
|
1431
|
+
var asAnyOf = (def, refs) => {
|
|
1432
|
+
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map(
|
|
1433
|
+
(x, i) => parseDef(x._def, __spreadProps(__spreadValues({}, refs), {
|
|
1434
|
+
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
1435
|
+
}))
|
|
1436
|
+
).filter(
|
|
1437
|
+
(x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0)
|
|
1438
|
+
);
|
|
1439
|
+
return anyOf.length ? { anyOf } : void 0;
|
|
1440
|
+
};
|
|
1441
|
+
function parseNullableDef(def, refs) {
|
|
1442
|
+
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(
|
|
1443
|
+
def.innerType._def.typeName
|
|
1444
|
+
) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
1445
|
+
return {
|
|
1446
|
+
type: [
|
|
1447
|
+
primitiveMappings[def.innerType._def.typeName],
|
|
1448
|
+
"null"
|
|
1449
|
+
]
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
const base = parseDef(def.innerType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1453
|
+
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
1454
|
+
}));
|
|
1455
|
+
return base && { anyOf: [base, { type: "null" }] };
|
|
1456
|
+
}
|
|
1457
|
+
function parseNumberDef(def) {
|
|
1458
|
+
const res = {
|
|
1459
|
+
type: "number"
|
|
1460
|
+
};
|
|
1461
|
+
if (!def.checks) return res;
|
|
1462
|
+
for (const check of def.checks) {
|
|
1463
|
+
switch (check.kind) {
|
|
1464
|
+
case "int":
|
|
1465
|
+
res.type = "integer";
|
|
1466
|
+
break;
|
|
1467
|
+
case "min":
|
|
1468
|
+
if (check.inclusive) {
|
|
1469
|
+
res.minimum = check.value;
|
|
1470
|
+
} else {
|
|
1471
|
+
res.exclusiveMinimum = check.value;
|
|
1472
|
+
}
|
|
1473
|
+
break;
|
|
1474
|
+
case "max":
|
|
1475
|
+
if (check.inclusive) {
|
|
1476
|
+
res.maximum = check.value;
|
|
1477
|
+
} else {
|
|
1478
|
+
res.exclusiveMaximum = check.value;
|
|
1479
|
+
}
|
|
1480
|
+
break;
|
|
1481
|
+
case "multipleOf":
|
|
1482
|
+
res.multipleOf = check.value;
|
|
1483
|
+
break;
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
return res;
|
|
1487
|
+
}
|
|
1488
|
+
function parseObjectDef(def, refs) {
|
|
1489
|
+
const result = {
|
|
1490
|
+
type: "object",
|
|
1491
|
+
properties: {}
|
|
1492
|
+
};
|
|
1493
|
+
const required = [];
|
|
1494
|
+
const shape = def.shape();
|
|
1495
|
+
for (const propName in shape) {
|
|
1496
|
+
let propDef = shape[propName];
|
|
1497
|
+
if (propDef === void 0 || propDef._def === void 0) {
|
|
1498
|
+
continue;
|
|
1499
|
+
}
|
|
1500
|
+
const propOptional = safeIsOptional(propDef);
|
|
1501
|
+
const parsedDef = parseDef(propDef._def, __spreadProps(__spreadValues({}, refs), {
|
|
1502
|
+
currentPath: [...refs.currentPath, "properties", propName],
|
|
1503
|
+
propertyPath: [...refs.currentPath, "properties", propName]
|
|
1504
|
+
}));
|
|
1505
|
+
if (parsedDef === void 0) {
|
|
1506
|
+
continue;
|
|
1507
|
+
}
|
|
1508
|
+
result.properties[propName] = parsedDef;
|
|
1509
|
+
if (!propOptional) {
|
|
1510
|
+
required.push(propName);
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
if (required.length) {
|
|
1514
|
+
result.required = required;
|
|
1515
|
+
}
|
|
1516
|
+
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
1517
|
+
if (additionalProperties !== void 0) {
|
|
1518
|
+
result.additionalProperties = additionalProperties;
|
|
1519
|
+
}
|
|
1520
|
+
return result;
|
|
1521
|
+
}
|
|
1522
|
+
function decideAdditionalProperties(def, refs) {
|
|
1523
|
+
if (def.catchall._def.typeName !== "ZodNever") {
|
|
1524
|
+
return parseDef(def.catchall._def, __spreadProps(__spreadValues({}, refs), {
|
|
1525
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1526
|
+
}));
|
|
1527
|
+
}
|
|
1528
|
+
switch (def.unknownKeys) {
|
|
1529
|
+
case "passthrough":
|
|
1530
|
+
return refs.allowedAdditionalProperties;
|
|
1531
|
+
case "strict":
|
|
1532
|
+
return refs.rejectedAdditionalProperties;
|
|
1533
|
+
case "strip":
|
|
1534
|
+
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
function safeIsOptional(schema) {
|
|
1538
|
+
try {
|
|
1539
|
+
return schema.isOptional();
|
|
1540
|
+
} catch (e) {
|
|
1541
|
+
return true;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
var parseOptionalDef = (def, refs) => {
|
|
1545
|
+
var _a22;
|
|
1546
|
+
if (refs.currentPath.toString() === ((_a22 = refs.propertyPath) == null ? void 0 : _a22.toString())) {
|
|
1547
|
+
return parseDef(def.innerType._def, refs);
|
|
1548
|
+
}
|
|
1549
|
+
const innerSchema = parseDef(def.innerType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1550
|
+
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
1551
|
+
}));
|
|
1552
|
+
return innerSchema ? { anyOf: [{ not: parseAnyDef() }, innerSchema] } : parseAnyDef();
|
|
1553
|
+
};
|
|
1554
|
+
var parsePipelineDef = (def, refs) => {
|
|
1555
|
+
if (refs.pipeStrategy === "input") {
|
|
1556
|
+
return parseDef(def.in._def, refs);
|
|
1557
|
+
} else if (refs.pipeStrategy === "output") {
|
|
1558
|
+
return parseDef(def.out._def, refs);
|
|
1559
|
+
}
|
|
1560
|
+
const a = parseDef(def.in._def, __spreadProps(__spreadValues({}, refs), {
|
|
1561
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1562
|
+
}));
|
|
1563
|
+
const b = parseDef(def.out._def, __spreadProps(__spreadValues({}, refs), {
|
|
1564
|
+
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
1565
|
+
}));
|
|
1566
|
+
return {
|
|
1567
|
+
allOf: [a, b].filter((x) => x !== void 0)
|
|
1568
|
+
};
|
|
1569
|
+
};
|
|
1570
|
+
function parsePromiseDef(def, refs) {
|
|
1571
|
+
return parseDef(def.type._def, refs);
|
|
1572
|
+
}
|
|
1573
|
+
function parseSetDef(def, refs) {
|
|
1574
|
+
const items = parseDef(def.valueType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1575
|
+
currentPath: [...refs.currentPath, "items"]
|
|
1576
|
+
}));
|
|
1577
|
+
const schema = {
|
|
1578
|
+
type: "array",
|
|
1579
|
+
uniqueItems: true,
|
|
1580
|
+
items
|
|
1581
|
+
};
|
|
1582
|
+
if (def.minSize) {
|
|
1583
|
+
schema.minItems = def.minSize.value;
|
|
1584
|
+
}
|
|
1585
|
+
if (def.maxSize) {
|
|
1586
|
+
schema.maxItems = def.maxSize.value;
|
|
1587
|
+
}
|
|
1588
|
+
return schema;
|
|
1589
|
+
}
|
|
1590
|
+
function parseTupleDef(def, refs) {
|
|
1591
|
+
if (def.rest) {
|
|
1592
|
+
return {
|
|
1593
|
+
type: "array",
|
|
1594
|
+
minItems: def.items.length,
|
|
1595
|
+
items: def.items.map(
|
|
1596
|
+
(x, i) => parseDef(x._def, __spreadProps(__spreadValues({}, refs), {
|
|
1597
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1598
|
+
}))
|
|
1599
|
+
).reduce(
|
|
1600
|
+
(acc, x) => x === void 0 ? acc : [...acc, x],
|
|
1601
|
+
[]
|
|
1602
|
+
),
|
|
1603
|
+
additionalItems: parseDef(def.rest._def, __spreadProps(__spreadValues({}, refs), {
|
|
1604
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
1605
|
+
}))
|
|
1606
|
+
};
|
|
1607
|
+
} else {
|
|
1608
|
+
return {
|
|
1609
|
+
type: "array",
|
|
1610
|
+
minItems: def.items.length,
|
|
1611
|
+
maxItems: def.items.length,
|
|
1612
|
+
items: def.items.map(
|
|
1613
|
+
(x, i) => parseDef(x._def, __spreadProps(__spreadValues({}, refs), {
|
|
1614
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1615
|
+
}))
|
|
1616
|
+
).reduce(
|
|
1617
|
+
(acc, x) => x === void 0 ? acc : [...acc, x],
|
|
1618
|
+
[]
|
|
1619
|
+
)
|
|
1620
|
+
};
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
function parseUndefinedDef() {
|
|
1624
|
+
return {
|
|
1625
|
+
not: parseAnyDef()
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1628
|
+
function parseUnknownDef() {
|
|
1629
|
+
return parseAnyDef();
|
|
1630
|
+
}
|
|
1631
|
+
var parseReadonlyDef = (def, refs) => {
|
|
1632
|
+
return parseDef(def.innerType._def, refs);
|
|
1633
|
+
};
|
|
1634
|
+
var selectParser = (def, typeName, refs) => {
|
|
1635
|
+
switch (typeName) {
|
|
1636
|
+
case import_v3.ZodFirstPartyTypeKind.ZodString:
|
|
1637
|
+
return parseStringDef(def, refs);
|
|
1638
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNumber:
|
|
1639
|
+
return parseNumberDef(def);
|
|
1640
|
+
case import_v3.ZodFirstPartyTypeKind.ZodObject:
|
|
1641
|
+
return parseObjectDef(def, refs);
|
|
1642
|
+
case import_v3.ZodFirstPartyTypeKind.ZodBigInt:
|
|
1643
|
+
return parseBigintDef(def);
|
|
1644
|
+
case import_v3.ZodFirstPartyTypeKind.ZodBoolean:
|
|
1645
|
+
return parseBooleanDef();
|
|
1646
|
+
case import_v3.ZodFirstPartyTypeKind.ZodDate:
|
|
1647
|
+
return parseDateDef(def, refs);
|
|
1648
|
+
case import_v3.ZodFirstPartyTypeKind.ZodUndefined:
|
|
1649
|
+
return parseUndefinedDef();
|
|
1650
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNull:
|
|
1651
|
+
return parseNullDef();
|
|
1652
|
+
case import_v3.ZodFirstPartyTypeKind.ZodArray:
|
|
1653
|
+
return parseArrayDef(def, refs);
|
|
1654
|
+
case import_v3.ZodFirstPartyTypeKind.ZodUnion:
|
|
1655
|
+
case import_v3.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
|
|
1656
|
+
return parseUnionDef(def, refs);
|
|
1657
|
+
case import_v3.ZodFirstPartyTypeKind.ZodIntersection:
|
|
1658
|
+
return parseIntersectionDef(def, refs);
|
|
1659
|
+
case import_v3.ZodFirstPartyTypeKind.ZodTuple:
|
|
1660
|
+
return parseTupleDef(def, refs);
|
|
1661
|
+
case import_v3.ZodFirstPartyTypeKind.ZodRecord:
|
|
1662
|
+
return parseRecordDef(def, refs);
|
|
1663
|
+
case import_v3.ZodFirstPartyTypeKind.ZodLiteral:
|
|
1664
|
+
return parseLiteralDef(def);
|
|
1665
|
+
case import_v3.ZodFirstPartyTypeKind.ZodEnum:
|
|
1666
|
+
return parseEnumDef(def);
|
|
1667
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNativeEnum:
|
|
1668
|
+
return parseNativeEnumDef(def);
|
|
1669
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNullable:
|
|
1670
|
+
return parseNullableDef(def, refs);
|
|
1671
|
+
case import_v3.ZodFirstPartyTypeKind.ZodOptional:
|
|
1672
|
+
return parseOptionalDef(def, refs);
|
|
1673
|
+
case import_v3.ZodFirstPartyTypeKind.ZodMap:
|
|
1674
|
+
return parseMapDef(def, refs);
|
|
1675
|
+
case import_v3.ZodFirstPartyTypeKind.ZodSet:
|
|
1676
|
+
return parseSetDef(def, refs);
|
|
1677
|
+
case import_v3.ZodFirstPartyTypeKind.ZodLazy:
|
|
1678
|
+
return () => def.getter()._def;
|
|
1679
|
+
case import_v3.ZodFirstPartyTypeKind.ZodPromise:
|
|
1680
|
+
return parsePromiseDef(def, refs);
|
|
1681
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNaN:
|
|
1682
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNever:
|
|
1683
|
+
return parseNeverDef();
|
|
1684
|
+
case import_v3.ZodFirstPartyTypeKind.ZodEffects:
|
|
1685
|
+
return parseEffectsDef(def, refs);
|
|
1686
|
+
case import_v3.ZodFirstPartyTypeKind.ZodAny:
|
|
1687
|
+
return parseAnyDef();
|
|
1688
|
+
case import_v3.ZodFirstPartyTypeKind.ZodUnknown:
|
|
1689
|
+
return parseUnknownDef();
|
|
1690
|
+
case import_v3.ZodFirstPartyTypeKind.ZodDefault:
|
|
1691
|
+
return parseDefaultDef(def, refs);
|
|
1692
|
+
case import_v3.ZodFirstPartyTypeKind.ZodBranded:
|
|
1693
|
+
return parseBrandedDef(def, refs);
|
|
1694
|
+
case import_v3.ZodFirstPartyTypeKind.ZodReadonly:
|
|
1695
|
+
return parseReadonlyDef(def, refs);
|
|
1696
|
+
case import_v3.ZodFirstPartyTypeKind.ZodCatch:
|
|
1697
|
+
return parseCatchDef(def, refs);
|
|
1698
|
+
case import_v3.ZodFirstPartyTypeKind.ZodPipeline:
|
|
1699
|
+
return parsePipelineDef(def, refs);
|
|
1700
|
+
case import_v3.ZodFirstPartyTypeKind.ZodFunction:
|
|
1701
|
+
case import_v3.ZodFirstPartyTypeKind.ZodVoid:
|
|
1702
|
+
case import_v3.ZodFirstPartyTypeKind.ZodSymbol:
|
|
1703
|
+
return void 0;
|
|
1704
|
+
default:
|
|
1705
|
+
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
var getRelativePath = (pathA, pathB) => {
|
|
1709
|
+
let i = 0;
|
|
1710
|
+
for (; i < pathA.length && i < pathB.length; i++) {
|
|
1711
|
+
if (pathA[i] !== pathB[i]) break;
|
|
1712
|
+
}
|
|
1713
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
1714
|
+
};
|
|
1715
|
+
function parseDef(def, refs, forceResolution = false) {
|
|
1716
|
+
var _a22;
|
|
1717
|
+
const seenItem = refs.seen.get(def);
|
|
1718
|
+
if (refs.override) {
|
|
1719
|
+
const overrideResult = (_a22 = refs.override) == null ? void 0 : _a22.call(
|
|
1720
|
+
refs,
|
|
1721
|
+
def,
|
|
1722
|
+
refs,
|
|
1723
|
+
seenItem,
|
|
1724
|
+
forceResolution
|
|
1725
|
+
);
|
|
1726
|
+
if (overrideResult !== ignoreOverride) {
|
|
1727
|
+
return overrideResult;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
if (seenItem && !forceResolution) {
|
|
1731
|
+
const seenSchema = get$ref(seenItem, refs);
|
|
1732
|
+
if (seenSchema !== void 0) {
|
|
1733
|
+
return seenSchema;
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
1737
|
+
refs.seen.set(def, newItem);
|
|
1738
|
+
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
1739
|
+
const jsonSchema2 = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
1740
|
+
if (jsonSchema2) {
|
|
1741
|
+
addMeta(def, refs, jsonSchema2);
|
|
1742
|
+
}
|
|
1743
|
+
if (refs.postProcess) {
|
|
1744
|
+
const postProcessResult = refs.postProcess(jsonSchema2, def, refs);
|
|
1745
|
+
newItem.jsonSchema = jsonSchema2;
|
|
1746
|
+
return postProcessResult;
|
|
1747
|
+
}
|
|
1748
|
+
newItem.jsonSchema = jsonSchema2;
|
|
1749
|
+
return jsonSchema2;
|
|
1750
|
+
}
|
|
1751
|
+
var get$ref = (item, refs) => {
|
|
1752
|
+
switch (refs.$refStrategy) {
|
|
1753
|
+
case "root":
|
|
1754
|
+
return { $ref: item.path.join("/") };
|
|
1755
|
+
case "relative":
|
|
1756
|
+
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
1757
|
+
case "none":
|
|
1758
|
+
case "seen": {
|
|
1759
|
+
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
1760
|
+
console.warn(
|
|
1761
|
+
`Recursive reference detected at ${refs.currentPath.join(
|
|
1762
|
+
"/"
|
|
1763
|
+
)}! Defaulting to any`
|
|
1764
|
+
);
|
|
1765
|
+
return parseAnyDef();
|
|
1766
|
+
}
|
|
1767
|
+
return refs.$refStrategy === "seen" ? parseAnyDef() : void 0;
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
};
|
|
1771
|
+
var addMeta = (def, refs, jsonSchema2) => {
|
|
1772
|
+
if (def.description) {
|
|
1773
|
+
jsonSchema2.description = def.description;
|
|
1774
|
+
}
|
|
1775
|
+
return jsonSchema2;
|
|
1776
|
+
};
|
|
1777
|
+
var getRefs = (options) => {
|
|
1778
|
+
const _options = getDefaultOptions(options);
|
|
1779
|
+
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
1780
|
+
return __spreadProps(__spreadValues({}, _options), {
|
|
1781
|
+
currentPath,
|
|
1782
|
+
propertyPath: void 0,
|
|
1783
|
+
seen: new Map(
|
|
1784
|
+
Object.entries(_options.definitions).map(([name22, def]) => [
|
|
1785
|
+
def._def,
|
|
1786
|
+
{
|
|
1787
|
+
def: def._def,
|
|
1788
|
+
path: [..._options.basePath, _options.definitionPath, name22],
|
|
1789
|
+
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
1790
|
+
jsonSchema: void 0
|
|
1791
|
+
}
|
|
1792
|
+
])
|
|
1793
|
+
)
|
|
1794
|
+
});
|
|
1795
|
+
};
|
|
1796
|
+
var zod3ToJsonSchema = (schema, options) => {
|
|
1797
|
+
var _a22;
|
|
1798
|
+
const refs = getRefs(options);
|
|
1799
|
+
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
|
|
1800
|
+
(acc, [name32, schema2]) => {
|
|
1801
|
+
var _a32;
|
|
1802
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1803
|
+
[name32]: (_a32 = parseDef(
|
|
1804
|
+
schema2._def,
|
|
1805
|
+
__spreadProps(__spreadValues({}, refs), {
|
|
1806
|
+
currentPath: [...refs.basePath, refs.definitionPath, name32]
|
|
1807
|
+
}),
|
|
1808
|
+
true
|
|
1809
|
+
)) != null ? _a32 : parseAnyDef()
|
|
1810
|
+
});
|
|
1811
|
+
},
|
|
1812
|
+
{}
|
|
1813
|
+
) : void 0;
|
|
1814
|
+
const name22 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
1815
|
+
const main = (_a22 = parseDef(
|
|
1816
|
+
schema._def,
|
|
1817
|
+
name22 === void 0 ? refs : __spreadProps(__spreadValues({}, refs), {
|
|
1818
|
+
currentPath: [...refs.basePath, refs.definitionPath, name22]
|
|
1819
|
+
}),
|
|
1820
|
+
false
|
|
1821
|
+
)) != null ? _a22 : parseAnyDef();
|
|
1822
|
+
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
1823
|
+
if (title !== void 0) {
|
|
1824
|
+
main.title = title;
|
|
1825
|
+
}
|
|
1826
|
+
const combined = name22 === void 0 ? definitions ? __spreadProps(__spreadValues({}, main), {
|
|
1827
|
+
[refs.definitionPath]: definitions
|
|
1828
|
+
}) : main : {
|
|
1829
|
+
$ref: [
|
|
1830
|
+
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
1831
|
+
refs.definitionPath,
|
|
1832
|
+
name22
|
|
1833
|
+
].join("/"),
|
|
1834
|
+
[refs.definitionPath]: __spreadProps(__spreadValues({}, definitions), {
|
|
1835
|
+
[name22]: main
|
|
1836
|
+
})
|
|
1837
|
+
};
|
|
1838
|
+
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
1839
|
+
return combined;
|
|
1840
|
+
};
|
|
1841
|
+
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
|
1842
|
+
function jsonSchema(jsonSchema2, {
|
|
1843
|
+
validate
|
|
1844
|
+
} = {}) {
|
|
1845
|
+
return {
|
|
1846
|
+
[schemaSymbol]: true,
|
|
1847
|
+
_type: void 0,
|
|
1848
|
+
// should never be used directly
|
|
1849
|
+
get jsonSchema() {
|
|
1850
|
+
if (typeof jsonSchema2 === "function") {
|
|
1851
|
+
jsonSchema2 = jsonSchema2();
|
|
1852
|
+
}
|
|
1853
|
+
return jsonSchema2;
|
|
1854
|
+
},
|
|
1855
|
+
validate
|
|
1856
|
+
};
|
|
1857
|
+
}
|
|
1858
|
+
function isSchema(value) {
|
|
1859
|
+
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
|
1860
|
+
}
|
|
1861
|
+
function asSchema(schema) {
|
|
1862
|
+
return schema == null ? jsonSchema({ properties: {}, additionalProperties: false }) : isSchema(schema) ? schema : "~standard" in schema ? schema["~standard"].vendor === "zod" ? zodSchema(schema) : standardSchema(schema) : schema();
|
|
1863
|
+
}
|
|
1864
|
+
function standardSchema(standardSchema2) {
|
|
1865
|
+
return jsonSchema(
|
|
1866
|
+
() => standardSchema2["~standard"].jsonSchema.input({
|
|
1867
|
+
target: "draft-07"
|
|
1868
|
+
}),
|
|
1869
|
+
{
|
|
1870
|
+
validate: async (value) => {
|
|
1871
|
+
const result = await standardSchema2["~standard"].validate(value);
|
|
1872
|
+
return "value" in result ? { success: true, value: result.value } : {
|
|
1873
|
+
success: false,
|
|
1874
|
+
error: new TypeValidationError({
|
|
1875
|
+
value,
|
|
1876
|
+
cause: result.issues
|
|
1877
|
+
})
|
|
1878
|
+
};
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
);
|
|
1882
|
+
}
|
|
1883
|
+
function zod3Schema(zodSchema2, options) {
|
|
1884
|
+
var _a22;
|
|
1885
|
+
const useReferences = (_a22 = options == null ? void 0 : options.useReferences) != null ? _a22 : false;
|
|
1886
|
+
return jsonSchema(
|
|
1887
|
+
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
1888
|
+
() => zod3ToJsonSchema(zodSchema2, {
|
|
1889
|
+
$refStrategy: useReferences ? "root" : "none"
|
|
1890
|
+
}),
|
|
1891
|
+
{
|
|
1892
|
+
validate: async (value) => {
|
|
1893
|
+
const result = await zodSchema2.safeParseAsync(value);
|
|
1894
|
+
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
);
|
|
1898
|
+
}
|
|
1899
|
+
function zod4Schema(zodSchema2, options) {
|
|
1900
|
+
var _a22;
|
|
1901
|
+
const useReferences = (_a22 = options == null ? void 0 : options.useReferences) != null ? _a22 : false;
|
|
1902
|
+
return jsonSchema(
|
|
1903
|
+
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
1904
|
+
() => addAdditionalPropertiesToJsonSchema(
|
|
1905
|
+
z4.toJSONSchema(zodSchema2, {
|
|
1906
|
+
target: "draft-7",
|
|
1907
|
+
io: "input",
|
|
1908
|
+
reused: useReferences ? "ref" : "inline"
|
|
1909
|
+
})
|
|
1910
|
+
),
|
|
1911
|
+
{
|
|
1912
|
+
validate: async (value) => {
|
|
1913
|
+
const result = await z4.safeParseAsync(zodSchema2, value);
|
|
1914
|
+
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
);
|
|
1918
|
+
}
|
|
1919
|
+
function isZod4Schema(zodSchema2) {
|
|
1920
|
+
return "_zod" in zodSchema2;
|
|
1921
|
+
}
|
|
1922
|
+
function zodSchema(zodSchema2, options) {
|
|
1923
|
+
if (isZod4Schema(zodSchema2)) {
|
|
1924
|
+
return zod4Schema(zodSchema2, options);
|
|
1925
|
+
} else {
|
|
1926
|
+
return zod3Schema(zodSchema2, options);
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
637
1929
|
async function validateTypes({
|
|
638
1930
|
value,
|
|
639
1931
|
schema
|
|
@@ -648,12 +1940,12 @@ async function safeValidateTypes({
|
|
|
648
1940
|
value,
|
|
649
1941
|
schema
|
|
650
1942
|
}) {
|
|
651
|
-
const
|
|
1943
|
+
const actualSchema = asSchema(schema);
|
|
652
1944
|
try {
|
|
653
|
-
if (
|
|
1945
|
+
if (actualSchema.validate == null) {
|
|
654
1946
|
return { success: true, value, rawValue: value };
|
|
655
1947
|
}
|
|
656
|
-
const result = await
|
|
1948
|
+
const result = await actualSchema.validate(value);
|
|
657
1949
|
if (result.success) {
|
|
658
1950
|
return { success: true, value: result.value, rawValue: value };
|
|
659
1951
|
}
|
|
@@ -736,7 +2028,7 @@ var postJsonToApi = async ({
|
|
|
736
2028
|
failedResponseHandler,
|
|
737
2029
|
successfulResponseHandler,
|
|
738
2030
|
abortSignal,
|
|
739
|
-
fetch
|
|
2031
|
+
fetch: fetch2
|
|
740
2032
|
}) => postToApi({
|
|
741
2033
|
url,
|
|
742
2034
|
headers: __spreadValues({
|
|
@@ -749,7 +2041,7 @@ var postJsonToApi = async ({
|
|
|
749
2041
|
failedResponseHandler,
|
|
750
2042
|
successfulResponseHandler,
|
|
751
2043
|
abortSignal,
|
|
752
|
-
fetch
|
|
2044
|
+
fetch: fetch2
|
|
753
2045
|
});
|
|
754
2046
|
var postToApi = async ({
|
|
755
2047
|
url,
|
|
@@ -758,12 +2050,16 @@ var postToApi = async ({
|
|
|
758
2050
|
successfulResponseHandler,
|
|
759
2051
|
failedResponseHandler,
|
|
760
2052
|
abortSignal,
|
|
761
|
-
fetch = getOriginalFetch2()
|
|
2053
|
+
fetch: fetch2 = getOriginalFetch2()
|
|
762
2054
|
}) => {
|
|
763
2055
|
try {
|
|
764
|
-
const response = await
|
|
2056
|
+
const response = await fetch2(url, {
|
|
765
2057
|
method: "POST",
|
|
766
|
-
headers:
|
|
2058
|
+
headers: withUserAgentSuffix(
|
|
2059
|
+
headers,
|
|
2060
|
+
`ai-sdk/provider-utils/${VERSION}`,
|
|
2061
|
+
getRuntimeEnvironmentUserAgent()
|
|
2062
|
+
),
|
|
767
2063
|
body: body.content,
|
|
768
2064
|
signal: abortSignal
|
|
769
2065
|
});
|
|
@@ -907,15 +2203,6 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
907
2203
|
rawValue: parsedResult.rawValue
|
|
908
2204
|
};
|
|
909
2205
|
};
|
|
910
|
-
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
|
911
|
-
var { btoa, atob } = globalThis;
|
|
912
|
-
function convertUint8ArrayToBase64(array) {
|
|
913
|
-
let latin1string = "";
|
|
914
|
-
for (let i = 0; i < array.length; i++) {
|
|
915
|
-
latin1string += String.fromCodePoint(array[i]);
|
|
916
|
-
}
|
|
917
|
-
return btoa(latin1string);
|
|
918
|
-
}
|
|
919
2206
|
function withoutTrailingSlash(url) {
|
|
920
2207
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
921
2208
|
}
|
|
@@ -996,10 +2283,10 @@ function getFileUrl({
|
|
|
996
2283
|
part,
|
|
997
2284
|
defaultMediaType
|
|
998
2285
|
}) {
|
|
999
|
-
var
|
|
2286
|
+
var _a16, _b16;
|
|
1000
2287
|
if (part.data instanceof Uint8Array) {
|
|
1001
2288
|
const base64 = convertUint8ArrayToBase64(part.data);
|
|
1002
|
-
return `data:${(
|
|
2289
|
+
return `data:${(_a16 = part.mediaType) != null ? _a16 : defaultMediaType};base64,${base64}`;
|
|
1003
2290
|
}
|
|
1004
2291
|
const stringUrl = part.data.toString();
|
|
1005
2292
|
if (isUrl({
|
|
@@ -1008,12 +2295,12 @@ function getFileUrl({
|
|
|
1008
2295
|
})) {
|
|
1009
2296
|
return stringUrl;
|
|
1010
2297
|
}
|
|
1011
|
-
return stringUrl.startsWith("data:") ? stringUrl : `data:${(
|
|
2298
|
+
return stringUrl.startsWith("data:") ? stringUrl : `data:${(_b16 = part.mediaType) != null ? _b16 : defaultMediaType};base64,${stringUrl}`;
|
|
1012
2299
|
}
|
|
1013
2300
|
function getMediaType(dataUrl, defaultMediaType) {
|
|
1014
|
-
var
|
|
2301
|
+
var _a16;
|
|
1015
2302
|
const match = dataUrl.match(/^data:([^;]+)/);
|
|
1016
|
-
return match ? (
|
|
2303
|
+
return match ? (_a16 = match[1]) != null ? _a16 : defaultMediaType : defaultMediaType;
|
|
1017
2304
|
}
|
|
1018
2305
|
function getBase64FromDataUrl(dataUrl) {
|
|
1019
2306
|
const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
|
|
@@ -1021,14 +2308,14 @@ function getBase64FromDataUrl(dataUrl) {
|
|
|
1021
2308
|
}
|
|
1022
2309
|
|
|
1023
2310
|
// src/chat/convert-to-llmgateway-chat-messages.ts
|
|
1024
|
-
function getCacheControl(
|
|
1025
|
-
var
|
|
1026
|
-
const anthropic =
|
|
1027
|
-
const llmgateway2 =
|
|
1028
|
-
return (_c = (
|
|
2311
|
+
function getCacheControl(providerOptions) {
|
|
2312
|
+
var _a16, _b16, _c;
|
|
2313
|
+
const anthropic = providerOptions == null ? void 0 : providerOptions.anthropic;
|
|
2314
|
+
const llmgateway2 = providerOptions == null ? void 0 : providerOptions.llmgateway;
|
|
2315
|
+
return (_c = (_b16 = (_a16 = llmgateway2 == null ? void 0 : llmgateway2.cacheControl) != null ? _a16 : llmgateway2 == null ? void 0 : llmgateway2.cache_control) != null ? _b16 : anthropic == null ? void 0 : anthropic.cacheControl) != null ? _c : anthropic == null ? void 0 : anthropic.cache_control;
|
|
1029
2316
|
}
|
|
1030
2317
|
function convertToLLMGatewayChatMessages(prompt) {
|
|
1031
|
-
var
|
|
2318
|
+
var _a16, _b16, _c;
|
|
1032
2319
|
const messages = [];
|
|
1033
2320
|
for (const { role, content, providerOptions } of prompt) {
|
|
1034
2321
|
switch (role) {
|
|
@@ -1041,8 +2328,8 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
1041
2328
|
break;
|
|
1042
2329
|
}
|
|
1043
2330
|
case "user": {
|
|
1044
|
-
if (content.length === 1 && ((
|
|
1045
|
-
const cacheControl = (
|
|
2331
|
+
if (content.length === 1 && ((_a16 = content[0]) == null ? void 0 : _a16.type) === "text") {
|
|
2332
|
+
const cacheControl = (_b16 = getCacheControl(providerOptions)) != null ? _b16 : getCacheControl(content[0].providerOptions);
|
|
1046
2333
|
const contentWithCacheControl = cacheControl ? [
|
|
1047
2334
|
{
|
|
1048
2335
|
type: "text",
|
|
@@ -1059,8 +2346,8 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
1059
2346
|
const messageCacheControl = getCacheControl(providerOptions);
|
|
1060
2347
|
const contentParts = content.map(
|
|
1061
2348
|
(part) => {
|
|
1062
|
-
var
|
|
1063
|
-
const cacheControl = (
|
|
2349
|
+
var _a17, _b17, _c2, _d, _e, _f;
|
|
2350
|
+
const cacheControl = (_a17 = getCacheControl(part.providerOptions)) != null ? _a17 : messageCacheControl;
|
|
1064
2351
|
switch (part.type) {
|
|
1065
2352
|
case "text":
|
|
1066
2353
|
return {
|
|
@@ -1070,7 +2357,7 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
1070
2357
|
cache_control: cacheControl
|
|
1071
2358
|
};
|
|
1072
2359
|
case "file": {
|
|
1073
|
-
if ((
|
|
2360
|
+
if ((_b17 = part.mediaType) == null ? void 0 : _b17.startsWith("image/")) {
|
|
1074
2361
|
const url = getFileUrl({
|
|
1075
2362
|
part,
|
|
1076
2363
|
defaultMediaType: "image/jpeg"
|
|
@@ -1169,7 +2456,7 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
1169
2456
|
role: "assistant",
|
|
1170
2457
|
content: text,
|
|
1171
2458
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
1172
|
-
|
|
2459
|
+
reasoningText: reasoning || void 0,
|
|
1173
2460
|
reasoning_details: reasoningDetails.length > 0 ? reasoningDetails : void 0,
|
|
1174
2461
|
cache_control: getCacheControl(providerOptions)
|
|
1175
2462
|
});
|
|
@@ -1274,6 +2561,7 @@ var LLMGatewayNonStreamChatCompletionResponseSchema = LLMGatewayChatCompletionBa
|
|
|
1274
2561
|
role: import_v45.z.literal("assistant"),
|
|
1275
2562
|
content: import_v45.z.string().nullable().optional(),
|
|
1276
2563
|
reasoning: import_v45.z.string().nullable().optional(),
|
|
2564
|
+
reasoningText: import_v45.z.string().nullable().optional(),
|
|
1277
2565
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1278
2566
|
images: ImageResponseArraySchema.nullish(),
|
|
1279
2567
|
tool_calls: import_v45.z.array(
|
|
@@ -1314,6 +2602,7 @@ var LLMGatewayStreamChatCompletionChunkSchema = import_v45.z.union([
|
|
|
1314
2602
|
role: import_v45.z.enum(["assistant"]).optional(),
|
|
1315
2603
|
content: import_v45.z.string().nullish(),
|
|
1316
2604
|
reasoning: import_v45.z.string().nullish().optional(),
|
|
2605
|
+
reasoningText: import_v45.z.string().nullish().optional(),
|
|
1317
2606
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1318
2607
|
images: ImageResponseArraySchema.nullish(),
|
|
1319
2608
|
tool_calls: import_v45.z.array(
|
|
@@ -1406,10 +2695,8 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1406
2695
|
messages: convertToLLMGatewayChatMessages(prompt),
|
|
1407
2696
|
// LLMGateway specific settings:
|
|
1408
2697
|
include_reasoning: this.settings.includeReasoning,
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
usage: this.settings.usage,
|
|
1412
|
-
image_config: this.settings.image_config
|
|
2698
|
+
reasoningText: this.settings.reasoningText,
|
|
2699
|
+
usage: this.settings.usage
|
|
1413
2700
|
}, this.config.extraBody), this.settings.extraBody);
|
|
1414
2701
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
|
|
1415
2702
|
if ("schema" in responseFormat && responseFormat.schema) {
|
|
@@ -1435,7 +2722,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1435
2722
|
function: {
|
|
1436
2723
|
name: tool.name,
|
|
1437
2724
|
description: tool.type,
|
|
1438
|
-
|
|
2725
|
+
inputSchema: tool.inputSchema
|
|
1439
2726
|
}
|
|
1440
2727
|
}));
|
|
1441
2728
|
return __spreadProps(__spreadValues({}, baseArgs), {
|
|
@@ -1446,10 +2733,11 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1446
2733
|
return baseArgs;
|
|
1447
2734
|
}
|
|
1448
2735
|
async doGenerate(options) {
|
|
1449
|
-
var
|
|
2736
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
1450
2737
|
const providerOptions = options.providerOptions || {};
|
|
1451
2738
|
const llmgatewayOptions = providerOptions.llmgateway || {};
|
|
1452
2739
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
|
|
2740
|
+
const includeUsageAccounting = ((_a16 = args.usage) == null ? void 0 : _a16.include) === true;
|
|
1453
2741
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
1454
2742
|
url: this.config.url({
|
|
1455
2743
|
path: "/chat/completions",
|
|
@@ -1469,11 +2757,11 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1469
2757
|
throw new Error("No choice in response");
|
|
1470
2758
|
}
|
|
1471
2759
|
const usageInfo = response.usage ? {
|
|
1472
|
-
inputTokens: (
|
|
1473
|
-
outputTokens: (
|
|
1474
|
-
totalTokens: ((
|
|
1475
|
-
reasoningTokens: (
|
|
1476
|
-
cachedInputTokens: (
|
|
2760
|
+
inputTokens: (_b16 = response.usage.prompt_tokens) != null ? _b16 : 0,
|
|
2761
|
+
outputTokens: (_c = response.usage.completion_tokens) != null ? _c : 0,
|
|
2762
|
+
totalTokens: ((_d = response.usage.prompt_tokens) != null ? _d : 0) + ((_e = response.usage.completion_tokens) != null ? _e : 0),
|
|
2763
|
+
reasoningTokens: (_g = (_f = response.usage.completion_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : 0,
|
|
2764
|
+
cachedInputTokens: (_i = (_h = response.usage.prompt_tokens_details) == null ? void 0 : _h.cached_tokens) != null ? _i : 0
|
|
1477
2765
|
} : {
|
|
1478
2766
|
inputTokens: 0,
|
|
1479
2767
|
outputTokens: 0,
|
|
@@ -1481,7 +2769,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1481
2769
|
reasoningTokens: 0,
|
|
1482
2770
|
cachedInputTokens: 0
|
|
1483
2771
|
};
|
|
1484
|
-
const reasoningDetails = (
|
|
2772
|
+
const reasoningDetails = (_j = choice.message.reasoning_details) != null ? _j : [];
|
|
1485
2773
|
const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
1486
2774
|
switch (detail.type) {
|
|
1487
2775
|
case "reasoning.text" /* Text */: {
|
|
@@ -1519,10 +2807,10 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1519
2807
|
return null;
|
|
1520
2808
|
}).filter(
|
|
1521
2809
|
(p) => p !== null
|
|
1522
|
-
) : choice.message.
|
|
2810
|
+
) : choice.message.reasoningText ? [
|
|
1523
2811
|
{
|
|
1524
2812
|
type: "reasoning",
|
|
1525
|
-
text: choice.message.
|
|
2813
|
+
text: choice.message.reasoningText
|
|
1526
2814
|
}
|
|
1527
2815
|
] : [];
|
|
1528
2816
|
const content = [];
|
|
@@ -1537,7 +2825,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1537
2825
|
for (const toolCall of choice.message.tool_calls) {
|
|
1538
2826
|
content.push({
|
|
1539
2827
|
type: "tool-call",
|
|
1540
|
-
toolCallId: (
|
|
2828
|
+
toolCallId: (_k = toolCall.id) != null ? _k : generateId(),
|
|
1541
2829
|
toolName: toolCall.function.name,
|
|
1542
2830
|
input: toolCall.function.arguments
|
|
1543
2831
|
});
|
|
@@ -1562,7 +2850,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1562
2850
|
url: annotation.url_citation.url,
|
|
1563
2851
|
title: annotation.url_citation.title,
|
|
1564
2852
|
providerMetadata: {
|
|
1565
|
-
|
|
2853
|
+
llmgateway: {
|
|
1566
2854
|
content: annotation.url_citation.content || ""
|
|
1567
2855
|
}
|
|
1568
2856
|
}
|
|
@@ -1575,25 +2863,25 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1575
2863
|
finishReason: mapLLMGatewayFinishReason(choice.finish_reason),
|
|
1576
2864
|
usage: usageInfo,
|
|
1577
2865
|
warnings: [],
|
|
1578
|
-
providerMetadata: {
|
|
2866
|
+
providerMetadata: includeUsageAccounting ? {
|
|
1579
2867
|
llmgateway: {
|
|
1580
2868
|
usage: {
|
|
1581
|
-
promptTokens: (
|
|
1582
|
-
completionTokens: (
|
|
1583
|
-
totalTokens: (
|
|
1584
|
-
cost: (
|
|
2869
|
+
promptTokens: (_l = usageInfo.inputTokens) != null ? _l : 0,
|
|
2870
|
+
completionTokens: (_m = usageInfo.outputTokens) != null ? _m : 0,
|
|
2871
|
+
totalTokens: (_n = usageInfo.totalTokens) != null ? _n : 0,
|
|
2872
|
+
cost: (_o = response.usage) == null ? void 0 : _o.cost,
|
|
1585
2873
|
promptTokensDetails: {
|
|
1586
|
-
cachedTokens: (
|
|
2874
|
+
cachedTokens: (_r = (_q = (_p = response.usage) == null ? void 0 : _p.prompt_tokens_details) == null ? void 0 : _q.cached_tokens) != null ? _r : 0
|
|
1587
2875
|
},
|
|
1588
2876
|
completionTokensDetails: {
|
|
1589
|
-
reasoningTokens: (
|
|
2877
|
+
reasoningTokens: (_u = (_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? _u : 0
|
|
1590
2878
|
},
|
|
1591
2879
|
costDetails: {
|
|
1592
|
-
upstreamInferenceCost: (
|
|
2880
|
+
upstreamInferenceCost: (_x = (_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? _x : 0
|
|
1593
2881
|
}
|
|
1594
2882
|
}
|
|
1595
2883
|
}
|
|
1596
|
-
},
|
|
2884
|
+
} : void 0,
|
|
1597
2885
|
request: { body: args },
|
|
1598
2886
|
response: {
|
|
1599
2887
|
id: response.id,
|
|
@@ -1603,7 +2891,6 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1603
2891
|
};
|
|
1604
2892
|
}
|
|
1605
2893
|
async doStream(options) {
|
|
1606
|
-
var _a15;
|
|
1607
2894
|
const providerOptions = options.providerOptions || {};
|
|
1608
2895
|
const llmgatewayOptions = providerOptions.llmgateway || {};
|
|
1609
2896
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
|
|
@@ -1616,9 +2903,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1616
2903
|
body: __spreadProps(__spreadValues({}, args), {
|
|
1617
2904
|
stream: true,
|
|
1618
2905
|
// only include stream_options when in strict compatibility mode:
|
|
1619
|
-
stream_options: this.config.compatibility === "strict" ?
|
|
1620
|
-
include_usage: true
|
|
1621
|
-
}, ((_a15 = this.settings.usage) == null ? void 0 : _a15.include) ? { include_usage: true } : {}) : void 0
|
|
2906
|
+
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
1622
2907
|
}),
|
|
1623
2908
|
failedResponseHandler: llmgatewayFailedResponseHandler,
|
|
1624
2909
|
successfulResponseHandler: createEventSourceResponseHandler(
|
|
@@ -1646,7 +2931,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1646
2931
|
stream: response.pipeThrough(
|
|
1647
2932
|
new TransformStream({
|
|
1648
2933
|
transform(chunk, controller) {
|
|
1649
|
-
var _a16,
|
|
2934
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1650
2935
|
if (!chunk.success) {
|
|
1651
2936
|
finishReason = "error";
|
|
1652
2937
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -1685,7 +2970,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1685
2970
|
}
|
|
1686
2971
|
llmgatewayUsage.completionTokens = value.usage.completion_tokens;
|
|
1687
2972
|
if (value.usage.completion_tokens_details) {
|
|
1688
|
-
const reasoningTokens = (
|
|
2973
|
+
const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
|
|
1689
2974
|
usage.reasoningTokens = reasoningTokens;
|
|
1690
2975
|
llmgatewayUsage.completionTokensDetails = {
|
|
1691
2976
|
reasoningTokens
|
|
@@ -1744,8 +3029,10 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1744
3029
|
}
|
|
1745
3030
|
}
|
|
1746
3031
|
}
|
|
1747
|
-
} else if (delta.
|
|
1748
|
-
emitReasoningChunk(
|
|
3032
|
+
} else if (delta.reasoningText != null || "reasoning" in delta && typeof delta.reasoning === "string") {
|
|
3033
|
+
emitReasoningChunk(
|
|
3034
|
+
(_d = (_c = delta.reasoningText) != null ? _c : "reasoning" in delta && typeof delta.reasoning === "string" ? delta.reasoning : void 0) != null ? _d : ""
|
|
3035
|
+
);
|
|
1749
3036
|
}
|
|
1750
3037
|
if (delta.content != null) {
|
|
1751
3038
|
if (!textStarted) {
|
|
@@ -1764,7 +3051,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1764
3051
|
}
|
|
1765
3052
|
if (delta.tool_calls != null) {
|
|
1766
3053
|
for (const toolCallDelta of delta.tool_calls) {
|
|
1767
|
-
const index = (
|
|
3054
|
+
const index = (_e = toolCallDelta.index) != null ? _e : toolCalls.length - 1;
|
|
1768
3055
|
if (toolCalls[index] == null) {
|
|
1769
3056
|
if (toolCallDelta.type !== "function") {
|
|
1770
3057
|
throw new InvalidResponseDataError({
|
|
@@ -1778,7 +3065,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1778
3065
|
message: `Expected 'id' to be a string.`
|
|
1779
3066
|
});
|
|
1780
3067
|
}
|
|
1781
|
-
if (((
|
|
3068
|
+
if (((_f = toolCallDelta.function) == null ? void 0 : _f.name) == null) {
|
|
1782
3069
|
throw new InvalidResponseDataError({
|
|
1783
3070
|
data: toolCallDelta,
|
|
1784
3071
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -1789,7 +3076,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1789
3076
|
type: "function",
|
|
1790
3077
|
function: {
|
|
1791
3078
|
name: toolCallDelta.function.name,
|
|
1792
|
-
arguments: (
|
|
3079
|
+
arguments: (_g = toolCallDelta.function.arguments) != null ? _g : ""
|
|
1793
3080
|
},
|
|
1794
3081
|
inputStarted: false,
|
|
1795
3082
|
sent: false
|
|
@@ -1798,7 +3085,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1798
3085
|
if (toolCall2 == null) {
|
|
1799
3086
|
throw new Error("Tool call is missing");
|
|
1800
3087
|
}
|
|
1801
|
-
if (((
|
|
3088
|
+
if (((_h = toolCall2.function) == null ? void 0 : _h.name) != null && ((_i = toolCall2.function) == null ? void 0 : _i.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
|
|
1802
3089
|
toolCall2.inputStarted = true;
|
|
1803
3090
|
controller.enqueue({
|
|
1804
3091
|
type: "tool-input-start",
|
|
@@ -1836,18 +3123,18 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1836
3123
|
toolName: toolCall.function.name
|
|
1837
3124
|
});
|
|
1838
3125
|
}
|
|
1839
|
-
if (((
|
|
1840
|
-
toolCall.function.arguments += (
|
|
3126
|
+
if (((_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null) {
|
|
3127
|
+
toolCall.function.arguments += (_l = (_k = toolCallDelta.function) == null ? void 0 : _k.arguments) != null ? _l : "";
|
|
1841
3128
|
}
|
|
1842
3129
|
controller.enqueue({
|
|
1843
3130
|
type: "tool-input-delta",
|
|
1844
3131
|
id: toolCall.id,
|
|
1845
|
-
delta: (
|
|
3132
|
+
delta: (_m = toolCallDelta.function.arguments) != null ? _m : ""
|
|
1846
3133
|
});
|
|
1847
|
-
if (((
|
|
3134
|
+
if (((_n = toolCall.function) == null ? void 0 : _n.name) != null && ((_o = toolCall.function) == null ? void 0 : _o.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
1848
3135
|
controller.enqueue({
|
|
1849
3136
|
type: "tool-call",
|
|
1850
|
-
toolCallId: (
|
|
3137
|
+
toolCallId: (_p = toolCall.id) != null ? _p : generateId(),
|
|
1851
3138
|
toolName: toolCall.function.name,
|
|
1852
3139
|
input: toolCall.function.arguments
|
|
1853
3140
|
});
|
|
@@ -2025,7 +3312,7 @@ var LLMGatewayCompletionChunkSchema = import_v46.z.union([
|
|
|
2025
3312
|
choices: import_v46.z.array(
|
|
2026
3313
|
import_v46.z.object({
|
|
2027
3314
|
text: import_v46.z.string(),
|
|
2028
|
-
|
|
3315
|
+
reasoningText: import_v46.z.string().nullish().optional(),
|
|
2029
3316
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
2030
3317
|
finish_reason: import_v46.z.string().nullish(),
|
|
2031
3318
|
index: import_v46.z.number().nullish(),
|
|
@@ -2121,13 +3408,11 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
2121
3408
|
prompt: completionPrompt,
|
|
2122
3409
|
// LLMGateway specific settings:
|
|
2123
3410
|
include_reasoning: this.settings.includeReasoning,
|
|
2124
|
-
|
|
2125
|
-
reasoning_effort: this.settings.reasoning_effort,
|
|
2126
|
-
image_config: this.settings.image_config
|
|
3411
|
+
reasoningText: this.settings.reasoningText
|
|
2127
3412
|
}, this.config.extraBody), this.settings.extraBody);
|
|
2128
3413
|
}
|
|
2129
3414
|
async doGenerate(options) {
|
|
2130
|
-
var
|
|
3415
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
2131
3416
|
const providerOptions = options.providerOptions || {};
|
|
2132
3417
|
const llmgatewayOptions = providerOptions.llmgateway || {};
|
|
2133
3418
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
|
|
@@ -2156,12 +3441,12 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
2156
3441
|
content: [
|
|
2157
3442
|
{
|
|
2158
3443
|
type: "text",
|
|
2159
|
-
text: (
|
|
3444
|
+
text: (_a16 = choice.text) != null ? _a16 : ""
|
|
2160
3445
|
}
|
|
2161
3446
|
],
|
|
2162
3447
|
finishReason: mapLLMGatewayFinishReason(choice.finish_reason),
|
|
2163
3448
|
usage: {
|
|
2164
|
-
inputTokens: (_c = (
|
|
3449
|
+
inputTokens: (_c = (_b16 = response.usage) == null ? void 0 : _b16.prompt_tokens) != null ? _c : 0,
|
|
2165
3450
|
outputTokens: (_e = (_d = response.usage) == null ? void 0 : _d.completion_tokens) != null ? _e : 0,
|
|
2166
3451
|
totalTokens: ((_g = (_f = response.usage) == null ? void 0 : _f.prompt_tokens) != null ? _g : 0) + ((_i = (_h = response.usage) == null ? void 0 : _h.completion_tokens) != null ? _i : 0),
|
|
2167
3452
|
reasoningTokens: (_l = (_k = (_j = response.usage) == null ? void 0 : _j.completion_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : 0,
|
|
@@ -2208,7 +3493,7 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
2208
3493
|
stream: response.pipeThrough(
|
|
2209
3494
|
new TransformStream({
|
|
2210
3495
|
transform(chunk, controller) {
|
|
2211
|
-
var
|
|
3496
|
+
var _a16, _b16;
|
|
2212
3497
|
if (!chunk.success) {
|
|
2213
3498
|
finishReason = "error";
|
|
2214
3499
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -2226,7 +3511,7 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
2226
3511
|
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
2227
3512
|
llmgatewayUsage.promptTokens = value.usage.prompt_tokens;
|
|
2228
3513
|
if (value.usage.prompt_tokens_details) {
|
|
2229
|
-
const cachedInputTokens = (
|
|
3514
|
+
const cachedInputTokens = (_a16 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a16 : 0;
|
|
2230
3515
|
usage.cachedInputTokens = cachedInputTokens;
|
|
2231
3516
|
llmgatewayUsage.promptTokensDetails = {
|
|
2232
3517
|
cachedTokens: cachedInputTokens
|
|
@@ -2234,7 +3519,7 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
2234
3519
|
}
|
|
2235
3520
|
llmgatewayUsage.completionTokens = value.usage.completion_tokens;
|
|
2236
3521
|
if (value.usage.completion_tokens_details) {
|
|
2237
|
-
const reasoningTokens = (
|
|
3522
|
+
const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
|
|
2238
3523
|
usage.reasoningTokens = reasoningTokens;
|
|
2239
3524
|
llmgatewayUsage.completionTokensDetails = {
|
|
2240
3525
|
reasoningTokens
|
|
@@ -2282,8 +3567,8 @@ var LLMGateway = class {
|
|
|
2282
3567
|
* Creates a new LLMGateway provider instance.
|
|
2283
3568
|
*/
|
|
2284
3569
|
constructor(options = {}) {
|
|
2285
|
-
var
|
|
2286
|
-
this.baseURL = (
|
|
3570
|
+
var _a16, _b16;
|
|
3571
|
+
this.baseURL = (_b16 = withoutTrailingSlash((_a16 = options.baseURL) != null ? _a16 : options.baseUrl)) != null ? _b16 : "https://api.llmgateway.io/v1";
|
|
2287
3572
|
this.apiKey = options.apiKey;
|
|
2288
3573
|
this.headers = options.headers;
|
|
2289
3574
|
}
|
|
@@ -2319,8 +3604,8 @@ var LLMGateway = class {
|
|
|
2319
3604
|
|
|
2320
3605
|
// src/provider.ts
|
|
2321
3606
|
function createLLMGateway(options = {}) {
|
|
2322
|
-
var
|
|
2323
|
-
const baseURL = (_c = (
|
|
3607
|
+
var _a16, _b16, _c, _d;
|
|
3608
|
+
const baseURL = (_c = (_b16 = withoutTrailingSlash((_a16 = options.baseURL) != null ? _a16 : options.baseUrl)) != null ? _b16 : process.env.LLM_GATEWAY_API_BASE) != null ? _c : "https://api.llmgateway.io/v1";
|
|
2324
3609
|
const compatibility = (_d = options.compatibility) != null ? _d : "compatible";
|
|
2325
3610
|
const getHeaders = () => __spreadValues({
|
|
2326
3611
|
Authorization: `Bearer ${loadApiKey({
|