@rulvar/anthropic 1.15.0 → 1.16.1

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.d.ts CHANGED
@@ -91,7 +91,16 @@ interface AnthropicAdapterOptions {
91
91
  * autoretries are disabled (max_retries 0): the core owns retries and
92
92
  * wall-clock. With no auth option at all, the underlying SDK resolves
93
93
  * credentials itself: `ANTHROPIC_API_KEY`, then bearer
94
- * `ANTHROPIC_AUTH_TOKEN`, then its config-file credential chain.
94
+ * `ANTHROPIC_AUTH_TOKEN`, then its config-file credential chain. When
95
+ * `sdkOptions` carries structured auth (`credentials`, `config`, or
96
+ * `profile`) and no `apiKey`/`authToken` is set to a string anywhere,
97
+ * ambient environment credentials are suppressed (explicit
98
+ * `apiKey: null, authToken: null` are passed to the SDK), so the
99
+ * configured provider is the one that authenticates; the SDK itself
100
+ * would otherwise let an environment `ANTHROPIC_API_KEY` or
101
+ * `ANTHROPIC_AUTH_TOKEN` win over the provider. An explicit
102
+ * `apiKey: null` or `authToken: null` counts as absence for this rule,
103
+ * never as a chosen credential.
95
104
  */
96
105
  declare function anthropic(options?: AnthropicAdapterOptions): ProviderAdapter;
97
106
  //#endregion
package/dist/index.js CHANGED
@@ -675,8 +675,13 @@ function resolveAnthropicClient(options) {
675
675
  const sdkOptions = options.sdkOptions ?? {};
676
676
  if (options.apiKey !== void 0 && sdkOptions.apiKey !== void 0) throw new ConfigError("anthropic(): 'apiKey' and 'sdkOptions.apiKey' are both set; pick one place");
677
677
  if (options.baseURL !== void 0 && sdkOptions.baseURL !== void 0) throw new ConfigError("anthropic(): 'baseURL' and 'sdkOptions.baseURL' are both set; pick one place");
678
+ const suppressAmbientEnv = (sdkOptions.credentials != null || sdkOptions.config != null || sdkOptions.profile != null) && options.apiKey == null && sdkOptions.apiKey == null && sdkOptions.authToken == null;
678
679
  return new Anthropic({
679
680
  ...sdkOptions,
681
+ ...suppressAmbientEnv ? {
682
+ apiKey: null,
683
+ authToken: null
684
+ } : {},
680
685
  ...options.apiKey === void 0 ? {} : { apiKey: options.apiKey },
681
686
  ...options.baseURL === void 0 ? {} : { baseURL: options.baseURL },
682
687
  maxRetries: 0
@@ -687,7 +692,16 @@ function resolveAnthropicClient(options) {
687
692
  * autoretries are disabled (max_retries 0): the core owns retries and
688
693
  * wall-clock. With no auth option at all, the underlying SDK resolves
689
694
  * credentials itself: `ANTHROPIC_API_KEY`, then bearer
690
- * `ANTHROPIC_AUTH_TOKEN`, then its config-file credential chain.
695
+ * `ANTHROPIC_AUTH_TOKEN`, then its config-file credential chain. When
696
+ * `sdkOptions` carries structured auth (`credentials`, `config`, or
697
+ * `profile`) and no `apiKey`/`authToken` is set to a string anywhere,
698
+ * ambient environment credentials are suppressed (explicit
699
+ * `apiKey: null, authToken: null` are passed to the SDK), so the
700
+ * configured provider is the one that authenticates; the SDK itself
701
+ * would otherwise let an environment `ANTHROPIC_API_KEY` or
702
+ * `ANTHROPIC_AUTH_TOKEN` win over the provider. An explicit
703
+ * `apiKey: null` or `authToken: null` counts as absence for this rule,
704
+ * never as a chosen credential.
691
705
  */
692
706
  function anthropic(options = {}) {
693
707
  const client = resolveAnthropicClient(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulvar/anthropic",
3
- "version": "1.15.0",
3
+ "version": "1.16.1",
4
4
  "description": "Rulvar first-class provider adapter over @anthropic-ai/sdk.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -23,13 +23,13 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@anthropic-ai/sdk": "^0.110.0",
26
- "@rulvar/core": "1.15.0"
26
+ "@rulvar/core": "1.16.1"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/node": "^22.20.0",
30
30
  "tsdown": "^0.22.3",
31
31
  "typescript": "~6.0.3",
32
- "@rulvar/testing": "1.15.0"
32
+ "@rulvar/testing": "1.16.1"
33
33
  },
34
34
  "repository": {
35
35
  "type": "git",