mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-10-24 01:24:18 +08:00
feat(settings): add config fetch/send/update in KiloProvider
This commit is contained in:
@@ -13,6 +13,8 @@ export class KiloProvider implements vscode.WebviewViewProvider {
|
||||
private cachedProvidersMessage: unknown = null
|
||||
/** Cached agentsLoaded payload so requestAgents can be served before httpClient is ready */
|
||||
private cachedAgentsMessage: unknown = null
|
||||
/** Cached configLoaded payload so requestConfig can be served before httpClient is ready */
|
||||
private cachedConfigMessage: unknown = null
|
||||
|
||||
private trackedSessionIds: Set<string> = new Set()
|
||||
private unsubscribeEvent: (() => void) | null = null
|
||||
@@ -209,6 +211,12 @@ export class KiloProvider implements vscode.WebviewViewProvider {
|
||||
case "questionReject":
|
||||
await this.handleQuestionReject(message.requestID)
|
||||
break
|
||||
case "requestConfig":
|
||||
await this.fetchAndSendConfig()
|
||||
break
|
||||
case "updateConfig":
|
||||
await this.handleUpdateConfig(message.config)
|
||||
break
|
||||
case "setLanguage":
|
||||
await vscode.workspace
|
||||
.getConfiguration("kilo-code.new")
|
||||
@@ -307,6 +315,7 @@ export class KiloProvider implements vscode.WebviewViewProvider {
|
||||
// Fetch providers and agents, then send to webview
|
||||
await this.fetchAndSendProviders()
|
||||
await this.fetchAndSendAgents()
|
||||
await this.fetchAndSendConfig()
|
||||
|
||||
console.log("[Kilo New] KiloProvider: ✅ initializeConnection completed successfully")
|
||||
} catch (error) {
|
||||
@@ -588,6 +597,61 @@ export class KiloProvider implements vscode.WebviewViewProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch backend config and send to webview.
|
||||
*/
|
||||
private async fetchAndSendConfig(): Promise<void> {
|
||||
if (!this.httpClient) {
|
||||
if (this.cachedConfigMessage) {
|
||||
this.postMessage(this.cachedConfigMessage)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const workspaceDir = this.getWorkspaceDirectory()
|
||||
const config = await this.httpClient.getConfig(workspaceDir)
|
||||
|
||||
const message = {
|
||||
type: "configLoaded",
|
||||
config,
|
||||
}
|
||||
this.cachedConfigMessage = message
|
||||
this.postMessage(message)
|
||||
} catch (error) {
|
||||
console.error("[Kilo New] KiloProvider: Failed to fetch config:", error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle config update request from the webview.
|
||||
* Applies a partial config update, then re-fetches and pushes the full config.
|
||||
*/
|
||||
private async handleUpdateConfig(partial: Record<string, unknown>): Promise<void> {
|
||||
if (!this.httpClient) {
|
||||
this.postMessage({ type: "error", message: "Not connected to CLI backend" })
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const workspaceDir = this.getWorkspaceDirectory()
|
||||
const updated = await this.httpClient.updateConfig(partial, workspaceDir)
|
||||
|
||||
const message = {
|
||||
type: "configUpdated",
|
||||
config: updated,
|
||||
}
|
||||
this.cachedConfigMessage = { type: "configLoaded", config: updated }
|
||||
this.postMessage(message)
|
||||
} catch (error) {
|
||||
console.error("[Kilo New] KiloProvider: Failed to update config:", error)
|
||||
this.postMessage({
|
||||
type: "error",
|
||||
message: error instanceof Error ? error.message : "Failed to update config",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle sending a message from the webview.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user