@ai-sdk/anthropic 4.0.27 → 4.0.28

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.
@@ -2924,15 +2924,16 @@ async function convertToAnthropicPrompt({
2924
2924
  cache_control: cacheControl
2925
2925
  });
2926
2926
  } else if (
2927
- // code execution 20250825:
2927
+ // code execution subtools:
2928
2928
  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")
2929
2929
  ) {
2930
+ const { type: codeExecutionType, ...inputWithoutType } = part.input;
2930
2931
  anthropicContent.push({
2931
2932
  type: "server_tool_use",
2932
2933
  id: part.toolCallId,
2933
- name: part.input.type,
2934
+ name: codeExecutionType,
2934
2935
  // map back to subtool name
2935
- input: part.input,
2936
+ input: inputWithoutType,
2936
2937
  cache_control: cacheControl
2937
2938
  });
2938
2939
  } else if (
@@ -3126,7 +3127,15 @@ async function convertToAnthropicPrompt({
3126
3127
  type: "bash_code_execution_tool_result",
3127
3128
  tool_use_id: part.toolCallId,
3128
3129
  cache_control: cacheControl,
3129
- content: codeExecutionOutput
3130
+ // Prompt caching requires stable key ordering:
3131
+ // https://platform.claude.com/docs/en/build-with-claude/prompt-caching#troubleshooting-common-issues
3132
+ content: codeExecutionOutput.type === "bash_code_execution_result" ? {
3133
+ type: codeExecutionOutput.type,
3134
+ stdout: codeExecutionOutput.stdout,
3135
+ stderr: codeExecutionOutput.stderr,
3136
+ return_code: codeExecutionOutput.return_code,
3137
+ content: codeExecutionOutput.content
3138
+ } : codeExecutionOutput
3130
3139
  });
3131
3140
  } else {
3132
3141
  anthropicContent.push({