From 66a45bbc8b23feebf712e052fd887533c1ccac98 Mon Sep 17 00:00:00 2001 From: Himanshu Date: Thu, 10 Apr 2025 13:23:39 +0530 Subject: [PATCH] fix-chat-freeze-pearaiprovider --- src/api/providers/pearai/pearai.ts | 1 + src/extension.ts | 9 +++++++++ src/shared/ExtensionMessage.ts | 1 + webview-ui/src/components/chat/ChatView.tsx | 22 ++++++++++++++------- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/api/providers/pearai/pearai.ts b/src/api/providers/pearai/pearai.ts index 58e1e5e9126..13183d92514 100644 --- a/src/api/providers/pearai/pearai.ts +++ b/src/api/providers/pearai/pearai.ts @@ -43,6 +43,7 @@ export class PearAiHandler extends BaseProvider implements SingleCompletionHandl throw new Error("PearAI API key not found. Please login to PearAI.") } else { vscode.commands.executeCommand("pearai.checkPearAITokens", undefined) + vscode.commands.executeCommand("pearai-roo-cline.pearaiTokensValidated") } this.options = options diff --git a/src/extension.ts b/src/extension.ts index 1d453ac13f2..d26101a9289 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -157,6 +157,15 @@ export function activate(context: vscode.ExtensionContext) { }), ) + context.subscriptions.push( + vscode.commands.registerCommand("pearai-roo-cline.pearaiTokensValidated", async () => { + const provider = await ClineProvider.getInstance() + if (provider) { + provider.postMessageToWebview({ type: "action", action: "pearaiTokensValidated" }) + } + }), + ) + // context.subscriptions.push( // vscode.commands.registerCommand("roo-cline.mcpButtonClicked", () => { // sidebarProvider.postMessageToWebview({ type: "action", action: "mcpButtonClicked" }) diff --git a/src/shared/ExtensionMessage.ts b/src/shared/ExtensionMessage.ts index b7219de2f85..72c72ca1706 100644 --- a/src/shared/ExtensionMessage.ts +++ b/src/shared/ExtensionMessage.ts @@ -66,6 +66,7 @@ export interface ExtensionMessage { | "historyButtonClicked" | "promptsButtonClicked" | "didBecomeVisible" + | "pearaiTokensValidated" invoke?: "newChat" | "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" | "setChatBoxMessage" state?: ExtensionState images?: string[] diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index f20ac5c4cff..9380a5807f8 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -325,6 +325,12 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie return false }, [modifiedMessages, clineAsk, enableButtons, primaryButtonText]) + const pearAiModels = usePearAiModels(apiConfiguration) + + const { selectedModelInfo, selectedProvider } = useMemo(() => { + return normalizeApiConfiguration(apiConfiguration, pearAiModels) + }, [apiConfiguration, pearAiModels]) + const handleChatReset = useCallback(() => { // Only reset message-specific state, preserving mode. setInputValue("") @@ -361,10 +367,15 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie // There is no other case that a textfield should be enabled. } } + + if (selectedProvider === "pearai") { + return + } + handleChatReset() } }, - [messages.length, clineAsk, handleChatReset], + [messages.length, clineAsk, handleChatReset, selectedProvider], ) const handleSetChatBoxMessage = useCallback( @@ -483,12 +494,6 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie startNewTask() }, [startNewTask]) - const pearAiModels = usePearAiModels(apiConfiguration) - - const { selectedModelInfo } = useMemo(() => { - return normalizeApiConfiguration(apiConfiguration, pearAiModels) - }, [apiConfiguration, pearAiModels]) - const selectImages = useCallback(() => { vscode.postMessage({ type: "selectImages" }) }, []) @@ -507,6 +512,9 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie textAreaRef.current?.focus() } break + case "pearaiTokensValidated": + handleChatReset() + break } break case "selectedImages":