π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Improve Ensu chat input responsiveness
Manav Rathi4f60ef7caed2
diff --git a/rust/apps/ensu/changes/input-responsiveness.md b/rust/apps/ensu/changes/input-responsiveness.mdnew file mode 100644index 0000000000..b0551427b4--- /dev/null+++ b/rust/apps/ensu/changes/input-responsiveness.md@@ -0,0 +1 @@+- Fixed typing lag in the message composer and chat search.diff --git a/web/apps/ensu/src/components/chat/ChatComposer.tsx b/web/apps/ensu/src/components/chat/ChatComposer.tsxindex 9fc1f74e10..2e0f35572f 100644--- a/web/apps/ensu/src/components/chat/ChatComposer.tsx+++ b/web/apps/ensu/src/components/chat/ChatComposer.tsx@@ -4,15 +4,12 @@ import {Attachment01Icon,Cancel01Icon,Edit01Icon,- Navigation06Icon,- Upload01Icon,} from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";import {Box,Button,IconButton,- InputBase,LinearProgress,Menu,MenuItem,@@ -20,7 +17,8 @@ import {Typography,} from "@mui/material";import type { SxProps, Theme } from "@mui/material/styles";-import React, { memo } from "react";+import React, { forwardRef, memo, useImperativeHandle, useRef } from "react";+import { ChatInput, type ChatInputHandle } from "./ChatInput";interface IconProps {size: number;@@ -49,6 +47,8 @@ type SuggestedModelStatus =| "ready"| "error";+export type ChatComposerHandle = ChatInputHandle;+export interface ChatComposerProps {showModelGate: boolean;showDownloadProgress: boolean;@@ -67,11 +67,8 @@ export interface ChatComposerProps {removePendingDocument: (id: string) => void;removePendingImage: (id: string) => void;formatBytes: (size: number) => string;- input: string;- onInputChange: React.Dispatch<React.SetStateAction<string>>;- inputRef: React.RefObject<HTMLTextAreaElement | null>;isGenerating: boolean;- handleSend: () => void | Promise<void>;+ handleSend: (input: string) => void | Promise<void>;handleStopGeneration: () => void;showAttachmentPicker: boolean;openAttachmentMenu: (event: React.MouseEvent<HTMLElement>) => void;@@ -91,57 +88,65 @@ export interface ChatComposerProps {}export const ChatComposer = memo(- ({- showModelGate,- showDownloadProgress,- downloadStatus,- downloadStatusLabel,- downloadSizeLabel,- modelGateStatus,- modelGateError,- isDownloading,- handleDownloadModel,- editingMessage,- handleCancelEdit,- pendingDocuments,- pendingImages,- pendingImagePreviews,- removePendingDocument,- removePendingImage,- formatBytes,- input,- onInputChange,- inputRef,- isGenerating,- handleSend,- handleStopGeneration,- showAttachmentPicker,- openAttachmentMenu,- attachmentAnchor,- closeAttachmentMenu,- handleAttachmentChoice,- showImageAttachment,- isImageAttachmentLimitReached,- getDocumentInputProps,- getImageInputProps,- actionButtonSx,- drawerIconButtonSx,- smallIconProps,- compactIconProps,- actionIconProps,- stopButtonColor,- }: ChatComposerProps) => {+ forwardRef<ChatInputHandle, ChatComposerProps>(function ChatComposer(+ {+ showModelGate,+ showDownloadProgress,+ downloadStatus,+ downloadStatusLabel,+ downloadSizeLabel,+ modelGateStatus,+ modelGateError,+ isDownloading,+ handleDownloadModel,+ editingMessage,+ handleCancelEdit,+ pendingDocuments,+ pendingImages,+ pendingImagePreviews,+ removePendingDocument,+ removePendingImage,+ formatBytes,+ isGenerating,+ handleSend,+ handleStopGeneration,+ showAttachmentPicker,+ openAttachmentMenu,+ attachmentAnchor,+ closeAttachmentMenu,+ handleAttachmentChoice,+ showImageAttachment,+ isImageAttachmentLimitReached,+ getDocumentInputProps,+ getImageInputProps,+ actionButtonSx,+ drawerIconButtonSx,+ smallIconProps,+ compactIconProps,+ actionIconProps,+ stopButtonColor,+ },+ ref,+ ) {+ const inputRef = useRef<ChatInputHandle>(null);+ const draftRef = useRef("");++ useImperativeHandle(+ ref,+ () => ({+ focus: () => inputRef.current?.focus(),+ setText: (text) => {+ draftRef.current = text;+ inputRef.current?.setText(text);+ },+ }),+ [],+ );+const isModelPreparationActive =modelGateStatus === "checking" ||modelGateStatus === "preloading" ||modelGateStatus === "downloading";- const disableSend =- isModelPreparationActive ||- isDownloading ||- (!isGenerating &&- !input.trim() &&- pendingDocuments.length === 0 &&- pendingImages.length === 0);const disableAttachmentButton =isGenerating ||isModelPreparationActive ||@@ -515,156 +520,36 @@ export const ChatComposer = memo(</Box>)}- <Box- sx={{- display: "flex",- alignItems: "center",- gap: 1,- px: 1,- py: 0.75,- borderRadius: 2,- bgcolor:- "color-mix(in srgb, var(--mui-palette-background-default) 45%, var(--mui-palette-background-paper) 55%)",+ <ChatInput+ ref={inputRef}+ actionIconProps={actionIconProps}+ disableAttachmentButton={+ disableAttachmentButton+ }+ drawerIconButtonSx={drawerIconButtonSx}+ handleSend={handleSend}+ handleStopGeneration={+ handleStopGeneration+ }+ hasPendingAttachments={+ pendingDocuments.length > 0 ||+ pendingImages.length > 0+ }+ isDownloading={isDownloading}+ isGenerating={isGenerating}+ isModelPreparationActive={+ isModelPreparationActive+ }+ initialText={draftRef.current}+ onTextChange={(text) => {+ draftRef.current = text;}}- >- <InputBase- multiline- maxRows={5}- inputRef={inputRef}- placeholder={- isDownloading- ? "Downloading model..."- : "Write a message..."- }- value={input}- onChange={(event) =>- onInputChange(- event.target.value,- )- }- onKeyDown={(event) => {- if (- event.key === "Enter" &&- !event.shiftKey- ) {- event.preventDefault();- void handleSend();- }- }}- sx={{- flex: 1,- bgcolor: "transparent",- borderRadius: 2,- px: 1.5,- py: 1.5,- minHeight: 48,- display: "flex",- alignItems: "center",- fontFamily: "inherit",- fontSize: "15px",- lineHeight: 1.7,- color: "text.base",- "& textarea": {- padding: 0,- margin: 0,- },- "& code": {- fontFamily:- 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',- },- }}- />- {showAttachmentPicker && (- <IconButton- aria-label="Add attachment"- sx={drawerIconButtonSx}- disabled={- disableAttachmentButton- }- onClick={openAttachmentMenu}- >- <HugeiconsIcon- icon={Upload01Icon}- {...actionIconProps}- />- </IconButton>- )}- <IconButton- aria-label={- isGenerating- ? "Stop"- : "Send message"- }- onClick={- isGenerating- ? handleStopGeneration- : () => void handleSend()- }- disabled={disableSend}- sx={{- width: 44,- height: 44,- borderRadius: 2,- bgcolor: "transparent",- color: isGenerating- ? "critical.main"- : "text.muted",- "&:hover": {- bgcolor: "fill.faint",- },- "&.Mui-disabled": {- color: "text.faint",- },- }}- >- {isGenerating ? (- <Box- sx={{- width: 22,- height: 22,- minWidth: 22,- minHeight: 22,- borderRadius: "999px",- bgcolor: "#ffffff",- display: "inline-flex",- alignItems: "center",- justifyContent:- "center",- }}- >- <Box- component="svg"- viewBox="0 0 24 24"- sx={{- width: 12,- height: 12,- display: "block",- }}- >- <path- d="M4 12C4 8.72077 4 7.08116 4.81382 5.91891C5.1149 5.48891 5.48891 5.1149 5.91891 4.81382C7.08116 4 8.72077 4 12 4C15.2792 4 16.9188 4 18.0811 4.81382C18.5111 5.1149 18.8851 5.48891 19.1862 5.91891C20 7.08116 20 8.72077 20 12C20 15.2792 20 16.9188 19.1862 18.0811C18.8851 18.5111 18.5111 18.8851 18.0811 19.1862C16.9188 20 15.2792 20 12 20C8.72077 20 7.08116 20 5.91891 19.1862C5.48891 18.8851 5.1149 18.5111 4.81382 18.0811C4 16.9188 4 15.2792 4 12Z"- fill={- stopButtonColor- }- />- </Box>- </Box>- ) : (- <Box- sx={{- transform:- "rotate(90deg)",- display: "flex",- }}- >- <HugeiconsIcon- icon={Navigation06Icon}- {...actionIconProps}- />- </Box>- )}- </IconButton>- </Box>+ openAttachmentMenu={openAttachmentMenu}+ showAttachmentPicker={+ showAttachmentPicker+ }+ stopButtonColor={stopButtonColor}+ /></Stack></>)}@@ -703,5 +588,5 @@ export const ChatComposer = memo()}</>);- },+ }),);diff --git a/web/apps/ensu/src/components/chat/ChatInput.tsx b/web/apps/ensu/src/components/chat/ChatInput.tsxnew file mode 100644index 0000000000..3ce5c8b9b9--- /dev/null+++ b/web/apps/ensu/src/components/chat/ChatInput.tsx@@ -0,0 +1,198 @@+import { Navigation06Icon, Upload01Icon } from "@hugeicons/core-free-icons";+import { HugeiconsIcon } from "@hugeicons/react";+import { Box, IconButton, InputBase } from "@mui/material";+import type { SxProps, Theme } from "@mui/material/styles";+import React, {+ forwardRef,+ memo,+ useImperativeHandle,+ useRef,+ useState,+} from "react";++interface IconProps {+ size: number;+ strokeWidth: number;+}++export interface ChatInputHandle {+ focus: () => void;+ setText: (text: string) => void;+}++interface ChatInputProps {+ actionIconProps: IconProps;+ disableAttachmentButton: boolean;+ drawerIconButtonSx: SxProps<Theme>;+ handleSend: (input: string) => void | Promise<void>;+ handleStopGeneration: () => void;+ hasPendingAttachments: boolean;+ initialText: string;+ isDownloading: boolean;+ isGenerating: boolean;+ isModelPreparationActive: boolean;+ openAttachmentMenu: (event: React.MouseEvent<HTMLElement>) => void;+ onTextChange: (text: string) => void;+ showAttachmentPicker: boolean;+ stopButtonColor: string;+}++export const ChatInput = memo(+ forwardRef<ChatInputHandle, ChatInputProps>(function ChatInput(+ {+ actionIconProps,+ disableAttachmentButton,+ drawerIconButtonSx,+ handleSend,+ handleStopGeneration,+ hasPendingAttachments,+ initialText,+ isDownloading,+ isGenerating,+ isModelPreparationActive,+ openAttachmentMenu,+ onTextChange,+ showAttachmentPicker,+ stopButtonColor,+ },+ ref,+ ) {+ const [input, setInput] = useState(initialText);+ const inputRef = useRef<HTMLTextAreaElement | null>(null);++ useImperativeHandle(+ ref,+ () => ({+ focus: () => inputRef.current?.focus(),+ setText: setInput,+ }),+ [],+ );++ const send = () => void handleSend(input);+ const disableSend =+ isModelPreparationActive ||+ isDownloading ||+ (!isGenerating && !input.trim() && !hasPendingAttachments);++ return (+ <Box+ sx={{+ display: "flex",+ alignItems: "center",+ gap: 1,+ px: 1,+ py: 0.75,+ borderRadius: 2,+ bgcolor:+ "color-mix(in srgb, var(--mui-palette-background-default) 45%, var(--mui-palette-background-paper) 55%)",+ }}+ >+ <InputBase+ multiline+ maxRows={5}+ inputRef={inputRef}+ placeholder={+ isDownloading+ ? "Downloading model..."+ : "Write a message..."+ }+ value={input}+ onChange={(event) => {+ const text = event.target.value;+ setInput(text);+ onTextChange(text);+ }}+ onKeyDown={(event) => {+ if (event.key === "Enter" && !event.shiftKey) {+ event.preventDefault();+ send();+ }+ }}+ sx={{+ flex: 1,+ bgcolor: "transparent",+ borderRadius: 2,+ px: 1.5,+ py: 1.5,+ minHeight: 48,+ display: "flex",+ alignItems: "center",+ fontFamily: "inherit",+ fontSize: "15px",+ lineHeight: 1.7,+ color: "text.base",+ "& textarea": { padding: 0, margin: 0 },+ "& code": {+ fontFamily:+ 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',+ },+ }}+ />+ {showAttachmentPicker && (+ <IconButton+ aria-label="Add attachment"+ sx={drawerIconButtonSx}+ disabled={disableAttachmentButton}+ onClick={openAttachmentMenu}+ >+ <HugeiconsIcon+ icon={Upload01Icon}+ {...actionIconProps}+ />+ </IconButton>+ )}+ <IconButton+ aria-label={isGenerating ? "Stop" : "Send message"}+ onClick={isGenerating ? handleStopGeneration : send}+ disabled={disableSend}+ sx={{+ width: 44,+ height: 44,+ borderRadius: 2,+ bgcolor: "transparent",+ color: isGenerating ? "critical.main" : "text.muted",+ "&:hover": { bgcolor: "fill.faint" },+ "&.Mui-disabled": { color: "text.faint" },+ }}+ >+ {isGenerating ? (+ <Box+ sx={{+ width: 22,+ height: 22,+ minWidth: 22,+ minHeight: 22,+ borderRadius: "999px",+ bgcolor: "#ffffff",+ display: "inline-flex",+ alignItems: "center",+ justifyContent: "center",+ }}+ >+ <Box+ component="svg"+ viewBox="0 0 24 24"+ sx={{ width: 12, height: 12, display: "block" }}+ >+ <path+ d="M4 12C4 8.72077 4 7.08116 4.81382 5.91891C5.1149 5.48891 5.48891 5.1149 5.91891 4.81382C7.08116 4 8.72077 4 12 4C15.2792 4 16.9188 4 18.0811 4.81382C18.5111 5.1149 18.8851 5.48891 19.1862 5.91891C20 7.08116 20 8.72077 20 12C20 15.2792 20 16.9188 19.1862 18.0811C18.8851 18.5111 18.5111 18.8851 18.0811 19.1862C16.9188 20 15.2792 20 12 20C8.72077 20 7.08116 20 5.91891 19.1862C5.48891 18.8851 5.1149 18.5111 4.81382 18.0811C4 16.9188 4 15.2792 4 12Z"+ fill={stopButtonColor}+ />+ </Box>+ </Box>+ ) : (+ <Box+ sx={{ transform: "rotate(90deg)", display: "flex" }}+ >+ <HugeiconsIcon+ icon={Navigation06Icon}+ {...actionIconProps}+ />+ </Box>+ )}+ </IconButton>+ </Box>+ );+ }),+);diff --git a/web/apps/ensu/src/components/chat/ChatSidebar.tsx b/web/apps/ensu/src/components/chat/ChatSidebar.tsxindex 388fd3dfbc..db56c83d92 100644--- a/web/apps/ensu/src/components/chat/ChatSidebar.tsx+++ b/web/apps/ensu/src/components/chat/ChatSidebar.tsx@@ -21,7 +21,13 @@ import {Typography,} from "@mui/material";import type { SxProps, Theme } from "@mui/material/styles";-import React, { memo } from "react";+import {+ memo,+ startTransition,+ useMemo,+ useState,+ type RefObject,+} from "react";interface IconProps {size: number;@@ -36,14 +42,13 @@ export interface ChatSidebarProps {tinyIconProps: IconProps;actionIconProps: IconProps;showSessionSearch: boolean;- sessionSearch: string;- setSessionSearch: React.Dispatch<React.SetStateAction<string>>;+ sessionSearchRef: RefObject<string>;handleOpenSessionSearch: () => void;handleCloseSessionSearch: () => void;handleNewChat: () => void;handleOpenDrawer: () => void;handleCollapseDrawer: () => void;- groupedSessions: [string, ChatSession[]][];+ sessions: ChatSession[];currentSessionId?: string;handleSelectSession: (sessionId: string) => void;requestRenameSession: (session: ChatSession) => void;@@ -52,6 +57,52 @@ export interface ChatSidebarProps {}export const ChatSidebar = memo(+ ({+ sessions,+ sessionSearchRef,+ handleCloseSessionSearch,+ ...props+ }: ChatSidebarProps) => {+ const [sessionSearch, setSessionSearch] = useState(+ sessionSearchRef.current,+ );+ const groupedSessions = useMemo(() => {+ const query = sessionSearch.trim().toLowerCase();+ const filteredSessions = query+ ? sessions.filter((session) => {+ const title = session.title.toLowerCase();+ const preview =+ session.lastMessagePreview?.toLowerCase() ?? "";+ return title.includes(query) || preview.includes(query);+ })+ : sessions;+ return groupSessionsByDate(filteredSessions);+ }, [sessionSearch, sessions]);++ const closeSessionSearch = () => {+ sessionSearchRef.current = "";+ setSessionSearch("");+ handleCloseSessionSearch();+ };++ return (+ <ChatSidebarView+ {...props}+ groupedSessions={groupedSessions}+ handleCloseSessionSearch={closeSessionSearch}+ sessionSearchRef={sessionSearchRef}+ setSessionSearch={setSessionSearch}+ />+ );+ },+);++interface ChatSidebarViewProps extends Omit<ChatSidebarProps, "sessions"> {+ groupedSessions: [string, ChatSession[]][];+ setSessionSearch: (query: string) => void;+}++const ChatSidebarView = memo(({drawerCollapsed,drawerIconButtonSx,@@ -60,7 +111,7 @@ export const ChatSidebar = memo(tinyIconProps,actionIconProps,showSessionSearch,- sessionSearch,+ sessionSearchRef,setSessionSearch,handleOpenSessionSearch,handleCloseSessionSearch,@@ -73,7 +124,7 @@ export const ChatSidebar = memo(requestRenameSession,requestDeleteSession,openSettingsModal,- }: ChatSidebarProps) => (+ }: ChatSidebarViewProps) => (<Stacksx={{width: "100%",@@ -111,44 +162,11 @@ export const ChatSidebar = memo(>{showSessionSearch ? (<>- <Box- sx={{- flex: 1,- display: "flex",- alignItems: "center",- justifyContent: "flex-start",- gap: 1,- px: 1.5,- height: 40,- borderRadius: 2,- bgcolor: "fill.faint",- textAlign: "left",- }}- >- <HugeiconsIcon- icon={Search01Icon}- {...tinyIconProps}- />- <InputBase- placeholder="Search chats"- autoFocus- value={sessionSearch}- onChange={(event) =>- setSessionSearch(event.target.value)- }- inputProps={{- style: { textAlign: "left" },- }}- sx={{- flex: 1,- color: "text.base",- fontFamily: "inherit",- fontSize: "13px",- textAlign: "left",- "& input": { textAlign: "left" },- }}- />- </Box>+ <SessionSearchInput+ sessionSearchRef={sessionSearchRef}+ setSessionSearch={setSessionSearch}+ tinyIconProps={tinyIconProps}+ /><IconButtonaria-label="Close search"sx={drawerIconButtonSx}@@ -428,3 +446,121 @@ export const ChatSidebar = memo(</Stack>),);++interface SessionSearchInputProps {+ sessionSearchRef: RefObject<string>;+ setSessionSearch: (query: string) => void;+ tinyIconProps: IconProps;+}++const SessionSearchInput = memo(+ ({+ sessionSearchRef,+ setSessionSearch,+ tinyIconProps,+ }: SessionSearchInputProps) => {+ const [value, setValue] = useState(sessionSearchRef.current);++ return (+ <Box+ sx={{+ flex: 1,+ display: "flex",+ alignItems: "center",+ justifyContent: "flex-start",+ gap: 1,+ px: 1.5,+ height: 40,+ borderRadius: 2,+ bgcolor: "fill.faint",+ textAlign: "left",+ }}+ >+ <HugeiconsIcon icon={Search01Icon} {...tinyIconProps} />+ <InputBase+ placeholder="Search chats"+ autoFocus+ value={value}+ onChange={(event) => {+ const query = event.target.value;+ sessionSearchRef.current = query;+ setValue(query);+ startTransition(() => setSessionSearch(query));+ }}+ inputProps={{ style: { textAlign: "left" } }}+ sx={{+ flex: 1,+ color: "text.base",+ fontFamily: "inherit",+ fontSize: "13px",+ textAlign: "left",+ "& input": { textAlign: "left" },+ }}+ />+ </Box>+ );+ },+);++type SessionGroupLabel =+ | "TODAY"+ | "YESTERDAY"+ | "THIS WEEK"+ | "LAST WEEK"+ | "THIS MONTH"+ | "OLDER";++const groupSessionsByDate = (sessions: ChatSession[]) => {+ const now = new Date();+ const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());+ const yesterday = new Date(today);+ yesterday.setDate(yesterday.getDate() - 1);++ const thisWeekStart = new Date(today);+ thisWeekStart.setDate(+ thisWeekStart.getDate() - (thisWeekStart.getDay() || 7) + 1,+ );++ const lastWeekStart = new Date(thisWeekStart);+ lastWeekStart.setDate(lastWeekStart.getDate() - 7);++ const thisMonthStart = new Date(now.getFullYear(), now.getMonth(), 1);++ const grouped: Record<SessionGroupLabel, ChatSession[]> = {+ TODAY: [],+ YESTERDAY: [],+ "THIS WEEK": [],+ "LAST WEEK": [],+ "THIS MONTH": [],+ OLDER: [],+ };++ sessions.forEach((session) => {+ const sessionDate = new Date(Math.floor(session.updatedAt / 1000));+ const sessionDay = new Date(+ sessionDate.getFullYear(),+ sessionDate.getMonth(),+ sessionDate.getDate(),+ );++ let category: SessionGroupLabel = "OLDER";++ if (sessionDay >= today) {+ category = "TODAY";+ } else if (sessionDay.getTime() === yesterday.getTime()) {+ category = "YESTERDAY";+ } else if (sessionDay >= thisWeekStart) {+ category = "THIS WEEK";+ } else if (sessionDay >= lastWeekStart) {+ category = "LAST WEEK";+ } else if (sessionDay >= thisMonthStart) {+ category = "THIS MONTH";+ }++ grouped[category].push(session);+ });++ return (+ Object.entries(grouped) as [SessionGroupLabel, ChatSession[]][]+ ).filter(([, group]) => group.length > 0);+};diff --git a/web/apps/ensu/src/pages/chat.tsx b/web/apps/ensu/src/pages/chat.tsxindex f9e20138a2..5468b78b77 100644--- a/web/apps/ensu/src/pages/chat.tsx+++ b/web/apps/ensu/src/pages/chat.tsx@@ -1,4 +1,7 @@-import { ChatComposer } from "@/components/chat/ChatComposer";+import {+ ChatComposer,+ type ChatComposerHandle,+} from "@/components/chat/ChatComposer";import { ChatDialogs } from "@/components/chat/ChatDialogs";import { ChatMessageList } from "@/components/chat/ChatMessageList";import { ChatSidebar } from "@/components/chat/ChatSidebar";@@ -358,69 +361,6 @@ const formatBytes = (bytes: number) => {return `${value.toFixed(value >= 10 ? 0 : 1)} ${units[idx]}`;};-type SessionGroupLabel =- | "TODAY"- | "YESTERDAY"- | "THIS WEEK"- | "LAST WEEK"- | "THIS MONTH"- | "OLDER";--const groupSessionsByDate = (sessions: ChatSession[]) => {- const now = new Date();- const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());- const yesterday = new Date(today);- yesterday.setDate(yesterday.getDate() - 1);-- const thisWeekStart = new Date(today);- thisWeekStart.setDate(- thisWeekStart.getDate() - (thisWeekStart.getDay() || 7) + 1,- );-- const lastWeekStart = new Date(thisWeekStart);- lastWeekStart.setDate(lastWeekStart.getDate() - 7);-- const thisMonthStart = new Date(now.getFullYear(), now.getMonth(), 1);-- const grouped: Record<SessionGroupLabel, ChatSession[]> = {- TODAY: [],- YESTERDAY: [],- "THIS WEEK": [],- "LAST WEEK": [],- "THIS MONTH": [],- OLDER: [],- };-- sessions.forEach((session) => {- const sessionDate = new Date(Math.floor(session.updatedAt / 1000));- const sessionDay = new Date(- sessionDate.getFullYear(),- sessionDate.getMonth(),- sessionDate.getDate(),- );-- let category: SessionGroupLabel = "OLDER";-- if (sessionDay >= today) {- category = "TODAY";- } else if (sessionDay.getTime() === yesterday.getTime()) {- category = "YESTERDAY";- } else if (sessionDay >= thisWeekStart) {- category = "THIS WEEK";- } else if (sessionDay >= lastWeekStart) {- category = "LAST WEEK";- } else if (sessionDay >= thisMonthStart) {- category = "THIS MONTH";- }-- grouped[category].push(session);- });-- return (- Object.entries(grouped) as [SessionGroupLabel, ChatSession[]][]- ).filter(([, group]) => group.length > 0);-};-const detectTauriRuntime = () => detectTauriAppRuntime();const Page: React.FC = () => {@@ -590,13 +530,11 @@ const Page: React.FC = () => {const [currentSessionId, setCurrentSessionId] = useState<string | undefined>();- const [input, setInput] = useState("");const [drawerOpen, setDrawerOpen] = useState(false);const [drawerCollapsed, setDrawerCollapsed] = useState(false);const [chatViewportWidth, setChatViewportWidth] = useState(() =>typeof window !== "undefined" ? window.innerWidth : 0,);- const [sessionSearch, setSessionSearch] = useState("");const [showSessionSearch, setShowSessionSearch] = useState(false);const [showSettingsModal, setShowSettingsModal] = useState(false);const [advancedUnlocked, setAdvancedUnlocked] = useState(false);@@ -725,7 +663,8 @@ const Page: React.FC = () => {generationStoppingRef.current = false;}}, []);- const inputRef = useRef<HTMLTextAreaElement | null>(null);+ const composerRef = useRef<ChatComposerHandle | null>(null);+ const sessionSearchRef = useRef("");const attachmentPreviewUrlsRef = useRef<Record<string, string>>({});const pendingPreviewUrlsRef = useRef<Record<string, string>>({});const imagePreviewUrlRef = useRef<string | null>(null);@@ -1678,21 +1617,6 @@ const Page: React.FC = () => {};}, [currentRootSessionUuid]);- const filteredSessions = useMemo(() => {- const query = sessionSearch.trim().toLowerCase();- if (!query) return sessions;- return sessions.filter((session) => {- const title = session.title.toLowerCase();- const preview = session.lastMessagePreview?.toLowerCase() ?? "";- return title.includes(query) || preview.includes(query);- });- }, [sessionSearch, sessions]);-- const groupedSessions = useMemo(- () => groupSessionsByDate(filteredSessions),- [filteredSessions],- );-const rootSessionUuid = currentSession?.rootSessionUuid ?? currentSessionId;const messageState = useMemo(@@ -1838,7 +1762,7 @@ const Page: React.FC = () => {const focusInput = useCallback(() => {if (showModelGate) return;if (typeof window === "undefined") return;- const target = inputRef.current;+ const target = composerRef.current;if (!target) return;window.requestAnimationFrame(() => {target.focus();@@ -2458,7 +2382,7 @@ const Page: React.FC = () => {setCurrentSessionId(undefined);currentSessionIdRef.current = undefined;setAllMessages([]);- setInput("");+ composerRef.current?.setText("");setEditingMessage(null);setPendingImages([]);setStreamingParentId(null);@@ -2604,7 +2528,7 @@ const Page: React.FC = () => {async (message: ChatMessage) => {const parsed = parseDocumentBlocks(message.text);setEditingMessage(message);- setInput(parsed.text);+ composerRef.current?.setText(parsed.text);const attachments = message.attachments ?? [];const imageAttachments = attachments.filter(@@ -2664,7 +2588,7 @@ const Page: React.FC = () => {const handleCancelEdit = useCallback(() => {setEditingMessage(null);- setInput("");+ composerRef.current?.setText("");setPendingDocuments([]);setPendingImages([]);}, []);@@ -3523,7 +3447,6 @@ const Page: React.FC = () => {setShowSessionSearch(true);}, []);const handleCloseSessionSearch = useCallback(() => {- setSessionSearch("");setShowSessionSearch(false);}, []);@@ -4139,7 +4062,7 @@ const Page: React.FC = () => {setPendingImages((prev) => prev.filter((img) => img.id !== id));}, []);- const handleSend = useCallback(async () => {+ const handleSend = async (input: string) => {const trimmed = input.trim();const hasDocuments = pendingDocuments.length > 0;const hasImages = pendingImages.length > 0;@@ -4298,7 +4221,7 @@ const Page: React.FC = () => {inferenceImagePaths.length,);- setInput("");+ composerRef.current?.setText("");let messageStored = false;try {@@ -4378,30 +4301,7 @@ const Page: React.FC = () => {} finally {await cleanupInferenceImages(inferenceImagePaths);}- }, [- input,- chatKey,- currentSessionId,- editingMessage,- isDownloading,- isGenerating,- isModelPreparationActive,- messageState.path,- pendingDocuments,- pendingImages,- showModelGate,- showMiniDialog,- onGenericError,- slicePathUntil,- startGeneration,- writeInferenceImages,- cleanupInferenceImages,- updateBranchSelectionState,- updateRouteSession,- appendMessageToState,- updateSessionAfterMessage,- refreshSessions,- ]);+ };useEffect(() => {return () => {@@ -4426,14 +4326,13 @@ const Page: React.FC = () => {tinyIconProps={tinyIconProps}actionIconProps={actionIconProps}showSessionSearch={showSessionSearch}- sessionSearch={sessionSearch}- setSessionSearch={setSessionSearch}+ sessionSearchRef={sessionSearchRef}handleOpenSessionSearch={handleOpenSessionSearch}handleCloseSessionSearch={handleCloseSessionSearch}handleNewChat={handleNewChat}handleOpenDrawer={handleOpenDrawer}handleCollapseDrawer={handleCollapseDrawer}- groupedSessions={groupedSessions}+ sessions={sessions}currentSessionId={currentSessionId}handleSelectSession={handleSelectSession}requestRenameSession={requestRenameSession}@@ -4620,6 +4519,7 @@ const Page: React.FC = () => {)}<ChatComposer+ ref={composerRef}showModelGate={showModelGate}showDownloadProgress={showDownloadProgress}downloadStatus={downloadStatus}@@ -4637,9 +4537,6 @@ const Page: React.FC = () => {removePendingDocument={removePendingDocument}removePendingImage={removePendingImage}formatBytes={formatBytes}- input={input}- onInputChange={setInput}- inputRef={inputRef}isGenerating={isGenerating}handleSend={handleSend}handleStopGeneration={handleStopGeneration}