@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 2.0.49
4
+
5
+ ### Patch Changes
6
+
7
+ - dcdfeb7: Retain user-supplied betas.
8
+
3
9
  ## 2.0.48
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
31
31
  var import_provider_utils20 = require("@ai-sdk/provider-utils");
32
32
 
33
33
  // src/version.ts
34
- var VERSION = true ? "2.0.48" : "0.0.0-test";
34
+ var VERSION = true ? "2.0.49" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -1769,6 +1769,7 @@ var AnthropicMessagesLanguageModel = class {
1769
1769
  return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
1770
1770
  }
1771
1771
  async getArgs({
1772
+ userSuppliedBetas,
1772
1773
  prompt,
1773
1774
  maxOutputTokens,
1774
1775
  temperature,
@@ -1986,7 +1987,7 @@ var AnthropicMessagesLanguageModel = class {
1986
1987
  tool_choice: anthropicToolChoice
1987
1988
  },
1988
1989
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
1989
- betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas]),
1990
+ betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
1990
1991
  usesJsonResponseTool: jsonResponseTool != null
1991
1992
  };
1992
1993
  }
@@ -1996,8 +1997,20 @@ var AnthropicMessagesLanguageModel = class {
1996
1997
  }) {
1997
1998
  return (0, import_provider_utils11.combineHeaders)(
1998
1999
  await (0, import_provider_utils11.resolve)(this.config.headers),
1999
- betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
2000
- headers
2000
+ headers,
2001
+ betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {}
2002
+ );
2003
+ }
2004
+ async getBetasFromHeaders(requestHeaders) {
2005
+ var _a, _b;
2006
+ const configHeaders = await (0, import_provider_utils11.resolve)(this.config.headers);
2007
+ const configBetaHeader = (_a = configHeaders["anthropic-beta"]) != null ? _a : "";
2008
+ const requestBetaHeader = (_b = requestHeaders == null ? void 0 : requestHeaders["anthropic-beta"]) != null ? _b : "";
2009
+ return new Set(
2010
+ [
2011
+ ...configBetaHeader.toLowerCase().split(","),
2012
+ ...requestBetaHeader.toLowerCase().split(",")
2013
+ ].map((beta) => beta.trim()).filter((beta) => beta !== "")
2001
2014
  );
2002
2015
  }
2003
2016
  buildRequestUrl(isStreaming) {
@@ -2033,7 +2046,10 @@ var AnthropicMessagesLanguageModel = class {
2033
2046
  }
2034
2047
  async doGenerate(options) {
2035
2048
  var _a, _b, _c, _d, _e, _f, _g, _h;
2036
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
2049
+ const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2050
+ ...options,
2051
+ userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
2052
+ });
2037
2053
  const citationDocuments = this.extractCitationDocuments(options.prompt);
2038
2054
  const {
2039
2055
  responseHeaders,
@@ -2298,7 +2314,10 @@ var AnthropicMessagesLanguageModel = class {
2298
2314
  };
2299
2315
  }
2300
2316
  async doStream(options) {
2301
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
2317
+ const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2318
+ ...options,
2319
+ userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
2320
+ });
2302
2321
  const citationDocuments = this.extractCitationDocuments(options.prompt);
2303
2322
  const body = { ...args, stream: true };
2304
2323
  const { responseHeaders, value: response } = await (0, import_provider_utils11.postJsonToApi)({