@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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +99 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -5
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +98 -4
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +98 -4
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-openai.mdx +4 -2
- package/package.json +1 -1
- package/src/chat/openai-chat-language-model.ts +2 -1
- package/src/chat/openai-chat-options.ts +2 -1
- package/src/normalize-openai-json-schema.ts +142 -0
- package/src/responses/openai-responses-language-model.ts +2 -1
- package/src/responses/openai-responses-options.ts +2 -1
package/dist/internal/index.mjs
CHANGED
|
@@ -72,6 +72,98 @@ function getGptVersion(modelId) {
|
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
// src/normalize-openai-json-schema.ts
|
|
76
|
+
function normalizeOpenAIJsonSchema(schema) {
|
|
77
|
+
const normalizedSchema = normalizeSchema(schema, true);
|
|
78
|
+
const reference = getSingletonReference(normalizedSchema);
|
|
79
|
+
if (reference == null) {
|
|
80
|
+
return normalizedSchema;
|
|
81
|
+
}
|
|
82
|
+
const { allOf: _allOf, ...schemaWithoutAllOf } = normalizedSchema;
|
|
83
|
+
const referencedSchema = getLocalReferenceSchema(reference, normalizedSchema);
|
|
84
|
+
return typeof referencedSchema !== "object" || referencedSchema == null ? normalizedSchema : { ...referencedSchema, ...schemaWithoutAllOf };
|
|
85
|
+
function normalizeSchema(schema2, isRoot = false) {
|
|
86
|
+
if (typeof schema2 !== "object" || schema2 == null) {
|
|
87
|
+
return schema2;
|
|
88
|
+
}
|
|
89
|
+
const normalizedSchema2 = { ...schema2 };
|
|
90
|
+
if (normalizedSchema2.properties != null) {
|
|
91
|
+
normalizedSchema2.properties = normalizeSchemaRecord(
|
|
92
|
+
normalizedSchema2.properties
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
if (normalizedSchema2.patternProperties != null) {
|
|
96
|
+
normalizedSchema2.patternProperties = normalizeSchemaRecord(
|
|
97
|
+
normalizedSchema2.patternProperties
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
if (normalizedSchema2.definitions != null) {
|
|
101
|
+
normalizedSchema2.definitions = normalizeSchemaRecord(
|
|
102
|
+
normalizedSchema2.definitions
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
if (normalizedSchema2.$defs != null) {
|
|
106
|
+
normalizedSchema2.$defs = normalizeSchemaRecord(normalizedSchema2.$defs);
|
|
107
|
+
}
|
|
108
|
+
if (normalizedSchema2.items != null) {
|
|
109
|
+
normalizedSchema2.items = Array.isArray(normalizedSchema2.items) ? normalizedSchema2.items.map((item) => normalizeSchema(item)) : normalizeSchema(normalizedSchema2.items);
|
|
110
|
+
}
|
|
111
|
+
if (normalizedSchema2.allOf != null) {
|
|
112
|
+
normalizedSchema2.allOf = normalizedSchema2.allOf.map(
|
|
113
|
+
(item) => normalizeSchema(item)
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
if (normalizedSchema2.anyOf != null) {
|
|
117
|
+
normalizedSchema2.anyOf = normalizedSchema2.anyOf.map(
|
|
118
|
+
(item) => normalizeSchema(item)
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (normalizedSchema2.oneOf != null) {
|
|
122
|
+
normalizedSchema2.oneOf = normalizedSchema2.oneOf.map(
|
|
123
|
+
(item) => normalizeSchema(item)
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
if (typeof normalizedSchema2.additionalProperties === "object" && normalizedSchema2.additionalProperties != null) {
|
|
127
|
+
normalizedSchema2.additionalProperties = normalizeSchema(
|
|
128
|
+
normalizedSchema2.additionalProperties
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
const reference2 = getSingletonReference(normalizedSchema2);
|
|
132
|
+
if (reference2 == null || isRoot) {
|
|
133
|
+
return normalizedSchema2;
|
|
134
|
+
}
|
|
135
|
+
const { allOf: _allOf2, ...schemaWithoutAllOf2 } = normalizedSchema2;
|
|
136
|
+
return { ...schemaWithoutAllOf2, $ref: reference2 };
|
|
137
|
+
}
|
|
138
|
+
function normalizeSchemaRecord(record) {
|
|
139
|
+
return Object.fromEntries(
|
|
140
|
+
Object.entries(record).map(([key, value]) => [
|
|
141
|
+
key,
|
|
142
|
+
normalizeSchema(value)
|
|
143
|
+
])
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
function getSingletonReference(schema2) {
|
|
147
|
+
var _a2;
|
|
148
|
+
if (((_a2 = schema2.allOf) == null ? void 0 : _a2.length) !== 1) {
|
|
149
|
+
return void 0;
|
|
150
|
+
}
|
|
151
|
+
const [allOfSchema] = schema2.allOf;
|
|
152
|
+
return typeof allOfSchema === "object" && allOfSchema != null && Object.keys(allOfSchema).length === 1 && typeof allOfSchema.$ref === "string" ? allOfSchema.$ref : void 0;
|
|
153
|
+
}
|
|
154
|
+
function getLocalReferenceSchema(reference2, schema2) {
|
|
155
|
+
var _a2, _b;
|
|
156
|
+
const match = /^#\/(definitions|\$defs)\/(.+)$/.exec(reference2);
|
|
157
|
+
if (match == null) {
|
|
158
|
+
return void 0;
|
|
159
|
+
}
|
|
160
|
+
const [, keyword, encodedName] = match;
|
|
161
|
+
const name = encodedName.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
162
|
+
const definition = keyword === "definitions" ? (_a2 = schema2.definitions) == null ? void 0 : _a2[name] : (_b = schema2.$defs) == null ? void 0 : _b[name];
|
|
163
|
+
return definition;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
75
167
|
// src/openai-stream-error.ts
|
|
76
168
|
import { APICallError } from "@ai-sdk/provider";
|
|
77
169
|
function createOpenAIProviderStreamError(frame) {
|
|
@@ -762,11 +854,12 @@ var openaiLanguageModelChatOptions = lazySchema2(
|
|
|
762
854
|
* - 'flex': 50% cheaper processing at the cost of increased latency. Only available for o3 and o4-mini models.
|
|
763
855
|
* - 'priority': Higher-speed processing with predictably low latency at premium cost. Available for Enterprise customers.
|
|
764
856
|
* - 'fast': OpenAI's newer name for the 'priority' tier. Interchangeable with it.
|
|
857
|
+
* - 'ultrafast': Access-controlled Ultrafast processing. Only available for gpt-5.6-sol.
|
|
765
858
|
* - 'default': The request will be processed with the standard pricing and performance for the selected model.
|
|
766
859
|
*
|
|
767
860
|
* @default 'auto'
|
|
768
861
|
*/
|
|
769
|
-
serviceTier: z3.enum(["auto", "flex", "priority", "fast", "default"]).optional(),
|
|
862
|
+
serviceTier: z3.enum(["auto", "flex", "priority", "fast", "ultrafast", "default"]).optional(),
|
|
770
863
|
/**
|
|
771
864
|
* Whether to use strict JSON schema validation.
|
|
772
865
|
*
|
|
@@ -975,7 +1068,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
975
1068
|
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
|
|
976
1069
|
type: "json_schema",
|
|
977
1070
|
json_schema: {
|
|
978
|
-
schema: responseFormat.schema,
|
|
1071
|
+
schema: normalizeOpenAIJsonSchema(responseFormat.schema),
|
|
979
1072
|
strict: strictJsonSchema,
|
|
980
1073
|
name: (_e = responseFormat.name) != null ? _e : "response",
|
|
981
1074
|
description: responseFormat.description
|
|
@@ -2966,10 +3059,11 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema12(
|
|
|
2966
3059
|
* Set to 'flex' for 50% cheaper processing at the cost of increased latency (available for o3, o4-mini, and gpt-5 models).
|
|
2967
3060
|
* 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).
|
|
2968
3061
|
* Set to 'fast' for the same tier as 'priority' (OpenAI's newer name for it).
|
|
3062
|
+
* Set to 'ultrafast' for access-controlled Ultrafast processing (available only for gpt-5.6-sol).
|
|
2969
3063
|
*
|
|
2970
3064
|
* Defaults to 'auto'.
|
|
2971
3065
|
*/
|
|
2972
|
-
serviceTier: z13.enum(["auto", "flex", "priority", "fast", "default"]).nullish(),
|
|
3066
|
+
serviceTier: z13.enum(["auto", "flex", "priority", "fast", "ultrafast", "default"]).nullish(),
|
|
2973
3067
|
/**
|
|
2974
3068
|
* Whether to store the generation. Defaults to `true`.
|
|
2975
3069
|
*/
|
|
@@ -6348,7 +6442,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6348
6442
|
strict: strictJsonSchema,
|
|
6349
6443
|
name: (_h = responseFormat.name) != null ? _h : "response",
|
|
6350
6444
|
description: responseFormat.description,
|
|
6351
|
-
schema: responseFormat.schema
|
|
6445
|
+
schema: normalizeOpenAIJsonSchema(responseFormat.schema)
|
|
6352
6446
|
} : { type: "json_object" }
|
|
6353
6447
|
},
|
|
6354
6448
|
...(openaiOptions == null ? void 0 : openaiOptions.textVerbosity) && {
|