Fix state messaging when updating credits

This commit is contained in:
Saoud Rizwan
2024-08-25 12:30:13 -04:00
parent 2a0a5435bc
commit 6c7f4a6533

View File

@@ -372,8 +372,11 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
if (koduApiKey) { if (koduApiKey) {
const credits = await fetchKoduCredits({ apiKey: koduApiKey }) const credits = await fetchKoduCredits({ apiKey: koduApiKey })
await this.updateGlobalState("koduCredits", credits) await this.updateGlobalState("koduCredits", credits)
await this.postStateToWebview() await this.postMessageToWebview({
await this.postMessageToWebview({ type: "action", action: "koduCreditsFetched" }) type: "action",
action: "koduCreditsFetched",
state: await this.getStateToPostToWebview(),
})
} }
break break
// Add more switch case statements here as more webview message commands // Add more switch case statements here as more webview message commands
@@ -491,6 +494,11 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
} }
async postStateToWebview() { async postStateToWebview() {
const state = await this.getStateToPostToWebview()
this.postMessageToWebview({ type: "state", state })
}
async getStateToPostToWebview() {
const { const {
apiConfiguration, apiConfiguration,
maxRequestsPerTask, maxRequestsPerTask,
@@ -500,21 +508,18 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
taskHistory, taskHistory,
koduCredits, koduCredits,
} = await this.getState() } = await this.getState()
this.postMessageToWebview({ return {
type: "state", version: this.context.extension?.packageJSON?.version ?? "",
state: { apiConfiguration,
version: this.context.extension?.packageJSON?.version ?? "", maxRequestsPerTask,
apiConfiguration, customInstructions,
maxRequestsPerTask, alwaysAllowReadOnly,
customInstructions, themeName: vscode.workspace.getConfiguration("workbench").get<string>("colorTheme"),
alwaysAllowReadOnly, claudeMessages: this.claudeDev?.claudeMessages || [],
themeName: vscode.workspace.getConfiguration("workbench").get<string>("colorTheme"), taskHistory: (taskHistory || []).filter((item) => item.ts && item.task).sort((a, b) => b.ts - a.ts),
claudeMessages: this.claudeDev?.claudeMessages || [], shouldShowAnnouncement: lastShownAnnouncementId !== this.latestAnnouncementId,
taskHistory: (taskHistory || []).filter((item) => item.ts && item.task).sort((a, b) => b.ts - a.ts), koduCredits,
shouldShowAnnouncement: lastShownAnnouncementId !== this.latestAnnouncementId, }
koduCredits,
},
})
} }
async clearTask() { async clearTask() {