@ai-sdk/amazon-bedrock 4.0.33 → 4.0.34
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 +7 -0
- package/dist/anthropic/index.d.mts +29 -29
- package/dist/anthropic/index.d.ts +29 -29
- package/dist/anthropic/index.js +1 -1
- package/dist/anthropic/index.js.map +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/index.d.mts +43 -43
- package/dist/index.d.ts +43 -43
- package/dist/index.js +18 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/anthropic/bedrock-anthropic-provider.ts +29 -29
- package/src/bedrock-embedding-options.ts +17 -17
- package/src/bedrock-provider.ts +43 -43
- package/src/bedrock-sigv4-fetch.ts +10 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/amazon-bedrock",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.34",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@smithy/eventstream-codec": "^4.0.1",
|
|
39
39
|
"@smithy/util-utf8": "^4.0.0",
|
|
40
40
|
"aws4fetch": "^1.0.20",
|
|
41
|
+
"@ai-sdk/anthropic": "3.0.26",
|
|
41
42
|
"@ai-sdk/provider": "3.0.5",
|
|
42
|
-
"@ai-sdk/anthropic": "3.0.25",
|
|
43
43
|
"@ai-sdk/provider-utils": "4.0.10"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
@@ -51,17 +51,17 @@ const BEDROCK_TOOL_BETA_MAP: Record<string, string> = {
|
|
|
51
51
|
|
|
52
52
|
export interface BedrockAnthropicProvider extends ProviderV3 {
|
|
53
53
|
/**
|
|
54
|
-
Creates a model for text generation.
|
|
55
|
-
*/
|
|
54
|
+
* Creates a model for text generation.
|
|
55
|
+
*/
|
|
56
56
|
(modelId: BedrockAnthropicModelId): LanguageModelV3;
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
Creates a model for text generation.
|
|
60
|
-
*/
|
|
59
|
+
* Creates a model for text generation.
|
|
60
|
+
*/
|
|
61
61
|
languageModel(modelId: BedrockAnthropicModelId): LanguageModelV3;
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
Anthropic-specific computer use tool.
|
|
64
|
+
* Anthropic-specific computer use tool.
|
|
65
65
|
*/
|
|
66
66
|
tools: typeof anthropicTools;
|
|
67
67
|
|
|
@@ -73,65 +73,65 @@ Anthropic-specific computer use tool.
|
|
|
73
73
|
|
|
74
74
|
export interface BedrockAnthropicProviderSettings {
|
|
75
75
|
/**
|
|
76
|
-
The AWS region to use for the Bedrock provider. Defaults to the value of the
|
|
77
|
-
`AWS_REGION` environment variable.
|
|
76
|
+
* The AWS region to use for the Bedrock provider. Defaults to the value of the
|
|
77
|
+
* `AWS_REGION` environment variable.
|
|
78
78
|
*/
|
|
79
79
|
region?: string;
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
|
-
API key for authenticating requests using Bearer token authentication.
|
|
83
|
-
When provided, this will be used instead of AWS SigV4 authentication.
|
|
84
|
-
Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.
|
|
82
|
+
* API key for authenticating requests using Bearer token authentication.
|
|
83
|
+
* When provided, this will be used instead of AWS SigV4 authentication.
|
|
84
|
+
* Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.
|
|
85
85
|
*/
|
|
86
86
|
apiKey?: string;
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
The AWS access key ID to use for the Bedrock provider. Defaults to the value of the
|
|
90
|
-
`AWS_ACCESS_KEY_ID` environment variable.
|
|
89
|
+
* The AWS access key ID to use for the Bedrock provider. Defaults to the value of the
|
|
90
|
+
* `AWS_ACCESS_KEY_ID` environment variable.
|
|
91
91
|
*/
|
|
92
92
|
accessKeyId?: string;
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
The AWS secret access key to use for the Bedrock provider. Defaults to the value of the
|
|
96
|
-
`AWS_SECRET_ACCESS_KEY` environment variable.
|
|
95
|
+
* The AWS secret access key to use for the Bedrock provider. Defaults to the value of the
|
|
96
|
+
* `AWS_SECRET_ACCESS_KEY` environment variable.
|
|
97
97
|
*/
|
|
98
98
|
secretAccessKey?: string;
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
|
-
The AWS session token to use for the Bedrock provider. Defaults to the value of the
|
|
102
|
-
`AWS_SESSION_TOKEN` environment variable.
|
|
101
|
+
* The AWS session token to use for the Bedrock provider. Defaults to the value of the
|
|
102
|
+
* `AWS_SESSION_TOKEN` environment variable.
|
|
103
103
|
*/
|
|
104
104
|
sessionToken?: string;
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
|
-
Base URL for the Bedrock API calls.
|
|
107
|
+
* Base URL for the Bedrock API calls.
|
|
108
108
|
*/
|
|
109
109
|
baseURL?: string;
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
|
-
Custom headers to include in the requests.
|
|
112
|
+
* Custom headers to include in the requests.
|
|
113
113
|
*/
|
|
114
114
|
headers?: Resolvable<Record<string, string | undefined>>;
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
118
|
-
or to provide a custom fetch implementation for e.g. testing.
|
|
119
|
-
*/
|
|
117
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
118
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
119
|
+
*/
|
|
120
120
|
fetch?: FetchFunction;
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
The AWS credential provider to use for the Bedrock provider to get dynamic
|
|
124
|
-
credentials similar to the AWS SDK. Setting a provider here will cause its
|
|
125
|
-
credential values to be used instead of the `accessKeyId`, `secretAccessKey`,
|
|
126
|
-
and `sessionToken` settings.
|
|
123
|
+
* The AWS credential provider to use for the Bedrock provider to get dynamic
|
|
124
|
+
* credentials similar to the AWS SDK. Setting a provider here will cause its
|
|
125
|
+
* credential values to be used instead of the `accessKeyId`, `secretAccessKey`,
|
|
126
|
+
* and `sessionToken` settings.
|
|
127
127
|
*/
|
|
128
128
|
credentialProvider?: () => PromiseLike<Omit<BedrockCredentials, 'region'>>;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
|
-
Create an Amazon Bedrock Anthropic provider instance.
|
|
133
|
-
This provider uses the native Anthropic API through Bedrock's InvokeModel endpoint,
|
|
134
|
-
bypassing the Converse API for better feature compatibility.
|
|
132
|
+
* Create an Amazon Bedrock Anthropic provider instance.
|
|
133
|
+
* This provider uses the native Anthropic API through Bedrock's InvokeModel endpoint,
|
|
134
|
+
* bypassing the Converse API for better feature compatibility.
|
|
135
135
|
*/
|
|
136
136
|
export function createBedrockAnthropic(
|
|
137
137
|
options: BedrockAnthropicProviderSettings = {},
|
|
@@ -352,6 +352,6 @@ export function createBedrockAnthropic(
|
|
|
352
352
|
}
|
|
353
353
|
|
|
354
354
|
/**
|
|
355
|
-
Default Bedrock Anthropic provider instance.
|
|
355
|
+
* Default Bedrock Anthropic provider instance.
|
|
356
356
|
*/
|
|
357
357
|
export const bedrockAnthropic = createBedrockAnthropic();
|
|
@@ -9,32 +9,32 @@ export type BedrockEmbeddingModelId =
|
|
|
9
9
|
|
|
10
10
|
export const bedrockEmbeddingProviderOptions = z.object({
|
|
11
11
|
/**
|
|
12
|
-
The number of dimensions the resulting output embeddings should have (defaults to 1024).
|
|
13
|
-
Only supported in amazon.titan-embed-text-v2:0.
|
|
12
|
+
* The number of dimensions the resulting output embeddings should have (defaults to 1024).
|
|
13
|
+
* Only supported in amazon.titan-embed-text-v2:0.
|
|
14
14
|
*/
|
|
15
15
|
dimensions: z
|
|
16
16
|
.union([z.literal(1024), z.literal(512), z.literal(256)])
|
|
17
17
|
.optional(),
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
Flag indicating whether or not to normalize the output embeddings. Defaults to true
|
|
21
|
-
Only supported in amazon.titan-embed-text-v2:0.
|
|
22
|
-
|
|
20
|
+
* Flag indicating whether or not to normalize the output embeddings. Defaults to true
|
|
21
|
+
* Only supported in amazon.titan-embed-text-v2:0.
|
|
22
|
+
*/
|
|
23
23
|
normalize: z.boolean().optional(),
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
The number of dimensions for Nova embedding models (defaults to 1024).
|
|
27
|
-
Supported values: 256, 384, 1024, 3072.
|
|
28
|
-
Only supported in amazon.nova-* embedding models.
|
|
29
|
-
|
|
26
|
+
* The number of dimensions for Nova embedding models (defaults to 1024).
|
|
27
|
+
* Supported values: 256, 384, 1024, 3072.
|
|
28
|
+
* Only supported in amazon.nova-* embedding models.
|
|
29
|
+
*/
|
|
30
30
|
embeddingDimension: z
|
|
31
31
|
.union([z.literal(256), z.literal(384), z.literal(1024), z.literal(3072)])
|
|
32
32
|
.optional(),
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
The purpose of the embedding. Defaults to 'GENERIC_INDEX'.
|
|
36
|
-
Only supported in amazon.nova-* embedding models.
|
|
37
|
-
|
|
35
|
+
* The purpose of the embedding. Defaults to 'GENERIC_INDEX'.
|
|
36
|
+
* Only supported in amazon.nova-* embedding models.
|
|
37
|
+
*/
|
|
38
38
|
embeddingPurpose: z
|
|
39
39
|
.enum([
|
|
40
40
|
'GENERIC_INDEX',
|
|
@@ -50,17 +50,17 @@ Only supported in amazon.nova-* embedding models.
|
|
|
50
50
|
.optional(),
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
Input type for Cohere embedding models on Bedrock.
|
|
54
|
-
Common values: `search_document`, `search_query`, `classification`, `clustering`.
|
|
55
|
-
If not set, the provider defaults to `search_query`.
|
|
53
|
+
* Input type for Cohere embedding models on Bedrock.
|
|
54
|
+
* Common values: `search_document`, `search_query`, `classification`, `clustering`.
|
|
55
|
+
* If not set, the provider defaults to `search_query`.
|
|
56
56
|
*/
|
|
57
57
|
inputType: z
|
|
58
58
|
.enum(['search_document', 'search_query', 'classification', 'clustering'])
|
|
59
59
|
.optional(),
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
Truncation behavior when input exceeds the model's context length.
|
|
63
|
-
Supported in Cohere and Nova embedding models. Defaults to 'END' for Nova models.
|
|
62
|
+
* Truncation behavior when input exceeds the model's context length.
|
|
63
|
+
* Supported in Cohere and Nova embedding models. Defaults to 'END' for Nova models.
|
|
64
64
|
*/
|
|
65
65
|
truncate: z.enum(['NONE', 'START', 'END']).optional(),
|
|
66
66
|
});
|
package/src/bedrock-provider.ts
CHANGED
|
@@ -31,75 +31,75 @@ import { VERSION } from './version';
|
|
|
31
31
|
|
|
32
32
|
export interface AmazonBedrockProviderSettings {
|
|
33
33
|
/**
|
|
34
|
-
The AWS region to use for the Bedrock provider. Defaults to the value of the
|
|
35
|
-
`AWS_REGION` environment variable.
|
|
34
|
+
* The AWS region to use for the Bedrock provider. Defaults to the value of the
|
|
35
|
+
* `AWS_REGION` environment variable.
|
|
36
36
|
*/
|
|
37
37
|
region?: string;
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
API key for authenticating requests using Bearer token authentication.
|
|
41
|
-
When provided, this will be used instead of AWS SigV4 authentication.
|
|
42
|
-
Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.
|
|
43
|
-
|
|
44
|
-
@example
|
|
45
|
-
```typescript
|
|
46
|
-
// Using API key directly
|
|
47
|
-
const bedrock = createAmazonBedrock({
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// Using environment variable AWS_BEARER_TOKEN_BEDROCK
|
|
53
|
-
const bedrock = createAmazonBedrock({
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
Note: When `apiKey` is provided, it takes precedence over AWS SigV4 authentication.
|
|
59
|
-
If neither `apiKey` nor `AWS_BEARER_TOKEN_BEDROCK` environment variable is set,
|
|
60
|
-
the provider will fall back to AWS SigV4 authentication using AWS credentials.
|
|
40
|
+
* API key for authenticating requests using Bearer token authentication.
|
|
41
|
+
* When provided, this will be used instead of AWS SigV4 authentication.
|
|
42
|
+
* Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // Using API key directly
|
|
47
|
+
* const bedrock = createAmazonBedrock({
|
|
48
|
+
* apiKey: 'your-api-key-here',
|
|
49
|
+
* region: 'us-east-1'
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* // Using environment variable AWS_BEARER_TOKEN_BEDROCK
|
|
53
|
+
* const bedrock = createAmazonBedrock({
|
|
54
|
+
* region: 'us-east-1'
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* Note: When `apiKey` is provided, it takes precedence over AWS SigV4 authentication.
|
|
59
|
+
* If neither `apiKey` nor `AWS_BEARER_TOKEN_BEDROCK` environment variable is set,
|
|
60
|
+
* the provider will fall back to AWS SigV4 authentication using AWS credentials.
|
|
61
61
|
*/
|
|
62
62
|
apiKey?: string;
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
The AWS access key ID to use for the Bedrock provider. Defaults to the value of the
|
|
66
|
-
`AWS_ACCESS_KEY_ID` environment variable.
|
|
65
|
+
* The AWS access key ID to use for the Bedrock provider. Defaults to the value of the
|
|
66
|
+
* `AWS_ACCESS_KEY_ID` environment variable.
|
|
67
67
|
*/
|
|
68
68
|
accessKeyId?: string;
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
|
-
The AWS secret access key to use for the Bedrock provider. Defaults to the value of the
|
|
72
|
-
`AWS_SECRET_ACCESS_KEY` environment variable.
|
|
71
|
+
* The AWS secret access key to use for the Bedrock provider. Defaults to the value of the
|
|
72
|
+
* `AWS_SECRET_ACCESS_KEY` environment variable.
|
|
73
73
|
*/
|
|
74
74
|
secretAccessKey?: string;
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
|
-
The AWS session token to use for the Bedrock provider. Defaults to the value of the
|
|
78
|
-
`AWS_SESSION_TOKEN` environment variable.
|
|
77
|
+
* The AWS session token to use for the Bedrock provider. Defaults to the value of the
|
|
78
|
+
* `AWS_SESSION_TOKEN` environment variable.
|
|
79
79
|
*/
|
|
80
80
|
sessionToken?: string;
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
Base URL for the Bedrock API calls.
|
|
83
|
+
* Base URL for the Bedrock API calls.
|
|
84
84
|
*/
|
|
85
85
|
baseURL?: string;
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
|
-
Custom headers to include in the requests.
|
|
88
|
+
* Custom headers to include in the requests.
|
|
89
89
|
*/
|
|
90
90
|
headers?: Record<string, string>;
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
94
|
-
or to provide a custom fetch implementation for e.g. testing.
|
|
95
|
-
*/
|
|
93
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
94
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
95
|
+
*/
|
|
96
96
|
fetch?: FetchFunction;
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
|
-
The AWS credential provider to use for the Bedrock provider to get dynamic
|
|
100
|
-
credentials similar to the AWS SDK. Setting a provider here will cause its
|
|
101
|
-
credential values to be used instead of the `accessKeyId`, `secretAccessKey`,
|
|
102
|
-
and `sessionToken` settings.
|
|
99
|
+
* The AWS credential provider to use for the Bedrock provider to get dynamic
|
|
100
|
+
* credentials similar to the AWS SDK. Setting a provider here will cause its
|
|
101
|
+
* credential values to be used instead of the `accessKeyId`, `secretAccessKey`,
|
|
102
|
+
* and `sessionToken` settings.
|
|
103
103
|
*/
|
|
104
104
|
credentialProvider?: () => PromiseLike<Omit<BedrockCredentials, 'region'>>;
|
|
105
105
|
|
|
@@ -133,12 +133,12 @@ export interface AmazonBedrockProvider extends ProviderV3 {
|
|
|
133
133
|
textEmbeddingModel(modelId: BedrockEmbeddingModelId): EmbeddingModelV3;
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
|
-
Creates a model for image generation.
|
|
136
|
+
* Creates a model for image generation.
|
|
137
137
|
*/
|
|
138
138
|
image(modelId: BedrockImageModelId): ImageModelV3;
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
|
-
Creates a model for image generation.
|
|
141
|
+
* Creates a model for image generation.
|
|
142
142
|
*/
|
|
143
143
|
imageModel(modelId: BedrockImageModelId): ImageModelV3;
|
|
144
144
|
|
|
@@ -153,13 +153,13 @@ Creates a model for image generation.
|
|
|
153
153
|
rerankingModel(modelId: BedrockRerankingModelId): RerankingModelV3;
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
|
-
Anthropic-specific tools that can be used with Anthropic models on Bedrock.
|
|
156
|
+
* Anthropic-specific tools that can be used with Anthropic models on Bedrock.
|
|
157
157
|
*/
|
|
158
158
|
tools: typeof anthropicTools;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
|
-
Create an Amazon Bedrock provider instance.
|
|
162
|
+
* Create an Amazon Bedrock provider instance.
|
|
163
163
|
*/
|
|
164
164
|
export function createAmazonBedrock(
|
|
165
165
|
options: AmazonBedrockProviderSettings = {},
|
|
@@ -346,6 +346,6 @@ export function createAmazonBedrock(
|
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
/**
|
|
349
|
-
Default Bedrock provider instance.
|
|
349
|
+
* Default Bedrock provider instance.
|
|
350
350
|
*/
|
|
351
351
|
export const bedrock = createAmazonBedrock();
|
|
@@ -16,11 +16,11 @@ export interface BedrockCredentials {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
Creates a fetch function that applies AWS Signature Version 4 signing.
|
|
20
|
-
|
|
21
|
-
@param getCredentials - Function that returns the AWS credentials to use when signing.
|
|
22
|
-
@param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.
|
|
23
|
-
@returns A FetchFunction that signs requests before passing them to the underlying fetch.
|
|
19
|
+
* Creates a fetch function that applies AWS Signature Version 4 signing.
|
|
20
|
+
*
|
|
21
|
+
* @param getCredentials - Function that returns the AWS credentials to use when signing.
|
|
22
|
+
* @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.
|
|
23
|
+
* @returns A FetchFunction that signs requests before passing them to the underlying fetch.
|
|
24
24
|
*/
|
|
25
25
|
export function createSigV4FetchFunction(
|
|
26
26
|
getCredentials: () => BedrockCredentials | PromiseLike<BedrockCredentials>,
|
|
@@ -105,11 +105,11 @@ function prepareBodyString(body: BodyInit | undefined): string {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
|
-
Creates a fetch function that applies Bearer token authentication.
|
|
109
|
-
|
|
110
|
-
@param apiKey - The API key to use for Bearer token authentication.
|
|
111
|
-
@param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.
|
|
112
|
-
@returns A FetchFunction that adds Authorization header with Bearer token to requests.
|
|
108
|
+
* Creates a fetch function that applies Bearer token authentication.
|
|
109
|
+
*
|
|
110
|
+
* @param apiKey - The API key to use for Bearer token authentication.
|
|
111
|
+
* @param fetch - Optional original fetch implementation to wrap. Defaults to global fetch.
|
|
112
|
+
* @returns A FetchFunction that adds Authorization header with Bearer token to requests.
|
|
113
113
|
*/
|
|
114
114
|
export function createApiKeyFetchFunction(
|
|
115
115
|
apiKey: string,
|