Shopping Assistant Online
Powered by your own transport — fully decoupled

Drag the right / bottom edge or corner to resize, or use the button above to expand the panel with an animated scale-up. 420 × 600

Empty state — the empty snippet fills the blank transcript

Shopping Assistant

No messages yet.

Ask about an order, a product, or returns — or pick a suggestion below.

Full agent turn — thinking trace, tool calls, and a work plan land in the transcript

Composed entirely from existing pieces, none of it built into Chat: ThinkingIndicator's own busy machine drives the search trace and settles into a collapsed row on its own timer, ToolCallLog records the tools that produced the reply, and a TaskList work plan appears once the turn is done. Follow-up ChatSuggestions then take their real spot — above the composer, not floating alone.

Can you put together a plan to fix our winter waffle-cone shortage?

Tool-status theming — backward compatible with the deprecated ChatToolStatus

The built-in tool-status row is ThinkingIndicator's chip variant internally now, not the deprecated ChatToolStatus component — but every --chat-tool-status-* variable still themes it (mapped onto the chip's own --thinking-indicator-chip-* variables), so an existing consumer's overrides keep working unchanged. The instance below overrides --chat-tool-status-background, --chat-tool-status-color, and --chat-tool-status-border the same way a pre-existing consumer already would; if the mapping works, the pill picks them up.

Backward-compat check

Scroll policy controls — passed through Chat to the message list

Scroll policy transcript message 1.
Scroll policy transcript message 2.
Scroll policy transcript message 3.
Scroll policy transcript message 4.
Scroll policy transcript message 5.
Scroll policy transcript message 6.
Scroll policy transcript message 7.
Scroll policy transcript message 8.
Scroll policy transcript message 9.
Scroll policy transcript message 10.
Scroll policy transcript message 11.
Scroll policy transcript message 12.
Scroll policy transcript message 13.
Scroll policy transcript message 14.
Scroll policy transcript message 15.
Scroll policy transcript message 16.
Scroll policy transcript message 17.
Scroll policy transcript message 18.
Scroll policy transcript message 19.
Scroll policy transcript message 20.
Scroll policy transcript message 21.
Scroll policy transcript message 22.
Scroll policy transcript message 23.
Scroll policy transcript message 24.
Scroll policy transcript message 25.
Scroll policy transcript message 26.
Scroll policy transcript message 27.
Scroll policy transcript message 28.
Scroll policy transcript message 29.
Scroll policy transcript message 30.
Scroll policy transcript message 31.
Scroll policy transcript message 32.
Scroll policy transcript message 33.
Scroll policy transcript message 34.
Scroll policy transcript message 35.
Scroll policy transcript message 36.
Scroll policy transcript message 37.
Scroll policy transcript message 38.
Scroll policy transcript message 39.
Scroll policy transcript message 40.
Scroll policy transcript message 41.
Scroll policy transcript message 42.
Scroll policy transcript message 43.
Scroll policy transcript message 44.
Scroll policy transcript message 45.
Scroll policy transcript message 46.
Scroll policy transcript message 47.
Scroll policy transcript message 48.
Scroll policy transcript message 49.
Scroll policy transcript message 50.
Scroll policy transcript message 51.
Scroll policy transcript message 52.
Scroll policy transcript message 53.
Scroll policy transcript message 54.
Scroll policy transcript message 55.
Scroll policy transcript message 56.
Scroll policy transcript message 57.
Scroll policy transcript message 58.
Scroll policy transcript message 59.
Scroll policy transcript message 60.
not-scrollable
Scroll policy transcript message 1.
Scroll policy transcript message 2.
Scroll policy transcript message 3.
Scroll policy transcript message 4.
Scroll policy transcript message 5.
Scroll policy transcript message 6.
Scroll policy transcript message 7.
Scroll policy transcript message 8.
Scroll policy transcript message 9.
Scroll policy transcript message 10.
Scroll policy transcript message 11.
Scroll policy transcript message 12.
Scroll policy transcript message 13.
Scroll policy transcript message 14.
Scroll policy transcript message 15.
Scroll policy transcript message 16.
Scroll policy transcript message 17.
Scroll policy transcript message 18.
Scroll policy transcript message 19.
Scroll policy transcript message 20.
Scroll policy transcript message 21.
Scroll policy transcript message 22.
Scroll policy transcript message 23.
Scroll policy transcript message 24.
Scroll policy transcript message 25.
Scroll policy transcript message 26.
Scroll policy transcript message 27.
Scroll policy transcript message 28.
Scroll policy transcript message 29.
Scroll policy transcript message 30.
Scroll policy transcript message 31.
Scroll policy transcript message 32.
Scroll policy transcript message 33.
Scroll policy transcript message 34.
Scroll policy transcript message 35.
Scroll policy transcript message 36.
Scroll policy transcript message 37.
Scroll policy transcript message 38.
Scroll policy transcript message 39.
Scroll policy transcript message 40.
Scroll policy transcript message 41.
Scroll policy transcript message 42.
Scroll policy transcript message 43.
Scroll policy transcript message 44.
Scroll policy transcript message 45.
Scroll policy transcript message 46.
Scroll policy transcript message 47.
Scroll policy transcript message 48.
Scroll policy transcript message 49.
Scroll policy transcript message 50.
Scroll policy transcript message 51.
Scroll policy transcript message 52.
Scroll policy transcript message 53.
Scroll policy transcript message 54.
Scroll policy transcript message 55.
Scroll policy transcript message 56.
Scroll policy transcript message 57.
Scroll policy transcript message 58.
Scroll policy transcript message 59.
Scroll policy transcript message 60.

