@ai-sdk/openai 4.0.0-beta.38 → 4.0.0-beta.39
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.ts +24 -10
- package/dist/index.js +36 -36
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +6 -6
- package/dist/internal/index.js +35 -35
- package/dist/internal/index.js.map +1 -1
- package/package.json +4 -3
- package/src/chat/convert-to-openai-chat-messages.ts +1 -1
- package/src/chat/openai-chat-language-model.ts +7 -9
- package/src/image/openai-image-options.ts +3 -0
- package/src/responses/convert-to-openai-responses-input.ts +2 -2
- package/src/tool/apply-patch.ts +33 -32
- package/src/tool/code-interpreter.ts +40 -41
- package/src/tool/custom.ts +2 -2
- package/src/tool/file-search.ts +2 -2
- package/src/tool/image-generation.ts +2 -2
- package/src/tool/local-shell.ts +2 -2
- package/src/tool/mcp.ts +2 -2
- package/src/tool/shell.ts +2 -2
- package/src/tool/tool-search.ts +2 -2
- package/src/tool/web-search-preview.ts +2 -2
- package/src/tool/web-search.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/openai",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.39",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@ai-sdk/provider": "4.0.0-beta.12",
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.0-beta.
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.27"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "20.17.24",
|
|
@@ -53,7 +53,8 @@
|
|
|
53
53
|
"node": ">=18"
|
|
54
54
|
},
|
|
55
55
|
"publishConfig": {
|
|
56
|
-
"access": "public"
|
|
56
|
+
"access": "public",
|
|
57
|
+
"provenance": true
|
|
57
58
|
},
|
|
58
59
|
"homepage": "https://ai-sdk.dev/docs",
|
|
59
60
|
"repository": {
|
|
@@ -211,7 +211,7 @@ export function convertToOpenAIChatMessages({
|
|
|
211
211
|
contentValue = output.value;
|
|
212
212
|
break;
|
|
213
213
|
case 'execution-denied':
|
|
214
|
-
contentValue = output.reason ?? 'Tool execution denied.';
|
|
214
|
+
contentValue = output.reason ?? 'Tool call execution denied.';
|
|
215
215
|
break;
|
|
216
216
|
case 'content':
|
|
217
217
|
case 'json':
|
|
@@ -452,10 +452,7 @@ export class OpenAIChatLanguageModel implements LanguageModelV4 {
|
|
|
452
452
|
fetch: this.config.fetch,
|
|
453
453
|
});
|
|
454
454
|
|
|
455
|
-
|
|
456
|
-
generateId,
|
|
457
|
-
typeValidation: 'if-present',
|
|
458
|
-
});
|
|
455
|
+
let toolCallTracker: StreamingToolCallTracker;
|
|
459
456
|
|
|
460
457
|
let finishReason: LanguageModelV4FinishReason = {
|
|
461
458
|
unified: 'other',
|
|
@@ -474,6 +471,10 @@ export class OpenAIChatLanguageModel implements LanguageModelV4 {
|
|
|
474
471
|
LanguageModelV4StreamPart
|
|
475
472
|
>({
|
|
476
473
|
start(controller) {
|
|
474
|
+
toolCallTracker = new StreamingToolCallTracker(controller, {
|
|
475
|
+
generateId,
|
|
476
|
+
typeValidation: 'if-present',
|
|
477
|
+
});
|
|
477
478
|
controller.enqueue({ type: 'stream-start', warnings });
|
|
478
479
|
},
|
|
479
480
|
|
|
@@ -565,10 +566,7 @@ export class OpenAIChatLanguageModel implements LanguageModelV4 {
|
|
|
565
566
|
|
|
566
567
|
if (delta.tool_calls != null) {
|
|
567
568
|
for (const toolCallDelta of delta.tool_calls) {
|
|
568
|
-
toolCallTracker.processDelta(
|
|
569
|
-
toolCallDelta,
|
|
570
|
-
controller.enqueue.bind(controller),
|
|
571
|
-
);
|
|
569
|
+
toolCallTracker.processDelta(toolCallDelta);
|
|
572
570
|
}
|
|
573
571
|
}
|
|
574
572
|
|
|
@@ -591,7 +589,7 @@ export class OpenAIChatLanguageModel implements LanguageModelV4 {
|
|
|
591
589
|
controller.enqueue({ type: 'text-end', id: '0' });
|
|
592
590
|
}
|
|
593
591
|
|
|
594
|
-
toolCallTracker.flush(
|
|
592
|
+
toolCallTracker.flush();
|
|
595
593
|
|
|
596
594
|
controller.enqueue({
|
|
597
595
|
type: 'finish',
|
|
@@ -4,6 +4,7 @@ export type OpenAIImageModelId =
|
|
|
4
4
|
| 'gpt-image-1'
|
|
5
5
|
| 'gpt-image-1-mini'
|
|
6
6
|
| 'gpt-image-1.5'
|
|
7
|
+
| 'gpt-image-2'
|
|
7
8
|
| 'chatgpt-image-latest'
|
|
8
9
|
| (string & {});
|
|
9
10
|
|
|
@@ -14,6 +15,7 @@ export const modelMaxImagesPerCall: Record<OpenAIImageModelId, number> = {
|
|
|
14
15
|
'gpt-image-1': 10,
|
|
15
16
|
'gpt-image-1-mini': 10,
|
|
16
17
|
'gpt-image-1.5': 10,
|
|
18
|
+
'gpt-image-2': 10,
|
|
17
19
|
'chatgpt-image-latest': 10,
|
|
18
20
|
};
|
|
19
21
|
|
|
@@ -22,6 +24,7 @@ const defaultResponseFormatPrefixes = [
|
|
|
22
24
|
'gpt-image-1-mini',
|
|
23
25
|
'gpt-image-1.5',
|
|
24
26
|
'gpt-image-1',
|
|
27
|
+
'gpt-image-2',
|
|
25
28
|
];
|
|
26
29
|
|
|
27
30
|
export function hasDefaultResponseFormat(modelId: string): boolean {
|
|
@@ -743,7 +743,7 @@ export async function convertToOpenAIResponsesInput({
|
|
|
743
743
|
outputValue = output.value;
|
|
744
744
|
break;
|
|
745
745
|
case 'execution-denied':
|
|
746
|
-
outputValue = output.reason ?? 'Tool execution denied.';
|
|
746
|
+
outputValue = output.reason ?? 'Tool call execution denied.';
|
|
747
747
|
break;
|
|
748
748
|
case 'json':
|
|
749
749
|
case 'error-json':
|
|
@@ -806,7 +806,7 @@ export async function convertToOpenAIResponsesInput({
|
|
|
806
806
|
contentValue = output.value;
|
|
807
807
|
break;
|
|
808
808
|
case 'execution-denied':
|
|
809
|
-
contentValue = output.reason ?? 'Tool execution denied.';
|
|
809
|
+
contentValue = output.reason ?? 'Tool call execution denied.';
|
|
810
810
|
break;
|
|
811
811
|
case 'json':
|
|
812
812
|
case 'error-json':
|
package/src/tool/apply-patch.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderDefinedToolFactoryWithOutputSchema,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -98,39 +98,40 @@ export type ApplyPatchOperation =
|
|
|
98
98
|
* - Returns the status of applying those patches (completed or failed)
|
|
99
99
|
*
|
|
100
100
|
*/
|
|
101
|
-
export const applyPatchToolFactory =
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
export const applyPatchToolFactory =
|
|
102
|
+
createProviderDefinedToolFactoryWithOutputSchema<
|
|
103
|
+
{
|
|
104
|
+
/**
|
|
105
|
+
* The unique ID of the apply patch tool call generated by the model.
|
|
106
|
+
*/
|
|
107
|
+
callId: string;
|
|
107
108
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
109
|
+
/**
|
|
110
|
+
* The specific create, delete, or update instruction for the apply_patch tool call.
|
|
111
|
+
*/
|
|
112
|
+
operation: ApplyPatchOperation;
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
/**
|
|
116
|
+
* The status of the apply patch tool call output.
|
|
117
|
+
* - 'completed': The patch was applied successfully.
|
|
118
|
+
* - 'failed': The patch failed to apply.
|
|
119
|
+
*/
|
|
120
|
+
status: 'completed' | 'failed';
|
|
120
121
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
>({
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
});
|
|
122
|
+
/**
|
|
123
|
+
* Optional human-readable log text from the apply patch tool
|
|
124
|
+
* (e.g., patch results or errors).
|
|
125
|
+
*/
|
|
126
|
+
output?: string;
|
|
127
|
+
},
|
|
128
|
+
// No configuration options for apply_patch
|
|
129
|
+
{}
|
|
130
|
+
>({
|
|
131
|
+
id: 'openai.apply_patch',
|
|
132
|
+
inputSchema: applyPatchInputSchema,
|
|
133
|
+
outputSchema: applyPatchOutputSchema,
|
|
134
|
+
});
|
|
134
135
|
|
|
135
136
|
/**
|
|
136
137
|
* The apply_patch tool lets GPT-5.1 create, update, and delete files in your
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -53,49 +53,48 @@ type CodeInterpreterArgs = {
|
|
|
53
53
|
container?: string | { fileIds?: string[] };
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
export const codeInterpreterToolFactory =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
code?: string | null;
|
|
56
|
+
export const codeInterpreterToolFactory = createProviderExecutedToolFactory<
|
|
57
|
+
{
|
|
58
|
+
/**
|
|
59
|
+
* The code to run, or null if not available.
|
|
60
|
+
*/
|
|
61
|
+
code?: string | null;
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
/**
|
|
64
|
+
* The ID of the container used to run the code.
|
|
65
|
+
*/
|
|
66
|
+
containerId: string;
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
/**
|
|
70
|
+
* The outputs generated by the code interpreter, such as logs or images.
|
|
71
|
+
* Can be null if no outputs are available.
|
|
72
|
+
*/
|
|
73
|
+
outputs?: Array<
|
|
74
|
+
| {
|
|
75
|
+
type: 'logs';
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
/**
|
|
78
|
+
* The logs output from the code interpreter.
|
|
79
|
+
*/
|
|
80
|
+
logs: string;
|
|
81
|
+
}
|
|
82
|
+
| {
|
|
83
|
+
type: 'image';
|
|
85
84
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
85
|
+
/**
|
|
86
|
+
* The URL of the image output from the code interpreter.
|
|
87
|
+
*/
|
|
88
|
+
url: string;
|
|
89
|
+
}
|
|
90
|
+
> | null;
|
|
91
|
+
},
|
|
92
|
+
CodeInterpreterArgs
|
|
93
|
+
>({
|
|
94
|
+
id: 'openai.code_interpreter',
|
|
95
|
+
inputSchema: codeInterpreterInputSchema,
|
|
96
|
+
outputSchema: codeInterpreterOutputSchema,
|
|
97
|
+
});
|
|
99
98
|
|
|
100
99
|
export const codeInterpreter = (
|
|
101
100
|
args: CodeInterpreterArgs = {}, // default
|
package/src/tool/custom.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderDefinedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -27,7 +27,7 @@ export const customArgsSchema = lazySchema(() =>
|
|
|
27
27
|
|
|
28
28
|
const customInputSchema = lazySchema(() => zodSchema(z.string()));
|
|
29
29
|
|
|
30
|
-
export const customToolFactory =
|
|
30
|
+
export const customToolFactory = createProviderDefinedToolFactory<
|
|
31
31
|
string,
|
|
32
32
|
{
|
|
33
33
|
/**
|
package/src/tool/file-search.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -59,7 +59,7 @@ export const fileSearchOutputSchema = lazySchema(() =>
|
|
|
59
59
|
),
|
|
60
60
|
);
|
|
61
61
|
|
|
62
|
-
export const fileSearch =
|
|
62
|
+
export const fileSearch = createProviderExecutedToolFactory<
|
|
63
63
|
{},
|
|
64
64
|
{
|
|
65
65
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -104,7 +104,7 @@ type ImageGenerationArgs = {
|
|
|
104
104
|
size?: 'auto' | '1024x1024' | '1024x1536' | '1536x1024';
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
-
const imageGenerationToolFactory =
|
|
107
|
+
const imageGenerationToolFactory = createProviderExecutedToolFactory<
|
|
108
108
|
{},
|
|
109
109
|
{
|
|
110
110
|
/**
|
package/src/tool/local-shell.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderDefinedToolFactoryWithOutputSchema,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -24,7 +24,7 @@ export const localShellOutputSchema = lazySchema(() =>
|
|
|
24
24
|
zodSchema(z.object({ output: z.string() })),
|
|
25
25
|
);
|
|
26
26
|
|
|
27
|
-
export const localShell =
|
|
27
|
+
export const localShell = createProviderDefinedToolFactoryWithOutputSchema<
|
|
28
28
|
{
|
|
29
29
|
/**
|
|
30
30
|
* Execute a shell command on the server.
|
package/src/tool/mcp.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -105,7 +105,7 @@ type McpArgs = {
|
|
|
105
105
|
serverUrl?: string;
|
|
106
106
|
};
|
|
107
107
|
|
|
108
|
-
export const mcpToolFactory =
|
|
108
|
+
export const mcpToolFactory = createProviderExecutedToolFactory<
|
|
109
109
|
{},
|
|
110
110
|
{
|
|
111
111
|
type: 'call';
|
package/src/tool/shell.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderDefinedToolFactoryWithOutputSchema,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -157,7 +157,7 @@ type ShellArgs = {
|
|
|
157
157
|
};
|
|
158
158
|
};
|
|
159
159
|
|
|
160
|
-
export const shell =
|
|
160
|
+
export const shell = createProviderDefinedToolFactoryWithOutputSchema<
|
|
161
161
|
{
|
|
162
162
|
/**
|
|
163
163
|
* Shell tool action containing commands to execute.
|
package/src/tool/tool-search.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JSONObject } from '@ai-sdk/provider';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
createProviderDefinedToolFactoryWithOutputSchema,
|
|
4
4
|
FlexibleSchema,
|
|
5
5
|
lazySchema,
|
|
6
6
|
zodSchema,
|
|
@@ -36,7 +36,7 @@ export const toolSearchOutputSchema: FlexibleSchema<{
|
|
|
36
36
|
),
|
|
37
37
|
) as FlexibleSchema<{ tools: Array<JSONObject> }>;
|
|
38
38
|
|
|
39
|
-
const toolSearchToolFactory =
|
|
39
|
+
const toolSearchToolFactory = createProviderDefinedToolFactoryWithOutputSchema<
|
|
40
40
|
{
|
|
41
41
|
/**
|
|
42
42
|
* The arguments from the tool_search_call.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -50,7 +50,7 @@ const webSearchPreviewOutputSchema = lazySchema(() =>
|
|
|
50
50
|
),
|
|
51
51
|
);
|
|
52
52
|
|
|
53
|
-
export const webSearchPreview =
|
|
53
|
+
export const webSearchPreview = createProviderExecutedToolFactory<
|
|
54
54
|
{
|
|
55
55
|
// Web search preview doesn't take input parameters - it's controlled by the prompt
|
|
56
56
|
},
|
package/src/tool/web-search.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -60,7 +60,7 @@ export const webSearchOutputSchema = lazySchema(() =>
|
|
|
60
60
|
),
|
|
61
61
|
);
|
|
62
62
|
|
|
63
|
-
export const webSearchToolFactory =
|
|
63
|
+
export const webSearchToolFactory = createProviderExecutedToolFactory<
|
|
64
64
|
{
|
|
65
65
|
// Web search doesn't take input parameters - it's controlled by the prompt
|
|
66
66
|
},
|