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) {
const credits = await fetchKoduCredits({ apiKey: koduApiKey })
await this.updateGlobalState("koduCredits", credits)
await this.postStateToWebview()
await this.postMessageToWebview({ type: "action", action: "koduCreditsFetched" })
await this.postMessageToWebview({
type: "action",
action: "koduCreditsFetched",
state: await this.getStateToPostToWebview(),
})
}
break
// Add more switch case statements here as more webview message commands
@@ -491,6 +494,11 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
}
async postStateToWebview() {
const state = await this.getStateToPostToWebview()
this.postMessageToWebview({ type: "state", state })
}
async getStateToPostToWebview() {
const {
apiConfiguration,
maxRequestsPerTask,
@@ -500,9 +508,7 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
taskHistory,
koduCredits,
} = await this.getState()
this.postMessageToWebview({
type: "state",
state: {
return {
version: this.context.extension?.packageJSON?.version ?? "",
apiConfiguration,
maxRequestsPerTask,
@@ -513,8 +519,7 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
taskHistory: (taskHistory || []).filter((item) => item.ts && item.task).sort((a, b) => b.ts - a.ts),
shouldShowAnnouncement: lastShownAnnouncementId !== this.latestAnnouncementId,
koduCredits,
},
})
}
}
async clearTask() {