@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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 4.0.88
4
+
5
+ ### Patch Changes
6
+
7
+ - 32ff7ad: Preserve tool errors in OpenAI Chat Completions and Responses by wrapping their payloads in an `error` object. Send Google tool errors and denied executions under `functionResponse.response.error`.
8
+
9
+ ## 4.0.87
10
+
11
+ ### Patch Changes
12
+
13
+ - bccc1b7: fix(openai): avoid duplicate references for stored messages with multiple text parts
14
+
3
15
  ## 4.0.86
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -617,15 +617,17 @@ function convertToOpenAIChatMessages({ prompt, systemMessageMode = "system" }) {
617
617
  let contentValue;
618
618
  switch (output.type) {
619
619
  case "text":
620
- case "error-text":
621
620
  contentValue = output.value;
622
621
  break;
622
+ case "error-text":
623
+ case "error-json":
624
+ contentValue = JSON.stringify({ error: output.value });
625
+ break;
623
626
  case "execution-denied":
624
627
  contentValue = output.reason ?? "Tool call execution denied.";
625
628
  break;
626
629
  case "content":
627
- case "json":
628
- case "error-json": contentValue = JSON.stringify(output.value);
630
+ case "json": contentValue = JSON.stringify(output.value);
629
631
  }
630
632
  messages.push({
631
633
  role: "tool",
@@ -4557,14 +4559,14 @@ async function convertFunctionToolResultOutput({ output, toolName, outputSchemaT
4557
4559
  prompt_cache_breakpoint: promptCacheBreakpoint
4558
4560
  }];
4559
4561
  switch (output.type) {
4560
- case "text":
4561
- case "error-text": return convertScalarOutput(hasOutputSchema ? JSON.stringify(output.value) : output.value);
4562
+ case "text": return convertScalarOutput(hasOutputSchema ? JSON.stringify(output.value) : output.value);
4563
+ case "error-text":
4564
+ case "error-json": return convertScalarOutput(JSON.stringify({ error: output.value }));
4562
4565
  case "execution-denied": {
4563
4566
  const reason = output.reason ?? "Tool call execution denied.";
4564
4567
  return convertScalarOutput(hasOutputSchema ? JSON.stringify(reason) : reason);
4565
4568
  }
4566
- case "json":
4567
- case "error-json": return convertScalarOutput(JSON.stringify(output.value));
4569
+ case "json": return convertScalarOutput(JSON.stringify(output.value));
4568
4570
  case "content": return output.value.map((item) => {
4569
4571
  const promptCacheBreakpoint = getPromptCacheBreakpoint(item.providerOptions, providerOptionsName);
4570
4572
  switch (item.type) {
@@ -4834,6 +4836,7 @@ async function convertToOpenAIResponsesInput({ prompt, toolNameMapping, systemMe
4834
4836
  break;
4835
4837
  case "assistant": {
4836
4838
  const reasoningMessages = {};
4839
+ const emittedTextItemIds = /* @__PURE__ */ new Set();
4837
4840
  for (const part of content) switch (part.type) {
4838
4841
  case "text": {
4839
4842
  const providerOptions = part.providerOptions?.[providerOptionsName];
@@ -4841,10 +4844,13 @@ async function convertToOpenAIResponsesInput({ prompt, toolNameMapping, systemMe
4841
4844
  const phase = providerOptions?.phase;
4842
4845
  if (hasConversation && id != null) break;
4843
4846
  if (store && id != null) {
4844
- input.push({
4845
- type: "item_reference",
4846
- id
4847
- });
4847
+ if (!emittedTextItemIds.has(id)) {
4848
+ emittedTextItemIds.add(id);
4849
+ input.push({
4850
+ type: "item_reference",
4851
+ id
4852
+ });
4853
+ }
4848
4854
  break;
4849
4855
  }
4850
4856
  input.push({
@@ -5379,14 +5385,16 @@ async function convertToOpenAIResponsesInput({ prompt, toolNameMapping, systemMe
5379
5385
  let outputValue;
5380
5386
  switch (output.type) {
5381
5387
  case "text":
5382
- case "error-text":
5383
5388
  outputValue = convertScalarOutput(output.value);
5384
5389
  break;
5390
+ case "error-text":
5391
+ case "error-json":
5392
+ outputValue = convertScalarOutput(JSON.stringify({ error: output.value }));
5393
+ break;
5385
5394
  case "execution-denied":
5386
5395
  outputValue = convertScalarOutput(output.reason ?? "Tool call execution denied.");
5387
5396
  break;
5388
5397
  case "json":
5389
- case "error-json":
5390
5398
  outputValue = convertScalarOutput(JSON.stringify(output.value));
5391
5399
  break;
5392
5400
  case "content":
@@ -10038,7 +10046,7 @@ var OpenAISkills = class {
10038
10046
  };
10039
10047
  //#endregion
10040
10048
  //#region src/version.ts
10041
- const VERSION = "4.0.86";
10049
+ const VERSION = "4.0.88";
10042
10050
  //#endregion
10043
10051
  //#region src/openai-provider.ts
10044
10052
  /**