@mastra/schema-compat 0.0.0-add-save-score-validation-on-stores-20250911031242
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +177 -0
- package/LICENSE.md +15 -0
- package/README.md +144 -0
- package/dist/chunk-7YUR5KZ5.cjs +34 -0
- package/dist/chunk-7YUR5KZ5.cjs.map +1 -0
- package/dist/chunk-GWTUXMDD.js +28 -0
- package/dist/chunk-GWTUXMDD.js.map +1 -0
- package/dist/index.cjs +1424 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1399 -0
- package/dist/index.js.map +1 -0
- package/dist/provider-compats/anthropic.d.ts +13 -0
- package/dist/provider-compats/anthropic.d.ts.map +1 -0
- package/dist/provider-compats/deepseek.d.ts +13 -0
- package/dist/provider-compats/deepseek.d.ts.map +1 -0
- package/dist/provider-compats/google.d.ts +13 -0
- package/dist/provider-compats/google.d.ts.map +1 -0
- package/dist/provider-compats/meta.d.ts +13 -0
- package/dist/provider-compats/meta.d.ts.map +1 -0
- package/dist/provider-compats/openai-reasoning.d.ts +14 -0
- package/dist/provider-compats/openai-reasoning.d.ts.map +1 -0
- package/dist/provider-compats/openai.d.ts +13 -0
- package/dist/provider-compats/openai.d.ts.map +1 -0
- package/dist/schema-compatibility-v3.d.ts +319 -0
- package/dist/schema-compatibility-v3.d.ts.map +1 -0
- package/dist/schema-compatibility-v4.d.ts +310 -0
- package/dist/schema-compatibility-v4.d.ts.map +1 -0
- package/dist/schema-compatibility.d.ts +228 -0
- package/dist/schema-compatibility.d.ts.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils-test-suite.d.ts +2 -0
- package/dist/utils-test-suite.d.ts.map +1 -0
- package/dist/utils.d.ts +96 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/zod-to-json.cjs +12 -0
- package/dist/zod-to-json.cjs.map +1 -0
- package/dist/zod-to-json.d.ts +6 -0
- package/dist/zod-to-json.d.ts.map +1 -0
- package/dist/zod-to-json.js +3 -0
- package/dist/zod-to-json.js.map +1 -0
- package/dist/zodTypes.d.ts +21 -0
- package/dist/zodTypes.d.ts.map +1 -0
- package/package.json +80 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1399 @@
|
|
|
1
|
+
import { zodToJsonSchema } from './chunk-GWTUXMDD.js';
|
|
2
|
+
import { z, ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, ZodNull, ZodDate, ZodDefault } from 'zod';
|
|
3
|
+
import { jsonSchema } from 'ai';
|
|
4
|
+
import { convertJsonSchemaToZod } from 'zod-from-json-schema';
|
|
5
|
+
import { convertJsonSchemaToZod as convertJsonSchemaToZod$1 } from 'zod-from-json-schema-v3';
|
|
6
|
+
import { ZodOptional as ZodOptional$1, ZodObject as ZodObject$1, ZodNull as ZodNull$1, ZodArray as ZodArray$1, ZodUnion as ZodUnion$1, ZodString as ZodString$1, ZodNumber as ZodNumber$1, ZodDate as ZodDate$1, ZodDefault as ZodDefault$1, z as z$1 } from 'zod/v4';
|
|
7
|
+
|
|
8
|
+
function convertZodSchemaToAISDKSchema(zodSchema, target = "jsonSchema7") {
|
|
9
|
+
const jsonSchemaToUse = zodToJsonSchema(zodSchema, target);
|
|
10
|
+
return jsonSchema(jsonSchemaToUse, {
|
|
11
|
+
validate: (value) => {
|
|
12
|
+
const result = zodSchema.safeParse(value);
|
|
13
|
+
return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function isZodType(value) {
|
|
18
|
+
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
19
|
+
}
|
|
20
|
+
function convertSchemaToZod(schema) {
|
|
21
|
+
if (isZodType(schema)) {
|
|
22
|
+
return schema;
|
|
23
|
+
} else {
|
|
24
|
+
const jsonSchemaToConvert = "jsonSchema" in schema ? schema.jsonSchema : schema;
|
|
25
|
+
try {
|
|
26
|
+
if ("toJSONSchema" in z) {
|
|
27
|
+
return convertJsonSchemaToZod(jsonSchemaToConvert);
|
|
28
|
+
} else {
|
|
29
|
+
return convertJsonSchemaToZod$1(jsonSchemaToConvert);
|
|
30
|
+
}
|
|
31
|
+
} catch (e) {
|
|
32
|
+
const errorMessage = `[Schema Builder] Failed to convert schema parameters to Zod. Original schema: ${JSON.stringify(jsonSchemaToConvert)}`;
|
|
33
|
+
console.error(errorMessage, e);
|
|
34
|
+
throw new Error(errorMessage + (e instanceof Error ? `
|
|
35
|
+
${e.stack}` : "\nUnknown error object"));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function applyCompatLayer({
|
|
40
|
+
schema,
|
|
41
|
+
compatLayers,
|
|
42
|
+
mode
|
|
43
|
+
}) {
|
|
44
|
+
let zodSchema;
|
|
45
|
+
if (!isZodType(schema)) {
|
|
46
|
+
zodSchema = convertSchemaToZod(schema);
|
|
47
|
+
} else {
|
|
48
|
+
zodSchema = schema;
|
|
49
|
+
}
|
|
50
|
+
for (const compat of compatLayers) {
|
|
51
|
+
if (compat.shouldApply()) {
|
|
52
|
+
return mode === "jsonSchema" ? compat.processToJSONSchema(zodSchema) : compat.processToAISDKSchema(zodSchema);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (mode === "jsonSchema") {
|
|
56
|
+
return zodToJsonSchema(zodSchema, "jsonSchema7");
|
|
57
|
+
} else {
|
|
58
|
+
return convertZodSchemaToAISDKSchema(zodSchema);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/schema-compatibility-v3.ts
|
|
63
|
+
var ALL_STRING_CHECKS = ["regex", "emoji", "email", "url", "uuid", "cuid", "min", "max"];
|
|
64
|
+
var ALL_NUMBER_CHECKS = [
|
|
65
|
+
"min",
|
|
66
|
+
// gte internally
|
|
67
|
+
"max",
|
|
68
|
+
// lte internally
|
|
69
|
+
"multipleOf"
|
|
70
|
+
];
|
|
71
|
+
var ALL_ARRAY_CHECKS = ["min", "max", "length"];
|
|
72
|
+
var isOptional = (v) => v instanceof ZodOptional;
|
|
73
|
+
var isObj = (v) => v instanceof ZodObject;
|
|
74
|
+
var isArr = (v) => v instanceof ZodArray;
|
|
75
|
+
var isUnion = (v) => v instanceof ZodUnion;
|
|
76
|
+
var isString = (v) => v instanceof ZodString;
|
|
77
|
+
var isNumber = (v) => v instanceof ZodNumber;
|
|
78
|
+
var UNSUPPORTED_ZOD_TYPES = ["ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
|
|
79
|
+
var SUPPORTED_ZOD_TYPES = [
|
|
80
|
+
"ZodObject",
|
|
81
|
+
"ZodArray",
|
|
82
|
+
"ZodUnion",
|
|
83
|
+
"ZodString",
|
|
84
|
+
"ZodNumber",
|
|
85
|
+
"ZodDate",
|
|
86
|
+
"ZodAny",
|
|
87
|
+
"ZodDefault"
|
|
88
|
+
];
|
|
89
|
+
var ALL_ZOD_TYPES = [...SUPPORTED_ZOD_TYPES, ...UNSUPPORTED_ZOD_TYPES];
|
|
90
|
+
var SchemaCompatLayer = class {
|
|
91
|
+
model;
|
|
92
|
+
parent;
|
|
93
|
+
/**
|
|
94
|
+
* Creates a new schema compatibility instance.
|
|
95
|
+
*
|
|
96
|
+
* @param model - The language model this compatibility layer applies to
|
|
97
|
+
*/
|
|
98
|
+
constructor(model, parent) {
|
|
99
|
+
this.model = model;
|
|
100
|
+
this.parent = parent;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Gets the language model associated with this compatibility layer.
|
|
104
|
+
*
|
|
105
|
+
* @returns The language model instance
|
|
106
|
+
*/
|
|
107
|
+
getModel() {
|
|
108
|
+
return this.model;
|
|
109
|
+
}
|
|
110
|
+
getUnsupportedZodTypes() {
|
|
111
|
+
return UNSUPPORTED_ZOD_TYPES;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Type guard for optional Zod types
|
|
115
|
+
*/
|
|
116
|
+
isOptional(v) {
|
|
117
|
+
return v instanceof ZodOptional;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Type guard for object Zod types
|
|
121
|
+
*/
|
|
122
|
+
isObj(v) {
|
|
123
|
+
return v instanceof ZodObject;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Type guard for null Zod types
|
|
127
|
+
*/
|
|
128
|
+
isNull(v) {
|
|
129
|
+
return v instanceof ZodNull;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Type guard for array Zod types
|
|
133
|
+
*/
|
|
134
|
+
isArr(v) {
|
|
135
|
+
return v instanceof ZodArray;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Type guard for union Zod types
|
|
139
|
+
*/
|
|
140
|
+
isUnion(v) {
|
|
141
|
+
return v instanceof ZodUnion;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Type guard for string Zod types
|
|
145
|
+
*/
|
|
146
|
+
isString(v) {
|
|
147
|
+
return v instanceof ZodString;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Type guard for number Zod types
|
|
151
|
+
*/
|
|
152
|
+
isNumber(v) {
|
|
153
|
+
return v instanceof ZodNumber;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Type guard for date Zod types
|
|
157
|
+
*/
|
|
158
|
+
isDate(v) {
|
|
159
|
+
return v instanceof ZodDate;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Type guard for default Zod types
|
|
163
|
+
*/
|
|
164
|
+
isDefault(v) {
|
|
165
|
+
return v instanceof ZodDefault;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Determines whether this compatibility layer should be applied for the current model.
|
|
169
|
+
*
|
|
170
|
+
* @returns True if this compatibility layer should be used, false otherwise
|
|
171
|
+
* @abstract
|
|
172
|
+
*/
|
|
173
|
+
shouldApply() {
|
|
174
|
+
return this.parent.shouldApply();
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Returns the JSON Schema target format for this provider.
|
|
178
|
+
*
|
|
179
|
+
* @returns The schema target format, or undefined to use the default 'jsonSchema7'
|
|
180
|
+
* @abstract
|
|
181
|
+
*/
|
|
182
|
+
getSchemaTarget() {
|
|
183
|
+
return this.parent.getSchemaTarget();
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Processes a specific Zod type according to the provider's requirements.
|
|
187
|
+
*
|
|
188
|
+
* @param value - The Zod type to process
|
|
189
|
+
* @returns The processed Zod type
|
|
190
|
+
* @abstract
|
|
191
|
+
*/
|
|
192
|
+
processZodType(value) {
|
|
193
|
+
return this.parent.processZodType(value);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Default handler for Zod object types. Recursively processes all properties in the object.
|
|
197
|
+
*
|
|
198
|
+
* @param value - The Zod object to process
|
|
199
|
+
* @returns The processed Zod object
|
|
200
|
+
*/
|
|
201
|
+
defaultZodObjectHandler(value, options = { passthrough: true }) {
|
|
202
|
+
const processedShape = Object.entries(value.shape).reduce((acc, [key, propValue]) => {
|
|
203
|
+
acc[key] = this.processZodType(propValue);
|
|
204
|
+
return acc;
|
|
205
|
+
}, {});
|
|
206
|
+
let result = z.object(processedShape);
|
|
207
|
+
if (value._def.unknownKeys === "strict") {
|
|
208
|
+
result = result.strict();
|
|
209
|
+
}
|
|
210
|
+
if (value._def.catchall && !(value._def.catchall instanceof z.ZodNever)) {
|
|
211
|
+
result = result.catchall(value._def.catchall);
|
|
212
|
+
}
|
|
213
|
+
if (value.description) {
|
|
214
|
+
result = result.describe(value.description);
|
|
215
|
+
}
|
|
216
|
+
if (options.passthrough && value._def.unknownKeys === "passthrough") {
|
|
217
|
+
result = result.passthrough();
|
|
218
|
+
}
|
|
219
|
+
return result;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Merges validation constraints into a parameter description.
|
|
223
|
+
*
|
|
224
|
+
* This helper method converts validation constraints that may not be supported
|
|
225
|
+
* by a provider into human-readable descriptions.
|
|
226
|
+
*
|
|
227
|
+
* @param description - The existing parameter description
|
|
228
|
+
* @param constraints - The validation constraints to merge
|
|
229
|
+
* @returns The updated description with constraints, or undefined if no constraints
|
|
230
|
+
*/
|
|
231
|
+
mergeParameterDescription(description, constraints) {
|
|
232
|
+
if (Object.keys(constraints).length > 0) {
|
|
233
|
+
return (description ? description + "\n" : "") + JSON.stringify(constraints);
|
|
234
|
+
} else {
|
|
235
|
+
return description;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Default handler for unsupported Zod types. Throws an error for specified unsupported types.
|
|
240
|
+
*
|
|
241
|
+
* @param value - The Zod type to check
|
|
242
|
+
* @param throwOnTypes - Array of type names to throw errors for
|
|
243
|
+
* @returns The original value if not in the throw list
|
|
244
|
+
* @throws Error if the type is in the unsupported list
|
|
245
|
+
*/
|
|
246
|
+
defaultUnsupportedZodTypeHandler(value, throwOnTypes = UNSUPPORTED_ZOD_TYPES) {
|
|
247
|
+
if (throwOnTypes.includes(value._def?.typeName)) {
|
|
248
|
+
throw new Error(`${this.model.modelId} does not support zod type: ${value._def?.typeName}`);
|
|
249
|
+
}
|
|
250
|
+
return value;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Default handler for Zod array types. Processes array constraints according to provider support.
|
|
254
|
+
*
|
|
255
|
+
* @param value - The Zod array to process
|
|
256
|
+
* @param handleChecks - Array constraints to convert to descriptions vs keep as validation
|
|
257
|
+
* @returns The processed Zod array
|
|
258
|
+
*/
|
|
259
|
+
defaultZodArrayHandler(value, handleChecks = ALL_ARRAY_CHECKS) {
|
|
260
|
+
const zodArrayDef = value._def;
|
|
261
|
+
const processedType = this.processZodType(zodArrayDef.type);
|
|
262
|
+
let result = z.array(processedType);
|
|
263
|
+
const constraints = {};
|
|
264
|
+
if (zodArrayDef.minLength?.value !== void 0) {
|
|
265
|
+
if (handleChecks.includes("min")) {
|
|
266
|
+
constraints.minLength = zodArrayDef.minLength.value;
|
|
267
|
+
} else {
|
|
268
|
+
result = result.min(zodArrayDef.minLength.value);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (zodArrayDef.maxLength?.value !== void 0) {
|
|
272
|
+
if (handleChecks.includes("max")) {
|
|
273
|
+
constraints.maxLength = zodArrayDef.maxLength.value;
|
|
274
|
+
} else {
|
|
275
|
+
result = result.max(zodArrayDef.maxLength.value);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (zodArrayDef.exactLength?.value !== void 0) {
|
|
279
|
+
if (handleChecks.includes("length")) {
|
|
280
|
+
constraints.exactLength = zodArrayDef.exactLength.value;
|
|
281
|
+
} else {
|
|
282
|
+
result = result.length(zodArrayDef.exactLength.value);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const description = this.mergeParameterDescription(value.description, constraints);
|
|
286
|
+
if (description) {
|
|
287
|
+
result = result.describe(description);
|
|
288
|
+
}
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Default handler for Zod union types. Processes all union options.
|
|
293
|
+
*
|
|
294
|
+
* @param value - The Zod union to process
|
|
295
|
+
* @returns The processed Zod union
|
|
296
|
+
* @throws Error if union has fewer than 2 options
|
|
297
|
+
*/
|
|
298
|
+
defaultZodUnionHandler(value) {
|
|
299
|
+
const processedOptions = value._def.options.map((option) => this.processZodType(option));
|
|
300
|
+
if (processedOptions.length < 2) throw new Error("Union must have at least 2 options");
|
|
301
|
+
let result = z.union(processedOptions);
|
|
302
|
+
if (value.description) {
|
|
303
|
+
result = result.describe(value.description);
|
|
304
|
+
}
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Default handler for Zod string types. Processes string validation constraints.
|
|
309
|
+
*
|
|
310
|
+
* @param value - The Zod string to process
|
|
311
|
+
* @param handleChecks - String constraints to convert to descriptions vs keep as validation
|
|
312
|
+
* @returns The processed Zod string
|
|
313
|
+
*/
|
|
314
|
+
defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS) {
|
|
315
|
+
const constraints = {};
|
|
316
|
+
const checks = value._def.checks || [];
|
|
317
|
+
const newChecks = [];
|
|
318
|
+
for (const check of checks) {
|
|
319
|
+
if ("kind" in check) {
|
|
320
|
+
if (handleChecks.includes(check.kind)) {
|
|
321
|
+
switch (check.kind) {
|
|
322
|
+
case "regex": {
|
|
323
|
+
constraints.regex = {
|
|
324
|
+
pattern: check.regex.source,
|
|
325
|
+
flags: check.regex.flags
|
|
326
|
+
};
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
case "emoji": {
|
|
330
|
+
constraints.emoji = true;
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
case "email": {
|
|
334
|
+
constraints.email = true;
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
case "url": {
|
|
338
|
+
constraints.url = true;
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
case "uuid": {
|
|
342
|
+
constraints.uuid = true;
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
case "cuid": {
|
|
346
|
+
constraints.cuid = true;
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
case "min": {
|
|
350
|
+
constraints.minLength = check.value;
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
case "max": {
|
|
354
|
+
constraints.maxLength = check.value;
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
newChecks.push(check);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
let result = z.string();
|
|
364
|
+
for (const check of newChecks) {
|
|
365
|
+
result = result._addCheck(check);
|
|
366
|
+
}
|
|
367
|
+
const description = this.mergeParameterDescription(value.description, constraints);
|
|
368
|
+
if (description) {
|
|
369
|
+
result = result.describe(description);
|
|
370
|
+
}
|
|
371
|
+
return result;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Default handler for Zod number types. Processes number validation constraints.
|
|
375
|
+
*
|
|
376
|
+
* @param value - The Zod number to process
|
|
377
|
+
* @param handleChecks - Number constraints to convert to descriptions vs keep as validation
|
|
378
|
+
* @returns The processed Zod number
|
|
379
|
+
*/
|
|
380
|
+
defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS) {
|
|
381
|
+
const constraints = {};
|
|
382
|
+
const checks = value._def.checks || [];
|
|
383
|
+
const newChecks = [];
|
|
384
|
+
for (const check of checks) {
|
|
385
|
+
if ("kind" in check) {
|
|
386
|
+
if (handleChecks.includes(check.kind)) {
|
|
387
|
+
switch (check.kind) {
|
|
388
|
+
case "min":
|
|
389
|
+
if (check.inclusive) {
|
|
390
|
+
constraints.gte = check.value;
|
|
391
|
+
} else {
|
|
392
|
+
constraints.gt = check.value;
|
|
393
|
+
}
|
|
394
|
+
break;
|
|
395
|
+
case "max":
|
|
396
|
+
if (check.inclusive) {
|
|
397
|
+
constraints.lte = check.value;
|
|
398
|
+
} else {
|
|
399
|
+
constraints.lt = check.value;
|
|
400
|
+
}
|
|
401
|
+
break;
|
|
402
|
+
case "multipleOf": {
|
|
403
|
+
constraints.multipleOf = check.value;
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
} else {
|
|
408
|
+
newChecks.push(check);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
let result = z.number();
|
|
413
|
+
for (const check of newChecks) {
|
|
414
|
+
switch (check.kind) {
|
|
415
|
+
case "int":
|
|
416
|
+
result = result.int();
|
|
417
|
+
break;
|
|
418
|
+
case "finite":
|
|
419
|
+
result = result.finite();
|
|
420
|
+
break;
|
|
421
|
+
default:
|
|
422
|
+
result = result._addCheck(check);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
const description = this.mergeParameterDescription(value.description, constraints);
|
|
426
|
+
if (description) {
|
|
427
|
+
result = result.describe(description);
|
|
428
|
+
}
|
|
429
|
+
return result;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Default handler for Zod date types. Converts dates to ISO strings with constraint descriptions.
|
|
433
|
+
*
|
|
434
|
+
* @param value - The Zod date to process
|
|
435
|
+
* @returns A Zod string schema representing the date in ISO format
|
|
436
|
+
*/
|
|
437
|
+
defaultZodDateHandler(value) {
|
|
438
|
+
const constraints = {};
|
|
439
|
+
const checks = value._def.checks || [];
|
|
440
|
+
for (const check of checks) {
|
|
441
|
+
if ("kind" in check) {
|
|
442
|
+
switch (check.kind) {
|
|
443
|
+
case "min":
|
|
444
|
+
const minDate = new Date(check.value);
|
|
445
|
+
if (!isNaN(minDate.getTime())) {
|
|
446
|
+
constraints.minDate = minDate.toISOString();
|
|
447
|
+
}
|
|
448
|
+
break;
|
|
449
|
+
case "max":
|
|
450
|
+
const maxDate = new Date(check.value);
|
|
451
|
+
if (!isNaN(maxDate.getTime())) {
|
|
452
|
+
constraints.maxDate = maxDate.toISOString();
|
|
453
|
+
}
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
constraints.dateFormat = "date-time";
|
|
459
|
+
let result = z.string().describe("date-time");
|
|
460
|
+
const description = this.mergeParameterDescription(value.description, constraints);
|
|
461
|
+
if (description) {
|
|
462
|
+
result = result.describe(description);
|
|
463
|
+
}
|
|
464
|
+
return result;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Default handler for Zod optional types. Processes the inner type and maintains optionality.
|
|
468
|
+
*
|
|
469
|
+
* @param value - The Zod optional to process
|
|
470
|
+
* @param handleTypes - Types that should be processed vs passed through
|
|
471
|
+
* @returns The processed Zod optional
|
|
472
|
+
*/
|
|
473
|
+
defaultZodOptionalHandler(value, handleTypes = SUPPORTED_ZOD_TYPES) {
|
|
474
|
+
if (handleTypes.includes(value._def.innerType._def.typeName)) {
|
|
475
|
+
return this.processZodType(value._def.innerType).optional();
|
|
476
|
+
} else {
|
|
477
|
+
return value;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Processes a Zod object schema and converts it to an AI SDK Schema.
|
|
482
|
+
*
|
|
483
|
+
* @param zodSchema - The Zod object schema to process
|
|
484
|
+
* @returns An AI SDK Schema with provider-specific compatibility applied
|
|
485
|
+
*/
|
|
486
|
+
processToAISDKSchema(zodSchema) {
|
|
487
|
+
const processedSchema = this.processZodType(zodSchema);
|
|
488
|
+
return convertZodSchemaToAISDKSchema(processedSchema, this.getSchemaTarget());
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Processes a Zod object schema and converts it to a JSON Schema.
|
|
492
|
+
*
|
|
493
|
+
* @param zodSchema - The Zod object schema to process
|
|
494
|
+
* @returns A JSONSchema7 object with provider-specific compatibility applied
|
|
495
|
+
*/
|
|
496
|
+
processToJSONSchema(zodSchema) {
|
|
497
|
+
return this.processToAISDKSchema(zodSchema).jsonSchema;
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
var ALL_STRING_CHECKS2 = [
|
|
501
|
+
"regex",
|
|
502
|
+
"emoji",
|
|
503
|
+
"email",
|
|
504
|
+
"url",
|
|
505
|
+
"uuid",
|
|
506
|
+
"cuid",
|
|
507
|
+
"min_length",
|
|
508
|
+
"max_length",
|
|
509
|
+
"string_format"
|
|
510
|
+
];
|
|
511
|
+
var ALL_NUMBER_CHECKS2 = ["greater_than", "less_than", "multiple_of"];
|
|
512
|
+
var ALL_ARRAY_CHECKS2 = ["min", "max", "length"];
|
|
513
|
+
var UNSUPPORTED_ZOD_TYPES2 = ["ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
|
|
514
|
+
var SUPPORTED_ZOD_TYPES2 = [
|
|
515
|
+
"ZodObject",
|
|
516
|
+
"ZodArray",
|
|
517
|
+
"ZodUnion",
|
|
518
|
+
"ZodString",
|
|
519
|
+
"ZodNumber",
|
|
520
|
+
"ZodDate",
|
|
521
|
+
"ZodAny",
|
|
522
|
+
"ZodDefault"
|
|
523
|
+
];
|
|
524
|
+
var SchemaCompatLayer2 = class {
|
|
525
|
+
model;
|
|
526
|
+
parent;
|
|
527
|
+
/**
|
|
528
|
+
* Creates a new schema compatibility instance.
|
|
529
|
+
*
|
|
530
|
+
* @param model - The language model this compatibility layer applies to
|
|
531
|
+
*/
|
|
532
|
+
constructor(model, parent) {
|
|
533
|
+
this.model = model;
|
|
534
|
+
this.parent = parent;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Gets the language model associated with this compatibility layer.
|
|
538
|
+
*
|
|
539
|
+
* @returns The language model instance
|
|
540
|
+
*/
|
|
541
|
+
getModel() {
|
|
542
|
+
return this.model;
|
|
543
|
+
}
|
|
544
|
+
getUnsupportedZodTypes() {
|
|
545
|
+
return UNSUPPORTED_ZOD_TYPES2;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Type guard for optional Zod types
|
|
549
|
+
*/
|
|
550
|
+
isOptional(v) {
|
|
551
|
+
return v instanceof ZodOptional$1;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Type guard for object Zod types
|
|
555
|
+
*/
|
|
556
|
+
isObj(v) {
|
|
557
|
+
return v instanceof ZodObject$1;
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Type guard for null Zod types
|
|
561
|
+
*/
|
|
562
|
+
isNull(v) {
|
|
563
|
+
return v instanceof ZodNull$1;
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Type guard for array Zod types
|
|
567
|
+
*/
|
|
568
|
+
isArr(v) {
|
|
569
|
+
return v instanceof ZodArray$1;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Type guard for union Zod types
|
|
573
|
+
*/
|
|
574
|
+
isUnion(v) {
|
|
575
|
+
return v instanceof ZodUnion$1;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Type guard for string Zod types
|
|
579
|
+
*/
|
|
580
|
+
isString(v) {
|
|
581
|
+
return v instanceof ZodString$1;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Type guard for number Zod types
|
|
585
|
+
*/
|
|
586
|
+
isNumber(v) {
|
|
587
|
+
return v instanceof ZodNumber$1;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Type guard for date Zod types
|
|
591
|
+
*/
|
|
592
|
+
isDate(v) {
|
|
593
|
+
return v instanceof ZodDate$1;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Type guard for default Zod types
|
|
597
|
+
*/
|
|
598
|
+
isDefault(v) {
|
|
599
|
+
return v instanceof ZodDefault$1;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Determines whether this compatibility layer should be applied for the current model.
|
|
603
|
+
*
|
|
604
|
+
* @returns True if this compatibility layer should be used, false otherwise
|
|
605
|
+
* @abstract
|
|
606
|
+
*/
|
|
607
|
+
shouldApply() {
|
|
608
|
+
return this.parent.shouldApply();
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Returns the JSON Schema target format for this provider.
|
|
612
|
+
*
|
|
613
|
+
* @returns The schema target format, or undefined to use the default 'jsonSchema7'
|
|
614
|
+
* @abstract
|
|
615
|
+
*/
|
|
616
|
+
getSchemaTarget() {
|
|
617
|
+
return this.parent.getSchemaTarget();
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Processes a specific Zod type according to the provider's requirements.
|
|
621
|
+
*
|
|
622
|
+
* @param value - The Zod type to process
|
|
623
|
+
* @returns The processed Zod type
|
|
624
|
+
* @abstract
|
|
625
|
+
*/
|
|
626
|
+
processZodType(value) {
|
|
627
|
+
return this.parent.processZodType(value);
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Default handler for Zod object types. Recursively processes all properties in the object.
|
|
631
|
+
*
|
|
632
|
+
* @param value - The Zod object to process
|
|
633
|
+
* @returns The processed Zod object
|
|
634
|
+
*/
|
|
635
|
+
defaultZodObjectHandler(value, options = { passthrough: true }) {
|
|
636
|
+
const processedShape = Object.entries(value.shape).reduce((acc, [key, propValue]) => {
|
|
637
|
+
acc[key] = this.processZodType(propValue);
|
|
638
|
+
return acc;
|
|
639
|
+
}, {});
|
|
640
|
+
let result = z$1.object(processedShape);
|
|
641
|
+
if (value._zod.def.catchall instanceof z$1.ZodNever) {
|
|
642
|
+
result = z$1.strictObject(processedShape);
|
|
643
|
+
}
|
|
644
|
+
if (value._zod.def.catchall && !(value._zod.def.catchall instanceof z$1.ZodNever)) {
|
|
645
|
+
result = result.catchall(value._zod.def.catchall);
|
|
646
|
+
}
|
|
647
|
+
if (value.description) {
|
|
648
|
+
result = result.describe(value.description);
|
|
649
|
+
}
|
|
650
|
+
if (options.passthrough && value._zod.def.catchall instanceof z$1.ZodUnknown) {
|
|
651
|
+
result = z$1.looseObject(processedShape);
|
|
652
|
+
}
|
|
653
|
+
return result;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Merges validation constraints into a parameter description.
|
|
657
|
+
*
|
|
658
|
+
* This helper method converts validation constraints that may not be supported
|
|
659
|
+
* by a provider into human-readable descriptions.
|
|
660
|
+
*
|
|
661
|
+
* @param description - The existing parameter description
|
|
662
|
+
* @param constraints - The validation constraints to merge
|
|
663
|
+
* @returns The updated description with constraints, or undefined if no constraints
|
|
664
|
+
*/
|
|
665
|
+
mergeParameterDescription(description, constraints) {
|
|
666
|
+
if (Object.keys(constraints).length > 0) {
|
|
667
|
+
return (description ? description + "\n" : "") + JSON.stringify(constraints);
|
|
668
|
+
} else {
|
|
669
|
+
return description;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Default handler for unsupported Zod types. Throws an error for specified unsupported types.
|
|
674
|
+
*
|
|
675
|
+
* @param value - The Zod type to check
|
|
676
|
+
* @param throwOnTypes - Array of type names to throw errors for
|
|
677
|
+
* @returns The original value if not in the throw list
|
|
678
|
+
* @throws Error if the type is in the unsupported list
|
|
679
|
+
*/
|
|
680
|
+
defaultUnsupportedZodTypeHandler(value, throwOnTypes = UNSUPPORTED_ZOD_TYPES2) {
|
|
681
|
+
if (throwOnTypes.includes(value.constructor.name)) {
|
|
682
|
+
throw new Error(`${this.model.modelId} does not support zod type: ${value.constructor.name}`);
|
|
683
|
+
}
|
|
684
|
+
return value;
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Default handler for Zod array types. Processes array constraints according to provider support.
|
|
688
|
+
*
|
|
689
|
+
* @param value - The Zod array to process
|
|
690
|
+
* @param handleChecks - Array constraints to convert to descriptions vs keep as validation
|
|
691
|
+
* @returns The processed Zod array
|
|
692
|
+
*/
|
|
693
|
+
defaultZodArrayHandler(value, handleChecks = ALL_ARRAY_CHECKS2) {
|
|
694
|
+
const zodArrayDef = value._zod.def;
|
|
695
|
+
const processedType = this.processZodType(zodArrayDef.element);
|
|
696
|
+
let result = z$1.array(processedType);
|
|
697
|
+
const constraints = {};
|
|
698
|
+
if (zodArrayDef.checks) {
|
|
699
|
+
for (const check of zodArrayDef.checks) {
|
|
700
|
+
if (check._zod.def.check === "min_length") {
|
|
701
|
+
if (handleChecks.includes("min")) {
|
|
702
|
+
constraints.minLength = check._zod.def.minimum;
|
|
703
|
+
} else {
|
|
704
|
+
result = result.min(check._zod.def.minimum);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
if (check._zod.def.check === "max_length") {
|
|
708
|
+
if (handleChecks.includes("max")) {
|
|
709
|
+
constraints.maxLength = check._zod.def.maximum;
|
|
710
|
+
} else {
|
|
711
|
+
result = result.max(check._zod.def.maximum);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
if (check._zod.def.check === "length_equals") {
|
|
715
|
+
if (handleChecks.includes("length")) {
|
|
716
|
+
constraints.exactLength = check._zod.def.length;
|
|
717
|
+
} else {
|
|
718
|
+
result = result.length(check._zod.def.length);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
const metaDescription = value.meta()?.description;
|
|
724
|
+
const legacyDescription = value.description;
|
|
725
|
+
const description = this.mergeParameterDescription(metaDescription || legacyDescription, constraints);
|
|
726
|
+
if (description) {
|
|
727
|
+
result = result.describe(description);
|
|
728
|
+
}
|
|
729
|
+
return result;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Default handler for Zod union types. Processes all union options.
|
|
733
|
+
*
|
|
734
|
+
* @param value - The Zod union to process
|
|
735
|
+
* @returns The processed Zod union
|
|
736
|
+
* @throws Error if union has fewer than 2 options
|
|
737
|
+
*/
|
|
738
|
+
defaultZodUnionHandler(value) {
|
|
739
|
+
const processedOptions = value._zod.def.options.map((option) => this.processZodType(option));
|
|
740
|
+
if (processedOptions.length < 2) throw new Error("Union must have at least 2 options");
|
|
741
|
+
let result = z$1.union(processedOptions);
|
|
742
|
+
if (value.description) {
|
|
743
|
+
result = result.describe(value.description);
|
|
744
|
+
}
|
|
745
|
+
return result;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Default handler for Zod string types. Processes string validation constraints.
|
|
749
|
+
*
|
|
750
|
+
* @param value - The Zod string to process
|
|
751
|
+
* @param handleChecks - String constraints to convert to descriptions vs keep as validation
|
|
752
|
+
* @returns The processed Zod string
|
|
753
|
+
*/
|
|
754
|
+
defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS2) {
|
|
755
|
+
const constraints = {};
|
|
756
|
+
const checks = value._zod.def.checks || [];
|
|
757
|
+
const newChecks = [];
|
|
758
|
+
if (checks) {
|
|
759
|
+
for (const check of checks) {
|
|
760
|
+
if (handleChecks.includes(check._zod.def.check)) {
|
|
761
|
+
switch (check._zod.def.check) {
|
|
762
|
+
case "min_length":
|
|
763
|
+
constraints.minLength = check._zod.def.minimum;
|
|
764
|
+
break;
|
|
765
|
+
case "max_length":
|
|
766
|
+
constraints.maxLength = check._zod.def.maximum;
|
|
767
|
+
break;
|
|
768
|
+
case "string_format":
|
|
769
|
+
{
|
|
770
|
+
switch (check._zod.def.format) {
|
|
771
|
+
case "email":
|
|
772
|
+
constraints.email = true;
|
|
773
|
+
break;
|
|
774
|
+
case "url":
|
|
775
|
+
constraints.url = true;
|
|
776
|
+
break;
|
|
777
|
+
case "emoji":
|
|
778
|
+
constraints.emoji = true;
|
|
779
|
+
break;
|
|
780
|
+
case "uuid":
|
|
781
|
+
constraints.uuid = true;
|
|
782
|
+
break;
|
|
783
|
+
case "cuid":
|
|
784
|
+
constraints.cuid = true;
|
|
785
|
+
break;
|
|
786
|
+
case "regex":
|
|
787
|
+
constraints.regex = {
|
|
788
|
+
// @ts-expect-error - fix later
|
|
789
|
+
pattern: check._zod.def.pattern,
|
|
790
|
+
// @ts-expect-error - fix later
|
|
791
|
+
flags: check._zod.def.flags
|
|
792
|
+
};
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
break;
|
|
797
|
+
}
|
|
798
|
+
} else {
|
|
799
|
+
newChecks.push(check);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
let result = z$1.string();
|
|
804
|
+
for (const check of newChecks) {
|
|
805
|
+
result = result.check(check);
|
|
806
|
+
}
|
|
807
|
+
const metaDescription = value.meta()?.description;
|
|
808
|
+
const legacyDescription = value.description;
|
|
809
|
+
const description = this.mergeParameterDescription(metaDescription || legacyDescription, constraints);
|
|
810
|
+
if (description) {
|
|
811
|
+
result = result.describe(description);
|
|
812
|
+
}
|
|
813
|
+
return result;
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Default handler for Zod number types. Processes number validation constraints.
|
|
817
|
+
*
|
|
818
|
+
* @param value - The Zod number to process
|
|
819
|
+
* @param handleChecks - Number constraints to convert to descriptions vs keep as validation
|
|
820
|
+
* @returns The processed Zod number
|
|
821
|
+
*/
|
|
822
|
+
defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS2) {
|
|
823
|
+
const constraints = {};
|
|
824
|
+
const checks = value._zod.def.checks || [];
|
|
825
|
+
const newChecks = [];
|
|
826
|
+
if (checks) {
|
|
827
|
+
for (const check of checks) {
|
|
828
|
+
if (handleChecks.includes(check._zod.def.check)) {
|
|
829
|
+
switch (check._zod.def.check) {
|
|
830
|
+
case "greater_than":
|
|
831
|
+
if (check._zod.def.inclusive) {
|
|
832
|
+
constraints.gte = check._zod.def.value;
|
|
833
|
+
} else {
|
|
834
|
+
constraints.gt = check._zod.def.value;
|
|
835
|
+
}
|
|
836
|
+
break;
|
|
837
|
+
case "less_than":
|
|
838
|
+
if (check._zod.def.inclusive) {
|
|
839
|
+
constraints.lte = check._zod.def.value;
|
|
840
|
+
} else {
|
|
841
|
+
constraints.lt = check._zod.def.value;
|
|
842
|
+
}
|
|
843
|
+
break;
|
|
844
|
+
case "multiple_of": {
|
|
845
|
+
constraints.multipleOf = check._zod.def.value;
|
|
846
|
+
break;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
} else {
|
|
850
|
+
newChecks.push(check);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
let result = z$1.number();
|
|
855
|
+
for (const check of newChecks) {
|
|
856
|
+
switch (check._zod.def.check) {
|
|
857
|
+
case "number_format": {
|
|
858
|
+
switch (check._zod.def.format) {
|
|
859
|
+
case "safeint":
|
|
860
|
+
result = result.int();
|
|
861
|
+
break;
|
|
862
|
+
}
|
|
863
|
+
break;
|
|
864
|
+
}
|
|
865
|
+
default:
|
|
866
|
+
result = result.check(check);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
const description = this.mergeParameterDescription(value.description, constraints);
|
|
870
|
+
if (description) {
|
|
871
|
+
result = result.describe(description);
|
|
872
|
+
}
|
|
873
|
+
return result;
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Default handler for Zod date types. Converts dates to ISO strings with constraint descriptions.
|
|
877
|
+
*
|
|
878
|
+
* @param value - The Zod date to process
|
|
879
|
+
* @returns A Zod string schema representing the date in ISO format
|
|
880
|
+
*/
|
|
881
|
+
defaultZodDateHandler(value) {
|
|
882
|
+
const constraints = {};
|
|
883
|
+
const checks = value._zod.def.checks || [];
|
|
884
|
+
if (checks) {
|
|
885
|
+
for (const check of checks) {
|
|
886
|
+
switch (check._zod.def.check) {
|
|
887
|
+
case "less_than":
|
|
888
|
+
const minDate = new Date(check._zod.def.value);
|
|
889
|
+
if (!isNaN(minDate.getTime())) {
|
|
890
|
+
constraints.minDate = minDate.toISOString();
|
|
891
|
+
}
|
|
892
|
+
break;
|
|
893
|
+
case "greater_than":
|
|
894
|
+
const maxDate = new Date(check._zod.def.value);
|
|
895
|
+
if (!isNaN(maxDate.getTime())) {
|
|
896
|
+
constraints.maxDate = maxDate.toISOString();
|
|
897
|
+
}
|
|
898
|
+
break;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
constraints.dateFormat = "date-time";
|
|
903
|
+
let result = z$1.string().describe("date-time");
|
|
904
|
+
const description = this.mergeParameterDescription(value.description, constraints);
|
|
905
|
+
if (description) {
|
|
906
|
+
result = result.describe(description);
|
|
907
|
+
}
|
|
908
|
+
return result;
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Default handler for Zod optional types. Processes the inner type and maintains optionality.
|
|
912
|
+
*
|
|
913
|
+
* @param value - The Zod optional to process
|
|
914
|
+
* @param handleTypes - Types that should be processed vs passed through
|
|
915
|
+
* @returns The processed Zod optional
|
|
916
|
+
*/
|
|
917
|
+
defaultZodOptionalHandler(value, handleTypes = SUPPORTED_ZOD_TYPES2) {
|
|
918
|
+
if (handleTypes.includes(value.constructor.name)) {
|
|
919
|
+
return this.processZodType(value._zod.def.innerType).optional();
|
|
920
|
+
} else {
|
|
921
|
+
return value;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Processes a Zod object schema and converts it to an AI SDK Schema.
|
|
926
|
+
*
|
|
927
|
+
* @param zodSchema - The Zod object schema to process
|
|
928
|
+
* @returns An AI SDK Schema with provider-specific compatibility applied
|
|
929
|
+
*/
|
|
930
|
+
processToAISDKSchema(zodSchema) {
|
|
931
|
+
const processedSchema = this.processZodType(zodSchema);
|
|
932
|
+
return convertZodSchemaToAISDKSchema(processedSchema, this.getSchemaTarget());
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* Processes a Zod object schema and converts it to a JSON Schema.
|
|
936
|
+
*
|
|
937
|
+
* @param zodSchema - The Zod object schema to process
|
|
938
|
+
* @returns A JSONSchema7 object with provider-specific compatibility applied
|
|
939
|
+
*/
|
|
940
|
+
processToJSONSchema(zodSchema) {
|
|
941
|
+
return this.processToAISDKSchema(zodSchema).jsonSchema;
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
// src/schema-compatibility.ts
|
|
946
|
+
var SchemaCompatLayer3 = class {
|
|
947
|
+
model;
|
|
948
|
+
v3Layer;
|
|
949
|
+
v4Layer;
|
|
950
|
+
/**
|
|
951
|
+
* Creates a new schema compatibility instance.
|
|
952
|
+
*
|
|
953
|
+
* @param model - The language model this compatibility layer applies to
|
|
954
|
+
*/
|
|
955
|
+
constructor(model) {
|
|
956
|
+
this.model = model;
|
|
957
|
+
this.v3Layer = new SchemaCompatLayer(model, this);
|
|
958
|
+
this.v4Layer = new SchemaCompatLayer2(model, this);
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Gets the language model associated with this compatibility layer.
|
|
962
|
+
*
|
|
963
|
+
* @returns The language model instance
|
|
964
|
+
*/
|
|
965
|
+
getModel() {
|
|
966
|
+
return this.model;
|
|
967
|
+
}
|
|
968
|
+
getUnsupportedZodTypes(v) {
|
|
969
|
+
if ("_zod" in v) {
|
|
970
|
+
return this.v4Layer.getUnsupportedZodTypes();
|
|
971
|
+
} else {
|
|
972
|
+
return this.v3Layer.getUnsupportedZodTypes();
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
isOptional(v) {
|
|
976
|
+
if ("_zod" in v) {
|
|
977
|
+
return this.v4Layer.isOptional(v);
|
|
978
|
+
} else {
|
|
979
|
+
return this.v3Layer.isOptional(v);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
isObj(v) {
|
|
983
|
+
if ("_zod" in v) {
|
|
984
|
+
return this.v4Layer.isObj(v);
|
|
985
|
+
} else {
|
|
986
|
+
return this.v3Layer.isObj(v);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
isNull(v) {
|
|
990
|
+
if ("_zod" in v) {
|
|
991
|
+
return this.v4Layer.isNull(v);
|
|
992
|
+
} else {
|
|
993
|
+
return this.v3Layer.isNull(v);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
isArr(v) {
|
|
997
|
+
if ("_zod" in v) {
|
|
998
|
+
return this.v4Layer.isArr(v);
|
|
999
|
+
} else {
|
|
1000
|
+
return this.v3Layer.isArr(v);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
isUnion(v) {
|
|
1004
|
+
if ("_zod" in v) {
|
|
1005
|
+
return this.v4Layer.isUnion(v);
|
|
1006
|
+
} else {
|
|
1007
|
+
return this.v3Layer.isUnion(v);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
isString(v) {
|
|
1011
|
+
if ("_zod" in v) {
|
|
1012
|
+
return this.v4Layer.isString(v);
|
|
1013
|
+
} else {
|
|
1014
|
+
return this.v3Layer.isString(v);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
isNumber(v) {
|
|
1018
|
+
if ("_zod" in v) {
|
|
1019
|
+
return this.v4Layer.isNumber(v);
|
|
1020
|
+
} else {
|
|
1021
|
+
return this.v3Layer.isNumber(v);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
isDate(v) {
|
|
1025
|
+
if ("_zod" in v) {
|
|
1026
|
+
return this.v4Layer.isDate(v);
|
|
1027
|
+
} else {
|
|
1028
|
+
return this.v3Layer.isDate(v);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
isDefault(v) {
|
|
1032
|
+
if ("_zod" in v) {
|
|
1033
|
+
return this.v4Layer.isDefault(v);
|
|
1034
|
+
} else {
|
|
1035
|
+
return this.v3Layer.isDefault(v);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
defaultZodObjectHandler(value, options = { passthrough: true }) {
|
|
1039
|
+
if ("_zod" in value) {
|
|
1040
|
+
return this.v4Layer.defaultZodObjectHandler(value, options);
|
|
1041
|
+
} else {
|
|
1042
|
+
return this.v3Layer.defaultZodObjectHandler(value, options);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Merges validation constraints into a parameter description.
|
|
1047
|
+
*
|
|
1048
|
+
* This helper method converts validation constraints that may not be supported
|
|
1049
|
+
* by a provider into human-readable descriptions.
|
|
1050
|
+
*
|
|
1051
|
+
* @param description - The existing parameter description
|
|
1052
|
+
* @param constraints - The validation constraints to merge
|
|
1053
|
+
* @returns The updated description with constraints, or undefined if no constraints
|
|
1054
|
+
*/
|
|
1055
|
+
mergeParameterDescription(description, constraints) {
|
|
1056
|
+
return this.v3Layer.mergeParameterDescription(description, constraints);
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Default handler for unsupported Zod types. Throws an error for specified unsupported types.
|
|
1060
|
+
*
|
|
1061
|
+
* @param value - The Zod type to check
|
|
1062
|
+
* @param throwOnTypes - Array of type names to throw errors for
|
|
1063
|
+
* @returns The original value if not in the throw list
|
|
1064
|
+
* @throws Error if the type is in the unsupported list
|
|
1065
|
+
*/
|
|
1066
|
+
defaultUnsupportedZodTypeHandler(value, throwOnTypes) {
|
|
1067
|
+
if ("_zod" in value) {
|
|
1068
|
+
return this.v4Layer.defaultUnsupportedZodTypeHandler(
|
|
1069
|
+
// @ts-expect-error - fix later
|
|
1070
|
+
value,
|
|
1071
|
+
throwOnTypes ?? UNSUPPORTED_ZOD_TYPES2
|
|
1072
|
+
);
|
|
1073
|
+
} else {
|
|
1074
|
+
return this.v3Layer.defaultUnsupportedZodTypeHandler(
|
|
1075
|
+
value,
|
|
1076
|
+
throwOnTypes ?? UNSUPPORTED_ZOD_TYPES
|
|
1077
|
+
);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
defaultZodArrayHandler(value, handleChecks = ALL_ARRAY_CHECKS) {
|
|
1081
|
+
if ("_zod" in value) {
|
|
1082
|
+
return this.v4Layer.defaultZodArrayHandler(value, handleChecks);
|
|
1083
|
+
} else {
|
|
1084
|
+
return this.v3Layer.defaultZodArrayHandler(value, handleChecks);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
defaultZodUnionHandler(value) {
|
|
1088
|
+
if ("_zod" in value) {
|
|
1089
|
+
return this.v4Layer.defaultZodUnionHandler(value);
|
|
1090
|
+
} else {
|
|
1091
|
+
return this.v3Layer.defaultZodUnionHandler(value);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS) {
|
|
1095
|
+
if ("_zod" in value) {
|
|
1096
|
+
return this.v4Layer.defaultZodStringHandler(value);
|
|
1097
|
+
} else {
|
|
1098
|
+
return this.v3Layer.defaultZodStringHandler(value, handleChecks);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS) {
|
|
1102
|
+
if ("_zod" in value) {
|
|
1103
|
+
return this.v4Layer.defaultZodNumberHandler(value);
|
|
1104
|
+
} else {
|
|
1105
|
+
return this.v3Layer.defaultZodNumberHandler(value, handleChecks);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
defaultZodDateHandler(value) {
|
|
1109
|
+
if ("_zod" in value) {
|
|
1110
|
+
return this.v4Layer.defaultZodDateHandler(value);
|
|
1111
|
+
} else {
|
|
1112
|
+
return this.v3Layer.defaultZodDateHandler(value);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
defaultZodOptionalHandler(value, handleTypes) {
|
|
1116
|
+
if ("_zod" in value) {
|
|
1117
|
+
return this.v4Layer.defaultZodOptionalHandler(value, handleTypes ?? SUPPORTED_ZOD_TYPES2);
|
|
1118
|
+
} else {
|
|
1119
|
+
return this.v3Layer.defaultZodOptionalHandler(value, handleTypes ?? SUPPORTED_ZOD_TYPES);
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Processes a Zod object schema and converts it to an AI SDK Schema.
|
|
1124
|
+
*
|
|
1125
|
+
* @param zodSchema - The Zod object schema to process
|
|
1126
|
+
* @returns An AI SDK Schema with provider-specific compatibility applied
|
|
1127
|
+
*/
|
|
1128
|
+
processToAISDKSchema(zodSchema) {
|
|
1129
|
+
const processedSchema = this.processZodType(zodSchema);
|
|
1130
|
+
return convertZodSchemaToAISDKSchema(processedSchema, this.getSchemaTarget());
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* Processes a Zod object schema and converts it to a JSON Schema.
|
|
1134
|
+
*
|
|
1135
|
+
* @param zodSchema - The Zod object schema to process
|
|
1136
|
+
* @returns A JSONSchema7 object with provider-specific compatibility applied
|
|
1137
|
+
*/
|
|
1138
|
+
processToJSONSchema(zodSchema) {
|
|
1139
|
+
return this.processToAISDKSchema(zodSchema).jsonSchema;
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
|
|
1143
|
+
// src/zodTypes.ts
|
|
1144
|
+
function isOptional2(z10) {
|
|
1145
|
+
return (v) => v instanceof z10["ZodOptional"];
|
|
1146
|
+
}
|
|
1147
|
+
function isObj2(z10) {
|
|
1148
|
+
return (v) => v instanceof z10["ZodObject"];
|
|
1149
|
+
}
|
|
1150
|
+
function isNull(z10) {
|
|
1151
|
+
return (v) => v instanceof z10["ZodNull"];
|
|
1152
|
+
}
|
|
1153
|
+
function isArr2(z10) {
|
|
1154
|
+
return (v) => v instanceof z10["ZodArray"];
|
|
1155
|
+
}
|
|
1156
|
+
function isUnion2(z10) {
|
|
1157
|
+
return (v) => v instanceof z10["ZodUnion"];
|
|
1158
|
+
}
|
|
1159
|
+
function isString2(z10) {
|
|
1160
|
+
return (v) => v instanceof z10["ZodString"];
|
|
1161
|
+
}
|
|
1162
|
+
function isNumber2(z10) {
|
|
1163
|
+
return (v) => v instanceof z10["ZodNumber"];
|
|
1164
|
+
}
|
|
1165
|
+
function isDate(z10) {
|
|
1166
|
+
return (v) => v instanceof z10["ZodDate"];
|
|
1167
|
+
}
|
|
1168
|
+
function isDefault(z10) {
|
|
1169
|
+
return (v) => v instanceof z10["ZodDefault"];
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
// src/provider-compats/anthropic.ts
|
|
1173
|
+
var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
1174
|
+
constructor(model) {
|
|
1175
|
+
super(model);
|
|
1176
|
+
}
|
|
1177
|
+
getSchemaTarget() {
|
|
1178
|
+
return "jsonSchema7";
|
|
1179
|
+
}
|
|
1180
|
+
shouldApply() {
|
|
1181
|
+
return this.getModel().modelId.includes("claude");
|
|
1182
|
+
}
|
|
1183
|
+
processZodType(value) {
|
|
1184
|
+
if (isOptional2(z)(value)) {
|
|
1185
|
+
const handleTypes = [
|
|
1186
|
+
"ZodObject",
|
|
1187
|
+
"ZodArray",
|
|
1188
|
+
"ZodUnion",
|
|
1189
|
+
"ZodNever",
|
|
1190
|
+
"ZodUndefined",
|
|
1191
|
+
"ZodTuple"
|
|
1192
|
+
];
|
|
1193
|
+
if (this.getModel().modelId.includes("claude-3.5-haiku")) handleTypes.push("ZodString");
|
|
1194
|
+
return this.defaultZodOptionalHandler(value, handleTypes);
|
|
1195
|
+
} else if (isObj2(z)(value)) {
|
|
1196
|
+
return this.defaultZodObjectHandler(value);
|
|
1197
|
+
} else if (isArr2(z)(value)) {
|
|
1198
|
+
return this.defaultZodArrayHandler(value, []);
|
|
1199
|
+
} else if (isUnion2(z)(value)) {
|
|
1200
|
+
return this.defaultZodUnionHandler(value);
|
|
1201
|
+
} else if (isString2(z)(value)) {
|
|
1202
|
+
if (this.getModel().modelId.includes("claude-3.5-haiku")) {
|
|
1203
|
+
return this.defaultZodStringHandler(value, ["max", "min"]);
|
|
1204
|
+
} else {
|
|
1205
|
+
return value;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
return this.defaultUnsupportedZodTypeHandler(value, [
|
|
1209
|
+
"ZodNever",
|
|
1210
|
+
"ZodTuple",
|
|
1211
|
+
"ZodUndefined"
|
|
1212
|
+
]);
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
1216
|
+
constructor(model) {
|
|
1217
|
+
super(model);
|
|
1218
|
+
}
|
|
1219
|
+
getSchemaTarget() {
|
|
1220
|
+
return "jsonSchema7";
|
|
1221
|
+
}
|
|
1222
|
+
shouldApply() {
|
|
1223
|
+
return this.getModel().modelId.includes("deepseek") && !this.getModel().modelId.includes("r1");
|
|
1224
|
+
}
|
|
1225
|
+
processZodType(value) {
|
|
1226
|
+
if (isOptional2(z)(value)) {
|
|
1227
|
+
return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
|
|
1228
|
+
} else if (isObj2(z)(value)) {
|
|
1229
|
+
return this.defaultZodObjectHandler(value);
|
|
1230
|
+
} else if (isArr2(z)(value)) {
|
|
1231
|
+
return this.defaultZodArrayHandler(value, ["min", "max"]);
|
|
1232
|
+
} else if (isUnion2(z)(value)) {
|
|
1233
|
+
return this.defaultZodUnionHandler(value);
|
|
1234
|
+
} else if (isString2(z)(value)) {
|
|
1235
|
+
return this.defaultZodStringHandler(value);
|
|
1236
|
+
}
|
|
1237
|
+
return value;
|
|
1238
|
+
}
|
|
1239
|
+
};
|
|
1240
|
+
var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
1241
|
+
constructor(model) {
|
|
1242
|
+
super(model);
|
|
1243
|
+
}
|
|
1244
|
+
getSchemaTarget() {
|
|
1245
|
+
return "jsonSchema7";
|
|
1246
|
+
}
|
|
1247
|
+
shouldApply() {
|
|
1248
|
+
return this.getModel().provider.includes("google") || this.getModel().modelId.includes("google");
|
|
1249
|
+
}
|
|
1250
|
+
processZodType(value) {
|
|
1251
|
+
if (isOptional2(z)(value)) {
|
|
1252
|
+
return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
|
|
1253
|
+
} else if (isNull(z)(value)) {
|
|
1254
|
+
return z.any().refine((v) => v === null, { message: "must be null" }).describe(value.description || "must be null");
|
|
1255
|
+
} else if (isObj2(z)(value)) {
|
|
1256
|
+
return this.defaultZodObjectHandler(value);
|
|
1257
|
+
} else if (isArr2(z)(value)) {
|
|
1258
|
+
return this.defaultZodArrayHandler(value, []);
|
|
1259
|
+
} else if (isUnion2(z)(value)) {
|
|
1260
|
+
return this.defaultZodUnionHandler(value);
|
|
1261
|
+
} else if (isString2(z)(value)) {
|
|
1262
|
+
return this.defaultZodStringHandler(value);
|
|
1263
|
+
} else if (isNumber2(z)(value)) {
|
|
1264
|
+
return this.defaultZodNumberHandler(value);
|
|
1265
|
+
}
|
|
1266
|
+
return this.defaultUnsupportedZodTypeHandler(value);
|
|
1267
|
+
}
|
|
1268
|
+
};
|
|
1269
|
+
var MetaSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
1270
|
+
constructor(model) {
|
|
1271
|
+
super(model);
|
|
1272
|
+
}
|
|
1273
|
+
getSchemaTarget() {
|
|
1274
|
+
return "jsonSchema7";
|
|
1275
|
+
}
|
|
1276
|
+
shouldApply() {
|
|
1277
|
+
return this.getModel().modelId.includes("meta");
|
|
1278
|
+
}
|
|
1279
|
+
processZodType(value) {
|
|
1280
|
+
if (isOptional2(z)(value)) {
|
|
1281
|
+
return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
|
|
1282
|
+
} else if (isObj2(z)(value)) {
|
|
1283
|
+
return this.defaultZodObjectHandler(value);
|
|
1284
|
+
} else if (isArr2(z)(value)) {
|
|
1285
|
+
return this.defaultZodArrayHandler(value, ["min", "max"]);
|
|
1286
|
+
} else if (isUnion2(z)(value)) {
|
|
1287
|
+
return this.defaultZodUnionHandler(value);
|
|
1288
|
+
} else if (isNumber2(z)(value)) {
|
|
1289
|
+
return this.defaultZodNumberHandler(value);
|
|
1290
|
+
} else if (isString2(z)(value)) {
|
|
1291
|
+
return this.defaultZodStringHandler(value);
|
|
1292
|
+
}
|
|
1293
|
+
return value;
|
|
1294
|
+
}
|
|
1295
|
+
};
|
|
1296
|
+
var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
1297
|
+
constructor(model) {
|
|
1298
|
+
super(model);
|
|
1299
|
+
}
|
|
1300
|
+
getSchemaTarget() {
|
|
1301
|
+
return `jsonSchema7`;
|
|
1302
|
+
}
|
|
1303
|
+
shouldApply() {
|
|
1304
|
+
if (!this.getModel().supportsStructuredOutputs && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
|
|
1305
|
+
return true;
|
|
1306
|
+
}
|
|
1307
|
+
return false;
|
|
1308
|
+
}
|
|
1309
|
+
processZodType(value) {
|
|
1310
|
+
if (isOptional2(z)(value)) {
|
|
1311
|
+
return this.defaultZodOptionalHandler(value, [
|
|
1312
|
+
"ZodObject",
|
|
1313
|
+
"ZodArray",
|
|
1314
|
+
"ZodUnion",
|
|
1315
|
+
"ZodString",
|
|
1316
|
+
"ZodNever",
|
|
1317
|
+
"ZodUndefined",
|
|
1318
|
+
"ZodTuple"
|
|
1319
|
+
]);
|
|
1320
|
+
} else if (isObj2(z)(value)) {
|
|
1321
|
+
return this.defaultZodObjectHandler(value);
|
|
1322
|
+
} else if (isUnion2(z)(value)) {
|
|
1323
|
+
return this.defaultZodUnionHandler(value);
|
|
1324
|
+
} else if (isArr2(z)(value)) {
|
|
1325
|
+
return this.defaultZodArrayHandler(value);
|
|
1326
|
+
} else if (isString2(z)(value)) {
|
|
1327
|
+
const model = this.getModel();
|
|
1328
|
+
const checks = ["emoji"];
|
|
1329
|
+
if (model.modelId.includes("gpt-4o-mini")) {
|
|
1330
|
+
return this.defaultZodStringHandler(value, ["emoji", "regex"]);
|
|
1331
|
+
}
|
|
1332
|
+
return this.defaultZodStringHandler(value, checks);
|
|
1333
|
+
}
|
|
1334
|
+
return this.defaultUnsupportedZodTypeHandler(value, [
|
|
1335
|
+
"ZodNever",
|
|
1336
|
+
"ZodUndefined",
|
|
1337
|
+
"ZodTuple"
|
|
1338
|
+
]);
|
|
1339
|
+
}
|
|
1340
|
+
};
|
|
1341
|
+
var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
1342
|
+
constructor(model) {
|
|
1343
|
+
super(model);
|
|
1344
|
+
}
|
|
1345
|
+
getSchemaTarget() {
|
|
1346
|
+
return `openApi3`;
|
|
1347
|
+
}
|
|
1348
|
+
isReasoningModel() {
|
|
1349
|
+
return this.getModel().modelId.includes(`o3`) || this.getModel().modelId.includes(`o4`) || this.getModel().modelId.includes(`o1`);
|
|
1350
|
+
}
|
|
1351
|
+
shouldApply() {
|
|
1352
|
+
if ((this.getModel().supportsStructuredOutputs || this.isReasoningModel()) && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))) {
|
|
1353
|
+
return true;
|
|
1354
|
+
}
|
|
1355
|
+
return false;
|
|
1356
|
+
}
|
|
1357
|
+
processZodType(value) {
|
|
1358
|
+
if (isOptional2(z)(value)) {
|
|
1359
|
+
const innerZodType = this.processZodType(value._def.innerType);
|
|
1360
|
+
return innerZodType.nullable();
|
|
1361
|
+
} else if (isObj2(z)(value)) {
|
|
1362
|
+
return this.defaultZodObjectHandler(value, { passthrough: false });
|
|
1363
|
+
} else if (isArr2(z)(value)) {
|
|
1364
|
+
return this.defaultZodArrayHandler(value);
|
|
1365
|
+
} else if (isUnion2(z)(value)) {
|
|
1366
|
+
return this.defaultZodUnionHandler(value);
|
|
1367
|
+
} else if (isDefault(z)(value)) {
|
|
1368
|
+
const defaultDef = value._def;
|
|
1369
|
+
const innerType = defaultDef.innerType;
|
|
1370
|
+
const defaultValue = defaultDef.defaultValue();
|
|
1371
|
+
const constraints = {};
|
|
1372
|
+
if (defaultValue !== void 0) {
|
|
1373
|
+
constraints.defaultValue = defaultValue;
|
|
1374
|
+
}
|
|
1375
|
+
const description = this.mergeParameterDescription(value.description, constraints);
|
|
1376
|
+
let result = this.processZodType(innerType);
|
|
1377
|
+
if (description) {
|
|
1378
|
+
result = result.describe(description);
|
|
1379
|
+
}
|
|
1380
|
+
return result;
|
|
1381
|
+
} else if (isNumber2(z)(value)) {
|
|
1382
|
+
return this.defaultZodNumberHandler(value);
|
|
1383
|
+
} else if (isString2(z)(value)) {
|
|
1384
|
+
return this.defaultZodStringHandler(value);
|
|
1385
|
+
} else if (isDate(z)(value)) {
|
|
1386
|
+
return this.defaultZodDateHandler(value);
|
|
1387
|
+
} else if (value.constructor.name === "ZodAny") {
|
|
1388
|
+
return z.string().describe(
|
|
1389
|
+
(value.description ?? "") + `
|
|
1390
|
+
Argument was an "any" type, but you (the LLM) do not support "any", so it was cast to a "string" type`
|
|
1391
|
+
);
|
|
1392
|
+
}
|
|
1393
|
+
return this.defaultUnsupportedZodTypeHandler(value);
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
|
|
1397
|
+
export { ALL_ARRAY_CHECKS, ALL_NUMBER_CHECKS, ALL_STRING_CHECKS, ALL_ZOD_TYPES, AnthropicSchemaCompatLayer, DeepSeekSchemaCompatLayer, GoogleSchemaCompatLayer, MetaSchemaCompatLayer, OpenAIReasoningSchemaCompatLayer, OpenAISchemaCompatLayer, SUPPORTED_ZOD_TYPES, SchemaCompatLayer3 as SchemaCompatLayer, SchemaCompatLayer as SchemaCompatLayerV3, SchemaCompatLayer2 as SchemaCompatLayerV4, UNSUPPORTED_ZOD_TYPES, applyCompatLayer, convertSchemaToZod, convertZodSchemaToAISDKSchema, isArr, isNumber, isObj, isOptional, isString, isUnion };
|
|
1398
|
+
//# sourceMappingURL=index.js.map
|
|
1399
|
+
//# sourceMappingURL=index.js.map
|