@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.
package/dist/index.js CHANGED
@@ -90,6 +90,22 @@ function getGptVersion(modelId) {
90
90
 
91
91
  // src/openai-stream-error.ts
92
92
  var import_provider = require("@ai-sdk/provider");
93
+ function createOpenAIProviderStreamError(frame) {
94
+ var _a2, _b;
95
+ const streamError = parseStreamError(frame);
96
+ if (streamError == null) {
97
+ return void 0;
98
+ }
99
+ const statusCode = getStatusCode(streamError);
100
+ return {
101
+ message: streamError.message,
102
+ type: (_a2 = streamError.type) != null ? _a2 : void 0,
103
+ code: (_b = streamError.code) != null ? _b : void 0,
104
+ statusCode,
105
+ isRetryable: isRetryableStreamError(streamError, statusCode),
106
+ data: frame
107
+ };
108
+ }
93
109
  async function throwIfOpenAIStreamErrorBeforeOutput({
94
110
  stream,
95
111
  getError,
@@ -161,16 +177,14 @@ function parseStreamError(frame) {
161
177
  return typeof (responseError == null ? void 0 : responseError.message) === "string" ? {
162
178
  message: responseError.message,
163
179
  code: getStringOrNumber(responseError.code),
164
- type: "response.failed",
165
- frame
180
+ type: "response.failed"
166
181
  } : void 0;
167
182
  }
168
183
  const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
169
184
  return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
170
185
  message: error.message,
171
186
  code: getStringOrNumber(error.code),
172
- type: typeof error.type === "string" ? error.type : void 0,
173
- frame
187
+ type: typeof error.type === "string" ? error.type : void 0
174
188
  } : void 0;
175
189
  }
176
190
  function getStatusCode(error) {
@@ -210,6 +224,15 @@ function getStringOrNumber(value) {
210
224
  function isHttpErrorStatusCode(value) {
211
225
  return Number.isInteger(value) && value >= 400 && value <= 599;
212
226
  }
227
+ function isRetryableStatusCode(statusCode) {
228
+ return statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500;
229
+ }
230
+ function isRetryableStreamError(error, statusCode) {
231
+ if (error.code === "insufficient_quota" || error.type === "insufficient_quota") {
232
+ return false;
233
+ }
234
+ return isRetryableStatusCode(statusCode);
235
+ }
213
236
 
214
237
  // src/chat/convert-openai-chat-usage.ts
215
238
  function convertOpenAIChatUsage(usage) {
@@ -3067,23 +3090,34 @@ function serializeToolCallArguments2(input) {
3067
3090
  }
3068
3091
  async function convertFunctionToolResultOutput({
3069
3092
  output,
3093
+ promptCacheBreakpoint,
3070
3094
  providerOptionsName,
3071
3095
  warnings
3072
3096
  }) {
3073
3097
  var _a2;
3098
+ const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
3099
+ {
3100
+ type: "input_text",
3101
+ text: value,
3102
+ prompt_cache_breakpoint: promptCacheBreakpoint
3103
+ }
3104
+ ];
3074
3105
  switch (output.type) {
3075
3106
  case "text":
3076
3107
  case "error-text":
3077
- return output.value;
3078
- case "execution-denied":
3079
- return (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
3108
+ return convertScalarOutput(output.value);
3109
+ case "execution-denied": {
3110
+ return convertScalarOutput(
3111
+ (_a2 = output.reason) != null ? _a2 : "Tool call execution denied."
3112
+ );
3113
+ }
3080
3114
  case "json":
3081
3115
  case "error-json":
3082
- return JSON.stringify(output.value);
3116
+ return convertScalarOutput(JSON.stringify(output.value));
3083
3117
  case "content":
3084
3118
  return output.value.map((item) => {
3085
3119
  var _a3, _b, _c, _d, _e;
3086
- const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3120
+ const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
3087
3121
  item.providerOptions,
3088
3122
  providerOptionsName
3089
3123
  );
@@ -3092,8 +3126,8 @@ async function convertFunctionToolResultOutput({
3092
3126
  return {
3093
3127
  type: "input_text",
3094
3128
  text: item.text,
3095
- ...promptCacheBreakpoint != null && {
3096
- prompt_cache_breakpoint: promptCacheBreakpoint
3129
+ ...promptCacheBreakpoint2 != null && {
3130
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3097
3131
  }
3098
3132
  };
3099
3133
  }
@@ -3102,8 +3136,8 @@ async function convertFunctionToolResultOutput({
3102
3136
  type: "input_image",
3103
3137
  image_url: `data:${item.mediaType};base64,${item.data}`,
3104
3138
  detail: (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail,
3105
- ...promptCacheBreakpoint != null && {
3106
- prompt_cache_breakpoint: promptCacheBreakpoint
3139
+ ...promptCacheBreakpoint2 != null && {
3140
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3107
3141
  }
3108
3142
  };
3109
3143
  }
@@ -3112,8 +3146,8 @@ async function convertFunctionToolResultOutput({
3112
3146
  type: "input_image",
3113
3147
  image_url: item.url,
3114
3148
  detail: (_d = (_c = item.providerOptions) == null ? void 0 : _c[providerOptionsName]) == null ? void 0 : _d.imageDetail,
3115
- ...promptCacheBreakpoint != null && {
3116
- prompt_cache_breakpoint: promptCacheBreakpoint
3149
+ ...promptCacheBreakpoint2 != null && {
3150
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3117
3151
  }
3118
3152
  };
3119
3153
  }
@@ -3122,8 +3156,8 @@ async function convertFunctionToolResultOutput({
3122
3156
  type: "input_file",
3123
3157
  filename: (_e = item.filename) != null ? _e : "data",
3124
3158
  file_data: `data:${item.mediaType};base64,${item.data}`,
3125
- ...promptCacheBreakpoint != null && {
3126
- prompt_cache_breakpoint: promptCacheBreakpoint
3159
+ ...promptCacheBreakpoint2 != null && {
3160
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3127
3161
  }
3128
3162
  };
3129
3163
  }
@@ -3131,8 +3165,8 @@ async function convertFunctionToolResultOutput({
3131
3165
  return {
3132
3166
  type: "input_file",
3133
3167
  file_url: item.url,
3134
- ...promptCacheBreakpoint != null && {
3135
- prompt_cache_breakpoint: promptCacheBreakpoint
3168
+ ...promptCacheBreakpoint2 != null && {
3169
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3136
3170
  }
3137
3171
  };
3138
3172
  }
@@ -3208,6 +3242,17 @@ function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
3208
3242
  var _a2;
3209
3243
  return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
3210
3244
  }
3245
+ function getScalarToolResultPromptCacheBreakpoint({
3246
+ output,
3247
+ toolResultProviderOptions,
3248
+ providerOptionsName
3249
+ }) {
3250
+ var _a2;
3251
+ return output.type === "content" ? void 0 : (_a2 = getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName)) != null ? _a2 : getPromptCacheBreakpoint2(
3252
+ toolResultProviderOptions,
3253
+ providerOptionsName
3254
+ );
3255
+ }
3211
3256
  function isFileId(data, prefixes) {
3212
3257
  if (!prefixes) return false;
3213
3258
  return prefixes.some((prefix) => data.startsWith(prefix));
@@ -3708,22 +3753,41 @@ async function convertToOpenAIResponsesInput({
3708
3753
  parallelToolResultGroup.metadata.toolCallId
3709
3754
  );
3710
3755
  const toolOutputs = await Promise.all(
3711
- parallelToolResultGroup.results.map(
3712
- async (result) => convertFunctionToolResultOutput({
3756
+ parallelToolResultGroup.results.map(async (result) => {
3757
+ const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
3713
3758
  output: result.output,
3714
- providerOptionsName,
3715
- warnings
3716
- })
3717
- )
3759
+ toolResultProviderOptions: result.providerOptions,
3760
+ providerOptionsName
3761
+ });
3762
+ return {
3763
+ output: await convertFunctionToolResultOutput({
3764
+ output: result.output,
3765
+ providerOptionsName,
3766
+ warnings
3767
+ }),
3768
+ promptCacheBreakpoint
3769
+ };
3770
+ })
3771
+ );
3772
+ const serializedToolOutputs = toolOutputs.map(
3773
+ ({ output: output2 }) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
3774
+ );
3775
+ const hasPromptCacheBreakpoint = toolOutputs.some(
3776
+ ({ promptCacheBreakpoint }) => promptCacheBreakpoint != null
3718
3777
  );
3719
3778
  input.push({
3720
3779
  type: "function_call_output",
3721
3780
  call_id: parallelToolResultGroup.metadata.toolCallId,
3722
3781
  // The internal wrapper returns one output containing the child
3723
3782
  // results in the same order as the original tool_uses array.
3724
- output: toolOutputs.map(
3725
- (output2) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
3726
- ).join("\n")
3783
+ output: hasPromptCacheBreakpoint ? serializedToolOutputs.map((text, index) => ({
3784
+ type: "input_text",
3785
+ text: index === 0 ? text : `
3786
+ ${text}`,
3787
+ ...toolOutputs[index].promptCacheBreakpoint != null && {
3788
+ prompt_cache_breakpoint: toolOutputs[index].promptCacheBreakpoint
3789
+ }
3790
+ })) : serializedToolOutputs.join("\n")
3727
3791
  });
3728
3792
  }
3729
3793
  continue;
@@ -3797,23 +3861,37 @@ async function convertToOpenAIResponsesInput({
3797
3861
  continue;
3798
3862
  }
3799
3863
  if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
3864
+ const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
3865
+ output,
3866
+ toolResultProviderOptions: part.providerOptions,
3867
+ providerOptionsName
3868
+ });
3869
+ const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
3870
+ {
3871
+ type: "input_text",
3872
+ text: value,
3873
+ prompt_cache_breakpoint: promptCacheBreakpoint
3874
+ }
3875
+ ];
3800
3876
  let outputValue;
3801
3877
  switch (output.type) {
3802
3878
  case "text":
3803
3879
  case "error-text":
3804
- outputValue = output.value;
3880
+ outputValue = convertScalarOutput(output.value);
3805
3881
  break;
3806
3882
  case "execution-denied":
3807
- outputValue = (_y = output.reason) != null ? _y : "Tool call execution denied.";
3883
+ outputValue = convertScalarOutput(
3884
+ (_y = output.reason) != null ? _y : "Tool call execution denied."
3885
+ );
3808
3886
  break;
3809
3887
  case "json":
3810
3888
  case "error-json":
3811
- outputValue = JSON.stringify(output.value);
3889
+ outputValue = convertScalarOutput(JSON.stringify(output.value));
3812
3890
  break;
3813
3891
  case "content":
3814
3892
  outputValue = output.value.map((item) => {
3815
3893
  var _a3, _b2, _c2, _d2, _e2;
3816
- const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3894
+ const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
3817
3895
  item.providerOptions,
3818
3896
  providerOptionsName
3819
3897
  );
@@ -3822,8 +3900,8 @@ async function convertToOpenAIResponsesInput({
3822
3900
  return {
3823
3901
  type: "input_text",
3824
3902
  text: item.text,
3825
- ...promptCacheBreakpoint != null && {
3826
- prompt_cache_breakpoint: promptCacheBreakpoint
3903
+ ...promptCacheBreakpoint2 != null && {
3904
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3827
3905
  }
3828
3906
  };
3829
3907
  case "image-data":
@@ -3831,8 +3909,8 @@ async function convertToOpenAIResponsesInput({
3831
3909
  type: "input_image",
3832
3910
  image_url: `data:${item.mediaType};base64,${item.data}`,
3833
3911
  detail: (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3834
- ...promptCacheBreakpoint != null && {
3835
- prompt_cache_breakpoint: promptCacheBreakpoint
3912
+ ...promptCacheBreakpoint2 != null && {
3913
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3836
3914
  }
3837
3915
  };
3838
3916
  case "image-url":
@@ -3840,8 +3918,8 @@ async function convertToOpenAIResponsesInput({
3840
3918
  type: "input_image",
3841
3919
  image_url: item.url,
3842
3920
  detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
3843
- ...promptCacheBreakpoint != null && {
3844
- prompt_cache_breakpoint: promptCacheBreakpoint
3921
+ ...promptCacheBreakpoint2 != null && {
3922
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3845
3923
  }
3846
3924
  };
3847
3925
  case "file-data":
@@ -3849,16 +3927,16 @@ async function convertToOpenAIResponsesInput({
3849
3927
  type: "input_file",
3850
3928
  filename: (_e2 = item.filename) != null ? _e2 : "data",
3851
3929
  file_data: `data:${item.mediaType};base64,${item.data}`,
3852
- ...promptCacheBreakpoint != null && {
3853
- prompt_cache_breakpoint: promptCacheBreakpoint
3930
+ ...promptCacheBreakpoint2 != null && {
3931
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3854
3932
  }
3855
3933
  };
3856
3934
  case "file-url":
3857
3935
  return {
3858
3936
  type: "input_file",
3859
3937
  file_url: item.url,
3860
- ...promptCacheBreakpoint != null && {
3861
- prompt_cache_breakpoint: promptCacheBreakpoint
3938
+ ...promptCacheBreakpoint2 != null && {
3939
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3862
3940
  }
3863
3941
  };
3864
3942
  default:
@@ -3882,6 +3960,11 @@ async function convertToOpenAIResponsesInput({
3882
3960
  }
3883
3961
  const contentValue = await convertFunctionToolResultOutput({
3884
3962
  output,
3963
+ promptCacheBreakpoint: getScalarToolResultPromptCacheBreakpoint({
3964
+ output,
3965
+ toolResultProviderOptions: part.providerOptions,
3966
+ providerOptionsName
3967
+ }),
3885
3968
  providerOptionsName,
3886
3969
  warnings
3887
3970
  });
@@ -3948,6 +4031,31 @@ var jsonValueSchema2 = import_v422.z.lazy(
3948
4031
  import_v422.z.record(import_v422.z.string(), jsonValueSchema2.optional())
3949
4032
  ])
3950
4033
  );
4034
+ var jsonObjectSchema = import_v422.z.record(import_v422.z.string(), jsonValueSchema2.optional());
4035
+ var openaiResponsesUsageSchema = import_v422.z.intersection(
4036
+ jsonObjectSchema,
4037
+ import_v422.z.object({
4038
+ input_tokens: import_v422.z.number(),
4039
+ input_tokens_details: import_v422.z.intersection(
4040
+ jsonObjectSchema,
4041
+ import_v422.z.object({
4042
+ cached_tokens: import_v422.z.number().nullish(),
4043
+ cache_write_tokens: import_v422.z.number().nullish(),
4044
+ orchestration_input_tokens: import_v422.z.number().nullish(),
4045
+ orchestration_input_cached_tokens: import_v422.z.number().nullish()
4046
+ })
4047
+ ).nullish(),
4048
+ output_tokens: import_v422.z.number(),
4049
+ output_tokens_details: import_v422.z.intersection(
4050
+ jsonObjectSchema,
4051
+ import_v422.z.object({
4052
+ reasoning_tokens: import_v422.z.number().nullish(),
4053
+ orchestration_output_tokens: import_v422.z.number().nullish()
4054
+ })
4055
+ ).nullish(),
4056
+ total_tokens: import_v422.z.number().optional()
4057
+ })
4058
+ );
3951
4059
  function isRecord(value) {
3952
4060
  return value != null && typeof value === "object" && !Array.isArray(value);
3953
4061
  }
@@ -4059,20 +4167,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils28.lazySchema)(
4059
4167
  type: import_v422.z.enum(["response.completed", "response.incomplete"]),
4060
4168
  response: import_v422.z.object({
4061
4169
  incomplete_details: import_v422.z.object({ reason: import_v422.z.string() }).nullish(),
4062
- usage: import_v422.z.object({
4063
- input_tokens: import_v422.z.number(),
4064
- input_tokens_details: import_v422.z.object({
4065
- cached_tokens: import_v422.z.number().nullish(),
4066
- cache_write_tokens: import_v422.z.number().nullish(),
4067
- orchestration_input_tokens: import_v422.z.number().nullish(),
4068
- orchestration_input_cached_tokens: import_v422.z.number().nullish()
4069
- }).nullish(),
4070
- output_tokens: import_v422.z.number(),
4071
- output_tokens_details: import_v422.z.object({
4072
- reasoning_tokens: import_v422.z.number().nullish(),
4073
- orchestration_output_tokens: import_v422.z.number().nullish()
4074
- }).nullish()
4075
- }),
4170
+ usage: openaiResponsesUsageSchema.nullish(),
4076
4171
  reasoning: import_v422.z.object({
4077
4172
  context: import_v422.z.string().nullish()
4078
4173
  }).nullish(),
@@ -4088,20 +4183,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils28.lazySchema)(
4088
4183
  message: import_v422.z.string()
4089
4184
  }).nullish(),
4090
4185
  incomplete_details: import_v422.z.object({ reason: import_v422.z.string() }).nullish(),
4091
- usage: import_v422.z.object({
4092
- input_tokens: import_v422.z.number(),
4093
- input_tokens_details: import_v422.z.object({
4094
- cached_tokens: import_v422.z.number().nullish(),
4095
- cache_write_tokens: import_v422.z.number().nullish(),
4096
- orchestration_input_tokens: import_v422.z.number().nullish(),
4097
- orchestration_input_cached_tokens: import_v422.z.number().nullish()
4098
- }).nullish(),
4099
- output_tokens: import_v422.z.number(),
4100
- output_tokens_details: import_v422.z.object({
4101
- reasoning_tokens: import_v422.z.number().nullish(),
4102
- orchestration_output_tokens: import_v422.z.number().nullish()
4103
- }).nullish()
4104
- }).nullish(),
4186
+ usage: openaiResponsesUsageSchema.nullish(),
4105
4187
  reasoning: import_v422.z.object({
4106
4188
  context: import_v422.z.string().nullish()
4107
4189
  }).nullish(),
@@ -4867,20 +4949,7 @@ var openaiResponsesResponseSchema = (0, import_provider_utils28.lazySchema)(
4867
4949
  context: import_v422.z.string().nullish()
4868
4950
  }).nullish(),
4869
4951
  incomplete_details: import_v422.z.object({ reason: import_v422.z.string() }).nullish(),
4870
- usage: import_v422.z.object({
4871
- input_tokens: import_v422.z.number(),
4872
- input_tokens_details: import_v422.z.object({
4873
- cached_tokens: import_v422.z.number().nullish(),
4874
- cache_write_tokens: import_v422.z.number().nullish(),
4875
- orchestration_input_tokens: import_v422.z.number().nullish(),
4876
- orchestration_input_cached_tokens: import_v422.z.number().nullish()
4877
- }).nullish(),
4878
- output_tokens: import_v422.z.number(),
4879
- output_tokens_details: import_v422.z.object({
4880
- reasoning_tokens: import_v422.z.number().nullish(),
4881
- orchestration_output_tokens: import_v422.z.number().nullish()
4882
- }).nullish()
4883
- }).optional()
4952
+ usage: openaiResponsesUsageSchema.nullish()
4884
4953
  })
4885
4954
  )
4886
4955
  );
@@ -6467,7 +6536,7 @@ var OpenAIResponsesLanguageModel = class {
6467
6536
  controller.enqueue({ type: "stream-start", warnings });
6468
6537
  },
6469
6538
  transform(chunk, controller) {
6470
- 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;
6539
+ 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;
6471
6540
  if (options.includeRawChunks) {
6472
6541
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
6473
6542
  }
@@ -7288,15 +7357,15 @@ var OpenAIResponsesLanguageModel = class {
7288
7357
  raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
7289
7358
  };
7290
7359
  }
7291
- usage = value.response.usage;
7360
+ usage = (_A = value.response.usage) != null ? _A : void 0;
7292
7361
  if (typeof value.response.service_tier === "string") {
7293
7362
  serviceTier = value.response.service_tier;
7294
7363
  }
7295
- if (((_A = value.response.reasoning) == null ? void 0 : _A.context) != null) {
7364
+ if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
7296
7365
  reasoningContext = value.response.reasoning.context;
7297
7366
  }
7298
7367
  } else if (isResponseFailedChunk(value)) {
7299
- const incompleteReason = (_B = value.response.incomplete_details) == null ? void 0 : _B.reason;
7368
+ const incompleteReason = (_C = value.response.incomplete_details) == null ? void 0 : _C.reason;
7300
7369
  finishReason = {
7301
7370
  unified: incompleteReason ? mapOpenAIResponseFinishReason({
7302
7371
  finishReason: incompleteReason,
@@ -7304,23 +7373,24 @@ var OpenAIResponsesLanguageModel = class {
7304
7373
  }) : "error",
7305
7374
  raw: incompleteReason != null ? incompleteReason : "error"
7306
7375
  };
7307
- usage = (_C = value.response.usage) != null ? _C : void 0;
7308
- if (((_D = value.response.reasoning) == null ? void 0 : _D.context) != null) {
7376
+ usage = (_D = value.response.usage) != null ? _D : void 0;
7377
+ if (((_E = value.response.reasoning) == null ? void 0 : _E.context) != null) {
7309
7378
  reasoningContext = value.response.reasoning.context;
7310
7379
  }
7311
7380
  if (!encounteredStreamError && value.response.error != null) {
7312
7381
  encounteredStreamError = true;
7382
+ const error = {
7383
+ type: "response.failed",
7384
+ sequence_number: value.sequence_number,
7385
+ response: {
7386
+ error: value.response.error,
7387
+ incomplete_details: value.response.incomplete_details,
7388
+ service_tier: value.response.service_tier
7389
+ }
7390
+ };
7313
7391
  controller.enqueue({
7314
7392
  type: "error",
7315
- error: {
7316
- type: "response.failed",
7317
- sequence_number: value.sequence_number,
7318
- response: {
7319
- error: value.response.error,
7320
- incomplete_details: value.response.incomplete_details,
7321
- service_tier: value.response.service_tier
7322
- }
7323
- }
7393
+ error: (_F = createOpenAIProviderStreamError(error)) != null ? _F : error
7324
7394
  });
7325
7395
  }
7326
7396
  } else if (isResponseAnnotationAddedChunk(value)) {
@@ -7329,7 +7399,7 @@ var OpenAIResponsesLanguageModel = class {
7329
7399
  controller.enqueue({
7330
7400
  type: "source",
7331
7401
  sourceType: "url",
7332
- id: (_G = (_F = (_E = self.config).generateId) == null ? void 0 : _F.call(_E)) != null ? _G : (0, import_provider_utils31.generateId)(),
7402
+ id: (_I = (_H = (_G = self.config).generateId) == null ? void 0 : _H.call(_G)) != null ? _I : (0, import_provider_utils31.generateId)(),
7333
7403
  url: value.annotation.url,
7334
7404
  title: value.annotation.title
7335
7405
  });
@@ -7337,7 +7407,7 @@ var OpenAIResponsesLanguageModel = class {
7337
7407
  controller.enqueue({
7338
7408
  type: "source",
7339
7409
  sourceType: "document",
7340
- id: (_J = (_I = (_H = self.config).generateId) == null ? void 0 : _I.call(_H)) != null ? _J : (0, import_provider_utils31.generateId)(),
7410
+ id: (_L = (_K = (_J = self.config).generateId) == null ? void 0 : _K.call(_J)) != null ? _L : (0, import_provider_utils31.generateId)(),
7341
7411
  mediaType: "text/plain",
7342
7412
  title: value.annotation.filename,
7343
7413
  filename: value.annotation.filename,
@@ -7353,7 +7423,7 @@ var OpenAIResponsesLanguageModel = class {
7353
7423
  controller.enqueue({
7354
7424
  type: "source",
7355
7425
  sourceType: "document",
7356
- id: (_M = (_L = (_K = self.config).generateId) == null ? void 0 : _L.call(_K)) != null ? _M : (0, import_provider_utils31.generateId)(),
7426
+ id: (_O = (_N = (_M = self.config).generateId) == null ? void 0 : _N.call(_M)) != null ? _O : (0, import_provider_utils31.generateId)(),
7357
7427
  mediaType: "text/plain",
7358
7428
  title: value.annotation.filename,
7359
7429
  filename: value.annotation.filename,
@@ -7369,7 +7439,7 @@ var OpenAIResponsesLanguageModel = class {
7369
7439
  controller.enqueue({
7370
7440
  type: "source",
7371
7441
  sourceType: "document",
7372
- id: (_P = (_O = (_N = self.config).generateId) == null ? void 0 : _O.call(_N)) != null ? _P : (0, import_provider_utils31.generateId)(),
7442
+ id: (_R = (_Q = (_P = self.config).generateId) == null ? void 0 : _Q.call(_P)) != null ? _R : (0, import_provider_utils31.generateId)(),
7373
7443
  mediaType: "application/octet-stream",
7374
7444
  title: value.annotation.file_id,
7375
7445
  filename: value.annotation.file_id,
@@ -7385,7 +7455,10 @@ var OpenAIResponsesLanguageModel = class {
7385
7455
  } else if (isErrorChunk(value)) {
7386
7456
  encounteredStreamError = true;
7387
7457
  finishReason = { unified: "error", raw: "error" };
7388
- controller.enqueue({ type: "error", error: value });
7458
+ controller.enqueue({
7459
+ type: "error",
7460
+ error: (_S = createOpenAIProviderStreamError(value)) != null ? _S : value
7461
+ });
7389
7462
  }
7390
7463
  },
7391
7464
  flush(controller) {
@@ -7888,7 +7961,7 @@ var OpenAITranscriptionModel = class {
7888
7961
  };
7889
7962
 
7890
7963
  // src/version.ts
7891
- var VERSION = true ? "3.0.105" : "0.0.0-test";
7964
+ var VERSION = true ? "3.0.107" : "0.0.0-test";
7892
7965
 
7893
7966
  // src/openai-provider.ts
7894
7967
  function createOpenAI(options = {}) {