@ai-sdk/openai 3.0.122 → 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) {
@@ -770,11 +862,12 @@ var openaiLanguageModelChatOptions = lazySchema2(
770
862
  * - 'flex': 50% cheaper processing at the cost of increased latency. Only available for o3 and o4-mini models.
771
863
  * - 'priority': Higher-speed processing with predictably low latency at premium cost. Available for Enterprise customers.
772
864
  * - 'fast': OpenAI's newer name for the 'priority' tier. Interchangeable with it.
865
+ * - 'ultrafast': Access-controlled Ultrafast processing. Only available for gpt-5.6-sol.
773
866
  * - 'default': The request will be processed with the standard pricing and performance for the selected model.
774
867
  *
775
868
  * @default 'auto'
776
869
  */
777
- serviceTier: z3.enum(["auto", "flex", "priority", "fast", "default"]).optional(),
870
+ serviceTier: z3.enum(["auto", "flex", "priority", "fast", "ultrafast", "default"]).optional(),
778
871
  /**
779
872
  * Whether to use strict JSON schema validation.
780
873
  *
@@ -983,7 +1076,7 @@ var OpenAIChatLanguageModel = class {
983
1076
  response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
984
1077
  type: "json_schema",
985
1078
  json_schema: {
986
- schema: responseFormat.schema,
1079
+ schema: normalizeOpenAIJsonSchema(responseFormat.schema),
987
1080
  strict: strictJsonSchema,
988
1081
  name: (_e = responseFormat.name) != null ? _e : "response",
989
1082
  description: responseFormat.description
@@ -3291,10 +3384,11 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema20(
3291
3384
  * Set to 'flex' for 50% cheaper processing at the cost of increased latency (available for o3, o4-mini, and gpt-5 models).
3292
3385
  * Set to 'priority' for faster processing with Enterprise access (available for gpt-4, gpt-5, gpt-5-mini, o3, o4-mini; gpt-5-nano is not supported).
3293
3386
  * Set to 'fast' for the same tier as 'priority' (OpenAI's newer name for it).
3387
+ * Set to 'ultrafast' for access-controlled Ultrafast processing (available only for gpt-5.6-sol).
3294
3388
  *
3295
3389
  * Defaults to 'auto'.
3296
3390
  */
3297
- serviceTier: z21.enum(["auto", "flex", "priority", "fast", "default"]).nullish(),
3391
+ serviceTier: z21.enum(["auto", "flex", "priority", "fast", "ultrafast", "default"]).nullish(),
3298
3392
  /**
3299
3393
  * Whether to store the generation. Defaults to `true`.
3300
3394
  */
@@ -6106,7 +6200,7 @@ var OpenAIResponsesLanguageModel = class {
6106
6200
  strict: strictJsonSchema,
6107
6201
  name: (_h = responseFormat.name) != null ? _h : "response",
6108
6202
  description: responseFormat.description,
6109
- schema: responseFormat.schema
6203
+ schema: normalizeOpenAIJsonSchema(responseFormat.schema)
6110
6204
  } : { type: "json_object" }
6111
6205
  },
6112
6206
  ...(openaiOptions == null ? void 0 : openaiOptions.textVerbosity) && {
@@ -8264,7 +8358,7 @@ var OpenAITranscriptionModel = class {
8264
8358
  };
8265
8359
 
8266
8360
  // src/version.ts
8267
- var VERSION = true ? "3.0.122" : "0.0.0-test";
8361
+ var VERSION = true ? "3.0.124" : "0.0.0-test";
8268
8362
 
8269
8363
  // src/openai-provider.ts
8270
8364
  function createOpenAI(options = {}) {