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

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.
@@ -288,7 +288,7 @@ var openaiProviderOptions = z.object({
288
288
  /**
289
289
  * Whether to use strict JSON schema validation.
290
290
  *
291
- * @default true
291
+ * @default false
292
292
  */
293
293
  strictJsonSchema: z.boolean().optional()
294
294
  });
@@ -2676,6 +2676,7 @@ var OpenAIResponsesLanguageModel = class {
2676
2676
  let responseId = null;
2677
2677
  const ongoingToolCalls = {};
2678
2678
  let hasToolCalls = false;
2679
+ const activeReasoning = {};
2679
2680
  return {
2680
2681
  stream: response.pipeThrough(
2681
2682
  new TransformStream({
@@ -2683,7 +2684,7 @@ var OpenAIResponsesLanguageModel = class {
2683
2684
  controller.enqueue({ type: "stream-start", warnings });
2684
2685
  },
2685
2686
  transform(chunk, controller) {
2686
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2687
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2687
2688
  if (options.includeRawChunks) {
2688
2689
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2689
2690
  }
@@ -2729,10 +2730,14 @@ var OpenAIResponsesLanguageModel = class {
2729
2730
  type: "text-start",
2730
2731
  id: value.item.id
2731
2732
  });
2732
- } else if (value.item.type === "reasoning") {
2733
+ } else if (isResponseOutputItemAddedReasoningChunk(value)) {
2734
+ activeReasoning[value.item.id] = {
2735
+ encryptedContent: value.item.encrypted_content,
2736
+ summaryParts: [0]
2737
+ };
2733
2738
  controller.enqueue({
2734
2739
  type: "reasoning-start",
2735
- id: value.item.id,
2740
+ id: `${value.item.id}:0`,
2736
2741
  providerMetadata: {
2737
2742
  openai: {
2738
2743
  reasoning: {
@@ -2810,19 +2815,23 @@ var OpenAIResponsesLanguageModel = class {
2810
2815
  type: "text-end",
2811
2816
  id: value.item.id
2812
2817
  });
2813
- } else if (value.item.type === "reasoning") {
2814
- controller.enqueue({
2815
- type: "reasoning-end",
2816
- id: value.item.id,
2817
- providerMetadata: {
2818
- openai: {
2819
- reasoning: {
2820
- id: value.item.id,
2821
- encryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
2818
+ } else if (isResponseOutputItemDoneReasoningChunk(value)) {
2819
+ const activeReasoningPart = activeReasoning[value.item.id];
2820
+ for (const summaryIndex of activeReasoningPart.summaryParts) {
2821
+ controller.enqueue({
2822
+ type: "reasoning-end",
2823
+ id: `${value.item.id}:${summaryIndex}`,
2824
+ providerMetadata: {
2825
+ openai: {
2826
+ reasoning: {
2827
+ id: value.item.id,
2828
+ encryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
2829
+ }
2822
2830
  }
2823
2831
  }
2824
- }
2825
- });
2832
+ });
2833
+ }
2834
+ delete activeReasoning[value.item.id];
2826
2835
  }
2827
2836
  } else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
2828
2837
  const toolCall = ongoingToolCalls[value.output_index];
@@ -2847,27 +2856,52 @@ var OpenAIResponsesLanguageModel = class {
2847
2856
  id: value.item_id,
2848
2857
  delta: value.delta
2849
2858
  });
2859
+ } else if (isResponseReasoningSummaryPartAddedChunk(value)) {
2860
+ if (value.summary_index > 0) {
2861
+ (_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
2862
+ value.summary_index
2863
+ );
2864
+ controller.enqueue({
2865
+ type: "reasoning-start",
2866
+ id: `${value.item_id}:${value.summary_index}`,
2867
+ providerMetadata: {
2868
+ openai: {
2869
+ reasoning: {
2870
+ id: value.item_id,
2871
+ encryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
2872
+ }
2873
+ }
2874
+ }
2875
+ });
2876
+ }
2850
2877
  } else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
2851
2878
  controller.enqueue({
2852
2879
  type: "reasoning-delta",
2853
- id: value.item_id,
2854
- delta: value.delta
2880
+ id: `${value.item_id}:${value.summary_index}`,
2881
+ delta: value.delta,
2882
+ providerMetadata: {
2883
+ openai: {
2884
+ reasoning: {
2885
+ id: value.item_id
2886
+ }
2887
+ }
2888
+ }
2855
2889
  });
2856
2890
  } else if (isResponseFinishedChunk(value)) {
2857
2891
  finishReason = mapOpenAIResponseFinishReason({
2858
- finishReason: (_c = value.response.incomplete_details) == null ? void 0 : _c.reason,
2892
+ finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
2859
2893
  hasToolCalls
2860
2894
  });
2861
2895
  usage.inputTokens = value.response.usage.input_tokens;
2862
2896
  usage.outputTokens = value.response.usage.output_tokens;
2863
2897
  usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
2864
- usage.reasoningTokens = (_e = (_d = value.response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : void 0;
2865
- usage.cachedInputTokens = (_g = (_f = value.response.usage.input_tokens_details) == null ? void 0 : _f.cached_tokens) != null ? _g : void 0;
2898
+ usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
2899
+ usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
2866
2900
  } else if (isResponseAnnotationAddedChunk(value)) {
2867
2901
  controller.enqueue({
2868
2902
  type: "source",
2869
2903
  sourceType: "url",
2870
- id: (_j = (_i = (_h = self.config).generateId) == null ? void 0 : _i.call(_h)) != null ? _j : generateId2(),
2904
+ id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : generateId2(),
2871
2905
  url: value.annotation.url,
2872
2906
  title: value.annotation.title
2873
2907
  });
@@ -2938,13 +2972,7 @@ var responseOutputItemAddedSchema = z15.object({
2938
2972
  z15.object({
2939
2973
  type: z15.literal("reasoning"),
2940
2974
  id: z15.string(),
2941
- encrypted_content: z15.string().nullish(),
2942
- summary: z15.array(
2943
- z15.object({
2944
- type: z15.literal("summary_text"),
2945
- text: z15.string()
2946
- })
2947
- )
2975
+ encrypted_content: z15.string().nullish()
2948
2976
  }),
2949
2977
  z15.object({
2950
2978
  type: z15.literal("function_call"),
@@ -2976,13 +3004,7 @@ var responseOutputItemDoneSchema = z15.object({
2976
3004
  z15.object({
2977
3005
  type: z15.literal("reasoning"),
2978
3006
  id: z15.string(),
2979
- encrypted_content: z15.string().nullish(),
2980
- summary: z15.array(
2981
- z15.object({
2982
- type: z15.literal("summary_text"),
2983
- text: z15.string()
2984
- })
2985
- )
3007
+ encrypted_content: z15.string().nullish()
2986
3008
  }),
2987
3009
  z15.object({
2988
3010
  type: z15.literal("function_call"),
@@ -3018,9 +3040,15 @@ var responseAnnotationAddedSchema = z15.object({
3018
3040
  title: z15.string()
3019
3041
  })
3020
3042
  });
3043
+ var responseReasoningSummaryPartAddedSchema = z15.object({
3044
+ type: z15.literal("response.reasoning_summary_part.added"),
3045
+ item_id: z15.string(),
3046
+ summary_index: z15.number()
3047
+ });
3021
3048
  var responseReasoningSummaryTextDeltaSchema = z15.object({
3022
3049
  type: z15.literal("response.reasoning_summary_text.delta"),
3023
3050
  item_id: z15.string(),
3051
+ summary_index: z15.number(),
3024
3052
  delta: z15.string()
3025
3053
  });
3026
3054
  var openaiResponsesChunkSchema = z15.union([
@@ -3031,6 +3059,7 @@ var openaiResponsesChunkSchema = z15.union([
3031
3059
  responseOutputItemDoneSchema,
3032
3060
  responseFunctionCallArgumentsDeltaSchema,
3033
3061
  responseAnnotationAddedSchema,
3062
+ responseReasoningSummaryPartAddedSchema,
3034
3063
  responseReasoningSummaryTextDeltaSchema,
3035
3064
  errorChunkSchema,
3036
3065
  z15.object({ type: z15.string() }).loose()
@@ -3042,6 +3071,9 @@ function isTextDeltaChunk(chunk) {
3042
3071
  function isResponseOutputItemDoneChunk(chunk) {
3043
3072
  return chunk.type === "response.output_item.done";
3044
3073
  }
3074
+ function isResponseOutputItemDoneReasoningChunk(chunk) {
3075
+ return isResponseOutputItemDoneChunk(chunk) && chunk.item.type === "reasoning";
3076
+ }
3045
3077
  function isResponseFinishedChunk(chunk) {
3046
3078
  return chunk.type === "response.completed" || chunk.type === "response.incomplete";
3047
3079
  }
@@ -3054,9 +3086,15 @@ function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
3054
3086
  function isResponseOutputItemAddedChunk(chunk) {
3055
3087
  return chunk.type === "response.output_item.added";
3056
3088
  }
3089
+ function isResponseOutputItemAddedReasoningChunk(chunk) {
3090
+ return isResponseOutputItemAddedChunk(chunk) && chunk.item.type === "reasoning";
3091
+ }
3057
3092
  function isResponseAnnotationAddedChunk(chunk) {
3058
3093
  return chunk.type === "response.output_text.annotation.added";
3059
3094
  }
3095
+ function isResponseReasoningSummaryPartAddedChunk(chunk) {
3096
+ return chunk.type === "response.reasoning_summary_part.added";
3097
+ }
3060
3098
  function isResponseReasoningSummaryTextDeltaChunk(chunk) {
3061
3099
  return chunk.type === "response.reasoning_summary_text.delta";
3062
3100
  }