Privacy-friendly analytics only with consent. No ads, no cross-site tracking. Read the privacy policy.
Slipstream components are stateless: they render the messages you pass and emit actions through callbacks. Everything else (threads, persistence, optimistic updates) is your store. This guide is the recommended shape for that store.
type Message = {id: string; // stable: used as React key, streaming target, error map keyrole: 'user' | 'assistant' | 'system' | 'tool';content: string; // markdown is fine: Response renders ittimestamp?: Date;metadata?: Record<string, unknown>; // toolCalls, sources, branch info…};
metadata, not in content markup.type Thread = {id: string;title: string;updatedAt: number;messages: Message[];streamingId?: string;errors?: Record<string, string>; // messageId -> retryable failure};// One hook, plain state: swap for Zustand/Jotai/Redux/SWR freely.function useThread(initial: Thread) {const [thread, setThread] = useState(initial);const patch = (id: string, content: string) =>setThread((t) => ({ ...t, messages: t.messages.map((m) => (m.id === id ? { ...m, content } : m)) }));const fail = (id: string, message: string) =>setThread((t) => ({ ...t, streamingId: undefined, errors: { ...t.errors, [id]: message } }));return { thread, setThread, patch, fail };}
// Save on idle, not per token: debounce the whole transcript.useEffect(() => {const t = setTimeout(() => saveThread(thread.id, stripEphemeral(thread)), 800);return () => clearTimeout(t);}, [thread]);// Reload older pages WITHOUT shifting the reader:function prependHistory(thread: Thread, older: Message[]): Thread {return { ...thread, messages: [...older, ...thread.messages] };}// Conversation keeps scroll anchoring stable when the top grows.
Slipstream has no Thread component baked in: a thread list is just data next to the active thread. The pattern used by the templates:
const [threads, setThreads] = useState<Thread[]>([]); // sidebar listconst [activeId, setActiveId] = useState<string>();const active = threads.find((t) => t.id === activeId);// Only the ACTIVE thread streams; background threads stay frozen snapshots.<ThreadList threads={threads} activeId={activeId} onSelect={setActiveId} /><Conversationkey={active!.id} // key resets scroll state per threadmessages={active!.messages}streamingMessageId={active!.streamingId}/>
Regeneration should add a variant, not overwrite. Store variants per message id and hand the active variant to the list. Branch renders the N/M navigator. Full recipe: multi-branch conversations.