desktop: clipboard auto-insert with prompt picker, remove old sessionStorage logic

This commit is contained in:
CREDO23 2026-03-29 00:45:11 +02:00
parent 03ca4f1f32
commit 6df9eea5a6
3 changed files with 24 additions and 36 deletions

View file

@ -52,7 +52,7 @@ function createQuickAskWindow(x: number, y: number): BrowserWindow {
skipTaskbar: true,
});
quickAskWindow.loadURL(`http://localhost:${getServerPort()}/dashboard/quick-ask`);
quickAskWindow.loadURL(`http://localhost:${getServerPort()}/dashboard`);
quickAskWindow.once('ready-to-show', () => {
quickAskWindow?.show();

View file

@ -4,7 +4,6 @@ import {
type AppendMessage,
AssistantRuntimeProvider,
type ThreadMessageLike,
useAui,
useExternalStoreRuntime,
} from "@assistant-ui/react";
import { useQueryClient } from "@tanstack/react-query";
@ -159,28 +158,6 @@ const TOOLS_WITH_UI = new Set([
// "write_todos", // Disabled for now
]);
function QuickAskAutoSubmit() {
const searchParams = useSearchParams();
const aui = useAui();
const handledRef = useRef(false);
useEffect(() => {
if (!window.electronAPI || handledRef.current) return;
if (sessionStorage.getItem("quickAskAutoSubmit") === "false") return;
const prompt = searchParams.get("quickAskPrompt");
if (!prompt) return;
handledRef.current = true;
setTimeout(() => {
aui.composer().setText(prompt);
aui.composer().send();
}, 500);
}, [searchParams, aui]);
return null;
}
export default function NewChatPage() {
const params = useParams();
const queryClient = useQueryClient();
@ -1610,7 +1587,6 @@ export default function NewChatPage() {
return (
<AssistantRuntimeProvider runtime={runtime}>
<ThinkingStepsDataUI />
<QuickAskAutoSubmit />
<div key={searchSpaceId} className="flex h-[calc(100dvh-64px)] overflow-hidden">
<div className="flex-1 flex flex-col min-w-0 overflow-hidden">
<Thread />

View file

@ -310,16 +310,17 @@ const Composer: FC = () => {
const aui = useAui();
const hasAutoFocusedRef = useRef(false);
const [quickAskInitialText, setQuickAskInitialText] = useState<string | undefined>();
const [clipboardInitialText, setClipboardInitialText] = useState<string | undefined>();
const clipboardLoadedRef = useRef(false);
useEffect(() => {
if (!window.electronAPI) return;
if (sessionStorage.getItem("quickAskAutoSubmit") === "false") {
const text = sessionStorage.getItem("quickAskInitialText");
if (!window.electronAPI || clipboardLoadedRef.current) return;
clipboardLoadedRef.current = true;
window.electronAPI.getQuickAskText().then((text) => {
if (text) {
setQuickAskInitialText(text);
sessionStorage.removeItem("quickAskInitialText");
setClipboardInitialText(text);
setShowPromptPicker(true);
}
}
});
}, []);
const isThreadEmpty = useAuiState(({ thread }) => thread.isEmpty);
@ -446,10 +447,21 @@ const Composer: FC = () => {
(action: { name: string; prompt: string; mode: "transform" | "explore" }) => {
setShowPromptPicker(false);
setActionQuery("");
pendingActionRef.current = action;
editorRef.current?.insertActionChip(action.name);
if (clipboardInitialText) {
const finalPrompt = action.prompt.replace("{selection}", clipboardInitialText);
window.electronAPI?.setQuickAskMode(action.mode);
aui.composer().setText(finalPrompt);
aui.composer().send();
editorRef.current?.clear();
setMentionedDocuments([]);
setSidebarDocs([]);
} else {
pendingActionRef.current = action;
editorRef.current?.insertActionChip(action.name);
}
},
[]
[clipboardInitialText, aui, setMentionedDocuments, setSidebarDocs]
);
const handleActionRemove = useCallback(() => {
@ -592,7 +604,7 @@ const Composer: FC = () => {
onDocumentRemove={handleDocumentRemove}
onSubmit={handleSubmit}
onKeyDown={handleKeyDown}
initialText={quickAskInitialText}
initialText={clipboardInitialText}
className="min-h-[24px]"
/>
</div>