@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/CHANGELOG.md +97 -0
- package/dist/index.js +26 -2
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +25 -1
- package/dist/internal/index.js.map +1 -1
- package/package.json +4 -4
- package/src/convert-to-anthropic-prompt.ts +32 -1
package/dist/internal/index.js
CHANGED
|
@@ -3192,7 +3192,10 @@ async function convertToAnthropicPrompt({
|
|
|
3192
3192
|
}
|
|
3193
3193
|
}
|
|
3194
3194
|
}
|
|
3195
|
-
messages.push({
|
|
3195
|
+
messages.push({
|
|
3196
|
+
role: "assistant",
|
|
3197
|
+
content: moveToolUseBlocksToEnd(anthropicContent)
|
|
3198
|
+
});
|
|
3196
3199
|
break;
|
|
3197
3200
|
}
|
|
3198
3201
|
default: {
|
|
@@ -3252,6 +3255,27 @@ function groupIntoBlocks(prompt) {
|
|
|
3252
3255
|
}
|
|
3253
3256
|
return blocks;
|
|
3254
3257
|
}
|
|
3258
|
+
function moveToolUseBlocksToEnd(content) {
|
|
3259
|
+
const result = [];
|
|
3260
|
+
let segment = [];
|
|
3261
|
+
function flushSegment() {
|
|
3262
|
+
result.push(
|
|
3263
|
+
...segment.filter((part) => part.type !== "tool_use"),
|
|
3264
|
+
...segment.filter((part) => part.type === "tool_use")
|
|
3265
|
+
);
|
|
3266
|
+
segment = [];
|
|
3267
|
+
}
|
|
3268
|
+
for (const part of content) {
|
|
3269
|
+
if (part.type === "thinking" || part.type === "redacted_thinking") {
|
|
3270
|
+
flushSegment();
|
|
3271
|
+
result.push(part);
|
|
3272
|
+
} else {
|
|
3273
|
+
segment.push(part);
|
|
3274
|
+
}
|
|
3275
|
+
}
|
|
3276
|
+
flushSegment();
|
|
3277
|
+
return result;
|
|
3278
|
+
}
|
|
3255
3279
|
|
|
3256
3280
|
// src/map-anthropic-stop-reason.ts
|
|
3257
3281
|
function mapAnthropicStopReason({
|