@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/dist/internal/index.js
CHANGED
|
@@ -2680,12 +2680,13 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2680
2680
|
// code execution 20250825:
|
|
2681
2681
|
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")
|
|
2682
2682
|
) {
|
|
2683
|
+
const { type: subtoolName, ...input } = part.input;
|
|
2683
2684
|
anthropicContent.push({
|
|
2684
2685
|
type: "server_tool_use",
|
|
2685
2686
|
id: part.toolCallId,
|
|
2686
|
-
name:
|
|
2687
|
+
name: subtoolName,
|
|
2687
2688
|
// map back to subtool name
|
|
2688
|
-
input
|
|
2689
|
+
input,
|
|
2689
2690
|
cache_control: cacheControl
|
|
2690
2691
|
});
|
|
2691
2692
|
} else if (
|
|
@@ -2879,7 +2880,15 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2879
2880
|
type: "bash_code_execution_tool_result",
|
|
2880
2881
|
tool_use_id: part.toolCallId,
|
|
2881
2882
|
cache_control: cacheControl,
|
|
2882
|
-
|
|
2883
|
+
// Prompt caching requires stable key ordering:
|
|
2884
|
+
// https://platform.claude.com/docs/en/build-with-claude/prompt-caching#troubleshooting-common-issues
|
|
2885
|
+
content: codeExecutionOutput.type === "bash_code_execution_result" ? {
|
|
2886
|
+
type: codeExecutionOutput.type,
|
|
2887
|
+
stdout: codeExecutionOutput.stdout,
|
|
2888
|
+
stderr: codeExecutionOutput.stderr,
|
|
2889
|
+
return_code: codeExecutionOutput.return_code,
|
|
2890
|
+
content: codeExecutionOutput.content
|
|
2891
|
+
} : codeExecutionOutput
|
|
2883
2892
|
});
|
|
2884
2893
|
} else {
|
|
2885
2894
|
anthropicContent.push({
|
|
@@ -4451,6 +4460,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4451
4460
|
let stopDetails = void 0;
|
|
4452
4461
|
let container = null;
|
|
4453
4462
|
let isJsonResponseFromTool = false;
|
|
4463
|
+
let isMessageOpen = false;
|
|
4464
|
+
let activeMessageId;
|
|
4465
|
+
let hasInvalidMessageSequence = false;
|
|
4454
4466
|
let blockType = void 0;
|
|
4455
4467
|
const generateId2 = this.generateId;
|
|
4456
4468
|
const transformedStream = response.pipeThrough(
|
|
@@ -4460,6 +4472,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4460
4472
|
},
|
|
4461
4473
|
transform(chunk, controller) {
|
|
4462
4474
|
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
4475
|
+
if (hasInvalidMessageSequence) {
|
|
4476
|
+
return;
|
|
4477
|
+
}
|
|
4463
4478
|
if (options.includeRawChunks) {
|
|
4464
4479
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
4465
4480
|
}
|
|
@@ -5080,6 +5095,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5080
5095
|
}
|
|
5081
5096
|
}
|
|
5082
5097
|
case "message_start": {
|
|
5098
|
+
if (isMessageOpen) {
|
|
5099
|
+
if (activeMessageId === value.message.id) {
|
|
5100
|
+
return;
|
|
5101
|
+
}
|
|
5102
|
+
hasInvalidMessageSequence = true;
|
|
5103
|
+
controller.enqueue({
|
|
5104
|
+
type: "error",
|
|
5105
|
+
error: new import_provider3.InvalidResponseDataError({
|
|
5106
|
+
data: value,
|
|
5107
|
+
message: `Received message_start for message ${JSON.stringify(value.message.id)} while message ${JSON.stringify(activeMessageId)} is still open.`
|
|
5108
|
+
})
|
|
5109
|
+
});
|
|
5110
|
+
return;
|
|
5111
|
+
}
|
|
5112
|
+
isMessageOpen = true;
|
|
5113
|
+
activeMessageId = value.message.id;
|
|
5083
5114
|
usage.input_tokens = value.message.usage.input_tokens;
|
|
5084
5115
|
usage.cache_read_input_tokens = (_e = value.message.usage.cache_read_input_tokens) != null ? _e : 0;
|
|
5085
5116
|
usage.cache_creation_input_tokens = (_f = value.message.usage.cache_creation_input_tokens) != null ? _f : 0;
|
|
@@ -5198,6 +5229,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5198
5229
|
return;
|
|
5199
5230
|
}
|
|
5200
5231
|
case "message_stop": {
|
|
5232
|
+
isMessageOpen = false;
|
|
5233
|
+
activeMessageId = void 0;
|
|
5201
5234
|
const anthropicMetadata = {
|
|
5202
5235
|
usage: rawUsage != null ? rawUsage : null,
|
|
5203
5236
|
cacheCreationInputTokens,
|