@matthewdunbar/amazon-bedrock-mantle 0.0.7 → 2.0.40

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/README.md CHANGED
@@ -1,52 +1,110 @@
1
- # AI SDK - Amazon Bedrock Mantle Provider
1
+ # Amazon Bedrock Mantle Provider
2
2
 
3
- The **Amazon Bedrock Mantle** provider for the [AI SDK](https://ai-sdk.dev) uses AWS Bedrock's OpenAI-compatible endpoint (bedrock-mantle) to provide language model capabilities.
3
+ An [AI SDK](https://ai-sdk.dev/) provider that enables using Mantle models deployed on Amazon Bedrock through an OpenAI-compatible API with AWS SigV4 authentication.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @matthewdunbar/amazon-bedrock-mantle
9
+ ```
4
10
 
5
11
  ## Setup
6
12
 
7
- The Bedrock Mantle provider is available in the `@ai-sdk/amazon-bedrock-mantle` module. You can install it with:
13
+ Configure the provider with your AWS credentials and Bedrock endpoint:
8
14
 
9
- ````bash
10
- npm install @ai-sdk/amazon-bedrock-mantle
11
- ```n
12
- ## Provider Configuration
15
+ ```ts
16
+ import { createOpenAICompatible, createMantleSigV4FetchFunction } from '@matthewdunbar/amazon-bedrock-mantle';
17
+ import { generateText } from 'ai';
13
18
 
14
- You can create a Bedrock Mantle provider instance using `createAmazonBedrockMantle`:
19
+ const provider = createOpenAICompatible({
20
+ baseURL: 'https://<bedrock-endpoint>/mantle/v1',
21
+ name: 'mantle',
22
+ fetch: createMantleSigV4FetchFunction(() => ({
23
+ region: 'us-east-1',
24
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
25
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
26
+ sessionToken: process.env.AWS_SESSION_TOKEN, // optional
27
+ })),
28
+ });
15
29
 
16
- ```typescript
17
- import { createAmazonBedrockMantle } from '@ai-sdk/amazon-bedrock-mantle';
30
+ const { text } = await generateText({
31
+ model: provider.chatModel('meta-llama/Llama-3-70b-chat-hf'),
32
+ prompt: 'Write a vegetarian lasagna recipe for 4 people.',
33
+ });
34
+ ```
18
35
 
19
- const bedrockMantle = createAmazonBedrockMantle({
36
+ ## Authentication
37
+
38
+ ### AWS Credentials
39
+
40
+ Provide credentials either directly or via AWS profile:
41
+
42
+ ```ts
43
+ // Direct credentials
44
+ createMantleSigV4FetchFunction(() => ({
20
45
  region: 'us-east-1',
21
- // Authentication via API key (bearer token)
22
- apiKey: 'your-api-key',
23
- // OR authentication via AWS credentials
24
- // accessKeyId: 'your-access-key',
25
- // secretAccessKey: 'your-secret-key',
26
- });
27
- ````
46
+ accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
47
+ secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
48
+ }));
28
49
 
29
- ### Authentication
50
+ // From AWS profile
51
+ import { loadAwsProfileCredentials } from '@matthewdunbar/amazon-bedrock-mantle';
30
52
 
31
- The provider supports two authentication methods:
53
+ createMantleSigV4FetchFunction(loadAwsProfileCredentials('default'));
54
+ ```
32
55
 
33
- 1. **Bearer Token** (API Key): Set `apiKey` or `AWS_BEARER_TOKEN_BEDROCK` environment variable
34
- 2. **AWS SigV4**: Set `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables
56
+ ### Credential Refreshing
35
57
 
36
- Bearer token authentication takes precedence if both are configured.
58
+ The fetch function supports automatic credential refresh on authentication errors:
37
59
 
38
- ## Usage
60
+ ```ts
61
+ createMantleSigV4FetchFunction(
62
+ () => getFreshCredentials(),
63
+ {
64
+ refreshCredentials: () => refreshCachedCredentials(),
65
+ }
66
+ );
67
+ ```
39
68
 
40
- ```typescript
41
- import { generateText } from 'ai';
42
- import { bedrockMantle } from '@ai-sdk/amazon-bedrock-mantle';
69
+ ## Model Types
43
70
 
44
- const { text } = await generateText({
45
- model: bedrockMantle('moonshotai.kimi-k2.5'),
46
- prompt: 'Hello, how are you?',
71
+ ### Chat Models
72
+
73
+ ```ts
74
+ const model = provider.chatModel('meta-llama/Llama-3-70b-chat-hf');
75
+ ```
76
+
77
+ ### Completion Models
78
+
79
+ ```ts
80
+ const model = provider.completionModel('codellama/CodeLlama-34b-Instruct-hf');
81
+ ```
82
+
83
+ ### Embedding Models
84
+
85
+ ```ts
86
+ const model = provider.embeddingModel('BAAI/bge-large-en-v1.5');
87
+ ```
88
+
89
+ ## TypeScript Support
90
+
91
+ You can provide type-safe model IDs:
92
+
93
+ ```ts
94
+ type MantleChatModelIds =
95
+ | 'meta-llama/Llama-3-70b-chat-hf'
96
+ | 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo'
97
+ | (string & {});
98
+
99
+ const model = createOpenAICompatible<MantleChatModelIds>({
100
+ baseURL: 'https://your-endpoint/v1',
101
+ name: 'mantle',
102
+ fetch: createMantleSigV4FetchFunction(/* ... */),
47
103
  });
