@cueframe/kernel 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_members/account-model/testing/conversationStoreContract.d.ts +1 -1
- package/dist/_members/authoring/providers/resourceApi.d.ts +1 -1
- package/dist/_members/authoring/transpileComponent.d.ts +1 -1
- package/dist/_members/cloud-import/CloudImportService.d.ts +35 -0
- package/dist/_members/cloud-import/ImportProvider.d.ts +73 -0
- package/dist/_members/cloud-import/MediaItemPreprocessor.d.ts +27 -0
- package/dist/_members/cloud-import/chunk-XKO6ZSWI.js +162 -0
- package/dist/_members/cloud-import/chunk-XKO6ZSWI.js.map +1 -0
- package/dist/_members/cloud-import/cloudConfig.d.ts +23 -0
- package/dist/_members/cloud-import/index.d.ts +9 -0
- package/dist/_members/cloud-import/index.js +241 -0
- package/dist/_members/cloud-import/index.js.map +1 -0
- package/dist/_members/cloud-import/multipartUpload.d.ts +12 -0
- package/dist/_members/cloud-import/multipartUpload.js +7 -0
- package/dist/_members/cloud-import/multipartUpload.js.map +1 -0
- package/dist/_members/composition/ops/compositionOps.d.ts +1 -1
- package/dist/_members/composition/ops/types.d.ts +1 -1
- package/dist/_members/composition/timeline/placement.d.ts +1 -1
- package/dist/_members/composition/validators/composition.d.ts +1 -1
- package/dist/_members/composition-ops/index.d.ts +1 -1
- package/dist/_members/composition-ops/opRecorder.d.ts +1 -1
- package/dist/_members/convex-api/api.d.ts +5 -0
- package/dist/_members/convex-api/dataModel.d.ts +6 -0
- package/dist/_members/core/render/exportSettings.d.ts +1 -1
- package/dist/_members/mcp/curation.d.ts +1 -1
- package/dist/_members/plane/conformance.d.ts +1 -1
- package/dist/_members/render-harness/localRender.d.ts +1 -1
- package/dist/animate.js +828 -79187
- package/dist/authoring/build-tools.js +8 -11
- package/dist/authoring/context.js +5 -5
- package/dist/authoring/models.js +1 -2
- package/dist/authoring/prompts.js +1 -1
- package/dist/authoring/tools.js +7 -7
- package/dist/authoring/transpileComponent.js +3 -2220
- package/dist/authoring.js +27 -29
- package/dist/brand-derivation.js +1 -1
- package/dist/chunk-6IU2UQI5.js +107 -0
- package/dist/{chunk-N67PDTKQ.js → chunk-ABL557OT.js} +1 -1
- package/dist/{chunk-DSNG6WLU.js → chunk-AYVJXDLB.js} +1 -4
- package/dist/{chunk-G3PBH53P.js → chunk-COYMZ76S.js} +1 -1
- package/dist/chunk-DSMLHYJ4.js +82 -0
- package/dist/{chunk-BRKJKB33.js → chunk-FYZVH3MC.js} +1 -1
- package/dist/{chunk-MVEE6HEC.js → chunk-GA23TRNR.js} +5 -7
- package/dist/{chunk-OIRUO5P7.js → chunk-GEA7E2FL.js} +1 -1
- package/dist/chunk-HCCBDJLW.js +68 -0
- package/dist/{chunk-QLAQHR3L.js → chunk-IBYQG46O.js} +1 -1
- package/dist/chunk-JQMPHKLU.js +126 -0
- package/dist/{chunk-ELLSET2N.js → chunk-LM4WDUQJ.js} +3 -6
- package/dist/{chunk-UEI3NLNK.js → chunk-MHOQTPOB.js} +1 -4
- package/dist/{chunk-ATAF24QG.js → chunk-MXFAADCQ.js} +1 -1
- package/dist/{chunk-TULRCY6U.js → chunk-NFEGPWGS.js} +1 -1
- package/dist/{chunk-MC5DLSEV.js → chunk-ODL7GQJG.js} +14 -14
- package/dist/{chunk-WZTTZHNR.js → chunk-OLFOPQCA.js} +12 -9
- package/dist/{chunk-P43IE4WB.js → chunk-P727GZVO.js} +2 -4
- package/dist/{chunk-S3P5BFFL.js → chunk-PMY24FUD.js} +2 -4
- package/dist/chunk-RF7U3SCL.js +606 -0
- package/dist/{chunk-JD77Y2WM.js → chunk-SW336CJP.js} +1 -4
- package/dist/{chunk-M3I5LMAB.js → chunk-UY4SWJVE.js} +1 -1
- package/dist/{chunk-52AHXNKM.js → chunk-VOO5FQSS.js} +5 -5
- package/dist/{chunk-NV4I6GJV.js → chunk-XWKZB5U5.js} +4 -4
- package/dist/{chunk-6QJ3V3VS.js → chunk-YX2GSJK7.js} +1 -1
- package/dist/{chunk-5I7VDCAC.js → chunk-ZB3C3HM7.js} +1 -1
- package/dist/chunk-ZT7MHRQU.js +104 -0
- package/dist/cloud-import/multipart.d.ts +1 -0
- package/dist/cloud-import/multipart.js +8 -0
- package/dist/cloud-import.d.ts +1 -0
- package/dist/cloud-import.js +234 -0
- package/dist/compose/renderer.js +18 -21
- package/dist/compose.js +18 -21
- package/dist/composition/graphics-plan.js +3 -3
- package/dist/composition/ops.js +4 -4
- package/dist/composition/primitive-catalog.js +1 -1
- package/dist/composition/projection.js +3 -3
- package/dist/composition/validators.js +2 -2
- package/dist/composition-ops.js +12 -12
- package/dist/composition.js +5 -5
- package/dist/{context-CEAKQ5T7.js → context-OKX3HHFS.js} +5 -5
- package/dist/convex-api/dataModel.d.ts +1 -0
- package/dist/convex-api/dataModel.js +0 -0
- package/dist/convex-api.d.ts +1 -0
- package/dist/convex-api.js +8 -0
- package/dist/core/render.js +2 -2
- package/dist/core.js +2 -2
- package/dist/mcp/adapter.js +1 -5
- package/dist/mcp/server.js +1 -2
- package/dist/mcp.js +2 -95
- package/dist/media-model/media-kind.js +9 -98
- package/dist/nle-export/xml.js +5 -22799
- package/dist/nle-export.js +18 -21
- package/dist/primitives/backgrounds.js +2 -3
- package/dist/primitives/captions.js +4 -243
- package/dist/primitives/effects.js +2 -3
- package/dist/primitives/hero-text.js +2 -3
- package/dist/primitives/layouts.js +2 -3
- package/dist/primitives/lib/index.js +8 -10
- package/dist/primitives/lib/preview.js +1 -2
- package/dist/primitives/lib/schema.js +1 -2
- package/dist/primitives/lib/text/fitText.js +1 -2
- package/dist/primitives/lib.js +8 -10
- package/dist/primitives/scenes.js +1 -2
- package/dist/primitives/text.js +2 -3
- package/dist/primitives/ui-blocks.js +4 -5
- package/dist/primitives.js +19 -21
- package/package.json +123 -13
- package/dist/TextureLoader-UQOFUSAP.js +0 -422
- package/dist/VideoTexture-AQWSPIJG.js +0 -62
- package/dist/chunk-7GISRVON.js +0 -14176
- package/dist/chunk-DIBOJJMU.js +0 -16838
- package/dist/chunk-EAUSEGB7.js +0 -420
- package/dist/chunk-FUWJOVVK.js +0 -3633
- package/dist/chunk-G75E7YA4.js +0 -11883
- package/dist/chunk-JCZQT7K3.js +0 -3266
- package/dist/chunk-KF5ETMKB.js +0 -544
- package/dist/chunk-NDKERSXY.js +0 -1296
- package/dist/chunk-V43Y7IE4.js +0 -3621
- package/dist/chunk-VIVQHIGZ.js +0 -4319
- package/dist/chunk-YA3OR2KK.js +0 -249
- package/dist/hls-HD4C5G6W.js +0 -33000
- package/dist/token-RGFIT24D.js +0 -69
- package/dist/token-util-GPLSGYVO.js +0 -5
- package/dist/vision_bundle-5Y376MAR.js +0 -4084
- package/dist/{chunk-6CMVBTTP.js → chunk-YIOY2XEO.js} +4 -4
package/dist/chunk-VIVQHIGZ.js
DELETED
|
@@ -1,4319 +0,0 @@
|
|
|
1
|
-
// ../../node_modules/.pnpm/@ai-sdk+provider@4.0.7/node_modules/@ai-sdk/provider/dist/index.js
|
|
2
|
-
var marker = "vercel.ai.error";
|
|
3
|
-
var symbol = Symbol.for(marker);
|
|
4
|
-
var _a;
|
|
5
|
-
var _b;
|
|
6
|
-
var AISDKError = class _AISDKError extends (_b = Error, _a = symbol, _b) {
|
|
7
|
-
/**
|
|
8
|
-
* Creates an AI SDK Error.
|
|
9
|
-
*
|
|
10
|
-
* @param {Object} params - The parameters for creating the error.
|
|
11
|
-
* @param {string} params.name - The name of the error.
|
|
12
|
-
* @param {string} params.message - The error message.
|
|
13
|
-
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
14
|
-
*/
|
|
15
|
-
constructor({
|
|
16
|
-
name: name152,
|
|
17
|
-
message,
|
|
18
|
-
cause
|
|
19
|
-
}) {
|
|
20
|
-
super(message);
|
|
21
|
-
this[_a] = true;
|
|
22
|
-
this.name = name152;
|
|
23
|
-
this.cause = cause;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Checks if the given error is an AI SDK Error.
|
|
27
|
-
* @param {unknown} error - The error to check.
|
|
28
|
-
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
29
|
-
*/
|
|
30
|
-
static isInstance(error) {
|
|
31
|
-
return _AISDKError.hasMarker(error, marker);
|
|
32
|
-
}
|
|
33
|
-
static hasMarker(error, marker162) {
|
|
34
|
-
const markerSymbol = Symbol.for(marker162);
|
|
35
|
-
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var name = "AI_APICallError";
|
|
39
|
-
var marker2 = `vercel.ai.error.${name}`;
|
|
40
|
-
var symbol2 = Symbol.for(marker2);
|
|
41
|
-
var _a2;
|
|
42
|
-
var _b2;
|
|
43
|
-
var APICallError = class extends (_b2 = AISDKError, _a2 = symbol2, _b2) {
|
|
44
|
-
constructor({
|
|
45
|
-
message,
|
|
46
|
-
url,
|
|
47
|
-
requestBodyValues,
|
|
48
|
-
statusCode,
|
|
49
|
-
responseHeaders,
|
|
50
|
-
responseBody,
|
|
51
|
-
cause,
|
|
52
|
-
isRetryable = statusCode != null && (statusCode === 408 || // request timeout
|
|
53
|
-
statusCode === 409 || // conflict
|
|
54
|
-
statusCode === 429 || // too many requests
|
|
55
|
-
statusCode >= 500),
|
|
56
|
-
// server error
|
|
57
|
-
data
|
|
58
|
-
}) {
|
|
59
|
-
super({ name, message, cause });
|
|
60
|
-
this[_a2] = true;
|
|
61
|
-
this.url = url;
|
|
62
|
-
this.requestBodyValues = requestBodyValues;
|
|
63
|
-
this.statusCode = statusCode;
|
|
64
|
-
this.responseHeaders = responseHeaders;
|
|
65
|
-
this.responseBody = responseBody;
|
|
66
|
-
this.isRetryable = isRetryable;
|
|
67
|
-
this.data = data;
|
|
68
|
-
}
|
|
69
|
-
static isInstance(error) {
|
|
70
|
-
return AISDKError.hasMarker(error, marker2);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
var name2 = "AI_EmptyResponseBodyError";
|
|
74
|
-
var marker3 = `vercel.ai.error.${name2}`;
|
|
75
|
-
var symbol3 = Symbol.for(marker3);
|
|
76
|
-
var _a3;
|
|
77
|
-
var _b3;
|
|
78
|
-
var EmptyResponseBodyError = class extends (_b3 = AISDKError, _a3 = symbol3, _b3) {
|
|
79
|
-
// used in isInstance
|
|
80
|
-
constructor({ message = "Empty response body" } = {}) {
|
|
81
|
-
super({ name: name2, message });
|
|
82
|
-
this[_a3] = true;
|
|
83
|
-
}
|
|
84
|
-
static isInstance(error) {
|
|
85
|
-
return AISDKError.hasMarker(error, marker3);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
function getErrorMessage(error) {
|
|
89
|
-
if (error == null) {
|
|
90
|
-
return "unknown error";
|
|
91
|
-
}
|
|
92
|
-
if (typeof error === "string") {
|
|
93
|
-
return error;
|
|
94
|
-
}
|
|
95
|
-
if (error instanceof Error) {
|
|
96
|
-
return error.toString();
|
|
97
|
-
}
|
|
98
|
-
return JSON.stringify(error);
|
|
99
|
-
}
|
|
100
|
-
var name3 = "AI_InvalidArgumentError";
|
|
101
|
-
var marker4 = `vercel.ai.error.${name3}`;
|
|
102
|
-
var symbol4 = Symbol.for(marker4);
|
|
103
|
-
var _a4;
|
|
104
|
-
var _b4;
|
|
105
|
-
var InvalidArgumentError = class extends (_b4 = AISDKError, _a4 = symbol4, _b4) {
|
|
106
|
-
constructor({
|
|
107
|
-
message,
|
|
108
|
-
cause,
|
|
109
|
-
argument
|
|
110
|
-
}) {
|
|
111
|
-
super({ name: name3, message, cause });
|
|
112
|
-
this[_a4] = true;
|
|
113
|
-
this.argument = argument;
|
|
114
|
-
}
|
|
115
|
-
static isInstance(error) {
|
|
116
|
-
return AISDKError.hasMarker(error, marker4);
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
var name4 = "AI_InvalidPromptError";
|
|
120
|
-
var marker5 = `vercel.ai.error.${name4}`;
|
|
121
|
-
var symbol5 = Symbol.for(marker5);
|
|
122
|
-
var _a5;
|
|
123
|
-
var _b5;
|
|
124
|
-
var InvalidPromptError = class extends (_b5 = AISDKError, _a5 = symbol5, _b5) {
|
|
125
|
-
constructor({
|
|
126
|
-
prompt,
|
|
127
|
-
message,
|
|
128
|
-
cause
|
|
129
|
-
}) {
|
|
130
|
-
super({ name: name4, message: `Invalid prompt: ${message}`, cause });
|
|
131
|
-
this[_a5] = true;
|
|
132
|
-
this.prompt = prompt;
|
|
133
|
-
}
|
|
134
|
-
static isInstance(error) {
|
|
135
|
-
return AISDKError.hasMarker(error, marker5);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
var name5 = "AI_InvalidResponseDataError";
|
|
139
|
-
var marker6 = `vercel.ai.error.${name5}`;
|
|
140
|
-
var symbol6 = Symbol.for(marker6);
|
|
141
|
-
var _a6;
|
|
142
|
-
var _b6;
|
|
143
|
-
var InvalidResponseDataError = class extends (_b6 = AISDKError, _a6 = symbol6, _b6) {
|
|
144
|
-
constructor({
|
|
145
|
-
data,
|
|
146
|
-
message = `Invalid response data: ${JSON.stringify(data)}.`
|
|
147
|
-
}) {
|
|
148
|
-
super({ name: name5, message });
|
|
149
|
-
this[_a6] = true;
|
|
150
|
-
this.data = data;
|
|
151
|
-
}
|
|
152
|
-
static isInstance(error) {
|
|
153
|
-
return AISDKError.hasMarker(error, marker6);
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
var name6 = "AI_JSONParseError";
|
|
157
|
-
var marker7 = `vercel.ai.error.${name6}`;
|
|
158
|
-
var symbol7 = Symbol.for(marker7);
|
|
159
|
-
var _a7;
|
|
160
|
-
var _b7;
|
|
161
|
-
var JSONParseError = class extends (_b7 = AISDKError, _a7 = symbol7, _b7) {
|
|
162
|
-
constructor({ text, cause }) {
|
|
163
|
-
super({
|
|
164
|
-
name: name6,
|
|
165
|
-
message: `JSON parsing failed: Text: ${text}.
|
|
166
|
-
Error message: ${getErrorMessage(cause)}`,
|
|
167
|
-
cause
|
|
168
|
-
});
|
|
169
|
-
this[_a7] = true;
|
|
170
|
-
this.text = text;
|
|
171
|
-
}
|
|
172
|
-
static isInstance(error) {
|
|
173
|
-
return AISDKError.hasMarker(error, marker7);
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
var name7 = "AI_LoadAPIKeyError";
|
|
177
|
-
var marker8 = `vercel.ai.error.${name7}`;
|
|
178
|
-
var symbol8 = Symbol.for(marker8);
|
|
179
|
-
var _a8;
|
|
180
|
-
var _b8;
|
|
181
|
-
var LoadAPIKeyError = class extends (_b8 = AISDKError, _a8 = symbol8, _b8) {
|
|
182
|
-
// used in isInstance
|
|
183
|
-
constructor({ message }) {
|
|
184
|
-
super({ name: name7, message });
|
|
185
|
-
this[_a8] = true;
|
|
186
|
-
}
|
|
187
|
-
static isInstance(error) {
|
|
188
|
-
return AISDKError.hasMarker(error, marker8);
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
var name8 = "AI_LoadSettingError";
|
|
192
|
-
var marker9 = `vercel.ai.error.${name8}`;
|
|
193
|
-
var symbol9 = Symbol.for(marker9);
|
|
194
|
-
var _a9;
|
|
195
|
-
var _b9;
|
|
196
|
-
var LoadSettingError = class extends (_b9 = AISDKError, _a9 = symbol9, _b9) {
|
|
197
|
-
// used in isInstance
|
|
198
|
-
constructor({ message }) {
|
|
199
|
-
super({ name: name8, message });
|
|
200
|
-
this[_a9] = true;
|
|
201
|
-
}
|
|
202
|
-
static isInstance(error) {
|
|
203
|
-
return AISDKError.hasMarker(error, marker9);
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
var name9 = "AI_NoContentGeneratedError";
|
|
207
|
-
var marker10 = `vercel.ai.error.${name9}`;
|
|
208
|
-
var symbol10 = Symbol.for(marker10);
|
|
209
|
-
var _a10;
|
|
210
|
-
var _b10;
|
|
211
|
-
var NoContentGeneratedError = class extends (_b10 = AISDKError, _a10 = symbol10, _b10) {
|
|
212
|
-
// used in isInstance
|
|
213
|
-
constructor({
|
|
214
|
-
message = "No content generated."
|
|
215
|
-
} = {}) {
|
|
216
|
-
super({ name: name9, message });
|
|
217
|
-
this[_a10] = true;
|
|
218
|
-
}
|
|
219
|
-
static isInstance(error) {
|
|
220
|
-
return AISDKError.hasMarker(error, marker10);
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
var name10 = "AI_NoSuchModelError";
|
|
224
|
-
var marker11 = `vercel.ai.error.${name10}`;
|
|
225
|
-
var symbol11 = Symbol.for(marker11);
|
|
226
|
-
var _a11;
|
|
227
|
-
var _b11;
|
|
228
|
-
var NoSuchModelError = class extends (_b11 = AISDKError, _a11 = symbol11, _b11) {
|
|
229
|
-
constructor({
|
|
230
|
-
errorName = name10,
|
|
231
|
-
modelId,
|
|
232
|
-
modelType,
|
|
233
|
-
message = `No such ${modelType}: ${modelId}`
|
|
234
|
-
}) {
|
|
235
|
-
super({ name: errorName, message });
|
|
236
|
-
this[_a11] = true;
|
|
237
|
-
this.modelId = modelId;
|
|
238
|
-
this.modelType = modelType;
|
|
239
|
-
}
|
|
240
|
-
static isInstance(error) {
|
|
241
|
-
return AISDKError.hasMarker(error, marker11);
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
var name11 = "AI_NoSuchProviderReferenceError";
|
|
245
|
-
var marker12 = `vercel.ai.error.${name11}`;
|
|
246
|
-
var symbol12 = Symbol.for(marker12);
|
|
247
|
-
var _a12;
|
|
248
|
-
var _b12;
|
|
249
|
-
var NoSuchProviderReferenceError = class extends (_b12 = AISDKError, _a12 = symbol12, _b12) {
|
|
250
|
-
constructor({
|
|
251
|
-
provider,
|
|
252
|
-
reference,
|
|
253
|
-
message = `No provider reference found for provider '${provider}'. Available providers: ${Object.keys(reference).join(", ")}`
|
|
254
|
-
}) {
|
|
255
|
-
super({ name: name11, message });
|
|
256
|
-
this[_a12] = true;
|
|
257
|
-
this.provider = provider;
|
|
258
|
-
this.reference = reference;
|
|
259
|
-
}
|
|
260
|
-
static isInstance(error) {
|
|
261
|
-
return AISDKError.hasMarker(error, marker12);
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
var name12 = "AI_TooManyEmbeddingValuesForCallError";
|
|
265
|
-
var marker13 = `vercel.ai.error.${name12}`;
|
|
266
|
-
var symbol13 = Symbol.for(marker13);
|
|
267
|
-
var _a13;
|
|
268
|
-
var _b13;
|
|
269
|
-
var TooManyEmbeddingValuesForCallError = class extends (_b13 = AISDKError, _a13 = symbol13, _b13) {
|
|
270
|
-
constructor(options) {
|
|
271
|
-
super({
|
|
272
|
-
name: name12,
|
|
273
|
-
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.`
|
|
274
|
-
});
|
|
275
|
-
this[_a13] = true;
|
|
276
|
-
this.provider = options.provider;
|
|
277
|
-
this.modelId = options.modelId;
|
|
278
|
-
this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
|
|
279
|
-
this.values = options.values;
|
|
280
|
-
}
|
|
281
|
-
static isInstance(error) {
|
|
282
|
-
return AISDKError.hasMarker(error, marker13);
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
var name13 = "AI_TypeValidationError";
|
|
286
|
-
var marker14 = `vercel.ai.error.${name13}`;
|
|
287
|
-
var symbol14 = Symbol.for(marker14);
|
|
288
|
-
var _a14;
|
|
289
|
-
var _b14;
|
|
290
|
-
var TypeValidationError = class _TypeValidationError extends (_b14 = AISDKError, _a14 = symbol14, _b14) {
|
|
291
|
-
constructor({
|
|
292
|
-
value,
|
|
293
|
-
cause,
|
|
294
|
-
context
|
|
295
|
-
}) {
|
|
296
|
-
let contextPrefix = "Type validation failed";
|
|
297
|
-
if (context == null ? void 0 : context.field) {
|
|
298
|
-
contextPrefix += ` for ${context.field}`;
|
|
299
|
-
}
|
|
300
|
-
if ((context == null ? void 0 : context.entityName) || (context == null ? void 0 : context.entityId)) {
|
|
301
|
-
contextPrefix += " (";
|
|
302
|
-
const parts = [];
|
|
303
|
-
if (context.entityName) {
|
|
304
|
-
parts.push(context.entityName);
|
|
305
|
-
}
|
|
306
|
-
if (context.entityId) {
|
|
307
|
-
parts.push(`id: "${context.entityId}"`);
|
|
308
|
-
}
|
|
309
|
-
contextPrefix += parts.join(", ");
|
|
310
|
-
contextPrefix += ")";
|
|
311
|
-
}
|
|
312
|
-
super({
|
|
313
|
-
name: name13,
|
|
314
|
-
message: `${contextPrefix}: Value: ${JSON.stringify(value)}.
|
|
315
|
-
Error message: ${getErrorMessage(cause)}`,
|
|
316
|
-
cause
|
|
317
|
-
});
|
|
318
|
-
this[_a14] = true;
|
|
319
|
-
this.value = value;
|
|
320
|
-
this.context = context;
|
|
321
|
-
}
|
|
322
|
-
static isInstance(error) {
|
|
323
|
-
return AISDKError.hasMarker(error, marker14);
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Wraps an error into a TypeValidationError.
|
|
327
|
-
* If the cause is already a TypeValidationError with the same value and context, it returns the cause.
|
|
328
|
-
* Otherwise, it creates a new TypeValidationError.
|
|
329
|
-
*
|
|
330
|
-
* @param {Object} params - The parameters for wrapping the error.
|
|
331
|
-
* @param {unknown} params.value - The value that failed validation.
|
|
332
|
-
* @param {unknown} params.cause - The original error or cause of the validation failure.
|
|
333
|
-
* @param {TypeValidationContext} params.context - Optional context about what is being validated.
|
|
334
|
-
* @returns {TypeValidationError} A TypeValidationError instance.
|
|
335
|
-
*/
|
|
336
|
-
static wrap({
|
|
337
|
-
value,
|
|
338
|
-
cause,
|
|
339
|
-
context
|
|
340
|
-
}) {
|
|
341
|
-
var _a162, _b162, _c;
|
|
342
|
-
if (_TypeValidationError.isInstance(cause) && cause.value === value && ((_a162 = cause.context) == null ? void 0 : _a162.field) === (context == null ? void 0 : context.field) && ((_b162 = cause.context) == null ? void 0 : _b162.entityName) === (context == null ? void 0 : context.entityName) && ((_c = cause.context) == null ? void 0 : _c.entityId) === (context == null ? void 0 : context.entityId)) {
|
|
343
|
-
return cause;
|
|
344
|
-
}
|
|
345
|
-
return new _TypeValidationError({ value, cause, context });
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
var name14 = "AI_UnsupportedFunctionalityError";
|
|
349
|
-
var marker15 = `vercel.ai.error.${name14}`;
|
|
350
|
-
var symbol15 = Symbol.for(marker15);
|
|
351
|
-
var _a15;
|
|
352
|
-
var _b15;
|
|
353
|
-
var UnsupportedFunctionalityError = class extends (_b15 = AISDKError, _a15 = symbol15, _b15) {
|
|
354
|
-
constructor({
|
|
355
|
-
functionality,
|
|
356
|
-
message = `'${functionality}' functionality not supported.`
|
|
357
|
-
}) {
|
|
358
|
-
super({ name: name14, message });
|
|
359
|
-
this[_a15] = true;
|
|
360
|
-
this.functionality = functionality;
|
|
361
|
-
}
|
|
362
|
-
static isInstance(error) {
|
|
363
|
-
return AISDKError.hasMarker(error, marker15);
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
function isJSONValue(value) {
|
|
367
|
-
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
368
|
-
return true;
|
|
369
|
-
}
|
|
370
|
-
if (Array.isArray(value)) {
|
|
371
|
-
return value.every(isJSONValue);
|
|
372
|
-
}
|
|
373
|
-
if (typeof value === "object") {
|
|
374
|
-
return Object.entries(value).every(
|
|
375
|
-
([key, val]) => typeof key === "string" && (val === void 0 || isJSONValue(val))
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
function isJSONArray(value) {
|
|
381
|
-
return Array.isArray(value) && value.every(isJSONValue);
|
|
382
|
-
}
|
|
383
|
-
function isJSONObject(value) {
|
|
384
|
-
return value != null && typeof value === "object" && Object.entries(value).every(
|
|
385
|
-
([key, val]) => typeof key === "string" && (val === void 0 || isJSONValue(val))
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
// ../../node_modules/.pnpm/@ai-sdk+provider-utils@5.0.27_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.js
|
|
390
|
-
import { safeParseAsync } from "zod/v4";
|
|
391
|
-
import { toJSONSchema } from "zod/v4/core";
|
|
392
|
-
|
|
393
|
-
// ../../node_modules/.pnpm/eventsource-parser@3.1.0/node_modules/eventsource-parser/dist/index.js
|
|
394
|
-
var ParseError = class extends Error {
|
|
395
|
-
constructor(message, options) {
|
|
396
|
-
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
var LF = 10;
|
|
400
|
-
var CR = 13;
|
|
401
|
-
var SPACE = 32;
|
|
402
|
-
function noop(_arg) {
|
|
403
|
-
}
|
|
404
|
-
function createParser(config) {
|
|
405
|
-
if (typeof config == "function")
|
|
406
|
-
throw new TypeError(
|
|
407
|
-
"`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
|
|
408
|
-
);
|
|
409
|
-
const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config, pendingFragments = [];
|
|
410
|
-
let pendingFragmentsLength = 0, isFirstChunk = true, id, data = "", dataLines = 0, eventType, terminated = false;
|
|
411
|
-
function feed(chunk) {
|
|
412
|
-
if (terminated)
|
|
413
|
-
throw new Error(
|
|
414
|
-
"Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
|
|
415
|
-
);
|
|
416
|
-
if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
|
|
417
|
-
const trailing2 = processLines(chunk);
|
|
418
|
-
trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
if (chunk.indexOf(`
|
|
422
|
-
`) === -1 && chunk.indexOf("\r") === -1) {
|
|
423
|
-
pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
pendingFragments.push(chunk);
|
|
427
|
-
const input = pendingFragments.join("");
|
|
428
|
-
pendingFragments.length = 0, pendingFragmentsLength = 0;
|
|
429
|
-
const trailing = processLines(input);
|
|
430
|
-
trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
|
|
431
|
-
}
|
|
432
|
-
function checkBufferSize() {
|
|
433
|
-
maxBufferSize !== void 0 && (pendingFragmentsLength + data.length <= maxBufferSize || (terminated = true, pendingFragments.length = 0, pendingFragmentsLength = 0, id = void 0, data = "", dataLines = 0, eventType = void 0, onError(
|
|
434
|
-
new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
|
|
435
|
-
type: "max-buffer-size-exceeded"
|
|
436
|
-
})
|
|
437
|
-
)));
|
|
438
|
-
}
|
|
439
|
-
function processLines(chunk) {
|
|
440
|
-
let searchIndex = 0;
|
|
441
|
-
if (chunk.indexOf("\r") === -1) {
|
|
442
|
-
let lfIndex = chunk.indexOf(`
|
|
443
|
-
`, searchIndex);
|
|
444
|
-
for (; lfIndex !== -1; ) {
|
|
445
|
-
if (searchIndex === lfIndex) {
|
|
446
|
-
dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
447
|
-
`, searchIndex);
|
|
448
|
-
continue;
|
|
449
|
-
}
|
|
450
|
-
const firstCharCode = chunk.charCodeAt(searchIndex);
|
|
451
|
-
if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
|
|
452
|
-
const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
|
|
453
|
-
if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
|
|
454
|
-
onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
|
|
455
|
-
`, searchIndex);
|
|
456
|
-
continue;
|
|
457
|
-
}
|
|
458
|
-
data = dataLines === 0 ? value : `${data}
|
|
459
|
-
${value}`, dataLines++;
|
|
460
|
-
} else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
|
|
461
|
-
chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
|
|
462
|
-
lfIndex
|
|
463
|
-
) || void 0 : parseLine(chunk, searchIndex, lfIndex);
|
|
464
|
-
searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
465
|
-
`, searchIndex);
|
|
466
|
-
}
|
|
467
|
-
return chunk.slice(searchIndex);
|
|
468
|
-
}
|
|
469
|
-
for (; searchIndex < chunk.length; ) {
|
|
470
|
-
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
471
|
-
`, searchIndex);
|
|
472
|
-
let lineEnd = -1;
|
|
473
|
-
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)
|
|
474
|
-
break;
|
|
475
|
-
parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
|
|
476
|
-
}
|
|
477
|
-
return chunk.slice(searchIndex);
|
|
478
|
-
}
|
|
479
|
-
function parseLine(chunk, start, end) {
|
|
480
|
-
if (start === end) {
|
|
481
|
-
dispatchEvent();
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
const firstCharCode = chunk.charCodeAt(start);
|
|
485
|
-
if (isDataPrefix(chunk, start, firstCharCode)) {
|
|
486
|
-
const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
|
|
487
|
-
data = dataLines === 0 ? value2 : `${data}
|
|
488
|
-
${value2}`, dataLines++;
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
if (isEventPrefix(chunk, start, firstCharCode)) {
|
|
492
|
-
eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
|
|
496
|
-
const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
|
|
497
|
-
id = value2.includes("\0") ? void 0 : value2;
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
if (firstCharCode === 58) {
|
|
501
|
-
if (onComment) {
|
|
502
|
-
const line2 = chunk.slice(start, end);
|
|
503
|
-
onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
|
|
504
|
-
}
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
|
|
508
|
-
if (fieldSeparatorIndex === -1) {
|
|
509
|
-
processField(line, "", line);
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
|
-
const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
513
|
-
processField(field, value, line);
|
|
514
|
-
}
|
|
515
|
-
function processField(field, value, line) {
|
|
516
|
-
switch (field) {
|
|
517
|
-
case "event":
|
|
518
|
-
eventType = value || void 0;
|
|
519
|
-
break;
|
|
520
|
-
case "data":
|
|
521
|
-
data = dataLines === 0 ? value : `${data}
|
|
522
|
-
${value}`, dataLines++;
|
|
523
|
-
break;
|
|
524
|
-
case "id":
|
|
525
|
-
id = value.includes("\0") ? void 0 : value;
|
|
526
|
-
break;
|
|
527
|
-
case "retry":
|
|
528
|
-
/^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
|
|
529
|
-
new ParseError(`Invalid \`retry\` value: "${value}"`, {
|
|
530
|
-
type: "invalid-retry",
|
|
531
|
-
value,
|
|
532
|
-
line
|
|
533
|
-
})
|
|
534
|
-
);
|
|
535
|
-
break;
|
|
536
|
-
default:
|
|
537
|
-
onError(
|
|
538
|
-
new ParseError(
|
|
539
|
-
`Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
|
|
540
|
-
{ type: "unknown-field", field, value, line }
|
|
541
|
-
)
|
|
542
|
-
);
|
|
543
|
-
break;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
function dispatchEvent() {
|
|
547
|
-
dataLines > 0 && onEvent({
|
|
548
|
-
id,
|
|
549
|
-
event: eventType,
|
|
550
|
-
data
|
|
551
|
-
}), id = void 0, data = "", dataLines = 0, eventType = void 0;
|
|
552
|
-
}
|
|
553
|
-
function reset(options = {}) {
|
|
554
|
-
if (options.consume && pendingFragments.length > 0) {
|
|
555
|
-
const incompleteLine = pendingFragments.join("");
|
|
556
|
-
parseLine(incompleteLine, 0, incompleteLine.length);
|
|
557
|
-
}
|
|
558
|
-
isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = false;
|
|
559
|
-
}
|
|
560
|
-
return { feed, reset };
|
|
561
|
-
}
|
|
562
|
-
function isDataPrefix(chunk, i, firstCharCode) {
|
|
563
|
-
return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
|
|
564
|
-
}
|
|
565
|
-
function isEventPrefix(chunk, i, firstCharCode) {
|
|
566
|
-
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;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
// ../../node_modules/.pnpm/eventsource-parser@3.1.0/node_modules/eventsource-parser/dist/stream.js
|
|
570
|
-
var EventSourceParserStream = class extends TransformStream {
|
|
571
|
-
constructor({ onError, onRetry, onComment, maxBufferSize } = {}) {
|
|
572
|
-
let parser;
|
|
573
|
-
super({
|
|
574
|
-
start(controller) {
|
|
575
|
-
parser = createParser({
|
|
576
|
-
onEvent: (event) => {
|
|
577
|
-
controller.enqueue(event);
|
|
578
|
-
},
|
|
579
|
-
onError(error) {
|
|
580
|
-
typeof onError == "function" && onError(error), (onError === "terminate" || error.type === "max-buffer-size-exceeded") && controller.error(error);
|
|
581
|
-
},
|
|
582
|
-
onRetry,
|
|
583
|
-
onComment,
|
|
584
|
-
maxBufferSize
|
|
585
|
-
});
|
|
586
|
-
},
|
|
587
|
-
transform(chunk) {
|
|
588
|
-
parser.feed(chunk);
|
|
589
|
-
}
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
};
|
|
593
|
-
|
|
594
|
-
// ../../node_modules/.pnpm/@workflow+serde@4.1.0/node_modules/@workflow/serde/dist/index.js
|
|
595
|
-
var WORKFLOW_SERIALIZE = /* @__PURE__ */ Symbol.for("workflow-serialize");
|
|
596
|
-
var WORKFLOW_DESERIALIZE = /* @__PURE__ */ Symbol.for("workflow-deserialize");
|
|
597
|
-
|
|
598
|
-
// ../../node_modules/.pnpm/@ai-sdk+provider-utils@5.0.27_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.js
|
|
599
|
-
function asArray(value) {
|
|
600
|
-
return value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
|
601
|
-
}
|
|
602
|
-
function combineHeaders(...headers) {
|
|
603
|
-
return headers.reduce(
|
|
604
|
-
(combinedHeaders, currentHeaders) => ({
|
|
605
|
-
...combinedHeaders,
|
|
606
|
-
...currentHeaders != null ? currentHeaders : {}
|
|
607
|
-
}),
|
|
608
|
-
{}
|
|
609
|
-
);
|
|
610
|
-
}
|
|
611
|
-
function removeUndefinedEntries(record) {
|
|
612
|
-
return Object.fromEntries(
|
|
613
|
-
Object.entries(record).filter(([_key, value]) => value != null)
|
|
614
|
-
);
|
|
615
|
-
}
|
|
616
|
-
async function delay(delayInMs, options) {
|
|
617
|
-
if (delayInMs == null) {
|
|
618
|
-
return Promise.resolve();
|
|
619
|
-
}
|
|
620
|
-
const signal = options == null ? void 0 : options.abortSignal;
|
|
621
|
-
return new Promise((resolve2, reject) => {
|
|
622
|
-
if (signal == null ? void 0 : signal.aborted) {
|
|
623
|
-
reject(createAbortError());
|
|
624
|
-
return;
|
|
625
|
-
}
|
|
626
|
-
const timeoutId = setTimeout(() => {
|
|
627
|
-
cleanup();
|
|
628
|
-
resolve2();
|
|
629
|
-
}, delayInMs);
|
|
630
|
-
const cleanup = () => {
|
|
631
|
-
clearTimeout(timeoutId);
|
|
632
|
-
signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
|
|
633
|
-
};
|
|
634
|
-
const onAbort = () => {
|
|
635
|
-
cleanup();
|
|
636
|
-
reject(createAbortError());
|
|
637
|
-
};
|
|
638
|
-
signal == null ? void 0 : signal.addEventListener("abort", onAbort);
|
|
639
|
-
});
|
|
640
|
-
}
|
|
641
|
-
function createAbortError() {
|
|
642
|
-
return new DOMException("Delay was aborted", "AbortError");
|
|
643
|
-
}
|
|
644
|
-
function getWebSocketConstructor(webSocket) {
|
|
645
|
-
const WebSocketConstructor = webSocket != null ? webSocket : globalThis.WebSocket;
|
|
646
|
-
if (WebSocketConstructor == null) {
|
|
647
|
-
throw new Error("No WebSocket implementation available.");
|
|
648
|
-
}
|
|
649
|
-
return WebSocketConstructor;
|
|
650
|
-
}
|
|
651
|
-
function toWebSocketUrl(url) {
|
|
652
|
-
const wsUrl = new URL(url);
|
|
653
|
-
if (wsUrl.protocol === "http:") {
|
|
654
|
-
wsUrl.protocol = "ws:";
|
|
655
|
-
} else if (wsUrl.protocol === "https:") {
|
|
656
|
-
wsUrl.protocol = "wss:";
|
|
657
|
-
}
|
|
658
|
-
return wsUrl;
|
|
659
|
-
}
|
|
660
|
-
var textDecoder = new TextDecoder();
|
|
661
|
-
async function readWebSocketMessageText(data) {
|
|
662
|
-
if (typeof data === "string") return data;
|
|
663
|
-
if (data instanceof ArrayBuffer) return textDecoder.decode(data);
|
|
664
|
-
if (ArrayBuffer.isView(data)) {
|
|
665
|
-
return textDecoder.decode(data);
|
|
666
|
-
}
|
|
667
|
-
if (typeof Blob !== "undefined" && data instanceof Blob) {
|
|
668
|
-
return data.text();
|
|
669
|
-
}
|
|
670
|
-
return String(data);
|
|
671
|
-
}
|
|
672
|
-
var WEBSOCKET_OPEN_STATE = 1;
|
|
673
|
-
async function waitForWebSocketBufferDrain(socket, {
|
|
674
|
-
highWaterMark = 1024 * 1024,
|
|
675
|
-
pollIntervalMs = 20,
|
|
676
|
-
abortSignal
|
|
677
|
-
} = {}) {
|
|
678
|
-
var _a32;
|
|
679
|
-
while (socket.readyState === WEBSOCKET_OPEN_STATE && ((_a32 = socket.bufferedAmount) != null ? _a32 : 0) > highWaterMark) {
|
|
680
|
-
if ((abortSignal == null ? void 0 : abortSignal.aborted) === true) {
|
|
681
|
-
return;
|
|
682
|
-
}
|
|
683
|
-
await delay(pollIntervalMs);
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
function connectToWebSocket({
|
|
687
|
-
url,
|
|
688
|
-
protocols,
|
|
689
|
-
headers,
|
|
690
|
-
webSocket,
|
|
691
|
-
abortSignal,
|
|
692
|
-
onOpen,
|
|
693
|
-
onMessageText,
|
|
694
|
-
onProcessingError,
|
|
695
|
-
onSocketError,
|
|
696
|
-
onClose,
|
|
697
|
-
onAbort
|
|
698
|
-
}) {
|
|
699
|
-
var _a32;
|
|
700
|
-
let socket;
|
|
701
|
-
let abortListener;
|
|
702
|
-
const close = (code) => {
|
|
703
|
-
if (abortListener != null) {
|
|
704
|
-
abortSignal == null ? void 0 : abortSignal.removeEventListener("abort", abortListener);
|
|
705
|
-
abortListener = void 0;
|
|
706
|
-
}
|
|
707
|
-
try {
|
|
708
|
-
socket == null ? void 0 : socket.close(code);
|
|
709
|
-
} catch (e) {
|
|
710
|
-
}
|
|
711
|
-
};
|
|
712
|
-
if (abortSignal == null ? void 0 : abortSignal.aborted) {
|
|
713
|
-
onAbort == null ? void 0 : onAbort((_a32 = abortSignal.reason) != null ? _a32 : new Error("Aborted"));
|
|
714
|
-
return { socket: void 0, close };
|
|
715
|
-
}
|
|
716
|
-
try {
|
|
717
|
-
const WebSocketConstructor = getWebSocketConstructor(webSocket);
|
|
718
|
-
socket = new WebSocketConstructor(url, protocols, {
|
|
719
|
-
headers: removeUndefinedEntries(headers != null ? headers : {})
|
|
720
|
-
});
|
|
721
|
-
} catch (error) {
|
|
722
|
-
onProcessingError(error);
|
|
723
|
-
return { socket: void 0, close };
|
|
724
|
-
}
|
|
725
|
-
if (abortSignal != null && onAbort != null) {
|
|
726
|
-
abortListener = () => {
|
|
727
|
-
var _a42;
|
|
728
|
-
return onAbort((_a42 = abortSignal.reason) != null ? _a42 : new Error("Aborted"));
|
|
729
|
-
};
|
|
730
|
-
abortSignal.addEventListener("abort", abortListener, { once: true });
|
|
731
|
-
}
|
|
732
|
-
const openedSocket = socket;
|
|
733
|
-
socket.onopen = () => {
|
|
734
|
-
try {
|
|
735
|
-
onOpen == null ? void 0 : onOpen(openedSocket);
|
|
736
|
-
} catch (error) {
|
|
737
|
-
onProcessingError(error);
|
|
738
|
-
}
|
|
739
|
-
};
|
|
740
|
-
let tail = Promise.resolve();
|
|
741
|
-
socket.onmessage = (event) => {
|
|
742
|
-
tail = tail.then(() => readWebSocketMessageText(event.data)).then((text) => onMessageText(text)).catch(onProcessingError);
|
|
743
|
-
};
|
|
744
|
-
socket.onerror = () => {
|
|
745
|
-
tail = tail.then(() => onSocketError == null ? void 0 : onSocketError()).catch(onProcessingError);
|
|
746
|
-
};
|
|
747
|
-
socket.onclose = (event) => {
|
|
748
|
-
const closeEvent = event;
|
|
749
|
-
const code = typeof (closeEvent == null ? void 0 : closeEvent.code) === "number" ? closeEvent.code : void 0;
|
|
750
|
-
const reason = typeof (closeEvent == null ? void 0 : closeEvent.reason) === "string" ? closeEvent.reason : void 0;
|
|
751
|
-
tail = tail.then(() => onClose == null ? void 0 : onClose({ code, reason })).catch(onProcessingError);
|
|
752
|
-
};
|
|
753
|
-
return { socket, close };
|
|
754
|
-
}
|
|
755
|
-
function convertAsyncIteratorToReadableStream(iterator) {
|
|
756
|
-
let cancelled = false;
|
|
757
|
-
return new ReadableStream({
|
|
758
|
-
/**
|
|
759
|
-
* Called when the consumer wants to pull more data from the stream.
|
|
760
|
-
*
|
|
761
|
-
* @param {ReadableStreamDefaultController<T>} controller - The controller to enqueue data into the stream.
|
|
762
|
-
* @returns {Promise<void>}
|
|
763
|
-
*/
|
|
764
|
-
async pull(controller) {
|
|
765
|
-
if (cancelled) return;
|
|
766
|
-
try {
|
|
767
|
-
const { value, done } = await iterator.next();
|
|
768
|
-
if (done) {
|
|
769
|
-
controller.close();
|
|
770
|
-
} else {
|
|
771
|
-
controller.enqueue(value);
|
|
772
|
-
}
|
|
773
|
-
} catch (error) {
|
|
774
|
-
controller.error(error);
|
|
775
|
-
}
|
|
776
|
-
},
|
|
777
|
-
/**
|
|
778
|
-
* Called when the consumer cancels the stream.
|
|
779
|
-
*/
|
|
780
|
-
async cancel(reason) {
|
|
781
|
-
cancelled = true;
|
|
782
|
-
if (iterator.return) {
|
|
783
|
-
try {
|
|
784
|
-
await iterator.return(reason);
|
|
785
|
-
} catch (e) {
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
});
|
|
790
|
-
}
|
|
791
|
-
var { btoa, atob } = globalThis;
|
|
792
|
-
function convertBase64ToUint8Array(base64String) {
|
|
793
|
-
const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
|
794
|
-
const latin1string = atob(base64Url);
|
|
795
|
-
return Uint8Array.from(latin1string, (byte) => byte.codePointAt(0));
|
|
796
|
-
}
|
|
797
|
-
function convertUint8ArrayToBase64(array) {
|
|
798
|
-
let latin1string = "";
|
|
799
|
-
for (let i = 0; i < array.length; i++) {
|
|
800
|
-
latin1string += String.fromCodePoint(array[i]);
|
|
801
|
-
}
|
|
802
|
-
return btoa(latin1string);
|
|
803
|
-
}
|
|
804
|
-
function convertToBase64(value) {
|
|
805
|
-
return value instanceof Uint8Array ? convertUint8ArrayToBase64(value) : value;
|
|
806
|
-
}
|
|
807
|
-
function convertInlineFileDataToUint8Array(data) {
|
|
808
|
-
if (data.type === "text") {
|
|
809
|
-
return new TextEncoder().encode(data.text);
|
|
810
|
-
}
|
|
811
|
-
if (data.data instanceof Uint8Array) {
|
|
812
|
-
return data.data;
|
|
813
|
-
}
|
|
814
|
-
if (data.data instanceof ArrayBuffer) {
|
|
815
|
-
return new Uint8Array(data.data);
|
|
816
|
-
}
|
|
817
|
-
return convertBase64ToUint8Array(data.data);
|
|
818
|
-
}
|
|
819
|
-
function convertToFormData(input, options = {}) {
|
|
820
|
-
const { useArrayBrackets = true } = options;
|
|
821
|
-
const formData = new FormData();
|
|
822
|
-
for (const [key, value] of Object.entries(input)) {
|
|
823
|
-
if (value == null) {
|
|
824
|
-
continue;
|
|
825
|
-
}
|
|
826
|
-
if (Array.isArray(value)) {
|
|
827
|
-
if (value.length === 1) {
|
|
828
|
-
formData.append(key, value[0]);
|
|
829
|
-
continue;
|
|
830
|
-
}
|
|
831
|
-
const arrayKey = useArrayBrackets ? `${key}[]` : key;
|
|
832
|
-
for (const item of value) {
|
|
833
|
-
formData.append(arrayKey, item);
|
|
834
|
-
}
|
|
835
|
-
continue;
|
|
836
|
-
}
|
|
837
|
-
formData.append(key, value);
|
|
838
|
-
}
|
|
839
|
-
return formData;
|
|
840
|
-
}
|
|
841
|
-
function createLanguageModelResponseMetadata({
|
|
842
|
-
id,
|
|
843
|
-
model,
|
|
844
|
-
created
|
|
845
|
-
}) {
|
|
846
|
-
return {
|
|
847
|
-
id: id != null ? id : void 0,
|
|
848
|
-
modelId: model != null ? model : void 0,
|
|
849
|
-
timestamp: created != null ? new Date(created * 1e3) : void 0
|
|
850
|
-
};
|
|
851
|
-
}
|
|
852
|
-
function createNullLanguageModelUsage() {
|
|
853
|
-
return {
|
|
854
|
-
inputTokens: {
|
|
855
|
-
total: void 0,
|
|
856
|
-
noCache: void 0,
|
|
857
|
-
cacheRead: void 0,
|
|
858
|
-
cacheWrite: void 0
|
|
859
|
-
},
|
|
860
|
-
outputTokens: {
|
|
861
|
-
total: void 0,
|
|
862
|
-
text: void 0,
|
|
863
|
-
reasoning: void 0
|
|
864
|
-
},
|
|
865
|
-
raw: void 0
|
|
866
|
-
};
|
|
867
|
-
}
|
|
868
|
-
function createToolNameMapping({
|
|
869
|
-
tools = [],
|
|
870
|
-
providerToolNames
|
|
871
|
-
}) {
|
|
872
|
-
const customToolNameToProviderToolName = {};
|
|
873
|
-
const providerToolNameToCustomToolName = {};
|
|
874
|
-
for (const tool2 of tools) {
|
|
875
|
-
if (tool2.type === "provider" && tool2.id in providerToolNames) {
|
|
876
|
-
const providerToolName = providerToolNames[tool2.id];
|
|
877
|
-
customToolNameToProviderToolName[tool2.name] = providerToolName;
|
|
878
|
-
providerToolNameToCustomToolName[providerToolName] = tool2.name;
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
return {
|
|
882
|
-
toProviderToolName: (customToolName) => {
|
|
883
|
-
var _a32;
|
|
884
|
-
return (_a32 = customToolNameToProviderToolName[customToolName]) != null ? _a32 : customToolName;
|
|
885
|
-
},
|
|
886
|
-
toCustomToolName: (providerToolName) => {
|
|
887
|
-
var _a32;
|
|
888
|
-
return (_a32 = providerToolNameToCustomToolName[providerToolName]) != null ? _a32 : providerToolName;
|
|
889
|
-
}
|
|
890
|
-
};
|
|
891
|
-
}
|
|
892
|
-
var DelayedPromise = class {
|
|
893
|
-
constructor() {
|
|
894
|
-
this.status = { type: "pending" };
|
|
895
|
-
this._resolve = void 0;
|
|
896
|
-
this._reject = void 0;
|
|
897
|
-
}
|
|
898
|
-
get promise() {
|
|
899
|
-
if (this._promise) {
|
|
900
|
-
return this._promise;
|
|
901
|
-
}
|
|
902
|
-
this._promise = new Promise((resolve2, reject) => {
|
|
903
|
-
if (this.status.type === "resolved") {
|
|
904
|
-
resolve2(this.status.value);
|
|
905
|
-
} else if (this.status.type === "rejected") {
|
|
906
|
-
reject(this.status.error);
|
|
907
|
-
}
|
|
908
|
-
this._resolve = resolve2;
|
|
909
|
-
this._reject = reject;
|
|
910
|
-
});
|
|
911
|
-
return this._promise;
|
|
912
|
-
}
|
|
913
|
-
resolve(value) {
|
|
914
|
-
var _a32;
|
|
915
|
-
this.status = { type: "resolved", value };
|
|
916
|
-
if (this._promise) {
|
|
917
|
-
(_a32 = this._resolve) == null ? void 0 : _a32.call(this, value);
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
reject(error) {
|
|
921
|
-
var _a32;
|
|
922
|
-
this.status = { type: "rejected", error };
|
|
923
|
-
if (this._promise) {
|
|
924
|
-
(_a32 = this._reject) == null ? void 0 : _a32.call(this, error);
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
isResolved() {
|
|
928
|
-
return this.status.type === "resolved";
|
|
929
|
-
}
|
|
930
|
-
isRejected() {
|
|
931
|
-
return this.status.type === "rejected";
|
|
932
|
-
}
|
|
933
|
-
isPending() {
|
|
934
|
-
return this.status.type === "pending";
|
|
935
|
-
}
|
|
936
|
-
};
|
|
937
|
-
var imageMediaTypeSignatures = [
|
|
938
|
-
{
|
|
939
|
-
mediaType: "image/gif",
|
|
940
|
-
bytesPrefix: [71, 73, 70]
|
|
941
|
-
// GIF
|
|
942
|
-
},
|
|
943
|
-
{
|
|
944
|
-
mediaType: "image/png",
|
|
945
|
-
bytesPrefix: [137, 80, 78, 71]
|
|
946
|
-
// PNG
|
|
947
|
-
},
|
|
948
|
-
{
|
|
949
|
-
mediaType: "image/jpeg",
|
|
950
|
-
bytesPrefix: [255, 216]
|
|
951
|
-
// JPEG
|
|
952
|
-
},
|
|
953
|
-
{
|
|
954
|
-
mediaType: "image/webp",
|
|
955
|
-
bytesPrefix: [
|
|
956
|
-
82,
|
|
957
|
-
73,
|
|
958
|
-
70,
|
|
959
|
-
70,
|
|
960
|
-
// "RIFF"
|
|
961
|
-
null,
|
|
962
|
-
null,
|
|
963
|
-
null,
|
|
964
|
-
null,
|
|
965
|
-
// file size (variable)
|
|
966
|
-
87,
|
|
967
|
-
69,
|
|
968
|
-
66,
|
|
969
|
-
80
|
|
970
|
-
// "WEBP"
|
|
971
|
-
]
|
|
972
|
-
},
|
|
973
|
-
{
|
|
974
|
-
mediaType: "image/bmp",
|
|
975
|
-
bytesPrefix: [66, 77]
|
|
976
|
-
},
|
|
977
|
-
{
|
|
978
|
-
mediaType: "image/tiff",
|
|
979
|
-
bytesPrefix: [73, 73, 42, 0]
|
|
980
|
-
},
|
|
981
|
-
{
|
|
982
|
-
mediaType: "image/tiff",
|
|
983
|
-
bytesPrefix: [77, 77, 0, 42]
|
|
984
|
-
},
|
|
985
|
-
{
|
|
986
|
-
mediaType: "image/avif",
|
|
987
|
-
bytesPrefix: [
|
|
988
|
-
0,
|
|
989
|
-
0,
|
|
990
|
-
0,
|
|
991
|
-
32,
|
|
992
|
-
102,
|
|
993
|
-
116,
|
|
994
|
-
121,
|
|
995
|
-
112,
|
|
996
|
-
97,
|
|
997
|
-
118,
|
|
998
|
-
105,
|
|
999
|
-
102
|
|
1000
|
-
]
|
|
1001
|
-
},
|
|
1002
|
-
{
|
|
1003
|
-
mediaType: "image/heic",
|
|
1004
|
-
bytesPrefix: [
|
|
1005
|
-
0,
|
|
1006
|
-
0,
|
|
1007
|
-
0,
|
|
1008
|
-
32,
|
|
1009
|
-
102,
|
|
1010
|
-
116,
|
|
1011
|
-
121,
|
|
1012
|
-
112,
|
|
1013
|
-
104,
|
|
1014
|
-
101,
|
|
1015
|
-
105,
|
|
1016
|
-
99
|
|
1017
|
-
]
|
|
1018
|
-
}
|
|
1019
|
-
];
|
|
1020
|
-
var documentMediaTypeSignatures = [
|
|
1021
|
-
{
|
|
1022
|
-
mediaType: "application/pdf",
|
|
1023
|
-
bytesPrefix: [37, 80, 68, 70]
|
|
1024
|
-
// %PDF
|
|
1025
|
-
}
|
|
1026
|
-
];
|
|
1027
|
-
var audioMediaTypeSignaturesWithoutMp4 = [
|
|
1028
|
-
{
|
|
1029
|
-
mediaType: "audio/mpeg",
|
|
1030
|
-
bytesPrefix: [255, 251]
|
|
1031
|
-
},
|
|
1032
|
-
{
|
|
1033
|
-
mediaType: "audio/mpeg",
|
|
1034
|
-
bytesPrefix: [255, 250]
|
|
1035
|
-
},
|
|
1036
|
-
{
|
|
1037
|
-
mediaType: "audio/mpeg",
|
|
1038
|
-
bytesPrefix: [255, 243]
|
|
1039
|
-
},
|
|
1040
|
-
{
|
|
1041
|
-
mediaType: "audio/mpeg",
|
|
1042
|
-
bytesPrefix: [255, 242]
|
|
1043
|
-
},
|
|
1044
|
-
{
|
|
1045
|
-
mediaType: "audio/mpeg",
|
|
1046
|
-
bytesPrefix: [255, 227]
|
|
1047
|
-
},
|
|
1048
|
-
{
|
|
1049
|
-
mediaType: "audio/mpeg",
|
|
1050
|
-
bytesPrefix: [255, 226]
|
|
1051
|
-
},
|
|
1052
|
-
{
|
|
1053
|
-
mediaType: "audio/wav",
|
|
1054
|
-
bytesPrefix: [
|
|
1055
|
-
82,
|
|
1056
|
-
// R
|
|
1057
|
-
73,
|
|
1058
|
-
// I
|
|
1059
|
-
70,
|
|
1060
|
-
// F
|
|
1061
|
-
70,
|
|
1062
|
-
// F
|
|
1063
|
-
null,
|
|
1064
|
-
null,
|
|
1065
|
-
null,
|
|
1066
|
-
null,
|
|
1067
|
-
87,
|
|
1068
|
-
// W
|
|
1069
|
-
65,
|
|
1070
|
-
// A
|
|
1071
|
-
86,
|
|
1072
|
-
// V
|
|
1073
|
-
69
|
|
1074
|
-
// E
|
|
1075
|
-
]
|
|
1076
|
-
},
|
|
1077
|
-
{
|
|
1078
|
-
mediaType: "audio/ogg",
|
|
1079
|
-
bytesPrefix: [79, 103, 103, 83]
|
|
1080
|
-
},
|
|
1081
|
-
{
|
|
1082
|
-
mediaType: "audio/flac",
|
|
1083
|
-
bytesPrefix: [102, 76, 97, 67]
|
|
1084
|
-
},
|
|
1085
|
-
{
|
|
1086
|
-
mediaType: "audio/aac",
|
|
1087
|
-
bytesPrefix: [64, 21, 0, 0]
|
|
1088
|
-
},
|
|
1089
|
-
{
|
|
1090
|
-
mediaType: "audio/webm",
|
|
1091
|
-
bytesPrefix: [26, 69, 223, 163]
|
|
1092
|
-
}
|
|
1093
|
-
];
|
|
1094
|
-
var audioMediaTypeSignatures = [
|
|
1095
|
-
...audioMediaTypeSignaturesWithoutMp4,
|
|
1096
|
-
{
|
|
1097
|
-
mediaType: "audio/mp4",
|
|
1098
|
-
bytesPrefix: [
|
|
1099
|
-
0,
|
|
1100
|
-
0,
|
|
1101
|
-
0,
|
|
1102
|
-
null,
|
|
1103
|
-
102,
|
|
1104
|
-
116,
|
|
1105
|
-
121,
|
|
1106
|
-
112
|
|
1107
|
-
// ftyp
|
|
1108
|
-
]
|
|
1109
|
-
}
|
|
1110
|
-
];
|
|
1111
|
-
var videoMediaTypeSignatures = [
|
|
1112
|
-
{
|
|
1113
|
-
mediaType: "video/mp4",
|
|
1114
|
-
bytesPrefix: [
|
|
1115
|
-
0,
|
|
1116
|
-
0,
|
|
1117
|
-
0,
|
|
1118
|
-
null,
|
|
1119
|
-
102,
|
|
1120
|
-
116,
|
|
1121
|
-
121,
|
|
1122
|
-
112
|
|
1123
|
-
// ftyp
|
|
1124
|
-
]
|
|
1125
|
-
},
|
|
1126
|
-
{
|
|
1127
|
-
mediaType: "video/webm",
|
|
1128
|
-
bytesPrefix: [26, 69, 223, 163]
|
|
1129
|
-
// EBML
|
|
1130
|
-
},
|
|
1131
|
-
{
|
|
1132
|
-
mediaType: "video/quicktime",
|
|
1133
|
-
bytesPrefix: [
|
|
1134
|
-
0,
|
|
1135
|
-
0,
|
|
1136
|
-
0,
|
|
1137
|
-
20,
|
|
1138
|
-
102,
|
|
1139
|
-
116,
|
|
1140
|
-
121,
|
|
1141
|
-
112,
|
|
1142
|
-
113,
|
|
1143
|
-
116
|
|
1144
|
-
// ftypqt
|
|
1145
|
-
]
|
|
1146
|
-
},
|
|
1147
|
-
{
|
|
1148
|
-
mediaType: "video/x-msvideo",
|
|
1149
|
-
bytesPrefix: [82, 73, 70, 70]
|
|
1150
|
-
// RIFF (AVI)
|
|
1151
|
-
}
|
|
1152
|
-
];
|
|
1153
|
-
var DEFAULT_SNIFF_BYTES = 18;
|
|
1154
|
-
var MAX_SIGNATURE_BYTES = 12;
|
|
1155
|
-
var MAX_ID3_TAG_BYTES = 128 * 1024;
|
|
1156
|
-
var ID3_SCAN_BYTES = MAX_ID3_TAG_BYTES + MAX_SIGNATURE_BYTES;
|
|
1157
|
-
function decodePrefix(data, maxBytes) {
|
|
1158
|
-
if (typeof data !== "string") {
|
|
1159
|
-
return data.length > maxBytes ? data.subarray(0, maxBytes) : data;
|
|
1160
|
-
}
|
|
1161
|
-
const maxChars = Math.ceil(maxBytes / 3) * 4;
|
|
1162
|
-
const bytes = convertBase64ToUint8Array(
|
|
1163
|
-
data.substring(0, Math.min(data.length, maxChars))
|
|
1164
|
-
);
|
|
1165
|
-
return bytes.length > maxBytes ? bytes.subarray(0, maxBytes) : bytes;
|
|
1166
|
-
}
|
|
1167
|
-
function hasID3(bytes) {
|
|
1168
|
-
return bytes.length > 10 && bytes[0] === 73 && // 'I'
|
|
1169
|
-
bytes[1] === 68 && // 'D'
|
|
1170
|
-
bytes[2] === 51;
|
|
1171
|
-
}
|
|
1172
|
-
var stripID3 = (bytes) => {
|
|
1173
|
-
const id3Size = (bytes[6] & 127) << 21 | (bytes[7] & 127) << 14 | (bytes[8] & 127) << 7 | bytes[9] & 127;
|
|
1174
|
-
return bytes.subarray(id3Size + 10);
|
|
1175
|
-
};
|
|
1176
|
-
function detectMediaTypeBySignatures({
|
|
1177
|
-
data,
|
|
1178
|
-
signatures
|
|
1179
|
-
}) {
|
|
1180
|
-
let bytes = decodePrefix(data, DEFAULT_SNIFF_BYTES);
|
|
1181
|
-
if (hasID3(bytes)) {
|
|
1182
|
-
bytes = stripID3(decodePrefix(data, ID3_SCAN_BYTES));
|
|
1183
|
-
}
|
|
1184
|
-
for (const signature of signatures) {
|
|
1185
|
-
if (bytes.length >= signature.bytesPrefix.length && signature.bytesPrefix.every(
|
|
1186
|
-
(byte, index) => byte === null || bytes[index] === byte
|
|
1187
|
-
)) {
|
|
1188
|
-
return signature.mediaType;
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
return void 0;
|
|
1192
|
-
}
|
|
1193
|
-
var topLevelSignatureTables = {
|
|
1194
|
-
image: imageMediaTypeSignatures,
|
|
1195
|
-
audio: audioMediaTypeSignatures,
|
|
1196
|
-
video: videoMediaTypeSignatures,
|
|
1197
|
-
application: documentMediaTypeSignatures
|
|
1198
|
-
};
|
|
1199
|
-
function detectMediaType({
|
|
1200
|
-
data,
|
|
1201
|
-
topLevelType
|
|
1202
|
-
}) {
|
|
1203
|
-
if (topLevelType === void 0) {
|
|
1204
|
-
return detectMediaTypeBySignatures({
|
|
1205
|
-
data,
|
|
1206
|
-
signatures: [
|
|
1207
|
-
...imageMediaTypeSignatures,
|
|
1208
|
-
...documentMediaTypeSignatures,
|
|
1209
|
-
// MP4 containers cannot be distinguished as audio or video by ftyp alone.
|
|
1210
|
-
// Preserve the generic detection result as video/mp4.
|
|
1211
|
-
...audioMediaTypeSignaturesWithoutMp4,
|
|
1212
|
-
...videoMediaTypeSignatures
|
|
1213
|
-
]
|
|
1214
|
-
});
|
|
1215
|
-
}
|
|
1216
|
-
const signatures = topLevelSignatureTables[topLevelType];
|
|
1217
|
-
if (signatures === void 0) {
|
|
1218
|
-
return void 0;
|
|
1219
|
-
}
|
|
1220
|
-
return detectMediaTypeBySignatures({ data, signatures });
|
|
1221
|
-
}
|
|
1222
|
-
function getTopLevelMediaType(mediaType) {
|
|
1223
|
-
const slashIndex = mediaType.indexOf("/");
|
|
1224
|
-
return slashIndex === -1 ? mediaType : mediaType.substring(0, slashIndex);
|
|
1225
|
-
}
|
|
1226
|
-
function isFullMediaType(mediaType) {
|
|
1227
|
-
const slashIndex = mediaType.indexOf("/");
|
|
1228
|
-
if (slashIndex === -1) {
|
|
1229
|
-
return false;
|
|
1230
|
-
}
|
|
1231
|
-
const subtype = mediaType.substring(slashIndex + 1);
|
|
1232
|
-
return subtype.length > 0 && subtype !== "*";
|
|
1233
|
-
}
|
|
1234
|
-
async function cancelResponseBody(response) {
|
|
1235
|
-
var _a32;
|
|
1236
|
-
try {
|
|
1237
|
-
await ((_a32 = response.body) == null ? void 0 : _a32.cancel());
|
|
1238
|
-
} catch (e) {
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
var name15 = "AI_DownloadError";
|
|
1242
|
-
var marker16 = `vercel.ai.error.${name15}`;
|
|
1243
|
-
var symbol16 = Symbol.for(marker16);
|
|
1244
|
-
var _a16;
|
|
1245
|
-
var _b16;
|
|
1246
|
-
var DownloadError = class extends (_b16 = AISDKError, _a16 = symbol16, _b16) {
|
|
1247
|
-
constructor({
|
|
1248
|
-
url,
|
|
1249
|
-
statusCode,
|
|
1250
|
-
statusText,
|
|
1251
|
-
cause,
|
|
1252
|
-
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
|
1253
|
-
}) {
|
|
1254
|
-
super({ name: name15, message, cause });
|
|
1255
|
-
this[_a16] = true;
|
|
1256
|
-
this.url = url;
|
|
1257
|
-
this.statusCode = statusCode;
|
|
1258
|
-
this.statusText = statusText;
|
|
1259
|
-
}
|
|
1260
|
-
static isInstance(error) {
|
|
1261
|
-
return AISDKError.hasMarker(error, marker16);
|
|
1262
|
-
}
|
|
1263
|
-
};
|
|
1264
|
-
function isBrowserRuntime(globalThisAny = globalThis) {
|
|
1265
|
-
return globalThisAny.window != null;
|
|
1266
|
-
}
|
|
1267
|
-
function isSameOrigin(url, baseUrl) {
|
|
1268
|
-
try {
|
|
1269
|
-
return new URL(url).origin === new URL(baseUrl).origin;
|
|
1270
|
-
} catch (e) {
|
|
1271
|
-
return false;
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
function validateDownloadUrl(url) {
|
|
1275
|
-
let parsed;
|
|
1276
|
-
try {
|
|
1277
|
-
parsed = new URL(url);
|
|
1278
|
-
} catch (e) {
|
|
1279
|
-
throw new DownloadError({
|
|
1280
|
-
url,
|
|
1281
|
-
message: `Invalid URL: ${url}`
|
|
1282
|
-
});
|
|
1283
|
-
}
|
|
1284
|
-
if (parsed.protocol === "data:") {
|
|
1285
|
-
return;
|
|
1286
|
-
}
|
|
1287
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
1288
|
-
throw new DownloadError({
|
|
1289
|
-
url,
|
|
1290
|
-
message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
|
|
1291
|
-
});
|
|
1292
|
-
}
|
|
1293
|
-
const hostname = parsed.hostname.toLowerCase().replace(/\.+$/, "");
|
|
1294
|
-
if (!hostname) {
|
|
1295
|
-
throw new DownloadError({
|
|
1296
|
-
url,
|
|
1297
|
-
message: `URL must have a hostname`
|
|
1298
|
-
});
|
|
1299
|
-
}
|
|
1300
|
-
if (hostname === "localhost" || hostname.endsWith(".local") || hostname.endsWith(".localhost")) {
|
|
1301
|
-
throw new DownloadError({
|
|
1302
|
-
url,
|
|
1303
|
-
message: `URL with hostname ${hostname} is not allowed`
|
|
1304
|
-
});
|
|
1305
|
-
}
|
|
1306
|
-
if (hostname.startsWith("[") && hostname.endsWith("]")) {
|
|
1307
|
-
const ipv6 = hostname.slice(1, -1);
|
|
1308
|
-
if (isPrivateIPv6(ipv6)) {
|
|
1309
|
-
throw new DownloadError({
|
|
1310
|
-
url,
|
|
1311
|
-
message: `URL with IPv6 address ${hostname} is not allowed`
|
|
1312
|
-
});
|
|
1313
|
-
}
|
|
1314
|
-
return;
|
|
1315
|
-
}
|
|
1316
|
-
if (isIPv4(hostname)) {
|
|
1317
|
-
if (isPrivateIPv4(hostname)) {
|
|
1318
|
-
throw new DownloadError({
|
|
1319
|
-
url,
|
|
1320
|
-
message: `URL with IP address ${hostname} is not allowed`
|
|
1321
|
-
});
|
|
1322
|
-
}
|
|
1323
|
-
return;
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
function validateDownloadAddress({
|
|
1327
|
-
address,
|
|
1328
|
-
family,
|
|
1329
|
-
hostname
|
|
1330
|
-
}) {
|
|
1331
|
-
const isUnsafe = family === 4 ? !isIPv4(address) || isPrivateIPv4(address) : family === 6 ? isPrivateIPv6(address) : true;
|
|
1332
|
-
if (isUnsafe) {
|
|
1333
|
-
throw new DownloadError({
|
|
1334
|
-
url: hostname,
|
|
1335
|
-
message: `Hostname ${hostname} resolved to disallowed IP address ${address}`
|
|
1336
|
-
});
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
function isIPv4(hostname) {
|
|
1340
|
-
const parts = hostname.split(".");
|
|
1341
|
-
if (parts.length !== 4) return false;
|
|
1342
|
-
return parts.every((part) => {
|
|
1343
|
-
const num = Number(part);
|
|
1344
|
-
return Number.isInteger(num) && num >= 0 && num <= 255 && String(num) === part;
|
|
1345
|
-
});
|
|
1346
|
-
}
|
|
1347
|
-
function isPrivateIPv4(ip) {
|
|
1348
|
-
const parts = ip.split(".").map(Number);
|
|
1349
|
-
const [a, b, c] = parts;
|
|
1350
|
-
if (a === 0) return true;
|
|
1351
|
-
if (a === 10) return true;
|
|
1352
|
-
if (a === 100 && b >= 64 && b <= 127) return true;
|
|
1353
|
-
if (a === 127) return true;
|
|
1354
|
-
if (a === 169 && b === 254) return true;
|
|
1355
|
-
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
1356
|
-
if (a === 192 && b === 0 && c === 0) return true;
|
|
1357
|
-
if (a === 192 && b === 0 && c === 2) return true;
|
|
1358
|
-
if (a === 192 && b === 168) return true;
|
|
1359
|
-
if (a === 198 && (b === 18 || b === 19)) return true;
|
|
1360
|
-
if (a === 198 && b === 51 && c === 100) return true;
|
|
1361
|
-
if (a === 203 && b === 0 && c === 113) return true;
|
|
1362
|
-
if (a >= 224) return true;
|
|
1363
|
-
return false;
|
|
1364
|
-
}
|
|
1365
|
-
function parseIPv6(ip) {
|
|
1366
|
-
let address = ip.toLowerCase();
|
|
1367
|
-
const zoneIndex = address.indexOf("%");
|
|
1368
|
-
if (zoneIndex !== -1) {
|
|
1369
|
-
address = address.slice(0, zoneIndex);
|
|
1370
|
-
}
|
|
1371
|
-
const halves = address.split("::");
|
|
1372
|
-
if (halves.length > 2) return null;
|
|
1373
|
-
const toGroups = (segment) => {
|
|
1374
|
-
if (segment === "") return [];
|
|
1375
|
-
const groups = [];
|
|
1376
|
-
const parts = segment.split(":");
|
|
1377
|
-
for (let i = 0; i < parts.length; i++) {
|
|
1378
|
-
const part = parts[i];
|
|
1379
|
-
if (part.includes(".")) {
|
|
1380
|
-
if (i !== parts.length - 1 || !isIPv4(part)) return null;
|
|
1381
|
-
const [a, b, c, d] = part.split(".").map(Number);
|
|
1382
|
-
groups.push(a << 8 | b, c << 8 | d);
|
|
1383
|
-
continue;
|
|
1384
|
-
}
|
|
1385
|
-
if (!/^[0-9a-f]{1,4}$/.test(part)) return null;
|
|
1386
|
-
groups.push(parseInt(part, 16));
|
|
1387
|
-
}
|
|
1388
|
-
return groups;
|
|
1389
|
-
};
|
|
1390
|
-
const head = toGroups(halves[0]);
|
|
1391
|
-
if (head === null) return null;
|
|
1392
|
-
if (halves.length === 2) {
|
|
1393
|
-
const tail = toGroups(halves[1]);
|
|
1394
|
-
if (tail === null) return null;
|
|
1395
|
-
const fill = 8 - head.length - tail.length;
|
|
1396
|
-
if (fill < 0) return null;
|
|
1397
|
-
return [...head, ...new Array(fill).fill(0), ...tail];
|
|
1398
|
-
}
|
|
1399
|
-
return head.length === 8 ? head : null;
|
|
1400
|
-
}
|
|
1401
|
-
function isPrivateIPv6(ip) {
|
|
1402
|
-
const groups = parseIPv6(ip);
|
|
1403
|
-
if (groups === null) return true;
|
|
1404
|
-
const topZero = (count) => groups.slice(0, count).every((group) => group === 0);
|
|
1405
|
-
if (topZero(7) && (groups[7] === 0 || groups[7] === 1)) return true;
|
|
1406
|
-
if ((groups[0] & 65024) === 64512) return true;
|
|
1407
|
-
if ((groups[0] & 65472) === 65152) return true;
|
|
1408
|
-
if ((groups[0] & 65472) === 65216) return true;
|
|
1409
|
-
if ((groups[0] & 65280) === 65280) return true;
|
|
1410
|
-
if (groups[0] === 8193 && groups[1] === 3512) return true;
|
|
1411
|
-
if (groups[0] === 16383 && (groups[1] & 61440) === 0) return true;
|
|
1412
|
-
const embedsIPv4 = (
|
|
1413
|
-
// ::/96 — IPv4-compatible (deprecated)
|
|
1414
|
-
topZero(6) || // ::ffff:0:0/96 — IPv4-mapped (ffff in group 5)
|
|
1415
|
-
topZero(5) && groups[5] === 65535 || // ::ffff:0:0/96 — IPv4-translated form (ffff in group 4, group 5 zero)
|
|
1416
|
-
topZero(4) && groups[4] === 65535 && groups[5] === 0 || // 64:ff9b::/96 — NAT64 well-known prefix
|
|
1417
|
-
groups[0] === 100 && groups[1] === 65435 && groups[2] === 0 && groups[3] === 0 && groups[4] === 0 && groups[5] === 0 || // 64:ff9b:1::/48 — NAT64 local-use prefix
|
|
1418
|
-
groups[0] === 100 && groups[1] === 65435 && groups[2] === 1
|
|
1419
|
-
);
|
|
1420
|
-
if (embedsIPv4) {
|
|
1421
|
-
const a = groups[6] >> 8 & 255;
|
|
1422
|
-
const b = groups[6] & 255;
|
|
1423
|
-
const c = groups[7] >> 8 & 255;
|
|
1424
|
-
const d = groups[7] & 255;
|
|
1425
|
-
return isPrivateIPv4(`${a}.${b}.${c}.${d}`);
|
|
1426
|
-
}
|
|
1427
|
-
return false;
|
|
1428
|
-
}
|
|
1429
|
-
function createSafeLookup(lookup) {
|
|
1430
|
-
return ((hostname, options, callback) => {
|
|
1431
|
-
lookup(hostname, { ...options, all: true }, (error, addresses) => {
|
|
1432
|
-
if (error) {
|
|
1433
|
-
callback(error);
|
|
1434
|
-
return;
|
|
1435
|
-
}
|
|
1436
|
-
try {
|
|
1437
|
-
const [firstAddress] = addresses;
|
|
1438
|
-
if (firstAddress == null) {
|
|
1439
|
-
throw new Error(`Hostname ${hostname} did not resolve to an address`);
|
|
1440
|
-
}
|
|
1441
|
-
for (const { address, family } of addresses) {
|
|
1442
|
-
validateDownloadAddress({ address, family, hostname });
|
|
1443
|
-
}
|
|
1444
|
-
if (options.all === true) {
|
|
1445
|
-
callback(null, addresses);
|
|
1446
|
-
} else {
|
|
1447
|
-
callback(
|
|
1448
|
-
null,
|
|
1449
|
-
firstAddress.address,
|
|
1450
|
-
firstAddress.family
|
|
1451
|
-
);
|
|
1452
|
-
}
|
|
1453
|
-
} catch (error2) {
|
|
1454
|
-
callback(
|
|
1455
|
-
error2 instanceof Error ? error2 : new Error(String(error2))
|
|
1456
|
-
);
|
|
1457
|
-
}
|
|
1458
|
-
});
|
|
1459
|
-
});
|
|
1460
|
-
}
|
|
1461
|
-
var safeNodeFetchPromise;
|
|
1462
|
-
var initialGlobalFetch = globalThis.fetch;
|
|
1463
|
-
var initialGlobalFetchIsNodeDefault = isNodeDefaultFetch(initialGlobalFetch);
|
|
1464
|
-
function isNodeRuntime() {
|
|
1465
|
-
var _a32, _b32;
|
|
1466
|
-
const runtimeProcess = globalThis.process;
|
|
1467
|
-
return ((_a32 = runtimeProcess == null ? void 0 : runtimeProcess.release) == null ? void 0 : _a32.name) === "node" && ((_b32 = runtimeProcess.versions) == null ? void 0 : _b32.bun) == null;
|
|
1468
|
-
}
|
|
1469
|
-
async function getDefaultDownloadFetch() {
|
|
1470
|
-
if (!isNodeRuntime() || !initialGlobalFetchIsNodeDefault || globalThis.fetch !== initialGlobalFetch) {
|
|
1471
|
-
return globalThis.fetch;
|
|
1472
|
-
}
|
|
1473
|
-
return safeNodeFetchPromise != null ? safeNodeFetchPromise : safeNodeFetchPromise = Promise.resolve().then(createSafeNodeFetch);
|
|
1474
|
-
}
|
|
1475
|
-
function isNodeDefaultFetch(fetch) {
|
|
1476
|
-
if (typeof fetch !== "function") {
|
|
1477
|
-
return false;
|
|
1478
|
-
}
|
|
1479
|
-
const source = Function.prototype.toString.call(fetch);
|
|
1480
|
-
return source.includes("internal/deps/undici") || source.includes("lazy loading of undici");
|
|
1481
|
-
}
|
|
1482
|
-
function createSafeNodeFetch() {
|
|
1483
|
-
const { createRequire } = loadBuiltinModule("node:module");
|
|
1484
|
-
const { lookup } = loadBuiltinModule("node:dns");
|
|
1485
|
-
const { Agent, fetch } = createRequire(getCurrentModulePath())(
|
|
1486
|
-
"undici"
|
|
1487
|
-
);
|
|
1488
|
-
const dispatcher = new Agent({
|
|
1489
|
-
connect: {
|
|
1490
|
-
lookup: createSafeLookup(lookup)
|
|
1491
|
-
}
|
|
1492
|
-
});
|
|
1493
|
-
return ((input, init) => fetch(
|
|
1494
|
-
input,
|
|
1495
|
-
{
|
|
1496
|
-
...init,
|
|
1497
|
-
dispatcher
|
|
1498
|
-
}
|
|
1499
|
-
));
|
|
1500
|
-
}
|
|
1501
|
-
function loadBuiltinModule(id) {
|
|
1502
|
-
var _a32;
|
|
1503
|
-
const processWithBuiltins = globalThis.process;
|
|
1504
|
-
const builtinModule = (_a32 = processWithBuiltins == null ? void 0 : processWithBuiltins.getBuiltinModule) == null ? void 0 : _a32.call(processWithBuiltins, id);
|
|
1505
|
-
if (builtinModule == null) {
|
|
1506
|
-
throw new Error(`Node.js built-in module ${id} is unavailable`);
|
|
1507
|
-
}
|
|
1508
|
-
return builtinModule;
|
|
1509
|
-
}
|
|
1510
|
-
function getCurrentModulePath() {
|
|
1511
|
-
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
1512
|
-
try {
|
|
1513
|
-
Error.prepareStackTrace = (_error, callSites) => callSites;
|
|
1514
|
-
const error = new Error("Capture current module path");
|
|
1515
|
-
Error.captureStackTrace(error, getCurrentModulePath);
|
|
1516
|
-
const [caller] = error.stack;
|
|
1517
|
-
const fileName = caller == null ? void 0 : caller.getFileName();
|
|
1518
|
-
if (fileName == null) {
|
|
1519
|
-
throw new Error("Unable to determine the current module path");
|
|
1520
|
-
}
|
|
1521
|
-
return fileName;
|
|
1522
|
-
} finally {
|
|
1523
|
-
Error.prepareStackTrace = originalPrepareStackTrace;
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
var BLOCKED_REQUEST_HEADERS = [
|
|
1527
|
-
// Hop-by-hop / transport (RFC 7230 §6.1)
|
|
1528
|
-
"connection",
|
|
1529
|
-
"keep-alive",
|
|
1530
|
-
"te",
|
|
1531
|
-
"trailer",
|
|
1532
|
-
"transfer-encoding",
|
|
1533
|
-
"upgrade",
|
|
1534
|
-
// Host / virtual-host routing
|
|
1535
|
-
"host",
|
|
1536
|
-
// Proxy / origin spoofing
|
|
1537
|
-
"forwarded",
|
|
1538
|
-
"proxy-authorization",
|
|
1539
|
-
"via",
|
|
1540
|
-
"x-forwarded-for",
|
|
1541
|
-
"x-forwarded-host",
|
|
1542
|
-
"x-forwarded-proto",
|
|
1543
|
-
"x-real-ip",
|
|
1544
|
-
// Cloud metadata (GCP, AWS IMDSv1/v2, Azure, Alibaba, DigitalOcean)
|
|
1545
|
-
"metadata",
|
|
1546
|
-
"metadata-flavor",
|
|
1547
|
-
"x-aws-ec2-metadata-token",
|
|
1548
|
-
"x-metadata-token",
|
|
1549
|
-
// Session / cookie
|
|
1550
|
-
"cookie",
|
|
1551
|
-
"set-cookie"
|
|
1552
|
-
];
|
|
1553
|
-
function sanitizeRequestHeaders(input) {
|
|
1554
|
-
const headers = new Headers(input);
|
|
1555
|
-
for (const name32 of BLOCKED_REQUEST_HEADERS) {
|
|
1556
|
-
headers.delete(name32);
|
|
1557
|
-
}
|
|
1558
|
-
return headers;
|
|
1559
|
-
}
|
|
1560
|
-
var MAX_DOWNLOAD_REDIRECTS = 10;
|
|
1561
|
-
var REDIRECT_STATUS_CODES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
1562
|
-
async function fetchWithValidatedRedirects({
|
|
1563
|
-
url,
|
|
1564
|
-
headers,
|
|
1565
|
-
abortSignal,
|
|
1566
|
-
maxRedirects = MAX_DOWNLOAD_REDIRECTS,
|
|
1567
|
-
fetch: customFetch,
|
|
1568
|
-
trustedOrigin
|
|
1569
|
-
}) {
|
|
1570
|
-
let currentHeaders = headers === void 0 ? void 0 : sanitizeRequestHeaders(headers);
|
|
1571
|
-
const perHopInit = (redirect) => {
|
|
1572
|
-
const init = { signal: abortSignal, redirect };
|
|
1573
|
-
if (currentHeaders !== void 0) {
|
|
1574
|
-
init.headers = new Headers(currentHeaders);
|
|
1575
|
-
}
|
|
1576
|
-
return init;
|
|
1577
|
-
};
|
|
1578
|
-
let currentUrl = url;
|
|
1579
|
-
for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
|
|
1580
|
-
const isTrustedHop = trustedOrigin !== void 0 && isSameOrigin(currentUrl, trustedOrigin);
|
|
1581
|
-
if (!isTrustedHop) {
|
|
1582
|
-
validateDownloadUrl(currentUrl);
|
|
1583
|
-
}
|
|
1584
|
-
const fetch = customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getDefaultDownloadFetch();
|
|
1585
|
-
const response = await fetch(currentUrl, perHopInit("manual"));
|
|
1586
|
-
if (response.type === "opaqueredirect") {
|
|
1587
|
-
if (!isBrowserRuntime()) {
|
|
1588
|
-
throw new DownloadError({
|
|
1589
|
-
url,
|
|
1590
|
-
message: `Redirect from ${currentUrl} could not be validated and was blocked`
|
|
1591
|
-
});
|
|
1592
|
-
}
|
|
1593
|
-
return await fetch(currentUrl, perHopInit("follow"));
|
|
1594
|
-
}
|
|
1595
|
-
const location = response.headers.get("location");
|
|
1596
|
-
if (REDIRECT_STATUS_CODES.has(response.status) && location) {
|
|
1597
|
-
await cancelResponseBody(response);
|
|
1598
|
-
const nextUrl = new URL(location, currentUrl).toString();
|
|
1599
|
-
if (currentHeaders !== void 0 && !isSameOrigin(nextUrl, currentUrl)) {
|
|
1600
|
-
const userAgent = currentHeaders.get("user-agent");
|
|
1601
|
-
currentHeaders = new Headers(
|
|
1602
|
-
userAgent == null ? void 0 : { "user-agent": userAgent }
|
|
1603
|
-
);
|
|
1604
|
-
}
|
|
1605
|
-
currentUrl = nextUrl;
|
|
1606
|
-
continue;
|
|
1607
|
-
}
|
|
1608
|
-
return response;
|
|
1609
|
-
}
|
|
1610
|
-
throw new DownloadError({
|
|
1611
|
-
url,
|
|
1612
|
-
message: `Too many redirects (max ${maxRedirects})`
|
|
1613
|
-
});
|
|
1614
|
-
}
|
|
1615
|
-
var DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
|
|
1616
|
-
async function readResponseWithSizeLimit({
|
|
1617
|
-
response,
|
|
1618
|
-
url,
|
|
1619
|
-
maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE
|
|
1620
|
-
}) {
|
|
1621
|
-
const contentLength = response.headers.get("content-length");
|
|
1622
|
-
if (contentLength != null) {
|
|
1623
|
-
const length = parseInt(contentLength, 10);
|
|
1624
|
-
if (!isNaN(length) && length > maxBytes) {
|
|
1625
|
-
await cancelResponseBody(response);
|
|
1626
|
-
throw new DownloadError({
|
|
1627
|
-
url,
|
|
1628
|
-
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
|
|
1629
|
-
});
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
const body = response.body;
|
|
1633
|
-
if (body == null) {
|
|
1634
|
-
return new Uint8Array(0);
|
|
1635
|
-
}
|
|
1636
|
-
const reader = body.getReader();
|
|
1637
|
-
const chunks = [];
|
|
1638
|
-
let totalBytes = 0;
|
|
1639
|
-
try {
|
|
1640
|
-
while (true) {
|
|
1641
|
-
const { done, value } = await reader.read();
|
|
1642
|
-
if (done) {
|
|
1643
|
-
break;
|
|
1644
|
-
}
|
|
1645
|
-
totalBytes += value.length;
|
|
1646
|
-
if (totalBytes > maxBytes) {
|
|
1647
|
-
throw new DownloadError({
|
|
1648
|
-
url,
|
|
1649
|
-
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
|
|
1650
|
-
});
|
|
1651
|
-
}
|
|
1652
|
-
chunks.push(value);
|
|
1653
|
-
}
|
|
1654
|
-
} finally {
|
|
1655
|
-
try {
|
|
1656
|
-
await reader.cancel();
|
|
1657
|
-
} catch (e) {
|
|
1658
|
-
} finally {
|
|
1659
|
-
reader.releaseLock();
|
|
1660
|
-
}
|
|
1661
|
-
}
|
|
1662
|
-
const result = new Uint8Array(totalBytes);
|
|
1663
|
-
let offset = 0;
|
|
1664
|
-
for (const chunk of chunks) {
|
|
1665
|
-
result.set(chunk, offset);
|
|
1666
|
-
offset += chunk.length;
|
|
1667
|
-
}
|
|
1668
|
-
return result;
|
|
1669
|
-
}
|
|
1670
|
-
async function downloadBlob(url, options) {
|
|
1671
|
-
var _a32, _b32;
|
|
1672
|
-
try {
|
|
1673
|
-
const response = await fetchWithValidatedRedirects({
|
|
1674
|
-
url,
|
|
1675
|
-
abortSignal: options == null ? void 0 : options.abortSignal
|
|
1676
|
-
});
|
|
1677
|
-
if (!response.ok) {
|
|
1678
|
-
await cancelResponseBody(response);
|
|
1679
|
-
throw new DownloadError({
|
|
1680
|
-
url,
|
|
1681
|
-
statusCode: response.status,
|
|
1682
|
-
statusText: response.statusText
|
|
1683
|
-
});
|
|
1684
|
-
}
|
|
1685
|
-
const data = await readResponseWithSizeLimit({
|
|
1686
|
-
response,
|
|
1687
|
-
url,
|
|
1688
|
-
maxBytes: (_a32 = options == null ? void 0 : options.maxBytes) != null ? _a32 : DEFAULT_MAX_DOWNLOAD_SIZE
|
|
1689
|
-
});
|
|
1690
|
-
const contentType = (_b32 = response.headers.get("content-type")) != null ? _b32 : void 0;
|
|
1691
|
-
return new Blob([data], contentType ? { type: contentType } : void 0);
|
|
1692
|
-
} catch (error) {
|
|
1693
|
-
if (DownloadError.isInstance(error)) {
|
|
1694
|
-
throw error;
|
|
1695
|
-
}
|
|
1696
|
-
throw new DownloadError({ url, cause: error });
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
function extractResponseHeaders(response) {
|
|
1700
|
-
return Object.fromEntries([...response.headers]);
|
|
1701
|
-
}
|
|
1702
|
-
function filterNullable(...values) {
|
|
1703
|
-
return values.filter((value) => value != null);
|
|
1704
|
-
}
|
|
1705
|
-
var createIdGenerator = ({
|
|
1706
|
-
prefix,
|
|
1707
|
-
size = 16,
|
|
1708
|
-
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
1709
|
-
separator = "-"
|
|
1710
|
-
} = {}) => {
|
|
1711
|
-
const generator = () => {
|
|
1712
|
-
const alphabetLength = alphabet.length;
|
|
1713
|
-
const chars = new Array(size);
|
|
1714
|
-
for (let i = 0; i < size; i++) {
|
|
1715
|
-
chars[i] = alphabet[Math.random() * alphabetLength | 0];
|
|
1716
|
-
}
|
|
1717
|
-
return chars.join("");
|
|
1718
|
-
};
|
|
1719
|
-
if (prefix == null) {
|
|
1720
|
-
return generator;
|
|
1721
|
-
}
|
|
1722
|
-
if (alphabet.includes(separator)) {
|
|
1723
|
-
throw new InvalidArgumentError({
|
|
1724
|
-
argument: "separator",
|
|
1725
|
-
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
1726
|
-
});
|
|
1727
|
-
}
|
|
1728
|
-
return () => `${prefix}${separator}${generator()}`;
|
|
1729
|
-
};
|
|
1730
|
-
var generateId = createIdGenerator();
|
|
1731
|
-
function isAbortError(error) {
|
|
1732
|
-
return (error instanceof Error || error instanceof DOMException) && (error.name === "AbortError" || error.name === "ResponseAborted" || // Next.js
|
|
1733
|
-
error.name === "TimeoutError");
|
|
1734
|
-
}
|
|
1735
|
-
var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
|
|
1736
|
-
var BUN_ERROR_CODES = [
|
|
1737
|
-
"ConnectionRefused",
|
|
1738
|
-
"ConnectionClosed",
|
|
1739
|
-
"FailedToOpenSocket",
|
|
1740
|
-
"ECONNRESET",
|
|
1741
|
-
"ECONNREFUSED",
|
|
1742
|
-
"ETIMEDOUT",
|
|
1743
|
-
"EPIPE"
|
|
1744
|
-
];
|
|
1745
|
-
function isBunNetworkError(error) {
|
|
1746
|
-
if (!(error instanceof Error)) {
|
|
1747
|
-
return false;
|
|
1748
|
-
}
|
|
1749
|
-
const code = error.code;
|
|
1750
|
-
if (typeof code === "string" && BUN_ERROR_CODES.includes(code)) {
|
|
1751
|
-
return true;
|
|
1752
|
-
}
|
|
1753
|
-
return false;
|
|
1754
|
-
}
|
|
1755
|
-
function handleFetchError({
|
|
1756
|
-
error,
|
|
1757
|
-
url,
|
|
1758
|
-
requestBodyValues
|
|
1759
|
-
}) {
|
|
1760
|
-
if (isAbortError(error)) {
|
|
1761
|
-
return error;
|
|
1762
|
-
}
|
|
1763
|
-
if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES.includes(error.message.toLowerCase())) {
|
|
1764
|
-
const cause = error.cause;
|
|
1765
|
-
if (cause != null) {
|
|
1766
|
-
return new APICallError({
|
|
1767
|
-
message: `Cannot connect to API: ${cause.message}`,
|
|
1768
|
-
cause,
|
|
1769
|
-
url,
|
|
1770
|
-
requestBodyValues,
|
|
1771
|
-
isRetryable: true
|
|
1772
|
-
// retry when network error
|
|
1773
|
-
});
|
|
1774
|
-
}
|
|
1775
|
-
}
|
|
1776
|
-
if (isBunNetworkError(error)) {
|
|
1777
|
-
return new APICallError({
|
|
1778
|
-
message: `Cannot connect to API: ${error.message}`,
|
|
1779
|
-
cause: error,
|
|
1780
|
-
url,
|
|
1781
|
-
requestBodyValues,
|
|
1782
|
-
isRetryable: true
|
|
1783
|
-
});
|
|
1784
|
-
}
|
|
1785
|
-
return error;
|
|
1786
|
-
}
|
|
1787
|
-
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
1788
|
-
var _a32, _b32, _c;
|
|
1789
|
-
if (globalThisAny.window) {
|
|
1790
|
-
return `runtime/browser`;
|
|
1791
|
-
}
|
|
1792
|
-
if ((_a32 = globalThisAny.navigator) == null ? void 0 : _a32.userAgent) {
|
|
1793
|
-
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
1794
|
-
}
|
|
1795
|
-
if ((_c = (_b32 = globalThisAny.process) == null ? void 0 : _b32.versions) == null ? void 0 : _c.node) {
|
|
1796
|
-
return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
|
1797
|
-
}
|
|
1798
|
-
if (globalThisAny.EdgeRuntime) {
|
|
1799
|
-
return `runtime/vercel-edge`;
|
|
1800
|
-
}
|
|
1801
|
-
return "runtime/unknown";
|
|
1802
|
-
}
|
|
1803
|
-
function normalizeHeaders(headers) {
|
|
1804
|
-
if (headers == null) {
|
|
1805
|
-
return {};
|
|
1806
|
-
}
|
|
1807
|
-
const normalized = {};
|
|
1808
|
-
if (headers instanceof Headers) {
|
|
1809
|
-
headers.forEach((value, key) => {
|
|
1810
|
-
normalized[key.toLowerCase()] = value;
|
|
1811
|
-
});
|
|
1812
|
-
} else {
|
|
1813
|
-
if (!Array.isArray(headers)) {
|
|
1814
|
-
headers = Object.entries(headers);
|
|
1815
|
-
}
|
|
1816
|
-
for (const [key, value] of headers) {
|
|
1817
|
-
if (value != null) {
|
|
1818
|
-
normalized[key.toLowerCase()] = value;
|
|
1819
|
-
}
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1822
|
-
return normalized;
|
|
1823
|
-
}
|
|
1824
|
-
function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
1825
|
-
const normalizedHeaders = new Headers(normalizeHeaders(headers));
|
|
1826
|
-
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
|
1827
|
-
normalizedHeaders.set(
|
|
1828
|
-
"user-agent",
|
|
1829
|
-
[currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ")
|
|
1830
|
-
);
|
|
1831
|
-
return Object.fromEntries(normalizedHeaders.entries());
|
|
1832
|
-
}
|
|
1833
|
-
var VERSION = true ? "5.0.27" : "0.0.0-test";
|
|
1834
|
-
var getOriginalFetch = () => globalThis.fetch;
|
|
1835
|
-
var getFromApi = async ({
|
|
1836
|
-
url,
|
|
1837
|
-
headers = {},
|
|
1838
|
-
successfulResponseHandler,
|
|
1839
|
-
failedResponseHandler,
|
|
1840
|
-
abortSignal,
|
|
1841
|
-
fetch,
|
|
1842
|
-
validateUrl,
|
|
1843
|
-
credentialedOrigin,
|
|
1844
|
-
trustedOrigin
|
|
1845
|
-
}) => {
|
|
1846
|
-
try {
|
|
1847
|
-
const requestFetch = fetch != null ? fetch : getOriginalFetch();
|
|
1848
|
-
const outgoingHeaders = credentialedOrigin !== void 0 && !isSameOrigin(url, credentialedOrigin) ? {} : headers;
|
|
1849
|
-
const requestHeaders = withUserAgentSuffix(
|
|
1850
|
-
outgoingHeaders,
|
|
1851
|
-
`ai-sdk/provider-utils/${VERSION}`,
|
|
1852
|
-
getRuntimeEnvironmentUserAgent()
|
|
1853
|
-
);
|
|
1854
|
-
const response = validateUrl ? await fetchWithValidatedRedirects({
|
|
1855
|
-
url,
|
|
1856
|
-
headers: requestHeaders,
|
|
1857
|
-
abortSignal,
|
|
1858
|
-
fetch,
|
|
1859
|
-
trustedOrigin
|
|
1860
|
-
}) : await requestFetch(url, {
|
|
1861
|
-
method: "GET",
|
|
1862
|
-
headers: requestHeaders,
|
|
1863
|
-
signal: abortSignal
|
|
1864
|
-
});
|
|
1865
|
-
const responseHeaders = extractResponseHeaders(response);
|
|
1866
|
-
if (!response.ok) {
|
|
1867
|
-
let errorInformation;
|
|
1868
|
-
try {
|
|
1869
|
-
errorInformation = await failedResponseHandler({
|
|
1870
|
-
response,
|
|
1871
|
-
url,
|
|
1872
|
-
requestBodyValues: {}
|
|
1873
|
-
});
|
|
1874
|
-
} catch (error) {
|
|
1875
|
-
if (isAbortError(error) || APICallError.isInstance(error)) {
|
|
1876
|
-
throw error;
|
|
1877
|
-
}
|
|
1878
|
-
throw new APICallError({
|
|
1879
|
-
message: "Failed to process error response",
|
|
1880
|
-
cause: error,
|
|
1881
|
-
statusCode: response.status,
|
|
1882
|
-
url,
|
|
1883
|
-
responseHeaders,
|
|
1884
|
-
requestBodyValues: {}
|
|
1885
|
-
});
|
|
1886
|
-
}
|
|
1887
|
-
throw errorInformation.value;
|
|
1888
|
-
}
|
|
1889
|
-
try {
|
|
1890
|
-
return await successfulResponseHandler({
|
|
1891
|
-
response,
|
|
1892
|
-
url,
|
|
1893
|
-
requestBodyValues: {}
|
|
1894
|
-
});
|
|
1895
|
-
} catch (error) {
|
|
1896
|
-
if (error instanceof Error) {
|
|
1897
|
-
if (isAbortError(error) || APICallError.isInstance(error)) {
|
|
1898
|
-
throw error;
|
|
1899
|
-
}
|
|
1900
|
-
}
|
|
1901
|
-
throw new APICallError({
|
|
1902
|
-
message: "Failed to process successful response",
|
|
1903
|
-
cause: error,
|
|
1904
|
-
statusCode: response.status,
|
|
1905
|
-
url,
|
|
1906
|
-
responseHeaders,
|
|
1907
|
-
requestBodyValues: {}
|
|
1908
|
-
});
|
|
1909
|
-
}
|
|
1910
|
-
} catch (error) {
|
|
1911
|
-
throw handleFetchError({ error, url, requestBodyValues: {} });
|
|
1912
|
-
}
|
|
1913
|
-
};
|
|
1914
|
-
function isBuffer(value) {
|
|
1915
|
-
var _a32, _b32;
|
|
1916
|
-
return (_b32 = (_a32 = globalThis.Buffer) == null ? void 0 : _a32.isBuffer(value)) != null ? _b32 : false;
|
|
1917
|
-
}
|
|
1918
|
-
function isNonNullable(value) {
|
|
1919
|
-
return value != null;
|
|
1920
|
-
}
|
|
1921
|
-
function isProviderReference(data) {
|
|
1922
|
-
return typeof data === "object" && data !== null && !(data instanceof Uint8Array) && !(data instanceof URL) && !(data instanceof ArrayBuffer) && !isBuffer(data) && !("type" in data);
|
|
1923
|
-
}
|
|
1924
|
-
function isRecord(value) {
|
|
1925
|
-
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
1926
|
-
}
|
|
1927
|
-
function isUrlSupported({
|
|
1928
|
-
mediaType,
|
|
1929
|
-
url,
|
|
1930
|
-
supportedUrls
|
|
1931
|
-
}) {
|
|
1932
|
-
url = url.toLowerCase();
|
|
1933
|
-
mediaType = mediaType.toLowerCase();
|
|
1934
|
-
const isTopLevelOnly = !mediaType.includes("/");
|
|
1935
|
-
return Object.entries(supportedUrls).map(([key, value]) => {
|
|
1936
|
-
const mediaType2 = key.toLowerCase();
|
|
1937
|
-
return mediaType2 === "*" || mediaType2 === "*/*" ? { mediaTypePrefix: "", regexes: value } : { mediaTypePrefix: mediaType2.replace(/\*/, ""), regexes: value };
|
|
1938
|
-
}).filter(({ mediaTypePrefix }) => {
|
|
1939
|
-
if (mediaTypePrefix === "") {
|
|
1940
|
-
return true;
|
|
1941
|
-
}
|
|
1942
|
-
if (isTopLevelOnly) {
|
|
1943
|
-
return `${mediaType}/` === mediaTypePrefix;
|
|
1944
|
-
}
|
|
1945
|
-
return mediaType.startsWith(mediaTypePrefix);
|
|
1946
|
-
}).flatMap(({ regexes }) => regexes).some((pattern) => testRegExpFromStart(pattern, url));
|
|
1947
|
-
}
|
|
1948
|
-
function testRegExpFromStart(pattern, value) {
|
|
1949
|
-
if (!pattern.global && !pattern.sticky) {
|
|
1950
|
-
return pattern.test(value);
|
|
1951
|
-
}
|
|
1952
|
-
const lastIndex = pattern.lastIndex;
|
|
1953
|
-
pattern.lastIndex = 0;
|
|
1954
|
-
try {
|
|
1955
|
-
return pattern.test(value);
|
|
1956
|
-
} finally {
|
|
1957
|
-
pattern.lastIndex = lastIndex;
|
|
1958
|
-
}
|
|
1959
|
-
}
|
|
1960
|
-
function loadApiKey({
|
|
1961
|
-
apiKey,
|
|
1962
|
-
environmentVariableName,
|
|
1963
|
-
apiKeyParameterName = "apiKey",
|
|
1964
|
-
description
|
|
1965
|
-
}) {
|
|
1966
|
-
if (typeof apiKey === "string") {
|
|
1967
|
-
return apiKey;
|
|
1968
|
-
}
|
|
1969
|
-
if (apiKey != null) {
|
|
1970
|
-
throw new LoadAPIKeyError({
|
|
1971
|
-
message: `${description} API key must be a string.`
|
|
1972
|
-
});
|
|
1973
|
-
}
|
|
1974
|
-
if (typeof process === "undefined") {
|
|
1975
|
-
throw new LoadAPIKeyError({
|
|
1976
|
-
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables are not supported in this environment.`
|
|
1977
|
-
});
|
|
1978
|
-
}
|
|
1979
|
-
apiKey = process.env[environmentVariableName];
|
|
1980
|
-
if (apiKey == null) {
|
|
1981
|
-
throw new LoadAPIKeyError({
|
|
1982
|
-
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
|
1983
|
-
});
|
|
1984
|
-
}
|
|
1985
|
-
if (typeof apiKey !== "string") {
|
|
1986
|
-
throw new LoadAPIKeyError({
|
|
1987
|
-
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
1988
|
-
});
|
|
1989
|
-
}
|
|
1990
|
-
return apiKey;
|
|
1991
|
-
}
|
|
1992
|
-
function loadOptionalSetting({
|
|
1993
|
-
settingValue,
|
|
1994
|
-
environmentVariableName
|
|
1995
|
-
}) {
|
|
1996
|
-
if (typeof settingValue === "string") {
|
|
1997
|
-
return settingValue;
|
|
1998
|
-
}
|
|
1999
|
-
if (settingValue != null || typeof process === "undefined") {
|
|
2000
|
-
return void 0;
|
|
2001
|
-
}
|
|
2002
|
-
settingValue = process.env[environmentVariableName];
|
|
2003
|
-
if (settingValue == null || typeof settingValue !== "string") {
|
|
2004
|
-
return void 0;
|
|
2005
|
-
}
|
|
2006
|
-
return settingValue;
|
|
2007
|
-
}
|
|
2008
|
-
function isCustomReasoning(reasoning) {
|
|
2009
|
-
return reasoning !== void 0 && reasoning !== "provider-default";
|
|
2010
|
-
}
|
|
2011
|
-
function mapReasoningToProviderEffort({
|
|
2012
|
-
reasoning,
|
|
2013
|
-
effortMap,
|
|
2014
|
-
warnings
|
|
2015
|
-
}) {
|
|
2016
|
-
const mapped = effortMap[reasoning];
|
|
2017
|
-
if (mapped == null) {
|
|
2018
|
-
warnings.push({
|
|
2019
|
-
type: "unsupported",
|
|
2020
|
-
feature: "reasoning",
|
|
2021
|
-
details: `reasoning "${reasoning}" is not supported by this model.`
|
|
2022
|
-
});
|
|
2023
|
-
return void 0;
|
|
2024
|
-
}
|
|
2025
|
-
if (mapped !== reasoning) {
|
|
2026
|
-
warnings.push({
|
|
2027
|
-
type: "compatibility",
|
|
2028
|
-
feature: "reasoning",
|
|
2029
|
-
details: `reasoning "${reasoning}" is not directly supported by this model. mapped to effort "${mapped}".`
|
|
2030
|
-
});
|
|
2031
|
-
}
|
|
2032
|
-
return mapped;
|
|
2033
|
-
}
|
|
2034
|
-
var DEFAULT_REASONING_BUDGET_PERCENTAGES = {
|
|
2035
|
-
minimal: 0.02,
|
|
2036
|
-
low: 0.1,
|
|
2037
|
-
medium: 0.3,
|
|
2038
|
-
high: 0.6,
|
|
2039
|
-
xhigh: 0.9
|
|
2040
|
-
};
|
|
2041
|
-
function mapReasoningToProviderBudget({
|
|
2042
|
-
reasoning,
|
|
2043
|
-
maxOutputTokens,
|
|
2044
|
-
maxReasoningBudget,
|
|
2045
|
-
minReasoningBudget = 1024,
|
|
2046
|
-
budgetPercentages = DEFAULT_REASONING_BUDGET_PERCENTAGES,
|
|
2047
|
-
warnings
|
|
2048
|
-
}) {
|
|
2049
|
-
const pct = budgetPercentages[reasoning];
|
|
2050
|
-
if (pct == null) {
|
|
2051
|
-
warnings.push({
|
|
2052
|
-
type: "unsupported",
|
|
2053
|
-
feature: "reasoning",
|
|
2054
|
-
details: `reasoning "${reasoning}" is not supported by this model.`
|
|
2055
|
-
});
|
|
2056
|
-
return void 0;
|
|
2057
|
-
}
|
|
2058
|
-
return Math.min(
|
|
2059
|
-
maxReasoningBudget,
|
|
2060
|
-
Math.max(minReasoningBudget, Math.round(maxOutputTokens * pct))
|
|
2061
|
-
);
|
|
2062
|
-
}
|
|
2063
|
-
function mediaTypeToExtension(mediaType) {
|
|
2064
|
-
var _a32;
|
|
2065
|
-
const [_type, subtype = ""] = mediaType.toLowerCase().split("/");
|
|
2066
|
-
return (_a32 = {
|
|
2067
|
-
mpeg: "mp3",
|
|
2068
|
-
"x-wav": "wav",
|
|
2069
|
-
opus: "ogg",
|
|
2070
|
-
mp4: "m4a",
|
|
2071
|
-
"x-m4a": "m4a"
|
|
2072
|
-
}[subtype]) != null ? _a32 : subtype;
|
|
2073
|
-
}
|
|
2074
|
-
var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
2075
|
-
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*:/;
|
|
2076
|
-
function _parse(text) {
|
|
2077
|
-
const obj = JSON.parse(text);
|
|
2078
|
-
if (obj === null || typeof obj !== "object") {
|
|
2079
|
-
return obj;
|
|
2080
|
-
}
|
|
2081
|
-
if (suspectProtoRx.test(text) === false && suspectConstructorRx.test(text) === false) {
|
|
2082
|
-
return obj;
|
|
2083
|
-
}
|
|
2084
|
-
return filter(obj);
|
|
2085
|
-
}
|
|
2086
|
-
function filter(obj) {
|
|
2087
|
-
let next = [obj];
|
|
2088
|
-
while (next.length) {
|
|
2089
|
-
const nodes = next;
|
|
2090
|
-
next = [];
|
|
2091
|
-
for (const node of nodes) {
|
|
2092
|
-
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
2093
|
-
throw new SyntaxError("Object contains forbidden prototype property");
|
|
2094
|
-
}
|
|
2095
|
-
if (Object.prototype.hasOwnProperty.call(node, "constructor") && node.constructor !== null && typeof node.constructor === "object" && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
2096
|
-
throw new SyntaxError("Object contains forbidden prototype property");
|
|
2097
|
-
}
|
|
2098
|
-
for (const key in node) {
|
|
2099
|
-
const value = node[key];
|
|
2100
|
-
if (value && typeof value === "object") {
|
|
2101
|
-
next.push(value);
|
|
2102
|
-
}
|
|
2103
|
-
}
|
|
2104
|
-
}
|
|
2105
|
-
}
|
|
2106
|
-
return obj;
|
|
2107
|
-
}
|
|
2108
|
-
function secureJsonParse(text) {
|
|
2109
|
-
const { stackTraceLimit } = Error;
|
|
2110
|
-
try {
|
|
2111
|
-
Error.stackTraceLimit = 0;
|
|
2112
|
-
} catch (e) {
|
|
2113
|
-
return _parse(text);
|
|
2114
|
-
}
|
|
2115
|
-
try {
|
|
2116
|
-
return _parse(text);
|
|
2117
|
-
} finally {
|
|
2118
|
-
Error.stackTraceLimit = stackTraceLimit;
|
|
2119
|
-
}
|
|
2120
|
-
}
|
|
2121
|
-
function addAdditionalPropertiesToJsonSchema(jsonSchema2) {
|
|
2122
|
-
if (jsonSchema2.type === "object" || Array.isArray(jsonSchema2.type) && jsonSchema2.type.includes("object")) {
|
|
2123
|
-
jsonSchema2.additionalProperties = false;
|
|
2124
|
-
const { properties } = jsonSchema2;
|
|
2125
|
-
if (properties != null) {
|
|
2126
|
-
for (const key of Object.keys(properties)) {
|
|
2127
|
-
properties[key] = visit(properties[key]);
|
|
2128
|
-
}
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
|
-
if (jsonSchema2.items != null) {
|
|
2132
|
-
jsonSchema2.items = Array.isArray(jsonSchema2.items) ? jsonSchema2.items.map(visit) : visit(jsonSchema2.items);
|
|
2133
|
-
}
|
|
2134
|
-
if (jsonSchema2.anyOf != null) {
|
|
2135
|
-
jsonSchema2.anyOf = jsonSchema2.anyOf.map(visit);
|
|
2136
|
-
}
|
|
2137
|
-
if (jsonSchema2.allOf != null) {
|
|
2138
|
-
jsonSchema2.allOf = jsonSchema2.allOf.map(visit);
|
|
2139
|
-
}
|
|
2140
|
-
if (jsonSchema2.oneOf != null) {
|
|
2141
|
-
jsonSchema2.oneOf = jsonSchema2.oneOf.map(visit);
|
|
2142
|
-
}
|
|
2143
|
-
const { definitions } = jsonSchema2;
|
|
2144
|
-
if (definitions != null) {
|
|
2145
|
-
for (const key of Object.keys(definitions)) {
|
|
2146
|
-
definitions[key] = visit(definitions[key]);
|
|
2147
|
-
}
|
|
2148
|
-
}
|
|
2149
|
-
return jsonSchema2;
|
|
2150
|
-
}
|
|
2151
|
-
function visit(def) {
|
|
2152
|
-
if (typeof def === "boolean") return def;
|
|
2153
|
-
return addAdditionalPropertiesToJsonSchema(def);
|
|
2154
|
-
}
|
|
2155
|
-
var ignoreOverride = /* @__PURE__ */ Symbol(
|
|
2156
|
-
"Let zodToJsonSchema decide on which parser to use"
|
|
2157
|
-
);
|
|
2158
|
-
var defaultOptions = {
|
|
2159
|
-
name: void 0,
|
|
2160
|
-
$refStrategy: "root",
|
|
2161
|
-
basePath: ["#"],
|
|
2162
|
-
effectStrategy: "input",
|
|
2163
|
-
pipeStrategy: "all",
|
|
2164
|
-
dateStrategy: "format:date-time",
|
|
2165
|
-
mapStrategy: "entries",
|
|
2166
|
-
removeAdditionalStrategy: "passthrough",
|
|
2167
|
-
allowedAdditionalProperties: true,
|
|
2168
|
-
rejectedAdditionalProperties: false,
|
|
2169
|
-
definitionPath: "definitions",
|
|
2170
|
-
strictUnions: false,
|
|
2171
|
-
definitions: {},
|
|
2172
|
-
errorMessages: false,
|
|
2173
|
-
patternStrategy: "escape",
|
|
2174
|
-
applyRegexFlags: false,
|
|
2175
|
-
emailStrategy: "format:email",
|
|
2176
|
-
base64Strategy: "contentEncoding:base64",
|
|
2177
|
-
nameStrategy: "ref"
|
|
2178
|
-
};
|
|
2179
|
-
var getDefaultOptions = (options) => typeof options === "string" ? {
|
|
2180
|
-
...defaultOptions,
|
|
2181
|
-
name: options
|
|
2182
|
-
} : {
|
|
2183
|
-
...defaultOptions,
|
|
2184
|
-
...options
|
|
2185
|
-
};
|
|
2186
|
-
function parseAnyDef() {
|
|
2187
|
-
return {};
|
|
2188
|
-
}
|
|
2189
|
-
function parseArrayDef(def, refs) {
|
|
2190
|
-
var _a32, _b32, _c;
|
|
2191
|
-
const res = {
|
|
2192
|
-
type: "array"
|
|
2193
|
-
};
|
|
2194
|
-
if (((_a32 = def.type) == null ? void 0 : _a32._def) && ((_c = (_b32 = def.type) == null ? void 0 : _b32._def) == null ? void 0 : _c.typeName) !== "ZodAny") {
|
|
2195
|
-
res.items = parseDef(def.type._def, {
|
|
2196
|
-
...refs,
|
|
2197
|
-
currentPath: [...refs.currentPath, "items"]
|
|
2198
|
-
});
|
|
2199
|
-
}
|
|
2200
|
-
if (def.minLength) {
|
|
2201
|
-
res.minItems = def.minLength.value;
|
|
2202
|
-
}
|
|
2203
|
-
if (def.maxLength) {
|
|
2204
|
-
res.maxItems = def.maxLength.value;
|
|
2205
|
-
}
|
|
2206
|
-
if (def.exactLength) {
|
|
2207
|
-
res.minItems = def.exactLength.value;
|
|
2208
|
-
res.maxItems = def.exactLength.value;
|
|
2209
|
-
}
|
|
2210
|
-
return res;
|
|
2211
|
-
}
|
|
2212
|
-
function parseBigintDef(def) {
|
|
2213
|
-
const res = {
|
|
2214
|
-
type: "integer",
|
|
2215
|
-
format: "int64"
|
|
2216
|
-
};
|
|
2217
|
-
if (!def.checks) return res;
|
|
2218
|
-
for (const check of def.checks) {
|
|
2219
|
-
switch (check.kind) {
|
|
2220
|
-
case "min":
|
|
2221
|
-
if (check.inclusive) {
|
|
2222
|
-
res.minimum = check.value;
|
|
2223
|
-
} else {
|
|
2224
|
-
res.exclusiveMinimum = check.value;
|
|
2225
|
-
}
|
|
2226
|
-
break;
|
|
2227
|
-
case "max":
|
|
2228
|
-
if (check.inclusive) {
|
|
2229
|
-
res.maximum = check.value;
|
|
2230
|
-
} else {
|
|
2231
|
-
res.exclusiveMaximum = check.value;
|
|
2232
|
-
}
|
|
2233
|
-
break;
|
|
2234
|
-
case "multipleOf":
|
|
2235
|
-
res.multipleOf = check.value;
|
|
2236
|
-
break;
|
|
2237
|
-
}
|
|
2238
|
-
}
|
|
2239
|
-
return res;
|
|
2240
|
-
}
|
|
2241
|
-
function parseBooleanDef() {
|
|
2242
|
-
return { type: "boolean" };
|
|
2243
|
-
}
|
|
2244
|
-
function parseBrandedDef(_def, refs) {
|
|
2245
|
-
return parseDef(_def.type._def, refs);
|
|
2246
|
-
}
|
|
2247
|
-
var parseCatchDef = (def, refs) => {
|
|
2248
|
-
return parseDef(def.innerType._def, refs);
|
|
2249
|
-
};
|
|
2250
|
-
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
2251
|
-
const strategy = overrideDateStrategy != null ? overrideDateStrategy : refs.dateStrategy;
|
|
2252
|
-
if (Array.isArray(strategy)) {
|
|
2253
|
-
return {
|
|
2254
|
-
anyOf: strategy.map((item) => parseDateDef(def, refs, item))
|
|
2255
|
-
};
|
|
2256
|
-
}
|
|
2257
|
-
switch (strategy) {
|
|
2258
|
-
case "string":
|
|
2259
|
-
case "format:date-time":
|
|
2260
|
-
return {
|
|
2261
|
-
type: "string",
|
|
2262
|
-
format: "date-time"
|
|
2263
|
-
};
|
|
2264
|
-
case "format:date":
|
|
2265
|
-
return {
|
|
2266
|
-
type: "string",
|
|
2267
|
-
format: "date"
|
|
2268
|
-
};
|
|
2269
|
-
case "integer":
|
|
2270
|
-
return integerDateParser(def);
|
|
2271
|
-
}
|
|
2272
|
-
}
|
|
2273
|
-
var integerDateParser = (def) => {
|
|
2274
|
-
const res = {
|
|
2275
|
-
type: "integer",
|
|
2276
|
-
format: "unix-time"
|
|
2277
|
-
};
|
|
2278
|
-
for (const check of def.checks) {
|
|
2279
|
-
switch (check.kind) {
|
|
2280
|
-
case "min":
|
|
2281
|
-
res.minimum = check.value;
|
|
2282
|
-
break;
|
|
2283
|
-
case "max":
|
|
2284
|
-
res.maximum = check.value;
|
|
2285
|
-
break;
|
|
2286
|
-
}
|
|
2287
|
-
}
|
|
2288
|
-
return res;
|
|
2289
|
-
};
|
|
2290
|
-
function parseDefaultDef(_def, refs) {
|
|
2291
|
-
return {
|
|
2292
|
-
...parseDef(_def.innerType._def, refs),
|
|
2293
|
-
default: _def.defaultValue()
|
|
2294
|
-
};
|
|
2295
|
-
}
|
|
2296
|
-
function parseEffectsDef(_def, refs) {
|
|
2297
|
-
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : parseAnyDef();
|
|
2298
|
-
}
|
|
2299
|
-
function parseEnumDef(def) {
|
|
2300
|
-
return {
|
|
2301
|
-
type: "string",
|
|
2302
|
-
enum: Array.from(def.values)
|
|
2303
|
-
};
|
|
2304
|
-
}
|
|
2305
|
-
var isJsonSchema7AllOfType = (type) => {
|
|
2306
|
-
if ("type" in type && type.type === "string") return false;
|
|
2307
|
-
return "allOf" in type;
|
|
2308
|
-
};
|
|
2309
|
-
function parseIntersectionDef(def, refs) {
|
|
2310
|
-
const allOf = [
|
|
2311
|
-
parseDef(def.left._def, {
|
|
2312
|
-
...refs,
|
|
2313
|
-
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
2314
|
-
}),
|
|
2315
|
-
parseDef(def.right._def, {
|
|
2316
|
-
...refs,
|
|
2317
|
-
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
2318
|
-
})
|
|
2319
|
-
].filter((x) => !!x);
|
|
2320
|
-
const mergedAllOf = [];
|
|
2321
|
-
allOf.forEach((schema) => {
|
|
2322
|
-
if (isJsonSchema7AllOfType(schema)) {
|
|
2323
|
-
mergedAllOf.push(...schema.allOf);
|
|
2324
|
-
} else {
|
|
2325
|
-
let nestedSchema = schema;
|
|
2326
|
-
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
2327
|
-
const { additionalProperties: _additionalProperties, ...rest } = schema;
|
|
2328
|
-
nestedSchema = rest;
|
|
2329
|
-
}
|
|
2330
|
-
mergedAllOf.push(nestedSchema);
|
|
2331
|
-
}
|
|
2332
|
-
});
|
|
2333
|
-
return mergedAllOf.length ? { allOf: mergedAllOf } : void 0;
|
|
2334
|
-
}
|
|
2335
|
-
function parseLiteralDef(def) {
|
|
2336
|
-
const parsedType = typeof def.value;
|
|
2337
|
-
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
2338
|
-
return {
|
|
2339
|
-
type: Array.isArray(def.value) ? "array" : "object"
|
|
2340
|
-
};
|
|
2341
|
-
}
|
|
2342
|
-
return {
|
|
2343
|
-
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
2344
|
-
const: def.value
|
|
2345
|
-
};
|
|
2346
|
-
}
|
|
2347
|
-
var emojiRegex = void 0;
|
|
2348
|
-
var zodPatterns = {
|
|
2349
|
-
/**
|
|
2350
|
-
* `c` was changed to `[cC]` to replicate /i flag
|
|
2351
|
-
*/
|
|
2352
|
-
cuid: /^[cC][^\s-]{8,}$/,
|
|
2353
|
-
cuid2: /^[0-9a-z]+$/,
|
|
2354
|
-
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
2355
|
-
/**
|
|
2356
|
-
* `a-z` was added to replicate /i flag
|
|
2357
|
-
*/
|
|
2358
|
-
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
2359
|
-
/**
|
|
2360
|
-
* Constructed a valid Unicode RegExp
|
|
2361
|
-
*
|
|
2362
|
-
* Lazily instantiate since this type of regex isn't supported
|
|
2363
|
-
* in all envs (e.g. React Native).
|
|
2364
|
-
*
|
|
2365
|
-
* See:
|
|
2366
|
-
* https://github.com/colinhacks/zod/issues/2433
|
|
2367
|
-
* Fix in Zod:
|
|
2368
|
-
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
2369
|
-
*/
|
|
2370
|
-
emoji: () => {
|
|
2371
|
-
if (emojiRegex === void 0) {
|
|
2372
|
-
emojiRegex = RegExp(
|
|
2373
|
-
"^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",
|
|
2374
|
-
"u"
|
|
2375
|
-
);
|
|
2376
|
-
}
|
|
2377
|
-
return emojiRegex;
|
|
2378
|
-
},
|
|
2379
|
-
/**
|
|
2380
|
-
* Unused
|
|
2381
|
-
*/
|
|
2382
|
-
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}$/,
|
|
2383
|
-
/**
|
|
2384
|
-
* Unused
|
|
2385
|
-
*/
|
|
2386
|
-
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])$/,
|
|
2387
|
-
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])$/,
|
|
2388
|
-
/**
|
|
2389
|
-
* Unused
|
|
2390
|
-
*/
|
|
2391
|
-
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})))$/,
|
|
2392
|
-
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])$/,
|
|
2393
|
-
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
2394
|
-
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
2395
|
-
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
2396
|
-
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
2397
|
-
};
|
|
2398
|
-
function parseStringDef(def, refs) {
|
|
2399
|
-
const res = {
|
|
2400
|
-
type: "string"
|
|
2401
|
-
};
|
|
2402
|
-
if (def.checks) {
|
|
2403
|
-
for (const check of def.checks) {
|
|
2404
|
-
switch (check.kind) {
|
|
2405
|
-
case "min":
|
|
2406
|
-
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
|
|
2407
|
-
break;
|
|
2408
|
-
case "max":
|
|
2409
|
-
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
|
|
2410
|
-
break;
|
|
2411
|
-
case "email":
|
|
2412
|
-
switch (refs.emailStrategy) {
|
|
2413
|
-
case "format:email":
|
|
2414
|
-
addFormat(res, "email", check.message, refs);
|
|
2415
|
-
break;
|
|
2416
|
-
case "format:idn-email":
|
|
2417
|
-
addFormat(res, "idn-email", check.message, refs);
|
|
2418
|
-
break;
|
|
2419
|
-
case "pattern:zod":
|
|
2420
|
-
addPattern(res, zodPatterns.email, check.message, refs);
|
|
2421
|
-
break;
|
|
2422
|
-
}
|
|
2423
|
-
break;
|
|
2424
|
-
case "url":
|
|
2425
|
-
addFormat(res, "uri", check.message, refs);
|
|
2426
|
-
break;
|
|
2427
|
-
case "uuid":
|
|
2428
|
-
addFormat(res, "uuid", check.message, refs);
|
|
2429
|
-
break;
|
|
2430
|
-
case "regex":
|
|
2431
|
-
addPattern(res, check.regex, check.message, refs);
|
|
2432
|
-
break;
|
|
2433
|
-
case "cuid":
|
|
2434
|
-
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
2435
|
-
break;
|
|
2436
|
-
case "cuid2":
|
|
2437
|
-
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
2438
|
-
break;
|
|
2439
|
-
case "startsWith":
|
|
2440
|
-
addPattern(
|
|
2441
|
-
res,
|
|
2442
|
-
RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`),
|
|
2443
|
-
check.message,
|
|
2444
|
-
refs
|
|
2445
|
-
);
|
|
2446
|
-
break;
|
|
2447
|
-
case "endsWith":
|
|
2448
|
-
addPattern(
|
|
2449
|
-
res,
|
|
2450
|
-
RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`),
|
|
2451
|
-
check.message,
|
|
2452
|
-
refs
|
|
2453
|
-
);
|
|
2454
|
-
break;
|
|
2455
|
-
case "datetime":
|
|
2456
|
-
addFormat(res, "date-time", check.message, refs);
|
|
2457
|
-
break;
|
|
2458
|
-
case "date":
|
|
2459
|
-
addFormat(res, "date", check.message, refs);
|
|
2460
|
-
break;
|
|
2461
|
-
case "time":
|
|
2462
|
-
addFormat(res, "time", check.message, refs);
|
|
2463
|
-
break;
|
|
2464
|
-
case "duration":
|
|
2465
|
-
addFormat(res, "duration", check.message, refs);
|
|
2466
|
-
break;
|
|
2467
|
-
case "length":
|
|
2468
|
-
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
|
|
2469
|
-
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
|
|
2470
|
-
break;
|
|
2471
|
-
case "includes": {
|
|
2472
|
-
addPattern(
|
|
2473
|
-
res,
|
|
2474
|
-
RegExp(escapeLiteralCheckValue(check.value, refs)),
|
|
2475
|
-
check.message,
|
|
2476
|
-
refs
|
|
2477
|
-
);
|
|
2478
|
-
break;
|
|
2479
|
-
}
|
|
2480
|
-
case "ip": {
|
|
2481
|
-
if (check.version !== "v6") {
|
|
2482
|
-
addFormat(res, "ipv4", check.message, refs);
|
|
2483
|
-
}
|
|
2484
|
-
if (check.version !== "v4") {
|
|
2485
|
-
addFormat(res, "ipv6", check.message, refs);
|
|
2486
|
-
}
|
|
2487
|
-
break;
|
|
2488
|
-
}
|
|
2489
|
-
case "base64url":
|
|
2490
|
-
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
2491
|
-
break;
|
|
2492
|
-
case "jwt":
|
|
2493
|
-
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
2494
|
-
break;
|
|
2495
|
-
case "cidr": {
|
|
2496
|
-
if (check.version !== "v6") {
|
|
2497
|
-
addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
2498
|
-
}
|
|
2499
|
-
if (check.version !== "v4") {
|
|
2500
|
-
addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
2501
|
-
}
|
|
2502
|
-
break;
|
|
2503
|
-
}
|
|
2504
|
-
case "emoji":
|
|
2505
|
-
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
2506
|
-
break;
|
|
2507
|
-
case "ulid": {
|
|
2508
|
-
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
2509
|
-
break;
|
|
2510
|
-
}
|
|
2511
|
-
case "base64": {
|
|
2512
|
-
switch (refs.base64Strategy) {
|
|
2513
|
-
case "format:binary": {
|
|
2514
|
-
addFormat(res, "binary", check.message, refs);
|
|
2515
|
-
break;
|
|
2516
|
-
}
|
|
2517
|
-
case "contentEncoding:base64": {
|
|
2518
|
-
res.contentEncoding = "base64";
|
|
2519
|
-
break;
|
|
2520
|
-
}
|
|
2521
|
-
case "pattern:zod": {
|
|
2522
|
-
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
2523
|
-
break;
|
|
2524
|
-
}
|
|
2525
|
-
}
|
|
2526
|
-
break;
|
|
2527
|
-
}
|
|
2528
|
-
case "nanoid": {
|
|
2529
|
-
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
2530
|
-
}
|
|
2531
|
-
case "toLowerCase":
|
|
2532
|
-
case "toUpperCase":
|
|
2533
|
-
case "trim":
|
|
2534
|
-
break;
|
|
2535
|
-
default:
|
|
2536
|
-
/* @__PURE__ */ ((_) => {
|
|
2537
|
-
})(check);
|
|
2538
|
-
}
|
|
2539
|
-
}
|
|
2540
|
-
}
|
|
2541
|
-
return res;
|
|
2542
|
-
}
|
|
2543
|
-
function escapeLiteralCheckValue(literal, refs) {
|
|
2544
|
-
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
2545
|
-
}
|
|
2546
|
-
var ALPHA_NUMERIC = new Set(
|
|
2547
|
-
"ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789"
|
|
2548
|
-
);
|
|
2549
|
-
function escapeNonAlphaNumeric(source) {
|
|
2550
|
-
let result = "";
|
|
2551
|
-
for (let i = 0; i < source.length; i++) {
|
|
2552
|
-
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
2553
|
-
result += "\\";
|
|
2554
|
-
}
|
|
2555
|
-
result += source[i];
|
|
2556
|
-
}
|
|
2557
|
-
return result;
|
|
2558
|
-
}
|
|
2559
|
-
function addFormat(schema, value, message, refs) {
|
|
2560
|
-
var _a32;
|
|
2561
|
-
if (schema.format || ((_a32 = schema.anyOf) == null ? void 0 : _a32.some((x) => x.format))) {
|
|
2562
|
-
if (!schema.anyOf) {
|
|
2563
|
-
schema.anyOf = [];
|
|
2564
|
-
}
|
|
2565
|
-
if (schema.format) {
|
|
2566
|
-
schema.anyOf.push({
|
|
2567
|
-
format: schema.format
|
|
2568
|
-
});
|
|
2569
|
-
delete schema.format;
|
|
2570
|
-
}
|
|
2571
|
-
schema.anyOf.push({
|
|
2572
|
-
format: value,
|
|
2573
|
-
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
2574
|
-
});
|
|
2575
|
-
} else {
|
|
2576
|
-
schema.format = value;
|
|
2577
|
-
}
|
|
2578
|
-
}
|
|
2579
|
-
function addPattern(schema, regex, message, refs) {
|
|
2580
|
-
var _a32;
|
|
2581
|
-
if (schema.pattern || ((_a32 = schema.allOf) == null ? void 0 : _a32.some((x) => x.pattern))) {
|
|
2582
|
-
if (!schema.allOf) {
|
|
2583
|
-
schema.allOf = [];
|
|
2584
|
-
}
|
|
2585
|
-
if (schema.pattern) {
|
|
2586
|
-
schema.allOf.push({
|
|
2587
|
-
pattern: schema.pattern
|
|
2588
|
-
});
|
|
2589
|
-
delete schema.pattern;
|
|
2590
|
-
}
|
|
2591
|
-
schema.allOf.push({
|
|
2592
|
-
pattern: stringifyRegExpWithFlags(regex, refs),
|
|
2593
|
-
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
2594
|
-
});
|
|
2595
|
-
} else {
|
|
2596
|
-
schema.pattern = stringifyRegExpWithFlags(regex, refs);
|
|
2597
|
-
}
|
|
2598
|
-
}
|
|
2599
|
-
function stringifyRegExpWithFlags(regex, refs) {
|
|
2600
|
-
var _a32;
|
|
2601
|
-
if (!refs.applyRegexFlags || !regex.flags) {
|
|
2602
|
-
return regex.source;
|
|
2603
|
-
}
|
|
2604
|
-
const flags = {
|
|
2605
|
-
i: regex.flags.includes("i"),
|
|
2606
|
-
// Case-insensitive
|
|
2607
|
-
m: regex.flags.includes("m"),
|
|
2608
|
-
// `^` and `$` matches adjacent to newline characters
|
|
2609
|
-
s: regex.flags.includes("s")
|
|
2610
|
-
// `.` matches newlines
|
|
2611
|
-
};
|
|
2612
|
-
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
2613
|
-
let pattern = "";
|
|
2614
|
-
let isEscaped = false;
|
|
2615
|
-
let inCharGroup = false;
|
|
2616
|
-
let inCharRange = false;
|
|
2617
|
-
for (let i = 0; i < source.length; i++) {
|
|
2618
|
-
if (isEscaped) {
|
|
2619
|
-
pattern += source[i];
|
|
2620
|
-
isEscaped = false;
|
|
2621
|
-
continue;
|
|
2622
|
-
}
|
|
2623
|
-
if (flags.i) {
|
|
2624
|
-
if (inCharGroup) {
|
|
2625
|
-
if (source[i].match(/[a-z]/)) {
|
|
2626
|
-
if (inCharRange) {
|
|
2627
|
-
pattern += source[i];
|
|
2628
|
-
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
2629
|
-
inCharRange = false;
|
|
2630
|
-
} else if (source[i + 1] === "-" && ((_a32 = source[i + 2]) == null ? void 0 : _a32.match(/[a-z]/))) {
|
|
2631
|
-
pattern += source[i];
|
|
2632
|
-
inCharRange = true;
|
|
2633
|
-
} else {
|
|
2634
|
-
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
2635
|
-
}
|
|
2636
|
-
continue;
|
|
2637
|
-
}
|
|
2638
|
-
} else if (source[i].match(/[a-z]/)) {
|
|
2639
|
-
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
2640
|
-
continue;
|
|
2641
|
-
}
|
|
2642
|
-
}
|
|
2643
|
-
if (flags.m) {
|
|
2644
|
-
if (source[i] === "^") {
|
|
2645
|
-
pattern += `(^|(?<=[\r
|
|
2646
|
-
]))`;
|
|
2647
|
-
continue;
|
|
2648
|
-
} else if (source[i] === "$") {
|
|
2649
|
-
pattern += `($|(?=[\r
|
|
2650
|
-
]))`;
|
|
2651
|
-
continue;
|
|
2652
|
-
}
|
|
2653
|
-
}
|
|
2654
|
-
if (flags.s && source[i] === ".") {
|
|
2655
|
-
pattern += inCharGroup ? `${source[i]}\r
|
|
2656
|
-
` : `[${source[i]}\r
|
|
2657
|
-
]`;
|
|
2658
|
-
continue;
|
|
2659
|
-
}
|
|
2660
|
-
pattern += source[i];
|
|
2661
|
-
if (source[i] === "\\") {
|
|
2662
|
-
isEscaped = true;
|
|
2663
|
-
} else if (inCharGroup && source[i] === "]") {
|
|
2664
|
-
inCharGroup = false;
|
|
2665
|
-
} else if (!inCharGroup && source[i] === "[") {
|
|
2666
|
-
inCharGroup = true;
|
|
2667
|
-
}
|
|
2668
|
-
}
|
|
2669
|
-
try {
|
|
2670
|
-
new RegExp(pattern);
|
|
2671
|
-
} catch (e) {
|
|
2672
|
-
console.warn(
|
|
2673
|
-
`Could not convert regex pattern at ${refs.currentPath.join(
|
|
2674
|
-
"/"
|
|
2675
|
-
)} to a flag-independent form! Falling back to the flag-ignorant source`
|
|
2676
|
-
);
|
|
2677
|
-
return regex.source;
|
|
2678
|
-
}
|
|
2679
|
-
return pattern;
|
|
2680
|
-
}
|
|
2681
|
-
function parseRecordDef(def, refs) {
|
|
2682
|
-
var _a32, _b32, _c, _d, _e, _f;
|
|
2683
|
-
const schema = {
|
|
2684
|
-
type: "object",
|
|
2685
|
-
additionalProperties: (_a32 = parseDef(def.valueType._def, {
|
|
2686
|
-
...refs,
|
|
2687
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
2688
|
-
})) != null ? _a32 : refs.allowedAdditionalProperties
|
|
2689
|
-
};
|
|
2690
|
-
if (((_b32 = def.keyType) == null ? void 0 : _b32._def.typeName) === "ZodString" && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
2691
|
-
const { type: _type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
2692
|
-
return {
|
|
2693
|
-
...schema,
|
|
2694
|
-
propertyNames: keyType
|
|
2695
|
-
};
|
|
2696
|
-
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) === "ZodEnum") {
|
|
2697
|
-
return {
|
|
2698
|
-
...schema,
|
|
2699
|
-
propertyNames: {
|
|
2700
|
-
enum: def.keyType._def.values
|
|
2701
|
-
}
|
|
2702
|
-
};
|
|
2703
|
-
} else if (((_e = def.keyType) == null ? void 0 : _e._def.typeName) === "ZodBranded" && def.keyType._def.type._def.typeName === "ZodString" && ((_f = def.keyType._def.type._def.checks) == null ? void 0 : _f.length)) {
|
|
2704
|
-
const { type: _type, ...keyType } = parseBrandedDef(
|
|
2705
|
-
def.keyType._def,
|
|
2706
|
-
refs
|
|
2707
|
-
);
|
|
2708
|
-
return {
|
|
2709
|
-
...schema,
|
|
2710
|
-
propertyNames: keyType
|
|
2711
|
-
};
|
|
2712
|
-
}
|
|
2713
|
-
return schema;
|
|
2714
|
-
}
|
|
2715
|
-
function parseMapDef(def, refs) {
|
|
2716
|
-
if (refs.mapStrategy === "record") {
|
|
2717
|
-
return parseRecordDef(def, refs);
|
|
2718
|
-
}
|
|
2719
|
-
const keys = parseDef(def.keyType._def, {
|
|
2720
|
-
...refs,
|
|
2721
|
-
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
2722
|
-
}) || parseAnyDef();
|
|
2723
|
-
const values = parseDef(def.valueType._def, {
|
|
2724
|
-
...refs,
|
|
2725
|
-
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
2726
|
-
}) || parseAnyDef();
|
|
2727
|
-
return {
|
|
2728
|
-
type: "array",
|
|
2729
|
-
maxItems: 125,
|
|
2730
|
-
items: {
|
|
2731
|
-
type: "array",
|
|
2732
|
-
items: [keys, values],
|
|
2733
|
-
minItems: 2,
|
|
2734
|
-
maxItems: 2
|
|
2735
|
-
}
|
|
2736
|
-
};
|
|
2737
|
-
}
|
|
2738
|
-
function parseNativeEnumDef(def) {
|
|
2739
|
-
const object = def.values;
|
|
2740
|
-
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
2741
|
-
return typeof object[object[key]] !== "number";
|
|
2742
|
-
});
|
|
2743
|
-
const actualValues = actualKeys.map((key) => object[key]);
|
|
2744
|
-
const parsedTypes = Array.from(
|
|
2745
|
-
new Set(actualValues.map((values) => typeof values))
|
|
2746
|
-
);
|
|
2747
|
-
return {
|
|
2748
|
-
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
2749
|
-
enum: actualValues
|
|
2750
|
-
};
|
|
2751
|
-
}
|
|
2752
|
-
function parseNeverDef() {
|
|
2753
|
-
return { not: parseAnyDef() };
|
|
2754
|
-
}
|
|
2755
|
-
function parseNullDef() {
|
|
2756
|
-
return {
|
|
2757
|
-
type: "null"
|
|
2758
|
-
};
|
|
2759
|
-
}
|
|
2760
|
-
var primitiveMappings = {
|
|
2761
|
-
ZodString: "string",
|
|
2762
|
-
ZodNumber: "number",
|
|
2763
|
-
ZodBigInt: "integer",
|
|
2764
|
-
ZodBoolean: "boolean",
|
|
2765
|
-
ZodNull: "null"
|
|
2766
|
-
};
|
|
2767
|
-
function parseUnionDef(def, refs) {
|
|
2768
|
-
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
2769
|
-
if (options.every(
|
|
2770
|
-
(x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length)
|
|
2771
|
-
)) {
|
|
2772
|
-
const types = options.reduce((types2, x) => {
|
|
2773
|
-
const type = primitiveMappings[x._def.typeName];
|
|
2774
|
-
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
2775
|
-
}, []);
|
|
2776
|
-
return {
|
|
2777
|
-
type: types.length > 1 ? types : types[0]
|
|
2778
|
-
};
|
|
2779
|
-
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
2780
|
-
const types = options.reduce(
|
|
2781
|
-
(acc, x) => {
|
|
2782
|
-
const type = typeof x._def.value;
|
|
2783
|
-
switch (type) {
|
|
2784
|
-
case "string":
|
|
2785
|
-
case "number":
|
|
2786
|
-
case "boolean":
|
|
2787
|
-
return [...acc, type];
|
|
2788
|
-
case "bigint":
|
|
2789
|
-
return [...acc, "integer"];
|
|
2790
|
-
case "object":
|
|
2791
|
-
if (x._def.value === null) return [...acc, "null"];
|
|
2792
|
-
case "symbol":
|
|
2793
|
-
case "undefined":
|
|
2794
|
-
case "function":
|
|
2795
|
-
default:
|
|
2796
|
-
return acc;
|
|
2797
|
-
}
|
|
2798
|
-
},
|
|
2799
|
-
[]
|
|
2800
|
-
);
|
|
2801
|
-
if (types.length === options.length) {
|
|
2802
|
-
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
2803
|
-
return {
|
|
2804
|
-
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
2805
|
-
enum: options.reduce(
|
|
2806
|
-
(acc, x) => {
|
|
2807
|
-
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
2808
|
-
},
|
|
2809
|
-
[]
|
|
2810
|
-
)
|
|
2811
|
-
};
|
|
2812
|
-
}
|
|
2813
|
-
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
2814
|
-
return {
|
|
2815
|
-
type: "string",
|
|
2816
|
-
enum: options.reduce(
|
|
2817
|
-
(acc, x) => [
|
|
2818
|
-
...acc,
|
|
2819
|
-
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
2820
|
-
],
|
|
2821
|
-
[]
|
|
2822
|
-
)
|
|
2823
|
-
};
|
|
2824
|
-
}
|
|
2825
|
-
return asAnyOf(def, refs);
|
|
2826
|
-
}
|
|
2827
|
-
var asAnyOf = (def, refs) => {
|
|
2828
|
-
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map(
|
|
2829
|
-
(x, i) => parseDef(x._def, {
|
|
2830
|
-
...refs,
|
|
2831
|
-
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
2832
|
-
})
|
|
2833
|
-
).filter(
|
|
2834
|
-
(x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0)
|
|
2835
|
-
);
|
|
2836
|
-
return anyOf.length ? { anyOf } : void 0;
|
|
2837
|
-
};
|
|
2838
|
-
function parseNullableDef(def, refs) {
|
|
2839
|
-
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(
|
|
2840
|
-
def.innerType._def.typeName
|
|
2841
|
-
) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
2842
|
-
return {
|
|
2843
|
-
type: [
|
|
2844
|
-
primitiveMappings[def.innerType._def.typeName],
|
|
2845
|
-
"null"
|
|
2846
|
-
]
|
|
2847
|
-
};
|
|
2848
|
-
}
|
|
2849
|
-
const base = parseDef(def.innerType._def, {
|
|
2850
|
-
...refs,
|
|
2851
|
-
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
2852
|
-
});
|
|
2853
|
-
return base && { anyOf: [base, { type: "null" }] };
|
|
2854
|
-
}
|
|
2855
|
-
function parseNumberDef(def) {
|
|
2856
|
-
const res = {
|
|
2857
|
-
type: "number"
|
|
2858
|
-
};
|
|
2859
|
-
if (!def.checks) return res;
|
|
2860
|
-
for (const check of def.checks) {
|
|
2861
|
-
switch (check.kind) {
|
|
2862
|
-
case "int":
|
|
2863
|
-
res.type = "integer";
|
|
2864
|
-
break;
|
|
2865
|
-
case "min":
|
|
2866
|
-
if (check.inclusive) {
|
|
2867
|
-
res.minimum = check.value;
|
|
2868
|
-
} else {
|
|
2869
|
-
res.exclusiveMinimum = check.value;
|
|
2870
|
-
}
|
|
2871
|
-
break;
|
|
2872
|
-
case "max":
|
|
2873
|
-
if (check.inclusive) {
|
|
2874
|
-
res.maximum = check.value;
|
|
2875
|
-
} else {
|
|
2876
|
-
res.exclusiveMaximum = check.value;
|
|
2877
|
-
}
|
|
2878
|
-
break;
|
|
2879
|
-
case "multipleOf":
|
|
2880
|
-
res.multipleOf = check.value;
|
|
2881
|
-
break;
|
|
2882
|
-
}
|
|
2883
|
-
}
|
|
2884
|
-
return res;
|
|
2885
|
-
}
|
|
2886
|
-
function parseObjectDef(def, refs) {
|
|
2887
|
-
const result = {
|
|
2888
|
-
type: "object",
|
|
2889
|
-
properties: {}
|
|
2890
|
-
};
|
|
2891
|
-
const required = [];
|
|
2892
|
-
const shape = def.shape();
|
|
2893
|
-
for (const propName in shape) {
|
|
2894
|
-
let propDef = shape[propName];
|
|
2895
|
-
if (propDef === void 0 || propDef._def === void 0) {
|
|
2896
|
-
continue;
|
|
2897
|
-
}
|
|
2898
|
-
const propOptional = safeIsOptional(propDef);
|
|
2899
|
-
const parsedDef = parseDef(propDef._def, {
|
|
2900
|
-
...refs,
|
|
2901
|
-
currentPath: [...refs.currentPath, "properties", propName],
|
|
2902
|
-
propertyPath: [...refs.currentPath, "properties", propName]
|
|
2903
|
-
});
|
|
2904
|
-
if (parsedDef === void 0) {
|
|
2905
|
-
continue;
|
|
2906
|
-
}
|
|
2907
|
-
result.properties[propName] = parsedDef;
|
|
2908
|
-
if (!propOptional) {
|
|
2909
|
-
required.push(propName);
|
|
2910
|
-
}
|
|
2911
|
-
}
|
|
2912
|
-
if (required.length) {
|
|
2913
|
-
result.required = required;
|
|
2914
|
-
}
|
|
2915
|
-
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
2916
|
-
if (additionalProperties !== void 0) {
|
|
2917
|
-
result.additionalProperties = additionalProperties;
|
|
2918
|
-
}
|
|
2919
|
-
return result;
|
|
2920
|
-
}
|
|
2921
|
-
function decideAdditionalProperties(def, refs) {
|
|
2922
|
-
if (def.catchall._def.typeName !== "ZodNever") {
|
|
2923
|
-
return parseDef(def.catchall._def, {
|
|
2924
|
-
...refs,
|
|
2925
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
2926
|
-
});
|
|
2927
|
-
}
|
|
2928
|
-
switch (def.unknownKeys) {
|
|
2929
|
-
case "passthrough":
|
|
2930
|
-
return refs.allowedAdditionalProperties;
|
|
2931
|
-
case "strict":
|
|
2932
|
-
return refs.rejectedAdditionalProperties;
|
|
2933
|
-
case "strip":
|
|
2934
|
-
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
2935
|
-
}
|
|
2936
|
-
}
|
|
2937
|
-
function safeIsOptional(schema) {
|
|
2938
|
-
try {
|
|
2939
|
-
return schema.isOptional();
|
|
2940
|
-
} catch (e) {
|
|
2941
|
-
return true;
|
|
2942
|
-
}
|
|
2943
|
-
}
|
|
2944
|
-
var parseOptionalDef = (def, refs) => {
|
|
2945
|
-
var _a32;
|
|
2946
|
-
if (refs.currentPath.toString() === ((_a32 = refs.propertyPath) == null ? void 0 : _a32.toString())) {
|
|
2947
|
-
return parseDef(def.innerType._def, refs);
|
|
2948
|
-
}
|
|
2949
|
-
const innerSchema = parseDef(def.innerType._def, {
|
|
2950
|
-
...refs,
|
|
2951
|
-
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
2952
|
-
});
|
|
2953
|
-
return innerSchema ? { anyOf: [{ not: parseAnyDef() }, innerSchema] } : parseAnyDef();
|
|
2954
|
-
};
|
|
2955
|
-
var parsePipelineDef = (def, refs) => {
|
|
2956
|
-
if (refs.pipeStrategy === "input") {
|
|
2957
|
-
return parseDef(def.in._def, refs);
|
|
2958
|
-
} else if (refs.pipeStrategy === "output") {
|
|
2959
|
-
return parseDef(def.out._def, refs);
|
|
2960
|
-
}
|
|
2961
|
-
const inputSchema = parseDef(def.in._def, {
|
|
2962
|
-
...refs,
|
|
2963
|
-
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
2964
|
-
});
|
|
2965
|
-
const outputSchema = parseDef(def.out._def, {
|
|
2966
|
-
...refs,
|
|
2967
|
-
currentPath: [...refs.currentPath, "allOf", inputSchema ? "1" : "0"]
|
|
2968
|
-
});
|
|
2969
|
-
return {
|
|
2970
|
-
allOf: [inputSchema, outputSchema].filter(
|
|
2971
|
-
(schema) => schema !== void 0
|
|
2972
|
-
)
|
|
2973
|
-
};
|
|
2974
|
-
};
|
|
2975
|
-
function parsePromiseDef(def, refs) {
|
|
2976
|
-
return parseDef(def.type._def, refs);
|
|
2977
|
-
}
|
|
2978
|
-
function parseSetDef(def, refs) {
|
|
2979
|
-
const items = parseDef(def.valueType._def, {
|
|
2980
|
-
...refs,
|
|
2981
|
-
currentPath: [...refs.currentPath, "items"]
|
|
2982
|
-
});
|
|
2983
|
-
const schema = {
|
|
2984
|
-
type: "array",
|
|
2985
|
-
uniqueItems: true,
|
|
2986
|
-
items
|
|
2987
|
-
};
|
|
2988
|
-
if (def.minSize) {
|
|
2989
|
-
schema.minItems = def.minSize.value;
|
|
2990
|
-
}
|
|
2991
|
-
if (def.maxSize) {
|
|
2992
|
-
schema.maxItems = def.maxSize.value;
|
|
2993
|
-
}
|
|
2994
|
-
return schema;
|
|
2995
|
-
}
|
|
2996
|
-
function parseTupleDef(def, refs) {
|
|
2997
|
-
if (def.rest) {
|
|
2998
|
-
return {
|
|
2999
|
-
type: "array",
|
|
3000
|
-
minItems: def.items.length,
|
|
3001
|
-
items: def.items.map(
|
|
3002
|
-
(x, i) => parseDef(x._def, {
|
|
3003
|
-
...refs,
|
|
3004
|
-
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
3005
|
-
})
|
|
3006
|
-
).reduce(
|
|
3007
|
-
(acc, x) => x === void 0 ? acc : [...acc, x],
|
|
3008
|
-
[]
|
|
3009
|
-
),
|
|
3010
|
-
additionalItems: parseDef(def.rest._def, {
|
|
3011
|
-
...refs,
|
|
3012
|
-
currentPath: [...refs.currentPath, "additionalItems"]
|
|
3013
|
-
})
|
|
3014
|
-
};
|
|
3015
|
-
} else {
|
|
3016
|
-
return {
|
|
3017
|
-
type: "array",
|
|
3018
|
-
minItems: def.items.length,
|
|
3019
|
-
maxItems: def.items.length,
|
|
3020
|
-
items: def.items.map(
|
|
3021
|
-
(x, i) => parseDef(x._def, {
|
|
3022
|
-
...refs,
|
|
3023
|
-
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
3024
|
-
})
|
|
3025
|
-
).reduce(
|
|
3026
|
-
(acc, x) => x === void 0 ? acc : [...acc, x],
|
|
3027
|
-
[]
|
|
3028
|
-
)
|
|
3029
|
-
};
|
|
3030
|
-
}
|
|
3031
|
-
}
|
|
3032
|
-
function parseUndefinedDef() {
|
|
3033
|
-
return {
|
|
3034
|
-
not: parseAnyDef()
|
|
3035
|
-
};
|
|
3036
|
-
}
|
|
3037
|
-
function parseUnknownDef() {
|
|
3038
|
-
return parseAnyDef();
|
|
3039
|
-
}
|
|
3040
|
-
var parseReadonlyDef = (def, refs) => {
|
|
3041
|
-
return parseDef(def.innerType._def, refs);
|
|
3042
|
-
};
|
|
3043
|
-
var selectParser = (def, typeName, refs) => {
|
|
3044
|
-
switch (typeName) {
|
|
3045
|
-
case "ZodString":
|
|
3046
|
-
return parseStringDef(def, refs);
|
|
3047
|
-
case "ZodNumber":
|
|
3048
|
-
return parseNumberDef(def);
|
|
3049
|
-
case "ZodObject":
|
|
3050
|
-
return parseObjectDef(def, refs);
|
|
3051
|
-
case "ZodBigInt":
|
|
3052
|
-
return parseBigintDef(def);
|
|
3053
|
-
case "ZodBoolean":
|
|
3054
|
-
return parseBooleanDef();
|
|
3055
|
-
case "ZodDate":
|
|
3056
|
-
return parseDateDef(def, refs);
|
|
3057
|
-
case "ZodUndefined":
|
|
3058
|
-
return parseUndefinedDef();
|
|
3059
|
-
case "ZodNull":
|
|
3060
|
-
return parseNullDef();
|
|
3061
|
-
case "ZodArray":
|
|
3062
|
-
return parseArrayDef(def, refs);
|
|
3063
|
-
case "ZodUnion":
|
|
3064
|
-
case "ZodDiscriminatedUnion":
|
|
3065
|
-
return parseUnionDef(def, refs);
|
|
3066
|
-
case "ZodIntersection":
|
|
3067
|
-
return parseIntersectionDef(def, refs);
|
|
3068
|
-
case "ZodTuple":
|
|
3069
|
-
return parseTupleDef(def, refs);
|
|
3070
|
-
case "ZodRecord":
|
|
3071
|
-
return parseRecordDef(def, refs);
|
|
3072
|
-
case "ZodLiteral":
|
|
3073
|
-
return parseLiteralDef(def);
|
|
3074
|
-
case "ZodEnum":
|
|
3075
|
-
return parseEnumDef(def);
|
|
3076
|
-
case "ZodNativeEnum":
|
|
3077
|
-
return parseNativeEnumDef(def);
|
|
3078
|
-
case "ZodNullable":
|
|
3079
|
-
return parseNullableDef(def, refs);
|
|
3080
|
-
case "ZodOptional":
|
|
3081
|
-
return parseOptionalDef(def, refs);
|
|
3082
|
-
case "ZodMap":
|
|
3083
|
-
return parseMapDef(def, refs);
|
|
3084
|
-
case "ZodSet":
|
|
3085
|
-
return parseSetDef(def, refs);
|
|
3086
|
-
case "ZodLazy":
|
|
3087
|
-
return () => def.getter()._def;
|
|
3088
|
-
case "ZodPromise":
|
|
3089
|
-
return parsePromiseDef(def, refs);
|
|
3090
|
-
case "ZodNaN":
|
|
3091
|
-
case "ZodNever":
|
|
3092
|
-
return parseNeverDef();
|
|
3093
|
-
case "ZodEffects":
|
|
3094
|
-
return parseEffectsDef(def, refs);
|
|
3095
|
-
case "ZodAny":
|
|
3096
|
-
return parseAnyDef();
|
|
3097
|
-
case "ZodUnknown":
|
|
3098
|
-
return parseUnknownDef();
|
|
3099
|
-
case "ZodDefault":
|
|
3100
|
-
return parseDefaultDef(def, refs);
|
|
3101
|
-
case "ZodBranded":
|
|
3102
|
-
return parseBrandedDef(def, refs);
|
|
3103
|
-
case "ZodReadonly":
|
|
3104
|
-
return parseReadonlyDef(def, refs);
|
|
3105
|
-
case "ZodCatch":
|
|
3106
|
-
return parseCatchDef(def, refs);
|
|
3107
|
-
case "ZodPipeline":
|
|
3108
|
-
return parsePipelineDef(def, refs);
|
|
3109
|
-
case "ZodFunction":
|
|
3110
|
-
case "ZodVoid":
|
|
3111
|
-
case "ZodSymbol":
|
|
3112
|
-
return void 0;
|
|
3113
|
-
default:
|
|
3114
|
-
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
3115
|
-
}
|
|
3116
|
-
};
|
|
3117
|
-
var getRelativePath = (pathA, pathB) => {
|
|
3118
|
-
let i = 0;
|
|
3119
|
-
for (; i < pathA.length && i < pathB.length; i++) {
|
|
3120
|
-
if (pathA[i] !== pathB[i]) break;
|
|
3121
|
-
}
|
|
3122
|
-
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
3123
|
-
};
|
|
3124
|
-
function parseDef(def, refs, forceResolution = false) {
|
|
3125
|
-
var _a32;
|
|
3126
|
-
const seenItem = refs.seen.get(def);
|
|
3127
|
-
if (refs.override) {
|
|
3128
|
-
const overrideResult = (_a32 = refs.override) == null ? void 0 : _a32.call(
|
|
3129
|
-
refs,
|
|
3130
|
-
def,
|
|
3131
|
-
refs,
|
|
3132
|
-
seenItem,
|
|
3133
|
-
forceResolution
|
|
3134
|
-
);
|
|
3135
|
-
if (overrideResult !== ignoreOverride) {
|
|
3136
|
-
return overrideResult;
|
|
3137
|
-
}
|
|
3138
|
-
}
|
|
3139
|
-
if (seenItem && !forceResolution) {
|
|
3140
|
-
const seenSchema = get$ref(seenItem, refs);
|
|
3141
|
-
if (seenSchema !== void 0) {
|
|
3142
|
-
return seenSchema;
|
|
3143
|
-
}
|
|
3144
|
-
}
|
|
3145
|
-
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
3146
|
-
refs.seen.set(def, newItem);
|
|
3147
|
-
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
3148
|
-
const jsonSchema2 = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
3149
|
-
if (jsonSchema2) {
|
|
3150
|
-
addMeta(def, refs, jsonSchema2);
|
|
3151
|
-
}
|
|
3152
|
-
if (refs.postProcess) {
|
|
3153
|
-
const postProcessResult = refs.postProcess(jsonSchema2, def, refs);
|
|
3154
|
-
newItem.jsonSchema = jsonSchema2;
|
|
3155
|
-
return postProcessResult;
|
|
3156
|
-
}
|
|
3157
|
-
newItem.jsonSchema = jsonSchema2;
|
|
3158
|
-
return jsonSchema2;
|
|
3159
|
-
}
|
|
3160
|
-
var get$ref = (item, refs) => {
|
|
3161
|
-
switch (refs.$refStrategy) {
|
|
3162
|
-
case "root":
|
|
3163
|
-
return { $ref: item.path.join("/") };
|
|
3164
|
-
case "relative":
|
|
3165
|
-
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
3166
|
-
case "none":
|
|
3167
|
-
case "seen": {
|
|
3168
|
-
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
3169
|
-
console.warn(
|
|
3170
|
-
`Recursive reference detected at ${refs.currentPath.join(
|
|
3171
|
-
"/"
|
|
3172
|
-
)}! Defaulting to any`
|
|
3173
|
-
);
|
|
3174
|
-
return parseAnyDef();
|
|
3175
|
-
}
|
|
3176
|
-
return refs.$refStrategy === "seen" ? parseAnyDef() : void 0;
|
|
3177
|
-
}
|
|
3178
|
-
}
|
|
3179
|
-
};
|
|
3180
|
-
var addMeta = (def, refs, jsonSchema2) => {
|
|
3181
|
-
if (def.description) {
|
|
3182
|
-
jsonSchema2.description = def.description;
|
|
3183
|
-
}
|
|
3184
|
-
return jsonSchema2;
|
|
3185
|
-
};
|
|
3186
|
-
var getRefs = (options) => {
|
|
3187
|
-
const _options = getDefaultOptions(options);
|
|
3188
|
-
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
3189
|
-
return {
|
|
3190
|
-
..._options,
|
|
3191
|
-
currentPath,
|
|
3192
|
-
propertyPath: void 0,
|
|
3193
|
-
seen: new Map(
|
|
3194
|
-
Object.entries(_options.definitions).map(([name32, def]) => [
|
|
3195
|
-
def._def,
|
|
3196
|
-
{
|
|
3197
|
-
def: def._def,
|
|
3198
|
-
path: [..._options.basePath, _options.definitionPath, name32],
|
|
3199
|
-
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
3200
|
-
jsonSchema: void 0
|
|
3201
|
-
}
|
|
3202
|
-
])
|
|
3203
|
-
)
|
|
3204
|
-
};
|
|
3205
|
-
};
|
|
3206
|
-
var zod3ToJsonSchema = (schema, options) => {
|
|
3207
|
-
var _a32;
|
|
3208
|
-
const refs = getRefs(options);
|
|
3209
|
-
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
|
|
3210
|
-
(acc, [name42, schema2]) => {
|
|
3211
|
-
var _a42;
|
|
3212
|
-
return {
|
|
3213
|
-
...acc,
|
|
3214
|
-
[name42]: (_a42 = parseDef(
|
|
3215
|
-
schema2._def,
|
|
3216
|
-
{
|
|
3217
|
-
...refs,
|
|
3218
|
-
currentPath: [...refs.basePath, refs.definitionPath, name42]
|
|
3219
|
-
},
|
|
3220
|
-
true
|
|
3221
|
-
)) != null ? _a42 : parseAnyDef()
|
|
3222
|
-
};
|
|
3223
|
-
},
|
|
3224
|
-
{}
|
|
3225
|
-
) : void 0;
|
|
3226
|
-
const name32 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
3227
|
-
const main = (_a32 = parseDef(
|
|
3228
|
-
schema._def,
|
|
3229
|
-
name32 === void 0 ? refs : {
|
|
3230
|
-
...refs,
|
|
3231
|
-
currentPath: [...refs.basePath, refs.definitionPath, name32]
|
|
3232
|
-
},
|
|
3233
|
-
false
|
|
3234
|
-
)) != null ? _a32 : parseAnyDef();
|
|
3235
|
-
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
3236
|
-
if (title !== void 0) {
|
|
3237
|
-
main.title = title;
|
|
3238
|
-
}
|
|
3239
|
-
const combined = name32 === void 0 ? definitions ? {
|
|
3240
|
-
...main,
|
|
3241
|
-
[refs.definitionPath]: definitions
|
|
3242
|
-
} : main : {
|
|
3243
|
-
$ref: [
|
|
3244
|
-
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
3245
|
-
refs.definitionPath,
|
|
3246
|
-
name32
|
|
3247
|
-
].join("/"),
|
|
3248
|
-
[refs.definitionPath]: {
|
|
3249
|
-
...definitions,
|
|
3250
|
-
[name32]: main
|
|
3251
|
-
}
|
|
3252
|
-
};
|
|
3253
|
-
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
3254
|
-
return combined;
|
|
3255
|
-
};
|
|
3256
|
-
var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
3257
|
-
function lazySchema(createSchema) {
|
|
3258
|
-
let schema;
|
|
3259
|
-
return () => {
|
|
3260
|
-
if (schema == null) {
|
|
3261
|
-
schema = createSchema();
|
|
3262
|
-
}
|
|
3263
|
-
return schema;
|
|
3264
|
-
};
|
|
3265
|
-
}
|
|
3266
|
-
function jsonSchema(jsonSchema2, {
|
|
3267
|
-
validate
|
|
3268
|
-
} = {}) {
|
|
3269
|
-
return {
|
|
3270
|
-
[schemaSymbol]: true,
|
|
3271
|
-
_type: void 0,
|
|
3272
|
-
// should never be used directly
|
|
3273
|
-
get jsonSchema() {
|
|
3274
|
-
if (typeof jsonSchema2 === "function") {
|
|
3275
|
-
jsonSchema2 = jsonSchema2();
|
|
3276
|
-
}
|
|
3277
|
-
return jsonSchema2;
|
|
3278
|
-
},
|
|
3279
|
-
validate
|
|
3280
|
-
};
|
|
3281
|
-
}
|
|
3282
|
-
function isSchema(value) {
|
|
3283
|
-
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
|
3284
|
-
}
|
|
3285
|
-
function asSchema(schema) {
|
|
3286
|
-
return schema == null ? jsonSchema({
|
|
3287
|
-
type: "object",
|
|
3288
|
-
properties: {},
|
|
3289
|
-
additionalProperties: false
|
|
3290
|
-
}) : isSchema(schema) ? schema : "~standard" in schema ? schema["~standard"].vendor === "zod" ? zodSchema(schema) : standardSchema(schema) : schema();
|
|
3291
|
-
}
|
|
3292
|
-
function standardSchema(standardSchema2) {
|
|
3293
|
-
return jsonSchema(
|
|
3294
|
-
() => {
|
|
3295
|
-
if (!hasStandardJsonSchema(standardSchema2)) {
|
|
3296
|
-
throw new Error(
|
|
3297
|
-
`Standard schema vendor '${standardSchema2["~standard"].vendor}' does not support JSON Schema conversion.`
|
|
3298
|
-
);
|
|
3299
|
-
}
|
|
3300
|
-
return addAdditionalPropertiesToJsonSchema(
|
|
3301
|
-
standardSchema2["~standard"].jsonSchema.input({
|
|
3302
|
-
target: "draft-07"
|
|
3303
|
-
})
|
|
3304
|
-
);
|
|
3305
|
-
},
|
|
3306
|
-
{
|
|
3307
|
-
validate: async (value) => {
|
|
3308
|
-
const result = await standardSchema2["~standard"].validate(value);
|
|
3309
|
-
return "value" in result ? { success: true, value: result.value } : {
|
|
3310
|
-
success: false,
|
|
3311
|
-
error: new TypeValidationError({
|
|
3312
|
-
value,
|
|
3313
|
-
cause: result.issues
|
|
3314
|
-
})
|
|
3315
|
-
};
|
|
3316
|
-
}
|
|
3317
|
-
}
|
|
3318
|
-
);
|
|
3319
|
-
}
|
|
3320
|
-
function hasStandardJsonSchema(schema) {
|
|
3321
|
-
return schema["~standard"].jsonSchema != null;
|
|
3322
|
-
}
|
|
3323
|
-
function zod3Schema(zodSchema2, options) {
|
|
3324
|
-
var _a32;
|
|
3325
|
-
const useReferences = (_a32 = options == null ? void 0 : options.useReferences) != null ? _a32 : false;
|
|
3326
|
-
return jsonSchema(
|
|
3327
|
-
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
3328
|
-
() => zod3ToJsonSchema(zodSchema2, {
|
|
3329
|
-
$refStrategy: useReferences ? "root" : "none"
|
|
3330
|
-
}),
|
|
3331
|
-
{
|
|
3332
|
-
validate: async (value) => {
|
|
3333
|
-
const result = await zodSchema2.safeParseAsync(value);
|
|
3334
|
-
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
3335
|
-
}
|
|
3336
|
-
}
|
|
3337
|
-
);
|
|
3338
|
-
}
|
|
3339
|
-
function zod4Schema(zodSchema2, options) {
|
|
3340
|
-
var _a32;
|
|
3341
|
-
const useReferences = (_a32 = options == null ? void 0 : options.useReferences) != null ? _a32 : false;
|
|
3342
|
-
return jsonSchema(
|
|
3343
|
-
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
3344
|
-
() => addAdditionalPropertiesToJsonSchema(
|
|
3345
|
-
toJSONSchema(zodSchema2, {
|
|
3346
|
-
target: "draft-7",
|
|
3347
|
-
io: "input",
|
|
3348
|
-
reused: useReferences ? "ref" : "inline"
|
|
3349
|
-
})
|
|
3350
|
-
),
|
|
3351
|
-
{
|
|
3352
|
-
validate: async (value) => {
|
|
3353
|
-
const result = await safeParseAsync(zodSchema2, value);
|
|
3354
|
-
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
3355
|
-
}
|
|
3356
|
-
}
|
|
3357
|
-
);
|
|
3358
|
-
}
|
|
3359
|
-
function isZod4Schema(zodSchema2) {
|
|
3360
|
-
return "_zod" in zodSchema2;
|
|
3361
|
-
}
|
|
3362
|
-
function zodSchema(zodSchema2, options) {
|
|
3363
|
-
if (isZod4Schema(zodSchema2)) {
|
|
3364
|
-
return zod4Schema(zodSchema2, options);
|
|
3365
|
-
} else {
|
|
3366
|
-
return zod3Schema(zodSchema2, options);
|
|
3367
|
-
}
|
|
3368
|
-
}
|
|
3369
|
-
async function validateTypes({
|
|
3370
|
-
value,
|
|
3371
|
-
schema,
|
|
3372
|
-
context
|
|
3373
|
-
}) {
|
|
3374
|
-
const result = await safeValidateTypes({ value, schema, context });
|
|
3375
|
-
if (!result.success) {
|
|
3376
|
-
throw TypeValidationError.wrap({ value, cause: result.error, context });
|
|
3377
|
-
}
|
|
3378
|
-
return result.value;
|
|
3379
|
-
}
|
|
3380
|
-
async function safeValidateTypes({
|
|
3381
|
-
value,
|
|
3382
|
-
schema,
|
|
3383
|
-
context
|
|
3384
|
-
}) {
|
|
3385
|
-
const actualSchema = asSchema(schema);
|
|
3386
|
-
try {
|
|
3387
|
-
if (actualSchema.validate == null) {
|
|
3388
|
-
return { success: true, value, rawValue: value };
|
|
3389
|
-
}
|
|
3390
|
-
const result = await actualSchema.validate(value);
|
|
3391
|
-
if (result.success) {
|
|
3392
|
-
return { success: true, value: result.value, rawValue: value };
|
|
3393
|
-
}
|
|
3394
|
-
return {
|
|
3395
|
-
success: false,
|
|
3396
|
-
error: TypeValidationError.wrap({ value, cause: result.error, context }),
|
|
3397
|
-
rawValue: value
|
|
3398
|
-
};
|
|
3399
|
-
} catch (error) {
|
|
3400
|
-
return {
|
|
3401
|
-
success: false,
|
|
3402
|
-
error: TypeValidationError.wrap({ value, cause: error, context }),
|
|
3403
|
-
rawValue: value
|
|
3404
|
-
};
|
|
3405
|
-
}
|
|
3406
|
-
}
|
|
3407
|
-
async function parseJSON({
|
|
3408
|
-
text,
|
|
3409
|
-
schema
|
|
3410
|
-
}) {
|
|
3411
|
-
try {
|
|
3412
|
-
const value = secureJsonParse(text);
|
|
3413
|
-
if (schema == null) {
|
|
3414
|
-
return value;
|
|
3415
|
-
}
|
|
3416
|
-
return await validateTypes({ value, schema });
|
|
3417
|
-
} catch (error) {
|
|
3418
|
-
if (JSONParseError.isInstance(error) || TypeValidationError.isInstance(error)) {
|
|
3419
|
-
throw error;
|
|
3420
|
-
}
|
|
3421
|
-
throw new JSONParseError({ text, cause: error });
|
|
3422
|
-
}
|
|
3423
|
-
}
|
|
3424
|
-
async function safeParseJSON({
|
|
3425
|
-
text,
|
|
3426
|
-
schema
|
|
3427
|
-
}) {
|
|
3428
|
-
try {
|
|
3429
|
-
const value = secureJsonParse(text);
|
|
3430
|
-
if (schema == null) {
|
|
3431
|
-
return { success: true, value, rawValue: value };
|
|
3432
|
-
}
|
|
3433
|
-
return await safeValidateTypes({ value, schema });
|
|
3434
|
-
} catch (error) {
|
|
3435
|
-
return {
|
|
3436
|
-
success: false,
|
|
3437
|
-
error: JSONParseError.isInstance(error) ? error : new JSONParseError({ text, cause: error }),
|
|
3438
|
-
rawValue: void 0
|
|
3439
|
-
};
|
|
3440
|
-
}
|
|
3441
|
-
}
|
|
3442
|
-
function parseJsonEventStream({
|
|
3443
|
-
stream,
|
|
3444
|
-
schema
|
|
3445
|
-
}) {
|
|
3446
|
-
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream()).pipeThrough(
|
|
3447
|
-
new TransformStream({
|
|
3448
|
-
async transform({ data }, controller) {
|
|
3449
|
-
if (data === "[DONE]") {
|
|
3450
|
-
return;
|
|
3451
|
-
}
|
|
3452
|
-
controller.enqueue(await safeParseJSON({ text: data, schema }));
|
|
3453
|
-
}
|
|
3454
|
-
})
|
|
3455
|
-
);
|
|
3456
|
-
}
|
|
3457
|
-
async function parseProviderOptions({
|
|
3458
|
-
provider,
|
|
3459
|
-
providerOptions,
|
|
3460
|
-
schema
|
|
3461
|
-
}) {
|
|
3462
|
-
if ((providerOptions == null ? void 0 : providerOptions[provider]) == null) {
|
|
3463
|
-
return void 0;
|
|
3464
|
-
}
|
|
3465
|
-
const parsedProviderOptions = await safeValidateTypes({
|
|
3466
|
-
value: providerOptions[provider],
|
|
3467
|
-
schema
|
|
3468
|
-
});
|
|
3469
|
-
if (!parsedProviderOptions.success) {
|
|
3470
|
-
throw new InvalidArgumentError({
|
|
3471
|
-
argument: "providerOptions",
|
|
3472
|
-
message: `invalid ${provider} provider options`,
|
|
3473
|
-
cause: parsedProviderOptions.error
|
|
3474
|
-
});
|
|
3475
|
-
}
|
|
3476
|
-
return parsedProviderOptions.value;
|
|
3477
|
-
}
|
|
3478
|
-
var getOriginalFetch2 = () => globalThis.fetch;
|
|
3479
|
-
var postJsonToApi = async ({
|
|
3480
|
-
url,
|
|
3481
|
-
headers,
|
|
3482
|
-
body,
|
|
3483
|
-
failedResponseHandler,
|
|
3484
|
-
successfulResponseHandler,
|
|
3485
|
-
abortSignal,
|
|
3486
|
-
fetch
|
|
3487
|
-
}) => await postToApi({
|
|
3488
|
-
url,
|
|
3489
|
-
headers: {
|
|
3490
|
-
"Content-Type": "application/json",
|
|
3491
|
-
...headers
|
|
3492
|
-
},
|
|
3493
|
-
body: {
|
|
3494
|
-
content: JSON.stringify(body),
|
|
3495
|
-
values: body
|
|
3496
|
-
},
|
|
3497
|
-
failedResponseHandler,
|
|
3498
|
-
successfulResponseHandler,
|
|
3499
|
-
abortSignal,
|
|
3500
|
-
fetch
|
|
3501
|
-
});
|
|
3502
|
-
var postFormDataToApi = async ({
|
|
3503
|
-
url,
|
|
3504
|
-
headers,
|
|
3505
|
-
formData,
|
|
3506
|
-
failedResponseHandler,
|
|
3507
|
-
successfulResponseHandler,
|
|
3508
|
-
abortSignal,
|
|
3509
|
-
fetch
|
|
3510
|
-
}) => await postToApi({
|
|
3511
|
-
url,
|
|
3512
|
-
headers,
|
|
3513
|
-
body: {
|
|
3514
|
-
content: formData,
|
|
3515
|
-
values: Object.fromEntries(formData.entries())
|
|
3516
|
-
},
|
|
3517
|
-
failedResponseHandler,
|
|
3518
|
-
successfulResponseHandler,
|
|
3519
|
-
abortSignal,
|
|
3520
|
-
fetch
|
|
3521
|
-
});
|
|
3522
|
-
var postToApi = async ({
|
|
3523
|
-
url,
|
|
3524
|
-
headers = {},
|
|
3525
|
-
body,
|
|
3526
|
-
successfulResponseHandler,
|
|
3527
|
-
failedResponseHandler,
|
|
3528
|
-
abortSignal,
|
|
3529
|
-
fetch = getOriginalFetch2()
|
|
3530
|
-
}) => {
|
|
3531
|
-
try {
|
|
3532
|
-
const response = await fetch(url, {
|
|
3533
|
-
method: "POST",
|
|
3534
|
-
headers: withUserAgentSuffix(
|
|
3535
|
-
headers,
|
|
3536
|
-
`ai-sdk/provider-utils/${VERSION}`,
|
|
3537
|
-
getRuntimeEnvironmentUserAgent()
|
|
3538
|
-
),
|
|
3539
|
-
body: body.content,
|
|
3540
|
-
signal: abortSignal
|
|
3541
|
-
});
|
|
3542
|
-
const responseHeaders = extractResponseHeaders(response);
|
|
3543
|
-
if (!response.ok) {
|
|
3544
|
-
let errorInformation;
|
|
3545
|
-
try {
|
|
3546
|
-
errorInformation = await failedResponseHandler({
|
|
3547
|
-
response,
|
|
3548
|
-
url,
|
|
3549
|
-
requestBodyValues: body.values
|
|
3550
|
-
});
|
|
3551
|
-
} catch (error) {
|
|
3552
|
-
if (isAbortError(error) || APICallError.isInstance(error)) {
|
|
3553
|
-
throw error;
|
|
3554
|
-
}
|
|
3555
|
-
throw new APICallError({
|
|
3556
|
-
message: "Failed to process error response",
|
|
3557
|
-
cause: error,
|
|
3558
|
-
statusCode: response.status,
|
|
3559
|
-
url,
|
|
3560
|
-
responseHeaders,
|
|
3561
|
-
requestBodyValues: body.values
|
|
3562
|
-
});
|
|
3563
|
-
}
|
|
3564
|
-
throw errorInformation.value;
|
|
3565
|
-
}
|
|
3566
|
-
try {
|
|
3567
|
-
return await successfulResponseHandler({
|
|
3568
|
-
response,
|
|
3569
|
-
url,
|
|
3570
|
-
requestBodyValues: body.values
|
|
3571
|
-
});
|
|
3572
|
-
} catch (error) {
|
|
3573
|
-
if (error instanceof Error) {
|
|
3574
|
-
if (isAbortError(error) || APICallError.isInstance(error)) {
|
|
3575
|
-
throw error;
|
|
3576
|
-
}
|
|
3577
|
-
}
|
|
3578
|
-
throw new APICallError({
|
|
3579
|
-
message: "Failed to process successful response",
|
|
3580
|
-
cause: error,
|
|
3581
|
-
statusCode: response.status,
|
|
3582
|
-
url,
|
|
3583
|
-
responseHeaders,
|
|
3584
|
-
requestBodyValues: body.values
|
|
3585
|
-
});
|
|
3586
|
-
}
|
|
3587
|
-
} catch (error) {
|
|
3588
|
-
throw handleFetchError({ error, url, requestBodyValues: body.values });
|
|
3589
|
-
}
|
|
3590
|
-
};
|
|
3591
|
-
function tool(tool2) {
|
|
3592
|
-
return tool2;
|
|
3593
|
-
}
|
|
3594
|
-
function createProviderDefinedToolFactory({
|
|
3595
|
-
id,
|
|
3596
|
-
inputSchema
|
|
3597
|
-
}) {
|
|
3598
|
-
return ({
|
|
3599
|
-
execute,
|
|
3600
|
-
outputSchema,
|
|
3601
|
-
needsApproval,
|
|
3602
|
-
toModelOutput,
|
|
3603
|
-
onInputStart,
|
|
3604
|
-
onInputDelta,
|
|
3605
|
-
onInputAvailable,
|
|
3606
|
-
...args
|
|
3607
|
-
}) => tool({
|
|
3608
|
-
type: "provider",
|
|
3609
|
-
isProviderExecuted: false,
|
|
3610
|
-
id,
|
|
3611
|
-
args,
|
|
3612
|
-
inputSchema,
|
|
3613
|
-
outputSchema,
|
|
3614
|
-
execute,
|
|
3615
|
-
needsApproval,
|
|
3616
|
-
toModelOutput,
|
|
3617
|
-
onInputStart,
|
|
3618
|
-
onInputDelta,
|
|
3619
|
-
onInputAvailable
|
|
3620
|
-
});
|
|
3621
|
-
}
|
|
3622
|
-
function createProviderDefinedToolFactoryWithOutputSchema({
|
|
3623
|
-
id,
|
|
3624
|
-
inputSchema,
|
|
3625
|
-
outputSchema
|
|
3626
|
-
}) {
|
|
3627
|
-
return ({
|
|
3628
|
-
execute,
|
|
3629
|
-
needsApproval,
|
|
3630
|
-
toModelOutput,
|
|
3631
|
-
onInputStart,
|
|
3632
|
-
onInputDelta,
|
|
3633
|
-
onInputAvailable,
|
|
3634
|
-
...args
|
|
3635
|
-
}) => tool({
|
|
3636
|
-
type: "provider",
|
|
3637
|
-
isProviderExecuted: false,
|
|
3638
|
-
id,
|
|
3639
|
-
args,
|
|
3640
|
-
inputSchema,
|
|
3641
|
-
outputSchema,
|
|
3642
|
-
execute,
|
|
3643
|
-
needsApproval,
|
|
3644
|
-
toModelOutput,
|
|
3645
|
-
onInputStart,
|
|
3646
|
-
onInputDelta,
|
|
3647
|
-
onInputAvailable
|
|
3648
|
-
});
|
|
3649
|
-
}
|
|
3650
|
-
function createProviderExecutedToolFactory({
|
|
3651
|
-
id,
|
|
3652
|
-
inputSchema,
|
|
3653
|
-
outputSchema,
|
|
3654
|
-
supportsDeferredResults
|
|
3655
|
-
}) {
|
|
3656
|
-
return ({
|
|
3657
|
-
onInputStart,
|
|
3658
|
-
onInputDelta,
|
|
3659
|
-
onInputAvailable,
|
|
3660
|
-
...args
|
|
3661
|
-
}) => tool({
|
|
3662
|
-
type: "provider",
|
|
3663
|
-
isProviderExecuted: true,
|
|
3664
|
-
id,
|
|
3665
|
-
args,
|
|
3666
|
-
inputSchema,
|
|
3667
|
-
outputSchema,
|
|
3668
|
-
onInputStart,
|
|
3669
|
-
onInputDelta,
|
|
3670
|
-
onInputAvailable,
|
|
3671
|
-
supportsDeferredResults
|
|
3672
|
-
});
|
|
3673
|
-
}
|
|
3674
|
-
async function resolve(value) {
|
|
3675
|
-
if (typeof value === "function") {
|
|
3676
|
-
value = value();
|
|
3677
|
-
}
|
|
3678
|
-
return Promise.resolve(value);
|
|
3679
|
-
}
|
|
3680
|
-
function resolveFullMediaType({
|
|
3681
|
-
part
|
|
3682
|
-
}) {
|
|
3683
|
-
if (isFullMediaType(part.mediaType)) {
|
|
3684
|
-
return part.mediaType;
|
|
3685
|
-
}
|
|
3686
|
-
if (part.data.type === "data") {
|
|
3687
|
-
const detected = detectMediaType({
|
|
3688
|
-
data: part.data.data,
|
|
3689
|
-
topLevelType: getTopLevelMediaType(part.mediaType)
|
|
3690
|
-
});
|
|
3691
|
-
if (detected) {
|
|
3692
|
-
return detected;
|
|
3693
|
-
}
|
|
3694
|
-
throw new UnsupportedFunctionalityError({
|
|
3695
|
-
functionality: `file of media type "${part.mediaType}" must specify subtype since it could not be auto-detected`
|
|
3696
|
-
});
|
|
3697
|
-
}
|
|
3698
|
-
throw new UnsupportedFunctionalityError({
|
|
3699
|
-
functionality: `file of media type "${part.mediaType}" must specify subtype since it is not passed as inline bytes`
|
|
3700
|
-
});
|
|
3701
|
-
}
|
|
3702
|
-
function resolveProviderReference({
|
|
3703
|
-
reference,
|
|
3704
|
-
provider
|
|
3705
|
-
}) {
|
|
3706
|
-
const id = reference[provider];
|
|
3707
|
-
if (id != null) {
|
|
3708
|
-
return id;
|
|
3709
|
-
}
|
|
3710
|
-
throw new NoSuchProviderReferenceError({
|
|
3711
|
-
provider,
|
|
3712
|
-
reference
|
|
3713
|
-
});
|
|
3714
|
-
}
|
|
3715
|
-
var retryWithExponentialBackoff = ({
|
|
3716
|
-
maxRetries = 2,
|
|
3717
|
-
initialDelayInMs = 2e3,
|
|
3718
|
-
backoffFactor = 2,
|
|
3719
|
-
abortSignal,
|
|
3720
|
-
shouldRetry,
|
|
3721
|
-
getDelayInMs = ({ exponentialBackoffDelay }) => exponentialBackoffDelay,
|
|
3722
|
-
createRetryError = ({ message }) => new Error(message)
|
|
3723
|
-
}) => async (f) => retryWithExponentialBackoffInternal(f, {
|
|
3724
|
-
maxRetries,
|
|
3725
|
-
delayInMs: initialDelayInMs,
|
|
3726
|
-
backoffFactor,
|
|
3727
|
-
abortSignal,
|
|
3728
|
-
shouldRetry,
|
|
3729
|
-
getDelayInMs,
|
|
3730
|
-
createRetryError
|
|
3731
|
-
});
|
|
3732
|
-
async function retryWithExponentialBackoffInternal(f, {
|
|
3733
|
-
maxRetries,
|
|
3734
|
-
delayInMs,
|
|
3735
|
-
backoffFactor,
|
|
3736
|
-
abortSignal,
|
|
3737
|
-
shouldRetry,
|
|
3738
|
-
getDelayInMs,
|
|
3739
|
-
createRetryError
|
|
3740
|
-
}, errors = []) {
|
|
3741
|
-
try {
|
|
3742
|
-
return await f();
|
|
3743
|
-
} catch (error) {
|
|
3744
|
-
if (isAbortError(error)) {
|
|
3745
|
-
throw error;
|
|
3746
|
-
}
|
|
3747
|
-
if (maxRetries === 0) {
|
|
3748
|
-
throw error;
|
|
3749
|
-
}
|
|
3750
|
-
const errorMessage = getErrorMessage(error);
|
|
3751
|
-
const newErrors = [...errors, error];
|
|
3752
|
-
const tryNumber = newErrors.length;
|
|
3753
|
-
if (tryNumber > maxRetries) {
|
|
3754
|
-
throw createRetryError({
|
|
3755
|
-
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
|
|
3756
|
-
reason: "maxRetriesExceeded",
|
|
3757
|
-
errors: newErrors
|
|
3758
|
-
});
|
|
3759
|
-
}
|
|
3760
|
-
if (await shouldRetry(error) && tryNumber <= maxRetries) {
|
|
3761
|
-
await delay(
|
|
3762
|
-
getDelayInMs({
|
|
3763
|
-
error,
|
|
3764
|
-
exponentialBackoffDelay: delayInMs
|
|
3765
|
-
}),
|
|
3766
|
-
{ abortSignal }
|
|
3767
|
-
);
|
|
3768
|
-
return retryWithExponentialBackoffInternal(
|
|
3769
|
-
f,
|
|
3770
|
-
{
|
|
3771
|
-
maxRetries,
|
|
3772
|
-
delayInMs: backoffFactor * delayInMs,
|
|
3773
|
-
backoffFactor,
|
|
3774
|
-
abortSignal,
|
|
3775
|
-
shouldRetry,
|
|
3776
|
-
getDelayInMs,
|
|
3777
|
-
createRetryError
|
|
3778
|
-
},
|
|
3779
|
-
newErrors
|
|
3780
|
-
);
|
|
3781
|
-
}
|
|
3782
|
-
if (tryNumber === 1) {
|
|
3783
|
-
throw error;
|
|
3784
|
-
}
|
|
3785
|
-
throw createRetryError({
|
|
3786
|
-
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
|
|
3787
|
-
reason: "errorNotRetryable",
|
|
3788
|
-
errors: newErrors
|
|
3789
|
-
});
|
|
3790
|
-
}
|
|
3791
|
-
}
|
|
3792
|
-
var textDecoder2 = new TextDecoder();
|
|
3793
|
-
async function readResponseBodyAsText({
|
|
3794
|
-
response,
|
|
3795
|
-
url
|
|
3796
|
-
}) {
|
|
3797
|
-
return textDecoder2.decode(
|
|
3798
|
-
await readResponseWithSizeLimit({
|
|
3799
|
-
response,
|
|
3800
|
-
url
|
|
3801
|
-
})
|
|
3802
|
-
);
|
|
3803
|
-
}
|
|
3804
|
-
var createJsonErrorResponseHandler = ({
|
|
3805
|
-
errorSchema,
|
|
3806
|
-
errorToMessage,
|
|
3807
|
-
isRetryable
|
|
3808
|
-
}) => async ({ response, url, requestBodyValues }) => {
|
|
3809
|
-
const responseBody = await readResponseBodyAsText({ response, url });
|
|
3810
|
-
const responseHeaders = extractResponseHeaders(response);
|
|
3811
|
-
if (responseBody.trim() === "") {
|
|
3812
|
-
return {
|
|
3813
|
-
responseHeaders,
|
|
3814
|
-
value: new APICallError({
|
|
3815
|
-
message: response.statusText,
|
|
3816
|
-
url,
|
|
3817
|
-
requestBodyValues,
|
|
3818
|
-
statusCode: response.status,
|
|
3819
|
-
responseHeaders,
|
|
3820
|
-
responseBody,
|
|
3821
|
-
isRetryable: isRetryable == null ? void 0 : isRetryable(response)
|
|
3822
|
-
})
|
|
3823
|
-
};
|
|
3824
|
-
}
|
|
3825
|
-
try {
|
|
3826
|
-
const parsedError = await parseJSON({
|
|
3827
|
-
text: responseBody,
|
|
3828
|
-
schema: errorSchema
|
|
3829
|
-
});
|
|
3830
|
-
return {
|
|
3831
|
-
responseHeaders,
|
|
3832
|
-
value: new APICallError({
|
|
3833
|
-
message: errorToMessage(parsedError),
|
|
3834
|
-
url,
|
|
3835
|
-
requestBodyValues,
|
|
3836
|
-
statusCode: response.status,
|
|
3837
|
-
responseHeaders,
|
|
3838
|
-
responseBody,
|
|
3839
|
-
data: parsedError,
|
|
3840
|
-
isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
|
|
3841
|
-
})
|
|
3842
|
-
};
|
|
3843
|
-
} catch (e) {
|
|
3844
|
-
return {
|
|
3845
|
-
responseHeaders,
|
|
3846
|
-
value: new APICallError({
|
|
3847
|
-
message: response.statusText,
|
|
3848
|
-
url,
|
|
3849
|
-
requestBodyValues,
|
|
3850
|
-
statusCode: response.status,
|
|
3851
|
-
responseHeaders,
|
|
3852
|
-
responseBody,
|
|
3853
|
-
isRetryable: isRetryable == null ? void 0 : isRetryable(response)
|
|
3854
|
-
})
|
|
3855
|
-
};
|
|
3856
|
-
}
|
|
3857
|
-
};
|
|
3858
|
-
var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
3859
|
-
const responseHeaders = extractResponseHeaders(response);
|
|
3860
|
-
if (response.body == null) {
|
|
3861
|
-
throw new EmptyResponseBodyError({});
|
|
3862
|
-
}
|
|
3863
|
-
return {
|
|
3864
|
-
responseHeaders,
|
|
3865
|
-
value: parseJsonEventStream({
|
|
3866
|
-
stream: response.body,
|
|
3867
|
-
schema: chunkSchema
|
|
3868
|
-
})
|
|
3869
|
-
};
|
|
3870
|
-
};
|
|
3871
|
-
var createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
|
|
3872
|
-
const responseBody = await readResponseBodyAsText({ response, url });
|
|
3873
|
-
const parsedResult = await safeParseJSON({
|
|
3874
|
-
text: responseBody,
|
|
3875
|
-
schema: responseSchema
|
|
3876
|
-
});
|
|
3877
|
-
const responseHeaders = extractResponseHeaders(response);
|
|
3878
|
-
if (!parsedResult.success) {
|
|
3879
|
-
throw new APICallError({
|
|
3880
|
-
message: "Invalid JSON response",
|
|
3881
|
-
cause: parsedResult.error,
|
|
3882
|
-
statusCode: response.status,
|
|
3883
|
-
responseHeaders,
|
|
3884
|
-
responseBody,
|
|
3885
|
-
url,
|
|
3886
|
-
requestBodyValues
|
|
3887
|
-
});
|
|
3888
|
-
}
|
|
3889
|
-
return {
|
|
3890
|
-
responseHeaders,
|
|
3891
|
-
value: parsedResult.value,
|
|
3892
|
-
rawValue: parsedResult.rawValue
|
|
3893
|
-
};
|
|
3894
|
-
};
|
|
3895
|
-
var createBinaryResponseHandler = () => async ({ response, url, requestBodyValues }) => {
|
|
3896
|
-
const responseHeaders = extractResponseHeaders(response);
|
|
3897
|
-
if (!response.body) {
|
|
3898
|
-
throw new APICallError({
|
|
3899
|
-
message: "Response body is empty",
|
|
3900
|
-
url,
|
|
3901
|
-
requestBodyValues,
|
|
3902
|
-
statusCode: response.status,
|
|
3903
|
-
responseHeaders,
|
|
3904
|
-
responseBody: void 0
|
|
3905
|
-
});
|
|
3906
|
-
}
|
|
3907
|
-
try {
|
|
3908
|
-
const buffer = await response.arrayBuffer();
|
|
3909
|
-
return {
|
|
3910
|
-
responseHeaders,
|
|
3911
|
-
value: new Uint8Array(buffer)
|
|
3912
|
-
};
|
|
3913
|
-
} catch (error) {
|
|
3914
|
-
throw new APICallError({
|
|
3915
|
-
message: "Failed to read response as array buffer",
|
|
3916
|
-
url,
|
|
3917
|
-
requestBodyValues,
|
|
3918
|
-
statusCode: response.status,
|
|
3919
|
-
responseHeaders,
|
|
3920
|
-
responseBody: void 0,
|
|
3921
|
-
cause: error
|
|
3922
|
-
});
|
|
3923
|
-
}
|
|
3924
|
-
};
|
|
3925
|
-
function isJSONSerializable(value) {
|
|
3926
|
-
if (value === null || value === void 0) return true;
|
|
3927
|
-
const type = typeof value;
|
|
3928
|
-
if (type === "string" || type === "number" || type === "boolean") return true;
|
|
3929
|
-
if (type === "function" || type === "symbol" || type === "bigint")
|
|
3930
|
-
return false;
|
|
3931
|
-
if (Array.isArray(value)) {
|
|
3932
|
-
return value.every(isJSONSerializable);
|
|
3933
|
-
}
|
|
3934
|
-
if (Object.getPrototypeOf(value) === Object.prototype) {
|
|
3935
|
-
return Object.values(value).every(
|
|
3936
|
-
isJSONSerializable
|
|
3937
|
-
);
|
|
3938
|
-
}
|
|
3939
|
-
return false;
|
|
3940
|
-
}
|
|
3941
|
-
var name22 = "AI_SerializationError";
|
|
3942
|
-
var marker22 = `vercel.ai.error.${name22}`;
|
|
3943
|
-
var symbol22 = Symbol.for(marker22);
|
|
3944
|
-
var _a22;
|
|
3945
|
-
var _b22;
|
|
3946
|
-
var SerializationError = class extends (_b22 = AISDKError, _a22 = symbol22, _b22) {
|
|
3947
|
-
// used in isInstance
|
|
3948
|
-
constructor({
|
|
3949
|
-
message = "Failed to serialize value.",
|
|
3950
|
-
cause
|
|
3951
|
-
} = {}) {
|
|
3952
|
-
super({ name: name22, message, cause });
|
|
3953
|
-
this[_a22] = true;
|
|
3954
|
-
}
|
|
3955
|
-
static isInstance(error) {
|
|
3956
|
-
return AISDKError.hasMarker(error, marker22);
|
|
3957
|
-
}
|
|
3958
|
-
};
|
|
3959
|
-
function serializeModelOptions(options) {
|
|
3960
|
-
const serializableConfig = {};
|
|
3961
|
-
for (const [key, value] of Object.entries(options.config)) {
|
|
3962
|
-
if (key === "headers") {
|
|
3963
|
-
const resolvedHeaders = resolveSync(value);
|
|
3964
|
-
if (isJSONSerializable(resolvedHeaders)) {
|
|
3965
|
-
serializableConfig[key] = resolvedHeaders;
|
|
3966
|
-
}
|
|
3967
|
-
} else if (isJSONSerializable(value)) {
|
|
3968
|
-
serializableConfig[key] = value;
|
|
3969
|
-
}
|
|
3970
|
-
}
|
|
3971
|
-
return { modelId: options.modelId, config: serializableConfig };
|
|
3972
|
-
}
|
|
3973
|
-
function resolveSync(value) {
|
|
3974
|
-
let next = value;
|
|
3975
|
-
if (typeof value === "function") {
|
|
3976
|
-
next = value();
|
|
3977
|
-
}
|
|
3978
|
-
if (next instanceof Promise) {
|
|
3979
|
-
throw new SerializationError({
|
|
3980
|
-
message: "Cannot serialize asynchronous model options."
|
|
3981
|
-
});
|
|
3982
|
-
}
|
|
3983
|
-
return next;
|
|
3984
|
-
}
|
|
3985
|
-
var StreamingToolCallTracker = class {
|
|
3986
|
-
constructor(controller, options = {}) {
|
|
3987
|
-
this.toolCalls = /* @__PURE__ */ new Set();
|
|
3988
|
-
this.toolCallsById = /* @__PURE__ */ new Map();
|
|
3989
|
-
this.toolCallsByIndex = /* @__PURE__ */ new Map();
|
|
3990
|
-
var _a32, _b32;
|
|
3991
|
-
this.controller = controller;
|
|
3992
|
-
this._generateId = (_a32 = options.generateId) != null ? _a32 : generateId;
|
|
3993
|
-
this.typeValidation = (_b32 = options.typeValidation) != null ? _b32 : "none";
|
|
3994
|
-
this.extractMetadata = options.extractMetadata;
|
|
3995
|
-
this.buildToolCallProviderMetadata = options.buildToolCallProviderMetadata;
|
|
3996
|
-
}
|
|
3997
|
-
/**
|
|
3998
|
-
* Process a tool call delta from a streaming response chunk.
|
|
3999
|
-
* Emits tool-input-start, tool-input-delta, tool-input-end, and tool-call
|
|
4000
|
-
* events as appropriate.
|
|
4001
|
-
*/
|
|
4002
|
-
processDelta(toolCallDelta) {
|
|
4003
|
-
const { id, index } = toolCallDelta;
|
|
4004
|
-
let toolCall = id != null && id.length > 0 ? this.toolCallsById.get(id) : index != null ? this.toolCallsByIndex.get(index) : this.latestToolCall;
|
|
4005
|
-
if (toolCall == null) {
|
|
4006
|
-
toolCall = this.processNewToolCall(toolCallDelta);
|
|
4007
|
-
} else {
|
|
4008
|
-
this.processExistingToolCall(toolCall, toolCallDelta);
|
|
4009
|
-
}
|
|
4010
|
-
if (index != null) {
|
|
4011
|
-
this.toolCallsByIndex.set(index, toolCall);
|
|
4012
|
-
}
|
|
4013
|
-
this.latestToolCall = toolCall;
|
|
4014
|
-
}
|
|
4015
|
-
/**
|
|
4016
|
-
* Finalize any unfinished tool calls. Should be called during the stream's
|
|
4017
|
-
* flush handler to ensure all tool calls are properly completed.
|
|
4018
|
-
*/
|
|
4019
|
-
flush() {
|
|
4020
|
-
for (const toolCall of this.toolCalls) {
|
|
4021
|
-
if (!toolCall.hasFinished) {
|
|
4022
|
-
this.finishToolCall(toolCall);
|
|
4023
|
-
}
|
|
4024
|
-
}
|
|
4025
|
-
}
|
|
4026
|
-
processNewToolCall(toolCallDelta) {
|
|
4027
|
-
var _a32, _b32, _c;
|
|
4028
|
-
if (this.typeValidation === "required") {
|
|
4029
|
-
if (toolCallDelta.type !== "function") {
|
|
4030
|
-
throw new InvalidResponseDataError({
|
|
4031
|
-
data: toolCallDelta,
|
|
4032
|
-
message: `Expected 'function' type.`
|
|
4033
|
-
});
|
|
4034
|
-
}
|
|
4035
|
-
} else if (this.typeValidation === "if-present") {
|
|
4036
|
-
if (toolCallDelta.type != null && toolCallDelta.type !== "function") {
|
|
4037
|
-
throw new InvalidResponseDataError({
|
|
4038
|
-
data: toolCallDelta,
|
|
4039
|
-
message: `Expected 'function' type.`
|
|
4040
|
-
});
|
|
4041
|
-
}
|
|
4042
|
-
}
|
|
4043
|
-
if (toolCallDelta.id == null) {
|
|
4044
|
-
throw new InvalidResponseDataError({
|
|
4045
|
-
data: toolCallDelta,
|
|
4046
|
-
message: `Expected 'id' to be a string.`
|
|
4047
|
-
});
|
|
4048
|
-
}
|
|
4049
|
-
if (((_a32 = toolCallDelta.function) == null ? void 0 : _a32.name) == null) {
|
|
4050
|
-
throw new InvalidResponseDataError({
|
|
4051
|
-
data: toolCallDelta,
|
|
4052
|
-
message: `Expected 'function.name' to be a string.`
|
|
4053
|
-
});
|
|
4054
|
-
}
|
|
4055
|
-
this.controller.enqueue({
|
|
4056
|
-
type: "tool-input-start",
|
|
4057
|
-
id: toolCallDelta.id,
|
|
4058
|
-
toolName: toolCallDelta.function.name
|
|
4059
|
-
});
|
|
4060
|
-
const metadata = (_b32 = this.extractMetadata) == null ? void 0 : _b32.call(this, toolCallDelta);
|
|
4061
|
-
const toolCall = {
|
|
4062
|
-
id: toolCallDelta.id,
|
|
4063
|
-
type: "function",
|
|
4064
|
-
function: {
|
|
4065
|
-
name: toolCallDelta.function.name,
|
|
4066
|
-
arguments: (_c = toolCallDelta.function.arguments) != null ? _c : ""
|
|
4067
|
-
},
|
|
4068
|
-
hasFinished: false,
|
|
4069
|
-
metadata
|
|
4070
|
-
};
|
|
4071
|
-
this.toolCalls.add(toolCall);
|
|
4072
|
-
if (toolCall.id.length > 0) {
|
|
4073
|
-
this.toolCallsById.set(toolCall.id, toolCall);
|
|
4074
|
-
}
|
|
4075
|
-
if (toolCall.function.arguments.length > 0) {
|
|
4076
|
-
this.controller.enqueue({
|
|
4077
|
-
type: "tool-input-delta",
|
|
4078
|
-
id: toolCall.id,
|
|
4079
|
-
delta: toolCall.function.arguments
|
|
4080
|
-
});
|
|
4081
|
-
}
|
|
4082
|
-
return toolCall;
|
|
4083
|
-
}
|
|
4084
|
-
processExistingToolCall(toolCall, toolCallDelta) {
|
|
4085
|
-
var _a32;
|
|
4086
|
-
if (toolCall.hasFinished) {
|
|
4087
|
-
return;
|
|
4088
|
-
}
|
|
4089
|
-
if (((_a32 = toolCallDelta.function) == null ? void 0 : _a32.arguments) != null) {
|
|
4090
|
-
toolCall.function.arguments += toolCallDelta.function.arguments;
|
|
4091
|
-
this.controller.enqueue({
|
|
4092
|
-
type: "tool-input-delta",
|
|
4093
|
-
id: toolCall.id,
|
|
4094
|
-
delta: toolCallDelta.function.arguments
|
|
4095
|
-
});
|
|
4096
|
-
}
|
|
4097
|
-
}
|
|
4098
|
-
finishToolCall(toolCall) {
|
|
4099
|
-
var _a32, _b32;
|
|
4100
|
-
this.controller.enqueue({
|
|
4101
|
-
type: "tool-input-end",
|
|
4102
|
-
id: toolCall.id
|
|
4103
|
-
});
|
|
4104
|
-
const providerMetadata = (_a32 = this.buildToolCallProviderMetadata) == null ? void 0 : _a32.call(
|
|
4105
|
-
this,
|
|
4106
|
-
toolCall.metadata
|
|
4107
|
-
);
|
|
4108
|
-
this.controller.enqueue({
|
|
4109
|
-
type: "tool-call",
|
|
4110
|
-
toolCallId: (_b32 = toolCall.id) != null ? _b32 : this._generateId(),
|
|
4111
|
-
toolName: toolCall.function.name,
|
|
4112
|
-
input: toolCall.function.arguments,
|
|
4113
|
-
...providerMetadata ? { providerMetadata } : {}
|
|
4114
|
-
});
|
|
4115
|
-
toolCall.hasFinished = true;
|
|
4116
|
-
}
|
|
4117
|
-
};
|
|
4118
|
-
var TRANSCRIPTION_STREAM_START_FRAME_TYPE = "transcription-stream.start";
|
|
4119
|
-
var TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE = "transcription-stream.audio-done";
|
|
4120
|
-
function parseTranscriptionStreamPart(text) {
|
|
4121
|
-
let value;
|
|
4122
|
-
try {
|
|
4123
|
-
value = secureJsonParse(text);
|
|
4124
|
-
} catch (e) {
|
|
4125
|
-
return void 0;
|
|
4126
|
-
}
|
|
4127
|
-
if (value == null || typeof value !== "object" || Array.isArray(value)) {
|
|
4128
|
-
return void 0;
|
|
4129
|
-
}
|
|
4130
|
-
const part = value;
|
|
4131
|
-
switch (part.type) {
|
|
4132
|
-
case "stream-start":
|
|
4133
|
-
return Array.isArray(part.warnings) && part.warnings.every(isWarning) ? part : void 0;
|
|
4134
|
-
case "transcript-delta":
|
|
4135
|
-
return isString(part.delta) && isOptional(part.id, isString) && isOptional(part.providerMetadata, isRecord) ? part : void 0;
|
|
4136
|
-
case "transcript-partial":
|
|
4137
|
-
return isString(part.text) && isOptional(part.id, isString) && isOptional(part.startSecond, isNumber) && isOptional(part.durationInSeconds, isNumber) && isOptional(part.channelIndex, isNumber) && isOptional(part.providerMetadata, isRecord) ? part : void 0;
|
|
4138
|
-
case "transcript-final":
|
|
4139
|
-
return isString(part.text) && isOptional(part.id, isString) && isOptional(part.startSecond, isNumber) && isOptional(part.endSecond, isNumber) && isOptional(part.channelIndex, isNumber) && isOptional(part.providerMetadata, isRecord) ? part : void 0;
|
|
4140
|
-
case "finish":
|
|
4141
|
-
return isString(part.text) && Array.isArray(part.segments) && part.segments.every(isSegment) && isOptional(part.language, isString) && isOptional(part.durationInSeconds, isNumber) && isOptional(part.providerMetadata, isRecord) ? part : void 0;
|
|
4142
|
-
case "response-metadata": {
|
|
4143
|
-
if (!(isOptional(part.modelId, isString) && isOptional(part.headers, isRecord))) {
|
|
4144
|
-
return void 0;
|
|
4145
|
-
}
|
|
4146
|
-
const timestamp = part.timestamp;
|
|
4147
|
-
if (timestamp == null) {
|
|
4148
|
-
return { ...part, timestamp: void 0 };
|
|
4149
|
-
}
|
|
4150
|
-
if (typeof timestamp !== "string") {
|
|
4151
|
-
return void 0;
|
|
4152
|
-
}
|
|
4153
|
-
const revived = new Date(timestamp);
|
|
4154
|
-
return Number.isNaN(revived.getTime()) ? void 0 : { ...part, timestamp: revived };
|
|
4155
|
-
}
|
|
4156
|
-
case "raw":
|
|
4157
|
-
return "rawValue" in part ? part : void 0;
|
|
4158
|
-
case "error":
|
|
4159
|
-
return "error" in part ? part : void 0;
|
|
4160
|
-
default:
|
|
4161
|
-
return void 0;
|
|
4162
|
-
}
|
|
4163
|
-
}
|
|
4164
|
-
function isString(value) {
|
|
4165
|
-
return typeof value === "string";
|
|
4166
|
-
}
|
|
4167
|
-
function isNumber(value) {
|
|
4168
|
-
return typeof value === "number";
|
|
4169
|
-
}
|
|
4170
|
-
function isOptional(value, check) {
|
|
4171
|
-
return value === void 0 || check(value);
|
|
4172
|
-
}
|
|
4173
|
-
function isWarning(value) {
|
|
4174
|
-
return isRecord(value) && isString(value.type);
|
|
4175
|
-
}
|
|
4176
|
-
function isSegment(value) {
|
|
4177
|
-
return isRecord(value) && isString(value.text) && isNumber(value.startSecond) && isNumber(value.endSecond);
|
|
4178
|
-
}
|
|
4179
|
-
function validateBaseURL(baseURL) {
|
|
4180
|
-
if ((baseURL == null ? void 0 : baseURL.trim()) === "") {
|
|
4181
|
-
throw new InvalidArgumentError({
|
|
4182
|
-
argument: "baseURL",
|
|
4183
|
-
message: "baseURL must be a non-empty string."
|
|
4184
|
-
});
|
|
4185
|
-
}
|
|
4186
|
-
return baseURL;
|
|
4187
|
-
}
|
|
4188
|
-
function withoutTrailingSlash(url) {
|
|
4189
|
-
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
4190
|
-
}
|
|
4191
|
-
function isExecutableTool(tool2) {
|
|
4192
|
-
return tool2 != null && typeof tool2.execute === "function";
|
|
4193
|
-
}
|
|
4194
|
-
function isAsyncIterable(obj) {
|
|
4195
|
-
return obj != null && typeof obj[Symbol.asyncIterator] === "function";
|
|
4196
|
-
}
|
|
4197
|
-
async function* executeTool({
|
|
4198
|
-
tool: tool2,
|
|
4199
|
-
input,
|
|
4200
|
-
options
|
|
4201
|
-
}) {
|
|
4202
|
-
const result = tool2.execute(input, options);
|
|
4203
|
-
if (isAsyncIterable(result)) {
|
|
4204
|
-
let lastOutput;
|
|
4205
|
-
for await (const output of result) {
|
|
4206
|
-
lastOutput = output;
|
|
4207
|
-
yield { type: "preliminary", output };
|
|
4208
|
-
}
|
|
4209
|
-
yield { type: "final", output: lastOutput };
|
|
4210
|
-
} else {
|
|
4211
|
-
yield { type: "final", output: await result };
|
|
4212
|
-
}
|
|
4213
|
-
}
|
|
4214
|
-
function toolCaller(tool2, definition) {
|
|
4215
|
-
return Object.defineProperty({ ...tool2 }, "experimental_toolCaller", {
|
|
4216
|
-
value: definition
|
|
4217
|
-
});
|
|
4218
|
-
}
|
|
4219
|
-
function getToolCaller(tool2) {
|
|
4220
|
-
return tool2 == null ? void 0 : tool2.experimental_toolCaller;
|
|
4221
|
-
}
|
|
4222
|
-
|
|
4223
|
-
export {
|
|
4224
|
-
AISDKError,
|
|
4225
|
-
APICallError,
|
|
4226
|
-
EmptyResponseBodyError,
|
|
4227
|
-
getErrorMessage,
|
|
4228
|
-
InvalidArgumentError,
|
|
4229
|
-
InvalidPromptError,
|
|
4230
|
-
InvalidResponseDataError,
|
|
4231
|
-
JSONParseError,
|
|
4232
|
-
NoSuchModelError,
|
|
4233
|
-
TooManyEmbeddingValuesForCallError,
|
|
4234
|
-
TypeValidationError,
|
|
4235
|
-
UnsupportedFunctionalityError,
|
|
4236
|
-
isJSONArray,
|
|
4237
|
-
isJSONObject,
|
|
4238
|
-
WORKFLOW_SERIALIZE,
|
|
4239
|
-
WORKFLOW_DESERIALIZE,
|
|
4240
|
-
asArray,
|
|
4241
|
-
combineHeaders,
|
|
4242
|
-
toWebSocketUrl,
|
|
4243
|
-
waitForWebSocketBufferDrain,
|
|
4244
|
-
connectToWebSocket,
|
|
4245
|
-
convertAsyncIteratorToReadableStream,
|
|
4246
|
-
convertBase64ToUint8Array,
|
|
4247
|
-
convertUint8ArrayToBase64,
|
|
4248
|
-
convertToBase64,
|
|
4249
|
-
convertInlineFileDataToUint8Array,
|
|
4250
|
-
convertToFormData,
|
|
4251
|
-
createLanguageModelResponseMetadata,
|
|
4252
|
-
createNullLanguageModelUsage,
|
|
4253
|
-
createToolNameMapping,
|
|
4254
|
-
DelayedPromise,
|
|
4255
|
-
detectMediaType,
|
|
4256
|
-
getTopLevelMediaType,
|
|
4257
|
-
isFullMediaType,
|
|
4258
|
-
cancelResponseBody,
|
|
4259
|
-
DownloadError,
|
|
4260
|
-
fetchWithValidatedRedirects,
|
|
4261
|
-
DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
4262
|
-
readResponseWithSizeLimit,
|
|
4263
|
-
downloadBlob,
|
|
4264
|
-
filterNullable,
|
|
4265
|
-
createIdGenerator,
|
|
4266
|
-
generateId,
|
|
4267
|
-
isAbortError,
|
|
4268
|
-
getRuntimeEnvironmentUserAgent,
|
|
4269
|
-
normalizeHeaders,
|
|
4270
|
-
withUserAgentSuffix,
|
|
4271
|
-
getFromApi,
|
|
4272
|
-
isBuffer,
|
|
4273
|
-
isNonNullable,
|
|
4274
|
-
isProviderReference,
|
|
4275
|
-
isRecord,
|
|
4276
|
-
isUrlSupported,
|
|
4277
|
-
loadApiKey,
|
|
4278
|
-
loadOptionalSetting,
|
|
4279
|
-
isCustomReasoning,
|
|
4280
|
-
mapReasoningToProviderEffort,
|
|
4281
|
-
mapReasoningToProviderBudget,
|
|
4282
|
-
mediaTypeToExtension,
|
|
4283
|
-
secureJsonParse,
|
|
4284
|
-
lazySchema,
|
|
4285
|
-
asSchema,
|
|
4286
|
-
zodSchema,
|
|
4287
|
-
validateTypes,
|
|
4288
|
-
safeValidateTypes,
|
|
4289
|
-
parseJSON,
|
|
4290
|
-
safeParseJSON,
|
|
4291
|
-
parseJsonEventStream,
|
|
4292
|
-
parseProviderOptions,
|
|
4293
|
-
postJsonToApi,
|
|
4294
|
-
postFormDataToApi,
|
|
4295
|
-
postToApi,
|
|
4296
|
-
tool,
|
|
4297
|
-
createProviderDefinedToolFactory,
|
|
4298
|
-
createProviderDefinedToolFactoryWithOutputSchema,
|
|
4299
|
-
createProviderExecutedToolFactory,
|
|
4300
|
-
resolve,
|
|
4301
|
-
resolveFullMediaType,
|
|
4302
|
-
resolveProviderReference,
|
|
4303
|
-
retryWithExponentialBackoff,
|
|
4304
|
-
createJsonErrorResponseHandler,
|
|
4305
|
-
createEventSourceResponseHandler,
|
|
4306
|
-
createJsonResponseHandler,
|
|
4307
|
-
createBinaryResponseHandler,
|
|
4308
|
-
serializeModelOptions,
|
|
4309
|
-
StreamingToolCallTracker,
|
|
4310
|
-
TRANSCRIPTION_STREAM_START_FRAME_TYPE,
|
|
4311
|
-
TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE,
|
|
4312
|
-
parseTranscriptionStreamPart,
|
|
4313
|
-
validateBaseURL,
|
|
4314
|
-
withoutTrailingSlash,
|
|
4315
|
-
isExecutableTool,
|
|
4316
|
-
executeTool,
|
|
4317
|
-
toolCaller,
|
|
4318
|
-
getToolCaller
|
|
4319
|
-
};
|