@ai-sdk/openai 3.0.123 → 3.0.124

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
+ ## 3.0.124
4
+
5
+ ### Patch Changes
6
+
7
+ - d131a3b: fix(openai): rewrite recursive Zod schemas that use `allOf` wrappers
8
+
3
9
  ## 3.0.123
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1125,7 +1125,7 @@ declare const openaiLanguageModelResponsesOptionsSchema: _ai_sdk_provider_utils.
1125
1125
  forceReasoning?: boolean | undefined;
1126
1126
  allowedTools?: {
1127
1127
  toolNames: string[];
1128
- mode?: "auto" | "required" | undefined;
1128
+ mode?: "required" | "auto" | undefined;
1129
1129
  } | undefined;
1130
1130
  }>;
1131
1131
  type OpenAILanguageModelResponsesOptions = InferSchema<typeof openaiLanguageModelResponsesOptionsSchema>;
package/dist/index.d.ts CHANGED
@@ -1125,7 +1125,7 @@ declare const openaiLanguageModelResponsesOptionsSchema: _ai_sdk_provider_utils.
1125
1125
  forceReasoning?: boolean | undefined;
1126
1126
  allowedTools?: {
1127
1127
  toolNames: string[];
1128
- mode?: "auto" | "required" | undefined;
1128
+ mode?: "required" | "auto" | undefined;
1129
1129
  } | undefined;
1130
1130
  }>;
1131
1131
  type OpenAILanguageModelResponsesOptions = InferSchema<typeof openaiLanguageModelResponsesOptionsSchema>;
package/dist/index.js CHANGED
@@ -93,6 +93,98 @@ function getGptVersion(modelId) {
93
93
  };
94
94
  }
95
95
 
