diff --git a/surfsense_desktop/src/modules/quick-ask.ts b/surfsense_desktop/src/modules/quick-ask.ts index 4a8b4c315..1b1687480 100644 --- a/surfsense_desktop/src/modules/quick-ask.ts +++ b/surfsense_desktop/src/modules/quick-ask.ts @@ -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(); diff --git a/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx b/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx index ac203157a..e8f0bc9f6 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx @@ -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 ( -
diff --git a/surfsense_web/components/assistant-ui/thread.tsx b/surfsense_web/components/assistant-ui/thread.tsx index 6ff05a252..638f0b22d 100644 --- a/surfsense_web/components/assistant-ui/thread.tsx +++ b/surfsense_web/components/assistant-ui/thread.tsx @@ -310,16 +310,17 @@ const Composer: FC = () => { const aui = useAui(); const hasAutoFocusedRef = useRef(false); - const [quickAskInitialText, setQuickAskInitialText] = useState(); + const [clipboardInitialText, setClipboardInitialText] = useState(); + 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]" />