@openrouter/ai-sdk-provider 1.5.4 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -24
- package/dist/index.d.mts +27 -25
- package/dist/index.d.ts +27 -25
- package/dist/index.js +1516 -195
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1516 -193
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +20 -20
- package/dist/internal/index.d.ts +20 -20
- package/dist/internal/index.js +1510 -180
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +1510 -178
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +9 -8
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") {
|
|
@@ -52,11 +64,12 @@ __export(index_exports, {
|
|
|
52
64
|
});
|
|
53
65
|
module.exports = __toCommonJS(index_exports);
|
|
54
66
|
|
|
55
|
-
// node_modules/.pnpm/@ai-sdk+provider@
|
|
67
|
+
// node_modules/.pnpm/@ai-sdk+provider@3.0.0/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
56
68
|
var marker = "vercel.ai.error";
|
|
57
69
|
var symbol = Symbol.for(marker);
|
|
58
70
|
var _a;
|
|
59
|
-
var
|
|
71
|
+
var _b;
|
|
72
|
+
var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
|
|
60
73
|
/**
|
|
61
74
|
* Creates an AI SDK Error.
|
|
62
75
|
*
|
|
@@ -66,13 +79,13 @@ var _AISDKError = class _AISDKError2 extends Error {
|
|
|
66
79
|
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
67
80
|
*/
|
|
68
81
|
constructor({
|
|
69
|
-
name:
|
|
82
|
+
name: name142,
|
|
70
83
|
message,
|
|
71
84
|
cause
|
|
72
85
|
}) {
|
|
73
86
|
super(message);
|
|
74
87
|
this[_a] = true;
|
|
75
|
-
this.name =
|
|
88
|
+
this.name = name142;
|
|
76
89
|
this.cause = cause;
|
|
77
90
|
}
|
|
78
91
|
/**
|
|
@@ -81,20 +94,19 @@ var _AISDKError = class _AISDKError2 extends Error {
|
|
|
81
94
|
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
82
95
|
*/
|
|
83
96
|
static isInstance(error) {
|
|
84
|
-
return
|
|
97
|
+
return _AISDKError.hasMarker(error, marker);
|
|
85
98
|
}
|
|
86
|
-
static hasMarker(error,
|
|
87
|
-
const markerSymbol = Symbol.for(
|
|
99
|
+
static hasMarker(error, marker152) {
|
|
100
|
+
const markerSymbol = Symbol.for(marker152);
|
|
88
101
|
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
89
102
|
}
|
|
90
103
|
};
|
|
91
|
-
_a = symbol;
|
|
92
|
-
var AISDKError = _AISDKError;
|
|
93
104
|
var name = "AI_APICallError";
|
|
94
105
|
var marker2 = `vercel.ai.error.${name}`;
|
|
95
106
|
var symbol2 = Symbol.for(marker2);
|
|
96
107
|
var _a2;
|
|
97
|
-
var
|
|
108
|
+
var _b2;
|
|
109
|
+
var APICallError = class extends (_b2 = AISDKError, _a2 = symbol2, _b2) {
|
|
98
110
|
constructor({
|
|
99
111
|
message,
|
|
100
112
|
url,
|
|
@@ -124,12 +136,12 @@ var APICallError = class extends AISDKError {
|
|
|
124
136
|
return AISDKError.hasMarker(error, marker2);
|
|
125
137
|
}
|
|
126
138
|
};
|
|
127
|
-
_a2 = symbol2;
|
|
128
139
|
var name2 = "AI_EmptyResponseBodyError";
|
|
129
140
|
var marker3 = `vercel.ai.error.${name2}`;
|
|
130
141
|
var symbol3 = Symbol.for(marker3);
|
|
131
142
|
var _a3;
|
|
132
|
-
var
|
|
143
|
+
var _b3;
|
|
144
|
+
var EmptyResponseBodyError = class extends (_b3 = AISDKError, _a3 = symbol3, _b3) {
|
|
133
145
|
// used in isInstance
|
|
134
146
|
constructor({ message = "Empty response body" } = {}) {
|
|
135
147
|
super({ name: name2, message });
|
|
@@ -139,7 +151,6 @@ var EmptyResponseBodyError = class extends AISDKError {
|
|
|
139
151
|
return AISDKError.hasMarker(error, marker3);
|
|
140
152
|
}
|
|
141
153
|
};
|
|
142
|
-
_a3 = symbol3;
|
|
143
154
|
function getErrorMessage(error) {
|
|
144
155
|
if (error == null) {
|
|
145
156
|
return "unknown error";
|
|
@@ -156,7 +167,8 @@ var name3 = "AI_InvalidArgumentError";
|
|
|
156
167
|
var marker4 = `vercel.ai.error.${name3}`;
|
|
157
168
|
var symbol4 = Symbol.for(marker4);
|
|
158
169
|
var _a4;
|
|
159
|
-
var
|
|
170
|
+
var _b4;
|
|
171
|
+
var InvalidArgumentError = class extends (_b4 = AISDKError, _a4 = symbol4, _b4) {
|
|
160
172
|
constructor({
|
|
161
173
|
message,
|
|
162
174
|
cause,
|
|
@@ -170,12 +182,12 @@ var InvalidArgumentError = class extends AISDKError {
|
|
|
170
182
|
return AISDKError.hasMarker(error, marker4);
|
|
171
183
|
}
|
|
172
184
|
};
|
|
173
|
-
_a4 = symbol4;
|
|
174
185
|
var name4 = "AI_InvalidPromptError";
|
|
175
186
|
var marker5 = `vercel.ai.error.${name4}`;
|
|
176
187
|
var symbol5 = Symbol.for(marker5);
|
|
177
188
|
var _a5;
|
|
178
|
-
var
|
|
189
|
+
var _b5;
|
|
190
|
+
var InvalidPromptError = class extends (_b5 = AISDKError, _a5 = symbol5, _b5) {
|
|
179
191
|
constructor({
|
|
180
192
|
prompt,
|
|
181
193
|
message,
|
|
@@ -189,12 +201,12 @@ var InvalidPromptError = class extends AISDKError {
|
|
|
189
201
|
return AISDKError.hasMarker(error, marker5);
|
|
190
202
|
}
|
|
191
203
|
};
|
|
192
|
-
_a5 = symbol5;
|
|
193
204
|
var name5 = "AI_InvalidResponseDataError";
|
|
194
205
|
var marker6 = `vercel.ai.error.${name5}`;
|
|
195
206
|
var symbol6 = Symbol.for(marker6);
|
|
196
207
|
var _a6;
|
|
197
|
-
var
|
|
208
|
+
var _b6;
|
|
209
|
+
var InvalidResponseDataError = class extends (_b6 = AISDKError, _a6 = symbol6, _b6) {
|
|
198
210
|
constructor({
|
|
199
211
|
data,
|
|
200
212
|
message = `Invalid response data: ${JSON.stringify(data)}.`
|
|
@@ -207,12 +219,12 @@ var InvalidResponseDataError = class extends AISDKError {
|
|
|
207
219
|
return AISDKError.hasMarker(error, marker6);
|
|
208
220
|
}
|
|
209
221
|
};
|
|
210
|
-
_a6 = symbol6;
|
|
211
222
|
var name6 = "AI_JSONParseError";
|
|
212
223
|
var marker7 = `vercel.ai.error.${name6}`;
|
|
213
224
|
var symbol7 = Symbol.for(marker7);
|
|
214
225
|
var _a7;
|
|
215
|
-
var
|
|
226
|
+
var _b7;
|
|
227
|
+
var JSONParseError = class extends (_b7 = AISDKError, _a7 = symbol7, _b7) {
|
|
216
228
|
constructor({ text, cause }) {
|
|
217
229
|
super({
|
|
218
230
|
name: name6,
|
|
@@ -227,22 +239,42 @@ Error message: ${getErrorMessage(cause)}`,
|
|
|
227
239
|
return AISDKError.hasMarker(error, marker7);
|
|
228
240
|
}
|
|
229
241
|
};
|
|
230
|
-
_a7 = symbol7;
|
|
231
242
|
var name7 = "AI_LoadAPIKeyError";
|
|
232
243
|
var marker8 = `vercel.ai.error.${name7}`;
|
|
233
244
|
var symbol8 = Symbol.for(marker8);
|
|
234
245
|
var _a8;
|
|
235
|
-
|
|
246
|
+
var _b8;
|
|
247
|
+
var LoadAPIKeyError = class extends (_b8 = AISDKError, _a8 = symbol8, _b8) {
|
|
248
|
+
// used in isInstance
|
|
249
|
+
constructor({ message }) {
|
|
250
|
+
super({ name: name7, message });
|
|
251
|
+
this[_a8] = true;
|
|
252
|
+
}
|
|
253
|
+
static isInstance(error) {
|
|
254
|
+
return AISDKError.hasMarker(error, marker8);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
236
257
|
var name8 = "AI_LoadSettingError";
|
|
237
258
|
var marker9 = `vercel.ai.error.${name8}`;
|
|
238
259
|
var symbol9 = Symbol.for(marker9);
|
|
239
260
|
var _a9;
|
|
240
|
-
|
|
261
|
+
var _b9;
|
|
262
|
+
var LoadSettingError = class extends (_b9 = AISDKError, _a9 = symbol9, _b9) {
|
|
263
|
+
// used in isInstance
|
|
264
|
+
constructor({ message }) {
|
|
265
|
+
super({ name: name8, message });
|
|
266
|
+
this[_a9] = true;
|
|
267
|
+
}
|
|
268
|
+
static isInstance(error) {
|
|
269
|
+
return AISDKError.hasMarker(error, marker9);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
241
272
|
var name9 = "AI_NoContentGeneratedError";
|
|
242
273
|
var marker10 = `vercel.ai.error.${name9}`;
|
|
243
274
|
var symbol10 = Symbol.for(marker10);
|
|
244
275
|
var _a10;
|
|
245
|
-
var
|
|
276
|
+
var _b10;
|
|
277
|
+
var NoContentGeneratedError = class extends (_b10 = AISDKError, _a10 = symbol10, _b10) {
|
|
246
278
|
// used in isInstance
|
|
247
279
|
constructor({
|
|
248
280
|
message = "No content generated."
|
|
@@ -254,22 +286,54 @@ var NoContentGeneratedError = class extends AISDKError {
|
|
|
254
286
|
return AISDKError.hasMarker(error, marker10);
|
|
255
287
|
}
|
|
256
288
|
};
|
|
257
|
-
_a10 = symbol10;
|
|
258
289
|
var name10 = "AI_NoSuchModelError";
|
|
259
290
|
var marker11 = `vercel.ai.error.${name10}`;
|
|
260
291
|
var symbol11 = Symbol.for(marker11);
|
|
261
292
|
var _a11;
|
|
262
|
-
|
|
293
|
+
var _b11;
|
|
294
|
+
var NoSuchModelError = class extends (_b11 = AISDKError, _a11 = symbol11, _b11) {
|
|
295
|
+
constructor({
|
|
296
|
+
errorName = name10,
|
|
297
|
+
modelId,
|
|
298
|
+
modelType,
|
|
299
|
+
message = `No such ${modelType}: ${modelId}`
|
|
300
|
+
}) {
|
|
301
|
+
super({ name: errorName, message });
|
|
302
|
+
this[_a11] = true;
|
|
303
|
+
this.modelId = modelId;
|
|
304
|
+
this.modelType = modelType;
|
|
305
|
+
}
|
|
306
|
+
static isInstance(error) {
|
|
307
|
+
return AISDKError.hasMarker(error, marker11);
|
|
308
|
+
}
|
|
309
|
+
};
|
|
263
310
|
var name11 = "AI_TooManyEmbeddingValuesForCallError";
|
|
264
311
|
var marker12 = `vercel.ai.error.${name11}`;
|
|
265
312
|
var symbol12 = Symbol.for(marker12);
|
|
266
313
|
var _a12;
|
|
267
|
-
|
|
314
|
+
var _b12;
|
|
315
|
+
var TooManyEmbeddingValuesForCallError = class extends (_b12 = AISDKError, _a12 = symbol12, _b12) {
|
|
316
|
+
constructor(options) {
|
|
317
|
+
super({
|
|
318
|
+
name: name11,
|
|
319
|
+
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.`
|
|
320
|
+
});
|
|
321
|
+
this[_a12] = true;
|
|
322
|
+
this.provider = options.provider;
|
|
323
|
+
this.modelId = options.modelId;
|
|
324
|
+
this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
|
|
325
|
+
this.values = options.values;
|
|
326
|
+
}
|
|
327
|
+
static isInstance(error) {
|
|
328
|
+
return AISDKError.hasMarker(error, marker12);
|
|
329
|
+
}
|
|
330
|
+
};
|
|
268
331
|
var name12 = "AI_TypeValidationError";
|
|
269
332
|
var marker13 = `vercel.ai.error.${name12}`;
|
|
270
333
|
var symbol13 = Symbol.for(marker13);
|
|
271
334
|
var _a13;
|
|
272
|
-
var
|
|
335
|
+
var _b13;
|
|
336
|
+
var TypeValidationError = class _TypeValidationError extends (_b13 = AISDKError, _a13 = symbol13, _b13) {
|
|
273
337
|
constructor({ value, cause }) {
|
|
274
338
|
super({
|
|
275
339
|
name: name12,
|
|
@@ -297,16 +361,15 @@ Error message: ${getErrorMessage(cause)}`,
|
|
|
297
361
|
value,
|
|
298
362
|
cause
|
|
299
363
|
}) {
|
|
300
|
-
return
|
|
364
|
+
return _TypeValidationError.isInstance(cause) && cause.value === value ? cause : new _TypeValidationError({ value, cause });
|
|
301
365
|
}
|
|
302
366
|
};
|
|
303
|
-
_a13 = symbol13;
|
|
304
|
-
var TypeValidationError = _TypeValidationError;
|
|
305
367
|
var name13 = "AI_UnsupportedFunctionalityError";
|
|
306
368
|
var marker14 = `vercel.ai.error.${name13}`;
|
|
307
369
|
var symbol14 = Symbol.for(marker14);
|
|
308
370
|
var _a14;
|
|
309
|
-
var
|
|
371
|
+
var _b14;
|
|
372
|
+
var UnsupportedFunctionalityError = class extends (_b14 = AISDKError, _a14 = symbol14, _b14) {
|
|
310
373
|
constructor({
|
|
311
374
|
functionality,
|
|
312
375
|
message = `'${functionality}' functionality not supported.`
|
|
@@ -319,9 +382,14 @@ var UnsupportedFunctionalityError = class extends AISDKError {
|
|
|
319
382
|
return AISDKError.hasMarker(error, marker14);
|
|
320
383
|
}
|
|
321
384
|
};
|
|
322
|
-
_a14 = symbol14;
|
|
323
385
|
|
|
324
|
-
// node_modules/.pnpm
|
|
386
|
+
// node_modules/.pnpm/@ai-sdk+provider-utils@4.0.1_zod@4.3.5/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
387
|
+
var z4 = __toESM(require("zod/v4"), 1);
|
|
388
|
+
var import_v3 = require("zod/v3");
|
|
389
|
+
var import_v32 = require("zod/v3");
|
|
390
|
+
var import_v33 = require("zod/v3");
|
|
391
|
+
|
|
392
|
+
// node_modules/.pnpm/eventsource-parser@3.0.6/node_modules/eventsource-parser/dist/index.js
|
|
325
393
|
var ParseError = class extends Error {
|
|
326
394
|
constructor(message, options) {
|
|
327
395
|
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
@@ -412,7 +480,7 @@ function splitLines(chunk) {
|
|
|
412
480
|
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
413
481
|
`, searchIndex);
|
|
414
482
|
let lineEnd = -1;
|
|
415
|
-
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
|
|
483
|
+
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) {
|
|
416
484
|
incompleteLine = chunk.slice(searchIndex);
|
|
417
485
|
break;
|
|
418
486
|
} else {
|
|
@@ -424,7 +492,7 @@ function splitLines(chunk) {
|
|
|
424
492
|
return [lines, incompleteLine];
|
|
425
493
|
}
|
|
426
494
|
|
|
427
|
-
// node_modules/.pnpm/eventsource-parser@3.0.
|
|
495
|
+
// node_modules/.pnpm/eventsource-parser@3.0.6/node_modules/eventsource-parser/dist/stream.js
|
|
428
496
|
var EventSourceParserStream = class extends TransformStream {
|
|
429
497
|
constructor({ onError, onRetry, onComment } = {}) {
|
|
430
498
|
let parser;
|
|
@@ -448,25 +516,7 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
448
516
|
}
|
|
449
517
|
};
|
|
450
518
|
|
|
451
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@
|
|
452
|
-
var z4 = __toESM(require("zod/v4"), 1);
|
|
453
|
-
|
|
454
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
455
|
-
var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
456
|
-
|
|
457
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
458
|
-
var import_zod3 = require("zod");
|
|
459
|
-
|
|
460
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/array.js
|
|
461
|
-
var import_zod = require("zod");
|
|
462
|
-
|
|
463
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
464
|
-
var import_zod2 = require("zod");
|
|
465
|
-
|
|
466
|
-
// node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
|
|
467
|
-
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
468
|
-
|
|
469
|
-
// node_modules/.pnpm/@ai-sdk+provider-utils@3.0.1_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
519
|
+
// node_modules/.pnpm/@ai-sdk+provider-utils@4.0.1_zod@4.3.5/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
470
520
|
function combineHeaders(...headers) {
|
|
471
521
|
return headers.reduce(
|
|
472
522
|
(combinedHeaders, currentHeaders) => __spreadValues(__spreadValues({}, combinedHeaders), currentHeaders != null ? currentHeaders : {}),
|
|
@@ -476,6 +526,37 @@ function combineHeaders(...headers) {
|
|
|
476
526
|
function extractResponseHeaders(response) {
|
|
477
527
|
return Object.fromEntries([...response.headers]);
|
|
478
528
|
}
|
|
529
|
+
var { btoa, atob } = globalThis;
|
|
530
|
+
function convertUint8ArrayToBase64(array) {
|
|
531
|
+
let latin1string = "";
|
|
532
|
+
for (let i = 0; i < array.length; i++) {
|
|
533
|
+
latin1string += String.fromCodePoint(array[i]);
|
|
534
|
+
}
|
|
535
|
+
return btoa(latin1string);
|
|
536
|
+
}
|
|
537
|
+
var name14 = "AI_DownloadError";
|
|
538
|
+
var marker15 = `vercel.ai.error.${name14}`;
|
|
539
|
+
var symbol15 = Symbol.for(marker15);
|
|
540
|
+
var _a15;
|
|
541
|
+
var _b15;
|
|
542
|
+
var DownloadError = class extends (_b15 = AISDKError, _a15 = symbol15, _b15) {
|
|
543
|
+
constructor({
|
|
544
|
+
url,
|
|
545
|
+
statusCode,
|
|
546
|
+
statusText,
|
|
547
|
+
cause,
|
|
548
|
+
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
|
549
|
+
}) {
|
|
550
|
+
super({ name: name14, message, cause });
|
|
551
|
+
this[_a15] = true;
|
|
552
|
+
this.url = url;
|
|
553
|
+
this.statusCode = statusCode;
|
|
554
|
+
this.statusText = statusText;
|
|
555
|
+
}
|
|
556
|
+
static isInstance(error) {
|
|
557
|
+
return AISDKError.hasMarker(error, marker15);
|
|
558
|
+
}
|
|
559
|
+
};
|
|
479
560
|
var createIdGenerator = ({
|
|
480
561
|
prefix,
|
|
481
562
|
size = 16,
|
|
@@ -530,11 +611,53 @@ function handleFetchError({
|
|
|
530
611
|
}
|
|
531
612
|
return error;
|
|
532
613
|
}
|
|
533
|
-
function
|
|
534
|
-
|
|
535
|
-
|
|
614
|
+
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
615
|
+
var _a22, _b22, _c;
|
|
616
|
+
if (globalThisAny.window) {
|
|
617
|
+
return `runtime/browser`;
|
|
618
|
+
}
|
|
619
|
+
if ((_a22 = globalThisAny.navigator) == null ? void 0 : _a22.userAgent) {
|
|
620
|
+
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
621
|
+
}
|
|
622
|
+
if ((_c = (_b22 = globalThisAny.process) == null ? void 0 : _b22.versions) == null ? void 0 : _c.node) {
|
|
623
|
+
return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
|
624
|
+
}
|
|
625
|
+
if (globalThisAny.EdgeRuntime) {
|
|
626
|
+
return `runtime/vercel-edge`;
|
|
627
|
+
}
|
|
628
|
+
return "runtime/unknown";
|
|
629
|
+
}
|
|
630
|
+
function normalizeHeaders(headers) {
|
|
631
|
+
if (headers == null) {
|
|
632
|
+
return {};
|
|
633
|
+
}
|
|
634
|
+
const normalized = {};
|
|
635
|
+
if (headers instanceof Headers) {
|
|
636
|
+
headers.forEach((value, key) => {
|
|
637
|
+
normalized[key.toLowerCase()] = value;
|
|
638
|
+
});
|
|
639
|
+
} else {
|
|
640
|
+
if (!Array.isArray(headers)) {
|
|
641
|
+
headers = Object.entries(headers);
|
|
642
|
+
}
|
|
643
|
+
for (const [key, value] of headers) {
|
|
644
|
+
if (value != null) {
|
|
645
|
+
normalized[key.toLowerCase()] = value;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
return normalized;
|
|
650
|
+
}
|
|
651
|
+
function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
652
|
+
const normalizedHeaders = new Headers(normalizeHeaders(headers));
|
|
653
|
+
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
|
654
|
+
normalizedHeaders.set(
|
|
655
|
+
"user-agent",
|
|
656
|
+
[currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ")
|
|
536
657
|
);
|
|
658
|
+
return Object.fromEntries(normalizedHeaders.entries());
|
|
537
659
|
}
|
|
660
|
+
var VERSION = true ? "4.0.1" : "0.0.0-test";
|
|
538
661
|
var suspectProtoRx = /"__proto__"\s*:/;
|
|
539
662
|
var suspectConstructorRx = /"constructor"\s*:/;
|
|
540
663
|
function _parse(text) {
|
|
@@ -571,34 +694,1195 @@ function filter(obj) {
|
|
|
571
694
|
}
|
|
572
695
|
function secureJsonParse(text) {
|
|
573
696
|
const { stackTraceLimit } = Error;
|
|
574
|
-
|
|
697
|
+
try {
|
|
698
|
+
Error.stackTraceLimit = 0;
|
|
699
|
+
} catch (e) {
|
|
700
|
+
return _parse(text);
|
|
701
|
+
}
|
|
575
702
|
try {
|
|
576
703
|
return _parse(text);
|
|
577
704
|
} finally {
|
|
578
705
|
Error.stackTraceLimit = stackTraceLimit;
|
|
579
706
|
}
|
|
580
707
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
708
|
+
function addAdditionalPropertiesToJsonSchema(jsonSchema2) {
|
|
709
|
+
if (jsonSchema2.type === "object") {
|
|
710
|
+
jsonSchema2.additionalProperties = false;
|
|
711
|
+
const properties = jsonSchema2.properties;
|
|
712
|
+
if (properties != null) {
|
|
713
|
+
for (const property in properties) {
|
|
714
|
+
properties[property] = addAdditionalPropertiesToJsonSchema(
|
|
715
|
+
properties[property]
|
|
716
|
+
);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
if (jsonSchema2.type === "array" && jsonSchema2.items != null) {
|
|
721
|
+
if (Array.isArray(jsonSchema2.items)) {
|
|
722
|
+
jsonSchema2.items = jsonSchema2.items.map(
|
|
723
|
+
(item) => addAdditionalPropertiesToJsonSchema(item)
|
|
724
|
+
);
|
|
725
|
+
} else {
|
|
726
|
+
jsonSchema2.items = addAdditionalPropertiesToJsonSchema(
|
|
727
|
+
jsonSchema2.items
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
return jsonSchema2;
|
|
584
732
|
}
|
|
585
|
-
|
|
586
|
-
|
|
733
|
+
var ignoreOverride = Symbol(
|
|
734
|
+
"Let zodToJsonSchema decide on which parser to use"
|
|
735
|
+
);
|
|
736
|
+
var defaultOptions = {
|
|
737
|
+
name: void 0,
|
|
738
|
+
$refStrategy: "root",
|
|
739
|
+
basePath: ["#"],
|
|
740
|
+
effectStrategy: "input",
|
|
741
|
+
pipeStrategy: "all",
|
|
742
|
+
dateStrategy: "format:date-time",
|
|
743
|
+
mapStrategy: "entries",
|
|
744
|
+
removeAdditionalStrategy: "passthrough",
|
|
745
|
+
allowedAdditionalProperties: true,
|
|
746
|
+
rejectedAdditionalProperties: false,
|
|
747
|
+
definitionPath: "definitions",
|
|
748
|
+
strictUnions: false,
|
|
749
|
+
definitions: {},
|
|
750
|
+
errorMessages: false,
|
|
751
|
+
patternStrategy: "escape",
|
|
752
|
+
applyRegexFlags: false,
|
|
753
|
+
emailStrategy: "format:email",
|
|
754
|
+
base64Strategy: "contentEncoding:base64",
|
|
755
|
+
nameStrategy: "ref"
|
|
756
|
+
};
|
|
757
|
+
var getDefaultOptions = (options) => typeof options === "string" ? __spreadProps(__spreadValues({}, defaultOptions), {
|
|
758
|
+
name: options
|
|
759
|
+
}) : __spreadValues(__spreadValues({}, defaultOptions), options);
|
|
760
|
+
function parseAnyDef() {
|
|
761
|
+
return {};
|
|
587
762
|
}
|
|
588
|
-
function
|
|
589
|
-
|
|
763
|
+
function parseArrayDef(def, refs) {
|
|
764
|
+
var _a22, _b22, _c;
|
|
765
|
+
const res = {
|
|
766
|
+
type: "array"
|
|
767
|
+
};
|
|
768
|
+
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) {
|
|
769
|
+
res.items = parseDef(def.type._def, __spreadProps(__spreadValues({}, refs), {
|
|
770
|
+
currentPath: [...refs.currentPath, "items"]
|
|
771
|
+
}));
|
|
772
|
+
}
|
|
773
|
+
if (def.minLength) {
|
|
774
|
+
res.minItems = def.minLength.value;
|
|
775
|
+
}
|
|
776
|
+
if (def.maxLength) {
|
|
777
|
+
res.maxItems = def.maxLength.value;
|
|
778
|
+
}
|
|
779
|
+
if (def.exactLength) {
|
|
780
|
+
res.minItems = def.exactLength.value;
|
|
781
|
+
res.maxItems = def.exactLength.value;
|
|
782
|
+
}
|
|
783
|
+
return res;
|
|
590
784
|
}
|
|
591
|
-
function
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
785
|
+
function parseBigintDef(def) {
|
|
786
|
+
const res = {
|
|
787
|
+
type: "integer",
|
|
788
|
+
format: "int64"
|
|
789
|
+
};
|
|
790
|
+
if (!def.checks) return res;
|
|
791
|
+
for (const check of def.checks) {
|
|
792
|
+
switch (check.kind) {
|
|
793
|
+
case "min":
|
|
794
|
+
if (check.inclusive) {
|
|
795
|
+
res.minimum = check.value;
|
|
796
|
+
} else {
|
|
797
|
+
res.exclusiveMinimum = check.value;
|
|
798
|
+
}
|
|
799
|
+
break;
|
|
800
|
+
case "max":
|
|
801
|
+
if (check.inclusive) {
|
|
802
|
+
res.maximum = check.value;
|
|
803
|
+
} else {
|
|
804
|
+
res.exclusiveMaximum = check.value;
|
|
805
|
+
}
|
|
806
|
+
break;
|
|
807
|
+
case "multipleOf":
|
|
808
|
+
res.multipleOf = check.value;
|
|
809
|
+
break;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
return res;
|
|
813
|
+
}
|
|
814
|
+
function parseBooleanDef() {
|
|
815
|
+
return { type: "boolean" };
|
|
816
|
+
}
|
|
817
|
+
function parseBrandedDef(_def, refs) {
|
|
818
|
+
return parseDef(_def.type._def, refs);
|
|
819
|
+
}
|
|
820
|
+
var parseCatchDef = (def, refs) => {
|
|
821
|
+
return parseDef(def.innerType._def, refs);
|
|
822
|
+
};
|
|
823
|
+
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
824
|
+
const strategy = overrideDateStrategy != null ? overrideDateStrategy : refs.dateStrategy;
|
|
825
|
+
if (Array.isArray(strategy)) {
|
|
826
|
+
return {
|
|
827
|
+
anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
switch (strategy) {
|
|
831
|
+
case "string":
|
|
832
|
+
case "format:date-time":
|
|
833
|
+
return {
|
|
834
|
+
type: "string",
|
|
835
|
+
format: "date-time"
|
|
836
|
+
};
|
|
837
|
+
case "format:date":
|
|
838
|
+
return {
|
|
839
|
+
type: "string",
|
|
840
|
+
format: "date"
|
|
841
|
+
};
|
|
842
|
+
case "integer":
|
|
843
|
+
return integerDateParser(def);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
var integerDateParser = (def) => {
|
|
847
|
+
const res = {
|
|
848
|
+
type: "integer",
|
|
849
|
+
format: "unix-time"
|
|
850
|
+
};
|
|
851
|
+
for (const check of def.checks) {
|
|
852
|
+
switch (check.kind) {
|
|
853
|
+
case "min":
|
|
854
|
+
res.minimum = check.value;
|
|
855
|
+
break;
|
|
856
|
+
case "max":
|
|
857
|
+
res.maximum = check.value;
|
|
858
|
+
break;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
return res;
|
|
862
|
+
};
|
|
863
|
+
function parseDefaultDef(_def, refs) {
|
|
864
|
+
return __spreadProps(__spreadValues({}, parseDef(_def.innerType._def, refs)), {
|
|
865
|
+
default: _def.defaultValue()
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
function parseEffectsDef(_def, refs) {
|
|
869
|
+
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : parseAnyDef();
|
|
870
|
+
}
|
|
871
|
+
function parseEnumDef(def) {
|
|
872
|
+
return {
|
|
873
|
+
type: "string",
|
|
874
|
+
enum: Array.from(def.values)
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
var isJsonSchema7AllOfType = (type) => {
|
|
878
|
+
if ("type" in type && type.type === "string") return false;
|
|
879
|
+
return "allOf" in type;
|
|
880
|
+
};
|
|
881
|
+
function parseIntersectionDef(def, refs) {
|
|
882
|
+
const allOf = [
|
|
883
|
+
parseDef(def.left._def, __spreadProps(__spreadValues({}, refs), {
|
|
884
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
885
|
+
})),
|
|
886
|
+
parseDef(def.right._def, __spreadProps(__spreadValues({}, refs), {
|
|
887
|
+
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
888
|
+
}))
|
|
889
|
+
].filter((x) => !!x);
|
|
890
|
+
const mergedAllOf = [];
|
|
891
|
+
allOf.forEach((schema) => {
|
|
892
|
+
if (isJsonSchema7AllOfType(schema)) {
|
|
893
|
+
mergedAllOf.push(...schema.allOf);
|
|
894
|
+
} else {
|
|
895
|
+
let nestedSchema = schema;
|
|
896
|
+
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
897
|
+
const _a16 = schema, { additionalProperties } = _a16, rest = __objRest(_a16, ["additionalProperties"]);
|
|
898
|
+
nestedSchema = rest;
|
|
899
|
+
}
|
|
900
|
+
mergedAllOf.push(nestedSchema);
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
return mergedAllOf.length ? { allOf: mergedAllOf } : void 0;
|
|
904
|
+
}
|
|
905
|
+
function parseLiteralDef(def) {
|
|
906
|
+
const parsedType = typeof def.value;
|
|
907
|
+
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
908
|
+
return {
|
|
909
|
+
type: Array.isArray(def.value) ? "array" : "object"
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
return {
|
|
913
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
914
|
+
const: def.value
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
var emojiRegex = void 0;
|
|
918
|
+
var zodPatterns = {
|
|
919
|
+
/**
|
|
920
|
+
* `c` was changed to `[cC]` to replicate /i flag
|
|
921
|
+
*/
|
|
922
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
923
|
+
cuid2: /^[0-9a-z]+$/,
|
|
924
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
925
|
+
/**
|
|
926
|
+
* `a-z` was added to replicate /i flag
|
|
927
|
+
*/
|
|
928
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
929
|
+
/**
|
|
930
|
+
* Constructed a valid Unicode RegExp
|
|
931
|
+
*
|
|
932
|
+
* Lazily instantiate since this type of regex isn't supported
|
|
933
|
+
* in all envs (e.g. React Native).
|
|
934
|
+
*
|
|
935
|
+
* See:
|
|
936
|
+
* https://github.com/colinhacks/zod/issues/2433
|
|
937
|
+
* Fix in Zod:
|
|
938
|
+
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
939
|
+
*/
|
|
940
|
+
emoji: () => {
|
|
941
|
+
if (emojiRegex === void 0) {
|
|
942
|
+
emojiRegex = RegExp(
|
|
943
|
+
"^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",
|
|
944
|
+
"u"
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
return emojiRegex;
|
|
948
|
+
},
|
|
949
|
+
/**
|
|
950
|
+
* Unused
|
|
951
|
+
*/
|
|
952
|
+
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}$/,
|
|
953
|
+
/**
|
|
954
|
+
* Unused
|
|
955
|
+
*/
|
|
956
|
+
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])$/,
|
|
957
|
+
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])$/,
|
|
958
|
+
/**
|
|
959
|
+
* Unused
|
|
960
|
+
*/
|
|
961
|
+
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})))$/,
|
|
962
|
+
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])$/,
|
|
963
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
964
|
+
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
965
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
966
|
+
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
967
|
+
};
|
|
968
|
+
function parseStringDef(def, refs) {
|
|
969
|
+
const res = {
|
|
970
|
+
type: "string"
|
|
971
|
+
};
|
|
972
|
+
if (def.checks) {
|
|
973
|
+
for (const check of def.checks) {
|
|
974
|
+
switch (check.kind) {
|
|
975
|
+
case "min":
|
|
976
|
+
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
|
|
977
|
+
break;
|
|
978
|
+
case "max":
|
|
979
|
+
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
|
|
980
|
+
break;
|
|
981
|
+
case "email":
|
|
982
|
+
switch (refs.emailStrategy) {
|
|
983
|
+
case "format:email":
|
|
984
|
+
addFormat(res, "email", check.message, refs);
|
|
985
|
+
break;
|
|
986
|
+
case "format:idn-email":
|
|
987
|
+
addFormat(res, "idn-email", check.message, refs);
|
|
988
|
+
break;
|
|
989
|
+
case "pattern:zod":
|
|
990
|
+
addPattern(res, zodPatterns.email, check.message, refs);
|
|
991
|
+
break;
|
|
992
|
+
}
|
|
993
|
+
break;
|
|
994
|
+
case "url":
|
|
995
|
+
addFormat(res, "uri", check.message, refs);
|
|
996
|
+
break;
|
|
997
|
+
case "uuid":
|
|
998
|
+
addFormat(res, "uuid", check.message, refs);
|
|
999
|
+
break;
|
|
1000
|
+
case "regex":
|
|
1001
|
+
addPattern(res, check.regex, check.message, refs);
|
|
1002
|
+
break;
|
|
1003
|
+
case "cuid":
|
|
1004
|
+
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
1005
|
+
break;
|
|
1006
|
+
case "cuid2":
|
|
1007
|
+
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
1008
|
+
break;
|
|
1009
|
+
case "startsWith":
|
|
1010
|
+
addPattern(
|
|
1011
|
+
res,
|
|
1012
|
+
RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`),
|
|
1013
|
+
check.message,
|
|
1014
|
+
refs
|
|
1015
|
+
);
|
|
1016
|
+
break;
|
|
1017
|
+
case "endsWith":
|
|
1018
|
+
addPattern(
|
|
1019
|
+
res,
|
|
1020
|
+
RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`),
|
|
1021
|
+
check.message,
|
|
1022
|
+
refs
|
|
1023
|
+
);
|
|
1024
|
+
break;
|
|
1025
|
+
case "datetime":
|
|
1026
|
+
addFormat(res, "date-time", check.message, refs);
|
|
1027
|
+
break;
|
|
1028
|
+
case "date":
|
|
1029
|
+
addFormat(res, "date", check.message, refs);
|
|
1030
|
+
break;
|
|
1031
|
+
case "time":
|
|
1032
|
+
addFormat(res, "time", check.message, refs);
|
|
1033
|
+
break;
|
|
1034
|
+
case "duration":
|
|
1035
|
+
addFormat(res, "duration", check.message, refs);
|
|
1036
|
+
break;
|
|
1037
|
+
case "length":
|
|
1038
|
+
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
|
|
1039
|
+
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
|
|
1040
|
+
break;
|
|
1041
|
+
case "includes": {
|
|
1042
|
+
addPattern(
|
|
1043
|
+
res,
|
|
1044
|
+
RegExp(escapeLiteralCheckValue(check.value, refs)),
|
|
1045
|
+
check.message,
|
|
1046
|
+
refs
|
|
1047
|
+
);
|
|
1048
|
+
break;
|
|
1049
|
+
}
|
|
1050
|
+
case "ip": {
|
|
1051
|
+
if (check.version !== "v6") {
|
|
1052
|
+
addFormat(res, "ipv4", check.message, refs);
|
|
1053
|
+
}
|
|
1054
|
+
if (check.version !== "v4") {
|
|
1055
|
+
addFormat(res, "ipv6", check.message, refs);
|
|
1056
|
+
}
|
|
1057
|
+
break;
|
|
1058
|
+
}
|
|
1059
|
+
case "base64url":
|
|
1060
|
+
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
1061
|
+
break;
|
|
1062
|
+
case "jwt":
|
|
1063
|
+
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
1064
|
+
break;
|
|
1065
|
+
case "cidr": {
|
|
1066
|
+
if (check.version !== "v6") {
|
|
1067
|
+
addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
1068
|
+
}
|
|
1069
|
+
if (check.version !== "v4") {
|
|
1070
|
+
addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
1071
|
+
}
|
|
1072
|
+
break;
|
|
1073
|
+
}
|
|
1074
|
+
case "emoji":
|
|
1075
|
+
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
1076
|
+
break;
|
|
1077
|
+
case "ulid": {
|
|
1078
|
+
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
case "base64": {
|
|
1082
|
+
switch (refs.base64Strategy) {
|
|
1083
|
+
case "format:binary": {
|
|
1084
|
+
addFormat(res, "binary", check.message, refs);
|
|
1085
|
+
break;
|
|
1086
|
+
}
|
|
1087
|
+
case "contentEncoding:base64": {
|
|
1088
|
+
res.contentEncoding = "base64";
|
|
1089
|
+
break;
|
|
1090
|
+
}
|
|
1091
|
+
case "pattern:zod": {
|
|
1092
|
+
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
1093
|
+
break;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
break;
|
|
1097
|
+
}
|
|
1098
|
+
case "nanoid": {
|
|
1099
|
+
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
1100
|
+
}
|
|
1101
|
+
case "toLowerCase":
|
|
1102
|
+
case "toUpperCase":
|
|
1103
|
+
case "trim":
|
|
1104
|
+
break;
|
|
1105
|
+
default:
|
|
1106
|
+
/* @__PURE__ */ ((_) => {
|
|
1107
|
+
})(check);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
return res;
|
|
1112
|
+
}
|
|
1113
|
+
function escapeLiteralCheckValue(literal, refs) {
|
|
1114
|
+
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
1115
|
+
}
|
|
1116
|
+
var ALPHA_NUMERIC = new Set(
|
|
1117
|
+
"ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789"
|
|
1118
|
+
);
|
|
1119
|
+
function escapeNonAlphaNumeric(source) {
|
|
1120
|
+
let result = "";
|
|
1121
|
+
for (let i = 0; i < source.length; i++) {
|
|
1122
|
+
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
1123
|
+
result += "\\";
|
|
1124
|
+
}
|
|
1125
|
+
result += source[i];
|
|
1126
|
+
}
|
|
1127
|
+
return result;
|
|
1128
|
+
}
|
|
1129
|
+
function addFormat(schema, value, message, refs) {
|
|
1130
|
+
var _a22;
|
|
1131
|
+
if (schema.format || ((_a22 = schema.anyOf) == null ? void 0 : _a22.some((x) => x.format))) {
|
|
1132
|
+
if (!schema.anyOf) {
|
|
1133
|
+
schema.anyOf = [];
|
|
1134
|
+
}
|
|
1135
|
+
if (schema.format) {
|
|
1136
|
+
schema.anyOf.push({
|
|
1137
|
+
format: schema.format
|
|
1138
|
+
});
|
|
1139
|
+
delete schema.format;
|
|
1140
|
+
}
|
|
1141
|
+
schema.anyOf.push(__spreadValues({
|
|
1142
|
+
format: value
|
|
1143
|
+
}, message && refs.errorMessages && { errorMessage: { format: message } }));
|
|
1144
|
+
} else {
|
|
1145
|
+
schema.format = value;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
function addPattern(schema, regex, message, refs) {
|
|
1149
|
+
var _a22;
|
|
1150
|
+
if (schema.pattern || ((_a22 = schema.allOf) == null ? void 0 : _a22.some((x) => x.pattern))) {
|
|
1151
|
+
if (!schema.allOf) {
|
|
1152
|
+
schema.allOf = [];
|
|
1153
|
+
}
|
|
1154
|
+
if (schema.pattern) {
|
|
1155
|
+
schema.allOf.push({
|
|
1156
|
+
pattern: schema.pattern
|
|
1157
|
+
});
|
|
1158
|
+
delete schema.pattern;
|
|
1159
|
+
}
|
|
1160
|
+
schema.allOf.push(__spreadValues({
|
|
1161
|
+
pattern: stringifyRegExpWithFlags(regex, refs)
|
|
1162
|
+
}, message && refs.errorMessages && { errorMessage: { pattern: message } }));
|
|
1163
|
+
} else {
|
|
1164
|
+
schema.pattern = stringifyRegExpWithFlags(regex, refs);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
function stringifyRegExpWithFlags(regex, refs) {
|
|
1168
|
+
var _a22;
|
|
1169
|
+
if (!refs.applyRegexFlags || !regex.flags) {
|
|
1170
|
+
return regex.source;
|
|
1171
|
+
}
|
|
1172
|
+
const flags = {
|
|
1173
|
+
i: regex.flags.includes("i"),
|
|
1174
|
+
// Case-insensitive
|
|
1175
|
+
m: regex.flags.includes("m"),
|
|
1176
|
+
// `^` and `$` matches adjacent to newline characters
|
|
1177
|
+
s: regex.flags.includes("s")
|
|
1178
|
+
// `.` matches newlines
|
|
1179
|
+
};
|
|
1180
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
1181
|
+
let pattern = "";
|
|
1182
|
+
let isEscaped = false;
|
|
1183
|
+
let inCharGroup = false;
|
|
1184
|
+
let inCharRange = false;
|
|
1185
|
+
for (let i = 0; i < source.length; i++) {
|
|
1186
|
+
if (isEscaped) {
|
|
1187
|
+
pattern += source[i];
|
|
1188
|
+
isEscaped = false;
|
|
1189
|
+
continue;
|
|
1190
|
+
}
|
|
1191
|
+
if (flags.i) {
|
|
1192
|
+
if (inCharGroup) {
|
|
1193
|
+
if (source[i].match(/[a-z]/)) {
|
|
1194
|
+
if (inCharRange) {
|
|
1195
|
+
pattern += source[i];
|
|
1196
|
+
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
1197
|
+
inCharRange = false;
|
|
1198
|
+
} else if (source[i + 1] === "-" && ((_a22 = source[i + 2]) == null ? void 0 : _a22.match(/[a-z]/))) {
|
|
1199
|
+
pattern += source[i];
|
|
1200
|
+
inCharRange = true;
|
|
1201
|
+
} else {
|
|
1202
|
+
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
1203
|
+
}
|
|
1204
|
+
continue;
|
|
1205
|
+
}
|
|
1206
|
+
} else if (source[i].match(/[a-z]/)) {
|
|
1207
|
+
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
1208
|
+
continue;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
if (flags.m) {
|
|
1212
|
+
if (source[i] === "^") {
|
|
1213
|
+
pattern += `(^|(?<=[\r
|
|
1214
|
+
]))`;
|
|
1215
|
+
continue;
|
|
1216
|
+
} else if (source[i] === "$") {
|
|
1217
|
+
pattern += `($|(?=[\r
|
|
1218
|
+
]))`;
|
|
1219
|
+
continue;
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
if (flags.s && source[i] === ".") {
|
|
1223
|
+
pattern += inCharGroup ? `${source[i]}\r
|
|
1224
|
+
` : `[${source[i]}\r
|
|
1225
|
+
]`;
|
|
1226
|
+
continue;
|
|
1227
|
+
}
|
|
1228
|
+
pattern += source[i];
|
|
1229
|
+
if (source[i] === "\\") {
|
|
1230
|
+
isEscaped = true;
|
|
1231
|
+
} else if (inCharGroup && source[i] === "]") {
|
|
1232
|
+
inCharGroup = false;
|
|
1233
|
+
} else if (!inCharGroup && source[i] === "[") {
|
|
1234
|
+
inCharGroup = true;
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
try {
|
|
1238
|
+
new RegExp(pattern);
|
|
1239
|
+
} catch (e) {
|
|
1240
|
+
console.warn(
|
|
1241
|
+
`Could not convert regex pattern at ${refs.currentPath.join(
|
|
1242
|
+
"/"
|
|
1243
|
+
)} to a flag-independent form! Falling back to the flag-ignorant source`
|
|
1244
|
+
);
|
|
1245
|
+
return regex.source;
|
|
1246
|
+
}
|
|
1247
|
+
return pattern;
|
|
1248
|
+
}
|
|
1249
|
+
function parseRecordDef(def, refs) {
|
|
1250
|
+
var _a22, _b22, _c, _d, _e, _f;
|
|
1251
|
+
const schema = {
|
|
1252
|
+
type: "object",
|
|
1253
|
+
additionalProperties: (_a22 = parseDef(def.valueType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1254
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1255
|
+
}))) != null ? _a22 : refs.allowedAdditionalProperties
|
|
1256
|
+
};
|
|
1257
|
+
if (((_b22 = def.keyType) == null ? void 0 : _b22._def.typeName) === import_v33.ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
1258
|
+
const _a16 = parseStringDef(def.keyType._def, refs), { type } = _a16, keyType = __objRest(_a16, ["type"]);
|
|
1259
|
+
return __spreadProps(__spreadValues({}, schema), {
|
|
1260
|
+
propertyNames: keyType
|
|
1261
|
+
});
|
|
1262
|
+
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) === import_v33.ZodFirstPartyTypeKind.ZodEnum) {
|
|
1263
|
+
return __spreadProps(__spreadValues({}, schema), {
|
|
1264
|
+
propertyNames: {
|
|
1265
|
+
enum: def.keyType._def.values
|
|
1266
|
+
}
|
|
1267
|
+
});
|
|
1268
|
+
} 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)) {
|
|
1269
|
+
const _b16 = parseBrandedDef(
|
|
1270
|
+
def.keyType._def,
|
|
1271
|
+
refs
|
|
1272
|
+
), { type } = _b16, keyType = __objRest(_b16, ["type"]);
|
|
1273
|
+
return __spreadProps(__spreadValues({}, schema), {
|
|
1274
|
+
propertyNames: keyType
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
return schema;
|
|
1278
|
+
}
|
|
1279
|
+
function parseMapDef(def, refs) {
|
|
1280
|
+
if (refs.mapStrategy === "record") {
|
|
1281
|
+
return parseRecordDef(def, refs);
|
|
1282
|
+
}
|
|
1283
|
+
const keys = parseDef(def.keyType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1284
|
+
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
1285
|
+
})) || parseAnyDef();
|
|
1286
|
+
const values = parseDef(def.valueType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1287
|
+
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
1288
|
+
})) || parseAnyDef();
|
|
1289
|
+
return {
|
|
1290
|
+
type: "array",
|
|
1291
|
+
maxItems: 125,
|
|
1292
|
+
items: {
|
|
1293
|
+
type: "array",
|
|
1294
|
+
items: [keys, values],
|
|
1295
|
+
minItems: 2,
|
|
1296
|
+
maxItems: 2
|
|
1297
|
+
}
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
function parseNativeEnumDef(def) {
|
|
1301
|
+
const object = def.values;
|
|
1302
|
+
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
1303
|
+
return typeof object[object[key]] !== "number";
|
|
1304
|
+
});
|
|
1305
|
+
const actualValues = actualKeys.map((key) => object[key]);
|
|
1306
|
+
const parsedTypes = Array.from(
|
|
1307
|
+
new Set(actualValues.map((values) => typeof values))
|
|
1308
|
+
);
|
|
1309
|
+
return {
|
|
1310
|
+
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
1311
|
+
enum: actualValues
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
function parseNeverDef() {
|
|
1315
|
+
return { not: parseAnyDef() };
|
|
1316
|
+
}
|
|
1317
|
+
function parseNullDef() {
|
|
1318
|
+
return {
|
|
1319
|
+
type: "null"
|
|
1320
|
+
};
|
|
1321
|
+
}
|
|
1322
|
+
var primitiveMappings = {
|
|
1323
|
+
ZodString: "string",
|
|
1324
|
+
ZodNumber: "number",
|
|
1325
|
+
ZodBigInt: "integer",
|
|
1326
|
+
ZodBoolean: "boolean",
|
|
1327
|
+
ZodNull: "null"
|
|
1328
|
+
};
|
|
1329
|
+
function parseUnionDef(def, refs) {
|
|
1330
|
+
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
1331
|
+
if (options.every(
|
|
1332
|
+
(x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length)
|
|
1333
|
+
)) {
|
|
1334
|
+
const types = options.reduce((types2, x) => {
|
|
1335
|
+
const type = primitiveMappings[x._def.typeName];
|
|
1336
|
+
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
1337
|
+
}, []);
|
|
1338
|
+
return {
|
|
1339
|
+
type: types.length > 1 ? types : types[0]
|
|
600
1340
|
};
|
|
1341
|
+
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
1342
|
+
const types = options.reduce(
|
|
1343
|
+
(acc, x) => {
|
|
1344
|
+
const type = typeof x._def.value;
|
|
1345
|
+
switch (type) {
|
|
1346
|
+
case "string":
|
|
1347
|
+
case "number":
|
|
1348
|
+
case "boolean":
|
|
1349
|
+
return [...acc, type];
|
|
1350
|
+
case "bigint":
|
|
1351
|
+
return [...acc, "integer"];
|
|
1352
|
+
case "object":
|
|
1353
|
+
if (x._def.value === null) return [...acc, "null"];
|
|
1354
|
+
case "symbol":
|
|
1355
|
+
case "undefined":
|
|
1356
|
+
case "function":
|
|
1357
|
+
default:
|
|
1358
|
+
return acc;
|
|
1359
|
+
}
|
|
1360
|
+
},
|
|
1361
|
+
[]
|
|
1362
|
+
);
|
|
1363
|
+
if (types.length === options.length) {
|
|
1364
|
+
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
1365
|
+
return {
|
|
1366
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
1367
|
+
enum: options.reduce(
|
|
1368
|
+
(acc, x) => {
|
|
1369
|
+
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
1370
|
+
},
|
|
1371
|
+
[]
|
|
1372
|
+
)
|
|
1373
|
+
};
|
|
1374
|
+
}
|
|
1375
|
+
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
1376
|
+
return {
|
|
1377
|
+
type: "string",
|
|
1378
|
+
enum: options.reduce(
|
|
1379
|
+
(acc, x) => [
|
|
1380
|
+
...acc,
|
|
1381
|
+
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
1382
|
+
],
|
|
1383
|
+
[]
|
|
1384
|
+
)
|
|
1385
|
+
};
|
|
1386
|
+
}
|
|
1387
|
+
return asAnyOf(def, refs);
|
|
1388
|
+
}
|
|
1389
|
+
var asAnyOf = (def, refs) => {
|
|
1390
|
+
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map(
|
|
1391
|
+
(x, i) => parseDef(x._def, __spreadProps(__spreadValues({}, refs), {
|
|
1392
|
+
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
1393
|
+
}))
|
|
1394
|
+
).filter(
|
|
1395
|
+
(x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0)
|
|
1396
|
+
);
|
|
1397
|
+
return anyOf.length ? { anyOf } : void 0;
|
|
1398
|
+
};
|
|
1399
|
+
function parseNullableDef(def, refs) {
|
|
1400
|
+
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(
|
|
1401
|
+
def.innerType._def.typeName
|
|
1402
|
+
) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
1403
|
+
return {
|
|
1404
|
+
type: [
|
|
1405
|
+
primitiveMappings[def.innerType._def.typeName],
|
|
1406
|
+
"null"
|
|
1407
|
+
]
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
const base = parseDef(def.innerType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1411
|
+
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
1412
|
+
}));
|
|
1413
|
+
return base && { anyOf: [base, { type: "null" }] };
|
|
1414
|
+
}
|
|
1415
|
+
function parseNumberDef(def) {
|
|
1416
|
+
const res = {
|
|
1417
|
+
type: "number"
|
|
1418
|
+
};
|
|
1419
|
+
if (!def.checks) return res;
|
|
1420
|
+
for (const check of def.checks) {
|
|
1421
|
+
switch (check.kind) {
|
|
1422
|
+
case "int":
|
|
1423
|
+
res.type = "integer";
|
|
1424
|
+
break;
|
|
1425
|
+
case "min":
|
|
1426
|
+
if (check.inclusive) {
|
|
1427
|
+
res.minimum = check.value;
|
|
1428
|
+
} else {
|
|
1429
|
+
res.exclusiveMinimum = check.value;
|
|
1430
|
+
}
|
|
1431
|
+
break;
|
|
1432
|
+
case "max":
|
|
1433
|
+
if (check.inclusive) {
|
|
1434
|
+
res.maximum = check.value;
|
|
1435
|
+
} else {
|
|
1436
|
+
res.exclusiveMaximum = check.value;
|
|
1437
|
+
}
|
|
1438
|
+
break;
|
|
1439
|
+
case "multipleOf":
|
|
1440
|
+
res.multipleOf = check.value;
|
|
1441
|
+
break;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
return res;
|
|
1445
|
+
}
|
|
1446
|
+
function parseObjectDef(def, refs) {
|
|
1447
|
+
const result = {
|
|
1448
|
+
type: "object",
|
|
1449
|
+
properties: {}
|
|
1450
|
+
};
|
|
1451
|
+
const required = [];
|
|
1452
|
+
const shape = def.shape();
|
|
1453
|
+
for (const propName in shape) {
|
|
1454
|
+
let propDef = shape[propName];
|
|
1455
|
+
if (propDef === void 0 || propDef._def === void 0) {
|
|
1456
|
+
continue;
|
|
1457
|
+
}
|
|
1458
|
+
const propOptional = safeIsOptional(propDef);
|
|
1459
|
+
const parsedDef = parseDef(propDef._def, __spreadProps(__spreadValues({}, refs), {
|
|
1460
|
+
currentPath: [...refs.currentPath, "properties", propName],
|
|
1461
|
+
propertyPath: [...refs.currentPath, "properties", propName]
|
|
1462
|
+
}));
|
|
1463
|
+
if (parsedDef === void 0) {
|
|
1464
|
+
continue;
|
|
1465
|
+
}
|
|
1466
|
+
result.properties[propName] = parsedDef;
|
|
1467
|
+
if (!propOptional) {
|
|
1468
|
+
required.push(propName);
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
if (required.length) {
|
|
1472
|
+
result.required = required;
|
|
1473
|
+
}
|
|
1474
|
+
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
1475
|
+
if (additionalProperties !== void 0) {
|
|
1476
|
+
result.additionalProperties = additionalProperties;
|
|
1477
|
+
}
|
|
1478
|
+
return result;
|
|
1479
|
+
}
|
|
1480
|
+
function decideAdditionalProperties(def, refs) {
|
|
1481
|
+
if (def.catchall._def.typeName !== "ZodNever") {
|
|
1482
|
+
return parseDef(def.catchall._def, __spreadProps(__spreadValues({}, refs), {
|
|
1483
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1484
|
+
}));
|
|
1485
|
+
}
|
|
1486
|
+
switch (def.unknownKeys) {
|
|
1487
|
+
case "passthrough":
|
|
1488
|
+
return refs.allowedAdditionalProperties;
|
|
1489
|
+
case "strict":
|
|
1490
|
+
return refs.rejectedAdditionalProperties;
|
|
1491
|
+
case "strip":
|
|
1492
|
+
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
function safeIsOptional(schema) {
|
|
1496
|
+
try {
|
|
1497
|
+
return schema.isOptional();
|
|
1498
|
+
} catch (e) {
|
|
1499
|
+
return true;
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
var parseOptionalDef = (def, refs) => {
|
|
1503
|
+
var _a22;
|
|
1504
|
+
if (refs.currentPath.toString() === ((_a22 = refs.propertyPath) == null ? void 0 : _a22.toString())) {
|
|
1505
|
+
return parseDef(def.innerType._def, refs);
|
|
1506
|
+
}
|
|
1507
|
+
const innerSchema = parseDef(def.innerType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1508
|
+
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
1509
|
+
}));
|
|
1510
|
+
return innerSchema ? { anyOf: [{ not: parseAnyDef() }, innerSchema] } : parseAnyDef();
|
|
1511
|
+
};
|
|
1512
|
+
var parsePipelineDef = (def, refs) => {
|
|
1513
|
+
if (refs.pipeStrategy === "input") {
|
|
1514
|
+
return parseDef(def.in._def, refs);
|
|
1515
|
+
} else if (refs.pipeStrategy === "output") {
|
|
1516
|
+
return parseDef(def.out._def, refs);
|
|
1517
|
+
}
|
|
1518
|
+
const a = parseDef(def.in._def, __spreadProps(__spreadValues({}, refs), {
|
|
1519
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1520
|
+
}));
|
|
1521
|
+
const b = parseDef(def.out._def, __spreadProps(__spreadValues({}, refs), {
|
|
1522
|
+
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
1523
|
+
}));
|
|
1524
|
+
return {
|
|
1525
|
+
allOf: [a, b].filter((x) => x !== void 0)
|
|
1526
|
+
};
|
|
1527
|
+
};
|
|
1528
|
+
function parsePromiseDef(def, refs) {
|
|
1529
|
+
return parseDef(def.type._def, refs);
|
|
1530
|
+
}
|
|
1531
|
+
function parseSetDef(def, refs) {
|
|
1532
|
+
const items = parseDef(def.valueType._def, __spreadProps(__spreadValues({}, refs), {
|
|
1533
|
+
currentPath: [...refs.currentPath, "items"]
|
|
1534
|
+
}));
|
|
1535
|
+
const schema = {
|
|
1536
|
+
type: "array",
|
|
1537
|
+
uniqueItems: true,
|
|
1538
|
+
items
|
|
1539
|
+
};
|
|
1540
|
+
if (def.minSize) {
|
|
1541
|
+
schema.minItems = def.minSize.value;
|
|
1542
|
+
}
|
|
1543
|
+
if (def.maxSize) {
|
|
1544
|
+
schema.maxItems = def.maxSize.value;
|
|
1545
|
+
}
|
|
1546
|
+
return schema;
|
|
1547
|
+
}
|
|
1548
|
+
function parseTupleDef(def, refs) {
|
|
1549
|
+
if (def.rest) {
|
|
1550
|
+
return {
|
|
1551
|
+
type: "array",
|
|
1552
|
+
minItems: def.items.length,
|
|
1553
|
+
items: def.items.map(
|
|
1554
|
+
(x, i) => parseDef(x._def, __spreadProps(__spreadValues({}, refs), {
|
|
1555
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1556
|
+
}))
|
|
1557
|
+
).reduce(
|
|
1558
|
+
(acc, x) => x === void 0 ? acc : [...acc, x],
|
|
1559
|
+
[]
|
|
1560
|
+
),
|
|
1561
|
+
additionalItems: parseDef(def.rest._def, __spreadProps(__spreadValues({}, refs), {
|
|
1562
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
1563
|
+
}))
|
|
1564
|
+
};
|
|
1565
|
+
} else {
|
|
1566
|
+
return {
|
|
1567
|
+
type: "array",
|
|
1568
|
+
minItems: def.items.length,
|
|
1569
|
+
maxItems: def.items.length,
|
|
1570
|
+
items: def.items.map(
|
|
1571
|
+
(x, i) => parseDef(x._def, __spreadProps(__spreadValues({}, refs), {
|
|
1572
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1573
|
+
}))
|
|
1574
|
+
).reduce(
|
|
1575
|
+
(acc, x) => x === void 0 ? acc : [...acc, x],
|
|
1576
|
+
[]
|
|
1577
|
+
)
|
|
1578
|
+
};
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
function parseUndefinedDef() {
|
|
1582
|
+
return {
|
|
1583
|
+
not: parseAnyDef()
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
function parseUnknownDef() {
|
|
1587
|
+
return parseAnyDef();
|
|
1588
|
+
}
|
|
1589
|
+
var parseReadonlyDef = (def, refs) => {
|
|
1590
|
+
return parseDef(def.innerType._def, refs);
|
|
1591
|
+
};
|
|
1592
|
+
var selectParser = (def, typeName, refs) => {
|
|
1593
|
+
switch (typeName) {
|
|
1594
|
+
case import_v3.ZodFirstPartyTypeKind.ZodString:
|
|
1595
|
+
return parseStringDef(def, refs);
|
|
1596
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNumber:
|
|
1597
|
+
return parseNumberDef(def);
|
|
1598
|
+
case import_v3.ZodFirstPartyTypeKind.ZodObject:
|
|
1599
|
+
return parseObjectDef(def, refs);
|
|
1600
|
+
case import_v3.ZodFirstPartyTypeKind.ZodBigInt:
|
|
1601
|
+
return parseBigintDef(def);
|
|
1602
|
+
case import_v3.ZodFirstPartyTypeKind.ZodBoolean:
|
|
1603
|
+
return parseBooleanDef();
|
|
1604
|
+
case import_v3.ZodFirstPartyTypeKind.ZodDate:
|
|
1605
|
+
return parseDateDef(def, refs);
|
|
1606
|
+
case import_v3.ZodFirstPartyTypeKind.ZodUndefined:
|
|
1607
|
+
return parseUndefinedDef();
|
|
1608
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNull:
|
|
1609
|
+
return parseNullDef();
|
|
1610
|
+
case import_v3.ZodFirstPartyTypeKind.ZodArray:
|
|
1611
|
+
return parseArrayDef(def, refs);
|
|
1612
|
+
case import_v3.ZodFirstPartyTypeKind.ZodUnion:
|
|
1613
|
+
case import_v3.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
|
|
1614
|
+
return parseUnionDef(def, refs);
|
|
1615
|
+
case import_v3.ZodFirstPartyTypeKind.ZodIntersection:
|
|
1616
|
+
return parseIntersectionDef(def, refs);
|
|
1617
|
+
case import_v3.ZodFirstPartyTypeKind.ZodTuple:
|
|
1618
|
+
return parseTupleDef(def, refs);
|
|
1619
|
+
case import_v3.ZodFirstPartyTypeKind.ZodRecord:
|
|
1620
|
+
return parseRecordDef(def, refs);
|
|
1621
|
+
case import_v3.ZodFirstPartyTypeKind.ZodLiteral:
|
|
1622
|
+
return parseLiteralDef(def);
|
|
1623
|
+
case import_v3.ZodFirstPartyTypeKind.ZodEnum:
|
|
1624
|
+
return parseEnumDef(def);
|
|
1625
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNativeEnum:
|
|
1626
|
+
return parseNativeEnumDef(def);
|
|
1627
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNullable:
|
|
1628
|
+
return parseNullableDef(def, refs);
|
|
1629
|
+
case import_v3.ZodFirstPartyTypeKind.ZodOptional:
|
|
1630
|
+
return parseOptionalDef(def, refs);
|
|
1631
|
+
case import_v3.ZodFirstPartyTypeKind.ZodMap:
|
|
1632
|
+
return parseMapDef(def, refs);
|
|
1633
|
+
case import_v3.ZodFirstPartyTypeKind.ZodSet:
|
|
1634
|
+
return parseSetDef(def, refs);
|
|
1635
|
+
case import_v3.ZodFirstPartyTypeKind.ZodLazy:
|
|
1636
|
+
return () => def.getter()._def;
|
|
1637
|
+
case import_v3.ZodFirstPartyTypeKind.ZodPromise:
|
|
1638
|
+
return parsePromiseDef(def, refs);
|
|
1639
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNaN:
|
|
1640
|
+
case import_v3.ZodFirstPartyTypeKind.ZodNever:
|
|
1641
|
+
return parseNeverDef();
|
|
1642
|
+
case import_v3.ZodFirstPartyTypeKind.ZodEffects:
|
|
1643
|
+
return parseEffectsDef(def, refs);
|
|
1644
|
+
case import_v3.ZodFirstPartyTypeKind.ZodAny:
|
|
1645
|
+
return parseAnyDef();
|
|
1646
|
+
case import_v3.ZodFirstPartyTypeKind.ZodUnknown:
|
|
1647
|
+
return parseUnknownDef();
|
|
1648
|
+
case import_v3.ZodFirstPartyTypeKind.ZodDefault:
|
|
1649
|
+
return parseDefaultDef(def, refs);
|
|
1650
|
+
case import_v3.ZodFirstPartyTypeKind.ZodBranded:
|
|
1651
|
+
return parseBrandedDef(def, refs);
|
|
1652
|
+
case import_v3.ZodFirstPartyTypeKind.ZodReadonly:
|
|
1653
|
+
return parseReadonlyDef(def, refs);
|
|
1654
|
+
case import_v3.ZodFirstPartyTypeKind.ZodCatch:
|
|
1655
|
+
return parseCatchDef(def, refs);
|
|
1656
|
+
case import_v3.ZodFirstPartyTypeKind.ZodPipeline:
|
|
1657
|
+
return parsePipelineDef(def, refs);
|
|
1658
|
+
case import_v3.ZodFirstPartyTypeKind.ZodFunction:
|
|
1659
|
+
case import_v3.ZodFirstPartyTypeKind.ZodVoid:
|
|
1660
|
+
case import_v3.ZodFirstPartyTypeKind.ZodSymbol:
|
|
1661
|
+
return void 0;
|
|
1662
|
+
default:
|
|
1663
|
+
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
1664
|
+
}
|
|
1665
|
+
};
|
|
1666
|
+
var getRelativePath = (pathA, pathB) => {
|
|
1667
|
+
let i = 0;
|
|
1668
|
+
for (; i < pathA.length && i < pathB.length; i++) {
|
|
1669
|
+
if (pathA[i] !== pathB[i]) break;
|
|
1670
|
+
}
|
|
1671
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
1672
|
+
};
|
|
1673
|
+
function parseDef(def, refs, forceResolution = false) {
|
|
1674
|
+
var _a22;
|
|
1675
|
+
const seenItem = refs.seen.get(def);
|
|
1676
|
+
if (refs.override) {
|
|
1677
|
+
const overrideResult = (_a22 = refs.override) == null ? void 0 : _a22.call(
|
|
1678
|
+
refs,
|
|
1679
|
+
def,
|
|
1680
|
+
refs,
|
|
1681
|
+
seenItem,
|
|
1682
|
+
forceResolution
|
|
1683
|
+
);
|
|
1684
|
+
if (overrideResult !== ignoreOverride) {
|
|
1685
|
+
return overrideResult;
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
if (seenItem && !forceResolution) {
|
|
1689
|
+
const seenSchema = get$ref(seenItem, refs);
|
|
1690
|
+
if (seenSchema !== void 0) {
|
|
1691
|
+
return seenSchema;
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
1695
|
+
refs.seen.set(def, newItem);
|
|
1696
|
+
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
1697
|
+
const jsonSchema2 = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
1698
|
+
if (jsonSchema2) {
|
|
1699
|
+
addMeta(def, refs, jsonSchema2);
|
|
1700
|
+
}
|
|
1701
|
+
if (refs.postProcess) {
|
|
1702
|
+
const postProcessResult = refs.postProcess(jsonSchema2, def, refs);
|
|
1703
|
+
newItem.jsonSchema = jsonSchema2;
|
|
1704
|
+
return postProcessResult;
|
|
1705
|
+
}
|
|
1706
|
+
newItem.jsonSchema = jsonSchema2;
|
|
1707
|
+
return jsonSchema2;
|
|
1708
|
+
}
|
|
1709
|
+
var get$ref = (item, refs) => {
|
|
1710
|
+
switch (refs.$refStrategy) {
|
|
1711
|
+
case "root":
|
|
1712
|
+
return { $ref: item.path.join("/") };
|
|
1713
|
+
case "relative":
|
|
1714
|
+
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
1715
|
+
case "none":
|
|
1716
|
+
case "seen": {
|
|
1717
|
+
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
1718
|
+
console.warn(
|
|
1719
|
+
`Recursive reference detected at ${refs.currentPath.join(
|
|
1720
|
+
"/"
|
|
1721
|
+
)}! Defaulting to any`
|
|
1722
|
+
);
|
|
1723
|
+
return parseAnyDef();
|
|
1724
|
+
}
|
|
1725
|
+
return refs.$refStrategy === "seen" ? parseAnyDef() : void 0;
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1729
|
+
var addMeta = (def, refs, jsonSchema2) => {
|
|
1730
|
+
if (def.description) {
|
|
1731
|
+
jsonSchema2.description = def.description;
|
|
1732
|
+
}
|
|
1733
|
+
return jsonSchema2;
|
|
1734
|
+
};
|
|
1735
|
+
var getRefs = (options) => {
|
|
1736
|
+
const _options = getDefaultOptions(options);
|
|
1737
|
+
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
1738
|
+
return __spreadProps(__spreadValues({}, _options), {
|
|
1739
|
+
currentPath,
|
|
1740
|
+
propertyPath: void 0,
|
|
1741
|
+
seen: new Map(
|
|
1742
|
+
Object.entries(_options.definitions).map(([name22, def]) => [
|
|
1743
|
+
def._def,
|
|
1744
|
+
{
|
|
1745
|
+
def: def._def,
|
|
1746
|
+
path: [..._options.basePath, _options.definitionPath, name22],
|
|
1747
|
+
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
1748
|
+
jsonSchema: void 0
|
|
1749
|
+
}
|
|
1750
|
+
])
|
|
1751
|
+
)
|
|
601
1752
|
});
|
|
1753
|
+
};
|
|
1754
|
+
var zod3ToJsonSchema = (schema, options) => {
|
|
1755
|
+
var _a22;
|
|
1756
|
+
const refs = getRefs(options);
|
|
1757
|
+
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
|
|
1758
|
+
(acc, [name32, schema2]) => {
|
|
1759
|
+
var _a32;
|
|
1760
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1761
|
+
[name32]: (_a32 = parseDef(
|
|
1762
|
+
schema2._def,
|
|
1763
|
+
__spreadProps(__spreadValues({}, refs), {
|
|
1764
|
+
currentPath: [...refs.basePath, refs.definitionPath, name32]
|
|
1765
|
+
}),
|
|
1766
|
+
true
|
|
1767
|
+
)) != null ? _a32 : parseAnyDef()
|
|
1768
|
+
});
|
|
1769
|
+
},
|
|
1770
|
+
{}
|
|
1771
|
+
) : void 0;
|
|
1772
|
+
const name22 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
1773
|
+
const main = (_a22 = parseDef(
|
|
1774
|
+
schema._def,
|
|
1775
|
+
name22 === void 0 ? refs : __spreadProps(__spreadValues({}, refs), {
|
|
1776
|
+
currentPath: [...refs.basePath, refs.definitionPath, name22]
|
|
1777
|
+
}),
|
|
1778
|
+
false
|
|
1779
|
+
)) != null ? _a22 : parseAnyDef();
|
|
1780
|
+
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
1781
|
+
if (title !== void 0) {
|
|
1782
|
+
main.title = title;
|
|
1783
|
+
}
|
|
1784
|
+
const combined = name22 === void 0 ? definitions ? __spreadProps(__spreadValues({}, main), {
|
|
1785
|
+
[refs.definitionPath]: definitions
|
|
1786
|
+
}) : main : {
|
|
1787
|
+
$ref: [
|
|
1788
|
+
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
1789
|
+
refs.definitionPath,
|
|
1790
|
+
name22
|
|
1791
|
+
].join("/"),
|
|
1792
|
+
[refs.definitionPath]: __spreadProps(__spreadValues({}, definitions), {
|
|
1793
|
+
[name22]: main
|
|
1794
|
+
})
|
|
1795
|
+
};
|
|
1796
|
+
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
1797
|
+
return combined;
|
|
1798
|
+
};
|
|
1799
|
+
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
|
1800
|
+
function jsonSchema(jsonSchema2, {
|
|
1801
|
+
validate
|
|
1802
|
+
} = {}) {
|
|
1803
|
+
return {
|
|
1804
|
+
[schemaSymbol]: true,
|
|
1805
|
+
_type: void 0,
|
|
1806
|
+
// should never be used directly
|
|
1807
|
+
get jsonSchema() {
|
|
1808
|
+
if (typeof jsonSchema2 === "function") {
|
|
1809
|
+
jsonSchema2 = jsonSchema2();
|
|
1810
|
+
}
|
|
1811
|
+
return jsonSchema2;
|
|
1812
|
+
},
|
|
1813
|
+
validate
|
|
1814
|
+
};
|
|
1815
|
+
}
|
|
1816
|
+
function isSchema(value) {
|
|
1817
|
+
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
|
1818
|
+
}
|
|
1819
|
+
function asSchema(schema) {
|
|
1820
|
+
return schema == null ? jsonSchema({ properties: {}, additionalProperties: false }) : isSchema(schema) ? schema : "~standard" in schema ? schema["~standard"].vendor === "zod" ? zodSchema(schema) : standardSchema(schema) : schema();
|
|
1821
|
+
}
|
|
1822
|
+
function standardSchema(standardSchema2) {
|
|
1823
|
+
return jsonSchema(
|
|
1824
|
+
() => standardSchema2["~standard"].jsonSchema.input({
|
|
1825
|
+
target: "draft-07"
|
|
1826
|
+
}),
|
|
1827
|
+
{
|
|
1828
|
+
validate: async (value) => {
|
|
1829
|
+
const result = await standardSchema2["~standard"].validate(value);
|
|
1830
|
+
return "value" in result ? { success: true, value: result.value } : {
|
|
1831
|
+
success: false,
|
|
1832
|
+
error: new TypeValidationError({
|
|
1833
|
+
value,
|
|
1834
|
+
cause: result.issues
|
|
1835
|
+
})
|
|
1836
|
+
};
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
);
|
|
1840
|
+
}
|
|
1841
|
+
function zod3Schema(zodSchema2, options) {
|
|
1842
|
+
var _a22;
|
|
1843
|
+
const useReferences = (_a22 = options == null ? void 0 : options.useReferences) != null ? _a22 : false;
|
|
1844
|
+
return jsonSchema(
|
|
1845
|
+
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
1846
|
+
() => zod3ToJsonSchema(zodSchema2, {
|
|
1847
|
+
$refStrategy: useReferences ? "root" : "none"
|
|
1848
|
+
}),
|
|
1849
|
+
{
|
|
1850
|
+
validate: async (value) => {
|
|
1851
|
+
const result = await zodSchema2.safeParseAsync(value);
|
|
1852
|
+
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
);
|
|
1856
|
+
}
|
|
1857
|
+
function zod4Schema(zodSchema2, options) {
|
|
1858
|
+
var _a22;
|
|
1859
|
+
const useReferences = (_a22 = options == null ? void 0 : options.useReferences) != null ? _a22 : false;
|
|
1860
|
+
return jsonSchema(
|
|
1861
|
+
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
1862
|
+
() => addAdditionalPropertiesToJsonSchema(
|
|
1863
|
+
z4.toJSONSchema(zodSchema2, {
|
|
1864
|
+
target: "draft-7",
|
|
1865
|
+
io: "input",
|
|
1866
|
+
reused: useReferences ? "ref" : "inline"
|
|
1867
|
+
})
|
|
1868
|
+
),
|
|
1869
|
+
{
|
|
1870
|
+
validate: async (value) => {
|
|
1871
|
+
const result = await z4.safeParseAsync(zodSchema2, value);
|
|
1872
|
+
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
);
|
|
1876
|
+
}
|
|
1877
|
+
function isZod4Schema(zodSchema2) {
|
|
1878
|
+
return "_zod" in zodSchema2;
|
|
1879
|
+
}
|
|
1880
|
+
function zodSchema(zodSchema2, options) {
|
|
1881
|
+
if (isZod4Schema(zodSchema2)) {
|
|
1882
|
+
return zod4Schema(zodSchema2, options);
|
|
1883
|
+
} else {
|
|
1884
|
+
return zod3Schema(zodSchema2, options);
|
|
1885
|
+
}
|
|
602
1886
|
}
|
|
603
1887
|
async function validateTypes({
|
|
604
1888
|
value,
|
|
@@ -614,12 +1898,12 @@ async function safeValidateTypes({
|
|
|
614
1898
|
value,
|
|
615
1899
|
schema
|
|
616
1900
|
}) {
|
|
617
|
-
const
|
|
1901
|
+
const actualSchema = asSchema(schema);
|
|
618
1902
|
try {
|
|
619
|
-
if (
|
|
1903
|
+
if (actualSchema.validate == null) {
|
|
620
1904
|
return { success: true, value, rawValue: value };
|
|
621
1905
|
}
|
|
622
|
-
const result = await
|
|
1906
|
+
const result = await actualSchema.validate(value);
|
|
623
1907
|
if (result.success) {
|
|
624
1908
|
return { success: true, value: result.value, rawValue: value };
|
|
625
1909
|
}
|
|
@@ -702,7 +1986,7 @@ var postJsonToApi = async ({
|
|
|
702
1986
|
failedResponseHandler,
|
|
703
1987
|
successfulResponseHandler,
|
|
704
1988
|
abortSignal,
|
|
705
|
-
fetch
|
|
1989
|
+
fetch: fetch2
|
|
706
1990
|
}) => postToApi({
|
|
707
1991
|
url,
|
|
708
1992
|
headers: __spreadValues({
|
|
@@ -715,7 +1999,7 @@ var postJsonToApi = async ({
|
|
|
715
1999
|
failedResponseHandler,
|
|
716
2000
|
successfulResponseHandler,
|
|
717
2001
|
abortSignal,
|
|
718
|
-
fetch
|
|
2002
|
+
fetch: fetch2
|
|
719
2003
|
});
|
|
720
2004
|
var postToApi = async ({
|
|
721
2005
|
url,
|
|
@@ -724,12 +2008,16 @@ var postToApi = async ({
|
|
|
724
2008
|
successfulResponseHandler,
|
|
725
2009
|
failedResponseHandler,
|
|
726
2010
|
abortSignal,
|
|
727
|
-
fetch = getOriginalFetch2()
|
|
2011
|
+
fetch: fetch2 = getOriginalFetch2()
|
|
728
2012
|
}) => {
|
|
729
2013
|
try {
|
|
730
|
-
const response = await
|
|
2014
|
+
const response = await fetch2(url, {
|
|
731
2015
|
method: "POST",
|
|
732
|
-
headers:
|
|
2016
|
+
headers: withUserAgentSuffix(
|
|
2017
|
+
headers,
|
|
2018
|
+
`ai-sdk/provider-utils/${VERSION}`,
|
|
2019
|
+
getRuntimeEnvironmentUserAgent()
|
|
2020
|
+
),
|
|
733
2021
|
body: body.content,
|
|
734
2022
|
signal: abortSignal
|
|
735
2023
|
});
|
|
@@ -873,15 +2161,6 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
873
2161
|
rawValue: parsedResult.rawValue
|
|
874
2162
|
};
|
|
875
2163
|
};
|
|
876
|
-
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
|
877
|
-
var { btoa, atob } = globalThis;
|
|
878
|
-
function convertUint8ArrayToBase64(array) {
|
|
879
|
-
let latin1string = "";
|
|
880
|
-
for (let i = 0; i < array.length; i++) {
|
|
881
|
-
latin1string += String.fromCodePoint(array[i]);
|
|
882
|
-
}
|
|
883
|
-
return btoa(latin1string);
|
|
884
|
-
}
|
|
885
2164
|
|
|
886
2165
|
// src/schemas/reasoning-details.ts
|
|
887
2166
|
var import_v4 = require("zod/v4");
|
|
@@ -1009,7 +2288,7 @@ var OpenRouterProviderOptionsSchema = import_v43.z.object({
|
|
|
1009
2288
|
}).optional();
|
|
1010
2289
|
|
|
1011
2290
|
// src/utils/map-finish-reason.ts
|
|
1012
|
-
function
|
|
2291
|
+
function mapToUnified(finishReason) {
|
|
1013
2292
|
switch (finishReason) {
|
|
1014
2293
|
case "stop":
|
|
1015
2294
|
return "stop";
|
|
@@ -1021,9 +2300,18 @@ function mapOpenRouterFinishReason(finishReason) {
|
|
|
1021
2300
|
case "tool_calls":
|
|
1022
2301
|
return "tool-calls";
|
|
1023
2302
|
default:
|
|
1024
|
-
return "
|
|
2303
|
+
return "other";
|
|
1025
2304
|
}
|
|
1026
2305
|
}
|
|
2306
|
+
function mapOpenRouterFinishReason(finishReason) {
|
|
2307
|
+
return {
|
|
2308
|
+
unified: mapToUnified(finishReason),
|
|
2309
|
+
raw: finishReason != null ? finishReason : void 0
|
|
2310
|
+
};
|
|
2311
|
+
}
|
|
2312
|
+
function createFinishReason(unified, raw) {
|
|
2313
|
+
return { unified, raw };
|
|
2314
|
+
}
|
|
1027
2315
|
|
|
1028
2316
|
// src/types/openrouter-chat-completions-input.ts
|
|
1029
2317
|
var OPENROUTER_AUDIO_FORMATS = [
|
|
@@ -1056,10 +2344,10 @@ function getFileUrl({
|
|
|
1056
2344
|
part,
|
|
1057
2345
|
defaultMediaType
|
|
1058
2346
|
}) {
|
|
1059
|
-
var
|
|
2347
|
+
var _a16, _b16;
|
|
1060
2348
|
if (part.data instanceof Uint8Array) {
|
|
1061
2349
|
const base64 = convertUint8ArrayToBase64(part.data);
|
|
1062
|
-
return `data:${(
|
|
2350
|
+
return `data:${(_a16 = part.mediaType) != null ? _a16 : defaultMediaType};base64,${base64}`;
|
|
1063
2351
|
}
|
|
1064
2352
|
const stringUrl = part.data.toString();
|
|
1065
2353
|
if (isUrl({
|
|
@@ -1068,12 +2356,12 @@ function getFileUrl({
|
|
|
1068
2356
|
})) {
|
|
1069
2357
|
return stringUrl;
|
|
1070
2358
|
}
|
|
1071
|
-
return stringUrl.startsWith("data:") ? stringUrl : `data:${(
|
|
2359
|
+
return stringUrl.startsWith("data:") ? stringUrl : `data:${(_b16 = part.mediaType) != null ? _b16 : defaultMediaType};base64,${stringUrl}`;
|
|
1072
2360
|
}
|
|
1073
2361
|
function getMediaType(dataUrl, defaultMediaType) {
|
|
1074
|
-
var
|
|
2362
|
+
var _a16;
|
|
1075
2363
|
const match = dataUrl.match(/^data:([^;]+)/);
|
|
1076
|
-
return match ? (
|
|
2364
|
+
return match ? (_a16 = match[1]) != null ? _a16 : defaultMediaType : defaultMediaType;
|
|
1077
2365
|
}
|
|
1078
2366
|
function getBase64FromDataUrl(dataUrl) {
|
|
1079
2367
|
const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
|
|
@@ -1148,13 +2436,13 @@ Learn more: https://openrouter.ai/docs/features/multimodal/audio`
|
|
|
1148
2436
|
|
|
1149
2437
|
// src/chat/convert-to-openrouter-chat-messages.ts
|
|
1150
2438
|
function getCacheControl(providerMetadata) {
|
|
1151
|
-
var
|
|
2439
|
+
var _a16, _b16, _c;
|
|
1152
2440
|
const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
1153
2441
|
const openrouter = providerMetadata == null ? void 0 : providerMetadata.openrouter;
|
|
1154
|
-
return (_c = (
|
|
2442
|
+
return (_c = (_b16 = (_a16 = openrouter == null ? void 0 : openrouter.cacheControl) != null ? _a16 : openrouter == null ? void 0 : openrouter.cache_control) != null ? _b16 : anthropic == null ? void 0 : anthropic.cacheControl) != null ? _c : anthropic == null ? void 0 : anthropic.cache_control;
|
|
1155
2443
|
}
|
|
1156
2444
|
function convertToOpenRouterChatMessages(prompt) {
|
|
1157
|
-
var
|
|
2445
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1158
2446
|
const messages = [];
|
|
1159
2447
|
for (const { role, content, providerOptions } of prompt) {
|
|
1160
2448
|
switch (role) {
|
|
@@ -1167,8 +2455,8 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1167
2455
|
break;
|
|
1168
2456
|
}
|
|
1169
2457
|
case "user": {
|
|
1170
|
-
if (content.length === 1 && ((
|
|
1171
|
-
const cacheControl = (
|
|
2458
|
+
if (content.length === 1 && ((_a16 = content[0]) == null ? void 0 : _a16.type) === "text") {
|
|
2459
|
+
const cacheControl = (_b16 = getCacheControl(providerOptions)) != null ? _b16 : getCacheControl(content[0].providerOptions);
|
|
1172
2460
|
const contentWithCacheControl = cacheControl ? [
|
|
1173
2461
|
{
|
|
1174
2462
|
type: "text",
|
|
@@ -1185,8 +2473,8 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1185
2473
|
const messageCacheControl = getCacheControl(providerOptions);
|
|
1186
2474
|
const contentParts = content.map(
|
|
1187
2475
|
(part) => {
|
|
1188
|
-
var
|
|
1189
|
-
const cacheControl = (
|
|
2476
|
+
var _a17, _b17, _c2, _d2, _e2, _f2, _g2;
|
|
2477
|
+
const cacheControl = (_a17 = getCacheControl(part.providerOptions)) != null ? _a17 : messageCacheControl;
|
|
1190
2478
|
switch (part.type) {
|
|
1191
2479
|
case "text":
|
|
1192
2480
|
return {
|
|
@@ -1196,7 +2484,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1196
2484
|
cache_control: cacheControl
|
|
1197
2485
|
};
|
|
1198
2486
|
case "file": {
|
|
1199
|
-
if ((
|
|
2487
|
+
if ((_b17 = part.mediaType) == null ? void 0 : _b17.startsWith("image/")) {
|
|
1200
2488
|
const url = getFileUrl({
|
|
1201
2489
|
part,
|
|
1202
2490
|
defaultMediaType: "image/jpeg"
|
|
@@ -1323,6 +2611,9 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1323
2611
|
}
|
|
1324
2612
|
case "tool": {
|
|
1325
2613
|
for (const toolResponse of content) {
|
|
2614
|
+
if (toolResponse.type === "tool-approval-response") {
|
|
2615
|
+
continue;
|
|
2616
|
+
}
|
|
1326
2617
|
const content2 = getToolResultContent(toolResponse);
|
|
1327
2618
|
messages.push({
|
|
1328
2619
|
role: "tool",
|
|
@@ -1341,7 +2632,18 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1341
2632
|
return messages;
|
|
1342
2633
|
}
|
|
1343
2634
|
function getToolResultContent(input) {
|
|
1344
|
-
|
|
2635
|
+
var _a16;
|
|
2636
|
+
switch (input.output.type) {
|
|
2637
|
+
case "text":
|
|
2638
|
+
case "error-text":
|
|
2639
|
+
return input.output.value;
|
|
2640
|
+
case "json":
|
|
2641
|
+
case "error-json":
|
|
2642
|
+
case "content":
|
|
2643
|
+
return JSON.stringify(input.output.value);
|
|
2644
|
+
case "execution-denied":
|
|
2645
|
+
return (_a16 = input.output.reason) != null ? _a16 : "Tool execution denied";
|
|
2646
|
+
}
|
|
1345
2647
|
}
|
|
1346
2648
|
|
|
1347
2649
|
// src/chat/get-tool-choice.ts
|
|
@@ -1584,7 +2886,7 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
|
|
|
1584
2886
|
// src/chat/index.ts
|
|
1585
2887
|
var OpenRouterChatLanguageModel = class {
|
|
1586
2888
|
constructor(modelId, settings, config) {
|
|
1587
|
-
this.specificationVersion = "
|
|
2889
|
+
this.specificationVersion = "v3";
|
|
1588
2890
|
this.provider = "openrouter";
|
|
1589
2891
|
this.defaultObjectGenerationMode = "tool";
|
|
1590
2892
|
this.supportsImageUrls = true;
|
|
@@ -1614,7 +2916,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1614
2916
|
tools,
|
|
1615
2917
|
toolChoice
|
|
1616
2918
|
}) {
|
|
1617
|
-
var
|
|
2919
|
+
var _a16;
|
|
1618
2920
|
const baseArgs = __spreadValues(__spreadValues({
|
|
1619
2921
|
// model id:
|
|
1620
2922
|
model: this.modelId,
|
|
@@ -1638,7 +2940,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1638
2940
|
json_schema: __spreadValues({
|
|
1639
2941
|
schema: responseFormat.schema,
|
|
1640
2942
|
strict: true,
|
|
1641
|
-
name: (
|
|
2943
|
+
name: (_a16 = responseFormat.name) != null ? _a16 : "response"
|
|
1642
2944
|
}, responseFormat.description && {
|
|
1643
2945
|
description: responseFormat.description
|
|
1644
2946
|
})
|
|
@@ -1677,7 +2979,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1677
2979
|
return baseArgs;
|
|
1678
2980
|
}
|
|
1679
2981
|
async doGenerate(options) {
|
|
1680
|
-
var
|
|
2982
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1681
2983
|
const providerOptions = options.providerOptions || {};
|
|
1682
2984
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1683
2985
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -1717,19 +3019,31 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1717
3019
|
});
|
|
1718
3020
|
}
|
|
1719
3021
|
const usageInfo = response.usage ? {
|
|
1720
|
-
inputTokens:
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
3022
|
+
inputTokens: {
|
|
3023
|
+
total: (_a16 = response.usage.prompt_tokens) != null ? _a16 : 0,
|
|
3024
|
+
noCache: void 0,
|
|
3025
|
+
cacheRead: (_c = (_b16 = response.usage.prompt_tokens_details) == null ? void 0 : _b16.cached_tokens) != null ? _c : void 0,
|
|
3026
|
+
cacheWrite: void 0
|
|
3027
|
+
},
|
|
3028
|
+
outputTokens: {
|
|
3029
|
+
total: (_d = response.usage.completion_tokens) != null ? _d : 0,
|
|
3030
|
+
text: void 0,
|
|
3031
|
+
reasoning: (_f = (_e = response.usage.completion_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : void 0
|
|
3032
|
+
}
|
|
1725
3033
|
} : {
|
|
1726
|
-
inputTokens:
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
3034
|
+
inputTokens: {
|
|
3035
|
+
total: 0,
|
|
3036
|
+
noCache: void 0,
|
|
3037
|
+
cacheRead: void 0,
|
|
3038
|
+
cacheWrite: void 0
|
|
3039
|
+
},
|
|
3040
|
+
outputTokens: {
|
|
3041
|
+
total: 0,
|
|
3042
|
+
text: void 0,
|
|
3043
|
+
reasoning: void 0
|
|
3044
|
+
}
|
|
1731
3045
|
};
|
|
1732
|
-
const reasoningDetails = (
|
|
3046
|
+
const reasoningDetails = (_g = choice.message.reasoning_details) != null ? _g : [];
|
|
1733
3047
|
const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
1734
3048
|
switch (detail.type) {
|
|
1735
3049
|
case "reasoning.text" /* Text */: {
|
|
@@ -1797,7 +3111,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1797
3111
|
for (const toolCall of choice.message.tool_calls) {
|
|
1798
3112
|
content.push({
|
|
1799
3113
|
type: "tool-call",
|
|
1800
|
-
toolCallId: (
|
|
3114
|
+
toolCallId: (_h = toolCall.id) != null ? _h : generateId(),
|
|
1801
3115
|
toolName: toolCall.function.name,
|
|
1802
3116
|
input: toolCall.function.arguments,
|
|
1803
3117
|
providerMetadata: {
|
|
@@ -1835,7 +3149,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1835
3149
|
}
|
|
1836
3150
|
}
|
|
1837
3151
|
}
|
|
1838
|
-
const fileAnnotations = (
|
|
3152
|
+
const fileAnnotations = (_i = choice.message.annotations) == null ? void 0 : _i.filter(
|
|
1839
3153
|
(a) => a.type === "file"
|
|
1840
3154
|
);
|
|
1841
3155
|
const hasToolCalls = choice.message.tool_calls && choice.message.tool_calls.length > 0;
|
|
@@ -1843,7 +3157,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1843
3157
|
(d) => d.type === "reasoning.encrypted" /* Encrypted */ && d.data
|
|
1844
3158
|
);
|
|
1845
3159
|
const shouldOverrideFinishReason = hasToolCalls && hasEncryptedReasoning && choice.finish_reason === "stop";
|
|
1846
|
-
const effectiveFinishReason = shouldOverrideFinishReason ? "tool-calls" : mapOpenRouterFinishReason(choice.finish_reason);
|
|
3160
|
+
const effectiveFinishReason = shouldOverrideFinishReason ? createFinishReason("tool-calls", (_j = choice.finish_reason) != null ? _j : void 0) : mapOpenRouterFinishReason(choice.finish_reason);
|
|
1847
3161
|
return {
|
|
1848
3162
|
content,
|
|
1849
3163
|
finishReason: effectiveFinishReason,
|
|
@@ -1851,13 +3165,13 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1851
3165
|
warnings: [],
|
|
1852
3166
|
providerMetadata: {
|
|
1853
3167
|
openrouter: OpenRouterProviderMetadataSchema.parse({
|
|
1854
|
-
provider: (
|
|
1855
|
-
reasoning_details: (
|
|
3168
|
+
provider: (_k = response.provider) != null ? _k : "",
|
|
3169
|
+
reasoning_details: (_l = choice.message.reasoning_details) != null ? _l : [],
|
|
1856
3170
|
annotations: fileAnnotations && fileAnnotations.length > 0 ? fileAnnotations : void 0,
|
|
1857
3171
|
usage: __spreadValues(__spreadValues(__spreadValues({
|
|
1858
|
-
promptTokens: (
|
|
1859
|
-
completionTokens: (
|
|
1860
|
-
totalTokens: (_p = usageInfo.
|
|
3172
|
+
promptTokens: (_m = usageInfo.inputTokens.total) != null ? _m : 0,
|
|
3173
|
+
completionTokens: (_n = usageInfo.outputTokens.total) != null ? _n : 0,
|
|
3174
|
+
totalTokens: ((_o = usageInfo.inputTokens.total) != null ? _o : 0) + ((_p = usageInfo.outputTokens.total) != null ? _p : 0),
|
|
1861
3175
|
cost: (_q = response.usage) == null ? void 0 : _q.cost
|
|
1862
3176
|
}, ((_s = (_r = response.usage) == null ? void 0 : _r.prompt_tokens_details) == null ? void 0 : _s.cached_tokens) != null ? {
|
|
1863
3177
|
promptTokensDetails: {
|
|
@@ -1883,7 +3197,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1883
3197
|
};
|
|
1884
3198
|
}
|
|
1885
3199
|
async doStream(options) {
|
|
1886
|
-
var
|
|
3200
|
+
var _a16;
|
|
1887
3201
|
const providerOptions = options.providerOptions || {};
|
|
1888
3202
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
1889
3203
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -1898,7 +3212,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1898
3212
|
// only include stream_options when in strict compatibility mode:
|
|
1899
3213
|
stream_options: this.config.compatibility === "strict" ? __spreadValues({
|
|
1900
3214
|
include_usage: true
|
|
1901
|
-
}, ((
|
|
3215
|
+
}, ((_a16 = this.settings.usage) == null ? void 0 : _a16.include) ? { include_usage: true } : {}) : void 0
|
|
1902
3216
|
}),
|
|
1903
3217
|
failedResponseHandler: openrouterFailedResponseHandler,
|
|
1904
3218
|
successfulResponseHandler: createEventSourceResponseHandler(
|
|
@@ -1908,13 +3222,19 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1908
3222
|
fetch: this.config.fetch
|
|
1909
3223
|
});
|
|
1910
3224
|
const toolCalls = [];
|
|
1911
|
-
let finishReason = "other";
|
|
3225
|
+
let finishReason = createFinishReason("other");
|
|
1912
3226
|
const usage = {
|
|
1913
|
-
inputTokens:
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
3227
|
+
inputTokens: {
|
|
3228
|
+
total: void 0,
|
|
3229
|
+
noCache: void 0,
|
|
3230
|
+
cacheRead: void 0,
|
|
3231
|
+
cacheWrite: void 0
|
|
3232
|
+
},
|
|
3233
|
+
outputTokens: {
|
|
3234
|
+
total: void 0,
|
|
3235
|
+
text: void 0,
|
|
3236
|
+
reasoning: void 0
|
|
3237
|
+
}
|
|
1918
3238
|
};
|
|
1919
3239
|
const openrouterUsage = {};
|
|
1920
3240
|
const accumulatedReasoningDetails = [];
|
|
@@ -1929,15 +3249,15 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1929
3249
|
stream: response.pipeThrough(
|
|
1930
3250
|
new TransformStream({
|
|
1931
3251
|
transform(chunk, controller) {
|
|
1932
|
-
var
|
|
3252
|
+
var _a17, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1933
3253
|
if (!chunk.success) {
|
|
1934
|
-
finishReason = "error";
|
|
3254
|
+
finishReason = createFinishReason("error");
|
|
1935
3255
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
1936
3256
|
return;
|
|
1937
3257
|
}
|
|
1938
3258
|
const value = chunk.value;
|
|
1939
3259
|
if ("error" in value) {
|
|
1940
|
-
finishReason = "error";
|
|
3260
|
+
finishReason = createFinishReason("error");
|
|
1941
3261
|
controller.enqueue({ type: "error", error: value.error });
|
|
1942
3262
|
return;
|
|
1943
3263
|
}
|
|
@@ -1958,21 +3278,20 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1958
3278
|
});
|
|
1959
3279
|
}
|
|
1960
3280
|
if (value.usage != null) {
|
|
1961
|
-
usage.inputTokens = value.usage.prompt_tokens;
|
|
1962
|
-
usage.outputTokens = value.usage.completion_tokens;
|
|
1963
|
-
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
3281
|
+
usage.inputTokens.total = value.usage.prompt_tokens;
|
|
3282
|
+
usage.outputTokens.total = value.usage.completion_tokens;
|
|
1964
3283
|
openrouterUsage.promptTokens = value.usage.prompt_tokens;
|
|
1965
3284
|
if (value.usage.prompt_tokens_details) {
|
|
1966
|
-
const cachedInputTokens = (
|
|
1967
|
-
usage.
|
|
3285
|
+
const cachedInputTokens = (_a17 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a17 : 0;
|
|
3286
|
+
usage.inputTokens.cacheRead = cachedInputTokens;
|
|
1968
3287
|
openrouterUsage.promptTokensDetails = {
|
|
1969
3288
|
cachedTokens: cachedInputTokens
|
|
1970
3289
|
};
|
|
1971
3290
|
}
|
|
1972
3291
|
openrouterUsage.completionTokens = value.usage.completion_tokens;
|
|
1973
3292
|
if (value.usage.completion_tokens_details) {
|
|
1974
|
-
const reasoningTokens = (
|
|
1975
|
-
usage.
|
|
3293
|
+
const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
|
|
3294
|
+
usage.outputTokens.reasoning = reasoningTokens;
|
|
1976
3295
|
openrouterUsage.completionTokensDetails = {
|
|
1977
3296
|
reasoningTokens
|
|
1978
3297
|
};
|
|
@@ -2231,20 +3550,20 @@ var OpenRouterChatLanguageModel = class {
|
|
|
2231
3550
|
}
|
|
2232
3551
|
},
|
|
2233
3552
|
flush(controller) {
|
|
2234
|
-
var
|
|
3553
|
+
var _a17;
|
|
2235
3554
|
const hasToolCalls = toolCalls.length > 0;
|
|
2236
3555
|
const hasEncryptedReasoning = accumulatedReasoningDetails.some(
|
|
2237
3556
|
(d) => d.type === "reasoning.encrypted" /* Encrypted */ && d.data
|
|
2238
3557
|
);
|
|
2239
|
-
if (hasToolCalls && hasEncryptedReasoning && finishReason === "stop") {
|
|
2240
|
-
finishReason = "tool-calls";
|
|
3558
|
+
if (hasToolCalls && hasEncryptedReasoning && finishReason.unified === "stop") {
|
|
3559
|
+
finishReason = createFinishReason("tool-calls", finishReason.raw);
|
|
2241
3560
|
}
|
|
2242
|
-
if (finishReason === "tool-calls") {
|
|
3561
|
+
if (finishReason.unified === "tool-calls") {
|
|
2243
3562
|
for (const toolCall of toolCalls) {
|
|
2244
3563
|
if (toolCall && !toolCall.sent) {
|
|
2245
3564
|
controller.enqueue({
|
|
2246
3565
|
type: "tool-call",
|
|
2247
|
-
toolCallId: (
|
|
3566
|
+
toolCallId: (_a17 = toolCall.id) != null ? _a17 : generateId(),
|
|
2248
3567
|
toolName: toolCall.function.name,
|
|
2249
3568
|
// Coerce invalid arguments to an empty JSON object
|
|
2250
3569
|
input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
|
|
@@ -2445,7 +3764,7 @@ var OpenRouterCompletionChunkSchema = import_v47.z.union([
|
|
|
2445
3764
|
// src/completion/index.ts
|
|
2446
3765
|
var OpenRouterCompletionLanguageModel = class {
|
|
2447
3766
|
constructor(modelId, settings, config) {
|
|
2448
|
-
this.specificationVersion = "
|
|
3767
|
+
this.specificationVersion = "v3";
|
|
2449
3768
|
this.provider = "openrouter";
|
|
2450
3769
|
this.supportsImageUrls = true;
|
|
2451
3770
|
this.supportedUrls = {
|
|
@@ -2516,7 +3835,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
2516
3835
|
}, this.config.extraBody), this.settings.extraBody);
|
|
2517
3836
|
}
|
|
2518
3837
|
async doGenerate(options) {
|
|
2519
|
-
var
|
|
3838
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2520
3839
|
const providerOptions = options.providerOptions || {};
|
|
2521
3840
|
const openrouterOptions = providerOptions.openrouter || {};
|
|
2522
3841
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), openrouterOptions);
|
|
@@ -2558,16 +3877,22 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
2558
3877
|
content: [
|
|
2559
3878
|
{
|
|
2560
3879
|
type: "text",
|
|
2561
|
-
text: (
|
|
3880
|
+
text: (_a16 = choice.text) != null ? _a16 : ""
|
|
2562
3881
|
}
|
|
2563
3882
|
],
|
|
2564
3883
|
finishReason: mapOpenRouterFinishReason(choice.finish_reason),
|
|
2565
3884
|
usage: {
|
|
2566
|
-
inputTokens:
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
3885
|
+
inputTokens: {
|
|
3886
|
+
total: (_c = (_b16 = response.usage) == null ? void 0 : _b16.prompt_tokens) != null ? _c : 0,
|
|
3887
|
+
noCache: void 0,
|
|
3888
|
+
cacheRead: (_f = (_e = (_d = response.usage) == null ? void 0 : _d.prompt_tokens_details) == null ? void 0 : _e.cached_tokens) != null ? _f : void 0,
|
|
3889
|
+
cacheWrite: void 0
|
|
3890
|
+
},
|
|
3891
|
+
outputTokens: {
|
|
3892
|
+
total: (_h = (_g = response.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : 0,
|
|
3893
|
+
text: void 0,
|
|
3894
|
+
reasoning: (_k = (_j = (_i = response.usage) == null ? void 0 : _i.completion_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0
|
|
3895
|
+
}
|
|
2571
3896
|
},
|
|
2572
3897
|
warnings: [],
|
|
2573
3898
|
response: {
|
|
@@ -2597,47 +3922,52 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
2597
3922
|
abortSignal: options.abortSignal,
|
|
2598
3923
|
fetch: this.config.fetch
|
|
2599
3924
|
});
|
|
2600
|
-
let finishReason = "other";
|
|
3925
|
+
let finishReason = createFinishReason("other");
|
|
2601
3926
|
const usage = {
|
|
2602
|
-
inputTokens:
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
3927
|
+
inputTokens: {
|
|
3928
|
+
total: void 0,
|
|
3929
|
+
noCache: void 0,
|
|
3930
|
+
cacheRead: void 0,
|
|
3931
|
+
cacheWrite: void 0
|
|
3932
|
+
},
|
|
3933
|
+
outputTokens: {
|
|
3934
|
+
total: void 0,
|
|
3935
|
+
text: void 0,
|
|
3936
|
+
reasoning: void 0
|
|
3937
|
+
}
|
|
2607
3938
|
};
|
|
2608
3939
|
const openrouterUsage = {};
|
|
2609
3940
|
return {
|
|
2610
3941
|
stream: response.pipeThrough(
|
|
2611
3942
|
new TransformStream({
|
|
2612
3943
|
transform(chunk, controller) {
|
|
2613
|
-
var
|
|
3944
|
+
var _a16, _b16, _c;
|
|
2614
3945
|
if (!chunk.success) {
|
|
2615
|
-
finishReason = "error";
|
|
3946
|
+
finishReason = createFinishReason("error");
|
|
2616
3947
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
2617
3948
|
return;
|
|
2618
3949
|
}
|
|
2619
3950
|
const value = chunk.value;
|
|
2620
3951
|
if ("error" in value) {
|
|
2621
|
-
finishReason = "error";
|
|
3952
|
+
finishReason = createFinishReason("error");
|
|
2622
3953
|
controller.enqueue({ type: "error", error: value.error });
|
|
2623
3954
|
return;
|
|
2624
3955
|
}
|
|
2625
3956
|
if (value.usage != null) {
|
|
2626
|
-
usage.inputTokens = value.usage.prompt_tokens;
|
|
2627
|
-
usage.outputTokens = value.usage.completion_tokens;
|
|
2628
|
-
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
3957
|
+
usage.inputTokens.total = value.usage.prompt_tokens;
|
|
3958
|
+
usage.outputTokens.total = value.usage.completion_tokens;
|
|
2629
3959
|
openrouterUsage.promptTokens = value.usage.prompt_tokens;
|
|
2630
3960
|
if (value.usage.prompt_tokens_details) {
|
|
2631
|
-
const cachedInputTokens = (
|
|
2632
|
-
usage.
|
|
3961
|
+
const cachedInputTokens = (_a16 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a16 : 0;
|
|
3962
|
+
usage.inputTokens.cacheRead = cachedInputTokens;
|
|
2633
3963
|
openrouterUsage.promptTokensDetails = {
|
|
2634
3964
|
cachedTokens: cachedInputTokens
|
|
2635
3965
|
};
|
|
2636
3966
|
}
|
|
2637
3967
|
openrouterUsage.completionTokens = value.usage.completion_tokens;
|
|
2638
3968
|
if (value.usage.completion_tokens_details) {
|
|
2639
|
-
const reasoningTokens = (
|
|
2640
|
-
usage.
|
|
3969
|
+
const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
|
|
3970
|
+
usage.outputTokens.reasoning = reasoningTokens;
|
|
2641
3971
|
openrouterUsage.completionTokensDetails = {
|
|
2642
3972
|
reasoningTokens
|
|
2643
3973
|
};
|