diff --git a/.changeset/tame-carpets-bake.md b/.changeset/tame-carpets-bake.md new file mode 100644 index 00000000000..69141ac4ca8 --- /dev/null +++ b/.changeset/tame-carpets-bake.md @@ -0,0 +1,5 @@ +--- +"roo-cline": patch +--- + +Add credentials auth for Google vertex diff --git a/src/api/providers/vertex.ts b/src/api/providers/vertex.ts index 7f764a9076a..bc888e04599 100644 --- a/src/api/providers/vertex.ts +++ b/src/api/providers/vertex.ts @@ -11,6 +11,7 @@ import { BaseProvider } from "./base-provider" import { ANTHROPIC_DEFAULT_MAX_TOKENS } from "./constants" import { getModelParams, SingleCompletionHandler } from "../" +import { GoogleAuth } from "google-auth-library" // Types for Vertex SDK @@ -120,16 +121,56 @@ export class VertexHandler extends BaseProvider implements SingleCompletionHandl throw new Error(`Unknown model ID: ${this.options.apiModelId}`) } - this.anthropicClient = new AnthropicVertex({ - projectId: this.options.vertexProjectId ?? "not-provided", - // https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions - region: this.options.vertexRegion ?? "us-east5", - }) + if (this.options.vertexJsonCredentials) { + this.anthropicClient = new AnthropicVertex({ + projectId: this.options.vertexProjectId ?? "not-provided", + // https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions + region: this.options.vertexRegion ?? "us-east5", + googleAuth: new GoogleAuth({ + scopes: ["https://www.googleapis.com/auth/cloud-platform"], + credentials: JSON.parse(this.options.vertexJsonCredentials), + }), + }) + } else if (this.options.vertexKeyFile) { + this.anthropicClient = new AnthropicVertex({ + projectId: this.options.vertexProjectId ?? "not-provided", + // https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions + region: this.options.vertexRegion ?? "us-east5", + googleAuth: new GoogleAuth({ + scopes: ["https://www.googleapis.com/auth/cloud-platform"], + keyFile: this.options.vertexKeyFile, + }), + }) + } else { + this.anthropicClient = new AnthropicVertex({ + projectId: this.options.vertexProjectId ?? "not-provided", + // https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#regions + region: this.options.vertexRegion ?? "us-east5", + }) + } - this.geminiClient = new VertexAI({ - project: this.options.vertexProjectId ?? "not-provided", - location: this.options.vertexRegion ?? "us-east5", - }) + if (this.options.vertexJsonCredentials) { + this.geminiClient = new VertexAI({ + project: this.options.vertexProjectId ?? "not-provided", + location: this.options.vertexRegion ?? "us-east5", + googleAuthOptions: { + credentials: JSON.parse(this.options.vertexJsonCredentials), + }, + }) + } else if (this.options.vertexKeyFile) { + this.geminiClient = new VertexAI({ + project: this.options.vertexProjectId ?? "not-provided", + location: this.options.vertexRegion ?? "us-east5", + googleAuthOptions: { + keyFile: this.options.vertexKeyFile, + }, + }) + } else { + this.geminiClient = new VertexAI({ + project: this.options.vertexProjectId ?? "not-provided", + location: this.options.vertexRegion ?? "us-east5", + }) + } } private formatMessageForCache(message: Anthropic.Messages.MessageParam, shouldCache: boolean): VertexMessage { diff --git a/src/shared/api.ts b/src/shared/api.ts index d066039850b..23a73b24036 100644 --- a/src/shared/api.ts +++ b/src/shared/api.ts @@ -39,6 +39,8 @@ export interface ApiHandlerOptions { awspromptCacheId?: string awsProfile?: string awsUseProfile?: boolean + vertexKeyFile?: string + vertexJsonCredentials?: string vertexProjectId?: string vertexRegion?: string openAiBaseUrl?: string @@ -97,6 +99,8 @@ export const API_CONFIG_KEYS: GlobalStateKey[] = [ // "awspromptCacheId", // NOT exist on GlobalStateKey "awsProfile", "awsUseProfile", + "vertexKeyFile", + "vertexJsonCredentials", "vertexProjectId", "vertexRegion", "openAiBaseUrl", diff --git a/src/shared/globalState.ts b/src/shared/globalState.ts index fd7bd1adb9f..0665586c472 100644 --- a/src/shared/globalState.ts +++ b/src/shared/globalState.ts @@ -28,6 +28,8 @@ export const GLOBAL_STATE_KEYS = [ "awsUseCrossRegionInference", "awsProfile", "awsUseProfile", + "vertexKeyFile", + "vertexJsonCredentials", "vertexProjectId", "vertexRegion", "lastShownAnnouncementId", diff --git a/webview-ui/src/components/settings/ApiOptions.tsx b/webview-ui/src/components/settings/ApiOptions.tsx index 407a4b4fcce..efbe098186b 100644 --- a/webview-ui/src/components/settings/ApiOptions.tsx +++ b/webview-ui/src/components/settings/ApiOptions.tsx @@ -565,7 +565,28 @@ const ApiOptions = ({ 2. Install the Google Cloud CLI & configure application default credentials. +
+ + 3. Or create a service account with credentials. + +
+ + Google Cloud Credentials + + + Google Cloud Key File Path +