@ai-sdk/openai 2.0.125 → 2.0.127
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 +17 -0
- package/dist/index.d.mts +280 -1
- package/dist/index.d.ts +280 -1
- package/dist/index.js +61 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -11
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +5 -0
- package/dist/internal/index.d.ts +5 -0
- package/dist/internal/index.js +60 -10
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +60 -10
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -56,6 +56,7 @@ function getOpenAILanguageModelCapabilities(modelId) {
|
|
|
56
56
|
supportsFlexProcessing,
|
|
57
57
|
supportsPriorityProcessing,
|
|
58
58
|
supportsConfigurationUpdate: isGpt6OrLaterModel,
|
|
59
|
+
supportsAsyncToolCalling: isGpt6OrLaterModel,
|
|
59
60
|
supportedReasoningEfforts: isGpt6OrLaterModel ? ["low", "medium", "high", "xhigh", "max"] : void 0,
|
|
60
61
|
isReasoningModel,
|
|
61
62
|
systemMessageMode,
|
|
@@ -941,6 +942,12 @@ var OpenAIChatLanguageModel = class {
|
|
|
941
942
|
fetch: this.config.fetch
|
|
942
943
|
});
|
|
943
944
|
const choice = response.choices[0];
|
|
945
|
+
if (choice == null) {
|
|
946
|
+
throw new InvalidResponseDataError({
|
|
947
|
+
data: rawResponse,
|
|
948
|
+
message: "Response did not contain any choices."
|
|
949
|
+
});
|
|
950
|
+
}
|
|
944
951
|
const content = [];
|
|
945
952
|
const text = choice.message.content;
|
|
946
953
|
if (text != null && text.length > 0) {
|
|
@@ -2429,11 +2436,12 @@ function isFileId(data, prefixes) {
|
|
|
2429
2436
|
async function convertToOpenAIResponsesInput({
|
|
2430
2437
|
prompt,
|
|
2431
2438
|
systemMessageMode,
|
|
2439
|
+
explicitMessageItemType = false,
|
|
2432
2440
|
fileIdPrefixes,
|
|
2433
2441
|
store,
|
|
2434
2442
|
hasLocalShellTool = false
|
|
2435
2443
|
}) {
|
|
2436
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
2444
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
2437
2445
|
let input = [];
|
|
2438
2446
|
const warnings = [];
|
|
2439
2447
|
for (const { role, content, providerOptions } of prompt) {
|
|
@@ -2443,6 +2451,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2443
2451
|
case "system": {
|
|
2444
2452
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
|
|
2445
2453
|
input.push({
|
|
2454
|
+
...explicitMessageItemType && { type: "message" },
|
|
2446
2455
|
role: "system",
|
|
2447
2456
|
content: promptCacheBreakpoint == null ? content : [
|
|
2448
2457
|
{
|
|
@@ -2457,6 +2466,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2457
2466
|
case "developer": {
|
|
2458
2467
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
|
|
2459
2468
|
input.push({
|
|
2469
|
+
...explicitMessageItemType && { type: "message" },
|
|
2460
2470
|
role: "developer",
|
|
2461
2471
|
content: promptCacheBreakpoint == null ? content : [
|
|
2462
2472
|
{
|
|
@@ -2486,6 +2496,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2486
2496
|
}
|
|
2487
2497
|
case "user": {
|
|
2488
2498
|
input.push({
|
|
2499
|
+
...explicitMessageItemType && { type: "message" },
|
|
2489
2500
|
role: "user",
|
|
2490
2501
|
content: content.map((part, index) => {
|
|
2491
2502
|
var _a3, _b2, _c2;
|
|
@@ -2562,6 +2573,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2562
2573
|
break;
|
|
2563
2574
|
}
|
|
2564
2575
|
input.push({
|
|
2576
|
+
...explicitMessageItemType && { type: "message" },
|
|
2565
2577
|
role: "assistant",
|
|
2566
2578
|
content: [{ type: "output_text", text: part.text }],
|
|
2567
2579
|
id,
|
|
@@ -2575,6 +2587,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2575
2587
|
break;
|
|
2576
2588
|
}
|
|
2577
2589
|
const id = (_f = (_e = part.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.itemId;
|
|
2590
|
+
const isAsync = (_h = (_g = part.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.async;
|
|
2578
2591
|
if (store && id != null) {
|
|
2579
2592
|
input.push({ type: "item_reference", id });
|
|
2580
2593
|
break;
|
|
@@ -2604,6 +2617,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2604
2617
|
call_id: part.toolCallId,
|
|
2605
2618
|
name: part.toolName,
|
|
2606
2619
|
arguments: JSON.stringify(part.input),
|
|
2620
|
+
...isAsync != null && { async: isAsync },
|
|
2607
2621
|
id
|
|
2608
2622
|
});
|
|
2609
2623
|
break;
|
|
@@ -2879,7 +2893,8 @@ var openaiResponsesChunkSchema = lazyValidator9(
|
|
|
2879
2893
|
id: z17.string(),
|
|
2880
2894
|
call_id: z17.string(),
|
|
2881
2895
|
name: z17.string(),
|
|
2882
|
-
arguments: z17.string()
|
|
2896
|
+
arguments: z17.string(),
|
|
2897
|
+
async: z17.boolean().nullish()
|
|
2883
2898
|
}),
|
|
2884
2899
|
z17.object({
|
|
2885
2900
|
type: z17.literal("web_search_call"),
|
|
@@ -2934,6 +2949,7 @@ var openaiResponsesChunkSchema = lazyValidator9(
|
|
|
2934
2949
|
call_id: z17.string(),
|
|
2935
2950
|
name: z17.string(),
|
|
2936
2951
|
arguments: z17.string(),
|
|
2952
|
+
async: z17.boolean().nullish(),
|
|
2937
2953
|
status: z17.literal("completed")
|
|
2938
2954
|
}),
|
|
2939
2955
|
z17.object({
|
|
@@ -3245,7 +3261,8 @@ var openaiResponsesResponseSchema = lazyValidator9(
|
|
|
3245
3261
|
call_id: z17.string(),
|
|
3246
3262
|
name: z17.string(),
|
|
3247
3263
|
arguments: z17.string(),
|
|
3248
|
-
id: z17.string()
|
|
3264
|
+
id: z17.string(),
|
|
3265
|
+
async: z17.boolean().nullish()
|
|
3249
3266
|
}),
|
|
3250
3267
|
z17.object({
|
|
3251
3268
|
type: z17.literal("computer_call"),
|
|
@@ -3483,8 +3500,10 @@ import { validateTypes as validateTypes2 } from "@ai-sdk/provider-utils";
|
|
|
3483
3500
|
async function prepareResponsesTools({
|
|
3484
3501
|
tools,
|
|
3485
3502
|
toolChoice,
|
|
3486
|
-
strictJsonSchema
|
|
3503
|
+
strictJsonSchema,
|
|
3504
|
+
supportsAsyncToolCalling = true
|
|
3487
3505
|
}) {
|
|
3506
|
+
var _a2;
|
|
3488
3507
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
3489
3508
|
const toolWarnings = [];
|
|
3490
3509
|
if (tools == null) {
|
|
@@ -3493,15 +3512,24 @@ async function prepareResponsesTools({
|
|
|
3493
3512
|
const openaiTools2 = [];
|
|
3494
3513
|
for (const tool of tools) {
|
|
3495
3514
|
switch (tool.type) {
|
|
3496
|
-
case "function":
|
|
3515
|
+
case "function": {
|
|
3516
|
+
const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
|
|
3517
|
+
const async = resolveAsyncToolOption({
|
|
3518
|
+
value: openaiOptions == null ? void 0 : openaiOptions.async,
|
|
3519
|
+
supportsAsyncToolCalling,
|
|
3520
|
+
tool,
|
|
3521
|
+
toolWarnings
|
|
3522
|
+
});
|
|
3497
3523
|
openaiTools2.push({
|
|
3498
3524
|
type: "function",
|
|
3499
3525
|
name: tool.name,
|
|
3500
3526
|
description: tool.description,
|
|
3501
3527
|
parameters: tool.inputSchema,
|
|
3502
|
-
strict: strictJsonSchema
|
|
3528
|
+
strict: strictJsonSchema,
|
|
3529
|
+
...async != null ? { async } : {}
|
|
3503
3530
|
});
|
|
3504
3531
|
break;
|
|
3532
|
+
}
|
|
3505
3533
|
case "provider-defined": {
|
|
3506
3534
|
switch (tool.id) {
|
|
3507
3535
|
case "openai.file_search": {
|
|
@@ -3620,6 +3648,22 @@ async function prepareResponsesTools({
|
|
|
3620
3648
|
}
|
|
3621
3649
|
}
|
|
3622
3650
|
}
|
|
3651
|
+
function resolveAsyncToolOption({
|
|
3652
|
+
value,
|
|
3653
|
+
supportsAsyncToolCalling,
|
|
3654
|
+
tool,
|
|
3655
|
+
toolWarnings
|
|
3656
|
+
}) {
|
|
3657
|
+
if (value !== true || supportsAsyncToolCalling) {
|
|
3658
|
+
return value;
|
|
3659
|
+
}
|
|
3660
|
+
toolWarnings.push({
|
|
3661
|
+
type: "unsupported-tool",
|
|
3662
|
+
tool,
|
|
3663
|
+
details: "Async tool calling is only supported by GPT-6 and later models."
|
|
3664
|
+
});
|
|
3665
|
+
return void 0;
|
|
3666
|
+
}
|
|
3623
3667
|
|
|
3624
3668
|
// src/responses/openai-responses-language-model.ts
|
|
3625
3669
|
var OpenAIResponsesLanguageModel = class {
|
|
@@ -3689,6 +3733,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3689
3733
|
const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
|
|
3690
3734
|
prompt,
|
|
3691
3735
|
systemMessageMode: modelCapabilities.systemMessageMode,
|
|
3736
|
+
explicitMessageItemType: this.config.explicitMessageItemType,
|
|
3692
3737
|
fileIdPrefixes: this.config.fileIdPrefixes,
|
|
3693
3738
|
store: (_a2 = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a2 : true,
|
|
3694
3739
|
hasLocalShellTool: hasOpenAITool("openai.local_shell")
|
|
@@ -3899,7 +3944,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3899
3944
|
} = await prepareResponsesTools({
|
|
3900
3945
|
tools,
|
|
3901
3946
|
toolChoice,
|
|
3902
|
-
strictJsonSchema
|
|
3947
|
+
strictJsonSchema,
|
|
3948
|
+
supportsAsyncToolCalling: modelCapabilities.supportsAsyncToolCalling
|
|
3903
3949
|
});
|
|
3904
3950
|
return {
|
|
3905
3951
|
webSearchToolName,
|
|
@@ -4093,7 +4139,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4093
4139
|
input: part.arguments,
|
|
4094
4140
|
providerMetadata: {
|
|
4095
4141
|
[providerKey]: {
|
|
4096
|
-
itemId: part.id
|
|
4142
|
+
itemId: part.id,
|
|
4143
|
+
...part.async != null && { async: part.async }
|
|
4097
4144
|
}
|
|
4098
4145
|
}
|
|
4099
4146
|
});
|
|
@@ -4293,7 +4340,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4293
4340
|
if (value.item.type === "function_call") {
|
|
4294
4341
|
ongoingToolCalls[value.output_index] = {
|
|
4295
4342
|
toolName: value.item.name,
|
|
4296
|
-
toolCallId: value.item.call_id
|
|
4343
|
+
toolCallId: value.item.call_id,
|
|
4344
|
+
async: value.item.async
|
|
4297
4345
|
};
|
|
4298
4346
|
controller.enqueue({
|
|
4299
4347
|
type: "tool-input-start",
|
|
@@ -4417,6 +4465,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4417
4465
|
}
|
|
4418
4466
|
});
|
|
4419
4467
|
} else if (value.item.type === "function_call") {
|
|
4468
|
+
const ongoingToolCall = ongoingToolCalls[value.output_index];
|
|
4420
4469
|
ongoingToolCalls[value.output_index] = void 0;
|
|
4421
4470
|
hasFunctionCall = true;
|
|
4422
4471
|
controller.enqueue({
|
|
@@ -4430,7 +4479,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4430
4479
|
input: value.item.arguments,
|
|
4431
4480
|
providerMetadata: {
|
|
4432
4481
|
[providerKey]: {
|
|
4433
|
-
itemId: value.item.id
|
|
4482
|
+
itemId: value.item.id,
|
|
4483
|
+
...value.item.async != null ? { async: value.item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {}
|
|
4434
4484
|
}
|
|
4435
4485
|
}
|
|
4436
4486
|
});
|
|
@@ -5183,7 +5233,7 @@ var OpenAITranscriptionModel = class {
|
|
|
5183
5233
|
};
|
|
5184
5234
|
|
|
5185
5235
|
// src/version.ts
|
|
5186
|
-
var VERSION = true ? "2.0.
|
|
5236
|
+
var VERSION = true ? "2.0.127" : "0.0.0-test";
|
|
5187
5237
|
|
|
5188
5238
|
// src/openai-provider.ts
|
|
5189
5239
|
function createOpenAI(options = {}) {
|