Documentation

A full chat surface that composes ChatHeader, ChatMessageList, ChatSuggestions, ThinkingIndicator (as its chip variant), and ChatComposer into one drop-in component. It is fully controlled — you pass messages and handle onsend; the component owns no transport, so it works with any backend. For a batteries-included experience, pair it with the decoupled ChatController (below), which manages message state, streaming, and an optional typewriter reveal while delegating the actual network call to a pluggable transport.

Markdown is bundled: set a message's markdown field and it renders in the bubble through the library's sanitized-by-construction pipeline (see MarkdownText) — no external marked + DOMPurify step needed. Pre-sanitized HTML on the html field still works for content you have already rendered and trust.

Usage (controlled)

<script>
  import { Chat } from '@juspay/svelte-ui-components';

  let messages = $state([]);
  let value = $state('');

  function onsend(text) {
    messages.push({ id: crypto.randomUUID(), role: 'sender', content: text });
    // ...call your API, append a responder message, stream into it...
  }
</script>

<Chat {messages} bind:value title="Assistant" placeholder="Ask anything…" {onsend} />

Usage (with the decoupled controller)

ChatController is a runes-based state holder. Its single dependency on your backend is the transport function — adapt SSE, WebSocket, or polling to the ChatTransport shape and the controller/UI never need to know the difference.

<script>
  import { Chat, ChatController } from '@juspay/svelte-ui-components';

  const chat = new ChatController({
    typewriter: true,
    transport: async ({ message, history, sessionId, signal }, handlers) => {
      const res = await fetch('/api/chat', {
        method: 'POST',
        body: JSON.stringify({ message }),
        signal
      });
      // parse your stream and call the handlers:
      handlers.onToolStatus?.({ label: 'Searching…' });
      handlers.onText('Hello ');
      handlers.onText('world');
      handlers.onDone?.();
    }
  });

  let value = $state('');
</script>

<Chat
  messages={chat.messages}
  bind:value
  toolStatus={chat.toolStatus}
  disabled={chat.isStreaming}
  suggestions={['Track my order', 'Return policy?']}
  onsend={(text) => chat.send(text)}
/>

ChatController

Member Type Description
messages ChatMessageData[] Reactive message list.
isStreaming boolean True while a response is in flight.
toolStatus ChatToolStatus | null Current tool/typing status.
send(text) Promise<void> Append the sender's message and stream the reply.
retry() Promise<void> Drop the last reply and re-run the most recent sender message.
stop() void Abort the in-flight response.
reset() void Clear all messages and state.

