Elffuss BraidHub

kikocis/continue public

support secretAccessKey and accessKeyId for bedrock
Changesetec79a4d62a4ecdfbb05efaec295909e700952977f7975c1f490bc3d147a1e67b
AuthorDallin Romney <dallinromney@gmail.com> · 2025-07-07 18:47 -07:00
CommitterDallin Romney <dallinromney@gmail.com> · 2025-07-07 18:47 -07:00
Parents07dacc635923

Browse the files at this changeset

9 files changed

modified core/config/yaml/models.ts +6 −0
@@ -126,6 +126,12 @@
126126 if ("profile" in env && typeof env.profile === "string") {
127127 options.profile = env.profile;
128128 }
129+ if ("accessKeyId" in env && typeof env.accessKeyId === "string") {
130+ options.accessKeyId = env.accessKeyId;
131+ }
132+ if ("secretAccessKey" in env && typeof env.secretAccessKey === "string") {
133+ options.secretAccessKey = env.secretAccessKey;
134+ }
129135 if ("modelArn" in env && typeof env.modelArn === "string") {
130136 options.modelArn = env.modelArn;
131137 }
modified core/index.d.ts +2 −0
@@ -611,6 +611,8 @@
611611 // AWS options
612612 profile?: string;
613613 modelArn?: string;
614+ accessKeyId?: string;
615+ secretAccessKey?: string;
614616
615617 // AWS and VertexAI Options
616618 region?: string;
modified core/llm/index.ts +4 −0
@@ -172,6 +172,8 @@
172172 accountId?: string;
173173 aiGatewaySlug?: string;
174174 profile?: string | undefined;
175+ accessKeyId?: string;
176+ secretAccessKey?: string;
175177
176178 // For IBM watsonx
177179 deploymentId?: string;
@@ -270,6 +272,8 @@
270272 this.region = options.region;
271273 this.projectId = options.projectId;
272274 this.profile = options.profile;
275+ this.accessKeyId = options.accessKeyId;
276+ this.secretAccessKey = options.secretAccessKey;
273277
274278 this.openaiAdapter = this.createOpenAiAdapter();
275279
modified core/llm/llms/Bedrock.ts +13 −26
@@ -73,11 +73,6 @@
7373 if (!options.apiBase) {
7474 this.apiBase = `https://bedrock-runtime.${options.region}.amazonaws.com`;
7575 }
76- if (options.profile) {
77- this.profile = options.profile;
78- } else {
79- this.profile = "bedrock";
80- }
8176
8277 this.requestOptions = {
8378 region: options.region,
@@ -612,30 +607,22 @@
612607 }
613608
614609 private async _getCredentials() {
615- if (this.apiKey) {
616- const [accessKeyId, secretAccessKey] = this.apiKey.split(":");
617- if (!accessKeyId || !secretAccessKey) {
618- throw new Error(
619- "Invalid Bedrock API key format. Expected format: accessKeyId:secretAccessKey",
620- );
621- }
610+ if (this.accessKeyId && this.secretAccessKey) {
622611 return {
623- accessKeyId,
624- secretAccessKey,
612+ accessKeyId: this.accessKeyId,
613+ secretAccessKey: this.secretAccessKey,
625614 };
626615 }
627-
628- if (this.profile) {
629- try {
630- return await fromNodeProviderChain({
631- profile: this.profile,
632- ignoreCache: true,
633- })();
634- } catch (e) {
635- console.warn(
636- `AWS profile with name ${this.profile} not found in ~/.aws/credentials, using default profile`,
637- );
638- }
616+ const profile = this.profile ?? "bedrock";
617+ try {
618+ return await fromNodeProviderChain({
619+ profile: profile,
620+ ignoreCache: true,
621+ })();
622+ } catch (e) {
623+ console.warn(
624+ `AWS profile with name ${profile} not found in ~/.aws/credentials, using default profile`,
625+ );
639626 }
640627 return await fromNodeProviderChain()();
641628 }
modified extensions/vscode/config_schema.json +21 −1
@@ -359,8 +359,18 @@
359359 "description": "The AWS security profile to use",
360360 "type": "string"
361361 },
362+ "accessKeyId": {
363+ "title": "Access Key ID",
364+ "description": "AWS access key id (can be used together with secretAccessKey in place of profile)",
365+ "type": "string"
366+ },
367+ "secretAccessKey": {
368+ "title": "Secret Access Key",
369+ "description": "AWS secret access key (can be used together with secretAccessKey in place of profile)",
370+ "type": "string"
371+ },
362372 "modelArn": {
363- "title": "Profile",
373+ "title": "Model ARN",
364374 "description": "The AWS arn for the imported model",
365375 "type": "string"
366376 },
@@ -2903,6 +2913,16 @@
29032913 "title": "Profile",
29042914 "description": "The AWS security profile to use",
29052915 "type": "string"
2916+ },
2917+ "accessKeyId": {
2918+ "title": "Access Key ID",
2919+ "description": "AWS access key id (can be used together with secretAccessKey in place of profile)",
2920+ "type": "string"
2921+ },
2922+ "secretAccessKey": {
2923+ "title": "Secret Access Key",
2924+ "description": "AWS secret access key (can be used together with secretAccessKey in place of profile)",
2925+ "type": "string"
29062926 }
29072927 },
29082928 "required": ["provider"],
modified packages/openai-adapters/package-lock.json +97 −0
@@ -10,6 +10,7 @@
1010 "license": "Apache-2.0",
1111 "dependencies": {
1212 "@aws-sdk/client-bedrock-runtime": "^3.842.0",
13+ "@aws-sdk/credential-providers": "^3.840.0",
1314 "@continuedev/config-types": "^1.0.5",
1415 "@continuedev/config-yaml": "^1.0.51",
1516 "@continuedev/fetch": "^1.0.15",
@@ -255,6 +256,56 @@
255256 "uuid": "dist/bin/uuid"
256257 }
257258 },
259+ "node_modules/@aws-sdk/client-cognito-identity": {
260+ "version": "3.840.0",
261+ "resolved": "https://registry.npmjs.org/@aws-sdk/client-cognito-identity/-/client-cognito-identity-3.840.0.tgz",
262+ "integrity": "sha512-0sn/X63Xqqh5D1FYmdSHiS9SkDzTitoGO++/8IFik4xf/jpn4ZQkIoDPvpxFZcLvebMuUa6jAQs4ap4RusKGkg==",
263+ "license": "Apache-2.0",
264+ "dependencies": {
265+ "@aws-crypto/sha256-browser": "5.2.0",
266+ "@aws-crypto/sha256-js": "5.2.0",
267+ "@aws-sdk/core": "3.840.0",
268+ "@aws-sdk/credential-provider-node": "3.840.0",
269+ "@aws-sdk/middleware-host-header": "3.840.0",
270+ "@aws-sdk/middleware-logger": "3.840.0",
271+ "@aws-sdk/middleware-recursion-detection": "3.840.0",
272+ "@aws-sdk/middleware-user-agent": "3.840.0",
273+ "@aws-sdk/region-config-resolver": "3.840.0",
274+ "@aws-sdk/types": "3.840.0",
275+ "@aws-sdk/util-endpoints": "3.840.0",
276+ "@aws-sdk/util-user-agent-browser": "3.840.0",
277+ "@aws-sdk/util-user-agent-node": "3.840.0",
278+ "@smithy/config-resolver": "^4.1.4",
279+ "@smithy/core": "^3.6.0",
280+ "@smithy/fetch-http-handler": "^5.0.4",
281+ "@smithy/hash-node": "^4.0.4",
282+ "@smithy/invalid-dependency": "^4.0.4",
283+ "@smithy/middleware-content-length": "^4.0.4",
284+ "@smithy/middleware-endpoint": "^4.1.13",
285+ "@smithy/middleware-retry": "^4.1.14",
286+ "@smithy/middleware-serde": "^4.0.8",
287+ "@smithy/middleware-stack": "^4.0.4",
288+ "@smithy/node-config-provider": "^4.1.3",
289+ "@smithy/node-http-handler": "^4.0.6",
290+ "@smithy/protocol-http": "^5.1.2",
291+ "@smithy/smithy-client": "^4.4.5",
292+ "@smithy/types": "^4.3.1",
293+ "@smithy/url-parser": "^4.0.4",
294+ "@smithy/util-base64": "^4.0.0",
295+ "@smithy/util-body-length-browser": "^4.0.0",
296+ "@smithy/util-body-length-node": "^4.0.0",
297+ "@smithy/util-defaults-mode-browser": "^4.0.21",
298+ "@smithy/util-defaults-mode-node": "^4.0.21",
299+ "@smithy/util-endpoints": "^3.0.6",
300+ "@smithy/util-middleware": "^4.0.4",
301+ "@smithy/util-retry": "^4.0.6",
302+ "@smithy/util-utf8": "^4.0.0",
303+ "tslib": "^2.6.2"
304+ },
305+ "engines": {
306+ "node": ">=18.0.0"
307+ }
308+ },
258309 "node_modules/@aws-sdk/client-sso": {
259310 "version": "3.840.0",
260311 "resolved": "https://registry.npmjs.org/@aws-sdk/client-sso/-/client-sso-3.840.0.tgz",
@@ -330,6 +381,22 @@
330381 "node": ">=18.0.0"
331382 }
332383 },
384+ "node_modules/@aws-sdk/credential-provider-cognito-identity": {
385+ "version": "3.840.0",
386+ "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-cognito-identity/-/credential-provider-cognito-identity-3.840.0.tgz",
387+ "integrity": "sha512-p1RaMVd6+6ruYjKsWRCZT/jWhrYfDKbXY+/ScIYTvcaOOf9ArMtVnhFk3egewrC7kPXFGRYhg2GPmxRotNYMng==",
388+ "license": "Apache-2.0",
389+ "dependencies": {
390+ "@aws-sdk/client-cognito-identity": "3.840.0",
391+ "@aws-sdk/types": "3.840.0",
392+ "@smithy/property-provider": "^4.0.4",
393+ "@smithy/types": "^4.3.1",
394+ "tslib": "^2.6.2"
395+ },
396+ "engines": {
397+ "node": ">=18.0.0"
398+ }
399+ },
333400 "node_modules/@aws-sdk/credential-provider-env": {
334401 "version": "3.840.0",
335402 "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-env/-/credential-provider-env-3.840.0.tgz",
@@ -467,6 +534,36 @@
467534 "node": ">=18.0.0"
468535 }
469536 },
537+ "node_modules/@aws-sdk/credential-providers": {
538+ "version": "3.840.0",
539+ "resolved": "https://registry.npmjs.org/@aws-sdk/credential-providers/-/credential-providers-3.840.0.tgz",
540+ "integrity": "sha512-+CxYdGd+uM4NZ9VUvFTU1c/H61qhDB4q362k8xKU+bz24g//LDQ5Mpwksv8OUD1en44v4fUwgZ4SthPZMs+eFQ==",
541+ "license": "Apache-2.0",
542+ "dependencies": {
543+ "@aws-sdk/client-cognito-identity": "3.840.0",
544+ "@aws-sdk/core": "3.840.0",
545+ "@aws-sdk/credential-provider-cognito-identity": "3.840.0",
546+ "@aws-sdk/credential-provider-env": "3.840.0",
547+ "@aws-sdk/credential-provider-http": "3.840.0",
548+ "@aws-sdk/credential-provider-ini": "3.840.0",
549+ "@aws-sdk/credential-provider-node": "3.840.0",
550+ "@aws-sdk/credential-provider-process": "3.840.0",
551+ "@aws-sdk/credential-provider-sso": "3.840.0",
552+ "@aws-sdk/credential-provider-web-identity": "3.840.0",
553+ "@aws-sdk/nested-clients": "3.840.0",
554+ "@aws-sdk/types": "3.840.0",
555+ "@smithy/config-resolver": "^4.1.4",
556+ "@smithy/core": "^3.6.0",
557+ "@smithy/credential-provider-imds": "^4.0.6",
558+ "@smithy/node-config-provider": "^4.1.3",
559+ "@smithy/property-provider": "^4.0.4",
560+ "@smithy/types": "^4.3.1",
561+ "tslib": "^2.6.2"
562+ },
563+ "engines": {
564+ "node": ">=18.0.0"
565+ }
566+ },
470567 "node_modules/@aws-sdk/eventstream-handler-node": {
471568 "version": "3.840.0",
472569 "resolved": "https://registry.npmjs.org/@aws-sdk/eventstream-handler-node/-/eventstream-handler-node-3.840.0.tgz",
modified packages/openai-adapters/package.json +1 −0
@@ -13,6 +13,7 @@
1313 "license": "Apache-2.0",
1414 "dependencies": {
1515 "@aws-sdk/client-bedrock-runtime": "^3.842.0",
16+ "@aws-sdk/credential-providers": "^3.840.0",
1617 "@continuedev/config-types": "^1.0.5",
1718 "@continuedev/config-yaml": "^1.0.51",
1819 "@continuedev/fetch": "^1.0.15",
modified packages/openai-adapters/src/apis/Bedrock.ts +43 −16
@@ -27,6 +27,7 @@
2727 Model,
2828 } from "openai/resources/index";
2929
30+import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
3031 import { BedrockConfig } from "../types.js";
3132 import { chatChunk, chatChunkFromDelta, embedding, rerank } from "../util.js";
3233 import { safeParseArgs } from "../util/parseArgs.js";
@@ -56,32 +57,56 @@
5657 }
5758
5859 export class BedrockApi implements BaseLlmApi {
59- private client: BedrockRuntimeClient;
6060 private _currentToolResponse: Partial<ToolUseState> | null = null;
6161
6262 constructor(protected config: BedrockConfig) {
6363 if (!config.env?.region) {
6464 throw new Error("region is required for Bedrock API");
6565 }
66- if (!config.apiKey) {
66+
67+ if (config.env?.accessKeyId || config?.env?.secretAccessKey) {
68+ if (!config.env?.accessKeyId) {
69+ throw new Error(
70+ "accessKeyId is required for Bedrock API. Only found secretAccessKey",
71+ );
72+ }
73+ if (!config.env?.secretAccessKey) {
74+ throw new Error(
75+ "secretAccessKey is required for Bedrock API. Only found accessKeyId",
76+ );
77+ }
78+ } else if (!config.env?.profile) {
6779 throw new Error(
68- "apiKey in the format accessKeyId:secretAccessKey is required for Bedrock API",
80+ "AWS credentials profile not found. Please provide accessKeyId and secretAccessKey or profile",
6981 );
7082 }
83+ }
7184
72- const [accessKeyId, secretAccessKey] = config.apiKey.split(":");
73- if (!accessKeyId || !secretAccessKey) {
74- throw new Error(
75- "Bedrock apiKey must be in the format accessKeyId:secretAccessKey",
85+ async getCreds() {
86+ if (this.config?.env?.accessKeyId && this.config?.env?.secretAccessKey) {
87+ return {
88+ accessKeyId: this.config.env.accessKeyId,
89+ secretAccessKey: this.config.env.secretAccessKey,
90+ };
91+ }
92+ const profile = this.config.env.profile ?? "bedrock";
93+ try {
94+ return await fromNodeProviderChain({
95+ profile: profile,
96+ ignoreCache: true,
97+ })();
98+ } catch (e) {
99+ console.warn(
100+ `AWS profile with name ${profile} not found in ~/.aws/credentials, using default profile`,
76101 );
77102 }
78-
79- this.client = new BedrockRuntimeClient({
80- region: config.env.region,
81- credentials: {
82- accessKeyId,
83- secretAccessKey,
84- },
103+ return await fromNodeProviderChain()();
104+ }
105+ async getClient(): Promise<BedrockRuntimeClient> {
106+ const creds = await this.getCreds();
107+ return new BedrockRuntimeClient({
108+ region: this.config.env.region,
109+ credentials: creds,
85110 });
86111 }
87112
@@ -431,7 +456,8 @@
431456 ...requestBody,
432457 });
433458
434- const response = await this.client.send(command, { abortSignal: signal });
459+ const client = await this.getClient();
460+ const response = await client.send(command, { abortSignal: signal });
435461
436462 if (!response?.stream) {
437463 throw new Error("No stream received from Bedrock API");
@@ -551,7 +577,8 @@
551577 contentType: "application/json",
552578 };
553579 const command = new InvokeModelCommand(payload);
554- const response = await this.client.send(command);
580+ const client = await this.getClient();
581+ const response = await client.send(command);
555582 if (!response.body) {
556583 throw new Error("No response body");
557584 }
modified packages/openai-adapters/src/types.ts +3 −0
@@ -79,6 +79,9 @@
7979 // }).optional(),
8080 env: z.object({
8181 region: z.string().optional(),
82+ accessKeyId: z.string().optional(),
83+ secretAccessKey: z.string().optional(),
84+ profile: z.string().optional(),
8285 }),
8386 });
8487 export type BedrockConfig = z.infer<typeof BedrockConfigSchema>;