@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/dist/index.mjs CHANGED
@@ -80,6 +80,98 @@ function getGptVersion(modelId) {
80
80
  };
81
81
  }
82
82
 
83
+ // src/normalize-openai-json-schema.ts
84
+ function normalizeOpenAIJsonSchema(schema) {
85
+ const normalizedSchema = normalizeSchema(schema, true);
86
+ const reference = getSingletonReference(normalizedSchema);
87
+ if (reference == null) {
88
+ return normalizedSchema;
89
+ }
90
+ const { allOf: _allOf, ...schemaWithoutAllOf } = normalizedSchema;
91
+ const referencedSchema = getLocalReferenceSchema(reference, normalizedSchema);
92
+ return typeof referencedSchema !== "object" || referencedSchema == null ? normalizedSchema : { ...referencedSchema, ...schemaWithoutAllOf };
93
+ function normalizeSchema(schema2, isRoot = false) {
94
+ if (typeof schema2 !== "object" || schema2 == null) {
95
+ return schema2;
96
+ }
97
+ const normalizedSchema2 = { ...schema2 };
98
+ if (normalizedSchema2.properties != null) {
99
+ normalizedSchema2.properties = normalizeSchemaRecord(
100
+ normalizedSchema2.properties
101
+ );
102
+ }
103
+ if (normalizedSchema2.patternProperties != null) {
104
+ normalizedSchema2.patternProperties = normalizeSchemaRecord(
105
+ normalizedSchema2.patternProperties
106
+ );
107
+ }
108
+ if (normalizedSchema2.definitions != null) {
109
+ normalizedSchema2.definitions = normalizeSchemaRecord(
110
+ normalizedSchema2.definitions
111
+ );
112
+ }
113
+ if (normalizedSchema2.$defs != null) {
114
+ normalizedSchema2.$defs = normalizeSchemaRecord(normalizedSchema2.$defs);
115
+ }
116
+ if (normalizedSchema2.items != null) {
117
+ normalizedSchema2.items = Array.isArray(normalizedSchema2.items) ? normalizedSchema2.items.map((item) => normalizeSchema(item)) : normalizeSchema(normalizedSchema2.items);
118
+ }
119
+ if (normalizedSchema2.allOf != null) {
120
+ normalizedSchema2.allOf = normalizedSchema2.allOf.map(
121
+ (item) => normalizeSchema(item)
122
+ );
123
+ }
124
+ if (normalizedSchema2.anyOf != null) {
125
+ normalizedSchema2.anyOf = normalizedSchema2.anyOf.map(
126
+ (item) => normalizeSchema(item)
127
+ );
128
+ }
129
+ if (normalizedSchema2.oneOf != null) {
130
+ normalizedSchema2.oneOf = normalizedSchema2.oneOf.map(
131
+ (item) => normalizeSchema(item)
132
+ );
133
+ }
134
+ if (typeof normalizedSchema2.additionalProperties === "object" && normalizedSchema2.additionalProperties != null) {
135
+ normalizedSchema2.additionalProperties = normalizeSchema(
136
+ normalizedSchema2.additionalProperties
137
+ );
138
+ }
139
+ const reference2 = getSingletonReference(normalizedSchema2);
140
+ if (reference2 == null || isRoot) {
141
+ return normalizedSchema2;
142
+ }
143
+ const { allOf: _allOf2, ...schemaWithoutAllOf2 } = normalizedSchema2;
144
+ return { ...schemaWithoutAllOf2, $ref: reference2 };
145
+ }
146
+ function normalizeSchemaRecord(record) {
147
+ return Object.fromEntries(
148
+ Object.entries(record).map(([key, value]) => [
149
+ key,
150
+ normalizeSchema(value)
151
+ ])
152
+ );
153
+ }
154
+ function getSingletonReference(schema2) {
155
+ var _a2;
156
+ if (((_a2 = schema2.allOf) == null ? void 0 : _a2.length) !== 1) {
157
+ return void 0;
158
+ }
159
+ const [allOfSchema] = schema2.allOf;
160
+ return typeof allOfSchema === "object" && allOfSchema != null && Object.keys(allOfSchema).length === 1 && typeof allOfSchema.$ref === "string" ? allOfSchema.$ref : void 0;
161
+ }
162
+ function getLocalReferenceSchema(reference2, schema2) {
163
+ var _a2, _b;
164
+ const match = /^#\/(definitions|\$defs)\/(.+)$/.exec(reference2);
165
+ if (match == null) {
166
+ return void 0;
167
+ }
168
+ const [, keyword, encodedName] = match;
169
+ const name = encodedName.replace(/~1/g, "/").replace(/~0/g, "~");
170
+ const definition = keyword === "definitions" ? (_a2 = schema2.definitions) == null ? void 0 : _a2[name] : (_b = schema2.$defs) == null ? void 0 : _b[name];
171
+ return definition;
172
+ }
173
+ }
174
+
83
175
  // src/openai-stream-error.ts
84
176
  import { APICallError } from "@ai-sdk/provider";
85
177
  function createOpenAIProviderStreamError(frame) {
@@ -984,7 +1076,7 @@ var OpenAIChatLanguageModel = class {
984
1076
  response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
985
1077
  type: "json_schema",
986
1078
  json_schema: {
987
- schema: responseFormat.schema,
1079
+ schema: normalizeOpenAIJsonSchema(responseFormat.schema),
988
1080
  strict: strictJsonSchema,
989
1081
  name: (_e = responseFormat.name) != null ? _e : "response",
990
1082
  description: responseFormat.description
@@ -6108,7 +6200,7 @@ var OpenAIResponsesLanguageModel = class {
6108
6200
  strict: strictJsonSchema,
6109
6201
  name: (_h = responseFormat.name) != null ? _h : "response",
6110
6202
  description: responseFormat.description,
6111
- schema: responseFormat.schema
6203
+ schema: normalizeOpenAIJsonSchema(responseFormat.schema)
6112
6204
  } : { type: "json_object" }
6113
6205
  },
6114
6206
  ...(openaiOptions == null ? void 0 : openaiOptions.textVerbosity) && {
@@ -8266,7 +8358,7 @@ var OpenAITranscriptionModel = class {
8266
8358
  };
8267
8359
 
8268
8360
  // src/version.ts
8269
- var VERSION = true ? "3.0.123" : "0.0.0-test";
8361
+ var VERSION = true ? "3.0.124" : "0.0.0-test";
8270
8362
 
8271
8363
  // src/openai-provider.ts
8272
8364
  function createOpenAI(options = {}) {