@codemation/core-nodes-ocr 0.2.6 → 0.2.8
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/CHANGELOG.md +16 -0
- package/dist/{analyzeInvoiceNode-BqZsN8iL.js → analyzeInvoiceNode-BQzww-XC.js} +1 -9
- package/dist/analyzeInvoiceNode-BQzww-XC.js.map +1 -0
- package/dist/{analyzeInvoiceNode-CmMsifbw.cjs → analyzeInvoiceNode-CW_SXNQf.cjs} +1 -9
- package/dist/analyzeInvoiceNode-CW_SXNQf.cjs.map +1 -0
- package/dist/codemation.plugin.cjs +1204 -14695
- package/dist/codemation.plugin.cjs.map +1 -1
- package/dist/codemation.plugin.d.cts +1 -73
- package/dist/codemation.plugin.d.ts +1 -58
- package/dist/codemation.plugin.js +1248 -14738
- package/dist/codemation.plugin.js.map +1 -1
- package/dist/dist-BDgdLisG.js +5378 -0
- package/dist/dist-BDgdLisG.js.map +1 -0
- package/dist/dist-BYInIjS8.js +2246 -0
- package/dist/dist-BYInIjS8.js.map +1 -0
- package/dist/dist-BlD4pqf2.cjs +4358 -0
- package/dist/dist-BlD4pqf2.cjs.map +1 -0
- package/dist/dist-CUcwHflE.cjs +14870 -0
- package/dist/dist-CUcwHflE.cjs.map +1 -0
- package/dist/dist-DB2xMXXm.cjs +5380 -0
- package/dist/dist-DB2xMXXm.cjs.map +1 -0
- package/dist/dist-DBYFkhSG.js +14739 -0
- package/dist/dist-DBYFkhSG.js.map +1 -0
- package/dist/dist-DZfaPW8T.js +4356 -0
- package/dist/dist-DZfaPW8T.js.map +1 -0
- package/dist/dist-Zdvm5pqX.cjs +2464 -0
- package/dist/dist-Zdvm5pqX.cjs.map +1 -0
- package/dist/{index-DF2ht42F.d.ts → index-DdjAAXvy.d.ts} +18 -274
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +15 -35
- package/dist/index.d.ts +7 -29
- package/dist/index.js +1 -1
- package/dist/metadata.json +1 -1
- package/dist/{runtimeTypes-WCvsnJMY.d.cts → runtimeTypes-D_9j5Pat.d.cts} +10 -253
- package/dist/{token-CgF09kyP.cjs → token-Cbd8b88n.cjs} +2 -2
- package/dist/{token-CgF09kyP.cjs.map → token-Cbd8b88n.cjs.map} +1 -1
- package/dist/{token-CIu4PqRI.js → token-P-r3QR1d.js} +2 -2
- package/dist/{token-CIu4PqRI.js.map → token-P-r3QR1d.js.map} +1 -1
- package/dist/{token-util-B2kSJtEV.cjs → token-util-B2Ofk2zk.cjs} +77 -77
- package/dist/token-util-B2Ofk2zk.cjs.map +1 -0
- package/dist/{token-util-Lr5foG4r.cjs → token-util-CT85hbGe.cjs} +1 -1
- package/dist/{token-util-EUxa8JtH.js → token-util-CfNdwRXi.js} +77 -77
- package/dist/token-util-CfNdwRXi.js.map +1 -0
- package/dist/token-util-rTxWuZPt.js +5 -0
- package/package.json +2 -2
- package/src/lib/analyzeWithAzure.ts +0 -9
- package/src/nodes/analyzeDocumentNode.ts +0 -9
- package/src/nodes/analyzeImageNode.ts +0 -9
- package/src/nodes/analyzeInvoiceNode.ts +0 -4
- package/dist/analyzeInvoiceNode-BqZsN8iL.js.map +0 -1
- package/dist/analyzeInvoiceNode-CmMsifbw.cjs.map +0 -1
- package/dist/token-util-B2kSJtEV.cjs.map +0 -1
- package/dist/token-util-BsR6OYHz.js +0 -5
- package/dist/token-util-EUxa8JtH.js.map +0 -1
|
@@ -0,0 +1,2246 @@
|
|
|
1
|
+
import * as z4 from "zod/v4";
|
|
2
|
+
import { ZodFirstPartyTypeKind } from "zod/v3";
|
|
3
|
+
|
|
4
|
+
//#region ../../node_modules/.pnpm/@ai-sdk+provider@3.0.10/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
5
|
+
var marker$1 = "vercel.ai.error";
|
|
6
|
+
var symbol$1 = Symbol.for(marker$1);
|
|
7
|
+
var _a$1, _b$1;
|
|
8
|
+
var AISDKError = class _AISDKError extends (_b$1 = Error, _a$1 = symbol$1, _b$1) {
|
|
9
|
+
/**
|
|
10
|
+
* Creates an AI SDK Error.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} params - The parameters for creating the error.
|
|
13
|
+
* @param {string} params.name - The name of the error.
|
|
14
|
+
* @param {string} params.message - The error message.
|
|
15
|
+
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
16
|
+
*/
|
|
17
|
+
constructor({ name: name14, message, cause }) {
|
|
18
|
+
super(message);
|
|
19
|
+
this[_a$1] = true;
|
|
20
|
+
this.name = name14;
|
|
21
|
+
this.cause = cause;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the given error is an AI SDK Error.
|
|
25
|
+
* @param {unknown} error - The error to check.
|
|
26
|
+
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
27
|
+
*/
|
|
28
|
+
static isInstance(error) {
|
|
29
|
+
return _AISDKError.hasMarker(error, marker$1);
|
|
30
|
+
}
|
|
31
|
+
static hasMarker(error, marker15) {
|
|
32
|
+
const markerSymbol = Symbol.for(marker15);
|
|
33
|
+
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var name$1 = "AI_APICallError";
|
|
37
|
+
var marker2 = `vercel.ai.error.${name$1}`;
|
|
38
|
+
var symbol2 = Symbol.for(marker2);
|
|
39
|
+
var _a2, _b2;
|
|
40
|
+
var APICallError = class extends (_b2 = AISDKError, _a2 = symbol2, _b2) {
|
|
41
|
+
constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
|
|
42
|
+
super({
|
|
43
|
+
name: name$1,
|
|
44
|
+
message,
|
|
45
|
+
cause
|
|
46
|
+
});
|
|
47
|
+
this[_a2] = true;
|
|
48
|
+
this.url = url;
|
|
49
|
+
this.requestBodyValues = requestBodyValues;
|
|
50
|
+
this.statusCode = statusCode;
|
|
51
|
+
this.responseHeaders = responseHeaders;
|
|
52
|
+
this.responseBody = responseBody;
|
|
53
|
+
this.isRetryable = isRetryable;
|
|
54
|
+
this.data = data;
|
|
55
|
+
}
|
|
56
|
+
static isInstance(error) {
|
|
57
|
+
return AISDKError.hasMarker(error, marker2);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var name2 = "AI_EmptyResponseBodyError";
|
|
61
|
+
var marker3 = `vercel.ai.error.${name2}`;
|
|
62
|
+
var symbol3 = Symbol.for(marker3);
|
|
63
|
+
var _a3, _b3;
|
|
64
|
+
var EmptyResponseBodyError = class extends (_b3 = AISDKError, _a3 = symbol3, _b3) {
|
|
65
|
+
constructor({ message = "Empty response body" } = {}) {
|
|
66
|
+
super({
|
|
67
|
+
name: name2,
|
|
68
|
+
message
|
|
69
|
+
});
|
|
70
|
+
this[_a3] = true;
|
|
71
|
+
}
|
|
72
|
+
static isInstance(error) {
|
|
73
|
+
return AISDKError.hasMarker(error, marker3);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
function getErrorMessage(error) {
|
|
77
|
+
if (error == null) return "unknown error";
|
|
78
|
+
if (typeof error === "string") return error;
|
|
79
|
+
if (error instanceof Error) return error.message;
|
|
80
|
+
return JSON.stringify(error);
|
|
81
|
+
}
|
|
82
|
+
var name3 = "AI_InvalidArgumentError";
|
|
83
|
+
var marker4 = `vercel.ai.error.${name3}`;
|
|
84
|
+
var symbol4 = Symbol.for(marker4);
|
|
85
|
+
var _a4, _b4;
|
|
86
|
+
var InvalidArgumentError = class extends (_b4 = AISDKError, _a4 = symbol4, _b4) {
|
|
87
|
+
constructor({ message, cause, argument }) {
|
|
88
|
+
super({
|
|
89
|
+
name: name3,
|
|
90
|
+
message,
|
|
91
|
+
cause
|
|
92
|
+
});
|
|
93
|
+
this[_a4] = true;
|
|
94
|
+
this.argument = argument;
|
|
95
|
+
}
|
|
96
|
+
static isInstance(error) {
|
|
97
|
+
return AISDKError.hasMarker(error, marker4);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var name4 = "AI_InvalidPromptError";
|
|
101
|
+
var marker5 = `vercel.ai.error.${name4}`;
|
|
102
|
+
var symbol5 = Symbol.for(marker5);
|
|
103
|
+
var _a5, _b5;
|
|
104
|
+
var InvalidPromptError = class extends (_b5 = AISDKError, _a5 = symbol5, _b5) {
|
|
105
|
+
constructor({ prompt, message, cause }) {
|
|
106
|
+
super({
|
|
107
|
+
name: name4,
|
|
108
|
+
message: `Invalid prompt: ${message}`,
|
|
109
|
+
cause
|
|
110
|
+
});
|
|
111
|
+
this[_a5] = true;
|
|
112
|
+
this.prompt = prompt;
|
|
113
|
+
}
|
|
114
|
+
static isInstance(error) {
|
|
115
|
+
return AISDKError.hasMarker(error, marker5);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var name5 = "AI_InvalidResponseDataError";
|
|
119
|
+
var marker6 = `vercel.ai.error.${name5}`;
|
|
120
|
+
var symbol6 = Symbol.for(marker6);
|
|
121
|
+
var _a6, _b6;
|
|
122
|
+
var InvalidResponseDataError = class extends (_b6 = AISDKError, _a6 = symbol6, _b6) {
|
|
123
|
+
constructor({ data, message = `Invalid response data: ${JSON.stringify(data)}.` }) {
|
|
124
|
+
super({
|
|
125
|
+
name: name5,
|
|
126
|
+
message
|
|
127
|
+
});
|
|
128
|
+
this[_a6] = true;
|
|
129
|
+
this.data = data;
|
|
130
|
+
}
|
|
131
|
+
static isInstance(error) {
|
|
132
|
+
return AISDKError.hasMarker(error, marker6);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
var name6 = "AI_JSONParseError";
|
|
136
|
+
var marker7 = `vercel.ai.error.${name6}`;
|
|
137
|
+
var symbol7 = Symbol.for(marker7);
|
|
138
|
+
var _a7, _b7;
|
|
139
|
+
var JSONParseError = class extends (_b7 = AISDKError, _a7 = symbol7, _b7) {
|
|
140
|
+
constructor({ text, cause }) {
|
|
141
|
+
super({
|
|
142
|
+
name: name6,
|
|
143
|
+
message: `JSON parsing failed: Text: ${text}.
|
|
144
|
+
Error message: ${getErrorMessage(cause)}`,
|
|
145
|
+
cause
|
|
146
|
+
});
|
|
147
|
+
this[_a7] = true;
|
|
148
|
+
this.text = text;
|
|
149
|
+
}
|
|
150
|
+
static isInstance(error) {
|
|
151
|
+
return AISDKError.hasMarker(error, marker7);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
var name7 = "AI_LoadAPIKeyError";
|
|
155
|
+
var marker8 = `vercel.ai.error.${name7}`;
|
|
156
|
+
var symbol8 = Symbol.for(marker8);
|
|
157
|
+
var _a8, _b8;
|
|
158
|
+
var LoadAPIKeyError = class extends (_b8 = AISDKError, _a8 = symbol8, _b8) {
|
|
159
|
+
constructor({ message }) {
|
|
160
|
+
super({
|
|
161
|
+
name: name7,
|
|
162
|
+
message
|
|
163
|
+
});
|
|
164
|
+
this[_a8] = true;
|
|
165
|
+
}
|
|
166
|
+
static isInstance(error) {
|
|
167
|
+
return AISDKError.hasMarker(error, marker8);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
var name8 = "AI_LoadSettingError";
|
|
171
|
+
var marker9 = `vercel.ai.error.${name8}`;
|
|
172
|
+
var symbol9 = Symbol.for(marker9);
|
|
173
|
+
var name9 = "AI_NoContentGeneratedError";
|
|
174
|
+
var marker10 = `vercel.ai.error.${name9}`;
|
|
175
|
+
var symbol10 = Symbol.for(marker10);
|
|
176
|
+
var name10 = "AI_NoSuchModelError";
|
|
177
|
+
var marker11 = `vercel.ai.error.${name10}`;
|
|
178
|
+
var symbol11 = Symbol.for(marker11);
|
|
179
|
+
var _a11, _b11;
|
|
180
|
+
var NoSuchModelError = class extends (_b11 = AISDKError, _a11 = symbol11, _b11) {
|
|
181
|
+
constructor({ errorName = name10, modelId, modelType, message = `No such ${modelType}: ${modelId}` }) {
|
|
182
|
+
super({
|
|
183
|
+
name: errorName,
|
|
184
|
+
message
|
|
185
|
+
});
|
|
186
|
+
this[_a11] = true;
|
|
187
|
+
this.modelId = modelId;
|
|
188
|
+
this.modelType = modelType;
|
|
189
|
+
}
|
|
190
|
+
static isInstance(error) {
|
|
191
|
+
return AISDKError.hasMarker(error, marker11);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
var name11 = "AI_TooManyEmbeddingValuesForCallError";
|
|
195
|
+
var marker12 = `vercel.ai.error.${name11}`;
|
|
196
|
+
var symbol12 = Symbol.for(marker12);
|
|
197
|
+
var _a12, _b12;
|
|
198
|
+
var TooManyEmbeddingValuesForCallError = class extends (_b12 = AISDKError, _a12 = symbol12, _b12) {
|
|
199
|
+
constructor(options) {
|
|
200
|
+
super({
|
|
201
|
+
name: name11,
|
|
202
|
+
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.`
|
|
203
|
+
});
|
|
204
|
+
this[_a12] = true;
|
|
205
|
+
this.provider = options.provider;
|
|
206
|
+
this.modelId = options.modelId;
|
|
207
|
+
this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
|
|
208
|
+
this.values = options.values;
|
|
209
|
+
}
|
|
210
|
+
static isInstance(error) {
|
|
211
|
+
return AISDKError.hasMarker(error, marker12);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
var name12 = "AI_TypeValidationError";
|
|
215
|
+
var marker13 = `vercel.ai.error.${name12}`;
|
|
216
|
+
var symbol13 = Symbol.for(marker13);
|
|
217
|
+
var _a13, _b13;
|
|
218
|
+
var TypeValidationError = class _TypeValidationError extends (_b13 = AISDKError, _a13 = symbol13, _b13) {
|
|
219
|
+
constructor({ value, cause, context }) {
|
|
220
|
+
let contextPrefix = "Type validation failed";
|
|
221
|
+
if (context == null ? void 0 : context.field) contextPrefix += ` for ${context.field}`;
|
|
222
|
+
if ((context == null ? void 0 : context.entityName) || (context == null ? void 0 : context.entityId)) {
|
|
223
|
+
contextPrefix += " (";
|
|
224
|
+
const parts = [];
|
|
225
|
+
if (context.entityName) parts.push(context.entityName);
|
|
226
|
+
if (context.entityId) parts.push(`id: "${context.entityId}"`);
|
|
227
|
+
contextPrefix += parts.join(", ");
|
|
228
|
+
contextPrefix += ")";
|
|
229
|
+
}
|
|
230
|
+
super({
|
|
231
|
+
name: name12,
|
|
232
|
+
message: `${contextPrefix}: Value: ${JSON.stringify(value)}.
|
|
233
|
+
Error message: ${getErrorMessage(cause)}`,
|
|
234
|
+
cause
|
|
235
|
+
});
|
|
236
|
+
this[_a13] = true;
|
|
237
|
+
this.value = value;
|
|
238
|
+
this.context = context;
|
|
239
|
+
}
|
|
240
|
+
static isInstance(error) {
|
|
241
|
+
return AISDKError.hasMarker(error, marker13);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Wraps an error into a TypeValidationError.
|
|
245
|
+
* If the cause is already a TypeValidationError with the same value and context, it returns the cause.
|
|
246
|
+
* Otherwise, it creates a new TypeValidationError.
|
|
247
|
+
*
|
|
248
|
+
* @param {Object} params - The parameters for wrapping the error.
|
|
249
|
+
* @param {unknown} params.value - The value that failed validation.
|
|
250
|
+
* @param {unknown} params.cause - The original error or cause of the validation failure.
|
|
251
|
+
* @param {TypeValidationContext} params.context - Optional context about what is being validated.
|
|
252
|
+
* @returns {TypeValidationError} A TypeValidationError instance.
|
|
253
|
+
*/
|
|
254
|
+
static wrap({ value, cause, context }) {
|
|
255
|
+
var _a15, _b15, _c;
|
|
256
|
+
if (_TypeValidationError.isInstance(cause) && cause.value === value && ((_a15 = cause.context) == null ? void 0 : _a15.field) === (context == null ? void 0 : context.field) && ((_b15 = cause.context) == null ? void 0 : _b15.entityName) === (context == null ? void 0 : context.entityName) && ((_c = cause.context) == null ? void 0 : _c.entityId) === (context == null ? void 0 : context.entityId)) return cause;
|
|
257
|
+
return new _TypeValidationError({
|
|
258
|
+
value,
|
|
259
|
+
cause,
|
|
260
|
+
context
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
var name13 = "AI_UnsupportedFunctionalityError";
|
|
265
|
+
var marker14 = `vercel.ai.error.${name13}`;
|
|
266
|
+
var symbol14 = Symbol.for(marker14);
|
|
267
|
+
var _a14, _b14;
|
|
268
|
+
var UnsupportedFunctionalityError = class extends (_b14 = AISDKError, _a14 = symbol14, _b14) {
|
|
269
|
+
constructor({ functionality, message = `'${functionality}' functionality not supported.` }) {
|
|
270
|
+
super({
|
|
271
|
+
name: name13,
|
|
272
|
+
message
|
|
273
|
+
});
|
|
274
|
+
this[_a14] = true;
|
|
275
|
+
this.functionality = functionality;
|
|
276
|
+
}
|
|
277
|
+
static isInstance(error) {
|
|
278
|
+
return AISDKError.hasMarker(error, marker14);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
//#endregion
|
|
283
|
+
//#region ../../node_modules/.pnpm/eventsource-parser@3.0.8/node_modules/eventsource-parser/dist/index.js
|
|
284
|
+
var ParseError = class extends Error {
|
|
285
|
+
constructor(message, options) {
|
|
286
|
+
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
const LF = 10, CR = 13, SPACE = 32;
|
|
290
|
+
function noop(_arg) {}
|
|
291
|
+
function createParser(callbacks) {
|
|
292
|
+
if (typeof callbacks == "function") throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");
|
|
293
|
+
const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks, pendingFragments = [];
|
|
294
|
+
let isFirstChunk = !0, id, data = "", dataLines = 0, eventType;
|
|
295
|
+
function feed(chunk) {
|
|
296
|
+
if (isFirstChunk && (isFirstChunk = !1, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
|
|
297
|
+
const trailing2 = processLines(chunk);
|
|
298
|
+
trailing2 !== "" && pendingFragments.push(trailing2);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (chunk.indexOf(`
|
|
302
|
+
`) === -1 && chunk.indexOf("\r") === -1) {
|
|
303
|
+
pendingFragments.push(chunk);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
pendingFragments.push(chunk);
|
|
307
|
+
const input = pendingFragments.join("");
|
|
308
|
+
pendingFragments.length = 0;
|
|
309
|
+
const trailing = processLines(input);
|
|
310
|
+
trailing !== "" && pendingFragments.push(trailing);
|
|
311
|
+
}
|
|
312
|
+
function processLines(chunk) {
|
|
313
|
+
let searchIndex = 0;
|
|
314
|
+
if (chunk.indexOf("\r") === -1) {
|
|
315
|
+
let lfIndex = chunk.indexOf(`
|
|
316
|
+
`, searchIndex);
|
|
317
|
+
for (; lfIndex !== -1;) {
|
|
318
|
+
if (searchIndex === lfIndex) {
|
|
319
|
+
dataLines > 0 && onEvent({
|
|
320
|
+
id,
|
|
321
|
+
event: eventType,
|
|
322
|
+
data
|
|
323
|
+
}), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
324
|
+
`, searchIndex);
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
const firstCharCode = chunk.charCodeAt(searchIndex);
|
|
328
|
+
if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
|
|
329
|
+
const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
|
|
330
|
+
if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
|
|
331
|
+
onEvent({
|
|
332
|
+
id,
|
|
333
|
+
event: eventType,
|
|
334
|
+
data: value
|
|
335
|
+
}), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
|
|
336
|
+
`, searchIndex);
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
data = dataLines === 0 ? value : `${data}
|
|
340
|
+
${value}`, dataLines++;
|
|
341
|
+
} else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6, lfIndex) || void 0 : parseLine(chunk, searchIndex, lfIndex);
|
|
342
|
+
searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
343
|
+
`, searchIndex);
|
|
344
|
+
}
|
|
345
|
+
return chunk.slice(searchIndex);
|
|
346
|
+
}
|
|
347
|
+
for (; searchIndex < chunk.length;) {
|
|
348
|
+
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
349
|
+
`, searchIndex);
|
|
350
|
+
let lineEnd = -1;
|
|
351
|
+
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) break;
|
|
352
|
+
parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
|
|
353
|
+
}
|
|
354
|
+
return chunk.slice(searchIndex);
|
|
355
|
+
}
|
|
356
|
+
function parseLine(chunk, start, end) {
|
|
357
|
+
if (start === end) {
|
|
358
|
+
dispatchEvent();
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const firstCharCode = chunk.charCodeAt(start);
|
|
362
|
+
if (isDataPrefix(chunk, start, firstCharCode)) {
|
|
363
|
+
const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
|
|
364
|
+
data = dataLines === 0 ? value2 : `${data}
|
|
365
|
+
${value2}`, dataLines++;
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
if (isEventPrefix(chunk, start, firstCharCode)) {
|
|
369
|
+
eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
|
|
373
|
+
const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
|
|
374
|
+
id = value2.includes("\0") ? void 0 : value2;
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
if (firstCharCode === 58) {
|
|
378
|
+
if (onComment) onComment(chunk.slice(start, end).slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
|
|
382
|
+
if (fieldSeparatorIndex === -1) {
|
|
383
|
+
processField(line, "", line);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1;
|
|
387
|
+
processField(field, line.slice(fieldSeparatorIndex + offset), line);
|
|
388
|
+
}
|
|
389
|
+
function processField(field, value, line) {
|
|
390
|
+
switch (field) {
|
|
391
|
+
case "event":
|
|
392
|
+
eventType = value || void 0;
|
|
393
|
+
break;
|
|
394
|
+
case "data":
|
|
395
|
+
data = dataLines === 0 ? value : `${data}
|
|
396
|
+
${value}`, dataLines++;
|
|
397
|
+
break;
|
|
398
|
+
case "id":
|
|
399
|
+
id = value.includes("\0") ? void 0 : value;
|
|
400
|
+
break;
|
|
401
|
+
case "retry":
|
|
402
|
+
/^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(new ParseError(`Invalid \`retry\` value: "${value}"`, {
|
|
403
|
+
type: "invalid-retry",
|
|
404
|
+
value,
|
|
405
|
+
line
|
|
406
|
+
}));
|
|
407
|
+
break;
|
|
408
|
+
default:
|
|
409
|
+
onError(new ParseError(`Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`, {
|
|
410
|
+
type: "unknown-field",
|
|
411
|
+
field,
|
|
412
|
+
value,
|
|
413
|
+
line
|
|
414
|
+
}));
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
function dispatchEvent() {
|
|
419
|
+
dataLines > 0 && onEvent({
|
|
420
|
+
id,
|
|
421
|
+
event: eventType,
|
|
422
|
+
data
|
|
423
|
+
}), id = void 0, data = "", dataLines = 0, eventType = void 0;
|
|
424
|
+
}
|
|
425
|
+
function reset(options = {}) {
|
|
426
|
+
if (options.consume && pendingFragments.length > 0) {
|
|
427
|
+
const incompleteLine = pendingFragments.join("");
|
|
428
|
+
parseLine(incompleteLine, 0, incompleteLine.length);
|
|
429
|
+
}
|
|
430
|
+
isFirstChunk = !0, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
|
|
431
|
+
}
|
|
432
|
+
return {
|
|
433
|
+
feed,
|
|
434
|
+
reset
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
function isDataPrefix(chunk, i, firstCharCode) {
|
|
438
|
+
return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
|
|
439
|
+
}
|
|
440
|
+
function isEventPrefix(chunk, i, firstCharCode) {
|
|
441
|
+
return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
//#endregion
|
|
445
|
+
//#region ../../node_modules/.pnpm/eventsource-parser@3.0.8/node_modules/eventsource-parser/dist/stream.js
|
|
446
|
+
var EventSourceParserStream = class extends TransformStream {
|
|
447
|
+
constructor({ onError, onRetry, onComment } = {}) {
|
|
448
|
+
let parser;
|
|
449
|
+
super({
|
|
450
|
+
start(controller) {
|
|
451
|
+
parser = createParser({
|
|
452
|
+
onEvent: (event) => {
|
|
453
|
+
controller.enqueue(event);
|
|
454
|
+
},
|
|
455
|
+
onError(error) {
|
|
456
|
+
onError === "terminate" ? controller.error(error) : typeof onError == "function" && onError(error);
|
|
457
|
+
},
|
|
458
|
+
onRetry,
|
|
459
|
+
onComment
|
|
460
|
+
});
|
|
461
|
+
},
|
|
462
|
+
transform(chunk) {
|
|
463
|
+
parser.feed(chunk);
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region ../../node_modules/.pnpm/@ai-sdk+provider-utils@4.0.30_zod@4.3.6/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
471
|
+
function combineHeaders(...headers) {
|
|
472
|
+
return headers.reduce((combinedHeaders, currentHeaders) => ({
|
|
473
|
+
...combinedHeaders,
|
|
474
|
+
...currentHeaders != null ? currentHeaders : {}
|
|
475
|
+
}), {});
|
|
476
|
+
}
|
|
477
|
+
function createToolNameMapping({ tools = [], providerToolNames, resolveProviderToolName }) {
|
|
478
|
+
var _a2$1;
|
|
479
|
+
const customToolNameToProviderToolName = {};
|
|
480
|
+
const providerToolNameToCustomToolName = {};
|
|
481
|
+
for (const tool2 of tools) if (tool2.type === "provider") {
|
|
482
|
+
const providerToolName = (_a2$1 = resolveProviderToolName == null ? void 0 : resolveProviderToolName(tool2)) != null ? _a2$1 : tool2.id in providerToolNames ? providerToolNames[tool2.id] : void 0;
|
|
483
|
+
if (providerToolName == null) continue;
|
|
484
|
+
customToolNameToProviderToolName[tool2.name] = providerToolName;
|
|
485
|
+
providerToolNameToCustomToolName[providerToolName] = tool2.name;
|
|
486
|
+
}
|
|
487
|
+
return {
|
|
488
|
+
toProviderToolName: (customToolName) => {
|
|
489
|
+
var _a3$1;
|
|
490
|
+
return (_a3$1 = customToolNameToProviderToolName[customToolName]) != null ? _a3$1 : customToolName;
|
|
491
|
+
},
|
|
492
|
+
toCustomToolName: (providerToolName) => {
|
|
493
|
+
var _a3$1;
|
|
494
|
+
return (_a3$1 = providerToolNameToCustomToolName[providerToolName]) != null ? _a3$1 : providerToolName;
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function extractResponseHeaders(response) {
|
|
499
|
+
return Object.fromEntries([...response.headers]);
|
|
500
|
+
}
|
|
501
|
+
var { btoa, atob } = globalThis;
|
|
502
|
+
function convertBase64ToUint8Array(base64String) {
|
|
503
|
+
const latin1string = atob(base64String.replace(/-/g, "+").replace(/_/g, "/"));
|
|
504
|
+
return Uint8Array.from(latin1string, (byte) => byte.codePointAt(0));
|
|
505
|
+
}
|
|
506
|
+
function convertUint8ArrayToBase64(array) {
|
|
507
|
+
let latin1string = "";
|
|
508
|
+
for (let i = 0; i < array.length; i++) latin1string += String.fromCodePoint(array[i]);
|
|
509
|
+
return btoa(latin1string);
|
|
510
|
+
}
|
|
511
|
+
function convertToBase64(value) {
|
|
512
|
+
return value instanceof Uint8Array ? convertUint8ArrayToBase64(value) : value;
|
|
513
|
+
}
|
|
514
|
+
function convertToFormData(input, options = {}) {
|
|
515
|
+
const { useArrayBrackets = true } = options;
|
|
516
|
+
const formData = new FormData();
|
|
517
|
+
for (const [key, value] of Object.entries(input)) {
|
|
518
|
+
if (value == null) continue;
|
|
519
|
+
if (Array.isArray(value)) {
|
|
520
|
+
if (value.length === 1) {
|
|
521
|
+
formData.append(key, value[0]);
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
const arrayKey = useArrayBrackets ? `${key}[]` : key;
|
|
525
|
+
for (const item of value) formData.append(arrayKey, item);
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
formData.append(key, value);
|
|
529
|
+
}
|
|
530
|
+
return formData;
|
|
531
|
+
}
|
|
532
|
+
async function cancelResponseBody(response) {
|
|
533
|
+
var _a2$1;
|
|
534
|
+
try {
|
|
535
|
+
await ((_a2$1 = response.body) == null ? void 0 : _a2$1.cancel());
|
|
536
|
+
} catch (e) {}
|
|
537
|
+
}
|
|
538
|
+
var name = "AI_DownloadError";
|
|
539
|
+
var marker = `vercel.ai.error.${name}`;
|
|
540
|
+
var symbol = Symbol.for(marker);
|
|
541
|
+
var _a, _b;
|
|
542
|
+
var DownloadError = class extends (_b = AISDKError, _a = symbol, _b) {
|
|
543
|
+
constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
|
|
544
|
+
super({
|
|
545
|
+
name,
|
|
546
|
+
message,
|
|
547
|
+
cause
|
|
548
|
+
});
|
|
549
|
+
this[_a] = true;
|
|
550
|
+
this.url = url;
|
|
551
|
+
this.statusCode = statusCode;
|
|
552
|
+
this.statusText = statusText;
|
|
553
|
+
}
|
|
554
|
+
static isInstance(error) {
|
|
555
|
+
return AISDKError.hasMarker(error, marker);
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
function isBrowserRuntime(globalThisAny = globalThis) {
|
|
559
|
+
return globalThisAny.window != null;
|
|
560
|
+
}
|
|
561
|
+
function validateDownloadUrl(url) {
|
|
562
|
+
let parsed;
|
|
563
|
+
try {
|
|
564
|
+
parsed = new URL(url);
|
|
565
|
+
} catch (e) {
|
|
566
|
+
throw new DownloadError({
|
|
567
|
+
url,
|
|
568
|
+
message: `Invalid URL: ${url}`
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
if (parsed.protocol === "data:") return;
|
|
572
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new DownloadError({
|
|
573
|
+
url,
|
|
574
|
+
message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
|
|
575
|
+
});
|
|
576
|
+
const hostname = parsed.hostname.toLowerCase().replace(/\.+$/, "");
|
|
577
|
+
if (!hostname) throw new DownloadError({
|
|
578
|
+
url,
|
|
579
|
+
message: `URL must have a hostname`
|
|
580
|
+
});
|
|
581
|
+
if (hostname === "localhost" || hostname.endsWith(".local") || hostname.endsWith(".localhost")) throw new DownloadError({
|
|
582
|
+
url,
|
|
583
|
+
message: `URL with hostname ${hostname} is not allowed`
|
|
584
|
+
});
|
|
585
|
+
if (hostname.startsWith("[") && hostname.endsWith("]")) {
|
|
586
|
+
if (isPrivateIPv6(hostname.slice(1, -1))) throw new DownloadError({
|
|
587
|
+
url,
|
|
588
|
+
message: `URL with IPv6 address ${hostname} is not allowed`
|
|
589
|
+
});
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
if (isIPv4(hostname)) {
|
|
593
|
+
if (isPrivateIPv4(hostname)) throw new DownloadError({
|
|
594
|
+
url,
|
|
595
|
+
message: `URL with IP address ${hostname} is not allowed`
|
|
596
|
+
});
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function isIPv4(hostname) {
|
|
601
|
+
const parts = hostname.split(".");
|
|
602
|
+
if (parts.length !== 4) return false;
|
|
603
|
+
return parts.every((part) => {
|
|
604
|
+
const num = Number(part);
|
|
605
|
+
return Number.isInteger(num) && num >= 0 && num <= 255 && String(num) === part;
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
function isPrivateIPv4(ip) {
|
|
609
|
+
const [a, b, c] = ip.split(".").map(Number);
|
|
610
|
+
if (a === 0) return true;
|
|
611
|
+
if (a === 10) return true;
|
|
612
|
+
if (a === 100 && b >= 64 && b <= 127) return true;
|
|
613
|
+
if (a === 127) return true;
|
|
614
|
+
if (a === 169 && b === 254) return true;
|
|
615
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
616
|
+
if (a === 192 && b === 0 && c === 0) return true;
|
|
617
|
+
if (a === 192 && b === 168) return true;
|
|
618
|
+
if (a === 198 && (b === 18 || b === 19)) return true;
|
|
619
|
+
if (a >= 240) return true;
|
|
620
|
+
return false;
|
|
621
|
+
}
|
|
622
|
+
function parseIPv6(ip) {
|
|
623
|
+
let address = ip.toLowerCase();
|
|
624
|
+
const zoneIndex = address.indexOf("%");
|
|
625
|
+
if (zoneIndex !== -1) address = address.slice(0, zoneIndex);
|
|
626
|
+
const halves = address.split("::");
|
|
627
|
+
if (halves.length > 2) return null;
|
|
628
|
+
const toGroups = (segment) => {
|
|
629
|
+
if (segment === "") return [];
|
|
630
|
+
const groups = [];
|
|
631
|
+
const parts = segment.split(":");
|
|
632
|
+
for (let i = 0; i < parts.length; i++) {
|
|
633
|
+
const part = parts[i];
|
|
634
|
+
if (part.includes(".")) {
|
|
635
|
+
if (i !== parts.length - 1 || !isIPv4(part)) return null;
|
|
636
|
+
const [a, b, c, d] = part.split(".").map(Number);
|
|
637
|
+
groups.push(a << 8 | b, c << 8 | d);
|
|
638
|
+
continue;
|
|
639
|
+
}
|
|
640
|
+
if (!/^[0-9a-f]{1,4}$/.test(part)) return null;
|
|
641
|
+
groups.push(parseInt(part, 16));
|
|
642
|
+
}
|
|
643
|
+
return groups;
|
|
644
|
+
};
|
|
645
|
+
const head = toGroups(halves[0]);
|
|
646
|
+
if (head === null) return null;
|
|
647
|
+
if (halves.length === 2) {
|
|
648
|
+
const tail = toGroups(halves[1]);
|
|
649
|
+
if (tail === null) return null;
|
|
650
|
+
const fill = 8 - head.length - tail.length;
|
|
651
|
+
if (fill < 0) return null;
|
|
652
|
+
return [
|
|
653
|
+
...head,
|
|
654
|
+
...new Array(fill).fill(0),
|
|
655
|
+
...tail
|
|
656
|
+
];
|
|
657
|
+
}
|
|
658
|
+
return head.length === 8 ? head : null;
|
|
659
|
+
}
|
|
660
|
+
function isPrivateIPv6(ip) {
|
|
661
|
+
const groups = parseIPv6(ip);
|
|
662
|
+
if (groups === null) return true;
|
|
663
|
+
const topZero = (count) => groups.slice(0, count).every((group) => group === 0);
|
|
664
|
+
if (topZero(7) && (groups[7] === 0 || groups[7] === 1)) return true;
|
|
665
|
+
if ((groups[0] & 65024) === 64512) return true;
|
|
666
|
+
if ((groups[0] & 65472) === 65152) return true;
|
|
667
|
+
if ((groups[0] & 65472) === 65216) return true;
|
|
668
|
+
if ((groups[0] & 65280) === 65280) return true;
|
|
669
|
+
if (topZero(6) || topZero(5) && groups[5] === 65535 || topZero(4) && groups[4] === 65535 && groups[5] === 0 || groups[0] === 100 && groups[1] === 65435 && groups[2] === 0 && groups[3] === 0 && groups[4] === 0 && groups[5] === 0 || groups[0] === 100 && groups[1] === 65435 && groups[2] === 1) return isPrivateIPv4(`${groups[6] >> 8 & 255}.${groups[6] & 255}.${groups[7] >> 8 & 255}.${groups[7] & 255}`);
|
|
670
|
+
return false;
|
|
671
|
+
}
|
|
672
|
+
var MAX_DOWNLOAD_REDIRECTS = 10;
|
|
673
|
+
async function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedirects = MAX_DOWNLOAD_REDIRECTS }) {
|
|
674
|
+
const baseInit = { signal: abortSignal };
|
|
675
|
+
if (headers !== void 0) baseInit.headers = headers;
|
|
676
|
+
let currentUrl = url;
|
|
677
|
+
for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
|
|
678
|
+
validateDownloadUrl(currentUrl);
|
|
679
|
+
const response = await fetch(currentUrl, {
|
|
680
|
+
...baseInit,
|
|
681
|
+
redirect: "manual"
|
|
682
|
+
});
|
|
683
|
+
if (response.type === "opaqueredirect") {
|
|
684
|
+
if (!isBrowserRuntime()) throw new DownloadError({
|
|
685
|
+
url,
|
|
686
|
+
message: `Redirect from ${currentUrl} could not be validated and was blocked`
|
|
687
|
+
});
|
|
688
|
+
return await fetch(currentUrl, {
|
|
689
|
+
...baseInit,
|
|
690
|
+
redirect: "follow"
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
const location = response.headers.get("location");
|
|
694
|
+
if (response.status >= 300 && response.status < 400 && location) {
|
|
695
|
+
await cancelResponseBody(response);
|
|
696
|
+
currentUrl = new URL(location, currentUrl).toString();
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
return response;
|
|
700
|
+
}
|
|
701
|
+
throw new DownloadError({
|
|
702
|
+
url,
|
|
703
|
+
message: `Too many redirects (max ${maxRedirects})`
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
var DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
|
|
707
|
+
async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE }) {
|
|
708
|
+
const contentLength = response.headers.get("content-length");
|
|
709
|
+
if (contentLength != null) {
|
|
710
|
+
const length = parseInt(contentLength, 10);
|
|
711
|
+
if (!isNaN(length) && length > maxBytes) {
|
|
712
|
+
await cancelResponseBody(response);
|
|
713
|
+
throw new DownloadError({
|
|
714
|
+
url,
|
|
715
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
const body = response.body;
|
|
720
|
+
if (body == null) return new Uint8Array(0);
|
|
721
|
+
const reader = body.getReader();
|
|
722
|
+
const chunks = [];
|
|
723
|
+
let totalBytes = 0;
|
|
724
|
+
try {
|
|
725
|
+
while (true) {
|
|
726
|
+
const { done, value } = await reader.read();
|
|
727
|
+
if (done) break;
|
|
728
|
+
totalBytes += value.length;
|
|
729
|
+
if (totalBytes > maxBytes) throw new DownloadError({
|
|
730
|
+
url,
|
|
731
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
|
|
732
|
+
});
|
|
733
|
+
chunks.push(value);
|
|
734
|
+
}
|
|
735
|
+
} finally {
|
|
736
|
+
try {
|
|
737
|
+
await reader.cancel();
|
|
738
|
+
} finally {
|
|
739
|
+
reader.releaseLock();
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
const result = new Uint8Array(totalBytes);
|
|
743
|
+
let offset = 0;
|
|
744
|
+
for (const chunk of chunks) {
|
|
745
|
+
result.set(chunk, offset);
|
|
746
|
+
offset += chunk.length;
|
|
747
|
+
}
|
|
748
|
+
return result;
|
|
749
|
+
}
|
|
750
|
+
async function downloadBlob(url, options) {
|
|
751
|
+
var _a2$1, _b2$1;
|
|
752
|
+
try {
|
|
753
|
+
const response = await fetchWithValidatedRedirects({
|
|
754
|
+
url,
|
|
755
|
+
abortSignal: options == null ? void 0 : options.abortSignal
|
|
756
|
+
});
|
|
757
|
+
if (!response.ok) {
|
|
758
|
+
await cancelResponseBody(response);
|
|
759
|
+
throw new DownloadError({
|
|
760
|
+
url,
|
|
761
|
+
statusCode: response.status,
|
|
762
|
+
statusText: response.statusText
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
const data = await readResponseWithSizeLimit({
|
|
766
|
+
response,
|
|
767
|
+
url,
|
|
768
|
+
maxBytes: (_a2$1 = options == null ? void 0 : options.maxBytes) != null ? _a2$1 : DEFAULT_MAX_DOWNLOAD_SIZE
|
|
769
|
+
});
|
|
770
|
+
const contentType = (_b2$1 = response.headers.get("content-type")) != null ? _b2$1 : void 0;
|
|
771
|
+
return new Blob([data], contentType ? { type: contentType } : void 0);
|
|
772
|
+
} catch (error) {
|
|
773
|
+
if (DownloadError.isInstance(error)) throw error;
|
|
774
|
+
throw new DownloadError({
|
|
775
|
+
url,
|
|
776
|
+
cause: error
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
var createIdGenerator = ({ prefix, size = 16, alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", separator = "-" } = {}) => {
|
|
781
|
+
const generator = () => {
|
|
782
|
+
const alphabetLength = alphabet.length;
|
|
783
|
+
const chars = new Array(size);
|
|
784
|
+
for (let i = 0; i < size; i++) chars[i] = alphabet[Math.random() * alphabetLength | 0];
|
|
785
|
+
return chars.join("");
|
|
786
|
+
};
|
|
787
|
+
if (prefix == null) return generator;
|
|
788
|
+
if (alphabet.includes(separator)) throw new InvalidArgumentError({
|
|
789
|
+
argument: "separator",
|
|
790
|
+
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
791
|
+
});
|
|
792
|
+
return () => `${prefix}${separator}${generator()}`;
|
|
793
|
+
};
|
|
794
|
+
var generateId = createIdGenerator();
|
|
795
|
+
function isAbortError(error) {
|
|
796
|
+
return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || error.name === "TimeoutError");
|
|
797
|
+
}
|
|
798
|
+
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
799
|
+
var BUN_ERROR_CODES = [
|
|
800
|
+
"ConnectionRefused",
|
|
801
|
+
"ConnectionClosed",
|
|
802
|
+
"FailedToOpenSocket",
|
|
803
|
+
"ECONNRESET",
|
|
804
|
+
"ECONNREFUSED",
|
|
805
|
+
"ETIMEDOUT",
|
|
806
|
+
"EPIPE"
|
|
807
|
+
];
|
|
808
|
+
function isBunNetworkError(error) {
|
|
809
|
+
if (!(error instanceof Error)) return false;
|
|
810
|
+
const code = error.code;
|
|
811
|
+
if (typeof code === "string" && BUN_ERROR_CODES.includes(code)) return true;
|
|
812
|
+
return false;
|
|
813
|
+
}
|
|
814
|
+
function handleFetchError({ error, url, requestBodyValues }) {
|
|
815
|
+
if (isAbortError(error)) return error;
|
|
816
|
+
if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES.includes(error.message.toLowerCase())) {
|
|
817
|
+
const cause = error.cause;
|
|
818
|
+
if (cause != null) return new APICallError({
|
|
819
|
+
message: `Cannot connect to API: ${cause.message}`,
|
|
820
|
+
cause,
|
|
821
|
+
url,
|
|
822
|
+
requestBodyValues,
|
|
823
|
+
isRetryable: true
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
if (isBunNetworkError(error)) return new APICallError({
|
|
827
|
+
message: `Cannot connect to API: ${error.message}`,
|
|
828
|
+
cause: error,
|
|
829
|
+
url,
|
|
830
|
+
requestBodyValues,
|
|
831
|
+
isRetryable: true
|
|
832
|
+
});
|
|
833
|
+
return error;
|
|
834
|
+
}
|
|
835
|
+
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
836
|
+
var _a2$1, _b2$1, _c;
|
|
837
|
+
if (globalThisAny.window) return `runtime/browser`;
|
|
838
|
+
if ((_a2$1 = globalThisAny.navigator) == null ? void 0 : _a2$1.userAgent) return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
839
|
+
if ((_c = (_b2$1 = globalThisAny.process) == null ? void 0 : _b2$1.versions) == null ? void 0 : _c.node) return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
|
840
|
+
if (globalThisAny.EdgeRuntime) return `runtime/vercel-edge`;
|
|
841
|
+
return "runtime/unknown";
|
|
842
|
+
}
|
|
843
|
+
function normalizeHeaders(headers) {
|
|
844
|
+
if (headers == null) return {};
|
|
845
|
+
const normalized = {};
|
|
846
|
+
if (headers instanceof Headers) headers.forEach((value, key) => {
|
|
847
|
+
normalized[key.toLowerCase()] = value;
|
|
848
|
+
});
|
|
849
|
+
else {
|
|
850
|
+
if (!Array.isArray(headers)) headers = Object.entries(headers);
|
|
851
|
+
for (const [key, value] of headers) if (value != null) normalized[key.toLowerCase()] = value;
|
|
852
|
+
}
|
|
853
|
+
return normalized;
|
|
854
|
+
}
|
|
855
|
+
function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
856
|
+
const normalizedHeaders = new Headers(normalizeHeaders(headers));
|
|
857
|
+
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
|
858
|
+
normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
|
|
859
|
+
return Object.fromEntries(normalizedHeaders.entries());
|
|
860
|
+
}
|
|
861
|
+
var VERSION = "4.0.30";
|
|
862
|
+
function isNonNullable(value) {
|
|
863
|
+
return value != null;
|
|
864
|
+
}
|
|
865
|
+
function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName = "apiKey", description }) {
|
|
866
|
+
if (typeof apiKey === "string") return apiKey;
|
|
867
|
+
if (apiKey != null) throw new LoadAPIKeyError({ message: `${description} API key must be a string.` });
|
|
868
|
+
if (typeof process === "undefined") throw new LoadAPIKeyError({ message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables are not supported in this environment.` });
|
|
869
|
+
apiKey = process.env[environmentVariableName];
|
|
870
|
+
if (apiKey == null) throw new LoadAPIKeyError({ message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.` });
|
|
871
|
+
if (typeof apiKey !== "string") throw new LoadAPIKeyError({ message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.` });
|
|
872
|
+
return apiKey;
|
|
873
|
+
}
|
|
874
|
+
function loadOptionalSetting({ settingValue, environmentVariableName }) {
|
|
875
|
+
if (typeof settingValue === "string") return settingValue;
|
|
876
|
+
if (settingValue != null || typeof process === "undefined") return;
|
|
877
|
+
settingValue = process.env[environmentVariableName];
|
|
878
|
+
if (settingValue == null || typeof settingValue !== "string") return;
|
|
879
|
+
return settingValue;
|
|
880
|
+
}
|
|
881
|
+
function mediaTypeToExtension(mediaType) {
|
|
882
|
+
var _a2$1;
|
|
883
|
+
const [_type, subtype = ""] = mediaType.toLowerCase().split("/");
|
|
884
|
+
return (_a2$1 = {
|
|
885
|
+
mpeg: "mp3",
|
|
886
|
+
"x-wav": "wav",
|
|
887
|
+
opus: "ogg",
|
|
888
|
+
mp4: "m4a",
|
|
889
|
+
"x-m4a": "m4a"
|
|
890
|
+
}[subtype]) != null ? _a2$1 : subtype;
|
|
891
|
+
}
|
|
892
|
+
var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
893
|
+
var suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
894
|
+
function _parse(text) {
|
|
895
|
+
const obj = JSON.parse(text);
|
|
896
|
+
if (obj === null || typeof obj !== "object") return obj;
|
|
897
|
+
if (suspectProtoRx.test(text) === false && suspectConstructorRx.test(text) === false) return obj;
|
|
898
|
+
return filter(obj);
|
|
899
|
+
}
|
|
900
|
+
function filter(obj) {
|
|
901
|
+
let next = [obj];
|
|
902
|
+
while (next.length) {
|
|
903
|
+
const nodes = next;
|
|
904
|
+
next = [];
|
|
905
|
+
for (const node of nodes) {
|
|
906
|
+
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) throw new SyntaxError("Object contains forbidden prototype property");
|
|
907
|
+
if (Object.prototype.hasOwnProperty.call(node, "constructor") && node.constructor !== null && typeof node.constructor === "object" && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) throw new SyntaxError("Object contains forbidden prototype property");
|
|
908
|
+
for (const key in node) {
|
|
909
|
+
const value = node[key];
|
|
910
|
+
if (value && typeof value === "object") next.push(value);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
return obj;
|
|
915
|
+
}
|
|
916
|
+
function secureJsonParse(text) {
|
|
917
|
+
const { stackTraceLimit } = Error;
|
|
918
|
+
try {
|
|
919
|
+
Error.stackTraceLimit = 0;
|
|
920
|
+
} catch (e) {
|
|
921
|
+
return _parse(text);
|
|
922
|
+
}
|
|
923
|
+
try {
|
|
924
|
+
return _parse(text);
|
|
925
|
+
} finally {
|
|
926
|
+
Error.stackTraceLimit = stackTraceLimit;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
function addAdditionalPropertiesToJsonSchema(jsonSchema2) {
|
|
930
|
+
if (jsonSchema2.type === "object" || Array.isArray(jsonSchema2.type) && jsonSchema2.type.includes("object")) {
|
|
931
|
+
jsonSchema2.additionalProperties = false;
|
|
932
|
+
const { properties } = jsonSchema2;
|
|
933
|
+
if (properties != null) for (const key of Object.keys(properties)) properties[key] = visit(properties[key]);
|
|
934
|
+
}
|
|
935
|
+
if (jsonSchema2.items != null) jsonSchema2.items = Array.isArray(jsonSchema2.items) ? jsonSchema2.items.map(visit) : visit(jsonSchema2.items);
|
|
936
|
+
if (jsonSchema2.anyOf != null) jsonSchema2.anyOf = jsonSchema2.anyOf.map(visit);
|
|
937
|
+
if (jsonSchema2.allOf != null) jsonSchema2.allOf = jsonSchema2.allOf.map(visit);
|
|
938
|
+
if (jsonSchema2.oneOf != null) jsonSchema2.oneOf = jsonSchema2.oneOf.map(visit);
|
|
939
|
+
const { definitions } = jsonSchema2;
|
|
940
|
+
if (definitions != null) for (const key of Object.keys(definitions)) definitions[key] = visit(definitions[key]);
|
|
941
|
+
return jsonSchema2;
|
|
942
|
+
}
|
|
943
|
+
function visit(def) {
|
|
944
|
+
if (typeof def === "boolean") return def;
|
|
945
|
+
return addAdditionalPropertiesToJsonSchema(def);
|
|
946
|
+
}
|
|
947
|
+
var ignoreOverride = /* @__PURE__ */ Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
948
|
+
var defaultOptions = {
|
|
949
|
+
name: void 0,
|
|
950
|
+
$refStrategy: "root",
|
|
951
|
+
basePath: ["#"],
|
|
952
|
+
effectStrategy: "input",
|
|
953
|
+
pipeStrategy: "all",
|
|
954
|
+
dateStrategy: "format:date-time",
|
|
955
|
+
mapStrategy: "entries",
|
|
956
|
+
removeAdditionalStrategy: "passthrough",
|
|
957
|
+
allowedAdditionalProperties: true,
|
|
958
|
+
rejectedAdditionalProperties: false,
|
|
959
|
+
definitionPath: "definitions",
|
|
960
|
+
strictUnions: false,
|
|
961
|
+
definitions: {},
|
|
962
|
+
errorMessages: false,
|
|
963
|
+
patternStrategy: "escape",
|
|
964
|
+
applyRegexFlags: false,
|
|
965
|
+
emailStrategy: "format:email",
|
|
966
|
+
base64Strategy: "contentEncoding:base64",
|
|
967
|
+
nameStrategy: "ref"
|
|
968
|
+
};
|
|
969
|
+
var getDefaultOptions = (options) => typeof options === "string" ? {
|
|
970
|
+
...defaultOptions,
|
|
971
|
+
name: options
|
|
972
|
+
} : {
|
|
973
|
+
...defaultOptions,
|
|
974
|
+
...options
|
|
975
|
+
};
|
|
976
|
+
function parseAnyDef() {
|
|
977
|
+
return {};
|
|
978
|
+
}
|
|
979
|
+
function parseArrayDef(def, refs) {
|
|
980
|
+
var _a2$1, _b2$1, _c;
|
|
981
|
+
const res = { type: "array" };
|
|
982
|
+
if (((_a2$1 = def.type) == null ? void 0 : _a2$1._def) && ((_c = (_b2$1 = def.type) == null ? void 0 : _b2$1._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny) res.items = parseDef(def.type._def, {
|
|
983
|
+
...refs,
|
|
984
|
+
currentPath: [...refs.currentPath, "items"]
|
|
985
|
+
});
|
|
986
|
+
if (def.minLength) res.minItems = def.minLength.value;
|
|
987
|
+
if (def.maxLength) res.maxItems = def.maxLength.value;
|
|
988
|
+
if (def.exactLength) {
|
|
989
|
+
res.minItems = def.exactLength.value;
|
|
990
|
+
res.maxItems = def.exactLength.value;
|
|
991
|
+
}
|
|
992
|
+
return res;
|
|
993
|
+
}
|
|
994
|
+
function parseBigintDef(def) {
|
|
995
|
+
const res = {
|
|
996
|
+
type: "integer",
|
|
997
|
+
format: "int64"
|
|
998
|
+
};
|
|
999
|
+
if (!def.checks) return res;
|
|
1000
|
+
for (const check of def.checks) switch (check.kind) {
|
|
1001
|
+
case "min":
|
|
1002
|
+
if (check.inclusive) res.minimum = check.value;
|
|
1003
|
+
else res.exclusiveMinimum = check.value;
|
|
1004
|
+
break;
|
|
1005
|
+
case "max":
|
|
1006
|
+
if (check.inclusive) res.maximum = check.value;
|
|
1007
|
+
else res.exclusiveMaximum = check.value;
|
|
1008
|
+
break;
|
|
1009
|
+
case "multipleOf":
|
|
1010
|
+
res.multipleOf = check.value;
|
|
1011
|
+
break;
|
|
1012
|
+
}
|
|
1013
|
+
return res;
|
|
1014
|
+
}
|
|
1015
|
+
function parseBooleanDef() {
|
|
1016
|
+
return { type: "boolean" };
|
|
1017
|
+
}
|
|
1018
|
+
function parseBrandedDef(_def, refs) {
|
|
1019
|
+
return parseDef(_def.type._def, refs);
|
|
1020
|
+
}
|
|
1021
|
+
var parseCatchDef = (def, refs) => {
|
|
1022
|
+
return parseDef(def.innerType._def, refs);
|
|
1023
|
+
};
|
|
1024
|
+
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
1025
|
+
const strategy = overrideDateStrategy != null ? overrideDateStrategy : refs.dateStrategy;
|
|
1026
|
+
if (Array.isArray(strategy)) return { anyOf: strategy.map((item, i) => parseDateDef(def, refs, item)) };
|
|
1027
|
+
switch (strategy) {
|
|
1028
|
+
case "string":
|
|
1029
|
+
case "format:date-time": return {
|
|
1030
|
+
type: "string",
|
|
1031
|
+
format: "date-time"
|
|
1032
|
+
};
|
|
1033
|
+
case "format:date": return {
|
|
1034
|
+
type: "string",
|
|
1035
|
+
format: "date"
|
|
1036
|
+
};
|
|
1037
|
+
case "integer": return integerDateParser(def);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
var integerDateParser = (def) => {
|
|
1041
|
+
const res = {
|
|
1042
|
+
type: "integer",
|
|
1043
|
+
format: "unix-time"
|
|
1044
|
+
};
|
|
1045
|
+
for (const check of def.checks) switch (check.kind) {
|
|
1046
|
+
case "min":
|
|
1047
|
+
res.minimum = check.value;
|
|
1048
|
+
break;
|
|
1049
|
+
case "max":
|
|
1050
|
+
res.maximum = check.value;
|
|
1051
|
+
break;
|
|
1052
|
+
}
|
|
1053
|
+
return res;
|
|
1054
|
+
};
|
|
1055
|
+
function parseDefaultDef(_def, refs) {
|
|
1056
|
+
return {
|
|
1057
|
+
...parseDef(_def.innerType._def, refs),
|
|
1058
|
+
default: _def.defaultValue()
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
function parseEffectsDef(_def, refs) {
|
|
1062
|
+
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : parseAnyDef();
|
|
1063
|
+
}
|
|
1064
|
+
function parseEnumDef(def) {
|
|
1065
|
+
return {
|
|
1066
|
+
type: "string",
|
|
1067
|
+
enum: Array.from(def.values)
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
var isJsonSchema7AllOfType = (type) => {
|
|
1071
|
+
if ("type" in type && type.type === "string") return false;
|
|
1072
|
+
return "allOf" in type;
|
|
1073
|
+
};
|
|
1074
|
+
function parseIntersectionDef(def, refs) {
|
|
1075
|
+
const allOf = [parseDef(def.left._def, {
|
|
1076
|
+
...refs,
|
|
1077
|
+
currentPath: [
|
|
1078
|
+
...refs.currentPath,
|
|
1079
|
+
"allOf",
|
|
1080
|
+
"0"
|
|
1081
|
+
]
|
|
1082
|
+
}), parseDef(def.right._def, {
|
|
1083
|
+
...refs,
|
|
1084
|
+
currentPath: [
|
|
1085
|
+
...refs.currentPath,
|
|
1086
|
+
"allOf",
|
|
1087
|
+
"1"
|
|
1088
|
+
]
|
|
1089
|
+
})].filter((x) => !!x);
|
|
1090
|
+
const mergedAllOf = [];
|
|
1091
|
+
allOf.forEach((schema) => {
|
|
1092
|
+
if (isJsonSchema7AllOfType(schema)) mergedAllOf.push(...schema.allOf);
|
|
1093
|
+
else {
|
|
1094
|
+
let nestedSchema = schema;
|
|
1095
|
+
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
1096
|
+
const { additionalProperties,...rest } = schema;
|
|
1097
|
+
nestedSchema = rest;
|
|
1098
|
+
}
|
|
1099
|
+
mergedAllOf.push(nestedSchema);
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
return mergedAllOf.length ? { allOf: mergedAllOf } : void 0;
|
|
1103
|
+
}
|
|
1104
|
+
function parseLiteralDef(def) {
|
|
1105
|
+
const parsedType = typeof def.value;
|
|
1106
|
+
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") return { type: Array.isArray(def.value) ? "array" : "object" };
|
|
1107
|
+
return {
|
|
1108
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
1109
|
+
const: def.value
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
var emojiRegex = void 0;
|
|
1113
|
+
var zodPatterns = {
|
|
1114
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
1115
|
+
cuid2: /^[0-9a-z]+$/,
|
|
1116
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
1117
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
1118
|
+
emoji: () => {
|
|
1119
|
+
if (emojiRegex === void 0) emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
1120
|
+
return emojiRegex;
|
|
1121
|
+
},
|
|
1122
|
+
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}$/,
|
|
1123
|
+
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])$/,
|
|
1124
|
+
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])$/,
|
|
1125
|
+
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})))$/,
|
|
1126
|
+
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])$/,
|
|
1127
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
1128
|
+
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
1129
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
1130
|
+
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
1131
|
+
};
|
|
1132
|
+
function parseStringDef(def, refs) {
|
|
1133
|
+
const res = { type: "string" };
|
|
1134
|
+
if (def.checks) for (const check of def.checks) switch (check.kind) {
|
|
1135
|
+
case "min":
|
|
1136
|
+
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
|
|
1137
|
+
break;
|
|
1138
|
+
case "max":
|
|
1139
|
+
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
|
|
1140
|
+
break;
|
|
1141
|
+
case "email":
|
|
1142
|
+
switch (refs.emailStrategy) {
|
|
1143
|
+
case "format:email":
|
|
1144
|
+
addFormat(res, "email", check.message, refs);
|
|
1145
|
+
break;
|
|
1146
|
+
case "format:idn-email":
|
|
1147
|
+
addFormat(res, "idn-email", check.message, refs);
|
|
1148
|
+
break;
|
|
1149
|
+
case "pattern:zod":
|
|
1150
|
+
addPattern(res, zodPatterns.email, check.message, refs);
|
|
1151
|
+
break;
|
|
1152
|
+
}
|
|
1153
|
+
break;
|
|
1154
|
+
case "url":
|
|
1155
|
+
addFormat(res, "uri", check.message, refs);
|
|
1156
|
+
break;
|
|
1157
|
+
case "uuid":
|
|
1158
|
+
addFormat(res, "uuid", check.message, refs);
|
|
1159
|
+
break;
|
|
1160
|
+
case "regex":
|
|
1161
|
+
addPattern(res, check.regex, check.message, refs);
|
|
1162
|
+
break;
|
|
1163
|
+
case "cuid":
|
|
1164
|
+
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
1165
|
+
break;
|
|
1166
|
+
case "cuid2":
|
|
1167
|
+
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
1168
|
+
break;
|
|
1169
|
+
case "startsWith":
|
|
1170
|
+
addPattern(res, RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`), check.message, refs);
|
|
1171
|
+
break;
|
|
1172
|
+
case "endsWith":
|
|
1173
|
+
addPattern(res, RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`), check.message, refs);
|
|
1174
|
+
break;
|
|
1175
|
+
case "datetime":
|
|
1176
|
+
addFormat(res, "date-time", check.message, refs);
|
|
1177
|
+
break;
|
|
1178
|
+
case "date":
|
|
1179
|
+
addFormat(res, "date", check.message, refs);
|
|
1180
|
+
break;
|
|
1181
|
+
case "time":
|
|
1182
|
+
addFormat(res, "time", check.message, refs);
|
|
1183
|
+
break;
|
|
1184
|
+
case "duration":
|
|
1185
|
+
addFormat(res, "duration", check.message, refs);
|
|
1186
|
+
break;
|
|
1187
|
+
case "length":
|
|
1188
|
+
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
|
|
1189
|
+
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
|
|
1190
|
+
break;
|
|
1191
|
+
case "includes":
|
|
1192
|
+
addPattern(res, RegExp(escapeLiteralCheckValue(check.value, refs)), check.message, refs);
|
|
1193
|
+
break;
|
|
1194
|
+
case "ip":
|
|
1195
|
+
if (check.version !== "v6") addFormat(res, "ipv4", check.message, refs);
|
|
1196
|
+
if (check.version !== "v4") addFormat(res, "ipv6", check.message, refs);
|
|
1197
|
+
break;
|
|
1198
|
+
case "base64url":
|
|
1199
|
+
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
1200
|
+
break;
|
|
1201
|
+
case "jwt":
|
|
1202
|
+
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
1203
|
+
break;
|
|
1204
|
+
case "cidr":
|
|
1205
|
+
if (check.version !== "v6") addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
1206
|
+
if (check.version !== "v4") addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
1207
|
+
break;
|
|
1208
|
+
case "emoji":
|
|
1209
|
+
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
1210
|
+
break;
|
|
1211
|
+
case "ulid":
|
|
1212
|
+
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
1213
|
+
break;
|
|
1214
|
+
case "base64":
|
|
1215
|
+
switch (refs.base64Strategy) {
|
|
1216
|
+
case "format:binary":
|
|
1217
|
+
addFormat(res, "binary", check.message, refs);
|
|
1218
|
+
break;
|
|
1219
|
+
case "contentEncoding:base64":
|
|
1220
|
+
res.contentEncoding = "base64";
|
|
1221
|
+
break;
|
|
1222
|
+
case "pattern:zod":
|
|
1223
|
+
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
1224
|
+
break;
|
|
1225
|
+
}
|
|
1226
|
+
break;
|
|
1227
|
+
case "nanoid": addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
1228
|
+
case "toLowerCase":
|
|
1229
|
+
case "toUpperCase":
|
|
1230
|
+
case "trim": break;
|
|
1231
|
+
default:
|
|
1232
|
+
}
|
|
1233
|
+
return res;
|
|
1234
|
+
}
|
|
1235
|
+
function escapeLiteralCheckValue(literal, refs) {
|
|
1236
|
+
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
1237
|
+
}
|
|
1238
|
+
var ALPHA_NUMERIC = /* @__PURE__ */ new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
1239
|
+
function escapeNonAlphaNumeric(source) {
|
|
1240
|
+
let result = "";
|
|
1241
|
+
for (let i = 0; i < source.length; i++) {
|
|
1242
|
+
if (!ALPHA_NUMERIC.has(source[i])) result += "\\";
|
|
1243
|
+
result += source[i];
|
|
1244
|
+
}
|
|
1245
|
+
return result;
|
|
1246
|
+
}
|
|
1247
|
+
function addFormat(schema, value, message, refs) {
|
|
1248
|
+
var _a2$1;
|
|
1249
|
+
if (schema.format || ((_a2$1 = schema.anyOf) == null ? void 0 : _a2$1.some((x) => x.format))) {
|
|
1250
|
+
if (!schema.anyOf) schema.anyOf = [];
|
|
1251
|
+
if (schema.format) {
|
|
1252
|
+
schema.anyOf.push({ format: schema.format });
|
|
1253
|
+
delete schema.format;
|
|
1254
|
+
}
|
|
1255
|
+
schema.anyOf.push({
|
|
1256
|
+
format: value,
|
|
1257
|
+
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
1258
|
+
});
|
|
1259
|
+
} else schema.format = value;
|
|
1260
|
+
}
|
|
1261
|
+
function addPattern(schema, regex, message, refs) {
|
|
1262
|
+
var _a2$1;
|
|
1263
|
+
if (schema.pattern || ((_a2$1 = schema.allOf) == null ? void 0 : _a2$1.some((x) => x.pattern))) {
|
|
1264
|
+
if (!schema.allOf) schema.allOf = [];
|
|
1265
|
+
if (schema.pattern) {
|
|
1266
|
+
schema.allOf.push({ pattern: schema.pattern });
|
|
1267
|
+
delete schema.pattern;
|
|
1268
|
+
}
|
|
1269
|
+
schema.allOf.push({
|
|
1270
|
+
pattern: stringifyRegExpWithFlags(regex, refs),
|
|
1271
|
+
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
1272
|
+
});
|
|
1273
|
+
} else schema.pattern = stringifyRegExpWithFlags(regex, refs);
|
|
1274
|
+
}
|
|
1275
|
+
function stringifyRegExpWithFlags(regex, refs) {
|
|
1276
|
+
var _a2$1;
|
|
1277
|
+
if (!refs.applyRegexFlags || !regex.flags) return regex.source;
|
|
1278
|
+
const flags = {
|
|
1279
|
+
i: regex.flags.includes("i"),
|
|
1280
|
+
m: regex.flags.includes("m"),
|
|
1281
|
+
s: regex.flags.includes("s")
|
|
1282
|
+
};
|
|
1283
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
1284
|
+
let pattern = "";
|
|
1285
|
+
let isEscaped = false;
|
|
1286
|
+
let inCharGroup = false;
|
|
1287
|
+
let inCharRange = false;
|
|
1288
|
+
for (let i = 0; i < source.length; i++) {
|
|
1289
|
+
if (isEscaped) {
|
|
1290
|
+
pattern += source[i];
|
|
1291
|
+
isEscaped = false;
|
|
1292
|
+
continue;
|
|
1293
|
+
}
|
|
1294
|
+
if (flags.i) {
|
|
1295
|
+
if (inCharGroup) {
|
|
1296
|
+
if (source[i].match(/[a-z]/)) {
|
|
1297
|
+
if (inCharRange) {
|
|
1298
|
+
pattern += source[i];
|
|
1299
|
+
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
1300
|
+
inCharRange = false;
|
|
1301
|
+
} else if (source[i + 1] === "-" && ((_a2$1 = source[i + 2]) == null ? void 0 : _a2$1.match(/[a-z]/))) {
|
|
1302
|
+
pattern += source[i];
|
|
1303
|
+
inCharRange = true;
|
|
1304
|
+
} else pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
1305
|
+
continue;
|
|
1306
|
+
}
|
|
1307
|
+
} else if (source[i].match(/[a-z]/)) {
|
|
1308
|
+
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
1309
|
+
continue;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
if (flags.m) {
|
|
1313
|
+
if (source[i] === "^") {
|
|
1314
|
+
pattern += `(^|(?<=[\r
|
|
1315
|
+
]))`;
|
|
1316
|
+
continue;
|
|
1317
|
+
} else if (source[i] === "$") {
|
|
1318
|
+
pattern += `($|(?=[\r
|
|
1319
|
+
]))`;
|
|
1320
|
+
continue;
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
if (flags.s && source[i] === ".") {
|
|
1324
|
+
pattern += inCharGroup ? `${source[i]}\r
|
|
1325
|
+
` : `[${source[i]}\r
|
|
1326
|
+
]`;
|
|
1327
|
+
continue;
|
|
1328
|
+
}
|
|
1329
|
+
pattern += source[i];
|
|
1330
|
+
if (source[i] === "\\") isEscaped = true;
|
|
1331
|
+
else if (inCharGroup && source[i] === "]") inCharGroup = false;
|
|
1332
|
+
else if (!inCharGroup && source[i] === "[") inCharGroup = true;
|
|
1333
|
+
}
|
|
1334
|
+
try {
|
|
1335
|
+
new RegExp(pattern);
|
|
1336
|
+
} catch (e) {
|
|
1337
|
+
console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
|
|
1338
|
+
return regex.source;
|
|
1339
|
+
}
|
|
1340
|
+
return pattern;
|
|
1341
|
+
}
|
|
1342
|
+
function parseRecordDef(def, refs) {
|
|
1343
|
+
var _a2$1, _b2$1, _c, _d, _e, _f;
|
|
1344
|
+
const schema = {
|
|
1345
|
+
type: "object",
|
|
1346
|
+
additionalProperties: (_a2$1 = parseDef(def.valueType._def, {
|
|
1347
|
+
...refs,
|
|
1348
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1349
|
+
})) != null ? _a2$1 : refs.allowedAdditionalProperties
|
|
1350
|
+
};
|
|
1351
|
+
if (((_b2$1 = def.keyType) == null ? void 0 : _b2$1._def.typeName) === ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
1352
|
+
const { type,...keyType } = parseStringDef(def.keyType._def, refs);
|
|
1353
|
+
return {
|
|
1354
|
+
...schema,
|
|
1355
|
+
propertyNames: keyType
|
|
1356
|
+
};
|
|
1357
|
+
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) === ZodFirstPartyTypeKind.ZodEnum) return {
|
|
1358
|
+
...schema,
|
|
1359
|
+
propertyNames: { enum: def.keyType._def.values }
|
|
1360
|
+
};
|
|
1361
|
+
else if (((_e = def.keyType) == null ? void 0 : _e._def.typeName) === ZodFirstPartyTypeKind.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind.ZodString && ((_f = def.keyType._def.type._def.checks) == null ? void 0 : _f.length)) {
|
|
1362
|
+
const { type,...keyType } = parseBrandedDef(def.keyType._def, refs);
|
|
1363
|
+
return {
|
|
1364
|
+
...schema,
|
|
1365
|
+
propertyNames: keyType
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
return schema;
|
|
1369
|
+
}
|
|
1370
|
+
function parseMapDef(def, refs) {
|
|
1371
|
+
if (refs.mapStrategy === "record") return parseRecordDef(def, refs);
|
|
1372
|
+
return {
|
|
1373
|
+
type: "array",
|
|
1374
|
+
maxItems: 125,
|
|
1375
|
+
items: {
|
|
1376
|
+
type: "array",
|
|
1377
|
+
items: [parseDef(def.keyType._def, {
|
|
1378
|
+
...refs,
|
|
1379
|
+
currentPath: [
|
|
1380
|
+
...refs.currentPath,
|
|
1381
|
+
"items",
|
|
1382
|
+
"items",
|
|
1383
|
+
"0"
|
|
1384
|
+
]
|
|
1385
|
+
}) || parseAnyDef(), parseDef(def.valueType._def, {
|
|
1386
|
+
...refs,
|
|
1387
|
+
currentPath: [
|
|
1388
|
+
...refs.currentPath,
|
|
1389
|
+
"items",
|
|
1390
|
+
"items",
|
|
1391
|
+
"1"
|
|
1392
|
+
]
|
|
1393
|
+
}) || parseAnyDef()],
|
|
1394
|
+
minItems: 2,
|
|
1395
|
+
maxItems: 2
|
|
1396
|
+
}
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
function parseNativeEnumDef(def) {
|
|
1400
|
+
const object = def.values;
|
|
1401
|
+
const actualValues = Object.keys(def.values).filter((key) => {
|
|
1402
|
+
return typeof object[object[key]] !== "number";
|
|
1403
|
+
}).map((key) => object[key]);
|
|
1404
|
+
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
1405
|
+
return {
|
|
1406
|
+
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
1407
|
+
enum: actualValues
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
function parseNeverDef() {
|
|
1411
|
+
return { not: parseAnyDef() };
|
|
1412
|
+
}
|
|
1413
|
+
function parseNullDef() {
|
|
1414
|
+
return { type: "null" };
|
|
1415
|
+
}
|
|
1416
|
+
var primitiveMappings = {
|
|
1417
|
+
ZodString: "string",
|
|
1418
|
+
ZodNumber: "number",
|
|
1419
|
+
ZodBigInt: "integer",
|
|
1420
|
+
ZodBoolean: "boolean",
|
|
1421
|
+
ZodNull: "null"
|
|
1422
|
+
};
|
|
1423
|
+
function parseUnionDef(def, refs) {
|
|
1424
|
+
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
1425
|
+
if (options.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))) {
|
|
1426
|
+
const types = options.reduce((types2, x) => {
|
|
1427
|
+
const type = primitiveMappings[x._def.typeName];
|
|
1428
|
+
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
1429
|
+
}, []);
|
|
1430
|
+
return { type: types.length > 1 ? types : types[0] };
|
|
1431
|
+
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
1432
|
+
const types = options.reduce((acc, x) => {
|
|
1433
|
+
const type = typeof x._def.value;
|
|
1434
|
+
switch (type) {
|
|
1435
|
+
case "string":
|
|
1436
|
+
case "number":
|
|
1437
|
+
case "boolean": return [...acc, type];
|
|
1438
|
+
case "bigint": return [...acc, "integer"];
|
|
1439
|
+
case "object": if (x._def.value === null) return [...acc, "null"];
|
|
1440
|
+
case "symbol":
|
|
1441
|
+
case "undefined":
|
|
1442
|
+
case "function":
|
|
1443
|
+
default: return acc;
|
|
1444
|
+
}
|
|
1445
|
+
}, []);
|
|
1446
|
+
if (types.length === options.length) {
|
|
1447
|
+
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
1448
|
+
return {
|
|
1449
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
1450
|
+
enum: options.reduce((acc, x) => {
|
|
1451
|
+
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
1452
|
+
}, [])
|
|
1453
|
+
};
|
|
1454
|
+
}
|
|
1455
|
+
} else if (options.every((x) => x._def.typeName === "ZodEnum")) return {
|
|
1456
|
+
type: "string",
|
|
1457
|
+
enum: options.reduce((acc, x) => [...acc, ...x._def.values.filter((x2) => !acc.includes(x2))], [])
|
|
1458
|
+
};
|
|
1459
|
+
return asAnyOf(def, refs);
|
|
1460
|
+
}
|
|
1461
|
+
var asAnyOf = (def, refs) => {
|
|
1462
|
+
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
|
|
1463
|
+
...refs,
|
|
1464
|
+
currentPath: [
|
|
1465
|
+
...refs.currentPath,
|
|
1466
|
+
"anyOf",
|
|
1467
|
+
`${i}`
|
|
1468
|
+
]
|
|
1469
|
+
})).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
|
|
1470
|
+
return anyOf.length ? { anyOf } : void 0;
|
|
1471
|
+
};
|
|
1472
|
+
function parseNullableDef(def, refs) {
|
|
1473
|
+
if ([
|
|
1474
|
+
"ZodString",
|
|
1475
|
+
"ZodNumber",
|
|
1476
|
+
"ZodBigInt",
|
|
1477
|
+
"ZodBoolean",
|
|
1478
|
+
"ZodNull"
|
|
1479
|
+
].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) return { type: [primitiveMappings[def.innerType._def.typeName], "null"] };
|
|
1480
|
+
const base = parseDef(def.innerType._def, {
|
|
1481
|
+
...refs,
|
|
1482
|
+
currentPath: [
|
|
1483
|
+
...refs.currentPath,
|
|
1484
|
+
"anyOf",
|
|
1485
|
+
"0"
|
|
1486
|
+
]
|
|
1487
|
+
});
|
|
1488
|
+
return base && { anyOf: [base, { type: "null" }] };
|
|
1489
|
+
}
|
|
1490
|
+
function parseNumberDef(def) {
|
|
1491
|
+
const res = { type: "number" };
|
|
1492
|
+
if (!def.checks) return res;
|
|
1493
|
+
for (const check of def.checks) switch (check.kind) {
|
|
1494
|
+
case "int":
|
|
1495
|
+
res.type = "integer";
|
|
1496
|
+
break;
|
|
1497
|
+
case "min":
|
|
1498
|
+
if (check.inclusive) res.minimum = check.value;
|
|
1499
|
+
else res.exclusiveMinimum = check.value;
|
|
1500
|
+
break;
|
|
1501
|
+
case "max":
|
|
1502
|
+
if (check.inclusive) res.maximum = check.value;
|
|
1503
|
+
else res.exclusiveMaximum = check.value;
|
|
1504
|
+
break;
|
|
1505
|
+
case "multipleOf":
|
|
1506
|
+
res.multipleOf = check.value;
|
|
1507
|
+
break;
|
|
1508
|
+
}
|
|
1509
|
+
return res;
|
|
1510
|
+
}
|
|
1511
|
+
function parseObjectDef(def, refs) {
|
|
1512
|
+
const result = {
|
|
1513
|
+
type: "object",
|
|
1514
|
+
properties: {}
|
|
1515
|
+
};
|
|
1516
|
+
const required = [];
|
|
1517
|
+
const shape = def.shape();
|
|
1518
|
+
for (const propName in shape) {
|
|
1519
|
+
let propDef = shape[propName];
|
|
1520
|
+
if (propDef === void 0 || propDef._def === void 0) continue;
|
|
1521
|
+
const propOptional = safeIsOptional(propDef);
|
|
1522
|
+
const parsedDef = parseDef(propDef._def, {
|
|
1523
|
+
...refs,
|
|
1524
|
+
currentPath: [
|
|
1525
|
+
...refs.currentPath,
|
|
1526
|
+
"properties",
|
|
1527
|
+
propName
|
|
1528
|
+
],
|
|
1529
|
+
propertyPath: [
|
|
1530
|
+
...refs.currentPath,
|
|
1531
|
+
"properties",
|
|
1532
|
+
propName
|
|
1533
|
+
]
|
|
1534
|
+
});
|
|
1535
|
+
if (parsedDef === void 0) continue;
|
|
1536
|
+
result.properties[propName] = parsedDef;
|
|
1537
|
+
if (!propOptional) required.push(propName);
|
|
1538
|
+
}
|
|
1539
|
+
if (required.length) result.required = required;
|
|
1540
|
+
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
1541
|
+
if (additionalProperties !== void 0) result.additionalProperties = additionalProperties;
|
|
1542
|
+
return result;
|
|
1543
|
+
}
|
|
1544
|
+
function decideAdditionalProperties(def, refs) {
|
|
1545
|
+
if (def.catchall._def.typeName !== "ZodNever") return parseDef(def.catchall._def, {
|
|
1546
|
+
...refs,
|
|
1547
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1548
|
+
});
|
|
1549
|
+
switch (def.unknownKeys) {
|
|
1550
|
+
case "passthrough": return refs.allowedAdditionalProperties;
|
|
1551
|
+
case "strict": return refs.rejectedAdditionalProperties;
|
|
1552
|
+
case "strip": return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
function safeIsOptional(schema) {
|
|
1556
|
+
try {
|
|
1557
|
+
return schema.isOptional();
|
|
1558
|
+
} catch (e) {
|
|
1559
|
+
return true;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
var parseOptionalDef = (def, refs) => {
|
|
1563
|
+
var _a2$1;
|
|
1564
|
+
if (refs.currentPath.toString() === ((_a2$1 = refs.propertyPath) == null ? void 0 : _a2$1.toString())) return parseDef(def.innerType._def, refs);
|
|
1565
|
+
const innerSchema = parseDef(def.innerType._def, {
|
|
1566
|
+
...refs,
|
|
1567
|
+
currentPath: [
|
|
1568
|
+
...refs.currentPath,
|
|
1569
|
+
"anyOf",
|
|
1570
|
+
"1"
|
|
1571
|
+
]
|
|
1572
|
+
});
|
|
1573
|
+
return innerSchema ? { anyOf: [{ not: parseAnyDef() }, innerSchema] } : parseAnyDef();
|
|
1574
|
+
};
|
|
1575
|
+
var parsePipelineDef = (def, refs) => {
|
|
1576
|
+
if (refs.pipeStrategy === "input") return parseDef(def.in._def, refs);
|
|
1577
|
+
else if (refs.pipeStrategy === "output") return parseDef(def.out._def, refs);
|
|
1578
|
+
const a = parseDef(def.in._def, {
|
|
1579
|
+
...refs,
|
|
1580
|
+
currentPath: [
|
|
1581
|
+
...refs.currentPath,
|
|
1582
|
+
"allOf",
|
|
1583
|
+
"0"
|
|
1584
|
+
]
|
|
1585
|
+
});
|
|
1586
|
+
return { allOf: [a, parseDef(def.out._def, {
|
|
1587
|
+
...refs,
|
|
1588
|
+
currentPath: [
|
|
1589
|
+
...refs.currentPath,
|
|
1590
|
+
"allOf",
|
|
1591
|
+
a ? "1" : "0"
|
|
1592
|
+
]
|
|
1593
|
+
})].filter((x) => x !== void 0) };
|
|
1594
|
+
};
|
|
1595
|
+
function parsePromiseDef(def, refs) {
|
|
1596
|
+
return parseDef(def.type._def, refs);
|
|
1597
|
+
}
|
|
1598
|
+
function parseSetDef(def, refs) {
|
|
1599
|
+
const schema = {
|
|
1600
|
+
type: "array",
|
|
1601
|
+
uniqueItems: true,
|
|
1602
|
+
items: parseDef(def.valueType._def, {
|
|
1603
|
+
...refs,
|
|
1604
|
+
currentPath: [...refs.currentPath, "items"]
|
|
1605
|
+
})
|
|
1606
|
+
};
|
|
1607
|
+
if (def.minSize) schema.minItems = def.minSize.value;
|
|
1608
|
+
if (def.maxSize) schema.maxItems = def.maxSize.value;
|
|
1609
|
+
return schema;
|
|
1610
|
+
}
|
|
1611
|
+
function parseTupleDef(def, refs) {
|
|
1612
|
+
if (def.rest) return {
|
|
1613
|
+
type: "array",
|
|
1614
|
+
minItems: def.items.length,
|
|
1615
|
+
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1616
|
+
...refs,
|
|
1617
|
+
currentPath: [
|
|
1618
|
+
...refs.currentPath,
|
|
1619
|
+
"items",
|
|
1620
|
+
`${i}`
|
|
1621
|
+
]
|
|
1622
|
+
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], []),
|
|
1623
|
+
additionalItems: parseDef(def.rest._def, {
|
|
1624
|
+
...refs,
|
|
1625
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
1626
|
+
})
|
|
1627
|
+
};
|
|
1628
|
+
else return {
|
|
1629
|
+
type: "array",
|
|
1630
|
+
minItems: def.items.length,
|
|
1631
|
+
maxItems: def.items.length,
|
|
1632
|
+
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1633
|
+
...refs,
|
|
1634
|
+
currentPath: [
|
|
1635
|
+
...refs.currentPath,
|
|
1636
|
+
"items",
|
|
1637
|
+
`${i}`
|
|
1638
|
+
]
|
|
1639
|
+
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], [])
|
|
1640
|
+
};
|
|
1641
|
+
}
|
|
1642
|
+
function parseUndefinedDef() {
|
|
1643
|
+
return { not: parseAnyDef() };
|
|
1644
|
+
}
|
|
1645
|
+
function parseUnknownDef() {
|
|
1646
|
+
return parseAnyDef();
|
|
1647
|
+
}
|
|
1648
|
+
var parseReadonlyDef = (def, refs) => {
|
|
1649
|
+
return parseDef(def.innerType._def, refs);
|
|
1650
|
+
};
|
|
1651
|
+
var selectParser = (def, typeName, refs) => {
|
|
1652
|
+
switch (typeName) {
|
|
1653
|
+
case ZodFirstPartyTypeKind.ZodString: return parseStringDef(def, refs);
|
|
1654
|
+
case ZodFirstPartyTypeKind.ZodNumber: return parseNumberDef(def);
|
|
1655
|
+
case ZodFirstPartyTypeKind.ZodObject: return parseObjectDef(def, refs);
|
|
1656
|
+
case ZodFirstPartyTypeKind.ZodBigInt: return parseBigintDef(def);
|
|
1657
|
+
case ZodFirstPartyTypeKind.ZodBoolean: return parseBooleanDef();
|
|
1658
|
+
case ZodFirstPartyTypeKind.ZodDate: return parseDateDef(def, refs);
|
|
1659
|
+
case ZodFirstPartyTypeKind.ZodUndefined: return parseUndefinedDef();
|
|
1660
|
+
case ZodFirstPartyTypeKind.ZodNull: return parseNullDef();
|
|
1661
|
+
case ZodFirstPartyTypeKind.ZodArray: return parseArrayDef(def, refs);
|
|
1662
|
+
case ZodFirstPartyTypeKind.ZodUnion:
|
|
1663
|
+
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: return parseUnionDef(def, refs);
|
|
1664
|
+
case ZodFirstPartyTypeKind.ZodIntersection: return parseIntersectionDef(def, refs);
|
|
1665
|
+
case ZodFirstPartyTypeKind.ZodTuple: return parseTupleDef(def, refs);
|
|
1666
|
+
case ZodFirstPartyTypeKind.ZodRecord: return parseRecordDef(def, refs);
|
|
1667
|
+
case ZodFirstPartyTypeKind.ZodLiteral: return parseLiteralDef(def);
|
|
1668
|
+
case ZodFirstPartyTypeKind.ZodEnum: return parseEnumDef(def);
|
|
1669
|
+
case ZodFirstPartyTypeKind.ZodNativeEnum: return parseNativeEnumDef(def);
|
|
1670
|
+
case ZodFirstPartyTypeKind.ZodNullable: return parseNullableDef(def, refs);
|
|
1671
|
+
case ZodFirstPartyTypeKind.ZodOptional: return parseOptionalDef(def, refs);
|
|
1672
|
+
case ZodFirstPartyTypeKind.ZodMap: return parseMapDef(def, refs);
|
|
1673
|
+
case ZodFirstPartyTypeKind.ZodSet: return parseSetDef(def, refs);
|
|
1674
|
+
case ZodFirstPartyTypeKind.ZodLazy: return () => def.getter()._def;
|
|
1675
|
+
case ZodFirstPartyTypeKind.ZodPromise: return parsePromiseDef(def, refs);
|
|
1676
|
+
case ZodFirstPartyTypeKind.ZodNaN:
|
|
1677
|
+
case ZodFirstPartyTypeKind.ZodNever: return parseNeverDef();
|
|
1678
|
+
case ZodFirstPartyTypeKind.ZodEffects: return parseEffectsDef(def, refs);
|
|
1679
|
+
case ZodFirstPartyTypeKind.ZodAny: return parseAnyDef();
|
|
1680
|
+
case ZodFirstPartyTypeKind.ZodUnknown: return parseUnknownDef();
|
|
1681
|
+
case ZodFirstPartyTypeKind.ZodDefault: return parseDefaultDef(def, refs);
|
|
1682
|
+
case ZodFirstPartyTypeKind.ZodBranded: return parseBrandedDef(def, refs);
|
|
1683
|
+
case ZodFirstPartyTypeKind.ZodReadonly: return parseReadonlyDef(def, refs);
|
|
1684
|
+
case ZodFirstPartyTypeKind.ZodCatch: return parseCatchDef(def, refs);
|
|
1685
|
+
case ZodFirstPartyTypeKind.ZodPipeline: return parsePipelineDef(def, refs);
|
|
1686
|
+
case ZodFirstPartyTypeKind.ZodFunction:
|
|
1687
|
+
case ZodFirstPartyTypeKind.ZodVoid:
|
|
1688
|
+
case ZodFirstPartyTypeKind.ZodSymbol: return;
|
|
1689
|
+
default: return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
1690
|
+
}
|
|
1691
|
+
};
|
|
1692
|
+
var getRelativePath = (pathA, pathB) => {
|
|
1693
|
+
let i = 0;
|
|
1694
|
+
for (; i < pathA.length && i < pathB.length; i++) if (pathA[i] !== pathB[i]) break;
|
|
1695
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
1696
|
+
};
|
|
1697
|
+
function parseDef(def, refs, forceResolution = false) {
|
|
1698
|
+
var _a2$1;
|
|
1699
|
+
const seenItem = refs.seen.get(def);
|
|
1700
|
+
if (refs.override) {
|
|
1701
|
+
const overrideResult = (_a2$1 = refs.override) == null ? void 0 : _a2$1.call(refs, def, refs, seenItem, forceResolution);
|
|
1702
|
+
if (overrideResult !== ignoreOverride) return overrideResult;
|
|
1703
|
+
}
|
|
1704
|
+
if (seenItem && !forceResolution) {
|
|
1705
|
+
const seenSchema = get$ref(seenItem, refs);
|
|
1706
|
+
if (seenSchema !== void 0) return seenSchema;
|
|
1707
|
+
}
|
|
1708
|
+
const newItem = {
|
|
1709
|
+
def,
|
|
1710
|
+
path: refs.currentPath,
|
|
1711
|
+
jsonSchema: void 0
|
|
1712
|
+
};
|
|
1713
|
+
refs.seen.set(def, newItem);
|
|
1714
|
+
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
1715
|
+
const jsonSchema2 = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
1716
|
+
if (jsonSchema2) addMeta(def, refs, jsonSchema2);
|
|
1717
|
+
if (refs.postProcess) {
|
|
1718
|
+
const postProcessResult = refs.postProcess(jsonSchema2, def, refs);
|
|
1719
|
+
newItem.jsonSchema = jsonSchema2;
|
|
1720
|
+
return postProcessResult;
|
|
1721
|
+
}
|
|
1722
|
+
newItem.jsonSchema = jsonSchema2;
|
|
1723
|
+
return jsonSchema2;
|
|
1724
|
+
}
|
|
1725
|
+
var get$ref = (item, refs) => {
|
|
1726
|
+
switch (refs.$refStrategy) {
|
|
1727
|
+
case "root": return { $ref: item.path.join("/") };
|
|
1728
|
+
case "relative": return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
1729
|
+
case "none":
|
|
1730
|
+
case "seen":
|
|
1731
|
+
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
1732
|
+
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
1733
|
+
return parseAnyDef();
|
|
1734
|
+
}
|
|
1735
|
+
return refs.$refStrategy === "seen" ? parseAnyDef() : void 0;
|
|
1736
|
+
}
|
|
1737
|
+
};
|
|
1738
|
+
var addMeta = (def, refs, jsonSchema2) => {
|
|
1739
|
+
if (def.description) jsonSchema2.description = def.description;
|
|
1740
|
+
return jsonSchema2;
|
|
1741
|
+
};
|
|
1742
|
+
var getRefs = (options) => {
|
|
1743
|
+
const _options = getDefaultOptions(options);
|
|
1744
|
+
const currentPath = _options.name !== void 0 ? [
|
|
1745
|
+
..._options.basePath,
|
|
1746
|
+
_options.definitionPath,
|
|
1747
|
+
_options.name
|
|
1748
|
+
] : _options.basePath;
|
|
1749
|
+
return {
|
|
1750
|
+
..._options,
|
|
1751
|
+
currentPath,
|
|
1752
|
+
propertyPath: void 0,
|
|
1753
|
+
seen: new Map(Object.entries(_options.definitions).map(([name2$1, def]) => [def._def, {
|
|
1754
|
+
def: def._def,
|
|
1755
|
+
path: [
|
|
1756
|
+
..._options.basePath,
|
|
1757
|
+
_options.definitionPath,
|
|
1758
|
+
name2$1
|
|
1759
|
+
],
|
|
1760
|
+
jsonSchema: void 0
|
|
1761
|
+
}]))
|
|
1762
|
+
};
|
|
1763
|
+
};
|
|
1764
|
+
var zod3ToJsonSchema = (schema, options) => {
|
|
1765
|
+
var _a2$1;
|
|
1766
|
+
const refs = getRefs(options);
|
|
1767
|
+
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name3$1, schema2]) => {
|
|
1768
|
+
var _a3$1;
|
|
1769
|
+
return {
|
|
1770
|
+
...acc,
|
|
1771
|
+
[name3$1]: (_a3$1 = parseDef(schema2._def, {
|
|
1772
|
+
...refs,
|
|
1773
|
+
currentPath: [
|
|
1774
|
+
...refs.basePath,
|
|
1775
|
+
refs.definitionPath,
|
|
1776
|
+
name3$1
|
|
1777
|
+
]
|
|
1778
|
+
}, true)) != null ? _a3$1 : parseAnyDef()
|
|
1779
|
+
};
|
|
1780
|
+
}, {}) : void 0;
|
|
1781
|
+
const name2$1 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
1782
|
+
const main = (_a2$1 = parseDef(schema._def, name2$1 === void 0 ? refs : {
|
|
1783
|
+
...refs,
|
|
1784
|
+
currentPath: [
|
|
1785
|
+
...refs.basePath,
|
|
1786
|
+
refs.definitionPath,
|
|
1787
|
+
name2$1
|
|
1788
|
+
]
|
|
1789
|
+
}, false)) != null ? _a2$1 : parseAnyDef();
|
|
1790
|
+
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
1791
|
+
if (title !== void 0) main.title = title;
|
|
1792
|
+
const combined = name2$1 === void 0 ? definitions ? {
|
|
1793
|
+
...main,
|
|
1794
|
+
[refs.definitionPath]: definitions
|
|
1795
|
+
} : main : {
|
|
1796
|
+
$ref: [
|
|
1797
|
+
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
1798
|
+
refs.definitionPath,
|
|
1799
|
+
name2$1
|
|
1800
|
+
].join("/"),
|
|
1801
|
+
[refs.definitionPath]: {
|
|
1802
|
+
...definitions,
|
|
1803
|
+
[name2$1]: main
|
|
1804
|
+
}
|
|
1805
|
+
};
|
|
1806
|
+
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
1807
|
+
return combined;
|
|
1808
|
+
};
|
|
1809
|
+
var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
1810
|
+
function lazySchema(createSchema) {
|
|
1811
|
+
let schema;
|
|
1812
|
+
return () => {
|
|
1813
|
+
if (schema == null) schema = createSchema();
|
|
1814
|
+
return schema;
|
|
1815
|
+
};
|
|
1816
|
+
}
|
|
1817
|
+
function jsonSchema(jsonSchema2, { validate } = {}) {
|
|
1818
|
+
return {
|
|
1819
|
+
[schemaSymbol]: true,
|
|
1820
|
+
_type: void 0,
|
|
1821
|
+
get jsonSchema() {
|
|
1822
|
+
if (typeof jsonSchema2 === "function") jsonSchema2 = jsonSchema2();
|
|
1823
|
+
return jsonSchema2;
|
|
1824
|
+
},
|
|
1825
|
+
validate
|
|
1826
|
+
};
|
|
1827
|
+
}
|
|
1828
|
+
function isSchema(value) {
|
|
1829
|
+
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
|
1830
|
+
}
|
|
1831
|
+
function asSchema(schema) {
|
|
1832
|
+
return schema == null ? jsonSchema({
|
|
1833
|
+
properties: {},
|
|
1834
|
+
additionalProperties: false
|
|
1835
|
+
}) : isSchema(schema) ? schema : "~standard" in schema ? schema["~standard"].vendor === "zod" ? zodSchema(schema) : standardSchema(schema) : schema();
|
|
1836
|
+
}
|
|
1837
|
+
function standardSchema(standardSchema2) {
|
|
1838
|
+
return jsonSchema(() => addAdditionalPropertiesToJsonSchema(standardSchema2["~standard"].jsonSchema.input({ target: "draft-07" })), { validate: async (value) => {
|
|
1839
|
+
const result = await standardSchema2["~standard"].validate(value);
|
|
1840
|
+
return "value" in result ? {
|
|
1841
|
+
success: true,
|
|
1842
|
+
value: result.value
|
|
1843
|
+
} : {
|
|
1844
|
+
success: false,
|
|
1845
|
+
error: new TypeValidationError({
|
|
1846
|
+
value,
|
|
1847
|
+
cause: result.issues
|
|
1848
|
+
})
|
|
1849
|
+
};
|
|
1850
|
+
} });
|
|
1851
|
+
}
|
|
1852
|
+
function zod3Schema(zodSchema2, options) {
|
|
1853
|
+
var _a2$1;
|
|
1854
|
+
const useReferences = (_a2$1 = options == null ? void 0 : options.useReferences) != null ? _a2$1 : false;
|
|
1855
|
+
return jsonSchema(() => zod3ToJsonSchema(zodSchema2, { $refStrategy: useReferences ? "root" : "none" }), { validate: async (value) => {
|
|
1856
|
+
const result = await zodSchema2.safeParseAsync(value);
|
|
1857
|
+
return result.success ? {
|
|
1858
|
+
success: true,
|
|
1859
|
+
value: result.data
|
|
1860
|
+
} : {
|
|
1861
|
+
success: false,
|
|
1862
|
+
error: result.error
|
|
1863
|
+
};
|
|
1864
|
+
} });
|
|
1865
|
+
}
|
|
1866
|
+
function zod4Schema(zodSchema2, options) {
|
|
1867
|
+
var _a2$1;
|
|
1868
|
+
const useReferences = (_a2$1 = options == null ? void 0 : options.useReferences) != null ? _a2$1 : false;
|
|
1869
|
+
return jsonSchema(() => addAdditionalPropertiesToJsonSchema(z4.toJSONSchema(zodSchema2, {
|
|
1870
|
+
target: "draft-7",
|
|
1871
|
+
io: "input",
|
|
1872
|
+
reused: useReferences ? "ref" : "inline"
|
|
1873
|
+
})), { validate: async (value) => {
|
|
1874
|
+
const result = await z4.safeParseAsync(zodSchema2, value);
|
|
1875
|
+
return result.success ? {
|
|
1876
|
+
success: true,
|
|
1877
|
+
value: result.data
|
|
1878
|
+
} : {
|
|
1879
|
+
success: false,
|
|
1880
|
+
error: result.error
|
|
1881
|
+
};
|
|
1882
|
+
} });
|
|
1883
|
+
}
|
|
1884
|
+
function isZod4Schema(zodSchema2) {
|
|
1885
|
+
return "_zod" in zodSchema2;
|
|
1886
|
+
}
|
|
1887
|
+
function zodSchema(zodSchema2, options) {
|
|
1888
|
+
if (isZod4Schema(zodSchema2)) return zod4Schema(zodSchema2, options);
|
|
1889
|
+
else return zod3Schema(zodSchema2, options);
|
|
1890
|
+
}
|
|
1891
|
+
async function validateTypes({ value, schema, context }) {
|
|
1892
|
+
const result = await safeValidateTypes({
|
|
1893
|
+
value,
|
|
1894
|
+
schema,
|
|
1895
|
+
context
|
|
1896
|
+
});
|
|
1897
|
+
if (!result.success) throw TypeValidationError.wrap({
|
|
1898
|
+
value,
|
|
1899
|
+
cause: result.error,
|
|
1900
|
+
context
|
|
1901
|
+
});
|
|
1902
|
+
return result.value;
|
|
1903
|
+
}
|
|
1904
|
+
async function safeValidateTypes({ value, schema, context }) {
|
|
1905
|
+
const actualSchema = asSchema(schema);
|
|
1906
|
+
try {
|
|
1907
|
+
if (actualSchema.validate == null) return {
|
|
1908
|
+
success: true,
|
|
1909
|
+
value,
|
|
1910
|
+
rawValue: value
|
|
1911
|
+
};
|
|
1912
|
+
const result = await actualSchema.validate(value);
|
|
1913
|
+
if (result.success) return {
|
|
1914
|
+
success: true,
|
|
1915
|
+
value: result.value,
|
|
1916
|
+
rawValue: value
|
|
1917
|
+
};
|
|
1918
|
+
return {
|
|
1919
|
+
success: false,
|
|
1920
|
+
error: TypeValidationError.wrap({
|
|
1921
|
+
value,
|
|
1922
|
+
cause: result.error,
|
|
1923
|
+
context
|
|
1924
|
+
}),
|
|
1925
|
+
rawValue: value
|
|
1926
|
+
};
|
|
1927
|
+
} catch (error) {
|
|
1928
|
+
return {
|
|
1929
|
+
success: false,
|
|
1930
|
+
error: TypeValidationError.wrap({
|
|
1931
|
+
value,
|
|
1932
|
+
cause: error,
|
|
1933
|
+
context
|
|
1934
|
+
}),
|
|
1935
|
+
rawValue: value
|
|
1936
|
+
};
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
async function parseJSON({ text, schema }) {
|
|
1940
|
+
try {
|
|
1941
|
+
const value = secureJsonParse(text);
|
|
1942
|
+
if (schema == null) return value;
|
|
1943
|
+
return validateTypes({
|
|
1944
|
+
value,
|
|
1945
|
+
schema
|
|
1946
|
+
});
|
|
1947
|
+
} catch (error) {
|
|
1948
|
+
if (JSONParseError.isInstance(error) || TypeValidationError.isInstance(error)) throw error;
|
|
1949
|
+
throw new JSONParseError({
|
|
1950
|
+
text,
|
|
1951
|
+
cause: error
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
async function safeParseJSON({ text, schema }) {
|
|
1956
|
+
try {
|
|
1957
|
+
const value = secureJsonParse(text);
|
|
1958
|
+
if (schema == null) return {
|
|
1959
|
+
success: true,
|
|
1960
|
+
value,
|
|
1961
|
+
rawValue: value
|
|
1962
|
+
};
|
|
1963
|
+
return await safeValidateTypes({
|
|
1964
|
+
value,
|
|
1965
|
+
schema
|
|
1966
|
+
});
|
|
1967
|
+
} catch (error) {
|
|
1968
|
+
return {
|
|
1969
|
+
success: false,
|
|
1970
|
+
error: JSONParseError.isInstance(error) ? error : new JSONParseError({
|
|
1971
|
+
text,
|
|
1972
|
+
cause: error
|
|
1973
|
+
}),
|
|
1974
|
+
rawValue: void 0
|
|
1975
|
+
};
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
function isParsableJson(input) {
|
|
1979
|
+
try {
|
|
1980
|
+
secureJsonParse(input);
|
|
1981
|
+
return true;
|
|
1982
|
+
} catch (e) {
|
|
1983
|
+
return false;
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
function parseJsonEventStream({ stream, schema }) {
|
|
1987
|
+
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream()).pipeThrough(new TransformStream({ async transform({ data }, controller) {
|
|
1988
|
+
if (data === "[DONE]") return;
|
|
1989
|
+
controller.enqueue(await safeParseJSON({
|
|
1990
|
+
text: data,
|
|
1991
|
+
schema
|
|
1992
|
+
}));
|
|
1993
|
+
} }));
|
|
1994
|
+
}
|
|
1995
|
+
async function parseProviderOptions({ provider, providerOptions, schema }) {
|
|
1996
|
+
if ((providerOptions == null ? void 0 : providerOptions[provider]) == null) return;
|
|
1997
|
+
const parsedProviderOptions = await safeValidateTypes({
|
|
1998
|
+
value: providerOptions[provider],
|
|
1999
|
+
schema
|
|
2000
|
+
});
|
|
2001
|
+
if (!parsedProviderOptions.success) throw new InvalidArgumentError({
|
|
2002
|
+
argument: "providerOptions",
|
|
2003
|
+
message: `invalid ${provider} provider options`,
|
|
2004
|
+
cause: parsedProviderOptions.error
|
|
2005
|
+
});
|
|
2006
|
+
return parsedProviderOptions.value;
|
|
2007
|
+
}
|
|
2008
|
+
var getOriginalFetch2 = () => globalThis.fetch;
|
|
2009
|
+
var postJsonToApi = async ({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch: fetch2 }) => postToApi({
|
|
2010
|
+
url,
|
|
2011
|
+
headers: {
|
|
2012
|
+
"Content-Type": "application/json",
|
|
2013
|
+
...headers
|
|
2014
|
+
},
|
|
2015
|
+
body: {
|
|
2016
|
+
content: JSON.stringify(body),
|
|
2017
|
+
values: body
|
|
2018
|
+
},
|
|
2019
|
+
failedResponseHandler,
|
|
2020
|
+
successfulResponseHandler,
|
|
2021
|
+
abortSignal,
|
|
2022
|
+
fetch: fetch2
|
|
2023
|
+
});
|
|
2024
|
+
var postFormDataToApi = async ({ url, headers, formData, failedResponseHandler, successfulResponseHandler, abortSignal, fetch: fetch2 }) => postToApi({
|
|
2025
|
+
url,
|
|
2026
|
+
headers,
|
|
2027
|
+
body: {
|
|
2028
|
+
content: formData,
|
|
2029
|
+
values: Object.fromEntries(formData.entries())
|
|
2030
|
+
},
|
|
2031
|
+
failedResponseHandler,
|
|
2032
|
+
successfulResponseHandler,
|
|
2033
|
+
abortSignal,
|
|
2034
|
+
fetch: fetch2
|
|
2035
|
+
});
|
|
2036
|
+
var postToApi = async ({ url, headers = {}, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch: fetch2 = getOriginalFetch2() }) => {
|
|
2037
|
+
try {
|
|
2038
|
+
const response = await fetch2(url, {
|
|
2039
|
+
method: "POST",
|
|
2040
|
+
headers: withUserAgentSuffix(headers, `ai-sdk/provider-utils/${VERSION}`, getRuntimeEnvironmentUserAgent()),
|
|
2041
|
+
body: body.content,
|
|
2042
|
+
signal: abortSignal
|
|
2043
|
+
});
|
|
2044
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
2045
|
+
if (!response.ok) {
|
|
2046
|
+
let errorInformation;
|
|
2047
|
+
try {
|
|
2048
|
+
errorInformation = await failedResponseHandler({
|
|
2049
|
+
response,
|
|
2050
|
+
url,
|
|
2051
|
+
requestBodyValues: body.values
|
|
2052
|
+
});
|
|
2053
|
+
} catch (error) {
|
|
2054
|
+
if (isAbortError(error) || APICallError.isInstance(error)) throw error;
|
|
2055
|
+
throw new APICallError({
|
|
2056
|
+
message: "Failed to process error response",
|
|
2057
|
+
cause: error,
|
|
2058
|
+
statusCode: response.status,
|
|
2059
|
+
url,
|
|
2060
|
+
responseHeaders,
|
|
2061
|
+
requestBodyValues: body.values
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
throw errorInformation.value;
|
|
2065
|
+
}
|
|
2066
|
+
try {
|
|
2067
|
+
return await successfulResponseHandler({
|
|
2068
|
+
response,
|
|
2069
|
+
url,
|
|
2070
|
+
requestBodyValues: body.values
|
|
2071
|
+
});
|
|
2072
|
+
} catch (error) {
|
|
2073
|
+
if (error instanceof Error) {
|
|
2074
|
+
if (isAbortError(error) || APICallError.isInstance(error)) throw error;
|
|
2075
|
+
}
|
|
2076
|
+
throw new APICallError({
|
|
2077
|
+
message: "Failed to process successful response",
|
|
2078
|
+
cause: error,
|
|
2079
|
+
statusCode: response.status,
|
|
2080
|
+
url,
|
|
2081
|
+
responseHeaders,
|
|
2082
|
+
requestBodyValues: body.values
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
} catch (error) {
|
|
2086
|
+
throw handleFetchError({
|
|
2087
|
+
error,
|
|
2088
|
+
url,
|
|
2089
|
+
requestBodyValues: body.values
|
|
2090
|
+
});
|
|
2091
|
+
}
|
|
2092
|
+
};
|
|
2093
|
+
function tool(tool2) {
|
|
2094
|
+
return tool2;
|
|
2095
|
+
}
|
|
2096
|
+
function createProviderToolFactory({ id, inputSchema }) {
|
|
2097
|
+
return ({ execute, outputSchema, needsApproval, toModelOutput, onInputStart, onInputDelta, onInputAvailable,...args }) => tool({
|
|
2098
|
+
type: "provider",
|
|
2099
|
+
id,
|
|
2100
|
+
args,
|
|
2101
|
+
inputSchema,
|
|
2102
|
+
outputSchema,
|
|
2103
|
+
execute,
|
|
2104
|
+
needsApproval,
|
|
2105
|
+
toModelOutput,
|
|
2106
|
+
onInputStart,
|
|
2107
|
+
onInputDelta,
|
|
2108
|
+
onInputAvailable
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2111
|
+
function createProviderToolFactoryWithOutputSchema({ id, inputSchema, outputSchema, supportsDeferredResults }) {
|
|
2112
|
+
return ({ execute, needsApproval, toModelOutput, onInputStart, onInputDelta, onInputAvailable,...args }) => tool({
|
|
2113
|
+
type: "provider",
|
|
2114
|
+
id,
|
|
2115
|
+
args,
|
|
2116
|
+
inputSchema,
|
|
2117
|
+
outputSchema,
|
|
2118
|
+
execute,
|
|
2119
|
+
needsApproval,
|
|
2120
|
+
toModelOutput,
|
|
2121
|
+
onInputStart,
|
|
2122
|
+
onInputDelta,
|
|
2123
|
+
onInputAvailable,
|
|
2124
|
+
supportsDeferredResults
|
|
2125
|
+
});
|
|
2126
|
+
}
|
|
2127
|
+
async function resolve(value) {
|
|
2128
|
+
if (typeof value === "function") value = value();
|
|
2129
|
+
return Promise.resolve(value);
|
|
2130
|
+
}
|
|
2131
|
+
var createJsonErrorResponseHandler = ({ errorSchema, errorToMessage, isRetryable }) => async ({ response, url, requestBodyValues }) => {
|
|
2132
|
+
const responseBody = await response.text();
|
|
2133
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
2134
|
+
if (responseBody.trim() === "") return {
|
|
2135
|
+
responseHeaders,
|
|
2136
|
+
value: new APICallError({
|
|
2137
|
+
message: response.statusText,
|
|
2138
|
+
url,
|
|
2139
|
+
requestBodyValues,
|
|
2140
|
+
statusCode: response.status,
|
|
2141
|
+
responseHeaders,
|
|
2142
|
+
responseBody,
|
|
2143
|
+
isRetryable: isRetryable == null ? void 0 : isRetryable(response)
|
|
2144
|
+
})
|
|
2145
|
+
};
|
|
2146
|
+
try {
|
|
2147
|
+
const parsedError = await parseJSON({
|
|
2148
|
+
text: responseBody,
|
|
2149
|
+
schema: errorSchema
|
|
2150
|
+
});
|
|
2151
|
+
return {
|
|
2152
|
+
responseHeaders,
|
|
2153
|
+
value: new APICallError({
|
|
2154
|
+
message: errorToMessage(parsedError),
|
|
2155
|
+
url,
|
|
2156
|
+
requestBodyValues,
|
|
2157
|
+
statusCode: response.status,
|
|
2158
|
+
responseHeaders,
|
|
2159
|
+
responseBody,
|
|
2160
|
+
data: parsedError,
|
|
2161
|
+
isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
|
|
2162
|
+
})
|
|
2163
|
+
};
|
|
2164
|
+
} catch (parseError) {
|
|
2165
|
+
return {
|
|
2166
|
+
responseHeaders,
|
|
2167
|
+
value: new APICallError({
|
|
2168
|
+
message: response.statusText,
|
|
2169
|
+
url,
|
|
2170
|
+
requestBodyValues,
|
|
2171
|
+
statusCode: response.status,
|
|
2172
|
+
responseHeaders,
|
|
2173
|
+
responseBody,
|
|
2174
|
+
isRetryable: isRetryable == null ? void 0 : isRetryable(response)
|
|
2175
|
+
})
|
|
2176
|
+
};
|
|
2177
|
+
}
|
|
2178
|
+
};
|
|
2179
|
+
var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
2180
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
2181
|
+
if (response.body == null) throw new EmptyResponseBodyError({});
|
|
2182
|
+
return {
|
|
2183
|
+
responseHeaders,
|
|
2184
|
+
value: parseJsonEventStream({
|
|
2185
|
+
stream: response.body,
|
|
2186
|
+
schema: chunkSchema
|
|
2187
|
+
})
|
|
2188
|
+
};
|
|
2189
|
+
};
|
|
2190
|
+
var createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
|
|
2191
|
+
const responseBody = await response.text();
|
|
2192
|
+
const parsedResult = await safeParseJSON({
|
|
2193
|
+
text: responseBody,
|
|
2194
|
+
schema: responseSchema
|
|
2195
|
+
});
|
|
2196
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
2197
|
+
if (!parsedResult.success) throw new APICallError({
|
|
2198
|
+
message: "Invalid JSON response",
|
|
2199
|
+
cause: parsedResult.error,
|
|
2200
|
+
statusCode: response.status,
|
|
2201
|
+
responseHeaders,
|
|
2202
|
+
responseBody,
|
|
2203
|
+
url,
|
|
2204
|
+
requestBodyValues
|
|
2205
|
+
});
|
|
2206
|
+
return {
|
|
2207
|
+
responseHeaders,
|
|
2208
|
+
value: parsedResult.value,
|
|
2209
|
+
rawValue: parsedResult.rawValue
|
|
2210
|
+
};
|
|
2211
|
+
};
|
|
2212
|
+
var createBinaryResponseHandler = () => async ({ response, url, requestBodyValues }) => {
|
|
2213
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
2214
|
+
if (!response.body) throw new APICallError({
|
|
2215
|
+
message: "Response body is empty",
|
|
2216
|
+
url,
|
|
2217
|
+
requestBodyValues,
|
|
2218
|
+
statusCode: response.status,
|
|
2219
|
+
responseHeaders,
|
|
2220
|
+
responseBody: void 0
|
|
2221
|
+
});
|
|
2222
|
+
try {
|
|
2223
|
+
const buffer = await response.arrayBuffer();
|
|
2224
|
+
return {
|
|
2225
|
+
responseHeaders,
|
|
2226
|
+
value: new Uint8Array(buffer)
|
|
2227
|
+
};
|
|
2228
|
+
} catch (error) {
|
|
2229
|
+
throw new APICallError({
|
|
2230
|
+
message: "Failed to read response as array buffer",
|
|
2231
|
+
url,
|
|
2232
|
+
requestBodyValues,
|
|
2233
|
+
statusCode: response.status,
|
|
2234
|
+
responseHeaders,
|
|
2235
|
+
responseBody: void 0,
|
|
2236
|
+
cause: error
|
|
2237
|
+
});
|
|
2238
|
+
}
|
|
2239
|
+
};
|
|
2240
|
+
function withoutTrailingSlash(url) {
|
|
2241
|
+
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
//#endregion
|
|
2245
|
+
export { APICallError as A, postJsonToApi as C, withUserAgentSuffix as D, validateTypes as E, TooManyEmbeddingValuesForCallError as F, UnsupportedFunctionalityError as I, InvalidPromptError as M, InvalidResponseDataError as N, withoutTrailingSlash as O, NoSuchModelError as P, postFormDataToApi as S, safeParseJSON as T, loadApiKey as _, createBinaryResponseHandler as a, parseJSON as b, createJsonResponseHandler as c, createToolNameMapping as d, downloadBlob as f, lazySchema as g, isParsableJson as h, convertToFormData as i, InvalidArgumentError as j, zodSchema as k, createProviderToolFactory as l, isNonNullable as m, convertBase64ToUint8Array as n, createEventSourceResponseHandler as o, generateId as p, convertToBase64 as r, createJsonErrorResponseHandler as s, combineHeaders as t, createProviderToolFactoryWithOutputSchema as u, loadOptionalSetting as v, resolve as w, parseProviderOptions as x, mediaTypeToExtension as y };
|
|
2246
|
+
//# sourceMappingURL=dist-BYInIjS8.js.map
|