@ai-sdk/openai 4.0.51 → 4.0.52
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/CHANGELOG.md +9 -0
- package/dist/index.js +101 -40
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +100 -39
- package/dist/internal/index.js.map +1 -1
- package/package.json +3 -3
- package/src/responses/convert-to-openai-responses-input.ts +102 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 4.0.52
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1c68540: Preserve explicit prompt cache breakpoints on scalar Responses tool results.
|
|
8
|
+
- Updated dependencies [aa45741]
|
|
9
|
+
- @ai-sdk/provider@4.0.9
|
|
10
|
+
- @ai-sdk/provider-utils@5.0.34
|
|
11
|
+
|
|
3
12
|
## 4.0.51
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -4607,26 +4607,38 @@ async function convertFunctionToolResultOutput({
|
|
|
4607
4607
|
output,
|
|
4608
4608
|
toolName,
|
|
4609
4609
|
outputSchemaToolNames,
|
|
4610
|
+
promptCacheBreakpoint,
|
|
4610
4611
|
providerOptionsName,
|
|
4611
4612
|
warnings
|
|
4612
4613
|
}) {
|
|
4613
4614
|
var _a2;
|
|
4614
4615
|
const hasOutputSchema = outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.has(toolName);
|
|
4616
|
+
const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
|
|
4617
|
+
{
|
|
4618
|
+
type: "input_text",
|
|
4619
|
+
text: value,
|
|
4620
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
4621
|
+
}
|
|
4622
|
+
];
|
|
4615
4623
|
switch (output.type) {
|
|
4616
4624
|
case "text":
|
|
4617
4625
|
case "error-text":
|
|
4618
|
-
return
|
|
4626
|
+
return convertScalarOutput(
|
|
4627
|
+
hasOutputSchema ? JSON.stringify(output.value) : output.value
|
|
4628
|
+
);
|
|
4619
4629
|
case "execution-denied": {
|
|
4620
4630
|
const reason = (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
|
|
4621
|
-
return
|
|
4631
|
+
return convertScalarOutput(
|
|
4632
|
+
hasOutputSchema ? JSON.stringify(reason) : reason
|
|
4633
|
+
);
|
|
4622
4634
|
}
|
|
4623
4635
|
case "json":
|
|
4624
4636
|
case "error-json":
|
|
4625
|
-
return JSON.stringify(output.value);
|
|
4637
|
+
return convertScalarOutput(JSON.stringify(output.value));
|
|
4626
4638
|
case "content":
|
|
4627
4639
|
return output.value.map((item) => {
|
|
4628
4640
|
var _a3, _b, _c;
|
|
4629
|
-
const
|
|
4641
|
+
const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
|
|
4630
4642
|
item.providerOptions,
|
|
4631
4643
|
providerOptionsName
|
|
4632
4644
|
);
|
|
@@ -4635,8 +4647,8 @@ async function convertFunctionToolResultOutput({
|
|
|
4635
4647
|
return {
|
|
4636
4648
|
type: "input_text",
|
|
4637
4649
|
text: item.text,
|
|
4638
|
-
...
|
|
4639
|
-
prompt_cache_breakpoint:
|
|
4650
|
+
...promptCacheBreakpoint2 != null && {
|
|
4651
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
4640
4652
|
}
|
|
4641
4653
|
};
|
|
4642
4654
|
}
|
|
@@ -4650,8 +4662,8 @@ async function convertFunctionToolResultOutput({
|
|
|
4650
4662
|
type: "input_image",
|
|
4651
4663
|
image_url: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
|
|
4652
4664
|
detail: imageDetail,
|
|
4653
|
-
...
|
|
4654
|
-
prompt_cache_breakpoint:
|
|
4665
|
+
...promptCacheBreakpoint2 != null && {
|
|
4666
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
4655
4667
|
}
|
|
4656
4668
|
};
|
|
4657
4669
|
}
|
|
@@ -4659,8 +4671,8 @@ async function convertFunctionToolResultOutput({
|
|
|
4659
4671
|
type: "input_file",
|
|
4660
4672
|
filename: (_c = item.filename) != null ? _c : "data",
|
|
4661
4673
|
file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
|
|
4662
|
-
...
|
|
4663
|
-
prompt_cache_breakpoint:
|
|
4674
|
+
...promptCacheBreakpoint2 != null && {
|
|
4675
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
4664
4676
|
}
|
|
4665
4677
|
};
|
|
4666
4678
|
}
|
|
@@ -4670,16 +4682,16 @@ async function convertFunctionToolResultOutput({
|
|
|
4670
4682
|
type: "input_image",
|
|
4671
4683
|
image_url: item.data.url.toString(),
|
|
4672
4684
|
detail: imageDetail,
|
|
4673
|
-
...
|
|
4674
|
-
prompt_cache_breakpoint:
|
|
4685
|
+
...promptCacheBreakpoint2 != null && {
|
|
4686
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
4675
4687
|
}
|
|
4676
4688
|
};
|
|
4677
4689
|
}
|
|
4678
4690
|
return {
|
|
4679
4691
|
type: "input_file",
|
|
4680
4692
|
file_url: item.data.url.toString(),
|
|
4681
|
-
...
|
|
4682
|
-
prompt_cache_breakpoint:
|
|
4693
|
+
...promptCacheBreakpoint2 != null && {
|
|
4694
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
4683
4695
|
}
|
|
4684
4696
|
};
|
|
4685
4697
|
}
|
|
@@ -4761,6 +4773,17 @@ function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
|
|
|
4761
4773
|
var _a2;
|
|
4762
4774
|
return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
4763
4775
|
}
|
|
4776
|
+
function getScalarToolResultPromptCacheBreakpoint({
|
|
4777
|
+
output,
|
|
4778
|
+
toolResultProviderOptions,
|
|
4779
|
+
providerOptionsName
|
|
4780
|
+
}) {
|
|
4781
|
+
var _a2;
|
|
4782
|
+
return output.type === "content" ? void 0 : (_a2 = getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName)) != null ? _a2 : getPromptCacheBreakpoint2(
|
|
4783
|
+
toolResultProviderOptions,
|
|
4784
|
+
providerOptionsName
|
|
4785
|
+
);
|
|
4786
|
+
}
|
|
4764
4787
|
function isFileId(data, prefixes) {
|
|
4765
4788
|
if (!prefixes) return false;
|
|
4766
4789
|
return prefixes.some((prefix) => data.startsWith(prefix));
|
|
@@ -5408,24 +5431,43 @@ async function convertToOpenAIResponsesInput({
|
|
|
5408
5431
|
parallelToolResultGroup.metadata.toolCallId
|
|
5409
5432
|
);
|
|
5410
5433
|
const toolOutputs = await Promise.all(
|
|
5411
|
-
parallelToolResultGroup.results.map(
|
|
5412
|
-
|
|
5434
|
+
parallelToolResultGroup.results.map(async (result) => {
|
|
5435
|
+
const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
|
|
5413
5436
|
output: result.output,
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
|
|
5419
|
-
|
|
5437
|
+
toolResultProviderOptions: result.providerOptions,
|
|
5438
|
+
providerOptionsName
|
|
5439
|
+
});
|
|
5440
|
+
return {
|
|
5441
|
+
output: await convertFunctionToolResultOutput({
|
|
5442
|
+
output: result.output,
|
|
5443
|
+
toolName: result.toolName,
|
|
5444
|
+
outputSchemaToolNames,
|
|
5445
|
+
providerOptionsName,
|
|
5446
|
+
warnings
|
|
5447
|
+
}),
|
|
5448
|
+
promptCacheBreakpoint
|
|
5449
|
+
};
|
|
5450
|
+
})
|
|
5451
|
+
);
|
|
5452
|
+
const serializedToolOutputs = toolOutputs.map(
|
|
5453
|
+
({ output: output2 }) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
|
|
5454
|
+
);
|
|
5455
|
+
const hasPromptCacheBreakpoint = toolOutputs.some(
|
|
5456
|
+
({ promptCacheBreakpoint }) => promptCacheBreakpoint != null
|
|
5420
5457
|
);
|
|
5421
5458
|
input.push({
|
|
5422
5459
|
type: "function_call_output",
|
|
5423
5460
|
call_id: parallelToolResultGroup.metadata.toolCallId,
|
|
5424
5461
|
// The internal wrapper returns one output containing the child
|
|
5425
5462
|
// results in the same order as the original tool_uses array.
|
|
5426
|
-
output:
|
|
5427
|
-
|
|
5428
|
-
|
|
5463
|
+
output: hasPromptCacheBreakpoint ? serializedToolOutputs.map((text, index) => ({
|
|
5464
|
+
type: "input_text",
|
|
5465
|
+
text: index === 0 ? text : `
|
|
5466
|
+
${text}`,
|
|
5467
|
+
...toolOutputs[index].promptCacheBreakpoint != null && {
|
|
5468
|
+
prompt_cache_breakpoint: toolOutputs[index].promptCacheBreakpoint
|
|
5469
|
+
}
|
|
5470
|
+
})) : serializedToolOutputs.join("\n")
|
|
5429
5471
|
});
|
|
5430
5472
|
}
|
|
5431
5473
|
continue;
|
|
@@ -5521,23 +5563,37 @@ async function convertToOpenAIResponsesInput({
|
|
|
5521
5563
|
continue;
|
|
5522
5564
|
}
|
|
5523
5565
|
if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
|
|
5566
|
+
const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
|
|
5567
|
+
output,
|
|
5568
|
+
toolResultProviderOptions: part.providerOptions,
|
|
5569
|
+
providerOptionsName
|
|
5570
|
+
});
|
|
5571
|
+
const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
|
|
5572
|
+
{
|
|
5573
|
+
type: "input_text",
|
|
5574
|
+
text: value,
|
|
5575
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
5576
|
+
}
|
|
5577
|
+
];
|
|
5524
5578
|
let outputValue;
|
|
5525
5579
|
switch (output.type) {
|
|
5526
5580
|
case "text":
|
|
5527
5581
|
case "error-text":
|
|
5528
|
-
outputValue = output.value;
|
|
5582
|
+
outputValue = convertScalarOutput(output.value);
|
|
5529
5583
|
break;
|
|
5530
5584
|
case "execution-denied":
|
|
5531
|
-
outputValue = (
|
|
5585
|
+
outputValue = convertScalarOutput(
|
|
5586
|
+
(_I = output.reason) != null ? _I : "Tool call execution denied."
|
|
5587
|
+
);
|
|
5532
5588
|
break;
|
|
5533
5589
|
case "json":
|
|
5534
5590
|
case "error-json":
|
|
5535
|
-
outputValue = JSON.stringify(output.value);
|
|
5591
|
+
outputValue = convertScalarOutput(JSON.stringify(output.value));
|
|
5536
5592
|
break;
|
|
5537
5593
|
case "content":
|
|
5538
5594
|
outputValue = output.value.map((item) => {
|
|
5539
5595
|
var _a3, _b2, _c2;
|
|
5540
|
-
const
|
|
5596
|
+
const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
|
|
5541
5597
|
item.providerOptions,
|
|
5542
5598
|
providerOptionsName
|
|
5543
5599
|
);
|
|
@@ -5546,8 +5602,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
5546
5602
|
return {
|
|
5547
5603
|
type: "input_text",
|
|
5548
5604
|
text: item.text,
|
|
5549
|
-
...
|
|
5550
|
-
prompt_cache_breakpoint:
|
|
5605
|
+
...promptCacheBreakpoint2 != null && {
|
|
5606
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
5551
5607
|
}
|
|
5552
5608
|
};
|
|
5553
5609
|
case "file": {
|
|
@@ -5562,8 +5618,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
5562
5618
|
type: "input_image",
|
|
5563
5619
|
image_url: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
|
|
5564
5620
|
detail: imageDetail,
|
|
5565
|
-
...
|
|
5566
|
-
prompt_cache_breakpoint:
|
|
5621
|
+
...promptCacheBreakpoint2 != null && {
|
|
5622
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
5567
5623
|
}
|
|
5568
5624
|
};
|
|
5569
5625
|
}
|
|
@@ -5571,8 +5627,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
5571
5627
|
type: "input_file",
|
|
5572
5628
|
filename: (_c2 = item.filename) != null ? _c2 : "data",
|
|
5573
5629
|
file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
|
|
5574
|
-
...
|
|
5575
|
-
prompt_cache_breakpoint:
|
|
5630
|
+
...promptCacheBreakpoint2 != null && {
|
|
5631
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
5576
5632
|
}
|
|
5577
5633
|
};
|
|
5578
5634
|
}
|
|
@@ -5582,16 +5638,16 @@ async function convertToOpenAIResponsesInput({
|
|
|
5582
5638
|
type: "input_image",
|
|
5583
5639
|
image_url: item.data.url.toString(),
|
|
5584
5640
|
detail: imageDetail,
|
|
5585
|
-
...
|
|
5586
|
-
prompt_cache_breakpoint:
|
|
5641
|
+
...promptCacheBreakpoint2 != null && {
|
|
5642
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
5587
5643
|
}
|
|
5588
5644
|
};
|
|
5589
5645
|
}
|
|
5590
5646
|
return {
|
|
5591
5647
|
type: "input_file",
|
|
5592
5648
|
file_url: item.data.url.toString(),
|
|
5593
|
-
...
|
|
5594
|
-
prompt_cache_breakpoint:
|
|
5649
|
+
...promptCacheBreakpoint2 != null && {
|
|
5650
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
5595
5651
|
}
|
|
5596
5652
|
};
|
|
5597
5653
|
}
|
|
@@ -5624,6 +5680,11 @@ async function convertToOpenAIResponsesInput({
|
|
|
5624
5680
|
output,
|
|
5625
5681
|
toolName: part.toolName,
|
|
5626
5682
|
outputSchemaToolNames,
|
|
5683
|
+
promptCacheBreakpoint: getScalarToolResultPromptCacheBreakpoint({
|
|
5684
|
+
output,
|
|
5685
|
+
toolResultProviderOptions: part.providerOptions,
|
|
5686
|
+
providerOptionsName
|
|
5687
|
+
}),
|
|
5627
5688
|
providerOptionsName,
|
|
5628
5689
|
warnings
|
|
5629
5690
|
});
|
|
@@ -10612,7 +10673,7 @@ var OpenAISkills = class {
|
|
|
10612
10673
|
};
|
|
10613
10674
|
|
|
10614
10675
|
// src/version.ts
|
|
10615
|
-
var VERSION = true ? "4.0.
|
|
10676
|
+
var VERSION = true ? "4.0.52" : "0.0.0-test";
|
|
10616
10677
|
|
|
10617
10678
|
// src/openai-provider.ts
|
|
10618
10679
|
function createOpenAI(options = {}) {
|