@ai-sdk/openai 2.0.27 → 2.0.29

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 2.0.29
4
+
5
+ ### Patch Changes
6
+
7
+ - 4235eb3: feat(provider/openai): code interpreter tool calls and results
8
+
9
+ ## 2.0.28
10
+
11
+ ### Patch Changes
12
+
13
+ - 4c2bb77: fix (provider/openai): send sources action as include
14
+ - 561e8b0: fix (provider/openai): fix code interpreter tool in doGenerate
15
+
3
16
  ## 2.0.27
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -11,7 +11,7 @@ type OpenAIEmbeddingModelId = 'text-embedding-3-small' | 'text-embedding-3-large
11
11
 
12
12
  type OpenAIImageModelId = 'gpt-image-1' | 'dall-e-3' | 'dall-e-2' | (string & {});
13
13
 
14
- declare const factory: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
14
+ declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
15
15
  /**
16
16
  * Filters for the search.
17
17
  */
@@ -67,34 +67,21 @@ declare const openaiTools: {
67
67
  *
68
68
  * Must have name `code_interpreter`.
69
69
  */
70
- codeInterpreter: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
70
+ codeInterpreter: (args?: {
71
71
  container?: string | {
72
- fileIds
73
- /**
74
- * File search is a tool available in the Responses API. It enables models to
75
- * retrieve information in a knowledge base of previously uploaded files through
76
- * semantic and keyword search.
77
- *
78
- * Must have name `file_search`.
79
- *
80
- * @param vectorStoreIds - The vector store IDs to use for the file search.
81
- * @param maxNumResults - The maximum number of results to return.
82
- * @param ranking - The ranking options to use for the file search.
83
- * @param filters - The filters to use for the file search.
84
- */
85
- ? /**
86
- * File search is a tool available in the Responses API. It enables models to
87
- * retrieve information in a knowledge base of previously uploaded files through
88
- * semantic and keyword search.
89
- *
90
- * Must have name `file_search`.
91
- *
92
- * @param vectorStoreIds - The vector store IDs to use for the file search.
93
- * @param maxNumResults - The maximum number of results to return.
94
- * @param ranking - The ranking options to use for the file search.
95
- * @param filters - The filters to use for the file search.
96
- */: string[];
72
+ fileIds?: string[];
97
73
  };
74
+ }) => _ai_sdk_provider_utils.Tool<{
75
+ code?: string | null;
76
+ containerId: string;
77
+ }, {
78
+ outputs?: Array<{
79
+ type: "logs";
80
+ logs: string;
81
+ } | {
82
+ type: "image";
83
+ url: string;
84
+ }> | null;
98
85
  }>;
99
86
  /**
100
87
  * File search is a tool available in the Responses API. It enables models to
@@ -156,7 +143,7 @@ declare const openaiTools: {
156
143
  * @param searchContextSize - The search context size to use for the web search.
157
144
  * @param userLocation - The user location to use for the web search.
158
145
  */
159
- webSearch: (args?: Parameters<typeof factory>[0]) => _ai_sdk_provider_utils.Tool<{}, unknown>;
146
+ webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<{}, unknown>;
160
147
  };
161
148
 
162
149
  type OpenAIResponsesModelId = 'o1' | 'o1-2024-12-17' | 'o3-mini' | 'o3-mini-2025-01-31' | 'o3' | 'o3-2025-04-16' | 'gpt-5' | 'gpt-5-2025-08-07' | 'gpt-5-mini' | 'gpt-5-mini-2025-08-07' | 'gpt-5-nano' | 'gpt-5-nano-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-4.1' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4' | 'gpt-4-0613' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'chatgpt-4o-latest' | (string & {});
@@ -272,9 +259,9 @@ declare const openaiResponsesProviderOptionsSchema: z.ZodObject<{
272
259
  priority: "priority";
273
260
  }>>>;
274
261
  include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
275
- "reasoning.encrypted_content": "reasoning.encrypted_content";
276
262
  "file_search_call.results": "file_search_call.results";
277
263
  "message.output_text.logprobs": "message.output_text.logprobs";
264
+ "reasoning.encrypted_content": "reasoning.encrypted_content";
278
265
  }>>>>;
279
266
  textVerbosity: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
280
267
  low: "low";
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ type OpenAIEmbeddingModelId = 'text-embedding-3-small' | 'text-embedding-3-large
11
11
 
