# Conversation

The thread of a chat with an AI agent: its Messages, oldest first, in a named region that scrolls (it fills its parent's height, or height). On first paint it shows the latest turn. A new turn's start lands near the top of the view with a peek of the turn before, and a reply grows into the view without moving it; once the reply fills the view the thread follows its newest line. Any scroll of the reader's stops following at once, and "Jump to latest" takes them back (smooth, instant under reduced motion). Older turns added above keep the reader's place, and turns scrolled out of view above fade at the region's top edge. One status region says when a reply starts and, once, when it ends (its text, or the Message's announcement); never word by word, and never for turns loaded with the page. With no turns, the region opens at its top with a welcome: title, description and up to four starters (onStarter), gone once the first turn is there and back when the turns are cleared. headingLevel (default 2) sets the welcome's and each turn's heading level.

Page: https://turtlekit.dev/components/conversation

## Import

```tsx
import { Conversation } from "turtlekit";
```

## Props

### Conversation

| Prop | Type | Default | What it does |
| --- | --- | --- | --- |
| `label` (required) | `string` |  | Names the thread's region ("Conversation with Acme Assistant"): it scrolls, so people can focus it. |
| `children` | `ReactNode` |  | The turns, oldest first: Messages. |
| `title` | `ReactNode` |  | The welcome's heading, while there are no turns: what people can do here ("What can I help with?"). |
| `description` | `ReactNode` |  | One line under it: what the assistant can and cannot do. |
| `starters` | `ReadonlyArray<string>` |  | Up to four prompts people can start with, as buttons under the welcome. |
| `onStarter` | `(prompt: string) => void` |  | A starter was chosen: send it as the person's first turn (and keep focus in the prompt box). |
| `startersLabel` | `string` | `Suggestions` | Names the starters' group. |
| `headingLevel` | `2 \| 3 \| 4 \| 5 \| 6` | `2` | The welcome's heading level and each turn's hidden heading. |
| `height` | `string` |  | The thread's height (any CSS length) where its parent sets none: a panel, a card, an embed. |
| `jumpLabel` | `string` | `Jump to latest` | The button back to the newest turn, once people scroll away from it. |
| `replyingLabel` | `(name: string) => string` | `(name) => `${name} is replying.`` | Said when a reply starts: (name) => `${name} is replying.` |
| `repliedLabel` | `(name: string, text: string) => string` | `(name, text) => `${name} replied: ${text}`` | Said once when a reply finishes: (name, text) => `${name} replied: ${text}`. |
| `endedLabel` | `(name: string, words: string) => string` | `(name, words) => `${name}: ${words}`` | Said once when a reply ends another way: (name, words) => `${name}: ${words}`, the words being the Message's stopped or failed words. |

## Rules it keeps

- `motion.purpose`
- `composition.states`
- `a11y.focus-visible`

## Examples

Every example on the page, as one file:

