@mastra/schema-compat 1.3.14-alpha.0 → 1.3.15-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -5151,18 +5151,22 @@ function schemaValuesEqual(left, right, keyword) {
5151
5151
  const rightRecord = right;
5152
5152
  return leftEntries.length === Object.keys(rightRecord).length && leftEntries.every(([key, value]) => Object.prototype.hasOwnProperty.call(rightRecord, key) && schemaValuesEqual(value, rightRecord[key], key));
5153
5153
  }
5154
+ function isOpenAICompatibleModel(model) {
5155
+ const provider = model.provider ?? "";
5156
+ const modelId = model.modelId ?? "";
5157
+ if (provider.includes("openai") || modelId.includes("openai")) return true;
5158
+ return /^azure\.(chat|responses|completion)$/.test(provider) && /(^|[-_./:])(gpt|chatgpt)(?=$|[-_./:]|\d)|(^|[-_./:])o[1-9](?=$|[-_.:])/i.test(modelId) && !/(^|[-_./:])(claude|deepseek|meta|llama|codellama|mistral|ministral|mixtral|codestral|phi|grok|cohere)(?=$|[-_./:]|\d)/i.test(modelId);
5159
+ }
5154
5160
  var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
5155
5161
  getSchemaTarget() {
5156
5162
  return `jsonSchema7`;
5157
5163
  }
5158
5164
  isReasoningModel() {
5159
- const modelId = this.getModel().modelId;
5160
- if (!modelId) return false;
5161
- return modelId.includes(`o3`) || modelId.includes(`o4`) || modelId.includes(`o1`);
5165
+ return /(^|[-_./:])o[1-9](?=$|[-_.:])/i.test(this.getModel().modelId ?? "");
5162
5166
  }
5163
5167
  shouldApply() {
5164
5168
  const model = this.getModel();
5165
- if (!this.isReasoningModel() && (model.provider.includes(`openai`) || model.modelId?.includes(`openai`) || model.provider.includes(`groq`))) return true;
5169
+ if (!this.isReasoningModel() && (isOpenAICompatibleModel(model) || model.provider.includes(`groq`))) return true;
5166
5170
  return false;
5167
5171
  }
5168
5172
  processZodType(value) {
@@ -5389,6 +5393,15 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
5389
5393
  delete prop.type;
5390
5394
  prop.anyOf = [propSchema, { type: "null" }];
5391
5395
  }
5396
+ } else if (prop.type === void 0 && Array.isArray(prop.anyOf)) {
5397
+ if (!prop.anyOf.some((branch) => typeof branch !== "boolean" && branch.type === "null")) if (genericConstraintKeywords.some((keyword) => keyword in prop)) {
5398
+ const branch = { anyOf: prop.anyOf };
5399
+ for (const keyword of genericConstraintKeywords) if (keyword in prop) {
5400
+ branch[keyword] = prop[keyword];
5401
+ delete prop[keyword];
5402
+ }
5403
+ prop.anyOf = [branch, { type: "null" }];
5404
+ } else prop.anyOf = [...prop.anyOf, { type: "null" }];
5392
5405
  }
5393
5406
  }
5394
5407
  }
@@ -5451,14 +5464,9 @@ var OpenAIReasoningSchemaCompatLayer = class extends OpenAISchemaCompatLayer {
5451
5464
  getSchemaTarget() {
5452
5465
  return `openApi3`;
5453
5466
  }
5454
- isReasoningModel() {
5455
- const modelId = this.getModel().modelId;
5456
- if (!modelId) return false;
5457
- return modelId.includes(`o3`) || modelId.includes(`o4`) || modelId.includes(`o1`);
5458
- }
5459
5467
  shouldApply() {
5460
5468
  const model = this.getModel();
5461
- if (this.isReasoningModel() && (model.provider.includes(`openai`) || model.modelId?.includes(`openai`))) return true;
5469
+ if (this.isReasoningModel() && isOpenAICompatibleModel(model)) return true;
5462
5470
  return false;
5463
5471
  }
5464
5472
  processZodType(value) {
@@ -5546,10 +5554,11 @@ function extractZodSchema(schema) {
5546
5554
  * ```
5547
5555
  */
5548
5556
  function applyOpenAICompatTransforms(schema, modelInfo) {
5549
- if (!(modelInfo.provider?.includes("openai") || modelInfo.modelId?.includes("openai"))) return schema;
5557
+ if (!isOpenAICompatibleModel(modelInfo)) return schema;
5550
5558
  const zodSchema = extractZodSchema(schema);
5551
5559
  if (!zodSchema) return schema;
5552
- const compatLayer = /^o[1-5]/.test(modelInfo.modelId) ? new OpenAIReasoningSchemaCompatLayer(modelInfo) : new OpenAISchemaCompatLayer(modelInfo);
5560
+ const reasoningLayer = new OpenAIReasoningSchemaCompatLayer(modelInfo);
5561
+ const compatLayer = reasoningLayer.isReasoningModel() ? reasoningLayer : new OpenAISchemaCompatLayer(modelInfo);
5553
5562
  if (!compatLayer.shouldApply()) return schema;
5554
5563
  return require_schema.toStandardSchema(compatLayer.processZodType(zodSchema));
5555
5564
  }