12
12
  type OpenAIImageModelId = 'gpt-image-1' | 'dall-e-3' | 'dall-e-2' | (string & {});
13
13
 
14
- declare const factory: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
14
+ declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
15
15
  /**
16
16
  * Filters for the search.
17
17
  */
@@ -67,34 +67,21 @@ declare const openaiTools: {
67
67
  *
68
68
  * Must have name `code_interpreter`.
69
69
  */
70
- codeInterpreter: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
70
+ codeInterpreter: (args?: {
71
71
  container?: string | {
72
- fileIds
73
- /**
74
- * File search is a tool available in the Responses API. It enables models to
75
- * retrieve information in a knowledge base of previously uploaded files through
76
- * semantic and keyword search.
77
- *
78
- * Must have name `file_search`.
79
- *
80
- * @param vectorStoreIds - The vector store IDs to use for the file search.
81
- * @param maxNumResults - The maximum number of results to return.
82
- * @param ranking - The ranking options to use for the file search.
83
- * @param filters - The filters to use for the file search.
84
- */
85
- ? /**
86
- * File search is a tool available in the Responses API. It enables models to
87
- * retrieve information in a knowledge base of previously uploaded files through
88
- * semantic and keyword search.
89
- *
90
- * Must have name `file_search`.
91
- *
92
- * @param vectorStoreIds - The vector store IDs to use for the file search.
93
- * @param maxNumResults - The maximum number of results to return.
94
- * @param ranking - The ranking options to use for the file search.
95
- * @param filters - The filters to use for the file search.
96
- */: string[];
72
+ fileIds?: string[];
97
73
  };
74
+ }) => _ai_sdk_provider_utils.Tool<{
75
+ code?: string | null;
76
+ containerId: string;
77
+ }, {
78
+ outputs?: Array<{
79
+ type: "logs";
80
+ logs: string;
81
+ } | {
82
+ type: "image";
83
+ url: string;
84
+ }> | null;
98
85
  }>;
99
86
  /**
100
87
  * File search is a tool available in the Responses API. It enables models to
@@ -156,7 +143,7 @@ declare const openaiTools: {
156
143
  * @param searchContextSize - The search context size to use for the web search.
157
144
  * @param userLocation - The user location to use for the web search.
158
145
  */
159
- webSearch: (args?: Parameters<typeof factory>[0]) => _ai_sdk_provider_utils.Tool<{}, unknown>;
146
+ webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _ai_sdk_provider_utils.Tool<{}, unknown>;
160
147
  };
161
148
 
162
149
  type OpenAIResponsesModelId = 'o1' | 'o1-2024-12-17' | 'o3-mini' | 'o3-mini-2025-01-31' | 'o3' | 'o3-2025-04-16' | 'gpt-5' | 'gpt-5-2025-08-07' | 'gpt-5-mini' | 'gpt-5-mini-2025-08-07' | 'gpt-5-nano' | 'gpt-5-nano-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-4.1' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4' | 'gpt-4-0613' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'chatgpt-4o-latest' | (string & {});
@@ -272,9 +259,9 @@ declare const openaiResponsesProviderOptionsSchema: z.ZodObject<{
272
259
  priority: "priority";
273
260
  }>>>;
274
261
  include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
275
- "reasoning.encrypted_content": "reasoning.encrypted_content";
276
262
  "file_search_call.results": "file_search_call.results";
277
263
  "message.output_text.logprobs": "message.output_text.logprobs";
264
+ "reasoning.encrypted_content": "reasoning.encrypted_content";
278
265
  }>>>>;
279
266
  textVerbosity: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
280
267
  low: "low";
