@ai-sdk/openai 4.0.0-beta.3 → 4.0.0-beta.31
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 +320 -22
- package/README.md +2 -0
- package/dist/index.d.ts +139 -36
- package/dist/index.js +2343 -1490
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +168 -45
- package/dist/internal/index.js +2112 -1511
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +274 -9
- package/package.json +9 -12
- package/src/chat/convert-openai-chat-usage.ts +2 -2
- package/src/chat/convert-to-openai-chat-messages.ts +26 -15
- package/src/chat/map-openai-finish-reason.ts +2 -2
- package/src/chat/openai-chat-language-model.ts +52 -28
- package/src/chat/openai-chat-options.ts +5 -0
- package/src/chat/openai-chat-prepare-tools.ts +6 -6
- package/src/completion/convert-openai-completion-usage.ts +2 -2
- package/src/completion/convert-to-openai-completion-prompt.ts +2 -2
- package/src/completion/map-openai-finish-reason.ts +2 -2
- package/src/completion/openai-completion-language-model.ts +40 -23
- package/src/embedding/openai-embedding-model.ts +23 -6
- package/src/files/openai-files-api.ts +17 -0
- package/src/files/openai-files-options.ts +18 -0
- package/src/files/openai-files.ts +102 -0
- package/src/image/openai-image-model.ts +28 -11
- package/src/index.ts +2 -0
- package/src/openai-config.ts +6 -6
- package/src/openai-language-model-capabilities.ts +3 -2
- package/src/openai-provider.ts +54 -21
- package/src/openai-tools.ts +12 -1
- package/src/responses/convert-openai-responses-usage.ts +2 -2
- package/src/responses/convert-to-openai-responses-input.ts +211 -37
- package/src/responses/map-openai-responses-finish-reason.ts +2 -2
- package/src/responses/openai-responses-api.ts +136 -2
- package/src/responses/openai-responses-language-model.ts +252 -39
- package/src/responses/openai-responses-options.ts +24 -2
- package/src/responses/openai-responses-prepare-tools.ts +47 -14
- package/src/responses/openai-responses-provider-metadata.ts +10 -0
- package/src/skills/openai-skills-api.ts +31 -0
- package/src/skills/openai-skills.ts +87 -0
- package/src/speech/openai-speech-model.ts +25 -8
- package/src/tool/custom.ts +0 -6
- package/src/tool/shell.ts +7 -2
- package/src/tool/tool-search.ts +98 -0
- package/src/transcription/openai-transcription-model.ts +26 -9
- package/dist/index.d.mts +0 -1107
- package/dist/index.mjs +0 -6497
- package/dist/index.mjs.map +0 -1
- package/dist/internal/index.d.mts +0 -1137
- package/dist/internal/index.mjs +0 -6310
- package/dist/internal/index.mjs.map +0 -1
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
APICallError,
|
|
3
3
|
JSONValue,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
LanguageModelV4,
|
|
5
|
+
LanguageModelV4Prompt,
|
|
6
|
+
LanguageModelV4CallOptions,
|
|
7
|
+
LanguageModelV4Content,
|
|
8
|
+
LanguageModelV4FinishReason,
|
|
9
|
+
LanguageModelV4GenerateResult,
|
|
10
|
+
LanguageModelV4ProviderTool,
|
|
11
|
+
LanguageModelV4StreamPart,
|
|
12
|
+
LanguageModelV4StreamResult,
|
|
13
|
+
LanguageModelV4ToolApprovalRequest,
|
|
14
|
+
SharedV4ProviderMetadata,
|
|
15
|
+
SharedV4Warning,
|
|
16
16
|
} from '@ai-sdk/provider';
|
|
17
17
|
import {
|
|
18
18
|
combineHeaders,
|
|
@@ -21,9 +21,13 @@ import {
|
|
|
21
21
|
createToolNameMapping,
|
|
22
22
|
generateId,
|
|
23
23
|
InferSchema,
|
|
24
|
+
isCustomReasoning,
|
|
24
25
|
parseProviderOptions,
|
|
25
26
|
ParseResult,
|
|
26
27
|
postJsonToApi,
|
|
28
|
+
serializeModelOptions,
|
|
29
|
+
WORKFLOW_DESERIALIZE,
|
|
30
|
+
WORKFLOW_SERIALIZE,
|
|
27
31
|
} from '@ai-sdk/provider-utils';
|
|
28
32
|
import { OpenAIConfig } from '../openai-config';
|
|
29
33
|
import { openaiFailedResponseHandler } from '../openai-error';
|
|
@@ -38,6 +42,10 @@ import { imageGenerationOutputSchema } from '../tool/image-generation';
|
|
|
38
42
|
import { localShellInputSchema } from '../tool/local-shell';
|
|
39
43
|
import { mcpOutputSchema } from '../tool/mcp';
|
|
40
44
|
import { shellInputSchema, shellOutputSchema } from '../tool/shell';
|
|
45
|
+
import {
|
|
46
|
+
toolSearchInputSchema,
|
|
47
|
+
toolSearchOutputSchema,
|
|
48
|
+
} from '../tool/tool-search';
|
|
41
49
|
import { webSearchOutputSchema } from '../tool/web-search';
|
|
42
50
|
import {
|
|
43
51
|
convertOpenAIResponsesUsage,
|
|
@@ -63,6 +71,7 @@ import {
|
|
|
63
71
|
} from './openai-responses-options';
|
|
64
72
|
import { prepareResponsesTools } from './openai-responses-prepare-tools';
|
|
65
73
|
import {
|
|
74
|
+
ResponsesCompactionProviderMetadata,
|
|
66
75
|
ResponsesProviderMetadata,
|
|
67
76
|
ResponsesReasoningProviderMetadata,
|
|
68
77
|
ResponsesSourceDocumentProviderMetadata,
|
|
@@ -77,7 +86,7 @@ import {
|
|
|
77
86
|
* so that tool results reference the correct tool call.
|
|
78
87
|
*/
|
|
79
88
|
function extractApprovalRequestIdToToolCallIdMapping(
|
|
80
|
-
prompt:
|
|
89
|
+
prompt: LanguageModelV4Prompt,
|
|
81
90
|
): Record<string, string> {
|
|
82
91
|
const mapping: Record<string, string> = {};
|
|
83
92
|
for (const message of prompt) {
|
|
@@ -94,13 +103,27 @@ function extractApprovalRequestIdToToolCallIdMapping(
|
|
|
94
103
|
return mapping;
|
|
95
104
|
}
|
|
96
105
|
|
|
97
|
-
export class OpenAIResponsesLanguageModel implements
|
|
98
|
-
readonly specificationVersion = '
|
|
106
|
+
export class OpenAIResponsesLanguageModel implements LanguageModelV4 {
|
|
107
|
+
readonly specificationVersion = 'v4';
|
|
99
108
|
|
|
100
109
|
readonly modelId: OpenAIResponsesModelId;
|
|
101
110
|
|
|
102
111
|
private readonly config: OpenAIConfig;
|
|
103
112
|
|
|
113
|
+
static [WORKFLOW_SERIALIZE](model: OpenAIResponsesLanguageModel) {
|
|
114
|
+
return serializeModelOptions({
|
|
115
|
+
modelId: model.modelId,
|
|
116
|
+
config: model.config,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
121
|
+
modelId: OpenAIResponsesModelId;
|
|
122
|
+
config: OpenAIConfig;
|
|
123
|
+
}) {
|
|
124
|
+
return new OpenAIResponsesLanguageModel(options.modelId, options.config);
|
|
125
|
+
}
|
|
126
|
+
|
|
104
127
|
constructor(modelId: OpenAIResponsesModelId, config: OpenAIConfig) {
|
|
105
128
|
this.modelId = modelId;
|
|
106
129
|
this.config = config;
|
|
@@ -125,12 +148,13 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
125
148
|
frequencyPenalty,
|
|
126
149
|
seed,
|
|
127
150
|
prompt,
|
|
151
|
+
reasoning,
|
|
128
152
|
providerOptions,
|
|
129
153
|
tools,
|
|
130
154
|
toolChoice,
|
|
131
155
|
responseFormat,
|
|
132
|
-
}:
|
|
133
|
-
const warnings:
|
|
156
|
+
}: LanguageModelV4CallOptions) {
|
|
157
|
+
const warnings: SharedV4Warning[] = [];
|
|
134
158
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
135
159
|
|
|
136
160
|
if (topK != null) {
|
|
@@ -170,6 +194,10 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
170
194
|
});
|
|
171
195
|
}
|
|
172
196
|
|
|
197
|
+
const resolvedReasoningEffort =
|
|
198
|
+
openaiOptions?.reasoningEffort ??
|
|
199
|
+
(isCustomReasoning(reasoning) ? reasoning : undefined);
|
|
200
|
+
|
|
173
201
|
const isReasoningModel =
|
|
174
202
|
openaiOptions?.forceReasoning ?? modelCapabilities.isReasoningModel;
|
|
175
203
|
|
|
@@ -193,11 +221,8 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
193
221
|
'openai.web_search_preview': 'web_search_preview',
|
|
194
222
|
'openai.mcp': 'mcp',
|
|
195
223
|
'openai.apply_patch': 'apply_patch',
|
|
224
|
+
'openai.tool_search': 'tool_search',
|
|
196
225
|
},
|
|
197
|
-
resolveProviderToolName: tool =>
|
|
198
|
-
tool.id === 'openai.custom'
|
|
199
|
-
? (tool.args as { name?: string }).name
|
|
200
|
-
: undefined,
|
|
201
226
|
});
|
|
202
227
|
|
|
203
228
|
const customProviderToolNames = new Set<string>();
|
|
@@ -273,7 +298,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
273
298
|
tool.type === 'provider' &&
|
|
274
299
|
(tool.id === 'openai.web_search' ||
|
|
275
300
|
tool.id === 'openai.web_search_preview'),
|
|
276
|
-
) as
|
|
301
|
+
) as LanguageModelV4ProviderTool | undefined
|
|
277
302
|
)?.name;
|
|
278
303
|
|
|
279
304
|
if (webSearchToolName) {
|
|
@@ -336,13 +361,21 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
336
361
|
top_logprobs: topLogprobs,
|
|
337
362
|
truncation: openaiOptions?.truncation,
|
|
338
363
|
|
|
364
|
+
// context management (server-side compaction):
|
|
365
|
+
...(openaiOptions?.contextManagement && {
|
|
366
|
+
context_management: openaiOptions.contextManagement.map(cm => ({
|
|
367
|
+
type: cm.type,
|
|
368
|
+
compact_threshold: cm.compactThreshold,
|
|
369
|
+
})),
|
|
370
|
+
}),
|
|
371
|
+
|
|
339
372
|
// model-specific settings:
|
|
340
373
|
...(isReasoningModel &&
|
|
341
|
-
(
|
|
374
|
+
(resolvedReasoningEffort != null ||
|
|
342
375
|
openaiOptions?.reasoningSummary != null) && {
|
|
343
376
|
reasoning: {
|
|
344
|
-
...(
|
|
345
|
-
effort:
|
|
377
|
+
...(resolvedReasoningEffort != null && {
|
|
378
|
+
effort: resolvedReasoningEffort,
|
|
346
379
|
}),
|
|
347
380
|
...(openaiOptions?.reasoningSummary != null && {
|
|
348
381
|
summary: openaiOptions.reasoningSummary,
|
|
@@ -358,7 +391,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
358
391
|
// https://platform.openai.com/docs/guides/latest-model#gpt-5-1-parameter-compatibility
|
|
359
392
|
if (
|
|
360
393
|
!(
|
|
361
|
-
|
|
394
|
+
resolvedReasoningEffort === 'none' &&
|
|
362
395
|
modelCapabilities.supportsNonReasoningParameters
|
|
363
396
|
)
|
|
364
397
|
) {
|
|
@@ -454,8 +487,8 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
454
487
|
}
|
|
455
488
|
|
|
456
489
|
async doGenerate(
|
|
457
|
-
options:
|
|
458
|
-
): Promise<
|
|
490
|
+
options: LanguageModelV4CallOptions,
|
|
491
|
+
): Promise<LanguageModelV4GenerateResult> {
|
|
459
492
|
const {
|
|
460
493
|
args: body,
|
|
461
494
|
warnings,
|
|
@@ -478,7 +511,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
478
511
|
rawValue: rawResponse,
|
|
479
512
|
} = await postJsonToApi({
|
|
480
513
|
url,
|
|
481
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
514
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
482
515
|
body,
|
|
483
516
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
484
517
|
successfulResponseHandler: createJsonResponseHandler(
|
|
@@ -500,11 +533,12 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
500
533
|
});
|
|
501
534
|
}
|
|
502
535
|
|
|
503
|
-
const content: Array<
|
|
536
|
+
const content: Array<LanguageModelV4Content> = [];
|
|
504
537
|
const logprobs: Array<OpenAIResponsesLogprobs> = [];
|
|
505
538
|
|
|
506
539
|
// flag that checks if there have been client-side tool calls (not executed by openai)
|
|
507
540
|
let hasFunctionCall = false;
|
|
541
|
+
const hostedToolSearchCallIds: string[] = [];
|
|
508
542
|
|
|
509
543
|
// map response content to content array (defined when there is no error)
|
|
510
544
|
for (const part of response.output!) {
|
|
@@ -551,6 +585,54 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
551
585
|
break;
|
|
552
586
|
}
|
|
553
587
|
|
|
588
|
+
case 'tool_search_call': {
|
|
589
|
+
const toolCallId = part.call_id ?? part.id;
|
|
590
|
+
const isHosted = part.execution === 'server';
|
|
591
|
+
|
|
592
|
+
if (isHosted) {
|
|
593
|
+
hostedToolSearchCallIds.push(toolCallId);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
content.push({
|
|
597
|
+
type: 'tool-call',
|
|
598
|
+
toolCallId,
|
|
599
|
+
toolName: toolNameMapping.toCustomToolName('tool_search'),
|
|
600
|
+
input: JSON.stringify({
|
|
601
|
+
arguments: part.arguments,
|
|
602
|
+
call_id: part.call_id,
|
|
603
|
+
} satisfies InferSchema<typeof toolSearchInputSchema>),
|
|
604
|
+
...(isHosted ? { providerExecuted: true } : {}),
|
|
605
|
+
providerMetadata: {
|
|
606
|
+
[providerOptionsName]: {
|
|
607
|
+
itemId: part.id,
|
|
608
|
+
},
|
|
609
|
+
},
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
case 'tool_search_output': {
|
|
616
|
+
const toolCallId =
|
|
617
|
+
part.call_id ?? hostedToolSearchCallIds.shift() ?? part.id;
|
|
618
|
+
|
|
619
|
+
content.push({
|
|
620
|
+
type: 'tool-result',
|
|
621
|
+
toolCallId,
|
|
622
|
+
toolName: toolNameMapping.toCustomToolName('tool_search'),
|
|
623
|
+
result: {
|
|
624
|
+
tools: part.tools,
|
|
625
|
+
} satisfies InferSchema<typeof toolSearchOutputSchema>,
|
|
626
|
+
providerMetadata: {
|
|
627
|
+
[providerOptionsName]: {
|
|
628
|
+
itemId: part.id,
|
|
629
|
+
},
|
|
630
|
+
},
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
635
|
+
|
|
554
636
|
case 'local_shell_call': {
|
|
555
637
|
content.push({
|
|
556
638
|
type: 'tool-call',
|
|
@@ -621,7 +703,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
621
703
|
logprobs.push(contentPart.logprobs);
|
|
622
704
|
}
|
|
623
705
|
|
|
624
|
-
const providerMetadata:
|
|
706
|
+
const providerMetadata: SharedV4ProviderMetadata[string] = {
|
|
625
707
|
itemId: part.id,
|
|
626
708
|
...(part.phase != null && { phase: part.phase }),
|
|
627
709
|
...(contentPart.annotations.length > 0 && {
|
|
@@ -833,7 +915,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
833
915
|
type: 'tool-approval-request',
|
|
834
916
|
approvalId: approvalRequestId,
|
|
835
917
|
toolCallId: dummyToolCallId,
|
|
836
|
-
} satisfies
|
|
918
|
+
} satisfies LanguageModelV4ToolApprovalRequest);
|
|
837
919
|
break;
|
|
838
920
|
}
|
|
839
921
|
|
|
@@ -927,10 +1009,25 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
927
1009
|
|
|
928
1010
|
break;
|
|
929
1011
|
}
|
|
1012
|
+
|
|
1013
|
+
case 'compaction': {
|
|
1014
|
+
content.push({
|
|
1015
|
+
type: 'custom',
|
|
1016
|
+
kind: 'openai.compaction',
|
|
1017
|
+
providerMetadata: {
|
|
1018
|
+
[providerOptionsName]: {
|
|
1019
|
+
type: 'compaction',
|
|
1020
|
+
itemId: part.id,
|
|
1021
|
+
encryptedContent: part.encrypted_content,
|
|
1022
|
+
} satisfies ResponsesCompactionProviderMetadata,
|
|
1023
|
+
},
|
|
1024
|
+
});
|
|
1025
|
+
break;
|
|
1026
|
+
}
|
|
930
1027
|
}
|
|
931
1028
|
}
|
|
932
1029
|
|
|
933
|
-
const providerMetadata:
|
|
1030
|
+
const providerMetadata: SharedV4ProviderMetadata = {
|
|
934
1031
|
[providerOptionsName]: {
|
|
935
1032
|
responseId: response.id,
|
|
936
1033
|
...(logprobs.length > 0 ? { logprobs } : {}),
|
|
@@ -966,8 +1063,8 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
966
1063
|
}
|
|
967
1064
|
|
|
968
1065
|
async doStream(
|
|
969
|
-
options:
|
|
970
|
-
): Promise<
|
|
1066
|
+
options: LanguageModelV4CallOptions,
|
|
1067
|
+
): Promise<LanguageModelV4StreamResult> {
|
|
971
1068
|
const {
|
|
972
1069
|
args: body,
|
|
973
1070
|
warnings,
|
|
@@ -983,7 +1080,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
983
1080
|
path: '/responses',
|
|
984
1081
|
modelId: this.modelId,
|
|
985
1082
|
}),
|
|
986
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
1083
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
987
1084
|
body: {
|
|
988
1085
|
...body,
|
|
989
1086
|
stream: true,
|
|
@@ -1006,7 +1103,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
1006
1103
|
string
|
|
1007
1104
|
>();
|
|
1008
1105
|
|
|
1009
|
-
let finishReason:
|
|
1106
|
+
let finishReason: LanguageModelV4FinishReason = {
|
|
1010
1107
|
unified: 'other',
|
|
1011
1108
|
raw: undefined,
|
|
1012
1109
|
};
|
|
@@ -1026,6 +1123,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
1026
1123
|
hasDiff: boolean;
|
|
1027
1124
|
endEmitted: boolean;
|
|
1028
1125
|
};
|
|
1126
|
+
toolSearchExecution?: 'server' | 'client';
|
|
1029
1127
|
}
|
|
1030
1128
|
| undefined
|
|
1031
1129
|
> = {};
|
|
@@ -1054,12 +1152,13 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
1054
1152
|
> = {};
|
|
1055
1153
|
|
|
1056
1154
|
let serviceTier: string | undefined;
|
|
1155
|
+
const hostedToolSearchCallIds: string[] = [];
|
|
1057
1156
|
|
|
1058
1157
|
return {
|
|
1059
1158
|
stream: response.pipeThrough(
|
|
1060
1159
|
new TransformStream<
|
|
1061
1160
|
ParseResult<OpenAIResponsesChunk>,
|
|
1062
|
-
|
|
1161
|
+
LanguageModelV4StreamPart
|
|
1063
1162
|
>({
|
|
1064
1163
|
start(controller) {
|
|
1065
1164
|
controller.enqueue({ type: 'stream-start', warnings });
|
|
@@ -1188,6 +1287,28 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
1188
1287
|
input: '{}',
|
|
1189
1288
|
providerExecuted: true,
|
|
1190
1289
|
});
|
|
1290
|
+
} else if (value.item.type === 'tool_search_call') {
|
|
1291
|
+
const toolCallId = value.item.id;
|
|
1292
|
+
const toolName =
|
|
1293
|
+
toolNameMapping.toCustomToolName('tool_search');
|
|
1294
|
+
const isHosted = value.item.execution === 'server';
|
|
1295
|
+
|
|
1296
|
+
ongoingToolCalls[value.output_index] = {
|
|
1297
|
+
toolName,
|
|
1298
|
+
toolCallId,
|
|
1299
|
+
toolSearchExecution: value.item.execution ?? 'server',
|
|
1300
|
+
};
|
|
1301
|
+
|
|
1302
|
+
if (isHosted) {
|
|
1303
|
+
controller.enqueue({
|
|
1304
|
+
type: 'tool-input-start',
|
|
1305
|
+
id: toolCallId,
|
|
1306
|
+
toolName,
|
|
1307
|
+
providerExecuted: true,
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
} else if (value.item.type === 'tool_search_output') {
|
|
1311
|
+
// handled on output_item.done so we can pair it with the call
|
|
1191
1312
|
} else if (
|
|
1192
1313
|
value.item.type === 'mcp_call' ||
|
|
1193
1314
|
value.item.type === 'mcp_list_tools' ||
|
|
@@ -1418,6 +1539,67 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
1418
1539
|
result: value.item.result,
|
|
1419
1540
|
} satisfies InferSchema<typeof imageGenerationOutputSchema>,
|
|
1420
1541
|
});
|
|
1542
|
+
} else if (value.item.type === 'tool_search_call') {
|
|
1543
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
1544
|
+
const isHosted = value.item.execution === 'server';
|
|
1545
|
+
|
|
1546
|
+
if (toolCall != null) {
|
|
1547
|
+
const toolCallId = isHosted
|
|
1548
|
+
? toolCall.toolCallId
|
|
1549
|
+
: (value.item.call_id ?? value.item.id);
|
|
1550
|
+
|
|
1551
|
+
if (isHosted) {
|
|
1552
|
+
hostedToolSearchCallIds.push(toolCallId);
|
|
1553
|
+
} else {
|
|
1554
|
+
controller.enqueue({
|
|
1555
|
+
type: 'tool-input-start',
|
|
1556
|
+
id: toolCallId,
|
|
1557
|
+
toolName: toolCall.toolName,
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
controller.enqueue({
|
|
1562
|
+
type: 'tool-input-end',
|
|
1563
|
+
id: toolCallId,
|
|
1564
|
+
});
|
|
1565
|
+
|
|
1566
|
+
controller.enqueue({
|
|
1567
|
+
type: 'tool-call',
|
|
1568
|
+
toolCallId,
|
|
1569
|
+
toolName: toolCall.toolName,
|
|
1570
|
+
input: JSON.stringify({
|
|
1571
|
+
arguments: value.item.arguments,
|
|
1572
|
+
call_id: isHosted ? null : toolCallId,
|
|
1573
|
+
} satisfies InferSchema<typeof toolSearchInputSchema>),
|
|
1574
|
+
...(isHosted ? { providerExecuted: true } : {}),
|
|
1575
|
+
providerMetadata: {
|
|
1576
|
+
[providerOptionsName]: {
|
|
1577
|
+
itemId: value.item.id,
|
|
1578
|
+
},
|
|
1579
|
+
},
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
ongoingToolCalls[value.output_index] = undefined;
|
|
1584
|
+
} else if (value.item.type === 'tool_search_output') {
|
|
1585
|
+
const toolCallId =
|
|
1586
|
+
value.item.call_id ??
|
|
1587
|
+
hostedToolSearchCallIds.shift() ??
|
|
1588
|
+
value.item.id;
|
|
1589
|
+
|
|
1590
|
+
controller.enqueue({
|
|
1591
|
+
type: 'tool-result',
|
|
1592
|
+
toolCallId,
|
|
1593
|
+
toolName: toolNameMapping.toCustomToolName('tool_search'),
|
|
1594
|
+
result: {
|
|
1595
|
+
tools: value.item.tools,
|
|
1596
|
+
} satisfies InferSchema<typeof toolSearchOutputSchema>,
|
|
1597
|
+
providerMetadata: {
|
|
1598
|
+
[providerOptionsName]: {
|
|
1599
|
+
itemId: value.item.id,
|
|
1600
|
+
},
|
|
1601
|
+
},
|
|
1602
|
+
});
|
|
1421
1603
|
} else if (value.item.type === 'mcp_call') {
|
|
1422
1604
|
ongoingToolCalls[value.output_index] = undefined;
|
|
1423
1605
|
|
|
@@ -1647,6 +1829,18 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
1647
1829
|
}
|
|
1648
1830
|
|
|
1649
1831
|
delete activeReasoning[value.item.id];
|
|
1832
|
+
} else if (value.item.type === 'compaction') {
|
|
1833
|
+
controller.enqueue({
|
|
1834
|
+
type: 'custom',
|
|
1835
|
+
kind: 'openai.compaction',
|
|
1836
|
+
providerMetadata: {
|
|
1837
|
+
[providerOptionsName]: {
|
|
1838
|
+
type: 'compaction',
|
|
1839
|
+
itemId: value.item.id,
|
|
1840
|
+
encryptedContent: value.item.encrypted_content,
|
|
1841
|
+
} satisfies ResponsesCompactionProviderMetadata,
|
|
1842
|
+
},
|
|
1843
|
+
});
|
|
1650
1844
|
}
|
|
1651
1845
|
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
1652
1846
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
@@ -1867,6 +2061,19 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
1867
2061
|
if (typeof value.response.service_tier === 'string') {
|
|
1868
2062
|
serviceTier = value.response.service_tier;
|
|
1869
2063
|
}
|
|
2064
|
+
} else if (isResponseFailedChunk(value)) {
|
|
2065
|
+
const incompleteReason =
|
|
2066
|
+
value.response.incomplete_details?.reason;
|
|
2067
|
+
finishReason = {
|
|
2068
|
+
unified: incompleteReason
|
|
2069
|
+
? mapOpenAIResponseFinishReason({
|
|
2070
|
+
finishReason: incompleteReason,
|
|
2071
|
+
hasFunctionCall,
|
|
2072
|
+
})
|
|
2073
|
+
: 'error',
|
|
2074
|
+
raw: incompleteReason ?? 'error',
|
|
2075
|
+
};
|
|
2076
|
+
usage = value.response.usage ?? undefined;
|
|
1870
2077
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
1871
2078
|
ongoingAnnotations.push(value.annotation);
|
|
1872
2079
|
if (value.annotation.type === 'url_citation') {
|
|
@@ -1941,7 +2148,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
1941
2148
|
},
|
|
1942
2149
|
|
|
1943
2150
|
flush(controller) {
|
|
1944
|
-
const providerMetadata:
|
|
2151
|
+
const providerMetadata: SharedV4ProviderMetadata = {
|
|
1945
2152
|
[providerOptionsName]: {
|
|
1946
2153
|
responseId: responseId,
|
|
1947
2154
|
...(logprobs.length > 0 ? { logprobs } : {}),
|
|
@@ -1986,6 +2193,12 @@ function isResponseFinishedChunk(
|
|
|
1986
2193
|
);
|
|
1987
2194
|
}
|
|
1988
2195
|
|
|
2196
|
+
function isResponseFailedChunk(
|
|
2197
|
+
chunk: OpenAIResponsesChunk,
|
|
2198
|
+
): chunk is OpenAIResponsesChunk & { type: 'response.failed' } {
|
|
2199
|
+
return chunk.type === 'response.failed';
|
|
2200
|
+
}
|
|
2201
|
+
|
|
1989
2202
|
function isResponseCreatedChunk(
|
|
1990
2203
|
chunk: OpenAIResponsesChunk,
|
|
1991
2204
|
): chunk is OpenAIResponsesChunk & { type: 'response.created' } {
|
|
@@ -37,11 +37,16 @@ export const openaiResponsesReasoningModelIds = [
|
|
|
37
37
|
'gpt-5.2-chat-latest',
|
|
38
38
|
'gpt-5.2-pro',
|
|
39
39
|
'gpt-5.2-codex',
|
|
40
|
+
'gpt-5.3-chat-latest',
|
|
41
|
+
'gpt-5.3-codex',
|
|
40
42
|
'gpt-5.4',
|
|
41
43
|
'gpt-5.4-2026-03-05',
|
|
44
|
+
'gpt-5.4-mini',
|
|
45
|
+
'gpt-5.4-mini-2026-03-17',
|
|
46
|
+
'gpt-5.4-nano',
|
|
47
|
+
'gpt-5.4-nano-2026-03-17',
|
|
42
48
|
'gpt-5.4-pro',
|
|
43
49
|
'gpt-5.4-pro-2026-03-05',
|
|
44
|
-
'gpt-5.3-codex',
|
|
45
50
|
] as const;
|
|
46
51
|
|
|
47
52
|
export const openaiResponsesModelIds = [
|
|
@@ -98,11 +103,16 @@ export type OpenAIResponsesModelId =
|
|
|
98
103
|
| 'gpt-5.2-pro'
|
|
99
104
|
| 'gpt-5.2-pro-2025-12-11'
|
|
100
105
|
| 'gpt-5.2-codex'
|
|
106
|
+
| 'gpt-5.3-chat-latest'
|
|
107
|
+
| 'gpt-5.3-codex'
|
|
101
108
|
| 'gpt-5.4'
|
|
102
109
|
| 'gpt-5.4-2026-03-05'
|
|
110
|
+
| 'gpt-5.4-mini'
|
|
111
|
+
| 'gpt-5.4-mini-2026-03-17'
|
|
112
|
+
| 'gpt-5.4-nano'
|
|
113
|
+
| 'gpt-5.4-nano-2026-03-17'
|
|
103
114
|
| 'gpt-5.4-pro'
|
|
104
115
|
| 'gpt-5.4-pro-2026-03-05'
|
|
105
|
-
| 'gpt-5.3-codex'
|
|
106
116
|
| 'gpt-5-2025-08-07'
|
|
107
117
|
| 'gpt-5-chat-latest'
|
|
108
118
|
| 'gpt-5-codex'
|
|
@@ -298,6 +308,18 @@ export const openaiLanguageModelResponsesOptionsSchema = lazySchema(() =>
|
|
|
298
308
|
* and defaults `systemMessageMode` to `developer` unless overridden.
|
|
299
309
|
*/
|
|
300
310
|
forceReasoning: z.boolean().optional(),
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Enable server-side context management (compaction).
|
|
314
|
+
*/
|
|
315
|
+
contextManagement: z
|
|
316
|
+
.array(
|
|
317
|
+
z.object({
|
|
318
|
+
type: z.literal('compaction'),
|
|
319
|
+
compactThreshold: z.number(),
|
|
320
|
+
}),
|
|
321
|
+
)
|
|
322
|
+
.nullish(),
|
|
301
323
|
}),
|
|
302
324
|
),
|
|
303
325
|
);
|