@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.
@@ -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 and currently only supports 30 minutes.
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.literal('30m').optional(),
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;
@@ -5,66 +5,68 @@ import {
5
5
  } from '@ai-sdk/provider-utils';
6
6
  import { z } from 'zod/v4';
7
7
 
8
- const safetyCheckSchema = z.object({
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
- type: z.literal('scroll'),
48
- x: z.number(),
49
- y: z.number(),
50
- scrollX: z.number(),
51
- scrollY: z.number(),
52
- keys: z.array(z.string()).optional(),
53
- }),
54
- z.object({
55
- type: z.literal('type'),
56
- text: z.string(),
57
- }),
58
- z.object({
59
- type: z.literal('wait'),
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<typeof computerActionSchema>;
96
- export type OpenAIComputerSafetyCheck = z.infer<typeof safetyCheckSchema>;
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
  {
@@ -9,18 +9,21 @@ import type {
9
9
  OpenAIResponsesFileSearchToolCompoundFilter,
10
10
  } from '../responses/openai-responses-api';
11
11
 
12
- const comparisonFilterSchema = z.object({
13
- key: z.string(),
14
- type: z.enum(['eq', 'ne', 'gt', 'gte', 'lt', 'lte', 'in', 'nin']),
15
- value: z.union([z.string(), z.number(), z.boolean(), z.array(z.string())]),
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
- const compoundFilterSchema: z.ZodType<any> = z.object({
19
- type: z.enum(['and', 'or']),
20
- filters: z.array(
21
- z.union([comparisonFilterSchema, z.lazy(() => compoundFilterSchema)]),
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
- const jsonValueSchema: z.ZodType<JSONValue> = z.lazy(() =>
10
- z.union([
11
- z.string(),
12
- z.number(),
13
- z.boolean(),
14
- z.null(),
15
- z.array(jsonValueSchema),
16
- z.record(z.string(), jsonValueSchema),
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 = z
39
- .array(
40
- z.discriminatedUnion('type', [
41
- z.object({
42
- type: z.literal('skillReference'),
43
- providerReference: z.record(z.string(), z.string()),
44
- version: z.string().optional(),
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
- .optional();
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
  */
@@ -6,6 +6,7 @@ export const openaiTranscriptionResponseSchema = lazySchema(() =>
6
6
  z.object({
7
7
  text: z.string(),
8
8
  language: z.string().nullish(),
9
+ languages: z.array(z.object({ code: z.string() })).nullish(),
9
10
  duration: z.number().nullish(),
10
11
  words: z
11
12
  .array(
@@ -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 != null && response.language in languageMap
303
- ? languageMap[response.language as keyof typeof languageMap]
304
- : undefined;
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
- diarizedSegments.length > 0 && {
345
- providerMetadata: {
346
- openai: {
347
- segments: diarizedSegments,
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