96
+ // src/normalize-openai-json-schema.ts
97
+ function normalizeOpenAIJsonSchema(schema) {
98
+ const normalizedSchema = normalizeSchema(schema, true);
99
+ const reference = getSingletonReference(normalizedSchema);
100
+ if (reference == null) {
101
+ return normalizedSchema;
102
+ }
103
+ const { allOf: _allOf, ...schemaWithoutAllOf } = normalizedSchema;
104
+ const referencedSchema = getLocalReferenceSchema(reference, normalizedSchema);
105
+ return typeof referencedSchema !== "object" || referencedSchema == null ? normalizedSchema : { ...referencedSchema, ...schemaWithoutAllOf };
106
+ function normalizeSchema(schema2, isRoot = false) {
107
+ if (typeof schema2 !== "object" || schema2 == null) {
108
+ return schema2;
109
+ }
110
+ const normalizedSchema2 = { ...schema2 };
111
+ if (normalizedSchema2.properties != null) {
112
+ normalizedSchema2.properties = normalizeSchemaRecord(
113
+ normalizedSchema2.properties
114
+ );
115
+ }
116
+ if (normalizedSchema2.patternProperties != null) {
117
+ normalizedSchema2.patternProperties = normalizeSchemaRecord(
118
+ normalizedSchema2.patternProperties
119
+ );
120
+ }
121
+ if (normalizedSchema2.definitions != null) {
122
+ normalizedSchema2.definitions = normalizeSchemaRecord(
123
+ normalizedSchema2.definitions
124
+ );
125
+ }
126
+ if (normalizedSchema2.$defs != null) {
127
+ normalizedSchema2.$defs = normalizeSchemaRecord(normalizedSchema2.$defs);
128
+ }
129
+ if (normalizedSchema2.items != null) {
130
+ normalizedSchema2.items = Array.isArray(normalizedSchema2.items) ? normalizedSchema2.items.map((item) => normalizeSchema(item)) : normalizeSchema(normalizedSchema2.items);
131
+ }
132
+ if (normalizedSchema2.allOf != null) {
133
+ normalizedSchema2.allOf = normalizedSchema2.allOf.map(
134
+ (item) => normalizeSchema(item)
135
+ );
136
+ }
137
+ if (normalizedSchema2.anyOf != null) {
138
+ normalizedSchema2.anyOf = normalizedSchema2.anyOf.map(
139
+ (item) => normalizeSchema(item)
140
+ );
141
+ }
142
+ if (normalizedSchema2.oneOf != null) {
143
+ normalizedSchema2.oneOf = normalizedSchema2.oneOf.map(
144
+ (item) => normalizeSchema(item)
145
+ );
146
+ }
147
+ if (typeof normalizedSchema2.additionalProperties === "object" && normalizedSchema2.additionalProperties != null) {
148
+ normalizedSchema2.additionalProperties = normalizeSchema(
149
+ normalizedSchema2.additionalProperties
150
+ );
151
+ }
152
+ const reference2 = getSingletonReference(normalizedSchema2);
153
+ if (reference2 == null || isRoot) {
154
+ return normalizedSchema2;
155
+ }
156
+ const { allOf: _allOf2, ...schemaWithoutAllOf2 } = normalizedSchema2;
157
+ return { ...schemaWithoutAllOf2, $ref: reference2 };
158
+ }
159
+ function normalizeSchemaRecord(record) {
160
+ return Object.fromEntries(
161
+ Object.entries(record).map(([key, value]) => [
162
+ key,
163
+ normalizeSchema(value)
164
+ ])
165
+ );
166
+ }
167
+ function getSingletonReference(schema2) {
168
+ var _a2;
169
+ if (((_a2 = schema2.allOf) == null ? void 0 : _a2.length) !== 1) {
170
+ return void 0;
171
+ }
172
+ const [allOfSchema] = schema2.allOf;
173
+ return typeof allOfSchema === "object" && allOfSchema != null && Object.keys(allOfSchema).length === 1 && typeof allOfSchema.$ref === "string" ? allOfSchema.$ref : void 0;
174
+ }
175
+ function getLocalReferenceSchema(reference2, schema2) {
176
+ var _a2, _b;
177
+ const match = /^#\/(definitions|\$defs)\/(.+)$/.exec(reference2);
178
+ if (match == null) {
179
+ return void 0;
180
+ }
181
+ const [, keyword, encodedName] = match;
182
+ const name = encodedName.replace(/~1/g, "/").replace(/~0/g, "~");
183
+ const definition = keyword === "definitions" ? (_a2 = schema2.definitions) == null ? void 0 : _a2[name] : (_b = schema2.$defs) == null ? void 0 : _b[name];
184
+ return definition;
185
+ }
186
+ }
187
+
96
188
  // src/openai-stream-error.ts
97
189
  var import_provider = require("@ai-sdk/provider");
98
190
  function createOpenAIProviderStreamError(frame) {
@@ -987,7 +1079,7 @@ var OpenAIChatLanguageModel = class {
987
1079
  response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
988
1080
  type: "json_schema",
989
1081
  json_schema: {
990
- schema: responseFormat.schema,
1082
+ schema: normalizeOpenAIJsonSchema(responseFormat.schema),
991
1083
  strict: strictJsonSchema,
992
1084
  name: (_e = responseFormat.name) != null ? _e : "response",
993
1085
  description: responseFormat.description
@@ -6000,7 +6092,7 @@ var OpenAIResponsesLanguageModel = class {
6000
6092
  strict: strictJsonSchema,
6001
6093
  name: (_h = responseFormat.name) != null ? _h : "response",
6002
6094
  description: responseFormat.description,
6003
- schema: responseFormat.schema
6095
+ schema: normalizeOpenAIJsonSchema(responseFormat.schema)
6004
6096
  } : { type: "json_object" }
6005
6097
  },
6006
6098
  ...(openaiOptions == null ? void 0 : openaiOptions.textVerbosity) && {
@@ -8140,7 +8232,7 @@ var OpenAITranscriptionModel = class {
8140
8232
  };
8141
8233
 
8142
8234
  // src/version.ts
8143
- var VERSION = true ? "3.0.123" : "0.0.0-test";
8235
+ var VERSION = true ? "3.0.124" : "0.0.0-test";
8144
8236
 
8145
8237
  // src/openai-provider.ts
8146
8238
  function createOpenAI(options = {}) {