ChatControllerOptions: transport (required ChatTransport), initialMessages?, typewriter? (reveal text char-by-char), generateId? (defaults to crypto.randomUUID()).

typewriter and the standalone TypewriterText component are two ways to do one job — use exactly one. The controller's reveal drains buffered chunks into msg.content itself, so it needs no extra component and is what the example above uses. TypewriterText is the standalone alternative, worth reaching for when you want pacing control the option does not expose (variableDelay, resolveDelay, renderCharacter, onprogress).

Combining them is the one thing to avoid: with typewriter: true and a messageBody snippet rendering <TypewriterText text={msg.content} … />, msg.content is already growing character by character, and TypewriterText re-types each increment on its own cadence — a compounding double-reveal. Set typewriter: false (or leave it unset) whenever a snippet owns the reveal. Both honour prefers-reduced-motion: reduce and disclose text without animating it.

ChatTransport: (input: { message, history, sessionId, signal }, handlers: ChatStreamHandlers) => Promise<void>. Handlers: onText (required), onToolStatus?, onAttachment?, onError?, onDone?. The controller threads sessions for you: whatever a transport reports via onDone({ sessionId }) is passed back on the next request's input.sessionId.

Roles. Messages use the two-party primitive role — sender / responder (see ChatMessage). The controller emits those, and partyOf(role) resolves any role (including the user/assistant/system extensions) to its party. Map the primitive to your provider's roles inside the transport, where the API-specific terms belong: history.map((m) => ({ role: partyOf(m.role) === 'sender' ? 'user' : 'assistant', content: m.content })).

Your own UI inside a message

Two snippets, and the difference matters. message replaces the whole message — you own the bubble, alignment, streaming indicator, and you lose the built-in copy / retry / feedback wiring. messageAttachments renders below the bubble and keeps all of that, so reach for it first.

It receives the whole ChatMessageData, so render on whatever field you like — a custom field of your own, or attachments, which ChatController fills from a transport's handlers.onAttachment(...):