package/dist/index.js CHANGED
@@ -1799,6 +1799,18 @@ var openaiImageResponseSchema = import_v410.z.object({
1799
1799
  // src/tool/code-interpreter.ts
1800
1800
  var import_provider_utils9 = require("@ai-sdk/provider-utils");
1801
1801
  var import_v411 = require("zod/v4");
1802
+ var codeInterpreterInputSchema = import_v411.z.object({
1803
+ code: import_v411.z.string().nullish(),
1804
+ containerId: import_v411.z.string()
1805
+ });
1806
+ var codeInterpreterOutputSchema = import_v411.z.object({
1807
+ outputs: import_v411.z.array(
1808
+ import_v411.z.discriminatedUnion("type", [
1809
+ import_v411.z.object({ type: import_v411.z.literal("logs"), logs: import_v411.z.string() }),
1810
+ import_v411.z.object({ type: import_v411.z.literal("image"), url: import_v411.z.string() })
1811
+ ])
1812
+ ).nullish()
1813
+ });
1802
1814
  var codeInterpreterArgsSchema = import_v411.z.object({
1803
1815
  container: import_v411.z.union([
1804
1816
  import_v411.z.string(),
@@ -1807,11 +1819,15 @@ var codeInterpreterArgsSchema = import_v411.z.object({
1807
1819
  })
1808
1820
  ]).optional()
1809
1821
  });
1810
- var codeInterpreter = (0, import_provider_utils9.createProviderDefinedToolFactory)({
1822
+ var codeInterpreterToolFactory = (0, import_provider_utils9.createProviderDefinedToolFactoryWithOutputSchema)({
1811
1823
  id: "openai.code_interpreter",
1812
1824
  name: "code_interpreter",
1813
- inputSchema: import_v411.z.object({})
1825
+ inputSchema: codeInterpreterInputSchema,
1826
+ outputSchema: codeInterpreterOutputSchema
1814
1827
  });
1828
+ var codeInterpreter = (args = {}) => {
1829
+ return codeInterpreterToolFactory(args);
1830
+ };
1815
1831
 
1816
1832
  // src/tool/web-search.ts
1817
1833
  var import_provider_utils10 = require("@ai-sdk/provider-utils");
@@ -1829,7 +1845,7 @@ var webSearchArgsSchema = import_v412.z.object({
1829
1845
  timezone: import_v412.z.string().optional()
1830
1846
  }).optional()
1831
1847
  });
1832
- var factory = (0, import_provider_utils10.createProviderDefinedToolFactory)({
1848
+ var webSearchToolFactory = (0, import_provider_utils10.createProviderDefinedToolFactory)({
1833
1849
  id: "openai.web_search",
1834
1850
  name: "web_search",
1835
1851
  inputSchema: import_v412.z.object({
@@ -1851,7 +1867,7 @@ var factory = (0, import_provider_utils10.createProviderDefinedToolFactory)({
1851
1867
  })
1852
1868
  });
1853
1869
  var webSearch = (args = {}) => {
1854
- return factory(args);
1870
+ return webSearchToolFactory(args);
1855
1871
  };
1856
1872
 
1857
1873
  // src/openai-tools.ts
@@ -2246,6 +2262,18 @@ var webSearchCallItem = import_v414.z.object({
2246
2262
  })
2247
2263
  ]).nullish()
2248
2264
  });
2265
+ var codeInterpreterCallItem = import_v414.z.object({
2266
+ type: import_v414.z.literal("code_interpreter_call"),
2267
+ id: import_v414.z.string(),
2268
+ code: import_v414.z.string().nullable(),
2269
+ container_id: import_v414.z.string(),
2270
+ outputs: import_v414.z.array(
2271
+ import_v414.z.discriminatedUnion("type", [
2272
+ import_v414.z.object({ type: import_v414.z.literal("logs"), logs: import_v414.z.string() }),
2273
+ import_v414.z.object({ type: import_v414.z.literal("image"), url: import_v414.z.string() })
2274
+ ])
2275
+ ).nullable()
2276
+ });
2249
2277
  var TOP_LOGPROBS_MAX = 20;
2250
2278
  var LOGPROBS_SCHEMA = import_v414.z.array(
2251
2279
  import_v414.z.object({
@@ -2287,7 +2315,7 @@ var OpenAIResponsesLanguageModel = class {
2287
2315
  toolChoice,
2288
2316
  responseFormat
2289
2317
  }) {
2290
- var _a, _b;
2318
+ var _a, _b, _c, _d;
2291
2319
  const warnings = [];
2292
2320
  const modelConfig = getResponsesModelConfig(this.modelId);
2293
2321
  if (topK != null) {
@@ -2323,8 +2351,17 @@ var OpenAIResponsesLanguageModel = class {
2323
2351
  schema: openaiResponsesProviderOptionsSchema
2324
2352
  });
2325
2353
  const strictJsonSchema = (_a = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _a : false;
2354
+ let include = openaiOptions == null ? void 0 : openaiOptions.include;
2326
2355
  const topLogprobs = typeof (openaiOptions == null ? void 0 : openaiOptions.logprobs) === "number" ? openaiOptions == null ? void 0 : openaiOptions.logprobs : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX : void 0;
2327
- const openaiOptionsInclude = topLogprobs ? Array.isArray(openaiOptions == null ? void 0 : openaiOptions.include) ? [...openaiOptions == null ? void 0 : openaiOptions.include, "message.output_text.logprobs"] : ["message.output_text.logprobs"] : openaiOptions == null ? void 0 : openaiOptions.include;
2356
+ include = topLogprobs ? Array.isArray(include) ? [...include, "message.output_text.logprobs"] : ["message.output_text.logprobs"] : include;
2357
+ const webSearchToolName = (_b = tools == null ? void 0 : tools.find(
2358
+ (tool) => tool.type === "provider-defined" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
2359
+ )) == null ? void 0 : _b.name;
2360
+ include = webSearchToolName ? Array.isArray(include) ? [...include, "web_search_call.action.sources"] : ["web_search_call.action.sources"] : include;
2361
+ const codeInterpreterToolName = (_c = tools == null ? void 0 : tools.find(
2362
+ (tool) => tool.type === "provider-defined" && tool.id === "openai.code_interpreter"
2363
+ )) == null ? void 0 : _c.name;
2364
+ include = codeInterpreterToolName ? Array.isArray(include) ? [...include, "code_interpreter_call.outputs"] : ["code_interpreter_call.outputs"] : include;
2328
2365
  const baseArgs = {
2329
2366
  model: this.modelId,
2330
2367
  input: messages,
@@ -2337,7 +2374,7 @@ var OpenAIResponsesLanguageModel = class {
2337
2374
  format: responseFormat.schema != null ? {
2338
2375
  type: "json_schema",
2339
2376
  strict: strictJsonSchema,
2340
- name: (_b = responseFormat.name) != null ? _b : "response",
2377
+ name: (_d = responseFormat.name) != null ? _d : "response",
2341
2378
  description: responseFormat.description,
2342
2379
  schema: responseFormat.schema
2343
2380
  } : { type: "json_object" }
@@ -2355,7 +2392,7 @@ var OpenAIResponsesLanguageModel = class {
2355
2392
  user: openaiOptions == null ? void 0 : openaiOptions.user,
2356
2393
  instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
2357
2394
  service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
2358
- include: openaiOptionsInclude,
2395
+ include,
2359
2396
  prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
2360
2397
  safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
2361
2398
  top_logprobs: topLogprobs,
@@ -2433,6 +2470,7 @@ var OpenAIResponsesLanguageModel = class {
2433
2470
  strictJsonSchema
2434
2471
  });
2435
2472
  return {
2473
+ webSearchToolName,
2436
2474
  args: {
2437
2475
  ...baseArgs,
2438
2476
  tools: openaiTools2,
@@ -2443,7 +2481,11 @@ var OpenAIResponsesLanguageModel = class {
2443
2481
  }
2444
2482
  async doGenerate(options) {
2445
2483
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
2446
- const { args: body, warnings } = await this.getArgs(options);
2484
+ const {
2485
+ args: body,
2486
+ warnings,
2487
+ webSearchToolName
2488
+ } = await this.getArgs(options);
2447
2489
  const url = this.config.url({
2448
2490
  path: "/responses",
2449
2491
  modelId: this.modelId
@@ -2494,12 +2536,16 @@ var OpenAIResponsesLanguageModel = class {
2494
2536
  start_index: import_v414.z.number().nullish(),
2495
2537
  end_index: import_v414.z.number().nullish(),
2496
2538
  quote: import_v414.z.string().nullish()
2539
+ }),
2540
+ import_v414.z.object({
2541
+ type: import_v414.z.literal("container_file_citation")
2497
2542
  })
2498
2543
  ])
2499
2544
  )
2500
2545
  })
2501
2546
  )
2502
2547
  }),
2548
+ codeInterpreterCallItem,
2503
2549
  import_v414.z.object({
2504
2550
  type: import_v414.z.literal("function_call"),
2505
2551
  call_id: import_v414.z.string(),
@@ -2640,14 +2686,14 @@ var OpenAIResponsesLanguageModel = class {
2640
2686
  content.push({
2641
2687
  type: "tool-call",
2642
2688
  toolCallId: part.id,
2643
- toolName: "web_search_preview",
2689
+ toolName: webSearchToolName != null ? webSearchToolName : "web_search",
2644
2690
  input: JSON.stringify({ action: part.action }),
2645
2691
  providerExecuted: true
2646
2692
  });
2647
2693
  content.push({
2648
2694
  type: "tool-result",
2649
2695
  toolCallId: part.id,
2650
- toolName: "web_search_preview",
2696
+ toolName: webSearchToolName != null ? webSearchToolName : "web_search",
2651
2697
  result: { status: part.status },
2652
2698
  providerExecuted: true
2653
2699
  });
@@ -2695,6 +2741,28 @@ var OpenAIResponsesLanguageModel = class {
2695
2741
  });
2696
2742
  break;
2697
2743
  }
2744
+ case "code_interpreter_call": {
2745
+ content.push({
2746
+ type: "tool-call",
2747
+ toolCallId: part.id,
2748
+ toolName: "code_interpreter",
2749
+ input: JSON.stringify({
2750
+ code: part.code,
2751
+ containerId: part.container_id
2752
+ }),
2753
+ providerExecuted: true
2754
+ });
2755
+ content.push({
2756
+ type: "tool-result",
2757
+ toolCallId: part.id,
2758
+ toolName: "code_interpreter",
2759
+ result: {
2760
+ outputs: part.outputs
2761
+ },
2762
+ providerExecuted: true
2763
+ });
2764
+ break;
2765
+ }
2698
2766
  }
2699
2767
  }
2700
2768
  const providerMetadata = {
@@ -2732,7 +2800,11 @@ var OpenAIResponsesLanguageModel = class {
2732
2800
  };
2733
2801
  }
2734
2802
  async doStream(options) {
2735
- const { args: body, warnings } = await this.getArgs(options);
2803
+ const {
2804
+ args: body,
2805
+ warnings,
2806
+ webSearchToolName
2807
+ } = await this.getArgs(options);
2736
2808
  const { responseHeaders, value: response } = await (0, import_provider_utils13.postJsonToApi)({
2737
2809
  url: this.config.url({
2738
2810
  path: "/responses",
@@ -2793,13 +2865,13 @@ var OpenAIResponsesLanguageModel = class {
2793
2865
  });
2794
2866
  } else if (value.item.type === "web_search_call") {
2795
2867
  ongoingToolCalls[value.output_index] = {
2796
- toolName: "web_search_preview",
2868
+ toolName: webSearchToolName != null ? webSearchToolName : "web_search",
2797
2869
  toolCallId: value.item.id
2798
2870
  };
2799
2871
  controller.enqueue({
2800
2872
  type: "tool-input-start",
2801
2873
  id: value.item.id,
2802
- toolName: "web_search_preview"
2874
+ toolName: webSearchToolName != null ? webSearchToolName : "web_search"
2803
2875
  });
2804
2876
  } else if (value.item.type === "computer_call") {
2805
2877
  ongoingToolCalls[value.output_index] = {
@@ -2934,6 +3006,26 @@ var OpenAIResponsesLanguageModel = class {
2934
3006
  },
2935
3007
  providerExecuted: true
2936
3008
  });
3009
+ } else if (value.item.type === "code_interpreter_call") {
3010
+ controller.enqueue({
3011
+ type: "tool-call",
3012
+ toolCallId: value.item.id,
3013
+ toolName: "code_interpreter",
3014
+ input: JSON.stringify({
3015
+ code: value.item.code,
3016
+ containerId: value.item.container_id
3017
+ }),
3018
+ providerExecuted: true
3019
+ });
3020
+ controller.enqueue({
3021
+ type: "tool-result",
3022
+ toolCallId: value.item.id,
3023
+ toolName: "code_interpreter",
3024
+ result: {
3025
+ outputs: value.item.outputs
3026
+ },
3027
+ providerExecuted: true
3028
+ });
2937
3029
  } else if (value.item.type === "message") {
2938
3030
  controller.enqueue({
2939
3031
  type: "text-end",
@@ -3179,6 +3271,7 @@ var responseOutputItemDoneSchema = import_v414.z.object({
3179
3271
  arguments: import_v414.z.string(),
3180
3272
  status: import_v414.z.literal("completed")
3181
3273
  }),
3274
+ codeInterpreterCallItem,
3182
3275
  webSearchCallItem,
3183
3276
  import_v414.z.object({
3184
3277
  type: import_v414.z.literal("computer_call"),