@ai-sdk/openai 3.0.123 → 3.0.125
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 +13 -0
- package/dist/index.d.mts +16 -16
- package/dist/index.d.ts +16 -16
- package/dist/index.js +167 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +168 -9
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +15 -15
- package/dist/internal/index.d.ts +15 -15
- package/dist/internal/index.js +1058 -900
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +1050 -891
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/chat/openai-chat-language-model.ts +2 -1
- package/src/normalize-openai-json-schema.ts +142 -0
- package/src/responses/convert-to-openai-responses-input.ts +89 -0
- package/src/responses/openai-responses-api.ts +9 -1
- package/src/responses/openai-responses-language-model.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 3.0.125
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ce4202b: fix(openai): replay web search results when response storage is disabled
|
|
8
|
+
- fde0b6c: fix(openai): classify Responses stream errors with null codes
|
|
9
|
+
|
|
10
|
+
## 3.0.124
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- d131a3b: fix(openai): rewrite recursive Zod schemas that use `allOf` wrappers
|
|
15
|
+
|
|
3
16
|
## 3.0.123
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -220,21 +220,6 @@ type OpenAIResponsesFileSearchToolCompoundFilter = {
|
|
|
220
220
|
declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
221
221
|
type: "unknown_chunk";
|
|
222
222
|
message: string;
|
|
223
|
-
} | {
|
|
224
|
-
type: "error";
|
|
225
|
-
sequence_number: number;
|
|
226
|
-
error: {
|
|
227
|
-
type: string;
|
|
228
|
-
code: string;
|
|
229
|
-
message: string;
|
|
230
|
-
param?: string | null | undefined;
|
|
231
|
-
};
|
|
232
|
-
} | {
|
|
233
|
-
type: "error";
|
|
234
|
-
sequence_number: number;
|
|
235
|
-
message: string;
|
|
236
|
-
code?: string | null | undefined;
|
|
237
|
-
param?: string | null | undefined;
|
|
238
223
|
} | {
|
|
239
224
|
type: "response.output_text.delta";
|
|
240
225
|
item_id: string;
|
|
@@ -709,6 +694,21 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
709
694
|
item_id: string;
|
|
710
695
|
output_index: number;
|
|
711
696
|
diff: string;
|
|
697
|
+
} | {
|
|
698
|
+
type: "error";
|
|
699
|
+
sequence_number: number;
|
|
700
|
+
error: {
|
|
701
|
+
type: string;
|
|
702
|
+
message: string;
|
|
703
|
+
code?: string | null | undefined;
|
|
704
|
+
param?: string | null | undefined;
|
|
705
|
+
};
|
|
706
|
+
} | {
|
|
707
|
+
type: "error";
|
|
708
|
+
sequence_number: number;
|
|
709
|
+
message: string;
|
|
710
|
+
code?: string | null | undefined;
|
|
711
|
+
param?: string | null | undefined;
|
|
712
712
|
}>;
|
|
713
713
|
type OpenAIResponsesChunk = InferSchema<typeof openaiResponsesChunkSchema>;
|
|
714
714
|
type OpenAIResponsesLogprobs = NonNullable<(OpenAIResponsesChunk & {
|
|
@@ -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?: "
|
|
1128
|
+
mode?: "required" | "auto" | undefined;
|
|
1129
1129
|
} | undefined;
|
|
1130
1130
|
}>;
|
|
1131
1131
|
type OpenAILanguageModelResponsesOptions = InferSchema<typeof openaiLanguageModelResponsesOptionsSchema>;
|
package/dist/index.d.ts
CHANGED
|
@@ -220,21 +220,6 @@ type OpenAIResponsesFileSearchToolCompoundFilter = {
|
|
|
220
220
|
declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
221
221
|
type: "unknown_chunk";
|
|
222
222
|
message: string;
|
|
223
|
-
} | {
|
|
224
|
-
type: "error";
|
|
225
|
-
sequence_number: number;
|
|
226
|
-
error: {
|
|
227
|
-
type: string;
|
|
228
|
-
code: string;
|
|
229
|
-
message: string;
|
|
230
|
-
param?: string | null | undefined;
|
|
231
|
-
};
|
|
232
|
-
} | {
|
|
233
|
-
type: "error";
|
|
234
|
-
sequence_number: number;
|
|
235
|
-
message: string;
|
|
236
|
-
code?: string | null | undefined;
|
|
237
|
-
param?: string | null | undefined;
|
|
238
223
|
} | {
|
|
239
224
|
type: "response.output_text.delta";
|
|
240
225
|
item_id: string;
|
|
@@ -709,6 +694,21 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
709
694
|
item_id: string;
|
|
710
695
|
output_index: number;
|
|
711
696
|
diff: string;
|
|
697
|
+
} | {
|
|
698
|
+
type: "error";
|
|
699
|
+
sequence_number: number;
|
|
700
|
+
error: {
|
|
701
|
+
type: string;
|
|
702
|
+
message: string;
|
|
703
|
+
code?: string | null | undefined;
|
|
704
|
+
param?: string | null | undefined;
|
|
705
|
+
};
|
|
706
|
+
} | {
|
|
707
|
+
type: "error";
|
|
708
|
+
sequence_number: number;
|
|
709
|
+
message: string;
|
|
710
|
+
code?: string | null | undefined;
|
|
711
|
+
param?: string | null | undefined;
|
|
712
712
|
}>;
|
|
713
713
|
type OpenAIResponsesChunk = InferSchema<typeof openaiResponsesChunkSchema>;
|
|
714
714
|
type OpenAIResponsesLogprobs = NonNullable<(OpenAIResponsesChunk & {
|
|
@@ -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?: "
|
|
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
|
|
@@ -3363,6 +3455,57 @@ async function expandParallelToolCall({
|
|
|
3363
3455
|
function serializeToolCallArguments2(input) {
|
|
3364
3456
|
return JSON.stringify(input === void 0 ? {} : input);
|
|
3365
3457
|
}
|
|
3458
|
+
async function convertWebSearchToolResultOutput({
|
|
3459
|
+
output,
|
|
3460
|
+
id
|
|
3461
|
+
}) {
|
|
3462
|
+
if (output.type !== "json") {
|
|
3463
|
+
return void 0;
|
|
3464
|
+
}
|
|
3465
|
+
const validation = await (0, import_provider_utils28.safeValidateTypes)({
|
|
3466
|
+
value: output.value,
|
|
3467
|
+
schema: webSearchOutputSchema
|
|
3468
|
+
});
|
|
3469
|
+
if (!validation.success || validation.value.action == null) {
|
|
3470
|
+
return void 0;
|
|
3471
|
+
}
|
|
3472
|
+
const { action, sources } = validation.value;
|
|
3473
|
+
switch (action.type) {
|
|
3474
|
+
case "search":
|
|
3475
|
+
return {
|
|
3476
|
+
type: "web_search_call",
|
|
3477
|
+
id,
|
|
3478
|
+
status: "completed",
|
|
3479
|
+
action: {
|
|
3480
|
+
type: "search",
|
|
3481
|
+
...action.query != null && { query: action.query },
|
|
3482
|
+
...action.queries != null && { queries: action.queries },
|
|
3483
|
+
...sources != null && { sources }
|
|
3484
|
+
}
|
|
3485
|
+
};
|
|
3486
|
+
case "openPage":
|
|
3487
|
+
return {
|
|
3488
|
+
type: "web_search_call",
|
|
3489
|
+
id,
|
|
3490
|
+
status: "completed",
|
|
3491
|
+
action: {
|
|
3492
|
+
type: "open_page",
|
|
3493
|
+
url: action.url
|
|
3494
|
+
}
|
|
3495
|
+
};
|
|
3496
|
+
case "findInPage":
|
|
3497
|
+
return {
|
|
3498
|
+
type: "web_search_call",
|
|
3499
|
+
id,
|
|
3500
|
+
status: "completed",
|
|
3501
|
+
action: {
|
|
3502
|
+
type: "find_in_page",
|
|
3503
|
+
url: action.url,
|
|
3504
|
+
pattern: action.pattern
|
|
3505
|
+
}
|
|
3506
|
+
};
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3366
3509
|
async function convertFunctionToolResultOutput({
|
|
3367
3510
|
output,
|
|
3368
3511
|
promptCacheBreakpoint,
|
|
@@ -3569,7 +3712,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3569
3712
|
toolSearchToolName,
|
|
3570
3713
|
customProviderToolNames
|
|
3571
3714
|
}) {
|
|
3572
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D;
|
|
3715
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G;
|
|
3573
3716
|
let input = [];
|
|
3574
3717
|
const warnings = [];
|
|
3575
3718
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
@@ -3915,8 +4058,23 @@ async function convertToOpenAIResponsesInput({
|
|
|
3915
4058
|
const resolvedResultToolName = toolNameMapping.toProviderToolName(
|
|
3916
4059
|
part.toolName
|
|
3917
4060
|
);
|
|
4061
|
+
if (resolvedResultToolName === "web_search" || resolvedResultToolName === "web_search_preview") {
|
|
4062
|
+
const itemId = (_u = (_t = (_s = part.providerOptions) == null ? void 0 : _s[providerOptionsName]) == null ? void 0 : _t.itemId) != null ? _u : part.toolCallId;
|
|
4063
|
+
if (store) {
|
|
4064
|
+
input.push({ type: "item_reference", id: itemId });
|
|
4065
|
+
break;
|
|
4066
|
+
}
|
|
4067
|
+
const webSearchCall = await convertWebSearchToolResultOutput({
|
|
4068
|
+
output: part.output,
|
|
4069
|
+
id: itemId
|
|
4070
|
+
});
|
|
4071
|
+
if (webSearchCall != null) {
|
|
4072
|
+
input.push(webSearchCall);
|
|
4073
|
+
break;
|
|
4074
|
+
}
|
|
4075
|
+
}
|
|
3918
4076
|
if (part.toolName === toolSearchToolName) {
|
|
3919
|
-
const itemId = (
|
|
4077
|
+
const itemId = (_A = (_z = (_w = (_v = part.providerOptions) == null ? void 0 : _v[providerOptionsName]) == null ? void 0 : _w.itemId) != null ? _z : (_y = (_x = part.providerMetadata) == null ? void 0 : _x[providerOptionsName]) == null ? void 0 : _y.itemId) != null ? _A : part.toolCallId;
|
|
3920
4078
|
if (store) {
|
|
3921
4079
|
input.push({ type: "item_reference", id: itemId });
|
|
3922
4080
|
} else if (part.output.type === "json") {
|
|
@@ -3957,7 +4115,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3957
4115
|
break;
|
|
3958
4116
|
}
|
|
3959
4117
|
if (store) {
|
|
3960
|
-
const itemId = (
|
|
4118
|
+
const itemId = (_D = (_C = (_B = part.providerOptions) == null ? void 0 : _B[providerOptionsName]) == null ? void 0 : _C.itemId) != null ? _D : part.toolCallId;
|
|
3961
4119
|
input.push({ type: "item_reference", id: itemId });
|
|
3962
4120
|
} else {
|
|
3963
4121
|
warnings.push({
|
|
@@ -4124,7 +4282,7 @@ ${text}`,
|
|
|
4124
4282
|
}
|
|
4125
4283
|
const output = part.output;
|
|
4126
4284
|
if (output.type === "execution-denied") {
|
|
4127
|
-
const approvalId = (
|
|
4285
|
+
const approvalId = (_F = (_E = output.providerOptions) == null ? void 0 : _E.openai) == null ? void 0 : _F.approvalId;
|
|
4128
4286
|
if (approvalId) {
|
|
4129
4287
|
continue;
|
|
4130
4288
|
}
|
|
@@ -4211,7 +4369,7 @@ ${text}`,
|
|
|
4211
4369
|
break;
|
|
4212
4370
|
case "execution-denied":
|
|
4213
4371
|
outputValue = convertScalarOutput(
|
|
4214
|
-
(
|
|
4372
|
+
(_G = output.reason) != null ? _G : "Tool call execution denied."
|
|
4215
4373
|
);
|
|
4216
4374
|
break;
|
|
4217
4375
|
case "json":
|
|
@@ -4407,7 +4565,7 @@ var openaiResponsesNestedErrorChunkSchema = import_v423.z.object({
|
|
|
4407
4565
|
sequence_number: import_v423.z.number(),
|
|
4408
4566
|
error: import_v423.z.object({
|
|
4409
4567
|
type: import_v423.z.string(),
|
|
4410
|
-
code: import_v423.z.string(),
|
|
4568
|
+
code: import_v423.z.string().nullish(),
|
|
4411
4569
|
message: import_v423.z.string(),
|
|
4412
4570
|
param: import_v423.z.string().nullish()
|
|
4413
4571
|
})
|
|
@@ -6000,7 +6158,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6000
6158
|
strict: strictJsonSchema,
|
|
6001
6159
|
name: (_h = responseFormat.name) != null ? _h : "response",
|
|
6002
6160
|
description: responseFormat.description,
|
|
6003
|
-
schema: responseFormat.schema
|
|
6161
|
+
schema: normalizeOpenAIJsonSchema(responseFormat.schema)
|
|
6004
6162
|
} : { type: "json_object" }
|
|
6005
6163
|
},
|
|
6006
6164
|
...(openaiOptions == null ? void 0 : openaiOptions.textVerbosity) && {
|
|
@@ -8140,7 +8298,7 @@ var OpenAITranscriptionModel = class {
|
|
|
8140
8298
|
};
|
|
8141
8299
|
|
|
8142
8300
|
// src/version.ts
|
|
8143
|
-
var VERSION = true ? "3.0.
|
|
8301
|
+
var VERSION = true ? "3.0.125" : "0.0.0-test";
|
|
8144
8302
|
|
|
8145
8303
|
// src/openai-provider.ts
|
|
8146
8304
|
function createOpenAI(options = {}) {
|