mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-16 23:01:06 +02:00
desktop: clipboard auto-insert with prompt picker, remove old sessionStorage logic
This commit is contained in:
parent
03ca4f1f32
commit
6df9eea5a6
3 changed files with 24 additions and 36 deletions
|
|
@ -52,7 +52,7 @@ function createQuickAskWindow(x: number, y: number): BrowserWindow {
|
||||||
skipTaskbar: true,
|
skipTaskbar: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
quickAskWindow.loadURL(`http://localhost:${getServerPort()}/dashboard/quick-ask`);
|
quickAskWindow.loadURL(`http://localhost:${getServerPort()}/dashboard`);
|
||||||
|
|
||||||
quickAskWindow.once('ready-to-show', () => {
|
quickAskWindow.once('ready-to-show', () => {
|
||||||
quickAskWindow?.show();
|
quickAskWindow?.show();
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import {
|
||||||
type AppendMessage,
|
type AppendMessage,
|
||||||
AssistantRuntimeProvider,
|
AssistantRuntimeProvider,
|
||||||
type ThreadMessageLike,
|
type ThreadMessageLike,
|
||||||
useAui,
|
|
||||||
useExternalStoreRuntime,
|
useExternalStoreRuntime,
|
||||||
} from "@assistant-ui/react";
|
} from "@assistant-ui/react";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
|
|
@ -159,28 +158,6 @@ const TOOLS_WITH_UI = new Set([
|
||||||
// "write_todos", // Disabled for now
|
// "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() {
|
export default function NewChatPage() {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
@ -1610,7 +1587,6 @@ export default function NewChatPage() {
|
||||||
return (
|
return (
|
||||||
<AssistantRuntimeProvider runtime={runtime}>
|
<AssistantRuntimeProvider runtime={runtime}>
|
||||||
<ThinkingStepsDataUI />
|
<ThinkingStepsDataUI />
|
||||||
<QuickAskAutoSubmit />
|
|
||||||
<div key={searchSpaceId} className="flex h-[calc(100dvh-64px)] overflow-hidden">
|
<div key={searchSpaceId} className="flex h-[calc(100dvh-64px)] overflow-hidden">
|
||||||
<div className="flex-1 flex flex-col min-w-0 overflow-hidden">
|
<div className="flex-1 flex flex-col min-w-0 overflow-hidden">
|
||||||
<Thread />
|
<Thread />
|
||||||
|
|
|
||||||
|
|
@ -310,16 +310,17 @@ const Composer: FC = () => {
|
||||||
const aui = useAui();
|
const aui = useAui();
|
||||||
const hasAutoFocusedRef = useRef(false);
|
const hasAutoFocusedRef = useRef(false);
|
||||||
|
|
||||||
const [quickAskInitialText, setQuickAskInitialText] = useState<string | undefined>();
|
const [clipboardInitialText, setClipboardInitialText] = useState<string | undefined>();
|
||||||
|
const clipboardLoadedRef = useRef(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!window.electronAPI) return;
|
if (!window.electronAPI || clipboardLoadedRef.current) return;
|
||||||
if (sessionStorage.getItem("quickAskAutoSubmit") === "false") {
|
clipboardLoadedRef.current = true;
|
||||||
const text = sessionStorage.getItem("quickAskInitialText");
|
window.electronAPI.getQuickAskText().then((text) => {
|
||||||
if (text) {
|
if (text) {
|
||||||
setQuickAskInitialText(text);
|
setClipboardInitialText(text);
|
||||||
sessionStorage.removeItem("quickAskInitialText");
|
setShowPromptPicker(true);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const isThreadEmpty = useAuiState(({ thread }) => thread.isEmpty);
|
const isThreadEmpty = useAuiState(({ thread }) => thread.isEmpty);
|
||||||
|
|
@ -446,10 +447,21 @@ const Composer: FC = () => {
|
||||||
(action: { name: string; prompt: string; mode: "transform" | "explore" }) => {
|
(action: { name: string; prompt: string; mode: "transform" | "explore" }) => {
|
||||||
setShowPromptPicker(false);
|
setShowPromptPicker(false);
|
||||||
setActionQuery("");
|
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(() => {
|
const handleActionRemove = useCallback(() => {
|
||||||
|
|
@ -592,7 +604,7 @@ const Composer: FC = () => {
|
||||||
onDocumentRemove={handleDocumentRemove}
|
onDocumentRemove={handleDocumentRemove}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
initialText={quickAskInitialText}
|
initialText={clipboardInitialText}
|
||||||
className="min-h-[24px]"
|
className="min-h-[24px]"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue