@ai-sdk/openai 4.0.80 → 4.0.81

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 4.0.81
4
+
5
+ ### Patch Changes
6
+
7
+ - 4e94782: fix(openai): rewrite recursive Zod schemas that use `allOf` wrappers
8
+
3
9
  ## 4.0.80
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -926,7 +926,7 @@ import {
926
926
  function normalizeOpenAIJsonSchema(schema) {
927
927
  let removedPropertyNames = false;
928
928
  let removedLookaroundPattern = false;
929
- const normalizedSchema = normalizeSchema(schema);
929
+ const normalizedSchema = normalizeSchema(schema, true);
930
930
  const warnings = [];
931
931
  if (removedPropertyNames) {
932
932
  warnings.push({
@@ -946,7 +946,7 @@ function normalizeOpenAIJsonSchema(schema) {
946
946
  schema: normalizedSchema,
947
947
  warnings
948
948
  };
949
- function normalizeSchema(schema2) {
949
+ function normalizeSchema(schema2, isRoot = false) {
950
950
  const propertyNames = schema2.propertyNames;
951
951
  if (propertyNames != null) {
952
952
  if (typeof propertyNames === "boolean" || propertyNames.type !== "string") {
@@ -1026,7 +1026,45 @@ function normalizeOpenAIJsonSchema(schema) {
1026
1026
  normalizedSchema2[keyword] = normalizeDefinition(conditionalSchema);
1027
1027
  }
1028
1028
  }
1029
- return normalizedSchema2;
1029
+ const reference = getSingletonReference(normalizedSchema2);
1030
+ if (reference == null) {
1031
+ return normalizedSchema2;
1032
+ }
1033
+ const { allOf: _allOf, ...schemaWithoutAllOf } = normalizedSchema2;
1034
+ if (!isRoot) {
1035
+ return {
1036
+ ...schemaWithoutAllOf,
1037
+ $ref: reference
1038
+ };
1039
+ }
1040
+ const referencedSchema = getLocalReferenceSchema(
1041
+ reference,
1042
+ normalizedSchema2
1043
+ );
1044
+ if (referencedSchema == null) {
1045
+ return normalizedSchema2;
1046
+ }
1047
+ return {
1048
+ ...referencedSchema,
1049
+ ...schemaWithoutAllOf
1050
+ };
1051
+ }
1052
+ function getSingletonReference(schema2) {
1053
+ if (schema2.allOf?.length !== 1) {
1054
+ return void 0;
1055
+ }
1056
+ const [allOfSchema] = schema2.allOf;
1057
+ return typeof allOfSchema === "object" && allOfSchema != null && Object.keys(allOfSchema).length === 1 && typeof allOfSchema.$ref === "string" ? allOfSchema.$ref : void 0;
1058
+ }
1059
+ function getLocalReferenceSchema(reference, schema2) {
1060
+ const match = /^#\/(definitions|\$defs)\/(.+)$/.exec(reference);
1061
+ if (match == null) {
1062
+ return void 0;
1063
+ }
1064
+ const [, keyword, encodedName] = match;
1065
+ const name = encodedName.replace(/~1/g, "/").replace(/~0/g, "~");
1066
+ const definition = keyword === "definitions" ? schema2.definitions?.[name] : schema2.$defs?.[name];
1067
+ return typeof definition === "object" && definition != null ? definition : void 0;
1030
1068
  }
1031
1069
  function normalizeSchemaRecord(schemas) {
1032
1070
  return Object.fromEntries(
@@ -12054,7 +12092,7 @@ var OpenAISkills = class {
12054
12092
  };
12055
12093
 
12056
12094
  // src/version.ts
12057
- var VERSION = true ? "4.0.80" : "0.0.0-test";
12095
+ var VERSION = true ? "4.0.81" : "0.0.0-test";
12058
12096
 
12059
12097
  // src/openai-provider.ts
12060
12098
  function createOpenAI(options = {}) {