|
@@ -8,7 +8,6 @@ import { downloadTask, getNonce, getUri, selectImages } from "../utils"
|
|
|
import * as path from "path"
|
|
import * as path from "path"
|
|
|
import fs from "fs/promises"
|
|
import fs from "fs/promises"
|
|
|
import { HistoryItem } from "../shared/HistoryItem"
|
|
import { HistoryItem } from "../shared/HistoryItem"
|
|
|
-import { fetchKoduCredits } from "../api/kodu"
|
|
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
|
|
https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
|
|
@@ -16,19 +15,16 @@ https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default
|
|
|
https://github.com/KumarVariable/vscode-extension-sidebar-html/blob/master/src/customSidebarViewProvider.ts
|
|
https://github.com/KumarVariable/vscode-extension-sidebar-html/blob/master/src/customSidebarViewProvider.ts
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-type SecretKey = "apiKey" | "openRouterApiKey" | "awsAccessKey" | "awsSecretKey" | "koduApiKey"
|
|
|
|
|
|
|
+type SecretKey = "apiKey" | "openRouterApiKey" | "awsAccessKey" | "awsSecretKey"
|
|
|
type GlobalStateKey =
|
|
type GlobalStateKey =
|
|
|
| "apiProvider"
|
|
| "apiProvider"
|
|
|
| "apiModelId"
|
|
| "apiModelId"
|
|
|
| "awsRegion"
|
|
| "awsRegion"
|
|
|
- | "koduEmail"
|
|
|
|
|
- | "koduCredits"
|
|
|
|
|
| "maxRequestsPerTask"
|
|
| "maxRequestsPerTask"
|
|
|
| "lastShownAnnouncementId"
|
|
| "lastShownAnnouncementId"
|
|
|
| "customInstructions"
|
|
| "customInstructions"
|
|
|
| "alwaysAllowReadOnly"
|
|
| "alwaysAllowReadOnly"
|
|
|
| "taskHistory"
|
|
| "taskHistory"
|
|
|
- | "shouldShowKoduPromo"
|
|
|
|
|
|
|
|
|
|
export class ClaudeDevProvider implements vscode.WebviewViewProvider {
|
|
export class ClaudeDevProvider implements vscode.WebviewViewProvider {
|
|
|
public static readonly sideBarId = "claude-dev.SidebarProvider" // used in package.json as the view's id. This value cannot be changed due to how vscode caches views based on their id, and updating the id would break existing instances of the extension.
|
|
public static readonly sideBarId = "claude-dev.SidebarProvider" // used in package.json as the view's id. This value cannot be changed due to how vscode caches views based on their id, and updating the id would break existing instances of the extension.
|
|
@@ -40,6 +36,28 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
|
|
|
|
|
|
|
|
constructor(readonly context: vscode.ExtensionContext, private readonly outputChannel: vscode.OutputChannel) {
|
|
constructor(readonly context: vscode.ExtensionContext, private readonly outputChannel: vscode.OutputChannel) {
|
|
|
this.outputChannel.appendLine("ClaudeDevProvider instantiated")
|
|
this.outputChannel.appendLine("ClaudeDevProvider instantiated")
|
|
|
|
|
+ this.revertKodu()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async revertKodu() {
|
|
|
|
|
+ const apiProvider = await this.getGlobalState("apiProvider")
|
|
|
|
|
+ if (apiProvider === "kodu") {
|
|
|
|
|
+ // switch back to previous provider
|
|
|
|
|
+ const anthropicKey = await this.getSecret("apiKey")
|
|
|
|
|
+ if (anthropicKey) {
|
|
|
|
|
+ await this.updateGlobalState("apiProvider", "anthropic" as ApiProvider)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const openRouterApiKey = await this.getSecret("openRouterApiKey")
|
|
|
|
|
+ if (openRouterApiKey) {
|
|
|
|
|
+ await this.updateGlobalState("apiProvider", "openrouter" as ApiProvider)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const awsAccessKey = await this.getSecret("awsAccessKey")
|
|
|
|
|
+ if (awsAccessKey) {
|
|
|
|
|
+ await this.updateGlobalState("apiProvider", "bedrock" as ApiProvider)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -359,25 +377,6 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
|
|
|
case "exportTaskWithId":
|
|
case "exportTaskWithId":
|
|
|
this.exportTaskWithId(message.text!)
|
|
this.exportTaskWithId(message.text!)
|
|
|
break
|
|
break
|
|
|
- case "didClickKoduSignOut":
|
|
|
|
|
- await this.signOutKodu()
|
|
|
|
|
- break
|
|
|
|
|
- case "fetchKoduCredits":
|
|
|
|
|
- const koduApiKey = await this.getSecret("koduApiKey")
|
|
|
|
|
- if (koduApiKey) {
|
|
|
|
|
- const credits = await fetchKoduCredits({ apiKey: koduApiKey })
|
|
|
|
|
- await this.updateGlobalState("koduCredits", credits)
|
|
|
|
|
- await this.postMessageToWebview({
|
|
|
|
|
- type: "action",
|
|
|
|
|
- action: "koduCreditsFetched",
|
|
|
|
|
- state: await this.getStateToPostToWebview(),
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- break
|
|
|
|
|
- case "didDismissKoduPromo":
|
|
|
|
|
- await this.updateGlobalState("shouldShowKoduPromo", false)
|
|
|
|
|
- await this.postStateToWebview()
|
|
|
|
|
- break
|
|
|
|
|
case "resetState":
|
|
case "resetState":
|
|
|
await this.resetState()
|
|
await this.resetState()
|
|
|
break
|
|
break
|
|
@@ -390,27 +389,6 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Kodu
|
|
|
|
|
-
|
|
|
|
|
- async saveKoduApiKey(apiKey: string, email?: string) {
|
|
|
|
|
- await this.storeSecret("koduApiKey", apiKey)
|
|
|
|
|
- await this.updateGlobalState("koduEmail", email)
|
|
|
|
|
- await this.updateGlobalState("apiProvider", "kodu")
|
|
|
|
|
- await this.updateGlobalState("shouldShowKoduPromo", false)
|
|
|
|
|
- await this.postStateToWebview()
|
|
|
|
|
- await this.postMessageToWebview({ type: "action", action: "koduAuthenticated" })
|
|
|
|
|
- this.claudeDev?.updateApi({ apiProvider: "kodu", koduApiKey: apiKey })
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async signOutKodu() {
|
|
|
|
|
- await this.storeSecret("koduApiKey", undefined)
|
|
|
|
|
- await this.updateGlobalState("koduEmail", undefined)
|
|
|
|
|
- await this.updateGlobalState("koduCredits", undefined)
|
|
|
|
|
- await this.updateGlobalState("apiProvider", "kodu")
|
|
|
|
|
- this.claudeDev?.updateApi({ apiProvider: "kodu", koduApiKey: undefined })
|
|
|
|
|
- await this.postStateToWebview()
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// Task history
|
|
// Task history
|
|
|
|
|
|
|
|
async getTaskWithId(id: string): Promise<{
|
|
async getTaskWithId(id: string): Promise<{
|
|
@@ -510,8 +488,6 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
|
|
|
customInstructions,
|
|
customInstructions,
|
|
|
alwaysAllowReadOnly,
|
|
alwaysAllowReadOnly,
|
|
|
taskHistory,
|
|
taskHistory,
|
|
|
- koduCredits,
|
|
|
|
|
- shouldShowKoduPromo,
|
|
|
|
|
} = await this.getState()
|
|
} = await this.getState()
|
|
|
return {
|
|
return {
|
|
|
version: this.context.extension?.packageJSON?.version ?? "",
|
|
version: this.context.extension?.packageJSON?.version ?? "",
|
|
@@ -524,8 +500,6 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
|
|
|
claudeMessages: this.claudeDev?.claudeMessages || [],
|
|
claudeMessages: this.claudeDev?.claudeMessages || [],
|
|
|
taskHistory: (taskHistory || []).filter((item) => item.ts && item.task).sort((a, b) => b.ts - a.ts),
|
|
taskHistory: (taskHistory || []).filter((item) => item.ts && item.task).sort((a, b) => b.ts - a.ts),
|
|
|
shouldShowAnnouncement: lastShownAnnouncementId !== this.latestAnnouncementId,
|
|
shouldShowAnnouncement: lastShownAnnouncementId !== this.latestAnnouncementId,
|
|
|
- koduCredits,
|
|
|
|
|
- shouldShowKoduPromo,
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -624,15 +598,11 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
|
|
|
awsAccessKey,
|
|
awsAccessKey,
|
|
|
awsSecretKey,
|
|
awsSecretKey,
|
|
|
awsRegion,
|
|
awsRegion,
|
|
|
- koduApiKey,
|
|
|
|
|
- koduEmail,
|
|
|
|
|
- koduCredits,
|
|
|
|
|
maxRequestsPerTask,
|
|
maxRequestsPerTask,
|
|
|
lastShownAnnouncementId,
|
|
lastShownAnnouncementId,
|
|
|
customInstructions,
|
|
customInstructions,
|
|
|
alwaysAllowReadOnly,
|
|
alwaysAllowReadOnly,
|
|
|
taskHistory,
|
|
taskHistory,
|
|
|
- shouldShowKoduPromo,
|
|
|
|
|
] = await Promise.all([
|
|
] = await Promise.all([
|
|
|
this.getGlobalState("apiProvider") as Promise<ApiProvider | undefined>,
|
|
this.getGlobalState("apiProvider") as Promise<ApiProvider | undefined>,
|
|
|
this.getGlobalState("apiModelId") as Promise<ApiModelId | undefined>,
|
|
this.getGlobalState("apiModelId") as Promise<ApiModelId | undefined>,
|
|
@@ -641,15 +611,11 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
|
|
|
this.getSecret("awsAccessKey") as Promise<string | undefined>,
|
|
this.getSecret("awsAccessKey") as Promise<string | undefined>,
|
|
|
this.getSecret("awsSecretKey") as Promise<string | undefined>,
|
|
this.getSecret("awsSecretKey") as Promise<string | undefined>,
|
|
|
this.getGlobalState("awsRegion") as Promise<string | undefined>,
|
|
this.getGlobalState("awsRegion") as Promise<string | undefined>,
|
|
|
- this.getSecret("koduApiKey") as Promise<string | undefined>,
|
|
|
|
|
- this.getGlobalState("koduEmail") as Promise<string | undefined>,
|
|
|
|
|
- this.getGlobalState("koduCredits") as Promise<number | undefined>,
|
|
|
|
|
this.getGlobalState("maxRequestsPerTask") as Promise<number | undefined>,
|
|
this.getGlobalState("maxRequestsPerTask") as Promise<number | undefined>,
|
|
|
this.getGlobalState("lastShownAnnouncementId") as Promise<string | undefined>,
|
|
this.getGlobalState("lastShownAnnouncementId") as Promise<string | undefined>,
|
|
|
this.getGlobalState("customInstructions") as Promise<string | undefined>,
|
|
this.getGlobalState("customInstructions") as Promise<string | undefined>,
|
|
|
this.getGlobalState("alwaysAllowReadOnly") as Promise<boolean | undefined>,
|
|
this.getGlobalState("alwaysAllowReadOnly") as Promise<boolean | undefined>,
|
|
|
this.getGlobalState("taskHistory") as Promise<HistoryItem[] | undefined>,
|
|
this.getGlobalState("taskHistory") as Promise<HistoryItem[] | undefined>,
|
|
|
- this.getGlobalState("shouldShowKoduPromo") as Promise<boolean | undefined>,
|
|
|
|
|
])
|
|
])
|
|
|
|
|
|
|
|
let apiProvider: ApiProvider
|
|
let apiProvider: ApiProvider
|
|
@@ -661,8 +627,8 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
|
|
|
if (apiKey) {
|
|
if (apiKey) {
|
|
|
apiProvider = "anthropic"
|
|
apiProvider = "anthropic"
|
|
|
} else {
|
|
} else {
|
|
|
- // New users should default to kodu
|
|
|
|
|
- apiProvider = "kodu"
|
|
|
|
|
|
|
+ // New users should default to anthropic
|
|
|
|
|
+ apiProvider = "anthropic"
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -675,16 +641,12 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
|
|
|
awsAccessKey,
|
|
awsAccessKey,
|
|
|
awsSecretKey,
|
|
awsSecretKey,
|
|
|
awsRegion,
|
|
awsRegion,
|
|
|
- koduApiKey,
|
|
|
|
|
- koduEmail,
|
|
|
|
|
},
|
|
},
|
|
|
maxRequestsPerTask,
|
|
maxRequestsPerTask,
|
|
|
lastShownAnnouncementId,
|
|
lastShownAnnouncementId,
|
|
|
customInstructions,
|
|
customInstructions,
|
|
|
alwaysAllowReadOnly: alwaysAllowReadOnly ?? false,
|
|
alwaysAllowReadOnly: alwaysAllowReadOnly ?? false,
|
|
|
taskHistory,
|
|
taskHistory,
|
|
|
- koduCredits,
|
|
|
|
|
- shouldShowKoduPromo: shouldShowKoduPromo ?? true,
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -700,10 +662,6 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
|
|
|
return history
|
|
return history
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async updateKoduCredits(credits: number) {
|
|
|
|
|
- await this.updateGlobalState("koduCredits", credits)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// global
|
|
// global
|
|
|
|
|
|
|
|
private async updateGlobalState(key: GlobalStateKey, value: any) {
|
|
private async updateGlobalState(key: GlobalStateKey, value: any) {
|
|
@@ -755,7 +713,7 @@ export class ClaudeDevProvider implements vscode.WebviewViewProvider {
|
|
|
for (const key of this.context.globalState.keys()) {
|
|
for (const key of this.context.globalState.keys()) {
|
|
|
await this.context.globalState.update(key, undefined)
|
|
await this.context.globalState.update(key, undefined)
|
|
|
}
|
|
}
|
|
|
- const secretKeys: SecretKey[] = ["apiKey", "openRouterApiKey", "awsAccessKey", "awsSecretKey", "koduApiKey"]
|
|
|
|
|
|
|
+ const secretKeys: SecretKey[] = ["apiKey", "openRouterApiKey", "awsAccessKey", "awsSecretKey"]
|
|
|
for (const key of secretKeys) {
|
|
for (const key of secretKeys) {
|
|
|
await this.storeSecret(key, undefined)
|
|
await this.storeSecret(key, undefined)
|
|
|
}
|
|
}
|