@ai-sdk/openai 4.0.86 → 4.0.88

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/openai",
3
- "version": "4.0.86",
3
+ "version": "4.0.88",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -322,15 +322,17 @@ export function convertToOpenAIChatMessages({
322
322
  let contentValue: string;
323
323
  switch (output.type) {
324
324
  case 'text':
325
- case 'error-text':
326
325
  contentValue = output.value;
327
326
  break;
327
+ case 'error-text':
328
+ case 'error-json':
329
+ contentValue = JSON.stringify({ error: output.value });
330
+ break;
328
331
  case 'execution-denied':
329
332
  contentValue = output.reason ?? 'Tool call execution denied.';
330
333
  break;
331
334
  case 'content':
332
335
  case 'json':
333
- case 'error-json':
334
336
  contentValue = JSON.stringify(output.value);
335
337
  break;
336
338
  }
@@ -102,10 +102,12 @@ async function convertFunctionToolResultOutput({
102
102
 
103
103
  switch (output.type) {
104
104
  case 'text':
105
- case 'error-text':
106
105
  return convertScalarOutput(
107
106
  hasOutputSchema ? JSON.stringify(output.value) : output.value,
108
107
  );
108
+ case 'error-text':
109
+ case 'error-json':
110
+ return convertScalarOutput(JSON.stringify({ error: output.value }));
109
111
  case 'execution-denied': {
110
112
  const reason = output.reason ?? 'Tool call execution denied.';
111
113
  return convertScalarOutput(
@@ -113,7 +115,6 @@ async function convertFunctionToolResultOutput({
113
115
  );
114
116
  }
115
117
  case 'json':
116
- case 'error-json':
117
118
  return convertScalarOutput(JSON.stringify(output.value));
118
119
  case 'content':
119
120
  return output.value
@@ -649,6 +650,7 @@ export async function convertToOpenAIResponsesInput({
649
650
 
650
651
  case 'assistant': {
651
652
  const reasoningMessages: Record<string, OpenAIResponsesReasoning> = {};
653
+ const emittedTextItemIds = new Set<string>();
652
654
 
653
655
  for (const part of content) {
654
656
  switch (part.type) {
@@ -669,7 +671,10 @@ export async function convertToOpenAIResponsesInput({
669
671
 
670
672
  // item references reduce the payload size
671
673
  if (store && id != null) {
672
- input.push({ type: 'item_reference', id });
674
+ if (!emittedTextItemIds.has(id)) {
675
+ emittedTextItemIds.add(id);
676
+ input.push({ type: 'item_reference', id });
677
+ }
673
678
  break;
674
679
  }
675
680
 
@@ -1538,16 +1543,20 @@ export async function convertToOpenAIResponsesInput({
1538
1543
  let outputValue: OpenAIResponsesCustomToolCallOutput['output'];
1539
1544
  switch (output.type) {
1540
1545
  case 'text':
1541
- case 'error-text':
1542
1546
  outputValue = convertScalarOutput(output.value);
1543
1547
  break;
1548
+ case 'error-text':
1549
+ case 'error-json':
1550
+ outputValue = convertScalarOutput(
1551
+ JSON.stringify({ error: output.value }),
1552
+ );
1553
+ break;
1544
1554
  case 'execution-denied':
1545
1555
  outputValue = convertScalarOutput(
1546
1556
  output.reason ?? 'Tool call execution denied.',
1547
1557
  );
1548
1558
  break;
1549
1559
  case 'json':
1550
- case 'error-json':
1551
1560
  outputValue = convertScalarOutput(JSON.stringify(output.value));
1552
1561
  break;
1553
1562
  case 'content':