@ai-sdk/anthropic 3.0.25 → 3.0.27
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 +12 -0
- package/dist/index.d.mts +20 -20
- package/dist/index.d.ts +20 -20
- package/dist/index.js +70 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -24
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +5 -0
- package/dist/internal/index.d.ts +5 -0
- package/dist/internal/index.js +69 -23
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +69 -23
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +37 -9
- package/package.json +1 -1
- package/src/anthropic-messages-language-model.ts +84 -20
- package/src/anthropic-provider.ts +20 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 3.0.27
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 572ea12: feat(anthropic): allow custom/dynamic key for providerOptions
|
|
8
|
+
|
|
9
|
+
## 3.0.26
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 2c70b90: chore: update provider docs
|
|
14
|
+
|
|
3
15
|
## 3.0.25
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -698,12 +698,12 @@ declare const anthropicTools: {
|
|
|
698
698
|
|
|
699
699
|
interface AnthropicProvider extends ProviderV3 {
|
|
700
700
|
/**
|
|
701
|
-
|
|
702
|
-
|
|
701
|
+
* Creates a model for text generation.
|
|
702
|
+
*/
|
|
703
703
|
(modelId: AnthropicMessagesModelId): LanguageModelV3;
|
|
704
704
|
/**
|
|
705
|
-
|
|
706
|
-
|
|
705
|
+
* Creates a model for text generation.
|
|
706
|
+
*/
|
|
707
707
|
languageModel(modelId: AnthropicMessagesModelId): LanguageModelV3;
|
|
708
708
|
chat(modelId: AnthropicMessagesModelId): LanguageModelV3;
|
|
709
709
|
messages(modelId: AnthropicMessagesModelId): LanguageModelV3;
|
|
@@ -712,36 +712,36 @@ interface AnthropicProvider extends ProviderV3 {
|
|
|
712
712
|
*/
|
|
713
713
|
textEmbeddingModel(modelId: string): never;
|
|
714
714
|
/**
|
|
715
|
-
|
|
715
|
+
* Anthropic-specific computer use tool.
|
|
716
716
|
*/
|
|
717
717
|
tools: typeof anthropicTools;
|
|
718
718
|
}
|
|
719
719
|
interface AnthropicProviderSettings {
|
|
720
720
|
/**
|
|
721
|
-
|
|
722
|
-
|
|
721
|
+
* Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
722
|
+
* The default prefix is `https://api.anthropic.com/v1`.
|
|
723
723
|
*/
|
|
724
724
|
baseURL?: string;
|
|
725
725
|
/**
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
726
|
+
* API key that is being send using the `x-api-key` header.
|
|
727
|
+
* It defaults to the `ANTHROPIC_API_KEY` environment variable.
|
|
728
|
+
* Only one of `apiKey` or `authToken` is required.
|
|
729
729
|
*/
|
|
730
730
|
apiKey?: string;
|
|
731
731
|
/**
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
732
|
+
* Auth token that is being sent using the `Authorization: Bearer` header.
|
|
733
|
+
* It defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable.
|
|
734
|
+
* Only one of `apiKey` or `authToken` is required.
|
|
735
735
|
*/
|
|
736
736
|
authToken?: string;
|
|
737
737
|
/**
|
|
738
|
-
|
|
739
|
-
|
|
738
|
+
* Custom headers to include in the requests.
|
|
739
|
+
*/
|
|
740
740
|
headers?: Record<string, string>;
|
|
741
741
|
/**
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
742
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
743
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
744
|
+
*/
|
|
745
745
|
fetch?: FetchFunction;
|
|
746
746
|
generateId?: () => string;
|
|
747
747
|
/**
|
|
@@ -751,11 +751,11 @@ interface AnthropicProviderSettings {
|
|
|
751
751
|
name?: string;
|
|
752
752
|
}
|
|
753
753
|
/**
|
|
754
|
-
Create an Anthropic provider instance.
|
|
754
|
+
* Create an Anthropic provider instance.
|
|
755
755
|
*/
|
|
756
756
|
declare function createAnthropic(options?: AnthropicProviderSettings): AnthropicProvider;
|
|
757
757
|
/**
|
|
758
|
-
Default Anthropic provider instance.
|
|
758
|
+
* Default Anthropic provider instance.
|
|
759
759
|
*/
|
|
760
760
|
declare const anthropic: AnthropicProvider;
|
|
761
761
|
|
package/dist/index.d.ts
CHANGED
|
@@ -698,12 +698,12 @@ declare const anthropicTools: {
|
|
|
698
698
|
|
|
699
699
|
interface AnthropicProvider extends ProviderV3 {
|
|
700
700
|
/**
|
|
701
|
-
|
|
702
|
-
|
|
701
|
+
* Creates a model for text generation.
|
|
702
|
+
*/
|
|
703
703
|
(modelId: AnthropicMessagesModelId): LanguageModelV3;
|
|
704
704
|
/**
|
|
705
|
-
|
|
706
|
-
|
|
705
|
+
* Creates a model for text generation.
|
|
706
|
+
*/
|
|
707
707
|
languageModel(modelId: AnthropicMessagesModelId): LanguageModelV3;
|
|
708
708
|
chat(modelId: AnthropicMessagesModelId): LanguageModelV3;
|
|
709
709
|
messages(modelId: AnthropicMessagesModelId): LanguageModelV3;
|
|
@@ -712,36 +712,36 @@ interface AnthropicProvider extends ProviderV3 {
|
|
|
712
712
|
*/
|
|
713
713
|
textEmbeddingModel(modelId: string): never;
|
|
714
714
|
/**
|
|
715
|
-
|
|
715
|
+
* Anthropic-specific computer use tool.
|
|
716
716
|
*/
|
|
717
717
|
tools: typeof anthropicTools;
|
|
718
718
|
}
|
|
719
719
|
interface AnthropicProviderSettings {
|
|
720
720
|
/**
|
|
721
|
-
|
|
722
|
-
|
|
721
|
+
* Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
722
|
+
* The default prefix is `https://api.anthropic.com/v1`.
|
|
723
723
|
*/
|
|
724
724
|
baseURL?: string;
|
|
725
725
|
/**
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
726
|
+
* API key that is being send using the `x-api-key` header.
|
|
727
|
+
* It defaults to the `ANTHROPIC_API_KEY` environment variable.
|
|
728
|
+
* Only one of `apiKey` or `authToken` is required.
|
|
729
729
|
*/
|
|
730
730
|
apiKey?: string;
|
|
731
731
|
/**
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
732
|
+
* Auth token that is being sent using the `Authorization: Bearer` header.
|
|
733
|
+
* It defaults to the `ANTHROPIC_AUTH_TOKEN` environment variable.
|
|
734
|
+
* Only one of `apiKey` or `authToken` is required.
|
|
735
735
|
*/
|
|
736
736
|
authToken?: string;
|
|
737
737
|
/**
|
|
738
|
-
|
|
739
|
-
|
|
738
|
+
* Custom headers to include in the requests.
|
|
739
|
+
*/
|
|
740
740
|
headers?: Record<string, string>;
|
|
741
741
|
/**
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
742
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
743
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
744
|
+
*/
|
|
745
745
|
fetch?: FetchFunction;
|
|
746
746
|
generateId?: () => string;
|
|
747
747
|
/**
|
|
@@ -751,11 +751,11 @@ interface AnthropicProviderSettings {
|
|
|
751
751
|
name?: string;
|
|
752
752
|
}
|
|
753
753
|
/**
|
|
754
|
-
Create an Anthropic provider instance.
|
|
754
|
+
* Create an Anthropic provider instance.
|
|
755
755
|
*/
|
|
756
756
|
declare function createAnthropic(options?: AnthropicProviderSettings): AnthropicProvider;
|
|
757
757
|
/**
|
|
758
|
-
Default Anthropic provider instance.
|
|
758
|
+
* Default Anthropic provider instance.
|
|
759
759
|
*/
|
|
760
760
|
declare const anthropic: AnthropicProvider;
|
|
761
761
|
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
32
32
|
var import_provider_utils23 = require("@ai-sdk/provider-utils");
|
|
33
33
|
|
|
34
34
|
// src/version.ts
|
|
35
|
-
var VERSION = true ? "3.0.
|
|
35
|
+
var VERSION = true ? "3.0.27" : "0.0.0-test";
|
|
36
36
|
|
|
37
37
|
// src/anthropic-messages-language-model.ts
|
|
38
38
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -2396,6 +2396,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2396
2396
|
get provider() {
|
|
2397
2397
|
return this.config.provider;
|
|
2398
2398
|
}
|
|
2399
|
+
/**
|
|
2400
|
+
* Extracts the dynamic provider name from the config.provider string.
|
|
2401
|
+
* e.g., 'my-custom-anthropic.messages' -> 'my-custom-anthropic'
|
|
2402
|
+
*/
|
|
2403
|
+
get providerOptionsName() {
|
|
2404
|
+
const provider = this.config.provider;
|
|
2405
|
+
const dotIndex = provider.indexOf(".");
|
|
2406
|
+
return dotIndex === -1 ? provider : provider.substring(0, dotIndex);
|
|
2407
|
+
}
|
|
2399
2408
|
get supportedUrls() {
|
|
2400
2409
|
var _a, _b, _c;
|
|
2401
2410
|
return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
|
@@ -2452,11 +2461,23 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2452
2461
|
});
|
|
2453
2462
|
}
|
|
2454
2463
|
}
|
|
2455
|
-
const
|
|
2464
|
+
const providerOptionsName = this.providerOptionsName;
|
|
2465
|
+
const canonicalOptions = await (0, import_provider_utils12.parseProviderOptions)({
|
|
2456
2466
|
provider: "anthropic",
|
|
2457
2467
|
providerOptions,
|
|
2458
2468
|
schema: anthropicProviderOptions
|
|
2459
2469
|
});
|
|
2470
|
+
const customProviderOptions = providerOptionsName !== "anthropic" ? await (0, import_provider_utils12.parseProviderOptions)({
|
|
2471
|
+
provider: providerOptionsName,
|
|
2472
|
+
providerOptions,
|
|
2473
|
+
schema: anthropicProviderOptions
|
|
2474
|
+
}) : null;
|
|
2475
|
+
const usedCustomProviderKey = customProviderOptions != null;
|
|
2476
|
+
const anthropicOptions = Object.assign(
|
|
2477
|
+
{},
|
|
2478
|
+
canonicalOptions != null ? canonicalOptions : {},
|
|
2479
|
+
customProviderOptions != null ? customProviderOptions : {}
|
|
2480
|
+
);
|
|
2460
2481
|
const {
|
|
2461
2482
|
maxOutputTokens: maxOutputTokensForModel,
|
|
2462
2483
|
supportsStructuredOutput: modelSupportsStructuredOutput,
|
|
@@ -2716,7 +2737,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2716
2737
|
warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
|
|
2717
2738
|
betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
|
|
2718
2739
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
2719
|
-
toolNameMapping
|
|
2740
|
+
toolNameMapping,
|
|
2741
|
+
providerOptionsName,
|
|
2742
|
+
usedCustomProviderKey
|
|
2720
2743
|
};
|
|
2721
2744
|
}
|
|
2722
2745
|
async getHeaders({
|
|
@@ -2773,8 +2796,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2773
2796
|
});
|
|
2774
2797
|
}
|
|
2775
2798
|
async doGenerate(options) {
|
|
2776
|
-
var _a, _b, _c, _d, _e, _f
|
|
2777
|
-
const {
|
|
2799
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2800
|
+
const {
|
|
2801
|
+
args,
|
|
2802
|
+
warnings,
|
|
2803
|
+
betas,
|
|
2804
|
+
usesJsonResponseTool,
|
|
2805
|
+
toolNameMapping,
|
|
2806
|
+
providerOptionsName,
|
|
2807
|
+
usedCustomProviderKey
|
|
2808
|
+
} = await this.getArgs({
|
|
2778
2809
|
...options,
|
|
2779
2810
|
stream: false,
|
|
2780
2811
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
@@ -3122,25 +3153,33 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3122
3153
|
body: rawResponse
|
|
3123
3154
|
},
|
|
3124
3155
|
warnings,
|
|
3125
|
-
providerMetadata: {
|
|
3126
|
-
|
|
3156
|
+
providerMetadata: (() => {
|
|
3157
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
3158
|
+
const anthropicMetadata = {
|
|
3127
3159
|
usage: response.usage,
|
|
3128
|
-
cacheCreationInputTokens: (
|
|
3129
|
-
stopSequence: (
|
|
3160
|
+
cacheCreationInputTokens: (_a2 = response.usage.cache_creation_input_tokens) != null ? _a2 : null,
|
|
3161
|
+
stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
|
|
3130
3162
|
container: response.container ? {
|
|
3131
3163
|
expiresAt: response.container.expires_at,
|
|
3132
3164
|
id: response.container.id,
|
|
3133
|
-
skills: (
|
|
3165
|
+
skills: (_d2 = (_c2 = response.container.skills) == null ? void 0 : _c2.map((skill) => ({
|
|
3134
3166
|
type: skill.type,
|
|
3135
3167
|
skillId: skill.skill_id,
|
|
3136
3168
|
version: skill.version
|
|
3137
|
-
}))) != null ?
|
|
3169
|
+
}))) != null ? _d2 : null
|
|
3138
3170
|
} : null,
|
|
3139
|
-
contextManagement: (
|
|
3171
|
+
contextManagement: (_e2 = mapAnthropicResponseContextManagement(
|
|
3140
3172
|
response.context_management
|
|
3141
|
-
)) != null ?
|
|
3173
|
+
)) != null ? _e2 : null
|
|
3174
|
+
};
|
|
3175
|
+
const providerMetadata = {
|
|
3176
|
+
anthropic: anthropicMetadata
|
|
3177
|
+
};
|
|
3178
|
+
if (usedCustomProviderKey && providerOptionsName !== "anthropic") {
|
|
3179
|
+
providerMetadata[providerOptionsName] = anthropicMetadata;
|
|
3142
3180
|
}
|
|
3143
|
-
|
|
3181
|
+
return providerMetadata;
|
|
3182
|
+
})()
|
|
3144
3183
|
};
|
|
3145
3184
|
}
|
|
3146
3185
|
async doStream(options) {
|
|
@@ -3150,7 +3189,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3150
3189
|
warnings,
|
|
3151
3190
|
betas,
|
|
3152
3191
|
usesJsonResponseTool,
|
|
3153
|
-
toolNameMapping
|
|
3192
|
+
toolNameMapping,
|
|
3193
|
+
providerOptionsName,
|
|
3194
|
+
usedCustomProviderKey
|
|
3154
3195
|
} = await this.getArgs({
|
|
3155
3196
|
...options,
|
|
3156
3197
|
stream: true,
|
|
@@ -3791,19 +3832,24 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3791
3832
|
return;
|
|
3792
3833
|
}
|
|
3793
3834
|
case "message_stop": {
|
|
3835
|
+
const anthropicMetadata = {
|
|
3836
|
+
usage: rawUsage != null ? rawUsage : null,
|
|
3837
|
+
cacheCreationInputTokens,
|
|
3838
|
+
stopSequence,
|
|
3839
|
+
container,
|
|
3840
|
+
contextManagement
|
|
3841
|
+
};
|
|
3842
|
+
const providerMetadata = {
|
|
3843
|
+
anthropic: anthropicMetadata
|
|
3844
|
+
};
|
|
3845
|
+
if (usedCustomProviderKey && providerOptionsName !== "anthropic") {
|
|
3846
|
+
providerMetadata[providerOptionsName] = anthropicMetadata;
|
|
3847
|
+
}
|
|
3794
3848
|
controller.enqueue({
|
|
3795
3849
|
type: "finish",
|
|
3796
3850
|
finishReason,
|
|
3797
3851
|
usage: convertAnthropicMessagesUsage(usage),
|
|
3798
|
-
providerMetadata
|
|
3799
|
-
anthropic: {
|
|
3800
|
-
usage: rawUsage != null ? rawUsage : null,
|
|
3801
|
-
cacheCreationInputTokens,
|
|
3802
|
-
stopSequence,
|
|
3803
|
-
container,
|
|
3804
|
-
contextManagement
|
|
3805
|
-
}
|
|
3806
|
-
}
|
|
3852
|
+
providerMetadata
|
|
3807
3853
|
});
|
|
3808
3854
|
return;
|
|
3809
3855
|
}
|