@ai-sdk/openai 3.0.124 → 3.0.126
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 +15 -15
- package/dist/index.d.ts +15 -15
- package/dist/index.js +84 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -8
- 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 +975 -899
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +967 -890
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- 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 +15 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 3.0.126
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e8ce454: fix(openai): JSON-encode custom tool input deltas for progressive UI updates
|
|
8
|
+
|
|
9
|
+
## 3.0.125
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- ce4202b: fix(openai): replay web search results when response storage is disabled
|
|
14
|
+
- fde0b6c: fix(openai): classify Responses stream errors with null codes
|
|
15
|
+
|
|
3
16
|
## 3.0.124
|
|
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 & {
|
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 & {
|
package/dist/index.js
CHANGED
|
@@ -3455,6 +3455,57 @@ async function expandParallelToolCall({
|
|
|
3455
3455
|
function serializeToolCallArguments2(input) {
|
|
3456
3456
|
return JSON.stringify(input === void 0 ? {} : input);
|
|
3457
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
|
+
}
|
|
3458
3509
|
async function convertFunctionToolResultOutput({
|
|
3459
3510
|
output,
|
|
3460
3511
|
promptCacheBreakpoint,
|
|
@@ -3661,7 +3712,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3661
3712
|
toolSearchToolName,
|
|
3662
3713
|
customProviderToolNames
|
|
3663
3714
|
}) {
|
|
3664
|
-
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;
|
|
3665
3716
|
let input = [];
|
|
3666
3717
|
const warnings = [];
|
|
3667
3718
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
@@ -4007,8 +4058,23 @@ async function convertToOpenAIResponsesInput({
|
|
|
4007
4058
|
const resolvedResultToolName = toolNameMapping.toProviderToolName(
|
|
4008
4059
|
part.toolName
|
|
4009
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
|
+
}
|
|
4010
4076
|
if (part.toolName === toolSearchToolName) {
|
|
4011
|
-
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;
|
|
4012
4078
|
if (store) {
|
|
4013
4079
|
input.push({ type: "item_reference", id: itemId });
|
|
4014
4080
|
} else if (part.output.type === "json") {
|
|
@@ -4049,7 +4115,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4049
4115
|
break;
|
|
4050
4116
|
}
|
|
4051
4117
|
if (store) {
|
|
4052
|
-
const itemId = (
|
|
4118
|
+
const itemId = (_D = (_C = (_B = part.providerOptions) == null ? void 0 : _B[providerOptionsName]) == null ? void 0 : _C.itemId) != null ? _D : part.toolCallId;
|
|
4053
4119
|
input.push({ type: "item_reference", id: itemId });
|
|
4054
4120
|
} else {
|
|
4055
4121
|
warnings.push({
|
|
@@ -4216,7 +4282,7 @@ ${text}`,
|
|
|
4216
4282
|
}
|
|
4217
4283
|
const output = part.output;
|
|
4218
4284
|
if (output.type === "execution-denied") {
|
|
4219
|
-
const approvalId = (
|
|
4285
|
+
const approvalId = (_F = (_E = output.providerOptions) == null ? void 0 : _E.openai) == null ? void 0 : _F.approvalId;
|
|
4220
4286
|
if (approvalId) {
|
|
4221
4287
|
continue;
|
|
4222
4288
|
}
|
|
@@ -4303,7 +4369,7 @@ ${text}`,
|
|
|
4303
4369
|
break;
|
|
4304
4370
|
case "execution-denied":
|
|
4305
4371
|
outputValue = convertScalarOutput(
|
|
4306
|
-
(
|
|
4372
|
+
(_G = output.reason) != null ? _G : "Tool call execution denied."
|
|
4307
4373
|
);
|
|
4308
4374
|
break;
|
|
4309
4375
|
case "json":
|
|
@@ -4499,7 +4565,7 @@ var openaiResponsesNestedErrorChunkSchema = import_v423.z.object({
|
|
|
4499
4565
|
sequence_number: import_v423.z.number(),
|
|
4500
4566
|
error: import_v423.z.object({
|
|
4501
4567
|
type: import_v423.z.string(),
|
|
4502
|
-
code: import_v423.z.string(),
|
|
4568
|
+
code: import_v423.z.string().nullish(),
|
|
4503
4569
|
message: import_v423.z.string(),
|
|
4504
4570
|
param: import_v423.z.string().nullish()
|
|
4505
4571
|
})
|
|
@@ -6853,6 +6919,11 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6853
6919
|
id: value.item.call_id,
|
|
6854
6920
|
toolName
|
|
6855
6921
|
});
|
|
6922
|
+
controller.enqueue({
|
|
6923
|
+
type: "tool-input-delta",
|
|
6924
|
+
id: value.item.call_id,
|
|
6925
|
+
delta: '"'
|
|
6926
|
+
});
|
|
6856
6927
|
} else if (value.item.type === "web_search_call") {
|
|
6857
6928
|
ongoingToolCalls[value.output_index] = {
|
|
6858
6929
|
toolName: toolNameMapping.toCustomToolName(
|
|
@@ -7141,6 +7212,11 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7141
7212
|
const toolName = toolNameMapping.toCustomToolName(
|
|
7142
7213
|
value.item.name
|
|
7143
7214
|
);
|
|
7215
|
+
controller.enqueue({
|
|
7216
|
+
type: "tool-input-delta",
|
|
7217
|
+
id: value.item.call_id,
|
|
7218
|
+
delta: '"'
|
|
7219
|
+
});
|
|
7144
7220
|
controller.enqueue({
|
|
7145
7221
|
type: "tool-input-end",
|
|
7146
7222
|
id: value.item.call_id
|
|
@@ -7467,7 +7543,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7467
7543
|
controller.enqueue({
|
|
7468
7544
|
type: "tool-input-delta",
|
|
7469
7545
|
id: toolCall.toolCallId,
|
|
7470
|
-
delta: value.delta
|
|
7546
|
+
delta: escapeJSONDelta(value.delta)
|
|
7471
7547
|
});
|
|
7472
7548
|
}
|
|
7473
7549
|
} else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
|
|
@@ -8232,7 +8308,7 @@ var OpenAITranscriptionModel = class {
|
|
|
8232
8308
|
};
|
|
8233
8309
|
|
|
8234
8310
|
// src/version.ts
|
|
8235
|
-
var VERSION = true ? "3.0.
|
|
8311
|
+
var VERSION = true ? "3.0.126" : "0.0.0-test";
|
|
8236
8312
|
|
|
8237
8313
|
// src/openai-provider.ts
|
|
8238
8314
|
function createOpenAI(options = {}) {
|