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 e91ad43e9..5024c446c 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 @@ -162,19 +162,26 @@ const TOOLS_WITH_UI = new Set([ function QuickAskAutoSubmit() { const searchParams = useSearchParams(); const aui = useAui(); - const submittedRef = useRef(false); + const handledRef = useRef(false); useEffect(() => { - if (!window.electronAPI || submittedRef.current) return; + if (!window.electronAPI || handledRef.current) return; const prompt = searchParams.get("quickAskPrompt"); - if (!prompt) return; + const initialText = searchParams.get("quickAskInitialText"); - submittedRef.current = true; - setTimeout(() => { - aui.composer().setText(prompt); - aui.composer().send(); - }, 500); + if (prompt) { + handledRef.current = true; + setTimeout(() => { + aui.composer().setText(prompt); + aui.composer().send(); + }, 500); + } else if (initialText) { + handledRef.current = true; + setTimeout(() => { + aui.composer().setText(initialText); + }, 500); + } }, [searchParams, aui]); return null; diff --git a/surfsense_web/app/dashboard/quick-ask/actions.ts b/surfsense_web/app/dashboard/quick-ask/actions.ts index 8d4ff0bb5..984aef2b6 100644 --- a/surfsense_web/app/dashboard/quick-ask/actions.ts +++ b/surfsense_web/app/dashboard/quick-ask/actions.ts @@ -33,6 +33,14 @@ export const DEFAULT_ACTIONS: QuickAskAction[] = [ icon: "pen-line", group: "transform", }, + { + id: "summarize", + name: "Summarize", + prompt: "Summarize the following text concisely. Return only the summary, nothing else.\n\n{selection}", + mode: "transform", + icon: "list", + group: "transform", + }, { id: "explain", name: "Explain", @@ -42,27 +50,19 @@ export const DEFAULT_ACTIONS: QuickAskAction[] = [ group: "explore", }, { - id: "summarize", - name: "Summarize", - prompt: "Summarize the following text:\n\n{selection}", - mode: "explore", - icon: "list", - group: "explore", - }, - { - id: "search-knowledge", - name: "Search my knowledge", + id: "ask-knowledge-base", + name: "Ask my knowledge base", prompt: "Search my knowledge base for information related to:\n\n{selection}", mode: "explore", icon: "search", - group: "knowledge", + group: "explore", }, { - id: "search-web", - name: "Search the web", + id: "look-up-web", + name: "Look up on the web", prompt: "Search the web for information about:\n\n{selection}", mode: "explore", icon: "globe", - group: "knowledge", + group: "explore", }, ]; diff --git a/surfsense_web/app/dashboard/quick-ask/page.tsx b/surfsense_web/app/dashboard/quick-ask/page.tsx index b6194d0af..95395c14d 100644 --- a/surfsense_web/app/dashboard/quick-ask/page.tsx +++ b/surfsense_web/app/dashboard/quick-ask/page.tsx @@ -11,7 +11,7 @@ import { PenLine, Search, } from "lucide-react"; -import { useEffect, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { DEFAULT_ACTIONS } from "./actions"; const ICONS: Record = { @@ -27,6 +27,7 @@ const ICONS: Record = { export default function QuickAskPage() { const [clipboardText, setClipboardText] = useState(""); + const [searchQuery, setSearchQuery] = useState(""); useEffect(() => { window.electronAPI?.getQuickAskText().then((text) => { @@ -40,80 +41,109 @@ export default function QuickAskPage() { window.location.href = `/dashboard?quickAskPrompt=${encoded}`; }; + const navigateWithInitialText = () => { + if (!clipboardText) return; + sessionStorage.setItem("quickAskMode", "explore"); + const encoded = encodeURIComponent(clipboardText); + window.location.href = `/dashboard?quickAskInitialText=${encoded}`; + }; + const handleAction = (actionId: string) => { const action = DEFAULT_ACTIONS.find((a) => a.id === actionId); - if (!action) return; + if (!action || !clipboardText) return; const prompt = action.prompt.replace("{selection}", clipboardText); navigateToChat(prompt, action.mode); }; const transformActions = DEFAULT_ACTIONS.filter((a) => a.group === "transform"); const exploreActions = DEFAULT_ACTIONS.filter((a) => a.group === "explore"); - const knowledgeActions = DEFAULT_ACTIONS.filter((a) => a.group === "knowledge"); + + const filteredTransform = useMemo( + () => transformActions.filter((a) => a.name.toLowerCase().includes(searchQuery.toLowerCase())), + [searchQuery] + ); + const filteredExplore = useMemo( + () => exploreActions.filter((a) => a.name.toLowerCase().includes(searchQuery.toLowerCase())), + [searchQuery] + ); + + if (!clipboardText) { + return ( +
+
Loading...
+
+ ); + } return (
-
- {!clipboardText && ( -
Loading...
+
+
+ + setSearchQuery(e.target.value)} + className="flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground" + /> +
+
+ +
+ {filteredTransform.length > 0 && ( + <> +
Transform
+
+ {filteredTransform.map((action) => ( + + ))} +
+ )} - {clipboardText && ( -
-
Transform
- {transformActions.map((action) => ( - - ))} -
- -
Explore
- {exploreActions.map((action) => ( - - ))} - -
- -
Knowledge
- {knowledgeActions.map((action) => ( - - ))} - -
- - -
+ {filteredExplore.length > 0 && ( + <> +
Explore
+
+ {filteredExplore.map((action) => ( + + ))} +
+ )} + +
My Actions
+
+ Custom actions coming soon +
+
+ +
+
);