<Chat {messages} bind:value allowCopy onretry={() => chat.retry()} {onsend}>
  {#snippet messageAttachments(msg)}
    {#each msg.attachments ?? [] as item, index (index)}
      <YourComponent data={item} />
    {/each}
  {/snippet}
</Chat>

The snippet is invoked for every message, so branch inside it to target specific ones. Rendering nothing costs no layout — the container collapses when empty.

Layout — fullscreen & floating

Chat is position- and size-agnostic: its root fills its container (--chat-height / --chat-width default to 100%), with the message list on flex: 1 and the composer pinned to the bottom. The only requirement is a bounded-height parent — the flexing list needs something to fill. Positioning (fixed, floating, modal) is the consumer's job; the component never assumes a layout context.

Fullscreen

Give it a viewport-sized box (use 100dvh so the mobile URL bar doesn't clip the composer):

<div style="height: 100dvh; width: 100vw">
  <Chat {messages} bind:value title="Assistant" {onsend} />
</div>

Or set the variables directly: --chat-height: 100dvh; --chat-width: 100vw. On very wide screens, constrain the reading column (bubbles cap at --chat-message-max-width, default 82%) with e.g. --chat-width: min(100%, 820px) or a centered wrapper.

Floating widget

The component ships no launcher button or fixed positioning — compose those, and wire the header's onclose to the close/minimize action:

<script>
  let open = $state(false);
</script>

{#if open}
  <div class="chat-panel">
    <Chat {messages} bind:value title="Assistant" {onsend} onclose={() => (open = false)} />
  </div>
{/if}

<button class="chat-launcher" onclick={() => (open = !open)} aria-label="Chat">💬</button>

<style>
  .chat-panel {
    position: fixed;
    right: 24px;
    bottom: 88px;
    width: 380px;
    height: 600px;
    max-height: calc(100dvh - 120px);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.22);
    z-index: 1000;
  }
  .chat-launcher {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1000;
    width: 56px;
    height: 56px;
    border-radius: 50%;
  }
</style>

The fixed-height .chat-panel gives Chat its bounds; add a slide/scale transition on it for the open animation.

Props

Prop Type Required Default Description
messages ChatMessageData[] Yes - The conversation to render.
value string No '' Bindable. The composer draft text.
title string No '' Header title. Header is hidden when there is no title/subtitle/image/close/avatar.
subtitle string No '' Header subtitle.
image string No - Optional header brand image URL (rendered via Img). Off by default.
imageAlt string No '' Alt text for the header image.
placeholder string No '' Composer placeholder.
disabled boolean No false Disable the composer entirely.
streaming boolean No false A reply is streaming — the send button becomes a stop button.
recording boolean No false Visual active state for the composer voice button.
autoscroll boolean No true Auto-scroll to the latest message (only when already near the bottom).
scrollPolicy 'near-bottom' | 'pin-sender-turn' No 'near-bottom' Follow policy for new messages. pin-sender-turn pins each new sender message to the top so its reply streams beneath it.
pinHold boolean No false With pin-sender-turn, retain the reserved reply headroom while the current turn is busy; set false when it finishes.
hideScrollbar boolean No false Hide the message list's scrollbar without losing scrolling (web component: hide-scrollbar).
jump boolean No true Render the built-in jump-to-latest button. Set false when providing your own affordance.
jumpLabel string No 'Jump to latest' Accessible label for the built-in jump-to-latest button.
jumpIcon Snippet No - Custom icon for the built-in jump-to-latest button.
toolStatus ChatToolStatus | null No null Tool/typing status shown above the composer.
suggestions ChatSuggestion[] No [] Prompt chips shown when the conversation is empty.
attachments File[] No [] Bindable. Pending composer attachments.
accept string No '' Accepted file types for the attach button.
multiple boolean No false Allow multiple files per attach pick.
allowCopy boolean No false Show copy buttons on assistant messages.
closeLabel string No 'Close' Aria-label for the header close button.
showClose boolean No - Force the close button on/off (defaults to showing when onclose is set).
headerAvatar Snippet No - Brand/avatar mark in the header (takes precedence over image).
headerActions Snippet No - Extra inline header actions.
headerContent Snippet No - Extra content as a full-width second row in the header (toolbar, status…).
message Snippet<[ChatMessageData]> No - Custom per-message rendering. Replaces the default bubble entirely.
messageBody Snippet<[ChatMessageData]> No - Per-message bubble body, threaded to ChatMessageList.
messageAttachments Snippet<[ChatMessageData]> No - Your own UI rendered below each bubble, keeping the default bubble and its actions.
empty Snippet No - Empty-state content.
composerLeading Snippet No - Content before the composer input.
sendIcon / stopIcon / voiceIcon / attachIcon Snippet No - Custom composer icons; each falls back to a built-in asset.
testId string No - data-pw on the root element.
messageListLabel string No title + messages, or 'Conversation messages' Accessible name passed to the transcript log.
classes string No - Class string on the root element.

Events

Event Type Description
onsend (value: string, attachments: File[]) => void Fires when a message is submitted from the composer.
onsuggestion (value: string, index: number) => void Fires when a suggestion chip is picked. Falls back to onsend.
onclose () => void Fires when the header close button is pressed.
onstop () => void Enables the stop button (e.g. chat.stop).
onvoice () => void Enables the composer voice button.
onattach (files: File[]) => void Enables the composer attach button.
onretry () => void Enables retry on the latest assistant message (e.g. chat.retry).
onfeedback (value: 'up' | 'down', message: ChatMessageData) => void Enables 👍/👎 on assistant messages.
onscrollstate (state: { atBottom: boolean; scrollable: boolean }) => void Reports whether the reader is at the bottom and whether the list overflows, for an external jump-to-latest control.

CSS Variables

Variable Default CSS Property Description
--chat-height 100% height Height of the chat surface.
--chat-width 100% width Width of the chat surface.
--chat-background #ffffff background Background of the chat surface.
--chat-border none border Border of the chat surface.
--chat-border-radius 0 border-radius Corner rounding of the chat surface.
--chat-footer-gap 10px gap Gap between footer rows.
--chat-footer-padding 12px 1.5rem padding Padding of the footer area.
--chat-footer-background transparent background Footer background.
--chat-footer-border-top none border-top Border above the footer.
--chat-tool-status-justify center justify-content Alignment of the tool-status row.

Child components (ChatHeader, ChatMessageList, ChatComposer, ThinkingIndicator, ChatSuggestions, ChatMessage) are themed through their own CSS variables, which cascade into Chat. The tool-status row's pill itself is ThinkingIndicator's chip variant internally, not the deprecated ChatToolStatus component — but its public theming contract is unchanged: every --chat-tool-status-* variable still controls it (mapped internally onto the chip's own --thinking-indicator-chip-* variables), so existing overrides keep working exactly as before. Reach for --thinking-indicator-chip-* directly only when using <ThinkingIndicator variant="chip"> outside of Chat.

Web Component

Tag: <sui-chat>

<sui-chat title="Assistant"></sui-chat>

Set .messages, .onsend, and other object/array props via JavaScript. Scroll controls map to scroll-policy, pin-hold, hide-scrollbar, jump, jump-label, and the .jumpIcon / .onscrollstate properties; onscrollstate receives { atBottom, scrollable }.

Web Component Events

onsend, onsuggestion, onstop, onvoice, onattach, onretry, onfeedback and onscrollstate are available as JS properties, and each also dispatches a same-named DOM custom event (bubbles, composed) for a consumer who only calls addEventListener: send's detail is { value, attachments }, suggestion's is { value, index }, feedback's is { value, message }, scrollstate's is the { atBottom, scrollable } state object as-is, attach's is the dropped File[] array as-is, and stop/retry carry no detail:

const chat = document.querySelector('sui-chat');
chat.addEventListener('send', (e) => submit(e.detail.value, e.detail.attachments));
chat.addEventListener('feedback', (e) => rate(e.detail.value, e.detail.message));
chat.addEventListener('scrollstate', (e) => setJumpVisible(!e.detail.atBottom));

onclose stays a JS-property-only callback and does not dispatch a DOM event: close is already HTMLElement's own native event, so a chat.addEventListener('close', ...) listener would receive both the real one and a synthetic one under the same name.

Slots

Slot Name Maps to Snippet Description
header-avatar headerAvatar Brand/avatar mark in the header. Takes effect only once slotted — an unslotted <sui-chat> keeps falling back to image/no-avatar instead of a blank space, so a JS-assigned headerAvatar still works when this slot is left empty.
header-actions headerActions Extra inline header actions.
header-content headerContent Extra content as a full-width second row in the header (toolbar, status…).
empty empty Empty-state content, shown when there are no messages.
composer-leading composerLeading Content before the composer input.
send-icon sendIcon Custom send-button icon. Defaults to the built-in send glyph.
stop-icon stopIcon Custom stop-button icon. Defaults to the built-in stop glyph.
voice-icon voiceIcon Custom voice-button icon. Defaults to the built-in mic glyph.
attach-icon attachIcon Custom attach-button icon. Defaults to the built-in paperclip glyph.
jump-icon jumpIcon Custom jump-to-latest icon. Defaults to the built-in chevron glyph.

Svelte-only: message (receives ChatMessageData), messageBody (receives ChatMessageData), messageAttachments (receives ChatMessageData) take arguments, so they cannot be expressed as a named slot: a Web Component <slot> projects markup, it does not forward Svelte snippet parameters, so the arguments above would be silently dropped. Use the Svelte component directly when you need these.

messageListLabel names the conversation transcript. By default it uses the chat title followed by messages, or Conversation messages when no title is set. The same prop is available on <sui-chat> through the message-list-label attribute.