@ai-sdk/openai 4.0.97 → 4.0.98

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/openai",
3
- "version": "4.0.97",
3
+ "version": "4.0.98",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -35,13 +35,14 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@ai-sdk/provider": "4.0.30",
39
- "@ai-sdk/provider-utils": "5.0.63"
38
+ "@ai-sdk/provider": "4.0.31",
39
+ "@ai-sdk/provider-utils": "5.0.64"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@ai-sdk/test-server": "2.0.4",
43
43
  "@types/node": "22.19.19",
44
44
  "@vercel/ai-tsconfig": "0.0.0",
45
+ "@vercel/ai-tsdown-config": "0.0.0",
45
46
  "tsdown": "^0.23.0",
46
47
  "typescript": "6.0.3",
47
48
  "zod": "3.25.76"
@@ -114,6 +114,8 @@ export class DecisionOpenAIModel implements DecisionModelV4 {
114
114
  async doDecide({
115
115
  state,
116
116
  questions,
117
+ maxOutputTokens,
118
+ reasoning,
117
119
  headers,
118
120
  abortSignal,
119
121
  providerOptions,
@@ -302,12 +304,20 @@ export class DecisionOpenAIModel implements DecisionModelV4 {
302
304
  },
303
305
  // The Decisions API reports probabilities and scores to two decimal places.
304
306
  rounding: { probabilityDecimals: 2, scoreDecimals: 2 },
305
- warnings: Object.keys(providerOptions?.openai ?? {})
306
- .filter(option => option !== 'safetyIdentifier')
307
- .map(option => ({
308
- type: 'unsupported',
309
- feature: `providerOptions.openai.${option}`,
310
- })),
307
+ warnings: [
308
+ ...(maxOutputTokens != null
309
+ ? [{ type: 'unsupported' as const, feature: 'maxOutputTokens' }]
310
+ : []),
311
+ ...(reasoning != null
312
+ ? [{ type: 'unsupported' as const, feature: 'reasoning' }]
313
+ : []),
314
+ ...Object.keys(providerOptions?.openai ?? {})
315
+ .filter(option => option !== 'safetyIdentifier')
316
+ .map(option => ({
317
+ type: 'unsupported' as const,
318
+ feature: `providerOptions.openai.${option}`,
319
+ })),
320
+ ],
311
321
  providerMetadata: {
312
322
  openai: {
313
323
  ...(response.usage == null ? {} : { usage: response.usage }),
@@ -1224,6 +1224,9 @@ export async function convertToOpenAIResponsesInput({
1224
1224
  input.push({
1225
1225
  type: 'shell_call_output',
1226
1226
  call_id: part.toolCallId,
1227
+ ...(parsedOutput.maxOutputLength != null && {
1228
+ max_output_length: parsedOutput.maxOutputLength,
1229
+ }),
1227
1230
  output: parsedOutput.output.map(item => ({
1228
1231
  stdout: item.stdout,
1229
1232
  stderr: item.stderr,
@@ -1565,6 +1568,9 @@ export async function convertToOpenAIResponsesInput({
1565
1568
  input.push({
1566
1569
  type: 'shell_call_output',
1567
1570
  call_id: part.toolCallId,
1571
+ ...(parsedOutput.maxOutputLength != null && {
1572
+ max_output_length: parsedOutput.maxOutputLength,
1573
+ }),
1568
1574
  output: parsedOutput.output.map(item => ({
1569
1575
  stdout: item.stdout,
1570
1576
  stderr: item.stderr,
@@ -1061,6 +1061,8 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
1061
1061
  status: z.enum(['in_progress', 'completed', 'incomplete']),
1062
1062
  action: z.object({
1063
1063
  commands: z.array(z.string()),
1064
+ timeout_ms: z.number().nullish(),
1065
+ max_output_length: z.number().nullish(),
1064
1066
  }),
1065
1067
  }),
1066
1068
  z.object({
@@ -1073,6 +1075,7 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
1073
1075
  id: z.string(),
1074
1076
  call_id: z.string(),
1075
1077
  status: z.enum(['in_progress', 'completed', 'incomplete']),
1078
+ max_output_length: z.number().nullish(),
1076
1079
  output: z.array(
1077
1080
  z.object({
1078
1081
  stdout: z.string(),
@@ -1296,6 +1299,8 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
1296
1299
  status: z.enum(['in_progress', 'completed', 'incomplete']),
1297
1300
  action: z.object({
1298
1301
  commands: z.array(z.string()),
1302
+ timeout_ms: z.number().nullish(),
1303
+ max_output_length: z.number().nullish(),
1299
1304
  }),
1300
1305
  }),
1301
1306
  z.object({
@@ -1308,6 +1313,7 @@ export const openaiResponsesChunkSchema = lazySchema(() =>
1308
1313
  id: z.string(),
1309
1314
  call_id: z.string(),
1310
1315
  status: z.enum(['in_progress', 'completed', 'incomplete']),
1316
+ max_output_length: z.number().nullish(),
1311
1317
  output: z.array(
1312
1318
  z.object({
1313
1319
  stdout: z.string(),
@@ -1737,6 +1743,8 @@ export const openaiResponsesResponseSchema = lazySchema(() =>
1737
1743
  status: z.enum(['in_progress', 'completed', 'incomplete']),
1738
1744
  action: z.object({
1739
1745
  commands: z.array(z.string()),
1746
+ timeout_ms: z.number().nullish(),
1747
+ max_output_length: z.number().nullish(),
1740
1748
  }),
1741
1749
  }),
1742
1750
  z.object({
@@ -1749,6 +1757,7 @@ export const openaiResponsesResponseSchema = lazySchema(() =>
1749
1757
  id: z.string(),
1750
1758
  call_id: z.string(),
1751
1759
  status: z.enum(['in_progress', 'completed', 'incomplete']),
1760
+ max_output_length: z.number().nullish(),
1752
1761
  output: z.array(
1753
1762
  z.object({
1754
1763
  stdout: z.string(),
@@ -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/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(),
@@ -180,6 +181,11 @@ export const shell = createProviderDefinedToolFactoryWithOutputSchema<
180
181
  };
181
182
  },
182
183
  {
184
+ /**
185
+ * Optional maximum number of characters that was applied to each command's output.
186
+ */
187
+ maxOutputLength?: number;
188
+
183
189
  /**
184
190
  * An array of shell call output contents.
185
191
  */
@@ -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