@mastra/schema-compat 0.0.0-ai-v5-20250625173645

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.
@@ -0,0 +1,31 @@
1
+ export { SchemaCompatLayer } from './_tsup-dts-rollup.js';
2
+ export { ALL_STRING_CHECKS } from './_tsup-dts-rollup.js';
3
+ export { ALL_NUMBER_CHECKS } from './_tsup-dts-rollup.js';
4
+ export { ALL_ARRAY_CHECKS } from './_tsup-dts-rollup.js';
5
+ export { UNSUPPORTED_ZOD_TYPES } from './_tsup-dts-rollup.js';
6
+ export { SUPPORTED_ZOD_TYPES } from './_tsup-dts-rollup.js';
7
+ export { ALL_ZOD_TYPES } from './_tsup-dts-rollup.js';
8
+ export { StringCheckType } from './_tsup-dts-rollup.js';
9
+ export { NumberCheckType } from './_tsup-dts-rollup.js';
10
+ export { ArrayCheckType } from './_tsup-dts-rollup.js';
11
+ export { UnsupportedZodType } from './_tsup-dts-rollup.js';
12
+ export { SupportedZodType } from './_tsup-dts-rollup.js';
13
+ export { AllZodType } from './_tsup-dts-rollup.js';
14
+ export { ZodShape } from './_tsup-dts-rollup.js';
15
+ export { ShapeKey } from './_tsup-dts-rollup.js';
16
+ export { ShapeValue } from './_tsup-dts-rollup.js';
17
+ export { isOptional } from './_tsup-dts-rollup.js';
18
+ export { isObj } from './_tsup-dts-rollup.js';
19
+ export { isArr } from './_tsup-dts-rollup.js';
20
+ export { isUnion } from './_tsup-dts-rollup.js';
21
+ export { isString } from './_tsup-dts-rollup.js';
22
+ export { isNumber } from './_tsup-dts-rollup.js';
23
+ export { convertZodSchemaToAISDKSchema } from './_tsup-dts-rollup.js';
24
+ export { applyCompatLayer } from './_tsup-dts-rollup.js';
25
+ export { convertSchemaToZod } from './_tsup-dts-rollup.js';
26
+ export { AnthropicSchemaCompatLayer } from './_tsup-dts-rollup.js';
27
+ export { DeepSeekSchemaCompatLayer } from './_tsup-dts-rollup.js';
28
+ export { GoogleSchemaCompatLayer } from './_tsup-dts-rollup.js';
29
+ export { MetaSchemaCompatLayer } from './_tsup-dts-rollup.js';
30
+ export { OpenAISchemaCompatLayer } from './_tsup-dts-rollup.js';
31
+ export { OpenAIReasoningSchemaCompatLayer } from './_tsup-dts-rollup.js';
package/dist/index.js ADDED
@@ -0,0 +1,647 @@
1
+ import { ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, z, ZodDefault, ZodDate } from 'zod';
2
+ import { jsonSchema } from 'ai';
3
+ import { convertJsonSchemaToZod } from 'zod-from-json-schema';
4
+ import { zodToJsonSchema } from 'zod-to-json-schema';
5
+
6
+ // src/schema-compatibility.ts
7
+ function convertZodSchemaToAISDKSchema(zodSchema, target = "jsonSchema7") {
8
+ return jsonSchema(
9
+ zodToJsonSchema(zodSchema, {
10
+ $refStrategy: "none",
11
+ target
12
+ }),
13
+ {
14
+ validate: (value) => {
15
+ const result = zodSchema.safeParse(value);
16
+ return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
17
+ }
18
+ }
19
+ );
20
+ }
21
+ function isZodType(value) {
22
+ return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
23
+ }
24
+ function convertSchemaToZod(schema) {
25
+ if (isZodType(schema)) {
26
+ return schema;
27
+ } else {
28
+ const jsonSchemaToConvert = "jsonSchema" in schema ? schema.jsonSchema : schema;
29
+ try {
30
+ return convertJsonSchemaToZod(jsonSchemaToConvert);
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, { $refStrategy: "none", target: "jsonSchema7" });
57
+ } else {
58
+ return convertZodSchemaToAISDKSchema(zodSchema);
59
+ }
60
+ }
61
+
62
+ // src/schema-compatibility.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 isDate = (v) => v instanceof ZodDate;
79
+ var isDefault = (v) => v instanceof ZodDefault;
80
+ var UNSUPPORTED_ZOD_TYPES = ["ZodIntersection", "ZodNever", "ZodNull", "ZodTuple", "ZodUndefined"];
81
+ var SUPPORTED_ZOD_TYPES = [
82
+ "ZodObject",
83
+ "ZodArray",
84
+ "ZodUnion",
85
+ "ZodString",
86
+ "ZodNumber",
87
+ "ZodDate",
88
+ "ZodAny",
89
+ "ZodDefault"
90
+ ];
91
+ var ALL_ZOD_TYPES = [...SUPPORTED_ZOD_TYPES, ...UNSUPPORTED_ZOD_TYPES];
92
+ var SchemaCompatLayer = class {
93
+ model;
94
+ /**
95
+ * Creates a new schema compatibility instance.
96
+ *
97
+ * @param model - The language model this compatibility layer applies to
98
+ */
99
+ constructor(model) {
100
+ this.model = model;
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
+ /**
111
+ * Default handler for Zod object types. Recursively processes all properties in the object.
112
+ *
113
+ * @param value - The Zod object to process
114
+ * @returns The processed Zod object
115
+ */
116
+ defaultZodObjectHandler(value) {
117
+ const processedShape = Object.entries(value.shape).reduce((acc, [key, propValue]) => {
118
+ acc[key] = this.processZodType(propValue);
119
+ return acc;
120
+ }, {});
121
+ let result = z.object(processedShape);
122
+ if (value._def.unknownKeys === "strict") {
123
+ result = result.strict();
124
+ }
125
+ if (value._def.catchall && !(value._def.catchall instanceof z.ZodNever)) {
126
+ result = result.catchall(value._def.catchall);
127
+ }
128
+ if (value.description) {
129
+ result = result.describe(value.description);
130
+ }
131
+ return result;
132
+ }
133
+ /**
134
+ * Merges validation constraints into a parameter description.
135
+ *
136
+ * This helper method converts validation constraints that may not be supported
137
+ * by a provider into human-readable descriptions.
138
+ *
139
+ * @param description - The existing parameter description
140
+ * @param constraints - The validation constraints to merge
141
+ * @returns The updated description with constraints, or undefined if no constraints
142
+ */
143
+ mergeParameterDescription(description, constraints) {
144
+ if (Object.keys(constraints).length > 0) {
145
+ return (description ? description + "\n" : "") + JSON.stringify(constraints);
146
+ } else {
147
+ return description;
148
+ }
149
+ }
150
+ /**
151
+ * Default handler for unsupported Zod types. Throws an error for specified unsupported types.
152
+ *
153
+ * @param value - The Zod type to check
154
+ * @param throwOnTypes - Array of type names to throw errors for
155
+ * @returns The original value if not in the throw list
156
+ * @throws Error if the type is in the unsupported list
157
+ */
158
+ defaultUnsupportedZodTypeHandler(value, throwOnTypes = UNSUPPORTED_ZOD_TYPES) {
159
+ if (throwOnTypes.includes(value._def.typeName)) {
160
+ throw new Error(`${this.model.modelId} does not support zod type: ${value._def.typeName}`);
161
+ }
162
+ return value;
163
+ }
164
+ /**
165
+ * Default handler for Zod array types. Processes array constraints according to provider support.
166
+ *
167
+ * @param value - The Zod array to process
168
+ * @param handleChecks - Array constraints to convert to descriptions vs keep as validation
169
+ * @returns The processed Zod array
170
+ */
171
+ defaultZodArrayHandler(value, handleChecks = ALL_ARRAY_CHECKS) {
172
+ const zodArrayDef = value._def;
173
+ const processedType = this.processZodType(zodArrayDef.type);
174
+ let result = z.array(processedType);
175
+ const constraints = {};
176
+ if (zodArrayDef.minLength?.value !== void 0) {
177
+ if (handleChecks.includes("min")) {
178
+ constraints.minLength = zodArrayDef.minLength.value;
179
+ } else {
180
+ result = result.min(zodArrayDef.minLength.value);
181
+ }
182
+ }
183
+ if (zodArrayDef.maxLength?.value !== void 0) {
184
+ if (handleChecks.includes("max")) {
185
+ constraints.maxLength = zodArrayDef.maxLength.value;
186
+ } else {
187
+ result = result.max(zodArrayDef.maxLength.value);
188
+ }
189
+ }
190
+ if (zodArrayDef.exactLength?.value !== void 0) {
191
+ if (handleChecks.includes("length")) {
192
+ constraints.exactLength = zodArrayDef.exactLength.value;
193
+ } else {
194
+ result = result.length(zodArrayDef.exactLength.value);
195
+ }
196
+ }
197
+ const description = this.mergeParameterDescription(value.description, constraints);
198
+ if (description) {
199
+ result = result.describe(description);
200
+ }
201
+ return result;
202
+ }
203
+ /**
204
+ * Default handler for Zod union types. Processes all union options.
205
+ *
206
+ * @param value - The Zod union to process
207
+ * @returns The processed Zod union
208
+ * @throws Error if union has fewer than 2 options
209
+ */
210
+ defaultZodUnionHandler(value) {
211
+ const processedOptions = value._def.options.map((option) => this.processZodType(option));
212
+ if (processedOptions.length < 2) throw new Error("Union must have at least 2 options");
213
+ let result = z.union(processedOptions);
214
+ if (value.description) {
215
+ result = result.describe(value.description);
216
+ }
217
+ return result;
218
+ }
219
+ /**
220
+ * Default handler for Zod string types. Processes string validation constraints.
221
+ *
222
+ * @param value - The Zod string to process
223
+ * @param handleChecks - String constraints to convert to descriptions vs keep as validation
224
+ * @returns The processed Zod string
225
+ */
226
+ defaultZodStringHandler(value, handleChecks = ALL_STRING_CHECKS) {
227
+ const constraints = {};
228
+ const checks = value._def.checks || [];
229
+ const newChecks = [];
230
+ for (const check of checks) {
231
+ if ("kind" in check) {
232
+ if (handleChecks.includes(check.kind)) {
233
+ switch (check.kind) {
234
+ case "regex": {
235
+ constraints.regex = {
236
+ pattern: check.regex.source,
237
+ flags: check.regex.flags
238
+ };
239
+ break;
240
+ }
241
+ case "emoji": {
242
+ constraints.emoji = true;
243
+ break;
244
+ }
245
+ case "email": {
246
+ constraints.email = true;
247
+ break;
248
+ }
249
+ case "url": {
250
+ constraints.url = true;
251
+ break;
252
+ }
253
+ case "uuid": {
254
+ constraints.uuid = true;
255
+ break;
256
+ }
257
+ case "cuid": {
258
+ constraints.cuid = true;
259
+ break;
260
+ }
261
+ case "min": {
262
+ constraints.minLength = check.value;
263
+ break;
264
+ }
265
+ case "max": {
266
+ constraints.maxLength = check.value;
267
+ break;
268
+ }
269
+ }
270
+ } else {
271
+ newChecks.push(check);
272
+ }
273
+ }
274
+ }
275
+ let result = z.string();
276
+ for (const check of newChecks) {
277
+ result = result._addCheck(check);
278
+ }
279
+ const description = this.mergeParameterDescription(value.description, constraints);
280
+ if (description) {
281
+ result = result.describe(description);
282
+ }
283
+ return result;
284
+ }
285
+ /**
286
+ * Default handler for Zod number types. Processes number validation constraints.
287
+ *
288
+ * @param value - The Zod number to process
289
+ * @param handleChecks - Number constraints to convert to descriptions vs keep as validation
290
+ * @returns The processed Zod number
291
+ */
292
+ defaultZodNumberHandler(value, handleChecks = ALL_NUMBER_CHECKS) {
293
+ const constraints = {};
294
+ const checks = value._def.checks || [];
295
+ const newChecks = [];
296
+ for (const check of checks) {
297
+ if ("kind" in check) {
298
+ if (handleChecks.includes(check.kind)) {
299
+ switch (check.kind) {
300
+ case "min":
301
+ if (check.inclusive) {
302
+ constraints.gte = check.value;
303
+ } else {
304
+ constraints.gt = check.value;
305
+ }
306
+ break;
307
+ case "max":
308
+ if (check.inclusive) {
309
+ constraints.lte = check.value;
310
+ } else {
311
+ constraints.lt = check.value;
312
+ }
313
+ break;
314
+ case "multipleOf": {
315
+ constraints.multipleOf = check.value;
316
+ break;
317
+ }
318
+ }
319
+ } else {
320
+ newChecks.push(check);
321
+ }
322
+ }
323
+ }
324
+ let result = z.number();
325
+ for (const check of newChecks) {
326
+ switch (check.kind) {
327
+ case "int":
328
+ result = result.int();
329
+ break;
330
+ case "finite":
331
+ result = result.finite();
332
+ break;
333
+ default:
334
+ result = result._addCheck(check);
335
+ }
336
+ }
337
+ const description = this.mergeParameterDescription(value.description, constraints);
338
+ if (description) {
339
+ result = result.describe(description);
340
+ }
341
+ return result;
342
+ }
343
+ /**
344
+ * Default handler for Zod date types. Converts dates to ISO strings with constraint descriptions.
345
+ *
346
+ * @param value - The Zod date to process
347
+ * @returns A Zod string schema representing the date in ISO format
348
+ */
349
+ defaultZodDateHandler(value) {
350
+ const constraints = {};
351
+ const checks = value._def.checks || [];
352
+ for (const check of checks) {
353
+ if ("kind" in check) {
354
+ switch (check.kind) {
355
+ case "min":
356
+ const minDate = new Date(check.value);
357
+ if (!isNaN(minDate.getTime())) {
358
+ constraints.minDate = minDate.toISOString();
359
+ }
360
+ break;
361
+ case "max":
362
+ const maxDate = new Date(check.value);
363
+ if (!isNaN(maxDate.getTime())) {
364
+ constraints.maxDate = maxDate.toISOString();
365
+ }
366
+ break;
367
+ }
368
+ }
369
+ }
370
+ constraints.dateFormat = "date-time";
371
+ let result = z.string().describe("date-time");
372
+ const description = this.mergeParameterDescription(value.description, constraints);
373
+ if (description) {
374
+ result = result.describe(description);
375
+ }
376
+ return result;
377
+ }
378
+ /**
379
+ * Default handler for Zod optional types. Processes the inner type and maintains optionality.
380
+ *
381
+ * @param value - The Zod optional to process
382
+ * @param handleTypes - Types that should be processed vs passed through
383
+ * @returns The processed Zod optional
384
+ */
385
+ defaultZodOptionalHandler(value, handleTypes = SUPPORTED_ZOD_TYPES) {
386
+ if (handleTypes.includes(value._def.innerType._def.typeName)) {
387
+ return this.processZodType(value._def.innerType).optional();
388
+ } else {
389
+ return value;
390
+ }
391
+ }
392
+ /**
393
+ * Processes a Zod object schema and converts it to an AI SDK Schema.
394
+ *
395
+ * @param zodSchema - The Zod object schema to process
396
+ * @returns An AI SDK Schema with provider-specific compatibility applied
397
+ */
398
+ processToAISDKSchema(zodSchema) {
399
+ const processedSchema = this.processZodType(zodSchema);
400
+ return convertZodSchemaToAISDKSchema(processedSchema, this.getSchemaTarget());
401
+ }
402
+ /**
403
+ * Processes a Zod object schema and converts it to a JSON Schema.
404
+ *
405
+ * @param zodSchema - The Zod object schema to process
406
+ * @returns A JSONSchema7 object with provider-specific compatibility applied
407
+ */
408
+ processToJSONSchema(zodSchema) {
409
+ return this.processToAISDKSchema(zodSchema).jsonSchema;
410
+ }
411
+ };
412
+
413
+ // src/provider-compats/anthropic.ts
414
+ var AnthropicSchemaCompatLayer = class extends SchemaCompatLayer {
415
+ constructor(model) {
416
+ super(model);
417
+ }
418
+ getSchemaTarget() {
419
+ return "jsonSchema7";
420
+ }
421
+ shouldApply() {
422
+ return this.getModel().modelId.includes("claude");
423
+ }
424
+ processZodType(value) {
425
+ if (isOptional(value)) {
426
+ const handleTypes = ["ZodObject", "ZodArray", "ZodUnion", "ZodNever", "ZodUndefined"];
427
+ if (this.getModel().modelId.includes("claude-3.5-haiku")) handleTypes.push("ZodString");
428
+ if (this.getModel().modelId.includes("claude-3.7")) handleTypes.push("ZodTuple");
429
+ return this.defaultZodOptionalHandler(value, handleTypes);
430
+ } else if (isObj(value)) {
431
+ return this.defaultZodObjectHandler(value);
432
+ } else if (isArr(value)) {
433
+ return this.defaultZodArrayHandler(value, []);
434
+ } else if (isUnion(value)) {
435
+ return this.defaultZodUnionHandler(value);
436
+ } else if (isString(value)) {
437
+ if (this.getModel().modelId.includes("claude-3.5-haiku")) {
438
+ return this.defaultZodStringHandler(value, ["max", "min"]);
439
+ } else {
440
+ return value;
441
+ }
442
+ }
443
+ if (this.getModel().modelId.includes("claude-3.7")) {
444
+ return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodTuple", "ZodUndefined"]);
445
+ } else {
446
+ return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodUndefined"]);
447
+ }
448
+ }
449
+ };
450
+
451
+ // src/provider-compats/deepseek.ts
452
+ var DeepSeekSchemaCompatLayer = class extends SchemaCompatLayer {
453
+ constructor(model) {
454
+ super(model);
455
+ }
456
+ getSchemaTarget() {
457
+ return "jsonSchema7";
458
+ }
459
+ shouldApply() {
460
+ return this.getModel().modelId.includes("deepseek") && !this.getModel().modelId.includes("r1");
461
+ }
462
+ processZodType(value) {
463
+ if (isOptional(value)) {
464
+ return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
465
+ } else if (isObj(value)) {
466
+ return this.defaultZodObjectHandler(value);
467
+ } else if (isArr(value)) {
468
+ return this.defaultZodArrayHandler(value, ["min", "max"]);
469
+ } else if (isUnion(value)) {
470
+ return this.defaultZodUnionHandler(value);
471
+ } else if (isString(value)) {
472
+ return this.defaultZodStringHandler(value);
473
+ }
474
+ return value;
475
+ }
476
+ };
477
+
478
+ // src/provider-compats/google.ts
479
+ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer {
480
+ constructor(model) {
481
+ super(model);
482
+ }
483
+ getSchemaTarget() {
484
+ return "jsonSchema7";
485
+ }
486
+ shouldApply() {
487
+ return this.getModel().provider.includes("google") || this.getModel().modelId.includes("google");
488
+ }
489
+ processZodType(value) {
490
+ if (isOptional(value)) {
491
+ return this.defaultZodOptionalHandler(value, [
492
+ "ZodObject",
493
+ "ZodArray",
494
+ "ZodUnion",
495
+ "ZodString",
496
+ "ZodNumber",
497
+ ...UNSUPPORTED_ZOD_TYPES
498
+ ]);
499
+ } else if (isObj(value)) {
500
+ return this.defaultZodObjectHandler(value);
501
+ } else if (isArr(value)) {
502
+ return this.defaultZodArrayHandler(value, []);
503
+ } else if (isUnion(value)) {
504
+ return this.defaultZodUnionHandler(value);
505
+ } else if (isString(value)) {
506
+ return this.defaultZodStringHandler(value);
507
+ } else if (isNumber(value)) {
508
+ return this.defaultZodNumberHandler(value);
509
+ }
510
+ return this.defaultUnsupportedZodTypeHandler(value);
511
+ }
512
+ };
513
+
514
+ // src/provider-compats/meta.ts
515
+ var MetaSchemaCompatLayer = class extends SchemaCompatLayer {
516
+ constructor(model) {
517
+ super(model);
518
+ }
519
+ getSchemaTarget() {
520
+ return "jsonSchema7";
521
+ }
522
+ shouldApply() {
523
+ return this.getModel().modelId.includes("meta");
524
+ }
525
+ processZodType(value) {
526
+ if (isOptional(value)) {
527
+ return this.defaultZodOptionalHandler(value, ["ZodObject", "ZodArray", "ZodUnion", "ZodString", "ZodNumber"]);
528
+ } else if (isObj(value)) {
529
+ return this.defaultZodObjectHandler(value);
530
+ } else if (isArr(value)) {
531
+ return this.defaultZodArrayHandler(value, ["min", "max"]);
532
+ } else if (isUnion(value)) {
533
+ return this.defaultZodUnionHandler(value);
534
+ } else if (isNumber(value)) {
535
+ return this.defaultZodNumberHandler(value);
536
+ } else if (isString(value)) {
537
+ return this.defaultZodStringHandler(value);
538
+ }
539
+ return value;
540
+ }
541
+ };
542
+
543
+ // src/provider-compats/openai.ts
544
+ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
545
+ constructor(model) {
546
+ super(model);
547
+ }
548
+ getSchemaTarget() {
549
+ return `jsonSchema7`;
550
+ }
551
+ shouldApply() {
552
+ if (
553
+ // !this.getModel().supportsStructuredOutputs && // <- TODO: this no longer exists, do we need it?
554
+ this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`)
555
+ ) {
556
+ return true;
557
+ }
558
+ return false;
559
+ }
560
+ processZodType(value) {
561
+ if (isOptional(value)) {
562
+ return this.defaultZodOptionalHandler(value, [
563
+ "ZodObject",
564
+ "ZodArray",
565
+ "ZodUnion",
566
+ "ZodString",
567
+ "ZodNever",
568
+ "ZodUndefined",
569
+ "ZodTuple"
570
+ ]);
571
+ } else if (isObj(value)) {
572
+ return this.defaultZodObjectHandler(value);
573
+ } else if (isUnion(value)) {
574
+ return this.defaultZodUnionHandler(value);
575
+ } else if (isArr(value)) {
576
+ return this.defaultZodArrayHandler(value);
577
+ } else if (isString(value)) {
578
+ const model = this.getModel();
579
+ const checks = ["emoji"];
580
+ if (model.modelId.includes("gpt-4o-mini")) {
581
+ checks.push("regex");
582
+ }
583
+ return this.defaultZodStringHandler(value, checks);
584
+ }
585
+ return this.defaultUnsupportedZodTypeHandler(value, ["ZodNever", "ZodUndefined", "ZodTuple"]);
586
+ }
587
+ };
588
+ var OpenAIReasoningSchemaCompatLayer = class extends SchemaCompatLayer {
589
+ constructor(model) {
590
+ super(model);
591
+ }
592
+ getSchemaTarget() {
593
+ return `openApi3`;
594
+ }
595
+ isReasoningModel() {
596
+ return this.getModel().modelId.includes(`o3`) || this.getModel().modelId.includes(`o4`);
597
+ }
598
+ shouldApply() {
599
+ if (
600
+ // (this.getModel().supportsStructuredOutputs || this.isReasoningModel()) && // <- supportsStructuredOutputs no longer exists
601
+ this.isReasoningModel() && (this.getModel().provider.includes(`openai`) || this.getModel().modelId.includes(`openai`))
602
+ ) {
603
+ return true;
604
+ }
605
+ return false;
606
+ }
607
+ processZodType(value) {
608
+ if (isOptional(value)) {
609
+ const innerZodType = this.processZodType(value._def.innerType);
610
+ return innerZodType.nullable();
611
+ } else if (isObj(value)) {
612
+ return this.defaultZodObjectHandler(value);
613
+ } else if (isArr(value)) {
614
+ return this.defaultZodArrayHandler(value);
615
+ } else if (isUnion(value)) {
616
+ return this.defaultZodUnionHandler(value);
617
+ } else if (isDefault(value)) {
618
+ const defaultDef = value._def;
619
+ const innerType = defaultDef.innerType;
620
+ const defaultValue = defaultDef.defaultValue();
621
+ const constraints = {};
622
+ if (defaultValue !== void 0) {
623
+ constraints.defaultValue = defaultValue;
624
+ }
625
+ const description = this.mergeParameterDescription(value.description, constraints);
626
+ let result = this.processZodType(innerType);
627
+ if (description) {
628
+ result = result.describe(description);
629
+ }
630
+ return result;
631
+ } else if (isNumber(value)) {
632
+ return this.defaultZodNumberHandler(value);
633
+ } else if (isString(value)) {
634
+ return this.defaultZodStringHandler(value);
635
+ } else if (isDate(value)) {
636
+ return this.defaultZodDateHandler(value);
637
+ } else if (value._def.typeName === "ZodAny") {
638
+ return z.string().describe(
639
+ (value.description ?? "") + `
640
+ Argument was an "any" type, but you (the LLM) do not support "any", so it was cast to a "string" type`
641
+ );
642
+ }
643
+ return this.defaultUnsupportedZodTypeHandler(value);
644
+ }
645
+ };
646
+
647
+ export { ALL_ARRAY_CHECKS, ALL_NUMBER_CHECKS, ALL_STRING_CHECKS, ALL_ZOD_TYPES, AnthropicSchemaCompatLayer, DeepSeekSchemaCompatLayer, GoogleSchemaCompatLayer, MetaSchemaCompatLayer, OpenAIReasoningSchemaCompatLayer, OpenAISchemaCompatLayer, SUPPORTED_ZOD_TYPES, SchemaCompatLayer, UNSUPPORTED_ZOD_TYPES, applyCompatLayer, convertSchemaToZod, convertZodSchemaToAISDKSchema, isArr, isNumber, isObj, isOptional, isString, isUnion };
@@ -0,0 +1,6 @@
1
+ import { createConfig } from '@internal/lint/eslint';
2
+
3
+ const config = await createConfig();
4
+
5
+ /** @type {import("eslint").Linter.Config[]} */
6
+ export default [...config];