@ai-sdk/openai 3.0.100 → 3.0.102
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 +14 -0
- package/dist/index.d.mts +29 -12
- package/dist/index.d.ts +29 -12
- package/dist/index.js +96 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -36
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +29 -12
- package/dist/internal/index.d.ts +29 -12
- package/dist/internal/index.js +95 -35
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +95 -35
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/chat/convert-openai-chat-usage.ts +1 -1
- package/src/responses/openai-responses-api.ts +113 -40
- package/src/responses/openai-responses-language-model.ts +10 -7
|
@@ -361,6 +361,18 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
361
361
|
type: "response.output_item.added";
|
|
362
362
|
output_index: number;
|
|
363
363
|
item: {
|
|
364
|
+
type: "local_shell_call";
|
|
365
|
+
id: string;
|
|
366
|
+
call_id: string;
|
|
367
|
+
action: {
|
|
368
|
+
type: "exec";
|
|
369
|
+
command: string[];
|
|
370
|
+
timeout_ms?: number | undefined;
|
|
371
|
+
user?: string | undefined;
|
|
372
|
+
working_directory?: string | undefined;
|
|
373
|
+
env?: Record<string, string> | undefined;
|
|
374
|
+
};
|
|
375
|
+
} | {
|
|
364
376
|
type: "message";
|
|
365
377
|
id: string;
|
|
366
378
|
phase?: "commentary" | "final_answer" | null | undefined;
|
|
@@ -478,6 +490,18 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
478
490
|
type: "response.output_item.done";
|
|
479
491
|
output_index: number;
|
|
480
492
|
item: {
|
|
493
|
+
type: "local_shell_call";
|
|
494
|
+
id: string;
|
|
495
|
+
call_id: string;
|
|
496
|
+
action: {
|
|
497
|
+
type: "exec";
|
|
498
|
+
command: string[];
|
|
499
|
+
timeout_ms?: number | undefined;
|
|
500
|
+
user?: string | undefined;
|
|
501
|
+
working_directory?: string | undefined;
|
|
502
|
+
env?: Record<string, string> | undefined;
|
|
503
|
+
};
|
|
504
|
+
} | {
|
|
481
505
|
type: "message";
|
|
482
506
|
id: string;
|
|
483
507
|
phase?: "commentary" | "final_answer" | null | undefined;
|
|
@@ -550,18 +574,6 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
550
574
|
score: number;
|
|
551
575
|
text: string;
|
|
552
576
|
}[] | null | undefined;
|
|
553
|
-
} | {
|
|
554
|
-
type: "local_shell_call";
|
|
555
|
-
id: string;
|
|
556
|
-
call_id: string;
|
|
557
|
-
action: {
|
|
558
|
-
type: "exec";
|
|
559
|
-
command: string[];
|
|
560
|
-
timeout_ms?: number | undefined;
|
|
561
|
-
user?: string | undefined;
|
|
562
|
-
working_directory?: string | undefined;
|
|
563
|
-
env?: Record<string, string> | undefined;
|
|
564
|
-
};
|
|
565
577
|
} | {
|
|
566
578
|
type: "computer_call";
|
|
567
579
|
id: string;
|
|
@@ -664,6 +676,11 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
664
676
|
item_id: string;
|
|
665
677
|
output_index: number;
|
|
666
678
|
delta: string;
|
|
679
|
+
} | {
|
|
680
|
+
type: "response.function_call_arguments.done";
|
|
681
|
+
item_id: string;
|
|
682
|
+
output_index: number;
|
|
683
|
+
arguments: string;
|
|
667
684
|
} | {
|
|
668
685
|
type: "response.custom_tool_call_input.delta";
|
|
669
686
|
item_id: string;
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -361,6 +361,18 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
361
361
|
type: "response.output_item.added";
|
|
362
362
|
output_index: number;
|
|
363
363
|
item: {
|
|
364
|
+
type: "local_shell_call";
|
|
365
|
+
id: string;
|
|
366
|
+
call_id: string;
|
|
367
|
+
action: {
|
|
368
|
+
type: "exec";
|
|
369
|
+
command: string[];
|
|
370
|
+
timeout_ms?: number | undefined;
|
|
371
|
+
user?: string | undefined;
|
|
372
|
+
working_directory?: string | undefined;
|
|
373
|
+
env?: Record<string, string> | undefined;
|
|
374
|
+
};
|
|
375
|
+
} | {
|
|
364
376
|
type: "message";
|
|
365
377
|
id: string;
|
|
366
378
|
phase?: "commentary" | "final_answer" | null | undefined;
|
|
@@ -478,6 +490,18 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
478
490
|
type: "response.output_item.done";
|
|
479
491
|
output_index: number;
|
|
480
492
|
item: {
|
|
493
|
+
type: "local_shell_call";
|
|
494
|
+
id: string;
|
|
495
|
+
call_id: string;
|
|
496
|
+
action: {
|
|
497
|
+
type: "exec";
|
|
498
|
+
command: string[];
|
|
499
|
+
timeout_ms?: number | undefined;
|
|
500
|
+
user?: string | undefined;
|
|
501
|
+
working_directory?: string | undefined;
|
|
502
|
+
env?: Record<string, string> | undefined;
|
|
503
|
+
};
|
|
504
|
+
} | {
|
|
481
505
|
type: "message";
|
|
482
506
|
id: string;
|
|
483
507
|
phase?: "commentary" | "final_answer" | null | undefined;
|
|
@@ -550,18 +574,6 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
550
574
|
score: number;
|
|
551
575
|
text: string;
|
|
552
576
|
}[] | null | undefined;
|
|
553
|
-
} | {
|
|
554
|
-
type: "local_shell_call";
|
|
555
|
-
id: string;
|
|
556
|
-
call_id: string;
|
|
557
|
-
action: {
|
|
558
|
-
type: "exec";
|
|
559
|
-
command: string[];
|
|
560
|
-
timeout_ms?: number | undefined;
|
|
561
|
-
user?: string | undefined;
|
|
562
|
-
working_directory?: string | undefined;
|
|
563
|
-
env?: Record<string, string> | undefined;
|
|
564
|
-
};
|
|
565
577
|
} | {
|
|
566
578
|
type: "computer_call";
|
|
567
579
|
id: string;
|
|
@@ -664,6 +676,11 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
664
676
|
item_id: string;
|
|
665
677
|
output_index: number;
|
|
666
678
|
delta: string;
|
|
679
|
+
} | {
|
|
680
|
+
type: "response.function_call_arguments.done";
|
|
681
|
+
item_id: string;
|
|
682
|
+
output_index: number;
|
|
683
|
+
arguments: string;
|
|
667
684
|
} | {
|
|
668
685
|
type: "response.custom_tool_call_input.delta";
|
|
669
686
|
item_id: string;
|
package/dist/internal/index.js
CHANGED
|
@@ -279,7 +279,7 @@ function convertOpenAIChatUsage(usage) {
|
|
|
279
279
|
},
|
|
280
280
|
outputTokens: {
|
|
281
281
|
total: completionTokens,
|
|
282
|
-
text: completionTokens - reasoningTokens,
|
|
282
|
+
text: Math.max(0, completionTokens - reasoningTokens),
|
|
283
283
|
reasoning: reasoningTokens
|
|
284
284
|
},
|
|
285
285
|
raw: usage
|
|
@@ -3886,6 +3886,22 @@ var jsonValueSchema = import_v418.z.lazy(
|
|
|
3886
3886
|
import_v418.z.record(import_v418.z.string(), jsonValueSchema.optional())
|
|
3887
3887
|
])
|
|
3888
3888
|
);
|
|
3889
|
+
function isRecord(value) {
|
|
3890
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
3891
|
+
}
|
|
3892
|
+
var openaiResponsesLocalShellCallSchema = import_v418.z.object({
|
|
3893
|
+
type: import_v418.z.literal("local_shell_call"),
|
|
3894
|
+
id: import_v418.z.string(),
|
|
3895
|
+
call_id: import_v418.z.string(),
|
|
3896
|
+
action: import_v418.z.object({
|
|
3897
|
+
type: import_v418.z.literal("exec"),
|
|
3898
|
+
command: import_v418.z.array(import_v418.z.string()),
|
|
3899
|
+
timeout_ms: import_v418.z.number().optional(),
|
|
3900
|
+
user: import_v418.z.string().optional(),
|
|
3901
|
+
working_directory: import_v418.z.string().optional(),
|
|
3902
|
+
env: import_v418.z.record(import_v418.z.string(), import_v418.z.string()).optional()
|
|
3903
|
+
})
|
|
3904
|
+
});
|
|
3889
3905
|
var openaiResponsesNestedErrorChunkSchema = import_v418.z.object({
|
|
3890
3906
|
type: import_v418.z.literal("error"),
|
|
3891
3907
|
sequence_number: import_v418.z.number(),
|
|
@@ -3903,6 +3919,60 @@ var openaiResponsesErrorChunkSchema = import_v418.z.object({
|
|
|
3903
3919
|
message: import_v418.z.string(),
|
|
3904
3920
|
param: import_v418.z.string().nullish()
|
|
3905
3921
|
});
|
|
3922
|
+
var openaiResponsesModeledChunkTypes = /* @__PURE__ */ new Set([
|
|
3923
|
+
"error",
|
|
3924
|
+
"response.apply_patch_call_operation_diff.delta",
|
|
3925
|
+
"response.apply_patch_call_operation_diff.done",
|
|
3926
|
+
"response.code_interpreter_call_code.delta",
|
|
3927
|
+
"response.code_interpreter_call_code.done",
|
|
3928
|
+
"response.completed",
|
|
3929
|
+
"response.created",
|
|
3930
|
+
"response.custom_tool_call_input.delta",
|
|
3931
|
+
"response.failed",
|
|
3932
|
+
"response.function_call_arguments.delta",
|
|
3933
|
+
"response.function_call_arguments.done",
|
|
3934
|
+
"response.image_generation_call.partial_image",
|
|
3935
|
+
"response.incomplete",
|
|
3936
|
+
"response.output_item.added",
|
|
3937
|
+
"response.output_item.done",
|
|
3938
|
+
"response.output_text.annotation.added",
|
|
3939
|
+
"response.output_text.delta",
|
|
3940
|
+
"response.reasoning_summary_part.added",
|
|
3941
|
+
"response.reasoning_summary_part.done",
|
|
3942
|
+
"response.reasoning_summary_text.delta"
|
|
3943
|
+
]);
|
|
3944
|
+
var openaiResponsesModeledOutputItemTypes = /* @__PURE__ */ new Set([
|
|
3945
|
+
"apply_patch_call",
|
|
3946
|
+
"code_interpreter_call",
|
|
3947
|
+
"computer_call",
|
|
3948
|
+
"custom_tool_call",
|
|
3949
|
+
"file_search_call",
|
|
3950
|
+
"function_call",
|
|
3951
|
+
"image_generation_call",
|
|
3952
|
+
"local_shell_call",
|
|
3953
|
+
"mcp_approval_request",
|
|
3954
|
+
"mcp_call",
|
|
3955
|
+
"mcp_list_tools",
|
|
3956
|
+
"message",
|
|
3957
|
+
"reasoning",
|
|
3958
|
+
"shell_call",
|
|
3959
|
+
"shell_call_output",
|
|
3960
|
+
"tool_search_call",
|
|
3961
|
+
"tool_search_output",
|
|
3962
|
+
"web_search_call"
|
|
3963
|
+
]);
|
|
3964
|
+
function isModeledOpenAIResponsesChunk(value) {
|
|
3965
|
+
if (typeof value.type !== "string" || !openaiResponsesModeledChunkTypes.has(value.type)) {
|
|
3966
|
+
return false;
|
|
3967
|
+
}
|
|
3968
|
+
if (value.type !== "response.output_item.added" && value.type !== "response.output_item.done") {
|
|
3969
|
+
return true;
|
|
3970
|
+
}
|
|
3971
|
+
if (!isRecord(value.item) || typeof value.item.type !== "string") {
|
|
3972
|
+
return true;
|
|
3973
|
+
}
|
|
3974
|
+
return openaiResponsesModeledOutputItemTypes.has(value.item.type);
|
|
3975
|
+
}
|
|
3906
3976
|
var openaiResponsesChunkSchema = (0, import_provider_utils26.lazySchema)(
|
|
3907
3977
|
() => (0, import_provider_utils26.zodSchema)(
|
|
3908
3978
|
import_v418.z.union([
|
|
@@ -4021,6 +4091,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
4021
4091
|
type: import_v418.z.literal("file_search_call"),
|
|
4022
4092
|
id: import_v418.z.string()
|
|
4023
4093
|
}),
|
|
4094
|
+
openaiResponsesLocalShellCallSchema,
|
|
4024
4095
|
import_v418.z.object({
|
|
4025
4096
|
type: import_v418.z.literal("image_generation_call"),
|
|
4026
4097
|
id: import_v418.z.string()
|
|
@@ -4219,19 +4290,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
4219
4290
|
})
|
|
4220
4291
|
).nullish()
|
|
4221
4292
|
}),
|
|
4222
|
-
|
|
4223
|
-
type: import_v418.z.literal("local_shell_call"),
|
|
4224
|
-
id: import_v418.z.string(),
|
|
4225
|
-
call_id: import_v418.z.string(),
|
|
4226
|
-
action: import_v418.z.object({
|
|
4227
|
-
type: import_v418.z.literal("exec"),
|
|
4228
|
-
command: import_v418.z.array(import_v418.z.string()),
|
|
4229
|
-
timeout_ms: import_v418.z.number().optional(),
|
|
4230
|
-
user: import_v418.z.string().optional(),
|
|
4231
|
-
working_directory: import_v418.z.string().optional(),
|
|
4232
|
-
env: import_v418.z.record(import_v418.z.string(), import_v418.z.string()).optional()
|
|
4233
|
-
})
|
|
4234
|
-
}),
|
|
4293
|
+
openaiResponsesLocalShellCallSchema,
|
|
4235
4294
|
import_v418.z.object({
|
|
4236
4295
|
type: import_v418.z.literal("computer_call"),
|
|
4237
4296
|
id: import_v418.z.string(),
|
|
@@ -4358,6 +4417,14 @@ var openaiResponsesChunkSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
4358
4417
|
output_index: import_v418.z.number(),
|
|
4359
4418
|
delta: import_v418.z.string()
|
|
4360
4419
|
}),
|
|
4420
|
+
import_v418.z.object({
|
|
4421
|
+
// `name` is documented as required but omitted from live API events:
|
|
4422
|
+
// https://github.com/openai/openai-openapi/issues/545
|
|
4423
|
+
type: import_v418.z.literal("response.function_call_arguments.done"),
|
|
4424
|
+
item_id: import_v418.z.string(),
|
|
4425
|
+
output_index: import_v418.z.number(),
|
|
4426
|
+
arguments: import_v418.z.string()
|
|
4427
|
+
}),
|
|
4361
4428
|
import_v418.z.object({
|
|
4362
4429
|
type: import_v418.z.literal("response.custom_tool_call_input.delta"),
|
|
4363
4430
|
item_id: import_v418.z.string(),
|
|
@@ -4444,7 +4511,9 @@ var openaiResponsesChunkSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
4444
4511
|
}),
|
|
4445
4512
|
openaiResponsesNestedErrorChunkSchema,
|
|
4446
4513
|
openaiResponsesErrorChunkSchema,
|
|
4447
|
-
import_v418.z.object({ type: import_v418.z.string() }).loose().
|
|
4514
|
+
import_v418.z.object({ type: import_v418.z.string() }).loose().refine((value) => !isModeledOpenAIResponsesChunk(value), {
|
|
4515
|
+
message: "Known response chunk failed schema validation"
|
|
4516
|
+
}).transform((value) => ({
|
|
4448
4517
|
type: "unknown_chunk",
|
|
4449
4518
|
message: value.type
|
|
4450
4519
|
}))
|
|
@@ -4584,19 +4653,7 @@ var openaiResponsesResponseSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
4584
4653
|
id: import_v418.z.string(),
|
|
4585
4654
|
result: import_v418.z.string()
|
|
4586
4655
|
}),
|
|
4587
|
-
|
|
4588
|
-
type: import_v418.z.literal("local_shell_call"),
|
|
4589
|
-
id: import_v418.z.string(),
|
|
4590
|
-
call_id: import_v418.z.string(),
|
|
4591
|
-
action: import_v418.z.object({
|
|
4592
|
-
type: import_v418.z.literal("exec"),
|
|
4593
|
-
command: import_v418.z.array(import_v418.z.string()),
|
|
4594
|
-
timeout_ms: import_v418.z.number().optional(),
|
|
4595
|
-
user: import_v418.z.string().optional(),
|
|
4596
|
-
working_directory: import_v418.z.string().optional(),
|
|
4597
|
-
env: import_v418.z.record(import_v418.z.string(), import_v418.z.string()).optional()
|
|
4598
|
-
})
|
|
4599
|
-
}),
|
|
4656
|
+
openaiResponsesLocalShellCallSchema,
|
|
4600
4657
|
import_v418.z.object({
|
|
4601
4658
|
type: import_v418.z.literal("function_call"),
|
|
4602
4659
|
call_id: import_v418.z.string(),
|
|
@@ -6679,6 +6736,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6679
6736
|
requestBodyValues: body,
|
|
6680
6737
|
responseHeaders
|
|
6681
6738
|
}) : chunk.error;
|
|
6739
|
+
encounteredStreamError = true;
|
|
6682
6740
|
finishReason = { unified: "error", raw: void 0 };
|
|
6683
6741
|
controller.enqueue({ type: "error", error });
|
|
6684
6742
|
return;
|
|
@@ -7478,13 +7536,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7478
7536
|
activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
|
|
7479
7537
|
}
|
|
7480
7538
|
} else if (isResponseFinishedChunk(value)) {
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7539
|
+
if (!encounteredStreamError) {
|
|
7540
|
+
finishReason = {
|
|
7541
|
+
unified: mapOpenAIResponseFinishReason({
|
|
7542
|
+
finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
|
|
7543
|
+
hasFunctionCall
|
|
7544
|
+
}),
|
|
7545
|
+
raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
|
|
7546
|
+
};
|
|
7547
|
+
}
|
|
7488
7548
|
usage = value.response.usage;
|
|
7489
7549
|
if (typeof value.response.service_tier === "string") {
|
|
7490
7550
|
serviceTier = value.response.service_tier;
|