@ai-sdk/anthropic 2.0.48 → 2.0.49

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.
@@ -25,6 +25,7 @@ declare class AnthropicMessagesLanguageModel implements LanguageModelV2 {
25
25
  get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
26
26
  private getArgs;
27
27
  private getHeaders;
28
+ private getBetasFromHeaders;
28
29
  private buildRequestUrl;
29
30
  private transformRequestBody;
30
31
  private extractCitationDocuments;
@@ -25,6 +25,7 @@ declare class AnthropicMessagesLanguageModel implements LanguageModelV2 {
25
25
  get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
26
26
  private getArgs;
27
27
  private getHeaders;
28
+ private getBetasFromHeaders;
28
29
  private buildRequestUrl;
29
30
  private transformRequestBody;
30
31
  private extractCitationDocuments;
@@ -1762,6 +1762,7 @@ var AnthropicMessagesLanguageModel = class {
1762
1762
  return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
1763
1763
  }
1764
1764
  async getArgs({
1765
+ userSuppliedBetas,
1765
1766
  prompt,
1766
1767
  maxOutputTokens,
1767
1768
  temperature,
@@ -1979,7 +1980,7 @@ var AnthropicMessagesLanguageModel = class {
1979
1980
  tool_choice: anthropicToolChoice
1980
1981
  },
1981
1982
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
1982
- betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas]),
1983
+ betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
1983
1984
  usesJsonResponseTool: jsonResponseTool != null
1984
1985
  };
1985
1986
  }
@@ -1989,8 +1990,20 @@ var AnthropicMessagesLanguageModel = class {
1989
1990
  }) {
1990
1991
  return (0, import_provider_utils11.combineHeaders)(
1991
1992
  await (0, import_provider_utils11.resolve)(this.config.headers),
1992
- betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
1993
- headers
1993
+ headers,
1994
+ betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {}
1995
+ );
1996
+ }
1997
+ async getBetasFromHeaders(requestHeaders) {
1998
+ var _a, _b;
1999
+ const configHeaders = await (0, import_provider_utils11.resolve)(this.config.headers);
2000
+ const configBetaHeader = (_a = configHeaders["anthropic-beta"]) != null ? _a : "";
2001
+ const requestBetaHeader = (_b = requestHeaders == null ? void 0 : requestHeaders["anthropic-beta"]) != null ? _b : "";
2002
+ return new Set(
2003
+ [
2004
+ ...configBetaHeader.toLowerCase().split(","),
2005
+ ...requestBetaHeader.toLowerCase().split(",")
2006
+ ].map((beta) => beta.trim()).filter((beta) => beta !== "")
1994
2007
  );
1995
2008
  }
1996
2009
  buildRequestUrl(isStreaming) {
@@ -2026,7 +2039,10 @@ var AnthropicMessagesLanguageModel = class {
2026
2039
  }
2027
2040
  async doGenerate(options) {
2028
2041
  var _a, _b, _c, _d, _e, _f, _g, _h;
2029
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
2042
+ const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2043
+ ...options,
2044
+ userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
2045
+ });
2030
2046
  const citationDocuments = this.extractCitationDocuments(options.prompt);
2031
2047
  const {
2032
2048
  responseHeaders,
@@ -2291,7 +2307,10 @@ var AnthropicMessagesLanguageModel = class {
2291
2307
  };
2292
2308
  }
2293
2309
  async doStream(options) {
2294
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
2310
+ const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2311
+ ...options,
2312
+ userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
2313
+ });
2295
2314
  const citationDocuments = this.extractCitationDocuments(options.prompt);
2296
2315
  const body = { ...args, stream: true };
2297
2316
  const { responseHeaders, value: response } = await (0, import_provider_utils11.postJsonToApi)({