@ai-sdk/anthropic 4.0.63 → 4.0.65

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/dist/index.js CHANGED
@@ -76,7 +76,6 @@ var AnthropicFiles = class {
76
76
  abortSignal,
77
77
  headers
78
78
  }) {
79
- var _a, _b;
80
79
  const fileBytes = convertInlineFileDataToUint8Array(data);
81
80
  const blob = new Blob([fileBytes], { type: mediaType });
82
81
  const formData = new FormData();
@@ -103,8 +102,8 @@ var AnthropicFiles = class {
103
102
  return {
104
103
  warnings: [],
105
104
  providerReference: { anthropic: response.id },
106
- mediaType: (_a = response.mime_type) != null ? _a : mediaType,
107
- filename: (_b = response.filename) != null ? _b : filename,
105
+ mediaType: response.mime_type ?? mediaType,
106
+ filename: response.filename ?? filename,
108
107
  providerMetadata: {
109
108
  anthropic: {
110
109
  filename: response.filename,
@@ -1014,9 +1013,10 @@ var anthropicSystemMessageProviderOptions = z4.object({
1014
1013
  */
1015
1014
  clearAt: z4.literal("next_user_message").optional(),
1016
1015
  /**
1017
- * Sets the model effort for the turn that follows this mid-conversation
1018
- * system message. The required `mid-conversation-output-config-2026-07-01`
1019
- * beta is added automatically.
1016
+ * Sets the model effort from the next user turn until a later message
1017
+ * changes it. An effort-only system message with empty content can appear
1018
+ * first. The required `mid-conversation-output-config-2026-07-01` beta is
1019
+ * added automatically.
1020
1020
  */
1021
1021
  effort: z4.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
1022
1022
  /**
@@ -1337,9 +1337,8 @@ import {
1337
1337
  // src/get-cache-control.ts
1338
1338
  var MAX_CACHE_BREAKPOINTS = 4;
1339
1339
  function getCacheControl(providerMetadata) {
1340
- var _a;
1341
- const anthropic2 = providerMetadata == null ? void 0 : providerMetadata.anthropic;
1342
- const cacheControlValue = (_a = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a : anthropic2 == null ? void 0 : anthropic2.cache_control;
1340
+ const anthropic2 = providerMetadata?.anthropic;
1341
+ const cacheControlValue = anthropic2?.cacheControl ?? anthropic2?.cache_control;
1343
1342
  return cacheControlValue;
1344
1343
  }
1345
1344
  var CacheControlValidator = class {
@@ -1886,8 +1885,7 @@ async function prepareTools({
1886
1885
  defaultEagerInputStreaming = false,
1887
1886
  rejectsForcedToolUse = false
1888
1887
  }) {
1889
- var _a, _b;
1890
- tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
1888
+ tools = tools?.length ? tools : void 0;
1891
1889
  const toolWarnings = [];
1892
1890
  const betas = /* @__PURE__ */ new Set();
1893
1891
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1902,10 +1900,10 @@ async function prepareTools({
1902
1900
  type: "tool definition",
1903
1901
  canCache: true
1904
1902
  });
1905
- const anthropicOptions = (_a = tool.providerOptions) == null ? void 0 : _a.anthropic;
1906
- const eagerInputStreaming = (_b = anthropicOptions == null ? void 0 : anthropicOptions.eagerInputStreaming) != null ? _b : defaultEagerInputStreaming;
1907
- const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
1908
- const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
1903
+ const anthropicOptions = tool.providerOptions?.anthropic;
1904
+ const eagerInputStreaming = anthropicOptions?.eagerInputStreaming ?? defaultEagerInputStreaming;
1905
+ const deferLoading = anthropicOptions?.deferLoading;
1906
+ const allowedCallers = anthropicOptions?.allowedCallers;
1909
1907
  if (!supportsStrictTools && tool.strict != null) {
1910
1908
  toolWarnings.push({
1911
1909
  type: "unsupported",
@@ -1996,10 +1994,10 @@ async function prepareTools({
1996
1994
  Object.entries(args.configs).map(([member, config]) => [
1997
1995
  member,
1998
1996
  {
1999
- ...(config == null ? void 0 : config.enabled) != null && {
1997
+ ...config?.enabled != null && {
2000
1998
  enabled: config.enabled
2001
1999
  },
2002
- ...(config == null ? void 0 : config.deferLoading) != null && {
2000
+ ...config?.deferLoading != null && {
2003
2001
  defer_loading: config.deferLoading
2004
2002
  }
2005
2003
  }
@@ -2337,13 +2335,12 @@ function convertAnthropicUsage({
2337
2335
  usage,
2338
2336
  rawUsage
2339
2337
  }) {
2340
- var _a, _b, _c, _d, _e;
2341
- const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
2342
- const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
2343
- const reasoningTokens = (_d = (_c = usage.output_tokens_details) == null ? void 0 : _c.thinking_tokens) != null ? _d : void 0;
2338
+ const cacheCreationTokens = usage.cache_creation_input_tokens ?? 0;
2339
+ const cacheReadTokens = usage.cache_read_input_tokens ?? 0;
2340
+ const reasoningTokens = usage.output_tokens_details?.thinking_tokens ?? void 0;
2344
2341
  let inputTokens;
2345
2342
  let outputTokens;
2346
- const servedByFallback = (_e = usage.iterations) == null ? void 0 : _e.some(
2343
+ const servedByFallback = usage.iterations?.some(
2347
2344
  (iter) => iter.type === "fallback_message"
2348
2345
  );
2349
2346
  if (usage.iterations && usage.iterations.length > 0 && !servedByFallback) {
@@ -2380,7 +2377,7 @@ function convertAnthropicUsage({
2380
2377
  text: reasoningTokens == null ? void 0 : outputTokens - reasoningTokens,
2381
2378
  reasoning: reasoningTokens
2382
2379
  },
2383
- raw: rawUsage != null ? rawUsage : usage
2380
+ raw: rawUsage ?? usage
2384
2381
  };
2385
2382
  }
2386
2383
 
@@ -2553,15 +2550,14 @@ var codeExecution_20250825 = (args = {}) => {
2553
2550
  return experimental_toolCaller(factory10(args), {
2554
2551
  type: "provider",
2555
2552
  prepareProviderOptions: (providerOptions) => {
2556
- var _a;
2557
- const anthropicOptions = providerOptions == null ? void 0 : providerOptions.anthropic;
2553
+ const anthropicOptions = providerOptions?.anthropic;
2558
2554
  return {
2559
2555
  ...providerOptions,
2560
2556
  anthropic: {
2561
2557
  ...anthropicOptions,
2562
2558
  allowedCallers: [
2563
2559
  .../* @__PURE__ */ new Set([
2564
- ...(_a = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers) != null ? _a : [],
2560
+ ...anthropicOptions?.allowedCallers ?? [],
2565
2561
  "code_execution_20250825"
2566
2562
  ])
2567
2563
  ]
@@ -2693,15 +2689,14 @@ var codeExecution_20260120 = (args = {}) => {
2693
2689
  return experimental_toolCaller2(factory11(args), {
2694
2690
  type: "provider",
2695
2691
  prepareProviderOptions: (providerOptions) => {
2696
- var _a;
2697
- const anthropicOptions = providerOptions == null ? void 0 : providerOptions.anthropic;
2692
+ const anthropicOptions = providerOptions?.anthropic;
2698
2693
  return {
2699
2694
  ...providerOptions,
2700
2695
  anthropic: {
2701
2696
  ...anthropicOptions,
2702
2697
  allowedCallers: [
2703
2698
  .../* @__PURE__ */ new Set([
2704
- ...(_a = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers) != null ? _a : [],
2699
+ ...anthropicOptions?.allowedCallers ?? [],
2705
2700
  "code_execution_20260120"
2706
2701
  ])
2707
2702
  ]
@@ -2773,8 +2768,8 @@ function extractErrorValue(value) {
2773
2768
  } else if (typeof value === "object" && value !== null) {
2774
2769
  return value;
2775
2770
  }
2776
- } catch (e) {
2777
- const extractedErrorCode = value == null ? void 0 : value.errorCode;
2771
+ } catch {
2772
+ const extractedErrorCode = value?.errorCode;
2778
2773
  return {
2779
2774
  errorCode: typeof extractedErrorCode === "string" ? extractedErrorCode : "unavailable"
2780
2775
  };
@@ -2789,29 +2784,26 @@ async function convertToAnthropicPrompt({
2789
2784
  toolNameMapping,
2790
2785
  toolsetNames = {}
2791
2786
  }) {
2792
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
2793
2787
  const betas = /* @__PURE__ */ new Set();
2794
2788
  const blocks = groupIntoBlocks(prompt);
2795
2789
  const validator = cacheControlValidator || new CacheControlValidator();
2796
2790
  let system = void 0;
2797
2791
  const messages = [];
2798
2792
  async function shouldEnableCitations(providerMetadata) {
2799
- var _a2, _b2;
2800
2793
  const anthropicOptions = await parseProviderOptions({
2801
2794
  provider: "anthropic",
2802
2795
  providerOptions: providerMetadata,
2803
2796
  schema: anthropicFilePartProviderOptions
2804
2797
  });
2805
- return (_b2 = (_a2 = anthropicOptions == null ? void 0 : anthropicOptions.citations) == null ? void 0 : _a2.enabled) != null ? _b2 : false;
2798
+ return anthropicOptions?.citations?.enabled ?? false;
2806
2799
  }
2807
2800
  async function shouldUseContainerUpload(providerMetadata) {
2808
- var _a2;
2809
2801
  const anthropicOptions = await parseProviderOptions({
2810
2802
  provider: "anthropic",
2811
2803
  providerOptions: providerMetadata,
2812
2804
  schema: anthropicFilePartProviderOptions
2813
2805
  });
2814
- return (_a2 = anthropicOptions == null ? void 0 : anthropicOptions.containerUpload) != null ? _a2 : false;
2806
+ return anthropicOptions?.containerUpload ?? false;
2815
2807
  }
2816
2808
  async function getDocumentMetadata(providerMetadata) {
2817
2809
  const anthropicOptions = await parseProviderOptions({
@@ -2820,8 +2812,8 @@ async function convertToAnthropicPrompt({
2820
2812
  schema: anthropicFilePartProviderOptions
2821
2813
  });
2822
2814
  return {
2823
- title: anthropicOptions == null ? void 0 : anthropicOptions.title,
2824
- context: anthropicOptions == null ? void 0 : anthropicOptions.context
2815
+ title: anthropicOptions?.title,
2816
+ context: anthropicOptions?.context
2825
2817
  };
2826
2818
  }
2827
2819
  for (let i = 0; i < blocks.length; i++) {
@@ -2837,9 +2829,9 @@ async function convertToAnthropicPrompt({
2837
2829
  providerOptions,
2838
2830
  schema: anthropicSystemMessageProviderOptions
2839
2831
  });
2840
- const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
2832
+ const toolChanges = systemMessageOptions?.toolChanges ?? [];
2841
2833
  const content = [];
2842
- if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
2834
+ if (text !== "" || toolChanges.length === 0 && systemMessageOptions?.clearAt == null && systemMessageOptions?.effort == null) {
2843
2835
  content.push({
2844
2836
  type: "text",
2845
2837
  text,
@@ -2860,8 +2852,8 @@ async function convertToAnthropicPrompt({
2860
2852
  }
2861
2853
  convertedMessages.push({
2862
2854
  content,
2863
- clearAt: systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt,
2864
- effort: systemMessageOptions == null ? void 0 : systemMessageOptions.effort,
2855
+ clearAt: systemMessageOptions?.clearAt,
2856
+ effort: systemMessageOptions?.effort,
2865
2857
  toolChangeCount: toolChanges.length
2866
2858
  });
2867
2859
  }
@@ -2880,10 +2872,17 @@ async function convertToAnthropicPrompt({
2880
2872
  });
2881
2873
  }
2882
2874
  for (const message of convertedMessages) {
2883
- if (message.clearAt != null || message.effort != null) {
2875
+ if (message.content.length === 0 && message.clearAt == null && message.effort != null) {
2876
+ messages.push({
2877
+ role: "system",
2878
+ content: [],
2879
+ output_config: { effort: message.effort }
2880
+ });
2881
+ betas.add("mid-conversation-output-config-2026-07-01");
2882
+ } else if (message.clearAt != null || message.effort != null) {
2884
2883
  warnings.push({
2885
2884
  type: "other",
2886
- message: "clearAt and effort on the initial system message are not supported by Anthropic. These options have been ignored."
2885
+ message: "clearAt and effort on this initial system message are not supported by Anthropic. Use a separate effort-only system message with empty content to set effort. These options have been ignored."
2887
2886
  });
2888
2887
  }
2889
2888
  }
@@ -2925,13 +2924,13 @@ async function convertToAnthropicPrompt({
2925
2924
  for (let j = 0; j < content.length; j++) {
2926
2925
  const part = content[j];
2927
2926
  const isLastPart = j === content.length - 1;
2928
- const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
2927
+ const cacheControl = validator.getCacheControl(part.providerOptions, {
2929
2928
  type: "user message part",
2930
2929
  canCache: true
2931
- })) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
2930
+ }) ?? (isLastPart ? validator.getCacheControl(message.providerOptions, {
2932
2931
  type: "user message",
2933
2932
  canCache: true
2934
- }) : void 0;
2933
+ }) : void 0);
2935
2934
  switch (part.type) {
2936
2935
  case "text": {
2937
2936
  anthropicContent.push({
@@ -2983,7 +2982,7 @@ async function convertToAnthropicPrompt({
2983
2982
  media_type: "text/plain",
2984
2983
  data: part.data.text
2985
2984
  },
2986
- title: (_c = metadata.title) != null ? _c : part.filename,
2985
+ title: metadata.title ?? part.filename,
2987
2986
  ...metadata.context && {
2988
2987
  context: metadata.context
2989
2988
  },
@@ -3028,7 +3027,7 @@ async function convertToAnthropicPrompt({
3028
3027
  media_type: "application/pdf",
3029
3028
  data: convertToBase64(part.data.data)
3030
3029
  },
3031
- title: (_d = metadata.title) != null ? _d : part.filename,
3030
+ title: metadata.title ?? part.filename,
3032
3031
  ...metadata.context && {
3033
3032
  context: metadata.context
3034
3033
  },
@@ -3056,7 +3055,7 @@ async function convertToAnthropicPrompt({
3056
3055
  part.data.data
3057
3056
  )
3058
3057
  },
3059
- title: (_e = metadata.title) != null ? _e : part.filename,
3058
+ title: metadata.title ?? part.filename,
3060
3059
  ...metadata.context && {
3061
3060
  context: metadata.context
3062
3061
  },
@@ -3086,25 +3085,24 @@ async function convertToAnthropicPrompt({
3086
3085
  continue;
3087
3086
  }
3088
3087
  const output = part.output;
3089
- const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_f = output.value.find(
3088
+ const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? output.value.find(
3090
3089
  (contentPart) => contentPart.providerOptions != null
3091
- )) == null ? void 0 : _f.providerOptions : void 0;
3090
+ )?.providerOptions : void 0;
3092
3091
  const isLastPart = i2 === content.length - 1;
3093
- const cacheControl = (_h = (_g = validator.getCacheControl(part.providerOptions, {
3092
+ const cacheControl = validator.getCacheControl(part.providerOptions, {
3094
3093
  type: "tool result part",
3095
3094
  canCache: true
3096
- })) != null ? _g : validator.getCacheControl(outputProviderOptions, {
3095
+ }) ?? validator.getCacheControl(outputProviderOptions, {
3097
3096
  type: "tool result output",
3098
3097
  canCache: true
3099
- })) != null ? _h : isLastPart ? validator.getCacheControl(message.providerOptions, {
3098
+ }) ?? (isLastPart ? validator.getCacheControl(message.providerOptions, {
3100
3099
  type: "tool result message",
3101
3100
  canCache: true
3102
- }) : void 0;
3101
+ }) : void 0);
3103
3102
  let contentValue;
3104
3103
  switch (output.type) {
3105
3104
  case "content":
3106
3105
  contentValue = output.value.map((contentPart) => {
3107
- var _a2;
3108
3106
  switch (contentPart.type) {
3109
3107
  case "text":
3110
3108
  return {
@@ -3174,8 +3172,8 @@ async function convertToAnthropicPrompt({
3174
3172
  return void 0;
3175
3173
  }
3176
3174
  case "custom": {
3177
- const anthropicOptions = (_a2 = contentPart.providerOptions) == null ? void 0 : _a2.anthropic;
3178
- if ((anthropicOptions == null ? void 0 : anthropicOptions.type) === "tool-reference") {
3175
+ const anthropicOptions = contentPart.providerOptions?.anthropic;
3176
+ if (anthropicOptions?.type === "tool-reference") {
3179
3177
  return {
3180
3178
  type: "tool_reference",
3181
3179
  tool_name: anthropicOptions.toolName
@@ -3202,7 +3200,7 @@ async function convertToAnthropicPrompt({
3202
3200
  contentValue = output.value;
3203
3201
  break;
3204
3202
  case "execution-denied":
3205
- contentValue = (_i = output.reason) != null ? _i : "Tool call execution denied.";
3203
+ contentValue = output.reason ?? "Tool call execution denied.";
3206
3204
  break;
3207
3205
  case "json":
3208
3206
  case "error-json":
@@ -3245,17 +3243,17 @@ async function convertToAnthropicPrompt({
3245
3243
  for (let k = 0; k < content.length; k++) {
3246
3244
  const part = content[k];
3247
3245
  const isLastContentPart = k === content.length - 1;
3248
- const cacheControl = (_j = validator.getCacheControl(part.providerOptions, {
3246
+ const cacheControl = validator.getCacheControl(part.providerOptions, {
3249
3247
  type: "assistant message part",
3250
3248
  canCache: true
3251
- })) != null ? _j : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
3249
+ }) ?? (isLastContentPart ? validator.getCacheControl(message.providerOptions, {
3252
3250
  type: "assistant message",
3253
3251
  canCache: true
3254
- }) : void 0;
3252
+ }) : void 0);
3255
3253
  switch (part.type) {
3256
3254
  case "text": {
3257
- const textMetadata = (_k = part.providerOptions) == null ? void 0 : _k.anthropic;
3258
- if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
3255
+ const textMetadata = part.providerOptions?.anthropic;
3256
+ if (textMetadata?.type === "compaction") {
3259
3257
  if (part.text === "") {
3260
3258
  break;
3261
3259
  }
@@ -3279,7 +3277,7 @@ async function convertToAnthropicPrompt({
3279
3277
  // in pre-filled assistant responses
3280
3278
  isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
3281
3279
  ),
3282
- ...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
3280
+ ...textMetadata?.citations != null && {
3283
3281
  citations: textMetadata.citations
3284
3282
  },
3285
3283
  cache_control: cacheControl
@@ -3340,10 +3338,10 @@ async function convertToAnthropicPrompt({
3340
3338
  const providerToolName = toolNameMapping.toProviderToolName(
3341
3339
  part.toolName
3342
3340
  );
3343
- const isMcpToolUse = ((_m = (_l = part.providerOptions) == null ? void 0 : _l.anthropic) == null ? void 0 : _m.type) === "mcp-tool-use";
3341
+ const isMcpToolUse = part.providerOptions?.anthropic?.type === "mcp-tool-use";
3344
3342
  if (isMcpToolUse) {
3345
3343
  mcpToolUseIds.add(part.toolCallId);
3346
- const serverName = (_o = (_n = part.providerOptions) == null ? void 0 : _n.anthropic) == null ? void 0 : _o.serverName;
3344
+ const serverName = part.providerOptions?.anthropic?.serverName;
3347
3345
  if (serverName == null || typeof serverName !== "string") {
3348
3346
  warnings.push({
3349
3347
  type: "other",
@@ -3493,7 +3491,7 @@ async function convertToAnthropicPrompt({
3493
3491
  } else if (typeof output.value === "object" && output.value !== null) {
3494
3492
  errorInfo = output.value;
3495
3493
  }
3496
- } catch (e) {
3494
+ } catch {
3497
3495
  }
3498
3496
  if (errorInfo.type === "code_execution_tool_result_error") {
3499
3497
  anthropicContent.push({
@@ -3501,7 +3499,7 @@ async function convertToAnthropicPrompt({
3501
3499
  tool_use_id: part.toolCallId,
3502
3500
  content: {
3503
3501
  type: "code_execution_tool_result_error",
3504
- error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
3502
+ error_code: errorInfo.errorCode ?? "unknown"
3505
3503
  },
3506
3504
  cache_control: cacheControl
3507
3505
  });
@@ -3512,7 +3510,7 @@ async function convertToAnthropicPrompt({
3512
3510
  cache_control: cacheControl,
3513
3511
  content: {
3514
3512
  type: "bash_code_execution_tool_result_error",
3515
- error_code: (_q = errorInfo.errorCode) != null ? _q : "unknown"
3513
+ error_code: errorInfo.errorCode ?? "unknown"
3516
3514
  }
3517
3515
  });
3518
3516
  }
@@ -3545,7 +3543,7 @@ async function convertToAnthropicPrompt({
3545
3543
  stdout: codeExecutionOutput.stdout,
3546
3544
  stderr: codeExecutionOutput.stderr,
3547
3545
  return_code: codeExecutionOutput.return_code,
3548
- content: (_r = codeExecutionOutput.content) != null ? _r : []
3546
+ content: codeExecutionOutput.content ?? []
3549
3547
  },
3550
3548
  cache_control: cacheControl
3551
3549
  });
@@ -3563,7 +3561,7 @@ async function convertToAnthropicPrompt({
3563
3561
  encrypted_stdout: codeExecutionOutput.encrypted_stdout,
3564
3562
  stderr: codeExecutionOutput.stderr,
3565
3563
  return_code: codeExecutionOutput.return_code,
3566
- content: (_s = codeExecutionOutput.content) != null ? _s : []
3564
+ content: codeExecutionOutput.content ?? []
3567
3565
  },
3568
3566
  cache_control: cacheControl
3569
3567
  });
@@ -3582,7 +3580,7 @@ async function convertToAnthropicPrompt({
3582
3580
  stdout: codeExecutionOutput.stdout,
3583
3581
  stderr: codeExecutionOutput.stderr,
3584
3582
  return_code: codeExecutionOutput.return_code,
3585
- content: (_t = codeExecutionOutput.content) != null ? _t : []
3583
+ content: codeExecutionOutput.content ?? []
3586
3584
  },
3587
3585
  cache_control: cacheControl
3588
3586
  });
@@ -3620,7 +3618,7 @@ async function convertToAnthropicPrompt({
3620
3618
  tool_use_id: part.toolCallId,
3621
3619
  content: {
3622
3620
  type: "web_fetch_tool_result_error",
3623
- error_code: (_u = extractErrorValue(output.value).errorCode) != null ? _u : "unavailable"
3621
+ error_code: extractErrorValue(output.value).errorCode ?? "unavailable"
3624
3622
  },
3625
3623
  ...caller && { caller },
3626
3624
  cache_control: cacheControl
@@ -3669,7 +3667,7 @@ async function convertToAnthropicPrompt({
3669
3667
  tool_use_id: part.toolCallId,
3670
3668
  content: {
3671
3669
  type: "web_search_tool_result_error",
3672
- error_code: (_v = extractErrorValue(output.value).errorCode) != null ? _v : "unavailable"
3670
+ error_code: extractErrorValue(output.value).errorCode ?? "unavailable"
3673
3671
  },
3674
3672
  ...caller && { caller },
3675
3673
  cache_control: cacheControl
@@ -3817,7 +3815,7 @@ function groupIntoBlocks(prompt) {
3817
3815
  const { role } = message;
3818
3816
  switch (role) {
3819
3817
  case "system": {
3820
- if ((currentBlock == null ? void 0 : currentBlock.type) !== "system") {
3818
+ if (currentBlock?.type !== "system") {
3821
3819
  currentBlock = { type: "system", messages: [] };
3822
3820
  blocks.push(currentBlock);
3823
3821
  }
@@ -3825,7 +3823,7 @@ function groupIntoBlocks(prompt) {
3825
3823
  break;
3826
3824
  }
3827
3825
  case "assistant": {
3828
- if ((currentBlock == null ? void 0 : currentBlock.type) !== "assistant") {
3826
+ if (currentBlock?.type !== "assistant") {
3829
3827
  currentBlock = { type: "assistant", messages: [] };
3830
3828
  blocks.push(currentBlock);
3831
3829
  }
@@ -3833,7 +3831,7 @@ function groupIntoBlocks(prompt) {
3833
3831
  break;
3834
3832
  }
3835
3833
  case "user": {
3836
- if ((currentBlock == null ? void 0 : currentBlock.type) !== "user") {
3834
+ if (currentBlock?.type !== "user") {
3837
3835
  currentBlock = { type: "user", messages: [] };
3838
3836
  blocks.push(currentBlock);
3839
3837
  }
@@ -3841,7 +3839,7 @@ function groupIntoBlocks(prompt) {
3841
3839
  break;
3842
3840
  }
3843
3841
  case "tool": {
3844
- if ((currentBlock == null ? void 0 : currentBlock.type) !== "user") {
3842
+ if (currentBlock?.type !== "user") {
3845
3843
  currentBlock = { type: "user", messages: [] };
3846
3844
  blocks.push(currentBlock);
3847
3845
  }
@@ -3882,24 +3880,22 @@ function getAnthropicToolsetName({
3882
3880
  providerOptions,
3883
3881
  toolsetNames
3884
3882
  }) {
3885
- var _a;
3886
3883
  const fromTools = toolsetNames[toolName];
3887
3884
  if (fromTools != null) {
3888
3885
  return fromTools;
3889
3886
  }
3890
- const fromMetadata = (_a = providerOptions == null ? void 0 : providerOptions.anthropic) == null ? void 0 : _a.toolsetName;
3887
+ const fromMetadata = providerOptions?.anthropic?.toolsetName;
3891
3888
  return typeof fromMetadata === "string" ? fromMetadata : void 0;
3892
3889
  }
3893
3890
  function getAnthropicCaller(providerOptions) {
3894
- var _a;
3895
- const caller = (_a = providerOptions == null ? void 0 : providerOptions.anthropic) == null ? void 0 : _a.caller;
3896
- if (((caller == null ? void 0 : caller.type) === "code_execution_20250825" || (caller == null ? void 0 : caller.type) === "code_execution_20260120") && caller.toolId) {
3891
+ const caller = providerOptions?.anthropic?.caller;
3892
+ if ((caller?.type === "code_execution_20250825" || caller?.type === "code_execution_20260120") && caller.toolId) {
3897
3893
  return {
3898
3894
  type: caller.type,
3899
3895
  tool_id: caller.toolId
3900
3896
  };
3901
3897
  }
3902
- return (caller == null ? void 0 : caller.type) === "direct" ? { type: "direct" } : void 0;
3898
+ return caller?.type === "direct" ? { type: "direct" } : void 0;
3903
3899
  }
3904
3900
  function toAnthropicToolInput(input) {
3905
3901
  return typeof input === "object" && input !== null && !Array.isArray(input) ? input : { rawInvalidInput: input };
@@ -4075,14 +4071,13 @@ function formatConstraintValue(value) {
4075
4071
 
4076
4072
  // src/anthropic-language-model.ts
4077
4073
  function createAnthropicStreamError(error) {
4078
- var _a, _b, _c;
4079
4074
  const inferredMetadata = getAnthropicStreamErrorMetadata(error.type);
4080
4075
  return createProviderStreamError({
4081
4076
  message: error.message,
4082
4077
  type: error.type,
4083
- code: (_a = error.code) != null ? _a : void 0,
4084
- statusCode: (_b = error.statusCode) != null ? _b : inferredMetadata.statusCode,
4085
- isRetryable: (_c = error.isRetryable) != null ? _c : inferredMetadata.isRetryable,
4078
+ code: error.code ?? void 0,
4079
+ statusCode: error.statusCode ?? inferredMetadata.statusCode,
4080
+ isRetryable: error.isRetryable ?? inferredMetadata.isRetryable,
4086
4081
  data: "data" in error ? error.data : error
4087
4082
  });
4088
4083
  }
@@ -4110,14 +4105,13 @@ function getAnthropicStreamErrorMetadata(type) {
4110
4105
  }
4111
4106
  }
4112
4107
  function createCitationSource(citation, citationDocuments, generateId4) {
4113
- var _a, _b;
4114
4108
  if (citation.type === "web_search_result_location") {
4115
4109
  return {
4116
4110
  type: "source",
4117
4111
  sourceType: "url",
4118
4112
  id: generateId4(),
4119
4113
  url: citation.url,
4120
- title: (_a = citation.title) != null ? _a : void 0,
4114
+ title: citation.title ?? void 0,
4121
4115
  providerMetadata: {
4122
4116
  anthropic: {
4123
4117
  citedText: citation.cited_text,
@@ -4138,7 +4132,7 @@ function createCitationSource(citation, citationDocuments, generateId4) {
4138
4132
  sourceType: "document",
4139
4133
  id: generateId4(),
4140
4134
  mediaType: documentInfo.mediaType,
4141
- title: (_b = citation.document_title) != null ? _b : documentInfo.title,
4135
+ title: citation.document_title ?? documentInfo.title,
4142
4136
  filename: documentInfo.filename,
4143
4137
  providerMetadata: {
4144
4138
  anthropic: citation.type === "page_location" ? {
@@ -4165,7 +4159,7 @@ function getAnthropicCallerMetadata(caller) {
4165
4159
  }
4166
4160
  function getAnthropicToolsetNames(tools) {
4167
4161
  const toolsetNames = {};
4168
- for (const tool of tools != null ? tools : []) {
4162
+ for (const tool of tools ?? []) {
4169
4163
  if (tool.type === "provider" && tool.id === "anthropic.computer_toolset_20260801") {
4170
4164
  toolsetNames[tool.name] = "computer";
4171
4165
  }
@@ -4188,10 +4182,9 @@ function getProviderOptionsName(provider) {
4188
4182
  var AnthropicLanguageModel = class _AnthropicLanguageModel {
4189
4183
  constructor(modelId, config) {
4190
4184
  this.specificationVersion = "v4";
4191
- var _a;
4192
4185
  this.modelId = modelId;
4193
4186
  this.config = config;
4194
- this.generateId = (_a = config.generateId) != null ? _a : generateId;
4187
+ this.generateId = config.generateId ?? generateId;
4195
4188
  }
4196
4189
  static [WORKFLOW_SERIALIZE](model) {
4197
4190
  return serializeModelOptions({
@@ -4209,8 +4202,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4209
4202
  return this.config.provider;
4210
4203
  }
4211
4204
  get supportedUrls() {
4212
- var _a, _b, _c;
4213
- return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
4205
+ return this.config.supportedUrls?.() ?? {};
4214
4206
  }
4215
4207
  static async prepareRequest({
4216
4208
  modelId,
@@ -4234,7 +4226,6 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4234
4226
  stream
4235
4227
  }
4236
4228
  }) {
4237
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
4238
4229
  const warnings = [];
4239
4230
  if (frequencyPenalty != null) {
4240
4231
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -4260,7 +4251,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4260
4251
  });
4261
4252
  temperature = 0;
4262
4253
  }
4263
- if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
4254
+ if (responseFormat?.type === "json") {
4264
4255
  if (responseFormat.schema == null) {
4265
4256
  warnings.push({
4266
4257
  type: "unsupported",
@@ -4283,8 +4274,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4283
4274
  const usedCustomProviderKey = customProviderOptions != null;
4284
4275
  const anthropicOptions = Object.assign(
4285
4276
  {},
4286
- canonicalOptions != null ? canonicalOptions : {},
4287
- customProviderOptions != null ? customProviderOptions : {}
4277
+ canonicalOptions ?? {},
4278
+ customProviderOptions ?? {}
4288
4279
  );
4289
4280
  const {
4290
4281
  maxOutputTokens: maxOutputTokensForModel,
@@ -4331,11 +4322,11 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4331
4322
  }
4332
4323
  }
4333
4324
  const isAnthropicModel = isKnownModel || modelId.includes("claude-");
4334
- const supportsStructuredOutput = ((_a = config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
4335
- const supportsStrictTools = ((_b = config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
4336
- const structureOutputMode = (_c = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _c : "auto";
4325
+ const supportsStructuredOutput = (config.supportsNativeStructuredOutput ?? true) && modelSupportsStructuredOutput;
4326
+ const supportsStrictTools = (config.supportsStrictTools ?? true) && modelSupportsStructuredOutput;
4327
+ const structureOutputMode = anthropicOptions?.structuredOutputMode ?? "auto";
4337
4328
  let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
4338
- if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
4329
+ if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && responseFormat?.type === "json" && responseFormat.schema != null) {
4339
4330
  warnings.push({
4340
4331
  type: "unsupported",
4341
4332
  feature: "providerOptions.anthropic.structuredOutputMode",
@@ -4343,21 +4334,21 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4343
4334
  });
4344
4335
  useStructuredOutput = true;
4345
4336
  }
4346
- const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
4337
+ const jsonResponseTool = responseFormat?.type === "json" && responseFormat.schema != null && !useStructuredOutput ? {
4347
4338
  type: "function",
4348
4339
  name: "json",
4349
4340
  description: "Respond with a JSON object.",
4350
4341
  inputSchema: responseFormat.schema
4351
4342
  } : void 0;
4352
- if (jsonResponseTool != null && (anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse) === false) {
4343
+ if (jsonResponseTool != null && anthropicOptions?.disableParallelToolUse === false) {
4353
4344
  warnings.push({
4354
4345
  type: "unsupported",
4355
4346
  feature: "providerOptions.anthropic.disableParallelToolUse",
4356
4347
  details: "`disableParallelToolUse: false` is ignored when using the JSON response tool. Parallel tool use is disabled to ensure a single coherent JSON tool call."
4357
4348
  });
4358
4349
  }
4359
- const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
4360
- const compaction = anthropicOptions == null ? void 0 : anthropicOptions.compaction;
4350
+ const contextManagement = anthropicOptions?.contextManagement;
4351
+ const compaction = anthropicOptions?.compaction;
4361
4352
  if (contextManagement != null && compaction != null) {
4362
4353
  throw new InvalidArgumentError({
4363
4354
  argument: "providerOptions",
@@ -4396,13 +4387,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4396
4387
  const toolsetNames = getAnthropicToolsetNames(tools);
4397
4388
  const { prompt: messagesPrompt, betas } = await convertToAnthropicPrompt({
4398
4389
  prompt,
4399
- sendReasoning: (_d = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _d : true,
4390
+ sendReasoning: anthropicOptions?.sendReasoning ?? true,
4400
4391
  warnings,
4401
4392
  cacheControlValidator,
4402
4393
  toolNameMapping,
4403
4394
  toolsetNames
4404
4395
  });
4405
- if (isCustomReasoning(reasoning) && (anthropicOptions == null ? void 0 : anthropicOptions.effort) == null) {
4396
+ if (isCustomReasoning(reasoning) && anthropicOptions?.effort == null) {
4406
4397
  const reasoningConfig = resolveAnthropicReasoningConfig({
4407
4398
  reasoning,
4408
4399
  modelId,
@@ -4416,12 +4407,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4416
4407
  if (anthropicOptions.thinking == null) {
4417
4408
  anthropicOptions.thinking = reasoningConfig.thinking;
4418
4409
  }
4419
- if (reasoningConfig.effort != null && ((_e = anthropicOptions.thinking) == null ? void 0 : _e.type) !== "disabled") {
4410
+ if (reasoningConfig.effort != null && anthropicOptions.thinking?.type !== "disabled") {
4420
4411
  anthropicOptions.effort = reasoningConfig.effort;
4421
4412
  }
4422
4413
  }
4423
4414
  }
4424
- if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
4415
+ if (rejectsThinkingDisabled && anthropicOptions?.thinking != null) {
4425
4416
  const thinking = anthropicOptions.thinking;
4426
4417
  if (thinking.type === "disabled") {
4427
4418
  warnings.push({
@@ -4439,7 +4430,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4439
4430
  anthropicOptions.thinking = { type: "adaptive" };
4440
4431
  }
4441
4432
  }
4442
- if (rejectsThinkingDisabledAboveHighEffort && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
4433
+ if (rejectsThinkingDisabledAboveHighEffort && anthropicOptions?.thinking?.type === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
4443
4434
  warnings.push({
4444
4435
  type: "unsupported",
4445
4436
  feature: "providerOptions.anthropic.effort",
@@ -4447,13 +4438,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4447
4438
  });
4448
4439
  anthropicOptions.effort = "high";
4449
4440
  }
4450
- const thinkingType = (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.type;
4441
+ const thinkingType = anthropicOptions?.thinking?.type;
4451
4442
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
4452
- const thinkingBlockBinding = (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null && "blockBinding" in anthropicOptions.thinking ? anthropicOptions.thinking.blockBinding : void 0;
4443
+ const thinkingBlockBinding = anthropicOptions?.thinking != null && "blockBinding" in anthropicOptions.thinking ? anthropicOptions.thinking.blockBinding : void 0;
4453
4444
  const sendThinking = isThinking || thinkingType === "disabled" || thinkingBlockBinding != null;
4454
- let thinkingBudget = thinkingType === "enabled" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.budgetTokens : void 0;
4455
- const thinkingDisplay = thinkingType === "adaptive" ? (_i = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _i.display : void 0;
4456
- const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
4445
+ let thinkingBudget = thinkingType === "enabled" ? anthropicOptions?.thinking?.budgetTokens : void 0;
4446
+ const thinkingDisplay = thinkingType === "adaptive" ? anthropicOptions?.thinking?.display : void 0;
4447
+ const maxTokens = maxOutputTokens ?? maxOutputTokensForModel;
4457
4448
  const baseArgs = {
4458
4449
  // model id:
4459
4450
  model: modelId,
@@ -4476,12 +4467,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4476
4467
  }
4477
4468
  }
4478
4469
  },
4479
- ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
4470
+ ...(anthropicOptions?.effort || anthropicOptions?.taskBudget || useStructuredOutput && responseFormat?.type === "json" && responseFormat.schema != null) && {
4480
4471
  output_config: {
4481
- ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
4472
+ ...anthropicOptions?.effort && {
4482
4473
  effort: anthropicOptions.effort
4483
4474
  },
4484
- ...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && {
4475
+ ...anthropicOptions?.taskBudget && {
4485
4476
  task_budget: {
4486
4477
  type: anthropicOptions.taskBudget.type,
4487
4478
  total: anthropicOptions.taskBudget.total,
@@ -4490,7 +4481,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4490
4481
  }
4491
4482
  }
4492
4483
  },
4493
- ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
4484
+ ...useStructuredOutput && responseFormat?.type === "json" && responseFormat.schema != null && {
4494
4485
  format: {
4495
4486
  type: "json_schema",
4496
4487
  schema: sanitizeJsonSchema(responseFormat.schema)
@@ -4498,26 +4489,26 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4498
4489
  }
4499
4490
  }
4500
4491
  },
4501
- ...(anthropicOptions == null ? void 0 : anthropicOptions.speed) && {
4492
+ ...anthropicOptions?.speed && {
4502
4493
  speed: anthropicOptions.speed
4503
4494
  },
4504
- ...(anthropicOptions == null ? void 0 : anthropicOptions.serviceTier) && {
4495
+ ...anthropicOptions?.serviceTier && {
4505
4496
  service_tier: anthropicOptions.serviceTier
4506
4497
  },
4507
- ...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
4498
+ ...anthropicOptions?.inferenceGeo && {
4508
4499
  inference_geo: anthropicOptions.inferenceGeo
4509
4500
  },
4510
- ...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) != null && (anthropicOptions.fallbacks === "default" || anthropicOptions.fallbacks.length > 0) && {
4501
+ ...anthropicOptions?.fallbacks != null && (anthropicOptions.fallbacks === "default" || anthropicOptions.fallbacks.length > 0) && {
4511
4502
  fallbacks: anthropicOptions.fallbacks
4512
4503
  },
4513
- ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
4504
+ ...anthropicOptions?.cacheControl && {
4514
4505
  cache_control: anthropicOptions.cacheControl
4515
4506
  },
4516
- ...((_j = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _j.userId) != null && {
4507
+ ...anthropicOptions?.metadata?.userId != null && {
4517
4508
  metadata: { user_id: anthropicOptions.metadata.userId }
4518
4509
  },
4519
4510
  // mcp servers:
4520
- ...(anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0 && {
4511
+ ...anthropicOptions?.mcpServers && anthropicOptions.mcpServers.length > 0 && {
4521
4512
  mcp_servers: anthropicOptions.mcpServers.map((server) => ({
4522
4513
  type: server.type,
4523
4514
  name: server.name,
@@ -4530,7 +4521,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4530
4521
  }))
4531
4522
  },
4532
4523
  // container: For programmatic tool calling (just an ID string) or agent skills (object with id and skills)
4533
- ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
4524
+ ...anthropicOptions?.container && {
4534
4525
  container: anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0 ? (
4535
4526
  // Object format when skills are provided (agent skills feature)
4536
4527
  {
@@ -4552,7 +4543,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4552
4543
  // prompt:
4553
4544
  system: messagesPrompt.system,
4554
4545
  messages: messagesPrompt.messages,
4555
- ...(anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0 && {
4546
+ ...anthropicOptions?.safeguards && anthropicOptions.safeguards.length > 0 && {
4556
4547
  safeguards: anthropicOptions.safeguards.map((safeguard) => ({
4557
4548
  type: safeguard.type,
4558
4549
  ...safeguard.classifierContext !== void 0 && {
@@ -4656,7 +4647,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4656
4647
  details: "topP is not supported when thinking is enabled"
4657
4648
  });
4658
4649
  }
4659
- baseArgs.max_tokens = maxTokens + (thinkingBudget != null ? thinkingBudget : 0);
4650
+ baseArgs.max_tokens = maxTokens + (thinkingBudget ?? 0);
4660
4651
  } else {
4661
4652
  if (isAnthropicModel && topP != null && temperature != null) {
4662
4653
  warnings.push({
@@ -4677,10 +4668,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4677
4668
  }
4678
4669
  baseArgs.max_tokens = maxOutputTokensForModel;
4679
4670
  }
4680
- if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
4671
+ if (anthropicOptions?.mcpServers && anthropicOptions.mcpServers.length > 0) {
4681
4672
  betas.add("mcp-client-2025-04-04");
4682
4673
  }
4683
- if ((anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0) {
4674
+ if (anthropicOptions?.safeguards && anthropicOptions.safeguards.length > 0) {
4684
4675
  betas.add("dangerous-tool-use-2026-09-03");
4685
4676
  }
4686
4677
  if (compaction) {
@@ -4692,23 +4683,23 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4692
4683
  betas.add("compact-2026-01-12");
4693
4684
  }
4694
4685
  }
4695
- if ((anthropicOptions == null ? void 0 : anthropicOptions.container) && anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0) {
4686
+ if (anthropicOptions?.container && anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0) {
4696
4687
  betas.add("code-execution-2025-08-25");
4697
4688
  betas.add("skills-2025-10-02");
4698
4689
  betas.add("files-api-2025-04-14");
4699
- if (!(tools == null ? void 0 : tools.some(
4690
+ if (!tools?.some(
4700
4691
  (tool) => tool.type === "provider" && (tool.id === "anthropic.code_execution_20250825" || tool.id === "anthropic.code_execution_20260120")
4701
- ))) {
4692
+ )) {
4702
4693
  warnings.push({
4703
4694
  type: "other",
4704
4695
  message: "code execution tool is required when using skills"
4705
4696
  });
4706
4697
  }
4707
4698
  }
4708
- if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
4699
+ if (anthropicOptions?.taskBudget) {
4709
4700
  betas.add("task-budgets-2026-03-13");
4710
4701
  }
4711
- if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
4702
+ if (anthropicOptions?.speed === "fast") {
4712
4703
  betas.add("fast-mode-2026-02-01");
4713
4704
  }
4714
4705
  if (thinkingDisplay === "updates") {
@@ -4717,12 +4708,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4717
4708
  if (thinkingBlockBinding != null) {
4718
4709
  betas.add("thinking-binding-controls-2026-08-01");
4719
4710
  }
4720
- if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) === "default") {
4711
+ if (anthropicOptions?.fallbacks === "default") {
4721
4712
  betas.add("server-side-fallback-2026-07-01");
4722
- } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
4713
+ } else if (anthropicOptions?.fallbacks && anthropicOptions.fallbacks.length > 0) {
4723
4714
  betas.add("server-side-fallback-2026-06-01");
4724
4715
  }
4725
- const defaultEagerInputStreaming = stream && ((_k = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _k : true);
4716
+ const defaultEagerInputStreaming = stream && (anthropicOptions?.toolStreaming ?? true);
4726
4717
  const {
4727
4718
  tools: anthropicTools2,
4728
4719
  toolChoice: anthropicToolChoice,
@@ -4730,7 +4721,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4730
4721
  betas: toolsBetas
4731
4722
  } = await prepareTools(
4732
4723
  jsonResponseTool != null ? {
4733
- tools: [...tools != null ? tools : [], jsonResponseTool],
4724
+ tools: [...tools ?? [], jsonResponseTool],
4734
4725
  toolChoice: { type: "required" },
4735
4726
  disableParallelToolUse: true,
4736
4727
  cacheControlValidator,
@@ -4739,9 +4730,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4739
4730
  defaultEagerInputStreaming,
4740
4731
  rejectsForcedToolUse
4741
4732
  } : {
4742
- tools: tools != null ? tools : [],
4733
+ tools: tools ?? [],
4743
4734
  toolChoice,
4744
- disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
4735
+ disableParallelToolUse: anthropicOptions?.disableParallelToolUse,
4745
4736
  cacheControlValidator,
4746
4737
  supportsStructuredOutput,
4747
4738
  supportsStrictTools,
@@ -4763,7 +4754,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4763
4754
  ...betas,
4764
4755
  ...toolsBetas,
4765
4756
  ...userSuppliedBetas,
4766
- ...(_l = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _l : []
4757
+ ...anthropicOptions?.anthropicBeta ?? []
4767
4758
  ]),
4768
4759
  usesJsonResponseTool: jsonResponseTool != null,
4769
4760
  toolNameMapping,
@@ -4789,10 +4780,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4789
4780
  );
4790
4781
  }
4791
4782
  async getBetasFromHeaders(requestHeaders) {
4792
- var _a, _b;
4793
4783
  const configHeaders = this.config.headers ? await resolve(this.config.headers) : void 0;
4794
- const configBetaHeader = (_a = configHeaders == null ? void 0 : configHeaders["anthropic-beta"]) != null ? _a : "";
4795
- const requestBetaHeader = (_b = requestHeaders == null ? void 0 : requestHeaders["anthropic-beta"]) != null ? _b : "";
4784
+ const configBetaHeader = configHeaders?.["anthropic-beta"] ?? "";
4785
+ const requestBetaHeader = requestHeaders?.["anthropic-beta"] ?? "";
4796
4786
  return new Set(
4797
4787
  [
4798
4788
  ...configBetaHeader.toLowerCase().split(","),
@@ -4801,38 +4791,33 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4801
4791
  );
4802
4792
  }
4803
4793
  buildRequestUrl(isStreaming) {
4804
- var _a, _b, _c;
4805
- return (_c = (_b = (_a = this.config).buildRequestUrl) == null ? void 0 : _b.call(_a, this.config.baseURL, isStreaming)) != null ? _c : `${this.config.baseURL}/messages`;
4794
+ return this.config.buildRequestUrl?.(this.config.baseURL, isStreaming) ?? `${this.config.baseURL}/messages`;
4806
4795
  }
4807
4796
  transformRequestBody(args, betas) {
4808
- var _a, _b, _c;
4809
- return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args, betas)) != null ? _c : args;
4797
+ return this.config.transformRequestBody?.(args, betas) ?? args;
4810
4798
  }
4811
4799
  extractCitationDocuments(prompt) {
4812
4800
  const isCitationPart = (part) => {
4813
- var _a, _b;
4814
4801
  if (part.type !== "file") {
4815
4802
  return false;
4816
4803
  }
4817
4804
  if (part.mediaType !== "application/pdf" && part.mediaType !== "text/plain") {
4818
4805
  return false;
4819
4806
  }
4820
- const anthropic2 = (_a = part.providerOptions) == null ? void 0 : _a.anthropic;
4821
- const citationsConfig = anthropic2 == null ? void 0 : anthropic2.citations;
4822
- return (_b = citationsConfig == null ? void 0 : citationsConfig.enabled) != null ? _b : false;
4807
+ const anthropic2 = part.providerOptions?.anthropic;
4808
+ const citationsConfig = anthropic2?.citations;
4809
+ return citationsConfig?.enabled ?? false;
4823
4810
  };
4824
4811
  return prompt.filter((message) => message.role === "user").flatMap((message) => message.content).filter(isCitationPart).map((part) => {
4825
- var _a;
4826
4812
  const filePart = part;
4827
4813
  return {
4828
- title: (_a = filePart.filename) != null ? _a : "Untitled Document",
4814
+ title: filePart.filename ?? "Untitled Document",
4829
4815
  filename: filePart.filename,
4830
4816
  mediaType: filePart.mediaType
4831
4817
  };
4832
4818
  });
4833
4819
  }
4834
4820
  async doGenerate(options) {
4835
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4836
4821
  const {
4837
4822
  args,
4838
4823
  warnings,
@@ -4873,7 +4858,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4873
4858
  switch (part.type) {
4874
4859
  case "text": {
4875
4860
  if (!usesJsonResponseTool) {
4876
- const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
4861
+ const webSearchCitations = part.citations?.filter(
4877
4862
  (citation) => citation.type === "web_search_result_location"
4878
4863
  );
4879
4864
  content.push({
@@ -4974,7 +4959,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4974
4959
  providerMetadata: {
4975
4960
  anthropic: {
4976
4961
  toolsetName: part.toolset_name,
4977
- ...(_b = getAnthropicCallerMetadata(part.caller).providerMetadata) == null ? void 0 : _b.anthropic
4962
+ ...getAnthropicCallerMetadata(part.caller).providerMetadata?.anthropic
4978
4963
  }
4979
4964
  }
4980
4965
  });
@@ -5075,7 +5060,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5075
5060
  case "web_fetch_tool_result": {
5076
5061
  if (part.content.type === "web_fetch_result") {
5077
5062
  citationDocuments.push({
5078
- title: (_c = part.content.content.title) != null ? _c : part.content.url,
5063
+ title: part.content.content.title ?? part.content.url,
5079
5064
  mediaType: part.content.content.source.media_type
5080
5065
  });
5081
5066
  content.push({
@@ -5120,16 +5105,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5120
5105
  type: "tool-result",
5121
5106
  toolCallId: part.tool_use_id,
5122
5107
  toolName: toolNameMapping.toCustomToolName("web_search"),
5123
- result: part.content.map((result) => {
5124
- var _a2;
5125
- return {
5126
- url: result.url,
5127
- ...result.title != null ? { title: result.title } : {},
5128
- pageAge: (_a2 = result.page_age) != null ? _a2 : null,
5129
- encryptedContent: result.encrypted_content,
5130
- type: result.type
5131
- };
5132
- }),
5108
+ result: part.content.map((result) => ({
5109
+ url: result.url,
5110
+ ...result.title != null ? { title: result.title } : {},
5111
+ pageAge: result.page_age ?? null,
5112
+ encryptedContent: result.encrypted_content,
5113
+ type: result.type
5114
+ })),
5133
5115
  ...getAnthropicCallerMetadata(part.caller)
5134
5116
  });
5135
5117
  for (const result of part.content) {
@@ -5141,7 +5123,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5141
5123
  ...result.title != null ? { title: result.title } : {},
5142
5124
  providerMetadata: {
5143
5125
  anthropic: {
5144
- pageAge: (_d = result.page_age) != null ? _d : null
5126
+ pageAge: result.page_age ?? null
5145
5127
  }
5146
5128
  }
5147
5129
  });
@@ -5173,7 +5155,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5173
5155
  stdout: part.content.stdout,
5174
5156
  stderr: part.content.stderr,
5175
5157
  return_code: part.content.return_code,
5176
- content: (_e = part.content.content) != null ? _e : []
5158
+ content: part.content.content ?? []
5177
5159
  }
5178
5160
  });
5179
5161
  } else if (part.content.type === "encrypted_code_execution_result") {
@@ -5186,7 +5168,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5186
5168
  encrypted_stdout: part.content.encrypted_stdout,
5187
5169
  stderr: part.content.stderr,
5188
5170
  return_code: part.content.return_code,
5189
- content: (_f = part.content.content) != null ? _f : []
5171
+ content: part.content.content ?? []
5190
5172
  }
5191
5173
  });
5192
5174
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -5314,23 +5296,22 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5314
5296
  finishReason: response.stop_reason,
5315
5297
  isJsonResponseFromTool
5316
5298
  }),
5317
- raw: (_g = response.stop_reason) != null ? _g : void 0
5299
+ raw: response.stop_reason ?? void 0
5318
5300
  },
5319
5301
  usage: convertAnthropicUsage({ usage: response.usage }),
5320
5302
  request: { body: args },
5321
5303
  response: {
5322
- id: (_h = response.id) != null ? _h : void 0,
5323
- modelId: (_i = response.model) != null ? _i : void 0,
5304
+ id: response.id ?? void 0,
5305
+ modelId: response.model ?? void 0,
5324
5306
  headers: responseHeaders,
5325
5307
  body: rawResponse
5326
5308
  },
5327
5309
  warnings,
5328
5310
  providerMetadata: (() => {
5329
- var _a2, _b2, _c2, _d2;
5330
5311
  const stopDetails = mapAnthropicStopDetails(response.stop_details);
5331
5312
  const anthropicMetadata = {
5332
5313
  usage: response.usage,
5333
- stopSequence: (_a2 = response.stop_sequence) != null ? _a2 : null,
5314
+ stopSequence: response.stop_sequence ?? null,
5334
5315
  ...stopDetails != null ? { stopDetails } : {},
5335
5316
  ...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
5336
5317
  ...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
@@ -5351,15 +5332,15 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5351
5332
  container: response.container ? {
5352
5333
  expiresAt: response.container.expires_at,
5353
5334
  id: response.container.id,
5354
- skills: (_c2 = (_b2 = response.container.skills) == null ? void 0 : _b2.map((skill) => ({
5335
+ skills: response.container.skills?.map((skill) => ({
5355
5336
  type: skill.type,
5356
5337
  skillId: skill.skill_id,
5357
5338
  version: skill.version
5358
- }))) != null ? _c2 : null
5339
+ })) ?? null
5359
5340
  } : null,
5360
- contextManagement: (_d2 = mapAnthropicResponseContextManagement(
5341
+ contextManagement: mapAnthropicResponseContextManagement(
5361
5342
  response.context_management
5362
- )) != null ? _d2 : null
5343
+ ) ?? null
5363
5344
  };
5364
5345
  const providerMetadata = {
5365
5346
  anthropic: anthropicMetadata
@@ -5373,7 +5354,6 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5373
5354
  }
5374
5355
  async doStream(options) {
5375
5356
  "use step";
5376
- var _a, _b, _c, _d;
5377
5357
  const {
5378
5358
  args: body,
5379
5359
  warnings,
@@ -5434,7 +5414,6 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5434
5414
  controller.enqueue({ type: "stream-start", warnings });
5435
5415
  },
5436
5416
  transform(chunk, controller) {
5437
- var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m;
5438
5417
  if (hasInvalidMessageSequence) {
5439
5418
  return;
5440
5419
  }
@@ -5662,7 +5641,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5662
5641
  case "web_fetch_tool_result": {
5663
5642
  if (part.content.type === "web_fetch_result") {
5664
5643
  citationDocuments.push({
5665
- title: (_a2 = part.content.content.title) != null ? _a2 : part.content.url,
5644
+ title: part.content.content.title ?? part.content.url,
5666
5645
  mediaType: part.content.content.source.media_type
5667
5646
  });
5668
5647
  controller.enqueue({
@@ -5707,16 +5686,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5707
5686
  type: "tool-result",
5708
5687
  toolCallId: part.tool_use_id,
5709
5688
  toolName: toolNameMapping.toCustomToolName("web_search"),
5710
- result: part.content.map((result) => {
5711
- var _a3;
5712
- return {
5713
- url: result.url,
5714
- ...result.title != null ? { title: result.title } : {},
5715
- pageAge: (_a3 = result.page_age) != null ? _a3 : null,
5716
- encryptedContent: result.encrypted_content,
5717
- type: result.type
5718
- };
5719
- }),
5689
+ result: part.content.map((result) => ({
5690
+ url: result.url,
5691
+ ...result.title != null ? { title: result.title } : {},
5692
+ pageAge: result.page_age ?? null,
5693
+ encryptedContent: result.encrypted_content,
5694
+ type: result.type
5695
+ })),
5720
5696
  ...getAnthropicCallerMetadata(part.caller)
5721
5697
  });
5722
5698
  for (const result of part.content) {
@@ -5728,7 +5704,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5728
5704
  ...result.title != null ? { title: result.title } : {},
5729
5705
  providerMetadata: {
5730
5706
  anthropic: {
5731
- pageAge: (_b2 = result.page_age) != null ? _b2 : null
5707
+ pageAge: result.page_age ?? null
5732
5708
  }
5733
5709
  }
5734
5710
  });
@@ -5760,7 +5736,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5760
5736
  stdout: part.content.stdout,
5761
5737
  stderr: part.content.stderr,
5762
5738
  return_code: part.content.return_code,
5763
- content: (_c2 = part.content.content) != null ? _c2 : []
5739
+ content: part.content.content ?? []
5764
5740
  }
5765
5741
  });
5766
5742
  } else if (part.content.type === "encrypted_code_execution_result") {
@@ -5773,7 +5749,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5773
5749
  encrypted_stdout: part.content.encrypted_stdout,
5774
5750
  stderr: part.content.stderr,
5775
5751
  return_code: part.content.return_code,
5776
- content: (_d2 = part.content.content) != null ? _d2 : []
5752
+ content: part.content.content ?? []
5777
5753
  }
5778
5754
  });
5779
5755
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -5957,7 +5933,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5957
5933
  let memberInput = {};
5958
5934
  try {
5959
5935
  memberInput = contentBlock.input === "" ? {} : secureJsonParse2(contentBlock.input);
5960
- } catch (e) {
5936
+ } catch {
5961
5937
  memberInput = void 0;
5962
5938
  }
5963
5939
  contentBlock.input = memberInput === void 0 ? contentBlock.input : JSON.stringify(
@@ -5986,7 +5962,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5986
5962
  ...parsed
5987
5963
  });
5988
5964
  }
5989
- } catch (e) {
5965
+ } catch {
5990
5966
  }
5991
5967
  }
5992
5968
  controller.enqueue({
@@ -6075,7 +6051,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6075
6051
  return;
6076
6052
  }
6077
6053
  if (isJsonResponseFromTool) {
6078
- if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
6054
+ if (contentBlock?.type !== "text") {
6079
6055
  return;
6080
6056
  }
6081
6057
  controller.enqueue({
@@ -6084,7 +6060,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6084
6060
  delta
6085
6061
  });
6086
6062
  } else {
6087
- if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
6063
+ if (contentBlock?.type !== "tool-call") {
6088
6064
  return;
6089
6065
  }
6090
6066
  if (contentBlock.toolset != null) {
@@ -6107,7 +6083,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6107
6083
  case "citations_delta": {
6108
6084
  const citation = value.delta.citation;
6109
6085
  const contentBlock = contentBlocks[value.index];
6110
- if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
6086
+ if (contentBlock?.type === "text" && citation.type === "web_search_result_location") {
6111
6087
  contentBlock.citations.push(citation);
6112
6088
  }
6113
6089
  const source = createCitationSource(
@@ -6146,8 +6122,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6146
6122
  isMessageOpen = true;
6147
6123
  activeMessageId = value.message.id;
6148
6124
  usage.input_tokens = value.message.usage.input_tokens;
6149
- usage.cache_read_input_tokens = (_e = value.message.usage.cache_read_input_tokens) != null ? _e : 0;
6150
- usage.cache_creation_input_tokens = (_f = value.message.usage.cache_creation_input_tokens) != null ? _f : 0;
6125
+ usage.cache_read_input_tokens = value.message.usage.cache_read_input_tokens ?? 0;
6126
+ usage.cache_creation_input_tokens = value.message.usage.cache_creation_input_tokens ?? 0;
6151
6127
  rawUsage = {
6152
6128
  ...value.message.usage
6153
6129
  };
@@ -6172,8 +6148,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6172
6148
  }
6173
6149
  controller.enqueue({
6174
6150
  type: "response-metadata",
6175
- id: (_g = value.message.id) != null ? _g : void 0,
6176
- modelId: (_h = value.message.model) != null ? _h : void 0
6151
+ id: value.message.id ?? void 0,
6152
+ modelId: value.message.model ?? void 0
6177
6153
  });
6178
6154
  if (value.message.content != null) {
6179
6155
  for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
@@ -6185,7 +6161,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6185
6161
  id: part.id,
6186
6162
  toolName: part.name
6187
6163
  });
6188
- const inputStr = JSON.stringify((_i = part.input) != null ? _i : {});
6164
+ const inputStr = JSON.stringify(part.input ?? {});
6189
6165
  controller.enqueue({
6190
6166
  type: "tool-input-delta",
6191
6167
  id: part.id,
@@ -6235,18 +6211,18 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6235
6211
  finishReason: value.delta.stop_reason,
6236
6212
  isJsonResponseFromTool
6237
6213
  }),
6238
- raw: (_j = value.delta.stop_reason) != null ? _j : void 0
6214
+ raw: value.delta.stop_reason ?? void 0
6239
6215
  };
6240
- stopSequence = (_k = value.delta.stop_sequence) != null ? _k : null;
6216
+ stopSequence = value.delta.stop_sequence ?? null;
6241
6217
  stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
6242
6218
  container = value.delta.container != null ? {
6243
6219
  expiresAt: value.delta.container.expires_at,
6244
6220
  id: value.delta.container.id,
6245
- skills: (_m = (_l = value.delta.container.skills) == null ? void 0 : _l.map((skill) => ({
6221
+ skills: value.delta.container.skills?.map((skill) => ({
6246
6222
  type: skill.type,
6247
6223
  skillId: skill.skill_id,
6248
6224
  version: skill.version
6249
- }))) != null ? _m : null
6225
+ })) ?? null
6250
6226
  } : null;
6251
6227
  if (value.context_management) {
6252
6228
  contextManagement = mapAnthropicResponseContextManagement(
@@ -6269,7 +6245,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6269
6245
  isMessageOpen = false;
6270
6246
  activeMessageId = void 0;
6271
6247
  const anthropicMetadata = {
6272
- usage: rawUsage != null ? rawUsage : null,
6248
+ usage: rawUsage ?? null,
6273
6249
  stopSequence,
6274
6250
  ...stopDetails != null ? { stopDetails } : {},
6275
6251
  ...inputTransformations != null ? { inputTransformations } : {},
@@ -6325,10 +6301,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6325
6301
  try {
6326
6302
  await firstChunkReader.read();
6327
6303
  let result = await firstChunkReader.read();
6328
- if (((_a = result.value) == null ? void 0 : _a.type) === "raw") {
6304
+ if (result.value?.type === "raw") {
6329
6305
  result = await firstChunkReader.read();
6330
6306
  }
6331
- if (((_b = result.value) == null ? void 0 : _b.type) === "error") {
6307
+ if (result.value?.type === "error") {
6332
6308
  const error = result.value.error;
6333
6309
  if (!isProviderStreamError(error)) {
6334
6310
  throw new Error("Expected a normalized Anthropic stream error");
@@ -6337,10 +6313,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6337
6313
  message: error.message,
6338
6314
  url,
6339
6315
  requestBodyValues: body,
6340
- statusCode: (_c = error.statusCode) != null ? _c : 500,
6316
+ statusCode: error.statusCode ?? 500,
6341
6317
  responseHeaders,
6342
6318
  responseBody: JSON.stringify(error.data),
6343
- isRetryable: (_d = error.isRetryable) != null ? _d : false
6319
+ isRetryable: error.isRetryable ?? false
6344
6320
  });
6345
6321
  }
6346
6322
  } finally {
@@ -6755,10 +6731,9 @@ var AnthropicBatch = class {
6755
6731
  constructor(options) {
6756
6732
  this.options = options;
6757
6733
  this.specificationVersion = "v4";
6758
- var _a;
6759
6734
  this.provider = options.provider;
6760
6735
  this.supportedUrls = options.supportedUrls;
6761
- this.generateId = (_a = options.config.generateId) != null ? _a : generateId2;
6736
+ this.generateId = options.config.generateId ?? generateId2;
6762
6737
  }
6763
6738
  async doStartBatch({
6764
6739
  requests,
@@ -6767,7 +6742,6 @@ var AnthropicBatch = class {
6767
6742
  abortSignal,
6768
6743
  webhookUrl
6769
6744
  }) {
6770
- var _a, _b, _c, _d;
6771
6745
  assertTextBatchRequests(requests);
6772
6746
  validateRequestIds(requests);
6773
6747
  const explicitBatchBetas = new Set(
@@ -6813,7 +6787,7 @@ var AnthropicBatch = class {
6813
6787
  message: `Anthropic Message Batches cannot decode the JSON-tool structured-output fallback (request "${request.id}") because batch results are retrieved independently of the start call. Use a model that supports native output_format structured outputs.`
6814
6788
  });
6815
6789
  }
6816
- const aliasedProviderTool = (_a = request.options.tools) == null ? void 0 : _a.find(
6790
+ const aliasedProviderTool = request.options.tools?.find(
6817
6791
  (tool) => tool.type === "provider" && prepared.toolNameMapping.toProviderToolName(tool.name) !== tool.name
6818
6792
  );
6819
6793
  if (aliasedProviderTool != null) {
@@ -6822,11 +6796,10 @@ var AnthropicBatch = class {
6822
6796
  message: `Anthropic Message Batches cannot restore the custom provider-tool name "${aliasedProviderTool.name}" when results are retrieved independently of the start call (request "${request.id}"). Use the provider's canonical tool name.`
6823
6797
  });
6824
6798
  }
6825
- const body = (_d = (_c = (_b = this.options.config).transformRequestBody) == null ? void 0 : _c.call(
6826
- _b,
6799
+ const body = this.options.config.transformRequestBody?.(
6827
6800
  prepared.args,
6828
6801
  prepared.betas
6829
- )) != null ? _d : prepared.args;
6802
+ ) ?? prepared.args;
6830
6803
  validateAnthropicBatchBody({
6831
6804
  body,
6832
6805
  requestId: request.id
@@ -6981,7 +6954,6 @@ async function getAnthropicBatchProviderBetas({
6981
6954
  provider,
6982
6955
  providerOptions
6983
6956
  }) {
6984
- var _a;
6985
6957
  const providerOptionsName = provider.split(".")[0];
6986
6958
  const canonicalOptions = await parseProviderOptions3({
6987
6959
  provider: "anthropic",
@@ -6995,10 +6967,10 @@ async function getAnthropicBatchProviderBetas({
6995
6967
  }) : void 0;
6996
6968
  const anthropicOptions = Object.assign(
6997
6969
  {},
6998
- canonicalOptions != null ? canonicalOptions : {},
6999
- customOptions != null ? customOptions : {}
6970
+ canonicalOptions ?? {},
6971
+ customOptions ?? {}
7000
6972
  );
7001
- return (_a = anthropicOptions.anthropicBeta) != null ? _a : [];
6973
+ return anthropicOptions.anthropicBeta ?? [];
7002
6974
  }
7003
6975
  function validateRequestIds(requests) {
7004
6976
  const ids = /* @__PURE__ */ new Set();
@@ -7038,7 +7010,6 @@ function validateAnthropicBatchBody({
7038
7010
  }
7039
7011
  }
7040
7012
  function convertAnthropicBatchStatus(batch) {
7041
- var _a, _b, _c, _d;
7042
7013
  const requestCounts = convertAnthropicRequestCounts(batch.request_counts);
7043
7014
  return {
7044
7015
  status: mapAnthropicBatchStatus(batch.processing_status),
@@ -7048,11 +7019,11 @@ function convertAnthropicBatchStatus(batch) {
7048
7019
  expiresAt: batch.expires_at,
7049
7020
  providerMetadata: {
7050
7021
  anthropic: {
7051
- archivedAt: (_a = batch.archived_at) != null ? _a : null,
7052
- cancelInitiatedAt: (_b = batch.cancel_initiated_at) != null ? _b : null,
7053
- endedAt: (_c = batch.ended_at) != null ? _c : null,
7022
+ archivedAt: batch.archived_at ?? null,
7023
+ cancelInitiatedAt: batch.cancel_initiated_at ?? null,
7024
+ endedAt: batch.ended_at ?? null,
7054
7025
  requestCounts: batch.request_counts,
7055
- resultsUrl: (_d = batch.results_url) != null ? _d : null
7026
+ resultsUrl: batch.results_url ?? null
7056
7027
  }
7057
7028
  }
7058
7029
  };
@@ -7164,7 +7135,6 @@ async function parseAnthropicBatchResponse(message) {
7164
7135
  return recovered.success ? recovered.value : void 0;
7165
7136
  }
7166
7137
  function convertAnthropicBatchResponse(response, generateId4) {
7167
- var _a, _b, _c, _d, _e, _f, _g;
7168
7138
  const content = [];
7169
7139
  const mcpToolCalls = {};
7170
7140
  const serverToolCalls = {};
@@ -7181,7 +7151,7 @@ function convertAnthropicBatchResponse(response, generateId4) {
7181
7151
  }
7182
7152
  }
7183
7153
  });
7184
- for (const citation of (_a = part.citations) != null ? _a : []) {
7154
+ for (const citation of part.citations ?? []) {
7185
7155
  const source = createCitationSource(citation, [], generateId4);
7186
7156
  if (source != null) {
7187
7157
  content.push(source);
@@ -7287,11 +7257,11 @@ function convertAnthropicBatchResponse(response, generateId4) {
7287
7257
  content.push({
7288
7258
  type: "tool-result",
7289
7259
  toolCallId: part.tool_use_id,
7290
- toolName: (_b = toolCall == null ? void 0 : toolCall.toolName) != null ? _b : "mcp",
7260
+ toolName: toolCall?.toolName ?? "mcp",
7291
7261
  isError: part.is_error,
7292
7262
  result: part.content,
7293
7263
  dynamic: true,
7294
- ...(toolCall == null ? void 0 : toolCall.providerMetadata) != null && {
7264
+ ...toolCall?.providerMetadata != null && {
7295
7265
  providerMetadata: toolCall.providerMetadata
7296
7266
  }
7297
7267
  });
@@ -7334,16 +7304,13 @@ function convertAnthropicBatchResponse(response, generateId4) {
7334
7304
  toolCallId: part.tool_use_id,
7335
7305
  toolName: "web_search",
7336
7306
  ...Array.isArray(part.content) ? {
7337
- result: part.content.map((result) => {
7338
- var _a2;
7339
- return {
7340
- encryptedContent: result.encrypted_content,
7341
- pageAge: (_a2 = result.page_age) != null ? _a2 : null,
7342
- ...result.title != null ? { title: result.title } : {},
7343
- type: result.type,
7344
- url: result.url
7345
- };
7346
- })
7307
+ result: part.content.map((result) => ({
7308
+ encryptedContent: result.encrypted_content,
7309
+ pageAge: result.page_age ?? null,
7310
+ ...result.title != null ? { title: result.title } : {},
7311
+ type: result.type,
7312
+ url: result.url
7313
+ }))
7347
7314
  } : {
7348
7315
  isError: true,
7349
7316
  result: {
@@ -7363,7 +7330,7 @@ function convertAnthropicBatchResponse(response, generateId4) {
7363
7330
  ...result.title != null ? { title: result.title } : {},
7364
7331
  providerMetadata: {
7365
7332
  anthropic: {
7366
- pageAge: (_c = result.page_age) != null ? _c : null
7333
+ pageAge: result.page_age ?? null
7367
7334
  }
7368
7335
  }
7369
7336
  });
@@ -7394,7 +7361,7 @@ function convertAnthropicBatchResponse(response, generateId4) {
7394
7361
  });
7395
7362
  break;
7396
7363
  case "tool_search_tool_result": {
7397
- const toolName = (_d = serverToolCalls[part.tool_use_id]) != null ? _d : "tool_search_tool_regex";
7364
+ const toolName = serverToolCalls[part.tool_use_id] ?? "tool_search_tool_regex";
7398
7365
  content.push({
7399
7366
  type: "tool-result",
7400
7367
  toolCallId: part.tool_use_id,
@@ -7460,12 +7427,12 @@ function convertAnthropicBatchResponse(response, generateId4) {
7460
7427
  unified: mapAnthropicStopReason({
7461
7428
  finishReason: response.stop_reason
7462
7429
  }),
7463
- raw: (_e = response.stop_reason) != null ? _e : void 0
7430
+ raw: response.stop_reason ?? void 0
7464
7431
  },
7465
7432
  usage: convertAnthropicUsage({ usage: response.usage }),
7466
7433
  response: {
7467
- id: (_f = response.id) != null ? _f : void 0,
7468
- modelId: (_g = response.model) != null ? _g : void 0
7434
+ id: response.id ?? void 0,
7435
+ modelId: response.model ?? void 0
7469
7436
  },
7470
7437
  warnings: [],
7471
7438
  providerMetadata: {
@@ -7486,11 +7453,10 @@ function anthropicCallerMetadata(caller) {
7486
7453
  };
7487
7454
  }
7488
7455
  function convertAnthropicMessageMetadata(response) {
7489
- var _a, _b, _c;
7490
7456
  const stopDetails = mapAnthropicStopDetails2(response.stop_details);
7491
7457
  return {
7492
7458
  usage: response.usage,
7493
- stopSequence: (_a = response.stop_sequence) != null ? _a : null,
7459
+ stopSequence: response.stop_sequence ?? null,
7494
7460
  ...stopDetails != null ? { stopDetails } : {},
7495
7461
  ...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
7496
7462
  ...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
@@ -7509,11 +7475,11 @@ function convertAnthropicMessageMetadata(response) {
7509
7475
  container: response.container ? {
7510
7476
  expiresAt: response.container.expires_at,
7511
7477
  id: response.container.id,
7512
- skills: (_c = (_b = response.container.skills) == null ? void 0 : _b.map((skill) => ({
7478
+ skills: response.container.skills?.map((skill) => ({
7513
7479
  type: skill.type,
7514
7480
  skillId: skill.skill_id,
7515
7481
  version: skill.version
7516
- }))) != null ? _c : null
7482
+ })) ?? null
7517
7483
  } : null,
7518
7484
  contextManagement: mapAnthropicResponseContextManagement2(
7519
7485
  response.context_management
@@ -8294,7 +8260,6 @@ var AnthropicSkills = class {
8294
8260
  };
8295
8261
  }
8296
8262
  async uploadSkill(params) {
8297
- var _a, _b;
8298
8263
  const warnings = [];
8299
8264
  const formData = new FormData();
8300
8265
  if (params.displayTitle != null) {
@@ -8320,8 +8285,8 @@ var AnthropicSkills = class {
8320
8285
  version: response.latest_version,
8321
8286
  headers
8322
8287
  }) : {};
8323
- const name = (_a = versionMetadata.name) != null ? _a : response.name;
8324
- const description = (_b = versionMetadata.description) != null ? _b : response.description;
8288
+ const name = versionMetadata.name ?? response.name;
8289
+ const description = versionMetadata.description ?? response.description;
8325
8290
  return {
8326
8291
  providerReference: { anthropic: response.id },
8327
8292
  ...response.display_title != null ? { displayTitle: response.display_title } : {},
@@ -8341,7 +8306,7 @@ var AnthropicSkills = class {
8341
8306
  };
8342
8307
 
8343
8308
  // src/version.ts
8344
- var VERSION = true ? "4.0.63" : "0.0.0-test";
8309
+ var VERSION = true ? "4.0.65" : "0.0.0-test";
8345
8310
 
8346
8311
  // src/anthropic-provider.ts
8347
8312
  var ANTHROPIC_API_URL = "https://api.anthropic.com";
@@ -8353,14 +8318,13 @@ function normalizeBaseURL(baseURL) {
8353
8318
  return baseURLWithoutTrailingSlash === ANTHROPIC_API_URL ? ANTHROPIC_API_VERSIONED_URL : baseURLWithoutTrailingSlash;
8354
8319
  }
8355
8320
  function createAnthropic(options = {}) {
8356
- var _a, _b, _c;
8357
- const baseURL = (_a = normalizeBaseURL(
8321
+ const baseURL = normalizeBaseURL(
8358
8322
  loadOptionalSetting({
8359
8323
  settingValue: options.baseURL,
8360
8324
  environmentVariableName: "ANTHROPIC_BASE_URL"
8361
8325
  })
8362
- )) != null ? _a : ANTHROPIC_API_VERSIONED_URL;
8363
- const providerName = (_b = options.name) != null ? _b : "anthropic.messages";
8326
+ ) ?? ANTHROPIC_API_VERSIONED_URL;
8327
+ const providerName = options.name ?? "anthropic.messages";
8364
8328
  const supportedUrls = {
8365
8329
  "image/*": [/^https?:\/\/.*$/],
8366
8330
  "application/pdf": [/^https?:\/\/.*$/]
@@ -8393,7 +8357,7 @@ function createAnthropic(options = {}) {
8393
8357
  baseURL,
8394
8358
  headers: getHeaders,
8395
8359
  fetch: options.fetch,
8396
- generateId: (_c = options.generateId) != null ? _c : generateId3,
8360
+ generateId: options.generateId ?? generateId3,
8397
8361
  supportedUrls: () => supportedUrls
8398
8362
  };
8399
8363
  const createChatModel = (modelId) => new AnthropicLanguageModel(modelId, languageModelConfig);
@@ -8448,9 +8412,8 @@ var anthropic = createAnthropic();
8448
8412
  function forwardAnthropicContainerIdFromLastStep({
8449
8413
  steps
8450
8414
  }) {
8451
- var _a, _b, _c;
8452
8415
  for (let i = steps.length - 1; i >= 0; i--) {
8453
- const containerId = (_c = (_b = (_a = steps[i].providerMetadata) == null ? void 0 : _a.anthropic) == null ? void 0 : _b.container) == null ? void 0 : _c.id;
8416
+ const containerId = steps[i].providerMetadata?.anthropic?.container?.id;
8454
8417
  if (containerId) {
8455
8418
  return {
8456
8419
  providerOptions: {