Skip to content
Skip to Content
ComposerKit
Components

Conversation View

A local conversation as a list of user and assistant turns, with edit and copy actions.

Loading the component gallery…

Install

shadcn registry

Set up once
npx shadcn@latest init --defaults --yesnpx shadcn registry add '@composerkit=https://composerkit.dynd.ai/r/{name}.json'
conversation-view
npx shadcn add https://composerkit.dynd.ai/r/conversation-view.json --overwrite
components.json
{+{+  "registries": {+    "@composerkit": "https://composerkit.dynd.ai/r/{name}.json"+  }+}}

Import

import { ConversationView } from "@/components/ui/conversation-view";

Demo code

conversation-view-examples.tsx
"use client";/* oxlint-disable typescript/consistent-return -- The effect returns a cleanup only when it starts a timer. */import { Button } from "composerkit/components/ui/button";import { ConversationView } from "composerkit/components/ui/conversation-view";import type {  ConversationAssistantAction,  ConversationTurn,} from "composerkit/components/ui/conversation-view";import { useEffect, useState } from "react";const CONVERSATION_ID = "019a0000-0000-7000-8000-000000000001";const turns: ConversationTurn[] = [  {    assistantMessage: {      id: "turn-1-agent",      markdown:        "A **closure** is a function that keeps access to the variables of the scope where it was created, even after that scope has returned.\n\n```js\nfunction counter() {\n  let count = 0;\n  return () => ++count;\n}\n\nconst next = counter();\nnext(); // 1\nnext(); // 2\n```\n\nEach call to `counter()` makes a new `count`, so two counters never share state.",      status: "completed",    },    id: "turn-1",    userMessage: {      id: "turn-1-user",      text: "Explain what a closure is in JavaScript.",    },  },  {    assistantMessage: {      id: "turn-2-agent",      markdown:        "Use a closure when a function needs private state:\n\n1. Counters and IDs that should not be global.\n2. Event handlers that remember their element.\n3. Factories that return configured functions.",      status: "completed",    },    id: "turn-2",    userMessage: { id: "turn-2-user", text: "When would I use one?" },  },];const streamedReply =  "A closure also lets you build a function once and reuse it with the values it captured.";const STREAM_STEP = 6;const STREAM_TICK_MS = 60;const ConversationViewGalleryExample = () => {  const [streamed, setStreamed] = useState<number | null>(null);  const [lastAction, setLastAction] = useState("");  useEffect(() => {    if (streamed === null || streamed >= streamedReply.length) {      return;    }    const timer = window.setTimeout(() => {      setStreamed(streamed + STREAM_STEP);    }, STREAM_TICK_MS);    return () => {      window.clearTimeout(timer);    };  }, [streamed]);  const assistantActions: ConversationAssistantAction[] = [    {      id: "retry",      label: "Try again",      onSelect: (turn) => {        setLastAction(`Try again on ${turn.id}`);      },    },  ];  const shownTurns: ConversationTurn[] =    streamed === null      ? turns      : [          ...turns,          {            assistantMessage: {              id: "turn-3-agent",              markdown: streamedReply.slice(0, streamed),              status:                streamed >= streamedReply.length ? "completed" : "streaming",            },            id: "turn-3",            userMessage: { id: "turn-3-user", text: "Anything else?" },          },        ];  return (    // The desktop host's appearance: the system font and a 14px chat size on the main surface.    <main className="flex h-dvh flex-col bg-panel font-sans text-foreground [--font-sans:var(--ck-default-sans)] [--ui-message-text-size:14px]">      <ConversationView        assistantActions={assistantActions}        className="flex-1"        conversationId={CONVERSATION_ID}        onEditUserMessage={(turn) => {          setLastAction(`Edit ${turn.id}`);        }}        turns={shownTurns}      />      <footer className="flex items-center gap-3 border-t px-4 py-2 text-sm">        <Button          color="secondary"          disabled={streamed !== null && streamed < streamedReply.length}          onClick={() => {            setStreamed(0);          }}        >          Stream a reply        </Button>        <output aria-live="polite">{lastAction}</output>      </footer>    </main>  );};export { ConversationViewGalleryExample };

Props

ConversationViewProps

Prop

Type

ConversationViewProps

PropTypeNotes
conversationIdstringSet as data-conversation-id and passed to each reply.
turnsConversationTurn[]Oldest first. A turn without assistantMessage shows only the user bubble.
assistantActionsConversationAssistantAction[]Items for the More actions menu under each finished reply.
onCopyMessage(text, messageId) => boolean | Promise<boolean>Replaces the clipboard write. Return false to skip the check mark.
onEditUserMessage(turn) => voidShows Edit message on the latest user message only.

A reply with status: "streaming" shows no actions until it is "completed".

Behavior

  • The scroll region takes focus, so keyboard scrolling works.
  • A hidden heading starts each message, for navigation by heading.
  • Actions appear on hover and on focus. The latest reply always shows them.
  • The view follows the newest turn while the reader is near the bottom.