104
+
105
+ model.chatModel('meta-llama/Llama-3-70b-chat-hf'); // auto-complete works
48
106
  ```
49
107
 
50
- ## Documentation
108
+ ## License
51
109
 
52
- For full documentation, visit [ai-sdk.dev/docs](https://ai-sdk.dev/docs).
110
+ Apache-2.0
package/dist/index.d.mts CHANGED
@@ -1,89 +1,3 @@
1
- import { ProviderV3, LanguageModelV3, EmbeddingModelV3, ImageModelV3 } from '@ai-sdk/provider';
2
- import { FetchFunction } from '@ai-sdk/provider-utils';
1
+ declare function export_default(): void;
3
2
 
4
- interface AmazonBedrockMantleProviderSettings {
5
- /**
6
- * The AWS region to use for the Bedrock Mantle provider. Defaults to 'us-east-1'.
7
- */
8
- region?: string;
9
- /**
10
- * API key for authenticating requests using Bearer token authentication.
11
- * When provided, this will be used instead of AWS SigV4 authentication.
12
- * Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.
13
- *
14
- * Note: When `apiKey` is provided, it takes precedence over AWS SigV4 authentication.
15
- * If neither `apiKey` nor `AWS_BEARER_TOKEN_BEDROCK` environment variable is set,
16
- * the provider will fall back to AWS SigV4 authentication using AWS credentials.
17
- */
18
- apiKey?: string;
19
- /**
20
- * The AWS access key ID to use for the Bedrock Mantle provider. Defaults to the value of the
21
- * `AWS_ACCESS_KEY_ID` environment variable.
22
- */
23
- accessKeyId?: string;
24
- /**
25
- * The AWS secret access key to use for the Bedrock Mantle provider. Defaults to the value of the
26
- * `AWS_SECRET_ACCESS_KEY` environment variable.
27
- */
28
- secretAccessKey?: string;
29
- /**
30
- * The AWS session token to use for the Bedrock Mantle provider. Defaults to the value of the
31
- * `AWS_SESSION_TOKEN` environment variable.
32
- */
33
- sessionToken?: string;
34
- /**
35
- * The AWS profile to use for loading credentials from the AWS CLI configuration.
36
- * When specified, credentials will be loaded from ~/.aws/credentials for the given profile.
37
- * This uses the AWS credential provider chain to support SSO, IAM roles, etc.
38
- * This takes precedence over static credentials but is overridden by `apiKey`.
39
- */
40
- profile?: string;
41
- /**
42
- * Base URL for the Bedrock Mantle API calls. Defaults to the bedrock-mantle endpoint.
43
- */
44
- baseURL?: string;
45
- /**
46
- * Custom headers to include in the requests.
47
- */
48
- headers?: Record<string, string>;
49
- /**
50
- * Custom fetch implementation. You can use it as a middleware to intercept requests,
51
- * or to provide a custom fetch implementation for e.g. testing.
52
- */
53
- fetch?: FetchFunction;
54
- /**
55
- * The AWS credential provider to use for the Bedrock Mantle provider to get dynamic
56
- * credentials similar to the AWS SDK. Setting a provider here will cause its
57
- * credential values to be used instead of the `accessKeyId`, `secretAccessKey`,
58
- * and `sessionToken` settings.
59
- */
60
- credentialProvider?: () => PromiseLike<{
61
- accessKeyId: string;
62
- secretAccessKey: string;
63
- sessionToken?: string;
64
- }>;
65
- }
66
- type BedrockMantleChatModelId = string;
67
- type BedrockMantleEmbeddingModelId = string;
68
- type BedrockMantleImageModelId = string;
69
- interface AmazonBedrockMantleProvider extends ProviderV3 {
70
- (modelId: BedrockMantleChatModelId): LanguageModelV3;
71
- languageModel(modelId: BedrockMantleChatModelId): LanguageModelV3;
72
- chatModel(modelId: BedrockMantleChatModelId): LanguageModelV3;
73
- embeddingModel(modelId: BedrockMantleEmbeddingModelId): EmbeddingModelV3;
74
- imageModel(modelId: BedrockMantleImageModelId): ImageModelV3;
75
- }
76
- /**
77
- * Create an Amazon Bedrock Mantle provider instance.
78
- * Bedrock Mantle is AWS Bedrock's OpenAI-compatible endpoint that routes all requests
79
- * through bedrock-mantle.<region>.api.aws/v1 using OpenAI API format.
80
- */
81
- declare function createAmazonBedrockMantle(options?: AmazonBedrockMantleProviderSettings): AmazonBedrockMantleProvider;
82
- /**
83
- * Default Bedrock Mantle provider instance.
84
- */
85
- declare const bedrockMantle: AmazonBedrockMantleProvider;
86
-
87
- declare const VERSION: string;
88
-
89
- export { type AmazonBedrockMantleProvider, type AmazonBedrockMantleProviderSettings, type BedrockMantleChatModelId, VERSION, bedrockMantle, createAmazonBedrockMantle };
3
+ export { export_default as default };
package/dist/index.d.ts CHANGED
@@ -1,89 +1,3 @@
1
- import { ProviderV3, LanguageModelV3, EmbeddingModelV3, ImageModelV3 } from '@ai-sdk/provider';
2
- import { FetchFunction } from '@ai-sdk/provider-utils';
1
+ declare function export_default(): void;
3
2
 
4
- interface AmazonBedrockMantleProviderSettings {
5
- /**
6
- * The AWS region to use for the Bedrock Mantle provider. Defaults to 'us-east-1'.
7
- */
8
- region?: string;
9
- /**
10
- * API key for authenticating requests using Bearer token authentication.
11
- * When provided, this will be used instead of AWS SigV4 authentication.
12
- * Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.
13
- *
14
- * Note: When `apiKey` is provided, it takes precedence over AWS SigV4 authentication.
15
- * If neither `apiKey` nor `AWS_BEARER_TOKEN_BEDROCK` environment variable is set,
16
- * the provider will fall back to AWS SigV4 authentication using AWS credentials.
17
- */
18
- apiKey?: string;
19
- /**
20
- * The AWS access key ID to use for the Bedrock Mantle provider. Defaults to the value of the
21
- * `AWS_ACCESS_KEY_ID` environment variable.
22
- */
23
- accessKeyId?: string;
24
- /**
25
- * The AWS secret access key to use for the Bedrock Mantle provider. Defaults to the value of the
26
- * `AWS_SECRET_ACCESS_KEY` environment variable.
27
- */
28
- secretAccessKey?: string;
29
- /**
30
- * The AWS session token to use for the Bedrock Mantle provider. Defaults to the value of the
31
- * `AWS_SESSION_TOKEN` environment variable.
32
- */
33
- sessionToken?: string;
34
- /**
35
- * The AWS profile to use for loading credentials from the AWS CLI configuration.
36
- * When specified, credentials will be loaded from ~/.aws/credentials for the given profile.
37
- * This uses the AWS credential provider chain to support SSO, IAM roles, etc.
38
- * This takes precedence over static credentials but is overridden by `apiKey`.
39
- */
40
- profile?: string;
41
- /**
42
- * Base URL for the Bedrock Mantle API calls. Defaults to the bedrock-mantle endpoint.
43
- */
44
- baseURL?: string;
45
- /**
46
- * Custom headers to include in the requests.
47
- */
48
- headers?: Record<string, string>;
49
- /**
50
- * Custom fetch implementation. You can use it as a middleware to intercept requests,
51
- * or to provide a custom fetch implementation for e.g. testing.
52
- */
53
- fetch?: FetchFunction;
54
- /**
55
- * The AWS credential provider to use for the Bedrock Mantle provider to get dynamic
56
- * credentials similar to the AWS SDK. Setting a provider here will cause its
57
- * credential values to be used instead of the `accessKeyId`, `secretAccessKey`,
58
- * and `sessionToken` settings.
59
- */
60
- credentialProvider?: () => PromiseLike<{
61
- accessKeyId: string;
62
- secretAccessKey: string;
63
- sessionToken?: string;
64
- }>;
65
- }
66
- type BedrockMantleChatModelId = string;
67
- type BedrockMantleEmbeddingModelId = string;
68
- type BedrockMantleImageModelId = string;
69
- interface AmazonBedrockMantleProvider extends ProviderV3 {
70
- (modelId: BedrockMantleChatModelId): LanguageModelV3;
71
- languageModel(modelId: BedrockMantleChatModelId): LanguageModelV3;
72
- chatModel(modelId: BedrockMantleChatModelId): LanguageModelV3;
73
- embeddingModel(modelId: BedrockMantleEmbeddingModelId): EmbeddingModelV3;
74
- imageModel(modelId: BedrockMantleImageModelId): ImageModelV3;
75
- }
76
- /**
77
- * Create an Amazon Bedrock Mantle provider instance.
78
- * Bedrock Mantle is AWS Bedrock's OpenAI-compatible endpoint that routes all requests
79
- * through bedrock-mantle.<region>.api.aws/v1 using OpenAI API format.
80
- */
81
- declare function createAmazonBedrockMantle(options?: AmazonBedrockMantleProviderSettings): AmazonBedrockMantleProvider;
82
- /**
83
- * Default Bedrock Mantle provider instance.
84
- */
85
- declare const bedrockMantle: AmazonBedrockMantleProvider;
86
-
87
- declare const VERSION: string;
88
-
89
- export { type AmazonBedrockMantleProvider, type AmazonBedrockMantleProviderSettings, type BedrockMantleChatModelId, VERSION, bedrockMantle, createAmazonBedrockMantle };
3
+ export { export_default as default };
package/dist/index.js CHANGED
@@ -18,145 +18,11 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- VERSION: () => VERSION,
24
- bedrockMantle: () => bedrockMantle,
25
- createAmazonBedrockMantle: () => createAmazonBedrockMantle
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ default: () => index_default
26
24
  });
27
- module.exports = __toCommonJS(src_exports);
28
-
29
- // src/bedrock-mantle-provider.ts
30
- var import_provider_utils = require("@ai-sdk/provider-utils");
31
- var import_openai_compatible = require("@ai-sdk/openai-compatible");
32
- var import_aws4fetch = require("aws4fetch");
33
- var import_credential_providers = require("@aws-sdk/credential-providers");
34
- function createMantleSigV4FetchFunction(getCredentials, fetchImpl = globalThis.fetch) {
35
- return async (input, init) => {
36
- var _a, _b;
37
- const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
38
- const body = typeof (init == null ? void 0 : init.body) === "string" ? init.body : (init == null ? void 0 : init.body) ? JSON.stringify(init.body) : void 0;
39
- const headers = (_a = init == null ? void 0 : init.headers) != null ? _a : {};
40
- const headerEntries = headers instanceof Headers ? Array.from(headers.entries()) : Array.isArray(headers) ? headers : Object.entries(headers);
41
- const credentials = await getCredentials();
42
- const signer = new import_aws4fetch.AwsV4Signer({
43
- url,
44
- method: (_b = init == null ? void 0 : init.method) != null ? _b : "POST",
45
- headers: headerEntries,
46
- body,
47
- region: credentials.region,
48
- accessKeyId: credentials.accessKeyId,
49
- secretAccessKey: credentials.secretAccessKey,
50
- sessionToken: credentials.sessionToken,
51
- service: "bedrock-mantle"
52
- });
53
- const signed = await signer.sign();
54
- return fetchImpl(input, {
55
- ...init,
56
- body,
57
- headers: Object.fromEntries(signed.headers.entries())
58
- });
59
- };
60
- }
61
- function createAmazonBedrockMantle(options = {}) {
62
- var _a, _b, _c, _d, _e, _f, _g, _h;
63
- const region = (_b = (_a = options.region) != null ? _a : (0, import_provider_utils.loadOptionalSetting)({
64
- settingValue: void 0,
65
- environmentVariableName: "AWS_REGION"
66
- })) != null ? _b : "us-east-1";
67
- const rawApiKey = (0, import_provider_utils.loadOptionalSetting)({
68
- settingValue: options.apiKey,
69
- environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
70
- });
71
- const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
72
- let fetchFunction;
73
- if (apiKey) {
74
- fetchFunction = (_c = options.fetch) != null ? _c : globalThis.fetch;
75
- } else if (options.profile) {
76
- const credentialProvider = (0, import_credential_providers.fromNodeProviderChain)({
77
- profile: options.profile
78
- });
79
- fetchFunction = createMantleSigV4FetchFunction(async () => {
80
- const creds = await credentialProvider();
81
- return {
82
- ...creds,
83
- region
84
- };
85
- }, options.fetch);
86
- } else if (options.credentialProvider) {
87
- fetchFunction = createMantleSigV4FetchFunction(async () => {
88
- return {
89
- ...await options.credentialProvider(),
90
- region
91
- };
92
- }, options.fetch);
93
- } else {
94
- const accessKeyId = (_d = options.accessKeyId) != null ? _d : (0, import_provider_utils.loadOptionalSetting)({
95
- settingValue: void 0,
96
- environmentVariableName: "AWS_ACCESS_KEY_ID"
97
- });
98
- const secretAccessKey = (_e = options.secretAccessKey) != null ? _e : (0, import_provider_utils.loadOptionalSetting)({
99
- settingValue: void 0,
100
- environmentVariableName: "AWS_SECRET_ACCESS_KEY"
101
- });
102
- const sessionToken = (_f = options.sessionToken) != null ? _f : (0, import_provider_utils.loadOptionalSetting)({
103
- settingValue: void 0,
104
- environmentVariableName: "AWS_SESSION_TOKEN"
105
- });
106
- if (!accessKeyId || !secretAccessKey) {
107
- const credentialProvider = (0, import_credential_providers.fromNodeProviderChain)();
108
- fetchFunction = createMantleSigV4FetchFunction(async () => {
109
- const creds = await credentialProvider();
110
- return {
111
- ...creds,
112
- region
113
- };
114
- }, options.fetch);
115
- } else {
116
- fetchFunction = createMantleSigV4FetchFunction(async () => {
117
- return {
118
- region,
119
- accessKeyId,
120
- secretAccessKey,
121
- sessionToken
122
- };
123
- }, options.fetch);
124
- }
125
- }
126
- const baseURL = (_h = (0, import_provider_utils.withoutTrailingSlash)(
127
- (_g = options.baseURL) != null ? _g : `https://bedrock-mantle.${region}.api.aws/v1`
128
- )) != null ? _h : `https://bedrock-mantle.us-east-1.api.aws/v1`;
129
- const mantleProvider = (0, import_openai_compatible.createOpenAICompatible)({
130
- baseURL,
131
- name: "amazon-bedrock-mantle",
132
- apiKey: apiKey != null ? apiKey : "dummy-key-for-sigv4",
133
- fetch: fetchFunction,
134
- headers: options.headers,
135
- includeUsage: false
136
- });
137
- const provider = function(modelId) {
138
- if (new.target) {
139
- throw new Error(
140
- "The Amazon Bedrock Mantle model function cannot be called with the new keyword."
141
- );
142
- }
143
- return mantleProvider.languageModel(modelId);
144
- };
145
- provider.specificationVersion = "v3";
146
- provider.languageModel = mantleProvider.languageModel;
147
- provider.chatModel = mantleProvider.languageModel;
148
- provider.embeddingModel = mantleProvider.embeddingModel;
149
- provider.imageModel = mantleProvider.imageModel;
150
- return provider;
25
+ module.exports = __toCommonJS(index_exports);
26
+ function index_default() {
151
27
  }
