@ai-sdk/anthropic 2.0.92 → 2.0.94
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 +12 -0
- package/dist/index.js +37 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -4
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +36 -3
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +37 -3
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 2.0.94
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e7afc18: Reject spliced Anthropic generations while allowing duplicate message start events for the active message.
|
|
8
|
+
|
|
9
|
+
## 2.0.93
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 950eec8: Preserve Anthropic prompt-cache matches by replaying complete code-execution transcripts in their original wire shape.
|
|
14
|
+
|
|
3
15
|
## 2.0.92
|
|
4
16
|
|
|
5
17
|
### 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.
|
|
34
|
+
var VERSION = true ? "2.0.94" : "0.0.0-test";
|
|
35
35
|
|
|
36
36
|
// src/anthropic-messages-language-model.ts
|
|
37
37
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -1826,12 +1826,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1826
1826
|
case "tool-call": {
|
|
1827
1827
|
if (part.providerExecuted) {
|
|
1828
1828
|
if (part.toolName === "code_execution" && part.input != null && typeof part.input === "object" && "type" in part.input && typeof part.input.type === "string" && (part.input.type === "bash_code_execution" || part.input.type === "text_editor_code_execution")) {
|
|
1829
|
+
const { type: type2, ...input } = part.input;
|
|
1829
1830
|
anthropicContent.push({
|
|
1830
1831
|
type: "server_tool_use",
|
|
1831
1832
|
id: part.toolCallId,
|
|
1832
|
-
name:
|
|
1833
|
+
name: type2,
|
|
1833
1834
|
// map back to subtool name
|
|
1834
|
-
input
|
|
1835
|
+
input,
|
|
1835
1836
|
cache_control: cacheControl
|
|
1836
1837
|
});
|
|
1837
1838
|
} else if (part.toolName === "code_execution" || // code execution 20250522
|
|
@@ -1903,7 +1904,15 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1903
1904
|
type: "bash_code_execution_tool_result",
|
|
1904
1905
|
tool_use_id: part.toolCallId,
|
|
1905
1906
|
cache_control: cacheControl,
|
|
1906
|
-
|
|
1907
|
+
// Prompt caching requires stable key ordering:
|
|
1908
|
+
// https://platform.claude.com/docs/en/build-with-claude/prompt-caching#troubleshooting-common-issues
|
|
1909
|
+
content: codeExecutionOutput.type === "bash_code_execution_result" ? {
|
|
1910
|
+
type: codeExecutionOutput.type,
|
|
1911
|
+
stdout: codeExecutionOutput.stdout,
|
|
1912
|
+
stderr: codeExecutionOutput.stderr,
|
|
1913
|
+
return_code: codeExecutionOutput.return_code,
|
|
1914
|
+
content: codeExecutionOutput.content
|
|
1915
|
+
} : codeExecutionOutput
|
|
1907
1916
|
} : {
|
|
1908
1917
|
type: "text_editor_code_execution_tool_result",
|
|
1909
1918
|
tool_use_id: part.toolCallId,
|
|
@@ -3088,6 +3097,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3088
3097
|
let container = null;
|
|
3089
3098
|
let iterations = null;
|
|
3090
3099
|
let contextManagement = null;
|
|
3100
|
+
let isMessageOpen = false;
|
|
3101
|
+
let activeMessageId;
|
|
3102
|
+
let hasInvalidMessageSequence = false;
|
|
3091
3103
|
let blockType = void 0;
|
|
3092
3104
|
const generateId3 = this.generateId;
|
|
3093
3105
|
const transformedStream = response.pipeThrough(
|
|
@@ -3097,6 +3109,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3097
3109
|
},
|
|
3098
3110
|
transform(chunk, controller) {
|
|
3099
3111
|
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3112
|
+
if (hasInvalidMessageSequence) {
|
|
3113
|
+
return;
|
|
3114
|
+
}
|
|
3100
3115
|
if (options.includeRawChunks) {
|
|
3101
3116
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3102
3117
|
}
|
|
@@ -3500,6 +3515,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3500
3515
|
}
|
|
3501
3516
|
}
|
|
3502
3517
|
case "message_start": {
|
|
3518
|
+
if (isMessageOpen) {
|
|
3519
|
+
if (activeMessageId === value.message.id) {
|
|
3520
|
+
return;
|
|
3521
|
+
}
|
|
3522
|
+
hasInvalidMessageSequence = true;
|
|
3523
|
+
controller.enqueue({
|
|
3524
|
+
type: "error",
|
|
3525
|
+
error: new import_provider3.InvalidResponseDataError({
|
|
3526
|
+
data: value,
|
|
3527
|
+
message: `Received message_start for message ${JSON.stringify(value.message.id)} while message ${JSON.stringify(activeMessageId)} is still open.`
|
|
3528
|
+
})
|
|
3529
|
+
});
|
|
3530
|
+
return;
|
|
3531
|
+
}
|
|
3532
|
+
isMessageOpen = true;
|
|
3533
|
+
activeMessageId = value.message.id;
|
|
3503
3534
|
usage.inputTokens = value.message.usage.input_tokens;
|
|
3504
3535
|
usage.cachedInputTokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : void 0;
|
|
3505
3536
|
rawUsage = {
|
|
@@ -3592,6 +3623,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3592
3623
|
return;
|
|
3593
3624
|
}
|
|
3594
3625
|
case "message_stop": {
|
|
3626
|
+
isMessageOpen = false;
|
|
3627
|
+
activeMessageId = void 0;
|
|
3595
3628
|
controller.enqueue({
|
|
3596
3629
|
type: "finish",
|
|
3597
3630
|
finishReason,
|