@ai-sdk/anthropic 2.0.96 → 2.0.99

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.
@@ -1988,7 +1988,10 @@ async function convertToAnthropicMessagesPrompt({
1988
1988
  }
1989
1989
  }
1990
1990
  }
1991
- messages.push({ role: "assistant", content: anthropicContent });
1991
+ messages.push({
1992
+ role: "assistant",
1993
+ content: moveToolUseBlocksToEnd(anthropicContent)
1994
+ });
1992
1995
  break;
1993
1996
  }
1994
1997
  default: {
@@ -2048,6 +2051,27 @@ function groupIntoBlocks(prompt) {
2048
2051
  }
2049
2052
  return blocks;
2050
2053
  }
2054
+ function moveToolUseBlocksToEnd(content) {
2055
+ const result = [];
2056
+ let segment = [];
2057
+ function flushSegment() {
2058
+ result.push(
2059
+ ...segment.filter((part) => part.type !== "tool_use"),
2060
+ ...segment.filter((part) => part.type === "tool_use")
2061
+ );
2062
+ segment = [];
2063
+ }
2064
+ for (const part of content) {
2065
+ if (part.type === "thinking" || part.type === "redacted_thinking") {
2066
+ flushSegment();
2067
+ result.push(part);
2068
+ } else {
2069
+ segment.push(part);
2070
+ }
2071
+ }
2072
+ flushSegment();
2073
+ return result;
2074
+ }
2051
2075
 
2052
2076
  // src/map-anthropic-stop-reason.ts
2053
2077
  function mapAnthropicStopReason({