@ai-sdk/anthropic 4.0.0-canary.65 → 4.0.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/anthropic",
3
- "version": "4.0.0-canary.65",
3
+ "version": "4.0.0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -35,15 +35,15 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@ai-sdk/provider": "4.0.0-canary.18",
39
- "@ai-sdk/provider-utils": "5.0.0-canary.47"
38
+ "@ai-sdk/provider": "4.0.0",
39
+ "@ai-sdk/provider-utils": "5.0.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "22.19.19",
43
43
  "tsup": "^8.5.1",
44
44
  "typescript": "5.8.3",
45
45
  "zod": "3.25.76",
46
- "@ai-sdk/test-server": "2.0.0-canary.6",
46
+ "@ai-sdk/test-server": "2.0.0",
47
47
  "@vercel/ai-tsconfig": "0.0.0"
48
48
  },
49
49
  "peerDependencies": {
@@ -1209,7 +1209,10 @@ export async function convertToAnthropicPrompt({
1209
1209
  }
1210
1210
  }
1211
1211
 
1212
- messages.push({ role: 'assistant', content: anthropicContent });
1212
+ messages.push({
1213
+ role: 'assistant',
1214
+ content: moveToolUseBlocksToEnd(anthropicContent),
1215
+ });
1213
1216
 
1214
1217
  break;
1215
1218
  }
@@ -1295,3 +1298,31 @@ function groupIntoBlocks(
1295
1298
 
1296
1299
  return blocks;
1297
1300
  }
1301
+
1302
+ function moveToolUseBlocksToEnd(
1303
+ content: AnthropicAssistantMessage['content'],
1304
+ ): AnthropicAssistantMessage['content'] {
1305
+ const result: AnthropicAssistantMessage['content'] = [];
1306
+ let segment: AnthropicAssistantMessage['content'] = [];
1307
+
1308
+ function flushSegment() {
1309
+ result.push(
1310
+ ...segment.filter(part => part.type !== 'tool_use'),
1311
+ ...segment.filter(part => part.type === 'tool_use'),
1312
+ );
1313
+ segment = [];
1314
+ }
1315
+
1316
+ for (const part of content) {
1317
+ if (part.type === 'thinking' || part.type === 'redacted_thinking') {
1318
+ flushSegment();
1319
+ result.push(part);
1320
+ } else {
1321
+ segment.push(part);
1322
+ }
1323
+ }
1324
+
1325
+ flushSegment();
1326
+
1327
+ return result;
1328
+ }