aiellie

Search

Find a component, template or page

GitHub
Components

Quick Chat

A compact conversation panel that floats at the bottom corner of the current page, keeping a quick question separate from the main thread.

Open full screen
fig. 01 · open it full screen from the corner

Installation

npx shadcn@latest add "@aiellie/quick-chat"

shadcn needs the @aiellie registry in components.json first. npx aiellie add quick-chat adds it on its first run, then installs the same way.

Quick chat is a small conversation that floats in the corner of a page, for a question that shouldn't pull someone out of what they're doing. It brings its own thread, which follows the reply as it streams, and a compact composer; hand it the messages and what to do on send. It isn't modal: the page behind it stays usable, Escape closes it, and focus goes back where it came from.

Getting started

  1. Open it from a button

    open and onOpenChange are yours. It stays mounted while closed, so it can scale away rather than vanish, and it's inert while it's gone.

    components/ask.tsx
    "use client"
    
    import * as React from "react"
    
    import {
      QuickChat,
      type QuickChatMessage,
    } from "@/components/aiellie/quick-chat"
    import { Button } from "@/components/ui/button"
    
    export function Ask() {
      const [open, setOpen] = React.useState(false)
      const [messages, setMessages] = React.useState<QuickChatMessage[]>([])
    
      return (
        <>
          <Button onClick={() => setOpen(true)}>Ask</Button>
          <QuickChat
            open={open}
            onOpenChange={setOpen}
            messages={messages}
            onSubmit={(text) =>
              setMessages((all) => [
                ...all,
                { id: crypto.randomUUID(), from: "user", content: text },
              ])
            }
          />
        </>
      )
    }
  2. Stream replies with the AI SDK

    Map useChat's messages onto QuickChatMessage. Mark the last reply streaming while the status says so and the panel writes it out word by word and shows the thinking indicator until the first word.

    components/ask.tsx
    const { messages, sendMessage, status, stop, setMessages } = useChat()
    const busy = status === "submitted" || status === "streaming"
    
    <QuickChat
      open={open}
      onOpenChange={setOpen}
      onNewChat={() => setMessages([])}
      status={status}
      onStop={stop}
      onSubmit={(text) => sendMessage({ text })}
      messages={messages.map((message, index) => ({
        id: message.id,
        from: message.role === "user" ? "user" : "assistant",
        content: message.parts
          .map((part) => (part.type === "text" ? part.text : ""))
          .join(""),
        streaming: busy && index === messages.length - 1,
      }))}
    />

    While a reply is submitted, add an empty assistant message marked streaming so the indicator has somewhere to show.

Anatomy

<section data-slot="quick-chat" data-state="open" role="dialog" aria-modal="false">
  <header data-slot="quick-chat-header">
    <h2 /> {/* title */}
    <button /> {/* new chat, with onNewChat */}
    <button /> {/* close */}
  </header>
  <div data-slot="thread">
    {/* one Message per entry, with its Reasoning, attachments and StreamText */}
  </div>
  <div data-slot="quick-chat-footer">
    <form data-slot="composer" /> {/* or your own, through `composer` */}
  </div>
</section>

It's built from Thread, Message, Reasoning, StreamText, ThinkingIndicator and Composer, which install with it. The panel is fixed to the end corner at 288 by 320px, 384px square from sm up, and it's a floating layer, so it's glass with a shadow. Each user message is a scroll anchor, so a new question scrolls to the top and the reply writes in below it.

Examples

Answer in place

Send something and the reply lands in the panel. The pencil starts over without closing it.

Show what the reply is doing

A message carries the model's reasoning and how long it took in reasoningDuration, which show as a Reasoning row above the reply. activity names what it's doing while no words come, like a web search, and startedAt is when it was asked, which the thinking count starts from.

{
  id: "reply-1",
  from: "assistant",
  content: "",
  streaming: true,
  activity: "Searching the web",
  reasoning: "They want this week's release notes, so…",
  startedAt: Date.now(),
}

Bring your own composer

composer swaps the compact composer for anything else, like the chat block's composer with its model selector, while keeping it in the panel's footer. Hand it its own onSubmit and status, since the panel's go to its own composer only.

<QuickChat
  open={open}
  onOpenChange={setOpen}
  messages={messages}
  composer={<ChatComposer onSend={send} status={status} {...rest} />}
/>

API reference

QuickChat

PropTypeDefaultDescription
openbooleanrequiredWhether the panel shows.
onOpenChange(open: boolean) => voidrequiredCalled by the close button and by Escape.
messagesQuickChatMessage[]requiredThe conversation, oldest first.
onSubmit(value: string) => voidCalled with the trimmed text. Without it the composer is disabled.
onStop() => voidCalled by the stop button while status is busy.
status"ready" | "submitted" | "streaming" | "error""ready"The AI SDK's useChat status.
onNewChat() => voidShows a new chat button that calls it and puts focus back in the composer.
titleReactNode"Quick chat"The panel's heading.
placeholderstring"Ask anything"The compact composer's placeholder.
emptyReactNode"Ask something without leaving this page."What shows while there are no messages.
composerReactNodeReplaces the compact composer while keeping it inside the panel's footer.
autoFocusbooleantruePuts focus in the composer when the panel opens.
classNamestringMerged onto the panel.

All other section props are forwarded.

QuickChatMessage

FieldTypeDefaultDescription
idstringrequiredKeys the message in the thread.
from"user" | "assistant"requiredWho sent it.
contentstringrequiredIts text, so far.
attachmentsReactNodeShown above the text, like an Attachments row.
streamingbooleanWhether the reply is still being written.
reasoningstringWhat the model thought before replying, for a model that shows it.
reasoningDurationnumberSeconds from asking to the reply's first word.
startedAtDate | numberWhen the reply was asked for, which the thinking count starts from.
activitystringWhat a streaming reply is doing while no words come.