Skip to content

Commit 26069de

Browse files
committed
Cherry pick himanshu
1 parent 392f35b commit 26069de

4 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/api/providers/pearai/pearai.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class PearAIHandler extends BaseProvider implements SingleCompletionHandl
2424
constructor(options: ApiHandlerOptions) {
2525
super()
2626
if (!options.pearaiApiKey) {
27+
vscode.commands.executeCommand("pearai-roo-cline.PearAIKeysNotFound", undefined)
2728
vscode.window.showErrorMessage("PearAI API key not found.", "Login to PearAI").then(async (selection) => {
2829
if (selection === "Login to PearAI") {
2930
const extensionUrl = `${vscode.env.uriScheme}://pearai.pearai/auth`

src/extension.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ export async function activate(context: vscode.ExtensionContext) {
165165
}),
166166
)
167167

168+
context.subscriptions.push(
169+
vscode.commands.registerCommand("pearai-roo-cline.PearAIKeysNotFound", async () => {
170+
const provider = await ClineProvider.getInstance()
171+
if (provider) {
172+
provider.postMessageToWebview({ type: "action", action: "PearAIKeysNotFound" })
173+
}
174+
}),
175+
)
176+
168177
/*
169178
We use the text document content provider API to show the left side for diff view by creating a virtual document for the original content. This makes it readonly so users know to edit the right side if they want to keep their changes.
170179

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export interface ExtensionMessage {
7676
| "promptsButtonClicked"
7777
| "didBecomeVisible"
7878
| "focusInput"
79+
| "PearAIKeysNotFound"
7980
invoke?: "newChat" | "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" | "setChatBoxMessage"
8081
state?: ExtensionState
8182
images?: string[]

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
119119
const apiMetrics = useMemo(() => getApiMetrics(modifiedMessages), [modifiedMessages])
120120

121121
const [inputValue, setInputValue] = useState("")
122+
const [lastInputValue, setLastInputValue] = useState("")
122123
const textAreaRef = useRef<HTMLTextAreaElement>(null)
123124
const [textAreaDisabled, setTextAreaDisabled] = useState(false)
124125
const [selectedImages, setSelectedImages] = useState<string[]>([])
126+
const [lastInputImages, setLastInputImages] = useState<string[]>([])
125127

126128
// 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)
127129
const [clineAsk, setClineAsk] = useState<ClineAsk | undefined>(undefined)
@@ -362,6 +364,8 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
362364

363365
const handleChatReset = useCallback(() => {
364366
// Only reset message-specific state, preserving mode.
367+
setLastInputValue(inputValue)
368+
setLastInputImages(selectedImages)
365369
setInputValue("")
366370
setTextAreaDisabled(true)
367371
setSelectedImages([])
@@ -371,7 +375,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
371375
// setPrimaryButtonText(undefined)
372376
// setSecondaryButtonText(undefined)
373377
disableAutoScrollRef.current = false
374-
}, [])
378+
}, [inputValue, selectedImages])
375379

376380
const handleSendMessage = useCallback(
377381
(text: string, images: string[]) => {
@@ -546,6 +550,13 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
546550
case "focusInput":
547551
textAreaRef.current?.focus()
548552
break
553+
case "PearAIKeysNotFound":
554+
setInputValue(lastInputValue)
555+
setTextAreaDisabled(false)
556+
setSelectedImages(lastInputImages)
557+
setEnableButtons(true)
558+
disableAutoScrollRef.current = true
559+
break
549560
}
550561
break
551562
case "selectedImages":
@@ -586,6 +597,12 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
586597
handleSetChatBoxMessage,
587598
handlePrimaryButtonClick,
588599
handleSecondaryButtonClick,
600+
lastInputValue,
601+
lastInputImages,
602+
setInputValue,
603+
setTextAreaDisabled,
604+
setSelectedImages,
605+
setEnableButtons,
589606
],
590607
)
591608

0 commit comments

Comments
 (0)