@ai-sdk/openai 2.0.28 → 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,11 @@
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
+
3
9
  ## 2.0.28
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -57,17 +57,6 @@ declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFa
57
57
  };
58
58
  }>;
59
59
 
60
- declare const codeInterpreterToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
61
- /**
62
- * The code interpreter container.
63
- * Can be a container ID
64
- * or an object that specifies uploaded file IDs to make available to your code.
65
- */
66
- container?: string | {
67
- fileIds?: string[];
68
- };
69
- }>;
70
-
71
60
  declare const openaiTools: {
72
61
  /**
73
62
  * The Code Interpreter tool allows models to write and run Python code in a
@@ -78,7 +67,22 @@ declare const openaiTools: {
78
67
  *
79
68
  * Must have name `code_interpreter`.
80
69
  */
81
- codeInterpreter: (args?: Parameters<typeof codeInterpreterToolFactory>[0]) => _ai_sdk_provider_utils.Tool<{}, unknown>;
70
+ codeInterpreter: (args?: {
71
+ container?: string | {
72
+ fileIds?: string[];
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;
85
+ }>;
82
86
  /**
83
87
  * File search is a tool available in the Responses API. It enables models to
84
88
  * retrieve information in a knowledge base of previously uploaded files through
package/dist/index.d.ts CHANGED
@@ -57,17 +57,6 @@ declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFa
57
57
  };
58
58
  }>;
59
59
 
60
- declare const codeInterpreterToolFactory: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {
61
- /**
62
- * The code interpreter container.
63
- * Can be a container ID
64
- * or an object that specifies uploaded file IDs to make available to your code.
65
- */
66
- container?: string | {
67
- fileIds?: string[];
68
- };
69
- }>;
70
-
71
60
  declare const openaiTools: {
72
61
  /**
73
62
  * The Code Interpreter tool allows models to write and run Python code in a
@@ -78,7 +67,22 @@ declare const openaiTools: {
78
67
  *
79
68
  * Must have name `code_interpreter`.
80
69
  */
81
- codeInterpreter: (args?: Parameters<typeof codeInterpreterToolFactory>[0]) => _ai_sdk_provider_utils.Tool<{}, unknown>;
70
+ codeInterpreter: (args?: {
71
+ container?: string | {
72
+ fileIds?: string[];
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;
85
+ }>;
82
86
  /**
83
87
  * File search is a tool available in the Responses API. It enables models to
84
88
  * retrieve information in a knowledge base of previously uploaded files through
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,10 +1819,11 @@ var codeInterpreterArgsSchema = import_v411.z.object({
1807
1819
  })
1808
1820
  ]).optional()
1809
1821
  });
1810
- var codeInterpreterToolFactory = (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
  });
1815
1828
  var codeInterpreter = (args = {}) => {
1816
1829
  return codeInterpreterToolFactory(args);
@@ -2249,6 +2262,18 @@ var webSearchCallItem = import_v414.z.object({
2249
2262
  })
2250
2263
  ]).nullish()
2251
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
+ });
2252
2277
  var TOP_LOGPROBS_MAX = 20;
2253
2278
  var LOGPROBS_SCHEMA = import_v414.z.array(
2254
2279
  import_v414.z.object({
@@ -2290,7 +2315,7 @@ var OpenAIResponsesLanguageModel = class {
2290
2315
  toolChoice,
2291
2316
  responseFormat
2292
2317
  }) {
2293
- var _a, _b, _c;
2318
+ var _a, _b, _c, _d;
2294
2319
  const warnings = [];
2295
2320
  const modelConfig = getResponsesModelConfig(this.modelId);
2296
2321
  if (topK != null) {
@@ -2333,6 +2358,10 @@ var OpenAIResponsesLanguageModel = class {
2333
2358
  (tool) => tool.type === "provider-defined" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
2334
2359
  )) == null ? void 0 : _b.name;
2335
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;
2336
2365
  const baseArgs = {
2337
2366
  model: this.modelId,
2338
2367
  input: messages,
@@ -2345,7 +2374,7 @@ var OpenAIResponsesLanguageModel = class {
2345
2374
  format: responseFormat.schema != null ? {
2346
2375
  type: "json_schema",
2347
2376
  strict: strictJsonSchema,
2348
- name: (_c = responseFormat.name) != null ? _c : "response",
2377
+ name: (_d = responseFormat.name) != null ? _d : "response",
2349
2378
  description: responseFormat.description,
2350
2379
  schema: responseFormat.schema
2351
2380
  } : { type: "json_object" }
@@ -2516,9 +2545,7 @@ var OpenAIResponsesLanguageModel = class {
2516
2545
  })
2517
2546
  )
2518
2547
  }),
2519
- import_v414.z.object({
2520
- type: import_v414.z.literal("code_interpreter_call")
2521
- }),
2548
+ codeInterpreterCallItem,
2522
2549
  import_v414.z.object({
2523
2550
  type: import_v414.z.literal("function_call"),
2524
2551
  call_id: import_v414.z.string(),
@@ -2714,6 +2741,28 @@ var OpenAIResponsesLanguageModel = class {
2714
2741
  });
2715
2742
  break;
2716
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
+ }
2717
2766
  }
2718
2767
  }
2719
2768
  const providerMetadata = {
@@ -2957,6 +3006,26 @@ var OpenAIResponsesLanguageModel = class {
2957
3006
  },
2958
3007
  providerExecuted: true
2959
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
+ });
2960
3029
  } else if (value.item.type === "message") {
2961
3030
  controller.enqueue({
2962
3031
  type: "text-end",
@@ -3202,6 +3271,7 @@ var responseOutputItemDoneSchema = import_v414.z.object({
3202
3271
  arguments: import_v414.z.string(),
3203
3272
  status: import_v414.z.literal("completed")
3204
3273
  }),
3274
+ codeInterpreterCallItem,
3205
3275
  webSearchCallItem,
3206
3276
  import_v414.z.object({
3207
3277
  type: import_v414.z.literal("computer_call"),