```tsx
import { useEffect, useState } from "react";
import { Plus } from "lucide-react";
import { Button, Card, Conversation, Inline, Inset, Message, Stack, Text, toast } from "turtlekit";
import type { MessageFeedback } from "turtlekit";

const thanks = (rating: MessageFeedback | null) => {
  if (rating) toast.success("Thanks for telling us.");
};

const LATE_FEES =
  "Yes. Open the invoice, choose Edit, and turn on Late fee. You choose a fixed amount or a percentage of the total, " +
  "and when it starts: the day after the due date, or a week later. Brightwater Coffee sees the fee on the invoice " +
  "and in the next reminder, so nothing arrives as a surprise. A fee never goes on an invoice that is already paid, " +
  "and you can take it off again at any time before the invoice is settled.";

/**
 * A reply streaming in: its words arrive a few at a time (a timer stands in for the model here). The thread follows
 * the newest line while the reader is at the end; scrolling up stops it, and "Jump to latest" goes back.
 */
export function StreamingReply() {
  const words = LATE_FEES.split(" ");
  const [shown, setShown] = useState(0);
  const streaming = shown < words.length;
  useEffect(() => {
    if (!streaming) return;
    const timer = setTimeout(() => setShown((count) => count + 2), 120);
    return () => clearTimeout(timer);
  }, [shown, streaming]);
  return (
    <Card>
      <Inset>
        <Conversation label="Conversation about invoice INV-1042" height="26rem">
          <Message from="you" time="2026-11-25T09:12:00Z">
            Can I move the due date on invoice INV-1042?
          </Message>
          <Message
            from="agent"
            name="Acme Assistant"
            time="2026-11-25T09:12:00Z"
            copyText="Yes. Open the invoice, choose Edit and change Due date."
            onFeedbackChange={thanks}
          >
            <Text as="p">
              Yes. Open the invoice, choose Edit and change Due date. Brightwater Coffee gets the new date
              with the next reminder.
            </Text>
          </Message>
          <Message from="you" time="2026-11-25T09:14:00Z">
            And can I add a late fee to it?
          </Message>
          <Message
            from="agent"
            name="Acme Assistant"
            time="2026-11-25T09:14:00Z"
            status={streaming ? "streaming" : "done"}
            copyText={LATE_FEES}
            onFeedbackChange={thanks}
          >
            {shown ? <Text as="p">{words.slice(0, shown).join(" ")}</Text> : null}
          </Message>
        </Conversation>
      </Inset>
    </Card>
  );
}

const ANSWERS: Record<string, string> = {
  "Which invoices are overdue?":
    "Two invoices are overdue. INV-1029 to Harbour Dental is 12 days late, and INV-1035 to Moss & Pine is 3 days late. " +
    "Both have had their first reminder.",
  "What did I earn in October?":
    "October's paid invoices come to £18,240, from 14 invoices. That is £2,100 more than September, mostly from two new " +
    "clients.",
  "Draft a polite reminder":
    "Here is a short one: “Hi Ana, a quick reminder that invoice INV-1029 was due on 13 November. You can pay it from " +
    "the link below. Thank you!” Shall I send it?",
};

interface Turn {
  id: number;
  from: "you" | "agent";
  text: string;
}

/**
 * A new conversation: a welcome with three starter prompts. Choosing one sends it; the starters go once the
 * conversation starts, and New chat clears it and brings them back.
 */
export function NewConversation() {
  const [turns, setTurns] = useState<Turn[]>([]);
  const [shown, setShown] = useState(0);
  const last = turns[turns.length - 1];
  const words = last?.from === "agent" ? last.text.split(" ") : [];
  const streaming = shown < words.length;
  useEffect(() => {
    if (!streaming) return;
    const timer = setTimeout(() => setShown((count) => count + 2), 120);
    return () => clearTimeout(timer);
  }, [shown, streaming]);
  const ask = (prompt: string) => {
    setShown(0);
    setTurns((list) => [
      ...list,
      { id: list.length, from: "you", text: prompt },
      { id: list.length + 1, from: "agent", text: ANSWERS[prompt] ?? "" },
    ]);
  };
  return (
    <Stack gap="tight">
      <Inline justify="end">
        <Button variant="soft" size="2" icon={<Plus />} disabled={!turns.length} onClick={() => setTurns([])}>
          New chat
        </Button>
      </Inline>
      <Card>
        <Inset>
          <Conversation
            label="New conversation with Acme Assistant"
            height="26rem"
            title="What can I help with?"
            description="Ask about your invoices, clients and payments. Acme Assistant can make mistakes, so check what matters."
            starters={Object.keys(ANSWERS)}
            onStarter={ask}
          >
            {turns.map((turn, index) =>
              turn.from === "you" ? (
                <Message key={turn.id} from="you">
                  {turn.text}
                </Message>
              ) : (
                <Message
                  key={turn.id}
                  from="agent"
                  name="Acme Assistant"
                  status={index === turns.length - 1 && streaming ? "streaming" : "done"}
                  copyText={turn.text}
                  onFeedbackChange={thanks}
                >
                  {index === turns.length - 1 && streaming ? (
                    shown ? (
                      <Text as="p">{words.slice(0, shown).join(" ")}</Text>
                    ) : null
                  ) : (
                    <Text as="p">{turn.text}</Text>
                  )}
                </Message>
              ),
            )}
          </Conversation>
        </Inset>
      </Card>
    </Stack>
  );
}
```
