@ai-sdk/anthropic 3.0.77 → 3.0.78

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 3.0.78
4
+
5
+ ### Patch Changes
6
+
7
+ - 6e28d25: fix(anthropic): propagate toModelOutput providerOption to anthropic tool results
8
+
3
9
  ## 3.0.77
4
10
 
5
11
  ### 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.77" : "0.0.0-test";
35
+ var VERSION = true ? "3.0.78" : "0.0.0-test";
36
36
 
37
37
  // src/anthropic-messages-language-model.ts
38
38
  var import_provider3 = require("@ai-sdk/provider");
@@ -2163,7 +2163,7 @@ async function convertToAnthropicMessagesPrompt({
2163
2163
  cacheControlValidator,
2164
2164
  toolNameMapping
2165
2165
  }) {
2166
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
2166
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
2167
2167
  const betas = /* @__PURE__ */ new Set();
2168
2168
  const blocks = groupIntoBlocks(prompt);
2169
2169
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -2315,15 +2315,21 @@ async function convertToAnthropicMessagesPrompt({
2315
2315
  if (part.type === "tool-approval-response") {
2316
2316
  continue;
2317
2317
  }
2318
+ const output = part.output;
2319
+ const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_d = output.value.find(
2320
+ (contentPart) => contentPart.providerOptions != null
2321
+ )) == null ? void 0 : _d.providerOptions : void 0;
2318
2322
  const isLastPart = i2 === content.length - 1;
2319
- const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
2323
+ const cacheControl = (_f = (_e = validator.getCacheControl(part.providerOptions, {
2320
2324
  type: "tool result part",
2321
2325
  canCache: true
2322
- })) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
2326
+ })) != null ? _e : validator.getCacheControl(outputProviderOptions, {
2327
+ type: "tool result output",
2328
+ canCache: true
2329
+ })) != null ? _f : isLastPart ? validator.getCacheControl(message.providerOptions, {
2323
2330
  type: "tool result message",
2324
2331
  canCache: true
2325
2332
  }) : void 0;
2326
- const output = part.output;
2327
2333
  let contentValue;
2328
2334
  switch (output.type) {
2329
2335
  case "content":
@@ -2410,7 +2416,7 @@ async function convertToAnthropicMessagesPrompt({
2410
2416
  contentValue = output.value;
2411
2417
  break;
2412
2418
  case "execution-denied":
2413
- contentValue = (_e = output.reason) != null ? _e : "Tool execution denied.";
2419
+ contentValue = (_g = output.reason) != null ? _g : "Tool execution denied.";
2414
2420
  break;
2415
2421
  case "json":
2416
2422
  case "error-json":
@@ -2447,16 +2453,16 @@ async function convertToAnthropicMessagesPrompt({
2447
2453
  for (let k = 0; k < content.length; k++) {
2448
2454
  const part = content[k];
2449
2455
  const isLastContentPart = k === content.length - 1;
2450
- const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
2456
+ const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
2451
2457
  type: "assistant message part",
2452
2458
  canCache: true
2453
- })) != null ? _f : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
2459
+ })) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
2454
2460
  type: "assistant message",
2455
2461
  canCache: true
2456
2462
  }) : void 0;
