@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/dist/index.mjs
CHANGED
|
@@ -11,10 +11,11 @@ import {
|
|
|
11
11
|
} from "@ai-sdk/provider-utils";
|
|
12
12
|
|
|
13
13
|
// src/version.ts
|
|
14
|
-
var VERSION = true ? "2.0.
|
|
14
|
+
var VERSION = true ? "2.0.94" : "0.0.0-test";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-messages-language-model.ts
|
|
17
17
|
import {
|
|
18
|
+
InvalidResponseDataError,
|
|
18
19
|
APICallError
|
|
19
20
|
} from "@ai-sdk/provider";
|
|
20
21
|
import {
|
|
@@ -1851,12 +1852,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1851
1852
|
case "tool-call": {
|
|
1852
1853
|
if (part.providerExecuted) {
|
|
1853
1854
|
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")) {
|
|
1855
|
+
const { type: type2, ...input } = part.input;
|
|
1854
1856
|
anthropicContent.push({
|
|
1855
1857
|
type: "server_tool_use",
|
|
1856
1858
|
id: part.toolCallId,
|
|
1857
|
-
name:
|
|
1859
|
+
name: type2,
|
|
1858
1860
|
// map back to subtool name
|
|
1859
|
-
input
|
|
1861
|
+
input,
|
|
1860
1862
|
cache_control: cacheControl
|
|
1861
1863
|
});
|
|
1862
1864
|
} else if (part.toolName === "code_execution" || // code execution 20250522
|
|
@@ -1928,7 +1930,15 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
1928
1930
|
type: "bash_code_execution_tool_result",
|
|
1929
1931
|
tool_use_id: part.toolCallId,
|
|
1930
1932
|
cache_control: cacheControl,
|
|
1931
|
-
|
|
1933
|
+
// Prompt caching requires stable key ordering:
|
|
1934
|
+
// https://platform.claude.com/docs/en/build-with-claude/prompt-caching#troubleshooting-common-issues
|
|
1935
|
+
content: codeExecutionOutput.type === "bash_code_execution_result" ? {
|
|
1936
|
+
type: codeExecutionOutput.type,
|
|
1937
|
+
stdout: codeExecutionOutput.stdout,
|
|
1938
|
+
stderr: codeExecutionOutput.stderr,
|
|
1939
|
+
return_code: codeExecutionOutput.return_code,
|
|
1940
|
+
content: codeExecutionOutput.content
|
|
1941
|
+
} : codeExecutionOutput
|
|
1932
1942
|
} : {
|
|
1933
1943
|
type: "text_editor_code_execution_tool_result",
|
|
1934
1944
|
tool_use_id: part.toolCallId,
|
|
@@ -3113,6 +3123,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3113
3123
|
let container = null;
|
|
3114
3124
|
let iterations = null;
|
|
3115
3125
|
let contextManagement = null;
|
|
3126
|
+
let isMessageOpen = false;
|
|
3127
|
+
let activeMessageId;
|
|
3128
|
+
let hasInvalidMessageSequence = false;
|
|
3116
3129
|
let blockType = void 0;
|
|
3117
3130
|
const generateId3 = this.generateId;
|
|
3118
3131
|
const transformedStream = response.pipeThrough(
|
|
@@ -3122,6 +3135,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3122
3135
|
},
|
|
3123
3136
|
transform(chunk, controller) {
|
|
3124
3137
|
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3138
|
+
if (hasInvalidMessageSequence) {
|
|
3139
|
+
return;
|
|
3140
|
+
}
|
|
3125
3141
|
if (options.includeRawChunks) {
|
|
3126
3142
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3127
3143
|
}
|
|
@@ -3525,6 +3541,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3525
3541
|
}
|
|
3526
3542
|
}
|
|
3527
3543
|
case "message_start": {
|
|
3544
|
+
if (isMessageOpen) {
|
|
3545
|
+
if (activeMessageId === value.message.id) {
|
|
3546
|
+
return;
|
|
3547
|
+
}
|
|
3548
|
+
hasInvalidMessageSequence = true;
|
|
3549
|
+
controller.enqueue({
|
|
3550
|
+
type: "error",
|
|
3551
|
+
error: new InvalidResponseDataError({
|
|
3552
|
+
data: value,
|
|
3553
|
+
message: `Received message_start for message ${JSON.stringify(value.message.id)} while message ${JSON.stringify(activeMessageId)} is still open.`
|
|
3554
|
+
})
|
|
3555
|
+
});
|
|
3556
|
+
return;
|
|
3557
|
+
}
|
|
3558
|
+
isMessageOpen = true;
|
|
3559
|
+
activeMessageId = value.message.id;
|
|
3528
3560
|
usage.inputTokens = value.message.usage.input_tokens;
|
|
3529
3561
|
usage.cachedInputTokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : void 0;
|
|
3530
3562
|
rawUsage = {
|
|
@@ -3617,6 +3649,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3617
3649
|
return;
|
|
3618
3650
|
}
|
|
3619
3651
|
case "message_stop": {
|
|
3652
|
+
isMessageOpen = false;
|
|
3653
|
+
activeMessageId = void 0;
|
|
3620
3654
|
controller.enqueue({
|
|
3621
3655
|
type: "finish",
|
|
3622
3656
|
finishReason,
|