@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 2.0.99
4
+
5
+ ### Patch Changes
6
+
7
+ - 78c7304: fix(anthropic): order client tool calls after provider-executed tool results
8
+
9
+ ## 2.0.98
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [77d33c0]
14
+ - @ai-sdk/provider-utils@3.0.35
15
+
16
+ ## 2.0.97
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [2fff9f1]
21
+ - Updated dependencies [f364ea0]
22
+ - @ai-sdk/provider-utils@3.0.34
23
+
3
24
  ## 2.0.96
4
25
 
5
26
  ### Patch Changes
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
31
31
  var import_provider_utils20 = require("@ai-sdk/provider-utils");
32
32
 
33
33
  // src/version.ts
34
- var VERSION = true ? "2.0.96" : "0.0.0-test";
34
+ var VERSION = true ? "2.0.99" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -1994,7 +1994,10 @@ async function convertToAnthropicMessagesPrompt({
1994
1994
  }
1995
1995
  }
1996
1996
  }
1997
- messages.push({ role: "assistant", content: anthropicContent });
1997
+ messages.push({
1998
+ role: "assistant",
1999
+ content: moveToolUseBlocksToEnd(anthropicContent)
2000
+ });
1998
2001
  break;
1999
2002
  }
2000
2003
  default: {
@@ -2054,6 +2057,27 @@ function groupIntoBlocks(prompt) {
2054
2057
  }
2055
2058
  return blocks;
2056
2059
  }
2060
+ function moveToolUseBlocksToEnd(content) {
2061
+ const result = [];
2062
+ let segment = [];
2063
+ function flushSegment() {
2064
+ result.push(
2065
+ ...segment.filter((part) => part.type !== "tool_use"),
2066
+ ...segment.filter((part) => part.type === "tool_use")
2067
+ );
2068
+ segment = [];
2069
+ }
2070
+ for (const part of content) {
2071
+ if (part.type === "thinking" || part.type === "redacted_thinking") {
2072
+ flushSegment();
2073
+ result.push(part);
2074
+ } else {
2075
+ segment.push(part);
2076
+ }
2077
+ }
2078
+ flushSegment();
2079
+ return result;
2080
+ }
2057
2081
 
2058
2082
  // src/map-anthropic-stop-reason.ts
2059
2083
  function mapAnthropicStopReason({