@ai-sdk/openai 2.0.28 → 2.0.30

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/dist/index.mjs CHANGED
@@ -1807,8 +1807,20 @@ var openaiImageResponseSchema = z10.object({
1807
1807
  });
1808
1808
 
1809
1809
  // src/tool/code-interpreter.ts
1810
- import { createProviderDefinedToolFactory as createProviderDefinedToolFactory3 } from "@ai-sdk/provider-utils";
1810
+ import { createProviderDefinedToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils";
1811
1811
  import { z as z11 } from "zod/v4";
1812
+ var codeInterpreterInputSchema = z11.object({
1813
+ code: z11.string().nullish(),
1814
+ containerId: z11.string()
1815
+ });
1816
+ var codeInterpreterOutputSchema = z11.object({
1817
+ outputs: z11.array(
1818
+ z11.discriminatedUnion("type", [
1819
+ z11.object({ type: z11.literal("logs"), logs: z11.string() }),
1820
+ z11.object({ type: z11.literal("image"), url: z11.string() })
1821
+ ])
1822
+ ).nullish()
1823
+ });
1812
1824
  var codeInterpreterArgsSchema = z11.object({
1813
1825
  container: z11.union([
1814
1826
  z11.string(),
@@ -1817,17 +1829,18 @@ var codeInterpreterArgsSchema = z11.object({
1817
1829
  })
1818
1830
  ]).optional()
1819
1831
  });
1820
- var codeInterpreterToolFactory = createProviderDefinedToolFactory3({
1832
+ var codeInterpreterToolFactory = createProviderDefinedToolFactoryWithOutputSchema({
1821
1833
  id: "openai.code_interpreter",
1822
1834
  name: "code_interpreter",
1823
- inputSchema: z11.object({})
1835
+ inputSchema: codeInterpreterInputSchema,
1836
+ outputSchema: codeInterpreterOutputSchema
1824
1837
  });
1825
1838
  var codeInterpreter = (args = {}) => {
1826
1839
  return codeInterpreterToolFactory(args);
1827
1840
  };
1828
1841
 
1829
1842
  // src/tool/web-search.ts
1830
- import { createProviderDefinedToolFactory as createProviderDefinedToolFactory4 } from "@ai-sdk/provider-utils";
1843
+ import { createProviderDefinedToolFactory as createProviderDefinedToolFactory3 } from "@ai-sdk/provider-utils";
1831
1844
  import { z as z12 } from "zod/v4";
1832
1845
  var webSearchArgsSchema = z12.object({
1833
1846
  filters: z12.object({
@@ -1842,7 +1855,7 @@ var webSearchArgsSchema = z12.object({
1842
1855
  timezone: z12.string().optional()
1843
1856
  }).optional()
1844
1857
  });
1845
- var webSearchToolFactory = createProviderDefinedToolFactory4({
1858
+ var webSearchToolFactory = createProviderDefinedToolFactory3({
1846
1859
  id: "openai.web_search",
1847
1860
  name: "web_search",
1848
1861
  inputSchema: z12.object({
@@ -1931,35 +1944,34 @@ import {
1931
1944
  } from "@ai-sdk/provider-utils";
1932
1945
  import { z as z14 } from "zod/v4";
1933
1946
 
1934
- // src/responses/convert-to-openai-responses-messages.ts
1947
+ // src/responses/convert-to-openai-responses-input.ts
1935
1948
  import {
1936
1949
  UnsupportedFunctionalityError as UnsupportedFunctionalityError4
1937
1950
  } from "@ai-sdk/provider";
1938
- import { parseProviderOptions as parseProviderOptions4 } from "@ai-sdk/provider-utils";
1951
+ import { convertToBase64 as convertToBase642, parseProviderOptions as parseProviderOptions4 } from "@ai-sdk/provider-utils";
1939
1952
  import { z as z13 } from "zod/v4";
1940
- import { convertToBase64 as convertToBase642 } from "@ai-sdk/provider-utils";
1941
1953
  function isFileId(data, prefixes) {
1942
1954
  if (!prefixes) return false;
1943
1955
  return prefixes.some((prefix) => data.startsWith(prefix));
1944
1956
  }
1945
- async function convertToOpenAIResponsesMessages({
1957
+ async function convertToOpenAIResponsesInput({
1946
1958
  prompt,
1947
1959
  systemMessageMode,
1948
1960
  fileIdPrefixes
1949
1961
  }) {
1950
1962
  var _a, _b, _c, _d, _e, _f;
1951
- const messages = [];
1963
+ const input = [];
1952
1964
  const warnings = [];
1953
1965
  for (const { role, content } of prompt) {
1954
1966
  switch (role) {
1955
1967
  case "system": {
1956
1968
  switch (systemMessageMode) {
1957
1969
  case "system": {
1958
- messages.push({ role: "system", content });
1970
+ input.push({ role: "system", content });
1959
1971
  break;
1960
1972
  }
1961
1973
  case "developer": {
1962
- messages.push({ role: "developer", content });
1974
+ input.push({ role: "developer", content });
1963
1975
  break;
1964
1976
  }
1965
1977
  case "remove": {
@@ -1979,7 +1991,7 @@ async function convertToOpenAIResponsesMessages({
1979
1991
  break;
1980
1992
  }
1981
1993
  case "user": {
1982
- messages.push({
1994
+ input.push({
1983
1995
  role: "user",
1984
1996
  content: content.map((part, index) => {
1985
1997
  var _a2, _b2, _c2;
@@ -2024,10 +2036,11 @@ async function convertToOpenAIResponsesMessages({
2024
2036
  }
2025
2037
  case "assistant": {
2026
2038
  const reasoningMessages = {};
2039
+ const toolCallParts = {};
2027
2040
  for (const part of content) {
2028
2041
  switch (part.type) {
2029
2042
  case "text": {
2030
- messages.push({
2043
+ input.push({
2031
2044
  role: "assistant",
2032
2045
  content: [{ type: "output_text", text: part.text }],
2033
2046
  id: (_c = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.itemId) != null ? _c : void 0
@@ -2035,10 +2048,11 @@ async function convertToOpenAIResponsesMessages({
2035
2048
  break;
2036
2049
  }
2037
2050
  case "tool-call": {
2051
+ toolCallParts[part.toolCallId] = part;
2038
2052
  if (part.providerExecuted) {
2039
2053
  break;
2040
2054
  }
2041
- messages.push({
2055
+ input.push({
2042
2056
  type: "function_call",
2043
2057
  call_id: part.toolCallId,
2044
2058
  name: part.toolName,
@@ -2079,7 +2093,7 @@ async function convertToOpenAIResponsesMessages({
2079
2093
  encrypted_content: providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent,
2080
2094
  summary: summaryParts
2081
2095
  };
2082
- messages.push(reasoningMessages[reasoningId]);
2096
+ input.push(reasoningMessages[reasoningId]);
2083
2097
  } else {
2084
2098
  existingReasoningMessage.summary.push(...summaryParts);
2085
2099
  }
@@ -2110,7 +2124,7 @@ async function convertToOpenAIResponsesMessages({
2110
2124
  contentValue = JSON.stringify(output.value);
2111
2125
  break;
2112
2126
  }
2113
- messages.push({
2127
+ input.push({
2114
2128
  type: "function_call_output",
2115
2129
  call_id: part.toolCallId,
2116
2130
  output: contentValue
@@ -2124,7 +2138,7 @@ async function convertToOpenAIResponsesMessages({
2124
2138
  }
2125
2139
  }
2126
2140
  }
2127
- return { messages, warnings };
2141
+ return { input, warnings };
2128
2142
  }
2129
2143
  var openaiResponsesReasoningProviderOptionsSchema = z13.object({
2130
2144
  itemId: z13.string().nullish(),
@@ -2272,6 +2286,18 @@ var webSearchCallItem = z14.object({
2272
2286
  })
2273
2287
  ]).nullish()
2274
2288
  });
2289
+ var codeInterpreterCallItem = z14.object({
2290
+ type: z14.literal("code_interpreter_call"),
2291
+ id: z14.string(),
2292
+ code: z14.string().nullable(),
2293
+ container_id: z14.string(),
2294
+ outputs: z14.array(
2295
+ z14.discriminatedUnion("type", [
2296
+ z14.object({ type: z14.literal("logs"), logs: z14.string() }),
2297
+ z14.object({ type: z14.literal("image"), url: z14.string() })
2298
+ ])
2299
+ ).nullable()
2300
+ });
2275
2301
  var TOP_LOGPROBS_MAX = 20;
2276
2302
  var LOGPROBS_SCHEMA = z14.array(
2277
2303
  z14.object({
@@ -2313,7 +2339,7 @@ var OpenAIResponsesLanguageModel = class {
2313
2339
  toolChoice,
2314
2340
  responseFormat
2315
2341
  }) {
2316
- var _a, _b, _c;
2342
+ var _a, _b, _c, _d;
2317
2343
  const warnings = [];
2318
2344
  const modelConfig = getResponsesModelConfig(this.modelId);
2319
2345
  if (topK != null) {
@@ -2337,12 +2363,12 @@ var OpenAIResponsesLanguageModel = class {
2337
2363
  if (stopSequences != null) {
2338
2364
  warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
2339
2365
  }
2340
- const { messages, warnings: messageWarnings } = await convertToOpenAIResponsesMessages({
2366
+ const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
2341
2367
  prompt,
2342
2368
  systemMessageMode: modelConfig.systemMessageMode,
2343
2369
  fileIdPrefixes: this.config.fileIdPrefixes
2344
2370
  });
2345
- warnings.push(...messageWarnings);
2371
+ warnings.push(...inputWarnings);
2346
2372
  const openaiOptions = await parseProviderOptions5({
2347
2373
  provider: "openai",
2348
2374
  providerOptions,
@@ -2356,9 +2382,13 @@ var OpenAIResponsesLanguageModel = class {
2356
2382
  (tool) => tool.type === "provider-defined" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
2357
2383
  )) == null ? void 0 : _b.name;
2358
2384
  include = webSearchToolName ? Array.isArray(include) ? [...include, "web_search_call.action.sources"] : ["web_search_call.action.sources"] : include;
2385
+ const codeInterpreterToolName = (_c = tools == null ? void 0 : tools.find(
2386
+ (tool) => tool.type === "provider-defined" && tool.id === "openai.code_interpreter"
2387
+ )) == null ? void 0 : _c.name;
2388
+ include = codeInterpreterToolName ? Array.isArray(include) ? [...include, "code_interpreter_call.outputs"] : ["code_interpreter_call.outputs"] : include;
2359
2389
  const baseArgs = {
2360
2390
  model: this.modelId,
2361
- input: messages,
2391
+ input,
2362
2392
  temperature,
2363
2393
  top_p: topP,
2364
2394
  max_output_tokens: maxOutputTokens,
@@ -2368,7 +2398,7 @@ var OpenAIResponsesLanguageModel = class {
2368
2398
  format: responseFormat.schema != null ? {
2369
2399
  type: "json_schema",
2370
2400
  strict: strictJsonSchema,
2371
- name: (_c = responseFormat.name) != null ? _c : "response",
2401
+ name: (_d = responseFormat.name) != null ? _d : "response",
2372
2402
  description: responseFormat.description,
2373
2403
  schema: responseFormat.schema
2374
2404
  } : { type: "json_object" }
@@ -2539,9 +2569,7 @@ var OpenAIResponsesLanguageModel = class {
2539
2569
  })
2540
2570
  )
2541
2571
  }),
2542
- z14.object({
2543
- type: z14.literal("code_interpreter_call")
2544
- }),
2572
+ codeInterpreterCallItem,
2545
2573
  z14.object({
2546
2574
  type: z14.literal("function_call"),
2547
2575
  call_id: z14.string(),
@@ -2737,6 +2765,28 @@ var OpenAIResponsesLanguageModel = class {
2737
2765
  });
2738
2766
  break;
2739
2767
  }
2768
+ case "code_interpreter_call": {
2769
+ content.push({
2770
+ type: "tool-call",
2771
+ toolCallId: part.id,
2772
+ toolName: "code_interpreter",
2773
+ input: JSON.stringify({
2774
+ code: part.code,
2775
+ containerId: part.container_id
2776
+ }),
2777
+ providerExecuted: true
2778
+ });
2779
+ content.push({
2780
+ type: "tool-result",
2781
+ toolCallId: part.id,
2782
+ toolName: "code_interpreter",
2783
+ result: {
2784
+ outputs: part.outputs
2785
+ },
2786
+ providerExecuted: true
2787
+ });
2788
+ break;
2789
+ }
2740
2790
  }
2741
2791
  }
2742
2792
  const providerMetadata = {
@@ -2980,6 +3030,26 @@ var OpenAIResponsesLanguageModel = class {
2980
3030
  },
2981
3031
  providerExecuted: true
2982
3032
  });
3033
+ } else if (value.item.type === "code_interpreter_call") {
3034
+ controller.enqueue({
3035
+ type: "tool-call",
3036
+ toolCallId: value.item.id,
3037
+ toolName: "code_interpreter",
3038
+ input: JSON.stringify({
3039
+ code: value.item.code,
3040
+ containerId: value.item.container_id
3041
+ }),
3042
+ providerExecuted: true
3043
+ });
3044
+ controller.enqueue({
3045
+ type: "tool-result",
3046
+ toolCallId: value.item.id,
3047
+ toolName: "code_interpreter",
3048
+ result: {
3049
+ outputs: value.item.outputs
3050
+ },
3051
+ providerExecuted: true
3052
+ });
2983
3053
  } else if (value.item.type === "message") {
2984
3054
  controller.enqueue({
2985
3055
  type: "text-end",
@@ -3225,6 +3295,7 @@ var responseOutputItemDoneSchema = z14.object({
3225
3295
  arguments: z14.string(),
3226
3296
  status: z14.literal("completed")
3227
3297
  }),
3298
+ codeInterpreterCallItem,
3228
3299
  webSearchCallItem,
3229
3300
  z14.object({
3230
3301
  type: z14.literal("computer_call"),