@ensembleapp/client-sdk 0.0.56 → 0.0.57
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/RealtimeVoicePanel-IZD3FICH.js +417 -0
- package/dist/RealtimeVoicePanel-IZD3FICH.js.map +1 -0
- package/dist/VoiceCharts-5TTAROFU.js +295 -0
- package/dist/VoiceCharts-5TTAROFU.js.map +1 -0
- package/dist/chunk-LFKJR7WX.js +1013 -0
- package/dist/chunk-LFKJR7WX.js.map +1 -0
- package/dist/chunk-LQHHZ2OJ.js +4177 -0
- package/dist/chunk-LQHHZ2OJ.js.map +1 -0
- package/dist/chunk-YLJ4XMA6.js +35 -0
- package/dist/chunk-YLJ4XMA6.js.map +1 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +4903 -8746
- package/dist/index.js.map +1 -1
- package/dist/widget/widget.global.js +218 -88
- package/dist/widget/widget.global.js.map +1 -1
- package/lib/chat/ChatWidget.css +111 -0
- package/package.json +7 -2
|
@@ -0,0 +1,4177 @@
|
|
|
1
|
+
// ../../node_modules/.pnpm/@ai-sdk+provider@3.0.13/node_modules/@ai-sdk/provider/dist/index.mjs
|
|
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: name143,
|
|
17
|
+
message,
|
|
18
|
+
cause
|
|
19
|
+
}) {
|
|
20
|
+
super(message);
|
|
21
|
+
this[_a] = true;
|
|
22
|
+
this.name = name143;
|
|
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, marker153) {
|
|
34
|
+
const markerSymbol = Symbol.for(marker153);
|
|
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.message;
|
|
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: text2, cause }) {
|
|
163
|
+
super({
|
|
164
|
+
name: name6,
|
|
165
|
+
message: `JSON parsing failed: Text: ${text2}.
|
|
166
|
+
Error message: ${getErrorMessage(cause)}`,
|
|
167
|
+
cause
|
|
168
|
+
});
|
|
169
|
+
this[_a7] = true;
|
|
170
|
+
this.text = text2;
|
|
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_TooManyEmbeddingValuesForCallError";
|
|
245
|
+
var marker12 = `vercel.ai.error.${name11}`;
|
|
246
|
+
var symbol12 = Symbol.for(marker12);
|
|
247
|
+
var _a12;
|
|
248
|
+
var _b12;
|
|
249
|
+
var TooManyEmbeddingValuesForCallError = class extends (_b12 = AISDKError, _a12 = symbol12, _b12) {
|
|
250
|
+
constructor(options) {
|
|
251
|
+
super({
|
|
252
|
+
name: name11,
|
|
253
|
+
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.`
|
|
254
|
+
});
|
|
255
|
+
this[_a12] = true;
|
|
256
|
+
this.provider = options.provider;
|
|
257
|
+
this.modelId = options.modelId;
|
|
258
|
+
this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall;
|
|
259
|
+
this.values = options.values;
|
|
260
|
+
}
|
|
261
|
+
static isInstance(error) {
|
|
262
|
+
return AISDKError.hasMarker(error, marker12);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
var name12 = "AI_TypeValidationError";
|
|
266
|
+
var marker13 = `vercel.ai.error.${name12}`;
|
|
267
|
+
var symbol13 = Symbol.for(marker13);
|
|
268
|
+
var _a13;
|
|
269
|
+
var _b13;
|
|
270
|
+
var TypeValidationError = class _TypeValidationError extends (_b13 = AISDKError, _a13 = symbol13, _b13) {
|
|
271
|
+
constructor({
|
|
272
|
+
value,
|
|
273
|
+
cause,
|
|
274
|
+
context
|
|
275
|
+
}) {
|
|
276
|
+
let contextPrefix = "Type validation failed";
|
|
277
|
+
if (context == null ? void 0 : context.field) {
|
|
278
|
+
contextPrefix += ` for ${context.field}`;
|
|
279
|
+
}
|
|
280
|
+
if ((context == null ? void 0 : context.entityName) || (context == null ? void 0 : context.entityId)) {
|
|
281
|
+
contextPrefix += " (";
|
|
282
|
+
const parts = [];
|
|
283
|
+
if (context.entityName) {
|
|
284
|
+
parts.push(context.entityName);
|
|
285
|
+
}
|
|
286
|
+
if (context.entityId) {
|
|
287
|
+
parts.push(`id: "${context.entityId}"`);
|
|
288
|
+
}
|
|
289
|
+
contextPrefix += parts.join(", ");
|
|
290
|
+
contextPrefix += ")";
|
|
291
|
+
}
|
|
292
|
+
super({
|
|
293
|
+
name: name12,
|
|
294
|
+
message: `${contextPrefix}: Value: ${JSON.stringify(value)}.
|
|
295
|
+
Error message: ${getErrorMessage(cause)}`,
|
|
296
|
+
cause
|
|
297
|
+
});
|
|
298
|
+
this[_a13] = true;
|
|
299
|
+
this.value = value;
|
|
300
|
+
this.context = context;
|
|
301
|
+
}
|
|
302
|
+
static isInstance(error) {
|
|
303
|
+
return AISDKError.hasMarker(error, marker13);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Wraps an error into a TypeValidationError.
|
|
307
|
+
* If the cause is already a TypeValidationError with the same value and context, it returns the cause.
|
|
308
|
+
* Otherwise, it creates a new TypeValidationError.
|
|
309
|
+
*
|
|
310
|
+
* @param {Object} params - The parameters for wrapping the error.
|
|
311
|
+
* @param {unknown} params.value - The value that failed validation.
|
|
312
|
+
* @param {unknown} params.cause - The original error or cause of the validation failure.
|
|
313
|
+
* @param {TypeValidationContext} params.context - Optional context about what is being validated.
|
|
314
|
+
* @returns {TypeValidationError} A TypeValidationError instance.
|
|
315
|
+
*/
|
|
316
|
+
static wrap({
|
|
317
|
+
value,
|
|
318
|
+
cause,
|
|
319
|
+
context
|
|
320
|
+
}) {
|
|
321
|
+
var _a153, _b152, _c;
|
|
322
|
+
if (_TypeValidationError.isInstance(cause) && cause.value === value && ((_a153 = cause.context) == null ? void 0 : _a153.field) === (context == null ? void 0 : context.field) && ((_b152 = cause.context) == null ? void 0 : _b152.entityName) === (context == null ? void 0 : context.entityName) && ((_c = cause.context) == null ? void 0 : _c.entityId) === (context == null ? void 0 : context.entityId)) {
|
|
323
|
+
return cause;
|
|
324
|
+
}
|
|
325
|
+
return new _TypeValidationError({ value, cause, context });
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
var name13 = "AI_UnsupportedFunctionalityError";
|
|
329
|
+
var marker14 = `vercel.ai.error.${name13}`;
|
|
330
|
+
var symbol14 = Symbol.for(marker14);
|
|
331
|
+
var _a14;
|
|
332
|
+
var _b14;
|
|
333
|
+
var UnsupportedFunctionalityError = class extends (_b14 = AISDKError, _a14 = symbol14, _b14) {
|
|
334
|
+
constructor({
|
|
335
|
+
functionality,
|
|
336
|
+
message = `'${functionality}' functionality not supported.`
|
|
337
|
+
}) {
|
|
338
|
+
super({ name: name13, message });
|
|
339
|
+
this[_a14] = true;
|
|
340
|
+
this.functionality = functionality;
|
|
341
|
+
}
|
|
342
|
+
static isInstance(error) {
|
|
343
|
+
return AISDKError.hasMarker(error, marker14);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
// ../../node_modules/.pnpm/@ai-sdk+provider-utils@4.0.34_zod@4.4.3/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
348
|
+
import * as z4 from "zod/v4";
|
|
349
|
+
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind3 } from "zod/v3";
|
|
350
|
+
import { ZodFirstPartyTypeKind } from "zod/v3";
|
|
351
|
+
import {
|
|
352
|
+
ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2
|
|
353
|
+
} from "zod/v3";
|
|
354
|
+
|
|
355
|
+
// ../../node_modules/.pnpm/eventsource-parser@3.1.0/node_modules/eventsource-parser/dist/index.js
|
|
356
|
+
var ParseError = class extends Error {
|
|
357
|
+
constructor(message, options) {
|
|
358
|
+
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
var LF = 10;
|
|
362
|
+
var CR = 13;
|
|
363
|
+
var SPACE = 32;
|
|
364
|
+
function noop(_arg) {
|
|
365
|
+
}
|
|
366
|
+
function createParser(config) {
|
|
367
|
+
if (typeof config == "function")
|
|
368
|
+
throw new TypeError(
|
|
369
|
+
"`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
|
|
370
|
+
);
|
|
371
|
+
const { onEvent = noop, onError = noop, onRetry = noop, onComment, maxBufferSize } = config, pendingFragments = [];
|
|
372
|
+
let pendingFragmentsLength = 0, isFirstChunk = true, id, data = "", dataLines = 0, eventType, terminated = false;
|
|
373
|
+
function feed(chunk) {
|
|
374
|
+
if (terminated)
|
|
375
|
+
throw new Error(
|
|
376
|
+
"Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
|
|
377
|
+
);
|
|
378
|
+
if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
|
|
379
|
+
const trailing2 = processLines(chunk);
|
|
380
|
+
trailing2 !== "" && (pendingFragments.push(trailing2), pendingFragmentsLength = trailing2.length), checkBufferSize();
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (chunk.indexOf(`
|
|
384
|
+
`) === -1 && chunk.indexOf("\r") === -1) {
|
|
385
|
+
pendingFragments.push(chunk), pendingFragmentsLength += chunk.length, checkBufferSize();
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
pendingFragments.push(chunk);
|
|
389
|
+
const input = pendingFragments.join("");
|
|
390
|
+
pendingFragments.length = 0, pendingFragmentsLength = 0;
|
|
391
|
+
const trailing = processLines(input);
|
|
392
|
+
trailing !== "" && (pendingFragments.push(trailing), pendingFragmentsLength = trailing.length), checkBufferSize();
|
|
393
|
+
}
|
|
394
|
+
function checkBufferSize() {
|
|
395
|
+
maxBufferSize !== void 0 && (pendingFragmentsLength + data.length <= maxBufferSize || (terminated = true, pendingFragments.length = 0, pendingFragmentsLength = 0, id = void 0, data = "", dataLines = 0, eventType = void 0, onError(
|
|
396
|
+
new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
|
|
397
|
+
type: "max-buffer-size-exceeded"
|
|
398
|
+
})
|
|
399
|
+
)));
|
|
400
|
+
}
|
|
401
|
+
function processLines(chunk) {
|
|
402
|
+
let searchIndex = 0;
|
|
403
|
+
if (chunk.indexOf("\r") === -1) {
|
|
404
|
+
let lfIndex = chunk.indexOf(`
|
|
405
|
+
`, searchIndex);
|
|
406
|
+
for (; lfIndex !== -1; ) {
|
|
407
|
+
if (searchIndex === lfIndex) {
|
|
408
|
+
dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
409
|
+
`, searchIndex);
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
const firstCharCode = chunk.charCodeAt(searchIndex);
|
|
413
|
+
if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
|
|
414
|
+
const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
|
|
415
|
+
if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
|
|
416
|
+
onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
|
|
417
|
+
`, searchIndex);
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
data = dataLines === 0 ? value : `${data}
|
|
421
|
+
${value}`, dataLines++;
|
|
422
|
+
} else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
|
|
423
|
+
chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
|
|
424
|
+
lfIndex
|
|
425
|
+
) || void 0 : parseLine(chunk, searchIndex, lfIndex);
|
|
426
|
+
searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
427
|
+
`, searchIndex);
|
|
428
|
+
}
|
|
429
|
+
return chunk.slice(searchIndex);
|
|
430
|
+
}
|
|
431
|
+
for (; searchIndex < chunk.length; ) {
|
|
432
|
+
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
433
|
+
`, searchIndex);
|
|
434
|
+
let lineEnd = -1;
|
|
435
|
+
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)
|
|
436
|
+
break;
|
|
437
|
+
parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
|
|
438
|
+
}
|
|
439
|
+
return chunk.slice(searchIndex);
|
|
440
|
+
}
|
|
441
|
+
function parseLine(chunk, start, end) {
|
|
442
|
+
if (start === end) {
|
|
443
|
+
dispatchEvent();
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
const firstCharCode = chunk.charCodeAt(start);
|
|
447
|
+
if (isDataPrefix(chunk, start, firstCharCode)) {
|
|
448
|
+
const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
|
|
449
|
+
data = dataLines === 0 ? value2 : `${data}
|
|
450
|
+
${value2}`, dataLines++;
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
if (isEventPrefix(chunk, start, firstCharCode)) {
|
|
454
|
+
eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
|
|
458
|
+
const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
|
|
459
|
+
id = value2.includes("\0") ? void 0 : value2;
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
if (firstCharCode === 58) {
|
|
463
|
+
if (onComment) {
|
|
464
|
+
const line2 = chunk.slice(start, end);
|
|
465
|
+
onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
|
|
466
|
+
}
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
|
|
470
|
+
if (fieldSeparatorIndex === -1) {
|
|
471
|
+
processField(line, "", line);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
475
|
+
processField(field, value, line);
|
|
476
|
+
}
|
|
477
|
+
function processField(field, value, line) {
|
|
478
|
+
switch (field) {
|
|
479
|
+
case "event":
|
|
480
|
+
eventType = value || void 0;
|
|
481
|
+
break;
|
|
482
|
+
case "data":
|
|
483
|
+
data = dataLines === 0 ? value : `${data}
|
|
484
|
+
${value}`, dataLines++;
|
|
485
|
+
break;
|
|
486
|
+
case "id":
|
|
487
|
+
id = value.includes("\0") ? void 0 : value;
|
|
488
|
+
break;
|
|
489
|
+
case "retry":
|
|
490
|
+
/^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
|
|
491
|
+
new ParseError(`Invalid \`retry\` value: "${value}"`, {
|
|
492
|
+
type: "invalid-retry",
|
|
493
|
+
value,
|
|
494
|
+
line
|
|
495
|
+
})
|
|
496
|
+
);
|
|
497
|
+
break;
|
|
498
|
+
default:
|
|
499
|
+
onError(
|
|
500
|
+
new ParseError(
|
|
501
|
+
`Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
|
|
502
|
+
{ type: "unknown-field", field, value, line }
|
|
503
|
+
)
|
|
504
|
+
);
|
|
505
|
+
break;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function dispatchEvent() {
|
|
509
|
+
dataLines > 0 && onEvent({
|
|
510
|
+
id,
|
|
511
|
+
event: eventType,
|
|
512
|
+
data
|
|
513
|
+
}), id = void 0, data = "", dataLines = 0, eventType = void 0;
|
|
514
|
+
}
|
|
515
|
+
function reset(options = {}) {
|
|
516
|
+
if (options.consume && pendingFragments.length > 0) {
|
|
517
|
+
const incompleteLine = pendingFragments.join("");
|
|
518
|
+
parseLine(incompleteLine, 0, incompleteLine.length);
|
|
519
|
+
}
|
|
520
|
+
isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0, pendingFragmentsLength = 0, terminated = false;
|
|
521
|
+
}
|
|
522
|
+
return { feed, reset };
|
|
523
|
+
}
|
|
524
|
+
function isDataPrefix(chunk, i, firstCharCode) {
|
|
525
|
+
return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
|
|
526
|
+
}
|
|
527
|
+
function isEventPrefix(chunk, i, firstCharCode) {
|
|
528
|
+
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;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// ../../node_modules/.pnpm/eventsource-parser@3.1.0/node_modules/eventsource-parser/dist/stream.js
|
|
532
|
+
var EventSourceParserStream = class extends TransformStream {
|
|
533
|
+
constructor({ onError, onRetry, onComment, maxBufferSize } = {}) {
|
|
534
|
+
let parser;
|
|
535
|
+
super({
|
|
536
|
+
start(controller) {
|
|
537
|
+
parser = createParser({
|
|
538
|
+
onEvent: (event) => {
|
|
539
|
+
controller.enqueue(event);
|
|
540
|
+
},
|
|
541
|
+
onError(error) {
|
|
542
|
+
typeof onError == "function" && onError(error), (onError === "terminate" || error.type === "max-buffer-size-exceeded") && controller.error(error);
|
|
543
|
+
},
|
|
544
|
+
onRetry,
|
|
545
|
+
onComment,
|
|
546
|
+
maxBufferSize
|
|
547
|
+
});
|
|
548
|
+
},
|
|
549
|
+
transform(chunk) {
|
|
550
|
+
parser.feed(chunk);
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
// ../../node_modules/.pnpm/@ai-sdk+provider-utils@4.0.34_zod@4.4.3/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
557
|
+
var { btoa, atob } = globalThis;
|
|
558
|
+
async function cancelResponseBody(response) {
|
|
559
|
+
var _a23;
|
|
560
|
+
try {
|
|
561
|
+
await ((_a23 = response.body) == null ? void 0 : _a23.cancel());
|
|
562
|
+
} catch (e) {
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
var name14 = "AI_DownloadError";
|
|
566
|
+
var marker15 = `vercel.ai.error.${name14}`;
|
|
567
|
+
var symbol15 = Symbol.for(marker15);
|
|
568
|
+
var _a15;
|
|
569
|
+
var _b15;
|
|
570
|
+
var DownloadError = class extends (_b15 = AISDKError, _a15 = symbol15, _b15) {
|
|
571
|
+
constructor({
|
|
572
|
+
url,
|
|
573
|
+
statusCode,
|
|
574
|
+
statusText,
|
|
575
|
+
cause,
|
|
576
|
+
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
|
577
|
+
}) {
|
|
578
|
+
super({ name: name14, message, cause });
|
|
579
|
+
this[_a15] = true;
|
|
580
|
+
this.url = url;
|
|
581
|
+
this.statusCode = statusCode;
|
|
582
|
+
this.statusText = statusText;
|
|
583
|
+
}
|
|
584
|
+
static isInstance(error) {
|
|
585
|
+
return AISDKError.hasMarker(error, marker15);
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
function isBrowserRuntime(globalThisAny = globalThis) {
|
|
589
|
+
return globalThisAny.window != null;
|
|
590
|
+
}
|
|
591
|
+
function validateDownloadUrl(url) {
|
|
592
|
+
let parsed;
|
|
593
|
+
try {
|
|
594
|
+
parsed = new URL(url);
|
|
595
|
+
} catch (e) {
|
|
596
|
+
throw new DownloadError({
|
|
597
|
+
url,
|
|
598
|
+
message: `Invalid URL: ${url}`
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
if (parsed.protocol === "data:") {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
605
|
+
throw new DownloadError({
|
|
606
|
+
url,
|
|
607
|
+
message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
const hostname = parsed.hostname.toLowerCase().replace(/\.+$/, "");
|
|
611
|
+
if (!hostname) {
|
|
612
|
+
throw new DownloadError({
|
|
613
|
+
url,
|
|
614
|
+
message: `URL must have a hostname`
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
if (hostname === "localhost" || hostname.endsWith(".local") || hostname.endsWith(".localhost")) {
|
|
618
|
+
throw new DownloadError({
|
|
619
|
+
url,
|
|
620
|
+
message: `URL with hostname ${hostname} is not allowed`
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
if (hostname.startsWith("[") && hostname.endsWith("]")) {
|
|
624
|
+
const ipv6 = hostname.slice(1, -1);
|
|
625
|
+
if (isPrivateIPv6(ipv6)) {
|
|
626
|
+
throw new DownloadError({
|
|
627
|
+
url,
|
|
628
|
+
message: `URL with IPv6 address ${hostname} is not allowed`
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
if (isIPv4(hostname)) {
|
|
634
|
+
if (isPrivateIPv4(hostname)) {
|
|
635
|
+
throw new DownloadError({
|
|
636
|
+
url,
|
|
637
|
+
message: `URL with IP address ${hostname} is not allowed`
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
function isIPv4(hostname) {
|
|
644
|
+
const parts = hostname.split(".");
|
|
645
|
+
if (parts.length !== 4) return false;
|
|
646
|
+
return parts.every((part) => {
|
|
647
|
+
const num = Number(part);
|
|
648
|
+
return Number.isInteger(num) && num >= 0 && num <= 255 && String(num) === part;
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
function isPrivateIPv4(ip) {
|
|
652
|
+
const parts = ip.split(".").map(Number);
|
|
653
|
+
const [a, b, c] = parts;
|
|
654
|
+
if (a === 0) return true;
|
|
655
|
+
if (a === 10) return true;
|
|
656
|
+
if (a === 100 && b >= 64 && b <= 127) return true;
|
|
657
|
+
if (a === 127) return true;
|
|
658
|
+
if (a === 169 && b === 254) return true;
|
|
659
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
660
|
+
if (a === 192 && b === 0 && c === 0) return true;
|
|
661
|
+
if (a === 192 && b === 168) return true;
|
|
662
|
+
if (a === 198 && (b === 18 || b === 19)) return true;
|
|
663
|
+
if (a >= 240) return true;
|
|
664
|
+
return false;
|
|
665
|
+
}
|
|
666
|
+
function parseIPv6(ip) {
|
|
667
|
+
let address = ip.toLowerCase();
|
|
668
|
+
const zoneIndex = address.indexOf("%");
|
|
669
|
+
if (zoneIndex !== -1) {
|
|
670
|
+
address = address.slice(0, zoneIndex);
|
|
671
|
+
}
|
|
672
|
+
const halves = address.split("::");
|
|
673
|
+
if (halves.length > 2) return null;
|
|
674
|
+
const toGroups = (segment) => {
|
|
675
|
+
if (segment === "") return [];
|
|
676
|
+
const groups = [];
|
|
677
|
+
const parts = segment.split(":");
|
|
678
|
+
for (let i = 0; i < parts.length; i++) {
|
|
679
|
+
const part = parts[i];
|
|
680
|
+
if (part.includes(".")) {
|
|
681
|
+
if (i !== parts.length - 1 || !isIPv4(part)) return null;
|
|
682
|
+
const [a, b, c, d] = part.split(".").map(Number);
|
|
683
|
+
groups.push(a << 8 | b, c << 8 | d);
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
if (!/^[0-9a-f]{1,4}$/.test(part)) return null;
|
|
687
|
+
groups.push(parseInt(part, 16));
|
|
688
|
+
}
|
|
689
|
+
return groups;
|
|
690
|
+
};
|
|
691
|
+
const head = toGroups(halves[0]);
|
|
692
|
+
if (head === null) return null;
|
|
693
|
+
if (halves.length === 2) {
|
|
694
|
+
const tail = toGroups(halves[1]);
|
|
695
|
+
if (tail === null) return null;
|
|
696
|
+
const fill = 8 - head.length - tail.length;
|
|
697
|
+
if (fill < 0) return null;
|
|
698
|
+
return [...head, ...new Array(fill).fill(0), ...tail];
|
|
699
|
+
}
|
|
700
|
+
return head.length === 8 ? head : null;
|
|
701
|
+
}
|
|
702
|
+
function isPrivateIPv6(ip) {
|
|
703
|
+
const groups = parseIPv6(ip);
|
|
704
|
+
if (groups === null) return true;
|
|
705
|
+
const topZero = (count) => groups.slice(0, count).every((group) => group === 0);
|
|
706
|
+
if (topZero(7) && (groups[7] === 0 || groups[7] === 1)) return true;
|
|
707
|
+
if ((groups[0] & 65024) === 64512) return true;
|
|
708
|
+
if ((groups[0] & 65472) === 65152) return true;
|
|
709
|
+
if ((groups[0] & 65472) === 65216) return true;
|
|
710
|
+
if ((groups[0] & 65280) === 65280) return true;
|
|
711
|
+
const embedsIPv4 = (
|
|
712
|
+
// ::/96 — IPv4-compatible (deprecated)
|
|
713
|
+
topZero(6) || // ::ffff:0:0/96 — IPv4-mapped (ffff in group 5)
|
|
714
|
+
topZero(5) && groups[5] === 65535 || // ::ffff:0:0/96 — IPv4-translated form (ffff in group 4, group 5 zero)
|
|
715
|
+
topZero(4) && groups[4] === 65535 && groups[5] === 0 || // 64:ff9b::/96 — NAT64 well-known prefix
|
|
716
|
+
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
|
|
717
|
+
groups[0] === 100 && groups[1] === 65435 && groups[2] === 1
|
|
718
|
+
);
|
|
719
|
+
if (embedsIPv4) {
|
|
720
|
+
const a = groups[6] >> 8 & 255;
|
|
721
|
+
const b = groups[6] & 255;
|
|
722
|
+
const c = groups[7] >> 8 & 255;
|
|
723
|
+
const d = groups[7] & 255;
|
|
724
|
+
return isPrivateIPv4(`${a}.${b}.${c}.${d}`);
|
|
725
|
+
}
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
var MAX_DOWNLOAD_REDIRECTS = 10;
|
|
729
|
+
async function fetchWithValidatedRedirects({
|
|
730
|
+
url,
|
|
731
|
+
headers,
|
|
732
|
+
abortSignal,
|
|
733
|
+
maxRedirects = MAX_DOWNLOAD_REDIRECTS
|
|
734
|
+
}) {
|
|
735
|
+
const baseInit = { signal: abortSignal };
|
|
736
|
+
if (headers !== void 0) {
|
|
737
|
+
baseInit.headers = headers;
|
|
738
|
+
}
|
|
739
|
+
let currentUrl = url;
|
|
740
|
+
for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
|
|
741
|
+
validateDownloadUrl(currentUrl);
|
|
742
|
+
const response = await fetch(currentUrl, {
|
|
743
|
+
...baseInit,
|
|
744
|
+
redirect: "manual"
|
|
745
|
+
});
|
|
746
|
+
if (response.type === "opaqueredirect") {
|
|
747
|
+
if (!isBrowserRuntime()) {
|
|
748
|
+
throw new DownloadError({
|
|
749
|
+
url,
|
|
750
|
+
message: `Redirect from ${currentUrl} could not be validated and was blocked`
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
return await fetch(currentUrl, { ...baseInit, redirect: "follow" });
|
|
754
|
+
}
|
|
755
|
+
const location = response.headers.get("location");
|
|
756
|
+
if (response.status >= 300 && response.status < 400 && location) {
|
|
757
|
+
await cancelResponseBody(response);
|
|
758
|
+
currentUrl = new URL(location, currentUrl).toString();
|
|
759
|
+
continue;
|
|
760
|
+
}
|
|
761
|
+
return response;
|
|
762
|
+
}
|
|
763
|
+
throw new DownloadError({
|
|
764
|
+
url,
|
|
765
|
+
message: `Too many redirects (max ${maxRedirects})`
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
var DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
|
|
769
|
+
async function readResponseWithSizeLimit({
|
|
770
|
+
response,
|
|
771
|
+
url,
|
|
772
|
+
maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE
|
|
773
|
+
}) {
|
|
774
|
+
const contentLength = response.headers.get("content-length");
|
|
775
|
+
if (contentLength != null) {
|
|
776
|
+
const length = parseInt(contentLength, 10);
|
|
777
|
+
if (!isNaN(length) && length > maxBytes) {
|
|
778
|
+
await cancelResponseBody(response);
|
|
779
|
+
throw new DownloadError({
|
|
780
|
+
url,
|
|
781
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
const body = response.body;
|
|
786
|
+
if (body == null) {
|
|
787
|
+
return new Uint8Array(0);
|
|
788
|
+
}
|
|
789
|
+
const reader = body.getReader();
|
|
790
|
+
const chunks = [];
|
|
791
|
+
let totalBytes = 0;
|
|
792
|
+
try {
|
|
793
|
+
while (true) {
|
|
794
|
+
const { done, value } = await reader.read();
|
|
795
|
+
if (done) {
|
|
796
|
+
break;
|
|
797
|
+
}
|
|
798
|
+
totalBytes += value.length;
|
|
799
|
+
if (totalBytes > maxBytes) {
|
|
800
|
+
throw new DownloadError({
|
|
801
|
+
url,
|
|
802
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
chunks.push(value);
|
|
806
|
+
}
|
|
807
|
+
} finally {
|
|
808
|
+
try {
|
|
809
|
+
await reader.cancel();
|
|
810
|
+
} finally {
|
|
811
|
+
reader.releaseLock();
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
const result = new Uint8Array(totalBytes);
|
|
815
|
+
let offset = 0;
|
|
816
|
+
for (const chunk of chunks) {
|
|
817
|
+
result.set(chunk, offset);
|
|
818
|
+
offset += chunk.length;
|
|
819
|
+
}
|
|
820
|
+
return result;
|
|
821
|
+
}
|
|
822
|
+
var createIdGenerator = ({
|
|
823
|
+
prefix,
|
|
824
|
+
size = 16,
|
|
825
|
+
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
826
|
+
separator = "-"
|
|
827
|
+
} = {}) => {
|
|
828
|
+
const generator = () => {
|
|
829
|
+
const alphabetLength = alphabet.length;
|
|
830
|
+
const chars = new Array(size);
|
|
831
|
+
for (let i = 0; i < size; i++) {
|
|
832
|
+
chars[i] = alphabet[Math.random() * alphabetLength | 0];
|
|
833
|
+
}
|
|
834
|
+
return chars.join("");
|
|
835
|
+
};
|
|
836
|
+
if (prefix == null) {
|
|
837
|
+
return generator;
|
|
838
|
+
}
|
|
839
|
+
if (alphabet.includes(separator)) {
|
|
840
|
+
throw new InvalidArgumentError({
|
|
841
|
+
argument: "separator",
|
|
842
|
+
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
return () => `${prefix}${separator}${generator()}`;
|
|
846
|
+
};
|
|
847
|
+
var generateId = createIdGenerator();
|
|
848
|
+
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
849
|
+
var _a23, _b22, _c;
|
|
850
|
+
if (globalThisAny.window) {
|
|
851
|
+
return `runtime/browser`;
|
|
852
|
+
}
|
|
853
|
+
if ((_a23 = globalThisAny.navigator) == null ? void 0 : _a23.userAgent) {
|
|
854
|
+
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
855
|
+
}
|
|
856
|
+
if ((_c = (_b22 = globalThisAny.process) == null ? void 0 : _b22.versions) == null ? void 0 : _c.node) {
|
|
857
|
+
return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
|
858
|
+
}
|
|
859
|
+
if (globalThisAny.EdgeRuntime) {
|
|
860
|
+
return `runtime/vercel-edge`;
|
|
861
|
+
}
|
|
862
|
+
return "runtime/unknown";
|
|
863
|
+
}
|
|
864
|
+
function normalizeHeaders(headers) {
|
|
865
|
+
if (headers == null) {
|
|
866
|
+
return {};
|
|
867
|
+
}
|
|
868
|
+
const normalized = {};
|
|
869
|
+
if (headers instanceof Headers) {
|
|
870
|
+
headers.forEach((value, key) => {
|
|
871
|
+
normalized[key.toLowerCase()] = value;
|
|
872
|
+
});
|
|
873
|
+
} else {
|
|
874
|
+
if (!Array.isArray(headers)) {
|
|
875
|
+
headers = Object.entries(headers);
|
|
876
|
+
}
|
|
877
|
+
for (const [key, value] of headers) {
|
|
878
|
+
if (value != null) {
|
|
879
|
+
normalized[key.toLowerCase()] = value;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
return normalized;
|
|
884
|
+
}
|
|
885
|
+
function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
886
|
+
const normalizedHeaders = new Headers(normalizeHeaders(headers));
|
|
887
|
+
const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
|
|
888
|
+
normalizedHeaders.set(
|
|
889
|
+
"user-agent",
|
|
890
|
+
[currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" ")
|
|
891
|
+
);
|
|
892
|
+
return Object.fromEntries(normalizedHeaders.entries());
|
|
893
|
+
}
|
|
894
|
+
var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
895
|
+
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*:/;
|
|
896
|
+
function _parse(text2) {
|
|
897
|
+
const obj = JSON.parse(text2);
|
|
898
|
+
if (obj === null || typeof obj !== "object") {
|
|
899
|
+
return obj;
|
|
900
|
+
}
|
|
901
|
+
if (suspectProtoRx.test(text2) === false && suspectConstructorRx.test(text2) === false) {
|
|
902
|
+
return obj;
|
|
903
|
+
}
|
|
904
|
+
return filter(obj);
|
|
905
|
+
}
|
|
906
|
+
function filter(obj) {
|
|
907
|
+
let next = [obj];
|
|
908
|
+
while (next.length) {
|
|
909
|
+
const nodes = next;
|
|
910
|
+
next = [];
|
|
911
|
+
for (const node of nodes) {
|
|
912
|
+
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
913
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
914
|
+
}
|
|
915
|
+
if (Object.prototype.hasOwnProperty.call(node, "constructor") && node.constructor !== null && typeof node.constructor === "object" && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
916
|
+
throw new SyntaxError("Object contains forbidden prototype property");
|
|
917
|
+
}
|
|
918
|
+
for (const key in node) {
|
|
919
|
+
const value = node[key];
|
|
920
|
+
if (value && typeof value === "object") {
|
|
921
|
+
next.push(value);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
return obj;
|
|
927
|
+
}
|
|
928
|
+
function secureJsonParse(text2) {
|
|
929
|
+
const { stackTraceLimit } = Error;
|
|
930
|
+
try {
|
|
931
|
+
Error.stackTraceLimit = 0;
|
|
932
|
+
} catch (e) {
|
|
933
|
+
return _parse(text2);
|
|
934
|
+
}
|
|
935
|
+
try {
|
|
936
|
+
return _parse(text2);
|
|
937
|
+
} finally {
|
|
938
|
+
Error.stackTraceLimit = stackTraceLimit;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
function addAdditionalPropertiesToJsonSchema(jsonSchema2) {
|
|
942
|
+
if (jsonSchema2.type === "object" || Array.isArray(jsonSchema2.type) && jsonSchema2.type.includes("object")) {
|
|
943
|
+
jsonSchema2.additionalProperties = false;
|
|
944
|
+
const { properties } = jsonSchema2;
|
|
945
|
+
if (properties != null) {
|
|
946
|
+
for (const key of Object.keys(properties)) {
|
|
947
|
+
properties[key] = visit(properties[key]);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
if (jsonSchema2.items != null) {
|
|
952
|
+
jsonSchema2.items = Array.isArray(jsonSchema2.items) ? jsonSchema2.items.map(visit) : visit(jsonSchema2.items);
|
|
953
|
+
}
|
|
954
|
+
if (jsonSchema2.anyOf != null) {
|
|
955
|
+
jsonSchema2.anyOf = jsonSchema2.anyOf.map(visit);
|
|
956
|
+
}
|
|
957
|
+
if (jsonSchema2.allOf != null) {
|
|
958
|
+
jsonSchema2.allOf = jsonSchema2.allOf.map(visit);
|
|
959
|
+
}
|
|
960
|
+
if (jsonSchema2.oneOf != null) {
|
|
961
|
+
jsonSchema2.oneOf = jsonSchema2.oneOf.map(visit);
|
|
962
|
+
}
|
|
963
|
+
const { definitions } = jsonSchema2;
|
|
964
|
+
if (definitions != null) {
|
|
965
|
+
for (const key of Object.keys(definitions)) {
|
|
966
|
+
definitions[key] = visit(definitions[key]);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
return jsonSchema2;
|
|
970
|
+
}
|
|
971
|
+
function visit(def) {
|
|
972
|
+
if (typeof def === "boolean") return def;
|
|
973
|
+
return addAdditionalPropertiesToJsonSchema(def);
|
|
974
|
+
}
|
|
975
|
+
var ignoreOverride = /* @__PURE__ */ Symbol(
|
|
976
|
+
"Let zodToJsonSchema decide on which parser to use"
|
|
977
|
+
);
|
|
978
|
+
var defaultOptions = {
|
|
979
|
+
name: void 0,
|
|
980
|
+
$refStrategy: "root",
|
|
981
|
+
basePath: ["#"],
|
|
982
|
+
effectStrategy: "input",
|
|
983
|
+
pipeStrategy: "all",
|
|
984
|
+
dateStrategy: "format:date-time",
|
|
985
|
+
mapStrategy: "entries",
|
|
986
|
+
removeAdditionalStrategy: "passthrough",
|
|
987
|
+
allowedAdditionalProperties: true,
|
|
988
|
+
rejectedAdditionalProperties: false,
|
|
989
|
+
definitionPath: "definitions",
|
|
990
|
+
strictUnions: false,
|
|
991
|
+
definitions: {},
|
|
992
|
+
errorMessages: false,
|
|
993
|
+
patternStrategy: "escape",
|
|
994
|
+
applyRegexFlags: false,
|
|
995
|
+
emailStrategy: "format:email",
|
|
996
|
+
base64Strategy: "contentEncoding:base64",
|
|
997
|
+
nameStrategy: "ref"
|
|
998
|
+
};
|
|
999
|
+
var getDefaultOptions = (options) => typeof options === "string" ? {
|
|
1000
|
+
...defaultOptions,
|
|
1001
|
+
name: options
|
|
1002
|
+
} : {
|
|
1003
|
+
...defaultOptions,
|
|
1004
|
+
...options
|
|
1005
|
+
};
|
|
1006
|
+
function parseAnyDef() {
|
|
1007
|
+
return {};
|
|
1008
|
+
}
|
|
1009
|
+
function parseArrayDef(def, refs) {
|
|
1010
|
+
var _a23, _b22, _c;
|
|
1011
|
+
const res = {
|
|
1012
|
+
type: "array"
|
|
1013
|
+
};
|
|
1014
|
+
if (((_a23 = def.type) == null ? void 0 : _a23._def) && ((_c = (_b22 = def.type) == null ? void 0 : _b22._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny) {
|
|
1015
|
+
res.items = parseDef(def.type._def, {
|
|
1016
|
+
...refs,
|
|
1017
|
+
currentPath: [...refs.currentPath, "items"]
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
if (def.minLength) {
|
|
1021
|
+
res.minItems = def.minLength.value;
|
|
1022
|
+
}
|
|
1023
|
+
if (def.maxLength) {
|
|
1024
|
+
res.maxItems = def.maxLength.value;
|
|
1025
|
+
}
|
|
1026
|
+
if (def.exactLength) {
|
|
1027
|
+
res.minItems = def.exactLength.value;
|
|
1028
|
+
res.maxItems = def.exactLength.value;
|
|
1029
|
+
}
|
|
1030
|
+
return res;
|
|
1031
|
+
}
|
|
1032
|
+
function parseBigintDef(def) {
|
|
1033
|
+
const res = {
|
|
1034
|
+
type: "integer",
|
|
1035
|
+
format: "int64"
|
|
1036
|
+
};
|
|
1037
|
+
if (!def.checks) return res;
|
|
1038
|
+
for (const check of def.checks) {
|
|
1039
|
+
switch (check.kind) {
|
|
1040
|
+
case "min":
|
|
1041
|
+
if (check.inclusive) {
|
|
1042
|
+
res.minimum = check.value;
|
|
1043
|
+
} else {
|
|
1044
|
+
res.exclusiveMinimum = check.value;
|
|
1045
|
+
}
|
|
1046
|
+
break;
|
|
1047
|
+
case "max":
|
|
1048
|
+
if (check.inclusive) {
|
|
1049
|
+
res.maximum = check.value;
|
|
1050
|
+
} else {
|
|
1051
|
+
res.exclusiveMaximum = check.value;
|
|
1052
|
+
}
|
|
1053
|
+
break;
|
|
1054
|
+
case "multipleOf":
|
|
1055
|
+
res.multipleOf = check.value;
|
|
1056
|
+
break;
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
return res;
|
|
1060
|
+
}
|
|
1061
|
+
function parseBooleanDef() {
|
|
1062
|
+
return { type: "boolean" };
|
|
1063
|
+
}
|
|
1064
|
+
function parseBrandedDef(_def, refs) {
|
|
1065
|
+
return parseDef(_def.type._def, refs);
|
|
1066
|
+
}
|
|
1067
|
+
var parseCatchDef = (def, refs) => {
|
|
1068
|
+
return parseDef(def.innerType._def, refs);
|
|
1069
|
+
};
|
|
1070
|
+
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
1071
|
+
const strategy = overrideDateStrategy != null ? overrideDateStrategy : refs.dateStrategy;
|
|
1072
|
+
if (Array.isArray(strategy)) {
|
|
1073
|
+
return {
|
|
1074
|
+
anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
switch (strategy) {
|
|
1078
|
+
case "string":
|
|
1079
|
+
case "format:date-time":
|
|
1080
|
+
return {
|
|
1081
|
+
type: "string",
|
|
1082
|
+
format: "date-time"
|
|
1083
|
+
};
|
|
1084
|
+
case "format:date":
|
|
1085
|
+
return {
|
|
1086
|
+
type: "string",
|
|
1087
|
+
format: "date"
|
|
1088
|
+
};
|
|
1089
|
+
case "integer":
|
|
1090
|
+
return integerDateParser(def);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
var integerDateParser = (def) => {
|
|
1094
|
+
const res = {
|
|
1095
|
+
type: "integer",
|
|
1096
|
+
format: "unix-time"
|
|
1097
|
+
};
|
|
1098
|
+
for (const check of def.checks) {
|
|
1099
|
+
switch (check.kind) {
|
|
1100
|
+
case "min":
|
|
1101
|
+
res.minimum = check.value;
|
|
1102
|
+
break;
|
|
1103
|
+
case "max":
|
|
1104
|
+
res.maximum = check.value;
|
|
1105
|
+
break;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
return res;
|
|
1109
|
+
};
|
|
1110
|
+
function parseDefaultDef(_def, refs) {
|
|
1111
|
+
return {
|
|
1112
|
+
...parseDef(_def.innerType._def, refs),
|
|
1113
|
+
default: _def.defaultValue()
|
|
1114
|
+
};
|
|
1115
|
+
}
|
|
1116
|
+
function parseEffectsDef(_def, refs) {
|
|
1117
|
+
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : parseAnyDef();
|
|
1118
|
+
}
|
|
1119
|
+
function parseEnumDef(def) {
|
|
1120
|
+
return {
|
|
1121
|
+
type: "string",
|
|
1122
|
+
enum: Array.from(def.values)
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
var isJsonSchema7AllOfType = (type) => {
|
|
1126
|
+
if ("type" in type && type.type === "string") return false;
|
|
1127
|
+
return "allOf" in type;
|
|
1128
|
+
};
|
|
1129
|
+
function parseIntersectionDef(def, refs) {
|
|
1130
|
+
const allOf = [
|
|
1131
|
+
parseDef(def.left._def, {
|
|
1132
|
+
...refs,
|
|
1133
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1134
|
+
}),
|
|
1135
|
+
parseDef(def.right._def, {
|
|
1136
|
+
...refs,
|
|
1137
|
+
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
1138
|
+
})
|
|
1139
|
+
].filter((x) => !!x);
|
|
1140
|
+
const mergedAllOf = [];
|
|
1141
|
+
allOf.forEach((schema) => {
|
|
1142
|
+
if (isJsonSchema7AllOfType(schema)) {
|
|
1143
|
+
mergedAllOf.push(...schema.allOf);
|
|
1144
|
+
} else {
|
|
1145
|
+
let nestedSchema = schema;
|
|
1146
|
+
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
1147
|
+
const { additionalProperties, ...rest } = schema;
|
|
1148
|
+
nestedSchema = rest;
|
|
1149
|
+
}
|
|
1150
|
+
mergedAllOf.push(nestedSchema);
|
|
1151
|
+
}
|
|
1152
|
+
});
|
|
1153
|
+
return mergedAllOf.length ? { allOf: mergedAllOf } : void 0;
|
|
1154
|
+
}
|
|
1155
|
+
function parseLiteralDef(def) {
|
|
1156
|
+
const parsedType = typeof def.value;
|
|
1157
|
+
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
1158
|
+
return {
|
|
1159
|
+
type: Array.isArray(def.value) ? "array" : "object"
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
return {
|
|
1163
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
1164
|
+
const: def.value
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
var emojiRegex = void 0;
|
|
1168
|
+
var zodPatterns = {
|
|
1169
|
+
/**
|
|
1170
|
+
* `c` was changed to `[cC]` to replicate /i flag
|
|
1171
|
+
*/
|
|
1172
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
1173
|
+
cuid2: /^[0-9a-z]+$/,
|
|
1174
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
1175
|
+
/**
|
|
1176
|
+
* `a-z` was added to replicate /i flag
|
|
1177
|
+
*/
|
|
1178
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
1179
|
+
/**
|
|
1180
|
+
* Constructed a valid Unicode RegExp
|
|
1181
|
+
*
|
|
1182
|
+
* Lazily instantiate since this type of regex isn't supported
|
|
1183
|
+
* in all envs (e.g. React Native).
|
|
1184
|
+
*
|
|
1185
|
+
* See:
|
|
1186
|
+
* https://github.com/colinhacks/zod/issues/2433
|
|
1187
|
+
* Fix in Zod:
|
|
1188
|
+
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
1189
|
+
*/
|
|
1190
|
+
emoji: () => {
|
|
1191
|
+
if (emojiRegex === void 0) {
|
|
1192
|
+
emojiRegex = RegExp(
|
|
1193
|
+
"^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",
|
|
1194
|
+
"u"
|
|
1195
|
+
);
|
|
1196
|
+
}
|
|
1197
|
+
return emojiRegex;
|
|
1198
|
+
},
|
|
1199
|
+
/**
|
|
1200
|
+
* Unused
|
|
1201
|
+
*/
|
|
1202
|
+
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}$/,
|
|
1203
|
+
/**
|
|
1204
|
+
* Unused
|
|
1205
|
+
*/
|
|
1206
|
+
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])$/,
|
|
1207
|
+
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])$/,
|
|
1208
|
+
/**
|
|
1209
|
+
* Unused
|
|
1210
|
+
*/
|
|
1211
|
+
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})))$/,
|
|
1212
|
+
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])$/,
|
|
1213
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
1214
|
+
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
1215
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
1216
|
+
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
1217
|
+
};
|
|
1218
|
+
function parseStringDef(def, refs) {
|
|
1219
|
+
const res = {
|
|
1220
|
+
type: "string"
|
|
1221
|
+
};
|
|
1222
|
+
if (def.checks) {
|
|
1223
|
+
for (const check of def.checks) {
|
|
1224
|
+
switch (check.kind) {
|
|
1225
|
+
case "min":
|
|
1226
|
+
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
|
|
1227
|
+
break;
|
|
1228
|
+
case "max":
|
|
1229
|
+
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
|
|
1230
|
+
break;
|
|
1231
|
+
case "email":
|
|
1232
|
+
switch (refs.emailStrategy) {
|
|
1233
|
+
case "format:email":
|
|
1234
|
+
addFormat(res, "email", check.message, refs);
|
|
1235
|
+
break;
|
|
1236
|
+
case "format:idn-email":
|
|
1237
|
+
addFormat(res, "idn-email", check.message, refs);
|
|
1238
|
+
break;
|
|
1239
|
+
case "pattern:zod":
|
|
1240
|
+
addPattern(res, zodPatterns.email, check.message, refs);
|
|
1241
|
+
break;
|
|
1242
|
+
}
|
|
1243
|
+
break;
|
|
1244
|
+
case "url":
|
|
1245
|
+
addFormat(res, "uri", check.message, refs);
|
|
1246
|
+
break;
|
|
1247
|
+
case "uuid":
|
|
1248
|
+
addFormat(res, "uuid", check.message, refs);
|
|
1249
|
+
break;
|
|
1250
|
+
case "regex":
|
|
1251
|
+
addPattern(res, check.regex, check.message, refs);
|
|
1252
|
+
break;
|
|
1253
|
+
case "cuid":
|
|
1254
|
+
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
1255
|
+
break;
|
|
1256
|
+
case "cuid2":
|
|
1257
|
+
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
1258
|
+
break;
|
|
1259
|
+
case "startsWith":
|
|
1260
|
+
addPattern(
|
|
1261
|
+
res,
|
|
1262
|
+
RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`),
|
|
1263
|
+
check.message,
|
|
1264
|
+
refs
|
|
1265
|
+
);
|
|
1266
|
+
break;
|
|
1267
|
+
case "endsWith":
|
|
1268
|
+
addPattern(
|
|
1269
|
+
res,
|
|
1270
|
+
RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`),
|
|
1271
|
+
check.message,
|
|
1272
|
+
refs
|
|
1273
|
+
);
|
|
1274
|
+
break;
|
|
1275
|
+
case "datetime":
|
|
1276
|
+
addFormat(res, "date-time", check.message, refs);
|
|
1277
|
+
break;
|
|
1278
|
+
case "date":
|
|
1279
|
+
addFormat(res, "date", check.message, refs);
|
|
1280
|
+
break;
|
|
1281
|
+
case "time":
|
|
1282
|
+
addFormat(res, "time", check.message, refs);
|
|
1283
|
+
break;
|
|
1284
|
+
case "duration":
|
|
1285
|
+
addFormat(res, "duration", check.message, refs);
|
|
1286
|
+
break;
|
|
1287
|
+
case "length":
|
|
1288
|
+
res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
|
|
1289
|
+
res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
|
|
1290
|
+
break;
|
|
1291
|
+
case "includes": {
|
|
1292
|
+
addPattern(
|
|
1293
|
+
res,
|
|
1294
|
+
RegExp(escapeLiteralCheckValue(check.value, refs)),
|
|
1295
|
+
check.message,
|
|
1296
|
+
refs
|
|
1297
|
+
);
|
|
1298
|
+
break;
|
|
1299
|
+
}
|
|
1300
|
+
case "ip": {
|
|
1301
|
+
if (check.version !== "v6") {
|
|
1302
|
+
addFormat(res, "ipv4", check.message, refs);
|
|
1303
|
+
}
|
|
1304
|
+
if (check.version !== "v4") {
|
|
1305
|
+
addFormat(res, "ipv6", check.message, refs);
|
|
1306
|
+
}
|
|
1307
|
+
break;
|
|
1308
|
+
}
|
|
1309
|
+
case "base64url":
|
|
1310
|
+
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
1311
|
+
break;
|
|
1312
|
+
case "jwt":
|
|
1313
|
+
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
1314
|
+
break;
|
|
1315
|
+
case "cidr": {
|
|
1316
|
+
if (check.version !== "v6") {
|
|
1317
|
+
addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
1318
|
+
}
|
|
1319
|
+
if (check.version !== "v4") {
|
|
1320
|
+
addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
1321
|
+
}
|
|
1322
|
+
break;
|
|
1323
|
+
}
|
|
1324
|
+
case "emoji":
|
|
1325
|
+
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
1326
|
+
break;
|
|
1327
|
+
case "ulid": {
|
|
1328
|
+
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
1329
|
+
break;
|
|
1330
|
+
}
|
|
1331
|
+
case "base64": {
|
|
1332
|
+
switch (refs.base64Strategy) {
|
|
1333
|
+
case "format:binary": {
|
|
1334
|
+
addFormat(res, "binary", check.message, refs);
|
|
1335
|
+
break;
|
|
1336
|
+
}
|
|
1337
|
+
case "contentEncoding:base64": {
|
|
1338
|
+
res.contentEncoding = "base64";
|
|
1339
|
+
break;
|
|
1340
|
+
}
|
|
1341
|
+
case "pattern:zod": {
|
|
1342
|
+
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
1343
|
+
break;
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
break;
|
|
1347
|
+
}
|
|
1348
|
+
case "nanoid": {
|
|
1349
|
+
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
1350
|
+
}
|
|
1351
|
+
case "toLowerCase":
|
|
1352
|
+
case "toUpperCase":
|
|
1353
|
+
case "trim":
|
|
1354
|
+
break;
|
|
1355
|
+
default:
|
|
1356
|
+
/* @__PURE__ */ ((_) => {
|
|
1357
|
+
})(check);
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
return res;
|
|
1362
|
+
}
|
|
1363
|
+
function escapeLiteralCheckValue(literal, refs) {
|
|
1364
|
+
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
1365
|
+
}
|
|
1366
|
+
var ALPHA_NUMERIC = new Set(
|
|
1367
|
+
"ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789"
|
|
1368
|
+
);
|
|
1369
|
+
function escapeNonAlphaNumeric(source) {
|
|
1370
|
+
let result = "";
|
|
1371
|
+
for (let i = 0; i < source.length; i++) {
|
|
1372
|
+
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
1373
|
+
result += "\\";
|
|
1374
|
+
}
|
|
1375
|
+
result += source[i];
|
|
1376
|
+
}
|
|
1377
|
+
return result;
|
|
1378
|
+
}
|
|
1379
|
+
function addFormat(schema, value, message, refs) {
|
|
1380
|
+
var _a23;
|
|
1381
|
+
if (schema.format || ((_a23 = schema.anyOf) == null ? void 0 : _a23.some((x) => x.format))) {
|
|
1382
|
+
if (!schema.anyOf) {
|
|
1383
|
+
schema.anyOf = [];
|
|
1384
|
+
}
|
|
1385
|
+
if (schema.format) {
|
|
1386
|
+
schema.anyOf.push({
|
|
1387
|
+
format: schema.format
|
|
1388
|
+
});
|
|
1389
|
+
delete schema.format;
|
|
1390
|
+
}
|
|
1391
|
+
schema.anyOf.push({
|
|
1392
|
+
format: value,
|
|
1393
|
+
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
1394
|
+
});
|
|
1395
|
+
} else {
|
|
1396
|
+
schema.format = value;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
function addPattern(schema, regex, message, refs) {
|
|
1400
|
+
var _a23;
|
|
1401
|
+
if (schema.pattern || ((_a23 = schema.allOf) == null ? void 0 : _a23.some((x) => x.pattern))) {
|
|
1402
|
+
if (!schema.allOf) {
|
|
1403
|
+
schema.allOf = [];
|
|
1404
|
+
}
|
|
1405
|
+
if (schema.pattern) {
|
|
1406
|
+
schema.allOf.push({
|
|
1407
|
+
pattern: schema.pattern
|
|
1408
|
+
});
|
|
1409
|
+
delete schema.pattern;
|
|
1410
|
+
}
|
|
1411
|
+
schema.allOf.push({
|
|
1412
|
+
pattern: stringifyRegExpWithFlags(regex, refs),
|
|
1413
|
+
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
1414
|
+
});
|
|
1415
|
+
} else {
|
|
1416
|
+
schema.pattern = stringifyRegExpWithFlags(regex, refs);
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
function stringifyRegExpWithFlags(regex, refs) {
|
|
1420
|
+
var _a23;
|
|
1421
|
+
if (!refs.applyRegexFlags || !regex.flags) {
|
|
1422
|
+
return regex.source;
|
|
1423
|
+
}
|
|
1424
|
+
const flags = {
|
|
1425
|
+
i: regex.flags.includes("i"),
|
|
1426
|
+
// Case-insensitive
|
|
1427
|
+
m: regex.flags.includes("m"),
|
|
1428
|
+
// `^` and `$` matches adjacent to newline characters
|
|
1429
|
+
s: regex.flags.includes("s")
|
|
1430
|
+
// `.` matches newlines
|
|
1431
|
+
};
|
|
1432
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
1433
|
+
let pattern = "";
|
|
1434
|
+
let isEscaped = false;
|
|
1435
|
+
let inCharGroup = false;
|
|
1436
|
+
let inCharRange = false;
|
|
1437
|
+
for (let i = 0; i < source.length; i++) {
|
|
1438
|
+
if (isEscaped) {
|
|
1439
|
+
pattern += source[i];
|
|
1440
|
+
isEscaped = false;
|
|
1441
|
+
continue;
|
|
1442
|
+
}
|
|
1443
|
+
if (flags.i) {
|
|
1444
|
+
if (inCharGroup) {
|
|
1445
|
+
if (source[i].match(/[a-z]/)) {
|
|
1446
|
+
if (inCharRange) {
|
|
1447
|
+
pattern += source[i];
|
|
1448
|
+
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
1449
|
+
inCharRange = false;
|
|
1450
|
+
} else if (source[i + 1] === "-" && ((_a23 = source[i + 2]) == null ? void 0 : _a23.match(/[a-z]/))) {
|
|
1451
|
+
pattern += source[i];
|
|
1452
|
+
inCharRange = true;
|
|
1453
|
+
} else {
|
|
1454
|
+
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
1455
|
+
}
|
|
1456
|
+
continue;
|
|
1457
|
+
}
|
|
1458
|
+
} else if (source[i].match(/[a-z]/)) {
|
|
1459
|
+
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
1460
|
+
continue;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
if (flags.m) {
|
|
1464
|
+
if (source[i] === "^") {
|
|
1465
|
+
pattern += `(^|(?<=[\r
|
|
1466
|
+
]))`;
|
|
1467
|
+
continue;
|
|
1468
|
+
} else if (source[i] === "$") {
|
|
1469
|
+
pattern += `($|(?=[\r
|
|
1470
|
+
]))`;
|
|
1471
|
+
continue;
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
if (flags.s && source[i] === ".") {
|
|
1475
|
+
pattern += inCharGroup ? `${source[i]}\r
|
|
1476
|
+
` : `[${source[i]}\r
|
|
1477
|
+
]`;
|
|
1478
|
+
continue;
|
|
1479
|
+
}
|
|
1480
|
+
pattern += source[i];
|
|
1481
|
+
if (source[i] === "\\") {
|
|
1482
|
+
isEscaped = true;
|
|
1483
|
+
} else if (inCharGroup && source[i] === "]") {
|
|
1484
|
+
inCharGroup = false;
|
|
1485
|
+
} else if (!inCharGroup && source[i] === "[") {
|
|
1486
|
+
inCharGroup = true;
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
try {
|
|
1490
|
+
new RegExp(pattern);
|
|
1491
|
+
} catch (e) {
|
|
1492
|
+
console.warn(
|
|
1493
|
+
`Could not convert regex pattern at ${refs.currentPath.join(
|
|
1494
|
+
"/"
|
|
1495
|
+
)} to a flag-independent form! Falling back to the flag-ignorant source`
|
|
1496
|
+
);
|
|
1497
|
+
return regex.source;
|
|
1498
|
+
}
|
|
1499
|
+
return pattern;
|
|
1500
|
+
}
|
|
1501
|
+
function parseRecordDef(def, refs) {
|
|
1502
|
+
var _a23, _b22, _c, _d, _e, _f;
|
|
1503
|
+
const schema = {
|
|
1504
|
+
type: "object",
|
|
1505
|
+
additionalProperties: (_a23 = parseDef(def.valueType._def, {
|
|
1506
|
+
...refs,
|
|
1507
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1508
|
+
})) != null ? _a23 : refs.allowedAdditionalProperties
|
|
1509
|
+
};
|
|
1510
|
+
if (((_b22 = def.keyType) == null ? void 0 : _b22._def.typeName) === ZodFirstPartyTypeKind2.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
1511
|
+
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
1512
|
+
return {
|
|
1513
|
+
...schema,
|
|
1514
|
+
propertyNames: keyType
|
|
1515
|
+
};
|
|
1516
|
+
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
1517
|
+
return {
|
|
1518
|
+
...schema,
|
|
1519
|
+
propertyNames: {
|
|
1520
|
+
enum: def.keyType._def.values
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
} else if (((_e = def.keyType) == null ? void 0 : _e._def.typeName) === ZodFirstPartyTypeKind2.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind2.ZodString && ((_f = def.keyType._def.type._def.checks) == null ? void 0 : _f.length)) {
|
|
1524
|
+
const { type, ...keyType } = parseBrandedDef(
|
|
1525
|
+
def.keyType._def,
|
|
1526
|
+
refs
|
|
1527
|
+
);
|
|
1528
|
+
return {
|
|
1529
|
+
...schema,
|
|
1530
|
+
propertyNames: keyType
|
|
1531
|
+
};
|
|
1532
|
+
}
|
|
1533
|
+
return schema;
|
|
1534
|
+
}
|
|
1535
|
+
function parseMapDef(def, refs) {
|
|
1536
|
+
if (refs.mapStrategy === "record") {
|
|
1537
|
+
return parseRecordDef(def, refs);
|
|
1538
|
+
}
|
|
1539
|
+
const keys = parseDef(def.keyType._def, {
|
|
1540
|
+
...refs,
|
|
1541
|
+
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
1542
|
+
}) || parseAnyDef();
|
|
1543
|
+
const values = parseDef(def.valueType._def, {
|
|
1544
|
+
...refs,
|
|
1545
|
+
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
1546
|
+
}) || parseAnyDef();
|
|
1547
|
+
return {
|
|
1548
|
+
type: "array",
|
|
1549
|
+
maxItems: 125,
|
|
1550
|
+
items: {
|
|
1551
|
+
type: "array",
|
|
1552
|
+
items: [keys, values],
|
|
1553
|
+
minItems: 2,
|
|
1554
|
+
maxItems: 2
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
function parseNativeEnumDef(def) {
|
|
1559
|
+
const object2 = def.values;
|
|
1560
|
+
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
1561
|
+
return typeof object2[object2[key]] !== "number";
|
|
1562
|
+
});
|
|
1563
|
+
const actualValues = actualKeys.map((key) => object2[key]);
|
|
1564
|
+
const parsedTypes = Array.from(
|
|
1565
|
+
new Set(actualValues.map((values) => typeof values))
|
|
1566
|
+
);
|
|
1567
|
+
return {
|
|
1568
|
+
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
1569
|
+
enum: actualValues
|
|
1570
|
+
};
|
|
1571
|
+
}
|
|
1572
|
+
function parseNeverDef() {
|
|
1573
|
+
return { not: parseAnyDef() };
|
|
1574
|
+
}
|
|
1575
|
+
function parseNullDef() {
|
|
1576
|
+
return {
|
|
1577
|
+
type: "null"
|
|
1578
|
+
};
|
|
1579
|
+
}
|
|
1580
|
+
var primitiveMappings = {
|
|
1581
|
+
ZodString: "string",
|
|
1582
|
+
ZodNumber: "number",
|
|
1583
|
+
ZodBigInt: "integer",
|
|
1584
|
+
ZodBoolean: "boolean",
|
|
1585
|
+
ZodNull: "null"
|
|
1586
|
+
};
|
|
1587
|
+
function parseUnionDef(def, refs) {
|
|
1588
|
+
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
1589
|
+
if (options.every(
|
|
1590
|
+
(x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length)
|
|
1591
|
+
)) {
|
|
1592
|
+
const types = options.reduce((types2, x) => {
|
|
1593
|
+
const type = primitiveMappings[x._def.typeName];
|
|
1594
|
+
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
1595
|
+
}, []);
|
|
1596
|
+
return {
|
|
1597
|
+
type: types.length > 1 ? types : types[0]
|
|
1598
|
+
};
|
|
1599
|
+
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
1600
|
+
const types = options.reduce(
|
|
1601
|
+
(acc, x) => {
|
|
1602
|
+
const type = typeof x._def.value;
|
|
1603
|
+
switch (type) {
|
|
1604
|
+
case "string":
|
|
1605
|
+
case "number":
|
|
1606
|
+
case "boolean":
|
|
1607
|
+
return [...acc, type];
|
|
1608
|
+
case "bigint":
|
|
1609
|
+
return [...acc, "integer"];
|
|
1610
|
+
case "object":
|
|
1611
|
+
if (x._def.value === null) return [...acc, "null"];
|
|
1612
|
+
case "symbol":
|
|
1613
|
+
case "undefined":
|
|
1614
|
+
case "function":
|
|
1615
|
+
default:
|
|
1616
|
+
return acc;
|
|
1617
|
+
}
|
|
1618
|
+
},
|
|
1619
|
+
[]
|
|
1620
|
+
);
|
|
1621
|
+
if (types.length === options.length) {
|
|
1622
|
+
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
1623
|
+
return {
|
|
1624
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
1625
|
+
enum: options.reduce(
|
|
1626
|
+
(acc, x) => {
|
|
1627
|
+
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
1628
|
+
},
|
|
1629
|
+
[]
|
|
1630
|
+
)
|
|
1631
|
+
};
|
|
1632
|
+
}
|
|
1633
|
+
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
1634
|
+
return {
|
|
1635
|
+
type: "string",
|
|
1636
|
+
enum: options.reduce(
|
|
1637
|
+
(acc, x) => [
|
|
1638
|
+
...acc,
|
|
1639
|
+
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
1640
|
+
],
|
|
1641
|
+
[]
|
|
1642
|
+
)
|
|
1643
|
+
};
|
|
1644
|
+
}
|
|
1645
|
+
return asAnyOf(def, refs);
|
|
1646
|
+
}
|
|
1647
|
+
var asAnyOf = (def, refs) => {
|
|
1648
|
+
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map(
|
|
1649
|
+
(x, i) => parseDef(x._def, {
|
|
1650
|
+
...refs,
|
|
1651
|
+
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
1652
|
+
})
|
|
1653
|
+
).filter(
|
|
1654
|
+
(x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0)
|
|
1655
|
+
);
|
|
1656
|
+
return anyOf.length ? { anyOf } : void 0;
|
|
1657
|
+
};
|
|
1658
|
+
function parseNullableDef(def, refs) {
|
|
1659
|
+
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(
|
|
1660
|
+
def.innerType._def.typeName
|
|
1661
|
+
) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
1662
|
+
return {
|
|
1663
|
+
type: [
|
|
1664
|
+
primitiveMappings[def.innerType._def.typeName],
|
|
1665
|
+
"null"
|
|
1666
|
+
]
|
|
1667
|
+
};
|
|
1668
|
+
}
|
|
1669
|
+
const base = parseDef(def.innerType._def, {
|
|
1670
|
+
...refs,
|
|
1671
|
+
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
1672
|
+
});
|
|
1673
|
+
return base && { anyOf: [base, { type: "null" }] };
|
|
1674
|
+
}
|
|
1675
|
+
function parseNumberDef(def) {
|
|
1676
|
+
const res = {
|
|
1677
|
+
type: "number"
|
|
1678
|
+
};
|
|
1679
|
+
if (!def.checks) return res;
|
|
1680
|
+
for (const check of def.checks) {
|
|
1681
|
+
switch (check.kind) {
|
|
1682
|
+
case "int":
|
|
1683
|
+
res.type = "integer";
|
|
1684
|
+
break;
|
|
1685
|
+
case "min":
|
|
1686
|
+
if (check.inclusive) {
|
|
1687
|
+
res.minimum = check.value;
|
|
1688
|
+
} else {
|
|
1689
|
+
res.exclusiveMinimum = check.value;
|
|
1690
|
+
}
|
|
1691
|
+
break;
|
|
1692
|
+
case "max":
|
|
1693
|
+
if (check.inclusive) {
|
|
1694
|
+
res.maximum = check.value;
|
|
1695
|
+
} else {
|
|
1696
|
+
res.exclusiveMaximum = check.value;
|
|
1697
|
+
}
|
|
1698
|
+
break;
|
|
1699
|
+
case "multipleOf":
|
|
1700
|
+
res.multipleOf = check.value;
|
|
1701
|
+
break;
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
return res;
|
|
1705
|
+
}
|
|
1706
|
+
function parseObjectDef(def, refs) {
|
|
1707
|
+
const result = {
|
|
1708
|
+
type: "object",
|
|
1709
|
+
properties: {}
|
|
1710
|
+
};
|
|
1711
|
+
const required = [];
|
|
1712
|
+
const shape = def.shape();
|
|
1713
|
+
for (const propName in shape) {
|
|
1714
|
+
let propDef = shape[propName];
|
|
1715
|
+
if (propDef === void 0 || propDef._def === void 0) {
|
|
1716
|
+
continue;
|
|
1717
|
+
}
|
|
1718
|
+
const propOptional = safeIsOptional(propDef);
|
|
1719
|
+
const parsedDef = parseDef(propDef._def, {
|
|
1720
|
+
...refs,
|
|
1721
|
+
currentPath: [...refs.currentPath, "properties", propName],
|
|
1722
|
+
propertyPath: [...refs.currentPath, "properties", propName]
|
|
1723
|
+
});
|
|
1724
|
+
if (parsedDef === void 0) {
|
|
1725
|
+
continue;
|
|
1726
|
+
}
|
|
1727
|
+
result.properties[propName] = parsedDef;
|
|
1728
|
+
if (!propOptional) {
|
|
1729
|
+
required.push(propName);
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
if (required.length) {
|
|
1733
|
+
result.required = required;
|
|
1734
|
+
}
|
|
1735
|
+
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
1736
|
+
if (additionalProperties !== void 0) {
|
|
1737
|
+
result.additionalProperties = additionalProperties;
|
|
1738
|
+
}
|
|
1739
|
+
return result;
|
|
1740
|
+
}
|
|
1741
|
+
function decideAdditionalProperties(def, refs) {
|
|
1742
|
+
if (def.catchall._def.typeName !== "ZodNever") {
|
|
1743
|
+
return parseDef(def.catchall._def, {
|
|
1744
|
+
...refs,
|
|
1745
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1748
|
+
switch (def.unknownKeys) {
|
|
1749
|
+
case "passthrough":
|
|
1750
|
+
return refs.allowedAdditionalProperties;
|
|
1751
|
+
case "strict":
|
|
1752
|
+
return refs.rejectedAdditionalProperties;
|
|
1753
|
+
case "strip":
|
|
1754
|
+
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
function safeIsOptional(schema) {
|
|
1758
|
+
try {
|
|
1759
|
+
return schema.isOptional();
|
|
1760
|
+
} catch (e) {
|
|
1761
|
+
return true;
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
var parseOptionalDef = (def, refs) => {
|
|
1765
|
+
var _a23;
|
|
1766
|
+
if (refs.currentPath.toString() === ((_a23 = refs.propertyPath) == null ? void 0 : _a23.toString())) {
|
|
1767
|
+
return parseDef(def.innerType._def, refs);
|
|
1768
|
+
}
|
|
1769
|
+
const innerSchema = parseDef(def.innerType._def, {
|
|
1770
|
+
...refs,
|
|
1771
|
+
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
1772
|
+
});
|
|
1773
|
+
return innerSchema ? { anyOf: [{ not: parseAnyDef() }, innerSchema] } : parseAnyDef();
|
|
1774
|
+
};
|
|
1775
|
+
var parsePipelineDef = (def, refs) => {
|
|
1776
|
+
if (refs.pipeStrategy === "input") {
|
|
1777
|
+
return parseDef(def.in._def, refs);
|
|
1778
|
+
} else if (refs.pipeStrategy === "output") {
|
|
1779
|
+
return parseDef(def.out._def, refs);
|
|
1780
|
+
}
|
|
1781
|
+
const a = parseDef(def.in._def, {
|
|
1782
|
+
...refs,
|
|
1783
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1784
|
+
});
|
|
1785
|
+
const b = parseDef(def.out._def, {
|
|
1786
|
+
...refs,
|
|
1787
|
+
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
1788
|
+
});
|
|
1789
|
+
return {
|
|
1790
|
+
allOf: [a, b].filter((x) => x !== void 0)
|
|
1791
|
+
};
|
|
1792
|
+
};
|
|
1793
|
+
function parsePromiseDef(def, refs) {
|
|
1794
|
+
return parseDef(def.type._def, refs);
|
|
1795
|
+
}
|
|
1796
|
+
function parseSetDef(def, refs) {
|
|
1797
|
+
const items = parseDef(def.valueType._def, {
|
|
1798
|
+
...refs,
|
|
1799
|
+
currentPath: [...refs.currentPath, "items"]
|
|
1800
|
+
});
|
|
1801
|
+
const schema = {
|
|
1802
|
+
type: "array",
|
|
1803
|
+
uniqueItems: true,
|
|
1804
|
+
items
|
|
1805
|
+
};
|
|
1806
|
+
if (def.minSize) {
|
|
1807
|
+
schema.minItems = def.minSize.value;
|
|
1808
|
+
}
|
|
1809
|
+
if (def.maxSize) {
|
|
1810
|
+
schema.maxItems = def.maxSize.value;
|
|
1811
|
+
}
|
|
1812
|
+
return schema;
|
|
1813
|
+
}
|
|
1814
|
+
function parseTupleDef(def, refs) {
|
|
1815
|
+
if (def.rest) {
|
|
1816
|
+
return {
|
|
1817
|
+
type: "array",
|
|
1818
|
+
minItems: def.items.length,
|
|
1819
|
+
items: def.items.map(
|
|
1820
|
+
(x, i) => parseDef(x._def, {
|
|
1821
|
+
...refs,
|
|
1822
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1823
|
+
})
|
|
1824
|
+
).reduce(
|
|
1825
|
+
(acc, x) => x === void 0 ? acc : [...acc, x],
|
|
1826
|
+
[]
|
|
1827
|
+
),
|
|
1828
|
+
additionalItems: parseDef(def.rest._def, {
|
|
1829
|
+
...refs,
|
|
1830
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
1831
|
+
})
|
|
1832
|
+
};
|
|
1833
|
+
} else {
|
|
1834
|
+
return {
|
|
1835
|
+
type: "array",
|
|
1836
|
+
minItems: def.items.length,
|
|
1837
|
+
maxItems: def.items.length,
|
|
1838
|
+
items: def.items.map(
|
|
1839
|
+
(x, i) => parseDef(x._def, {
|
|
1840
|
+
...refs,
|
|
1841
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1842
|
+
})
|
|
1843
|
+
).reduce(
|
|
1844
|
+
(acc, x) => x === void 0 ? acc : [...acc, x],
|
|
1845
|
+
[]
|
|
1846
|
+
)
|
|
1847
|
+
};
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
function parseUndefinedDef() {
|
|
1851
|
+
return {
|
|
1852
|
+
not: parseAnyDef()
|
|
1853
|
+
};
|
|
1854
|
+
}
|
|
1855
|
+
function parseUnknownDef() {
|
|
1856
|
+
return parseAnyDef();
|
|
1857
|
+
}
|
|
1858
|
+
var parseReadonlyDef = (def, refs) => {
|
|
1859
|
+
return parseDef(def.innerType._def, refs);
|
|
1860
|
+
};
|
|
1861
|
+
var selectParser = (def, typeName, refs) => {
|
|
1862
|
+
switch (typeName) {
|
|
1863
|
+
case ZodFirstPartyTypeKind3.ZodString:
|
|
1864
|
+
return parseStringDef(def, refs);
|
|
1865
|
+
case ZodFirstPartyTypeKind3.ZodNumber:
|
|
1866
|
+
return parseNumberDef(def);
|
|
1867
|
+
case ZodFirstPartyTypeKind3.ZodObject:
|
|
1868
|
+
return parseObjectDef(def, refs);
|
|
1869
|
+
case ZodFirstPartyTypeKind3.ZodBigInt:
|
|
1870
|
+
return parseBigintDef(def);
|
|
1871
|
+
case ZodFirstPartyTypeKind3.ZodBoolean:
|
|
1872
|
+
return parseBooleanDef();
|
|
1873
|
+
case ZodFirstPartyTypeKind3.ZodDate:
|
|
1874
|
+
return parseDateDef(def, refs);
|
|
1875
|
+
case ZodFirstPartyTypeKind3.ZodUndefined:
|
|
1876
|
+
return parseUndefinedDef();
|
|
1877
|
+
case ZodFirstPartyTypeKind3.ZodNull:
|
|
1878
|
+
return parseNullDef();
|
|
1879
|
+
case ZodFirstPartyTypeKind3.ZodArray:
|
|
1880
|
+
return parseArrayDef(def, refs);
|
|
1881
|
+
case ZodFirstPartyTypeKind3.ZodUnion:
|
|
1882
|
+
case ZodFirstPartyTypeKind3.ZodDiscriminatedUnion:
|
|
1883
|
+
return parseUnionDef(def, refs);
|
|
1884
|
+
case ZodFirstPartyTypeKind3.ZodIntersection:
|
|
1885
|
+
return parseIntersectionDef(def, refs);
|
|
1886
|
+
case ZodFirstPartyTypeKind3.ZodTuple:
|
|
1887
|
+
return parseTupleDef(def, refs);
|
|
1888
|
+
case ZodFirstPartyTypeKind3.ZodRecord:
|
|
1889
|
+
return parseRecordDef(def, refs);
|
|
1890
|
+
case ZodFirstPartyTypeKind3.ZodLiteral:
|
|
1891
|
+
return parseLiteralDef(def);
|
|
1892
|
+
case ZodFirstPartyTypeKind3.ZodEnum:
|
|
1893
|
+
return parseEnumDef(def);
|
|
1894
|
+
case ZodFirstPartyTypeKind3.ZodNativeEnum:
|
|
1895
|
+
return parseNativeEnumDef(def);
|
|
1896
|
+
case ZodFirstPartyTypeKind3.ZodNullable:
|
|
1897
|
+
return parseNullableDef(def, refs);
|
|
1898
|
+
case ZodFirstPartyTypeKind3.ZodOptional:
|
|
1899
|
+
return parseOptionalDef(def, refs);
|
|
1900
|
+
case ZodFirstPartyTypeKind3.ZodMap:
|
|
1901
|
+
return parseMapDef(def, refs);
|
|
1902
|
+
case ZodFirstPartyTypeKind3.ZodSet:
|
|
1903
|
+
return parseSetDef(def, refs);
|
|
1904
|
+
case ZodFirstPartyTypeKind3.ZodLazy:
|
|
1905
|
+
return () => def.getter()._def;
|
|
1906
|
+
case ZodFirstPartyTypeKind3.ZodPromise:
|
|
1907
|
+
return parsePromiseDef(def, refs);
|
|
1908
|
+
case ZodFirstPartyTypeKind3.ZodNaN:
|
|
1909
|
+
case ZodFirstPartyTypeKind3.ZodNever:
|
|
1910
|
+
return parseNeverDef();
|
|
1911
|
+
case ZodFirstPartyTypeKind3.ZodEffects:
|
|
1912
|
+
return parseEffectsDef(def, refs);
|
|
1913
|
+
case ZodFirstPartyTypeKind3.ZodAny:
|
|
1914
|
+
return parseAnyDef();
|
|
1915
|
+
case ZodFirstPartyTypeKind3.ZodUnknown:
|
|
1916
|
+
return parseUnknownDef();
|
|
1917
|
+
case ZodFirstPartyTypeKind3.ZodDefault:
|
|
1918
|
+
return parseDefaultDef(def, refs);
|
|
1919
|
+
case ZodFirstPartyTypeKind3.ZodBranded:
|
|
1920
|
+
return parseBrandedDef(def, refs);
|
|
1921
|
+
case ZodFirstPartyTypeKind3.ZodReadonly:
|
|
1922
|
+
return parseReadonlyDef(def, refs);
|
|
1923
|
+
case ZodFirstPartyTypeKind3.ZodCatch:
|
|
1924
|
+
return parseCatchDef(def, refs);
|
|
1925
|
+
case ZodFirstPartyTypeKind3.ZodPipeline:
|
|
1926
|
+
return parsePipelineDef(def, refs);
|
|
1927
|
+
case ZodFirstPartyTypeKind3.ZodFunction:
|
|
1928
|
+
case ZodFirstPartyTypeKind3.ZodVoid:
|
|
1929
|
+
case ZodFirstPartyTypeKind3.ZodSymbol:
|
|
1930
|
+
return void 0;
|
|
1931
|
+
default:
|
|
1932
|
+
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
1933
|
+
}
|
|
1934
|
+
};
|
|
1935
|
+
var getRelativePath = (pathA, pathB) => {
|
|
1936
|
+
let i = 0;
|
|
1937
|
+
for (; i < pathA.length && i < pathB.length; i++) {
|
|
1938
|
+
if (pathA[i] !== pathB[i]) break;
|
|
1939
|
+
}
|
|
1940
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
1941
|
+
};
|
|
1942
|
+
function parseDef(def, refs, forceResolution = false) {
|
|
1943
|
+
var _a23;
|
|
1944
|
+
const seenItem = refs.seen.get(def);
|
|
1945
|
+
if (refs.override) {
|
|
1946
|
+
const overrideResult = (_a23 = refs.override) == null ? void 0 : _a23.call(
|
|
1947
|
+
refs,
|
|
1948
|
+
def,
|
|
1949
|
+
refs,
|
|
1950
|
+
seenItem,
|
|
1951
|
+
forceResolution
|
|
1952
|
+
);
|
|
1953
|
+
if (overrideResult !== ignoreOverride) {
|
|
1954
|
+
return overrideResult;
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
if (seenItem && !forceResolution) {
|
|
1958
|
+
const seenSchema = get$ref(seenItem, refs);
|
|
1959
|
+
if (seenSchema !== void 0) {
|
|
1960
|
+
return seenSchema;
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
1964
|
+
refs.seen.set(def, newItem);
|
|
1965
|
+
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
1966
|
+
const jsonSchema2 = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
1967
|
+
if (jsonSchema2) {
|
|
1968
|
+
addMeta(def, refs, jsonSchema2);
|
|
1969
|
+
}
|
|
1970
|
+
if (refs.postProcess) {
|
|
1971
|
+
const postProcessResult = refs.postProcess(jsonSchema2, def, refs);
|
|
1972
|
+
newItem.jsonSchema = jsonSchema2;
|
|
1973
|
+
return postProcessResult;
|
|
1974
|
+
}
|
|
1975
|
+
newItem.jsonSchema = jsonSchema2;
|
|
1976
|
+
return jsonSchema2;
|
|
1977
|
+
}
|
|
1978
|
+
var get$ref = (item, refs) => {
|
|
1979
|
+
switch (refs.$refStrategy) {
|
|
1980
|
+
case "root":
|
|
1981
|
+
return { $ref: item.path.join("/") };
|
|
1982
|
+
case "relative":
|
|
1983
|
+
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
1984
|
+
case "none":
|
|
1985
|
+
case "seen": {
|
|
1986
|
+
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
1987
|
+
console.warn(
|
|
1988
|
+
`Recursive reference detected at ${refs.currentPath.join(
|
|
1989
|
+
"/"
|
|
1990
|
+
)}! Defaulting to any`
|
|
1991
|
+
);
|
|
1992
|
+
return parseAnyDef();
|
|
1993
|
+
}
|
|
1994
|
+
return refs.$refStrategy === "seen" ? parseAnyDef() : void 0;
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
};
|
|
1998
|
+
var addMeta = (def, refs, jsonSchema2) => {
|
|
1999
|
+
if (def.description) {
|
|
2000
|
+
jsonSchema2.description = def.description;
|
|
2001
|
+
}
|
|
2002
|
+
return jsonSchema2;
|
|
2003
|
+
};
|
|
2004
|
+
var getRefs = (options) => {
|
|
2005
|
+
const _options = getDefaultOptions(options);
|
|
2006
|
+
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
2007
|
+
return {
|
|
2008
|
+
..._options,
|
|
2009
|
+
currentPath,
|
|
2010
|
+
propertyPath: void 0,
|
|
2011
|
+
seen: new Map(
|
|
2012
|
+
Object.entries(_options.definitions).map(([name23, def]) => [
|
|
2013
|
+
def._def,
|
|
2014
|
+
{
|
|
2015
|
+
def: def._def,
|
|
2016
|
+
path: [..._options.basePath, _options.definitionPath, name23],
|
|
2017
|
+
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
2018
|
+
jsonSchema: void 0
|
|
2019
|
+
}
|
|
2020
|
+
])
|
|
2021
|
+
)
|
|
2022
|
+
};
|
|
2023
|
+
};
|
|
2024
|
+
var zod3ToJsonSchema = (schema, options) => {
|
|
2025
|
+
var _a23;
|
|
2026
|
+
const refs = getRefs(options);
|
|
2027
|
+
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
|
|
2028
|
+
(acc, [name33, schema2]) => {
|
|
2029
|
+
var _a33;
|
|
2030
|
+
return {
|
|
2031
|
+
...acc,
|
|
2032
|
+
[name33]: (_a33 = parseDef(
|
|
2033
|
+
schema2._def,
|
|
2034
|
+
{
|
|
2035
|
+
...refs,
|
|
2036
|
+
currentPath: [...refs.basePath, refs.definitionPath, name33]
|
|
2037
|
+
},
|
|
2038
|
+
true
|
|
2039
|
+
)) != null ? _a33 : parseAnyDef()
|
|
2040
|
+
};
|
|
2041
|
+
},
|
|
2042
|
+
{}
|
|
2043
|
+
) : void 0;
|
|
2044
|
+
const name23 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
2045
|
+
const main = (_a23 = parseDef(
|
|
2046
|
+
schema._def,
|
|
2047
|
+
name23 === void 0 ? refs : {
|
|
2048
|
+
...refs,
|
|
2049
|
+
currentPath: [...refs.basePath, refs.definitionPath, name23]
|
|
2050
|
+
},
|
|
2051
|
+
false
|
|
2052
|
+
)) != null ? _a23 : parseAnyDef();
|
|
2053
|
+
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
2054
|
+
if (title !== void 0) {
|
|
2055
|
+
main.title = title;
|
|
2056
|
+
}
|
|
2057
|
+
const combined = name23 === void 0 ? definitions ? {
|
|
2058
|
+
...main,
|
|
2059
|
+
[refs.definitionPath]: definitions
|
|
2060
|
+
} : main : {
|
|
2061
|
+
$ref: [
|
|
2062
|
+
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
2063
|
+
refs.definitionPath,
|
|
2064
|
+
name23
|
|
2065
|
+
].join("/"),
|
|
2066
|
+
[refs.definitionPath]: {
|
|
2067
|
+
...definitions,
|
|
2068
|
+
[name23]: main
|
|
2069
|
+
}
|
|
2070
|
+
};
|
|
2071
|
+
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
2072
|
+
return combined;
|
|
2073
|
+
};
|
|
2074
|
+
var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
2075
|
+
function lazySchema(createSchema) {
|
|
2076
|
+
let schema;
|
|
2077
|
+
return () => {
|
|
2078
|
+
if (schema == null) {
|
|
2079
|
+
schema = createSchema();
|
|
2080
|
+
}
|
|
2081
|
+
return schema;
|
|
2082
|
+
};
|
|
2083
|
+
}
|
|
2084
|
+
function jsonSchema(jsonSchema2, {
|
|
2085
|
+
validate
|
|
2086
|
+
} = {}) {
|
|
2087
|
+
return {
|
|
2088
|
+
[schemaSymbol]: true,
|
|
2089
|
+
_type: void 0,
|
|
2090
|
+
// should never be used directly
|
|
2091
|
+
get jsonSchema() {
|
|
2092
|
+
if (typeof jsonSchema2 === "function") {
|
|
2093
|
+
jsonSchema2 = jsonSchema2();
|
|
2094
|
+
}
|
|
2095
|
+
return jsonSchema2;
|
|
2096
|
+
},
|
|
2097
|
+
validate
|
|
2098
|
+
};
|
|
2099
|
+
}
|
|
2100
|
+
function isSchema(value) {
|
|
2101
|
+
return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
|
|
2102
|
+
}
|
|
2103
|
+
function asSchema(schema) {
|
|
2104
|
+
return schema == null ? jsonSchema({ properties: {}, additionalProperties: false }) : isSchema(schema) ? schema : "~standard" in schema ? schema["~standard"].vendor === "zod" ? zodSchema(schema) : standardSchema(schema) : schema();
|
|
2105
|
+
}
|
|
2106
|
+
function standardSchema(standardSchema2) {
|
|
2107
|
+
return jsonSchema(
|
|
2108
|
+
() => addAdditionalPropertiesToJsonSchema(
|
|
2109
|
+
standardSchema2["~standard"].jsonSchema.input({
|
|
2110
|
+
target: "draft-07"
|
|
2111
|
+
})
|
|
2112
|
+
),
|
|
2113
|
+
{
|
|
2114
|
+
validate: async (value) => {
|
|
2115
|
+
const result = await standardSchema2["~standard"].validate(value);
|
|
2116
|
+
return "value" in result ? { success: true, value: result.value } : {
|
|
2117
|
+
success: false,
|
|
2118
|
+
error: new TypeValidationError({
|
|
2119
|
+
value,
|
|
2120
|
+
cause: result.issues
|
|
2121
|
+
})
|
|
2122
|
+
};
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
);
|
|
2126
|
+
}
|
|
2127
|
+
function zod3Schema(zodSchema2, options) {
|
|
2128
|
+
var _a23;
|
|
2129
|
+
const useReferences = (_a23 = options == null ? void 0 : options.useReferences) != null ? _a23 : false;
|
|
2130
|
+
return jsonSchema(
|
|
2131
|
+
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
2132
|
+
() => zod3ToJsonSchema(zodSchema2, {
|
|
2133
|
+
$refStrategy: useReferences ? "root" : "none"
|
|
2134
|
+
}),
|
|
2135
|
+
{
|
|
2136
|
+
validate: async (value) => {
|
|
2137
|
+
const result = await zodSchema2.safeParseAsync(value);
|
|
2138
|
+
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
);
|
|
2142
|
+
}
|
|
2143
|
+
function zod4Schema(zodSchema2, options) {
|
|
2144
|
+
var _a23;
|
|
2145
|
+
const useReferences = (_a23 = options == null ? void 0 : options.useReferences) != null ? _a23 : false;
|
|
2146
|
+
return jsonSchema(
|
|
2147
|
+
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
2148
|
+
() => addAdditionalPropertiesToJsonSchema(
|
|
2149
|
+
z4.toJSONSchema(zodSchema2, {
|
|
2150
|
+
target: "draft-7",
|
|
2151
|
+
io: "input",
|
|
2152
|
+
reused: useReferences ? "ref" : "inline"
|
|
2153
|
+
})
|
|
2154
|
+
),
|
|
2155
|
+
{
|
|
2156
|
+
validate: async (value) => {
|
|
2157
|
+
const result = await z4.safeParseAsync(zodSchema2, value);
|
|
2158
|
+
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
);
|
|
2162
|
+
}
|
|
2163
|
+
function isZod4Schema(zodSchema2) {
|
|
2164
|
+
return "_zod" in zodSchema2;
|
|
2165
|
+
}
|
|
2166
|
+
function zodSchema(zodSchema2, options) {
|
|
2167
|
+
if (isZod4Schema(zodSchema2)) {
|
|
2168
|
+
return zod4Schema(zodSchema2, options);
|
|
2169
|
+
} else {
|
|
2170
|
+
return zod3Schema(zodSchema2, options);
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
async function safeValidateTypes({
|
|
2174
|
+
value,
|
|
2175
|
+
schema,
|
|
2176
|
+
context
|
|
2177
|
+
}) {
|
|
2178
|
+
const actualSchema = asSchema(schema);
|
|
2179
|
+
try {
|
|
2180
|
+
if (actualSchema.validate == null) {
|
|
2181
|
+
return { success: true, value, rawValue: value };
|
|
2182
|
+
}
|
|
2183
|
+
const result = await actualSchema.validate(value);
|
|
2184
|
+
if (result.success) {
|
|
2185
|
+
return { success: true, value: result.value, rawValue: value };
|
|
2186
|
+
}
|
|
2187
|
+
return {
|
|
2188
|
+
success: false,
|
|
2189
|
+
error: TypeValidationError.wrap({ value, cause: result.error, context }),
|
|
2190
|
+
rawValue: value
|
|
2191
|
+
};
|
|
2192
|
+
} catch (error) {
|
|
2193
|
+
return {
|
|
2194
|
+
success: false,
|
|
2195
|
+
error: TypeValidationError.wrap({ value, cause: error, context }),
|
|
2196
|
+
rawValue: value
|
|
2197
|
+
};
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
async function safeParseJSON({
|
|
2201
|
+
text: text2,
|
|
2202
|
+
schema
|
|
2203
|
+
}) {
|
|
2204
|
+
try {
|
|
2205
|
+
const value = secureJsonParse(text2);
|
|
2206
|
+
if (schema == null) {
|
|
2207
|
+
return { success: true, value, rawValue: value };
|
|
2208
|
+
}
|
|
2209
|
+
return await safeValidateTypes({ value, schema });
|
|
2210
|
+
} catch (error) {
|
|
2211
|
+
return {
|
|
2212
|
+
success: false,
|
|
2213
|
+
error: JSONParseError.isInstance(error) ? error : new JSONParseError({ text: text2, cause: error }),
|
|
2214
|
+
rawValue: void 0
|
|
2215
|
+
};
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
function parseJsonEventStream({
|
|
2219
|
+
stream,
|
|
2220
|
+
schema
|
|
2221
|
+
}) {
|
|
2222
|
+
return stream.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream()).pipeThrough(
|
|
2223
|
+
new TransformStream({
|
|
2224
|
+
async transform({ data }, controller) {
|
|
2225
|
+
if (data === "[DONE]") {
|
|
2226
|
+
return;
|
|
2227
|
+
}
|
|
2228
|
+
controller.enqueue(await safeParseJSON({ text: data, schema }));
|
|
2229
|
+
}
|
|
2230
|
+
})
|
|
2231
|
+
);
|
|
2232
|
+
}
|
|
2233
|
+
async function resolve(value) {
|
|
2234
|
+
if (typeof value === "function") {
|
|
2235
|
+
value = value();
|
|
2236
|
+
}
|
|
2237
|
+
return Promise.resolve(value);
|
|
2238
|
+
}
|
|
2239
|
+
var textDecoder = new TextDecoder();
|
|
2240
|
+
|
|
2241
|
+
// ../../node_modules/.pnpm/ai@6.0.217_zod@4.4.3/node_modules/ai/dist/index.mjs
|
|
2242
|
+
import { z } from "zod/v4";
|
|
2243
|
+
import { z as z6 } from "zod/v4";
|
|
2244
|
+
import { z as z5 } from "zod/v4";
|
|
2245
|
+
import { z as z3 } from "zod/v4";
|
|
2246
|
+
import { z as z2 } from "zod/v4";
|
|
2247
|
+
import { z as z42 } from "zod/v4";
|
|
2248
|
+
import { z as z7 } from "zod/v4";
|
|
2249
|
+
import { z as z8 } from "zod/v4";
|
|
2250
|
+
var __defProp = Object.defineProperty;
|
|
2251
|
+
var __export = (target, all) => {
|
|
2252
|
+
for (var name222 in all)
|
|
2253
|
+
__defProp(target, name222, { get: all[name222], enumerable: true });
|
|
2254
|
+
};
|
|
2255
|
+
var name15 = "AI_InvalidArgumentError";
|
|
2256
|
+
var marker16 = `vercel.ai.error.${name15}`;
|
|
2257
|
+
var symbol16 = Symbol.for(marker16);
|
|
2258
|
+
var _a16;
|
|
2259
|
+
_a16 = symbol16;
|
|
2260
|
+
var name22 = "AI_InvalidStreamPartError";
|
|
2261
|
+
var marker22 = `vercel.ai.error.${name22}`;
|
|
2262
|
+
var symbol22 = Symbol.for(marker22);
|
|
2263
|
+
var _a22;
|
|
2264
|
+
_a22 = symbol22;
|
|
2265
|
+
var name32 = "AI_InvalidToolApprovalError";
|
|
2266
|
+
var marker32 = `vercel.ai.error.${name32}`;
|
|
2267
|
+
var symbol32 = Symbol.for(marker32);
|
|
2268
|
+
var _a32;
|
|
2269
|
+
_a32 = symbol32;
|
|
2270
|
+
var name42 = "AI_InvalidToolApprovalSignatureError";
|
|
2271
|
+
var marker42 = `vercel.ai.error.${name42}`;
|
|
2272
|
+
var symbol42 = Symbol.for(marker42);
|
|
2273
|
+
var _a42;
|
|
2274
|
+
_a42 = symbol42;
|
|
2275
|
+
var name52 = "AI_InvalidToolInputError";
|
|
2276
|
+
var marker52 = `vercel.ai.error.${name52}`;
|
|
2277
|
+
var symbol52 = Symbol.for(marker52);
|
|
2278
|
+
var _a52;
|
|
2279
|
+
_a52 = symbol52;
|
|
2280
|
+
var name62 = "AI_ToolCallNotFoundForApprovalError";
|
|
2281
|
+
var marker62 = `vercel.ai.error.${name62}`;
|
|
2282
|
+
var symbol62 = Symbol.for(marker62);
|
|
2283
|
+
var _a62;
|
|
2284
|
+
_a62 = symbol62;
|
|
2285
|
+
var name72 = "AI_MissingToolResultsError";
|
|
2286
|
+
var marker72 = `vercel.ai.error.${name72}`;
|
|
2287
|
+
var symbol72 = Symbol.for(marker72);
|
|
2288
|
+
var _a72;
|
|
2289
|
+
_a72 = symbol72;
|
|
2290
|
+
var name82 = "AI_NoImageGeneratedError";
|
|
2291
|
+
var marker82 = `vercel.ai.error.${name82}`;
|
|
2292
|
+
var symbol82 = Symbol.for(marker82);
|
|
2293
|
+
var _a82;
|
|
2294
|
+
_a82 = symbol82;
|
|
2295
|
+
var name92 = "AI_NoObjectGeneratedError";
|
|
2296
|
+
var marker92 = `vercel.ai.error.${name92}`;
|
|
2297
|
+
var symbol92 = Symbol.for(marker92);
|
|
2298
|
+
var _a92;
|
|
2299
|
+
var NoObjectGeneratedError = class extends AISDKError {
|
|
2300
|
+
constructor({
|
|
2301
|
+
message = "No object generated.",
|
|
2302
|
+
cause,
|
|
2303
|
+
text: text2,
|
|
2304
|
+
response,
|
|
2305
|
+
usage,
|
|
2306
|
+
finishReason
|
|
2307
|
+
}) {
|
|
2308
|
+
super({ name: name92, message, cause });
|
|
2309
|
+
this[_a92] = true;
|
|
2310
|
+
this.text = text2;
|
|
2311
|
+
this.response = response;
|
|
2312
|
+
this.usage = usage;
|
|
2313
|
+
this.finishReason = finishReason;
|
|
2314
|
+
}
|
|
2315
|
+
static isInstance(error) {
|
|
2316
|
+
return AISDKError.hasMarker(error, marker92);
|
|
2317
|
+
}
|
|
2318
|
+
};
|
|
2319
|
+
_a92 = symbol92;
|
|
2320
|
+
var name102 = "AI_NoOutputGeneratedError";
|
|
2321
|
+
var marker102 = `vercel.ai.error.${name102}`;
|
|
2322
|
+
var symbol102 = Symbol.for(marker102);
|
|
2323
|
+
var _a102;
|
|
2324
|
+
_a102 = symbol102;
|
|
2325
|
+
var name112 = "AI_NoSpeechGeneratedError";
|
|
2326
|
+
var marker112 = `vercel.ai.error.${name112}`;
|
|
2327
|
+
var symbol112 = Symbol.for(marker112);
|
|
2328
|
+
var _a112;
|
|
2329
|
+
_a112 = symbol112;
|
|
2330
|
+
var name122 = "AI_NoTranscriptGeneratedError";
|
|
2331
|
+
var marker122 = `vercel.ai.error.${name122}`;
|
|
2332
|
+
var symbol122 = Symbol.for(marker122);
|
|
2333
|
+
var _a122;
|
|
2334
|
+
_a122 = symbol122;
|
|
2335
|
+
var name132 = "AI_NoVideoGeneratedError";
|
|
2336
|
+
var marker132 = `vercel.ai.error.${name132}`;
|
|
2337
|
+
var symbol132 = Symbol.for(marker132);
|
|
2338
|
+
var _a132;
|
|
2339
|
+
_a132 = symbol132;
|
|
2340
|
+
var name142 = "AI_NoSuchToolError";
|
|
2341
|
+
var marker142 = `vercel.ai.error.${name142}`;
|
|
2342
|
+
var symbol142 = Symbol.for(marker142);
|
|
2343
|
+
var _a142;
|
|
2344
|
+
_a142 = symbol142;
|
|
2345
|
+
var name152 = "AI_ToolCallRepairError";
|
|
2346
|
+
var marker152 = `vercel.ai.error.${name152}`;
|
|
2347
|
+
var symbol152 = Symbol.for(marker152);
|
|
2348
|
+
var _a152;
|
|
2349
|
+
_a152 = symbol152;
|
|
2350
|
+
var name16 = "AI_UIMessageStreamError";
|
|
2351
|
+
var marker162 = `vercel.ai.error.${name16}`;
|
|
2352
|
+
var symbol162 = Symbol.for(marker162);
|
|
2353
|
+
var _a162;
|
|
2354
|
+
_a162 = symbol162;
|
|
2355
|
+
var name17 = "AI_InvalidDataContentError";
|
|
2356
|
+
var marker17 = `vercel.ai.error.${name17}`;
|
|
2357
|
+
var symbol17 = Symbol.for(marker17);
|
|
2358
|
+
var _a17;
|
|
2359
|
+
_a17 = symbol17;
|
|
2360
|
+
var name18 = "AI_InvalidMessageRoleError";
|
|
2361
|
+
var marker18 = `vercel.ai.error.${name18}`;
|
|
2362
|
+
var symbol18 = Symbol.for(marker18);
|
|
2363
|
+
var _a18;
|
|
2364
|
+
_a18 = symbol18;
|
|
2365
|
+
var name19 = "AI_MessageConversionError";
|
|
2366
|
+
var marker19 = `vercel.ai.error.${name19}`;
|
|
2367
|
+
var symbol19 = Symbol.for(marker19);
|
|
2368
|
+
var _a19;
|
|
2369
|
+
_a19 = symbol19;
|
|
2370
|
+
var name20 = "AI_RetryError";
|
|
2371
|
+
var marker20 = `vercel.ai.error.${name20}`;
|
|
2372
|
+
var symbol20 = Symbol.for(marker20);
|
|
2373
|
+
var _a20;
|
|
2374
|
+
_a20 = symbol20;
|
|
2375
|
+
var VERSION = true ? "6.0.217" : "0.0.0-test";
|
|
2376
|
+
var download = async ({
|
|
2377
|
+
url,
|
|
2378
|
+
maxBytes,
|
|
2379
|
+
abortSignal
|
|
2380
|
+
}) => {
|
|
2381
|
+
var _a222;
|
|
2382
|
+
const urlText = url.toString();
|
|
2383
|
+
try {
|
|
2384
|
+
const headers = withUserAgentSuffix(
|
|
2385
|
+
{},
|
|
2386
|
+
`ai-sdk/${VERSION}`,
|
|
2387
|
+
getRuntimeEnvironmentUserAgent()
|
|
2388
|
+
);
|
|
2389
|
+
const response = await fetchWithValidatedRedirects({
|
|
2390
|
+
url: urlText,
|
|
2391
|
+
headers,
|
|
2392
|
+
abortSignal
|
|
2393
|
+
});
|
|
2394
|
+
if (!response.ok) {
|
|
2395
|
+
await cancelResponseBody(response);
|
|
2396
|
+
throw new DownloadError({
|
|
2397
|
+
url: urlText,
|
|
2398
|
+
statusCode: response.status,
|
|
2399
|
+
statusText: response.statusText
|
|
2400
|
+
});
|
|
2401
|
+
}
|
|
2402
|
+
const data = await readResponseWithSizeLimit({
|
|
2403
|
+
response,
|
|
2404
|
+
url: urlText,
|
|
2405
|
+
maxBytes: maxBytes != null ? maxBytes : DEFAULT_MAX_DOWNLOAD_SIZE
|
|
2406
|
+
});
|
|
2407
|
+
return {
|
|
2408
|
+
data,
|
|
2409
|
+
mediaType: (_a222 = response.headers.get("content-type")) != null ? _a222 : void 0
|
|
2410
|
+
};
|
|
2411
|
+
} catch (error) {
|
|
2412
|
+
if (DownloadError.isInstance(error)) {
|
|
2413
|
+
throw error;
|
|
2414
|
+
}
|
|
2415
|
+
throw new DownloadError({ url: urlText, cause: error });
|
|
2416
|
+
}
|
|
2417
|
+
};
|
|
2418
|
+
var dataContentSchema = z.union([
|
|
2419
|
+
z.string(),
|
|
2420
|
+
z.instanceof(Uint8Array),
|
|
2421
|
+
z.instanceof(ArrayBuffer),
|
|
2422
|
+
z.custom(
|
|
2423
|
+
// Buffer might not be available in some environments such as CloudFlare:
|
|
2424
|
+
(value) => {
|
|
2425
|
+
var _a222, _b16;
|
|
2426
|
+
return (_b16 = (_a222 = globalThis.Buffer) == null ? void 0 : _a222.isBuffer(value)) != null ? _b16 : false;
|
|
2427
|
+
},
|
|
2428
|
+
{ message: "Must be a Buffer" }
|
|
2429
|
+
)
|
|
2430
|
+
]);
|
|
2431
|
+
var jsonValueSchema = z2.lazy(
|
|
2432
|
+
() => z2.union([
|
|
2433
|
+
z2.null(),
|
|
2434
|
+
z2.string(),
|
|
2435
|
+
z2.number(),
|
|
2436
|
+
z2.boolean(),
|
|
2437
|
+
z2.record(z2.string(), jsonValueSchema.optional()),
|
|
2438
|
+
z2.array(jsonValueSchema)
|
|
2439
|
+
])
|
|
2440
|
+
);
|
|
2441
|
+
var providerMetadataSchema = z3.record(
|
|
2442
|
+
z3.string(),
|
|
2443
|
+
z3.record(z3.string(), jsonValueSchema.optional())
|
|
2444
|
+
);
|
|
2445
|
+
var textPartSchema = z42.object({
|
|
2446
|
+
type: z42.literal("text"),
|
|
2447
|
+
text: z42.string(),
|
|
2448
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2449
|
+
});
|
|
2450
|
+
var imagePartSchema = z42.object({
|
|
2451
|
+
type: z42.literal("image"),
|
|
2452
|
+
image: z42.union([dataContentSchema, z42.instanceof(URL)]),
|
|
2453
|
+
mediaType: z42.string().optional(),
|
|
2454
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2455
|
+
});
|
|
2456
|
+
var filePartSchema = z42.object({
|
|
2457
|
+
type: z42.literal("file"),
|
|
2458
|
+
data: z42.union([dataContentSchema, z42.instanceof(URL)]),
|
|
2459
|
+
filename: z42.string().optional(),
|
|
2460
|
+
mediaType: z42.string(),
|
|
2461
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2462
|
+
});
|
|
2463
|
+
var reasoningPartSchema = z42.object({
|
|
2464
|
+
type: z42.literal("reasoning"),
|
|
2465
|
+
text: z42.string(),
|
|
2466
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2467
|
+
});
|
|
2468
|
+
var toolCallPartSchema = z42.object({
|
|
2469
|
+
type: z42.literal("tool-call"),
|
|
2470
|
+
toolCallId: z42.string(),
|
|
2471
|
+
toolName: z42.string(),
|
|
2472
|
+
input: z42.unknown(),
|
|
2473
|
+
providerOptions: providerMetadataSchema.optional(),
|
|
2474
|
+
providerExecuted: z42.boolean().optional()
|
|
2475
|
+
});
|
|
2476
|
+
var outputSchema = z42.discriminatedUnion(
|
|
2477
|
+
"type",
|
|
2478
|
+
[
|
|
2479
|
+
z42.object({
|
|
2480
|
+
type: z42.literal("text"),
|
|
2481
|
+
value: z42.string(),
|
|
2482
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2483
|
+
}),
|
|
2484
|
+
z42.object({
|
|
2485
|
+
type: z42.literal("json"),
|
|
2486
|
+
value: jsonValueSchema,
|
|
2487
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2488
|
+
}),
|
|
2489
|
+
z42.object({
|
|
2490
|
+
type: z42.literal("execution-denied"),
|
|
2491
|
+
reason: z42.string().optional(),
|
|
2492
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2493
|
+
}),
|
|
2494
|
+
z42.object({
|
|
2495
|
+
type: z42.literal("error-text"),
|
|
2496
|
+
value: z42.string(),
|
|
2497
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2498
|
+
}),
|
|
2499
|
+
z42.object({
|
|
2500
|
+
type: z42.literal("error-json"),
|
|
2501
|
+
value: jsonValueSchema,
|
|
2502
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2503
|
+
}),
|
|
2504
|
+
z42.object({
|
|
2505
|
+
type: z42.literal("content"),
|
|
2506
|
+
value: z42.array(
|
|
2507
|
+
z42.union([
|
|
2508
|
+
z42.object({
|
|
2509
|
+
type: z42.literal("text"),
|
|
2510
|
+
text: z42.string(),
|
|
2511
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2512
|
+
}),
|
|
2513
|
+
z42.object({
|
|
2514
|
+
type: z42.literal("media"),
|
|
2515
|
+
data: z42.string(),
|
|
2516
|
+
mediaType: z42.string()
|
|
2517
|
+
}),
|
|
2518
|
+
z42.object({
|
|
2519
|
+
type: z42.literal("file-data"),
|
|
2520
|
+
data: z42.string(),
|
|
2521
|
+
mediaType: z42.string(),
|
|
2522
|
+
filename: z42.string().optional(),
|
|
2523
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2524
|
+
}),
|
|
2525
|
+
z42.object({
|
|
2526
|
+
type: z42.literal("file-url"),
|
|
2527
|
+
url: z42.string(),
|
|
2528
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2529
|
+
}),
|
|
2530
|
+
z42.object({
|
|
2531
|
+
type: z42.literal("file-id"),
|
|
2532
|
+
fileId: z42.union([z42.string(), z42.record(z42.string(), z42.string())]),
|
|
2533
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2534
|
+
}),
|
|
2535
|
+
z42.object({
|
|
2536
|
+
type: z42.literal("image-data"),
|
|
2537
|
+
data: z42.string(),
|
|
2538
|
+
mediaType: z42.string(),
|
|
2539
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2540
|
+
}),
|
|
2541
|
+
z42.object({
|
|
2542
|
+
type: z42.literal("image-url"),
|
|
2543
|
+
url: z42.string(),
|
|
2544
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2545
|
+
}),
|
|
2546
|
+
z42.object({
|
|
2547
|
+
type: z42.literal("image-file-id"),
|
|
2548
|
+
fileId: z42.union([z42.string(), z42.record(z42.string(), z42.string())]),
|
|
2549
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2550
|
+
}),
|
|
2551
|
+
z42.object({
|
|
2552
|
+
type: z42.literal("custom"),
|
|
2553
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2554
|
+
})
|
|
2555
|
+
])
|
|
2556
|
+
)
|
|
2557
|
+
})
|
|
2558
|
+
]
|
|
2559
|
+
);
|
|
2560
|
+
var toolResultPartSchema = z42.object({
|
|
2561
|
+
type: z42.literal("tool-result"),
|
|
2562
|
+
toolCallId: z42.string(),
|
|
2563
|
+
toolName: z42.string(),
|
|
2564
|
+
output: outputSchema,
|
|
2565
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2566
|
+
});
|
|
2567
|
+
var toolApprovalRequestSchema = z42.object({
|
|
2568
|
+
type: z42.literal("tool-approval-request"),
|
|
2569
|
+
approvalId: z42.string(),
|
|
2570
|
+
toolCallId: z42.string()
|
|
2571
|
+
});
|
|
2572
|
+
var toolApprovalResponseSchema = z42.object({
|
|
2573
|
+
type: z42.literal("tool-approval-response"),
|
|
2574
|
+
approvalId: z42.string(),
|
|
2575
|
+
approved: z42.boolean(),
|
|
2576
|
+
reason: z42.string().optional()
|
|
2577
|
+
});
|
|
2578
|
+
var systemModelMessageSchema = z5.object(
|
|
2579
|
+
{
|
|
2580
|
+
role: z5.literal("system"),
|
|
2581
|
+
content: z5.string(),
|
|
2582
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2583
|
+
}
|
|
2584
|
+
);
|
|
2585
|
+
var userModelMessageSchema = z5.object({
|
|
2586
|
+
role: z5.literal("user"),
|
|
2587
|
+
content: z5.union([
|
|
2588
|
+
z5.string(),
|
|
2589
|
+
z5.array(z5.union([textPartSchema, imagePartSchema, filePartSchema]))
|
|
2590
|
+
]),
|
|
2591
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2592
|
+
});
|
|
2593
|
+
var assistantModelMessageSchema = z5.object({
|
|
2594
|
+
role: z5.literal("assistant"),
|
|
2595
|
+
content: z5.union([
|
|
2596
|
+
z5.string(),
|
|
2597
|
+
z5.array(
|
|
2598
|
+
z5.union([
|
|
2599
|
+
textPartSchema,
|
|
2600
|
+
filePartSchema,
|
|
2601
|
+
reasoningPartSchema,
|
|
2602
|
+
toolCallPartSchema,
|
|
2603
|
+
toolResultPartSchema,
|
|
2604
|
+
toolApprovalRequestSchema
|
|
2605
|
+
])
|
|
2606
|
+
)
|
|
2607
|
+
]),
|
|
2608
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2609
|
+
});
|
|
2610
|
+
var toolModelMessageSchema = z5.object({
|
|
2611
|
+
role: z5.literal("tool"),
|
|
2612
|
+
content: z5.array(z5.union([toolResultPartSchema, toolApprovalResponseSchema])),
|
|
2613
|
+
providerOptions: providerMetadataSchema.optional()
|
|
2614
|
+
});
|
|
2615
|
+
var modelMessageSchema = z5.union([
|
|
2616
|
+
systemModelMessageSchema,
|
|
2617
|
+
userModelMessageSchema,
|
|
2618
|
+
assistantModelMessageSchema,
|
|
2619
|
+
toolModelMessageSchema
|
|
2620
|
+
]);
|
|
2621
|
+
var encoder = new TextEncoder();
|
|
2622
|
+
var output_exports = {};
|
|
2623
|
+
__export(output_exports, {
|
|
2624
|
+
array: () => array,
|
|
2625
|
+
choice: () => choice,
|
|
2626
|
+
json: () => json,
|
|
2627
|
+
object: () => object,
|
|
2628
|
+
text: () => text
|
|
2629
|
+
});
|
|
2630
|
+
function fixJson(input) {
|
|
2631
|
+
const stack = ["ROOT"];
|
|
2632
|
+
let lastValidIndex = -1;
|
|
2633
|
+
let literalStart = null;
|
|
2634
|
+
let unicodeEscapeDigits = 0;
|
|
2635
|
+
function isHexDigit(char) {
|
|
2636
|
+
return char >= "0" && char <= "9" || char >= "A" && char <= "F" || char >= "a" && char <= "f";
|
|
2637
|
+
}
|
|
2638
|
+
function processValueStart(char, i, swapState) {
|
|
2639
|
+
{
|
|
2640
|
+
switch (char) {
|
|
2641
|
+
case '"': {
|
|
2642
|
+
lastValidIndex = i;
|
|
2643
|
+
stack.pop();
|
|
2644
|
+
stack.push(swapState);
|
|
2645
|
+
stack.push("INSIDE_STRING");
|
|
2646
|
+
break;
|
|
2647
|
+
}
|
|
2648
|
+
case "f":
|
|
2649
|
+
case "t":
|
|
2650
|
+
case "n": {
|
|
2651
|
+
lastValidIndex = i;
|
|
2652
|
+
literalStart = i;
|
|
2653
|
+
stack.pop();
|
|
2654
|
+
stack.push(swapState);
|
|
2655
|
+
stack.push("INSIDE_LITERAL");
|
|
2656
|
+
break;
|
|
2657
|
+
}
|
|
2658
|
+
case "-": {
|
|
2659
|
+
stack.pop();
|
|
2660
|
+
stack.push(swapState);
|
|
2661
|
+
stack.push("INSIDE_NUMBER");
|
|
2662
|
+
break;
|
|
2663
|
+
}
|
|
2664
|
+
case "0":
|
|
2665
|
+
case "1":
|
|
2666
|
+
case "2":
|
|
2667
|
+
case "3":
|
|
2668
|
+
case "4":
|
|
2669
|
+
case "5":
|
|
2670
|
+
case "6":
|
|
2671
|
+
case "7":
|
|
2672
|
+
case "8":
|
|
2673
|
+
case "9": {
|
|
2674
|
+
lastValidIndex = i;
|
|
2675
|
+
stack.pop();
|
|
2676
|
+
stack.push(swapState);
|
|
2677
|
+
stack.push("INSIDE_NUMBER");
|
|
2678
|
+
break;
|
|
2679
|
+
}
|
|
2680
|
+
case "{": {
|
|
2681
|
+
lastValidIndex = i;
|
|
2682
|
+
stack.pop();
|
|
2683
|
+
stack.push(swapState);
|
|
2684
|
+
stack.push("INSIDE_OBJECT_START");
|
|
2685
|
+
break;
|
|
2686
|
+
}
|
|
2687
|
+
case "[": {
|
|
2688
|
+
lastValidIndex = i;
|
|
2689
|
+
stack.pop();
|
|
2690
|
+
stack.push(swapState);
|
|
2691
|
+
stack.push("INSIDE_ARRAY_START");
|
|
2692
|
+
break;
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
function processAfterObjectValue(char, i) {
|
|
2698
|
+
switch (char) {
|
|
2699
|
+
case ",": {
|
|
2700
|
+
stack.pop();
|
|
2701
|
+
stack.push("INSIDE_OBJECT_AFTER_COMMA");
|
|
2702
|
+
break;
|
|
2703
|
+
}
|
|
2704
|
+
case "}": {
|
|
2705
|
+
lastValidIndex = i;
|
|
2706
|
+
stack.pop();
|
|
2707
|
+
break;
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
function processAfterArrayValue(char, i) {
|
|
2712
|
+
switch (char) {
|
|
2713
|
+
case ",": {
|
|
2714
|
+
stack.pop();
|
|
2715
|
+
stack.push("INSIDE_ARRAY_AFTER_COMMA");
|
|
2716
|
+
break;
|
|
2717
|
+
}
|
|
2718
|
+
case "]": {
|
|
2719
|
+
lastValidIndex = i;
|
|
2720
|
+
stack.pop();
|
|
2721
|
+
break;
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2725
|
+
for (let i = 0; i < input.length; i++) {
|
|
2726
|
+
const char = input[i];
|
|
2727
|
+
const currentState = stack[stack.length - 1];
|
|
2728
|
+
switch (currentState) {
|
|
2729
|
+
case "ROOT":
|
|
2730
|
+
processValueStart(char, i, "FINISH");
|
|
2731
|
+
break;
|
|
2732
|
+
case "INSIDE_OBJECT_START": {
|
|
2733
|
+
switch (char) {
|
|
2734
|
+
case '"': {
|
|
2735
|
+
stack.pop();
|
|
2736
|
+
stack.push("INSIDE_OBJECT_KEY");
|
|
2737
|
+
break;
|
|
2738
|
+
}
|
|
2739
|
+
case "}": {
|
|
2740
|
+
lastValidIndex = i;
|
|
2741
|
+
stack.pop();
|
|
2742
|
+
break;
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
break;
|
|
2746
|
+
}
|
|
2747
|
+
case "INSIDE_OBJECT_AFTER_COMMA": {
|
|
2748
|
+
switch (char) {
|
|
2749
|
+
case '"': {
|
|
2750
|
+
stack.pop();
|
|
2751
|
+
stack.push("INSIDE_OBJECT_KEY");
|
|
2752
|
+
break;
|
|
2753
|
+
}
|
|
2754
|
+
}
|
|
2755
|
+
break;
|
|
2756
|
+
}
|
|
2757
|
+
case "INSIDE_OBJECT_KEY": {
|
|
2758
|
+
switch (char) {
|
|
2759
|
+
case '"': {
|
|
2760
|
+
stack.pop();
|
|
2761
|
+
stack.push("INSIDE_OBJECT_AFTER_KEY");
|
|
2762
|
+
break;
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
break;
|
|
2766
|
+
}
|
|
2767
|
+
case "INSIDE_OBJECT_AFTER_KEY": {
|
|
2768
|
+
switch (char) {
|
|
2769
|
+
case ":": {
|
|
2770
|
+
stack.pop();
|
|
2771
|
+
stack.push("INSIDE_OBJECT_BEFORE_VALUE");
|
|
2772
|
+
break;
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
break;
|
|
2776
|
+
}
|
|
2777
|
+
case "INSIDE_OBJECT_BEFORE_VALUE": {
|
|
2778
|
+
processValueStart(char, i, "INSIDE_OBJECT_AFTER_VALUE");
|
|
2779
|
+
break;
|
|
2780
|
+
}
|
|
2781
|
+
case "INSIDE_OBJECT_AFTER_VALUE": {
|
|
2782
|
+
processAfterObjectValue(char, i);
|
|
2783
|
+
break;
|
|
2784
|
+
}
|
|
2785
|
+
case "INSIDE_STRING": {
|
|
2786
|
+
switch (char) {
|
|
2787
|
+
case '"': {
|
|
2788
|
+
stack.pop();
|
|
2789
|
+
lastValidIndex = i;
|
|
2790
|
+
break;
|
|
2791
|
+
}
|
|
2792
|
+
case "\\": {
|
|
2793
|
+
stack.push("INSIDE_STRING_ESCAPE");
|
|
2794
|
+
break;
|
|
2795
|
+
}
|
|
2796
|
+
default: {
|
|
2797
|
+
lastValidIndex = i;
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
break;
|
|
2801
|
+
}
|
|
2802
|
+
case "INSIDE_ARRAY_START": {
|
|
2803
|
+
switch (char) {
|
|
2804
|
+
case "]": {
|
|
2805
|
+
lastValidIndex = i;
|
|
2806
|
+
stack.pop();
|
|
2807
|
+
break;
|
|
2808
|
+
}
|
|
2809
|
+
default: {
|
|
2810
|
+
lastValidIndex = i;
|
|
2811
|
+
processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
|
|
2812
|
+
break;
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2815
|
+
break;
|
|
2816
|
+
}
|
|
2817
|
+
case "INSIDE_ARRAY_AFTER_VALUE": {
|
|
2818
|
+
switch (char) {
|
|
2819
|
+
case ",": {
|
|
2820
|
+
stack.pop();
|
|
2821
|
+
stack.push("INSIDE_ARRAY_AFTER_COMMA");
|
|
2822
|
+
break;
|
|
2823
|
+
}
|
|
2824
|
+
case "]": {
|
|
2825
|
+
lastValidIndex = i;
|
|
2826
|
+
stack.pop();
|
|
2827
|
+
break;
|
|
2828
|
+
}
|
|
2829
|
+
default: {
|
|
2830
|
+
lastValidIndex = i;
|
|
2831
|
+
break;
|
|
2832
|
+
}
|
|
2833
|
+
}
|
|
2834
|
+
break;
|
|
2835
|
+
}
|
|
2836
|
+
case "INSIDE_ARRAY_AFTER_COMMA": {
|
|
2837
|
+
processValueStart(char, i, "INSIDE_ARRAY_AFTER_VALUE");
|
|
2838
|
+
break;
|
|
2839
|
+
}
|
|
2840
|
+
case "INSIDE_STRING_ESCAPE": {
|
|
2841
|
+
stack.pop();
|
|
2842
|
+
if (char === "u") {
|
|
2843
|
+
unicodeEscapeDigits = 0;
|
|
2844
|
+
stack.push("INSIDE_STRING_UNICODE_ESCAPE");
|
|
2845
|
+
} else {
|
|
2846
|
+
lastValidIndex = i;
|
|
2847
|
+
}
|
|
2848
|
+
break;
|
|
2849
|
+
}
|
|
2850
|
+
case "INSIDE_STRING_UNICODE_ESCAPE": {
|
|
2851
|
+
if (isHexDigit(char)) {
|
|
2852
|
+
unicodeEscapeDigits++;
|
|
2853
|
+
if (unicodeEscapeDigits === 4) {
|
|
2854
|
+
stack.pop();
|
|
2855
|
+
lastValidIndex = i;
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
break;
|
|
2859
|
+
}
|
|
2860
|
+
case "INSIDE_NUMBER": {
|
|
2861
|
+
switch (char) {
|
|
2862
|
+
case "0":
|
|
2863
|
+
case "1":
|
|
2864
|
+
case "2":
|
|
2865
|
+
case "3":
|
|
2866
|
+
case "4":
|
|
2867
|
+
case "5":
|
|
2868
|
+
case "6":
|
|
2869
|
+
case "7":
|
|
2870
|
+
case "8":
|
|
2871
|
+
case "9": {
|
|
2872
|
+
lastValidIndex = i;
|
|
2873
|
+
break;
|
|
2874
|
+
}
|
|
2875
|
+
case "e":
|
|
2876
|
+
case "E":
|
|
2877
|
+
case "-":
|
|
2878
|
+
case ".": {
|
|
2879
|
+
break;
|
|
2880
|
+
}
|
|
2881
|
+
case ",": {
|
|
2882
|
+
stack.pop();
|
|
2883
|
+
if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
|
|
2884
|
+
processAfterArrayValue(char, i);
|
|
2885
|
+
}
|
|
2886
|
+
if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
|
|
2887
|
+
processAfterObjectValue(char, i);
|
|
2888
|
+
}
|
|
2889
|
+
break;
|
|
2890
|
+
}
|
|
2891
|
+
case "}": {
|
|
2892
|
+
stack.pop();
|
|
2893
|
+
if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
|
|
2894
|
+
processAfterObjectValue(char, i);
|
|
2895
|
+
}
|
|
2896
|
+
break;
|
|
2897
|
+
}
|
|
2898
|
+
case "]": {
|
|
2899
|
+
stack.pop();
|
|
2900
|
+
if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
|
|
2901
|
+
processAfterArrayValue(char, i);
|
|
2902
|
+
}
|
|
2903
|
+
break;
|
|
2904
|
+
}
|
|
2905
|
+
default: {
|
|
2906
|
+
stack.pop();
|
|
2907
|
+
break;
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2910
|
+
break;
|
|
2911
|
+
}
|
|
2912
|
+
case "INSIDE_LITERAL": {
|
|
2913
|
+
const partialLiteral = input.substring(literalStart, i + 1);
|
|
2914
|
+
if (!"false".startsWith(partialLiteral) && !"true".startsWith(partialLiteral) && !"null".startsWith(partialLiteral)) {
|
|
2915
|
+
stack.pop();
|
|
2916
|
+
if (stack[stack.length - 1] === "INSIDE_OBJECT_AFTER_VALUE") {
|
|
2917
|
+
processAfterObjectValue(char, i);
|
|
2918
|
+
} else if (stack[stack.length - 1] === "INSIDE_ARRAY_AFTER_VALUE") {
|
|
2919
|
+
processAfterArrayValue(char, i);
|
|
2920
|
+
}
|
|
2921
|
+
} else {
|
|
2922
|
+
lastValidIndex = i;
|
|
2923
|
+
}
|
|
2924
|
+
break;
|
|
2925
|
+
}
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
let result = input.slice(0, lastValidIndex + 1);
|
|
2929
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
2930
|
+
const state = stack[i];
|
|
2931
|
+
switch (state) {
|
|
2932
|
+
case "INSIDE_STRING": {
|
|
2933
|
+
result += '"';
|
|
2934
|
+
break;
|
|
2935
|
+
}
|
|
2936
|
+
case "INSIDE_OBJECT_KEY":
|
|
2937
|
+
case "INSIDE_OBJECT_AFTER_KEY":
|
|
2938
|
+
case "INSIDE_OBJECT_AFTER_COMMA":
|
|
2939
|
+
case "INSIDE_OBJECT_START":
|
|
2940
|
+
case "INSIDE_OBJECT_BEFORE_VALUE":
|
|
2941
|
+
case "INSIDE_OBJECT_AFTER_VALUE": {
|
|
2942
|
+
result += "}";
|
|
2943
|
+
break;
|
|
2944
|
+
}
|
|
2945
|
+
case "INSIDE_ARRAY_START":
|
|
2946
|
+
case "INSIDE_ARRAY_AFTER_COMMA":
|
|
2947
|
+
case "INSIDE_ARRAY_AFTER_VALUE": {
|
|
2948
|
+
result += "]";
|
|
2949
|
+
break;
|
|
2950
|
+
}
|
|
2951
|
+
case "INSIDE_LITERAL": {
|
|
2952
|
+
const partialLiteral = input.substring(literalStart, input.length);
|
|
2953
|
+
if ("true".startsWith(partialLiteral)) {
|
|
2954
|
+
result += "true".slice(partialLiteral.length);
|
|
2955
|
+
} else if ("false".startsWith(partialLiteral)) {
|
|
2956
|
+
result += "false".slice(partialLiteral.length);
|
|
2957
|
+
} else if ("null".startsWith(partialLiteral)) {
|
|
2958
|
+
result += "null".slice(partialLiteral.length);
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
}
|
|
2962
|
+
}
|
|
2963
|
+
return result;
|
|
2964
|
+
}
|
|
2965
|
+
async function parsePartialJson(jsonText) {
|
|
2966
|
+
if (jsonText === void 0) {
|
|
2967
|
+
return { value: void 0, state: "undefined-input" };
|
|
2968
|
+
}
|
|
2969
|
+
let result = await safeParseJSON({ text: jsonText });
|
|
2970
|
+
if (result.success) {
|
|
2971
|
+
return { value: result.value, state: "successful-parse" };
|
|
2972
|
+
}
|
|
2973
|
+
result = await safeParseJSON({ text: fixJson(jsonText) });
|
|
2974
|
+
if (result.success) {
|
|
2975
|
+
return { value: result.value, state: "repaired-parse" };
|
|
2976
|
+
}
|
|
2977
|
+
return { value: void 0, state: "failed-parse" };
|
|
2978
|
+
}
|
|
2979
|
+
var text = () => ({
|
|
2980
|
+
name: "text",
|
|
2981
|
+
responseFormat: Promise.resolve({ type: "text" }),
|
|
2982
|
+
async parseCompleteOutput({ text: text2 }) {
|
|
2983
|
+
return text2;
|
|
2984
|
+
},
|
|
2985
|
+
async parsePartialOutput({ text: text2 }) {
|
|
2986
|
+
return { partial: text2 };
|
|
2987
|
+
},
|
|
2988
|
+
createElementStreamTransform() {
|
|
2989
|
+
return void 0;
|
|
2990
|
+
}
|
|
2991
|
+
});
|
|
2992
|
+
var object = ({
|
|
2993
|
+
schema: inputSchema,
|
|
2994
|
+
name: name222,
|
|
2995
|
+
description
|
|
2996
|
+
}) => {
|
|
2997
|
+
const schema = asSchema(inputSchema);
|
|
2998
|
+
return {
|
|
2999
|
+
name: "object",
|
|
3000
|
+
responseFormat: resolve(schema.jsonSchema).then((jsonSchema2) => ({
|
|
3001
|
+
type: "json",
|
|
3002
|
+
schema: jsonSchema2,
|
|
3003
|
+
...name222 != null && { name: name222 },
|
|
3004
|
+
...description != null && { description }
|
|
3005
|
+
})),
|
|
3006
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
3007
|
+
const parseResult = await safeParseJSON({ text: text2 });
|
|
3008
|
+
if (!parseResult.success) {
|
|
3009
|
+
throw new NoObjectGeneratedError({
|
|
3010
|
+
message: "No object generated: could not parse the response.",
|
|
3011
|
+
cause: parseResult.error,
|
|
3012
|
+
text: text2,
|
|
3013
|
+
response: context2.response,
|
|
3014
|
+
usage: context2.usage,
|
|
3015
|
+
finishReason: context2.finishReason
|
|
3016
|
+
});
|
|
3017
|
+
}
|
|
3018
|
+
const validationResult = await safeValidateTypes({
|
|
3019
|
+
value: parseResult.value,
|
|
3020
|
+
schema
|
|
3021
|
+
});
|
|
3022
|
+
if (!validationResult.success) {
|
|
3023
|
+
throw new NoObjectGeneratedError({
|
|
3024
|
+
message: "No object generated: response did not match schema.",
|
|
3025
|
+
cause: validationResult.error,
|
|
3026
|
+
text: text2,
|
|
3027
|
+
response: context2.response,
|
|
3028
|
+
usage: context2.usage,
|
|
3029
|
+
finishReason: context2.finishReason
|
|
3030
|
+
});
|
|
3031
|
+
}
|
|
3032
|
+
return validationResult.value;
|
|
3033
|
+
},
|
|
3034
|
+
async parsePartialOutput({ text: text2 }) {
|
|
3035
|
+
const result = await parsePartialJson(text2);
|
|
3036
|
+
switch (result.state) {
|
|
3037
|
+
case "failed-parse":
|
|
3038
|
+
case "undefined-input": {
|
|
3039
|
+
return void 0;
|
|
3040
|
+
}
|
|
3041
|
+
case "repaired-parse":
|
|
3042
|
+
case "successful-parse": {
|
|
3043
|
+
return {
|
|
3044
|
+
// Note: currently no validation of partial results:
|
|
3045
|
+
partial: result.value
|
|
3046
|
+
};
|
|
3047
|
+
}
|
|
3048
|
+
}
|
|
3049
|
+
},
|
|
3050
|
+
createElementStreamTransform() {
|
|
3051
|
+
return void 0;
|
|
3052
|
+
}
|
|
3053
|
+
};
|
|
3054
|
+
};
|
|
3055
|
+
var array = ({
|
|
3056
|
+
element: inputElementSchema,
|
|
3057
|
+
name: name222,
|
|
3058
|
+
description
|
|
3059
|
+
}) => {
|
|
3060
|
+
const elementSchema = asSchema(inputElementSchema);
|
|
3061
|
+
return {
|
|
3062
|
+
name: "array",
|
|
3063
|
+
// JSON schema that describes an array of elements:
|
|
3064
|
+
responseFormat: resolve(elementSchema.jsonSchema).then((jsonSchema2) => {
|
|
3065
|
+
const { $schema, ...itemSchema } = jsonSchema2;
|
|
3066
|
+
return {
|
|
3067
|
+
type: "json",
|
|
3068
|
+
schema: {
|
|
3069
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
3070
|
+
type: "object",
|
|
3071
|
+
properties: {
|
|
3072
|
+
elements: { type: "array", items: itemSchema }
|
|
3073
|
+
},
|
|
3074
|
+
required: ["elements"],
|
|
3075
|
+
additionalProperties: false
|
|
3076
|
+
},
|
|
3077
|
+
...name222 != null && { name: name222 },
|
|
3078
|
+
...description != null && { description }
|
|
3079
|
+
};
|
|
3080
|
+
}),
|
|
3081
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
3082
|
+
const parseResult = await safeParseJSON({ text: text2 });
|
|
3083
|
+
if (!parseResult.success) {
|
|
3084
|
+
throw new NoObjectGeneratedError({
|
|
3085
|
+
message: "No object generated: could not parse the response.",
|
|
3086
|
+
cause: parseResult.error,
|
|
3087
|
+
text: text2,
|
|
3088
|
+
response: context2.response,
|
|
3089
|
+
usage: context2.usage,
|
|
3090
|
+
finishReason: context2.finishReason
|
|
3091
|
+
});
|
|
3092
|
+
}
|
|
3093
|
+
const outerValue = parseResult.value;
|
|
3094
|
+
if (outerValue == null || typeof outerValue !== "object" || !("elements" in outerValue) || !Array.isArray(outerValue.elements)) {
|
|
3095
|
+
throw new NoObjectGeneratedError({
|
|
3096
|
+
message: "No object generated: response did not match schema.",
|
|
3097
|
+
cause: new TypeValidationError({
|
|
3098
|
+
value: outerValue,
|
|
3099
|
+
cause: "response must be an object with an elements array"
|
|
3100
|
+
}),
|
|
3101
|
+
text: text2,
|
|
3102
|
+
response: context2.response,
|
|
3103
|
+
usage: context2.usage,
|
|
3104
|
+
finishReason: context2.finishReason
|
|
3105
|
+
});
|
|
3106
|
+
}
|
|
3107
|
+
for (const element of outerValue.elements) {
|
|
3108
|
+
const validationResult = await safeValidateTypes({
|
|
3109
|
+
value: element,
|
|
3110
|
+
schema: elementSchema
|
|
3111
|
+
});
|
|
3112
|
+
if (!validationResult.success) {
|
|
3113
|
+
throw new NoObjectGeneratedError({
|
|
3114
|
+
message: "No object generated: response did not match schema.",
|
|
3115
|
+
cause: validationResult.error,
|
|
3116
|
+
text: text2,
|
|
3117
|
+
response: context2.response,
|
|
3118
|
+
usage: context2.usage,
|
|
3119
|
+
finishReason: context2.finishReason
|
|
3120
|
+
});
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
return outerValue.elements;
|
|
3124
|
+
},
|
|
3125
|
+
async parsePartialOutput({ text: text2 }) {
|
|
3126
|
+
const result = await parsePartialJson(text2);
|
|
3127
|
+
switch (result.state) {
|
|
3128
|
+
case "failed-parse":
|
|
3129
|
+
case "undefined-input": {
|
|
3130
|
+
return void 0;
|
|
3131
|
+
}
|
|
3132
|
+
case "repaired-parse":
|
|
3133
|
+
case "successful-parse": {
|
|
3134
|
+
const outerValue = result.value;
|
|
3135
|
+
if (outerValue == null || typeof outerValue !== "object" || !("elements" in outerValue) || !Array.isArray(outerValue.elements)) {
|
|
3136
|
+
return void 0;
|
|
3137
|
+
}
|
|
3138
|
+
const rawElements = result.state === "repaired-parse" && outerValue.elements.length > 0 ? outerValue.elements.slice(0, -1) : outerValue.elements;
|
|
3139
|
+
const parsedElements = [];
|
|
3140
|
+
for (const rawElement of rawElements) {
|
|
3141
|
+
const validationResult = await safeValidateTypes({
|
|
3142
|
+
value: rawElement,
|
|
3143
|
+
schema: elementSchema
|
|
3144
|
+
});
|
|
3145
|
+
if (validationResult.success) {
|
|
3146
|
+
parsedElements.push(validationResult.value);
|
|
3147
|
+
}
|
|
3148
|
+
}
|
|
3149
|
+
return { partial: parsedElements };
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
},
|
|
3153
|
+
createElementStreamTransform() {
|
|
3154
|
+
let publishedElements = 0;
|
|
3155
|
+
return new TransformStream({
|
|
3156
|
+
transform({ partialOutput }, controller) {
|
|
3157
|
+
if (partialOutput != null) {
|
|
3158
|
+
for (; publishedElements < partialOutput.length; publishedElements++) {
|
|
3159
|
+
controller.enqueue(partialOutput[publishedElements]);
|
|
3160
|
+
}
|
|
3161
|
+
}
|
|
3162
|
+
}
|
|
3163
|
+
});
|
|
3164
|
+
}
|
|
3165
|
+
};
|
|
3166
|
+
};
|
|
3167
|
+
var choice = ({
|
|
3168
|
+
options: choiceOptions,
|
|
3169
|
+
name: name222,
|
|
3170
|
+
description
|
|
3171
|
+
}) => {
|
|
3172
|
+
return {
|
|
3173
|
+
name: "choice",
|
|
3174
|
+
// JSON schema that describes an enumeration:
|
|
3175
|
+
responseFormat: Promise.resolve({
|
|
3176
|
+
type: "json",
|
|
3177
|
+
schema: {
|
|
3178
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
3179
|
+
type: "object",
|
|
3180
|
+
properties: {
|
|
3181
|
+
result: { type: "string", enum: choiceOptions }
|
|
3182
|
+
},
|
|
3183
|
+
required: ["result"],
|
|
3184
|
+
additionalProperties: false
|
|
3185
|
+
},
|
|
3186
|
+
...name222 != null && { name: name222 },
|
|
3187
|
+
...description != null && { description }
|
|
3188
|
+
}),
|
|
3189
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
3190
|
+
const parseResult = await safeParseJSON({ text: text2 });
|
|
3191
|
+
if (!parseResult.success) {
|
|
3192
|
+
throw new NoObjectGeneratedError({
|
|
3193
|
+
message: "No object generated: could not parse the response.",
|
|
3194
|
+
cause: parseResult.error,
|
|
3195
|
+
text: text2,
|
|
3196
|
+
response: context2.response,
|
|
3197
|
+
usage: context2.usage,
|
|
3198
|
+
finishReason: context2.finishReason
|
|
3199
|
+
});
|
|
3200
|
+
}
|
|
3201
|
+
const outerValue = parseResult.value;
|
|
3202
|
+
if (outerValue == null || typeof outerValue !== "object" || !("result" in outerValue) || typeof outerValue.result !== "string" || !choiceOptions.includes(outerValue.result)) {
|
|
3203
|
+
throw new NoObjectGeneratedError({
|
|
3204
|
+
message: "No object generated: response did not match schema.",
|
|
3205
|
+
cause: new TypeValidationError({
|
|
3206
|
+
value: outerValue,
|
|
3207
|
+
cause: "response must be an object that contains a choice value."
|
|
3208
|
+
}),
|
|
3209
|
+
text: text2,
|
|
3210
|
+
response: context2.response,
|
|
3211
|
+
usage: context2.usage,
|
|
3212
|
+
finishReason: context2.finishReason
|
|
3213
|
+
});
|
|
3214
|
+
}
|
|
3215
|
+
return outerValue.result;
|
|
3216
|
+
},
|
|
3217
|
+
async parsePartialOutput({ text: text2 }) {
|
|
3218
|
+
const result = await parsePartialJson(text2);
|
|
3219
|
+
switch (result.state) {
|
|
3220
|
+
case "failed-parse":
|
|
3221
|
+
case "undefined-input": {
|
|
3222
|
+
return void 0;
|
|
3223
|
+
}
|
|
3224
|
+
case "repaired-parse":
|
|
3225
|
+
case "successful-parse": {
|
|
3226
|
+
const outerValue = result.value;
|
|
3227
|
+
if (outerValue == null || typeof outerValue !== "object" || !("result" in outerValue) || typeof outerValue.result !== "string") {
|
|
3228
|
+
return void 0;
|
|
3229
|
+
}
|
|
3230
|
+
const potentialMatches = choiceOptions.filter(
|
|
3231
|
+
(choiceOption) => choiceOption.startsWith(outerValue.result)
|
|
3232
|
+
);
|
|
3233
|
+
if (result.state === "successful-parse") {
|
|
3234
|
+
return potentialMatches.includes(outerValue.result) ? { partial: outerValue.result } : void 0;
|
|
3235
|
+
} else {
|
|
3236
|
+
return potentialMatches.length === 1 ? { partial: potentialMatches[0] } : void 0;
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3240
|
+
},
|
|
3241
|
+
createElementStreamTransform() {
|
|
3242
|
+
return void 0;
|
|
3243
|
+
}
|
|
3244
|
+
};
|
|
3245
|
+
};
|
|
3246
|
+
var json = ({
|
|
3247
|
+
name: name222,
|
|
3248
|
+
description
|
|
3249
|
+
} = {}) => {
|
|
3250
|
+
return {
|
|
3251
|
+
name: "json",
|
|
3252
|
+
responseFormat: Promise.resolve({
|
|
3253
|
+
type: "json",
|
|
3254
|
+
...name222 != null && { name: name222 },
|
|
3255
|
+
...description != null && { description }
|
|
3256
|
+
}),
|
|
3257
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
3258
|
+
const parseResult = await safeParseJSON({ text: text2 });
|
|
3259
|
+
if (!parseResult.success) {
|
|
3260
|
+
throw new NoObjectGeneratedError({
|
|
3261
|
+
message: "No object generated: could not parse the response.",
|
|
3262
|
+
cause: parseResult.error,
|
|
3263
|
+
text: text2,
|
|
3264
|
+
response: context2.response,
|
|
3265
|
+
usage: context2.usage,
|
|
3266
|
+
finishReason: context2.finishReason
|
|
3267
|
+
});
|
|
3268
|
+
}
|
|
3269
|
+
return parseResult.value;
|
|
3270
|
+
},
|
|
3271
|
+
async parsePartialOutput({ text: text2 }) {
|
|
3272
|
+
const result = await parsePartialJson(text2);
|
|
3273
|
+
switch (result.state) {
|
|
3274
|
+
case "failed-parse":
|
|
3275
|
+
case "undefined-input": {
|
|
3276
|
+
return void 0;
|
|
3277
|
+
}
|
|
3278
|
+
case "repaired-parse":
|
|
3279
|
+
case "successful-parse": {
|
|
3280
|
+
return result.value === void 0 ? void 0 : { partial: result.value };
|
|
3281
|
+
}
|
|
3282
|
+
}
|
|
3283
|
+
},
|
|
3284
|
+
createElementStreamTransform() {
|
|
3285
|
+
return void 0;
|
|
3286
|
+
}
|
|
3287
|
+
};
|
|
3288
|
+
};
|
|
3289
|
+
var originalGenerateId = createIdGenerator({
|
|
3290
|
+
prefix: "aitxt",
|
|
3291
|
+
size: 24
|
|
3292
|
+
});
|
|
3293
|
+
var JsonToSseTransformStream = class extends TransformStream {
|
|
3294
|
+
constructor() {
|
|
3295
|
+
super({
|
|
3296
|
+
transform(part, controller) {
|
|
3297
|
+
controller.enqueue(`data: ${JSON.stringify(part)}
|
|
3298
|
+
|
|
3299
|
+
`);
|
|
3300
|
+
},
|
|
3301
|
+
flush(controller) {
|
|
3302
|
+
controller.enqueue("data: [DONE]\n\n");
|
|
3303
|
+
}
|
|
3304
|
+
});
|
|
3305
|
+
}
|
|
3306
|
+
};
|
|
3307
|
+
var toolMetadataSchema = z7.record(
|
|
3308
|
+
z7.string(),
|
|
3309
|
+
jsonValueSchema.optional()
|
|
3310
|
+
);
|
|
3311
|
+
var uiMessageChunkSchema = lazySchema(
|
|
3312
|
+
() => zodSchema(
|
|
3313
|
+
z7.union([
|
|
3314
|
+
z7.strictObject({
|
|
3315
|
+
type: z7.literal("text-start"),
|
|
3316
|
+
id: z7.string(),
|
|
3317
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
3318
|
+
}),
|
|
3319
|
+
z7.strictObject({
|
|
3320
|
+
type: z7.literal("text-delta"),
|
|
3321
|
+
id: z7.string(),
|
|
3322
|
+
delta: z7.string(),
|
|
3323
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
3324
|
+
}),
|
|
3325
|
+
z7.strictObject({
|
|
3326
|
+
type: z7.literal("text-end"),
|
|
3327
|
+
id: z7.string(),
|
|
3328
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
3329
|
+
}),
|
|
3330
|
+
z7.strictObject({
|
|
3331
|
+
type: z7.literal("error"),
|
|
3332
|
+
errorText: z7.string()
|
|
3333
|
+
}),
|
|
3334
|
+
z7.strictObject({
|
|
3335
|
+
type: z7.literal("tool-input-start"),
|
|
3336
|
+
toolCallId: z7.string(),
|
|
3337
|
+
toolName: z7.string(),
|
|
3338
|
+
providerExecuted: z7.boolean().optional(),
|
|
3339
|
+
providerMetadata: providerMetadataSchema.optional(),
|
|
3340
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
3341
|
+
dynamic: z7.boolean().optional(),
|
|
3342
|
+
title: z7.string().optional()
|
|
3343
|
+
}),
|
|
3344
|
+
z7.strictObject({
|
|
3345
|
+
type: z7.literal("tool-input-delta"),
|
|
3346
|
+
toolCallId: z7.string(),
|
|
3347
|
+
inputTextDelta: z7.string()
|
|
3348
|
+
}),
|
|
3349
|
+
z7.strictObject({
|
|
3350
|
+
type: z7.literal("tool-input-available"),
|
|
3351
|
+
toolCallId: z7.string(),
|
|
3352
|
+
toolName: z7.string(),
|
|
3353
|
+
input: z7.unknown(),
|
|
3354
|
+
providerExecuted: z7.boolean().optional(),
|
|
3355
|
+
providerMetadata: providerMetadataSchema.optional(),
|
|
3356
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
3357
|
+
dynamic: z7.boolean().optional(),
|
|
3358
|
+
title: z7.string().optional()
|
|
3359
|
+
}),
|
|
3360
|
+
z7.strictObject({
|
|
3361
|
+
type: z7.literal("tool-input-error"),
|
|
3362
|
+
toolCallId: z7.string(),
|
|
3363
|
+
toolName: z7.string(),
|
|
3364
|
+
input: z7.unknown(),
|
|
3365
|
+
providerExecuted: z7.boolean().optional(),
|
|
3366
|
+
providerMetadata: providerMetadataSchema.optional(),
|
|
3367
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
3368
|
+
dynamic: z7.boolean().optional(),
|
|
3369
|
+
errorText: z7.string(),
|
|
3370
|
+
title: z7.string().optional()
|
|
3371
|
+
}),
|
|
3372
|
+
z7.strictObject({
|
|
3373
|
+
type: z7.literal("tool-approval-request"),
|
|
3374
|
+
approvalId: z7.string(),
|
|
3375
|
+
toolCallId: z7.string(),
|
|
3376
|
+
signature: z7.string().optional()
|
|
3377
|
+
}),
|
|
3378
|
+
z7.strictObject({
|
|
3379
|
+
type: z7.literal("tool-output-available"),
|
|
3380
|
+
toolCallId: z7.string(),
|
|
3381
|
+
output: z7.unknown(),
|
|
3382
|
+
providerExecuted: z7.boolean().optional(),
|
|
3383
|
+
providerMetadata: providerMetadataSchema.optional(),
|
|
3384
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
3385
|
+
dynamic: z7.boolean().optional(),
|
|
3386
|
+
preliminary: z7.boolean().optional()
|
|
3387
|
+
}),
|
|
3388
|
+
z7.strictObject({
|
|
3389
|
+
type: z7.literal("tool-output-error"),
|
|
3390
|
+
toolCallId: z7.string(),
|
|
3391
|
+
errorText: z7.string(),
|
|
3392
|
+
providerExecuted: z7.boolean().optional(),
|
|
3393
|
+
providerMetadata: providerMetadataSchema.optional(),
|
|
3394
|
+
toolMetadata: toolMetadataSchema.optional(),
|
|
3395
|
+
dynamic: z7.boolean().optional()
|
|
3396
|
+
}),
|
|
3397
|
+
z7.strictObject({
|
|
3398
|
+
type: z7.literal("tool-output-denied"),
|
|
3399
|
+
toolCallId: z7.string()
|
|
3400
|
+
}),
|
|
3401
|
+
z7.strictObject({
|
|
3402
|
+
type: z7.literal("reasoning-start"),
|
|
3403
|
+
id: z7.string(),
|
|
3404
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
3405
|
+
}),
|
|
3406
|
+
z7.strictObject({
|
|
3407
|
+
type: z7.literal("reasoning-delta"),
|
|
3408
|
+
id: z7.string(),
|
|
3409
|
+
delta: z7.string(),
|
|
3410
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
3411
|
+
}),
|
|
3412
|
+
z7.strictObject({
|
|
3413
|
+
type: z7.literal("reasoning-end"),
|
|
3414
|
+
id: z7.string(),
|
|
3415
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
3416
|
+
}),
|
|
3417
|
+
z7.strictObject({
|
|
3418
|
+
type: z7.literal("source-url"),
|
|
3419
|
+
sourceId: z7.string(),
|
|
3420
|
+
url: z7.string(),
|
|
3421
|
+
title: z7.string().optional(),
|
|
3422
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
3423
|
+
}),
|
|
3424
|
+
z7.strictObject({
|
|
3425
|
+
type: z7.literal("source-document"),
|
|
3426
|
+
sourceId: z7.string(),
|
|
3427
|
+
mediaType: z7.string(),
|
|
3428
|
+
title: z7.string(),
|
|
3429
|
+
filename: z7.string().optional(),
|
|
3430
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
3431
|
+
}),
|
|
3432
|
+
z7.strictObject({
|
|
3433
|
+
type: z7.literal("file"),
|
|
3434
|
+
url: z7.string(),
|
|
3435
|
+
mediaType: z7.string(),
|
|
3436
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
3437
|
+
}),
|
|
3438
|
+
z7.strictObject({
|
|
3439
|
+
type: z7.custom(
|
|
3440
|
+
(value) => typeof value === "string" && value.startsWith("data-"),
|
|
3441
|
+
{ message: 'Type must start with "data-"' }
|
|
3442
|
+
),
|
|
3443
|
+
id: z7.string().optional(),
|
|
3444
|
+
data: z7.unknown(),
|
|
3445
|
+
transient: z7.boolean().optional()
|
|
3446
|
+
}),
|
|
3447
|
+
z7.strictObject({
|
|
3448
|
+
type: z7.literal("start-step")
|
|
3449
|
+
}),
|
|
3450
|
+
z7.strictObject({
|
|
3451
|
+
type: z7.literal("finish-step")
|
|
3452
|
+
}),
|
|
3453
|
+
z7.strictObject({
|
|
3454
|
+
type: z7.literal("start"),
|
|
3455
|
+
messageId: z7.string().optional(),
|
|
3456
|
+
messageMetadata: z7.unknown().optional()
|
|
3457
|
+
}),
|
|
3458
|
+
z7.strictObject({
|
|
3459
|
+
type: z7.literal("finish"),
|
|
3460
|
+
finishReason: z7.enum([
|
|
3461
|
+
"stop",
|
|
3462
|
+
"length",
|
|
3463
|
+
"content-filter",
|
|
3464
|
+
"tool-calls",
|
|
3465
|
+
"error",
|
|
3466
|
+
"other"
|
|
3467
|
+
]).optional(),
|
|
3468
|
+
messageMetadata: z7.unknown().optional()
|
|
3469
|
+
}),
|
|
3470
|
+
z7.strictObject({
|
|
3471
|
+
type: z7.literal("abort"),
|
|
3472
|
+
reason: z7.string().optional()
|
|
3473
|
+
}),
|
|
3474
|
+
z7.strictObject({
|
|
3475
|
+
type: z7.literal("message-metadata"),
|
|
3476
|
+
messageMetadata: z7.unknown()
|
|
3477
|
+
})
|
|
3478
|
+
])
|
|
3479
|
+
)
|
|
3480
|
+
);
|
|
3481
|
+
function isStaticToolUIPart(part) {
|
|
3482
|
+
return part.type.startsWith("tool-");
|
|
3483
|
+
}
|
|
3484
|
+
function isDynamicToolUIPart(part) {
|
|
3485
|
+
return part.type === "dynamic-tool";
|
|
3486
|
+
}
|
|
3487
|
+
function isToolUIPart(part) {
|
|
3488
|
+
return isStaticToolUIPart(part) || isDynamicToolUIPart(part);
|
|
3489
|
+
}
|
|
3490
|
+
var originalGenerateId2 = createIdGenerator({
|
|
3491
|
+
prefix: "aitxt",
|
|
3492
|
+
size: 24
|
|
3493
|
+
});
|
|
3494
|
+
var toolMetadataSchema2 = z8.record(
|
|
3495
|
+
z8.string(),
|
|
3496
|
+
jsonValueSchema.optional()
|
|
3497
|
+
);
|
|
3498
|
+
var uiMessagesSchema = lazySchema(
|
|
3499
|
+
() => zodSchema(
|
|
3500
|
+
z8.array(
|
|
3501
|
+
z8.object({
|
|
3502
|
+
id: z8.string(),
|
|
3503
|
+
role: z8.enum(["system", "user", "assistant"]),
|
|
3504
|
+
metadata: z8.unknown().optional(),
|
|
3505
|
+
parts: z8.array(
|
|
3506
|
+
z8.union([
|
|
3507
|
+
z8.object({
|
|
3508
|
+
type: z8.literal("text"),
|
|
3509
|
+
text: z8.string(),
|
|
3510
|
+
state: z8.enum(["streaming", "done"]).optional(),
|
|
3511
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
3512
|
+
}),
|
|
3513
|
+
z8.object({
|
|
3514
|
+
type: z8.literal("reasoning"),
|
|
3515
|
+
text: z8.string(),
|
|
3516
|
+
state: z8.enum(["streaming", "done"]).optional(),
|
|
3517
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
3518
|
+
}),
|
|
3519
|
+
z8.object({
|
|
3520
|
+
type: z8.literal("source-url"),
|
|
3521
|
+
sourceId: z8.string(),
|
|
3522
|
+
url: z8.string(),
|
|
3523
|
+
title: z8.string().optional(),
|
|
3524
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
3525
|
+
}),
|
|
3526
|
+
z8.object({
|
|
3527
|
+
type: z8.literal("source-document"),
|
|
3528
|
+
sourceId: z8.string(),
|
|
3529
|
+
mediaType: z8.string(),
|
|
3530
|
+
title: z8.string(),
|
|
3531
|
+
filename: z8.string().optional(),
|
|
3532
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
3533
|
+
}),
|
|
3534
|
+
z8.object({
|
|
3535
|
+
type: z8.literal("file"),
|
|
3536
|
+
mediaType: z8.string(),
|
|
3537
|
+
filename: z8.string().optional(),
|
|
3538
|
+
url: z8.string(),
|
|
3539
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
3540
|
+
}),
|
|
3541
|
+
z8.object({
|
|
3542
|
+
type: z8.literal("step-start")
|
|
3543
|
+
}),
|
|
3544
|
+
z8.object({
|
|
3545
|
+
type: z8.string().startsWith("data-"),
|
|
3546
|
+
id: z8.string().optional(),
|
|
3547
|
+
data: z8.unknown()
|
|
3548
|
+
}),
|
|
3549
|
+
z8.object({
|
|
3550
|
+
type: z8.literal("dynamic-tool"),
|
|
3551
|
+
toolName: z8.string(),
|
|
3552
|
+
toolCallId: z8.string(),
|
|
3553
|
+
toolMetadata: toolMetadataSchema2.optional(),
|
|
3554
|
+
state: z8.literal("input-streaming"),
|
|
3555
|
+
input: z8.unknown().optional(),
|
|
3556
|
+
providerExecuted: z8.boolean().optional(),
|
|
3557
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
3558
|
+
output: z8.never().optional(),
|
|
3559
|
+
errorText: z8.never().optional(),
|
|
3560
|
+
approval: z8.never().optional()
|
|
3561
|
+
}),
|
|
3562
|
+
z8.object({
|
|
3563
|
+
type: z8.literal("dynamic-tool"),
|
|
3564
|
+
toolName: z8.string(),
|
|
3565
|
+
toolCallId: z8.string(),
|
|
3566
|
+
toolMetadata: toolMetadataSchema2.optional(),
|
|
3567
|
+
state: z8.literal("input-available"),
|
|
3568
|
+
input: z8.unknown(),
|
|
3569
|
+
providerExecuted: z8.boolean().optional(),
|
|
3570
|
+
output: z8.never().optional(),
|
|
3571
|
+
errorText: z8.never().optional(),
|
|
3572
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
3573
|
+
approval: z8.never().optional()
|
|
3574
|
+
}),
|
|
3575
|
+
z8.object({
|
|
3576
|
+
type: z8.literal("dynamic-tool"),
|
|
3577
|
+
toolName: z8.string(),
|
|
3578
|
+
toolCallId: z8.string(),
|
|
3579
|
+
toolMetadata: toolMetadataSchema2.optional(),
|
|
3580
|
+
state: z8.literal("approval-requested"),
|
|
3581
|
+
input: z8.unknown(),
|
|
3582
|
+
providerExecuted: z8.boolean().optional(),
|
|
3583
|
+
output: z8.never().optional(),
|
|
3584
|
+
errorText: z8.never().optional(),
|
|
3585
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
3586
|
+
approval: z8.object({
|
|
3587
|
+
id: z8.string(),
|
|
3588
|
+
approved: z8.never().optional(),
|
|
3589
|
+
reason: z8.never().optional(),
|
|
3590
|
+
signature: z8.string().optional()
|
|
3591
|
+
})
|
|
3592
|
+
}),
|
|
3593
|
+
z8.object({
|
|
3594
|
+
type: z8.literal("dynamic-tool"),
|
|
3595
|
+
toolName: z8.string(),
|
|
3596
|
+
toolCallId: z8.string(),
|
|
3597
|
+
toolMetadata: toolMetadataSchema2.optional(),
|
|
3598
|
+
state: z8.literal("approval-responded"),
|
|
3599
|
+
input: z8.unknown(),
|
|
3600
|
+
providerExecuted: z8.boolean().optional(),
|
|
3601
|
+
output: z8.never().optional(),
|
|
3602
|
+
errorText: z8.never().optional(),
|
|
3603
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
3604
|
+
approval: z8.object({
|
|
3605
|
+
id: z8.string(),
|
|
3606
|
+
approved: z8.boolean(),
|
|
3607
|
+
reason: z8.string().optional(),
|
|
3608
|
+
signature: z8.string().optional()
|
|
3609
|
+
})
|
|
3610
|
+
}),
|
|
3611
|
+
z8.object({
|
|
3612
|
+
type: z8.literal("dynamic-tool"),
|
|
3613
|
+
toolName: z8.string(),
|
|
3614
|
+
toolCallId: z8.string(),
|
|
3615
|
+
toolMetadata: toolMetadataSchema2.optional(),
|
|
3616
|
+
state: z8.literal("output-available"),
|
|
3617
|
+
input: z8.unknown(),
|
|
3618
|
+
providerExecuted: z8.boolean().optional(),
|
|
3619
|
+
output: z8.unknown(),
|
|
3620
|
+
errorText: z8.never().optional(),
|
|
3621
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
3622
|
+
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
3623
|
+
preliminary: z8.boolean().optional(),
|
|
3624
|
+
approval: z8.object({
|
|
3625
|
+
id: z8.string(),
|
|
3626
|
+
approved: z8.literal(true),
|
|
3627
|
+
reason: z8.string().optional(),
|
|
3628
|
+
signature: z8.string().optional()
|
|
3629
|
+
}).optional()
|
|
3630
|
+
}),
|
|
3631
|
+
z8.object({
|
|
3632
|
+
type: z8.literal("dynamic-tool"),
|
|
3633
|
+
toolName: z8.string(),
|
|
3634
|
+
toolCallId: z8.string(),
|
|
3635
|
+
toolMetadata: toolMetadataSchema2.optional(),
|
|
3636
|
+
state: z8.literal("output-error"),
|
|
3637
|
+
input: z8.unknown().optional(),
|
|
3638
|
+
rawInput: z8.unknown().optional(),
|
|
3639
|
+
providerExecuted: z8.boolean().optional(),
|
|
3640
|
+
output: z8.never().optional(),
|
|
3641
|
+
errorText: z8.string(),
|
|
3642
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
3643
|
+
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
3644
|
+
approval: z8.object({
|
|
3645
|
+
id: z8.string(),
|
|
3646
|
+
approved: z8.literal(true),
|
|
3647
|
+
reason: z8.string().optional(),
|
|
3648
|
+
signature: z8.string().optional()
|
|
3649
|
+
}).optional()
|
|
3650
|
+
}),
|
|
3651
|
+
z8.object({
|
|
3652
|
+
type: z8.literal("dynamic-tool"),
|
|
3653
|
+
toolName: z8.string(),
|
|
3654
|
+
toolCallId: z8.string(),
|
|
3655
|
+
toolMetadata: toolMetadataSchema2.optional(),
|
|
3656
|
+
state: z8.literal("output-denied"),
|
|
3657
|
+
input: z8.unknown(),
|
|
3658
|
+
providerExecuted: z8.boolean().optional(),
|
|
3659
|
+
output: z8.never().optional(),
|
|
3660
|
+
errorText: z8.never().optional(),
|
|
3661
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
3662
|
+
approval: z8.object({
|
|
3663
|
+
id: z8.string(),
|
|
3664
|
+
approved: z8.literal(false),
|
|
3665
|
+
reason: z8.string().optional(),
|
|
3666
|
+
signature: z8.string().optional()
|
|
3667
|
+
})
|
|
3668
|
+
}),
|
|
3669
|
+
z8.object({
|
|
3670
|
+
type: z8.string().startsWith("tool-"),
|
|
3671
|
+
toolCallId: z8.string(),
|
|
3672
|
+
toolMetadata: toolMetadataSchema2.optional(),
|
|
3673
|
+
state: z8.literal("input-streaming"),
|
|
3674
|
+
providerExecuted: z8.boolean().optional(),
|
|
3675
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
3676
|
+
input: z8.unknown().optional(),
|
|
3677
|
+
output: z8.never().optional(),
|
|
3678
|
+
errorText: z8.never().optional(),
|
|
3679
|
+
approval: z8.never().optional()
|
|
3680
|
+
}),
|
|
3681
|
+
z8.object({
|
|
3682
|
+
type: z8.string().startsWith("tool-"),
|
|
3683
|
+
toolCallId: z8.string(),
|
|
3684
|
+
toolMetadata: toolMetadataSchema2.optional(),
|
|
3685
|
+
state: z8.literal("input-available"),
|
|
3686
|
+
providerExecuted: z8.boolean().optional(),
|
|
3687
|
+
input: z8.unknown(),
|
|
3688
|
+
output: z8.never().optional(),
|
|
3689
|
+
errorText: z8.never().optional(),
|
|
3690
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
3691
|
+
approval: z8.never().optional()
|
|
3692
|
+
}),
|
|
3693
|
+
z8.object({
|
|
3694
|
+
type: z8.string().startsWith("tool-"),
|
|
3695
|
+
toolCallId: z8.string(),
|
|
3696
|
+
toolMetadata: toolMetadataSchema2.optional(),
|
|
3697
|
+
state: z8.literal("approval-requested"),
|
|
3698
|
+
input: z8.unknown(),
|
|
3699
|
+
providerExecuted: z8.boolean().optional(),
|
|
3700
|
+
output: z8.never().optional(),
|
|
3701
|
+
errorText: z8.never().optional(),
|
|
3702
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
3703
|
+
approval: z8.object({
|
|
3704
|
+
id: z8.string(),
|
|
3705
|
+
approved: z8.never().optional(),
|
|
3706
|
+
reason: z8.never().optional(),
|
|
3707
|
+
signature: z8.string().optional()
|
|
3708
|
+
})
|
|
3709
|
+
}),
|
|
3710
|
+
z8.object({
|
|
3711
|
+
type: z8.string().startsWith("tool-"),
|
|
3712
|
+
toolCallId: z8.string(),
|
|
3713
|
+
toolMetadata: toolMetadataSchema2.optional(),
|
|
3714
|
+
state: z8.literal("approval-responded"),
|
|
3715
|
+
input: z8.unknown(),
|
|
3716
|
+
providerExecuted: z8.boolean().optional(),
|
|
3717
|
+
output: z8.never().optional(),
|
|
3718
|
+
errorText: z8.never().optional(),
|
|
3719
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
3720
|
+
approval: z8.object({
|
|
3721
|
+
id: z8.string(),
|
|
3722
|
+
approved: z8.boolean(),
|
|
3723
|
+
reason: z8.string().optional(),
|
|
3724
|
+
signature: z8.string().optional()
|
|
3725
|
+
})
|
|
3726
|
+
}),
|
|
3727
|
+
z8.object({
|
|
3728
|
+
type: z8.string().startsWith("tool-"),
|
|
3729
|
+
toolCallId: z8.string(),
|
|
3730
|
+
toolMetadata: toolMetadataSchema2.optional(),
|
|
3731
|
+
state: z8.literal("output-available"),
|
|
3732
|
+
providerExecuted: z8.boolean().optional(),
|
|
3733
|
+
input: z8.unknown(),
|
|
3734
|
+
output: z8.unknown(),
|
|
3735
|
+
errorText: z8.never().optional(),
|
|
3736
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
3737
|
+
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
3738
|
+
preliminary: z8.boolean().optional(),
|
|
3739
|
+
approval: z8.object({
|
|
3740
|
+
id: z8.string(),
|
|
3741
|
+
approved: z8.literal(true),
|
|
3742
|
+
reason: z8.string().optional(),
|
|
3743
|
+
signature: z8.string().optional()
|
|
3744
|
+
}).optional()
|
|
3745
|
+
}),
|
|
3746
|
+
z8.object({
|
|
3747
|
+
type: z8.string().startsWith("tool-"),
|
|
3748
|
+
toolCallId: z8.string(),
|
|
3749
|
+
toolMetadata: toolMetadataSchema2.optional(),
|
|
3750
|
+
state: z8.literal("output-error"),
|
|
3751
|
+
providerExecuted: z8.boolean().optional(),
|
|
3752
|
+
input: z8.unknown().optional(),
|
|
3753
|
+
rawInput: z8.unknown().optional(),
|
|
3754
|
+
output: z8.never().optional(),
|
|
3755
|
+
errorText: z8.string(),
|
|
3756
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
3757
|
+
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
3758
|
+
approval: z8.object({
|
|
3759
|
+
id: z8.string(),
|
|
3760
|
+
approved: z8.literal(true),
|
|
3761
|
+
reason: z8.string().optional(),
|
|
3762
|
+
signature: z8.string().optional()
|
|
3763
|
+
}).optional()
|
|
3764
|
+
}),
|
|
3765
|
+
z8.object({
|
|
3766
|
+
type: z8.string().startsWith("tool-"),
|
|
3767
|
+
toolCallId: z8.string(),
|
|
3768
|
+
toolMetadata: toolMetadataSchema2.optional(),
|
|
3769
|
+
state: z8.literal("output-denied"),
|
|
3770
|
+
providerExecuted: z8.boolean().optional(),
|
|
3771
|
+
input: z8.unknown(),
|
|
3772
|
+
output: z8.never().optional(),
|
|
3773
|
+
errorText: z8.never().optional(),
|
|
3774
|
+
callProviderMetadata: providerMetadataSchema.optional(),
|
|
3775
|
+
approval: z8.object({
|
|
3776
|
+
id: z8.string(),
|
|
3777
|
+
approved: z8.literal(false),
|
|
3778
|
+
reason: z8.string().optional(),
|
|
3779
|
+
signature: z8.string().optional()
|
|
3780
|
+
})
|
|
3781
|
+
})
|
|
3782
|
+
])
|
|
3783
|
+
).nonempty("Message must contain at least one part")
|
|
3784
|
+
})
|
|
3785
|
+
).nonempty("Messages array must not be empty")
|
|
3786
|
+
)
|
|
3787
|
+
);
|
|
3788
|
+
var originalGenerateId3 = createIdGenerator({ prefix: "aiobj", size: 24 });
|
|
3789
|
+
function createDownload(options) {
|
|
3790
|
+
return ({ url, abortSignal }) => download({ url, maxBytes: options == null ? void 0 : options.maxBytes, abortSignal });
|
|
3791
|
+
}
|
|
3792
|
+
var originalGenerateId4 = createIdGenerator({ prefix: "aiobj", size: 24 });
|
|
3793
|
+
var defaultDownload = createDownload();
|
|
3794
|
+
var name21 = "AI_NoSuchProviderError";
|
|
3795
|
+
var marker21 = `vercel.ai.error.${name21}`;
|
|
3796
|
+
var symbol21 = Symbol.for(marker21);
|
|
3797
|
+
var _a21;
|
|
3798
|
+
_a21 = symbol21;
|
|
3799
|
+
var defaultDownload2 = createDownload();
|
|
3800
|
+
var HttpChatTransport = class {
|
|
3801
|
+
constructor({
|
|
3802
|
+
api = "/api/chat",
|
|
3803
|
+
credentials,
|
|
3804
|
+
headers,
|
|
3805
|
+
body,
|
|
3806
|
+
fetch: fetch2,
|
|
3807
|
+
prepareSendMessagesRequest,
|
|
3808
|
+
prepareReconnectToStreamRequest
|
|
3809
|
+
}) {
|
|
3810
|
+
this.api = api;
|
|
3811
|
+
this.credentials = credentials;
|
|
3812
|
+
this.headers = headers;
|
|
3813
|
+
this.body = body;
|
|
3814
|
+
this.fetch = fetch2;
|
|
3815
|
+
this.prepareSendMessagesRequest = prepareSendMessagesRequest;
|
|
3816
|
+
this.prepareReconnectToStreamRequest = prepareReconnectToStreamRequest;
|
|
3817
|
+
}
|
|
3818
|
+
async sendMessages({
|
|
3819
|
+
abortSignal,
|
|
3820
|
+
...options
|
|
3821
|
+
}) {
|
|
3822
|
+
var _a222, _b16, _c, _d, _e;
|
|
3823
|
+
const resolvedBody = await resolve(this.body);
|
|
3824
|
+
const resolvedHeaders = await resolve(this.headers);
|
|
3825
|
+
const resolvedCredentials = await resolve(this.credentials);
|
|
3826
|
+
const baseHeaders = {
|
|
3827
|
+
...normalizeHeaders(resolvedHeaders),
|
|
3828
|
+
...normalizeHeaders(options.headers)
|
|
3829
|
+
};
|
|
3830
|
+
const preparedRequest = await ((_a222 = this.prepareSendMessagesRequest) == null ? void 0 : _a222.call(this, {
|
|
3831
|
+
api: this.api,
|
|
3832
|
+
id: options.chatId,
|
|
3833
|
+
messages: options.messages,
|
|
3834
|
+
body: { ...resolvedBody, ...options.body },
|
|
3835
|
+
headers: baseHeaders,
|
|
3836
|
+
credentials: resolvedCredentials,
|
|
3837
|
+
requestMetadata: options.metadata,
|
|
3838
|
+
trigger: options.trigger,
|
|
3839
|
+
messageId: options.messageId
|
|
3840
|
+
}));
|
|
3841
|
+
const api = (_b16 = preparedRequest == null ? void 0 : preparedRequest.api) != null ? _b16 : this.api;
|
|
3842
|
+
const headers = (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? normalizeHeaders(preparedRequest.headers) : baseHeaders;
|
|
3843
|
+
const body = (preparedRequest == null ? void 0 : preparedRequest.body) !== void 0 ? preparedRequest.body : {
|
|
3844
|
+
...resolvedBody,
|
|
3845
|
+
...options.body,
|
|
3846
|
+
id: options.chatId,
|
|
3847
|
+
messages: options.messages,
|
|
3848
|
+
trigger: options.trigger,
|
|
3849
|
+
messageId: options.messageId
|
|
3850
|
+
};
|
|
3851
|
+
const credentials = (_c = preparedRequest == null ? void 0 : preparedRequest.credentials) != null ? _c : resolvedCredentials;
|
|
3852
|
+
const fetch2 = (_d = this.fetch) != null ? _d : globalThis.fetch;
|
|
3853
|
+
const response = await fetch2(api, {
|
|
3854
|
+
method: "POST",
|
|
3855
|
+
headers: {
|
|
3856
|
+
"Content-Type": "application/json",
|
|
3857
|
+
...headers
|
|
3858
|
+
},
|
|
3859
|
+
body: JSON.stringify(body),
|
|
3860
|
+
credentials,
|
|
3861
|
+
signal: abortSignal
|
|
3862
|
+
});
|
|
3863
|
+
if (!response.ok) {
|
|
3864
|
+
throw new Error(
|
|
3865
|
+
(_e = await response.text()) != null ? _e : "Failed to fetch the chat response."
|
|
3866
|
+
);
|
|
3867
|
+
}
|
|
3868
|
+
if (!response.body) {
|
|
3869
|
+
throw new Error("The response body is empty.");
|
|
3870
|
+
}
|
|
3871
|
+
return this.processResponseStream(response.body);
|
|
3872
|
+
}
|
|
3873
|
+
async reconnectToStream(options) {
|
|
3874
|
+
var _a222, _b16, _c, _d, _e;
|
|
3875
|
+
const resolvedBody = await resolve(this.body);
|
|
3876
|
+
const resolvedHeaders = await resolve(this.headers);
|
|
3877
|
+
const resolvedCredentials = await resolve(this.credentials);
|
|
3878
|
+
const baseHeaders = {
|
|
3879
|
+
...normalizeHeaders(resolvedHeaders),
|
|
3880
|
+
...normalizeHeaders(options.headers)
|
|
3881
|
+
};
|
|
3882
|
+
const preparedRequest = await ((_a222 = this.prepareReconnectToStreamRequest) == null ? void 0 : _a222.call(this, {
|
|
3883
|
+
api: this.api,
|
|
3884
|
+
id: options.chatId,
|
|
3885
|
+
body: { ...resolvedBody, ...options.body },
|
|
3886
|
+
headers: baseHeaders,
|
|
3887
|
+
credentials: resolvedCredentials,
|
|
3888
|
+
requestMetadata: options.metadata
|
|
3889
|
+
}));
|
|
3890
|
+
const api = (_b16 = preparedRequest == null ? void 0 : preparedRequest.api) != null ? _b16 : `${this.api}/${options.chatId}/stream`;
|
|
3891
|
+
const headers = (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? normalizeHeaders(preparedRequest.headers) : baseHeaders;
|
|
3892
|
+
const credentials = (_c = preparedRequest == null ? void 0 : preparedRequest.credentials) != null ? _c : resolvedCredentials;
|
|
3893
|
+
const fetch2 = (_d = this.fetch) != null ? _d : globalThis.fetch;
|
|
3894
|
+
const response = await fetch2(api, {
|
|
3895
|
+
method: "GET",
|
|
3896
|
+
headers,
|
|
3897
|
+
credentials
|
|
3898
|
+
});
|
|
3899
|
+
if (response.status === 204) {
|
|
3900
|
+
return null;
|
|
3901
|
+
}
|
|
3902
|
+
if (!response.ok) {
|
|
3903
|
+
throw new Error(
|
|
3904
|
+
(_e = await response.text()) != null ? _e : "Failed to fetch the chat response."
|
|
3905
|
+
);
|
|
3906
|
+
}
|
|
3907
|
+
if (!response.body) {
|
|
3908
|
+
throw new Error("The response body is empty.");
|
|
3909
|
+
}
|
|
3910
|
+
return this.processResponseStream(response.body);
|
|
3911
|
+
}
|
|
3912
|
+
};
|
|
3913
|
+
var DefaultChatTransport = class extends HttpChatTransport {
|
|
3914
|
+
constructor(options = {}) {
|
|
3915
|
+
super(options);
|
|
3916
|
+
}
|
|
3917
|
+
processResponseStream(stream) {
|
|
3918
|
+
return parseJsonEventStream({
|
|
3919
|
+
stream,
|
|
3920
|
+
schema: uiMessageChunkSchema
|
|
3921
|
+
}).pipeThrough(
|
|
3922
|
+
new TransformStream({
|
|
3923
|
+
async transform(chunk, controller) {
|
|
3924
|
+
if (!chunk.success) {
|
|
3925
|
+
throw chunk.error;
|
|
3926
|
+
}
|
|
3927
|
+
controller.enqueue(chunk.value);
|
|
3928
|
+
}
|
|
3929
|
+
})
|
|
3930
|
+
);
|
|
3931
|
+
}
|
|
3932
|
+
};
|
|
3933
|
+
function lastAssistantMessageIsCompleteWithApprovalResponses({
|
|
3934
|
+
messages
|
|
3935
|
+
}) {
|
|
3936
|
+
const message = messages[messages.length - 1];
|
|
3937
|
+
if (!message) {
|
|
3938
|
+
return false;
|
|
3939
|
+
}
|
|
3940
|
+
if (message.role !== "assistant") {
|
|
3941
|
+
return false;
|
|
3942
|
+
}
|
|
3943
|
+
const lastStepStartIndex = message.parts.reduce((lastIndex, part, index) => {
|
|
3944
|
+
return part.type === "step-start" ? index : lastIndex;
|
|
3945
|
+
}, -1);
|
|
3946
|
+
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolUIPart);
|
|
3947
|
+
return (
|
|
3948
|
+
// has at least one tool approval response
|
|
3949
|
+
lastStepToolInvocations.filter((part) => part.state === "approval-responded").length > 0 && // all tool approvals must have a response
|
|
3950
|
+
lastStepToolInvocations.every(
|
|
3951
|
+
(part) => part.state === "output-available" || part.state === "output-error" || part.state === "approval-responded"
|
|
3952
|
+
)
|
|
3953
|
+
);
|
|
3954
|
+
}
|
|
3955
|
+
function lastAssistantMessageIsCompleteWithToolCalls({
|
|
3956
|
+
messages
|
|
3957
|
+
}) {
|
|
3958
|
+
const message = messages[messages.length - 1];
|
|
3959
|
+
if (!message) {
|
|
3960
|
+
return false;
|
|
3961
|
+
}
|
|
3962
|
+
if (message.role !== "assistant") {
|
|
3963
|
+
return false;
|
|
3964
|
+
}
|
|
3965
|
+
const lastStepStartIndex = message.parts.reduce((lastIndex, part, index) => {
|
|
3966
|
+
return part.type === "step-start" ? index : lastIndex;
|
|
3967
|
+
}, -1);
|
|
3968
|
+
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolUIPart).filter((part) => !part.providerExecuted);
|
|
3969
|
+
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every(
|
|
3970
|
+
(part) => part.state === "output-available" || part.state === "output-error"
|
|
3971
|
+
);
|
|
3972
|
+
}
|
|
3973
|
+
|
|
3974
|
+
// ../agent-sdk/dist/schemas.js
|
|
3975
|
+
import z32 from "zod";
|
|
3976
|
+
import z9 from "zod";
|
|
3977
|
+
import z22 from "zod";
|
|
3978
|
+
import { z as z43 } from "zod";
|
|
3979
|
+
var VersionSelectorSchema = z9.union([
|
|
3980
|
+
z9.literal("latest").describe("Latest version (draft if available, otherwise latest published). This is the default if left empty"),
|
|
3981
|
+
z9.literal("published").describe("Last published version (fallback to draft if no published version exists)"),
|
|
3982
|
+
z9.number().min(1).describe("Specific version number (1, 2, 3...)")
|
|
3983
|
+
]);
|
|
3984
|
+
var FeedbackRatingSchema = z22.enum(["positive", "negative"]);
|
|
3985
|
+
var CreateFeedbackRequestSchema = z32.object({
|
|
3986
|
+
agentId: z32.string(),
|
|
3987
|
+
agentVersion: VersionSelectorSchema.optional(),
|
|
3988
|
+
threadId: z32.string().min(1),
|
|
3989
|
+
messageId: z32.string().min(1),
|
|
3990
|
+
// these can be undefined (not provided - use old values) or null (explicitly clear values)
|
|
3991
|
+
rating: FeedbackRatingSchema.nullish(),
|
|
3992
|
+
improvementText: z32.string().nullish(),
|
|
3993
|
+
// Array of notes with optional noteId + free-form key/value pairs
|
|
3994
|
+
notes: z32.array(z32.record(z32.string(), z32.any())).optional()
|
|
3995
|
+
});
|
|
3996
|
+
var ChoicesFieldSchema = z43.object({
|
|
3997
|
+
type: z43.literal("choices"),
|
|
3998
|
+
name: z43.string(),
|
|
3999
|
+
label: z43.string(),
|
|
4000
|
+
options: z43.array(z43.object({
|
|
4001
|
+
label: z43.string(),
|
|
4002
|
+
value: z43.string(),
|
|
4003
|
+
description: z43.string().optional()
|
|
4004
|
+
})).min(2),
|
|
4005
|
+
multiSelect: z43.boolean().optional(),
|
|
4006
|
+
required: z43.boolean().optional(),
|
|
4007
|
+
defaultValue: z43.union([z43.string(), z43.array(z43.string())]).optional()
|
|
4008
|
+
});
|
|
4009
|
+
var TextFieldSchema = z43.object({
|
|
4010
|
+
type: z43.literal("text"),
|
|
4011
|
+
name: z43.string(),
|
|
4012
|
+
label: z43.string(),
|
|
4013
|
+
placeholder: z43.string().optional(),
|
|
4014
|
+
multiline: z43.boolean().optional(),
|
|
4015
|
+
required: z43.boolean().optional(),
|
|
4016
|
+
defaultValue: z43.string().optional()
|
|
4017
|
+
});
|
|
4018
|
+
var NumberFieldSchema = z43.object({
|
|
4019
|
+
type: z43.literal("number"),
|
|
4020
|
+
name: z43.string(),
|
|
4021
|
+
label: z43.string(),
|
|
4022
|
+
min: z43.number().optional(),
|
|
4023
|
+
max: z43.number().optional(),
|
|
4024
|
+
required: z43.boolean().optional(),
|
|
4025
|
+
defaultValue: z43.number().optional()
|
|
4026
|
+
});
|
|
4027
|
+
var CheckboxFieldSchema = z43.object({
|
|
4028
|
+
type: z43.literal("checkbox"),
|
|
4029
|
+
name: z43.string(),
|
|
4030
|
+
label: z43.string(),
|
|
4031
|
+
defaultValue: z43.boolean().optional()
|
|
4032
|
+
});
|
|
4033
|
+
var DateFieldSchema = z43.object({
|
|
4034
|
+
type: z43.literal("date"),
|
|
4035
|
+
name: z43.string(),
|
|
4036
|
+
label: z43.string(),
|
|
4037
|
+
required: z43.boolean().optional(),
|
|
4038
|
+
defaultValue: z43.string().optional()
|
|
4039
|
+
// ISO date string
|
|
4040
|
+
});
|
|
4041
|
+
var InputFieldSchema = z43.discriminatedUnion("type", [
|
|
4042
|
+
ChoicesFieldSchema,
|
|
4043
|
+
TextFieldSchema,
|
|
4044
|
+
NumberFieldSchema,
|
|
4045
|
+
CheckboxFieldSchema,
|
|
4046
|
+
DateFieldSchema
|
|
4047
|
+
]);
|
|
4048
|
+
var CollectUserInputArgsSchema = z43.object({
|
|
4049
|
+
title: z43.string().optional(),
|
|
4050
|
+
description: z43.string().optional(),
|
|
4051
|
+
fields: z43.array(InputFieldSchema).min(1),
|
|
4052
|
+
submitLabel: z43.string().optional(),
|
|
4053
|
+
cancelLabel: z43.string().optional(),
|
|
4054
|
+
allowFreeformResponse: z43.boolean().optional().default(true)
|
|
4055
|
+
});
|
|
4056
|
+
var voiceTableWidgetDefinition = {
|
|
4057
|
+
widgetType: "table",
|
|
4058
|
+
schema: {
|
|
4059
|
+
type: "object",
|
|
4060
|
+
description: "Display a comparison or other tabular details beside the spoken answer.",
|
|
4061
|
+
properties: {
|
|
4062
|
+
title: { type: "string", description: "Short descriptive title for the table." },
|
|
4063
|
+
markdown: { type: "string", description: "A Markdown table with a header row, separator row, and data rows. Use accurate retrieved values. Do not include code fences or narrative." }
|
|
4064
|
+
},
|
|
4065
|
+
required: ["markdown"],
|
|
4066
|
+
additionalProperties: false
|
|
4067
|
+
}
|
|
4068
|
+
};
|
|
4069
|
+
var commonProperties = {
|
|
4070
|
+
title: { type: "string", description: "Short chart title." },
|
|
4071
|
+
description: { type: "string", description: "Optional context, period, or source note." },
|
|
4072
|
+
valueLabel: { type: "string", description: "Metric and unit, e.g. Monthly premium ($), Employees, or Coverage (%). Keep all values in the same unit." }
|
|
4073
|
+
};
|
|
4074
|
+
var categoryData = (nonnegative = false) => ({
|
|
4075
|
+
type: "array",
|
|
4076
|
+
minItems: 1,
|
|
4077
|
+
maxItems: nonnegative ? 12 : 40,
|
|
4078
|
+
items: {
|
|
4079
|
+
type: "object",
|
|
4080
|
+
properties: { label: { type: "string" }, value: { type: "number", ...nonnegative ? { minimum: 0 } : {} } },
|
|
4081
|
+
required: ["label", "value"],
|
|
4082
|
+
additionalProperties: false
|
|
4083
|
+
}
|
|
4084
|
+
});
|
|
4085
|
+
var voiceChartWidgetDefinitions = [
|
|
4086
|
+
{
|
|
4087
|
+
widgetType: "bar_chart",
|
|
4088
|
+
schema: {
|
|
4089
|
+
type: "object",
|
|
4090
|
+
description: "Compare numeric values across categories. Prefer one chart for related values in the same unit; do not mix dollars and percentages.",
|
|
4091
|
+
properties: { ...commonProperties, data: categoryData() },
|
|
4092
|
+
required: ["title", "data"],
|
|
4093
|
+
additionalProperties: false
|
|
4094
|
+
}
|
|
4095
|
+
},
|
|
4096
|
+
{
|
|
4097
|
+
widgetType: "line_chart",
|
|
4098
|
+
schema: {
|
|
4099
|
+
type: "object",
|
|
4100
|
+
description: "Show one or more trends over ordered time points. Values keys must match series keys. Omit a missing value instead of inventing zero.",
|
|
4101
|
+
properties: {
|
|
4102
|
+
...commonProperties,
|
|
4103
|
+
series: {
|
|
4104
|
+
type: "array",
|
|
4105
|
+
minItems: 1,
|
|
4106
|
+
maxItems: 6,
|
|
4107
|
+
items: { type: "object", properties: { key: { type: "string" }, label: { type: "string" } }, required: ["key", "label"], additionalProperties: false }
|
|
4108
|
+
},
|
|
4109
|
+
data: {
|
|
4110
|
+
type: "array",
|
|
4111
|
+
minItems: 2,
|
|
4112
|
+
maxItems: 100,
|
|
4113
|
+
items: {
|
|
4114
|
+
type: "object",
|
|
4115
|
+
properties: { label: { type: "string" }, values: { type: "object", additionalProperties: { type: "number" } } },
|
|
4116
|
+
required: ["label", "values"],
|
|
4117
|
+
additionalProperties: false
|
|
4118
|
+
}
|
|
4119
|
+
}
|
|
4120
|
+
},
|
|
4121
|
+
required: ["title", "series", "data"],
|
|
4122
|
+
additionalProperties: false
|
|
4123
|
+
}
|
|
4124
|
+
},
|
|
4125
|
+
{
|
|
4126
|
+
widgetType: "pie_chart",
|
|
4127
|
+
schema: {
|
|
4128
|
+
type: "object",
|
|
4129
|
+
description: "Show parts of one whole as a donut. Values must be nonnegative and total above zero. Use bar_chart for unrelated comparisons or negative values.",
|
|
4130
|
+
properties: { ...commonProperties, centerLabel: { type: "string", description: "Short label underneath the total in the donut center." }, data: categoryData(true) },
|
|
4131
|
+
required: ["title", "data"],
|
|
4132
|
+
additionalProperties: false
|
|
4133
|
+
}
|
|
4134
|
+
}
|
|
4135
|
+
];
|
|
4136
|
+
var INTERRUPTED_TOOL_ERROR = "Interrupted before completion.";
|
|
4137
|
+
function markInterruptedTools(message) {
|
|
4138
|
+
return {
|
|
4139
|
+
...message,
|
|
4140
|
+
parts: message.parts.map((part) => {
|
|
4141
|
+
if ((part.type.startsWith("tool-") || part.type === "dynamic-tool") && "state" in part && (part.state === "input-streaming" || part.state === "input-available")) {
|
|
4142
|
+
return { ...part, state: "output-error", input: part.input ?? {}, errorText: INTERRUPTED_TOOL_ERROR };
|
|
4143
|
+
}
|
|
4144
|
+
return part;
|
|
4145
|
+
})
|
|
4146
|
+
};
|
|
4147
|
+
}
|
|
4148
|
+
|
|
4149
|
+
// lib/ui-widgets.ts
|
|
4150
|
+
var SDK_WIDGET_MARKER = /* @__PURE__ */ Symbol("__isSDKWidget");
|
|
4151
|
+
function isSDKWidget(widget) {
|
|
4152
|
+
return SDK_WIDGET_MARKER in widget && widget[SDK_WIDGET_MARKER] === true;
|
|
4153
|
+
}
|
|
4154
|
+
function createSDKWidget(widget) {
|
|
4155
|
+
return {
|
|
4156
|
+
...widget,
|
|
4157
|
+
[SDK_WIDGET_MARKER]: true
|
|
4158
|
+
};
|
|
4159
|
+
}
|
|
4160
|
+
var createWidget = (widget) => widget;
|
|
4161
|
+
|
|
4162
|
+
export {
|
|
4163
|
+
jsonSchema,
|
|
4164
|
+
asSchema,
|
|
4165
|
+
DefaultChatTransport,
|
|
4166
|
+
lastAssistantMessageIsCompleteWithApprovalResponses,
|
|
4167
|
+
lastAssistantMessageIsCompleteWithToolCalls,
|
|
4168
|
+
voiceTableWidgetDefinition,
|
|
4169
|
+
voiceChartWidgetDefinitions,
|
|
4170
|
+
INTERRUPTED_TOOL_ERROR,
|
|
4171
|
+
markInterruptedTools,
|
|
4172
|
+
SDK_WIDGET_MARKER,
|
|
4173
|
+
isSDKWidget,
|
|
4174
|
+
createSDKWidget,
|
|
4175
|
+
createWidget
|
|
4176
|
+
};
|
|
4177
|
+
//# sourceMappingURL=chunk-LQHHZ2OJ.js.map
|