@ai-sdk/anthropic 4.0.62 → 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.
@@ -61,7 +61,6 @@ var AnthropicFiles = class {
61
61
  abortSignal,
62
62
  headers
63
63
  }) {
64
- var _a, _b;
65
64
  const fileBytes = convertInlineFileDataToUint8Array(data);
66
65
  const blob = new Blob([fileBytes], { type: mediaType });
67
66
  const formData = new FormData();
@@ -88,8 +87,8 @@ var AnthropicFiles = class {
88
87
  return {
89
88
  warnings: [],
90
89
  providerReference: { anthropic: response.id },
91
- mediaType: (_a = response.mime_type) != null ? _a : mediaType,
92
- filename: (_b = response.filename) != null ? _b : filename,
90
+ mediaType: response.mime_type ?? mediaType,
91
+ filename: response.filename ?? filename,
93
92
  providerMetadata: {
94
93
  anthropic: {
95
94
  filename: response.filename,
@@ -106,6 +105,7 @@ var AnthropicFiles = class {
106
105
  // src/anthropic-language-model.ts
107
106
  import {
108
107
  APICallError,
108
+ InvalidArgumentError,
109
109
  InvalidResponseDataError
110
110
  } from "@ai-sdk/provider";
111
111
  import {
@@ -257,7 +257,8 @@ var anthropicResponseSchema = lazySchema3(
257
257
  }),
258
258
  z3.object({
259
259
  type: z3.literal("compaction"),
260
- content: z3.string().nullish()
260
+ content: z3.string().nullish(),
261
+ signature: z3.string().nullish()
261
262
  }),
262
263
  z3.object({
263
264
  type: z3.literal("tool_use"),
@@ -612,7 +613,8 @@ var anthropicChunkSchema = lazySchema3(
612
613
  }),
613
614
  z3.object({
614
615
  type: z3.literal("compaction"),
615
- content: z3.string().nullish()
616
+ content: z3.string().nullish(),
617
+ signature: z3.string().nullish()
616
618
  }),
617
619
  z3.object({
618
620
  type: z3.literal("server_tool_use"),
@@ -996,9 +998,10 @@ var anthropicSystemMessageProviderOptions = z4.object({
996
998
  */
997
999
  clearAt: z4.literal("next_user_message").optional(),
998
1000
  /**
999
- * Sets the model effort for the turn that follows this mid-conversation
1000
- * system message. The required `mid-conversation-output-config-2026-07-01`
1001
- * beta is added automatically.
1001
+ * Sets the model effort from the next user turn until a later message
1002
+ * changes it. An effort-only system message with empty content can appear
1003
+ * first. The required `mid-conversation-output-config-2026-07-01` beta is
1004
+ * added automatically.
1002
1005
  */
1003
1006
  effort: z4.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
1004
1007
  /**
@@ -1251,6 +1254,16 @@ var anthropicLanguageModelOptions = z4.object({
1251
1254
  classifierContext: z4.record(z4.string(), z4.unknown()).optional()
1252
1255
  })
1253
1256
  ).optional(),
1257
+ /**
1258
+ * Requests an on-demand summary of the supplied conversation.
1259
+ *
1260
+ * The required `compact-2026-09-04` beta is added automatically.
1261
+ * Cannot be combined with `contextManagement`.
1262
+ */
1263
+ compaction: z4.object({
1264
+ type: z4.literal("summarize"),
1265
+ instructions: z4.string().optional()
1266
+ }).optional(),
1254
1267
  contextManagement: z4.object({
1255
1268
  edits: z4.array(
1256
1269
  z4.discriminatedUnion("type", [
@@ -1309,9 +1322,8 @@ import {
1309
1322
  // src/get-cache-control.ts
1310
1323
  var MAX_CACHE_BREAKPOINTS = 4;
1311
1324
  function getCacheControl(providerMetadata) {
1312
- var _a;
1313
- const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
1314
- const cacheControlValue = (_a = anthropic == null ? void 0 : anthropic.cacheControl) != null ? _a : anthropic == null ? void 0 : anthropic.cache_control;
1325
+ const anthropic = providerMetadata?.anthropic;
1326
+ const cacheControlValue = anthropic?.cacheControl ?? anthropic?.cache_control;
1315
1327
  return cacheControlValue;
1316
1328
  }
1317
1329
  var CacheControlValidator = class {
@@ -1858,8 +1870,7 @@ async function prepareTools({
1858
1870
  defaultEagerInputStreaming = false,
1859
1871
  rejectsForcedToolUse = false
1860
1872
  }) {
1861
- var _a, _b;
1862
- tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
1873
+ tools = tools?.length ? tools : void 0;
1863
1874
  const toolWarnings = [];
1864
1875
  const betas = /* @__PURE__ */ new Set();
1865
1876
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1874,10 +1885,10 @@ async function prepareTools({
1874
1885
  type: "tool definition",
1875
1886
  canCache: true
1876
1887
  });
1877
- const anthropicOptions = (_a = tool.providerOptions) == null ? void 0 : _a.anthropic;
1878
- const eagerInputStreaming = (_b = anthropicOptions == null ? void 0 : anthropicOptions.eagerInputStreaming) != null ? _b : defaultEagerInputStreaming;
1879
- const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
1880
- const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
1888
+ const anthropicOptions = tool.providerOptions?.anthropic;
1889
+ const eagerInputStreaming = anthropicOptions?.eagerInputStreaming ?? defaultEagerInputStreaming;
1890
+ const deferLoading = anthropicOptions?.deferLoading;
1891
+ const allowedCallers = anthropicOptions?.allowedCallers;
1881
1892
  if (!supportsStrictTools && tool.strict != null) {
1882
1893
  toolWarnings.push({
1883
1894
  type: "unsupported",
@@ -1968,10 +1979,10 @@ async function prepareTools({
1968
1979
  Object.entries(args.configs).map(([member, config]) => [
1969
1980
  member,
1970
1981
  {
1971
- ...(config == null ? void 0 : config.enabled) != null && {
1982
+ ...config?.enabled != null && {
1972
1983
  enabled: config.enabled
1973
1984
  },
1974
- ...(config == null ? void 0 : config.deferLoading) != null && {
1985
+ ...config?.deferLoading != null && {
1975
1986
  defer_loading: config.deferLoading
1976
1987
  }
1977
1988
  }
@@ -2309,13 +2320,12 @@ function convertAnthropicUsage({
2309
2320
  usage,
2310
2321
  rawUsage
2311
2322
  }) {
2312
- var _a, _b, _c, _d, _e;
2313
- const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
2314
- const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
2315
- const reasoningTokens = (_d = (_c = usage.output_tokens_details) == null ? void 0 : _c.thinking_tokens) != null ? _d : void 0;
2323
+ const cacheCreationTokens = usage.cache_creation_input_tokens ?? 0;
2324
+ const cacheReadTokens = usage.cache_read_input_tokens ?? 0;
2325
+ const reasoningTokens = usage.output_tokens_details?.thinking_tokens ?? void 0;
2316
2326
  let inputTokens;
2317
2327
  let outputTokens;
2318
- const servedByFallback = (_e = usage.iterations) == null ? void 0 : _e.some(
2328
+ const servedByFallback = usage.iterations?.some(
2319
2329
  (iter) => iter.type === "fallback_message"
2320
2330
  );
2321
2331
  if (usage.iterations && usage.iterations.length > 0 && !servedByFallback) {
@@ -2352,7 +2362,7 @@ function convertAnthropicUsage({
2352
2362
  text: reasoningTokens == null ? void 0 : outputTokens - reasoningTokens,
2353
2363
  reasoning: reasoningTokens
2354
2364
  },
2355
- raw: rawUsage != null ? rawUsage : usage
2365
+ raw: rawUsage ?? usage
2356
2366
  };
2357
2367
  }
2358
2368
 
@@ -2525,15 +2535,14 @@ var codeExecution_20250825 = (args = {}) => {
2525
2535
  return experimental_toolCaller(factory10(args), {
2526
2536
  type: "provider",
2527
2537
  prepareProviderOptions: (providerOptions) => {
2528
- var _a;
2529
- const anthropicOptions = providerOptions == null ? void 0 : providerOptions.anthropic;
2538
+ const anthropicOptions = providerOptions?.anthropic;
2530
2539
  return {
2531
2540
  ...providerOptions,
2532
2541
  anthropic: {
2533
2542
  ...anthropicOptions,
2534
2543
  allowedCallers: [
2535
2544
  .../* @__PURE__ */ new Set([
2536
- ...(_a = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers) != null ? _a : [],
2545
+ ...anthropicOptions?.allowedCallers ?? [],
2537
2546
  "code_execution_20250825"
2538
2547
  ])
2539
2548
  ]
@@ -2665,15 +2674,14 @@ var codeExecution_20260120 = (args = {}) => {
2665
2674
  return experimental_toolCaller2(factory11(args), {
2666
2675
  type: "provider",
2667
2676
  prepareProviderOptions: (providerOptions) => {
2668
- var _a;
2669
- const anthropicOptions = providerOptions == null ? void 0 : providerOptions.anthropic;
2677
+ const anthropicOptions = providerOptions?.anthropic;
2670
2678
  return {
2671
2679
  ...providerOptions,
2672
2680
  anthropic: {
2673
2681
  ...anthropicOptions,
2674
2682
  allowedCallers: [
2675
2683
  .../* @__PURE__ */ new Set([
2676
- ...(_a = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers) != null ? _a : [],
2684
+ ...anthropicOptions?.allowedCallers ?? [],
2677
2685
  "code_execution_20260120"
2678
2686
  ])
2679
2687
  ]
@@ -2745,8 +2753,8 @@ function extractErrorValue(value) {
2745
2753
  } else if (typeof value === "object" && value !== null) {
2746
2754
  return value;
2747
2755
  }
2748
- } catch (e) {
2749
- const extractedErrorCode = value == null ? void 0 : value.errorCode;
2756
+ } catch {
2757
+ const extractedErrorCode = value?.errorCode;
2750
2758
  return {
2751
2759
  errorCode: typeof extractedErrorCode === "string" ? extractedErrorCode : "unavailable"
2752
2760
  };
@@ -2761,29 +2769,26 @@ async function convertToAnthropicPrompt({
2761
2769
  toolNameMapping,
2762
2770
  toolsetNames = {}
2763
2771
  }) {
2764
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
2765
2772
  const betas = /* @__PURE__ */ new Set();
2766
2773
  const blocks = groupIntoBlocks(prompt);
2767
2774
  const validator = cacheControlValidator || new CacheControlValidator();
2768
2775
  let system = void 0;
2769
2776
  const messages = [];
2770
2777
  async function shouldEnableCitations(providerMetadata) {
2771
- var _a2, _b2;
2772
2778
  const anthropicOptions = await parseProviderOptions({
2773
2779
  provider: "anthropic",
2774
2780
  providerOptions: providerMetadata,
2775
2781
  schema: anthropicFilePartProviderOptions
2776
2782
  });
2777
- return (_b2 = (_a2 = anthropicOptions == null ? void 0 : anthropicOptions.citations) == null ? void 0 : _a2.enabled) != null ? _b2 : false;
2783
+ return anthropicOptions?.citations?.enabled ?? false;
2778
2784
  }
2779
2785
  async function shouldUseContainerUpload(providerMetadata) {
2780
- var _a2;
2781
2786
  const anthropicOptions = await parseProviderOptions({
2782
2787
  provider: "anthropic",
2783
2788
  providerOptions: providerMetadata,
2784
2789
  schema: anthropicFilePartProviderOptions
2785
2790
  });
2786
- return (_a2 = anthropicOptions == null ? void 0 : anthropicOptions.containerUpload) != null ? _a2 : false;
2791
+ return anthropicOptions?.containerUpload ?? false;
2787
2792
  }
2788
2793
  async function getDocumentMetadata(providerMetadata) {
2789
2794
  const anthropicOptions = await parseProviderOptions({
@@ -2792,8 +2797,8 @@ async function convertToAnthropicPrompt({
2792
2797
  schema: anthropicFilePartProviderOptions
2793
2798
  });
2794
2799
  return {
2795
- title: anthropicOptions == null ? void 0 : anthropicOptions.title,
2796
- context: anthropicOptions == null ? void 0 : anthropicOptions.context
2800
+ title: anthropicOptions?.title,
2801
+ context: anthropicOptions?.context
2797
2802
  };
2798
2803
  }
2799
2804
  for (let i = 0; i < blocks.length; i++) {
@@ -2809,9 +2814,9 @@ async function convertToAnthropicPrompt({
2809
2814
  providerOptions,
2810
2815
  schema: anthropicSystemMessageProviderOptions
2811
2816
  });
2812
- const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
2817
+ const toolChanges = systemMessageOptions?.toolChanges ?? [];
2813
2818
  const content = [];
2814
- if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
2819
+ if (text !== "" || toolChanges.length === 0 && systemMessageOptions?.clearAt == null && systemMessageOptions?.effort == null) {
2815
2820
  content.push({
2816
2821
  type: "text",
2817
2822
  text,
@@ -2832,8 +2837,8 @@ async function convertToAnthropicPrompt({
2832
2837
  }
2833
2838
  convertedMessages.push({
2834
2839
  content,
2835
- clearAt: systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt,
2836
- effort: systemMessageOptions == null ? void 0 : systemMessageOptions.effort,
2840
+ clearAt: systemMessageOptions?.clearAt,
2841
+ effort: systemMessageOptions?.effort,
2837
2842
  toolChangeCount: toolChanges.length
2838
2843
  });
2839
2844
  }
@@ -2852,10 +2857,17 @@ async function convertToAnthropicPrompt({
2852
2857
  });
2853
2858
  }
2854
2859
  for (const message of convertedMessages) {
2855
- if (message.clearAt != null || message.effort != null) {
2860
+ if (message.content.length === 0 && message.clearAt == null && message.effort != null) {
2861
+ messages.push({
2862
+ role: "system",
2863
+ content: [],
2864
+ output_config: { effort: message.effort }
2865
+ });
2866
+ betas.add("mid-conversation-output-config-2026-07-01");
2867
+ } else if (message.clearAt != null || message.effort != null) {
2856
2868
  warnings.push({
2857
2869
  type: "other",
2858
- message: "clearAt and effort on the initial system message are not supported by Anthropic. These options have been ignored."
2870
+ 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."
2859
2871
  });
2860
2872
  }
2861
2873
  }
@@ -2897,13 +2909,13 @@ async function convertToAnthropicPrompt({
2897
2909
  for (let j = 0; j < content.length; j++) {
2898
2910
  const part = content[j];
2899
2911
  const isLastPart = j === content.length - 1;
2900
- const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
2912
+ const cacheControl = validator.getCacheControl(part.providerOptions, {
2901
2913
  type: "user message part",
2902
2914
  canCache: true
2903
- })) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
2915
+ }) ?? (isLastPart ? validator.getCacheControl(message.providerOptions, {
2904
2916
  type: "user message",
2905
2917
  canCache: true
2906
- }) : void 0;
2918
+ }) : void 0);
2907
2919
  switch (part.type) {
2908
2920
  case "text": {
2909
2921
  anthropicContent.push({
@@ -2955,7 +2967,7 @@ async function convertToAnthropicPrompt({
2955
2967
  media_type: "text/plain",
2956
2968
  data: part.data.text
2957
2969
  },
2958
- title: (_c = metadata.title) != null ? _c : part.filename,
2970
+ title: metadata.title ?? part.filename,
2959
2971
  ...metadata.context && {
2960
2972
  context: metadata.context
2961
2973
  },
@@ -3000,7 +3012,7 @@ async function convertToAnthropicPrompt({
3000
3012
  media_type: "application/pdf",
3001
3013
  data: convertToBase64(part.data.data)
3002
3014
  },
3003
- title: (_d = metadata.title) != null ? _d : part.filename,
3015
+ title: metadata.title ?? part.filename,
3004
3016
  ...metadata.context && {
3005
3017
  context: metadata.context
3006
3018
  },
@@ -3028,7 +3040,7 @@ async function convertToAnthropicPrompt({
3028
3040
  part.data.data
3029
3041
  )
3030
3042
  },
3031
- title: (_e = metadata.title) != null ? _e : part.filename,
3043
+ title: metadata.title ?? part.filename,
3032
3044
  ...metadata.context && {
3033
3045
  context: metadata.context
3034
3046
  },
@@ -3058,25 +3070,24 @@ async function convertToAnthropicPrompt({
3058
3070
  continue;
3059
3071
  }
3060
3072
  const output = part.output;
3061
- const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_f = output.value.find(
3073
+ const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? output.value.find(
3062
3074
  (contentPart) => contentPart.providerOptions != null
3063
- )) == null ? void 0 : _f.providerOptions : void 0;
3075
+ )?.providerOptions : void 0;
3064
3076
  const isLastPart = i2 === content.length - 1;
3065
- const cacheControl = (_h = (_g = validator.getCacheControl(part.providerOptions, {
3077
+ const cacheControl = validator.getCacheControl(part.providerOptions, {
3066
3078
  type: "tool result part",
3067
3079
  canCache: true
3068
- })) != null ? _g : validator.getCacheControl(outputProviderOptions, {
3080
+ }) ?? validator.getCacheControl(outputProviderOptions, {
3069
3081
  type: "tool result output",
3070
3082
  canCache: true
3071
- })) != null ? _h : isLastPart ? validator.getCacheControl(message.providerOptions, {
3083
+ }) ?? (isLastPart ? validator.getCacheControl(message.providerOptions, {
3072
3084
  type: "tool result message",
3073
3085
  canCache: true
3074
- }) : void 0;
3086
+ }) : void 0);
3075
3087
  let contentValue;
3076
3088
  switch (output.type) {
3077
3089
  case "content":
3078
3090
  contentValue = output.value.map((contentPart) => {
3079
- var _a2;
3080
3091
  switch (contentPart.type) {
3081
3092
  case "text":
3082
3093
  return {
@@ -3146,8 +3157,8 @@ async function convertToAnthropicPrompt({
3146
3157
  return void 0;
3147
3158
  }
3148
3159
  case "custom": {
3149
- const anthropicOptions = (_a2 = contentPart.providerOptions) == null ? void 0 : _a2.anthropic;
3150
- if ((anthropicOptions == null ? void 0 : anthropicOptions.type) === "tool-reference") {
3160
+ const anthropicOptions = contentPart.providerOptions?.anthropic;
3161
+ if (anthropicOptions?.type === "tool-reference") {
3151
3162
  return {
3152
3163
  type: "tool_reference",
3153
3164
  tool_name: anthropicOptions.toolName
@@ -3174,7 +3185,7 @@ async function convertToAnthropicPrompt({
3174
3185
  contentValue = output.value;
3175
3186
  break;
3176
3187
  case "execution-denied":
3177
- contentValue = (_i = output.reason) != null ? _i : "Tool call execution denied.";
3188
+ contentValue = output.reason ?? "Tool call execution denied.";
3178
3189
  break;
3179
3190
  case "json":
3180
3191
  case "error-json":
@@ -3217,23 +3228,29 @@ async function convertToAnthropicPrompt({
3217
3228
  for (let k = 0; k < content.length; k++) {
3218
3229
  const part = content[k];
3219
3230
  const isLastContentPart = k === content.length - 1;
3220
- const cacheControl = (_j = validator.getCacheControl(part.providerOptions, {
3231
+ const cacheControl = validator.getCacheControl(part.providerOptions, {
3221
3232
  type: "assistant message part",
3222
3233
  canCache: true
3223
- })) != null ? _j : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
3234
+ }) ?? (isLastContentPart ? validator.getCacheControl(message.providerOptions, {
3224
3235
  type: "assistant message",
3225
3236
  canCache: true
3226
- }) : void 0;
3237
+ }) : void 0);
3227
3238
  switch (part.type) {
3228
3239
  case "text": {
3229
- const textMetadata = (_k = part.providerOptions) == null ? void 0 : _k.anthropic;
3230
- if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
3240
+ const textMetadata = part.providerOptions?.anthropic;
3241
+ if (textMetadata?.type === "compaction") {
3231
3242
  if (part.text === "") {
3232
3243
  break;
3233
3244
  }
3245
+ if (typeof textMetadata.signature === "string") {
3246
+ betas.add("compact-2026-09-04");
3247
+ }
3234
3248
  anthropicContent.push({
3235
3249
  type: "compaction",
3236
3250
  content: part.text,
3251
+ ...typeof textMetadata.signature === "string" && {
3252
+ signature: textMetadata.signature
3253
+ },
3237
3254
  cache_control: cacheControl
3238
3255
  });
3239
3256
  } else {
@@ -3245,7 +3262,7 @@ async function convertToAnthropicPrompt({
3245
3262
  // in pre-filled assistant responses
3246
3263
  isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
3247
3264
  ),
3248
- ...(textMetadata == null ? void 0 : textMetadata.citations) != null && {
3265
+ ...textMetadata?.citations != null && {
3249
3266
  citations: textMetadata.citations
3250
3267
  },
3251
3268
  cache_control: cacheControl
@@ -3306,10 +3323,10 @@ async function convertToAnthropicPrompt({
3306
3323
  const providerToolName = toolNameMapping.toProviderToolName(
3307
3324
  part.toolName
3308
3325
  );
3309
- const isMcpToolUse = ((_m = (_l = part.providerOptions) == null ? void 0 : _l.anthropic) == null ? void 0 : _m.type) === "mcp-tool-use";
3326
+ const isMcpToolUse = part.providerOptions?.anthropic?.type === "mcp-tool-use";
3310
3327
  if (isMcpToolUse) {
3311
3328
  mcpToolUseIds.add(part.toolCallId);
3312
- const serverName = (_o = (_n = part.providerOptions) == null ? void 0 : _n.anthropic) == null ? void 0 : _o.serverName;
3329
+ const serverName = part.providerOptions?.anthropic?.serverName;
3313
3330
  if (serverName == null || typeof serverName !== "string") {
3314
3331
  warnings.push({
3315
3332
  type: "other",
@@ -3459,7 +3476,7 @@ async function convertToAnthropicPrompt({
3459
3476
  } else if (typeof output.value === "object" && output.value !== null) {
3460
3477
  errorInfo = output.value;
3461
3478
  }
3462
- } catch (e) {
3479
+ } catch {
3463
3480
  }
3464
3481
  if (errorInfo.type === "code_execution_tool_result_error") {
3465
3482
  anthropicContent.push({
@@ -3467,7 +3484,7 @@ async function convertToAnthropicPrompt({
3467
3484
  tool_use_id: part.toolCallId,
3468
3485
  content: {
3469
3486
  type: "code_execution_tool_result_error",
3470
- error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
3487
+ error_code: errorInfo.errorCode ?? "unknown"
3471
3488
  },
3472
3489
  cache_control: cacheControl
3473
3490
  });
@@ -3478,7 +3495,7 @@ async function convertToAnthropicPrompt({
3478
3495
  cache_control: cacheControl,
3479
3496
  content: {
3480
3497
  type: "bash_code_execution_tool_result_error",
3481
- error_code: (_q = errorInfo.errorCode) != null ? _q : "unknown"
3498
+ error_code: errorInfo.errorCode ?? "unknown"
3482
3499
  }
3483
3500
  });
3484
3501
  }
@@ -3511,7 +3528,7 @@ async function convertToAnthropicPrompt({
3511
3528
  stdout: codeExecutionOutput.stdout,
3512
3529
  stderr: codeExecutionOutput.stderr,
3513
3530
  return_code: codeExecutionOutput.return_code,
3514
- content: (_r = codeExecutionOutput.content) != null ? _r : []
3531
+ content: codeExecutionOutput.content ?? []
3515
3532
  },
3516
3533
  cache_control: cacheControl
3517
3534
  });
@@ -3529,7 +3546,7 @@ async function convertToAnthropicPrompt({
3529
3546
  encrypted_stdout: codeExecutionOutput.encrypted_stdout,
3530
3547
  stderr: codeExecutionOutput.stderr,
3531
3548
  return_code: codeExecutionOutput.return_code,
3532
- content: (_s = codeExecutionOutput.content) != null ? _s : []
3549
+ content: codeExecutionOutput.content ?? []
3533
3550
  },
3534
3551
  cache_control: cacheControl
3535
3552
  });
@@ -3548,7 +3565,7 @@ async function convertToAnthropicPrompt({
3548
3565
  stdout: codeExecutionOutput.stdout,
3549
3566
  stderr: codeExecutionOutput.stderr,
3550
3567
  return_code: codeExecutionOutput.return_code,
3551
- content: (_t = codeExecutionOutput.content) != null ? _t : []
3568
+ content: codeExecutionOutput.content ?? []
3552
3569
  },
3553
3570
  cache_control: cacheControl
3554
3571
  });
@@ -3586,7 +3603,7 @@ async function convertToAnthropicPrompt({
3586
3603
  tool_use_id: part.toolCallId,
3587
3604
  content: {
3588
3605
  type: "web_fetch_tool_result_error",
3589
- error_code: (_u = extractErrorValue(output.value).errorCode) != null ? _u : "unavailable"
3606
+ error_code: extractErrorValue(output.value).errorCode ?? "unavailable"
3590
3607
  },
3591
3608
  ...caller && { caller },
3592
3609
  cache_control: cacheControl
@@ -3635,7 +3652,7 @@ async function convertToAnthropicPrompt({
3635
3652
  tool_use_id: part.toolCallId,
3636
3653
  content: {
3637
3654
  type: "web_search_tool_result_error",
3638
- error_code: (_v = extractErrorValue(output.value).errorCode) != null ? _v : "unavailable"
3655
+ error_code: extractErrorValue(output.value).errorCode ?? "unavailable"
3639
3656
  },
3640
3657
  ...caller && { caller },
3641
3658
  cache_control: cacheControl
@@ -3783,7 +3800,7 @@ function groupIntoBlocks(prompt) {
3783
3800
  const { role } = message;
3784
3801
  switch (role) {
3785
3802
  case "system": {
3786
- if ((currentBlock == null ? void 0 : currentBlock.type) !== "system") {
3803
+ if (currentBlock?.type !== "system") {
3787
3804
  currentBlock = { type: "system", messages: [] };
3788
3805
  blocks.push(currentBlock);
3789
3806
  }
@@ -3791,7 +3808,7 @@ function groupIntoBlocks(prompt) {
3791
3808
  break;
3792
3809
  }
3793
3810
  case "assistant": {
3794
- if ((currentBlock == null ? void 0 : currentBlock.type) !== "assistant") {
3811
+ if (currentBlock?.type !== "assistant") {
3795
3812
  currentBlock = { type: "assistant", messages: [] };
3796
3813
  blocks.push(currentBlock);
3797
3814
  }
@@ -3799,7 +3816,7 @@ function groupIntoBlocks(prompt) {
3799
3816
  break;
3800
3817
  }
3801
3818
  case "user": {
3802
- if ((currentBlock == null ? void 0 : currentBlock.type) !== "user") {
3819
+ if (currentBlock?.type !== "user") {
3803
3820
  currentBlock = { type: "user", messages: [] };
3804
3821
  blocks.push(currentBlock);
3805
3822
  }
@@ -3807,7 +3824,7 @@ function groupIntoBlocks(prompt) {
3807
3824
  break;
3808
3825
  }
3809
3826
  case "tool": {
3810
- if ((currentBlock == null ? void 0 : currentBlock.type) !== "user") {
3827
+ if (currentBlock?.type !== "user") {
3811
3828
  currentBlock = { type: "user", messages: [] };
3812
3829
  blocks.push(currentBlock);
3813
3830
  }
@@ -3848,24 +3865,22 @@ function getAnthropicToolsetName({
3848
3865
  providerOptions,
3849
3866
  toolsetNames
3850
3867
  }) {
3851
- var _a;
3852
3868
  const fromTools = toolsetNames[toolName];
3853
3869
  if (fromTools != null) {
3854
3870
  return fromTools;
3855
3871
  }
3856
- const fromMetadata = (_a = providerOptions == null ? void 0 : providerOptions.anthropic) == null ? void 0 : _a.toolsetName;
3872
+ const fromMetadata = providerOptions?.anthropic?.toolsetName;
3857
3873
  return typeof fromMetadata === "string" ? fromMetadata : void 0;
3858
3874
  }
3859
3875
  function getAnthropicCaller(providerOptions) {
3860
- var _a;
3861
- const caller = (_a = providerOptions == null ? void 0 : providerOptions.anthropic) == null ? void 0 : _a.caller;
3862
- if (((caller == null ? void 0 : caller.type) === "code_execution_20250825" || (caller == null ? void 0 : caller.type) === "code_execution_20260120") && caller.toolId) {
3876
+ const caller = providerOptions?.anthropic?.caller;
3877
+ if ((caller?.type === "code_execution_20250825" || caller?.type === "code_execution_20260120") && caller.toolId) {
3863
3878
  return {
3864
3879
  type: caller.type,
3865
3880
  tool_id: caller.toolId
3866
3881
  };
3867
3882
  }
3868
- return (caller == null ? void 0 : caller.type) === "direct" ? { type: "direct" } : void 0;
3883
+ return caller?.type === "direct" ? { type: "direct" } : void 0;
3869
3884
  }
3870
3885
  function toAnthropicToolInput(input) {
3871
3886
  return typeof input === "object" && input !== null && !Array.isArray(input) ? input : { rawInvalidInput: input };
@@ -4041,14 +4056,13 @@ function formatConstraintValue(value) {
4041
4056
 
4042
4057
  // src/anthropic-language-model.ts
4043
4058
  function createAnthropicStreamError(error) {
4044
- var _a, _b, _c;
4045
4059
  const inferredMetadata = getAnthropicStreamErrorMetadata(error.type);
4046
4060
  return createProviderStreamError({
4047
4061
  message: error.message,
4048
4062
  type: error.type,
4049
- code: (_a = error.code) != null ? _a : void 0,
4050
- statusCode: (_b = error.statusCode) != null ? _b : inferredMetadata.statusCode,
4051
- isRetryable: (_c = error.isRetryable) != null ? _c : inferredMetadata.isRetryable,
4063
+ code: error.code ?? void 0,
4064
+ statusCode: error.statusCode ?? inferredMetadata.statusCode,
4065
+ isRetryable: error.isRetryable ?? inferredMetadata.isRetryable,
4052
4066
  data: "data" in error ? error.data : error
4053
4067
  });
4054
4068
  }
@@ -4076,14 +4090,13 @@ function getAnthropicStreamErrorMetadata(type) {
4076
4090
  }
4077
4091
  }
4078
4092
  function createCitationSource(citation, citationDocuments, generateId2) {
4079
- var _a, _b;
4080
4093
  if (citation.type === "web_search_result_location") {
4081
4094
  return {
4082
4095
  type: "source",
4083
4096
  sourceType: "url",
4084
4097
  id: generateId2(),
4085
4098
  url: citation.url,
4086
- title: (_a = citation.title) != null ? _a : void 0,
4099
+ title: citation.title ?? void 0,
4087
4100
  providerMetadata: {
4088
4101
  anthropic: {
4089
4102
  citedText: citation.cited_text,
@@ -4104,7 +4117,7 @@ function createCitationSource(citation, citationDocuments, generateId2) {
4104
4117
  sourceType: "document",
4105
4118
  id: generateId2(),
4106
4119
  mediaType: documentInfo.mediaType,
4107
- title: (_b = citation.document_title) != null ? _b : documentInfo.title,
4120
+ title: citation.document_title ?? documentInfo.title,
4108
4121
  filename: documentInfo.filename,
4109
4122
  providerMetadata: {
4110
4123
  anthropic: citation.type === "page_location" ? {
@@ -4131,7 +4144,7 @@ function getAnthropicCallerMetadata(caller) {
4131
4144
  }
4132
4145
  function getAnthropicToolsetNames(tools) {
4133
4146
  const toolsetNames = {};
4134
- for (const tool of tools != null ? tools : []) {
4147
+ for (const tool of tools ?? []) {
4135
4148
  if (tool.type === "provider" && tool.id === "anthropic.computer_toolset_20260801") {
4136
4149
  toolsetNames[tool.name] = "computer";
4137
4150
  }
@@ -4154,10 +4167,9 @@ function getProviderOptionsName(provider) {
4154
4167
  var AnthropicLanguageModel = class _AnthropicLanguageModel {
4155
4168
  constructor(modelId, config) {
4156
4169
  this.specificationVersion = "v4";
4157
- var _a;
4158
4170
  this.modelId = modelId;
4159
4171
  this.config = config;
4160
- this.generateId = (_a = config.generateId) != null ? _a : generateId;
4172
+ this.generateId = config.generateId ?? generateId;
4161
4173
  }
4162
4174
  static [WORKFLOW_SERIALIZE](model) {
4163
4175
  return serializeModelOptions({
@@ -4175,8 +4187,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4175
4187
  return this.config.provider;
4176
4188
  }
4177
4189
  get supportedUrls() {
4178
- var _a, _b, _c;
4179
- return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
4190
+ return this.config.supportedUrls?.() ?? {};
4180
4191
  }
4181
4192
  static async prepareRequest({
4182
4193
  modelId,
@@ -4200,7 +4211,6 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4200
4211
  stream
4201
4212
  }
4202
4213
  }) {
4203
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
4204
4214
  const warnings = [];
4205
4215
  if (frequencyPenalty != null) {
4206
4216
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -4226,7 +4236,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4226
4236
  });
4227
4237
  temperature = 0;
4228
4238
  }
4229
- if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
4239
+ if (responseFormat?.type === "json") {
4230
4240
  if (responseFormat.schema == null) {
4231
4241
  warnings.push({
4232
4242
  type: "unsupported",
@@ -4249,8 +4259,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4249
4259
  const usedCustomProviderKey = customProviderOptions != null;
4250
4260
  const anthropicOptions = Object.assign(
4251
4261
  {},
4252
- canonicalOptions != null ? canonicalOptions : {},
4253
- customProviderOptions != null ? customProviderOptions : {}
4262
+ canonicalOptions ?? {},
4263
+ customProviderOptions ?? {}
4254
4264
  );
4255
4265
  const {
4256
4266
  maxOutputTokens: maxOutputTokensForModel,
@@ -4297,11 +4307,11 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4297
4307
  }
4298
4308
  }
4299
4309
  const isAnthropicModel = isKnownModel || modelId.includes("claude-");
4300
- const supportsStructuredOutput = ((_a = config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
4301
- const supportsStrictTools = ((_b = config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
4302
- const structureOutputMode = (_c = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _c : "auto";
4310
+ const supportsStructuredOutput = (config.supportsNativeStructuredOutput ?? true) && modelSupportsStructuredOutput;
4311
+ const supportsStrictTools = (config.supportsStrictTools ?? true) && modelSupportsStructuredOutput;
4312
+ const structureOutputMode = anthropicOptions?.structuredOutputMode ?? "auto";
4303
4313
  let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
4304
- if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
4314
+ if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && responseFormat?.type === "json" && responseFormat.schema != null) {
4305
4315
  warnings.push({
4306
4316
  type: "unsupported",
4307
4317
  feature: "providerOptions.anthropic.structuredOutputMode",
@@ -4309,20 +4319,27 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4309
4319
  });
4310
4320
  useStructuredOutput = true;
4311
4321
  }
4312
- const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
4322
+ const jsonResponseTool = responseFormat?.type === "json" && responseFormat.schema != null && !useStructuredOutput ? {
4313
4323
  type: "function",
4314
4324
  name: "json",
4315
4325
  description: "Respond with a JSON object.",
4316
4326
  inputSchema: responseFormat.schema
4317
4327
  } : void 0;
4318
- if (jsonResponseTool != null && (anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse) === false) {
4328
+ if (jsonResponseTool != null && anthropicOptions?.disableParallelToolUse === false) {
4319
4329
  warnings.push({
4320
4330
  type: "unsupported",
4321
4331
  feature: "providerOptions.anthropic.disableParallelToolUse",
4322
4332
  details: "`disableParallelToolUse: false` is ignored when using the JSON response tool. Parallel tool use is disabled to ensure a single coherent JSON tool call."
4323
4333
  });
4324
4334
  }
4325
- const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
4335
+ const contextManagement = anthropicOptions?.contextManagement;
4336
+ const compaction = anthropicOptions?.compaction;
4337
+ if (contextManagement != null && compaction != null) {
4338
+ throw new InvalidArgumentError({
4339
+ argument: "providerOptions",
4340
+ message: "Anthropic provider options `compaction` and `contextManagement` cannot be used together."
4341
+ });
4342
+ }
4326
4343
  const cacheControlValidator = new CacheControlValidator();
4327
4344
  const toolNameMapping = createToolNameMapping({
4328
4345
  tools,
@@ -4355,13 +4372,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4355
4372
  const toolsetNames = getAnthropicToolsetNames(tools);
4356
4373
  const { prompt: messagesPrompt, betas } = await convertToAnthropicPrompt({
4357
4374
  prompt,
4358
- sendReasoning: (_d = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _d : true,
4375
+ sendReasoning: anthropicOptions?.sendReasoning ?? true,
4359
4376
  warnings,
4360
4377
  cacheControlValidator,
4361
4378
  toolNameMapping,
4362
4379
  toolsetNames
4363
4380
  });
4364
- if (isCustomReasoning(reasoning) && (anthropicOptions == null ? void 0 : anthropicOptions.effort) == null) {
4381
+ if (isCustomReasoning(reasoning) && anthropicOptions?.effort == null) {
4365
4382
  const reasoningConfig = resolveAnthropicReasoningConfig({
4366
4383
  reasoning,
4367
4384
  modelId,
@@ -4375,12 +4392,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4375
4392
  if (anthropicOptions.thinking == null) {
4376
4393
  anthropicOptions.thinking = reasoningConfig.thinking;
4377
4394
  }
4378
- if (reasoningConfig.effort != null && ((_e = anthropicOptions.thinking) == null ? void 0 : _e.type) !== "disabled") {
4395
+ if (reasoningConfig.effort != null && anthropicOptions.thinking?.type !== "disabled") {
4379
4396
  anthropicOptions.effort = reasoningConfig.effort;
4380
4397
  }
4381
4398
  }
4382
4399
  }
4383
- if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
4400
+ if (rejectsThinkingDisabled && anthropicOptions?.thinking != null) {
4384
4401
  const thinking = anthropicOptions.thinking;
4385
4402
  if (thinking.type === "disabled") {
4386
4403
  warnings.push({
@@ -4398,7 +4415,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4398
4415
  anthropicOptions.thinking = { type: "adaptive" };
4399
4416
  }
4400
4417
  }
4401
- if (rejectsThinkingDisabledAboveHighEffort && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
4418
+ if (rejectsThinkingDisabledAboveHighEffort && anthropicOptions?.thinking?.type === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
4402
4419
  warnings.push({
4403
4420
  type: "unsupported",
4404
4421
  feature: "providerOptions.anthropic.effort",
@@ -4406,13 +4423,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4406
4423
  });
4407
4424
  anthropicOptions.effort = "high";
4408
4425
  }
4409
- const thinkingType = (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.type;
4426
+ const thinkingType = anthropicOptions?.thinking?.type;
4410
4427
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
4411
- const thinkingBlockBinding = (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null && "blockBinding" in anthropicOptions.thinking ? anthropicOptions.thinking.blockBinding : void 0;
4428
+ const thinkingBlockBinding = anthropicOptions?.thinking != null && "blockBinding" in anthropicOptions.thinking ? anthropicOptions.thinking.blockBinding : void 0;
4412
4429
  const sendThinking = isThinking || thinkingType === "disabled" || thinkingBlockBinding != null;
4413
- let thinkingBudget = thinkingType === "enabled" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.budgetTokens : void 0;
4414
- const thinkingDisplay = thinkingType === "adaptive" ? (_i = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _i.display : void 0;
4415
- const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
4430
+ let thinkingBudget = thinkingType === "enabled" ? anthropicOptions?.thinking?.budgetTokens : void 0;
4431
+ const thinkingDisplay = thinkingType === "adaptive" ? anthropicOptions?.thinking?.display : void 0;
4432
+ const maxTokens = maxOutputTokens ?? maxOutputTokensForModel;
4416
4433
  const baseArgs = {
4417
4434
  // model id:
4418
4435
  model: modelId,
@@ -4435,12 +4452,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4435
4452
  }
4436
4453
  }
4437
4454
  },
4438
- ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
4455
+ ...(anthropicOptions?.effort || anthropicOptions?.taskBudget || useStructuredOutput && responseFormat?.type === "json" && responseFormat.schema != null) && {
4439
4456
  output_config: {
4440
- ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
4457
+ ...anthropicOptions?.effort && {
4441
4458
  effort: anthropicOptions.effort
4442
4459
  },
4443
- ...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && {
4460
+ ...anthropicOptions?.taskBudget && {
4444
4461
  task_budget: {
4445
4462
  type: anthropicOptions.taskBudget.type,
4446
4463
  total: anthropicOptions.taskBudget.total,
@@ -4449,7 +4466,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4449
4466
  }
4450
4467
  }
4451
4468
  },
4452
- ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
4469
+ ...useStructuredOutput && responseFormat?.type === "json" && responseFormat.schema != null && {
4453
4470
  format: {
4454
4471
  type: "json_schema",
4455
4472
  schema: sanitizeJsonSchema(responseFormat.schema)
@@ -4457,26 +4474,26 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4457
4474
  }
4458
4475
  }
4459
4476
  },
4460
- ...(anthropicOptions == null ? void 0 : anthropicOptions.speed) && {
4477
+ ...anthropicOptions?.speed && {
4461
4478
  speed: anthropicOptions.speed
4462
4479
  },
4463
- ...(anthropicOptions == null ? void 0 : anthropicOptions.serviceTier) && {
4480
+ ...anthropicOptions?.serviceTier && {
4464
4481
  service_tier: anthropicOptions.serviceTier
4465
4482
  },
4466
- ...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
4483
+ ...anthropicOptions?.inferenceGeo && {
4467
4484
  inference_geo: anthropicOptions.inferenceGeo
4468
4485
  },
4469
- ...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) != null && (anthropicOptions.fallbacks === "default" || anthropicOptions.fallbacks.length > 0) && {
4486
+ ...anthropicOptions?.fallbacks != null && (anthropicOptions.fallbacks === "default" || anthropicOptions.fallbacks.length > 0) && {
4470
4487
  fallbacks: anthropicOptions.fallbacks
4471
4488
  },
4472
- ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
4489
+ ...anthropicOptions?.cacheControl && {
4473
4490
  cache_control: anthropicOptions.cacheControl
4474
4491
  },
4475
- ...((_j = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _j.userId) != null && {
4492
+ ...anthropicOptions?.metadata?.userId != null && {
4476
4493
  metadata: { user_id: anthropicOptions.metadata.userId }
4477
4494
  },
4478
4495
  // mcp servers:
4479
- ...(anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0 && {
4496
+ ...anthropicOptions?.mcpServers && anthropicOptions.mcpServers.length > 0 && {
4480
4497
  mcp_servers: anthropicOptions.mcpServers.map((server) => ({
4481
4498
  type: server.type,
4482
4499
  name: server.name,
@@ -4489,7 +4506,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4489
4506
  }))
4490
4507
  },
4491
4508
  // container: For programmatic tool calling (just an ID string) or agent skills (object with id and skills)
4492
- ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
4509
+ ...anthropicOptions?.container && {
4493
4510
  container: anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0 ? (
4494
4511
  // Object format when skills are provided (agent skills feature)
4495
4512
  {
@@ -4511,7 +4528,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4511
4528
  // prompt:
4512
4529
  system: messagesPrompt.system,
4513
4530
  messages: messagesPrompt.messages,
4514
- ...(anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0 && {
4531
+ ...anthropicOptions?.safeguards && anthropicOptions.safeguards.length > 0 && {
4515
4532
  safeguards: anthropicOptions.safeguards.map((safeguard) => ({
4516
4533
  type: safeguard.type,
4517
4534
  ...safeguard.classifierContext !== void 0 && {
@@ -4519,6 +4536,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4519
4536
  }
4520
4537
  }))
4521
4538
  },
4539
+ ...compaction && {
4540
+ compaction: {
4541
+ type: compaction.type,
4542
+ ...compaction.instructions !== void 0 && {
4543
+ instructions: compaction.instructions
4544
+ }
4545
+ }
4546
+ },
4522
4547
  ...contextManagement && {
4523
4548
  context_management: {
4524
4549
  edits: contextManagement.edits.map((edit) => {
@@ -4607,7 +4632,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4607
4632
  details: "topP is not supported when thinking is enabled"
4608
4633
  });
4609
4634
  }
4610
- baseArgs.max_tokens = maxTokens + (thinkingBudget != null ? thinkingBudget : 0);
4635
+ baseArgs.max_tokens = maxTokens + (thinkingBudget ?? 0);
4611
4636
  } else {
4612
4637
  if (isAnthropicModel && topP != null && temperature != null) {
4613
4638
  warnings.push({
@@ -4628,35 +4653,38 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4628
4653
  }
4629
4654
  baseArgs.max_tokens = maxOutputTokensForModel;
4630
4655
  }
4631
- if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
4656
+ if (anthropicOptions?.mcpServers && anthropicOptions.mcpServers.length > 0) {
4632
4657
  betas.add("mcp-client-2025-04-04");
4633
4658
  }
4634
- if ((anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0) {
4659
+ if (anthropicOptions?.safeguards && anthropicOptions.safeguards.length > 0) {
4635
4660
  betas.add("dangerous-tool-use-2026-09-03");
4636
4661
  }
4662
+ if (compaction) {
4663
+ betas.add("compact-2026-09-04");
4664
+ }
4637
4665
  if (contextManagement) {
4638
4666
  betas.add("context-management-2025-06-27");
4639
4667
  if (contextManagement.edits.some((e) => e.type === "compact_20260112")) {
4640
4668
  betas.add("compact-2026-01-12");
4641
4669
  }
4642
4670
  }
4643
- if ((anthropicOptions == null ? void 0 : anthropicOptions.container) && anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0) {
4671
+ if (anthropicOptions?.container && anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0) {
4644
4672
  betas.add("code-execution-2025-08-25");
4645
4673
  betas.add("skills-2025-10-02");
4646
4674
  betas.add("files-api-2025-04-14");
4647
- if (!(tools == null ? void 0 : tools.some(
4675
+ if (!tools?.some(
4648
4676
  (tool) => tool.type === "provider" && (tool.id === "anthropic.code_execution_20250825" || tool.id === "anthropic.code_execution_20260120")
4649
- ))) {
4677
+ )) {
4650
4678
  warnings.push({
4651
4679
  type: "other",
4652
4680
  message: "code execution tool is required when using skills"
4653
4681
  });
4654
4682
  }
4655
4683
  }
4656
- if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
4684
+ if (anthropicOptions?.taskBudget) {
4657
4685
  betas.add("task-budgets-2026-03-13");
4658
4686
  }
4659
- if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
4687
+ if (anthropicOptions?.speed === "fast") {
4660
4688
  betas.add("fast-mode-2026-02-01");
4661
4689
  }
4662
4690
  if (thinkingDisplay === "updates") {
@@ -4665,12 +4693,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4665
4693
  if (thinkingBlockBinding != null) {
4666
4694
  betas.add("thinking-binding-controls-2026-08-01");
4667
4695
  }
4668
- if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) === "default") {
4696
+ if (anthropicOptions?.fallbacks === "default") {
4669
4697
  betas.add("server-side-fallback-2026-07-01");
4670
- } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
4698
+ } else if (anthropicOptions?.fallbacks && anthropicOptions.fallbacks.length > 0) {
4671
4699
  betas.add("server-side-fallback-2026-06-01");
4672
4700
  }
4673
- const defaultEagerInputStreaming = stream && ((_k = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _k : true);
4701
+ const defaultEagerInputStreaming = stream && (anthropicOptions?.toolStreaming ?? true);
4674
4702
  const {
4675
4703
  tools: anthropicTools2,
4676
4704
  toolChoice: anthropicToolChoice,
@@ -4678,7 +4706,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4678
4706
  betas: toolsBetas
4679
4707
  } = await prepareTools(
4680
4708
  jsonResponseTool != null ? {
4681
- tools: [...tools != null ? tools : [], jsonResponseTool],
4709
+ tools: [...tools ?? [], jsonResponseTool],
4682
4710
  toolChoice: { type: "required" },
4683
4711
  disableParallelToolUse: true,
4684
4712
  cacheControlValidator,
@@ -4687,9 +4715,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4687
4715
  defaultEagerInputStreaming,
4688
4716
  rejectsForcedToolUse
4689
4717
  } : {
4690
- tools: tools != null ? tools : [],
4718
+ tools: tools ?? [],
4691
4719
  toolChoice,
4692
- disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
4720
+ disableParallelToolUse: anthropicOptions?.disableParallelToolUse,
4693
4721
  cacheControlValidator,
4694
4722
  supportsStructuredOutput,
4695
4723
  supportsStrictTools,
@@ -4711,7 +4739,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4711
4739
  ...betas,
4712
4740
  ...toolsBetas,
4713
4741
  ...userSuppliedBetas,
4714
- ...(_l = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _l : []
4742
+ ...anthropicOptions?.anthropicBeta ?? []
4715
4743
  ]),
4716
4744
  usesJsonResponseTool: jsonResponseTool != null,
4717
4745
  toolNameMapping,
@@ -4737,10 +4765,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4737
4765
  );
4738
4766
  }
4739
4767
  async getBetasFromHeaders(requestHeaders) {
4740
- var _a, _b;
4741
4768
  const configHeaders = this.config.headers ? await resolve(this.config.headers) : void 0;
4742
- const configBetaHeader = (_a = configHeaders == null ? void 0 : configHeaders["anthropic-beta"]) != null ? _a : "";
4743
- const requestBetaHeader = (_b = requestHeaders == null ? void 0 : requestHeaders["anthropic-beta"]) != null ? _b : "";
4769
+ const configBetaHeader = configHeaders?.["anthropic-beta"] ?? "";
4770
+ const requestBetaHeader = requestHeaders?.["anthropic-beta"] ?? "";
4744
4771
  return new Set(
4745
4772
  [
4746
4773
  ...configBetaHeader.toLowerCase().split(","),
@@ -4749,38 +4776,33 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4749
4776
  );
4750
4777
  }
4751
4778
  buildRequestUrl(isStreaming) {
4752
- var _a, _b, _c;
4753
- return (_c = (_b = (_a = this.config).buildRequestUrl) == null ? void 0 : _b.call(_a, this.config.baseURL, isStreaming)) != null ? _c : `${this.config.baseURL}/messages`;
4779
+ return this.config.buildRequestUrl?.(this.config.baseURL, isStreaming) ?? `${this.config.baseURL}/messages`;
4754
4780
  }
4755
4781
  transformRequestBody(args, betas) {
4756
- var _a, _b, _c;
4757
- return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args, betas)) != null ? _c : args;
4782
+ return this.config.transformRequestBody?.(args, betas) ?? args;
4758
4783
  }
4759
4784
  extractCitationDocuments(prompt) {
4760
4785
  const isCitationPart = (part) => {
4761
- var _a, _b;
4762
4786
  if (part.type !== "file") {
4763
4787
  return false;
4764
4788
  }
4765
4789
  if (part.mediaType !== "application/pdf" && part.mediaType !== "text/plain") {
4766
4790
  return false;
4767
4791
  }
4768
- const anthropic = (_a = part.providerOptions) == null ? void 0 : _a.anthropic;
4769
- const citationsConfig = anthropic == null ? void 0 : anthropic.citations;
4770
- return (_b = citationsConfig == null ? void 0 : citationsConfig.enabled) != null ? _b : false;
4792
+ const anthropic = part.providerOptions?.anthropic;
4793
+ const citationsConfig = anthropic?.citations;
4794
+ return citationsConfig?.enabled ?? false;
4771
4795
  };
4772
4796
  return prompt.filter((message) => message.role === "user").flatMap((message) => message.content).filter(isCitationPart).map((part) => {
4773
- var _a;
4774
4797
  const filePart = part;
4775
4798
  return {
4776
- title: (_a = filePart.filename) != null ? _a : "Untitled Document",
4799
+ title: filePart.filename ?? "Untitled Document",
4777
4800
  filename: filePart.filename,
4778
4801
  mediaType: filePart.mediaType
4779
4802
  };
4780
4803
  });
4781
4804
  }
4782
4805
  async doGenerate(options) {
4783
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4784
4806
  const {
4785
4807
  args,
4786
4808
  warnings,
@@ -4821,7 +4843,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4821
4843
  switch (part.type) {
4822
4844
  case "text": {
4823
4845
  if (!usesJsonResponseTool) {
4824
- const webSearchCitations = (_a = part.citations) == null ? void 0 : _a.filter(
4846
+ const webSearchCitations = part.citations?.filter(
4825
4847
  (citation) => citation.type === "web_search_result_location"
4826
4848
  );
4827
4849
  content.push({
@@ -4891,7 +4913,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4891
4913
  text: part.content,
4892
4914
  providerMetadata: {
4893
4915
  anthropic: {
4894
- type: "compaction"
4916
+ type: "compaction",
4917
+ ...part.signature != null && {
4918
+ signature: part.signature
4919
+ }
4895
4920
  }
4896
4921
  }
4897
4922
  });
@@ -4919,7 +4944,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4919
4944
  providerMetadata: {
4920
4945
  anthropic: {
4921
4946
  toolsetName: part.toolset_name,
4922
- ...(_b = getAnthropicCallerMetadata(part.caller).providerMetadata) == null ? void 0 : _b.anthropic
4947
+ ...getAnthropicCallerMetadata(part.caller).providerMetadata?.anthropic
4923
4948
  }
4924
4949
  }
4925
4950
  });
@@ -5020,7 +5045,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5020
5045
  case "web_fetch_tool_result": {
5021
5046
  if (part.content.type === "web_fetch_result") {
5022
5047
  citationDocuments.push({
5023
- title: (_c = part.content.content.title) != null ? _c : part.content.url,
5048
+ title: part.content.content.title ?? part.content.url,
5024
5049
  mediaType: part.content.content.source.media_type
5025
5050
  });
5026
5051
  content.push({
@@ -5065,16 +5090,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5065
5090
  type: "tool-result",
5066
5091
  toolCallId: part.tool_use_id,
5067
5092
  toolName: toolNameMapping.toCustomToolName("web_search"),
5068
- result: part.content.map((result) => {
5069
- var _a2;
5070
- return {
5071
- url: result.url,
5072
- ...result.title != null ? { title: result.title } : {},
5073
- pageAge: (_a2 = result.page_age) != null ? _a2 : null,
5074
- encryptedContent: result.encrypted_content,
5075
- type: result.type
5076
- };
5077
- }),
5093
+ result: part.content.map((result) => ({
5094
+ url: result.url,
5095
+ ...result.title != null ? { title: result.title } : {},
5096
+ pageAge: result.page_age ?? null,
5097
+ encryptedContent: result.encrypted_content,
5098
+ type: result.type
5099
+ })),
5078
5100
  ...getAnthropicCallerMetadata(part.caller)
5079
5101
  });
5080
5102
  for (const result of part.content) {
@@ -5086,7 +5108,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5086
5108
  ...result.title != null ? { title: result.title } : {},
5087
5109
  providerMetadata: {
5088
5110
  anthropic: {
5089
- pageAge: (_d = result.page_age) != null ? _d : null
5111
+ pageAge: result.page_age ?? null
5090
5112
  }
5091
5113
  }
5092
5114
  });
@@ -5118,7 +5140,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5118
5140
  stdout: part.content.stdout,
5119
5141
  stderr: part.content.stderr,
5120
5142
  return_code: part.content.return_code,
5121
- content: (_e = part.content.content) != null ? _e : []
5143
+ content: part.content.content ?? []
5122
5144
  }
5123
5145
  });
5124
5146
  } else if (part.content.type === "encrypted_code_execution_result") {
@@ -5131,7 +5153,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5131
5153
  encrypted_stdout: part.content.encrypted_stdout,
5132
5154
  stderr: part.content.stderr,
5133
5155
  return_code: part.content.return_code,
5134
- content: (_f = part.content.content) != null ? _f : []
5156
+ content: part.content.content ?? []
5135
5157
  }
5136
5158
  });
5137
5159
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -5259,23 +5281,22 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5259
5281
  finishReason: response.stop_reason,
5260
5282
  isJsonResponseFromTool
5261
5283
  }),
5262
- raw: (_g = response.stop_reason) != null ? _g : void 0
5284
+ raw: response.stop_reason ?? void 0
5263
5285
  },
5264
5286
  usage: convertAnthropicUsage({ usage: response.usage }),
5265
5287
  request: { body: args },
5266
5288
  response: {
5267
- id: (_h = response.id) != null ? _h : void 0,
5268
- modelId: (_i = response.model) != null ? _i : void 0,
5289
+ id: response.id ?? void 0,
5290
+ modelId: response.model ?? void 0,
5269
5291
  headers: responseHeaders,
5270
5292
  body: rawResponse
5271
5293
  },
5272
5294
  warnings,
5273
5295
  providerMetadata: (() => {
5274
- var _a2, _b2, _c2, _d2;
5275
5296
  const stopDetails = mapAnthropicStopDetails(response.stop_details);
5276
5297
  const anthropicMetadata = {
5277
5298
  usage: response.usage,
5278
- stopSequence: (_a2 = response.stop_sequence) != null ? _a2 : null,
5299
+ stopSequence: response.stop_sequence ?? null,
5279
5300
  ...stopDetails != null ? { stopDetails } : {},
5280
5301
  ...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
5281
5302
  ...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
@@ -5296,15 +5317,15 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5296
5317
  container: response.container ? {
5297
5318
  expiresAt: response.container.expires_at,
5298
5319
  id: response.container.id,
5299
- skills: (_c2 = (_b2 = response.container.skills) == null ? void 0 : _b2.map((skill) => ({
5320
+ skills: response.container.skills?.map((skill) => ({
5300
5321
  type: skill.type,
5301
5322
  skillId: skill.skill_id,
5302
5323
  version: skill.version
5303
- }))) != null ? _c2 : null
5324
+ })) ?? null
5304
5325
  } : null,
5305
- contextManagement: (_d2 = mapAnthropicResponseContextManagement(
5326
+ contextManagement: mapAnthropicResponseContextManagement(
5306
5327
  response.context_management
5307
- )) != null ? _d2 : null
5328
+ ) ?? null
5308
5329
  };
5309
5330
  const providerMetadata = {
5310
5331
  anthropic: anthropicMetadata
@@ -5318,7 +5339,6 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5318
5339
  }
5319
5340
  async doStream(options) {
5320
5341
  "use step";
5321
- var _a, _b, _c, _d;
5322
5342
  const {
5323
5343
  args: body,
5324
5344
  warnings,
@@ -5379,7 +5399,6 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5379
5399
  controller.enqueue({ type: "stream-start", warnings });
5380
5400
  },
5381
5401
  transform(chunk, controller) {
5382
- var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m;
5383
5402
  if (hasInvalidMessageSequence) {
5384
5403
  return;
5385
5404
  }
@@ -5448,10 +5467,20 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5448
5467
  id: String(value.index),
5449
5468
  providerMetadata: {
5450
5469
  anthropic: {
5451
- type: "compaction"
5470
+ type: "compaction",
5471
+ ...part.signature != null && {
5472
+ signature: part.signature
5473
+ }
5452
5474
  }
5453
5475
  }
5454
5476
  });
5477
+ if (part.signature != null && part.content != null && part.content !== "") {
5478
+ controller.enqueue({
5479
+ type: "text-delta",
5480
+ id: String(value.index),
5481
+ delta: part.content
5482
+ });
5483
+ }
5455
5484
  return;
5456
5485
  }
5457
5486
  case "tool_use": {
@@ -5597,7 +5626,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5597
5626
  case "web_fetch_tool_result": {
5598
5627
  if (part.content.type === "web_fetch_result") {
5599
5628
  citationDocuments.push({
5600
- title: (_a2 = part.content.content.title) != null ? _a2 : part.content.url,
5629
+ title: part.content.content.title ?? part.content.url,
5601
5630
  mediaType: part.content.content.source.media_type
5602
5631
  });
5603
5632
  controller.enqueue({
@@ -5642,16 +5671,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5642
5671
  type: "tool-result",
5643
5672
  toolCallId: part.tool_use_id,
5644
5673
  toolName: toolNameMapping.toCustomToolName("web_search"),
5645
- result: part.content.map((result) => {
5646
- var _a3;
5647
- return {
5648
- url: result.url,
5649
- ...result.title != null ? { title: result.title } : {},
5650
- pageAge: (_a3 = result.page_age) != null ? _a3 : null,
5651
- encryptedContent: result.encrypted_content,
5652
- type: result.type
5653
- };
5654
- }),
5674
+ result: part.content.map((result) => ({
5675
+ url: result.url,
5676
+ ...result.title != null ? { title: result.title } : {},
5677
+ pageAge: result.page_age ?? null,
5678
+ encryptedContent: result.encrypted_content,
5679
+ type: result.type
5680
+ })),
5655
5681
  ...getAnthropicCallerMetadata(part.caller)
5656
5682
  });
5657
5683
  for (const result of part.content) {
@@ -5663,7 +5689,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5663
5689
  ...result.title != null ? { title: result.title } : {},
5664
5690
  providerMetadata: {
5665
5691
  anthropic: {
5666
- pageAge: (_b2 = result.page_age) != null ? _b2 : null
5692
+ pageAge: result.page_age ?? null
5667
5693
  }
5668
5694
  }
5669
5695
  });
@@ -5695,7 +5721,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5695
5721
  stdout: part.content.stdout,
5696
5722
  stderr: part.content.stderr,
5697
5723
  return_code: part.content.return_code,
5698
- content: (_c2 = part.content.content) != null ? _c2 : []
5724
+ content: part.content.content ?? []
5699
5725
  }
5700
5726
  });
5701
5727
  } else if (part.content.type === "encrypted_code_execution_result") {
@@ -5708,7 +5734,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5708
5734
  encrypted_stdout: part.content.encrypted_stdout,
5709
5735
  stderr: part.content.stderr,
5710
5736
  return_code: part.content.return_code,
5711
- content: (_d2 = part.content.content) != null ? _d2 : []
5737
+ content: part.content.content ?? []
5712
5738
  }
5713
5739
  });
5714
5740
  } else if (part.content.type === "code_execution_tool_result_error") {
@@ -5892,7 +5918,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5892
5918
  let memberInput = {};
5893
5919
  try {
5894
5920
  memberInput = contentBlock.input === "" ? {} : secureJsonParse2(contentBlock.input);
5895
- } catch (e) {
5921
+ } catch {
5896
5922
  memberInput = void 0;
5897
5923
  }
5898
5924
  contentBlock.input = memberInput === void 0 ? contentBlock.input : JSON.stringify(
@@ -5921,7 +5947,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5921
5947
  ...parsed
5922
5948
  });
5923
5949
  }
5924
- } catch (e) {
5950
+ } catch {
5925
5951
  }
5926
5952
  }
5927
5953
  controller.enqueue({
@@ -6010,7 +6036,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6010
6036
  return;
6011
6037
  }
6012
6038
  if (isJsonResponseFromTool) {
6013
- if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
6039
+ if (contentBlock?.type !== "text") {
6014
6040
  return;
6015
6041
  }
6016
6042
  controller.enqueue({
@@ -6019,7 +6045,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6019
6045
  delta
6020
6046
  });
6021
6047
  } else {
6022
- if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
6048
+ if (contentBlock?.type !== "tool-call") {
6023
6049
  return;
6024
6050
  }
6025
6051
  if (contentBlock.toolset != null) {
@@ -6042,7 +6068,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6042
6068
  case "citations_delta": {
6043
6069
  const citation = value.delta.citation;
6044
6070
  const contentBlock = contentBlocks[value.index];
6045
- if ((contentBlock == null ? void 0 : contentBlock.type) === "text" && citation.type === "web_search_result_location") {
6071
+ if (contentBlock?.type === "text" && citation.type === "web_search_result_location") {
6046
6072
  contentBlock.citations.push(citation);
6047
6073
  }
6048
6074
  const source = createCitationSource(
@@ -6081,8 +6107,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6081
6107
  isMessageOpen = true;
6082
6108
  activeMessageId = value.message.id;
6083
6109
  usage.input_tokens = value.message.usage.input_tokens;
6084
- usage.cache_read_input_tokens = (_e = value.message.usage.cache_read_input_tokens) != null ? _e : 0;
6085
- usage.cache_creation_input_tokens = (_f = value.message.usage.cache_creation_input_tokens) != null ? _f : 0;
6110
+ usage.cache_read_input_tokens = value.message.usage.cache_read_input_tokens ?? 0;
6111
+ usage.cache_creation_input_tokens = value.message.usage.cache_creation_input_tokens ?? 0;
6086
6112
  rawUsage = {
6087
6113
  ...value.message.usage
6088
6114
  };
@@ -6107,8 +6133,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6107
6133
  }
6108
6134
  controller.enqueue({
6109
6135
  type: "response-metadata",
6110
- id: (_g = value.message.id) != null ? _g : void 0,
6111
- modelId: (_h = value.message.model) != null ? _h : void 0
6136
+ id: value.message.id ?? void 0,
6137
+ modelId: value.message.model ?? void 0
6112
6138
  });
6113
6139
  if (value.message.content != null) {
6114
6140
  for (let contentIndex = 0; contentIndex < value.message.content.length; contentIndex++) {
@@ -6120,7 +6146,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6120
6146
  id: part.id,
6121
6147
  toolName: part.name
6122
6148
  });
6123
- const inputStr = JSON.stringify((_i = part.input) != null ? _i : {});
6149
+ const inputStr = JSON.stringify(part.input ?? {});
6124
6150
  controller.enqueue({
6125
6151
  type: "tool-input-delta",
6126
6152
  id: part.id,
@@ -6170,18 +6196,18 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6170
6196
  finishReason: value.delta.stop_reason,
6171
6197
  isJsonResponseFromTool
6172
6198
  }),
6173
- raw: (_j = value.delta.stop_reason) != null ? _j : void 0
6199
+ raw: value.delta.stop_reason ?? void 0
6174
6200
  };
6175
- stopSequence = (_k = value.delta.stop_sequence) != null ? _k : null;
6201
+ stopSequence = value.delta.stop_sequence ?? null;
6176
6202
  stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
6177
6203
  container = value.delta.container != null ? {
6178
6204
  expiresAt: value.delta.container.expires_at,
6179
6205
  id: value.delta.container.id,
6180
- skills: (_m = (_l = value.delta.container.skills) == null ? void 0 : _l.map((skill) => ({
6206
+ skills: value.delta.container.skills?.map((skill) => ({
6181
6207
  type: skill.type,
6182
6208
  skillId: skill.skill_id,
6183
6209
  version: skill.version
6184
- }))) != null ? _m : null
6210
+ })) ?? null
6185
6211
  } : null;
6186
6212
  if (value.context_management) {
6187
6213
  contextManagement = mapAnthropicResponseContextManagement(
@@ -6204,7 +6230,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6204
6230
  isMessageOpen = false;
6205
6231
  activeMessageId = void 0;
6206
6232
  const anthropicMetadata = {
6207
- usage: rawUsage != null ? rawUsage : null,
6233
+ usage: rawUsage ?? null,
6208
6234
  stopSequence,
6209
6235
  ...stopDetails != null ? { stopDetails } : {},
6210
6236
  ...inputTransformations != null ? { inputTransformations } : {},
@@ -6260,10 +6286,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6260
6286
  try {
6261
6287
  await firstChunkReader.read();
6262
6288
  let result = await firstChunkReader.read();
6263
- if (((_a = result.value) == null ? void 0 : _a.type) === "raw") {
6289
+ if (result.value?.type === "raw") {
6264
6290
  result = await firstChunkReader.read();
6265
6291
  }
6266
- if (((_b = result.value) == null ? void 0 : _b.type) === "error") {
6292
+ if (result.value?.type === "error") {
6267
6293
  const error = result.value.error;
6268
6294
  if (!isProviderStreamError(error)) {
6269
6295
  throw new Error("Expected a normalized Anthropic stream error");
@@ -6272,10 +6298,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6272
6298
  message: error.message,
6273
6299
  url,
6274
6300
  requestBodyValues: body,
6275
- statusCode: (_c = error.statusCode) != null ? _c : 500,
6301
+ statusCode: error.statusCode ?? 500,
6276
6302
  responseHeaders,
6277
6303
  responseBody: JSON.stringify(error.data),
6278
- isRetryable: (_d = error.isRetryable) != null ? _d : false
6304
+ isRetryable: error.isRetryable ?? false
6279
6305
  });
6280
6306
  }
6281
6307
  } finally {
@@ -7307,7 +7333,6 @@ var AnthropicSkills = class {
7307
7333
  };
7308
7334
  }
7309
7335
  async uploadSkill(params) {
7310
- var _a, _b;
7311
7336
  const warnings = [];
7312
7337
  const formData = new FormData();
7313
7338
  if (params.displayTitle != null) {
@@ -7333,8 +7358,8 @@ var AnthropicSkills = class {
7333
7358
  version: response.latest_version,
7334
7359
  headers
7335
7360
  }) : {};
7336
- const name = (_a = versionMetadata.name) != null ? _a : response.name;
7337
- const description = (_b = versionMetadata.description) != null ? _b : response.description;
7361
+ const name = versionMetadata.name ?? response.name;
7362
+ const description = versionMetadata.description ?? response.description;
7338
7363
  return {
7339
7364
  providerReference: { anthropic: response.id },
7340
7365
  ...response.display_title != null ? { displayTitle: response.display_title } : {},