Skip to content

Commit 959fe94

Browse files
committed
Merge remote-tracking branch 'origin/feature/add-valkey-password' into feature/add-valkey
2 parents cc899ca + 9cae8fa commit 959fe94

File tree

14 files changed

+174
-29
lines changed

14 files changed

+174
-29
lines changed

packages/types/src/codebase-index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export const codebaseIndexConfigSchema = z.object({
3535
codebaseIndexOpenAiCompatibleBaseUrl: z.string().optional(),
3636
codebaseIndexOpenAiCompatibleModelDimension: z.number().optional(),
3737
codebaseIndexValkeyUrl: z.string().optional(),
38+
codebaseIndexValkeyUsername: z.string().optional(),
39+
codebaseIndexValkeyPassword: z.string().optional(),
3840
searchProvider: z.string().optional(),
3941
})
4042

@@ -61,6 +63,7 @@ export type CodebaseIndexModels = z.infer<typeof codebaseIndexModelsSchema>
6163
export const codebaseIndexProviderSchema = z.object({
6264
codeIndexOpenAiKey: z.string().optional(),
6365
codeIndexQdrantApiKey: z.string().optional(),
66+
codeIndexValkeyPassword: z.string().optional(),
6467
codebaseIndexOpenAiCompatibleBaseUrl: z.string().optional(),
6568
codebaseIndexOpenAiCompatibleApiKey: z.string().optional(),
6669
codebaseIndexOpenAiCompatibleModelDimension: z.number().optional(),

packages/types/src/global-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export const SECRET_STATE_KEYS = [
181181
"litellmApiKey",
182182
"codeIndexOpenAiKey",
183183
"codeIndexQdrantApiKey",
184+
"codeIndexValkeyPassword",
184185
"codebaseIndexOpenAiCompatibleApiKey",
185186
"codebaseIndexGeminiApiKey",
186187
"codebaseIndexMistralApiKey",

src/core/webview/ClineProvider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,9 @@ export class ClineProvider
15471547
codebaseIndexConfig: {
15481548
codebaseIndexEnabled: codebaseIndexConfig?.codebaseIndexEnabled ?? true,
15491549
codebaseIndexQdrantUrl: codebaseIndexConfig?.codebaseIndexQdrantUrl ?? "http://localhost:6333",
1550-
codebaseIndexValkeyUrl: codebaseIndexConfig?.codebaseIndexValkeyUrl ?? "http://localhost:6379",
1550+
codebaseIndexValkeyUrl: codebaseIndexConfig?.codebaseIndexValkeyUrl ?? "redis://localhost:6379",
1551+
codebaseIndexValkeyUsername: codebaseIndexConfig?.codebaseIndexValkeyUsername ?? "",
1552+
codebaseIndexValkeyPassword: codebaseIndexConfig?.codebaseIndexValkeyPassword ?? "",
15511553
codebaseIndexEmbedderProvider: codebaseIndexConfig?.codebaseIndexEmbedderProvider ?? "openai",
15521554
codebaseIndexEmbedderBaseUrl: codebaseIndexConfig?.codebaseIndexEmbedderBaseUrl ?? "",
15531555
codebaseIndexEmbedderModelId: codebaseIndexConfig?.codebaseIndexEmbedderModelId ?? "",
@@ -1720,6 +1722,8 @@ export class ClineProvider
17201722
stateValues.codebaseIndexConfig?.codebaseIndexQdrantUrl ?? "http://localhost:6333",
17211723
codebaseIndexValkeyUrl:
17221724
stateValues.codebaseIndexConfig?.codebaseIndexValkeyUrl ?? "http://localhost:6379",
1725+
codebaseIndexValkeyUsername: stateValues.codebaseIndexConfig?.codebaseIndexValkeyUsername ?? "",
1726+
codebaseIndexValkeyPassword: stateValues.codebaseIndexConfig?.codebaseIndexValkeyPassword ?? "",
17231727
codebaseIndexEmbedderProvider:
17241728
stateValues.codebaseIndexConfig?.codebaseIndexEmbedderProvider ?? "openai",
17251729
codebaseIndexEmbedderBaseUrl: stateValues.codebaseIndexConfig?.codebaseIndexEmbedderBaseUrl ?? "",

src/core/webview/webviewMessageHandler.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,8 @@ export const webviewMessageHandler = async (
19921992
codebaseIndexEnabled: settings.codebaseIndexEnabled,
19931993
codebaseIndexQdrantUrl: settings.codebaseIndexQdrantUrl,
19941994
codebaseIndexValkeyUrl: settings.codebaseIndexValkeyUrl,
1995+
codebaseIndexValkeyUsername: settings.codebaseIndexValkeyUsername,
1996+
codebaseIndexValkeyPassword: settings.codeIndexValkeyPassword,
19951997
codebaseIndexEmbedderProvider: settings.codebaseIndexEmbedderProvider,
19961998
codebaseIndexEmbedderBaseUrl: settings.codebaseIndexEmbedderBaseUrl,
19971999
codebaseIndexEmbedderModelId: settings.codebaseIndexEmbedderModelId,
@@ -2012,6 +2014,9 @@ export const webviewMessageHandler = async (
20122014
if (settings.codeIndexQdrantApiKey !== undefined) {
20132015
await provider.contextProxy.storeSecret("codeIndexQdrantApiKey", settings.codeIndexQdrantApiKey)
20142016
}
2017+
if (settings.codeIndexValkeyPassword !== undefined) {
2018+
await provider.contextProxy.storeSecret("codeIndexValkeyPassword", settings.codeIndexValkeyPassword)
2019+
}
20152020
if (settings.codebaseIndexOpenAiCompatibleApiKey !== undefined) {
20162021
await provider.contextProxy.storeSecret(
20172022
"codebaseIndexOpenAiCompatibleApiKey",
@@ -2146,6 +2151,7 @@ export const webviewMessageHandler = async (
21462151
// Check if secrets are set using the VSCode context directly for async access
21472152
const hasOpenAiKey = !!(await provider.context.secrets.get("codeIndexOpenAiKey"))
21482153
const hasQdrantApiKey = !!(await provider.context.secrets.get("codeIndexQdrantApiKey"))
2154+
const hasValkeyPassword = !!(await provider.context.secrets.get("codeIndexValkeyPassword"))
21492155
const hasOpenAiCompatibleApiKey = !!(await provider.context.secrets.get(
21502156
"codebaseIndexOpenAiCompatibleApiKey",
21512157
))
@@ -2160,6 +2166,7 @@ export const webviewMessageHandler = async (
21602166
hasOpenAiCompatibleApiKey,
21612167
hasGeminiApiKey,
21622168
hasMistralApiKey,
2169+
hasValkeyPassword,
21632170
},
21642171
})
21652172
break

src/services/code-index/config-manager.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export class CodeIndexConfigManager {
2323
private qdrantApiKey?: string
2424
private searchProvider?: string
2525
private valkeyUrl?: string = "http://localhost:6379"
26+
private valkeyUsername?: string
27+
private valkeyPassword?: string
2628
private searchMinScore?: number
2729
private searchMaxResults?: number
2830

@@ -48,6 +50,7 @@ export class CodeIndexConfigManager {
4850
codebaseIndexEnabled: true,
4951
codebaseIndexQdrantUrl: "http://localhost:6333",
5052
codebaseIndexValkeyUrl: "http://localhost:6379",
53+
codebaseIndexValkeyUsername: "",
5154
codebaseIndexEmbedderProvider: "openai",
5255
codebaseIndexEmbedderBaseUrl: "",
5356
codebaseIndexEmbedderModelId: "",
@@ -59,6 +62,7 @@ export class CodeIndexConfigManager {
5962
codebaseIndexEnabled,
6063
codebaseIndexQdrantUrl,
6164
codebaseIndexValkeyUrl,
65+
codebaseIndexValkeyUsername,
6266
codebaseIndexEmbedderProvider,
6367
codebaseIndexEmbedderBaseUrl,
6468
codebaseIndexEmbedderModelId,
@@ -69,6 +73,7 @@ export class CodeIndexConfigManager {
6973

7074
const openAiKey = this.contextProxy?.getSecret("codeIndexOpenAiKey") ?? ""
7175
const qdrantApiKey = this.contextProxy?.getSecret("codeIndexQdrantApiKey") ?? ""
76+
const valkeyPassword = this.contextProxy?.getSecret("codeIndexValkeyPassword") ?? ""
7277
// Fix: Read OpenAI Compatible settings from the correct location within codebaseIndexConfig
7378
const openAiCompatibleBaseUrl = codebaseIndexConfig.codebaseIndexOpenAiCompatibleBaseUrl ?? ""
7479
const openAiCompatibleApiKey = this.contextProxy?.getSecret("codebaseIndexOpenAiCompatibleApiKey") ?? ""
@@ -80,6 +85,8 @@ export class CodeIndexConfigManager {
8085
this.qdrantUrl = codebaseIndexQdrantUrl
8186
this.qdrantApiKey = qdrantApiKey ?? ""
8287
this.valkeyUrl = codebaseIndexValkeyUrl
88+
this.valkeyPassword = valkeyPassword
89+
this.valkeyUsername = codebaseIndexValkeyUsername
8390
this.searchMinScore = codebaseIndexSearchMinScore
8491
this.searchMaxResults = codebaseIndexSearchMaxResults
8592
this.searchProvider = searchProvider
@@ -151,6 +158,8 @@ export class CodeIndexConfigManager {
151158
qdrantUrl?: string
152159
qdrantApiKey?: string
153160
valkeyUrl?: string
161+
valkeyPassword?: string
162+
valkeyUsername?: string
154163
searchProvider?: string
155164
searchMinScore?: number
156165
}
@@ -171,8 +180,10 @@ export class CodeIndexConfigManager {
171180
mistralApiKey: this.mistralOptions?.apiKey ?? "",
172181
qdrantUrl: this.qdrantUrl ?? "",
173182
valkeyUrl: this.valkeyUrl ?? "",
183+
valkeyUsername: this.valkeyUsername ?? "",
174184
searchProvider: this.searchProvider ?? "",
175185
qdrantApiKey: this.qdrantApiKey ?? "",
186+
valkeyPassword: this.valkeyPassword ?? "",
176187
}
177188

178189
// Refresh secrets from VSCode storage to ensure we have the latest values
@@ -198,6 +209,8 @@ export class CodeIndexConfigManager {
198209
qdrantUrl: this.qdrantUrl,
199210
qdrantApiKey: this.qdrantApiKey,
200211
valkeyUrl: this.valkeyUrl,
212+
valkeyPassword: this.valkeyPassword,
213+
valkeyUsername: this.valkeyUsername,
201214
searchProvider: this.searchProvider,
202215
searchMinScore: this.currentSearchMinScore,
203216
},
@@ -209,30 +222,26 @@ export class CodeIndexConfigManager {
209222
* Checks if the service is properly configured based on the embedder type.
210223
*/
211224
public isConfigured(): boolean {
225+
const dbUrlPresent = this.qdrantUrl || this.valkeyUrl
212226
if (this.embedderProvider === "openai") {
213227
const openAiKey = this.openAiOptions?.openAiNativeApiKey
214-
const qdrantUrl = this.qdrantUrl
215-
return !!(openAiKey && qdrantUrl)
228+
return !!(openAiKey && dbUrlPresent)
216229
} else if (this.embedderProvider === "ollama") {
217230
// Ollama model ID has a default, so only base URL is strictly required for config
218231
const ollamaBaseUrl = this.ollamaOptions?.ollamaBaseUrl
219-
const qdrantUrl = this.qdrantUrl
220-
return !!(ollamaBaseUrl && qdrantUrl)
232+
return !!(ollamaBaseUrl && dbUrlPresent)
221233
} else if (this.embedderProvider === "openai-compatible") {
222234
const baseUrl = this.openAiCompatibleOptions?.baseUrl
223235
const apiKey = this.openAiCompatibleOptions?.apiKey
224-
const qdrantUrl = this.qdrantUrl
225-
const isConfigured = !!(baseUrl && apiKey && qdrantUrl)
236+
const isConfigured = !!(baseUrl && apiKey && dbUrlPresent)
226237
return isConfigured
227238
} else if (this.embedderProvider === "gemini") {
228239
const apiKey = this.geminiOptions?.apiKey
229-
const qdrantUrl = this.qdrantUrl
230-
const isConfigured = !!(apiKey && qdrantUrl)
240+
const isConfigured = !!(apiKey && dbUrlPresent)
231241
return isConfigured
232242
} else if (this.embedderProvider === "mistral") {
233243
const apiKey = this.mistralOptions?.apiKey
234-
const qdrantUrl = this.qdrantUrl
235-
const isConfigured = !!(apiKey && qdrantUrl)
244+
const isConfigured = !!(apiKey && dbUrlPresent)
236245
return isConfigured
237246
}
238247
return false // Should not happen if embedderProvider is always set correctly
@@ -272,6 +281,8 @@ export class CodeIndexConfigManager {
272281
const prevValkeyUrl = prev?.valkeyUrl ?? ""
273282
const prevSearchProvider = prev?.searchProvider ?? ""
274283
const prevQdrantApiKey = prev?.qdrantApiKey ?? ""
284+
const prevValkeyPassword = prev?.valkeyPassword ?? ""
285+
const prevValkeyUsername = prev?.valkeyUsername ?? ""
275286

276287
// 1. Transition from disabled/unconfigured to enabled/configured
277288
if ((!prevEnabled || !prevConfigured) && this.codebaseIndexEnabled && nowConfigured) {
@@ -311,6 +322,8 @@ export class CodeIndexConfigManager {
311322
const currentValkeyUrl = this.valkeyUrl ?? ""
312323
const currentSearchProvider = this.searchProvider ?? ""
313324
const currentQdrantApiKey = this.qdrantApiKey ?? ""
325+
const currentValkeyPassword = this.valkeyPassword ?? ""
326+
const currentValkeyUsername = this.valkeyUsername ?? ""
314327

315328
if (prevOpenAiKey !== currentOpenAiKey) {
316329
return true
@@ -352,6 +365,14 @@ export class CodeIndexConfigManager {
352365
return true
353366
}
354367

368+
if (prevValkeyPassword !== currentValkeyPassword) {
369+
return true
370+
}
371+
372+
if (prevValkeyUsername !== currentValkeyUsername) {
373+
return true
374+
}
375+
355376
if (currentSearchProvider != prevSearchProvider) {
356377
return true
357378
}
@@ -408,6 +429,8 @@ export class CodeIndexConfigManager {
408429
qdrantApiKey: this.qdrantApiKey,
409430
searchProvider: this.searchProvider,
410431
valkeyUrl: this.valkeyUrl,
432+
valkeyUsername: this.valkeyUsername,
433+
valkeyPassword: this.valkeyPassword,
411434
searchMinScore: this.currentSearchMinScore,
412435
searchMaxResults: this.currentSearchMaxResults,
413436
}

src/services/code-index/interfaces/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export interface CodeIndexConfig {
1717
qdrantUrl?: string
1818
qdrantApiKey?: string
1919
valkeyUrl?: string
20+
valkeyUsername?: string
21+
valkeyPassword?: string
2022
searchProvider?: string
2123
searchMinScore?: number
2224
searchMaxResults?: number
@@ -40,5 +42,7 @@ export type PreviousConfigSnapshot = {
4042
qdrantUrl?: string
4143
qdrantApiKey?: string
4244
valkeyUrl?: string
45+
valkeyUsername?: string
46+
valkeyPassword?: string
4347
searchProvider?: string
4448
}

src/services/code-index/service-factory.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,13 @@ export class CodeIndexServiceFactory {
138138
if (searchProvider && searchProvider === "qdrant" && config.qdrantUrl) {
139139
return new QdrantVectorStore(this.workspacePath, config.qdrantUrl, vectorSize, config.qdrantApiKey)
140140
} else if (searchProvider === "valkey" && config.valkeyUrl) {
141-
return new ValkeySearchVectorStore(this.workspacePath, config.valkeyUrl, vectorSize)
141+
return new ValkeySearchVectorStore(
142+
this.workspacePath,
143+
config.valkeyUrl,
144+
vectorSize,
145+
config.valkeyUsername,
146+
config.valkeyPassword,
147+
)
142148
}
143149

144150
throw new Error(t("embeddings:serviceFactory.vectorUrlMissing"))

src/services/code-index/vector-store/valkey-search-client.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ export class ValkeySearchVectorStore implements IVectorStore {
1212
private isInitializing = false
1313
private readonly indexName: string
1414
private readonly valkeyUrl: string
15+
private readonly valkeyUsername?: string
16+
private readonly valkeyPassword?: string
1517

16-
constructor(workspacePath: string, url: string, vectorSize: number) {
18+
constructor(workspacePath: string, url: string, vectorSize: number, username?: string, password?: string) {
1719
this.valkeyUrl = this.parseValkeyUrl(url)
20+
this.valkeyUsername = username
21+
this.valkeyPassword = password
1822
this.vectorSize = vectorSize
1923

2024
const hash = createHash("sha256").update(workspacePath).digest("hex")
@@ -64,8 +68,8 @@ export class ValkeySearchVectorStore implements IVectorStore {
6468
this.client = new Valkey({
6569
host: hostname,
6670
port,
67-
password,
68-
username,
71+
password: this.valkeyPassword || password,
72+
username: this.valkeyUsername || username,
6973
})
7074

7175
this.client.on("error", (err: Error) => {

src/shared/WebviewMessage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ export interface WebviewMessage {
260260
// Secret settings
261261
codeIndexOpenAiKey?: string
262262
codeIndexQdrantApiKey?: string
263+
codeIndexValkeyPassword?: string
263264
codebaseIndexValkeyUrl?: string
265+
codebaseIndexValkeyUsername?: string
264266
codebaseIndexOpenAiCompatibleApiKey?: string
265267
codebaseIndexGeminiApiKey?: string
266268
codebaseIndexMistralApiKey?: string

0 commit comments

Comments
 (0)