@ai-sdk/anthropic 3.0.79 → 3.0.81

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.
@@ -2243,19 +2243,20 @@ async function convertToAnthropicMessagesPrompt({
2243
2243
  const type = block.type;
2244
2244
  switch (type) {
2245
2245
  case "system": {
2246
- if (system != null) {
2247
- throw new UnsupportedFunctionalityError2({
2248
- functionality: "Multiple system messages that are separated by user/assistant messages"
2249
- });
2250
- }
2251
- system = block.messages.map(({ content, providerOptions }) => ({
2246
+ const content = block.messages.map(({ content: content2, providerOptions }) => ({
2252
2247
  type: "text",
2253
- text: content,
2248
+ text: content2,
2254
2249
  cache_control: validator.getCacheControl(providerOptions, {
2255
2250
  type: "system message",
2256
2251
  canCache: true
2257
2252
  })
2258
2253
  }));
2254
+ if (system == null) {
2255
+ system = content;
2256
+ } else {
2257
+ messages.push({ role: "system", content });
2258
+ betas.add("mid-conversation-system-2026-04-07");
2259
+ }
2259
2260
  break;
2260
2261
  }
2261
2262
  case "user": {
@@ -3889,12 +3890,18 @@ var AnthropicMessagesLanguageModel = class {
3889
3890
  }
3890
3891
  case "server_tool_use": {
3891
3892
  if (part.name === "text_editor_code_execution" || part.name === "bash_code_execution") {
3893
+ const providerToolName = "code_execution";
3892
3894
  content.push({
3893
3895
  type: "tool-call",
3894
3896
  toolCallId: part.id,
3895
3897
  toolName: toolNameMapping.toCustomToolName("code_execution"),
3896
3898
  input: JSON.stringify({ type: part.name, ...part.input }),
3897
- providerExecuted: true
3899
+ providerExecuted: true,
3900
+ // Specific 'web_fetch' or 'web_search' tools may need code execution, which the Anthropic API
3901
+ // implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
3902
+ // tool was not explicitly provided. We therefore bypass the general validation by marking the
3903
+ // tool as dynamic.
3904
+ ...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {}
3898
3905
  });
3899
3906
  } else if (part.name === "web_search" || part.name === "code_execution" || part.name === "web_fetch") {
3900
3907
  const inputToSerialize = part.name === "code_execution" && part.input != null && typeof part.input === "object" && "code" in part.input && !("type" in part.input) ? { type: "programmatic-tool-call", ...part.input } : part.input;
@@ -3904,8 +3911,10 @@ var AnthropicMessagesLanguageModel = class {
3904
3911
  toolName: toolNameMapping.toCustomToolName(part.name),
3905
3912
  input: JSON.stringify(inputToSerialize),
3906
3913
  providerExecuted: true,
3907
- // We want this 'code_execution' tool call to be allowed even if the tool is not explicitly provided.
3908
- // Since the validation generally bypasses dynamic tools, we mark this specific tool as dynamic.
3914
+ // Specific 'web_fetch' or 'web_search' tools may need code execution, which the Anthropic API
3915
+ // implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
3916
+ // tool was not explicitly provided. We therefore bypass the general validation by marking the
3917
+ // tool as dynamic.
3909
3918
  ...markCodeExecutionDynamic && part.name === "code_execution" ? { dynamic: true } : {}
3910
3919
  });
3911
3920
  } else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
@@ -4425,15 +4434,23 @@ var AnthropicMessagesLanguageModel = class {
4425
4434
  toolName: customToolName,
4426
4435
  input: finalInput,
4427
4436
  providerExecuted: true,
4437
+ // Specific 'web_fetch' or 'web_search' tools may need code execution, which the Anthropic API
4438
+ // implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
4439
+ // tool was not explicitly provided. We therefore bypass the general validation by marking the
4440
+ // tool as dynamic.
4428
4441
  ...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {},
4429
4442
  firstDelta: true,
4430
- providerToolName: part.name
4443
+ providerToolName
4431
4444
  };
4432
4445
  controller.enqueue({
4433
4446
  type: "tool-input-start",
4434
4447
  id: part.id,
4435
4448
  toolName: customToolName,
4436
4449
  providerExecuted: true,
4450
+ // Specific 'web_fetch' or 'web_search' tools may need code execution, which the Anthropic API
4451
+ // implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
4452
+ // tool was not explicitly provided. We therefore bypass the general validation by marking the
4453
+ // tool as dynamic.
4437
4454
  ...markCodeExecutionDynamic && providerToolName === "code_execution" ? { dynamic: true } : {}
4438
4455
  });
4439
4456
  } else if (part.name === "tool_search_tool_regex" || part.name === "tool_search_tool_bm25") {
@@ -4776,6 +4793,10 @@ var AnthropicMessagesLanguageModel = class {
4776
4793
  toolName: contentBlock.toolName,
4777
4794
  input: finalInput,
4778
4795
  providerExecuted: contentBlock.providerExecuted,
4796
+ // Specific 'web_fetch' or 'web_search' tools may need code execution, which the Anthropic API
4797
+ // implicitly allows. In this scenario, we need to allow 'code_execution' tool calls even if the
4798
+ // tool was not explicitly provided. We therefore bypass the general validation by marking the
4799
+ // tool as dynamic.
4779
4800
  ...markCodeExecutionDynamic && contentBlock.providerToolName === "code_execution" ? { dynamic: true } : {},
4780
4801
  ...contentBlock.caller && {
4781
4802
  providerMetadata: {
@@ -4859,8 +4880,8 @@ var AnthropicMessagesLanguageModel = class {
4859
4880
  if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
4860
4881
  return;
4861
4882
  }
4862
- if (contentBlock.firstDelta && (contentBlock.providerToolName === "bash_code_execution" || contentBlock.providerToolName === "text_editor_code_execution")) {
4863
- delta = `{"type": "${contentBlock.providerToolName}",${delta.substring(1)}`;
4883
+ if (contentBlock.firstDelta && contentBlock.providerToolName === "code_execution") {
4884
+ delta = `{"type": "programmatic-tool-call",${delta.substring(1)}`;
4864
4885
  }
4865
4886
  controller.enqueue({
4866
4887
  type: "tool-input-delta",
@@ -5097,7 +5118,7 @@ var AnthropicMessagesLanguageModel = class {
5097
5118
  }
5098
5119
  };
5099
5120
  function getModelCapabilities(modelId) {
5100
- if (modelId.includes("claude-opus-4-7")) {
5121
+ if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7")) {
5101
5122
  return {
5102
5123
  maxOutputTokens: 128e3,
5103
5124
  supportsStructuredOutput: true,
@@ -5555,7 +5576,7 @@ var anthropicTools = {
5555
5576
  * Supported executor models: Claude Haiku 4.5, Sonnet 4.6, Opus 4.6,
5556
5577
  * Opus 4.7. The advisor must be at least as capable as the executor.
5557
5578
  *
5558
- * @param model - The advisor model ID (required), e.g. `"claude-opus-4-7"`.
5579
+ * @param model - The advisor model ID (required), e.g. `"claude-opus-4-8"`.
5559
5580
  * @param maxUses - Maximum advisor calls per request (per-request cap).
5560
5581
  * @param caching - Enables prompt caching for the advisor's transcript
5561
5582
  * across calls within a conversation. Worthwhile from ~3 advisor calls