152
- var bedrockMantle = createAmazonBedrockMantle();
153
-
154
- // src/version.ts
155
- var VERSION = true ? "0.0.6" : "0.0.0-test";
156
- // Annotate the CommonJS export names for ESM import in node:
157
- 0 && (module.exports = {
158
- VERSION,
159
- bedrockMantle,
160
- createAmazonBedrockMantle
161
- });
162
28
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/bedrock-mantle-provider.ts","../src/version.ts"],"sourcesContent":["export {\n bedrockMantle,\n createAmazonBedrockMantle,\n} from './bedrock-mantle-provider';\nexport type {\n AmazonBedrockMantleProvider,\n AmazonBedrockMantleProviderSettings,\n BedrockMantleChatModelId,\n} from './bedrock-mantle-provider';\nexport { VERSION } from './version';\n","import {\n EmbeddingModelV3,\n ImageModelV3,\n LanguageModelV3,\n ProviderV3,\n} from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadOptionalSetting,\n withoutTrailingSlash,\n} from '@ai-sdk/provider-utils';\nimport {\n createOpenAICompatible,\n OpenAICompatibleProvider,\n} from '@ai-sdk/openai-compatible';\nimport { AwsV4Signer } from 'aws4fetch';\nimport { fromNodeProviderChain } from '@aws-sdk/credential-providers';\n\nexport interface AmazonBedrockMantleProviderSettings {\n /**\n * The AWS region to use for the Bedrock Mantle provider. Defaults to 'us-east-1'.\n */\n region?: string;\n\n /**\n * API key for authenticating requests using Bearer token authentication.\n * When provided, this will be used instead of AWS SigV4 authentication.\n * Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.\n *\n * Note: When `apiKey` is provided, it takes precedence over AWS SigV4 authentication.\n * If neither `apiKey` nor `AWS_BEARER_TOKEN_BEDROCK` environment variable is set,\n * the provider will fall back to AWS SigV4 authentication using AWS credentials.\n */\n apiKey?: string;\n\n /**\n * The AWS access key ID to use for the Bedrock Mantle provider. Defaults to the value of the\n * `AWS_ACCESS_KEY_ID` environment variable.\n */\n accessKeyId?: string;\n\n /**\n * The AWS secret access key to use for the Bedrock Mantle provider. Defaults to the value of the\n * `AWS_SECRET_ACCESS_KEY` environment variable.\n */\n secretAccessKey?: string;\n\n /**\n * The AWS session token to use for the Bedrock Mantle provider. Defaults to the value of the\n * `AWS_SESSION_TOKEN` environment variable.\n */\n sessionToken?: string;\n\n /**\n * The AWS profile to use for loading credentials from the AWS CLI configuration.\n * When specified, credentials will be loaded from ~/.aws/credentials for the given profile.\n * This uses the AWS credential provider chain to support SSO, IAM roles, etc.\n * This takes precedence over static credentials but is overridden by `apiKey`.\n */\n profile?: string;\n\n /**\n * Base URL for the Bedrock Mantle API calls. Defaults to the bedrock-mantle endpoint.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * The AWS credential provider to use for the Bedrock Mantle provider to get dynamic\n * credentials similar to the AWS SDK. Setting a provider here will cause its\n * credential values to be used instead of the `accessKeyId`, `secretAccessKey`,\n * and `sessionToken` settings.\n */\n credentialProvider?: () => PromiseLike<{\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n }>;\n}\n\nexport type BedrockMantleChatModelId = string;\nexport type BedrockMantleEmbeddingModelId = string;\nexport type BedrockMantleImageModelId = string;\n\nexport interface AmazonBedrockMantleProvider extends ProviderV3 {\n (modelId: BedrockMantleChatModelId): LanguageModelV3;\n\n languageModel(modelId: BedrockMantleChatModelId): LanguageModelV3;\n\n chatModel(modelId: BedrockMantleChatModelId): LanguageModelV3;\n\n embeddingModel(modelId: BedrockMantleEmbeddingModelId): EmbeddingModelV3;\n\n imageModel(modelId: BedrockMantleImageModelId): ImageModelV3;\n}\n\ninterface BedrockCredentials {\n region: string;\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n}\n\n/**\n * Creates a fetch function that applies AWS Signature Version 4 signing for bedrock-mantle service.\n *\n * @param getCredentials - Function that returns the AWS credentials to use when signing.\n * @param fetchImpl - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @returns A FetchFunction that signs requests before passing them to the underlying fetch.\n */\nfunction createMantleSigV4FetchFunction(\n getCredentials: () => BedrockCredentials | PromiseLike<BedrockCredentials>,\n fetchImpl: FetchFunction = globalThis.fetch,\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n const url =\n typeof input === 'string'\n ? input\n : input instanceof URL\n ? input.href\n : input.url;\n\n const body =\n typeof init?.body === 'string'\n ? init.body\n : init?.body\n ? JSON.stringify(init.body)\n : undefined;\n\n const headers = init?.headers ?? {};\n const headerEntries =\n headers instanceof Headers\n ? Array.from(headers.entries())\n : Array.isArray(headers)\n ? headers\n : Object.entries(headers);\n\n const credentials = await getCredentials();\n const signer = new AwsV4Signer({\n url,\n method: init?.method ?? 'POST',\n headers: headerEntries,\n body,\n region: credentials.region,\n accessKeyId: credentials.accessKeyId,\n secretAccessKey: credentials.secretAccessKey,\n sessionToken: credentials.sessionToken,\n service: 'bedrock-mantle',\n });\n\n const signed = await signer.sign();\n return fetchImpl(input, {\n ...init,\n body,\n headers: Object.fromEntries(signed.headers.entries()),\n });\n };\n}\n\n/**\n * Create an Amazon Bedrock Mantle provider instance.\n * Bedrock Mantle is AWS Bedrock's OpenAI-compatible endpoint that routes all requests\n * through bedrock-mantle.<region>.api.aws/v1 using OpenAI API format.\n */\nexport function createAmazonBedrockMantle(\n options: AmazonBedrockMantleProviderSettings = {},\n): AmazonBedrockMantleProvider {\n // Get region - use option first, then environment variable, then default to us-east-1\n const region =\n options.region ??\n loadOptionalSetting({\n settingValue: undefined,\n environmentVariableName: 'AWS_REGION',\n }) ??\n 'us-east-1';\n\n // Check for API key authentication\n const rawApiKey = loadOptionalSetting({\n settingValue: options.apiKey,\n environmentVariableName: 'AWS_BEARER_TOKEN_BEDROCK',\n });\n\n // Only use API key if it's a non-empty, non-whitespace string\n const apiKey =\n rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : undefined;\n\n // Use API key authentication if available, otherwise fall back to SigV4\n let fetchFunction: FetchFunction;\n if (apiKey) {\n fetchFunction = options.fetch ?? globalThis.fetch;\n } else if (options.profile) {\n // Use AWS credential provider chain with profile\n const credentialProvider = fromNodeProviderChain({\n profile: options.profile,\n });\n fetchFunction = createMantleSigV4FetchFunction(async () => {\n const creds = await credentialProvider();\n return {\n ...creds,\n region,\n };\n }, options.fetch);\n } else if (options.credentialProvider) {\n fetchFunction = createMantleSigV4FetchFunction(async () => {\n return {\n ...(await options.credentialProvider!()),\n region,\n };\n }, options.fetch);\n } else {\n // For static credentials, load from options or environment variables\n const accessKeyId =\n options.accessKeyId ??\n loadOptionalSetting({\n settingValue: undefined,\n environmentVariableName: 'AWS_ACCESS_KEY_ID',\n });\n\n const secretAccessKey =\n options.secretAccessKey ??\n loadOptionalSetting({\n settingValue: undefined,\n environmentVariableName: 'AWS_SECRET_ACCESS_KEY',\n });\n\n const sessionToken =\n options.sessionToken ??\n loadOptionalSetting({\n settingValue: undefined,\n environmentVariableName: 'AWS_SESSION_TOKEN',\n });\n\n // If no static credentials, use the default credential provider chain\n if (!accessKeyId || !secretAccessKey) {\n const credentialProvider = fromNodeProviderChain();\n fetchFunction = createMantleSigV4FetchFunction(async () => {\n const creds = await credentialProvider();\n return {\n ...creds,\n region,\n };\n }, options.fetch);\n } else {\n fetchFunction = createMantleSigV4FetchFunction(async () => {\n return {\n region,\n accessKeyId: accessKeyId!,\n secretAccessKey: secretAccessKey!,\n sessionToken,\n };\n }, options.fetch);\n }\n }\n\n const baseURL =\n withoutTrailingSlash(\n options.baseURL ?? `https://bedrock-mantle.${region}.api.aws/v1`,\n ) ?? `https://bedrock-mantle.us-east-1.api.aws/v1`;\n\n // Create the OpenAI-compatible provider\n const mantleProvider: OpenAICompatibleProvider<\n string,\n string,\n string,\n string\n > = createOpenAICompatible({\n baseURL,\n name: 'amazon-bedrock-mantle',\n apiKey: apiKey ?? 'dummy-key-for-sigv4',\n fetch: fetchFunction,\n headers: options.headers,\n includeUsage: false,\n });\n\n const provider = function (modelId: BedrockMantleChatModelId) {\n if (new.target) {\n throw new Error(\n 'The Amazon Bedrock Mantle model function cannot be called with the new keyword.',\n );\n }\n return mantleProvider.languageModel(modelId);\n };\n\n provider.specificationVersion = 'v3' as const;\n provider.languageModel = mantleProvider.languageModel;\n provider.chatModel = mantleProvider.languageModel;\n provider.embeddingModel = mantleProvider.embeddingModel;\n provider.imageModel = mantleProvider.imageModel;\n\n return provider as AmazonBedrockMantleProvider;\n}\n\n/**\n * Default Bedrock Mantle provider instance.\n */\nexport const bedrockMantle = createAmazonBedrockMantle();\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,4BAIO;AACP,+BAGO;AACP,uBAA4B;AAC5B,kCAAsC;AAwGtC,SAAS,+BACP,gBACA,YAA2B,WAAW,OACvB;AACf,SAAO,OACL,OACA,SACsB;AA/H1B;AAgII,UAAM,MACJ,OAAO,UAAU,WACb,QACA,iBAAiB,MACf,MAAM,OACN,MAAM;AAEd,UAAM,OACJ,QAAO,6BAAM,UAAS,WAClB,KAAK,QACL,6BAAM,QACJ,KAAK,UAAU,KAAK,IAAI,IACxB;AAER,UAAM,WAAU,kCAAM,YAAN,YAAiB,CAAC;AAClC,UAAM,gBACJ,mBAAmB,UACf,MAAM,KAAK,QAAQ,QAAQ,CAAC,IAC5B,MAAM,QAAQ,OAAO,IACnB,UACA,OAAO,QAAQ,OAAO;AAE9B,UAAM,cAAc,MAAM,eAAe;AACzC,UAAM,SAAS,IAAI,6BAAY;AAAA,MAC7B;AAAA,MACA,SAAQ,kCAAM,WAAN,YAAgB;AAAA,MACxB,SAAS;AAAA,MACT;AAAA,MACA,QAAQ,YAAY;AAAA,MACpB,aAAa,YAAY;AAAA,MACzB,iBAAiB,YAAY;AAAA,MAC7B,cAAc,YAAY;AAAA,MAC1B,SAAS;AAA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AEH,UAAM,gBACJ,aAAQ,iBAAR,gBACA,2CAAoB;AAAA,MAClB,cAAc;AAAA,MACd,yBAAyB;AAAA,IAC3B,CAAC;AAGH,QAAI,CAAC,eAAe,CAAC,iBAAiB;AACpC,YAAM,yBAAqB,mDAAsB;AACjD,sBAAgB,+BAA+B,YAAY;AACzD,cAAM,QAAQ,MAAM,mBAAmB;AACvC,eAAO;AAAA,UACL,GAAG;AAAA,UACH;AAAA,QACF;AAAA,MACF,GAAG,QAAQ,KAAK;AAAA,IAClB,OAAO;AACL,sBAAgB,+BAA+B,YAAY;AACzD,eAAO;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF,GAAG,QAAQ,KAAK;AAAA,IAClB;AAAA,EACF;AAEA,QAAM,WACJ;AAAA,KACE,aAAQ,YAAR,YAAmB,0BAA0B,MAAM;AAAA,EACrD,MAFA,YAEK;AAGP,QAAM,qBAKF,iDAAuB;AAAA,IACzB;AAAA,IACA,MAAM;AAAA,IACN,QAAQ,0BAAU;AAAA,IAClB,OAAO;AAAA,IACP,SAAS,QAAQ;AAAA,IACjB,cAAc;AAAA,EAChB,CAAC;AAED,QAAM,WAAW,SAAU,SAAmC;AAC5D,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,WAAO,eAAe,cAAc,OAAO;AAAA,EAC7C;AAEA,WAAS,uBAAuB;AAChC,WAAS,gBAAgB,eAAe;AACxC,WAAS,YAAY,eAAe;AACpC,WAAS,iBAAiB,eAAe;AACzC,WAAS,aAAa,eAAe;AAErC,SAAO;AACT;AAKO,IAAM,gBAAgB,0BAA0B;;;AClThD,IAAM,UACX,OACI,UACA;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export default function () {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAe,SAAR,gBAAoB;AAAC;","names":[]}
package/dist/index.mjs CHANGED
@@ -1,138 +1,7 @@
1
- // src/bedrock-mantle-provider.ts
2
- import {
3
- loadOptionalSetting,
4
- withoutTrailingSlash
5
- } from "@ai-sdk/provider-utils";
6
- import {
7
- createOpenAICompatible
8
- } from "@ai-sdk/openai-compatible";
9
- import { AwsV4Signer } from "aws4fetch";
10
- import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
11
- function createMantleSigV4FetchFunction(getCredentials, fetchImpl = globalThis.fetch) {
12
- return async (input, init) => {
13
- var _a, _b;
14
- const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
15
- const body = typeof (init == null ? void 0 : init.body) === "string" ? init.body : (init == null ? void 0 : init.body) ? JSON.stringify(init.body) : void 0;
16
- const headers = (_a = init == null ? void 0 : init.headers) != null ? _a : {};
17
- const headerEntries = headers instanceof Headers ? Array.from(headers.entries()) : Array.isArray(headers) ? headers : Object.entries(headers);
18
- const credentials = await getCredentials();
19
- const signer = new AwsV4Signer({
20
- url,
21
- method: (_b = init == null ? void 0 : init.method) != null ? _b : "POST",
22
- headers: headerEntries,
23
- body,
24
- region: credentials.region,
25
- accessKeyId: credentials.accessKeyId,
26
- secretAccessKey: credentials.secretAccessKey,
27
- sessionToken: credentials.sessionToken,
28
- service: "bedrock-mantle"
29
- });
30
- const signed = await signer.sign();
31
- return fetchImpl(input, {
32
- ...init,
33
- body,
34
- headers: Object.fromEntries(signed.headers.entries())
35
- });
36
- };
1
+ // src/index.ts
2
+ function index_default() {
37
3
  }
38
- function createAmazonBedrockMantle(options = {}) {
39
- var _a, _b, _c, _d, _e, _f, _g, _h;
40
- const region = (_b = (_a = options.region) != null ? _a : loadOptionalSetting({
41
- settingValue: void 0,
42
- environmentVariableName: "AWS_REGION"
43
- })) != null ? _b : "us-east-1";
44
- const rawApiKey = loadOptionalSetting({
45
- settingValue: options.apiKey,
46
- environmentVariableName: "AWS_BEARER_TOKEN_BEDROCK"
47
- });
48
- const apiKey = rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : void 0;
49
- let fetchFunction;
50
- if (apiKey) {
51
- fetchFunction = (_c = options.fetch) != null ? _c : globalThis.fetch;
52
- } else if (options.profile) {
53
- const credentialProvider = fromNodeProviderChain({
54
- profile: options.profile
55
- });
56
- fetchFunction = createMantleSigV4FetchFunction(async () => {
57
- const creds = await credentialProvider();
58
- return {
59
- ...creds,
60
- region
61
- };
62
- }, options.fetch);
63
- } else if (options.credentialProvider) {
64
- fetchFunction = createMantleSigV4FetchFunction(async () => {
65
- return {
66
- ...await options.credentialProvider(),
67
- region
68
- };
69
- }, options.fetch);
70
- } else {
71
- const accessKeyId = (_d = options.accessKeyId) != null ? _d : loadOptionalSetting({
72
- settingValue: void 0,
73
- environmentVariableName: "AWS_ACCESS_KEY_ID"
74
- });
75
- const secretAccessKey = (_e = options.secretAccessKey) != null ? _e : loadOptionalSetting({
76
- settingValue: void 0,
77
- environmentVariableName: "AWS_SECRET_ACCESS_KEY"
78
- });
79
- const sessionToken = (_f = options.sessionToken) != null ? _f : loadOptionalSetting({
80
- settingValue: void 0,
81
- environmentVariableName: "AWS_SESSION_TOKEN"
82
- });
83
- if (!accessKeyId || !secretAccessKey) {
84
- const credentialProvider = fromNodeProviderChain();
85
- fetchFunction = createMantleSigV4FetchFunction(async () => {
86
- const creds = await credentialProvider();
87
- return {
88
- ...creds,
89
- region
90
- };
91
- }, options.fetch);
92
- } else {
93
- fetchFunction = createMantleSigV4FetchFunction(async () => {
94
- return {
95
- region,
96
- accessKeyId,
97
- secretAccessKey,
98
- sessionToken
99
- };
100
- }, options.fetch);
101
- }
102
- }
103
- const baseURL = (_h = withoutTrailingSlash(
104
- (_g = options.baseURL) != null ? _g : `https://bedrock-mantle.${region}.api.aws/v1`
105
- )) != null ? _h : `https://bedrock-mantle.us-east-1.api.aws/v1`;
106
- const mantleProvider = createOpenAICompatible({
107
- baseURL,
108
- name: "amazon-bedrock-mantle",
109
- apiKey: apiKey != null ? apiKey : "dummy-key-for-sigv4",
110
- fetch: fetchFunction,
111
- headers: options.headers,
112
- includeUsage: false
113
- });
114
- const provider = function(modelId) {
115
- if (new.target) {
116
- throw new Error(
117
- "The Amazon Bedrock Mantle model function cannot be called with the new keyword."
118
- );
119
- }
120
- return mantleProvider.languageModel(modelId);
121
- };
122
- provider.specificationVersion = "v3";
123
- provider.languageModel = mantleProvider.languageModel;
124
- provider.chatModel = mantleProvider.languageModel;
125
- provider.embeddingModel = mantleProvider.embeddingModel;
126
- provider.imageModel = mantleProvider.imageModel;
127
- return provider;
128
- }
129
- var bedrockMantle = createAmazonBedrockMantle();
130
-
131
- // src/version.ts
132
- var VERSION = true ? "0.0.6" : "0.0.0-test";
133
4
  export {
134
- VERSION,
135
- bedrockMantle,
136
- createAmazonBedrockMantle
5
+ index_default as default
137
6
  };
138
7
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/bedrock-mantle-provider.ts","../src/version.ts"],"sourcesContent":["import {\n EmbeddingModelV3,\n ImageModelV3,\n LanguageModelV3,\n ProviderV3,\n} from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadOptionalSetting,\n withoutTrailingSlash,\n} from '@ai-sdk/provider-utils';\nimport {\n createOpenAICompatible,\n OpenAICompatibleProvider,\n} from '@ai-sdk/openai-compatible';\nimport { AwsV4Signer } from 'aws4fetch';\nimport { fromNodeProviderChain } from '@aws-sdk/credential-providers';\n\nexport interface AmazonBedrockMantleProviderSettings {\n /**\n * The AWS region to use for the Bedrock Mantle provider. Defaults to 'us-east-1'.\n */\n region?: string;\n\n /**\n * API key for authenticating requests using Bearer token authentication.\n * When provided, this will be used instead of AWS SigV4 authentication.\n * Defaults to the value of the `AWS_BEARER_TOKEN_BEDROCK` environment variable.\n *\n * Note: When `apiKey` is provided, it takes precedence over AWS SigV4 authentication.\n * If neither `apiKey` nor `AWS_BEARER_TOKEN_BEDROCK` environment variable is set,\n * the provider will fall back to AWS SigV4 authentication using AWS credentials.\n */\n apiKey?: string;\n\n /**\n * The AWS access key ID to use for the Bedrock Mantle provider. Defaults to the value of the\n * `AWS_ACCESS_KEY_ID` environment variable.\n */\n accessKeyId?: string;\n\n /**\n * The AWS secret access key to use for the Bedrock Mantle provider. Defaults to the value of the\n * `AWS_SECRET_ACCESS_KEY` environment variable.\n */\n secretAccessKey?: string;\n\n /**\n * The AWS session token to use for the Bedrock Mantle provider. Defaults to the value of the\n * `AWS_SESSION_TOKEN` environment variable.\n */\n sessionToken?: string;\n\n /**\n * The AWS profile to use for loading credentials from the AWS CLI configuration.\n * When specified, credentials will be loaded from ~/.aws/credentials for the given profile.\n * This uses the AWS credential provider chain to support SSO, IAM roles, etc.\n * This takes precedence over static credentials but is overridden by `apiKey`.\n */\n profile?: string;\n\n /**\n * Base URL for the Bedrock Mantle API calls. Defaults to the bedrock-mantle endpoint.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * The AWS credential provider to use for the Bedrock Mantle provider to get dynamic\n * credentials similar to the AWS SDK. Setting a provider here will cause its\n * credential values to be used instead of the `accessKeyId`, `secretAccessKey`,\n * and `sessionToken` settings.\n */\n credentialProvider?: () => PromiseLike<{\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n }>;\n}\n\nexport type BedrockMantleChatModelId = string;\nexport type BedrockMantleEmbeddingModelId = string;\nexport type BedrockMantleImageModelId = string;\n\nexport interface AmazonBedrockMantleProvider extends ProviderV3 {\n (modelId: BedrockMantleChatModelId): LanguageModelV3;\n\n languageModel(modelId: BedrockMantleChatModelId): LanguageModelV3;\n\n chatModel(modelId: BedrockMantleChatModelId): LanguageModelV3;\n\n embeddingModel(modelId: BedrockMantleEmbeddingModelId): EmbeddingModelV3;\n\n imageModel(modelId: BedrockMantleImageModelId): ImageModelV3;\n}\n\ninterface BedrockCredentials {\n region: string;\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken?: string;\n}\n\n/**\n * Creates a fetch function that applies AWS Signature Version 4 signing for bedrock-mantle service.\n *\n * @param getCredentials - Function that returns the AWS credentials to use when signing.\n * @param fetchImpl - Optional original fetch implementation to wrap. Defaults to global fetch.\n * @returns A FetchFunction that signs requests before passing them to the underlying fetch.\n */\nfunction createMantleSigV4FetchFunction(\n getCredentials: () => BedrockCredentials | PromiseLike<BedrockCredentials>,\n fetchImpl: FetchFunction = globalThis.fetch,\n): FetchFunction {\n return async (\n input: RequestInfo | URL,\n init?: RequestInit,\n ): Promise<Response> => {\n const url =\n typeof input === 'string'\n ? input\n : input instanceof URL\n ? input.href\n : input.url;\n\n const body =\n typeof init?.body === 'string'\n ? init.body\n : init?.body\n ? JSON.stringify(init.body)\n : undefined;\n\n const headers = init?.headers ?? {};\n const headerEntries =\n headers instanceof Headers\n ? Array.from(headers.entries())\n : Array.isArray(headers)\n ? headers\n : Object.entries(headers);\n\n const credentials = await getCredentials();\n const signer = new AwsV4Signer({\n url,\n method: init?.method ?? 'POST',\n headers: headerEntries,\n body,\n region: credentials.region,\n accessKeyId: credentials.accessKeyId,\n secretAccessKey: credentials.secretAccessKey,\n sessionToken: credentials.sessionToken,\n service: 'bedrock-mantle',\n });\n\n const signed = await signer.sign();\n return fetchImpl(input, {\n ...init,\n body,\n headers: Object.fromEntries(signed.headers.entries()),\n });\n };\n}\n\n/**\n * Create an Amazon Bedrock Mantle provider instance.\n * Bedrock Mantle is AWS Bedrock's OpenAI-compatible endpoint that routes all requests\n * through bedrock-mantle.<region>.api.aws/v1 using OpenAI API format.\n */\nexport function createAmazonBedrockMantle(\n options: AmazonBedrockMantleProviderSettings = {},\n): AmazonBedrockMantleProvider {\n // Get region - use option first, then environment variable, then default to us-east-1\n const region =\n options.region ??\n loadOptionalSetting({\n settingValue: undefined,\n environmentVariableName: 'AWS_REGION',\n }) ??\n 'us-east-1';\n\n // Check for API key authentication\n const rawApiKey = loadOptionalSetting({\n settingValue: options.apiKey,\n environmentVariableName: 'AWS_BEARER_TOKEN_BEDROCK',\n });\n\n // Only use API key if it's a non-empty, non-whitespace string\n const apiKey =\n rawApiKey && rawApiKey.trim().length > 0 ? rawApiKey.trim() : undefined;\n\n // Use API key authentication if available, otherwise fall back to SigV4\n let fetchFunction: FetchFunction;\n if (apiKey) {\n fetchFunction = options.fetch ?? globalThis.fetch;\n } else if (options.profile) {\n // Use AWS credential provider chain with profile\n const credentialProvider = fromNodeProviderChain({\n profile: options.profile,\n });\n fetchFunction = createMantleSigV4FetchFunction(async () => {\n const creds = await credentialProvider();\n return {\n ...creds,\n region,\n };\n }, options.fetch);\n } else if (options.credentialProvider) {\n fetchFunction = createMantleSigV4FetchFunction(async () => {\n return {\n ...(await options.credentialProvider!()),\n region,\n };\n }, options.fetch);\n } else {\n // For static credentials, load from options or environment variables\n const accessKeyId =\n options.accessKeyId ??\n loadOptionalSetting({\n settingValue: undefined,\n environmentVariableName: 'AWS_ACCESS_KEY_ID',\n });\n\n const secretAccessKey =\n options.secretAccessKey ??\n loadOptionalSetting({\n settingValue: undefined,\n environmentVariableName: 'AWS_SECRET_ACCESS_KEY',\n });\n\n const sessionToken =\n options.sessionToken ??\n loadOptionalSetting({\n settingValue: undefined,\n environmentVariableName: 'AWS_SESSION_TOKEN',\n });\n\n // If no static credentials, use the default credential provider chain\n if (!accessKeyId || !secretAccessKey) {\n const credentialProvider = fromNodeProviderChain();\n fetchFunction = createMantleSigV4FetchFunction(async () => {\n const creds = await credentialProvider();\n return {\n ...creds,\n region,\n };\n }, options.fetch);\n } else {\n fetchFunction = createMantleSigV4FetchFunction(async () => {\n return {\n region,\n accessKeyId: accessKeyId!,\n secretAccessKey: secretAccessKey!,\n sessionToken,\n };\n }, options.fetch);\n }\n }\n\n const baseURL =\n withoutTrailingSlash(\n options.baseURL ?? `https://bedrock-mantle.${region}.api.aws/v1`,\n ) ?? `https://bedrock-mantle.us-east-1.api.aws/v1`;\n\n // Create the OpenAI-compatible provider\n const mantleProvider: OpenAICompatibleProvider<\n string,\n string,\n string,\n string\n > = createOpenAICompatible({\n baseURL,\n name: 'amazon-bedrock-mantle',\n apiKey: apiKey ?? 'dummy-key-for-sigv4',\n fetch: fetchFunction,\n headers: options.headers,\n includeUsage: false,\n });\n\n const provider = function (modelId: BedrockMantleChatModelId) {\n if (new.target) {\n throw new Error(\n 'The Amazon Bedrock Mantle model function cannot be called with the new keyword.',\n );\n }\n return mantleProvider.languageModel(modelId);\n };\n\n provider.specificationVersion = 'v3' as const;\n provider.languageModel = mantleProvider.languageModel;\n provider.chatModel = mantleProvider.languageModel;\n provider.embeddingModel = mantleProvider.embeddingModel;\n provider.imageModel = mantleProvider.imageModel;\n\n return provider as AmazonBedrockMantleProvider;\n}\n\n/**\n * Default Bedrock Mantle provider instance.\n */\nexport const bedrockMantle = createAmazonBedrockMantle();\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAMA;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,OAEK;AACP,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AAwGtC,SAAS,+BACP,gBACA,YAA2B,WAAW,OACvB;AACf,SAAO,OACL,OACA,SACsB;AA/H1B;AAgII,UAAM,MACJ,OAAO,UAAU,WACb,QACA,iBAAiB,MACf,MAAM,OACN,MAAM;AAEd,UAAM,OACJ,QAAO,6BAAM,UAAS,WAClB,KAAK,QACL,6BAAM,QACJ,KAAK,UAAU,KAAK,IAAI,IACxB;AAER,UAAM,WAAU,kCAAM,YAAN,YAAiB,CAAC;AAClC,UAAM,gBACJ,mBAAmB,UACf,MAAM,KAAK,QAAQ,QAAQ,CAAC,IAC5B,MAAM,QAAQ,OAAO,IACnB,UACA,OAAO,QAAQ,OAAO;AAE9B,UAAM,cAAc,MAAM,e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;AACT;AAKO,IAAM,gBAAgB,0BAA0B;;;AClThD,IAAM,UACX,OACI,UACA;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export default function () {}\n"],"mappings":";AAAe,SAAR,gBAAoB;AAAC;","names":[]}
package/internal.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/internal';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matthewdunbar/amazon-bedrock-mantle",
3
- "version": "0.0.7",
3
+ "version": "2.0.40",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -8,18 +8,28 @@
8
8
  "types": "./dist/index.d.ts",
9
9
  "files": [
10
10
  "dist/**/*",
11
+ "docs/**/*",
12
+ "src",
13
+ "!src/**/*.test.ts",
14
+ "!src/**/*.test-d.ts",
15
+ "!**/__snapshots__",
16
+ "!**/__fixtures__",
11
17
  "CHANGELOG.md",
12
- "README.md"
18
+ "README.md",
19
+ "internal.d.ts"
13
20
  ],
21
+ "directories": {
22
+ "doc": "./docs"
23
+ },
14
24
  "scripts": {
15
- "build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
16
- "build:watch": "pnpm clean && tsup --watch",
17
- "clean": "del-cli dist *.tsbuildinfo",
25
+ "build": "npm run clean && tsup --tsconfig tsconfig.build.json",
26
+ "build:watch": "npm run clean && tsup --watch",
27
+ "clean": "del-cli dist docs *.tsbuildinfo",
18
28
  "lint": "eslint \"./**/*.ts*\"",
19
29
  "type-check": "tsc --build",
20
30
  "prettier-check": "prettier --check \"./**/*.ts*\"",
21
- "test": "pnpm test:node && pnpm test:edge",
22
- "test:update": "pnpm test:node -u",
31
+ "test": "npm run test:node && npm run test:edge",
32
+ "test:update": "npm run test:node -u",
23
33
  "test:watch": "vitest --config vitest.node.config.js",
24
34
  "test:edge": "vitest --config vitest.edge.config.js --run",
25
35
  "test:node": "vitest --config vitest.node.config.js --run"
@@ -30,22 +40,21 @@
30
40
  "types": "./dist/index.d.ts",
31
41
  "import": "./dist/index.mjs",
32
42
  "require": "./dist/index.js"
43
+ },
44
+ "./internal": {
45
+ "types": "./dist/internal/index.d.ts",
46
+ "import": "./dist/internal/index.mjs",
47
+ "module": "./dist/internal/index.mjs",
48
+ "require": "./dist/internal/index.js"
33
49
  }
34
50
  },
35
- "dependencies": {
36
- "@ai-sdk/openai-compatible": "^2.0.30",
37
- "@ai-sdk/provider": "^3.0.8",
38
- "@ai-sdk/provider-utils": "^4.0.15",
39
- "@aws-sdk/credential-providers": "^3.750.0",
40
- "aws4fetch": "^1.0.20"
41
- },
51
+ "dependencies": {},
42
52
  "devDependencies": {
43
- "@ai-sdk/test-server": "workspace:*",
44
- "@types/node": "20.17.24",
45
- "@vercel/ai-tsconfig": "workspace:*",
46
- "tsup": "^8.3.0",
47
- "typescript": "5.8.3",
48
- "zod": "3.25.76"
53
+ "@types/node": "^20.17.24",
54
+ "del-cli": "^6.0.0",
55
+ "tsup": "^8",
56
+ "typescript": "^5.8.3",
57
+ "zod": "^3.25.76"
49
58
  },
50
59
  "peerDependencies": {
51
60
  "zod": "^3.25.76 || ^4.1.8"
@@ -55,16 +64,5 @@
55
64
  },
56
65
  "publishConfig": {
57
66
  "access": "public"
58
- },
59
- "homepage": "https://ai-sdk.dev/docs",
60
- "repository": {
61
- "type": "git",
62
- "url": "git+https://github.com/vercel/ai.git"
63
- },
64
- "bugs": {
65
- "url": "https://github.com/vercel/ai/issues"
66
- },
67
- "keywords": [
68
- "ai"
69
- ]
67
+ }
70
68
  }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export default function () {}