@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.
@@ -409,15 +409,17 @@ function convertToOpenAIChatMessages({ prompt, systemMessageMode = "system" }) {
409
409
  let contentValue;
410
410
  switch (output.type) {
411
411
  case "text":
412
- case "error-text":
413
412
  contentValue = output.value;
414
413
  break;
414
+ case "error-text":
415
+ case "error-json":
416
+ contentValue = JSON.stringify({ error: output.value });
417
+ break;
415
418
  case "execution-denied":
416
419
  contentValue = output.reason ?? "Tool call execution denied.";
417
420
  break;
418
421
  case "content":
419
- case "json":
420
- case "error-json": contentValue = JSON.stringify(output.value);
422
+ case "json": contentValue = JSON.stringify(output.value);
421
423
  }
422
424
  messages.push({
423
425
  role: "tool",
@@ -3311,14 +3313,14 @@ async function convertFunctionToolResultOutput({ output, toolName, outputSchemaT
3311
3313
  prompt_cache_breakpoint: promptCacheBreakpoint
3312
3314
  }];
3313
3315
  switch (output.type) {
3314
- case "text":
3315
- case "error-text": return convertScalarOutput(hasOutputSchema ? JSON.stringify(output.value) : output.value);
3316
+ case "text": return convertScalarOutput(hasOutputSchema ? JSON.stringify(output.value) : output.value);
3317
+ case "error-text":
3318
+ case "error-json": return convertScalarOutput(JSON.stringify({ error: output.value }));
3316
3319
  case "execution-denied": {
3317
3320
  const reason = output.reason ?? "Tool call execution denied.";
3318
3321
  return convertScalarOutput(hasOutputSchema ? JSON.stringify(reason) : reason);
3319
3322
  }
3320
- case "json":
3321
- case "error-json": return convertScalarOutput(JSON.stringify(output.value));
3323
+ case "json": return convertScalarOutput(JSON.stringify(output.value));
3322
3324
  case "content": return output.value.map((item) => {
3323
3325
  const promptCacheBreakpoint = getPromptCacheBreakpoint(item.providerOptions, providerOptionsName);
3324
3326
  switch (item.type) {
@@ -3588,6 +3590,7 @@ async function convertToOpenAIResponsesInput({ prompt, toolNameMapping, systemMe
3588
3590
  break;
3589
3591
  case "assistant": {
3590
3592
  const reasoningMessages = {};
3593
+ const emittedTextItemIds = /* @__PURE__ */ new Set();
3591
3594
  for (const part of content) switch (part.type) {
3592
3595
  case "text": {
3593
3596
  const providerOptions = part.providerOptions?.[providerOptionsName];
@@ -3595,10 +3598,13 @@ async function convertToOpenAIResponsesInput({ prompt, toolNameMapping, systemMe
3595
3598
  const phase = providerOptions?.phase;
3596
3599
  if (hasConversation && id != null) break;
3597
3600
  if (store && id != null) {
3598
- input.push({
3599
- type: "item_reference",
3600
- id
3601
- });
3601
+ if (!emittedTextItemIds.has(id)) {
3602
+ emittedTextItemIds.add(id);
3603
+ input.push({
3604
+ type: "item_reference",
3605
+ id
3606
+ });
3607
+ }
3602
3608
  break;
3603
3609
  }
3604
3610
  input.push({
@@ -4133,14 +4139,16 @@ async function convertToOpenAIResponsesInput({ prompt, toolNameMapping, systemMe
4133
4139
  let outputValue;
4134
4140
  switch (output.type) {
4135
4141
  case "text":
4136
- case "error-text":
4137
4142
  outputValue = convertScalarOutput(output.value);
4138
4143
  break;
4144
+ case "error-text":
4145
+ case "error-json":
4146
+ outputValue = convertScalarOutput(JSON.stringify({ error: output.value }));
4147
+ break;
4139
4148
  case "execution-denied":
4140
4149
  outputValue = convertScalarOutput(output.reason ?? "Tool call execution denied.");
4141
4150
  break;
4142
4151
  case "json":
4143
- case "error-json":
4144
4152
  outputValue = convertScalarOutput(JSON.stringify(output.value));
4145
4153
  break;
4146
4154
  case "content":