@ai-sdk/anthropic 2.0.66 → 2.0.68

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.
@@ -10,7 +10,7 @@ type AnthropicMessagesConfig = {
10
10
  headers: Resolvable<Record<string, string | undefined>>;
11
11
  fetch?: FetchFunction;
12
12
  buildRequestUrl?: (baseURL: string, isStreaming: boolean) => string;
13
- transformRequestBody?: (args: Record<string, any>) => Record<string, any>;
13
+ transformRequestBody?: (args: Record<string, any>, betas: Set<string>) => Record<string, any>;
14
14
  supportedUrls?: () => LanguageModelV2['supportedUrls'];
15
15
  generateId?: () => string;
16
16
  };
@@ -10,7 +10,7 @@ type AnthropicMessagesConfig = {
10
10
  headers: Resolvable<Record<string, string | undefined>>;
11
11
  fetch?: FetchFunction;
12
12
  buildRequestUrl?: (baseURL: string, isStreaming: boolean) => string;
13
- transformRequestBody?: (args: Record<string, any>) => Record<string, any>;
13
+ transformRequestBody?: (args: Record<string, any>, betas: Set<string>) => Record<string, any>;
14
14
  supportedUrls?: () => LanguageModelV2['supportedUrls'];
15
15
  generateId?: () => string;
16
16
  };
@@ -741,7 +741,12 @@ var anthropicProviderOptions = import_v43.z.object({
741
741
  })
742
742
  ])
743
743
  )
744
- }).optional()
744
+ }).optional(),
745
+ /**
746
+ * A set of beta features to enable.
747
+ * Allow a provider to receive the full `betas` set if it needs it.
748
+ */
749
+ anthropicBeta: import_v43.z.array(import_v43.z.string()).optional()
745
750
  });
746
751
 
747
752
  // src/anthropic-prepare-tools.ts
@@ -1935,7 +1940,7 @@ var AnthropicMessagesLanguageModel = class {
1935
1940
  toolChoice,
1936
1941
  providerOptions
1937
1942
  }) {
1938
- var _a, _b, _c, _d, _e;
1943
+ var _a, _b, _c, _d, _e, _f;
1939
1944
  const warnings = [];
1940
1945
  if (frequencyPenalty != null) {
1941
1946
  warnings.push({
@@ -2036,6 +2041,9 @@ var AnthropicMessagesLanguageModel = class {
2036
2041
  ...(anthropicOptions == null ? void 0 : anthropicOptions.speed) && {
2037
2042
  speed: anthropicOptions.speed
2038
2043
  },
2044
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
2045
+ cache_control: anthropicOptions.cacheControl
2046
+ },
2039
2047
  // structured output:
2040
2048
  ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
2041
2049
  output_format: {
@@ -2206,7 +2214,12 @@ var AnthropicMessagesLanguageModel = class {
2206
2214
  tool_choice: anthropicToolChoice
2207
2215
  },
2208
2216
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
2209
- betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
2217
+ betas: /* @__PURE__ */ new Set([
2218
+ ...betas,
2219
+ ...toolsBetas,
2220
+ ...userSuppliedBetas,
2221
+ ...(_f = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _f : []
2222
+ ]),
2210
2223
  usesJsonResponseTool: jsonResponseTool != null
2211
2224
  };
2212
2225
  }
@@ -2236,9 +2249,9 @@ var AnthropicMessagesLanguageModel = class {
2236
2249
  var _a, _b, _c;
2237
2250
  return (_c = (_b = (_a = this.config).buildRequestUrl) == null ? void 0 : _b.call(_a, this.config.baseURL, isStreaming)) != null ? _c : `${this.config.baseURL}/messages`;
2238
2251
  }
2239
- transformRequestBody(args) {
2252
+ transformRequestBody(args, betas) {
2240
2253
  var _a, _b, _c;
2241
- return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args)) != null ? _c : args;
2254
+ return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args, betas)) != null ? _c : args;
2242
2255
  }
2243
2256
  extractCitationDocuments(prompt) {
2244
2257
  const isCitationPart = (part) => {
@@ -2277,7 +2290,7 @@ var AnthropicMessagesLanguageModel = class {
2277
2290
  } = await (0, import_provider_utils11.postJsonToApi)({
2278
2291
  url: this.buildRequestUrl(false),
2279
2292
  headers: await this.getHeaders({ betas, headers: options.headers }),
2280
- body: this.transformRequestBody(args),
2293
+ body: this.transformRequestBody(args, betas),
2281
2294
  failedResponseHandler: anthropicFailedResponseHandler,
2282
2295
  successfulResponseHandler: (0, import_provider_utils11.createJsonResponseHandler)(
2283
2296
  anthropicMessagesResponseSchema
@@ -2602,7 +2615,7 @@ var AnthropicMessagesLanguageModel = class {
2602
2615
  const { responseHeaders, value: response } = await (0, import_provider_utils11.postJsonToApi)({
2603
2616
  url,
2604
2617
  headers: await this.getHeaders({ betas, headers: options.headers }),
2605
- body: this.transformRequestBody(body),
2618
+ body: this.transformRequestBody(body, betas),
2606
2619
  failedResponseHandler: anthropicFailedResponseHandler,
2607
2620
  successfulResponseHandler: (0, import_provider_utils11.createEventSourceResponseHandler)(
2608
2621
  anthropicMessagesChunkSchema