diff --git a/src/api/providers/pearai/pearai.ts b/src/api/providers/pearai/pearai.ts index 2565eb42550..6aba0736414 100644 --- a/src/api/providers/pearai/pearai.ts +++ b/src/api/providers/pearai/pearai.ts @@ -29,6 +29,7 @@ export class PearAiHandler extends BaseProvider implements SingleCompletionHandl constructor(options: ApiHandlerOptions) { super() if (!options.pearaiApiKey) { + vscode.commands.executeCommand("pearai-roo-cline.PearAIKeysNotFound", undefined) vscode.window.showErrorMessage("PearAI API key not found.", "Login to PearAI").then(async (selection) => { if (selection === "Login to PearAI") { const extensionUrl = `${vscode.env.uriScheme}://pearai.pearai/auth` diff --git a/src/extension.ts b/src/extension.ts index 1d453ac13f2..e5c19043f2d 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.PearAIKeysNotFound", async () => { + const provider = await ClineProvider.getInstance() + if (provider) { + provider.postMessageToWebview({ type: "action", action: "PearAIKeysNotFound" }) + } + }), + ) + // 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..1b106ad3429 100644 --- a/src/shared/ExtensionMessage.ts +++ b/src/shared/ExtensionMessage.ts @@ -66,6 +66,7 @@ export interface ExtensionMessage { | "historyButtonClicked" | "promptsButtonClicked" | "didBecomeVisible" + | "PearAIKeysNotFound" 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..a3c02c1973b 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -88,9 +88,11 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie const apiMetrics = useMemo(() => getApiMetrics(modifiedMessages), [modifiedMessages]) const [inputValue, setInputValue] = useState("") + const [lastInputValue, setLastInputValue] = useState("") const textAreaRef = useRef(null) const [textAreaDisabled, setTextAreaDisabled] = useState(false) const [selectedImages, setSelectedImages] = useState([]) + const [lastInputImages, setLastInputImages] = useState([]) // we need to hold on to the ask because useEffect > lastMessage will always let us know when an ask comes in and handle it, but by the time handleMessage is called, the last message might not be the ask anymore (it could be a say that followed) const [clineAsk, setClineAsk] = useState(undefined) @@ -327,6 +329,8 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie const handleChatReset = useCallback(() => { // Only reset message-specific state, preserving mode. + setLastInputValue(inputValue) + setLastInputImages(selectedImages) setInputValue("") setTextAreaDisabled(true) setSelectedImages([]) @@ -336,7 +340,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie // setPrimaryButtonText(undefined) // setSecondaryButtonText(undefined) disableAutoScrollRef.current = false - }, []) + }, [inputValue, selectedImages]) const handleSendMessage = useCallback( (text: string, images: string[]) => { @@ -507,6 +511,13 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie textAreaRef.current?.focus() } break + case "PearAIKeysNotFound": + setInputValue(lastInputValue) + setTextAreaDisabled(false) + setSelectedImages(lastInputImages) + setEnableButtons(true) + disableAutoScrollRef.current = true + break } break case "selectedImages": @@ -547,6 +558,12 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie handleSetChatBoxMessage, handlePrimaryButtonClick, handleSecondaryButtonClick, + lastInputValue, + lastInputImages, + setInputValue, + setTextAreaDisabled, + setSelectedImages, + setEnableButtons, ], )