@ai-sdk/openai 4.0.97 → 4.0.99
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 +23 -0
- package/dist/index.d.ts +21 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +179 -122
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +37 -44
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +151 -100
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +52 -8
- package/package.json +4 -3
- package/src/chat/openai-chat-api.ts +1 -1
- package/src/completion/openai-completion-api.ts +1 -1
- package/src/files/openai-files.ts +1 -11
- package/src/image/openai-image-model-options.ts +40 -39
- package/src/live/openai-realtime-model-live.ts +13 -4
- package/src/openai-batch.ts +2 -2
- package/src/openai-decision-model.ts +71 -50
- package/src/openai-error.ts +22 -14
- package/src/responses/convert-openai-responses-usage.ts +6 -0
- package/src/responses/convert-to-openai-responses-input.ts +23 -11
- package/src/responses/openai-responses-api.ts +230 -192
- package/src/responses/openai-responses-language-model-options.ts +4 -2
- package/src/responses/openai-responses-language-model.ts +11 -0
- package/src/tool/computer.ts +64 -58
- package/src/tool/file-search.ts +15 -12
- package/src/tool/mcp.ts +13 -11
- package/src/tool/shell.ts +28 -21
- package/src/transcription/openai-transcription-api.ts +1 -0
- package/src/transcription/openai-transcription-model.ts +29 -10
|
@@ -250,12 +250,14 @@ export const openaiLanguageModelResponsesOptionsSchema = lazySchema(() =>
|
|
|
250
250
|
/**
|
|
251
251
|
* Prompt cache behavior for GPT-5.6 and later models.
|
|
252
252
|
* `mode` controls whether OpenAI also places an implicit breakpoint.
|
|
253
|
-
* `ttl` sets the minimum cache lifetime
|
|
253
|
+
* `ttl` sets the minimum cache lifetime: `'30m'` (default) or `'12h'`.
|
|
254
|
+
* `prewarm` writes the prompt to the cache without generating output.
|
|
254
255
|
*/
|
|
255
256
|
promptCacheOptions: z
|
|
256
257
|
.object({
|
|
257
258
|
mode: z.enum(['implicit', 'explicit']).optional(),
|
|
258
|
-
ttl: z.
|
|
259
|
+
ttl: z.enum(['30m', '12h']).optional(),
|
|
260
|
+
prewarm: z.boolean().optional(),
|
|
259
261
|
})
|
|
260
262
|
.optional(),
|
|
261
263
|
|
|
@@ -1045,6 +1045,8 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV4 {
|
|
|
1045
1045
|
input: JSON.stringify({
|
|
1046
1046
|
action: {
|
|
1047
1047
|
commands: part.action.commands,
|
|
1048
|
+
timeoutMs: part.action.timeout_ms ?? undefined,
|
|
1049
|
+
maxOutputLength: part.action.max_output_length ?? undefined,
|
|
1048
1050
|
},
|
|
1049
1051
|
} satisfies InferSchema<typeof shellInputSchema>),
|
|
1050
1052
|
...(isShellProviderExecuted && { providerExecuted: true }),
|
|
@@ -1064,6 +1066,9 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV4 {
|
|
|
1064
1066
|
toolCallId: part.call_id,
|
|
1065
1067
|
toolName: toolNameMapping.toCustomToolName('shell'),
|
|
1066
1068
|
result: {
|
|
1069
|
+
...(part.max_output_length != null && {
|
|
1070
|
+
maxOutputLength: part.max_output_length,
|
|
1071
|
+
}),
|
|
1067
1072
|
output: part.output.map(item => ({
|
|
1068
1073
|
stdout: item.stdout,
|
|
1069
1074
|
stderr: item.stderr,
|
|
@@ -2530,6 +2535,9 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV4 {
|
|
|
2530
2535
|
input: JSON.stringify({
|
|
2531
2536
|
action: {
|
|
2532
2537
|
commands: value.item.action.commands,
|
|
2538
|
+
timeoutMs: value.item.action.timeout_ms ?? undefined,
|
|
2539
|
+
maxOutputLength:
|
|
2540
|
+
value.item.action.max_output_length ?? undefined,
|
|
2533
2541
|
},
|
|
2534
2542
|
} satisfies InferSchema<typeof shellInputSchema>),
|
|
2535
2543
|
...(isShellProviderExecuted && {
|
|
@@ -2545,6 +2553,9 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV4 {
|
|
|
2545
2553
|
toolCallId: value.item.call_id,
|
|
2546
2554
|
toolName: toolNameMapping.toCustomToolName('shell'),
|
|
2547
2555
|
result: {
|
|
2556
|
+
...(value.item.max_output_length != null && {
|
|
2557
|
+
maxOutputLength: value.item.max_output_length,
|
|
2558
|
+
}),
|
|
2548
2559
|
output: value.item.output.map(
|
|
2549
2560
|
(item: {
|
|
2550
2561
|
stdout: string;
|
package/src/tool/computer.ts
CHANGED
|
@@ -5,66 +5,68 @@ import {
|
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
6
6
|
import { z } from 'zod/v4';
|
|
7
7
|
|
|
8
|
-
const safetyCheckSchema =
|
|
9
|
-
id: z.string(),
|
|
10
|
-
code: z.string().optional(),
|
|
11
|
-
message: z.string().optional(),
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const computerActionSchema = z.discriminatedUnion('type', [
|
|
15
|
-
z.object({
|
|
16
|
-
type: z.literal('click'),
|
|
17
|
-
button: z.enum(['left', 'right', 'wheel', 'back', 'forward']),
|
|
18
|
-
x: z.number(),
|
|
19
|
-
y: z.number(),
|
|
20
|
-
keys: z.array(z.string()).optional(),
|
|
21
|
-
}),
|
|
22
|
-
z.object({
|
|
23
|
-
type: z.literal('double_click'),
|
|
24
|
-
x: z.number(),
|
|
25
|
-
y: z.number(),
|
|
26
|
-
keys: z.array(z.string()).optional(),
|
|
27
|
-
}),
|
|
28
|
-
z.object({
|
|
29
|
-
type: z.literal('drag'),
|
|
30
|
-
path: z.array(z.object({ x: z.number(), y: z.number() })),
|
|
31
|
-
keys: z.array(z.string()).optional(),
|
|
32
|
-
}),
|
|
33
|
-
z.object({
|
|
34
|
-
type: z.literal('keypress'),
|
|
35
|
-
keys: z.array(z.string()),
|
|
36
|
-
}),
|
|
37
|
-
z.object({
|
|
38
|
-
type: z.literal('move'),
|
|
39
|
-
x: z.number(),
|
|
40
|
-
y: z.number(),
|
|
41
|
-
keys: z.array(z.string()).optional(),
|
|
42
|
-
}),
|
|
43
|
-
z.object({
|
|
44
|
-
type: z.literal('screenshot'),
|
|
45
|
-
}),
|
|
8
|
+
const safetyCheckSchema = () =>
|
|
46
9
|
z.object({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
10
|
+
id: z.string(),
|
|
11
|
+
code: z.string().optional(),
|
|
12
|
+
message: z.string().optional(),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const computerActionSchema = () =>
|
|
16
|
+
z.discriminatedUnion('type', [
|
|
17
|
+
z.object({
|
|
18
|
+
type: z.literal('click'),
|
|
19
|
+
button: z.enum(['left', 'right', 'wheel', 'back', 'forward']),
|
|
20
|
+
x: z.number(),
|
|
21
|
+
y: z.number(),
|
|
22
|
+
keys: z.array(z.string()).optional(),
|
|
23
|
+
}),
|
|
24
|
+
z.object({
|
|
25
|
+
type: z.literal('double_click'),
|
|
26
|
+
x: z.number(),
|
|
27
|
+
y: z.number(),
|
|
28
|
+
keys: z.array(z.string()).optional(),
|
|
29
|
+
}),
|
|
30
|
+
z.object({
|
|
31
|
+
type: z.literal('drag'),
|
|
32
|
+
path: z.array(z.object({ x: z.number(), y: z.number() })),
|
|
33
|
+
keys: z.array(z.string()).optional(),
|
|
34
|
+
}),
|
|
35
|
+
z.object({
|
|
36
|
+
type: z.literal('keypress'),
|
|
37
|
+
keys: z.array(z.string()),
|
|
38
|
+
}),
|
|
39
|
+
z.object({
|
|
40
|
+
type: z.literal('move'),
|
|
41
|
+
x: z.number(),
|
|
42
|
+
y: z.number(),
|
|
43
|
+
keys: z.array(z.string()).optional(),
|
|
44
|
+
}),
|
|
45
|
+
z.object({
|
|
46
|
+
type: z.literal('screenshot'),
|
|
47
|
+
}),
|
|
48
|
+
z.object({
|
|
49
|
+
type: z.literal('scroll'),
|
|
50
|
+
x: z.number(),
|
|
51
|
+
y: z.number(),
|
|
52
|
+
scrollX: z.number(),
|
|
53
|
+
scrollY: z.number(),
|
|
54
|
+
keys: z.array(z.string()).optional(),
|
|
55
|
+
}),
|
|
56
|
+
z.object({
|
|
57
|
+
type: z.literal('type'),
|
|
58
|
+
text: z.string(),
|
|
59
|
+
}),
|
|
60
|
+
z.object({
|
|
61
|
+
type: z.literal('wait'),
|
|
62
|
+
}),
|
|
63
|
+
]);
|
|
62
64
|
|
|
63
65
|
export const computerInputSchema = lazySchema(() =>
|
|
64
66
|
zodSchema(
|
|
65
67
|
z.object({
|
|
66
|
-
actions: z.array(computerActionSchema),
|
|
67
|
-
pendingSafetyChecks: z.array(safetyCheckSchema),
|
|
68
|
+
actions: z.array(computerActionSchema()),
|
|
69
|
+
pendingSafetyChecks: z.array(safetyCheckSchema()),
|
|
68
70
|
status: z.enum(['in_progress', 'completed', 'incomplete']),
|
|
69
71
|
}),
|
|
70
72
|
),
|
|
@@ -87,13 +89,17 @@ export const computerOutputSchema = lazySchema(() =>
|
|
|
87
89
|
detail: z.enum(['auto', 'low', 'high', 'original']).optional(),
|
|
88
90
|
}),
|
|
89
91
|
]),
|
|
90
|
-
acknowledgedSafetyChecks: z.array(safetyCheckSchema).optional(),
|
|
92
|
+
acknowledgedSafetyChecks: z.array(safetyCheckSchema()).optional(),
|
|
91
93
|
}),
|
|
92
94
|
),
|
|
93
95
|
);
|
|
94
96
|
|
|
95
|
-
export type OpenAIComputerAction = z.infer<
|
|
96
|
-
|
|
97
|
+
export type OpenAIComputerAction = z.infer<
|
|
98
|
+
ReturnType<typeof computerActionSchema>
|
|
99
|
+
>;
|
|
100
|
+
export type OpenAIComputerSafetyCheck = z.infer<
|
|
101
|
+
ReturnType<typeof safetyCheckSchema>
|
|
102
|
+
>;
|
|
97
103
|
|
|
98
104
|
const computerToolFactory = createProviderDefinedToolFactoryWithOutputSchema<
|
|
99
105
|
{
|
package/src/tool/file-search.ts
CHANGED
|
@@ -9,18 +9,21 @@ import type {
|
|
|
9
9
|
OpenAIResponsesFileSearchToolCompoundFilter,
|
|
10
10
|
} from '../responses/openai-responses-api';
|
|
11
11
|
|
|
12
|
-
const comparisonFilterSchema =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const comparisonFilterSchema = () =>
|
|
13
|
+
z.object({
|
|
14
|
+
key: z.string(),
|
|
15
|
+
type: z.enum(['eq', 'ne', 'gt', 'gte', 'lt', 'lte', 'in', 'nin']),
|
|
16
|
+
value: z.union([z.string(), z.number(), z.boolean(), z.array(z.string())]),
|
|
17
|
+
});
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
z.
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
let cachedCompoundFilterSchema: z.ZodType<any> | undefined;
|
|
20
|
+
const compoundFilterSchema = (): z.ZodType<any> =>
|
|
21
|
+
(cachedCompoundFilterSchema ??= z.object({
|
|
22
|
+
type: z.enum(['and', 'or']),
|
|
23
|
+
filters: z.array(
|
|
24
|
+
z.union([comparisonFilterSchema(), z.lazy(() => compoundFilterSchema())]),
|
|
25
|
+
),
|
|
26
|
+
}));
|
|
24
27
|
|
|
25
28
|
export const fileSearchArgsSchema = lazySchema(() =>
|
|
26
29
|
zodSchema(
|
|
@@ -34,7 +37,7 @@ export const fileSearchArgsSchema = lazySchema(() =>
|
|
|
34
37
|
})
|
|
35
38
|
.optional(),
|
|
36
39
|
filters: z
|
|
37
|
-
.union([comparisonFilterSchema, compoundFilterSchema])
|
|
40
|
+
.union([comparisonFilterSchema(), compoundFilterSchema()])
|
|
38
41
|
.optional(),
|
|
39
42
|
}),
|
|
40
43
|
),
|
package/src/tool/mcp.ts
CHANGED
|
@@ -6,16 +6,18 @@ import {
|
|
|
6
6
|
import type { JSONValue } from '@ai-sdk/provider';
|
|
7
7
|
import { z } from 'zod/v4';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
z.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
)
|
|
9
|
+
let cachedJsonValueSchema: z.ZodType<JSONValue> | undefined;
|
|
10
|
+
const jsonValueSchema = (): z.ZodType<JSONValue> =>
|
|
11
|
+
(cachedJsonValueSchema ??= z.lazy(() =>
|
|
12
|
+
z.union([
|
|
13
|
+
z.string(),
|
|
14
|
+
z.number(),
|
|
15
|
+
z.boolean(),
|
|
16
|
+
z.null(),
|
|
17
|
+
z.array(jsonValueSchema()),
|
|
18
|
+
z.record(z.string(), jsonValueSchema()),
|
|
19
|
+
]),
|
|
20
|
+
));
|
|
19
21
|
|
|
20
22
|
export const mcpArgsSchema = lazySchema(() =>
|
|
21
23
|
zodSchema(
|
|
@@ -67,7 +69,7 @@ export const mcpOutputSchema = lazySchema(() =>
|
|
|
67
69
|
name: z.string(),
|
|
68
70
|
arguments: z.string(),
|
|
69
71
|
output: z.string().nullish(),
|
|
70
|
-
error: z.union([z.string(), jsonValueSchema]).optional(),
|
|
72
|
+
error: z.union([z.string(), jsonValueSchema()]).optional(),
|
|
71
73
|
}),
|
|
72
74
|
),
|
|
73
75
|
);
|
package/src/tool/shell.ts
CHANGED
|
@@ -21,6 +21,7 @@ export const shellInputSchema = lazySchema(() =>
|
|
|
21
21
|
export const shellOutputSchema = lazySchema(() =>
|
|
22
22
|
zodSchema(
|
|
23
23
|
z.object({
|
|
24
|
+
maxOutputLength: z.number().optional(),
|
|
24
25
|
output: z.array(
|
|
25
26
|
z.object({
|
|
26
27
|
stdout: z.string(),
|
|
@@ -35,27 +36,28 @@ export const shellOutputSchema = lazySchema(() =>
|
|
|
35
36
|
),
|
|
36
37
|
);
|
|
37
38
|
|
|
38
|
-
const shellSkillsSchema =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
z.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
z.object({
|
|
47
|
-
type: z.literal('inline'),
|
|
48
|
-
name: z.string(),
|
|
49
|
-
description: z.string(),
|
|
50
|
-
source: z.object({
|
|
51
|
-
type: z.literal('base64'),
|
|
52
|
-
mediaType: z.literal('application/zip'),
|
|
53
|
-
data: z.string(),
|
|
39
|
+
const shellSkillsSchema = () =>
|
|
40
|
+
z
|
|
41
|
+
.array(
|
|
42
|
+
z.discriminatedUnion('type', [
|
|
43
|
+
z.object({
|
|
44
|
+
type: z.literal('skillReference'),
|
|
45
|
+
providerReference: z.record(z.string(), z.string()),
|
|
46
|
+
version: z.string().optional(),
|
|
54
47
|
}),
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
z.object({
|
|
49
|
+
type: z.literal('inline'),
|
|
50
|
+
name: z.string(),
|
|
51
|
+
description: z.string(),
|
|
52
|
+
source: z.object({
|
|
53
|
+
type: z.literal('base64'),
|
|
54
|
+
mediaType: z.literal('application/zip'),
|
|
55
|
+
data: z.string(),
|
|
56
|
+
}),
|
|
57
|
+
}),
|
|
58
|
+
]),
|
|
59
|
+
)
|
|
60
|
+
.optional();
|
|
59
61
|
|
|
60
62
|
export const shellArgsSchema = lazySchema(() =>
|
|
61
63
|
zodSchema(
|
|
@@ -84,7 +86,7 @@ export const shellArgsSchema = lazySchema(() =>
|
|
|
84
86
|
}),
|
|
85
87
|
])
|
|
86
88
|
.optional(),
|
|
87
|
-
skills: shellSkillsSchema,
|
|
89
|
+
skills: shellSkillsSchema(),
|
|
88
90
|
}),
|
|
89
91
|
z.object({
|
|
90
92
|
type: z.literal('containerReference'),
|
|
@@ -180,6 +182,11 @@ export const shell = createProviderDefinedToolFactoryWithOutputSchema<
|
|
|
180
182
|
};
|
|
181
183
|
},
|
|
182
184
|
{
|
|
185
|
+
/**
|
|
186
|
+
* Optional maximum number of characters that was applied to each command's output.
|
|
187
|
+
*/
|
|
188
|
+
maxOutputLength?: number;
|
|
189
|
+
|
|
183
190
|
/**
|
|
184
191
|
* An array of shell call output contents.
|
|
185
192
|
*/
|
|
@@ -136,6 +136,12 @@ const languageMap = {
|
|
|
136
136
|
welsh: 'cy',
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
+
function isLanguageCode(
|
|
140
|
+
language: string | null | undefined,
|
|
141
|
+
): language is string {
|
|
142
|
+
return language != null && /^[a-z]{2}$/.test(language);
|
|
143
|
+
}
|
|
144
|
+
|
|
139
145
|
export class OpenAITranscriptionModel implements TranscriptionModelV4 {
|
|
140
146
|
readonly specificationVersion = 'v4';
|
|
141
147
|
|
|
@@ -299,9 +305,16 @@ export class OpenAITranscriptionModel implements TranscriptionModelV4 {
|
|
|
299
305
|
});
|
|
300
306
|
|
|
301
307
|
const language =
|
|
302
|
-
response.language
|
|
303
|
-
?
|
|
304
|
-
:
|
|
308
|
+
(isLanguageCode(response.language)
|
|
309
|
+
? response.language
|
|
310
|
+
: response.language != null &&
|
|
311
|
+
Object.prototype.hasOwnProperty.call(languageMap, response.language)
|
|
312
|
+
? languageMap[response.language as keyof typeof languageMap]
|
|
313
|
+
: undefined) ??
|
|
314
|
+
(response.languages?.length === 1 &&
|
|
315
|
+
isLanguageCode(response.languages[0].code)
|
|
316
|
+
? response.languages[0].code
|
|
317
|
+
: undefined);
|
|
305
318
|
|
|
306
319
|
const diarizedSegments = response.segments?.flatMap(segment =>
|
|
307
320
|
'speaker' in segment
|
|
@@ -340,14 +353,20 @@ export class OpenAITranscriptionModel implements TranscriptionModelV4 {
|
|
|
340
353
|
headers: responseHeaders,
|
|
341
354
|
body: rawResponse,
|
|
342
355
|
},
|
|
343
|
-
...(diarizedSegments != null &&
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
356
|
+
...(((diarizedSegments != null && diarizedSegments.length > 0) ||
|
|
357
|
+
response.languages != null) && {
|
|
358
|
+
providerMetadata: {
|
|
359
|
+
openai: {
|
|
360
|
+
...(diarizedSegments != null &&
|
|
361
|
+
diarizedSegments.length > 0 && {
|
|
362
|
+
segments: diarizedSegments,
|
|
363
|
+
}),
|
|
364
|
+
...(response.languages != null && {
|
|
365
|
+
languages: response.languages,
|
|
366
|
+
}),
|
|
349
367
|
},
|
|
350
|
-
}
|
|
368
|
+
},
|
|
369
|
+
}),
|
|
351
370
|
};
|
|
352
371
|
}
|
|
353
372
|
|