@ai-sdk/openai 2.0.0-beta.5 → 2.0.0-beta.7

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.
@@ -314,7 +314,7 @@ var openaiProviderOptions = import_v4.z.object({
314
314
  /**
315
315
  * Whether to use strict JSON schema validation.
316
316
  *
317
- * @default true
317
+ * @default false
318
318
  */
319
319
  strictJsonSchema: import_v4.z.boolean().optional()
320
320
  });
@@ -2212,6 +2212,16 @@ function prepareResponsesTools({
2212
2212
  break;
2213
2213
  case "provider-defined":
2214
2214
  switch (tool.id) {
2215
+ case "openai.file_search": {
2216
+ const args = fileSearchArgsSchema.parse(tool.args);
2217
+ openaiTools.push({
2218
+ type: "file_search",
2219
+ vector_store_ids: args.vectorStoreIds,
2220
+ max_results: args.maxResults,
2221
+ search_type: args.searchType
2222
+ });
2223
+ break;
2224
+ }
2215
2225
  case "openai.web_search_preview":
2216
2226
  openaiTools.push({
2217
2227
  type: "web_search_preview",
@@ -2241,7 +2251,7 @@ function prepareResponsesTools({
2241
2251
  case "tool":
2242
2252
  return {
2243
2253
  tools: openaiTools,
2244
- toolChoice: toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
2254
+ toolChoice: toolChoice.toolName === "file_search" ? { type: "file_search" } : toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
2245
2255
  toolWarnings
2246
2256
  };
2247
2257
  default: {
@@ -2656,6 +2666,7 @@ var OpenAIResponsesLanguageModel = class {
2656
2666
  let responseId = null;
2657
2667
  const ongoingToolCalls = {};
2658
2668
  let hasToolCalls = false;
2669
+ const activeReasoning = {};
2659
2670
  return {
2660
2671
  stream: response.pipeThrough(
2661
2672
  new TransformStream({
@@ -2663,7 +2674,7 @@ var OpenAIResponsesLanguageModel = class {
2663
2674
  controller.enqueue({ type: "stream-start", warnings });
2664
2675
  },
2665
2676
  transform(chunk, controller) {
2666
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2677
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2667
2678
  if (options.includeRawChunks) {
2668
2679
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2669
2680
  }
@@ -2709,10 +2720,14 @@ var OpenAIResponsesLanguageModel = class {
2709
2720
  type: "text-start",
2710
2721
  id: value.item.id
2711
2722
  });
2712
- } else if (value.item.type === "reasoning") {
2723
+ } else if (isResponseOutputItemAddedReasoningChunk(value)) {
2724
+ activeReasoning[value.item.id] = {
2725
+ encryptedContent: value.item.encrypted_content,
2726
+ summaryParts: [0]
2727
+ };
2713
2728
  controller.enqueue({
2714
2729
  type: "reasoning-start",
2715
- id: value.item.id,
2730
+ id: `${value.item.id}:0`,
2716
2731
  providerMetadata: {
2717
2732
  openai: {
2718
2733
  reasoning: {
@@ -2790,19 +2805,23 @@ var OpenAIResponsesLanguageModel = class {
2790
2805
  type: "text-end",
2791
2806
  id: value.item.id
2792
2807
  });
2793
- } else if (value.item.type === "reasoning") {
2794
- controller.enqueue({
2795
- type: "reasoning-end",
2796
- id: value.item.id,
2797
- providerMetadata: {
2798
- openai: {
2799
- reasoning: {
2800
- id: value.item.id,
2801
- encryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
2808
+ } else if (isResponseOutputItemDoneReasoningChunk(value)) {
2809
+ const activeReasoningPart = activeReasoning[value.item.id];
2810
+ for (const summaryIndex of activeReasoningPart.summaryParts) {
2811
+ controller.enqueue({
2812
+ type: "reasoning-end",
2813
+ id: `${value.item.id}:${summaryIndex}`,
2814
+ providerMetadata: {
2815
+ openai: {
2816
+ reasoning: {
2817
+ id: value.item.id,
2818
+ encryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
2819
+ }
2802
2820
  }
2803
2821
  }
2804
- }
2805
- });
2822
+ });
2823
+ }
2824
+ delete activeReasoning[value.item.id];
2806
2825
  }
2807
2826
  } else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
2808
2827
  const toolCall = ongoingToolCalls[value.output_index];
@@ -2827,27 +2846,52 @@ var OpenAIResponsesLanguageModel = class {
2827
2846
  id: value.item_id,
2828
2847
  delta: value.delta
2829
2848
  });
2849
+ } else if (isResponseReasoningSummaryPartAddedChunk(value)) {
2850
+ if (value.summary_index > 0) {
2851
+ (_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
2852
+ value.summary_index
2853
+ );
2854
+ controller.enqueue({
2855
+ type: "reasoning-start",
2856
+ id: `${value.item_id}:${value.summary_index}`,
2857
+ providerMetadata: {
2858
+ openai: {
2859
+ reasoning: {
2860
+ id: value.item_id,
2861
+ encryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
2862
+ }
2863
+ }
2864
+ }
2865
+ });
2866
+ }
2830
2867
  } else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
2831
2868
  controller.enqueue({
2832
2869
  type: "reasoning-delta",
2833
- id: value.item_id,
2834
- delta: value.delta
2870
+ id: `${value.item_id}:${value.summary_index}`,
2871
+ delta: value.delta,
2872
+ providerMetadata: {
2873
+ openai: {
2874
+ reasoning: {
2875
+ id: value.item_id
2876
+ }
2877
+ }
2878
+ }
2835
2879
  });
2836
2880
  } else if (isResponseFinishedChunk(value)) {
2837
2881
  finishReason = mapOpenAIResponseFinishReason({
2838
- finishReason: (_c = value.response.incomplete_details) == null ? void 0 : _c.reason,
2882
+ finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
2839
2883
  hasToolCalls
2840
2884
  });
2841
2885
  usage.inputTokens = value.response.usage.input_tokens;
2842
2886
  usage.outputTokens = value.response.usage.output_tokens;
2843
2887
  usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
2844
- usage.reasoningTokens = (_e = (_d = value.response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : void 0;
2845
- usage.cachedInputTokens = (_g = (_f = value.response.usage.input_tokens_details) == null ? void 0 : _f.cached_tokens) != null ? _g : void 0;
2888
+ usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
2889
+ usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
2846
2890
  } else if (isResponseAnnotationAddedChunk(value)) {
2847
2891
  controller.enqueue({
2848
2892
  type: "source",
2849
2893
  sourceType: "url",
2850
- id: (_j = (_i = (_h = self.config).generateId) == null ? void 0 : _i.call(_h)) != null ? _j : (0, import_provider_utils12.generateId)(),
2894
+ id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : (0, import_provider_utils12.generateId)(),
2851
2895
  url: value.annotation.url,
2852
2896
  title: value.annotation.title
2853
2897
  });
@@ -2918,13 +2962,7 @@ var responseOutputItemAddedSchema = import_v415.z.object({
2918
2962
  import_v415.z.object({
2919
2963
  type: import_v415.z.literal("reasoning"),
2920
2964
  id: import_v415.z.string(),
2921
- encrypted_content: import_v415.z.string().nullish(),
2922
- summary: import_v415.z.array(
2923
- import_v415.z.object({
2924
- type: import_v415.z.literal("summary_text"),
2925
- text: import_v415.z.string()
2926
- })
2927
- )
2965
+ encrypted_content: import_v415.z.string().nullish()
2928
2966
  }),
2929
2967
  import_v415.z.object({
2930
2968
  type: import_v415.z.literal("function_call"),
@@ -2956,13 +2994,7 @@ var responseOutputItemDoneSchema = import_v415.z.object({
2956
2994
  import_v415.z.object({
2957
2995
  type: import_v415.z.literal("reasoning"),
2958
2996
  id: import_v415.z.string(),
2959
- encrypted_content: import_v415.z.string().nullish(),
2960
- summary: import_v415.z.array(
2961
- import_v415.z.object({
2962
- type: import_v415.z.literal("summary_text"),
2963
- text: import_v415.z.string()
2964
- })
2965
- )
2997
+ encrypted_content: import_v415.z.string().nullish()
2966
2998
  }),
2967
2999
  import_v415.z.object({
2968
3000
  type: import_v415.z.literal("function_call"),
@@ -2998,9 +3030,15 @@ var responseAnnotationAddedSchema = import_v415.z.object({
2998
3030
  title: import_v415.z.string()
2999
3031
  })
3000
3032
  });
3033
+ var responseReasoningSummaryPartAddedSchema = import_v415.z.object({
3034
+ type: import_v415.z.literal("response.reasoning_summary_part.added"),
3035
+ item_id: import_v415.z.string(),
3036
+ summary_index: import_v415.z.number()
3037
+ });
3001
3038
  var responseReasoningSummaryTextDeltaSchema = import_v415.z.object({
3002
3039
  type: import_v415.z.literal("response.reasoning_summary_text.delta"),
3003
3040
  item_id: import_v415.z.string(),
3041
+ summary_index: import_v415.z.number(),
3004
3042
  delta: import_v415.z.string()
3005
3043
  });
3006
3044
  var openaiResponsesChunkSchema = import_v415.z.union([
@@ -3011,6 +3049,7 @@ var openaiResponsesChunkSchema = import_v415.z.union([
3011
3049
  responseOutputItemDoneSchema,
3012
3050
  responseFunctionCallArgumentsDeltaSchema,
3013
3051
  responseAnnotationAddedSchema,
3052
+ responseReasoningSummaryPartAddedSchema,
3014
3053
  responseReasoningSummaryTextDeltaSchema,
3015
3054
  errorChunkSchema,
3016
3055
  import_v415.z.object({ type: import_v415.z.string() }).loose()
@@ -3022,6 +3061,9 @@ function isTextDeltaChunk(chunk) {
3022
3061
  function isResponseOutputItemDoneChunk(chunk) {
3023
3062
  return chunk.type === "response.output_item.done";
3024
3063
  }
3064
+ function isResponseOutputItemDoneReasoningChunk(chunk) {
3065
+ return isResponseOutputItemDoneChunk(chunk) && chunk.item.type === "reasoning";
3066
+ }
3025
3067
  function isResponseFinishedChunk(chunk) {
3026
3068
  return chunk.type === "response.completed" || chunk.type === "response.incomplete";
3027
3069
  }
@@ -3034,9 +3076,15 @@ function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
3034
3076
  function isResponseOutputItemAddedChunk(chunk) {
3035
3077
  return chunk.type === "response.output_item.added";
3036
3078
  }
3079
+ function isResponseOutputItemAddedReasoningChunk(chunk) {
3080
+ return isResponseOutputItemAddedChunk(chunk) && chunk.item.type === "reasoning";
3081
+ }
3037
3082
  function isResponseAnnotationAddedChunk(chunk) {
3038
3083
  return chunk.type === "response.output_text.annotation.added";
3039
3084
  }
3085
+ function isResponseReasoningSummaryPartAddedChunk(chunk) {
3086
+ return chunk.type === "response.reasoning_summary_part.added";
3087
+ }
3040
3088
  function isResponseReasoningSummaryTextDeltaChunk(chunk) {
3041
3089
  return chunk.type === "response.reasoning_summary_text.delta";
3042
3090
  }