From ee2588d153f8671ab6b1c16ba9ed3d84c9aec4be Mon Sep 17 00:00:00 2001 From: ColemanRoo Date: Tue, 14 Jan 2025 22:10:31 -0600 Subject: [PATCH] PR review changes --- src/core/Cline.ts | 12 +++++-- src/core/webview/ClineProvider.ts | 36 +++++++------------ .../src/components/settings/SettingsView.tsx | 13 ------- .../src/context/ExtensionStateContext.tsx | 19 ---------- 4 files changed, 22 insertions(+), 58 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 716c9e2777..24ca565645 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -86,6 +86,7 @@ export class Cline { didFinishAborting = false abandoned = false private diffViewProvider: DiffViewProvider + private slackConfig?: { enabled: boolean; webhookUrl: string } // streaming private currentStreamingContentIndex = 0 @@ -152,6 +153,7 @@ export class Cline { console.error('Failed to send initialization notification:', error); }); } + this.slackConfig = slackConfig this.diffViewProvider = new DiffViewProvider(cwd) this.customInstructions = customInstructions this.diffEnabled = enableDiff ?? false @@ -2070,13 +2072,14 @@ export class Cline { commandResult = execCommandResult } else { await this.say("completion_result", result, undefined, false) + if(this.slackConfig?.enabled && this.slackConfig?.webhookUrl) { await (async () => { try { if (!result) { console.warn("No result provided for completion notification", { taskId: this.taskId, timestamp: new Date().toISOString() - }); + }) } const completionMessage = result ? `✅ Task completed successfully!\n\nResult:\n${result}` @@ -2088,10 +2091,11 @@ export class Cline { errorMessage: error instanceof Error ? error.message : 'Unknown error', errorStack: error instanceof Error ? error.stack : 'No stack trace', taskId: this.taskId - }); + }) vscode.window.showErrorMessage(`Failed to send Slack completion notification: ${error instanceof Error ? error.message : 'Unknown error'}`); } - })(); + })() + } } // we already sent completion_result says, an empty string asks relinquishes control over button and field const { response, text, images } = await this.ask("completion_result", "", false); @@ -2261,6 +2265,7 @@ export class Cline { // lastMessage.ts = Date.now() DO NOT update ts since it is used as a key for virtuoso list lastMessage.partial = false // instead of streaming partialMessage events, we do a save and post like normal to persist to disk + console.log("updating artial message", lastMessage) // await this.saveClineMessages() } @@ -2327,6 +2332,7 @@ export class Cline { } if (this.abort) { + console.log("aborting stream...") if (!this.abandoned) { // only need to gracefully abort if this instance isn't abandoned (sometimes openrouter stream hangs, in which case this would affect future instances of cline) await abortStream("user_cancelled") diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index f5293632f2..81054aa17b 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -1071,19 +1071,11 @@ export class ClineProvider implements vscode.WebviewViewProvider { } async updateCustomInstructions(instructions?: string): Promise { - try { - // User may be clearing the field - const normalizedInstructions = instructions || undefined; - await this.updateGlobalState("customInstructions", normalizedInstructions); - - if (this.cline) { - this.cline.customInstructions = normalizedInstructions; - } - - await this.postStateToWebview(); - } catch (error) { - throw new Error(`Failed to update custom instructions: ${error instanceof Error ? error.message : 'Unknown error'}`); + await this.updateGlobalState("customInstructions", instructions || undefined) + if (this.cline) { + this.cline.customInstructions = instructions || undefined } + await this.postStateToWebview() } // MCP @@ -1430,11 +1422,11 @@ export class ClineProvider implements vscode.WebviewViewProvider { if (fileExists) { const apiConversationHistory = JSON.parse(await fs.readFile(apiConversationHistoryFilePath, "utf8")) return { - historyItem, - taskDirPath, - apiConversationHistoryFilePath, - uiMessagesFilePath, - apiConversationHistory, + historyItem, + taskDirPath, + apiConversationHistoryFilePath, + uiMessagesFilePath, + apiConversationHistory, } } } @@ -1459,9 +1451,9 @@ export class ClineProvider implements vscode.WebviewViewProvider { } async deleteTaskWithId(id: string) { - if (id === this.cline?.taskId) { + if (id === this.cline?.taskId) { await this.clearTask() - } + } const { taskDirPath, apiConversationHistoryFilePath, uiMessagesFilePath } = await this.getTaskWithId(id) @@ -1525,6 +1517,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { listApiConfigMeta, slackWebhookUrl, slackNotificationsEnabled, + slackConfig, mode, } = await this.getState() @@ -1564,10 +1557,7 @@ export class ClineProvider implements vscode.WebviewViewProvider { listApiConfigMeta: listApiConfigMeta ?? [], slackWebhookUrl: slackWebhookUrl ?? "", slackNotificationsEnabled: slackNotificationsEnabled ?? false, - slackConfig: { - enabled: slackNotificationsEnabled ?? false, - webhookUrl: slackWebhookUrl ?? "" - }, + slackConfig: slackConfig ?? {}, mode: mode ?? codeMode, } } diff --git a/webview-ui/src/components/settings/SettingsView.tsx b/webview-ui/src/components/settings/SettingsView.tsx index a9c820aad7..3997a4e225 100644 --- a/webview-ui/src/components/settings/SettingsView.tsx +++ b/webview-ui/src/components/settings/SettingsView.tsx @@ -71,16 +71,12 @@ const SettingsView = ({ onDone }: SettingsViewProps) => { const [commandInput, setCommandInput] = useState("") const handleSubmit = () => { - console.log('handleSubmit called'); - console.log('Validating configuration...'); const apiValidationResult = validateApiConfiguration(apiConfiguration) const modelIdValidationResult = validateModelId(apiConfiguration, glamaModels, openRouterModels) - console.log('Validation results:', { apiValidationResult, modelIdValidationResult }); setApiErrorMessage(apiValidationResult) setModelIdErrorMessage(modelIdValidationResult) if (!apiValidationResult && !modelIdValidationResult) { - console.log('Validation passed, sending messages...'); vscode.postMessage({ type: "apiConfiguration", apiConfiguration @@ -105,15 +101,6 @@ const SettingsView = ({ onDone }: SettingsViewProps) => { vscode.postMessage({ type: "alwaysApproveResubmit", bool: alwaysApproveResubmit }) vscode.postMessage({ type: "requestDelaySeconds", value: requestDelaySeconds }) vscode.postMessage({ type: "currentApiConfigName", text: currentApiConfigName }) - // Send settings to extension - console.log('Sending settings to extension...'); - console.log('Sound enabled:', soundEnabled); - console.log('Sound volume:', soundVolume); - console.log('Slack notifications enabled:', slackNotificationsEnabled); - console.log('Slack webhook URL:', slackWebhookUrl); - - vscode.postMessage({ type: "soundEnabled", bool: soundEnabled }); - vscode.postMessage({ type: "soundVolume", value: soundVolume }); vscode.postMessage({ type: "slackNotificationsEnabled", bool: slackNotificationsEnabled }); vscode.postMessage({ type: "slackWebhookUrl", text: slackWebhookUrl }); vscode.postMessage({ diff --git a/webview-ui/src/context/ExtensionStateContext.tsx b/webview-ui/src/context/ExtensionStateContext.tsx index 9119e59db1..8b3d858ec3 100644 --- a/webview-ui/src/context/ExtensionStateContext.tsx +++ b/webview-ui/src/context/ExtensionStateContext.tsx @@ -183,25 +183,6 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode setListApiConfigMeta(message.listApiConfig ?? []) break } - case "soundEnabled": { - if (message.bool !== undefined) { - setState((prevState: ExtensionState) => ({ ...prevState, soundEnabled: message.bool })) - } - break - } - case "soundVolume": { - if (message.value !== undefined) { - setState((prevState: ExtensionState) => ({ ...prevState, soundVolume: message.value })) - } - break - } - case "slackWebhookUrl": { - if (message.text !== undefined) { - setState((prevState: ExtensionState) => ({ ...prevState, slackWebhookUrl: message.text })) - vscode.postMessage({ type: "slackWebhookUrl", text: message.text }) - } - break - } } }, [setListApiConfigMeta])