@ai-sdk/amazon-bedrock 5.0.127 → 5.0.129
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 +37 -0
- package/dist/anthropic/index.d.ts +2 -1
- package/dist/anthropic/index.d.ts.map +1 -1
- package/dist/anthropic/index.js +8 -6
- package/dist/anthropic/index.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -32
- package/dist/index.js.map +1 -1
- package/dist/mantle/index.cjs +7 -5
- package/dist/mantle/index.cjs.map +1 -1
- package/dist/mantle/index.d.cts +3 -2
- package/dist/mantle/index.d.cts.map +1 -1
- package/dist/mantle/index.d.ts +3 -2
- package/dist/mantle/index.d.ts.map +1 -1
- package/dist/mantle/index.js +9 -7
- package/dist/mantle/index.js.map +1 -1
- package/docs/08-amazon-bedrock.mdx +19 -4
- package/package.json +5 -5
- package/src/amazon-bedrock-chat-language-model.ts +59 -37
- package/src/amazon-bedrock-provider.ts +11 -6
- package/src/amazon-bedrock-sigv4-fetch.ts +15 -2
- package/src/anthropic/amazon-bedrock-anthropic-provider.ts +10 -6
- package/src/mantle/bedrock-mantle-provider.ts +11 -6
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { LoadAPIKeyError } from '@ai-sdk/provider';
|
|
1
2
|
import {
|
|
2
3
|
combineHeaders,
|
|
4
|
+
resolve,
|
|
5
|
+
type Resolvable,
|
|
3
6
|
normalizeHeaders,
|
|
4
7
|
withUserAgentSuffix,
|
|
5
8
|
getRuntimeEnvironmentUserAgent,
|
|
@@ -124,7 +127,7 @@ function isAscii(value: string): boolean {
|
|
|
124
127
|
* @returns A FetchFunction that adds Authorization header with Bearer token to requests.
|
|
125
128
|
*/
|
|
126
129
|
export function createApiKeyFetchFunction(
|
|
127
|
-
apiKey: string
|
|
130
|
+
apiKey: Resolvable<string>,
|
|
128
131
|
fetch?: FetchFunction,
|
|
129
132
|
): FetchFunction {
|
|
130
133
|
return async (
|
|
@@ -140,8 +143,18 @@ export function createApiKeyFetchFunction(
|
|
|
140
143
|
getRuntimeEnvironmentUserAgent(),
|
|
141
144
|
);
|
|
142
145
|
|
|
146
|
+
const resolvedApiKey = await resolve(apiKey);
|
|
147
|
+
if (
|
|
148
|
+
typeof apiKey !== 'string' &&
|
|
149
|
+
(typeof resolvedApiKey !== 'string' || !resolvedApiKey.trim())
|
|
150
|
+
) {
|
|
151
|
+
throw new LoadAPIKeyError({
|
|
152
|
+
message: 'Amazon Bedrock API key must be a non-empty string.',
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
143
156
|
const finalHeaders = combineHeaders(headersWithUserAgent, {
|
|
144
|
-
Authorization: `Bearer ${apiKey}`,
|
|
157
|
+
Authorization: `Bearer ${typeof apiKey === 'string' ? resolvedApiKey : resolvedApiKey.trim()}`,
|
|
145
158
|
});
|
|
146
159
|
|
|
147
160
|
return effectiveFetch(input, {
|
|
@@ -88,10 +88,11 @@ export interface AmazonBedrockAnthropicProviderSettings {
|
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* API key for authenticating requests using Bearer token authentication.
|
|
91
|
+
* A callback is resolved before each request and must return a non-empty key.
|
|
91
92
|
* When provided, this will be used instead of AWS SigV4 authentication.
|
|
92
93
|
* Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.
|
|
93
94
|
*/
|
|
94
|
-
apiKey?: string
|
|
95
|
+
apiKey?: Resolvable<string>;
|
|
95
96
|
|
|
96
97
|
/**
|
|
97
98
|
* The AWS access key ID to use for the Bedrock provider. Defaults to the value of the
|
|
@@ -147,14 +148,17 @@ export function createAmazonBedrockAnthropic(
|
|
|
147
148
|
options: AmazonBedrockAnthropicProviderSettings = {},
|
|
148
149
|
): AmazonBedrockAnthropicProvider {
|
|
149
150
|
// Check for API key authentication first
|
|
150
|
-
const rawApiKey =
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
const rawApiKey =
|
|
152
|
+
typeof options.apiKey === 'string' || options.apiKey == null
|
|
153
|
+
? loadOptionalSetting({
|
|
154
|
+
settingValue: options.apiKey,
|
|
155
|
+
environmentVariableName: 'AWS_BEARER_TOKEN_BEDROCK',
|
|
156
|
+
})
|
|
157
|
+
: options.apiKey;
|
|
154
158
|
|
|
155
159
|
// Only use API key if it's a non-empty, non-whitespace string
|
|
156
160
|
const apiKey =
|
|
157
|
-
|
|
161
|
+
typeof rawApiKey === 'string' ? rawApiKey.trim() || undefined : rawApiKey;
|
|
158
162
|
|
|
159
163
|
// Use API key authentication if available, otherwise fall back to SigV4
|
|
160
164
|
const baseFetchFunction = apiKey
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
withoutTrailingSlash,
|
|
16
16
|
withUserAgentSuffix,
|
|
17
17
|
type FetchFunction,
|
|
18
|
+
type Resolvable,
|
|
18
19
|
} from '@ai-sdk/provider-utils';
|
|
19
20
|
import {
|
|
20
21
|
createApiKeyFetchFunction,
|
|
@@ -66,10 +67,11 @@ export interface BedrockMantleProviderSettings {
|
|
|
66
67
|
|
|
67
68
|
/**
|
|
68
69
|
* API key for authenticating requests using Bearer token authentication.
|
|
70
|
+
* A callback is resolved before each request and must return a non-empty key.
|
|
69
71
|
* When provided, this will be used instead of AWS SigV4 authentication.
|
|
70
72
|
* Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.
|
|
71
73
|
*/
|
|
72
|
-
apiKey?: string
|
|
74
|
+
apiKey?: Resolvable<string>;
|
|
73
75
|
|
|
74
76
|
/**
|
|
75
77
|
* The AWS access key ID to use for SigV4 authentication. Defaults to the value of the
|
|
@@ -125,14 +127,17 @@ export function createBedrockMantle(
|
|
|
125
127
|
options: BedrockMantleProviderSettings = {},
|
|
126
128
|
): BedrockMantleProvider {
|
|
127
129
|
// Check for API key authentication first
|
|
128
|
-
const rawApiKey =
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
const rawApiKey =
|
|
131
|
+
typeof options.apiKey === 'string' || options.apiKey == null
|
|
132
|
+
? loadOptionalSetting({
|
|
133
|
+
settingValue: options.apiKey,
|
|
134
|
+
environmentVariableName: 'AWS_BEARER_TOKEN_BEDROCK',
|
|
135
|
+
})
|
|
136
|
+
: options.apiKey;
|
|
132
137
|
|
|
133
138
|
// Only use API key if it's a non-empty, non-whitespace string
|
|
134
139
|
const apiKey =
|
|
135
|
-
|
|
140
|
+
typeof rawApiKey === 'string' ? rawApiKey.trim() || undefined : rawApiKey;
|
|
136
141
|
|
|
137
142
|
// Use API key authentication if available, otherwise fall back to SigV4
|
|
138
143
|
const fetchFunction = apiKey
|