@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.
@@ -2005,7 +2005,10 @@ async function convertToAnthropicMessagesPrompt({
2005
2005
  }
2006
2006
  }
2007
2007
  }
2008
- messages.push({ role: "assistant", content: anthropicContent });
2008
+ messages.push({
2009
+ role: "assistant",
2010
+ content: moveToolUseBlocksToEnd(anthropicContent)
2011
+ });
2009
2012
  break;
2010
2013
  }
2011
2014
  default: {
@@ -2065,6 +2068,27 @@ function groupIntoBlocks(prompt) {
2065
2068
  }
2066
2069
  return blocks;
2067
2070
  }
2071
+ function moveToolUseBlocksToEnd(content) {
2072
+ const result = [];
2073
+ let segment = [];
2074
+ function flushSegment() {
2075
+ result.push(
2076
+ ...segment.filter((part) => part.type !== "tool_use"),
2077
+ ...segment.filter((part) => part.type === "tool_use")
2078
+ );
2079
+ segment = [];
2080
+ }
2081
+ for (const part of content) {
2082
+ if (part.type === "thinking" || part.type === "redacted_thinking") {
2083
+ flushSegment();
2084
+ result.push(part);
2085
+ } else {
2086
+ segment.push(part);
2087
+ }
2088
+ }
2089
+ flushSegment();
2090
+ return result;
2091
+ }
2068
2092
 
2069
2093
  // src/map-anthropic-stop-reason.ts
2070
2094
  function mapAnthropicStopReason({