Skip to content

Commit d883d90

Browse files
committed
change valkeyUrl
1 parent 959fe94 commit d883d90

File tree

14 files changed

+151
-128
lines changed

14 files changed

+151
-128
lines changed

packages/types/src/codebase-index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export const codebaseIndexConfigSchema = z.object({
3434
// OpenAI Compatible specific fields
3535
codebaseIndexOpenAiCompatibleBaseUrl: z.string().optional(),
3636
codebaseIndexOpenAiCompatibleModelDimension: z.number().optional(),
37-
codebaseIndexValkeyUrl: z.string().optional(),
37+
codebaseIndexValkeyHostname: z.string().optional(),
38+
codebaseIndexValkeyPort: z.number().optional(),
3839
codebaseIndexValkeyUsername: z.string().optional(),
3940
codebaseIndexValkeyPassword: z.string().optional(),
4041
searchProvider: z.string().optional(),
@@ -63,6 +64,7 @@ export type CodebaseIndexModels = z.infer<typeof codebaseIndexModelsSchema>
6364
export const codebaseIndexProviderSchema = z.object({
6465
codeIndexOpenAiKey: z.string().optional(),
6566
codeIndexQdrantApiKey: z.string().optional(),
67+
codebaseIndexValkeyUsername: z.string().optional(),
6668
codeIndexValkeyPassword: z.string().optional(),
6769
codebaseIndexOpenAiCompatibleBaseUrl: z.string().optional(),
6870
codebaseIndexOpenAiCompatibleApiKey: z.string().optional(),

src/core/webview/ClineProvider.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,8 @@ export class ClineProvider
15471547
codebaseIndexConfig: {
15481548
codebaseIndexEnabled: codebaseIndexConfig?.codebaseIndexEnabled ?? true,
15491549
codebaseIndexQdrantUrl: codebaseIndexConfig?.codebaseIndexQdrantUrl ?? "http://localhost:6333",
1550-
codebaseIndexValkeyUrl: codebaseIndexConfig?.codebaseIndexValkeyUrl ?? "redis://localhost:6379",
1550+
codebaseIndexValkeyHostname: codebaseIndexConfig?.codebaseIndexValkeyHostname ?? "localhost",
1551+
codebaseIndexValkeyPort: codebaseIndexConfig?.codebaseIndexValkeyPort ?? 6379,
15511552
codebaseIndexValkeyUsername: codebaseIndexConfig?.codebaseIndexValkeyUsername ?? "",
15521553
codebaseIndexValkeyPassword: codebaseIndexConfig?.codebaseIndexValkeyPassword ?? "",
15531554
codebaseIndexEmbedderProvider: codebaseIndexConfig?.codebaseIndexEmbedderProvider ?? "openai",
@@ -1720,8 +1721,9 @@ export class ClineProvider
17201721
codebaseIndexEnabled: stateValues.codebaseIndexConfig?.codebaseIndexEnabled ?? true,
17211722
codebaseIndexQdrantUrl:
17221723
stateValues.codebaseIndexConfig?.codebaseIndexQdrantUrl ?? "http://localhost:6333",
1723-
codebaseIndexValkeyUrl:
1724-
stateValues.codebaseIndexConfig?.codebaseIndexValkeyUrl ?? "http://localhost:6379",
1724+
codebaseIndexValkeyHostname:
1725+
stateValues.codebaseIndexConfig?.codebaseIndexValkeyHostname ?? "localhost",
1726+
codebaseIndexValkeyPort: stateValues.codebaseIndexConfig?.codebaseIndexValkeyPort ?? 6379,
17251727
codebaseIndexValkeyUsername: stateValues.codebaseIndexConfig?.codebaseIndexValkeyUsername ?? "",
17261728
codebaseIndexValkeyPassword: stateValues.codebaseIndexConfig?.codebaseIndexValkeyPassword ?? "",
17271729
codebaseIndexEmbedderProvider:

src/core/webview/webviewMessageHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1991,7 +1991,8 @@ export const webviewMessageHandler = async (
19911991
...currentConfig,
19921992
codebaseIndexEnabled: settings.codebaseIndexEnabled,
19931993
codebaseIndexQdrantUrl: settings.codebaseIndexQdrantUrl,
1994-
codebaseIndexValkeyUrl: settings.codebaseIndexValkeyUrl,
1994+
codebaseIndexValkeyHostname: settings.codebaseIndexValkeyHostname,
1995+
codebaseIndexValkeyPort: settings.codebaseIndexValkeyPort,
19951996
codebaseIndexValkeyUsername: settings.codebaseIndexValkeyUsername,
19961997
codebaseIndexValkeyPassword: settings.codeIndexValkeyPassword,
19971998
codebaseIndexEmbedderProvider: settings.codebaseIndexEmbedderProvider,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ describe("CodeIndexConfigManager", () => {
112112
openAiOptions: { openAiNativeApiKey: "" },
113113
ollamaOptions: { ollamaBaseUrl: "" },
114114
qdrantUrl: "http://localhost:6333",
115-
valkeyUrl: "http://localhost:6379",
115+
valkeyHostname: "localhost",
116+
valkeyPort: 6379,
116117
qdrantApiKey: "",
117118
searchMinScore: 0.4,
118119
})

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export class CodeIndexConfigManager {
2222
private qdrantUrl?: string = "http://localhost:6333"
2323
private qdrantApiKey?: string
2424
private searchProvider?: string
25-
private valkeyUrl?: string = "http://localhost:6379"
25+
private valkeyHostname?: string = "localhost"
26+
private valkeyPort?: number = 6379
2627
private valkeyUsername?: string
2728
private valkeyPassword?: string
2829
private searchMinScore?: number
@@ -49,7 +50,8 @@ export class CodeIndexConfigManager {
4950
const codebaseIndexConfig = this.contextProxy?.getGlobalState("codebaseIndexConfig") ?? {
5051
codebaseIndexEnabled: true,
5152
codebaseIndexQdrantUrl: "http://localhost:6333",
52-
codebaseIndexValkeyUrl: "http://localhost:6379",
53+
codebaseIndexValkeyHostname: "localhost",
54+
codebaseIndexValkeyPort: 6379,
5355
codebaseIndexValkeyUsername: "",
5456
codebaseIndexEmbedderProvider: "openai",
5557
codebaseIndexEmbedderBaseUrl: "",
@@ -61,7 +63,8 @@ export class CodeIndexConfigManager {
6163
const {
6264
codebaseIndexEnabled,
6365
codebaseIndexQdrantUrl,
64-
codebaseIndexValkeyUrl,
66+
codebaseIndexValkeyHostname,
67+
codebaseIndexValkeyPort,
6568
codebaseIndexValkeyUsername,
6669
codebaseIndexEmbedderProvider,
6770
codebaseIndexEmbedderBaseUrl,
@@ -84,7 +87,8 @@ export class CodeIndexConfigManager {
8487
this.codebaseIndexEnabled = codebaseIndexEnabled ?? true
8588
this.qdrantUrl = codebaseIndexQdrantUrl
8689
this.qdrantApiKey = qdrantApiKey ?? ""
87-
this.valkeyUrl = codebaseIndexValkeyUrl
90+
this.valkeyHostname = codebaseIndexValkeyHostname ?? "localhost"
91+
this.valkeyPort = codebaseIndexValkeyPort ?? 6379
8892
this.valkeyPassword = valkeyPassword
8993
this.valkeyUsername = codebaseIndexValkeyUsername
9094
this.searchMinScore = codebaseIndexSearchMinScore
@@ -157,7 +161,8 @@ export class CodeIndexConfigManager {
157161
mistralOptions?: { apiKey: string }
158162
qdrantUrl?: string
159163
qdrantApiKey?: string
160-
valkeyUrl?: string
164+
valkeyHostname?: string
165+
valkeyPort?: number
161166
valkeyPassword?: string
162167
valkeyUsername?: string
163168
searchProvider?: string
@@ -179,7 +184,8 @@ export class CodeIndexConfigManager {
179184
geminiApiKey: this.geminiOptions?.apiKey ?? "",
180185
mistralApiKey: this.mistralOptions?.apiKey ?? "",
181186
qdrantUrl: this.qdrantUrl ?? "",
182-
valkeyUrl: this.valkeyUrl ?? "",
187+
valkeyHostname: this.valkeyHostname ?? "",
188+
valkeyPort: this.valkeyPort ?? 6379,
183189
valkeyUsername: this.valkeyUsername ?? "",
184190
searchProvider: this.searchProvider ?? "",
185191
qdrantApiKey: this.qdrantApiKey ?? "",
@@ -208,7 +214,8 @@ export class CodeIndexConfigManager {
208214
mistralOptions: this.mistralOptions,
209215
qdrantUrl: this.qdrantUrl,
210216
qdrantApiKey: this.qdrantApiKey,
211-
valkeyUrl: this.valkeyUrl,
217+
valkeyHostname: this.valkeyHostname,
218+
valkeyPort: this.valkeyPort,
212219
valkeyPassword: this.valkeyPassword,
213220
valkeyUsername: this.valkeyUsername,
214221
searchProvider: this.searchProvider,
@@ -222,7 +229,7 @@ export class CodeIndexConfigManager {
222229
* Checks if the service is properly configured based on the embedder type.
223230
*/
224231
public isConfigured(): boolean {
225-
const dbUrlPresent = this.qdrantUrl || this.valkeyUrl
232+
const dbUrlPresent = this.qdrantUrl || this.valkeyHostname
226233
if (this.embedderProvider === "openai") {
227234
const openAiKey = this.openAiOptions?.openAiNativeApiKey
228235
return !!(openAiKey && dbUrlPresent)
@@ -278,7 +285,8 @@ export class CodeIndexConfigManager {
278285
const prevGeminiApiKey = prev?.geminiApiKey ?? ""
279286
const prevMistralApiKey = prev?.mistralApiKey ?? ""
280287
const prevQdrantUrl = prev?.qdrantUrl ?? ""
281-
const prevValkeyUrl = prev?.valkeyUrl ?? ""
288+
const prevValkeyHostname = prev?.valkeyHostname ?? ""
289+
const prevValkeyPort = prev?.valkeyPort ?? 6379
282290
const prevSearchProvider = prev?.searchProvider ?? ""
283291
const prevQdrantApiKey = prev?.qdrantApiKey ?? ""
284292
const prevValkeyPassword = prev?.valkeyPassword ?? ""
@@ -319,7 +327,8 @@ export class CodeIndexConfigManager {
319327
const currentGeminiApiKey = this.geminiOptions?.apiKey ?? ""
320328
const currentMistralApiKey = this.mistralOptions?.apiKey ?? ""
321329
const currentQdrantUrl = this.qdrantUrl ?? ""
322-
const currentValkeyUrl = this.valkeyUrl ?? ""
330+
const currentValkeyHostname = this.valkeyHostname ?? ""
331+
const currentValkeyPort = this.valkeyPort ?? 6379
323332
const currentSearchProvider = this.searchProvider ?? ""
324333
const currentQdrantApiKey = this.qdrantApiKey ?? ""
325334
const currentValkeyPassword = this.valkeyPassword ?? ""
@@ -361,7 +370,7 @@ export class CodeIndexConfigManager {
361370
return true
362371
}
363372

364-
if (prevValkeyUrl !== currentValkeyUrl) {
373+
if (prevValkeyHostname !== currentValkeyHostname || prevValkeyPort !== currentValkeyPort) {
365374
return true
366375
}
367376

@@ -428,7 +437,8 @@ export class CodeIndexConfigManager {
428437
qdrantUrl: this.qdrantUrl,
429438
qdrantApiKey: this.qdrantApiKey,
430439
searchProvider: this.searchProvider,
431-
valkeyUrl: this.valkeyUrl,
440+
valkeyHostname: this.valkeyHostname,
441+
valkeyPort: this.valkeyPort,
432442
valkeyUsername: this.valkeyUsername,
433443
valkeyPassword: this.valkeyPassword,
434444
searchMinScore: this.currentSearchMinScore,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export interface CodeIndexConfig {
1616
mistralOptions?: { apiKey: string }
1717
qdrantUrl?: string
1818
qdrantApiKey?: string
19-
valkeyUrl?: string
19+
valkeyHostname?: string
20+
valkeyPort?: number
2021
valkeyUsername?: string
2122
valkeyPassword?: string
2223
searchProvider?: string
@@ -41,7 +42,8 @@ export type PreviousConfigSnapshot = {
4142
mistralApiKey?: string
4243
qdrantUrl?: string
4344
qdrantApiKey?: string
44-
valkeyUrl?: string
45+
valkeyHostname?: string
46+
valkeyPort?: number
4547
valkeyUsername?: string
4648
valkeyPassword?: string
4749
searchProvider?: string

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,11 @@ export class CodeIndexServiceFactory {
137137

138138
if (searchProvider && searchProvider === "qdrant" && config.qdrantUrl) {
139139
return new QdrantVectorStore(this.workspacePath, config.qdrantUrl, vectorSize, config.qdrantApiKey)
140-
} else if (searchProvider === "valkey" && config.valkeyUrl) {
140+
} else if (searchProvider === "valkey" && config.valkeyHostname) {
141141
return new ValkeySearchVectorStore(
142142
this.workspacePath,
143-
config.valkeyUrl,
143+
config.valkeyHostname,
144+
config.valkeyPort ?? 6379,
144145
vectorSize,
145146
config.valkeyUsername,
146147
config.valkeyPassword,

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

Lines changed: 20 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@ export class ValkeySearchVectorStore implements IVectorStore {
1111
private client: Redis | null = null
1212
private isInitializing = false
1313
private readonly indexName: string
14-
private readonly valkeyUrl: string
14+
private readonly valkeyHostname: string
15+
private readonly valkeyPort: number
1516
private readonly valkeyUsername?: string
1617
private readonly valkeyPassword?: string
1718

18-
constructor(workspacePath: string, url: string, vectorSize: number, username?: string, password?: string) {
19-
this.valkeyUrl = this.parseValkeyUrl(url)
19+
constructor(
20+
workspacePath: string,
21+
hostname: string,
22+
port: number,
23+
vectorSize: number,
24+
username?: string,
25+
password?: string,
26+
) {
27+
this.valkeyHostname = hostname
28+
this.valkeyPort = port
2029
this.valkeyUsername = username
2130
this.valkeyPassword = password
2231
this.vectorSize = vectorSize
@@ -26,36 +35,6 @@ export class ValkeySearchVectorStore implements IVectorStore {
2635
this.initializeClient()
2736
}
2837

29-
private parseValkeyUrl(url: string | undefined): string {
30-
if (!url || url.trim() === "") {
31-
return "http://localhost:6379"
32-
}
33-
34-
const trimmedUrl = url.trim()
35-
36-
if (!trimmedUrl.startsWith("http://") && !trimmedUrl.startsWith("https://") && !trimmedUrl.includes("://")) {
37-
return this.parseHostname(trimmedUrl)
38-
}
39-
40-
try {
41-
const parsedUrl = new URL(trimmedUrl)
42-
return trimmedUrl
43-
} catch {
44-
// Failed to parse as URL - treat as hostname
45-
return this.parseHostname(trimmedUrl)
46-
}
47-
}
48-
49-
private parseHostname(hostname: string): string {
50-
if (hostname.includes(":")) {
51-
// Has port - add http:// prefix if missing
52-
return hostname.startsWith("http") ? hostname : `http://${hostname}`
53-
} else {
54-
// No port - add http:// prefix without port (let constructor handle port assignment)
55-
return `http://${hostname}`
56-
}
57-
}
58-
5938
private async initializeClient(): Promise<void> {
6039
if (this.isInitializing || (this.client && this.client.status === "ready")) {
6140
return
@@ -64,21 +43,19 @@ export class ValkeySearchVectorStore implements IVectorStore {
6443
this.isInitializing = true
6544

6645
try {
67-
const { hostname, port, password, username } = this.parseConnectionOptions()
6846
this.client = new Valkey({
69-
host: hostname,
70-
port,
71-
password: this.valkeyPassword || password,
72-
username: this.valkeyUsername || username,
47+
host: this.valkeyHostname,
48+
port: this.valkeyPort,
49+
password: this.valkeyPassword,
50+
username: this.valkeyUsername,
7351
})
74-
7552
this.client.on("error", (err: Error) => {
7653
console.error("[ValkeySearch] Connection error:", err)
7754
this.isInitializing = false
7855
throw new Error(
7956
t("embeddings:vectorStore.vectorError", {
80-
valkeyUrl: this.valkeyUrl,
81-
errorMessage: err,
57+
valkeyHostname: this.valkeyHostname,
58+
valkeyPort: this.valkeyPort,
8259
}),
8360
{ cause: err },
8461
)
@@ -103,8 +80,8 @@ export class ValkeySearchVectorStore implements IVectorStore {
10380
}
10481
throw new Error(
10582
t("embeddings:vectorStore.valkeyConnectionFailed", {
106-
valkeyUrl: this.valkeyUrl,
107-
errorMessage: error,
83+
valkeyHostname: this.valkeyHostname,
84+
valkeyPort: this.valkeyPort,
10885
}),
10986
{ cause: error },
11087
)
@@ -113,16 +90,6 @@ export class ValkeySearchVectorStore implements IVectorStore {
11390
}
11491
}
11592

116-
private parseConnectionOptions() {
117-
const url = new URL(this.valkeyUrl)
118-
return {
119-
hostname: url.hostname,
120-
port: Number(url.port) || 6379,
121-
password: url.password || undefined,
122-
username: url.username || undefined,
123-
}
124-
}
125-
12693
private async ensureConnected() {
12794
if (!this.client || this.client.status !== "ready") {
12895
await this.initializeClient()

src/shared/WebviewMessage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ export interface WebviewMessage {
261261
codeIndexOpenAiKey?: string
262262
codeIndexQdrantApiKey?: string
263263
codeIndexValkeyPassword?: string
264-
codebaseIndexValkeyUrl?: string
264+
codebaseIndexValkeyHostname?: string
265+
codebaseIndexValkeyPort?: number
265266
codebaseIndexValkeyUsername?: string
266267
codebaseIndexOpenAiCompatibleApiKey?: string
267268
codebaseIndexGeminiApiKey?: string

0 commit comments

Comments
 (0)