defuss-shadcn / Application / Scaffolds / scaffold-ai-chat
AI Chat
An Open WebUI-style chat for language models - "Lumen". Pick a suggestion or type a question: the answer streams in as Markdown, with its thinking folded above it. Attach pictures, audio, video and documents - with +, by pasting, by dropping them on the conversation - or record a voice message. Copy, edit, regenerate and rate answers, keep chats by day in the sidebar, set the system prompt and sampling in Controls, or point it at any OpenAI-compatible API. Adapted from the defuss ai-chat example. Part of the Application Scaffolds.
On this page (2)
§AI Chat
The whole chat in one source. Chats are routes (#/c/...) of defuss-dom-router; Settings › Language translates the chrome with defuss-i18n; the sidebars are the Sidebar component, the transcript the Session, every message a Message with a Bubble. Answers come from a local demo model, or from any OpenAI-compatible API set in Controls › Connection.
§How it works
A page, not a component: it composes the library and keeps its own glue small. It adapts the ai-chat example of defuss - conversations, streaming, message actions, the settings sidebar and the sign-in - to the shipped components, in the look of Open WebUI.
- Layout - the Sidebar twice in one
.sidebar-layout: the chats on the start side, Controls on the end side (data-side="right"). Their state (default/collapsed) opens and closes them; below 52rem of width they lie over the conversation and a scrim closes them. - Chats - grouped into Pinned, Today, Yesterday, Previous 7 days and Older; the search filters titles and messages. Each row has a Dropdown Menu to pin, rename in place or delete (an Alert Dialog asks first).
- Conversation - the Session: every question is a
data-anchorturn that settles near the top, the answer streams under thestreamingstate and the window follows it while you are at the end. Turns are Messages with Bubbles; "Thinking..." and the folded reasoning are Markers with the shimmer. - Answers - Markdown through marked (pinned), cleaned before it enters the page; tables become the Table, code blocks a Code mockup with a copy button. Hover an answer to copy, read it aloud (
speechSynthesis), show its tokens per second, rate it or regenerate it; hover a question to edit it (what followed is dropped and asked again) or delete it. - Models - four demo models answer in the page (Markdown with code, a table, a plan, prose; Echo repeats), at their own pace. Controls › Connection switches to any OpenAI-compatible API:
POST {base}/chat/completionswithstream: true, the Server-Sent Events read as they arrive, reasoning fromreasoning_contentor<think>tags; the stop button aborts the request (AbortController). - Controls - the system prompt and the sampling parameters of the example (temperature, top P, top K, repetition and presence penalty, max tokens, thinking) as Sliders with
<output>, a number Input and a Switch; the form is the settings store. - Composer - the Textarea group grows with the text; ↵ sends, ⇧ ↵ breaks the line (Settings can swap it); the Toggle turns thinking on.
- Attachments - any file, from the + button, a paste or a drop on the conversation (the Session's
data-dropand itssession-dropevent), shows as a File Input chip with a thumbnail and its size or length. Sent, a picture is a media Bubble (data-media) that opens in a Dialog, audio and video play in the Audio and Video players, documents are Message attachment cards that download. The microphone button records a voice message withMediaRecorder. The demo model measures what it gets (size, length, the average colour of a picture, the lines of a text); an API gets pictures asimage_urlparts, text files as text. Pictures are kept with the chat (scaled to 1280 px, WebP); audio, video and other files live for the visit and say so after a reload. - Chat Components - an answer can ask with a card: a Component Schema document in a
ui::component-schemafence becomes Chat Components (amounts, choices, dates, a plan to confirm, a questionnaire, quick replies). Answering it stores the answer on the message - the card renders answered from then on - and sends your turn: the answer's sentence, and for an API the JSON too. The demo model answers card-shaped questions with one (try "book a table" or "deploy release 2.4"); in API mode the system prompt describes the fence and the request offers theshow_componentstool - a tool call is stored as the same fence, so the history replays on any server. Controls › Connection turns both off. - Examples - the sidebar's first group holds conversations to try: cards answered and still open, and two Chat Scripts - a support bot and a pizza order that run without a language model. A script runs through
chatScript.create(script, hooks), so its turns land in the chat's store like any other and the run continues after a reload. - State - chats and settings are
df$.store.persistedstores: kept in the browser on the full-screen page, in memory inside the docs card. - Routing - defuss-dom-router in hash mode:
#/a new chat,#/c/:ida chat,#/auththe sign-in (Sign out leads there; the demo account is on the card). See Client-side Routing. - Translation - defuss-i18n: Settings › Language switches the chrome between English and German; what the script writes (message actions, chat menus, dialogs) follows from its own table. See Translation.
- Full screen - app-ai-chat.html is generated from this page's example at build time and loads only its own bundle.
Comments, ideas or improvements? Edit this page's source on GitHub