@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.
@@ -2381,8 +2381,20 @@ import {
2381
2381
  } from "@ai-sdk/provider";
2382
2382
 
2383
2383
  // src/tool/code-interpreter.ts
2384
- import { createProviderDefinedToolFactory as createProviderDefinedToolFactory3 } from "@ai-sdk/provider-utils";
2384
+ import { createProviderDefinedToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils";
2385
2385
  import { z as z15 } from "zod/v4";
2386
+ var codeInterpreterInputSchema = z15.object({
2387
+ code: z15.string().nullish(),
2388
+ containerId: z15.string()
2389
+ });
2390
+ var codeInterpreterOutputSchema = z15.object({
2391
+ outputs: z15.array(
2392
+ z15.discriminatedUnion("type", [
2393
+ z15.object({ type: z15.literal("logs"), logs: z15.string() }),
2394
+ z15.object({ type: z15.literal("image"), url: z15.string() })
2395
+ ])
2396
+ ).nullish()
2397
+ });
2386
2398
  var codeInterpreterArgsSchema = z15.object({
2387
2399
  container: z15.union([
2388
2400
  z15.string(),
@@ -2391,14 +2403,15 @@ var codeInterpreterArgsSchema = z15.object({
2391
2403
  })
2392
2404
  ]).optional()
2393
2405
  });
2394
- var codeInterpreter = createProviderDefinedToolFactory3({
2406
+ var codeInterpreterToolFactory = createProviderDefinedToolFactoryWithOutputSchema({
2395
2407
  id: "openai.code_interpreter",
2396
2408
  name: "code_interpreter",
2397
- inputSchema: z15.object({})
2409
+ inputSchema: codeInterpreterInputSchema,
2410
+ outputSchema: codeInterpreterOutputSchema
2398
2411
  });
2399
2412
 
2400
2413
  // src/tool/web-search.ts
2401
- import { createProviderDefinedToolFactory as createProviderDefinedToolFactory4 } from "@ai-sdk/provider-utils";
2414
+ import { createProviderDefinedToolFactory as createProviderDefinedToolFactory3 } from "@ai-sdk/provider-utils";
2402
2415
  import { z as z16 } from "zod/v4";
2403
2416
  var webSearchArgsSchema = z16.object({
2404
2417
  filters: z16.object({
@@ -2413,7 +2426,7 @@ var webSearchArgsSchema = z16.object({
2413
2426
  timezone: z16.string().optional()
2414
2427
  }).optional()
2415
2428
  });
2416
- var factory = createProviderDefinedToolFactory4({
2429
+ var webSearchToolFactory = createProviderDefinedToolFactory3({
2417
2430
  id: "openai.web_search",
2418
2431
  name: "web_search",
2419
2432
  inputSchema: z16.object({
@@ -2555,6 +2568,18 @@ var webSearchCallItem = z17.object({
2555
2568
  })
2556
2569
  ]).nullish()
2557
2570
  });
2571
+ var codeInterpreterCallItem = z17.object({
2572
+ type: z17.literal("code_interpreter_call"),
2573
+ id: z17.string(),
2574
+ code: z17.string().nullable(),
2575
+ container_id: z17.string(),
2576
+ outputs: z17.array(
2577
+ z17.discriminatedUnion("type", [
2578
+ z17.object({ type: z17.literal("logs"), logs: z17.string() }),
2579
+ z17.object({ type: z17.literal("image"), url: z17.string() })
2580
+ ])
2581
+ ).nullable()
2582
+ });
2558
2583
  var TOP_LOGPROBS_MAX = 20;
2559
2584
  var LOGPROBS_SCHEMA = z17.array(
2560
2585
  z17.object({
@@ -2596,7 +2621,7 @@ var OpenAIResponsesLanguageModel = class {
2596
2621
  toolChoice,
2597
2622
  responseFormat
2598
2623
  }) {
2599
- var _a, _b;
2624
+ var _a, _b, _c, _d;
2600
2625
  const warnings = [];
2601
2626
  const modelConfig = getResponsesModelConfig(this.modelId);
2602
2627
  if (topK != null) {
@@ -2632,8 +2657,17 @@ var OpenAIResponsesLanguageModel = class {
2632
2657
  schema: openaiResponsesProviderOptionsSchema
2633
2658
  });
2634
2659
  const strictJsonSchema = (_a = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _a : false;
2660
+ let include = openaiOptions == null ? void 0 : openaiOptions.include;
2635
2661
  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;
2636
- 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;
2662
+ include = topLogprobs ? Array.isArray(include) ? [...include, "message.output_text.logprobs"] : ["message.output_text.logprobs"] : include;
2663
+ const webSearchToolName = (_b = tools == null ? void 0 : tools.find(
2664
+ (tool) => tool.type === "provider-defined" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
2665
+ )) == null ? void 0 : _b.name;
2666
+ include = webSearchToolName ? Array.isArray(include) ? [...include, "web_search_call.action.sources"] : ["web_search_call.action.sources"] : include;
2667
+ const codeInterpreterToolName = (_c = tools == null ? void 0 : tools.find(
2668
+ (tool) => tool.type === "provider-defined" && tool.id === "openai.code_interpreter"
2669
+ )) == null ? void 0 : _c.name;
2670
+ include = codeInterpreterToolName ? Array.isArray(include) ? [...include, "code_interpreter_call.outputs"] : ["code_interpreter_call.outputs"] : include;
2637
2671
  const baseArgs = {
2638
2672
  model: this.modelId,
2639
2673
  input: messages,
@@ -2646,7 +2680,7 @@ var OpenAIResponsesLanguageModel = class {
2646
2680
  format: responseFormat.schema != null ? {
2647
2681
  type: "json_schema",
2648
2682
  strict: strictJsonSchema,
2649
- name: (_b = responseFormat.name) != null ? _b : "response",
2683
+ name: (_d = responseFormat.name) != null ? _d : "response",
2650
2684
  description: responseFormat.description,
2651
2685
  schema: responseFormat.schema
2652
2686
  } : { type: "json_object" }
@@ -2664,7 +2698,7 @@ var OpenAIResponsesLanguageModel = class {
2664
2698
  user: openaiOptions == null ? void 0 : openaiOptions.user,
2665
2699
  instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
2666
2700
  service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
2667
- include: openaiOptionsInclude,
2701
+ include,
2668
2702
  prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
2669
2703
  safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
2670
2704
  top_logprobs: topLogprobs,
@@ -2742,6 +2776,7 @@ var OpenAIResponsesLanguageModel = class {
2742
2776
  strictJsonSchema
2743
2777
  });
2744
2778
  return {
2779
+ webSearchToolName,
2745
2780
  args: {
2746
2781
  ...baseArgs,
2747
2782
  tools: openaiTools,
@@ -2752,7 +2787,11 @@ var OpenAIResponsesLanguageModel = class {
2752
2787
  }
2753
2788
  async doGenerate(options) {
2754
2789
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
2755
- const { args: body, warnings } = await this.getArgs(options);
2790
+ const {
2791
+ args: body,
2792
+ warnings,
2793
+ webSearchToolName
2794
+ } = await this.getArgs(options);
2756
2795
  const url = this.config.url({
2757
2796
  path: "/responses",
2758
2797
  modelId: this.modelId
@@ -2803,12 +2842,16 @@ var OpenAIResponsesLanguageModel = class {
2803
2842
  start_index: z17.number().nullish(),
2804
2843
  end_index: z17.number().nullish(),
2805
2844
  quote: z17.string().nullish()
2845
+ }),
2846
+ z17.object({
2847
+ type: z17.literal("container_file_citation")
2806
2848
  })
2807
2849
  ])
2808
2850
  )
2809
2851
  })
2810
2852
  )
2811
2853
  }),
2854
+ codeInterpreterCallItem,
2812
2855
  z17.object({
2813
2856
  type: z17.literal("function_call"),
2814
2857
  call_id: z17.string(),
@@ -2949,14 +2992,14 @@ var OpenAIResponsesLanguageModel = class {
2949
2992
  content.push({
2950
2993
  type: "tool-call",
2951
2994
  toolCallId: part.id,
2952
- toolName: "web_search_preview",
2995
+ toolName: webSearchToolName != null ? webSearchToolName : "web_search",
2953
2996
  input: JSON.stringify({ action: part.action }),
2954
2997
  providerExecuted: true
2955
2998
  });
2956
2999
  content.push({
2957
3000
  type: "tool-result",
2958
3001
  toolCallId: part.id,
2959
- toolName: "web_search_preview",
3002
+ toolName: webSearchToolName != null ? webSearchToolName : "web_search",
2960
3003
  result: { status: part.status },
2961
3004
  providerExecuted: true
2962
3005
  });
@@ -3004,6 +3047,28 @@ var OpenAIResponsesLanguageModel = class {
3004
3047
  });
3005
3048
  break;
3006
3049
  }
3050
+ case "code_interpreter_call": {
3051
+ content.push({
3052
+ type: "tool-call",
3053
+ toolCallId: part.id,
3054
+ toolName: "code_interpreter",
3055
+ input: JSON.stringify({
3056
+ code: part.code,
3057
+ containerId: part.container_id
3058
+ }),
3059
+ providerExecuted: true
3060
+ });
3061
+ content.push({
3062
+ type: "tool-result",
3063
+ toolCallId: part.id,
3064
+ toolName: "code_interpreter",
3065
+ result: {
3066
+ outputs: part.outputs
3067
+ },
3068
+ providerExecuted: true
3069
+ });
3070
+ break;
3071
+ }
3007
3072
  }
3008
3073
  }
3009
3074
  const providerMetadata = {
@@ -3041,7 +3106,11 @@ var OpenAIResponsesLanguageModel = class {
3041
3106
  };
3042
3107
  }
3043
3108
  async doStream(options) {
3044
- const { args: body, warnings } = await this.getArgs(options);
3109
+ const {
3110
+ args: body,
3111
+ warnings,
3112
+ webSearchToolName
3113
+ } = await this.getArgs(options);
3045
3114
  const { responseHeaders, value: response } = await postJsonToApi6({
3046
3115
  url: this.config.url({
3047
3116
  path: "/responses",
@@ -3102,13 +3171,13 @@ var OpenAIResponsesLanguageModel = class {
3102
3171
  });
3103
3172
  } else if (value.item.type === "web_search_call") {
3104
3173
  ongoingToolCalls[value.output_index] = {
3105
- toolName: "web_search_preview",
3174
+ toolName: webSearchToolName != null ? webSearchToolName : "web_search",
3106
3175
  toolCallId: value.item.id
3107
3176
  };
3108
3177
  controller.enqueue({
3109
3178
  type: "tool-input-start",
3110
3179
  id: value.item.id,
3111
- toolName: "web_search_preview"
3180
+ toolName: webSearchToolName != null ? webSearchToolName : "web_search"
3112
3181
  });
3113
3182
  } else if (value.item.type === "computer_call") {
3114
3183
  ongoingToolCalls[value.output_index] = {
@@ -3243,6 +3312,26 @@ var OpenAIResponsesLanguageModel = class {
3243
3312
  },
3244
3313
  providerExecuted: true
3245
3314
  });
3315
+ } else if (value.item.type === "code_interpreter_call") {
3316
+ controller.enqueue({
3317
+ type: "tool-call",
3318
+ toolCallId: value.item.id,
3319
+ toolName: "code_interpreter",
3320
+ input: JSON.stringify({
3321
+ code: value.item.code,
3322
+ containerId: value.item.container_id
3323
+ }),
3324
+ providerExecuted: true
3325
+ });
3326
+ controller.enqueue({
3327
+ type: "tool-result",
3328
+ toolCallId: value.item.id,
3329
+ toolName: "code_interpreter",
3330
+ result: {
3331
+ outputs: value.item.outputs
3332
+ },
3333
+ providerExecuted: true
3334
+ });
3246
3335
  } else if (value.item.type === "message") {
3247
3336
  controller.enqueue({
3248
3337
  type: "text-end",
@@ -3488,6 +3577,7 @@ var responseOutputItemDoneSchema = z17.object({
3488
3577
  arguments: z17.string(),
3489
3578
  status: z17.literal("completed")
3490
3579
  }),
3580
+ codeInterpreterCallItem,
3491
3581
  webSearchCallItem,
3492
3582
  z17.object({
3493
3583
  type: z17.literal("computer_call"),