@ai-sdk/openai 3.0.105 → 3.0.106

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.mjs CHANGED
@@ -3165,23 +3165,34 @@ function serializeToolCallArguments2(input) {
3165
3165
  }
3166
3166
  async function convertFunctionToolResultOutput({
3167
3167
  output,
3168
+ promptCacheBreakpoint,
3168
3169
  providerOptionsName,
3169
3170
  warnings
3170
3171
  }) {
3171
3172
  var _a2;
3173
+ const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
3174
+ {
3175
+ type: "input_text",
3176
+ text: value,
3177
+ prompt_cache_breakpoint: promptCacheBreakpoint
3178
+ }
3179
+ ];
3172
3180
  switch (output.type) {
3173
3181
  case "text":
3174
3182
  case "error-text":
3175
- return output.value;
3176
- case "execution-denied":
3177
- return (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
3183
+ return convertScalarOutput(output.value);
3184
+ case "execution-denied": {
3185
+ return convertScalarOutput(
3186
+ (_a2 = output.reason) != null ? _a2 : "Tool call execution denied."
3187
+ );
3188
+ }
3178
3189
  case "json":
3179
3190
  case "error-json":
3180
- return JSON.stringify(output.value);
3191
+ return convertScalarOutput(JSON.stringify(output.value));
3181
3192
  case "content":
3182
3193
  return output.value.map((item) => {
3183
3194
  var _a3, _b, _c, _d, _e;
3184
- const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3195
+ const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
3185
3196
  item.providerOptions,
3186
3197
  providerOptionsName
3187
3198
  );
@@ -3190,8 +3201,8 @@ async function convertFunctionToolResultOutput({
3190
3201
  return {
3191
3202
  type: "input_text",
3192
3203
  text: item.text,
3193
- ...promptCacheBreakpoint != null && {
3194
- prompt_cache_breakpoint: promptCacheBreakpoint
3204
+ ...promptCacheBreakpoint2 != null && {
3205
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3195
3206
  }
3196
3207
  };
3197
3208
  }
@@ -3200,8 +3211,8 @@ async function convertFunctionToolResultOutput({
3200
3211
  type: "input_image",
3201
3212
  image_url: `data:${item.mediaType};base64,${item.data}`,
3202
3213
  detail: (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail,
3203
- ...promptCacheBreakpoint != null && {
3204
- prompt_cache_breakpoint: promptCacheBreakpoint
3214
+ ...promptCacheBreakpoint2 != null && {
3215
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3205
3216
  }
3206
3217
  };
3207
3218
  }
@@ -3210,8 +3221,8 @@ async function convertFunctionToolResultOutput({
3210
3221
  type: "input_image",
3211
3222
  image_url: item.url,
3212
3223
  detail: (_d = (_c = item.providerOptions) == null ? void 0 : _c[providerOptionsName]) == null ? void 0 : _d.imageDetail,
3213
- ...promptCacheBreakpoint != null && {
3214
- prompt_cache_breakpoint: promptCacheBreakpoint
3224
+ ...promptCacheBreakpoint2 != null && {
3225
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3215
3226
  }
3216
3227
  };
3217
3228
  }
@@ -3220,8 +3231,8 @@ async function convertFunctionToolResultOutput({
3220
3231
  type: "input_file",
3221
3232
  filename: (_e = item.filename) != null ? _e : "data",
3222
3233
  file_data: `data:${item.mediaType};base64,${item.data}`,
3223
- ...promptCacheBreakpoint != null && {
3224
- prompt_cache_breakpoint: promptCacheBreakpoint
3234
+ ...promptCacheBreakpoint2 != null && {
3235
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3225
3236
  }
3226
3237
  };
3227
3238
  }
@@ -3229,8 +3240,8 @@ async function convertFunctionToolResultOutput({
3229
3240
  return {
3230
3241
  type: "input_file",
3231
3242
  file_url: item.url,
3232
- ...promptCacheBreakpoint != null && {
3233
- prompt_cache_breakpoint: promptCacheBreakpoint
3243
+ ...promptCacheBreakpoint2 != null && {
3244
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3234
3245
  }
3235
3246
  };
3236
3247
  }
@@ -3306,6 +3317,17 @@ function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
3306
3317
  var _a2;
3307
3318
  return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
3308
3319
  }
3320
+ function getScalarToolResultPromptCacheBreakpoint({
3321
+ output,
3322
+ toolResultProviderOptions,
3323
+ providerOptionsName
3324
+ }) {
3325
+ var _a2;
3326
+ return output.type === "content" ? void 0 : (_a2 = getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName)) != null ? _a2 : getPromptCacheBreakpoint2(
3327
+ toolResultProviderOptions,
3328
+ providerOptionsName
3329
+ );
3330
+ }
3309
3331
  function isFileId(data, prefixes) {
3310
3332
  if (!prefixes) return false;
3311
3333
  return prefixes.some((prefix) => data.startsWith(prefix));
@@ -3806,22 +3828,41 @@ async function convertToOpenAIResponsesInput({
3806
3828
  parallelToolResultGroup.metadata.toolCallId
3807
3829
  );
3808
3830
  const toolOutputs = await Promise.all(
3809
- parallelToolResultGroup.results.map(
3810
- async (result) => convertFunctionToolResultOutput({
3831
+ parallelToolResultGroup.results.map(async (result) => {
3832
+ const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
3811
3833
  output: result.output,
3812
- providerOptionsName,
3813
- warnings
3814
- })
3815
- )
3834
+ toolResultProviderOptions: result.providerOptions,
3835
+ providerOptionsName
3836
+ });
3837
+ return {
3838
+ output: await convertFunctionToolResultOutput({
3839
+ output: result.output,
3840
+ providerOptionsName,
3841
+ warnings
3842
+ }),
3843
+ promptCacheBreakpoint
3844
+ };
3845
+ })
3846
+ );
3847
+ const serializedToolOutputs = toolOutputs.map(
3848
+ ({ output: output2 }) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
3849
+ );
3850
+ const hasPromptCacheBreakpoint = toolOutputs.some(
3851
+ ({ promptCacheBreakpoint }) => promptCacheBreakpoint != null
3816
3852
  );
3817
3853
  input.push({
3818
3854
  type: "function_call_output",
3819
3855
  call_id: parallelToolResultGroup.metadata.toolCallId,
3820
3856
  // The internal wrapper returns one output containing the child
3821
3857
  // results in the same order as the original tool_uses array.
3822
- output: toolOutputs.map(
3823
- (output2) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
3824
- ).join("\n")
3858
+ output: hasPromptCacheBreakpoint ? serializedToolOutputs.map((text, index) => ({
3859
+ type: "input_text",
3860
+ text: index === 0 ? text : `
3861
+ ${text}`,
3862
+ ...toolOutputs[index].promptCacheBreakpoint != null && {
3863
+ prompt_cache_breakpoint: toolOutputs[index].promptCacheBreakpoint
3864
+ }
3865
+ })) : serializedToolOutputs.join("\n")
3825
3866
  });
3826
3867
  }
3827
3868
  continue;
@@ -3895,23 +3936,37 @@ async function convertToOpenAIResponsesInput({
3895
3936
  continue;
3896
3937
  }
3897
3938
  if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
3939
+ const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
3940
+ output,
3941
+ toolResultProviderOptions: part.providerOptions,
3942
+ providerOptionsName
3943
+ });
3944
+ const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
3945
+ {
3946
+ type: "input_text",
3947
+ text: value,
3948
+ prompt_cache_breakpoint: promptCacheBreakpoint
3949
+ }
3950
+ ];
3898
3951
  let outputValue;
3899
3952
  switch (output.type) {
3900
3953
  case "text":
3901
3954
  case "error-text":
3902
- outputValue = output.value;
3955
+ outputValue = convertScalarOutput(output.value);
3903
3956
  break;
3904
3957
  case "execution-denied":
3905
- outputValue = (_y = output.reason) != null ? _y : "Tool call execution denied.";
3958
+ outputValue = convertScalarOutput(
3959
+ (_y = output.reason) != null ? _y : "Tool call execution denied."
3960
+ );
3906
3961
  break;
3907
3962
  case "json":
3908
3963
  case "error-json":
3909
- outputValue = JSON.stringify(output.value);
3964
+ outputValue = convertScalarOutput(JSON.stringify(output.value));
3910
3965
  break;
3911
3966
  case "content":
3912
3967
  outputValue = output.value.map((item) => {
3913
3968
  var _a3, _b2, _c2, _d2, _e2;
3914
- const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3969
+ const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
3915
3970
  item.providerOptions,
3916
3971
  providerOptionsName
3917
3972
  );
@@ -3920,8 +3975,8 @@ async function convertToOpenAIResponsesInput({
3920
3975
  return {
3921
3976
  type: "input_text",
3922
3977
  text: item.text,
3923
- ...promptCacheBreakpoint != null && {
3924
- prompt_cache_breakpoint: promptCacheBreakpoint
3978
+ ...promptCacheBreakpoint2 != null && {
3979
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3925
3980
  }
3926
3981
  };
3927
3982
  case "image-data":
@@ -3929,8 +3984,8 @@ async function convertToOpenAIResponsesInput({
3929
3984
  type: "input_image",
3930
3985
  image_url: `data:${item.mediaType};base64,${item.data}`,
3931
3986
  detail: (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3932
- ...promptCacheBreakpoint != null && {
3933
- prompt_cache_breakpoint: promptCacheBreakpoint
3987
+ ...promptCacheBreakpoint2 != null && {
3988
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3934
3989
  }
3935
3990
  };
3936
3991
  case "image-url":
@@ -3938,8 +3993,8 @@ async function convertToOpenAIResponsesInput({
3938
3993
  type: "input_image",
3939
3994
  image_url: item.url,
3940
3995
  detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
3941
- ...promptCacheBreakpoint != null && {
3942
- prompt_cache_breakpoint: promptCacheBreakpoint
3996
+ ...promptCacheBreakpoint2 != null && {
3997
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3943
3998
  }
3944
3999
  };
3945
4000
  case "file-data":
@@ -3947,16 +4002,16 @@ async function convertToOpenAIResponsesInput({
3947
4002
  type: "input_file",
3948
4003
  filename: (_e2 = item.filename) != null ? _e2 : "data",
3949
4004
  file_data: `data:${item.mediaType};base64,${item.data}`,
3950
- ...promptCacheBreakpoint != null && {
3951
- prompt_cache_breakpoint: promptCacheBreakpoint
4005
+ ...promptCacheBreakpoint2 != null && {
4006
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3952
4007
  }
3953
4008
  };
3954
4009
  case "file-url":
3955
4010
  return {
3956
4011
  type: "input_file",
3957
4012
  file_url: item.url,
3958
- ...promptCacheBreakpoint != null && {
3959
- prompt_cache_breakpoint: promptCacheBreakpoint
4013
+ ...promptCacheBreakpoint2 != null && {
4014
+ prompt_cache_breakpoint: promptCacheBreakpoint2
3960
4015
  }
3961
4016
  };
3962
4017
  default:
@@ -3980,6 +4035,11 @@ async function convertToOpenAIResponsesInput({
3980
4035
  }
3981
4036
  const contentValue = await convertFunctionToolResultOutput({
3982
4037
  output,
4038
+ promptCacheBreakpoint: getScalarToolResultPromptCacheBreakpoint({
4039
+ output,
4040
+ toolResultProviderOptions: part.providerOptions,
4041
+ providerOptionsName
4042
+ }),
3983
4043
  providerOptionsName,
3984
4044
  warnings
3985
4045
  });
@@ -8012,7 +8072,7 @@ var OpenAITranscriptionModel = class {
8012
8072
  };
8013
8073
 
8014
8074
  // src/version.ts
8015
- var VERSION = true ? "3.0.105" : "0.0.0-test";
8075
+ var VERSION = true ? "3.0.106" : "0.0.0-test";
8016
8076
 
8017
8077
  // src/openai-provider.ts
8018
8078
  function createOpenAI(options = {}) {