YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat: arrow shortcut to recall chat messages (#4400)
Mohane3076488a3a6
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-composer-shell.ts b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-composer-shell.tsindex 158dc3a28..018574887 100644--- a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-composer-shell.ts+++ b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-chat-composer-shell.ts@@ -45,6 +45,7 @@ interface UseChatComposerShellActionsOptions {pastedImages: string[];pendingDocsRef: React.MutableRefObject<PendingDoc[]>;attachedDocsRef: React.MutableRefObject<ExtractedDoc[]>;+ messageHistory: string[];queuedPrompts: PiQueuedPrompt[];steerShortcutInFlightRef: React.MutableRefObject<boolean>;isKnownConnectionId: (id: string) => boolean;@@ -129,6 +130,7 @@ export function useChatComposerShellActions({pastedImages,pendingDocsRef,attachedDocsRef,+ messageHistory,queuedPrompts,steerShortcutInFlightRef,isKnownConnectionId,@@ -138,10 +140,14 @@ export function useChatComposerShellActions({steerMessage,steerQueuedPrompt,}: UseChatComposerShellActionsOptions) {+ // Index from the newest message. `null` means the user is editing normally.+ const historyIndexRef = useRef<number | null>(null);+const sendComposerMessage = useCallback(() => {if (pendingDocsRef.current.length > 0) return;if (!input.trim() && pastedImages.length === 0 && attachedDocsRef.current.length === 0) return;+ historyIndexRef.current = null;const chip = connectionChip;setConnectionChip(null);void sendMessage(@@ -164,6 +170,7 @@ export function useChatComposerShellActions({}, [sendComposerMessage]);const handlePaste = useCallback((event: React.ClipboardEvent) => {+ historyIndexRef.current = null;if (handlePastedFiles(event.clipboardData)) {event.preventDefault();return;@@ -255,6 +262,39 @@ export function useChatComposerShellActions({return;}+ const isPlainArrow = !event.shiftKey && !event.altKey && !event.ctrlKey && !event.metaKey;+ if (+ !mentions.isOpen &&+ isPlainArrow &&+ event.key === "ArrowUp" &&+ (input === "" || historyIndexRef.current !== null)+ ) {+ const nextIndex = Math.min((historyIndexRef.current ?? -1) + 1, messageHistory.length - 1);+ if (nextIndex >= 0) {+ event.preventDefault();+ historyIndexRef.current = nextIndex;+ setInput(messageHistory[messageHistory.length - 1 - nextIndex]);+ }+ return;+ }++ if (+ !mentions.isOpen &&+ isPlainArrow &&+ event.key === "ArrowDown" &&+ historyIndexRef.current !== null+ ) {+ event.preventDefault();+ const nextIndex = historyIndexRef.current - 1;+ historyIndexRef.current = nextIndex >= 0 ? nextIndex : null;+ setInput(nextIndex >= 0 ? messageHistory[messageHistory.length - 1 - nextIndex] : "");+ return;+ }++ if (event.key !== "ArrowUp" && event.key !== "ArrowDown") {+ historyIndexRef.current = null;+ }+if (event.key === "Enter" && !event.shiftKey && !mentions.isOpen) {event.preventDefault();sendComposerMessage();@@ -283,6 +323,8 @@ export function useChatComposerShellActions({handleSteerShortcut,isComposing,isMac,+ input,+ messageHistory,mentionActions,mentions,sendComposerMessage,diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsxindex de6fd5515..89585e7c9 100644--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx@@ -27,6 +27,8 @@ import { useSqlAutocomplete, useTagAutocomplete } from "@/lib/hooks/use-sql-autoimport {buildAppMentionSuggestions,buildTagMentionSuggestions,+ isConversationHistorySyncPrompt,+ isInjectedTitleSourcePrompt,} from "@/lib/chat-utils";import { useAutoSuggestions } from "@/lib/hooks/use-auto-suggestions";import {@@ -947,6 +949,20 @@ export function StandaloneChat({turnIntentTextValuesMatch,});+ const messageHistory = React.useMemo(+ () =>+ messages+ .filter(+ (message) =>+ message.role === "user" &&+ message.content.trim() &&+ !isInjectedTitleSourcePrompt(message.content) &&+ !isConversationHistorySyncPrompt(message.content),+ )+ .map((message) => message.content),+ [messages],+ );+const {handleKeyDown,handlePaste,@@ -973,6 +989,7 @@ export function StandaloneChat({pastedImages,pendingDocsRef,attachedDocsRef,+ messageHistory,queuedPrompts,steerShortcutInFlightRef,isKnownConnectionId: (id) => INTEGRATION_ICON_KEYS.has(id),