@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/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
|
|
@@ -3077,6 +3169,7 @@ import {
|
|
|
3077
3169
|
isNonNullable,
|
|
3078
3170
|
parseJSON,
|
|
3079
3171
|
parseProviderOptions as parseProviderOptions5,
|
|
3172
|
+
safeValidateTypes,
|
|
3080
3173
|
validateTypes
|
|
3081
3174
|
} from "@ai-sdk/provider-utils";
|
|
3082
3175
|
import { z as z22 } from "zod/v4";
|
|
@@ -3466,6 +3559,57 @@ async function expandParallelToolCall({
|
|
|
3466
3559
|
function serializeToolCallArguments2(input) {
|
|
3467
3560
|
return JSON.stringify(input === void 0 ? {} : input);
|
|
3468
3561
|
}
|
|
3562
|
+
async function convertWebSearchToolResultOutput({
|
|
3563
|
+
output,
|
|
3564
|
+
id
|
|
3565
|
+
}) {
|
|
3566
|
+
if (output.type !== "json") {
|
|
3567
|
+
return void 0;
|
|
3568
|
+
}
|
|
3569
|
+
const validation = await safeValidateTypes({
|
|
3570
|
+
value: output.value,
|
|
3571
|
+
schema: webSearchOutputSchema
|
|
3572
|
+
});
|
|
3573
|
+
if (!validation.success || validation.value.action == null) {
|
|
3574
|
+
return void 0;
|
|
3575
|
+
}
|
|
3576
|
+
const { action, sources } = validation.value;
|
|
3577
|
+
switch (action.type) {
|
|
3578
|
+
case "search":
|
|
3579
|
+
return {
|
|
3580
|
+
type: "web_search_call",
|
|
3581
|
+
id,
|
|
3582
|
+
status: "completed",
|
|
3583
|
+
action: {
|
|
3584
|
+
type: "search",
|
|
3585
|
+
...action.query != null && { query: action.query },
|
|
3586
|
+
...action.queries != null && { queries: action.queries },
|
|
3587
|
+
...sources != null && { sources }
|
|
3588
|
+
}
|
|
3589
|
+
};
|
|
3590
|
+
case "openPage":
|
|
3591
|
+
return {
|
|
3592
|
+
type: "web_search_call",
|
|
3593
|
+
id,
|
|
3594
|
+
status: "completed",
|
|
3595
|
+
action: {
|
|
3596
|
+
type: "open_page",
|
|
3597
|
+
url: action.url
|
|
3598
|
+
}
|
|
3599
|
+
};
|
|
3600
|
+
case "findInPage":
|
|
3601
|
+
return {
|
|
3602
|
+
type: "web_search_call",
|
|
3603
|
+
id,
|
|
3604
|
+
status: "completed",
|
|
3605
|
+
action: {
|
|
3606
|
+
type: "find_in_page",
|
|
3607
|
+
url: action.url,
|
|
3608
|
+
pattern: action.pattern
|
|
3609
|
+
}
|
|
3610
|
+
};
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3469
3613
|
async function convertFunctionToolResultOutput({
|
|
3470
3614
|
output,
|
|
3471
3615
|
promptCacheBreakpoint,
|
|
@@ -3672,7 +3816,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3672
3816
|
toolSearchToolName,
|
|
3673
3817
|
customProviderToolNames
|
|
3674
3818
|
}) {
|
|
3675
|
-
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;
|
|
3819
|
+
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;
|
|
3676
3820
|
let input = [];
|
|
3677
3821
|
const warnings = [];
|
|
3678
3822
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
@@ -4018,8 +4162,23 @@ async function convertToOpenAIResponsesInput({
|
|
|
4018
4162
|
const resolvedResultToolName = toolNameMapping.toProviderToolName(
|
|
4019
4163
|
part.toolName
|
|
4020
4164
|
);
|
|
4165
|
+
if (resolvedResultToolName === "web_search" || resolvedResultToolName === "web_search_preview") {
|
|
4166
|
+
const itemId = (_u = (_t = (_s = part.providerOptions) == null ? void 0 : _s[providerOptionsName]) == null ? void 0 : _t.itemId) != null ? _u : part.toolCallId;
|
|
4167
|
+
if (store) {
|
|
4168
|
+
input.push({ type: "item_reference", id: itemId });
|
|
4169
|
+
break;
|
|
4170
|
+
}
|
|
4171
|
+
const webSearchCall = await convertWebSearchToolResultOutput({
|
|
4172
|
+
output: part.output,
|
|
4173
|
+
id: itemId
|
|
4174
|
+
});
|
|
4175
|
+
if (webSearchCall != null) {
|
|
4176
|
+
input.push(webSearchCall);
|
|
4177
|
+
break;
|
|
4178
|
+
}
|
|
4179
|
+
}
|
|
4021
4180
|
if (part.toolName === toolSearchToolName) {
|
|
4022
|
-
const itemId = (
|
|
4181
|
+
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;
|
|
4023
4182
|
if (store) {
|
|
4024
4183
|
input.push({ type: "item_reference", id: itemId });
|
|
4025
4184
|
} else if (part.output.type === "json") {
|
|
@@ -4060,7 +4219,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4060
4219
|
break;
|
|
4061
4220
|
}
|
|
4062
4221
|
if (store) {
|
|
4063
|
-
const itemId = (
|
|
4222
|
+
const itemId = (_D = (_C = (_B = part.providerOptions) == null ? void 0 : _B[providerOptionsName]) == null ? void 0 : _C.itemId) != null ? _D : part.toolCallId;
|
|
4064
4223
|
input.push({ type: "item_reference", id: itemId });
|
|
4065
4224
|
} else {
|
|
4066
4225
|
warnings.push({
|
|
@@ -4227,7 +4386,7 @@ ${text}`,
|
|
|
4227
4386
|
}
|
|
4228
4387
|
const output = part.output;
|
|
4229
4388
|
if (output.type === "execution-denied") {
|
|
4230
|
-
const approvalId = (
|
|
4389
|
+
const approvalId = (_F = (_E = output.providerOptions) == null ? void 0 : _E.openai) == null ? void 0 : _F.approvalId;
|
|
4231
4390
|
if (approvalId) {
|
|
4232
4391
|
continue;
|
|
4233
4392
|
}
|
|
@@ -4314,7 +4473,7 @@ ${text}`,
|
|
|
4314
4473
|
break;
|
|
4315
4474
|
case "execution-denied":
|
|
4316
4475
|
outputValue = convertScalarOutput(
|
|
4317
|
-
(
|
|
4476
|
+
(_G = output.reason) != null ? _G : "Tool call execution denied."
|
|
4318
4477
|
);
|
|
4319
4478
|
break;
|
|
4320
4479
|
case "json":
|
|
@@ -4513,7 +4672,7 @@ var openaiResponsesNestedErrorChunkSchema = z23.object({
|
|
|
4513
4672
|
sequence_number: z23.number(),
|
|
4514
4673
|
error: z23.object({
|
|
4515
4674
|
type: z23.string(),
|
|
4516
|
-
code: z23.string(),
|
|
4675
|
+
code: z23.string().nullish(),
|
|
4517
4676
|
message: z23.string(),
|
|
4518
4677
|
param: z23.string().nullish()
|
|
4519
4678
|
})
|
|
@@ -6108,7 +6267,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6108
6267
|
strict: strictJsonSchema,
|
|
6109
6268
|
name: (_h = responseFormat.name) != null ? _h : "response",
|
|
6110
6269
|
description: responseFormat.description,
|
|
6111
|
-
schema: responseFormat.schema
|
|
6270
|
+
schema: normalizeOpenAIJsonSchema(responseFormat.schema)
|
|
6112
6271
|
} : { type: "json_object" }
|
|
6113
6272
|
},
|
|
6114
6273
|
...(openaiOptions == null ? void 0 : openaiOptions.textVerbosity) && {
|
|
@@ -8266,7 +8425,7 @@ var OpenAITranscriptionModel = class {
|
|
|
8266
8425
|
};
|
|
8267
8426
|
|
|
8268
8427
|
// src/version.ts
|
|
8269
|
-
var VERSION = true ? "3.0.
|
|
8428
|
+
var VERSION = true ? "3.0.125" : "0.0.0-test";
|
|
8270
8429
|
|
|
8271
8430
|
// src/openai-provider.ts
|
|
8272
8431
|
function createOpenAI(options = {}) {
|