Skip to content

Commit bfc299f

Browse files
fix-chat-freeze-pearaiprovider (#62)
1 parent b732296 commit bfc299f

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

src/api/providers/pearai/pearai.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class PearAiHandler extends BaseProvider implements SingleCompletionHandl
4343
throw new Error("PearAI API key not found. Please login to PearAI.")
4444
} else {
4545
vscode.commands.executeCommand("pearai.checkPearAITokens", undefined)
46+
vscode.commands.executeCommand("pearai-roo-cline.pearaiTokensValidated")
4647
}
4748
this.options = options
4849

src/extension.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ export function activate(context: vscode.ExtensionContext) {
157157
}),
158158
)
159159

160+
context.subscriptions.push(
161+
vscode.commands.registerCommand("pearai-roo-cline.pearaiTokensValidated", async () => {
162+
const provider = await ClineProvider.getInstance()
163+
if (provider) {
164+
provider.postMessageToWebview({ type: "action", action: "pearaiTokensValidated" })
165+
}
166+
}),
167+
)
168+
160169
// context.subscriptions.push(
161170
// vscode.commands.registerCommand("roo-cline.mcpButtonClicked", () => {
162171
// sidebarProvider.postMessageToWebview({ type: "action", action: "mcpButtonClicked" })

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export interface ExtensionMessage {
6666
| "historyButtonClicked"
6767
| "promptsButtonClicked"
6868
| "didBecomeVisible"
69+
| "pearaiTokensValidated"
6970
invoke?: "newChat" | "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" | "setChatBoxMessage"
7071
state?: ExtensionState
7172
images?: string[]

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,12 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
325325
return false
326326
}, [modifiedMessages, clineAsk, enableButtons, primaryButtonText])
327327

328+
const pearAiModels = usePearAiModels(apiConfiguration)
329+
330+
const { selectedModelInfo, selectedProvider } = useMemo(() => {
331+
return normalizeApiConfiguration(apiConfiguration, pearAiModels)
332+
}, [apiConfiguration, pearAiModels])
333+
328334
const handleChatReset = useCallback(() => {
329335
// Only reset message-specific state, preserving mode.
330336
setInputValue("")
@@ -361,10 +367,15 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
361367
// There is no other case that a textfield should be enabled.
362368
}
363369
}
370+
371+
if (selectedProvider === "pearai") {
372+
return
373+
}
374+
364375
handleChatReset()
365376
}
366377
},
367-
[messages.length, clineAsk, handleChatReset],
378+
[messages.length, clineAsk, handleChatReset, selectedProvider],
368379
)
369380

370381
const handleSetChatBoxMessage = useCallback(
@@ -483,12 +494,6 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
483494
startNewTask()
484495
}, [startNewTask])
485496

486-
const pearAiModels = usePearAiModels(apiConfiguration)
487-
488-
const { selectedModelInfo } = useMemo(() => {
489-
return normalizeApiConfiguration(apiConfiguration, pearAiModels)
490-
}, [apiConfiguration, pearAiModels])
491-
492497
const selectImages = useCallback(() => {
493498
vscode.postMessage({ type: "selectImages" })
494499
}, [])
@@ -507,6 +512,9 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
507512
textAreaRef.current?.focus()
508513
}
509514
break
515+
case "pearaiTokensValidated":
516+
handleChatReset()
517+
break
510518
}
511519
break
512520
case "selectedImages":

0 commit comments

Comments
 (0)