@ai-sdk/openai 3.0.109 → 3.0.110
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 +7 -0
- package/dist/index.d.mts +38 -19
- package/dist/index.d.ts +38 -19
- package/dist/index.js +74 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -22
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +20 -7
- package/dist/internal/index.d.ts +20 -7
- package/dist/internal/index.js +71 -20
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +71 -20
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-openai.mdx +73 -1
- package/package.json +1 -1
- package/src/image/openai-image-model-options.ts +3 -2
- package/src/index.ts +2 -0
- package/src/openai-language-model-capabilities.ts +2 -0
- package/src/openai-tools.ts +2 -1
- package/src/responses/convert-to-openai-responses-input.ts +14 -0
- package/src/responses/openai-responses-api.ts +11 -1
- package/src/responses/openai-responses-language-model.ts +22 -4
- package/src/responses/openai-responses-prepare-tools.ts +48 -1
- package/src/responses/openai-responses-provider-metadata.ts +10 -0
- package/src/tool/custom.ts +7 -0
- package/src/tool/image-generation.ts +6 -3
package/docs/03-openai.mdx
CHANGED
|
@@ -548,6 +548,55 @@ metadata on tool-call parts. The SDK uses `providerMetadata.openai.namespace` or
|
|
|
548
548
|
`providerOptions.openai.namespace` to round-trip the namespace back to OpenAI on
|
|
549
549
|
subsequent requests.
|
|
550
550
|
|
|
551
|
+
#### Async Tool Calling
|
|
552
|
+
|
|
553
|
+
GPT-6 Astra and later Responses models support
|
|
554
|
+
[async tool calling](https://developers.openai.com/api/docs/guides/async-tool-calling).
|
|
555
|
+
An async tool lets the model continue generating independent output after issuing
|
|
556
|
+
the call instead of waiting for its result. Your application still executes the
|
|
557
|
+
tool and sends its result in a later request using the original tool call ID.
|
|
558
|
+
|
|
559
|
+
Enable async calling on a function tool with `providerOptions.openai.async`:
|
|
560
|
+
|
|
561
|
+
```ts
|
|
562
|
+
import { openai, type OpenAIToolOptions } from '@ai-sdk/openai';
|
|
563
|
+
import { generateText, tool } from 'ai';
|
|
564
|
+
import { z } from 'zod';
|
|
565
|
+
|
|
566
|
+
const result = await generateText({
|
|
567
|
+
model: openai.responses('gpt-6-astra'),
|
|
568
|
+
tools: {
|
|
569
|
+
getWeather: tool({
|
|
570
|
+
description: 'Get the weather for a city.',
|
|
571
|
+
inputSchema: z.object({ city: z.string() }),
|
|
572
|
+
outputSchema: z.object({
|
|
573
|
+
city: z.string(),
|
|
574
|
+
temperatureC: z.number(),
|
|
575
|
+
}),
|
|
576
|
+
providerOptions: {
|
|
577
|
+
openai: { async: true } satisfies OpenAIToolOptions,
|
|
578
|
+
},
|
|
579
|
+
}),
|
|
580
|
+
},
|
|
581
|
+
prompt:
|
|
582
|
+
'Start the weather lookup for Paris, then list three general packing essentials without waiting.',
|
|
583
|
+
});
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
The generated tool call exposes the provider marker as
|
|
587
|
+
`providerMetadata.openai.async`. Use `providerMetadata.openai.responseId` as the
|
|
588
|
+
next request's `previousResponseId`, and submit the result in a tool message with
|
|
589
|
+
the original `toolCallId`.
|
|
590
|
+
|
|
591
|
+
With `streamText`, OpenAI can continue streaming text after the completed
|
|
592
|
+
`tool-call` part. Use the tool's `onInputAvailable` callback to start work as soon
|
|
593
|
+
as that part arrives. If `execute` returns the same already-running promise, tool
|
|
594
|
+
execution overlaps the rest of the model stream. Omit `execute` when the job
|
|
595
|
+
should outlive the current generation and submit its result in a later request.
|
|
596
|
+
|
|
597
|
+
Async calling applies to directly called function and custom tools. It does not
|
|
598
|
+
apply to hosted tools.
|
|
599
|
+
|
|
551
600
|
#### Web Search Tool
|
|
552
601
|
|
|
553
602
|
The OpenAI responses API supports web search through the `openai.tools.webSearch` tool.
|
|
@@ -736,6 +785,16 @@ for await (const part of result.fullStream) {
|
|
|
736
785
|
setting `store: false`.
|
|
737
786
|
</Note>
|
|
738
787
|
|
|
788
|
+
To use `xhigh` or `max` quality, select `gpt-image-2.5-flare` or
|
|
789
|
+
`gpt-image-2.5-sunburst` as the image generation tool's model:
|
|
790
|
+
|
|
791
|
+
```ts
|
|
792
|
+
openai.tools.imageGeneration({
|
|
793
|
+
model: 'gpt-image-2.5-flare',
|
|
794
|
+
quality: 'xhigh',
|
|
795
|
+
});
|
|
796
|
+
```
|
|
797
|
+
|
|
739
798
|
For complete details on model availability, image quality controls, supported sizes, and tool-specific parameters,
|
|
740
799
|
refer to the OpenAI documentation:
|
|
741
800
|
|
|
@@ -2665,6 +2724,19 @@ const { image, providerMetadata } = await generateImage({
|
|
|
2665
2724
|
});
|
|
2666
2725
|
```
|
|
2667
2726
|
|
|
2727
|
+
The `gpt-image-2.5-flare` and `gpt-image-2.5-sunburst` models also support
|
|
2728
|
+
`quality: 'xhigh'` and `quality: 'max'` for both image generation and editing:
|
|
2729
|
+
|
|
2730
|
+
```ts
|
|
2731
|
+
const { image } = await generateImage({
|
|
2732
|
+
model: openai.image('gpt-image-2.5-sunburst'),
|
|
2733
|
+
prompt: 'A salamander at sunrise in a forest pond in the Seychelles.',
|
|
2734
|
+
providerOptions: {
|
|
2735
|
+
openai: { quality: 'max' } satisfies OpenAIImageModelGenerationOptions,
|
|
2736
|
+
},
|
|
2737
|
+
});
|
|
2738
|
+
```
|
|
2739
|
+
|
|
2668
2740
|
For more on `generateImage()` see [Image Generation](/docs/ai-sdk-core/image-generation).
|
|
2669
2741
|
|
|
2670
2742
|
OpenAI's image models return additional metadata in the response that can be
|
|
@@ -2678,7 +2750,7 @@ is available:
|
|
|
2678
2750
|
- `revisedPrompt` _string_ - The revised prompt that was actually used to generate the image (OpenAI may modify your prompt for safety or clarity)
|
|
2679
2751
|
- `created` _number_ - The Unix timestamp (in seconds) of when the image was created
|
|
2680
2752
|
- `size` _string_ - The size of the generated image. One of `1024x1024`, `1024x1536`, or `1536x1024`
|
|
2681
|
-
- `quality` _string_ - The quality of the generated image. One of `low`, `medium`, or `
|
|
2753
|
+
- `quality` _string_ - The quality of the generated image. One of `low`, `medium`, `high`, `xhigh`, or `max`
|
|
2682
2754
|
- `background` _string_ - The background parameter used for the image generation. Either `transparent` or `opaque`
|
|
2683
2755
|
- `outputFormat` _string_ - The output format of the generated image. One of `png`, `webp`, or `jpeg`
|
|
2684
2756
|
|
package/package.json
CHANGED
|
@@ -45,10 +45,11 @@ const baseImageModelOptionsObject = z.object({
|
|
|
45
45
|
/**
|
|
46
46
|
* Quality of the generated image(s).
|
|
47
47
|
*
|
|
48
|
-
* Valid values: `standard`, `hd`, `low`, `medium`, `high`, `auto`.
|
|
48
|
+
* Valid values: `standard`, `hd`, `low`, `medium`, `high`, `xhigh`, `max`, `auto`.
|
|
49
|
+
* `xhigh` and `max` are supported by GPT Image 2.5 models.
|
|
49
50
|
*/
|
|
50
51
|
quality: z
|
|
51
|
-
.enum(['standard', 'hd', 'low', 'medium', 'high', 'auto'])
|
|
52
|
+
.enum(['standard', 'hd', 'low', 'medium', 'high', 'xhigh', 'max', 'auto'])
|
|
52
53
|
.optional(),
|
|
53
54
|
|
|
54
55
|
/**
|
package/src/index.ts
CHANGED
|
@@ -19,9 +19,11 @@ export type { OpenAILanguageModelCompletionOptions } from './completion/openai-c
|
|
|
19
19
|
export type { OpenAIEmbeddingModelOptions } from './embedding/openai-embedding-options';
|
|
20
20
|
export type { OpenAISpeechModelOptions } from './speech/openai-speech-options';
|
|
21
21
|
export type { OpenAITranscriptionModelOptions } from './transcription/openai-transcription-options';
|
|
22
|
+
export type { OpenAIToolOptions } from './responses/openai-responses-prepare-tools';
|
|
22
23
|
export type {
|
|
23
24
|
OpenaiResponsesProviderMetadata,
|
|
24
25
|
OpenaiResponsesReasoningProviderMetadata,
|
|
26
|
+
OpenaiResponsesToolCallProviderMetadata,
|
|
25
27
|
OpenaiResponsesTextProviderMetadata,
|
|
26
28
|
OpenaiResponsesSourceDocumentProviderMetadata,
|
|
27
29
|
} from './responses/openai-responses-provider-metadata';
|
|
@@ -4,6 +4,7 @@ export type OpenAILanguageModelCapabilities = {
|
|
|
4
4
|
supportsFlexProcessing: boolean;
|
|
5
5
|
supportsPriorityProcessing: boolean;
|
|
6
6
|
supportsConfigurationUpdate: boolean;
|
|
7
|
+
supportsAsyncToolCalling: boolean;
|
|
7
8
|
supportedReasoningEfforts: readonly string[] | undefined;
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -55,6 +56,7 @@ export function getOpenAILanguageModelCapabilities(
|
|
|
55
56
|
supportsFlexProcessing,
|
|
56
57
|
supportsPriorityProcessing,
|
|
57
58
|
supportsConfigurationUpdate: isGpt6OrLaterModel,
|
|
59
|
+
supportsAsyncToolCalling: isGpt6OrLaterModel,
|
|
58
60
|
supportedReasoningEfforts: isGpt6OrLaterModel
|
|
59
61
|
? ['low', 'medium', 'high', 'xhigh', 'max']
|
|
60
62
|
: undefined,
|
package/src/openai-tools.ts
CHANGED
|
@@ -27,6 +27,7 @@ export const openaiTools = {
|
|
|
27
27
|
*
|
|
28
28
|
* @param name - The name of the custom tool.
|
|
29
29
|
* @param description - An optional description of the tool.
|
|
30
|
+
* @param async - Whether the model can continue without waiting for the tool result.
|
|
30
31
|
* @param format - The output format constraint (grammar type, syntax, and definition).
|
|
31
32
|
*/
|
|
32
33
|
customTool,
|
|
@@ -65,7 +66,7 @@ export const openaiTools = {
|
|
|
65
66
|
* @param outputCompression - Compression level for the output image (0-100).
|
|
66
67
|
* @param outputFormat - The output format of the generated image. One of 'png', 'jpeg', or 'webp'.
|
|
67
68
|
* @param partialImages - Number of partial images to generate in streaming mode (0-3).
|
|
68
|
-
* @param quality - The quality of the generated image. One of 'auto', 'low', 'medium', or '
|
|
69
|
+
* @param quality - The quality of the generated image. One of 'auto', 'low', 'medium', 'high', 'xhigh', or 'max'. 'xhigh' and 'max' require a GPT Image 2.5 model.
|
|
69
70
|
* @param size - The size of the generated image. One of 'auto', '1024x1024', '1024x1536', or '1536x1024'.
|
|
70
71
|
*/
|
|
71
72
|
imageGeneration,
|
|
@@ -589,6 +589,18 @@ export async function convertToOpenAIResponsesInput({
|
|
|
589
589
|
| string
|
|
590
590
|
| undefined;
|
|
591
591
|
|
|
592
|
+
const isAsync = (part.providerOptions?.[providerOptionsName]
|
|
593
|
+
?.async ??
|
|
594
|
+
(
|
|
595
|
+
part as {
|
|
596
|
+
providerMetadata?: {
|
|
597
|
+
[providerOptionsName]?: { async?: boolean };
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
).providerMetadata?.[providerOptionsName]?.async) as
|
|
601
|
+
| boolean
|
|
602
|
+
| undefined;
|
|
603
|
+
|
|
592
604
|
if (hasConversation && id != null) {
|
|
593
605
|
break;
|
|
594
606
|
}
|
|
@@ -739,6 +751,7 @@ export async function convertToOpenAIResponsesInput({
|
|
|
739
751
|
typeof part.input === 'string'
|
|
740
752
|
? part.input
|
|
741
753
|
: JSON.stringify(part.input),
|
|
754
|
+
...(isAsync != null && { async: isAsync }),
|
|
742
755
|
id,
|
|
743
756
|
});
|
|
744
757
|
break;
|
|
@@ -749,6 +762,7 @@ export async function convertToOpenAIResponsesInput({
|
|
|
749
762
|
call_id: part.toolCallId,
|
|
750
763
|
name: resolvedToolName,
|
|
751
764
|
arguments: serializeToolCallArguments(part.input),
|
|
765
|
+
...(isAsync != null && { async: isAsync }),
|
|
752
766
|
...(namespace != null && { namespace }),
|
|
753
767
|
});
|
|
754
768
|
break;
|
|
@@ -180,6 +180,7 @@ export type OpenAIResponsesFunctionCall = {
|
|
|
180
180
|
call_id: string;
|
|
181
181
|
name: string;
|
|
182
182
|
arguments: string;
|
|
183
|
+
async?: boolean;
|
|
183
184
|
id?: string;
|
|
184
185
|
namespace?: string;
|
|
185
186
|
};
|
|
@@ -220,6 +221,7 @@ export type OpenAIResponsesCustomToolCall = {
|
|
|
220
221
|
call_id: string;
|
|
221
222
|
name: string;
|
|
222
223
|
input: string;
|
|
224
|
+
async?: boolean;
|
|
223
225
|
};
|
|
224
226
|
|
|
225
227
|
export type OpenAIResponsesCustomToolCallOutput = {
|
|
@@ -373,6 +375,7 @@ export type OpenAIResponsesFunctionTool = {
|
|
|
373
375
|
name: string;
|
|
374
376
|
description: string | undefined;
|
|
375
377
|
parameters: JSONSchema7;
|
|
378
|
+
async?: boolean;
|
|
376
379
|
strict?: boolean;
|
|
377
380
|
defer_loading?: boolean;
|
|
378
381
|
};
|
|
@@ -467,7 +470,7 @@ export type OpenAIResponsesTool =
|
|
|
467
470
|
output_compression: number | undefined;
|
|
468
471
|
output_format: 'png' | 'jpeg' | 'webp' | undefined;
|
|
469
472
|
partial_images: number | undefined;
|
|
470
|
-
quality: 'auto' | 'low' | 'medium' | 'high' | undefined;
|
|
473
|
+
quality: 'auto' | 'low' | 'medium' | 'high' | 'xhigh' | 'max' | undefined;
|
|
471
474
|
size: 'auto' | '1024x1024' | '1024x1536' | '1536x1024' | undefined;
|
|
472
475
|
}
|
|
473
476
|
|
|
@@ -501,6 +504,7 @@ export type OpenAIResponsesTool =
|
|
|
501
504
|
type: 'custom';
|
|
502
505
|
name: string;
|
|
503
506
|
description?: string;
|
|
507
|
+
async?: boolean;
|
|
504
508
|
format?:
|
|
505
509
|
| {
|
|
506
510
|
type: 'grammar';
|
|
@@ -772,6 +776,7 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
|
|
|
772
776
|
call_id: z.string(),
|
|
773
777
|
name: z.string(),
|
|
774
778
|
arguments: z.string(),
|
|
779
|
+
async: z.boolean().nullish(),
|
|
775
780
|
namespace: z.string().nullish(),
|
|
776
781
|
}),
|
|
777
782
|
z.object({
|
|
@@ -850,6 +855,7 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
|
|
|
850
855
|
call_id: z.string(),
|
|
851
856
|
name: z.string(),
|
|
852
857
|
input: z.string(),
|
|
858
|
+
async: z.boolean().nullish(),
|
|
853
859
|
}),
|
|
854
860
|
z.object({
|
|
855
861
|
type: z.literal('shell_call'),
|
|
@@ -917,6 +923,7 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
|
|
|
917
923
|
call_id: z.string(),
|
|
918
924
|
name: z.string(),
|
|
919
925
|
arguments: z.string(),
|
|
926
|
+
async: z.boolean().nullish(),
|
|
920
927
|
status: z.literal('completed'),
|
|
921
928
|
namespace: z.string().nullish(),
|
|
922
929
|
}),
|
|
@@ -926,6 +933,7 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
|
|
|
926
933
|
call_id: z.string(),
|
|
927
934
|
name: z.string(),
|
|
928
935
|
input: z.string(),
|
|
936
|
+
async: z.boolean().nullish(),
|
|
929
937
|
status: z.literal('completed'),
|
|
930
938
|
}),
|
|
931
939
|
z.object({
|
|
@@ -1410,6 +1418,7 @@ export const openaiResponsesResponseSchema = lazySchema(() =>
|
|
|
1410
1418
|
name: z.string(),
|
|
1411
1419
|
arguments: z.string(),
|
|
1412
1420
|
id: z.string(),
|
|
1421
|
+
async: z.boolean().nullish(),
|
|
1413
1422
|
namespace: z.string().nullish(),
|
|
1414
1423
|
}),
|
|
1415
1424
|
z.object({
|
|
@@ -1418,6 +1427,7 @@ export const openaiResponsesResponseSchema = lazySchema(() =>
|
|
|
1418
1427
|
name: z.string(),
|
|
1419
1428
|
input: z.string(),
|
|
1420
1429
|
id: z.string(),
|
|
1430
|
+
async: z.boolean().nullish(),
|
|
1421
1431
|
}),
|
|
1422
1432
|
z.object({
|
|
1423
1433
|
type: z.literal('computer_call'),
|
|
@@ -80,6 +80,7 @@ import type {
|
|
|
80
80
|
ResponsesReasoningProviderMetadata,
|
|
81
81
|
ResponsesSourceDocumentProviderMetadata,
|
|
82
82
|
ResponsesTextProviderMetadata,
|
|
83
|
+
ResponsesToolCallProviderMetadata,
|
|
83
84
|
} from './openai-responses-provider-metadata';
|
|
84
85
|
|
|
85
86
|
/**
|
|
@@ -242,6 +243,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
242
243
|
allowedTools: openaiOptions?.allowedTools ?? undefined,
|
|
243
244
|
toolNameMapping,
|
|
244
245
|
customProviderToolNames,
|
|
246
|
+
supportsAsyncToolCalling: modelCapabilities.supportsAsyncToolCalling,
|
|
245
247
|
});
|
|
246
248
|
|
|
247
249
|
const { input, warnings: inputWarnings } =
|
|
@@ -910,8 +912,9 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
910
912
|
providerMetadata: {
|
|
911
913
|
[providerOptionsName]: {
|
|
912
914
|
itemId: part.id,
|
|
915
|
+
...(part.async != null && { async: part.async }),
|
|
913
916
|
...(part.namespace != null && { namespace: part.namespace }),
|
|
914
|
-
},
|
|
917
|
+
} satisfies ResponsesToolCallProviderMetadata,
|
|
915
918
|
},
|
|
916
919
|
});
|
|
917
920
|
break;
|
|
@@ -929,7 +932,8 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
929
932
|
providerMetadata: {
|
|
930
933
|
[providerOptionsName]: {
|
|
931
934
|
itemId: part.id,
|
|
932
|
-
|
|
935
|
+
...(part.async != null && { async: part.async }),
|
|
936
|
+
} satisfies ResponsesToolCallProviderMetadata,
|
|
933
937
|
},
|
|
934
938
|
});
|
|
935
939
|
break;
|
|
@@ -1242,6 +1246,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
1242
1246
|
toolSearchExecution?: 'server' | 'client';
|
|
1243
1247
|
suppressInputStreaming?: boolean;
|
|
1244
1248
|
bufferedInputDeltas?: string[];
|
|
1249
|
+
async?: boolean | null;
|
|
1245
1250
|
}
|
|
1246
1251
|
| undefined
|
|
1247
1252
|
> = {};
|
|
@@ -1321,6 +1326,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
1321
1326
|
toolCallId: value.item.call_id,
|
|
1322
1327
|
suppressInputStreaming,
|
|
1323
1328
|
bufferedInputDeltas: suppressInputStreaming ? [] : undefined,
|
|
1329
|
+
async: value.item.async,
|
|
1324
1330
|
};
|
|
1325
1331
|
|
|
1326
1332
|
if (!suppressInputStreaming) {
|
|
@@ -1337,6 +1343,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
1337
1343
|
ongoingToolCalls[value.output_index] = {
|
|
1338
1344
|
toolName,
|
|
1339
1345
|
toolCallId: value.item.call_id,
|
|
1346
|
+
async: value.item.async,
|
|
1340
1347
|
};
|
|
1341
1348
|
|
|
1342
1349
|
controller.enqueue({
|
|
@@ -1620,10 +1627,15 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
1620
1627
|
providerMetadata: {
|
|
1621
1628
|
[providerOptionsName]: {
|
|
1622
1629
|
itemId: item.id,
|
|
1630
|
+
...(item.async != null
|
|
1631
|
+
? { async: item.async }
|
|
1632
|
+
: ongoingToolCall?.async != null
|
|
1633
|
+
? { async: ongoingToolCall.async }
|
|
1634
|
+
: {}),
|
|
1623
1635
|
...(item.namespace != null && {
|
|
1624
1636
|
namespace: item.namespace,
|
|
1625
1637
|
}),
|
|
1626
|
-
},
|
|
1638
|
+
} satisfies ResponsesToolCallProviderMetadata,
|
|
1627
1639
|
},
|
|
1628
1640
|
});
|
|
1629
1641
|
};
|
|
@@ -1667,6 +1679,7 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
1667
1679
|
}
|
|
1668
1680
|
});
|
|
1669
1681
|
} else if (value.item.type === 'custom_tool_call') {
|
|
1682
|
+
const ongoingToolCall = ongoingToolCalls[value.output_index];
|
|
1670
1683
|
ongoingToolCalls[value.output_index] = undefined;
|
|
1671
1684
|
hasFunctionCall = true;
|
|
1672
1685
|
const toolName = toolNameMapping.toCustomToolName(
|
|
@@ -1686,7 +1699,12 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV3 {
|
|
|
1686
1699
|
providerMetadata: {
|
|
1687
1700
|
[providerOptionsName]: {
|
|
1688
1701
|
itemId: value.item.id,
|
|
1689
|
-
|
|
1702
|
+
...(value.item.async != null
|
|
1703
|
+
? { async: value.item.async }
|
|
1704
|
+
: ongoingToolCall?.async != null
|
|
1705
|
+
? { async: ongoingToolCall.async }
|
|
1706
|
+
: {}),
|
|
1707
|
+
} satisfies ResponsesToolCallProviderMetadata,
|
|
1690
1708
|
},
|
|
1691
1709
|
});
|
|
1692
1710
|
} else if (value.item.type === 'web_search_call') {
|
|
@@ -24,7 +24,12 @@ type AllowedToolResolution =
|
|
|
24
24
|
| { supported: true; entry: OpenAIResponsesAllowedTool }
|
|
25
25
|
| { supported: false; reason: string };
|
|
26
26
|
|
|
27
|
-
type OpenAIToolOptions = {
|
|
27
|
+
export type OpenAIToolOptions = {
|
|
28
|
+
/**
|
|
29
|
+
* Whether the model can continue generating after calling this tool without
|
|
30
|
+
* waiting for its result.
|
|
31
|
+
*/
|
|
32
|
+
async?: boolean;
|
|
28
33
|
deferLoading?: boolean;
|
|
29
34
|
namespace?: {
|
|
30
35
|
name: string;
|
|
@@ -38,6 +43,7 @@ export async function prepareResponsesTools({
|
|
|
38
43
|
allowedTools,
|
|
39
44
|
toolNameMapping,
|
|
40
45
|
customProviderToolNames,
|
|
46
|
+
supportsAsyncToolCalling = true,
|
|
41
47
|
}: {
|
|
42
48
|
tools: LanguageModelV3CallOptions['tools'];
|
|
43
49
|
toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
|
|
@@ -47,6 +53,7 @@ export async function prepareResponsesTools({
|
|
|
47
53
|
};
|
|
48
54
|
toolNameMapping?: ToolNameMapping;
|
|
49
55
|
customProviderToolNames?: Set<string>;
|
|
56
|
+
supportsAsyncToolCalling?: boolean;
|
|
50
57
|
}): Promise<{
|
|
51
58
|
tools?: Array<OpenAIResponsesTool>;
|
|
52
59
|
toolChoice?:
|
|
@@ -124,6 +131,12 @@ export async function prepareResponsesTools({
|
|
|
124
131
|
const openaiFunctionTool = prepareFunctionTool({
|
|
125
132
|
tool,
|
|
126
133
|
options: openaiOptions,
|
|
134
|
+
async: resolveAsyncToolOption({
|
|
135
|
+
value: openaiOptions?.async,
|
|
136
|
+
supportsAsyncToolCalling,
|
|
137
|
+
toolName: tool.name,
|
|
138
|
+
toolWarnings,
|
|
139
|
+
}),
|
|
127
140
|
});
|
|
128
141
|
const namespace = openaiOptions?.namespace;
|
|
129
142
|
|
|
@@ -355,6 +368,14 @@ export async function prepareResponsesTools({
|
|
|
355
368
|
type: 'custom',
|
|
356
369
|
name: args.name,
|
|
357
370
|
description: args.description,
|
|
371
|
+
...(resolveAsyncToolOption({
|
|
372
|
+
value: args.async,
|
|
373
|
+
supportsAsyncToolCalling,
|
|
374
|
+
toolName: args.name,
|
|
375
|
+
toolWarnings,
|
|
376
|
+
}) != null
|
|
377
|
+
? { async: args.async }
|
|
378
|
+
: {}),
|
|
358
379
|
format: args.format,
|
|
359
380
|
});
|
|
360
381
|
resolvedCustomProviderToolNames.add(args.name);
|
|
@@ -573,9 +594,11 @@ function toAllowedToolResolution(
|
|
|
573
594
|
function prepareFunctionTool({
|
|
574
595
|
tool,
|
|
575
596
|
options,
|
|
597
|
+
async,
|
|
576
598
|
}: {
|
|
577
599
|
tool: LanguageModelV3FunctionTool;
|
|
578
600
|
options: OpenAIToolOptions | undefined;
|
|
601
|
+
async: boolean | undefined;
|
|
579
602
|
}): OpenAIResponsesFunctionTool {
|
|
580
603
|
const deferLoading = options?.deferLoading;
|
|
581
604
|
|
|
@@ -584,11 +607,35 @@ function prepareFunctionTool({
|
|
|
584
607
|
name: tool.name,
|
|
585
608
|
description: tool.description,
|
|
586
609
|
parameters: tool.inputSchema,
|
|
610
|
+
...(async != null ? { async } : {}),
|
|
587
611
|
...(tool.strict != null ? { strict: tool.strict } : {}),
|
|
588
612
|
...(deferLoading != null ? { defer_loading: deferLoading } : {}),
|
|
589
613
|
};
|
|
590
614
|
}
|
|
591
615
|
|
|
616
|
+
function resolveAsyncToolOption({
|
|
617
|
+
value,
|
|
618
|
+
supportsAsyncToolCalling,
|
|
619
|
+
toolName,
|
|
620
|
+
toolWarnings,
|
|
621
|
+
}: {
|
|
622
|
+
value: boolean | undefined;
|
|
623
|
+
supportsAsyncToolCalling: boolean;
|
|
624
|
+
toolName: string;
|
|
625
|
+
toolWarnings: SharedV3Warning[];
|
|
626
|
+
}): boolean | undefined {
|
|
627
|
+
if (value !== true || supportsAsyncToolCalling) {
|
|
628
|
+
return value;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
toolWarnings.push({
|
|
632
|
+
type: 'unsupported',
|
|
633
|
+
feature: `async tool calling for "${toolName}"`,
|
|
634
|
+
details: 'Async tool calling is only supported by GPT-6 and later models.',
|
|
635
|
+
});
|
|
636
|
+
return undefined;
|
|
637
|
+
}
|
|
638
|
+
|
|
592
639
|
function mapShellEnvironment(environment: {
|
|
593
640
|
type?: string;
|
|
594
641
|
[key: string]: unknown;
|
|
@@ -31,6 +31,16 @@ export type OpenaiResponsesProviderMetadata = {
|
|
|
31
31
|
openai: ResponsesProviderMetadata;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
export type ResponsesToolCallProviderMetadata = {
|
|
35
|
+
itemId: string;
|
|
36
|
+
async?: boolean;
|
|
37
|
+
namespace?: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type OpenaiResponsesToolCallProviderMetadata = {
|
|
41
|
+
openai: ResponsesToolCallProviderMetadata;
|
|
42
|
+
};
|
|
43
|
+
|
|
34
44
|
export type ResponsesTextProviderMetadata = {
|
|
35
45
|
itemId: string;
|
|
36
46
|
phase?: 'commentary' | 'final_answer' | null;
|
package/src/tool/custom.ts
CHANGED
|
@@ -10,6 +10,7 @@ export const customArgsSchema = lazySchema(() =>
|
|
|
10
10
|
z.object({
|
|
11
11
|
name: z.string(),
|
|
12
12
|
description: z.string().optional(),
|
|
13
|
+
async: z.boolean().optional(),
|
|
13
14
|
format: z
|
|
14
15
|
.union([
|
|
15
16
|
z.object({
|
|
@@ -41,6 +42,12 @@ export const customToolFactory = createProviderToolFactory<
|
|
|
41
42
|
*/
|
|
42
43
|
description?: string;
|
|
43
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Whether the model can continue generating after calling this tool
|
|
47
|
+
* without waiting for its result.
|
|
48
|
+
*/
|
|
49
|
+
async?: boolean;
|
|
50
|
+
|
|
44
51
|
/**
|
|
45
52
|
* The output format specification for the tool.
|
|
46
53
|
* Omit for unconstrained text output.
|
|
@@ -22,7 +22,9 @@ export const imageGenerationArgsSchema = lazySchema(() =>
|
|
|
22
22
|
outputCompression: z.number().int().min(0).max(100).optional(),
|
|
23
23
|
outputFormat: z.enum(['png', 'jpeg', 'webp']).optional(),
|
|
24
24
|
partialImages: z.number().int().min(0).max(3).optional(),
|
|
25
|
-
quality: z
|
|
25
|
+
quality: z
|
|
26
|
+
.enum(['auto', 'low', 'medium', 'high', 'xhigh', 'max'])
|
|
27
|
+
.optional(),
|
|
26
28
|
size: z
|
|
27
29
|
.enum(['1024x1024', '1024x1536', '1536x1024', 'auto'])
|
|
28
30
|
.optional(),
|
|
@@ -92,9 +94,10 @@ type ImageGenerationArgs = {
|
|
|
92
94
|
|
|
93
95
|
/**
|
|
94
96
|
* The quality of the generated image.
|
|
95
|
-
* One of low, medium, high, or auto. Default: auto.
|
|
97
|
+
* One of low, medium, high, xhigh, max, or auto. Default: auto.
|
|
98
|
+
* xhigh and max are supported by GPT Image 2.5 models.
|
|
96
99
|
*/
|
|
97
|
-
quality?: 'auto' | 'low' | 'medium' | 'high';
|
|
100
|
+
quality?: 'auto' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
98
101
|
|
|
99
102
|
/**
|
|
100
103
|
* The size of the generated image.
|