Changesets · Branches · Tags · Compare
| Changeset | ec79a4d62a4ecdfbb05efaec295909e700952977f7975c1f490bc3d147a1e67b |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-07-07 18:47 -07:00 |
| Committer | Dallin Romney <dallinromney@gmail.com> · 2025-07-07 18:47 -07:00 |
| Parents | 07dacc635923 |
9 files changed
modified core/config/yaml/models.ts +6 −0
| @@ -126,6 +126,12 @@ | ||
| 126 | 126 | if ("profile" in env && typeof env.profile === "string") { |
| 127 | 127 | options.profile = env.profile; |
| 128 | 128 | } |
| 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 | + } | |
| 129 | 135 | if ("modelArn" in env && typeof env.modelArn === "string") { |
| 130 | 136 | options.modelArn = env.modelArn; |
| 131 | 137 | } |
modified core/index.d.ts +2 −0
| @@ -611,6 +611,8 @@ | ||
| 611 | 611 | // AWS options |
| 612 | 612 | profile?: string; |
| 613 | 613 | modelArn?: string; |
| 614 | + accessKeyId?: string; | |
| 615 | + secretAccessKey?: string; | |
| 614 | 616 | |
| 615 | 617 | // AWS and VertexAI Options |
| 616 | 618 | region?: string; |
modified core/llm/index.ts +4 −0
| @@ -172,6 +172,8 @@ | ||
| 172 | 172 | accountId?: string; |
| 173 | 173 | aiGatewaySlug?: string; |
| 174 | 174 | profile?: string | undefined; |
| 175 | + accessKeyId?: string; | |
| 176 | + secretAccessKey?: string; | |
| 175 | 177 | |
| 176 | 178 | // For IBM watsonx |
| 177 | 179 | deploymentId?: string; |
| @@ -270,6 +272,8 @@ | ||
| 270 | 272 | this.region = options.region; |
| 271 | 273 | this.projectId = options.projectId; |
| 272 | 274 | this.profile = options.profile; |
| 275 | + this.accessKeyId = options.accessKeyId; | |
| 276 | + this.secretAccessKey = options.secretAccessKey; | |
| 273 | 277 | |
| 274 | 278 | this.openaiAdapter = this.createOpenAiAdapter(); |
| 275 | 279 |
modified core/llm/llms/Bedrock.ts +13 −26
| @@ -73,11 +73,6 @@ | ||
| 73 | 73 | if (!options.apiBase) { |
| 74 | 74 | this.apiBase = `https://bedrock-runtime.${options.region}.amazonaws.com`; |
| 75 | 75 | } |
| 76 | - if (options.profile) { | |
| 77 | - this.profile = options.profile; | |
| 78 | - } else { | |
| 79 | - this.profile = "bedrock"; | |
| 80 | - } | |
| 81 | 76 | |
| 82 | 77 | this.requestOptions = { |
| 83 | 78 | region: options.region, |
| @@ -612,30 +607,22 @@ | ||
| 612 | 607 | } |
| 613 | 608 | |
| 614 | 609 | 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) { | |
| 622 | 611 | return { |
| 623 | - accessKeyId, | |
| 624 | - secretAccessKey, | |
| 612 | + accessKeyId: this.accessKeyId, | |
| 613 | + secretAccessKey: this.secretAccessKey, | |
| 625 | 614 | }; |
| 626 | 615 | } |
| 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 | + ); | |
| 639 | 626 | } |
| 640 | 627 | return await fromNodeProviderChain()(); |
| 641 | 628 | } |
modified extensions/vscode/config_schema.json +21 −1
| @@ -359,8 +359,18 @@ | ||
| 359 | 359 | "description": "The AWS security profile to use", |
| 360 | 360 | "type": "string" |
| 361 | 361 | }, |
| 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 | + }, | |
| 362 | 372 | "modelArn": { |
| 363 | - "title": "Profile", | |
| 373 | + "title": "Model ARN", | |
| 364 | 374 | "description": "The AWS arn for the imported model", |
| 365 | 375 | "type": "string" |
| 366 | 376 | }, |
| @@ -2903,6 +2913,16 @@ | ||
| 2903 | 2913 | "title": "Profile", |
| 2904 | 2914 | "description": "The AWS security profile to use", |
| 2905 | 2915 | "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" | |
| 2906 | 2926 | } |
| 2907 | 2927 | }, |
| 2908 | 2928 | "required": ["provider"], |
modified packages/openai-adapters/package-lock.json +97 −0
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | "license": "Apache-2.0", |
| 11 | 11 | "dependencies": { |
| 12 | 12 | "@aws-sdk/client-bedrock-runtime": "^3.842.0", |
| 13 | + "@aws-sdk/credential-providers": "^3.840.0", | |
| 13 | 14 | "@continuedev/config-types": "^1.0.5", |
| 14 | 15 | "@continuedev/config-yaml": "^1.0.51", |
| 15 | 16 | "@continuedev/fetch": "^1.0.15", |
| @@ -255,6 +256,56 @@ | ||
| 255 | 256 | "uuid": "dist/bin/uuid" |
| 256 | 257 | } |
| 257 | 258 | }, |
| 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 | + }, | |
| 258 | 309 | "node_modules/@aws-sdk/client-sso": { |
| 259 | 310 | "version": "3.840.0", |
| 260 | 311 | "resolved": "https://registry.npmjs.org/@aws-sdk/client-sso/-/client-sso-3.840.0.tgz", |
| @@ -330,6 +381,22 @@ | ||
| 330 | 381 | "node": ">=18.0.0" |
| 331 | 382 | } |
| 332 | 383 | }, |
| 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 | + }, | |
| 333 | 400 | "node_modules/@aws-sdk/credential-provider-env": { |
| 334 | 401 | "version": "3.840.0", |
| 335 | 402 | "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-env/-/credential-provider-env-3.840.0.tgz", |
| @@ -467,6 +534,36 @@ | ||
| 467 | 534 | "node": ">=18.0.0" |
| 468 | 535 | } |
| 469 | 536 | }, |
| 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 | + }, | |
| 470 | 567 | "node_modules/@aws-sdk/eventstream-handler-node": { |
| 471 | 568 | "version": "3.840.0", |
| 472 | 569 | "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 @@ | ||
| 13 | 13 | "license": "Apache-2.0", |
| 14 | 14 | "dependencies": { |
| 15 | 15 | "@aws-sdk/client-bedrock-runtime": "^3.842.0", |
| 16 | + "@aws-sdk/credential-providers": "^3.840.0", | |
| 16 | 17 | "@continuedev/config-types": "^1.0.5", |
| 17 | 18 | "@continuedev/config-yaml": "^1.0.51", |
| 18 | 19 | "@continuedev/fetch": "^1.0.15", |
modified packages/openai-adapters/src/apis/Bedrock.ts +43 −16
| @@ -27,6 +27,7 @@ | ||
| 27 | 27 | Model, |
| 28 | 28 | } from "openai/resources/index"; |
| 29 | 29 | |
| 30 | +import { fromNodeProviderChain } from "@aws-sdk/credential-providers"; | |
| 30 | 31 | import { BedrockConfig } from "../types.js"; |
| 31 | 32 | import { chatChunk, chatChunkFromDelta, embedding, rerank } from "../util.js"; |
| 32 | 33 | import { safeParseArgs } from "../util/parseArgs.js"; |
| @@ -56,32 +57,56 @@ | ||
| 56 | 57 | } |
| 57 | 58 | |
| 58 | 59 | export class BedrockApi implements BaseLlmApi { |
| 59 | - private client: BedrockRuntimeClient; | |
| 60 | 60 | private _currentToolResponse: Partial<ToolUseState> | null = null; |
| 61 | 61 | |
| 62 | 62 | constructor(protected config: BedrockConfig) { |
| 63 | 63 | if (!config.env?.region) { |
| 64 | 64 | throw new Error("region is required for Bedrock API"); |
| 65 | 65 | } |
| 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) { | |
| 67 | 79 | 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", | |
| 69 | 81 | ); |
| 70 | 82 | } |
| 83 | + } | |
| 71 | 84 | |
| 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`, | |
| 76 | 101 | ); |
| 77 | 102 | } |
| 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, | |
| 85 | 110 | }); |
| 86 | 111 | } |
| 87 | 112 | |
| @@ -431,7 +456,8 @@ | ||
| 431 | 456 | ...requestBody, |
| 432 | 457 | }); |
| 433 | 458 | |
| 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 }); | |
| 435 | 461 | |
| 436 | 462 | if (!response?.stream) { |
| 437 | 463 | throw new Error("No stream received from Bedrock API"); |
| @@ -551,7 +577,8 @@ | ||
| 551 | 577 | contentType: "application/json", |
| 552 | 578 | }; |
| 553 | 579 | 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); | |
| 555 | 582 | if (!response.body) { |
| 556 | 583 | throw new Error("No response body"); |
| 557 | 584 | } |
modified packages/openai-adapters/src/types.ts +3 −0
| @@ -79,6 +79,9 @@ | ||
| 79 | 79 | // }).optional(), |
| 80 | 80 | env: z.object({ |
| 81 | 81 | region: z.string().optional(), |
| 82 | + accessKeyId: z.string().optional(), | |
| 83 | + secretAccessKey: z.string().optional(), | |
| 84 | + profile: z.string().optional(), | |
| 82 | 85 | }), |
| 83 | 86 | }); |
| 84 | 87 | export type BedrockConfig = z.infer<typeof BedrockConfigSchema>; |