From e0bc7b580e08802004585f0bf4af4b02947b672a Mon Sep 17 00:00:00 2001 From: Elijah Date: Mon, 16 Nov 2026 12:22:04 -0700 Subject: [PATCH] Resizable assistant drawer, and the same drawer on share links - The assistant drawer can be resized by dragging its left edge (or with the arrow keys), from 340 to 760 px, always leaving the page 420 px; double-click resets it. The width is remembered in the browser. - Share-link visitors get the same side-drawer assistant as the owner instead of the small popup, with a New chat button; a full-screen sheet on phones. Co-Authored-By: Claude Opus 5.5 --- PROGRESS.md | 6 + docs/AI.md | 8 +- web/src/app/Shell.tsx | 5 +- web/src/features/SharedAssistant.tsx | 200 ++++++++++++++++++--------- web/src/pages/SharedPage.tsx | 7 +- web/src/ui/SideDrawer.tsx | 108 +++++++++++++++ 6 files changed, 263 insertions(+), 71 deletions(-) create mode 100644 web/src/ui/SideDrawer.tsx diff --git a/PROGRESS.md b/PROGRESS.md index fe4c278..b69fe9c 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -198,6 +198,12 @@ shown in bold, the rest in short paragraphs, and a walk-through of the choices b The practice score in the quiz header is now a plain "x/y correct" with no percentage or colour. Tests: `tests/rationale.test.ts`. +Share-link visitors get the same side-drawer assistant as the owner instead of the small popup: +same header, empty state with suggestions, messages and composer, plus "New chat"; a full-screen +sheet on phones. The drawer is resizable for both (drag the edge, 340-760 px, double-click to +reset, remembered per browser). Checked in the browser at 1440, 1100 and 375 px wide, with a live +answer streamed on a share link. + Tests: `tests/revision5.test.ts`. Live check on the rev1 copy with DeepSeek flash: a visitor's 10-card set was written, named ("Heparin, Furosemide, and Dosage Calculations"), saved and listed once with the New tag; cards were single facts with no hints. The rev1 copy's 401 was its diff --git a/docs/AI.md b/docs/AI.md index 29617ed..5592827 100644 --- a/docs/AI.md +++ b/docs/AI.md @@ -276,7 +276,13 @@ Each share link has two switches, both off by default: share), so a link cannot be used to run arbitrary prompts. - **Ask about this material**: a chat that answers from the shared item (or, for a shared class or folder, the item being viewed, the list of materials and passages from its - documents). It cannot read the rest of the library and saves nothing. + documents). It cannot read the rest of the library and saves nothing. It opens in the + same side drawer as the owner's assistant (a full-screen sheet on phones). + +The assistant drawer (`web/src/ui/SideDrawer.tsx`, used for the owner and on share links) can be +resized by dragging its left edge, or with the arrow keys when the edge is focused. It goes from +340 to 760 px and always leaves the page at least 420 px. Double-click the edge to reset it to +440 px. The width is remembered in the browser (`sd.drawer.width`). Neither has library tools; MCP servers join only when allowed on share links. Both use the owner's models and keys and show only when an AI model is configured. diff --git a/web/src/app/Shell.tsx b/web/src/app/Shell.tsx index 1a6b4ac..875198a 100644 --- a/web/src/app/Shell.tsx +++ b/web/src/app/Shell.tsx @@ -12,6 +12,7 @@ import { cx, useDebounced, useHotkeys, useIsDesktop, useTheme, type ThemeChoice import { Brand } from '@/pages/Auth'; import { Button, ClassDot, Dialog, Field, IconButton, Input, Menu, MenuItem, MenuLabel, MenuSeparator, Spinner, Textarea, Tooltip, Select } from '@/ui'; import { SidebarDrafts, useDraftNotifications } from '@/features/DraftsTray'; +import { SideDrawer } from '@/ui/SideDrawer'; const AssistantPanel = lazy(() => import('@/features/AssistantPanel')); @@ -589,7 +590,7 @@ export function Shell() { {showDrawer && ( - + )} {!showDrawer && !onAssistantPage && !immersive && isDesktop && ( diff --git a/web/src/features/SharedAssistant.tsx b/web/src/features/SharedAssistant.tsx index fa61e20..ab5fa53 100644 --- a/web/src/features/SharedAssistant.tsx +++ b/web/src/features/SharedAssistant.tsx @@ -1,10 +1,11 @@ -import { CornerDownLeft, Sparkles, Square, X } from 'lucide-react'; +import { ArrowUp, CircleAlert, Plus, Sparkles, Square, X } from 'lucide-react'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { errorMessage, streamEvents } from '@/lib/api'; import type { ToolActivity } from '@/lib/types'; -import { cx } from '@/lib/util'; +import { cx, useLocalStorage } from '@/lib/util'; import { GenUiContext, Markdown } from '@/ui/Markdown'; -import { Button, Callout, IconButton, Thinking, Tooltip } from '@/ui'; +import { SideDrawer } from '@/ui/SideDrawer'; +import { Callout, IconButton, Thinking, Tooltip } from '@/ui'; import { ToolSteps } from './ToolSteps'; type Event = { type: 'text'; delta: string } | { type: 'tool'; tool: ToolActivity } | { type: 'error'; message: string } | { type: 'done' }; @@ -14,29 +15,41 @@ interface Turn { tools?: ToolActivity[]; } +const SUGGESTIONS = ['Summarize the key points', 'Explain the hardest idea here simply', 'Quiz me with three quick questions']; + /** - * The visitor-facing assistant on a share link (when the owner allows it). It answers from the - * shared material only; the conversation lives in this tab and is never saved on the server. - * `hidden` tucks it away (during a quiz or flashcard session) without losing the conversation. + * The visitor-facing assistant on a share link (when the owner allows it), in the same + * resizable side drawer the owner's assistant uses. It answers from the shared material only; + * the conversation lives in this tab and is never saved on the server. `hidden` tucks it away + * (during a quiz or flashcard session) without losing the conversation. */ export function SharedAssistant({ token, title, item, hidden }: { token: string; title: string; item?: { kind: 'quiz' | 'deck' | 'note' | 'document'; id: string }; hidden?: boolean }) { - const [open, setOpen] = useState(false); + const [open, setOpen] = useLocalStorage('sd.pub.assistantOpen', false); const [turns, setTurns] = useState([]); const [input, setInput] = useState(''); const [busy, setBusy] = useState(false); const [error, setError] = useState(''); const abort = useRef(null); const list = useRef(null); + const inputRef = useRef(null); + const stick = useRef(true); useEffect(() => () => abort.current?.abort(), []); useEffect(() => { const el = list.current; - if (el) el.scrollTop = el.scrollHeight; + if (el && stick.current) el.scrollTop = el.scrollHeight; }, [turns, open]); + useEffect(() => { + if (open && !hidden) inputRef.current?.focus(); + }, [open, hidden]); const send = useCallback( - async (text: string) => { - if (busy) return; + async (raw: string) => { + const text = raw.trim().slice(0, 4000); + if (busy || !text) return; + setInput(''); + if (inputRef.current) inputRef.current.style.height = 'auto'; + stick.current = true; // The server accepts the last 16 turns; older ones are dropped from the request. const history: Turn[] = [...turns, { role: 'user' as const, text }].slice(-15); setTurns([...turns, { role: 'user', text }, { role: 'assistant', text: '', tools: [] }]); @@ -66,27 +79,35 @@ export function SharedAssistant({ token, title, item, hidden }: { token: string; }, [busy, turns, token, item], ); - const genUi = useMemo(() => ({ streaming: busy, onSend: (text: string) => void send(text.slice(0, 4000)) }), [busy, send]); + const stop = () => abort.current?.abort(); + const newChat = () => { + stop(); + setTurns([]); + setError(''); + setInput(''); + inputRef.current?.focus(); + }; + const genUi = useMemo(() => ({ streaming: busy, onSend: (text: string) => void send(text) }), [busy, send]); if (hidden) return null; if (!open) { // The same round sparkle button the owner sees in the app. return ( - + ); } return ( -
-
+ +
@@ -94,59 +115,108 @@ export function SharedAssistant({ token, title, item, hidden }: { token: string;
Assistant
{title}
- setOpen(false)}> + + + + setOpen(false)}>
-
- {turns.length === 0 &&

Ask a question about this material: what something means, why an answer is right, or for a quick recap.

} - - {turns.map((t, i) => - t.role === 'user' ? ( -
-
{t.text}
-
- ) : ( -
- {t.tools && t.tools.length > 0 && } - {t.text ? ( - {t.text} - ) : busy && i === turns.length - 1 && !t.tools?.some((x) => x.status === 'running') ? ( - - ) : null} -
- ), - )} -
- {error && ( - - {error} - + +
{ + const el = e.currentTarget; + stick.current = el.scrollHeight - el.scrollTop - el.clientHeight < 80; + }} + className="min-h-0 flex-1 overflow-y-auto px-4 py-5" + aria-live="polite" + > + {turns.length === 0 ? ( +
+

Ask about this material

+

What something means, why an answer is right, or a quick recap. Answers come from what was shared here.

+
+ {SUGGESTIONS.map((s) => ( + + ))} +
+
+ ) : ( + +
+ {turns.map((t, i) => + t.role === 'user' ? ( +
+
{t.text}
+
+ ) : ( +
+ {t.tools && t.tools.length > 0 && } + {t.text ? ( + {t.text} + ) : busy && i === turns.length - 1 && !t.tools?.some((x) => x.status === 'running') ? ( + + ) : null} +
+ ), + )} + {error && ( + } className="py-2.5"> + {error} + + )} +
+
)}
-
{ - e.preventDefault(); - if (busy) return abort.current?.abort(); - const text = input.trim(); - if (!text) return; - setInput(''); - void send(text.slice(0, 4000)); - }} - > - setInput(e.target.value)} - placeholder="Ask a question…" - aria-label="Your question" - className={cx('h-10 min-w-0 flex-1 rounded-[10px] border border-line-strong bg-paper px-3 text-sm outline-none focus:border-accent')} - /> - -
-

AI can be wrong. Nothing you type here is saved.

-
+ +
+
+
{ + e.preventDefault(); + if (busy) stop(); + else void send(input); + }} + > +
+