import type { ComponentType } from "preact"; import { useEffect, useLayoutEffect, useRef, useState } from "preact/hooks"; import { Bot, LogOut, Menu, MessageSquare, Plus, RefreshCw, Search, SendHorizontal, Settings2, Star, X } from "lucide-preact"; import { AssistantMessageFooter } from "@/components/chat/assistant-message-footer"; import { MarkdownContent } from "@/components/markdown/markdown-content"; import { useSessionAuth } from "@/hooks/use-session-auth"; import { useLiteWorkspace } from "@/hooks/use-lite-workspace"; import { useWorkspaceSearch } from "@/hooks/use-workspace-search"; import { getMessageAttachments, type Message, type SearchDetail, type WorkspaceItem } from "@/lib/api"; import { getProviderLabel } from "@/lib/message-generation"; import { buildUiModeUrl } from "@/lib/ui-mode"; import "./lite.css"; const PAGE_SIZE = 30; function LiteAgentPanel() { const [Agent, setAgent] = useState(null); const [failed, setFailed] = useState(false); useEffect(() => { let active = true; setFailed(false); void import("@/components/lite/lite-agent").then(module => { if (active) setAgent(() => module.LiteAgent); }, () => { if (active) setFailed(true); }); return () => { active = false; }; }, []); if (failed) return

Agent could not load. Check your connection and reload this page.

; return Agent ? :

Opening Agent…

; } function itemTitle(item: WorkspaceItem) { return item.title?.trim() || (item.type === "search" ? item.query : null) || (item.type === "chat" ? "New chat" : "New search"); } function formatDate(value: string) { const date = new Date(value); return Number.isNaN(date.getTime()) ? "" : date.toLocaleDateString(undefined, { month: "short", day: "numeric" }); } function webLink(value: string | undefined) { return value && /^https?:\/\//i.test(value) ? value : undefined; } function LiteMessage({ message }: { message: Message }) { const attachments = getMessageAttachments(message.metadata); if (message.role === "system") return null; if (message.role === "tool") return (
{message.name || "Tool activity"}
{message.content}
); return (
{attachments.length > 0 &&
    {attachments.map(file =>
  • {file.filename}
  • )}
} {message.role === "assistant" && }
); } function LiteTranscript({ messages }: { messages: Message[] }) { const [count, setCount] = useState(PAGE_SIZE); const visible = messages.filter(message => message.role !== "system"); return (
{visible.length > count && } {visible.slice(-count).map(message => )}
); } function LiteSearch({ search }: { search: SearchDetail }) { return (
{search.error &&

{search.error}

} {search.answerError &&

{search.answerError}

} {search.answerText &&

Answer

} {!!search.answerCitations?.length &&
Answer sources
}
    {search.results.map(result =>
  1. {result.title || result.url}

    {result.url}

    {(result.highlights?.length || result.text) &&

    {(result.highlights?.join(" ") || result.text || "").slice(0, 600)}

    }
  2. )}
{!search.results.length && !search.answerText && !search.error &&

No results saved for this search.

}
); } export default function LiteRoutePage() { const auth = useSessionAuth({ backgroundSession: false }); const workspace = useLiteWorkspace(auth.isAuthenticated, auth.handleAuthFailure); const [sidebarOpen, setSidebarOpen] = useState(false); const [historyQuery, setHistoryQuery] = useState(""); const [historyCount, setHistoryCount] = useState(PAGE_SIZE); const [draft, setDraft] = useState(() => new URLSearchParams(window.location.search).get("q") || ""); const [submitted, setSubmitted] = useState(""); const submitLock = useRef(false); const transcriptRef = useRef(null); const followTranscript = useRef(true); const historySearch = useWorkspaceSearch(historyQuery, auth.isAuthenticated, workspace.items.length); const historyItems = historyQuery.trim() ? historySearch.items : workspace.items; const isAgent = workspace.selection?.kind === "agent"; const isSearch = workspace.selection?.kind === "search" || (!workspace.selection && workspace.draftKind === "search"); const title = isAgent ? "Sybil Agent" : isSearch ? workspace.search?.title || "New search" : workspace.chat?.title || "New chat"; const selectedKey = workspace.selection ? `${workspace.selection.kind}:${workspace.selection.id}` : workspace.draftKind; const priorSelection = useRef(selectedKey); const lastMessageId = workspace.chat?.messages[workspace.chat.messages.length - 1]?.id; useEffect(() => { document.title = `${title} · Sybil Lite`; }, [title]); useLayoutEffect(() => { if (priorSelection.current !== selectedKey && (!submitLock.current || !workspace.isSending)) { setDraft(""); setSubmitted(""); } priorSelection.current = selectedKey; }, [selectedKey, workspace.isSending]); useEffect(() => { setHistoryCount(PAGE_SIZE); }, [historyQuery]); useLayoutEffect(() => { followTranscript.current = true; }, [selectedKey]); useLayoutEffect(() => { const transcript = transcriptRef.current; if (transcript && followTranscript.current) transcript.scrollTop = isSearch ? 0 : transcript.scrollHeight; }, [selectedKey, lastMessageId, submitted, workspace.isBusy]); useEffect(() => { if (!sidebarOpen) return; const close = (event: KeyboardEvent) => { if (event.key === "Escape") setSidebarOpen(false); }; window.addEventListener("keydown", close); return () => window.removeEventListener("keydown", close); }, [sidebarOpen]); const send = async (event: Event) => { event.preventDefault(); const text = draft.trim(); if (!text || workspace.isBusy || submitLock.current) return; submitLock.current = true; followTranscript.current = true; setSubmitted(text); try { if (await workspace.send(text)) setDraft(""); } finally { setSubmitted(""); submitLock.current = false; } }; const fullLink = Full interface; const brand = SYBIL; if (auth.isCheckingSession) return
{brand}

Checking session…

; if (!auth.isAuthenticated) return (
{brand}

Sign in to Sybil

Enter your admin token.

{ event.preventDefault(); if (auth.authTokenInput.trim()) void auth.handleSignIn(auth.authTokenInput.trim()); }}> auth.setAuthTokenInput(event.currentTarget.value)} disabled={auth.isSigningIn} />
{auth.authError &&

{auth.authError}

} {fullLink}
); return (
Skip to conversation {sidebarOpen &&

History

{historySearch.error && historyQuery &&

{historySearch.error}

} {historySearch.isLoading &&

Searching history…

}
    {historyItems.slice(0, historyCount).map(item =>
  • )}
{historyItems.length > historyCount && } {!historyItems.length && !workspace.isLoading && !historySearch.isLoading &&

{historyQuery ? "No matches." : "No chats or searches."}

} {historySearch.hasMore &&

Refine your search to see more matches.

}
{fullLink}

{title}

{!isSearch && !isAgent &&

{getProviderLabel(workspace.provider)} · {workspace.model || "No model"}

}
{!isAgent &&
{!isSearch &&
{workspace.modelOptions.map(model =>
}
}
{isAgent ? : <>
{ const element = event.currentTarget; followTranscript.current = element.scrollHeight - element.scrollTop - element.clientHeight < 96; }}> {workspace.isLoading &&

Loading…

} {workspace.chat && } {workspace.search && } {submitted &&

{submitted}

} {workspace.isBusy &&

{isSearch ? "Searching…" : "Generating…"}{!workspace.isSending && " Refresh to reconnect."}

}
{workspace.error &&

{workspace.error}

}