@ai-sdk/openai 3.0.105 → 3.0.107

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.
@@ -68,6 +68,22 @@ function getGptVersion(modelId) {
68
68
 
69
69
  // src/openai-stream-error.ts
70
70
  import { APICallError } from "@ai-sdk/provider";
71
+ function createOpenAIProviderStreamError(frame) {
72
+ var _a2, _b;
73
+ const streamError = parseStreamError(frame);
74
+ if (streamError == null) {
75
+ return void 0;
76
+ }
77
+ const statusCode = getStatusCode(streamError);
78
+ return {
79
+ message: streamError.message,
80
+ type: (_a2 = streamError.type) != null ? _a2 : void 0,
81
+ code: (_b = streamError.code) != null ? _b : void 0,
82
+ statusCode,
83
+ isRetryable: isRetryableStreamError(streamError, statusCode),
84
+ data: frame
85
+ };
86
+ }
71
87
  async function throwIfOpenAIStreamErrorBeforeOutput({
72
88
  stream,
73
89
  getError,
@@ -139,16 +155,14 @@ function parseStreamError(frame) {
139
155
  return typeof (responseError == null ? void 0 : responseError.message) === "string" ? {
140
156
  message: responseError.message,
141
157
  code: getStringOrNumber(responseError.code),
142
- type: "response.failed",
143
- frame
158
+ type: "response.failed"
144
159
  } : void 0;
145
160
  }
146
161
  const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
147
162
  return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
148
163
  message: error.message,
149
164
  code: getStringOrNumber(error.code),
150
- type: typeof error.type === "string" ? error.type : void 0,
151
- frame
165
+ type: typeof error.type === "string" ? error.type : void 0
152
166
  } : void 0;
153
167
  }
154
168
  function getStatusCode(error) {
@@ -188,6 +202,15 @@ function getStringOrNumber(value) {
188
202
  function isHttpErrorStatusCode(value) {
189
203
  return Number.isInteger(value) && value >= 400 && value <= 599;
190
204
  }
205
+ function isRetryableStatusCode(statusCode) {
206
+ return statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500;
207
+ }
208
+ function isRetryableStreamError(error, statusCode) {
209
+ if (error.code === "insufficient_quota" || error.type === "insufficient_quota") {
210
+ return false;
211
+ }
212
+ return isRetryableStatusCode(statusCode);
213
+ }
191
214
 
192
215
  // src/chat/convert-openai-chat-usage.ts
193
216
  function convertOpenAIChatUsage(usage) {
@@ -3056,23 +3079,34 @@ function serializeToolCallArguments2(input) {
3056
3079
  }
3057
3080
  async function convertFunctionToolResultOutput({
3058
3081
  output,
3082
+ promptCacheBreakpoint,
3059
3083
  providerOptionsName,
3060
3084
  warnings
3061
3085
  }) {
3062
3086
  var _a2;
3087
+ const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
3088
+ {
3089
+ type: "input_text",
3090
+ text: value,
3091
+ prompt_cache_breakpoint: promptCacheBreakpoint
3092
+ }
3093
+ ];
3063
3094
  switch (output.type) {
3064
3095
  case "text":
3065
3096
  case "error-text":
3066
- return output.value;
3067
- case "execution-denied":
3068
- return (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
3097
+ return convertScalarOutput(output.value);
3098
+ case "execution-denied": {
3099
+ return convertScalarOutput(
3100
+ (_a2 = output.reason) != null ? _a2 : "Tool call execution denied."
3101
+ );
3102
+ }
3069
3103
  case "json":
3070
3104
  case "error-json":
3071
- return JSON.stringify(output.value);
3105
+ return convertScalarOutput(JSON.stringify(output.value));
3072
3106
  case "content":
3073
3107
  return output.value.map((item) => {
3074
3108
  var _a3, _b, _c, _d, _e;
3075
- const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3109
+ const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
3076
3110
  item.providerOptions,
3077
3111
  providerOptionsName
3078
3112
  );
@@ -3081,8 +3115,8 @@ async function convertFunctionToolResultOutput({
3081
3115
  return {
3082
3116
  type: "input_text",
3083
3117
  text: item.text,
3084
- ...promptCacheBreakpoint != null && {
3085
- prompt_cache_breakpoint: promptCacheBreakpoint
3118
+ ...promptCacheBreakpoint2 != null && {
3119
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3086
3120
  }
3087
3121
  };
3088
3122
  }
@@ -3091,8 +3125,8 @@ async function convertFunctionToolResultOutput({
3091
3125
  type: "input_image",
3092
3126
  image_url: `data:${item.mediaType};base64,${item.data}`,
3093
3127
  detail: (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail,
3094
- ...promptCacheBreakpoint != null && {
3095
- prompt_cache_breakpoint: promptCacheBreakpoint
3128
+ ...promptCacheBreakpoint2 != null && {
3129
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3096
3130
  }
3097
3131
  };
3098
3132
  }
@@ -3101,8 +3135,8 @@ async function convertFunctionToolResultOutput({
3101
3135
  type: "input_image",
3102
3136
  image_url: item.url,
3103
3137
  detail: (_d = (_c = item.providerOptions) == null ? void 0 : _c[providerOptionsName]) == null ? void 0 : _d.imageDetail,
3104
- ...promptCacheBreakpoint != null && {
3105
- prompt_cache_breakpoint: promptCacheBreakpoint
3138
+ ...promptCacheBreakpoint2 != null && {
3139
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3106
3140
  }
3107
3141
  };
3108
3142
  }
@@ -3111,8 +3145,8 @@ async function convertFunctionToolResultOutput({
3111
3145
  type: "input_file",
3112
3146
  filename: (_e = item.filename) != null ? _e : "data",
3113
3147
  file_data: `data:${item.mediaType};base64,${item.data}`,
3114
- ...promptCacheBreakpoint != null && {
3115
- prompt_cache_breakpoint: promptCacheBreakpoint
3148
+ ...promptCacheBreakpoint2 != null && {
3149
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3116
3150
  }
3117
3151
  };
3118
3152
  }
@@ -3120,8 +3154,8 @@ async function convertFunctionToolResultOutput({
3120
3154
  return {
3121
3155
  type: "input_file",
3122
3156
  file_url: item.url,
3123
- ...promptCacheBreakpoint != null && {
3124
- prompt_cache_breakpoint: promptCacheBreakpoint
3157
+ ...promptCacheBreakpoint2 != null && {
3158
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3125
3159
  }
3126
3160
  };
3127
3161
  }
@@ -3197,6 +3231,17 @@ function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
3197
3231
  var _a2;
3198
3232
  return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
3199
3233
  }
3234
+ function getScalarToolResultPromptCacheBreakpoint({
3235
+ output,
3236
+ toolResultProviderOptions,
3237
+ providerOptionsName
3238
+ }) {
3239
+ var _a2;
3240
+ return output.type === "content" ? void 0 : (_a2 = getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName)) != null ? _a2 : getPromptCacheBreakpoint2(
3241
+ toolResultProviderOptions,
3242
+ providerOptionsName
3243
+ );
3244
+ }
3200
3245
  function isFileId(data, prefixes) {
3201
3246
  if (!prefixes) return false;
3202
3247
  return prefixes.some((prefix) => data.startsWith(prefix));
@@ -3697,22 +3742,41 @@ async function convertToOpenAIResponsesInput({
3697
3742
  parallelToolResultGroup.metadata.toolCallId
3698
3743
  );
3699
3744
  const toolOutputs = await Promise.all(
3700
- parallelToolResultGroup.results.map(
3701
- async (result) => convertFunctionToolResultOutput({
3745
+ parallelToolResultGroup.results.map(async (result) => {
3746
+ const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
3702
3747
  output: result.output,
3703
- providerOptionsName,
3704
- warnings
3705
- })
3706
- )
3748
+ toolResultProviderOptions: result.providerOptions,
3749
+ providerOptionsName
3750
+ });
3751
+ return {
3752
+ output: await convertFunctionToolResultOutput({
3753
+ output: result.output,
3754
+ providerOptionsName,
3755
+ warnings
3756
+ }),
3757
+ promptCacheBreakpoint
3758
+ };
3759
+ })
3760
+ );
3761
+ const serializedToolOutputs = toolOutputs.map(
3762
+ ({ output: output2 }) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
3763
+ );
3764
+ const hasPromptCacheBreakpoint = toolOutputs.some(
3765
+ ({ promptCacheBreakpoint }) => promptCacheBreakpoint != null
3707
3766
  );
3708
3767
  input.push({
3709
3768
  type: "function_call_output",
3710
3769
  call_id: parallelToolResultGroup.metadata.toolCallId,
3711
3770
  // The internal wrapper returns one output containing the child
3712
3771
  // results in the same order as the original tool_uses array.
3713
- output: toolOutputs.map(
3714
- (output2) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
3715
- ).join("\n")
3772
+ output: hasPromptCacheBreakpoint ? serializedToolOutputs.map((text, index) => ({
3773
+ type: "input_text",
3774
+ text: index === 0 ? text : `
3775
+ ${text}`,
3776
+ ...toolOutputs[index].promptCacheBreakpoint != null && {
3777
+ prompt_cache_breakpoint: toolOutputs[index].promptCacheBreakpoint
3778
+ }
3779
+ })) : serializedToolOutputs.join("\n")
3716
3780
  });
3717
3781
  }
3718
3782
  continue;
@@ -3786,23 +3850,37 @@ async function convertToOpenAIResponsesInput({
3786
3850
  continue;
3787
3851
  }
3788
3852
  if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
3853
+ const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
3854
+ output,
3855
+ toolResultProviderOptions: part.providerOptions,
3856
+ providerOptionsName
3857
+ });
3858
+ const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
3859
+ {
3860
+ type: "input_text",
3861
+ text: value,
3862
+ prompt_cache_breakpoint: promptCacheBreakpoint
3863
+ }
3864
+ ];
3789
3865
  let outputValue;
3790
3866
  switch (output.type) {
3791
3867
  case "text":
3792
3868
  case "error-text":
3793
- outputValue = output.value;
3869
+ outputValue = convertScalarOutput(output.value);
3794
3870
  break;
3795
3871
  case "execution-denied":
3796
- outputValue = (_y = output.reason) != null ? _y : "Tool call execution denied.";
3872
+ outputValue = convertScalarOutput(
3873
+ (_y = output.reason) != null ? _y : "Tool call execution denied."
3874
+ );
3797
3875
  break;
3798
3876
  case "json":
3799
3877
  case "error-json":
3800
- outputValue = JSON.stringify(output.value);
3878
+ outputValue = convertScalarOutput(JSON.stringify(output.value));
3801
3879
  break;
3802
3880
  case "content":
3803
3881
  outputValue = output.value.map((item) => {
3804
3882
  var _a3, _b2, _c2, _d2, _e2;
3805
- const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3883
+ const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
3806
3884
  item.providerOptions,
3807
3885
  providerOptionsName
3808
3886
  );
@@ -3811,8 +3889,8 @@ async function convertToOpenAIResponsesInput({
3811
3889
  return {
3812
3890
  type: "input_text",
3813
3891
  text: item.text,
3814
- ...promptCacheBreakpoint != null && {
3815
- prompt_cache_breakpoint: promptCacheBreakpoint
3892
+ ...promptCacheBreakpoint2 != null && {
3893
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3816
3894
  }
3817
3895
  };
3818
3896
  case "image-data":
@@ -3820,8 +3898,8 @@ async function convertToOpenAIResponsesInput({
3820
3898
  type: "input_image",
3821
3899
  image_url: `data:${item.mediaType};base64,${item.data}`,
3822
3900
  detail: (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3823
- ...promptCacheBreakpoint != null && {
3824
- prompt_cache_breakpoint: promptCacheBreakpoint
3901
+ ...promptCacheBreakpoint2 != null && {
3902
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3825
3903
  }
3826
3904
  };
3827
3905
  case "image-url":
@@ -3829,8 +3907,8 @@ async function convertToOpenAIResponsesInput({
3829
3907
  type: "input_image",
3830
3908
  image_url: item.url,
3831
3909
  detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
3832
- ...promptCacheBreakpoint != null && {
3833
- prompt_cache_breakpoint: promptCacheBreakpoint
3910
+ ...promptCacheBreakpoint2 != null && {
3911
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3834
3912
  }
3835
3913
  };
3836
3914
  case "file-data":
@@ -3838,16 +3916,16 @@ async function convertToOpenAIResponsesInput({
3838
3916
  type: "input_file",
3839
3917
  filename: (_e2 = item.filename) != null ? _e2 : "data",
3840
3918
  file_data: `data:${item.mediaType};base64,${item.data}`,
3841
- ...promptCacheBreakpoint != null && {
3842
- prompt_cache_breakpoint: promptCacheBreakpoint
3919
+ ...promptCacheBreakpoint2 != null && {
3920
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3843
3921
  }
3844
3922
  };
3845
3923
  case "file-url":
3846
3924
  return {
3847
3925
  type: "input_file",
3848
3926
  file_url: item.url,
3849
- ...promptCacheBreakpoint != null && {
3850
- prompt_cache_breakpoint: promptCacheBreakpoint
3927
+ ...promptCacheBreakpoint2 != null && {
3928
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3851
3929
  }
3852
3930
  };
3853
3931
  default:
@@ -3871,6 +3949,11 @@ async function convertToOpenAIResponsesInput({
3871
3949
  }
3872
3950
  const contentValue = await convertFunctionToolResultOutput({
3873
3951
  output,
3952
+ promptCacheBreakpoint: getScalarToolResultPromptCacheBreakpoint({
3953
+ output,
3954
+ toolResultProviderOptions: part.providerOptions,
3955
+ providerOptionsName
3956
+ }),
3874
3957
  providerOptionsName,
3875
3958
  warnings
3876
3959
  });
@@ -3940,6 +4023,31 @@ var jsonValueSchema = z18.lazy(
3940
4023
  z18.record(z18.string(), jsonValueSchema.optional())
3941
4024
  ])
3942
4025
  );
4026
+ var jsonObjectSchema = z18.record(z18.string(), jsonValueSchema.optional());
4027
+ var openaiResponsesUsageSchema = z18.intersection(
4028
+ jsonObjectSchema,
4029
+ z18.object({
4030
+ input_tokens: z18.number(),
4031
+ input_tokens_details: z18.intersection(
4032
+ jsonObjectSchema,
4033
+ z18.object({
4034
+ cached_tokens: z18.number().nullish(),
4035
+ cache_write_tokens: z18.number().nullish(),
4036
+ orchestration_input_tokens: z18.number().nullish(),
4037
+ orchestration_input_cached_tokens: z18.number().nullish()
4038
+ })
4039
+ ).nullish(),
4040
+ output_tokens: z18.number(),
4041
+ output_tokens_details: z18.intersection(
4042
+ jsonObjectSchema,
4043
+ z18.object({
4044
+ reasoning_tokens: z18.number().nullish(),
4045
+ orchestration_output_tokens: z18.number().nullish()
4046
+ })
4047
+ ).nullish(),
4048
+ total_tokens: z18.number().optional()
4049
+ })
4050
+ );
3943
4051
  function isRecord(value) {
3944
4052
  return value != null && typeof value === "object" && !Array.isArray(value);
3945
4053
  }
@@ -4051,20 +4159,7 @@ var openaiResponsesChunkSchema = lazySchema16(
4051
4159
  type: z18.enum(["response.completed", "response.incomplete"]),
4052
4160
  response: z18.object({
4053
4161
  incomplete_details: z18.object({ reason: z18.string() }).nullish(),
4054
- usage: z18.object({
4055
- input_tokens: z18.number(),
4056
- input_tokens_details: z18.object({
4057
- cached_tokens: z18.number().nullish(),
4058
- cache_write_tokens: z18.number().nullish(),
4059
- orchestration_input_tokens: z18.number().nullish(),
4060
- orchestration_input_cached_tokens: z18.number().nullish()
4061
- }).nullish(),
4062
- output_tokens: z18.number(),
4063
- output_tokens_details: z18.object({
4064
- reasoning_tokens: z18.number().nullish(),
4065
- orchestration_output_tokens: z18.number().nullish()
4066
- }).nullish()
4067
- }),
4162
+ usage: openaiResponsesUsageSchema.nullish(),
4068
4163
  reasoning: z18.object({
4069
4164
  context: z18.string().nullish()
4070
4165
  }).nullish(),
@@ -4080,20 +4175,7 @@ var openaiResponsesChunkSchema = lazySchema16(
4080
4175
  message: z18.string()
4081
4176
  }).nullish(),
4082
4177
  incomplete_details: z18.object({ reason: z18.string() }).nullish(),
4083
- usage: z18.object({
4084
- input_tokens: z18.number(),
4085
- input_tokens_details: z18.object({
4086
- cached_tokens: z18.number().nullish(),
4087
- cache_write_tokens: z18.number().nullish(),
4088
- orchestration_input_tokens: z18.number().nullish(),
4089
- orchestration_input_cached_tokens: z18.number().nullish()
4090
- }).nullish(),
4091
- output_tokens: z18.number(),
4092
- output_tokens_details: z18.object({
4093
- reasoning_tokens: z18.number().nullish(),
4094
- orchestration_output_tokens: z18.number().nullish()
4095
- }).nullish()
4096
- }).nullish(),
4178
+ usage: openaiResponsesUsageSchema.nullish(),
4097
4179
  reasoning: z18.object({
4098
4180
  context: z18.string().nullish()
4099
4181
  }).nullish(),
@@ -4859,20 +4941,7 @@ var openaiResponsesResponseSchema = lazySchema16(
4859
4941
  context: z18.string().nullish()
4860
4942
  }).nullish(),
4861
4943
  incomplete_details: z18.object({ reason: z18.string() }).nullish(),
4862
- usage: z18.object({
4863
- input_tokens: z18.number(),
4864
- input_tokens_details: z18.object({
4865
- cached_tokens: z18.number().nullish(),
4866
- cache_write_tokens: z18.number().nullish(),
4867
- orchestration_input_tokens: z18.number().nullish(),
4868
- orchestration_input_cached_tokens: z18.number().nullish()
4869
- }).nullish(),
4870
- output_tokens: z18.number(),
4871
- output_tokens_details: z18.object({
4872
- reasoning_tokens: z18.number().nullish(),
4873
- orchestration_output_tokens: z18.number().nullish()
4874
- }).nullish()
4875
- }).optional()
4944
+ usage: openaiResponsesUsageSchema.nullish()
4876
4945
  })
4877
4946
  )
4878
4947
  );
@@ -6816,7 +6885,7 @@ var OpenAIResponsesLanguageModel = class {
6816
6885
  controller.enqueue({ type: "stream-start", warnings });
6817
6886
  },
6818
6887
  transform(chunk, controller) {
6819
- var _a3, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P;
6888
+ var _a3, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S;
6820
6889
  if (options.includeRawChunks) {
6821
6890
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
6822
6891
  }
@@ -7637,15 +7706,15 @@ var OpenAIResponsesLanguageModel = class {
7637
7706
  raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
7638
7707
  };
7639
7708
  }
7640
- usage = value.response.usage;
7709
+ usage = (_A = value.response.usage) != null ? _A : void 0;
7641
7710
  if (typeof value.response.service_tier === "string") {
7642
7711
  serviceTier = value.response.service_tier;
7643
7712
  }
7644
- if (((_A = value.response.reasoning) == null ? void 0 : _A.context) != null) {
7713
+ if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
7645
7714
  reasoningContext = value.response.reasoning.context;
7646
7715
  }
7647
7716
  } else if (isResponseFailedChunk(value)) {
7648
- const incompleteReason = (_B = value.response.incomplete_details) == null ? void 0 : _B.reason;
7717
+ const incompleteReason = (_C = value.response.incomplete_details) == null ? void 0 : _C.reason;
7649
7718
  finishReason = {
7650
7719
  unified: incompleteReason ? mapOpenAIResponseFinishReason({
7651
7720
  finishReason: incompleteReason,
@@ -7653,23 +7722,24 @@ var OpenAIResponsesLanguageModel = class {
7653
7722
  }) : "error",
7654
7723
  raw: incompleteReason != null ? incompleteReason : "error"
7655
7724
  };
7656
- usage = (_C = value.response.usage) != null ? _C : void 0;
7657
- if (((_D = value.response.reasoning) == null ? void 0 : _D.context) != null) {
7725
+ usage = (_D = value.response.usage) != null ? _D : void 0;
7726
+ if (((_E = value.response.reasoning) == null ? void 0 : _E.context) != null) {
7658
7727
  reasoningContext = value.response.reasoning.context;
7659
7728
  }
7660
7729
  if (!encounteredStreamError && value.response.error != null) {
7661
7730
  encounteredStreamError = true;
7731
+ const error = {
7732
+ type: "response.failed",
7733
+ sequence_number: value.sequence_number,
7734
+ response: {
7735
+ error: value.response.error,
7736
+ incomplete_details: value.response.incomplete_details,
7737
+ service_tier: value.response.service_tier
7738
+ }
7739
+ };
7662
7740
  controller.enqueue({
7663
7741
  type: "error",
7664
- error: {
7665
- type: "response.failed",
7666
- sequence_number: value.sequence_number,
7667
- response: {
7668
- error: value.response.error,
7669
- incomplete_details: value.response.incomplete_details,
7670
- service_tier: value.response.service_tier
7671
- }
7672
- }
7742
+ error: (_F = createOpenAIProviderStreamError(error)) != null ? _F : error
7673
7743
  });
7674
7744
  }
7675
7745
  } else if (isResponseAnnotationAddedChunk(value)) {
@@ -7678,7 +7748,7 @@ var OpenAIResponsesLanguageModel = class {
7678
7748
  controller.enqueue({
7679
7749
  type: "source",
7680
7750
  sourceType: "url",
7681
- id: (_G = (_F = (_E = self.config).generateId) == null ? void 0 : _F.call(_E)) != null ? _G : generateId2(),
7751
+ id: (_I = (_H = (_G = self.config).generateId) == null ? void 0 : _H.call(_G)) != null ? _I : generateId2(),
7682
7752
  url: value.annotation.url,
7683
7753
  title: value.annotation.title
7684
7754
  });
@@ -7686,7 +7756,7 @@ var OpenAIResponsesLanguageModel = class {
7686
7756
  controller.enqueue({
7687
7757
  type: "source",
7688
7758
  sourceType: "document",
7689
- id: (_J = (_I = (_H = self.config).generateId) == null ? void 0 : _I.call(_H)) != null ? _J : generateId2(),
7759
+ id: (_L = (_K = (_J = self.config).generateId) == null ? void 0 : _K.call(_J)) != null ? _L : generateId2(),
7690
7760
  mediaType: "text/plain",
7691
7761
  title: value.annotation.filename,
7692
7762
  filename: value.annotation.filename,
@@ -7702,7 +7772,7 @@ var OpenAIResponsesLanguageModel = class {
7702
7772
  controller.enqueue({
7703
7773
  type: "source",
7704
7774
  sourceType: "document",
7705
- id: (_M = (_L = (_K = self.config).generateId) == null ? void 0 : _L.call(_K)) != null ? _M : generateId2(),
7775
+ id: (_O = (_N = (_M = self.config).generateId) == null ? void 0 : _N.call(_M)) != null ? _O : generateId2(),
7706
7776
  mediaType: "text/plain",
7707
7777
  title: value.annotation.filename,
7708
7778
  filename: value.annotation.filename,
@@ -7718,7 +7788,7 @@ var OpenAIResponsesLanguageModel = class {
7718
7788
  controller.enqueue({
7719
7789
  type: "source",
7720
7790
  sourceType: "document",
7721
- id: (_P = (_O = (_N = self.config).generateId) == null ? void 0 : _O.call(_N)) != null ? _P : generateId2(),
7791
+ id: (_R = (_Q = (_P = self.config).generateId) == null ? void 0 : _Q.call(_P)) != null ? _R : generateId2(),
7722
7792
  mediaType: "application/octet-stream",
7723
7793
  title: value.annotation.file_id,
7724
7794
  filename: value.annotation.file_id,
@@ -7734,7 +7804,10 @@ var OpenAIResponsesLanguageModel = class {
7734
7804
  } else if (isErrorChunk(value)) {
7735
7805
  encounteredStreamError = true;
7736
7806
  finishReason = { unified: "error", raw: "error" };
7737
- controller.enqueue({ type: "error", error: value });
7807
+ controller.enqueue({
7808
+ type: "error",
7809
+ error: (_S = createOpenAIProviderStreamError(value)) != null ? _S : value
7810
+ });
7738
7811
  }
7739
7812
  },
7740
7813
  flush(controller) {