Skip to content

Commit 8bf8326

Browse files
committed
feat: rewrite VertexEmbedder to use @google/genai library with multiple auth options
- Replace OpenAI-compatible approach with native @google/genai SDK - Add support for multiple authentication methods: - API key (uses regular Gemini API endpoint) - JSON credentials (service account) - Key file path - Application default credentials - Add projectId and location fields for Vertex AI configuration - Update UI to show all authentication options for Vertex - Update tests to reflect new implementation - Update all related type definitions and interfaces
1 parent a1c10fe commit 8bf8326

File tree

11 files changed

+624
-134
lines changed

11 files changed

+624
-134
lines changed

packages/types/src/codebase-index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export const codebaseIndexConfigSchema = z.object({
3636
// OpenAI Compatible specific fields
3737
codebaseIndexOpenAiCompatibleBaseUrl: z.string().optional(),
3838
codebaseIndexOpenAiCompatibleModelDimension: z.number().optional(),
39+
// Vertex AI specific fields
40+
codebaseIndexVertexProjectId: z.string().optional(),
41+
codebaseIndexVertexLocation: z.string().optional(),
3942
})
4043

4144
export type CodebaseIndexConfig = z.infer<typeof codebaseIndexConfigSchema>
@@ -68,6 +71,8 @@ export const codebaseIndexProviderSchema = z.object({
6871
codebaseIndexGeminiApiKey: z.string().optional(),
6972
codebaseIndexMistralApiKey: z.string().optional(),
7073
codebaseIndexVertexApiKey: z.string().optional(),
74+
codebaseIndexVertexJsonCredentials: z.string().optional(),
75+
codebaseIndexVertexKeyFile: z.string().optional(),
7176
})
7277

7378
export type CodebaseIndexProvider = z.infer<typeof codebaseIndexProviderSchema>

packages/types/src/global-settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ export const SECRET_STATE_KEYS = [
185185
"codebaseIndexGeminiApiKey",
186186
"codebaseIndexMistralApiKey",
187187
"codebaseIndexVertexApiKey",
188+
"codebaseIndexVertexJsonCredentials",
189+
"codebaseIndexVertexKeyFile",
188190
"huggingFaceApiKey",
189191
] as const satisfies readonly (keyof ProviderSettings)[]
190192
export type SecretState = Pick<ProviderSettings, (typeof SECRET_STATE_KEYS)[number]>

src/core/webview/ClineProvider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,8 @@ export class ClineProvider
15541554
codebaseIndexOpenAiCompatibleBaseUrl: codebaseIndexConfig?.codebaseIndexOpenAiCompatibleBaseUrl,
15551555
codebaseIndexSearchMaxResults: codebaseIndexConfig?.codebaseIndexSearchMaxResults,
15561556
codebaseIndexSearchMinScore: codebaseIndexConfig?.codebaseIndexSearchMinScore,
1557+
codebaseIndexVertexProjectId: codebaseIndexConfig?.codebaseIndexVertexProjectId,
1558+
codebaseIndexVertexLocation: codebaseIndexConfig?.codebaseIndexVertexLocation,
15571559
},
15581560
mdmCompliant: this.checkMdmCompliance(),
15591561
profileThresholds: profileThresholds ?? {},
@@ -1726,6 +1728,8 @@ export class ClineProvider
17261728
stateValues.codebaseIndexConfig?.codebaseIndexOpenAiCompatibleBaseUrl,
17271729
codebaseIndexSearchMaxResults: stateValues.codebaseIndexConfig?.codebaseIndexSearchMaxResults,
17281730
codebaseIndexSearchMinScore: stateValues.codebaseIndexConfig?.codebaseIndexSearchMinScore,
1731+
codebaseIndexVertexProjectId: stateValues.codebaseIndexConfig?.codebaseIndexVertexProjectId,
1732+
codebaseIndexVertexLocation: stateValues.codebaseIndexConfig?.codebaseIndexVertexLocation,
17291733
},
17301734
profileThresholds: stateValues.profileThresholds ?? {},
17311735
// Add diagnostic message settings

src/core/webview/webviewMessageHandler.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,8 @@ export const webviewMessageHandler = async (
19981998
codebaseIndexOpenAiCompatibleBaseUrl: settings.codebaseIndexOpenAiCompatibleBaseUrl,
19991999
codebaseIndexSearchMaxResults: settings.codebaseIndexSearchMaxResults,
20002000
codebaseIndexSearchMinScore: settings.codebaseIndexSearchMinScore,
2001+
codebaseIndexVertexProjectId: settings.codebaseIndexVertexProjectId,
2002+
codebaseIndexVertexLocation: settings.codebaseIndexVertexLocation,
20012003
}
20022004

20032005
// Save global state first
@@ -2028,6 +2030,24 @@ export const webviewMessageHandler = async (
20282030
settings.codebaseIndexMistralApiKey,
20292031
)
20302032
}
2033+
if (settings.codebaseIndexVertexApiKey !== undefined) {
2034+
await provider.contextProxy.storeSecret(
2035+
"codebaseIndexVertexApiKey",
2036+
settings.codebaseIndexVertexApiKey,
2037+
)
2038+
}
2039+
if (settings.codebaseIndexVertexJsonCredentials !== undefined) {
2040+
await provider.contextProxy.storeSecret(
2041+
"codebaseIndexVertexJsonCredentials",
2042+
settings.codebaseIndexVertexJsonCredentials,
2043+
)
2044+
}
2045+
if (settings.codebaseIndexVertexKeyFile !== undefined) {
2046+
await provider.contextProxy.storeSecret(
2047+
"codebaseIndexVertexKeyFile",
2048+
settings.codebaseIndexVertexKeyFile,
2049+
)
2050+
}
20312051

20322052
// Send success response first - settings are saved regardless of validation
20332053
await provider.postMessageToWebview({
@@ -2149,6 +2169,11 @@ export const webviewMessageHandler = async (
21492169
))
21502170
const hasGeminiApiKey = !!(await provider.context.secrets.get("codebaseIndexGeminiApiKey"))
21512171
const hasMistralApiKey = !!(await provider.context.secrets.get("codebaseIndexMistralApiKey"))
2172+
const hasVertexApiKey = !!(await provider.context.secrets.get("codebaseIndexVertexApiKey"))
2173+
const hasVertexJsonCredentials = !!(await provider.context.secrets.get(
2174+
"codebaseIndexVertexJsonCredentials",
2175+
))
2176+
const hasVertexKeyFile = !!(await provider.context.secrets.get("codebaseIndexVertexKeyFile"))
21522177

21532178
provider.postMessageToWebview({
21542179
type: "codeIndexSecretStatus",
@@ -2158,6 +2183,9 @@ export const webviewMessageHandler = async (
21582183
hasOpenAiCompatibleApiKey,
21592184
hasGeminiApiKey,
21602185
hasMistralApiKey,
2186+
hasVertexApiKey,
2187+
hasVertexJsonCredentials,
2188+
hasVertexKeyFile,
21612189
},
21622190
})
21632191
break

0 commit comments

Comments
 (0)