@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/internal/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") {
|
|
@@ -79,11 +91,12 @@ var ReasoningDetailsWithUnknownSchema = import_v4.z.union([
|
|
|
79
91
|
]);
|
|
80
92
|
var ReasoningDetailArraySchema = import_v4.z.array(ReasoningDetailsWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
81
93
|
|
|
82
|
-
// node_modules/.pnpm/@ai-sdk+provider@
|
|
94
|
+
// node_modules/.pnpm/@ai-sdk+provider@3.0.2/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
83
95
|
var marker = "vercel.ai.error";
|
|
84
96
|
var symbol = Symbol.for(marker);
|
|
85
97
|
var _a;
|
|
86
|
-
var
|
|
98
|
+
var _b;
|
|
99
|
+
var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
|
|
87
100
|
/**
|
|
88
101
|
* Creates an AI SDK Error.
|
|
89
102
|
*
|
|
@@ -93,13 +106,13 @@ var _AISDKError = class _AISDKError2 extends Error {
|
|
|
93
106
|
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
94
107
|
*/
|
|
95
108
|
constructor({
|
|
96
|
-
name:
|
|
109
|
+
name: name142,
|
|
97
110
|
message,
|
|
98
111
|
cause
|
|
99
112
|
}) {
|
|
100
113
|
super(message);
|
|
101
114
|
this[_a] = true;
|
|
102
|
-
this.name =
|
|
115
|
+
this.name = name142;
|
|
103
116
|
this.cause = cause;
|
|
104
117
|
}
|
|
105
118
|
/**
|
|
@@ -108,20 +121,19 @@ var _AISDKError = class _AISDKError2 extends Error {
|
|
|
108
121
|
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
109
122
|
*/
|
|
110
123
|
static isInstance(error) {
|
|
111
|
-
return
|
|
124
|
+
return _AISDKError.hasMarker(error, marker);
|
|
112
125
|
}
|
|
113
|
-
static hasMarker(error,
|
|
114
|
-
const markerSymbol = Symbol.for(
|
|
126
|
+
static hasMarker(error, marker152) {
|
|
127
|
+
const markerSymbol = Symbol.for(marker152);
|
|
115
128
|
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
116
129
|
}
|
|
117
130
|
};
|
|
118
|
-
_a = symbol;
|
|
119
|
-
var AISDKError = _AISDKError;
|
|
120
131
|
var name = "AI_APICallError";
|
|
121
132
|
var marker2 = `vercel.ai.error.${name}`;
|
|
122
133
|
var symbol2 = Symbol.for(marker2);
|
|
123
134
|
var _a2;
|
|
124
|
-
var
|
|
135
|
+
var _b2;
|
|
136
|
+
var APICallError = class extends (_b2 = AISDKError, _a2 = symbol2, _b2) {
|
|
125
137
|
constructor({
|
|
126
138
|
message,
|
|
127
139
|
url,
|
|
@@ -151,12 +163,12 @@ var APICallError = class extends AISDKError {
|
|
|
151
163
|
return AISDKError.hasMarker(error, marker2);
|
|
152
164
|
}
|
|
153
165
|
};
|
|
154
|
-
_a2 = symbol2;
|
|
155
166
|
var name2 = "AI_EmptyResponseBodyError";
|
|
156
167
|
var marker3 = `vercel.ai.error.${name2}`;
|
|
157
168
|
var symbol3 = Symbol.for(marker3);
|
|
158
169
|
var _a3;
|
|
159
|
-
var
|
|
170
|
+
var _b3;
|
|
171
|
+
var EmptyResponseBodyError = class extends (_b3 = AISDKError, _a3 = symbol3, _b3) {
|
|
160
172
|
// used in isInstance
|
|
161
173
|
constructor({ message = "Empty response body" } = {}) {
|
|
162
174
|
super({ name: name2, message });
|
|
@@ -166,7 +178,6 @@ var EmptyResponseBodyError = class extends AISDKError {
|
|
|
166
178
|
return AISDKError.hasMarker(error, marker3);
|
|
167
179
|
}
|
|
168
180
|
};
|
|
169
|
-
_a3 = symbol3;
|
|
170
181
|
function getErrorMessage(error) {
|
|
171
182
|
if (error == null) {
|
|
172
183
|
return "unknown error";
|
|
@@ -183,7 +194,8 @@ var name3 = "AI_InvalidArgumentError";
|
|
|
183
194
|
var marker4 = `vercel.ai.error.${name3}`;
|
|
184
195
|
var symbol4 = Symbol.for(marker4);
|
|
185
196
|
var _a4;
|
|
186
|
-
var
|
|
197
|
+
var _b4;
|
|
198
|
+
var InvalidArgumentError = class extends (_b4 = AISDKError, _a4 = symbol4, _b4) {
|
|
187
199
|
constructor({
|
|
188
200
|
message,
|
|
189
201
|
cause,
|
|
@@ -197,12 +209,12 @@ var InvalidArgumentError = class extends AISDKError {
|
|
|
197
209
|
return AISDKError.hasMarker(error, marker4);
|
|
198
210
|
}
|
|
199
211
|
};
|
|
200
|
-
_a4 = symbol4;
|
|
201
212
|
var name4 = "AI_InvalidPromptError";
|
|
202
213
|
var marker5 = `vercel.ai.error.${name4}`;
|
|
203
214
|
var symbol5 = Symbol.for(marker5);
|
|
204
215
|
var _a5;
|
|
205
|
-
var
|
|
216
|
+
var _b5;
|
|
217
|
+
var InvalidPromptError = class extends (_b5 = AISDKError, _a5 = symbol5, _b5) {
|
|
206
218
|
constructor({
|
|
207
219
|
prompt,
|
|
208
220
|
message,
|
|
@@ -216,12 +228,12 @@ var InvalidPromptError = class extends AISDKError {
|
|
|
216
228
|
return AISDKError.hasMarker(error, marker5);
|
|
217
229
|
}
|
|
218
230
|
};
|
|
219
|
-
_a5 = symbol5;
|
|
220
231
|
var name5 = "AI_InvalidResponseDataError";
|
|
221
232
|
var marker6 = `vercel.ai.error.${name5}`;
|
|
222
233
|
var symbol6 = Symbol.for(marker6);
|
|
223
234
|
var _a6;
|
|
224
|
-
var
|
|
235
|
+
var _b6;
|
|
236
|
+
var InvalidResponseDataError = class extends (_b6 = AISDKError, _a6 = symbol6, _b6) {
|
|
225
237
|
constructor({
|
|
226
238
|
data,
|
|
227
239
|
message = `Invalid response data: ${JSON.stringify(data)}.`
|
|
@@ -234,12 +246,12 @@ var InvalidResponseDataError = class extends AISDKError {
|
|
|
234
246
|
return AISDKError.hasMarker(error, marker6);
|
|
235
247
|
}
|
|
236
248
|
};
|
|
237
|
-
_a6 = symbol6;
|
|
238
249
|
var name6 = "AI_JSONParseError";
|
|
239
250
|
var marker7 = `vercel.ai.error.${name6}`;
|
|
240
251
|
var symbol7 = Symbol.for(marker7);
|
|
241
252
|
var _a7;
|
|
242
|
-
var
|
|
253
|
+
var _b7;
|
|
254
|
+
var JSONParseError = class extends (_b7 = AISDKError, _a7 = symbol7, _b7) {
|
|
243
255
|
constructor({ text, cause }) {
|
|
244
256
|
super({
|
|
245
257
|
name: name6,
|
|
@@ -254,37 +266,101 @@ Error message: ${getErrorMessage(cause)}`,
|
|
|
254
266
|
return AISDKError.hasMarker(error, marker7);
|
|
255
267
|
}
|
|
256
268
|
};
|
|
257
|
-
_a7 = symbol7;
|
|
258
269
|
var name7 = "AI_LoadAPIKeyError";
|
|
259
270
|
var marker8 = `vercel.ai.error.${name7}`;
|
|
260
271
|
var symbol8 = Symbol.for(marker8);
|
|
261
272
|
var _a8;
|
|
262
|
-
|
|
273
|
+
var _b8;
|
|
274
|
+
var LoadAPIKeyError = class extends (_b8 = AISDKError, _a8 = symbol8, _b8) {
|
|
275
|
+
// used in isInstance
|
|
276
|
+
constructor({ message }) {
|
|
277
|
+
super({ name: name7, message });
|
|
278
|
+
this[_a8] = true;
|
|
279
|
+
}
|
|
280
|
+
static isInstance(error) {
|
|
281
|
+
return AISDKError.hasMarker(error, marker8);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
263
284
|
var name8 = "AI_LoadSettingError";
|
|
264
285
|
var marker9 = `vercel.ai.error.${name8}`;
|
|
265
286
|
var symbol9 = Symbol.for(marker9);
|
|
266
287
|
var _a9;
|
|
267
|
-
|
|
288
|
+
var _b9;
|
|
289
|
+
var LoadSettingError = class extends (_b9 = AISDKError, _a9 = symbol9, _b9) {
|
|
290
|
+
// used in isInstance
|
|
291
|
+
constructor({ message }) {
|
|
292
|
+
super({ name: name8, message });
|
|
293
|
+
this[_a9] = true;
|
|
294
|
+
}
|
|
295
|
+
static isInstance(error) {
|
|
296
|
+
return AISDKError.hasMarker(error, marker9);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
268
299
|
var name9 = "AI_NoContentGeneratedError";
|
|
269
300
|
var marker10 = `vercel.ai.error.${name9}`;
|
|
270
301
|
var symbol10 = Symbol.for(marker10);
|
|
271
302
|
var _a10;
|
|
272
|
-
|
|
303
|
+
var _b10;
|
|
304
|
+
var NoContentGeneratedError = class extends (_b10 = AISDKError, _a10 = symbol10, _b10) {
|
|
305
|
+
// used in isInstance
|
|
306
|
+
constructor({
|
|
307
|
+
message = "No content generated."
|
|
308
|
+
} = {}) {
|
|
309
|
+
super({ name: name9, message });
|
|
310
|
+
this[_a10] = true;
|
|
311
|
+
}
|
|
312
|
+
static isInstance(error) {
|
|
313
|
+
return AISDKError.hasMarker(error, marker10);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
273
316
|
var name10 = "AI_NoSuchModelError";
|
|
274
317
|
var marker11 = `vercel.ai.error.${name10}`;
|
|
275
318
|
var symbol11 = Symbol.for(marker11);
|
|
276
319
|
var _a11;
|
|
277
|
-
|
|
320
|
+
var _b11;
|
|
321
|
+
var NoSuchModelError = class extends (_b11 = AISDKError, _a11 = symbol11, _b11) {
|
|
322
|
+
constructor({
|
|
323
|
+
errorName = name10,
|
|
324
|
+
modelId,
|
|
325
|
+
modelType,
|
|
326
|
+
message = `No such ${modelType}: ${modelId}`
|
|
327
|
+
}) {
|
|
328
|
+
super({ name: errorName, message });
|
|
329
|
+
this[_a11] = true;
|
|
330
|
+
this.modelId = modelId;
|
|
331
|
+
this.modelType = modelType;
|
|
332
|
+
}
|
|
333
|
+
static isInstance(error) {
|
|
334
|
+
return AISDKError.hasMarker(error, marker11);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
278
337
|
var name11 = "AI_TooManyEmbeddingValuesForCallError";
|
|
279
338
|
var marker12 = `vercel.ai.error.${name11}`;
|
|
280
339
|
var symbol12 = Symbol.for(marker12);
|
|
281
340
|
var _a12;
|
|
282
|
-
|
|
341
|
+
var _b12;
|
|
342
|
+
var TooManyEmbeddingValuesForCallError = class extends (_b12 = AISDKError, _a12 = symbol12, _b12) {
|
|
343
|
+
constructor(options) {
|
|
344
|
+
super({
|
|
345
|
+
name: name11,
|
|
346
|
+
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.`
|
|
347
|
+
});
|
|
348
|
+
this[_a12] = true;
|
|
349
|
+
this.provider = options.provider;
|
|
350
|
+
this.modelId = options.modelId;
|
|
351
|
+
this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
|
|
352
|
+
this.values = options.values;
|
|
353
|
+
}
|
|
354
|
+
static isInstance(error) {
|
|
355
|
+
return AISDKError.hasMarker(error, marker12);
|
|
356
|
+
}
|
|
357
|
+
};
|
|
283
358
|
var name12 = "AI_TypeValidationError";
|
|
284
359
|
var marker13 = `vercel.ai.error.${name12}`;
|
|
285
360
|
var symbol13 = Symbol.for(marker13);
|
|
286
361
|
var _a13;
|
|
287
|
-
var
|
|
362
|
+
var _b13;
|
|
363
|
+
var TypeValidationError = class _TypeValidationError extends (_b13 = AISDKError, _a13 = symbol13, _b13) {
|
|
288
364
|
constructor({ value, cause }) {
|
|
289
365
|
super({
|
|
290
366
|
name: name12,
|
|
@@ -312,16 +388,15 @@ Error message: ${getErrorMessage(cause)}`,
|
|
|
312
388
|
value,
|
|
313
389
|
cause
|
|
314
390
|
}) {
|
|
315
|
-
return
|
|
391
|
+
return _TypeValidationError.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError({ value, cause });
|
|
316
392
|
}
|
|
317
393
|
};
|
|
318
|
-
_a13 = symbol13;
|
|
319
|
-
var TypeValidationError = _TypeValidationError;
|
|
320
394
|
var name13 = "AI_UnsupportedFunctionalityError";
|
|
321
395
|
var marker14 = `vercel.ai.error.${name13}`;
|
|
322
396
|
var symbol14 = Symbol.for(marker14);
|
|
323
397
|
var _a14;
|
|
324
|
-
var
|
|
398
|
+
var _b14;
|
|
399
|
+
var UnsupportedFunctionalityError = class extends (_b14 = AISDKError, _a14 = symbol14, _b14) {
|
|
325
400
|
constructor({
|
|
326
401
|
functionality,
|
|
327
402
|
message = `'${functionality}' functionality not supported.`
|
|
@@ -334,9 +409,14 @@ var UnsupportedFunctionalityError = class extends AISDKError {
|
|
|
334
409
|
return AISDKError.hasMarker(error, marker14);
|
|
335
410
|
}
|
|
336
411
|
};
|
|
337
|
-
_a14 = symbol14;
|
|
338
412
|
|
|
339
|
-
// node_modules/.pnpm
|
|
413
|
+
// node_modules/.pnpm/@ai-sdk+provider-utils@4.0.4_zod@3.25.34/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
414
|
+
var z4 = __toESM(require("zod/v4"), 1);
|
|
415
|
+
var import_v3 = require("zod/v3");
|
|
416
|
+
var import_v32 = require("zod/v3");
|
|
417
|
+
var import_v33 = require("zod/v3");
|
|
418
|
+
|
|
419
|
+
// node_modules/.pnpm/eventsource-parser@3.0.6/node_modules/eventsource-parser/dist/index.js
|
|
340
420
|
var ParseError = class extends Error {
|
|
341
421
|
constructor(message, options) {
|
|
342
422
|
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
@@ -427,7 +507,7 @@ function splitLines(chunk) {
|
|
|
427
507
|
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
428
508
|
`, searchIndex);
|
|
429
509
|
let lineEnd = -1;
|
|
430
|
-
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
|
|
510
|
+
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) {
|
|
431
511
|
incompleteLine = chunk.slice(searchIndex);
|
|
432
512
|
break;
|
|
433
513
|
} else {
|
|
@@ -439,7 +519,7 @@ function splitLines(chunk) {
|
|
|
439
519
|
return [lines, incompleteLine];
|
|
440
520
|
}
|
|
441
521
|
|
|
442
|
-
// node_modules/.pnpm/eventsource-parser@3.0.
|
|
522
|
+
// node_modules/.pnpm/eventsource-parser@3.0.6/node_modules/eventsource-parser/dist/stream.js
|
|
443
523
|
var EventSourceParserStream = class extends TransformStream {
|
|
444
524
|
constructor({ onError, onRetry, onComment } = {}) {
|
|
445
525
|
let parser;
|
|
@@ -463,28 +543,7 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
463
543
|
}
|
|
464
544
|
};
|
|
465
545
|
|
|
466
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@
|
|
467
|
-
var z4 = __toESM(require("zod/v4"), 1);
|
|
468
|
-
|
|
469
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.34/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
470
|
-
var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
471
|
-
|
|
472
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.25.34/node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
473
|
-
var import_zod4 = require("zod");
|
|
474
|
-
|
|
475
|
-
// 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
|
|
476
|
-
var import_zod = require("zod");
|
|
477
|
-
|
|
478
|
-
// 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
|
|
479
|
-
var import_zod2 = require("zod");
|
|
480
|
-
|
|
481
|
-
// 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
|
|
482
|
-
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
483
|
-
|
|
484
|
-
// 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
|
|
485
|
-
var import_zod3 = require("zod");
|
|
486
|
-
|
|
487
|
-
// 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
|
|
546
|
+
// node_modules/.pnpm/@ai-sdk+provider-utils@4.0.4_zod@3.25.34/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
488
547
|
function combineHeaders(...headers) {
|
|
489
548
|
return headers.reduce(
|
|
490
549
|
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
@@ -494,6 +553,37 @@ function combineHeaders(...headers) {
|
|
|
494
553
|
function extractResponseHeaders(response) {
|
|
495
554
|
return Object.fromEntries([...response.headers]);
|
|
496
555
|
}
|
|
556
|
+
var { btoa, atob } = globalThis;
|
|
557
|
+
function convertUint8ArrayToBase64(array) {
|
|
558
|
+
let latin1string = "";
|
|
559
|
+
for (let i = 0; i < array.length; i++) {
|
|
560
|
+
latin1string += String.fromCodePoint(array[i]);
|
|
561
|
+
}
|
|
562
|
+
return btoa(latin1string);
|
|
563
|
+
}
|
|
564
|
+
var name14 = "AI_DownloadError";
|
|
565
|
+
var marker15 = `vercel.ai.error.${name14}`;
|
|
566
|
+
var symbol15 = Symbol.for(marker15);
|
|
567
|
+
var _a15;
|
|
568
|
+
var _b15;
|
|
569
|
+
var DownloadError = class extends (_b15 = AISDKError, _a15 = symbol15, _b15) {
|
|
570
|
+
constructor({
|
|
571
|
+
url,
|
|
572
|
+
statusCode,
|
|
573
|
+
statusText,
|
|
574
|
+
cause,
|
|
575
|
+
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
|
576
|
+
}) {
|
|
577
|
+
super({ name: name14, message, cause });
|
|
578
|
+
this[_a15] = true;
|
|
579
|
+
this.url = url;
|
|
580
|
+
this.statusCode = statusCode;
|
|
581
|
+
this.statusText = statusText;
|
|
582
|
+
}
|
|
583
|
+
static isInstance(error) {
|
|
584
|
+
return AISDKError.hasMarker(error, marker15);
|
|
585
|
+
}
|
|
586
|
+
};
|
|
497
587
|
var createIdGenerator = ({
|
|
498
588
|
prefix,
|
|
499
589
|
size = 16,
|
|
@@ -521,7 +611,7 @@ var createIdGenerator = ({
|
|
|
521
611
|
};
|
|
522
612
|
var generateId = createIdGenerator();
|
|
523
613
|
function isAbortError(error) {
|
|
524
|
-
return error instanceof Error && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
614
|
+
return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
525
615
|
error.name === "TimeoutError");
|
|
526
616
|
}
|
|
527
617
|
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
@@ -548,11 +638,53 @@ function handleFetchError({
|
|
|
548
638
|
}
|
|
549
639
|
return error;
|
|
550
640
|
}
|
|
551
|
-
function
|
|
552
|
-
|
|
553
|
-
|
|
641
|
+
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
642
|
+
var _a22, _b22, _c;
|
|
643
|
+
if (globalThisAny.window) {
|
|
644
|
+
return `runtime/browser`;
|
|
645
|
+
}
|
|
646
|
+
if ((_a22 = globalThisAny.navigator) == null ? void 0 : _a22.userAgent) {
|
|
647
|
+
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
648
|
+
}
|
|
649
|
+
if ((_c = (_b22 = globalThisAny.process) == null ? void 0 : _b22.versions) == null ? void 0 : _c.node) {
|
|
650
|
+
return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
|
651
|
+
}
|
|
652
|
+
if (globalThisAny.EdgeRuntime) {
|
|
653
|
+
return `runtime/vercel-edge`;
|
|
654
|
+
}
|
|
655
|
+
return "runtime/unknown";
|
|
656
|
+
}
|
|
657
|
+
function normalizeHeaders(headers) {
|
|
658
|
+
if (headers == null) {
|
|
659
|
+
return {};
|
|
660
|
+
}
|
|
661
|
+
const normalized = {};
|
|
662
|
+
if (headers instanceof Headers) {
|
|
663
|
+
headers.forEach((value, key) => {
|
|
664
|
+
normalized[key.toLowerCase()] = value;
|
|
665
|
+
});
|
|
666
|
+
} else {
|
|
667
|
+
if (!Array.isArray(headers)) {
|
|
668
|
+
headers = Object.entries(headers);
|
|
669
|
+
}
|
|
670
|
+
for (const [key, value] of headers) {
|
|
671
|
+
if (value != null) {
|
|
672
|
+
normalized[key.toLowerCase()] = value;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
return normalized;
|
|
677
|
+
}
|
|
678
|
+
function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
679
|
+
const normalizedHeaders = new Headers(normalizeHeaders(headers));
|
|
680
|
+
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
|
681
|
+
normalizedHeaders.set(
|
|
682
|
+
"user-agent",
|
|
683
|
+
[currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ")
|
|
554
684
|
);
|
|
685
|
+
return Object.fromEntries(normalizedHeaders.entries());
|
|
555
686
|
}
|
|
687
|
+
var VERSION = true ? "4.0.4" : "0.0.0-test";
|
|
556
688
|
var suspectProtoRx = /"__proto__"\s*:/;
|
|
557
689
|
var suspectConstructorRx = /"constructor"\s*:/;
|
|
558
690
|
function _parse(text) {
|
|
@@ -589,34 +721,1204 @@ function filter(obj) {
|
|
|
589
721
|
}
|
|
590
722
|
function secureJsonParse(text) {
|
|
591
723
|
const { stackTraceLimit } = Error;
|
|
592
|
-
|
|
724
|
+
try {
|
|
725
|
+
Error.stackTraceLimit = 0;
|
|
726
|
+
} catch (e) {
|
|
727
|
+
return _parse(text);
|
|
728
|
+
}
|
|
593
729
|
try {
|
|
594
730
|
return _parse(text);
|
|
595
731
|
} finally {
|
|
596
732
|
Error.stackTraceLimit = stackTraceLimit;
|
|
597
733
|
}
|
|
598
734
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
735
|
+
function addAdditionalPropertiesToJsonSchema(jsonSchema2) {
|
|
736
|
+
if (jsonSchema2.type === "object" || Array.isArray(jsonSchema2.type) && jsonSchema2.type.includes("object")) {
|
|
737
|
+
jsonSchema2.additionalProperties = false;
|
|
738
|
+
const { properties } = jsonSchema2;
|
|
739
|
+
if (properties != null) {
|
|
740
|
+
for (const key of Object.keys(properties)) {
|
|
741
|
+
properties[key] = visit(properties[key]);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
if (jsonSchema2.items != null) {
|
|
746
|
+
jsonSchema2.items = Array.isArray(jsonSchema2.items) ? jsonSchema2.items.map(visit) : visit(jsonSchema2.items);
|
|
747
|
+
}
|
|
748
|
+
if (jsonSchema2.anyOf != null) {
|
|
749
|
+
jsonSchema2.anyOf = jsonSchema2.anyOf.map(visit);
|
|
750
|
+
}
|
|
751
|
+
if (jsonSchema2.allOf != null) {
|
|
752
|
+
jsonSchema2.allOf = jsonSchema2.allOf.map(visit);
|
|
753
|
+
}
|
|
754
|
+
if (jsonSchema2.oneOf != null) {
|
|
755
|
+
jsonSchema2.oneOf = jsonSchema2.oneOf.map(visit);
|
|
756
|
+
}
|
|
757
|
+
const { definitions } = jsonSchema2;
|
|
758
|
+
if (definitions != null) {
|
|
759
|
+
for (const key of Object.keys(definitions)) {
|
|
760
|
+
definitions[key] = visit(definitions[key]);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return jsonSchema2;
|
|
602
764
|
}
|
|
603
|
-
function
|
|
604
|
-
|
|
765
|
+
function visit(def) {
|
|
766
|
+
if (typeof def === "boolean") return def;
|
|
767
|
+
return addAdditionalPropertiesToJsonSchema(def);
|
|
605
768
|
}
|
|
606
|
-
|
|
607
|
-
|
|
769
|
+
var ignoreOverride = Symbol(
|
|
770
|
+
"Let zodToJsonSchema decide on which parser to use"
|
|
771
|
+
);
|
|
772
|
+
var defaultOptions = {
|
|
773
|
+
name: void 0,
|
|
774
|
+
$refStrategy: "root",
|
|
775
|
+
basePath: ["#"],
|
|
776
|
+
effectStrategy: "input",
|
|
777
|
+
pipeStrategy: "all",
|
|
778
|
+
dateStrategy: "format:date-time",
|
|
779
|
+
mapStrategy: "entries",
|
|
780
|
+
removeAdditionalStrategy: "passthrough",
|
|
781
|
+
allowedAdditionalProperties: true,
|
|
782
|
+
rejectedAdditionalProperties: false,
|
|
783
|
+
definitionPath: "definitions",
|
|
784
|
+
strictUnions: false,
|
|
785
|
+
definitions: {},
|
|
786
|
+
errorMessages: false,
|
|
787
|
+
patternStrategy: "escape",
|
|
788
|
+
applyRegexFlags: false,
|
|
789
|
+
emailStrategy: "format:email",
|
|
790
|
+
base64Strategy: "contentEncoding:base64",
|
|
791
|
+
nameStrategy: "ref"
|
|
792
|
+
};
|
|
793
|
+
var getDefaultOptions = (options) => typeof options === "string" ? __spreadProps(__spreadValues({}, defaultOptions), {
|
|
794
|
+
name: options
|
|
795
|
+
}) : __spreadValues(__spreadValues({}, defaultOptions), options);
|
|
796
|
+
function parseAnyDef() {
|
|
797
|
+
return {};
|
|
608
798
|
}
|
|
609
|
-
function
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
799
|
+
function parseArrayDef(def, refs) {
|
|
800
|
+
var _a22, _b22, _c;
|
|
801
|
+
const res = {
|
|
802
|
+
type: "array"
|
|
803
|
+
};
|
|
804
|
+
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) {
|
|
805
|
+
res.items = parseDef(def.type._def, __spreadProps(__spreadValues({}, refs), {
|
|
806
|
+
currentPath: [...refs.currentPath, "items"]
|
|
807
|
+
}));
|
|
808
|
+
}
|
|
809
|
+
if (def.minLength) {
|
|
810
|
+
res.minItems = def.minLength.value;
|
|
811
|
+
}
|
|
812
|
+
if (def.maxLength) {
|
|
813
|
+
res.maxItems = def.maxLength.value;
|
|
814
|
+
}
|
|
815
|
+
if (def.exactLength) {
|
|
816
|
+
res.minItems = def.exactLength.value;
|
|
817
|
+
res.maxItems = def.exactLength.value;
|
|
818
|
+
}
|
|
819
|
+
return res;
|
|
820
|
+
}
|
|
821
|
+
function parseBigintDef(def) {
|
|
822
|
+
const res = {
|
|
823
|
+
type: "integer",
|
|
824
|
+
format: "int64"
|
|
825
|
+
};
|
|
826
|
+
if (!def.checks) return res;
|
|
827
|
+
for (const check of def.checks) {
|
|
828
|
+
switch (check.kind) {
|
|
829
|
+
case "min":
|
|
830
|
+
if (check.inclusive) {
|
|
831
|
+
res.minimum = check.value;
|
|
832
|
+
} else {
|
|
833
|
+
res.exclusiveMinimum = check.value;
|
|
834
|
+
}
|
|
835
|
+
break;
|
|
836
|
+
case "max":
|
|
837
|
+
if (check.inclusive) {
|
|
838
|
+
res.maximum = check.value;
|
|
839
|
+
} else {
|
|
840
|
+
res.exclusiveMaximum = check.value;
|
|
841
|
+
}
|
|
842
|
+
break;
|
|
843
|
+
case "multipleOf":
|
|
844
|
+
res.multipleOf = check.value;
|
|
845
|
+
break;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
return res;
|
|
849
|
+
}
|
|
850
|
+
function parseBooleanDef() {
|
|
851
|
+
return { type: "boolean" };
|
|
852
|
+
}
|
|
853
|
+
function parseBrandedDef(_def, refs) {
|
|
854
|
+
return parseDef(_def.type._def, refs);
|
|
855
|
+
}
|
|
856
|
+
var parseCatchDef = (def, refs) => {
|
|
857
|
+
return parseDef(def.innerType._def, refs);
|
|
858
|
+
};
|
|
859
|
+
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
860
|
+
const strategy = overrideDateStrategy != null ? overrideDateStrategy : refs.dateStrategy;
|
|
861
|
+
if (Array.isArray(strategy)) {
|
|
862
|
+
return {
|
|
863
|
+
anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
switch (strategy) {
|
|
867
|
+
case "string":
|
|
868
|
+
case "format:date-time":
|
|
869
|
+
return {
|
|
870
|
+
type: "string",
|
|
871
|
+
format: "date-time"
|
|
872
|
+
};
|
|
873
|
+
case "format:date":
|
|
874
|
+
return {
|
|
875
|
+
type: "string",
|
|
876
|
+
format: "date"
|
|
877
|
+
};
|
|
878
|
+
case "integer":
|
|
879
|
+
return integerDateParser(def);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
var integerDateParser = (def) => {
|
|
883
|
+
const res = {
|
|
884
|
+
type: "integer",
|
|
885
|
+
format: "unix-time"
|
|
886
|
+
};
|
|
887
|
+
for (const check of def.checks) {
|
|
888
|
+
switch (check.kind) {
|
|
889
|
+
case "min":
|
|
890
|
+
res.minimum = check.value;
|
|
891
|
+
break;
|
|
892
|
+
case "max":
|
|
893
|
+
res.maximum = check.value;
|
|
894
|
+
break;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
return res;
|
|
898
|
+
};
|
|
899
|
+
function parseDefaultDef(_def, refs) {
|
|
900
|
+
return __spreadProps(__spreadValues({}, parseDef(_def.innerType._def, refs)), {
|
|
901
|
+
default: _def.defaultValue()
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
function parseEffectsDef(_def, refs) {
|
|
905
|
+
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : parseAnyDef();
|
|
906
|
+
}
|
|
907
|
+
function parseEnumDef(def) {
|
|
908
|
+
return {
|
|
909
|
+
type: "string",
|
|
910
|
+
enum: Array.from(def.values)
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
var isJsonSchema7AllOfType = (type) => {
|
|
914
|
+
if ("type" in type && type.type === "string") return false;
|
|
915
|
+
return "allOf" in type;
|
|
916
|
+
};
|
|
917
|
+
function parseIntersectionDef(def, refs) {
|
|
918
|
+
const allOf = [
|
|
919
|
+
parseDef(def.left._def, __spreadProps(__spreadValues({}, refs), {
|
|
920
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
921
|
+
})),
|
|
922
|
+
parseDef(def.right._def, __spreadProps(__spreadValues({}, refs), {
|
|
923
|
+
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
924
|
+
}))
|
|
925
|
+
].filter((x) => !!x);
|
|
926
|
+
const mergedAllOf = [];
|
|
927
|
+
allOf.forEach((schema) => {
|
|
928
|
+
if (isJsonSchema7AllOfType(schema)) {
|
|
929
|
+
mergedAllOf.push(...schema.allOf);
|
|
930
|
+
} else {
|
|
931
|
+
let nestedSchema = schema;
|
|
932
|
+
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
933
|
+
const _a16 = schema, { additionalProperties } = _a16, rest = __objRest(_a16, ["additionalProperties"]);
|
|
934
|
+
nestedSchema = rest;
|
|
935
|
+
}
|
|
936
|
+
mergedAllOf.push(nestedSchema);
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
return mergedAllOf.length ? { allOf: mergedAllOf } : void 0;
|
|
940
|
+
}
|
|
941
|
+
function parseLiteralDef(def) {
|
|
942
|
+
const parsedType = typeof def.value;
|
|
943
|
+
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
944
|
+
return {
|
|
945
|
+
type: Array.isArray(def.value) ? "array" : "object"
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
return {
|
|
949
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
950
|
+
const: def.value
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
var emojiRegex = void 0;
|
|
954
|
+
var zodPatterns = {
|
|
955
|
+
/**
|
|
956
|
+
* `c` was changed to `[cC]` to replicate /i flag
|
|
957
|
+
*/
|
|
958
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
959
|
+
cuid2: /^[0-9a-z]+$/,
|
|
960
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
961
|
+
/**
|
|
962
|
+
* `a-z` was added to replicate /i flag
|
|
963
|
+
*/
|
|
964
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
965
|
+
/**
|
|
966
|
+
* Constructed a valid Unicode RegExp
|
|
967
|
+
*
|
|
968
|
+
* Lazily instantiate since this type of regex isn't supported
|
|
969
|
+
* in all envs (e.g. React Native).
|
|
970
|
+
*
|
|
971
|
+
* See:
|
|
972
|
+
* https://github.com/colinhacks/zod/issues/2433
|
|
973
|
+
* Fix in Zod:
|
|
974
|
+
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
975
|
+
*/
|
|
976
|
+
emoji: () => {
|
|
977
|
+
if (emojiRegex === void 0) {
|
|
978
|
+
emojiRegex = RegExp(
|
|
979
|
+
"^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",
|
|
980
|
+
"u"
|
|
981
|
+
);
|
|
982
|
+
}
|
|
983
|
+
return emojiRegex;
|
|
984
|
+
},
|
|
985
|
+
/**
|
|
986
|
+
* Unused
|
|
987
|
+
*/
|
|
988
|
+
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}$/,
|
|
989
|
+
/**
|
|
990
|
+
* Unused
|
|
991
|
+
*/
|
|
992
|
+
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])$/,
|
|
993
|
+
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])$/,
|
|
994
|
+
/**
|
|
995
|
+
* Unused
|
|
996
|
+
*/
|
|
997
|
+
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})))$/,
|
|
998
|
+
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])$/,
|
|
999
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
1000
|
+
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
1001
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
1002
|
+
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
1003
|
+
};
|
|
1004
|
+
function parseStringDef(def, refs) {
|
|
1005
|
+
const res = {
|
|
1006
|
+
type: "string"
|
|
1007
|
+
};
|
|
1008
|
+
if (def.checks) {
|
|
1009
|
+
for (const check of def.checks) {
|
|
1010
|
+
switch (check.kind) {
|
|
1011
|
+
case "min":
|
|
1012
|
+
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
|
|
1013
|
+
break;
|
|
1014
|
+
case "max":
|
|
1015
|
+
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
|
|
1016
|
+
break;
|
|
1017
|
+
case "email":
|
|
1018
|
+
switch (refs.emailStrategy) {
|
|
1019
|
+
case "format:email":
|
|
1020
|
+
addFormat(res, "email", check.message, refs);
|
|
1021
|
+
break;
|
|
1022
|
+
case "format:idn-email":
|
|
1023
|
+
addFormat(res, "idn-email", check.message, refs);
|
|
1024
|
+
break;
|
|
1025
|
+
case "pattern:zod":
|
|
1026
|
+
addPattern(res, zodPatterns.email, check.message, refs);
|
|
1027
|
+
break;
|
|
1028
|
+
}
|
|
1029
|
+
break;
|
|
1030
|
+
case "url":
|
|
1031
|
+
addFormat(res, "uri", check.message, refs);
|
|
1032
|
+
break;
|
|
1033
|
+
case "uuid":
|
|
1034
|
+
addFormat(res, "uuid", check.message, refs);
|
|
1035
|
+
break;
|
|
1036
|
+
case "regex":
|
|
1037
|
+
addPattern(res, check.regex, check.message, refs);
|
|
1038
|
+
break;
|
|
1039
|
+
case "cuid":
|
|
1040
|
+
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
1041
|
+
break;
|
|
1042
|
+
case "cuid2":
|
|
1043
|
+
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
1044
|
+
break;
|
|
1045
|
+
case "startsWith":
|
|
1046
|
+
addPattern(
|
|
1047
|
+
res,
|
|
1048
|
+
RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`),
|
|
1049
|
+
check.message,
|
|
1050
|
+
refs
|
|
1051
|
+
);
|
|
1052
|
+
break;
|
|
1053
|
+
case "endsWith":
|
|
1054
|
+
addPattern(
|
|
1055
|
+
res,
|
|
1056
|
+
RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`),
|
|
1057
|
+
check.message,
|
|
1058
|
+
refs
|
|
1059
|
+
);
|
|
1060
|
+
break;
|
|
1061
|
+
case "datetime":
|
|
1062
|
+
addFormat(res, "date-time", check.message, refs);
|
|
1063
|
+
break;
|
|
1064
|
+
case "date":
|
|
1065
|
+
addFormat(res, "date", check.message, refs);
|
|
1066
|
+
break;
|
|
1067
|
+
case "time":
|
|
1068
|
+
addFormat(res, "time", check.message, refs);
|
|
1069
|
+
break;
|
|
1070
|
+
case "duration":
|
|
1071
|
+
addFormat(res, "duration", check.message, refs);
|
|
1072
|
+
break;
|
|
1073
|
+
case "length":
|
|
1074
|
+
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
|
|
1075
|
+
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
|
|
1076
|
+
break;
|
|
1077
|
+
case "includes": {
|
|
1078
|
+
addPattern(
|
|
1079
|
+
res,
|
|
1080
|
+
RegExp(escapeLiteralCheckValue(check.value, refs)),
|
|
1081
|
+
check.message,
|
|
1082
|
+
refs
|
|
1083
|
+
);
|
|
1084
|
+
break;
|
|
1085
|
+
}
|
|
1086
|
+
case "ip": {
|
|
1087
|
+
if (check.version !== "v6") {
|
|
1088
|
+
addFormat(res, "ipv4", check.message, refs);
|
|
1089
|
+
}
|
|
1090
|
+
if (check.version !== "v4") {
|
|
1091
|
+
addFormat(res, "ipv6", check.message, refs);
|
|
1092
|
+
}
|
|
1093
|
+
break;
|
|
1094
|
+
}
|
|
1095
|
+
case "base64url":
|
|
1096
|
+
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
1097
|
+
break;
|
|
1098
|
+
case "jwt":
|
|
1099
|
+
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
1100
|
+
break;
|
|
1101
|
+
case "cidr": {
|
|
1102
|
+
if (check.version !== "v6") {
|
|
1103
|
+
addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
1104
|
+
}
|
|
1105
|
+
if (check.version !== "v4") {
|
|
1106
|
+
addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
1107
|
+
}
|
|
1108
|
+
break;
|
|
1109
|
+
}
|
|
1110
|
+
case "emoji":
|
|
1111
|
+
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
1112
|
+
break;
|
|
1113
|
+
case "ulid": {
|
|
1114
|
+
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
1115
|
+
break;
|
|
1116
|
+
}
|
|
1117
|
+
case "base64": {
|
|
1118
|
+
switch (refs.base64Strategy) {
|
|
1119
|
+
case "format:binary": {
|
|
1120
|
+
addFormat(res, "binary", check.message, refs);
|
|
1121
|
+
break;
|
|
1122
|
+
}
|
|
1123
|
+
case "contentEncoding:base64": {
|
|
1124
|
+
res.contentEncoding = "base64";
|
|
1125
|
+
break;
|
|
1126
|
+
}
|
|
1127
|
+
case "pattern:zod": {
|
|
1128
|
+
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
1129
|
+
break;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
break;
|
|
1133
|
+
}
|
|
1134
|
+
case "nanoid": {
|
|
1135
|
+
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
1136
|
+
}
|
|
1137
|
+
case "toLowerCase":
|
|
1138
|
+
case "toUpperCase":
|
|
1139
|
+
case "trim":
|
|
1140
|
+
break;
|
|
1141
|
+
default:
|
|
1142
|
+
/* @__PURE__ */ ((_) => {
|
|
1143
|
+
})(check);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
return res;
|
|
1148
|
+
}
|
|
1149
|
+
function escapeLiteralCheckValue(literal, refs) {
|
|
1150
|
+
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
1151
|
+
}
|
|
1152
|
+
var ALPHA_NUMERIC = new Set(
|
|
1153
|
+
"ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789"
|
|
1154
|
+
);
|
|
1155
|
+
function escapeNonAlphaNumeric(source) {
|
|
1156
|
+
let result = "";
|
|
1157
|
+
for (let i = 0; i < source.length; i++) {
|
|
1158
|
+
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
1159
|
+
result += "\\";
|
|
1160
|
+
}
|
|
1161
|
+
result += source[i];
|
|
1162
|
+
}
|
|
1163
|
+
return result;
|
|
1164
|
+
}
|
|
1165
|
+
function addFormat(schema, value, message, refs) {
|
|
1166
|
+
var _a22;
|
|
1167
|
+
if (schema.format || ((_a22 = schema.anyOf) == null ? void 0 : _a22.some((x) => x.format))) {
|
|
1168
|
+
if (!schema.anyOf) {
|
|
1169
|
+
schema.anyOf = [];
|
|
1170
|
+
}
|
|
1171
|
+
if (schema.format) {
|
|
1172
|
+
schema.anyOf.push({
|
|
1173
|
+
format: schema.format
|
|
1174
|
+
});
|
|
1175
|
+
delete schema.format;
|
|
1176
|
+
}
|
|
1177
|
+
schema.anyOf.push(__spreadValues({
|
|
1178
|
+
format: value
|
|
1179
|
+
}, message && refs.errorMessages && { errorMessage: { format: message } }));
|
|
1180
|
+
} else {
|
|
1181
|
+
schema.format = value;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
function addPattern(schema, regex, message, refs) {
|
|
1185
|
+
var _a22;
|
|
1186
|
+
if (schema.pattern || ((_a22 = schema.allOf) == null ? void 0 : _a22.some((x) => x.pattern))) {
|
|
1187
|
+
if (!schema.allOf) {
|
|
1188
|
+
schema.allOf = [];
|
|
1189
|
+
}
|
|
1190
|
+
if (schema.pattern) {
|
|
1191
|
+
schema.allOf.push({
|
|
1192
|
+
pattern: schema.pattern
|
|
1193
|
+
});
|
|
1194
|
+
delete schema.pattern;
|
|
1195
|
+
}
|
|
1196
|
+
schema.allOf.push(__spreadValues({
|
|
1197
|
+
pattern: stringifyRegExpWithFlags(regex, refs)
|
|
1198
|
+
}, message && refs.errorMessages && { errorMessage: { pattern: message } }));
|
|
1199
|
+
} else {
|
|
1200
|
+
schema.pattern = stringifyRegExpWithFlags(regex, refs);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
function stringifyRegExpWithFlags(regex, refs) {
|
|
1204
|
+
var _a22;
|
|
1205
|
+
if (!refs.applyRegexFlags || !regex.flags) {
|
|
1206
|
+
return regex.source;
|
|
1207
|
+
}
|
|
1208
|
+
const flags = {
|
|
1209
|
+
i: regex.flags.includes("i"),
|
|
1210
|
+
// Case-insensitive
|
|
1211
|
+
m: regex.flags.includes("m"),
|
|
1212
|
+
// `^` and `$` matches adjacent to newline characters
|
|
1213
|
+
s: regex.flags.includes("s")
|
|
1214
|
+
// `.` matches newlines
|
|
1215
|
+
};
|
|
1216
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
1217
|
+
let pattern = "";
|
|
1218
|
+
let isEscaped = false;
|
|
1219
|
+
let inCharGroup = false;
|
|
1220
|
+
let inCharRange = false;
|
|
1221
|
+
for (let i = 0; i < source.length; i++) {
|
|
1222
|
+
if (isEscaped) {
|
|
1223
|
+
pattern += source[i];
|
|
1224
|
+
isEscaped = false;
|
|
1225
|
+
continue;
|
|
1226
|
+
}
|
|
1227
|
+
if (flags.i) {
|
|
1228
|
+
if (inCharGroup) {
|
|
1229
|
+
if (source[i].match(/[a-z]/)) {
|
|
1230
|
+
if (inCharRange) {
|
|
1231
|
+
pattern += source[i];
|
|
1232
|
+
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
1233
|
+
inCharRange = false;
|
|
1234
|
+
} else if (source[i + 1] === "-" && ((_a22 = source[i + 2]) == null ? void 0 : _a22.match(/[a-z]/))) {
|
|
1235
|
+
pattern += source[i];
|
|
1236
|
+
inCharRange = true;
|
|
1237
|
+
} else {
|
|
1238
|
+
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
1239
|
+
}
|
|
1240
|
+
continue;
|
|
1241
|
+
}
|
|
1242
|
+
} else if (source[i].match(/[a-z]/)) {
|
|
1243
|
+
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
1244
|
+
continue;
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
if (flags.m) {
|
|
1248
|
+
if (source[i] === "^") {
|
|
1249
|
+
pattern += `(^|(?<=[\r
|
|
1250
|
+
]))`;
|
|
1251
|
+
continue;
|
|
1252
|
+
} else if (source[i] === "$") {
|
|
1253
|
+
pattern += `($|(?=[\r
|
|
1254
|
+
]))`;
|
|
1255
|
+
continue;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
if (flags.s && source[i] === ".") {
|
|
1259
|
+
pattern += inCharGroup ? `${source[i]}\r
|
|
1260
|
+
` : `[${source[i]}\r
|
|
1261
|
+
]`;
|
|
1262
|
+
continue;
|
|
1263
|
+
}
|
|
1264
|
+
pattern += source[i];
|
|
1265
|
+
if (source[i] === "\\") {
|
|
1266
|
+
isEscaped = true;
|
|
1267
|
+
} else if (inCharGroup && source[i] === "]") {
|
|
1268
|
+
inCharGroup = false;
|
|
1269
|
+
} else if (!inCharGroup && source[i] === "[") {
|
|
1270
|
+
inCharGroup = true;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
try {
|
|
1274
|
+
new RegExp(pattern);
|
|
1275
|
+
} catch (e) {
|
|
1276
|
+
console.warn(
|
|
1277
|
+
`Could not convert regex pattern at ${refs.currentPath.join(
|
|
1278
|
+
"/"
|
|
1279
|
+
)} to a flag-independent form! Falling back to the flag-ignorant source`
|
|
1280
|
+
);
|
|
1281
|
+
return regex.source;
|
|
1282
|
+
}
|
|
1283
|
+
return pattern;
|
|
1284
|
+
}
|
|
1285
|
+
function parseRecordDef(def, refs) {
|
|
1286
|
+
var _a22, _b22, _c, _d, _e, _f;
|
|
1287
|
+
const schema = {
|
|
1288
|
+
type: "object",
|
|
1289
|
+
additionalProperties: (_a22 = parseDef(def.valueType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1290
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1291
|
+
}))) != null ? _a22 : refs.allowedAdditionalProperties
|
|
1292
|
+
};
|
|
1293
|
+
if (((_b22 = def.keyType) == null ? void 0 : _b22._def.typeName) === import_v33.ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
1294
|
+
const _a16 = parseStringDef(def.keyType._def, refs), { type } = _a16, keyType = __objRest(_a16, ["type"]);
|
|
1295
|
+
return __spreadProps(__spreadValues({}, schema), {
|
|
1296
|
+
propertyNames: keyType
|
|
1297
|
+
});
|
|
1298
|
+
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) === import_v33.ZodFirstPartyTypeKind.ZodEnum) {
|
|
1299
|
+
return __spreadProps(__spreadValues({}, schema), {
|
|
1300
|
+
propertyNames: {
|
|
1301
|
+
enum: def.keyType._def.values
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
} 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)) {
|
|
1305
|
+
const _b16 = parseBrandedDef(
|
|
1306
|
+
def.keyType._def,
|
|
1307
|
+
refs
|
|
1308
|
+
), { type } = _b16, keyType = __objRest(_b16, ["type"]);
|
|
1309
|
+
return __spreadProps(__spreadValues({}, schema), {
|
|
1310
|
+
propertyNames: keyType
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
return schema;
|
|
1314
|
+
}
|
|
1315
|
+
function parseMapDef(def, refs) {
|
|
1316
|
+
if (refs.mapStrategy === "record") {
|
|
1317
|
+
return parseRecordDef(def, refs);
|
|
1318
|
+
}
|
|
1319
|
+
const keys = parseDef(def.keyType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1320
|
+
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
1321
|
+
})) || parseAnyDef();
|
|
1322
|
+
const values = parseDef(def.valueType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1323
|
+
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
1324
|
+
})) || parseAnyDef();
|
|
1325
|
+
return {
|
|
1326
|
+
type: "array",
|
|
1327
|
+
maxItems: 125,
|
|
1328
|
+
items: {
|
|
1329
|
+
type: "array",
|
|
1330
|
+
items: [keys, values],
|
|
1331
|
+
minItems: 2,
|
|
1332
|
+
maxItems: 2
|
|
1333
|
+
}
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
function parseNativeEnumDef(def) {
|
|
1337
|
+
const object = def.values;
|
|
1338
|
+
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
1339
|
+
return typeof object[object[key]] !== "number";
|
|
1340
|
+
});
|
|
1341
|
+
const actualValues = actualKeys.map((key) => object[key]);
|
|
1342
|
+
const parsedTypes = Array.from(
|
|
1343
|
+
new Set(actualValues.map((values) => typeof values))
|
|
1344
|
+
);
|
|
1345
|
+
return {
|
|
1346
|
+
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
1347
|
+
enum: actualValues
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
function parseNeverDef() {
|
|
1351
|
+
return { not: parseAnyDef() };
|
|
1352
|
+
}
|
|
1353
|
+
function parseNullDef() {
|
|
1354
|
+
return {
|
|
1355
|
+
type: "null"
|
|
1356
|
+
};
|
|
1357
|
+
}
|
|
1358
|
+
var primitiveMappings = {
|
|
1359
|
+
ZodString: "string",
|
|
1360
|
+
ZodNumber: "number",
|
|
1361
|
+
ZodBigInt: "integer",
|
|
1362
|
+
ZodBoolean: "boolean",
|
|
1363
|
+
ZodNull: "null"
|
|
1364
|
+
};
|
|
1365
|
+
function parseUnionDef(def, refs) {
|
|
1366
|
+
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
1367
|
+
if (options.every(
|
|
1368
|
+
(x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length)
|
|
1369
|
+
)) {
|
|
1370
|
+
const types = options.reduce((types2, x) => {
|
|
1371
|
+
const type = primitiveMappings[x._def.typeName];
|
|
1372
|
+
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
1373
|
+
}, []);
|
|
1374
|
+
return {
|
|
1375
|
+
type: types.length > 1 ? types : types[0]
|
|
618
1376
|
};
|
|
1377
|
+
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
1378
|
+
const types = options.reduce(
|
|
1379
|
+
(acc, x) => {
|
|
1380
|
+
const type = typeof x._def.value;
|
|
1381
|
+
switch (type) {
|
|
1382
|
+
case "string":
|
|
1383
|
+
case "number":
|
|
1384
|
+
case "boolean":
|
|
1385
|
+
return [...acc, type];
|
|
1386
|
+
case "bigint":
|
|
1387
|
+
return [...acc, "integer"];
|
|
1388
|
+
case "object":
|
|
1389
|
+
if (x._def.value === null) return [...acc, "null"];
|
|
1390
|
+
case "symbol":
|
|
1391
|
+
case "undefined":
|
|
1392
|
+
case "function":
|
|
1393
|
+
default:
|
|
1394
|
+
return acc;
|
|
1395
|
+
}
|
|
1396
|
+
},
|
|
1397
|
+
[]
|
|
1398
|
+
);
|
|
1399
|
+
if (types.length === options.length) {
|
|
1400
|
+
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
1401
|
+
return {
|
|
1402
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
1403
|
+
enum: options.reduce(
|
|
1404
|
+
(acc, x) => {
|
|
1405
|
+
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
1406
|
+
},
|
|
1407
|
+
[]
|
|
1408
|
+
)
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
1412
|
+
return {
|
|
1413
|
+
type: "string",
|
|
1414
|
+
enum: options.reduce(
|
|
1415
|
+
(acc, x) => [
|
|
1416
|
+
...acc,
|
|
1417
|
+
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
1418
|
+
],
|
|
1419
|
+
[]
|
|
1420
|
+
)
|
|
1421
|
+
};
|
|
1422
|
+
}
|
|
1423
|
+
return asAnyOf(def, refs);
|
|
1424
|
+
}
|
|
1425
|
+
var asAnyOf = (def, refs) => {
|
|
1426
|
+
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map(
|
|
1427
|
+
(x, i) => parseDef(x._def, __spreadProps(__spreadValues({}, refs), {
|
|
1428
|
+
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
1429
|
+
}))
|
|
1430
|
+
).filter(
|
|
1431
|
+
(x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0)
|
|
1432
|
+
);
|
|
1433
|
+
return anyOf.length ? { anyOf } : void 0;
|
|
1434
|
+
};
|
|
1435
|
+
function parseNullableDef(def, refs) {
|
|
1436
|
+
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(
|
|
1437
|
+
def.innerType._def.typeName
|
|
1438
|
+
) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
1439
|
+
return {
|
|
1440
|
+
type: [
|
|
1441
|
+
primitiveMappings[def.innerType._def.typeName],
|
|
1442
|
+
"null"
|
|
1443
|
+
]
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
const base = parseDef(def.innerType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1447
|
+
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
1448
|
+
}));
|
|
1449
|
+
return base && { anyOf: [base, { type: "null" }] };
|
|
1450
|
+
}
|
|
1451
|
+
function parseNumberDef(def) {
|
|
1452
|
+
const res = {
|
|
1453
|
+
type: "number"
|
|
1454
|
+
};
|
|
1455
|
+
if (!def.checks) return res;
|
|
1456
|
+
for (const check of def.checks) {
|
|
1457
|
+
switch (check.kind) {
|
|
1458
|
+
case "int":
|
|
1459
|
+
res.type = "integer";
|
|
1460
|
+
break;
|
|
1461
|
+
case "min":
|
|
1462
|
+
if (check.inclusive) {
|
|
1463
|
+
res.minimum = check.value;
|
|
1464
|
+
} else {
|
|
1465
|
+
res.exclusiveMinimum = check.value;
|
|
1466
|
+
}
|
|
1467
|
+
break;
|
|
1468
|
+
case "max":
|
|
1469
|
+
if (check.inclusive) {
|
|
1470
|
+
res.maximum = check.value;
|
|
1471
|
+
} else {
|
|
1472
|
+
res.exclusiveMaximum = check.value;
|
|
1473
|
+
}
|
|
1474
|
+
break;
|
|
1475
|
+
case "multipleOf":
|
|
1476
|
+
res.multipleOf = check.value;
|
|
1477
|
+
break;
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
return res;
|
|
1481
|
+
}
|
|
1482
|
+
function parseObjectDef(def, refs) {
|
|
1483
|
+
const result = {
|
|
1484
|
+
type: "object",
|
|
1485
|
+
properties: {}
|
|
1486
|
+
};
|
|
1487
|
+
const required = [];
|
|
1488
|
+
const shape = def.shape();
|
|
1489
|
+
for (const propName in shape) {
|
|
1490
|
+
let propDef = shape[propName];
|
|
1491
|
+
if (propDef === void 0 || propDef._def === void 0) {
|
|
1492
|
+
continue;
|
|
1493
|
+
}
|
|
1494
|
+
const propOptional = safeIsOptional(propDef);
|
|
1495
|
+
const parsedDef = parseDef(propDef._def, __spreadProps(__spreadValues({}, refs), {
|
|
1496
|
+
currentPath: [...refs.currentPath, "properties", propName],
|
|
1497
|
+
propertyPath: [...refs.currentPath, "properties", propName]
|
|
1498
|
+
}));
|
|
1499
|
+
if (parsedDef === void 0) {
|
|
1500
|
+
continue;
|
|
1501
|
+
}
|
|
1502
|
+
result.properties[propName] = parsedDef;
|
|
1503
|
+
if (!propOptional) {
|
|
1504
|
+
required.push(propName);
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
if (required.length) {
|
|
1508
|
+
result.required = required;
|
|
1509
|
+
}
|
|
1510
|
+
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
1511
|
+
if (additionalProperties !== void 0) {
|
|
1512
|
+
result.additionalProperties = additionalProperties;
|
|
1513
|
+
}
|
|
1514
|
+
return result;
|
|
1515
|
+
}
|
|
1516
|
+
function decideAdditionalProperties(def, refs) {
|
|
1517
|
+
if (def.catchall._def.typeName !== "ZodNever") {
|
|
1518
|
+
return parseDef(def.catchall._def, __spreadProps(__spreadValues({}, refs), {
|
|
1519
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1520
|
+
}));
|
|
1521
|
+
}
|
|
1522
|
+
switch (def.unknownKeys) {
|
|
1523
|
+
case "passthrough":
|
|
1524
|
+
return refs.allowedAdditionalProperties;
|
|
1525
|
+
case "strict":
|
|
1526
|
+
return refs.rejectedAdditionalProperties;
|
|
1527
|
+
case "strip":
|
|
1528
|
+
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
function safeIsOptional(schema) {
|
|
1532
|
+
try {
|
|
1533
|
+
return schema.isOptional();
|
|
1534
|
+
} catch (e) {
|
|
1535
|
+
return true;
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
var parseOptionalDef = (def, refs) => {
|
|
1539
|
+
var _a22;
|
|
1540
|
+
if (refs.currentPath.toString() === ((_a22 = refs.propertyPath) == null ? void 0 : _a22.toString())) {
|
|
1541
|
+
return parseDef(def.innerType._def, refs);
|
|
1542
|
+
}
|
|
1543
|
+
const innerSchema = parseDef(def.innerType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1544
|
+
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
1545
|
+
}));
|
|
1546
|
+
return innerSchema ? { anyOf: [{ not: parseAnyDef() }, innerSchema] } : parseAnyDef();
|
|
1547
|
+
};
|
|
1548
|
+
var parsePipelineDef = (def, refs) => {
|
|
1549
|
+
if (refs.pipeStrategy === "input") {
|
|
1550
|
+
return parseDef(def.in._def, refs);
|
|
1551
|
+
} else if (refs.pipeStrategy === "output") {
|
|
1552
|
+
return parseDef(def.out._def, refs);
|
|
1553
|
+
}
|
|
1554
|
+
const a = parseDef(def.in._def, __spreadProps(__spreadValues({}, refs), {
|
|
1555
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1556
|
+
}));
|
|
1557
|
+
const b = parseDef(def.out._def, __spreadProps(__spreadValues({}, refs), {
|
|
1558
|
+
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
1559
|
+
}));
|
|
1560
|
+
return {
|
|
1561
|
+
allOf: [a, b].filter((x) => x !== void 0)
|
|
1562
|
+
};
|
|
1563
|
+
};
|
|
1564
|
+
function parsePromiseDef(def, refs) {
|
|
1565
|
+
return parseDef(def.type._def, refs);
|
|
1566
|
+
}
|
|
1567
|
+
function parseSetDef(def, refs) {
|
|
1568
|
+
const items = parseDef(def.valueType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1569
|
+
currentPath: [...refs.currentPath, "items"]
|
|
1570
|
+
}));
|
|
1571
|
+
const schema = {
|
|
1572
|
+
type: "array",
|
|
1573
|
+
uniqueItems: true,
|
|
1574
|
+
items
|
|
1575
|
+
};
|
|
1576
|
+
if (def.minSize) {
|
|
1577
|
+
schema.minItems = def.minSize.value;
|
|
1578
|
+
}
|
|
1579
|
+
if (def.maxSize) {
|
|
1580
|
+
schema.maxItems = def.maxSize.value;
|
|
1581
|
+
}
|
|
1582
|
+
return schema;
|
|
1583
|
+
}
|
|
1584
|
+
function parseTupleDef(def, refs) {
|
|
1585
|
+
if (def.rest) {
|
|
1586
|
+
return {
|
|
1587
|
+
type: "array",
|
|
1588
|
+
minItems: def.items.length,
|
|
1589
|
+
items: def.items.map(
|
|
1590
|
+
(x, i) => parseDef(x._def, __spreadProps(__spreadValues({}, refs), {
|
|
1591
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1592
|
+
}))
|
|
1593
|
+
).reduce(
|
|
1594
|
+
(acc, x) => x === void 0 ? acc : [...acc, x],
|
|
1595
|
+
[]
|
|
1596
|
+
),
|
|
1597
|
+
additionalItems: parseDef(def.rest._def, __spreadProps(__spreadValues({}, refs), {
|
|
1598
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
1599
|
+
}))
|
|
1600
|
+
};
|
|
1601
|
+
} else {
|
|
1602
|
+
return {
|
|
1603
|
+
type: "array",
|
|
1604
|
+
minItems: def.items.length,
|
|
1605
|
+
maxItems: def.items.length,
|
|
1606
|
+
items: def.items.map(
|
|
1607
|
+
(x, i) => parseDef(x._def, __spreadProps(__spreadValues({}, refs), {
|
|
1608
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1609
|
+
}))
|
|
1610
|
+
).reduce(
|
|
1611
|
+
(acc, x) => x === void 0 ? acc : [...acc, x],
|
|
1612
|
+
[]
|
|
1613
|
+
)
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
function parseUndefinedDef() {
|
|
1618
|
+
return {
|
|
1619
|
+
not: parseAnyDef()
|
|
1620
|
+
};
|
|
1621
|
+
}
|
|
1622
|
+
function parseUnknownDef() {
|
|
1623
|
+
return parseAnyDef();
|
|
1624
|
+
}
|
|
1625
|
+
var parseReadonlyDef = (def, refs) => {
|
|
1626
|
+
return parseDef(def.innerType._def, refs);
|
|
1627
|
+
};
|
|
1628
|
+
var selectParser = (def, typeName, refs) => {
|
|
1629
|
+
switch (typeName) {
|
|
1630
|
+
case import_v3.ZodFirstPartyTypeKind.ZodString:
|
|
1631
|
+
return parseStringDef(def, refs);
|
|
1632
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNumber:
|
|
1633
|
+
return parseNumberDef(def);
|
|
1634
|
+
case import_v3.ZodFirstPartyTypeKind.ZodObject:
|
|
1635
|
+
return parseObjectDef(def, refs);
|
|
1636
|
+
case import_v3.ZodFirstPartyTypeKind.ZodBigInt:
|
|
1637
|
+
return parseBigintDef(def);
|
|
1638
|
+
case import_v3.ZodFirstPartyTypeKind.ZodBoolean:
|
|
1639
|
+
return parseBooleanDef();
|
|
1640
|
+
case import_v3.ZodFirstPartyTypeKind.ZodDate:
|
|
1641
|
+
return parseDateDef(def, refs);
|
|
1642
|
+
case import_v3.ZodFirstPartyTypeKind.ZodUndefined:
|
|
1643
|
+
return parseUndefinedDef();
|
|
1644
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNull:
|
|
1645
|
+
return parseNullDef();
|
|
1646
|
+
case import_v3.ZodFirstPartyTypeKind.ZodArray:
|
|
1647
|
+
return parseArrayDef(def, refs);
|
|
1648
|
+
case import_v3.ZodFirstPartyTypeKind.ZodUnion:
|
|
1649
|
+
case import_v3.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
|
|
1650
|
+
return parseUnionDef(def, refs);
|
|
1651
|
+
case import_v3.ZodFirstPartyTypeKind.ZodIntersection:
|
|
1652
|
+
return parseIntersectionDef(def, refs);
|
|
1653
|
+
case import_v3.ZodFirstPartyTypeKind.ZodTuple:
|
|
1654
|
+
return parseTupleDef(def, refs);
|
|
1655
|
+
case import_v3.ZodFirstPartyTypeKind.ZodRecord:
|
|
1656
|
+
return parseRecordDef(def, refs);
|
|
1657
|
+
case import_v3.ZodFirstPartyTypeKind.ZodLiteral:
|
|
1658
|
+
return parseLiteralDef(def);
|
|
1659
|
+
case import_v3.ZodFirstPartyTypeKind.ZodEnum:
|
|
1660
|
+
return parseEnumDef(def);
|
|
1661
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNativeEnum:
|
|
1662
|
+
return parseNativeEnumDef(def);
|
|
1663
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNullable:
|
|
1664
|
+
return parseNullableDef(def, refs);
|
|
1665
|
+
case import_v3.ZodFirstPartyTypeKind.ZodOptional:
|
|
1666
|
+
return parseOptionalDef(def, refs);
|
|
1667
|
+
case import_v3.ZodFirstPartyTypeKind.ZodMap:
|
|
1668
|
+
return parseMapDef(def, refs);
|
|
1669
|
+
case import_v3.ZodFirstPartyTypeKind.ZodSet:
|
|
1670
|
+
return parseSetDef(def, refs);
|
|
1671
|
+
case import_v3.ZodFirstPartyTypeKind.ZodLazy:
|
|
1672
|
+
return () => def.getter()._def;
|
|
1673
|
+
case import_v3.ZodFirstPartyTypeKind.ZodPromise:
|
|
1674
|
+
return parsePromiseDef(def, refs);
|
|
1675
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNaN:
|
|
1676
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNever:
|
|
1677
|
+
return parseNeverDef();
|
|
1678
|
+
case import_v3.ZodFirstPartyTypeKind.ZodEffects:
|
|
1679
|
+
return parseEffectsDef(def, refs);
|
|
1680
|
+
case import_v3.ZodFirstPartyTypeKind.ZodAny:
|
|
1681
|
+
return parseAnyDef();
|
|
1682
|
+
case import_v3.ZodFirstPartyTypeKind.ZodUnknown:
|
|
1683
|
+
return parseUnknownDef();
|
|
1684
|
+
case import_v3.ZodFirstPartyTypeKind.ZodDefault:
|
|
1685
|
+
return parseDefaultDef(def, refs);
|
|
1686
|
+
case import_v3.ZodFirstPartyTypeKind.ZodBranded:
|
|
1687
|
+
return parseBrandedDef(def, refs);
|
|
1688
|
+
case import_v3.ZodFirstPartyTypeKind.ZodReadonly:
|
|
1689
|
+
return parseReadonlyDef(def, refs);
|
|
1690
|
+
case import_v3.ZodFirstPartyTypeKind.ZodCatch:
|
|
1691
|
+
return parseCatchDef(def, refs);
|
|
1692
|
+
case import_v3.ZodFirstPartyTypeKind.ZodPipeline:
|
|
1693
|
+
return parsePipelineDef(def, refs);
|
|
1694
|
+
case import_v3.ZodFirstPartyTypeKind.ZodFunction:
|
|
1695
|
+
case import_v3.ZodFirstPartyTypeKind.ZodVoid:
|
|
1696
|
+
case import_v3.ZodFirstPartyTypeKind.ZodSymbol:
|
|
1697
|
+
return void 0;
|
|
1698
|
+
default:
|
|
1699
|
+
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
1700
|
+
}
|
|
1701
|
+
};
|
|
1702
|
+
var getRelativePath = (pathA, pathB) => {
|
|
1703
|
+
let i = 0;
|
|
1704
|
+
for (; i < pathA.length && i < pathB.length; i++) {
|
|
1705
|
+
if (pathA[i] !== pathB[i]) break;
|
|
1706
|
+
}
|
|
1707
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
1708
|
+
};
|
|
1709
|
+
function parseDef(def, refs, forceResolution = false) {
|
|
1710
|
+
var _a22;
|
|
1711
|
+
const seenItem = refs.seen.get(def);
|
|
1712
|
+
if (refs.override) {
|
|
1713
|
+
const overrideResult = (_a22 = refs.override) == null ? void 0 : _a22.call(
|
|
1714
|
+
refs,
|
|
1715
|
+
def,
|
|
1716
|
+
refs,
|
|
1717
|
+
seenItem,
|
|
1718
|
+
forceResolution
|
|
1719
|
+
);
|
|
1720
|
+
if (overrideResult !== ignoreOverride) {
|
|
1721
|
+
return overrideResult;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
if (seenItem && !forceResolution) {
|
|
1725
|
+
const seenSchema = get$ref(seenItem, refs);
|
|
1726
|
+
if (seenSchema !== void 0) {
|
|
1727
|
+
return seenSchema;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
1731
|
+
refs.seen.set(def, newItem);
|
|
1732
|
+
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
1733
|
+
const jsonSchema2 = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
1734
|
+
if (jsonSchema2) {
|
|
1735
|
+
addMeta(def, refs, jsonSchema2);
|
|
1736
|
+
}
|
|
1737
|
+
if (refs.postProcess) {
|
|
1738
|
+
const postProcessResult = refs.postProcess(jsonSchema2, def, refs);
|
|
1739
|
+
newItem.jsonSchema = jsonSchema2;
|
|
1740
|
+
return postProcessResult;
|
|
1741
|
+
}
|
|
1742
|
+
newItem.jsonSchema = jsonSchema2;
|
|
1743
|
+
return jsonSchema2;
|
|
1744
|
+
}
|
|
1745
|
+
var get$ref = (item, refs) => {
|
|
1746
|
+
switch (refs.$refStrategy) {
|
|
1747
|
+
case "root":
|
|
1748
|
+
return { $ref: item.path.join("/") };
|
|
1749
|
+
case "relative":
|
|
1750
|
+
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
1751
|
+
case "none":
|
|
1752
|
+
case "seen": {
|
|
1753
|
+
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
1754
|
+
console.warn(
|
|
1755
|
+
`Recursive reference detected at ${refs.currentPath.join(
|
|
1756
|
+
"/"
|
|
1757
|
+
)}! Defaulting to any`
|
|
1758
|
+
);
|
|
1759
|
+
return parseAnyDef();
|
|
1760
|
+
}
|
|
1761
|
+
return refs.$refStrategy === "seen" ? parseAnyDef() : void 0;
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
};
|
|
1765
|
+
var addMeta = (def, refs, jsonSchema2) => {
|
|
1766
|
+
if (def.description) {
|
|
1767
|
+
jsonSchema2.description = def.description;
|
|
1768
|
+
}
|
|
1769
|
+
return jsonSchema2;
|
|
1770
|
+
};
|
|
1771
|
+
var getRefs = (options) => {
|
|
1772
|
+
const _options = getDefaultOptions(options);
|
|
1773
|
+
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
1774
|
+
return __spreadProps(__spreadValues({}, _options), {
|
|
1775
|
+
currentPath,
|
|
1776
|
+
propertyPath: void 0,
|
|
1777
|
+
seen: new Map(
|
|
1778
|
+
Object.entries(_options.definitions).map(([name22, def]) => [
|
|
1779
|
+
def._def,
|
|
1780
|
+
{
|
|
1781
|
+
def: def._def,
|
|
1782
|
+
path: [..._options.basePath, _options.definitionPath, name22],
|
|
1783
|
+
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
1784
|
+
jsonSchema: void 0
|
|
1785
|
+
}
|
|
1786
|
+
])
|
|
1787
|
+
)
|
|
619
1788
|
});
|
|
1789
|
+
};
|
|
1790
|
+
var zod3ToJsonSchema = (schema, options) => {
|
|
1791
|
+
var _a22;
|
|
1792
|
+
const refs = getRefs(options);
|
|
1793
|
+
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
|
|
1794
|
+
(acc, [name32, schema2]) => {
|
|
1795
|
+
var _a32;
|
|
1796
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1797
|
+
[name32]: (_a32 = parseDef(
|
|
1798
|
+
schema2._def,
|
|
1799
|
+
__spreadProps(__spreadValues({}, refs), {
|
|
1800
|
+
currentPath: [...refs.basePath, refs.definitionPath, name32]
|
|
1801
|
+
}),
|
|
1802
|
+
true
|
|
1803
|
+
)) != null ? _a32 : parseAnyDef()
|
|
1804
|
+
});
|
|
1805
|
+
},
|
|
1806
|
+
{}
|
|
1807
|
+
) : void 0;
|
|
1808
|
+
const name22 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
1809
|
+
const main = (_a22 = parseDef(
|
|
1810
|
+
schema._def,
|
|
1811
|
+
name22 === void 0 ? refs : __spreadProps(__spreadValues({}, refs), {
|
|
1812
|
+
currentPath: [...refs.basePath, refs.definitionPath, name22]
|
|
1813
|
+
}),
|
|
1814
|
+
false
|
|
1815
|
+
)) != null ? _a22 : parseAnyDef();
|
|
1816
|
+
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
1817
|
+
if (title !== void 0) {
|
|
1818
|
+
main.title = title;
|
|
1819
|
+
}
|
|
1820
|
+
const combined = name22 === void 0 ? definitions ? __spreadProps(__spreadValues({}, main), {
|
|
1821
|
+
[refs.definitionPath]: definitions
|
|
1822
|
+
}) : main : {
|
|
1823
|
+
$ref: [
|
|
1824
|
+
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
1825
|
+
refs.definitionPath,
|
|
1826
|
+
name22
|
|
1827
|
+
].join("/"),
|
|
1828
|
+
[refs.definitionPath]: __spreadProps(__spreadValues({}, definitions), {
|
|
1829
|
+
[name22]: main
|
|
1830
|
+
})
|
|
1831
|
+
};
|
|
1832
|
+
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
1833
|
+
return combined;
|
|
1834
|
+
};
|
|
1835
|
+
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
|
1836
|
+
function jsonSchema(jsonSchema2, {
|
|
1837
|
+
validate
|
|
1838
|
+
} = {}) {
|
|
1839
|
+
return {
|
|
1840
|
+
[schemaSymbol]: true,
|
|
1841
|
+
_type: void 0,
|
|
1842
|
+
// should never be used directly
|
|
1843
|
+
get jsonSchema() {
|
|
1844
|
+
if (typeof jsonSchema2 === "function") {
|
|
1845
|
+
jsonSchema2 = jsonSchema2();
|
|
1846
|
+
}
|
|
1847
|
+
return jsonSchema2;
|
|
1848
|
+
},
|
|
1849
|
+
validate
|
|
1850
|
+
};
|
|
1851
|
+
}
|
|
1852
|
+
function isSchema(value) {
|
|
1853
|
+
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
|
1854
|
+
}
|
|
1855
|
+
function asSchema(schema) {
|
|
1856
|
+
return schema == null ? jsonSchema({ properties: {}, additionalProperties: false }) : isSchema(schema) ? schema : "~standard" in schema ? schema["~standard"].vendor === "zod" ? zodSchema(schema) : standardSchema(schema) : schema();
|
|
1857
|
+
}
|
|
1858
|
+
function standardSchema(standardSchema2) {
|
|
1859
|
+
return jsonSchema(
|
|
1860
|
+
() => standardSchema2["~standard"].jsonSchema.input({
|
|
1861
|
+
target: "draft-07"
|
|
1862
|
+
}),
|
|
1863
|
+
{
|
|
1864
|
+
validate: async (value) => {
|
|
1865
|
+
const result = await standardSchema2["~standard"].validate(value);
|
|
1866
|
+
return "value" in result ? { success: true, value: result.value } : {
|
|
1867
|
+
success: false,
|
|
1868
|
+
error: new TypeValidationError({
|
|
1869
|
+
value,
|
|
1870
|
+
cause: result.issues
|
|
1871
|
+
})
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
);
|
|
1876
|
+
}
|
|
1877
|
+
function zod3Schema(zodSchema2, options) {
|
|
1878
|
+
var _a22;
|
|
1879
|
+
const useReferences = (_a22 = options == null ? void 0 : options.useReferences) != null ? _a22 : false;
|
|
1880
|
+
return jsonSchema(
|
|
1881
|
+
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
1882
|
+
() => zod3ToJsonSchema(zodSchema2, {
|
|
1883
|
+
$refStrategy: useReferences ? "root" : "none"
|
|
1884
|
+
}),
|
|
1885
|
+
{
|
|
1886
|
+
validate: async (value) => {
|
|
1887
|
+
const result = await zodSchema2.safeParseAsync(value);
|
|
1888
|
+
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
);
|
|
1892
|
+
}
|
|
1893
|
+
function zod4Schema(zodSchema2, options) {
|
|
1894
|
+
var _a22;
|
|
1895
|
+
const useReferences = (_a22 = options == null ? void 0 : options.useReferences) != null ? _a22 : false;
|
|
1896
|
+
return jsonSchema(
|
|
1897
|
+
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
1898
|
+
() => addAdditionalPropertiesToJsonSchema(
|
|
1899
|
+
z4.toJSONSchema(zodSchema2, {
|
|
1900
|
+
target: "draft-7",
|
|
1901
|
+
io: "input",
|
|
1902
|
+
reused: useReferences ? "ref" : "inline"
|
|
1903
|
+
})
|
|
1904
|
+
),
|
|
1905
|
+
{
|
|
1906
|
+
validate: async (value) => {
|
|
1907
|
+
const result = await z4.safeParseAsync(zodSchema2, value);
|
|
1908
|
+
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
);
|
|
1912
|
+
}
|
|
1913
|
+
function isZod4Schema(zodSchema2) {
|
|
1914
|
+
return "_zod" in zodSchema2;
|
|
1915
|
+
}
|
|
1916
|
+
function zodSchema(zodSchema2, options) {
|
|
1917
|
+
if (isZod4Schema(zodSchema2)) {
|
|
1918
|
+
return zod4Schema(zodSchema2, options);
|
|
1919
|
+
} else {
|
|
1920
|
+
return zod3Schema(zodSchema2, options);
|
|
1921
|
+
}
|
|
620
1922
|
}
|
|
621
1923
|
async function validateTypes({
|
|
622
1924
|
value,
|
|
@@ -632,12 +1934,12 @@ async function safeValidateTypes({
|
|
|
632
1934
|
value,
|
|
633
1935
|
schema
|
|
634
1936
|
}) {
|
|
635
|
-
const
|
|
1937
|
+
const actualSchema = asSchema(schema);
|
|
636
1938
|
try {
|
|
637
|
-
if (
|
|
1939
|
+
if (actualSchema.validate == null) {
|
|
638
1940
|
return { success: true, value, rawValue: value };
|
|
639
1941
|
}
|
|
640
|
-
const result = await
|
|
1942
|
+
const result = await actualSchema.validate(value);
|
|
641
1943
|
if (result.success) {
|
|
642
1944
|
return { success: true, value: result.value, rawValue: value };
|
|
643
1945
|
}
|
|
@@ -720,7 +2022,7 @@ var postJsonToApi = async ({
|
|
|
720
2022
|
failedResponseHandler,
|
|
721
2023
|
successfulResponseHandler,
|
|
722
2024
|
abortSignal,
|
|
723
|
-
fetch
|
|
2025
|
+
fetch: fetch2
|
|
724
2026
|
}) => postToApi({
|
|
725
2027
|
url,
|
|
726
2028
|
headers: __spreadValues({
|
|
@@ -733,7 +2035,7 @@ var postJsonToApi = async ({
|
|
|
733
2035
|
failedResponseHandler,
|
|
734
2036
|
successfulResponseHandler,
|
|
735
2037
|
abortSignal,
|
|
736
|
-
fetch
|
|
2038
|
+
fetch: fetch2
|
|
737
2039
|
});
|
|
738
2040
|
var postToApi = async ({
|
|
739
2041
|
url,
|
|
@@ -742,12 +2044,16 @@ var postToApi = async ({
|
|
|
742
2044
|
successfulResponseHandler,
|
|
743
2045
|
failedResponseHandler,
|
|
744
2046
|
abortSignal,
|
|
745
|
-
fetch = getOriginalFetch2()
|
|
2047
|
+
fetch: fetch2 = getOriginalFetch2()
|
|
746
2048
|
}) => {
|
|
747
2049
|
try {
|
|
748
|
-
const response = await
|
|
2050
|
+
const response = await fetch2(url, {
|
|
749
2051
|
method: "POST",
|
|
750
|
-
headers:
|
|
2052
|
+
headers: withUserAgentSuffix(
|
|
2053
|
+
headers,
|
|
2054
|
+
`ai-sdk/provider-utils/${VERSION}`,
|
|
2055
|
+
getRuntimeEnvironmentUserAgent()
|
|
2056
|
+
),
|
|
751
2057
|
body: body.content,
|
|
752
2058
|
signal: abortSignal
|
|
753
2059
|
});
|
|
@@ -891,15 +2197,6 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
891
2197
|
rawValue: parsedResult.rawValue
|
|
892
2198
|
};
|
|
893
2199
|
};
|
|
894
|
-
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
|
895
|
-
var { btoa, atob } = globalThis;
|
|
896
|
-
function convertUint8ArrayToBase64(array) {
|
|
897
|
-
let latin1string = "";
|
|
898
|
-
for (let i = 0; i < array.length; i++) {
|
|
899
|
-
latin1string += String.fromCodePoint(array[i]);
|
|
900
|
-
}
|
|
901
|
-
return btoa(latin1string);
|
|
902
|
-
}
|
|
903
2200
|
|
|
904
2201
|
// src/schemas/error-response.ts
|
|
905
2202
|
var import_v42 = require("zod/v4");
|
|
@@ -951,10 +2248,10 @@ function getFileUrl({
|
|
|
951
2248
|
part,
|
|
952
2249
|
defaultMediaType
|
|
953
2250
|
}) {
|
|
954
|
-
var
|
|
2251
|
+
var _a16, _b16;
|
|
955
2252
|
if (part.data instanceof Uint8Array) {
|
|
956
2253
|
const base64 = convertUint8ArrayToBase64(part.data);
|
|
957
|
-
return `data:${(
|
|
2254
|
+
return `data:${(_a16 = part.mediaType) != null ? _a16 : defaultMediaType};base64,${base64}`;
|
|
958
2255
|
}
|
|
959
2256
|
const stringUrl = part.data.toString();
|
|
960
2257
|
if (isUrl({
|
|
@@ -963,12 +2260,12 @@ function getFileUrl({
|
|
|
963
2260
|
})) {
|
|
964
2261
|
return stringUrl;
|
|
965
2262
|
}
|
|
966
|
-
return stringUrl.startsWith("data:") ? stringUrl : `data:${(
|
|
2263
|
+
return stringUrl.startsWith("data:") ? stringUrl : `data:${(_b16 = part.mediaType) != null ? _b16 : defaultMediaType};base64,${stringUrl}`;
|
|
967
2264
|
}
|
|
968
2265
|
function getMediaType(dataUrl, defaultMediaType) {
|
|
969
|
-
var
|
|
2266
|
+
var _a16;
|
|
970
2267
|
const match = dataUrl.match(/^data:([^;]+)/);
|
|
971
|
-
return match ? (
|
|
2268
|
+
return match ? (_a16 = match[1]) != null ? _a16 : defaultMediaType : defaultMediaType;
|
|
972
2269
|
}
|
|
973
2270
|
function getBase64FromDataUrl(dataUrl) {
|
|
974
2271
|
const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
|
|
@@ -976,14 +2273,14 @@ function getBase64FromDataUrl(dataUrl) {
|
|
|
976
2273
|
}
|
|
977
2274
|
|
|
978
2275
|
// src/chat/convert-to-llmgateway-chat-messages.ts
|
|
979
|
-
function getCacheControl(
|
|
980
|
-
var
|
|
981
|
-
const anthropic =
|
|
982
|
-
const llmgateway =
|
|
983
|
-
return (_c = (
|
|
2276
|
+
function getCacheControl(providerOptions) {
|
|
2277
|
+
var _a16, _b16, _c;
|
|
2278
|
+
const anthropic = providerOptions == null ? void 0 : providerOptions.anthropic;
|
|
2279
|
+
const llmgateway = providerOptions == null ? void 0 : providerOptions.llmgateway;
|
|
2280
|
+
return (_c = (_b16 = (_a16 = llmgateway == null ? void 0 : llmgateway.cacheControl) != null ? _a16 : llmgateway == null ? void 0 : llmgateway.cache_control) != null ? _b16 : anthropic == null ? void 0 : anthropic.cacheControl) != null ? _c : anthropic == null ? void 0 : anthropic.cache_control;
|
|
984
2281
|
}
|
|
985
2282
|
function convertToLLMGatewayChatMessages(prompt) {
|
|
986
|
-
var
|
|
2283
|
+
var _a16, _b16, _c;
|
|
987
2284
|
const messages = [];
|
|
988
2285
|
for (const { role, content, providerOptions } of prompt) {
|
|
989
2286
|
switch (role) {
|
|
@@ -996,8 +2293,8 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
996
2293
|
break;
|
|
997
2294
|
}
|
|
998
2295
|
case "user": {
|
|
999
|
-
if (content.length === 1 && ((
|
|
1000
|
-
const cacheControl = (
|
|
2296
|
+
if (content.length === 1 && ((_a16 = content[0]) == null ? void 0 : _a16.type) === "text") {
|
|
2297
|
+
const cacheControl = (_b16 = getCacheControl(providerOptions)) != null ? _b16 : getCacheControl(content[0].providerOptions);
|
|
1001
2298
|
const contentWithCacheControl = cacheControl ? [
|
|
1002
2299
|
{
|
|
1003
2300
|
type: "text",
|
|
@@ -1014,8 +2311,8 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
1014
2311
|
const messageCacheControl = getCacheControl(providerOptions);
|
|
1015
2312
|
const contentParts = content.map(
|
|
1016
2313
|
(part) => {
|
|
1017
|
-
var
|
|
1018
|
-
const cacheControl = (
|
|
2314
|
+
var _a17, _b17, _c2, _d, _e, _f;
|
|
2315
|
+
const cacheControl = (_a17 = getCacheControl(part.providerOptions)) != null ? _a17 : messageCacheControl;
|
|
1019
2316
|
switch (part.type) {
|
|
1020
2317
|
case "text":
|
|
1021
2318
|
return {
|
|
@@ -1025,7 +2322,7 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
1025
2322
|
cache_control: cacheControl
|
|
1026
2323
|
};
|
|
1027
2324
|
case "file": {
|
|
1028
|
-
if ((
|
|
2325
|
+
if ((_b17 = part.mediaType) == null ? void 0 : _b17.startsWith("image/")) {
|
|
1029
2326
|
const url = getFileUrl({
|
|
1030
2327
|
part,
|
|
1031
2328
|
defaultMediaType: "image/jpeg"
|
|
@@ -1124,7 +2421,7 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
1124
2421
|
role: "assistant",
|
|
1125
2422
|
content: text,
|
|
1126
2423
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
1127
|
-
|
|
2424
|
+
reasoningText: reasoning || void 0,
|
|
1128
2425
|
reasoning_details: reasoningDetails.length > 0 ? reasoningDetails : void 0,
|
|
1129
2426
|
cache_control: getCacheControl(providerOptions)
|
|
1130
2427
|
});
|
|
@@ -1229,6 +2526,7 @@ var LLMGatewayNonStreamChatCompletionResponseSchema = LLMGatewayChatCompletionBa
|
|
|
1229
2526
|
role: import_v45.z.literal("assistant"),
|
|
1230
2527
|
content: import_v45.z.string().nullable().optional(),
|
|
1231
2528
|
reasoning: import_v45.z.string().nullable().optional(),
|
|
2529
|
+
reasoningText: import_v45.z.string().nullable().optional(),
|
|
1232
2530
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1233
2531
|
images: ImageResponseArraySchema.nullish(),
|
|
1234
2532
|
tool_calls: import_v45.z.array(
|
|
@@ -1269,6 +2567,7 @@ var LLMGatewayStreamChatCompletionChunkSchema = import_v45.z.union([
|
|
|
1269
2567
|
role: import_v45.z.enum(["assistant"]).optional(),
|
|
1270
2568
|
content: import_v45.z.string().nullish(),
|
|
1271
2569
|
reasoning: import_v45.z.string().nullish().optional(),
|
|
2570
|
+
reasoningText: import_v45.z.string().nullish().optional(),
|
|
1272
2571
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1273
2572
|
images: ImageResponseArraySchema.nullish(),
|
|
1274
2573
|
tool_calls: import_v45.z.array(
|
|
@@ -1361,10 +2660,8 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1361
2660
|
messages: convertToLLMGatewayChatMessages(prompt),
|
|
1362
2661
|
// LLMGateway specific settings:
|
|
1363
2662
|
include_reasoning: this.settings.includeReasoning,
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
usage: this.settings.usage,
|
|
1367
|
-
image_config: this.settings.image_config
|
|
2663
|
+
reasoningText: this.settings.reasoningText,
|
|
2664
|
+
usage: this.settings.usage
|
|
1368
2665
|
}, this.config.extraBody), this.settings.extraBody);
|
|
1369
2666
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
|
|
1370
2667
|
if ("schema" in responseFormat && responseFormat.schema) {
|
|
@@ -1390,7 +2687,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1390
2687
|
function: {
|
|
1391
2688
|
name: tool.name,
|
|
1392
2689
|
description: tool.type,
|
|
1393
|
-
|
|
2690
|
+
inputSchema: tool.inputSchema
|
|
1394
2691
|
}
|
|
1395
2692
|
}));
|
|
1396
2693
|
return __spreadProps(__spreadValues({}, baseArgs), {
|
|
@@ -1401,10 +2698,11 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1401
2698
|
return baseArgs;
|
|
1402
2699
|
}
|
|
1403
2700
|
async doGenerate(options) {
|
|
1404
|
-
var
|
|
2701
|
+
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;
|
|
1405
2702
|
const providerOptions = options.providerOptions || {};
|
|
1406
2703
|
const llmgatewayOptions = providerOptions.llmgateway || {};
|
|
1407
2704
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
|
|
2705
|
+
const includeUsageAccounting = ((_a16 = args.usage) == null ? void 0 : _a16.include) === true;
|
|
1408
2706
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
1409
2707
|
url: this.config.url({
|
|
1410
2708
|
path: "/chat/completions",
|
|
@@ -1424,11 +2722,11 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1424
2722
|
throw new Error("No choice in response");
|
|
1425
2723
|
}
|
|
1426
2724
|
const usageInfo = response.usage ? {
|
|
1427
|
-
inputTokens: (
|
|
1428
|
-
outputTokens: (
|
|
1429
|
-
totalTokens: ((
|
|
1430
|
-
reasoningTokens: (
|
|
1431
|
-
cachedInputTokens: (
|
|
2725
|
+
inputTokens: (_b16 = response.usage.prompt_tokens) != null ? _b16 : 0,
|
|
2726
|
+
outputTokens: (_c = response.usage.completion_tokens) != null ? _c : 0,
|
|
2727
|
+
totalTokens: ((_d = response.usage.prompt_tokens) != null ? _d : 0) + ((_e = response.usage.completion_tokens) != null ? _e : 0),
|
|
2728
|
+
reasoningTokens: (_g = (_f = response.usage.completion_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : 0,
|
|
2729
|
+
cachedInputTokens: (_i = (_h = response.usage.prompt_tokens_details) == null ? void 0 : _h.cached_tokens) != null ? _i : 0
|
|
1432
2730
|
} : {
|
|
1433
2731
|
inputTokens: 0,
|
|
1434
2732
|
outputTokens: 0,
|
|
@@ -1436,7 +2734,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1436
2734
|
reasoningTokens: 0,
|
|
1437
2735
|
cachedInputTokens: 0
|
|
1438
2736
|
};
|
|
1439
|
-
const reasoningDetails = (
|
|
2737
|
+
const reasoningDetails = (_j = choice.message.reasoning_details) != null ? _j : [];
|
|
1440
2738
|
const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
1441
2739
|
switch (detail.type) {
|
|
1442
2740
|
case "reasoning.text" /* Text */: {
|
|
@@ -1474,10 +2772,10 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1474
2772
|
return null;
|
|
1475
2773
|
}).filter(
|
|
1476
2774
|
(p) => p !== null
|
|
1477
|
-
) : choice.message.
|
|
2775
|
+
) : choice.message.reasoningText ? [
|
|
1478
2776
|
{
|
|
1479
2777
|
type: "reasoning",
|
|
1480
|
-
text: choice.message.
|
|
2778
|
+
text: choice.message.reasoningText
|
|
1481
2779
|
}
|
|
1482
2780
|
] : [];
|
|
1483
2781
|
const content = [];
|
|
@@ -1492,7 +2790,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1492
2790
|
for (const toolCall of choice.message.tool_calls) {
|
|
1493
2791
|
content.push({
|
|
1494
2792
|
type: "tool-call",
|
|
1495
|
-
toolCallId: (
|
|
2793
|
+
toolCallId: (_k = toolCall.id) != null ? _k : generateId(),
|
|
1496
2794
|
toolName: toolCall.function.name,
|
|
1497
2795
|
input: toolCall.function.arguments
|
|
1498
2796
|
});
|
|
@@ -1517,7 +2815,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1517
2815
|
url: annotation.url_citation.url,
|
|
1518
2816
|
title: annotation.url_citation.title,
|
|
1519
2817
|
providerMetadata: {
|
|
1520
|
-
|
|
2818
|
+
llmgateway: {
|
|
1521
2819
|
content: annotation.url_citation.content || ""
|
|
1522
2820
|
}
|
|
1523
2821
|
}
|
|
@@ -1530,25 +2828,25 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1530
2828
|
finishReason: mapLLMGatewayFinishReason(choice.finish_reason),
|
|
1531
2829
|
usage: usageInfo,
|
|
1532
2830
|
warnings: [],
|
|
1533
|
-
providerMetadata: {
|
|
2831
|
+
providerMetadata: includeUsageAccounting ? {
|
|
1534
2832
|
llmgateway: {
|
|
1535
2833
|
usage: {
|
|
1536
|
-
promptTokens: (
|
|
1537
|
-
completionTokens: (
|
|
1538
|
-
totalTokens: (
|
|
1539
|
-
cost: (
|
|
2834
|
+
promptTokens: (_l = usageInfo.inputTokens) != null ? _l : 0,
|
|
2835
|
+
completionTokens: (_m = usageInfo.outputTokens) != null ? _m : 0,
|
|
2836
|
+
totalTokens: (_n = usageInfo.totalTokens) != null ? _n : 0,
|
|
2837
|
+
cost: (_o = response.usage) == null ? void 0 : _o.cost,
|
|
1540
2838
|
promptTokensDetails: {
|
|
1541
|
-
cachedTokens: (
|
|
2839
|
+
cachedTokens: (_r = (_q = (_p = response.usage) == null ? void 0 : _p.prompt_tokens_details) == null ? void 0 : _q.cached_tokens) != null ? _r : 0
|
|
1542
2840
|
},
|
|
1543
2841
|
completionTokensDetails: {
|
|
1544
|
-
reasoningTokens: (
|
|
2842
|
+
reasoningTokens: (_u = (_t = (_s = response.usage) == null ? void 0 : _s.completion_tokens_details) == null ? void 0 : _t.reasoning_tokens) != null ? _u : 0
|
|
1545
2843
|
},
|
|
1546
2844
|
costDetails: {
|
|
1547
|
-
upstreamInferenceCost: (
|
|
2845
|
+
upstreamInferenceCost: (_x = (_w = (_v = response.usage) == null ? void 0 : _v.cost_details) == null ? void 0 : _w.upstream_inference_cost) != null ? _x : 0
|
|
1548
2846
|
}
|
|
1549
2847
|
}
|
|
1550
2848
|
}
|
|
1551
|
-
},
|
|
2849
|
+
} : void 0,
|
|
1552
2850
|
request: { body: args },
|
|
1553
2851
|
response: {
|
|
1554
2852
|
id: response.id,
|
|
@@ -1558,7 +2856,6 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1558
2856
|
};
|
|
1559
2857
|
}
|
|
1560
2858
|
async doStream(options) {
|
|
1561
|
-
var _a15;
|
|
1562
2859
|
const providerOptions = options.providerOptions || {};
|
|
1563
2860
|
const llmgatewayOptions = providerOptions.llmgateway || {};
|
|
1564
2861
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
|
|
@@ -1571,9 +2868,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1571
2868
|
body: __spreadProps(__spreadValues({}, args), {
|
|
1572
2869
|
stream: true,
|
|
1573
2870
|
// only include stream_options when in strict compatibility mode:
|
|
1574
|
-
stream_options: this.config.compatibility === "strict" ?
|
|
1575
|
-
include_usage: true
|
|
1576
|
-
}, ((_a15 = this.settings.usage) == null ? void 0 : _a15.include) ? { include_usage: true } : {}) : void 0
|
|
2871
|
+
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
1577
2872
|
}),
|
|
1578
2873
|
failedResponseHandler: llmgatewayFailedResponseHandler,
|
|
1579
2874
|
successfulResponseHandler: createEventSourceResponseHandler(
|
|
@@ -1601,7 +2896,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1601
2896
|
stream: response.pipeThrough(
|
|
1602
2897
|
new TransformStream({
|
|
1603
2898
|
transform(chunk, controller) {
|
|
1604
|
-
var _a16,
|
|
2899
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1605
2900
|
if (!chunk.success) {
|
|
1606
2901
|
finishReason = "error";
|
|
1607
2902
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -1640,7 +2935,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1640
2935
|
}
|
|
1641
2936
|
llmgatewayUsage.completionTokens = value.usage.completion_tokens;
|
|
1642
2937
|
if (value.usage.completion_tokens_details) {
|
|
1643
|
-
const reasoningTokens = (
|
|
2938
|
+
const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
|
|
1644
2939
|
usage.reasoningTokens = reasoningTokens;
|
|
1645
2940
|
llmgatewayUsage.completionTokensDetails = {
|
|
1646
2941
|
reasoningTokens
|
|
@@ -1699,8 +2994,10 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1699
2994
|
}
|
|
1700
2995
|
}
|
|
1701
2996
|
}
|
|
1702
|
-
} else if (delta.
|
|
1703
|
-
emitReasoningChunk(
|
|
2997
|
+
} else if (delta.reasoningText != null || "reasoning" in delta && typeof delta.reasoning === "string") {
|
|
2998
|
+
emitReasoningChunk(
|
|
2999
|
+
(_d = (_c = delta.reasoningText) != null ? _c : "reasoning" in delta && typeof delta.reasoning === "string" ? delta.reasoning : void 0) != null ? _d : ""
|
|
3000
|
+
);
|
|
1704
3001
|
}
|
|
1705
3002
|
if (delta.content != null) {
|
|
1706
3003
|
if (!textStarted) {
|
|
@@ -1719,7 +3016,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1719
3016
|
}
|
|
1720
3017
|
if (delta.tool_calls != null) {
|
|
1721
3018
|
for (const toolCallDelta of delta.tool_calls) {
|
|
1722
|
-
const index = (
|
|
3019
|
+
const index = (_e = toolCallDelta.index) != null ? _e : toolCalls.length - 1;
|
|
1723
3020
|
if (toolCalls[index] == null) {
|
|
1724
3021
|
if (toolCallDelta.type !== "function") {
|
|
1725
3022
|
throw new InvalidResponseDataError({
|
|
@@ -1733,7 +3030,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1733
3030
|
message: `Expected 'id' to be a string.`
|
|
1734
3031
|
});
|
|
1735
3032
|
}
|
|
1736
|
-
if (((
|
|
3033
|
+
if (((_f = toolCallDelta.function) == null ? void 0 : _f.name) == null) {
|
|
1737
3034
|
throw new InvalidResponseDataError({
|
|
1738
3035
|
data: toolCallDelta,
|
|
1739
3036
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -1744,7 +3041,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1744
3041
|
type: "function",
|
|
1745
3042
|
function: {
|
|
1746
3043
|
name: toolCallDelta.function.name,
|
|
1747
|
-
arguments: (
|
|
3044
|
+
arguments: (_g = toolCallDelta.function.arguments) != null ? _g : ""
|
|
1748
3045
|
},
|
|
1749
3046
|
inputStarted: false,
|
|
1750
3047
|
sent: false
|
|
@@ -1753,7 +3050,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1753
3050
|
if (toolCall2 == null) {
|
|
1754
3051
|
throw new Error("Tool call is missing");
|
|
1755
3052
|
}
|
|
1756
|
-
if (((
|
|
3053
|
+
if (((_h = toolCall2.function) == null ? void 0 : _h.name) != null && ((_i = toolCall2.function) == null ? void 0 : _i.arguments) != null && isParsableJson(toolCall2.function.arguments)) {
|
|
1757
3054
|
toolCall2.inputStarted = true;
|
|
1758
3055
|
controller.enqueue({
|
|
1759
3056
|
type: "tool-input-start",
|
|
@@ -1791,18 +3088,18 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
1791
3088
|
toolName: toolCall.function.name
|
|
1792
3089
|
});
|
|
1793
3090
|
}
|
|
1794
|
-
if (((
|
|
1795
|
-
toolCall.function.arguments += (
|
|
3091
|
+
if (((_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null) {
|
|
3092
|
+
toolCall.function.arguments += (_l = (_k = toolCallDelta.function) == null ? void 0 : _k.arguments) != null ? _l : "";
|
|
1796
3093
|
}
|
|
1797
3094
|
controller.enqueue({
|
|
1798
3095
|
type: "tool-input-delta",
|
|
1799
3096
|
id: toolCall.id,
|
|
1800
|
-
delta: (
|
|
3097
|
+
delta: (_m = toolCallDelta.function.arguments) != null ? _m : ""
|
|
1801
3098
|
});
|
|
1802
|
-
if (((
|
|
3099
|
+
if (((_n = toolCall.function) == null ? void 0 : _n.name) != null && ((_o = toolCall.function) == null ? void 0 : _o.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
1803
3100
|
controller.enqueue({
|
|
1804
3101
|
type: "tool-call",
|
|
1805
|
-
toolCallId: (
|
|
3102
|
+
toolCallId: (_p = toolCall.id) != null ? _p : generateId(),
|
|
1806
3103
|
toolName: toolCall.function.name,
|
|
1807
3104
|
input: toolCall.function.arguments
|
|
1808
3105
|
});
|
|
@@ -1980,7 +3277,7 @@ var LLMGatewayCompletionChunkSchema = import_v46.z.union([
|
|
|
1980
3277
|
choices: import_v46.z.array(
|
|
1981
3278
|
import_v46.z.object({
|
|
1982
3279
|
text: import_v46.z.string(),
|
|
1983
|
-
|
|
3280
|
+
reasoningText: import_v46.z.string().nullish().optional(),
|
|
1984
3281
|
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
1985
3282
|
finish_reason: import_v46.z.string().nullish(),
|
|
1986
3283
|
index: import_v46.z.number().nullish(),
|
|
@@ -2076,13 +3373,11 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
2076
3373
|
prompt: completionPrompt,
|
|
2077
3374
|
// LLMGateway specific settings:
|
|
2078
3375
|
include_reasoning: this.settings.includeReasoning,
|
|
2079
|
-
|
|
2080
|
-
reasoning_effort: this.settings.reasoning_effort,
|
|
2081
|
-
image_config: this.settings.image_config
|
|
3376
|
+
reasoningText: this.settings.reasoningText
|
|
2082
3377
|
}, this.config.extraBody), this.settings.extraBody);
|
|
2083
3378
|
}
|
|
2084
3379
|
async doGenerate(options) {
|
|
2085
|
-
var
|
|
3380
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
2086
3381
|
const providerOptions = options.providerOptions || {};
|
|
2087
3382
|
const llmgatewayOptions = providerOptions.llmgateway || {};
|
|
2088
3383
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
|
|
@@ -2111,12 +3406,12 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
2111
3406
|
content: [
|
|
2112
3407
|
{
|
|
2113
3408
|
type: "text",
|
|
2114
|
-
text: (
|
|
3409
|
+
text: (_a16 = choice.text) != null ? _a16 : ""
|
|
2115
3410
|
}
|
|
2116
3411
|
],
|
|
2117
3412
|
finishReason: mapLLMGatewayFinishReason(choice.finish_reason),
|
|
2118
3413
|
usage: {
|
|
2119
|
-
inputTokens: (_c = (
|
|
3414
|
+
inputTokens: (_c = (_b16 = response.usage) == null ? void 0 : _b16.prompt_tokens) != null ? _c : 0,
|
|
2120
3415
|
outputTokens: (_e = (_d = response.usage) == null ? void 0 : _d.completion_tokens) != null ? _e : 0,
|
|
2121
3416
|
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),
|
|
2122
3417
|
reasoningTokens: (_l = (_k = (_j = response.usage) == null ? void 0 : _j.completion_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : 0,
|
|
@@ -2163,7 +3458,7 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
2163
3458
|
stream: response.pipeThrough(
|
|
2164
3459
|
new TransformStream({
|
|
2165
3460
|
transform(chunk, controller) {
|
|
2166
|
-
var
|
|
3461
|
+
var _a16, _b16;
|
|
2167
3462
|
if (!chunk.success) {
|
|
2168
3463
|
finishReason = "error";
|
|
2169
3464
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -2181,7 +3476,7 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
2181
3476
|
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
2182
3477
|
llmgatewayUsage.promptTokens = value.usage.prompt_tokens;
|
|
2183
3478
|
if (value.usage.prompt_tokens_details) {
|
|
2184
|
-
const cachedInputTokens = (
|
|
3479
|
+
const cachedInputTokens = (_a16 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a16 : 0;
|
|
2185
3480
|
usage.cachedInputTokens = cachedInputTokens;
|
|
2186
3481
|
llmgatewayUsage.promptTokensDetails = {
|
|
2187
3482
|
cachedTokens: cachedInputTokens
|
|
@@ -2189,7 +3484,7 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
2189
3484
|
}
|
|
2190
3485
|
llmgatewayUsage.completionTokens = value.usage.completion_tokens;
|
|
2191
3486
|
if (value.usage.completion_tokens_details) {
|
|
2192
|
-
const reasoningTokens = (
|
|
3487
|
+
const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
|
|
2193
3488
|
usage.reasoningTokens = reasoningTokens;
|
|
2194
3489
|
llmgatewayUsage.completionTokensDetails = {
|
|
2195
3490
|
reasoningTokens
|
|
@@ -2446,7 +3741,7 @@ var alibabaModels = [
|
|
|
2446
3741
|
requestPrice: 0,
|
|
2447
3742
|
contextSize: 262e3,
|
|
2448
3743
|
maxOutput: 8192,
|
|
2449
|
-
|
|
3744
|
+
reasoningText: false,
|
|
2450
3745
|
streaming: true,
|
|
2451
3746
|
vision: false,
|
|
2452
3747
|
tools: true
|
|
@@ -2469,7 +3764,7 @@ var alibabaModels = [
|
|
|
2469
3764
|
requestPrice: 0,
|
|
2470
3765
|
contextSize: 262e3,
|
|
2471
3766
|
maxOutput: 8192,
|
|
2472
|
-
|
|
3767
|
+
reasoningText: true,
|
|
2473
3768
|
streaming: true,
|
|
2474
3769
|
vision: false,
|
|
2475
3770
|
tools: true
|
|
@@ -2737,7 +4032,7 @@ var alibabaModels = [
|
|
|
2737
4032
|
streaming: true,
|
|
2738
4033
|
vision: false,
|
|
2739
4034
|
tools: true,
|
|
2740
|
-
|
|
4035
|
+
reasoningText: true
|
|
2741
4036
|
}
|
|
2742
4037
|
],
|
|
2743
4038
|
jsonOutput: true
|
|
@@ -2801,7 +4096,7 @@ var alibabaModels = [
|
|
|
2801
4096
|
requestPrice: 0,
|
|
2802
4097
|
contextSize: 131072,
|
|
2803
4098
|
maxOutput: 32768,
|
|
2804
|
-
|
|
4099
|
+
reasoningText: true,
|
|
2805
4100
|
reasoningOutput: "omit",
|
|
2806
4101
|
streaming: true,
|
|
2807
4102
|
vision: false,
|
|
@@ -2848,7 +4143,7 @@ var alibabaModels = [
|
|
|
2848
4143
|
requestPrice: 0,
|
|
2849
4144
|
contextSize: 256e3,
|
|
2850
4145
|
maxOutput: 32800,
|
|
2851
|
-
|
|
4146
|
+
reasoningText: true,
|
|
2852
4147
|
reasoningOutput: "omit",
|
|
2853
4148
|
streaming: true,
|
|
2854
4149
|
vision: true,
|
|
@@ -2901,7 +4196,7 @@ var anthropicModels = [
|
|
|
2901
4196
|
maxOutput: 8192,
|
|
2902
4197
|
streaming: true,
|
|
2903
4198
|
vision: false,
|
|
2904
|
-
|
|
4199
|
+
reasoningText: true,
|
|
2905
4200
|
tools: true
|
|
2906
4201
|
}
|
|
2907
4202
|
]
|
|
@@ -3011,7 +4306,7 @@ var anthropicModels = [
|
|
|
3011
4306
|
maxOutput: 32e3,
|
|
3012
4307
|
streaming: true,
|
|
3013
4308
|
vision: true,
|
|
3014
|
-
|
|
4309
|
+
reasoningText: true,
|
|
3015
4310
|
tools: true
|
|
3016
4311
|
}
|
|
3017
4312
|
]
|
|
@@ -3616,7 +4911,7 @@ var googleModels = [
|
|
|
3616
4911
|
contextSize: 1e6,
|
|
3617
4912
|
maxOutput: void 0,
|
|
3618
4913
|
streaming: true,
|
|
3619
|
-
|
|
4914
|
+
reasoningText: false,
|
|
3620
4915
|
vision: false,
|
|
3621
4916
|
tools: false
|
|
3622
4917
|
}
|
|
@@ -3638,7 +4933,7 @@ var googleModels = [
|
|
|
3638
4933
|
contextSize: 1e6,
|
|
3639
4934
|
maxOutput: void 0,
|
|
3640
4935
|
streaming: true,
|
|
3641
|
-
|
|
4936
|
+
reasoningText: false,
|
|
3642
4937
|
vision: false,
|
|
3643
4938
|
tools: false
|
|
3644
4939
|
}
|
|
@@ -4364,7 +5659,7 @@ var openaiModels = [
|
|
|
4364
5659
|
maxOutput: void 0,
|
|
4365
5660
|
streaming: true,
|
|
4366
5661
|
vision: true,
|
|
4367
|
-
|
|
5662
|
+
reasoningText: true,
|
|
4368
5663
|
tools: false
|
|
4369
5664
|
}
|
|
4370
5665
|
],
|
|
@@ -4388,7 +5683,7 @@ var openaiModels = [
|
|
|
4388
5683
|
streaming: false,
|
|
4389
5684
|
vision: false,
|
|
4390
5685
|
tools: false,
|
|
4391
|
-
|
|
5686
|
+
reasoningText: false,
|
|
4392
5687
|
supportsResponsesApi: false
|
|
4393
5688
|
}
|
|
4394
5689
|
],
|
|
@@ -4503,7 +5798,7 @@ var openaiModels = [
|
|
|
4503
5798
|
streaming: true,
|
|
4504
5799
|
vision: false,
|
|
4505
5800
|
tools: true,
|
|
4506
|
-
|
|
5801
|
+
reasoningText: true
|
|
4507
5802
|
}
|
|
4508
5803
|
],
|
|
4509
5804
|
jsonOutput: true
|
|
@@ -4526,7 +5821,7 @@ var openaiModels = [
|
|
|
4526
5821
|
streaming: true,
|
|
4527
5822
|
vision: false,
|
|
4528
5823
|
tools: true,
|
|
4529
|
-
|
|
5824
|
+
reasoningText: true
|
|
4530
5825
|
}
|
|
4531
5826
|
],
|
|
4532
5827
|
jsonOutput: true
|
|
@@ -4547,7 +5842,7 @@ var openaiModels = [
|
|
|
4547
5842
|
requestPrice: 0,
|
|
4548
5843
|
contextSize: 4e5,
|
|
4549
5844
|
maxOutput: 128e3,
|
|
4550
|
-
|
|
5845
|
+
reasoningText: true,
|
|
4551
5846
|
streaming: true,
|
|
4552
5847
|
vision: true,
|
|
4553
5848
|
tools: true,
|
|
@@ -4580,7 +5875,7 @@ var openaiModels = [
|
|
|
4580
5875
|
requestPrice: 0,
|
|
4581
5876
|
contextSize: 4e5,
|
|
4582
5877
|
maxOutput: 128e3,
|
|
4583
|
-
|
|
5878
|
+
reasoningText: true,
|
|
4584
5879
|
streaming: true,
|
|
4585
5880
|
vision: true,
|
|
4586
5881
|
tools: true,
|
|
@@ -4613,7 +5908,7 @@ var openaiModels = [
|
|
|
4613
5908
|
requestPrice: 0,
|
|
4614
5909
|
contextSize: 4e5,
|
|
4615
5910
|
maxOutput: 128e3,
|
|
4616
|
-
|
|
5911
|
+
reasoningText: true,
|
|
4617
5912
|
streaming: true,
|
|
4618
5913
|
vision: false,
|
|
4619
5914
|
tools: true,
|
|
@@ -5149,7 +6444,7 @@ var zaiModels = [
|
|
|
5149
6444
|
contextSize: 128e3,
|
|
5150
6445
|
maxOutput: void 0,
|
|
5151
6446
|
streaming: true,
|
|
5152
|
-
|
|
6447
|
+
reasoningText: true,
|
|
5153
6448
|
vision: false,
|
|
5154
6449
|
tools: true
|
|
5155
6450
|
}
|
|
@@ -5172,7 +6467,7 @@ var zaiModels = [
|
|
|
5172
6467
|
contextSize: 128e3,
|
|
5173
6468
|
maxOutput: void 0,
|
|
5174
6469
|
streaming: true,
|
|
5175
|
-
|
|
6470
|
+
reasoningText: true,
|
|
5176
6471
|
reasoningOutput: "omit",
|
|
5177
6472
|
vision: true,
|
|
5178
6473
|
tools: true
|
|
@@ -5196,7 +6491,7 @@ var zaiModels = [
|
|
|
5196
6491
|
contextSize: 128e3,
|
|
5197
6492
|
maxOutput: void 0,
|
|
5198
6493
|
streaming: true,
|
|
5199
|
-
|
|
6494
|
+
reasoningText: false,
|
|
5200
6495
|
vision: false,
|
|
5201
6496
|
tools: true
|
|
5202
6497
|
}
|
|
@@ -5219,7 +6514,7 @@ var zaiModels = [
|
|
|
5219
6514
|
contextSize: 128e3,
|
|
5220
6515
|
maxOutput: void 0,
|
|
5221
6516
|
streaming: true,
|
|
5222
|
-
|
|
6517
|
+
reasoningText: true,
|
|
5223
6518
|
vision: false,
|
|
5224
6519
|
tools: true
|
|
5225
6520
|
}
|
|
@@ -5242,7 +6537,7 @@ var zaiModels = [
|
|
|
5242
6537
|
contextSize: 128e3,
|
|
5243
6538
|
maxOutput: void 0,
|
|
5244
6539
|
streaming: true,
|
|
5245
|
-
|
|
6540
|
+
reasoningText: false,
|
|
5246
6541
|
vision: false,
|
|
5247
6542
|
tools: true
|
|
5248
6543
|
}
|
|
@@ -5265,7 +6560,7 @@ var zaiModels = [
|
|
|
5265
6560
|
contextSize: 128e3,
|
|
5266
6561
|
maxOutput: void 0,
|
|
5267
6562
|
streaming: true,
|
|
5268
|
-
|
|
6563
|
+
reasoningText: false,
|
|
5269
6564
|
vision: false,
|
|
5270
6565
|
tools: true
|
|
5271
6566
|
}
|
|
@@ -5288,7 +6583,7 @@ var zaiModels = [
|
|
|
5288
6583
|
contextSize: 128e3,
|
|
5289
6584
|
maxOutput: void 0,
|
|
5290
6585
|
streaming: true,
|
|
5291
|
-
|
|
6586
|
+
reasoningText: false,
|
|
5292
6587
|
vision: false,
|
|
5293
6588
|
tools: true
|
|
5294
6589
|
}
|