2457
2463
  switch (part.type) {
2458
2464
  case "text": {
2459
- const textMetadata = (_g = part.providerOptions) == null ? void 0 : _g.anthropic;
2465
+ const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
2460
2466
  if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
2461
2467
  anthropicContent.push({
2462
2468
  type: "compaction",
@@ -2529,10 +2535,10 @@ async function convertToAnthropicMessagesPrompt({
2529
2535
  const providerToolName = toolNameMapping.toProviderToolName(
2530
2536
  part.toolName
2531
2537
  );
2532
- const isMcpToolUse = ((_i = (_h = part.providerOptions) == null ? void 0 : _h.anthropic) == null ? void 0 : _i.type) === "mcp-tool-use";
2538
+ const isMcpToolUse = ((_k = (_j = part.providerOptions) == null ? void 0 : _j.anthropic) == null ? void 0 : _k.type) === "mcp-tool-use";
2533
2539
  if (isMcpToolUse) {
2534
2540
  mcpToolUseIds.add(part.toolCallId);
2535
- const serverName = (_k = (_j = part.providerOptions) == null ? void 0 : _j.anthropic) == null ? void 0 : _k.serverName;
2541
+ const serverName = (_m = (_l = part.providerOptions) == null ? void 0 : _l.anthropic) == null ? void 0 : _m.serverName;
2536
2542
  if (serverName == null || typeof serverName !== "string") {
2537
2543
  warnings.push({
2538
2544
  type: "other",
@@ -2608,7 +2614,7 @@ async function convertToAnthropicMessagesPrompt({
2608
2614
  }
2609
2615
  break;
2610
2616
  }
2611
- const callerOptions = (_l = part.providerOptions) == null ? void 0 : _l.anthropic;
2617
+ const callerOptions = (_n = part.providerOptions) == null ? void 0 : _n.anthropic;
2612
2618
  const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
2613
2619
  type: callerOptions.caller.type,
2614
2620
  tool_id: callerOptions.caller.toolId
@@ -2661,7 +2667,7 @@ async function convertToAnthropicMessagesPrompt({
2661
2667
  tool_use_id: part.toolCallId,
2662
2668
  content: {
2663
2669
  type: "code_execution_tool_result_error",
2664
- error_code: (_m = errorInfo.errorCode) != null ? _m : "unknown"
2670
+ error_code: (_o = errorInfo.errorCode) != null ? _o : "unknown"
2665
2671
  },
2666
2672
  cache_control: cacheControl
2667
2673
  });
@@ -2672,7 +2678,7 @@ async function convertToAnthropicMessagesPrompt({
2672
2678
  cache_control: cacheControl,
2673
2679
  content: {
2674
2680
  type: "bash_code_execution_tool_result_error",
2675
- error_code: (_n = errorInfo.errorCode) != null ? _n : "unknown"
2681
+ error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
2676
2682
  }
2677
2683
  });
2678
2684
  }
@@ -2705,7 +2711,7 @@ async function convertToAnthropicMessagesPrompt({
2705
2711
  stdout: codeExecutionOutput.stdout,
2706
2712
  stderr: codeExecutionOutput.stderr,
2707
2713
  return_code: codeExecutionOutput.return_code,
2708
- content: (_o = codeExecutionOutput.content) != null ? _o : []
2714
+ content: (_q = codeExecutionOutput.content) != null ? _q : []
2709
2715
  },
2710
2716
  cache_control: cacheControl
2711
2717
  });
@@ -2723,7 +2729,7 @@ async function convertToAnthropicMessagesPrompt({
2723
2729
  encrypted_stdout: codeExecutionOutput.encrypted_stdout,
2724
2730
  stderr: codeExecutionOutput.stderr,
2725
2731
  return_code: codeExecutionOutput.return_code,
2726
- content: (_p = codeExecutionOutput.content) != null ? _p : []
2732
+ content: (_r = codeExecutionOutput.content) != null ? _r : []
2727
2733
  },
2728
2734
  cache_control: cacheControl
2729
2735
  });
@@ -2742,7 +2748,7 @@ async function convertToAnthropicMessagesPrompt({
2742
2748
  stdout: codeExecutionOutput.stdout,
2743
2749
  stderr: codeExecutionOutput.stderr,
2744
2750
  return_code: codeExecutionOutput.return_code,
2745
- content: (_q = codeExecutionOutput.content) != null ? _q : []
2751
+ content: (_s = codeExecutionOutput.content) != null ? _s : []
2746
2752
  },
2747
2753
  cache_control: cacheControl
2748
2754
  });
@@ -2775,7 +2781,7 @@ async function convertToAnthropicMessagesPrompt({
2775
2781
  errorValue = output.value;
2776
2782
  }
2777
2783
  } catch (e) {
2778
- const extractedErrorCode = (_r = output.value) == null ? void 0 : _r.errorCode;
2784
+ const extractedErrorCode = (_t = output.value) == null ? void 0 : _t.errorCode;
2779
2785
  errorValue = {
2780
2786
  errorCode: typeof extractedErrorCode === "string" ? extractedErrorCode : "unavailable"
2781
2787
  };
@@ -2785,7 +2791,7 @@ async function convertToAnthropicMessagesPrompt({
2785
2791
  tool_use_id: part.toolCallId,
2786
2792
  content: {
2787
2793
  type: "web_fetch_tool_result_error",
2788
- error_code: (_s = errorValue.errorCode) != null ? _s : "unavailable"
2794
+ error_code: (_u = errorValue.errorCode) != null ? _u : "unavailable"
2789
2795
  },
2790
2796
  cache_control: cacheControl
2791
2797
  });