ai 5.0.279 → 5.0.280

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
@@ -727,7 +727,7 @@ import {
727
727
  } from "@ai-sdk/provider-utils";
728
728
 
729
729
  // src/version.ts
730
- var VERSION = true ? "5.0.279" : "0.0.0-test";
730
+ var VERSION = true ? "5.0.280" : "0.0.0-test";
731
731
 
732
732
  // src/util/download/download.ts
733
733
  var download = async ({
@@ -8884,21 +8884,52 @@ function pruneMessages({
8884
8884
  if (message.role !== "assistant" && message.role !== "tool" || typeof message.content === "string" || keepLastMessagesCount && messageIndex >= messages.length - keepLastMessagesCount) {
8885
8885
  return message;
8886
8886
  }
8887
- const toolCallIdToToolName = {};
8888
- return {
8889
- ...message,
8890
- content: message.content.filter((part) => {
8891
- if (part.type !== "tool-call" && part.type !== "tool-result") {
8892
- return true;
8887
+ const keepParts = message.content.map((part) => {
8888
+ if (part.type !== "tool-call" && part.type !== "tool-result") {
8889
+ return true;
8890
+ }
8891
+ if ((part.type === "tool-call" || part.type === "tool-result") && keptToolCallIds.has(part.toolCallId)) {
8892
+ return true;
8893
+ }
8894
+ return toolCall.tools != null && !toolCall.tools.includes(part.toolName);
8895
+ });
8896
+ if (message.role === "assistant") {
8897
+ for (let reasoningIndex = 0; reasoningIndex < message.content.length; reasoningIndex++) {
8898
+ const part = message.content[reasoningIndex];
8899
+ if (part.type !== "reasoning") {
8900
+ continue;
8893
8901
  }
8894
- if (part.type === "tool-call") {
8895
- toolCallIdToToolName[part.toolCallId] = part.toolName;
8902
+ let reasoningEndIndex = reasoningIndex + 1;
8903
+ while (reasoningEndIndex < message.content.length) {
8904
+ const nextPart = message.content[reasoningEndIndex];
8905
+ if (nextPart.type !== "reasoning") {
8906
+ break;
8907
+ }
8908
+ reasoningEndIndex++;
8896
8909
  }
8897
- if ((part.type === "tool-call" || part.type === "tool-result") && keptToolCallIds.has(part.toolCallId)) {
8898
- return true;
8910
+ let followingPartIndex = reasoningEndIndex;
8911
+ let hasFollowingPart = false;
8912
+ let hasKeptFollowingPart = false;
8913
+ while (followingPartIndex < message.content.length) {
8914
+ const followingPart = message.content[followingPartIndex];
8915
+ if (followingPart.type === "reasoning") {
8916
+ break;
8917
+ }
8918
+ hasFollowingPart = true;
8919
+ hasKeptFollowingPart || (hasKeptFollowingPart = keepParts[followingPartIndex]);
8920
+ followingPartIndex++;
8899
8921
  }
8900
- return toolCall.tools != null && !toolCall.tools.includes(part.toolName);
8901
- })
8922
+ if (hasFollowingPart && !hasKeptFollowingPart) {
8923
+ for (let index = reasoningIndex; index < reasoningEndIndex; index++) {
8924
+ keepParts[index] = false;
8925
+ }
8926
+ }
8927
+ reasoningIndex = followingPartIndex - 1;
8928
+ }
8929
+ }
8930
+ return {
8931
+ ...message,
8932
+ content: message.content.filter((_, index) => keepParts[index])
8902
8933
  };
8903
8934
  });
8904
8935
  }