Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
feat(notes): add embedded chat panel with floating and sidebar modes
Gabriel Stein2035b414f107
diff --git a/src/components/chat/useChatStreaming.ts b/src/components/chat/useChatStreaming.tsindex de179c8fb..ee99bff30 100644--- a/src/components/chat/useChatStreaming.ts+++ b/src/components/chat/useChatStreaming.ts@@ -41,6 +41,8 @@ async function buildRAGContext(userText: string): Promise<string> {interface UseChatStreamingOptions {messages: Message[];setMessages: React.Dispatch<React.SetStateAction<Message[]>>;+ /** Optional note context to prepend to the system prompt (used by embedded note chat). */+ noteContext?: string;onStreamComplete?: (assistantId: string, content: string, toolCalls?: ToolCallInfo[]) => void;}@@ -55,6 +57,7 @@ export interface ChatStreaming {export function useChatStreaming({messages,setMessages,+ noteContext: externalNoteContext,onStreamComplete,}: UseChatStreamingOptions): ChatStreaming {const { t } = useTranslation();@@ -63,6 +66,8 @@ export function useChatStreaming({const [activeToolName, setActiveToolName] = useState("");const mountedRef = useRef(true);const messagesRef = useRef<Message[]>([]);+ const noteContextRef = useRef(externalNoteContext);+ noteContextRef.current = externalNoteContext;const toolRegistryRef = useRef<{ key: string; registry: ToolRegistry } | null>(null);useEffect(() => {@@ -112,10 +117,11 @@ export function useChatStreaming({}}- const noteContext = await buildRAGContext(userText);+ const ragContext = await buildRAGContext(userText);+ const combinedContext = [noteContextRef.current, ragContext].filter(Boolean).join("\n\n");const systemPrompt = getAgentSystemPrompt(registry?.getAll().map((t) => t.name),- noteContext+ combinedContext || undefined);const llmMessages = [diff --git a/src/components/notes/EmbeddedChat.tsx b/src/components/notes/EmbeddedChat.tsxnew file mode 100644index 000000000..d6ddd1361--- /dev/null+++ b/src/components/notes/EmbeddedChat.tsx@@ -0,0 +1,160 @@+import { useEffect, useCallback, forwardRef, useImperativeHandle } from "react";+import { useTranslation } from "react-i18next";+import { X, PanelRight, PanelRightClose } from "lucide-react";+import { cn } from "../lib/utils";+import { ChatMessages } from "../chat/ChatMessages";+import { ChatInput } from "../chat/ChatInput";+import { useEmbeddedChat } from "../../hooks/useEmbeddedChat";++type EmbeddedChatMode = "hidden" | "floating" | "sidebar";++interface EmbeddedChatProps {+ mode: EmbeddedChatMode;+ onModeChange: (mode: EmbeddedChatMode) => void;+ noteId: number | null;+ noteTitle: string;+ noteContent: string;+ noteTranscript?: string;+}++export interface EmbeddedChatHandle {+ sendMessage: (text: string) => Promise<void>;+}++function EmptyState() {+ const { t } = useTranslation();+ return (+ <div className="flex items-center justify-center h-full select-none">+ <p className="text-xs text-foreground/30 dark:text-foreground/20 text-center max-w-44">+ {t("embeddedChat.emptyState")}+ </p>+ </div>+ );+}++const EmbeddedChat = forwardRef<EmbeddedChatHandle, EmbeddedChatProps>(+ function EmbeddedChat(+ { mode, onModeChange, noteId, noteTitle, noteContent, noteTranscript },+ ref+ ) {+ const { t } = useTranslation();+ const { messages, agentState, sendMessage, cancelStream } = useEmbeddedChat({+ noteId,+ noteTitle,+ noteContent,+ noteTranscript,+ });++ useImperativeHandle(ref, () => ({ sendMessage }), [sendMessage]);++ // Escape key closes floating panel+ const handleKeyDown = useCallback(+ (e: KeyboardEvent) => {+ if (e.key === "Escape" && mode === "floating") {+ onModeChange("hidden");+ }+ },+ [mode, onModeChange]+ );++ useEffect(() => {+ document.addEventListener("keydown", handleKeyDown);+ return () => document.removeEventListener("keydown", handleKeyDown);+ }, [handleKeyDown]);++ if (mode === "hidden") return null;++ const handleTextSubmit = (text: string) => {+ sendMessage(text);+ };++ const headerContent = (+ <div className="h-9 flex items-center px-3 shrink-0">+ <span className="text-xs font-medium text-foreground/50">+ {t("embeddedChat.title")}+ </span>+ <div className="flex-1" />+ <div className="flex items-center gap-0.5">+ {mode === "floating" ? (+ <button+ onClick={() => onModeChange("sidebar")}+ className="h-6 w-6 flex items-center justify-center rounded-md text-foreground/25 hover:text-foreground/40 hover:bg-foreground/6 transition-colors"+ aria-label={t("embeddedChat.dock")}+ >+ <PanelRight size={13} />+ </button>+ ) : (+ <button+ onClick={() => onModeChange("floating")}+ className="h-6 w-6 flex items-center justify-center rounded-md text-foreground/25 hover:text-foreground/40 hover:bg-foreground/6 transition-colors"+ aria-label={t("embeddedChat.undock")}+ >+ <PanelRightClose size={13} />+ </button>+ )}+ <button+ onClick={() => onModeChange("hidden")}+ className="h-6 w-6 flex items-center justify-center rounded-md text-foreground/25 hover:text-foreground/40 hover:bg-foreground/6 transition-colors"+ aria-label={t("embeddedChat.close")}+ >+ <X size={13} />+ </button>+ </div>+ </div>+ );++ if (mode === "floating") {+ return (+ <div+ className={cn(+ "absolute bottom-20 right-4 z-20",+ "w-[380px] max-h-[480px] min-h-[200px]",+ "flex flex-col",+ "bg-background/95 dark:bg-surface-2/95",+ "border border-border/20 dark:border-white/8",+ "rounded-xl",+ "shadow-elevated",+ "backdrop-blur-2xl",+ "animate-[scale-in_200ms_ease-out]"+ )}+ >+ {headerContent}+ <ChatMessages messages={messages} emptyState={<EmptyState />} />+ <ChatInput+ agentState={agentState}+ partialTranscript=""+ onTextSubmit={handleTextSubmit}+ onCancel={cancelStream}+ showHotkey={false}+ autoFocus={false}+ />+ </div>+ );+ }++ // sidebar mode+ return (+ <div+ className={cn(+ "w-[340px] shrink-0",+ "border-l border-border/15 dark:border-white/6",+ "flex flex-col",+ "min-h-0"+ )}+ >+ {headerContent}+ <ChatMessages messages={messages} emptyState={<EmptyState />} />+ <ChatInput+ agentState={agentState}+ partialTranscript=""+ onTextSubmit={handleTextSubmit}+ onCancel={cancelStream}+ showHotkey={false}+ autoFocus={false}+ />+ </div>+ );+ }+);++export default EmbeddedChat;diff --git a/src/components/notes/NoteEditor.tsx b/src/components/notes/NoteEditor.tsxindex 775cf046b..8c8c2a4c0 100644--- a/src/components/notes/NoteEditor.tsx+++ b/src/components/notes/NoteEditor.tsx@@ -16,9 +16,12 @@ import type { NoteItem } from "../../types/electron";import type { ActionProcessingState } from "../../hooks/useActionProcessing";import ActionProcessingOverlay from "./ActionProcessingOverlay";import NoteBottomBar from "./NoteBottomBar";+import EmbeddedChat, { type EmbeddedChatHandle } from "./EmbeddedChat";import { normalizeDbDate } from "../../utils/dateFormatting";import { parseTranscriptSegments } from "../../utils/parseTranscriptSegments";+type EmbeddedChatMode = "hidden" | "floating" | "sidebar";+function formatNoteDate(dateStr: string): string {const date = normalizeDbDate(dateStr);if (Number.isNaN(date.getTime())) return "";@@ -60,7 +63,6 @@ interface NoteEditorProps {meetingSystemPartial?: string;onStopMeetingRecording?: () => void;liveTranscript?: string;- onAskSubmit?: (text: string) => void;}export default function NoteEditor({@@ -84,10 +86,12 @@ export default function NoteEditor({meetingSystemPartial,onStopMeetingRecording,liveTranscript,- onAskSubmit,}: NoteEditorProps) {const { t } = useTranslation();const [viewMode, setViewMode] = useState<MeetingViewMode>("raw");+ const [chatMode, setChatMode] = useState<EmbeddedChatMode>("hidden");+ const embeddedChatRef = useRef<EmbeddedChatHandle>(null);+ const pendingAskRef = useRef<string | null>(null);const editorRef = useRef<Editor | null>(null);const titleRef = useRef<HTMLDivElement>(null);const prevNoteIdRef = useRef<number>(note.id);@@ -212,6 +216,25 @@ export default function NoteEditor({[enhancement]);+ // Handle ask submit from NoteBottomBar: open chat + send message+ const handleAskSubmit = useCallback((text: string) => {+ if (chatMode === "hidden") {+ pendingAskRef.current = text;+ setChatMode("floating");+ } else {+ embeddedChatRef.current?.sendMessage(text);+ }+ }, [chatMode]);++ // Send pending message once EmbeddedChat mounts+ useEffect(() => {+ if (chatMode !== "hidden" && pendingAskRef.current && embeddedChatRef.current) {+ const text = pendingAskRef.current;+ pendingAskRef.current = null;+ embeddedChatRef.current.sendMessage(text);+ }+ }, [chatMode]);+const wordCount = useMemo(() => {const trimmed = note.content.trim();return trimmed ? trimmed.split(/\s+/).length : 0;@@ -338,46 +361,70 @@ export default function NoteEditor({</div></div>- <div className="flex-1 relative min-h-0">- <div className="h-full overflow-y-auto">- {viewMode === "transcript" && (hasChatSegments || isMeetingRecording) ? (- <MeetingTranscriptChat- segments={displaySegments}- micPartial={isMeetingRecording ? meetingMicPartial : undefined}- systemPartial={isMeetingRecording ? meetingSystemPartial : undefined}- />- ) : viewMode === "transcript" && hasMeetingTranscript ? (- <RichTextEditor value={effectiveTranscript} disabled />- ) : viewMode === "enhanced" && enhancement ? (- <RichTextEditor value={enhancement.content} onChange={handleEnhancedChange} />- ) : (- <RichTextEditor- value={note.content}- onChange={handleContentChange}- editorRef={editorRef}- placeholder={t("notes.editor.startWriting")}- disabled={actionProcessingState === "processing"}+ <div className="flex-1 relative min-h-0 flex">+ <div className="flex-1 min-w-0 relative">+ <div className="h-full overflow-y-auto">+ {viewMode === "transcript" && (hasChatSegments || isMeetingRecording) ? (+ <MeetingTranscriptChat+ segments={displaySegments}+ micPartial={isMeetingRecording ? meetingMicPartial : undefined}+ systemPartial={isMeetingRecording ? meetingSystemPartial : undefined}+ />+ ) : viewMode === "transcript" && hasMeetingTranscript ? (+ <RichTextEditor value={effectiveTranscript} disabled />+ ) : viewMode === "enhanced" && enhancement ? (+ <RichTextEditor value={enhancement.content} onChange={handleEnhancedChange} />+ ) : (+ <RichTextEditor+ value={note.content}+ onChange={handleContentChange}+ editorRef={editorRef}+ placeholder={t("notes.editor.startWriting")}+ disabled={actionProcessingState === "processing"}+ />+ )}+ </div>+ <ActionProcessingOverlay+ state={actionProcessingState ?? "idle"}+ actionName={actionName ?? null}+ />+ <div+ className="absolute bottom-0 left-0 right-0 h-24 pointer-events-none"+ style={{ background: "linear-gradient(to bottom, transparent, var(--color-background))" }}+ />+ <NoteBottomBar+ isRecording={isRecording || !!isMeetingRecording}+ isProcessing={isProcessing}+ onStartRecording={onStartRecording}+ onStopRecording={+ isMeetingRecording ? (onStopMeetingRecording ?? onStopRecording) : onStopRecording+ }+ onAskSubmit={handleAskSubmit}+ actionPicker={isMeetingRecording ? undefined : actionPicker}+ />+ {chatMode === "floating" && (+ <EmbeddedChat+ ref={embeddedChatRef}+ mode="floating"+ onModeChange={setChatMode}+ noteId={note.id}+ noteTitle={note.title}+ noteContent={note.content}+ noteTranscript={note.transcript}/>)}</div>- <ActionProcessingOverlay- state={actionProcessingState ?? "idle"}- actionName={actionName ?? null}- />- <div- className="absolute bottom-0 left-0 right-0 h-24 pointer-events-none"- style={{ background: "linear-gradient(to bottom, transparent, var(--color-background))" }}- />- <NoteBottomBar- isRecording={isRecording || !!isMeetingRecording}- isProcessing={isProcessing}- onStartRecording={onStartRecording}- onStopRecording={- isMeetingRecording ? (onStopMeetingRecording ?? onStopRecording) : onStopRecording- }- onAskSubmit={onAskSubmit ?? (() => {})}- actionPicker={isMeetingRecording ? undefined : actionPicker}- />+ {chatMode === "sidebar" && (+ <EmbeddedChat+ ref={embeddedChatRef}+ mode="sidebar"+ onModeChange={setChatMode}+ noteId={note.id}+ noteTitle={note.title}+ noteContent={note.content}+ noteTranscript={note.transcript}+ />+ )}</div></div>);diff --git a/src/hooks/useEmbeddedChat.ts b/src/hooks/useEmbeddedChat.tsnew file mode 100644index 000000000..b2fb29486--- /dev/null+++ b/src/hooks/useEmbeddedChat.ts@@ -0,0 +1,102 @@+import { useState, useCallback, useEffect, useRef } from "react";+import { useChatPersistence } from "../components/chat/useChatPersistence";+import { useChatStreaming } from "../components/chat/useChatStreaming";+import type { Message, AgentState } from "../components/chat/types";++interface UseEmbeddedChatOptions {+ noteId: number | null;+ noteTitle: string;+ noteContent: string;+ noteTranscript?: string;+}++interface UseEmbeddedChatReturn {+ messages: Message[];+ agentState: AgentState;+ sendMessage: (text: string) => Promise<void>;+ cancelStream: () => void;+ clearChat: () => void;+ hasMessages: boolean;+}++export function useEmbeddedChat({+ noteId,+ noteTitle,+ noteContent,+ noteTranscript,+}: UseEmbeddedChatOptions): UseEmbeddedChatReturn {+ const [conversationId, setConversationId] = useState<number | null>(null);+ const noteIdRef = useRef(noteId);++ const persistence = useChatPersistence({+ conversationId,+ onConversationCreated: (id) => {+ setConversationId(id);+ },+ });++ const noteContextRef = useRef("");+ noteContextRef.current = [+ `Title: ${noteTitle}`,+ `Content:\n${noteContent}`,+ noteTranscript ? `\nTranscript:\n${noteTranscript}` : "",+ ]+ .filter(Boolean)+ .join("\n");++ const streaming = useChatStreaming({+ messages: persistence.messages,+ setMessages: persistence.setMessages,+ noteContext: noteContextRef.current,+ onStreamComplete: (_id, content, toolCalls) => {+ persistence.saveAssistantMessage(content, toolCalls);+ },+ });++ // Reset chat when noteId changes+ useEffect(() => {+ if (noteId !== noteIdRef.current) {+ noteIdRef.current = noteId;+ persistence.handleNewChat();+ setConversationId(null);+ }+ }, [noteId, persistence]);++ const sendMessage = useCallback(+ async (text: string) => {+ let convId = conversationId;+ if (!convId) {+ const title = `Note: ${noteTitle || "Untitled"}`;+ convId = await persistence.createConversation(title);+ }++ const userMsg: Message = {+ id: crypto.randomUUID(),+ role: "user",+ content: text,+ isStreaming: false,+ };+ persistence.setMessages((prev) => [...prev, userMsg]);+ await persistence.saveUserMessage(text);++ const allMessages = [...persistence.messages, userMsg];+ await streaming.sendToAI(text, allMessages);+ },+ [conversationId, noteTitle, persistence, streaming]+ );++ const clearChat = useCallback(() => {+ persistence.handleNewChat();+ setConversationId(null);+ streaming.cancelStream();+ }, [persistence, streaming]);++ return {+ messages: persistence.messages,+ agentState: streaming.agentState,+ sendMessage,+ cancelStream: streaming.cancelStream,+ clearChat,+ hasMessages: persistence.messages.length > 0,+ };+}diff --git a/src/locales/de/translation.json b/src/locales/de/translation.jsonindex 99d3e1de4..7b7499994 100644--- a/src/locales/de/translation.json+++ b/src/locales/de/translation.json@@ -2048,5 +2048,14 @@"title": "Berechtigungen erforderlich","description": "OpenWhispr benötigt einige Berechtigungen, um auf diesem Computer zu funktionieren.","continue": "Weiter"+ },+ "embeddedChat": {+ "askPlaceholder": "Frag etwas...",+ "send": "Senden",+ "title": "Chat",+ "emptyState": "Stelle eine Frage zu dieser Notiz",+ "dock": "In Seitenleiste andocken",+ "undock": "Von Seitenleiste abdocken",+ "close": "Chat schließen"}}diff --git a/src/locales/en/translation.json b/src/locales/en/translation.jsonindex 760c7c5c5..470c6850a 100644--- a/src/locales/en/translation.json+++ b/src/locales/en/translation.json@@ -2051,6 +2051,11 @@},"embeddedChat": {"askPlaceholder": "Ask anything...",- "send": "Send"+ "send": "Send",+ "title": "Chat",+ "emptyState": "Ask a question about this note",+ "dock": "Dock to sidebar",+ "undock": "Undock from sidebar",+ "close": "Close chat"}}diff --git a/src/locales/es/translation.json b/src/locales/es/translation.jsonindex 928f59f7b..6dd8581a8 100644--- a/src/locales/es/translation.json+++ b/src/locales/es/translation.json@@ -2048,5 +2048,14 @@"title": "Permisos necesarios","description": "OpenWhispr necesita algunos permisos para funcionar en este ordenador.","continue": "Continuar"+ },+ "embeddedChat": {+ "askPlaceholder": "Pregunta algo...",+ "send": "Enviar",+ "title": "Chat",+ "emptyState": "Haz una pregunta sobre esta nota",+ "dock": "Anclar a la barra lateral",+ "undock": "Desanclar de la barra lateral",+ "close": "Cerrar chat"}}diff --git a/src/locales/fr/translation.json b/src/locales/fr/translation.jsonindex a6d92b197..7ef68ad5f 100644--- a/src/locales/fr/translation.json+++ b/src/locales/fr/translation.json@@ -2048,5 +2048,14 @@"title": "Autorisations requises","description": "OpenWhispr a besoin de quelques autorisations pour fonctionner sur cet ordinateur.","continue": "Continuer"+ },+ "embeddedChat": {+ "askPlaceholder": "Posez une question...",+ "send": "Envoyer",+ "title": "Chat",+ "emptyState": "Posez une question sur cette note",+ "dock": "Ancrer dans la barre latérale",+ "undock": "Détacher de la barre latérale",+ "close": "Fermer le chat"}}diff --git a/src/locales/it/translation.json b/src/locales/it/translation.jsonindex ba80327af..198e8567a 100644--- a/src/locales/it/translation.json+++ b/src/locales/it/translation.json@@ -2048,5 +2048,14 @@"title": "Autorizzazioni necessarie","description": "OpenWhispr ha bisogno di alcune autorizzazioni per funzionare su questo computer.","continue": "Continua"+ },+ "embeddedChat": {+ "askPlaceholder": "Chiedi qualcosa...",+ "send": "Invia",+ "title": "Chat",+ "emptyState": "Fai una domanda su questa nota",+ "dock": "Ancora nella barra laterale",+ "undock": "Sgancia dalla barra laterale",+ "close": "Chiudi chat"}}diff --git a/src/locales/ja/translation.json b/src/locales/ja/translation.jsonindex d58224ab8..e068099f4 100644--- a/src/locales/ja/translation.json+++ b/src/locales/ja/translation.json@@ -2048,5 +2048,14 @@"title": "権限が必要です","description": "OpenWhispr がこのコンピュータで動作するために、いくつかの権限が必要です。","continue": "続行"+ },+ "embeddedChat": {+ "askPlaceholder": "何でも聞いてください...",+ "send": "送信",+ "title": "チャット",+ "emptyState": "このノートについて質問してください",+ "dock": "サイドバーに固定",+ "undock": "サイドバーから外す",+ "close": "チャットを閉じる"}}diff --git a/src/locales/pt/translation.json b/src/locales/pt/translation.jsonindex dcc234673..1f565bd20 100644--- a/src/locales/pt/translation.json+++ b/src/locales/pt/translation.json@@ -2048,5 +2048,14 @@"title": "Permissões necessárias","description": "O OpenWhispr precisa de algumas permissões para funcionar neste computador.","continue": "Continuar"+ },+ "embeddedChat": {+ "askPlaceholder": "Pergunte algo...",+ "send": "Enviar",+ "title": "Chat",+ "emptyState": "Faça uma pergunta sobre esta nota",+ "dock": "Fixar na barra lateral",+ "undock": "Desafixar da barra lateral",+ "close": "Fechar chat"}}diff --git a/src/locales/ru/translation.json b/src/locales/ru/translation.jsonindex 86c4581f8..ec46e6d53 100644--- a/src/locales/ru/translation.json+++ b/src/locales/ru/translation.json@@ -2048,5 +2048,14 @@"title": "Требуются разрешения","description": "OpenWhispr нужны некоторые разрешения для работы на этом компьютере.","continue": "Продолжить"+ },+ "embeddedChat": {+ "askPlaceholder": "Спросите что-нибудь...",+ "send": "Отправить",+ "title": "Чат",+ "emptyState": "Задайте вопрос об этой заметке",+ "dock": "Закрепить на боковой панели",+ "undock": "Открепить от боковой панели",+ "close": "Закрыть чат"}}diff --git a/src/locales/zh-CN/translation.json b/src/locales/zh-CN/translation.jsonindex 86be4715f..c0ada9cbf 100644--- a/src/locales/zh-CN/translation.json+++ b/src/locales/zh-CN/translation.json@@ -2043,5 +2043,14 @@"title": "需要权限","description": "OpenWhispr 需要一些权限才能在此电脑上正常运行。","continue": "继续"+ },+ "embeddedChat": {+ "askPlaceholder": "随便问点什么...",+ "send": "发送",+ "title": "聊天",+ "emptyState": "就这条笔记提个问题",+ "dock": "固定到侧边栏",+ "undock": "从侧边栏取消固定",+ "close": "关闭聊天"}}diff --git a/src/locales/zh-TW/translation.json b/src/locales/zh-TW/translation.jsonindex 7a742e568..0714ca1ed 100644--- a/src/locales/zh-TW/translation.json+++ b/src/locales/zh-TW/translation.json@@ -2043,5 +2043,14 @@"title": "需要權限","description": "OpenWhispr 需要一些權限才能在此電腦上正常運作。","continue": "繼續"+ },+ "embeddedChat": {+ "askPlaceholder": "隨便問點什麼...",+ "send": "傳送",+ "title": "聊天",+ "emptyState": "就這條筆記提個問題",+ "dock": "固定到側邊欄",+ "undock": "從側邊欄取消固定",+ "close": "關閉聊天"}}