@ai-sdk/anthropic 3.0.104 → 3.0.107
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 +19 -0
- package/dist/index.js +37 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -5
- 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 +38 -4
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +5 -0
- package/package.json +2 -2
- package/src/anthropic-messages-language-model.ts +32 -0
- package/src/convert-to-anthropic-messages-prompt.ts +16 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 3.0.107
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [ee2bf30]
|
|
8
|
+
- @ai-sdk/provider-utils@4.0.42
|
|
9
|
+
|
|
10
|
+
## 3.0.106
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- b74e654: Reject spliced Anthropic generations while allowing duplicate message start events for the active message.
|
|
15
|
+
|
|
16
|
+
## 3.0.105
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 0a295e3: Preserve Anthropic prompt-cache matches by replaying complete code-execution transcripts in their original wire shape.
|
|
21
|
+
|
|
3
22
|
## 3.0.104
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
32
32
|
var import_provider_utils26 = require("@ai-sdk/provider-utils");
|
|
33
33
|
|
|
34
34
|
// src/version.ts
|
|
35
|
-
var VERSION = true ? "3.0.
|
|
35
|
+
var VERSION = true ? "3.0.107" : "0.0.0-test";
|
|
36
36
|
|
|
37
37
|
// src/anthropic-messages-language-model.ts
|
|
38
38
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -2686,12 +2686,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2686
2686
|
// code execution 20250825:
|
|
2687
2687
|
providerToolName === "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")
|
|
2688
2688
|
) {
|
|
2689
|
+
const { type: subtoolName, ...input } = part.input;
|
|
2689
2690
|
anthropicContent.push({
|
|
2690
2691
|
type: "server_tool_use",
|
|
2691
2692
|
id: part.toolCallId,
|
|
2692
|
-
name:
|
|
2693
|
+
name: subtoolName,
|
|
2693
2694
|
// map back to subtool name
|
|
2694
|
-
input
|
|
2695
|
+
input,
|
|
2695
2696
|
cache_control: cacheControl
|
|
2696
2697
|
});
|
|
2697
2698
|
} else if (
|
|
@@ -2885,7 +2886,15 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2885
2886
|
type: "bash_code_execution_tool_result",
|
|
2886
2887
|
tool_use_id: part.toolCallId,
|
|
2887
2888
|
cache_control: cacheControl,
|
|
2888
|
-
|
|
2889
|
+
// Prompt caching requires stable key ordering:
|
|
2890
|
+
// https://platform.claude.com/docs/en/build-with-claude/prompt-caching#troubleshooting-common-issues
|
|
2891
|
+
content: codeExecutionOutput.type === "bash_code_execution_result" ? {
|
|
2892
|
+
type: codeExecutionOutput.type,
|
|
2893
|
+
stdout: codeExecutionOutput.stdout,
|
|
2894
|
+
stderr: codeExecutionOutput.stderr,
|
|
2895
|
+
return_code: codeExecutionOutput.return_code,
|
|
2896
|
+
content: codeExecutionOutput.content
|
|
2897
|
+
} : codeExecutionOutput
|
|
2889
2898
|
});
|
|
2890
2899
|
} else {
|
|
2891
2900
|
anthropicContent.push({
|
|
@@ -4457,6 +4466,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4457
4466
|
let stopDetails = void 0;
|
|
4458
4467
|
let container = null;
|
|
4459
4468
|
let isJsonResponseFromTool = false;
|
|
4469
|
+
let isMessageOpen = false;
|
|
4470
|
+
let activeMessageId;
|
|
4471
|
+
let hasInvalidMessageSequence = false;
|
|
4460
4472
|
let blockType = void 0;
|
|
4461
4473
|
const generateId3 = this.generateId;
|
|
4462
4474
|
const transformedStream = response.pipeThrough(
|
|
@@ -4466,6 +4478,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4466
4478
|
},
|
|
4467
4479
|
transform(chunk, controller) {
|
|
4468
4480
|
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
4481
|
+
if (hasInvalidMessageSequence) {
|
|
4482
|
+
return;
|
|
4483
|
+
}
|
|
4469
4484
|
if (options.includeRawChunks) {
|
|
4470
4485
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
4471
4486
|
}
|
|
@@ -5086,6 +5101,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5086
5101
|
}
|
|
5087
5102
|
}
|
|
5088
5103
|
case "message_start": {
|
|
5104
|
+
if (isMessageOpen) {
|
|
5105
|
+
if (activeMessageId === value.message.id) {
|
|
5106
|
+
return;
|
|
5107
|
+
}
|
|
5108
|
+
hasInvalidMessageSequence = true;
|
|
5109
|
+
controller.enqueue({
|
|
5110
|
+
type: "error",
|
|
5111
|
+
error: new import_provider3.InvalidResponseDataError({
|
|
5112
|
+
data: value,
|
|
5113
|
+
message: `Received message_start for message ${JSON.stringify(value.message.id)} while message ${JSON.stringify(activeMessageId)} is still open.`
|
|
5114
|
+
})
|
|
5115
|
+
});
|
|
5116
|
+
return;
|
|
5117
|
+
}
|
|
5118
|
+
isMessageOpen = true;
|
|
5119
|
+
activeMessageId = value.message.id;
|
|
5089
5120
|
usage.input_tokens = value.message.usage.input_tokens;
|
|
5090
5121
|
usage.cache_read_input_tokens = (_e = value.message.usage.cache_read_input_tokens) != null ? _e : 0;
|
|
5091
5122
|
usage.cache_creation_input_tokens = (_f = value.message.usage.cache_creation_input_tokens) != null ? _f : 0;
|
|
@@ -5204,6 +5235,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5204
5235
|
return;
|
|
5205
5236
|
}
|
|
5206
5237
|
case "message_stop": {
|
|
5238
|
+
isMessageOpen = false;
|
|
5239
|
+
activeMessageId = void 0;
|
|
5207
5240
|
const anthropicMetadata = {
|
|
5208
5241
|
usage: rawUsage != null ? rawUsage : null,
|
|
5209
5242
|
cacheCreationInputTokens,
|