# Task list

Show planned work and the status of each task.

## Preview

todo-list-preview-1.jsx

```jsx
import { useEffect, useId, useState } from "react";
import {
  Activity,
  ActivityLine,
  ActivityTitle,
} from "@/components/ui/activity";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
  Conversation,
  ConversationContent,
  ConversationItem,
} from "@/components/ui/conversation";
import { Ellipsis } from "@/components/ui/loader";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageFooter,
  MessageHeader,
} from "@/components/ui/message";
import { MessageParts } from "@/components/ui/message-parts";
import { TodoList } from "@/components/ui/todo-list";

export default function Example() {
  return (
    <ActivityDemoTurn
      prompt="Plan the weekly update."
      answer="Gather changes, draft the summary, then review the next steps."
    >
      <TodoList title="Weekly update" items={weekly} defaultOpen />
    </ActivityDemoTurn>
  );
}

var user = {
  id: "user",
  name: "You",
  kind: "human",
};

var activityAgent = {
  id: "release-assistant",
  name: "Release assistant",
  kind: "agent",
};

var participants = [user, activityAgent];

function ThinkingActivity() {
  return (
    <Activity status="active">
      <ActivityLine state="active">
        <ActivityTitle>
          Thinking
          <Ellipsis />
        </ActivityTitle>
      </ActivityLine>
    </Activity>
  );
}

function ActivityConversationTurn({
  prompt,
  response,
  children,
  composer,
  footer,
  renderers,
  onReplay,
  pendingIndicator,
  participants: roster = participants,
}) {
  const turnId = useId();
  const request = {
    id: `${turnId}-prompt`,
    actor: "user",
    author: user,
    parts: [
      {
        type: "text",
        text: prompt,
      },
    ],
  };
  const hasActivity = response.parts.some((part) => part.type === "activity");
  const thinking =
    response.status === "streaming" &&
    !children &&
    !response.parts.some(
      (part) => part.type !== "text" || part.text.length > 0,
    );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-4)",
        width: 560,
        maxWidth: "100%",
      }}
    >
      <Conversation
        label="Activity conversation"
        currentUserId={user.id}
        participants={roster}
        initialPosition="start"
        follow="never"
        style={{
          "--conversation-height": "auto",
        }}
      >
        <ConversationContent>
          <ConversationItem id={request.id} message={request}>
            <Message actor="user">
              <MessageBody>
                <MessageParts parts={request.parts} />
              </MessageBody>
            </Message>
          </ConversationItem>
          <ConversationItem id={`${turnId}-response`} message={response}>
            <Message
              actor="assistant"
              status={response.status}
              className="ui-activity-demo-message"
            >
              <MessageAvatar
                style={
                  hasActivity
                    ? {
                        marginBlockStart:
                          "calc((var(--space-8) - var(--space-6)) / 2)",
                      }
                    : undefined
                }
              >
                <Avatar
                  name={response.author?.name ?? activityAgent.name}
                  kind="agent"
                  seed={response.author?.id ?? activityAgent.id}
                  aria-hidden="true"
                />
              </MessageAvatar>
              <MessageContent>
                {!hasActivity ? (
                  <MessageHeader>
                    {response.author?.name ?? activityAgent.name}
                  </MessageHeader>
                ) : null}
                <MessageBody>
                  <div
                    style={{
                      display: "grid",
                      gridTemplateColumns: "minmax(0, 1fr)",
                      gap: "var(--space-2)",
                    }}
                  >
                    {thinking ? undefined : null}
                    {children}
                    <MessageParts
                      parts={response.parts}
                      renderers={renderers}
                      activityLabel={
                        hasActivity && roster.length > 2 ? (
                          <MessageHeader render={<ActivityTitle />}>
                            {response.author?.name ?? activityAgent.name}
                          </MessageHeader>
                        ) : undefined
                      }
                    />
                  </div>
                </MessageBody>
                <MessageFooter>
                  {footer}
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onReplay}
                  >
                    Replay
                  </Button>
                </MessageFooter>
              </MessageContent>
            </Message>
          </ConversationItem>
        </ConversationContent>
      </Conversation>
      {composer}
    </div>
  );
}

function ActivityPlayback({
  prompt,
  answer,
  children,
  composer,
  footer,
  renderers,
  workDuration = 1200,
  onReplay,
  participants: participants2,
  parts = [],
  pendingIndicator,
}) {
  const [run, setRun] = useState(0);
  const [tick, setTick] = useState(0);
  const [reduced, setReduced] = useState(false);
  const answerAt = 15 + Math.ceil(workDuration / 40);
  const end = answerAt + Math.ceil(answer.length / 2);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    const update = () => setReduced(query.matches);
    update();
    query.addEventListener("change", update);
    return () => query.removeEventListener("change", update);
  }, []);
  useEffect(() => {
    if (reduced || tick >= end) return;
    const timer = window.setTimeout(() => setTick((value) => value + 1), 40);
    return () => window.clearTimeout(timer);
  }, [tick, end, reduced]);
  const thinking = !reduced && tick < 15;
  const text = reduced
    ? answer
    : answer.slice(0, Math.max(0, (tick - answerAt) * 2));
  const done = reduced || tick >= end;
  const progress = reduced
    ? 1
    : Math.min(1, Math.max(0, (tick - 15) / Math.max(1, answerAt - 15)));
  const inlineActivity = parts.some((part) => part.type === "activity");
  const visibleParts = thinking
    ? parts
        .filter((part) => part.type === "activity")
        .map((part) => ({
          ...part,
          event: {
            ...part.event,
            state: "active",
            label: "is thinking",
            meta: undefined,
            description: undefined,
            children: undefined,
          },
        }))
    : parts;
  const response = {
    id: "activity-response",
    actor: "assistant",
    author: activityAgent,
    status: done ? "complete" : "streaming",
    parts: [
      ...visibleParts,
      {
        type: "text",
        id: "answer",
        text,
        state: done ? "complete" : "streaming",
      },
    ],
  };
  return (
    <div
      data-activity-playback={
        thinking ? "thinking" : done ? "complete" : "streaming"
      }
    >
      <ActivityConversationTurn
        prompt={prompt}
        response={response}
        composer={composer}
        footer={done ? footer : null}
        renderers={renderers}
        participants={participants2}
        onReplay={() => {
          onReplay?.();
          setRun((value) => value + 1);
          setTick(0);
        }}
      >
        {thinking && !inlineActivity ? pendingIndicator : null}
        <div key={run} hidden={thinking}>
          {typeof children === "function" ? children(progress) : children}
        </div>
      </ActivityConversationTurn>
    </div>
  );
}

function ActivityDemoTurn(props) {
  return (
    <ActivityPlayback {...props} pendingIndicator={<ThinkingActivity />} />
  );
}

var weekly = [
  {
    id: "gather",
    label: "Gather changes",
    status: "complete",
  },
  {
    id: "draft",
    label: "Draft summary",
    status: "active",
  },
  {
    id: "review",
    label: "Review next steps",
    status: "pending",
  },
];

```

## Design guidance

TodoList uses [Activity](/ai-elements/activity) to display task records. The summary is the top row. Tasks sit under the summary, or under a status row when grouped into a queue. AgentTodoList and the agent-todo-list import are aliases.

Use TodoList when steps are known in advance or grouped into a queue. Use [Activity](/ai-elements/activity#nested) for steps discovered as work progresses. Ask for plan approval with [Tool approval](/ai-elements/tool) and tie the decision to your app’s request ID.

Keep task IDs stable through label/status changes. An empty list renders nothing; distinguish a confirmed empty plan from loading/unknown state in the host. The containing Composer or page owns the surface; TodoList owns only the tree and adds no card, border or background.

**Also known as**

Tasks, Agent todos, Queue, Plan, Action plan.

These names describe task progress shown with Todo list. A queue shows pending work; a plan describes intended steps. The caller supplies the records and their order. Todo list does not schedule or execute work.

## Installation

```sh
npx shadcn@latest add https://ghost-ui.com/r/todo-list.json
```

## Basic usage

```tsx
import { TodoList, type TodoItem } from "@/components/ui/todo-list";

const tasks: TodoItem[] = [
  { id: "gather", label: "Gather changes", status: "complete" },
  { id: "draft", label: "Draft summary", status: "active" },
  { id: "review", label: "Review next steps", status: "pending" },
];

export function TodoListExample() {
  return <TodoList title="Weekly update" items={tasks} />;
}
```

## Structures

TodoList is the public data-driven composition; task records and nested items are inputs, not additional exported UI parts.

The list is data-driven: the caller provides ordered task records and owns every status transition. The summary row is the parent Activity node; task rows are its children. A grouped queue inserts one status-group node per section, and items nests subtasks one rail deeper. The component does not run tasks or change their status.

## Examples

Compare task states and caller updates, then choose where the plan belongs.

### Task states

#### Not started

All tasks are pending and the summary starts collapsed.

todo-list-not-started-2.jsx

```jsx
import { useEffect, useId, useState } from "react";
import {
  Activity,
  ActivityLine,
  ActivityTitle,
} from "@/components/ui/activity";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
  Conversation,
  ConversationContent,
  ConversationItem,
} from "@/components/ui/conversation";
import { Ellipsis } from "@/components/ui/loader";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageFooter,
  MessageHeader,
} from "@/components/ui/message";
import { MessageParts } from "@/components/ui/message-parts";
import { TodoList } from "@/components/ui/todo-list";

export default function Example() {
  return (
    <ActivityDemoTurn
      prompt="Plan the release readiness."
      answer="The recorded steps are shown above for review."
    >
      <TodoList
        title="Release readiness"
        items={weekly.map((item) => ({
          ...item,
          status: "pending",
        }))}
      />
    </ActivityDemoTurn>
  );
}

var user = {
  id: "user",
  name: "You",
  kind: "human",
};

var activityAgent = {
  id: "release-assistant",
  name: "Release assistant",
  kind: "agent",
};

var participants = [user, activityAgent];

function ThinkingActivity() {
  return (
    <Activity status="active">
      <ActivityLine state="active">
        <ActivityTitle>
          Thinking
          <Ellipsis />
        </ActivityTitle>
      </ActivityLine>
    </Activity>
  );
}

function ActivityConversationTurn({
  prompt,
  response,
  children,
  composer,
  footer,
  renderers,
  onReplay,
  pendingIndicator,
  participants: roster = participants,
}) {
  const turnId = useId();
  const request = {
    id: `${turnId}-prompt`,
    actor: "user",
    author: user,
    parts: [
      {
        type: "text",
        text: prompt,
      },
    ],
  };
  const hasActivity = response.parts.some((part) => part.type === "activity");
  const thinking =
    response.status === "streaming" &&
    !children &&
    !response.parts.some(
      (part) => part.type !== "text" || part.text.length > 0,
    );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-4)",
        width: 560,
        maxWidth: "100%",
      }}
    >
      <Conversation
        label="Activity conversation"
        currentUserId={user.id}
        participants={roster}
        initialPosition="start"
        follow="never"
        style={{
          "--conversation-height": "auto",
        }}
      >
        <ConversationContent>
          <ConversationItem id={request.id} message={request}>
            <Message actor="user">
              <MessageBody>
                <MessageParts parts={request.parts} />
              </MessageBody>
            </Message>
          </ConversationItem>
          <ConversationItem id={`${turnId}-response`} message={response}>
            <Message
              actor="assistant"
              status={response.status}
              className="ui-activity-demo-message"
            >
              <MessageAvatar
                style={
                  hasActivity
                    ? {
                        marginBlockStart:
                          "calc((var(--space-8) - var(--space-6)) / 2)",
                      }
                    : undefined
                }
              >
                <Avatar
                  name={response.author?.name ?? activityAgent.name}
                  kind="agent"
                  seed={response.author?.id ?? activityAgent.id}
                  aria-hidden="true"
                />
              </MessageAvatar>
              <MessageContent>
                {!hasActivity ? (
                  <MessageHeader>
                    {response.author?.name ?? activityAgent.name}
                  </MessageHeader>
                ) : null}
                <MessageBody>
                  <div
                    style={{
                      display: "grid",
                      gridTemplateColumns: "minmax(0, 1fr)",
                      gap: "var(--space-2)",
                    }}
                  >
                    {thinking ? undefined : null}
                    {children}
                    <MessageParts
                      parts={response.parts}
                      renderers={renderers}
                      activityLabel={
                        hasActivity && roster.length > 2 ? (
                          <MessageHeader render={<ActivityTitle />}>
                            {response.author?.name ?? activityAgent.name}
                          </MessageHeader>
                        ) : undefined
                      }
                    />
                  </div>
                </MessageBody>
                <MessageFooter>
                  {footer}
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onReplay}
                  >
                    Replay
                  </Button>
                </MessageFooter>
              </MessageContent>
            </Message>
          </ConversationItem>
        </ConversationContent>
      </Conversation>
      {composer}
    </div>
  );
}

function ActivityPlayback({
  prompt,
  answer,
  children,
  composer,
  footer,
  renderers,
  workDuration = 1200,
  onReplay,
  participants: participants2,
  parts = [],
  pendingIndicator,
}) {
  const [run, setRun] = useState(0);
  const [tick, setTick] = useState(0);
  const [reduced, setReduced] = useState(false);
  const answerAt = 15 + Math.ceil(workDuration / 40);
  const end = answerAt + Math.ceil(answer.length / 2);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    const update = () => setReduced(query.matches);
    update();
    query.addEventListener("change", update);
    return () => query.removeEventListener("change", update);
  }, []);
  useEffect(() => {
    if (reduced || tick >= end) return;
    const timer = window.setTimeout(() => setTick((value) => value + 1), 40);
    return () => window.clearTimeout(timer);
  }, [tick, end, reduced]);
  const thinking = !reduced && tick < 15;
  const text = reduced
    ? answer
    : answer.slice(0, Math.max(0, (tick - answerAt) * 2));
  const done = reduced || tick >= end;
  const progress = reduced
    ? 1
    : Math.min(1, Math.max(0, (tick - 15) / Math.max(1, answerAt - 15)));
  const inlineActivity = parts.some((part) => part.type === "activity");
  const visibleParts = thinking
    ? parts
        .filter((part) => part.type === "activity")
        .map((part) => ({
          ...part,
          event: {
            ...part.event,
            state: "active",
            label: "is thinking",
            meta: undefined,
            description: undefined,
            children: undefined,
          },
        }))
    : parts;
  const response = {
    id: "activity-response",
    actor: "assistant",
    author: activityAgent,
    status: done ? "complete" : "streaming",
    parts: [
      ...visibleParts,
      {
        type: "text",
        id: "answer",
        text,
        state: done ? "complete" : "streaming",
      },
    ],
  };
  return (
    <div
      data-activity-playback={
        thinking ? "thinking" : done ? "complete" : "streaming"
      }
    >
      <ActivityConversationTurn
        prompt={prompt}
        response={response}
        composer={composer}
        footer={done ? footer : null}
        renderers={renderers}
        participants={participants2}
        onReplay={() => {
          onReplay?.();
          setRun((value) => value + 1);
          setTick(0);
        }}
      >
        {thinking && !inlineActivity ? pendingIndicator : null}
        <div key={run} hidden={thinking}>
          {typeof children === "function" ? children(progress) : children}
        </div>
      </ActivityConversationTurn>
    </div>
  );
}

function ActivityDemoTurn(props) {
  return (
    <ActivityPlayback {...props} pendingIndicator={<ThinkingActivity />} />
  );
}

var weekly = [
  {
    id: "gather",
    label: "Gather changes",
    status: "complete",
  },
  {
    id: "draft",
    label: "Draft summary",
    status: "active",
  },
  {
    id: "review",
    label: "Review next steps",
    status: "pending",
  },
];

```

#### In progress

A completed task, active task, and pending task share the same ordered list.

todo-list-in-progress-3.jsx

```jsx
import { useEffect, useId, useState } from "react";
import {
  Activity,
  ActivityLine,
  ActivityTitle,
} from "@/components/ui/activity";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
  Conversation,
  ConversationContent,
  ConversationItem,
} from "@/components/ui/conversation";
import { Ellipsis } from "@/components/ui/loader";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageFooter,
  MessageHeader,
} from "@/components/ui/message";
import { MessageParts } from "@/components/ui/message-parts";
import { TodoList } from "@/components/ui/todo-list";

export default function Example() {
  return (
    <ActivityDemoTurn
      prompt="Draft the weekly update."
      answer="The weekly update plan is recorded above; unfinished steps remain visible."
    >
      <TodoList title="Weekly update" items={weekly} />
    </ActivityDemoTurn>
  );
}

var user = {
  id: "user",
  name: "You",
  kind: "human",
};

var activityAgent = {
  id: "release-assistant",
  name: "Release assistant",
  kind: "agent",
};

var participants = [user, activityAgent];

function ThinkingActivity() {
  return (
    <Activity status="active">
      <ActivityLine state="active">
        <ActivityTitle>
          Thinking
          <Ellipsis />
        </ActivityTitle>
      </ActivityLine>
    </Activity>
  );
}

function ActivityConversationTurn({
  prompt,
  response,
  children,
  composer,
  footer,
  renderers,
  onReplay,
  pendingIndicator,
  participants: roster = participants,
}) {
  const turnId = useId();
  const request = {
    id: `${turnId}-prompt`,
    actor: "user",
    author: user,
    parts: [
      {
        type: "text",
        text: prompt,
      },
    ],
  };
  const hasActivity = response.parts.some((part) => part.type === "activity");
  const thinking =
    response.status === "streaming" &&
    !children &&
    !response.parts.some(
      (part) => part.type !== "text" || part.text.length > 0,
    );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-4)",
        width: 560,
        maxWidth: "100%",
      }}
    >
      <Conversation
        label="Activity conversation"
        currentUserId={user.id}
        participants={roster}
        initialPosition="start"
        follow="never"
        style={{
          "--conversation-height": "auto",
        }}
      >
        <ConversationContent>
          <ConversationItem id={request.id} message={request}>
            <Message actor="user">
              <MessageBody>
                <MessageParts parts={request.parts} />
              </MessageBody>
            </Message>
          </ConversationItem>
          <ConversationItem id={`${turnId}-response`} message={response}>
            <Message
              actor="assistant"
              status={response.status}
              className="ui-activity-demo-message"
            >
              <MessageAvatar
                style={
                  hasActivity
                    ? {
                        marginBlockStart:
                          "calc((var(--space-8) - var(--space-6)) / 2)",
                      }
                    : undefined
                }
              >
                <Avatar
                  name={response.author?.name ?? activityAgent.name}
                  kind="agent"
                  seed={response.author?.id ?? activityAgent.id}
                  aria-hidden="true"
                />
              </MessageAvatar>
              <MessageContent>
                {!hasActivity ? (
                  <MessageHeader>
                    {response.author?.name ?? activityAgent.name}
                  </MessageHeader>
                ) : null}
                <MessageBody>
                  <div
                    style={{
                      display: "grid",
                      gridTemplateColumns: "minmax(0, 1fr)",
                      gap: "var(--space-2)",
                    }}
                  >
                    {thinking ? undefined : null}
                    {children}
                    <MessageParts
                      parts={response.parts}
                      renderers={renderers}
                      activityLabel={
                        hasActivity && roster.length > 2 ? (
                          <MessageHeader render={<ActivityTitle />}>
                            {response.author?.name ?? activityAgent.name}
                          </MessageHeader>
                        ) : undefined
                      }
                    />
                  </div>
                </MessageBody>
                <MessageFooter>
                  {footer}
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onReplay}
                  >
                    Replay
                  </Button>
                </MessageFooter>
              </MessageContent>
            </Message>
          </ConversationItem>
        </ConversationContent>
      </Conversation>
      {composer}
    </div>
  );
}

function ActivityPlayback({
  prompt,
  answer,
  children,
  composer,
  footer,
  renderers,
  workDuration = 1200,
  onReplay,
  participants: participants2,
  parts = [],
  pendingIndicator,
}) {
  const [run, setRun] = useState(0);
  const [tick, setTick] = useState(0);
  const [reduced, setReduced] = useState(false);
  const answerAt = 15 + Math.ceil(workDuration / 40);
  const end = answerAt + Math.ceil(answer.length / 2);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    const update = () => setReduced(query.matches);
    update();
    query.addEventListener("change", update);
    return () => query.removeEventListener("change", update);
  }, []);
  useEffect(() => {
    if (reduced || tick >= end) return;
    const timer = window.setTimeout(() => setTick((value) => value + 1), 40);
    return () => window.clearTimeout(timer);
  }, [tick, end, reduced]);
  const thinking = !reduced && tick < 15;
  const text = reduced
    ? answer
    : answer.slice(0, Math.max(0, (tick - answerAt) * 2));
  const done = reduced || tick >= end;
  const progress = reduced
    ? 1
    : Math.min(1, Math.max(0, (tick - 15) / Math.max(1, answerAt - 15)));
  const inlineActivity = parts.some((part) => part.type === "activity");
  const visibleParts = thinking
    ? parts
        .filter((part) => part.type === "activity")
        .map((part) => ({
          ...part,
          event: {
            ...part.event,
            state: "active",
            label: "is thinking",
            meta: undefined,
            description: undefined,
            children: undefined,
          },
        }))
    : parts;
  const response = {
    id: "activity-response",
    actor: "assistant",
    author: activityAgent,
    status: done ? "complete" : "streaming",
    parts: [
      ...visibleParts,
      {
        type: "text",
        id: "answer",
        text,
        state: done ? "complete" : "streaming",
      },
    ],
  };
  return (
    <div
      data-activity-playback={
        thinking ? "thinking" : done ? "complete" : "streaming"
      }
    >
      <ActivityConversationTurn
        prompt={prompt}
        response={response}
        composer={composer}
        footer={done ? footer : null}
        renderers={renderers}
        participants={participants2}
        onReplay={() => {
          onReplay?.();
          setRun((value) => value + 1);
          setTick(0);
        }}
      >
        {thinking && !inlineActivity ? pendingIndicator : null}
        <div key={run} hidden={thinking}>
          {typeof children === "function" ? children(progress) : children}
        </div>
      </ActivityConversationTurn>
    </div>
  );
}

function ActivityDemoTurn(props) {
  return (
    <ActivityPlayback {...props} pendingIndicator={<ThinkingActivity />} />
  );
}

var weekly = [
  {
    id: "gather",
    label: "Gather changes",
    status: "complete",
  },
  {
    id: "draft",
    label: "Draft summary",
    status: "active",
  },
  {
    id: "review",
    label: "Review next steps",
    status: "pending",
  },
];

```

#### Complete

The caller reports every task complete; the derived count reflects it.

todo-list-complete-4.jsx

```jsx
import { useEffect, useId, useState } from "react";
import {
  Activity,
  ActivityLine,
  ActivityTitle,
} from "@/components/ui/activity";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
  Conversation,
  ConversationContent,
  ConversationItem,
} from "@/components/ui/conversation";
import { Ellipsis } from "@/components/ui/loader";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageFooter,
  MessageHeader,
} from "@/components/ui/message";
import { MessageParts } from "@/components/ui/message-parts";
import { TodoList } from "@/components/ui/todo-list";

export default function Example() {
  return (
    <ActivityDemoTurn
      prompt="Finish the weekly update."
      answer="The recorded steps are shown above for review."
    >
      <TodoList
        title="Weekly update"
        items={weekly.map((item) => ({
          ...item,
          status: "complete",
        }))}
      />
    </ActivityDemoTurn>
  );
}

var user = {
  id: "user",
  name: "You",
  kind: "human",
};

var activityAgent = {
  id: "release-assistant",
  name: "Release assistant",
  kind: "agent",
};

var participants = [user, activityAgent];

function ThinkingActivity() {
  return (
    <Activity status="active">
      <ActivityLine state="active">
        <ActivityTitle>
          Thinking
          <Ellipsis />
        </ActivityTitle>
      </ActivityLine>
    </Activity>
  );
}

function ActivityConversationTurn({
  prompt,
  response,
  children,
  composer,
  footer,
  renderers,
  onReplay,
  pendingIndicator,
  participants: roster = participants,
}) {
  const turnId = useId();
  const request = {
    id: `${turnId}-prompt`,
    actor: "user",
    author: user,
    parts: [
      {
        type: "text",
        text: prompt,
      },
    ],
  };
  const hasActivity = response.parts.some((part) => part.type === "activity");
  const thinking =
    response.status === "streaming" &&
    !children &&
    !response.parts.some(
      (part) => part.type !== "text" || part.text.length > 0,
    );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-4)",
        width: 560,
        maxWidth: "100%",
      }}
    >
      <Conversation
        label="Activity conversation"
        currentUserId={user.id}
        participants={roster}
        initialPosition="start"
        follow="never"
        style={{
          "--conversation-height": "auto",
        }}
      >
        <ConversationContent>
          <ConversationItem id={request.id} message={request}>
            <Message actor="user">
              <MessageBody>
                <MessageParts parts={request.parts} />
              </MessageBody>
            </Message>
          </ConversationItem>
          <ConversationItem id={`${turnId}-response`} message={response}>
            <Message
              actor="assistant"
              status={response.status}
              className="ui-activity-demo-message"
            >
              <MessageAvatar
                style={
                  hasActivity
                    ? {
                        marginBlockStart:
                          "calc((var(--space-8) - var(--space-6)) / 2)",
                      }
                    : undefined
                }
              >
                <Avatar
                  name={response.author?.name ?? activityAgent.name}
                  kind="agent"
                  seed={response.author?.id ?? activityAgent.id}
                  aria-hidden="true"
                />
              </MessageAvatar>
              <MessageContent>
                {!hasActivity ? (
                  <MessageHeader>
                    {response.author?.name ?? activityAgent.name}
                  </MessageHeader>
                ) : null}
                <MessageBody>
                  <div
                    style={{
                      display: "grid",
                      gridTemplateColumns: "minmax(0, 1fr)",
                      gap: "var(--space-2)",
                    }}
                  >
                    {thinking ? undefined : null}
                    {children}
                    <MessageParts
                      parts={response.parts}
                      renderers={renderers}
                      activityLabel={
                        hasActivity && roster.length > 2 ? (
                          <MessageHeader render={<ActivityTitle />}>
                            {response.author?.name ?? activityAgent.name}
                          </MessageHeader>
                        ) : undefined
                      }
                    />
                  </div>
                </MessageBody>
                <MessageFooter>
                  {footer}
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onReplay}
                  >
                    Replay
                  </Button>
                </MessageFooter>
              </MessageContent>
            </Message>
          </ConversationItem>
        </ConversationContent>
      </Conversation>
      {composer}
    </div>
  );
}

function ActivityPlayback({
  prompt,
  answer,
  children,
  composer,
  footer,
  renderers,
  workDuration = 1200,
  onReplay,
  participants: participants2,
  parts = [],
  pendingIndicator,
}) {
  const [run, setRun] = useState(0);
  const [tick, setTick] = useState(0);
  const [reduced, setReduced] = useState(false);
  const answerAt = 15 + Math.ceil(workDuration / 40);
  const end = answerAt + Math.ceil(answer.length / 2);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    const update = () => setReduced(query.matches);
    update();
    query.addEventListener("change", update);
    return () => query.removeEventListener("change", update);
  }, []);
  useEffect(() => {
    if (reduced || tick >= end) return;
    const timer = window.setTimeout(() => setTick((value) => value + 1), 40);
    return () => window.clearTimeout(timer);
  }, [tick, end, reduced]);
  const thinking = !reduced && tick < 15;
  const text = reduced
    ? answer
    : answer.slice(0, Math.max(0, (tick - answerAt) * 2));
  const done = reduced || tick >= end;
  const progress = reduced
    ? 1
    : Math.min(1, Math.max(0, (tick - 15) / Math.max(1, answerAt - 15)));
  const inlineActivity = parts.some((part) => part.type === "activity");
  const visibleParts = thinking
    ? parts
        .filter((part) => part.type === "activity")
        .map((part) => ({
          ...part,
          event: {
            ...part.event,
            state: "active",
            label: "is thinking",
            meta: undefined,
            description: undefined,
            children: undefined,
          },
        }))
    : parts;
  const response = {
    id: "activity-response",
    actor: "assistant",
    author: activityAgent,
    status: done ? "complete" : "streaming",
    parts: [
      ...visibleParts,
      {
        type: "text",
        id: "answer",
        text,
        state: done ? "complete" : "streaming",
      },
    ],
  };
  return (
    <div
      data-activity-playback={
        thinking ? "thinking" : done ? "complete" : "streaming"
      }
    >
      <ActivityConversationTurn
        prompt={prompt}
        response={response}
        composer={composer}
        footer={done ? footer : null}
        renderers={renderers}
        participants={participants2}
        onReplay={() => {
          onReplay?.();
          setRun((value) => value + 1);
          setTick(0);
        }}
      >
        {thinking && !inlineActivity ? pendingIndicator : null}
        <div key={run} hidden={thinking}>
          {typeof children === "function" ? children(progress) : children}
        </div>
      </ActivityConversationTurn>
    </div>
  );
}

function ActivityDemoTurn(props) {
  return (
    <ActivityPlayback {...props} pendingIndicator={<ThinkingActivity />} />
  );
}

var weekly = [
  {
    id: "gather",
    label: "Gather changes",
    status: "complete",
  },
  {
    id: "draft",
    label: "Draft summary",
    status: "active",
  },
  {
    id: "review",
    label: "Review next steps",
    status: "pending",
  },
];

```

#### Failed task

Failed tasks keep their reason and do not contribute to completion.

todo-list-failed-task-5.jsx

```jsx
import { useEffect, useId, useState } from "react";
import {
  Activity,
  ActivityLine,
  ActivityTitle,
} from "@/components/ui/activity";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
  Conversation,
  ConversationContent,
  ConversationItem,
} from "@/components/ui/conversation";
import { Ellipsis } from "@/components/ui/loader";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageFooter,
  MessageHeader,
} from "@/components/ui/message";
import { MessageParts } from "@/components/ui/message-parts";
import { TodoList } from "@/components/ui/todo-list";

export default function Example() {
  return (
    <ActivityDemoTurn
      prompt="Draft the weekly update."
      answer="The weekly update plan is recorded above; unfinished steps remain visible."
    >
      <TodoList
        title="Weekly update"
        items={[
          weekly[0],
          {
            ...weekly[1],
            status: "error",
            description:
              "Staging notes are unavailable. The gathered changes remain in the plan.",
          },
          weekly[2],
        ]}
        defaultOpen
      />
    </ActivityDemoTurn>
  );
}

var user = {
  id: "user",
  name: "You",
  kind: "human",
};

var activityAgent = {
  id: "release-assistant",
  name: "Release assistant",
  kind: "agent",
};

var participants = [user, activityAgent];

function ThinkingActivity() {
  return (
    <Activity status="active">
      <ActivityLine state="active">
        <ActivityTitle>
          Thinking
          <Ellipsis />
        </ActivityTitle>
      </ActivityLine>
    </Activity>
  );
}

function ActivityConversationTurn({
  prompt,
  response,
  children,
  composer,
  footer,
  renderers,
  onReplay,
  pendingIndicator,
  participants: roster = participants,
}) {
  const turnId = useId();
  const request = {
    id: `${turnId}-prompt`,
    actor: "user",
    author: user,
    parts: [
      {
        type: "text",
        text: prompt,
      },
    ],
  };
  const hasActivity = response.parts.some((part) => part.type === "activity");
  const thinking =
    response.status === "streaming" &&
    !children &&
    !response.parts.some(
      (part) => part.type !== "text" || part.text.length > 0,
    );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-4)",
        width: 560,
        maxWidth: "100%",
      }}
    >
      <Conversation
        label="Activity conversation"
        currentUserId={user.id}
        participants={roster}
        initialPosition="start"
        follow="never"
        style={{
          "--conversation-height": "auto",
        }}
      >
        <ConversationContent>
          <ConversationItem id={request.id} message={request}>
            <Message actor="user">
              <MessageBody>
                <MessageParts parts={request.parts} />
              </MessageBody>
            </Message>
          </ConversationItem>
          <ConversationItem id={`${turnId}-response`} message={response}>
            <Message
              actor="assistant"
              status={response.status}
              className="ui-activity-demo-message"
            >
              <MessageAvatar
                style={
                  hasActivity
                    ? {
                        marginBlockStart:
                          "calc((var(--space-8) - var(--space-6)) / 2)",
                      }
                    : undefined
                }
              >
                <Avatar
                  name={response.author?.name ?? activityAgent.name}
                  kind="agent"
                  seed={response.author?.id ?? activityAgent.id}
                  aria-hidden="true"
                />
              </MessageAvatar>
              <MessageContent>
                {!hasActivity ? (
                  <MessageHeader>
                    {response.author?.name ?? activityAgent.name}
                  </MessageHeader>
                ) : null}
                <MessageBody>
                  <div
                    style={{
                      display: "grid",
                      gridTemplateColumns: "minmax(0, 1fr)",
                      gap: "var(--space-2)",
                    }}
                  >
                    {thinking ? undefined : null}
                    {children}
                    <MessageParts
                      parts={response.parts}
                      renderers={renderers}
                      activityLabel={
                        hasActivity && roster.length > 2 ? (
                          <MessageHeader render={<ActivityTitle />}>
                            {response.author?.name ?? activityAgent.name}
                          </MessageHeader>
                        ) : undefined
                      }
                    />
                  </div>
                </MessageBody>
                <MessageFooter>
                  {footer}
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onReplay}
                  >
                    Replay
                  </Button>
                </MessageFooter>
              </MessageContent>
            </Message>
          </ConversationItem>
        </ConversationContent>
      </Conversation>
      {composer}
    </div>
  );
}

function ActivityPlayback({
  prompt,
  answer,
  children,
  composer,
  footer,
  renderers,
  workDuration = 1200,
  onReplay,
  participants: participants2,
  parts = [],
  pendingIndicator,
}) {
  const [run, setRun] = useState(0);
  const [tick, setTick] = useState(0);
  const [reduced, setReduced] = useState(false);
  const answerAt = 15 + Math.ceil(workDuration / 40);
  const end = answerAt + Math.ceil(answer.length / 2);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    const update = () => setReduced(query.matches);
    update();
    query.addEventListener("change", update);
    return () => query.removeEventListener("change", update);
  }, []);
  useEffect(() => {
    if (reduced || tick >= end) return;
    const timer = window.setTimeout(() => setTick((value) => value + 1), 40);
    return () => window.clearTimeout(timer);
  }, [tick, end, reduced]);
  const thinking = !reduced && tick < 15;
  const text = reduced
    ? answer
    : answer.slice(0, Math.max(0, (tick - answerAt) * 2));
  const done = reduced || tick >= end;
  const progress = reduced
    ? 1
    : Math.min(1, Math.max(0, (tick - 15) / Math.max(1, answerAt - 15)));
  const inlineActivity = parts.some((part) => part.type === "activity");
  const visibleParts = thinking
    ? parts
        .filter((part) => part.type === "activity")
        .map((part) => ({
          ...part,
          event: {
            ...part.event,
            state: "active",
            label: "is thinking",
            meta: undefined,
            description: undefined,
            children: undefined,
          },
        }))
    : parts;
  const response = {
    id: "activity-response",
    actor: "assistant",
    author: activityAgent,
    status: done ? "complete" : "streaming",
    parts: [
      ...visibleParts,
      {
        type: "text",
        id: "answer",
        text,
        state: done ? "complete" : "streaming",
      },
    ],
  };
  return (
    <div
      data-activity-playback={
        thinking ? "thinking" : done ? "complete" : "streaming"
      }
    >
      <ActivityConversationTurn
        prompt={prompt}
        response={response}
        composer={composer}
        footer={done ? footer : null}
        renderers={renderers}
        participants={participants2}
        onReplay={() => {
          onReplay?.();
          setRun((value) => value + 1);
          setTick(0);
        }}
      >
        {thinking && !inlineActivity ? pendingIndicator : null}
        <div key={run} hidden={thinking}>
          {typeof children === "function" ? children(progress) : children}
        </div>
      </ActivityConversationTurn>
    </div>
  );
}

function ActivityDemoTurn(props) {
  return (
    <ActivityPlayback {...props} pendingIndicator={<ThinkingActivity />} />
  );
}

var weekly = [
  {
    id: "gather",
    label: "Gather changes",
    status: "complete",
  },
  {
    id: "draft",
    label: "Draft summary",
    status: "active",
  },
  {
    id: "review",
    label: "Review next steps",
    status: "pending",
  },
];

```

#### Cancelled task

Stopped work remains distinct from completed work.

todo-list-cancelled-task-6.jsx

```jsx
import { useEffect, useId, useState } from "react";
import {
  Activity,
  ActivityLine,
  ActivityTitle,
} from "@/components/ui/activity";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
  Conversation,
  ConversationContent,
  ConversationItem,
} from "@/components/ui/conversation";
import { Ellipsis } from "@/components/ui/loader";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageFooter,
  MessageHeader,
} from "@/components/ui/message";
import { MessageParts } from "@/components/ui/message-parts";
import { TodoList } from "@/components/ui/todo-list";

export default function Example() {
  return (
    <ActivityDemoTurn
      prompt="Draft the weekly update."
      answer="The weekly update plan is recorded above; unfinished steps remain visible."
    >
      <TodoList
        title="Weekly update"
        items={[
          weekly[0],
          {
            ...weekly[1],
            status: "cancelled",
            description: "Drafting stopped before the file was saved.",
          },
          weekly[2],
        ]}
        defaultOpen
      />
    </ActivityDemoTurn>
  );
}

var user = {
  id: "user",
  name: "You",
  kind: "human",
};

var activityAgent = {
  id: "release-assistant",
  name: "Release assistant",
  kind: "agent",
};

var participants = [user, activityAgent];

function ThinkingActivity() {
  return (
    <Activity status="active">
      <ActivityLine state="active">
        <ActivityTitle>
          Thinking
          <Ellipsis />
        </ActivityTitle>
      </ActivityLine>
    </Activity>
  );
}

function ActivityConversationTurn({
  prompt,
  response,
  children,
  composer,
  footer,
  renderers,
  onReplay,
  pendingIndicator,
  participants: roster = participants,
}) {
  const turnId = useId();
  const request = {
    id: `${turnId}-prompt`,
    actor: "user",
    author: user,
    parts: [
      {
        type: "text",
        text: prompt,
      },
    ],
  };
  const hasActivity = response.parts.some((part) => part.type === "activity");
  const thinking =
    response.status === "streaming" &&
    !children &&
    !response.parts.some(
      (part) => part.type !== "text" || part.text.length > 0,
    );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-4)",
        width: 560,
        maxWidth: "100%",
      }}
    >
      <Conversation
        label="Activity conversation"
        currentUserId={user.id}
        participants={roster}
        initialPosition="start"
        follow="never"
        style={{
          "--conversation-height": "auto",
        }}
      >
        <ConversationContent>
          <ConversationItem id={request.id} message={request}>
            <Message actor="user">
              <MessageBody>
                <MessageParts parts={request.parts} />
              </MessageBody>
            </Message>
          </ConversationItem>
          <ConversationItem id={`${turnId}-response`} message={response}>
            <Message
              actor="assistant"
              status={response.status}
              className="ui-activity-demo-message"
            >
              <MessageAvatar
                style={
                  hasActivity
                    ? {
                        marginBlockStart:
                          "calc((var(--space-8) - var(--space-6)) / 2)",
                      }
                    : undefined
                }
              >
                <Avatar
                  name={response.author?.name ?? activityAgent.name}
                  kind="agent"
                  seed={response.author?.id ?? activityAgent.id}
                  aria-hidden="true"
                />
              </MessageAvatar>
              <MessageContent>
                {!hasActivity ? (
                  <MessageHeader>
                    {response.author?.name ?? activityAgent.name}
                  </MessageHeader>
                ) : null}
                <MessageBody>
                  <div
                    style={{
                      display: "grid",
                      gridTemplateColumns: "minmax(0, 1fr)",
                      gap: "var(--space-2)",
                    }}
                  >
                    {thinking ? undefined : null}
                    {children}
                    <MessageParts
                      parts={response.parts}
                      renderers={renderers}
                      activityLabel={
                        hasActivity && roster.length > 2 ? (
                          <MessageHeader render={<ActivityTitle />}>
                            {response.author?.name ?? activityAgent.name}
                          </MessageHeader>
                        ) : undefined
                      }
                    />
                  </div>
                </MessageBody>
                <MessageFooter>
                  {footer}
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onReplay}
                  >
                    Replay
                  </Button>
                </MessageFooter>
              </MessageContent>
            </Message>
          </ConversationItem>
        </ConversationContent>
      </Conversation>
      {composer}
    </div>
  );
}

function ActivityPlayback({
  prompt,
  answer,
  children,
  composer,
  footer,
  renderers,
  workDuration = 1200,
  onReplay,
  participants: participants2,
  parts = [],
  pendingIndicator,
}) {
  const [run, setRun] = useState(0);
  const [tick, setTick] = useState(0);
  const [reduced, setReduced] = useState(false);
  const answerAt = 15 + Math.ceil(workDuration / 40);
  const end = answerAt + Math.ceil(answer.length / 2);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    const update = () => setReduced(query.matches);
    update();
    query.addEventListener("change", update);
    return () => query.removeEventListener("change", update);
  }, []);
  useEffect(() => {
    if (reduced || tick >= end) return;
    const timer = window.setTimeout(() => setTick((value) => value + 1), 40);
    return () => window.clearTimeout(timer);
  }, [tick, end, reduced]);
  const thinking = !reduced && tick < 15;
  const text = reduced
    ? answer
    : answer.slice(0, Math.max(0, (tick - answerAt) * 2));
  const done = reduced || tick >= end;
  const progress = reduced
    ? 1
    : Math.min(1, Math.max(0, (tick - 15) / Math.max(1, answerAt - 15)));
  const inlineActivity = parts.some((part) => part.type === "activity");
  const visibleParts = thinking
    ? parts
        .filter((part) => part.type === "activity")
        .map((part) => ({
          ...part,
          event: {
            ...part.event,
            state: "active",
            label: "is thinking",
            meta: undefined,
            description: undefined,
            children: undefined,
          },
        }))
    : parts;
  const response = {
    id: "activity-response",
    actor: "assistant",
    author: activityAgent,
    status: done ? "complete" : "streaming",
    parts: [
      ...visibleParts,
      {
        type: "text",
        id: "answer",
        text,
        state: done ? "complete" : "streaming",
      },
    ],
  };
  return (
    <div
      data-activity-playback={
        thinking ? "thinking" : done ? "complete" : "streaming"
      }
    >
      <ActivityConversationTurn
        prompt={prompt}
        response={response}
        composer={composer}
        footer={done ? footer : null}
        renderers={renderers}
        participants={participants2}
        onReplay={() => {
          onReplay?.();
          setRun((value) => value + 1);
          setTick(0);
        }}
      >
        {thinking && !inlineActivity ? pendingIndicator : null}
        <div key={run} hidden={thinking}>
          {typeof children === "function" ? children(progress) : children}
        </div>
      </ActivityConversationTurn>
    </div>
  );
}

function ActivityDemoTurn(props) {
  return (
    <ActivityPlayback {...props} pendingIndicator={<ThinkingActivity />} />
  );
}

var weekly = [
  {
    id: "gather",
    label: "Gather changes",
    status: "complete",
  },
  {
    id: "draft",
    label: "Draft summary",
    status: "active",
  },
  {
    id: "review",
    label: "Review next steps",
    status: "pending",
  },
];

```

#### Expanded in progress

Set defaultOpen when the initial list should be visible.

todo-list-expanded-in-progress-7.jsx

```jsx
import { useEffect, useId, useState } from "react";
import {
  Activity,
  ActivityLine,
  ActivityTitle,
} from "@/components/ui/activity";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
  Conversation,
  ConversationContent,
  ConversationItem,
} from "@/components/ui/conversation";
import { Ellipsis } from "@/components/ui/loader";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageFooter,
  MessageHeader,
} from "@/components/ui/message";
import { MessageParts } from "@/components/ui/message-parts";
import { TodoList } from "@/components/ui/todo-list";

export default function Example() {
  return (
    <ActivityDemoTurn
      prompt="Show the weekly update plan."
      answer="The recorded steps are shown above for review."
    >
      <TodoList title="Weekly update" items={weekly} defaultOpen />
    </ActivityDemoTurn>
  );
}

var user = {
  id: "user",
  name: "You",
  kind: "human",
};

var activityAgent = {
  id: "release-assistant",
  name: "Release assistant",
  kind: "agent",
};

var participants = [user, activityAgent];

function ThinkingActivity() {
  return (
    <Activity status="active">
      <ActivityLine state="active">
        <ActivityTitle>
          Thinking
          <Ellipsis />
        </ActivityTitle>
      </ActivityLine>
    </Activity>
  );
}

function ActivityConversationTurn({
  prompt,
  response,
  children,
  composer,
  footer,
  renderers,
  onReplay,
  pendingIndicator,
  participants: roster = participants,
}) {
  const turnId = useId();
  const request = {
    id: `${turnId}-prompt`,
    actor: "user",
    author: user,
    parts: [
      {
        type: "text",
        text: prompt,
      },
    ],
  };
  const hasActivity = response.parts.some((part) => part.type === "activity");
  const thinking =
    response.status === "streaming" &&
    !children &&
    !response.parts.some(
      (part) => part.type !== "text" || part.text.length > 0,
    );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-4)",
        width: 560,
        maxWidth: "100%",
      }}
    >
      <Conversation
        label="Activity conversation"
        currentUserId={user.id}
        participants={roster}
        initialPosition="start"
        follow="never"
        style={{
          "--conversation-height": "auto",
        }}
      >
        <ConversationContent>
          <ConversationItem id={request.id} message={request}>
            <Message actor="user">
              <MessageBody>
                <MessageParts parts={request.parts} />
              </MessageBody>
            </Message>
          </ConversationItem>
          <ConversationItem id={`${turnId}-response`} message={response}>
            <Message
              actor="assistant"
              status={response.status}
              className="ui-activity-demo-message"
            >
              <MessageAvatar
                style={
                  hasActivity
                    ? {
                        marginBlockStart:
                          "calc((var(--space-8) - var(--space-6)) / 2)",
                      }
                    : undefined
                }
              >
                <Avatar
                  name={response.author?.name ?? activityAgent.name}
                  kind="agent"
                  seed={response.author?.id ?? activityAgent.id}
                  aria-hidden="true"
                />
              </MessageAvatar>
              <MessageContent>
                {!hasActivity ? (
                  <MessageHeader>
                    {response.author?.name ?? activityAgent.name}
                  </MessageHeader>
                ) : null}
                <MessageBody>
                  <div
                    style={{
                      display: "grid",
                      gridTemplateColumns: "minmax(0, 1fr)",
                      gap: "var(--space-2)",
                    }}
                  >
                    {thinking ? undefined : null}
                    {children}
                    <MessageParts
                      parts={response.parts}
                      renderers={renderers}
                      activityLabel={
                        hasActivity && roster.length > 2 ? (
                          <MessageHeader render={<ActivityTitle />}>
                            {response.author?.name ?? activityAgent.name}
                          </MessageHeader>
                        ) : undefined
                      }
                    />
                  </div>
                </MessageBody>
                <MessageFooter>
                  {footer}
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onReplay}
                  >
                    Replay
                  </Button>
                </MessageFooter>
              </MessageContent>
            </Message>
          </ConversationItem>
        </ConversationContent>
      </Conversation>
      {composer}
    </div>
  );
}

function ActivityPlayback({
  prompt,
  answer,
  children,
  composer,
  footer,
  renderers,
  workDuration = 1200,
  onReplay,
  participants: participants2,
  parts = [],
  pendingIndicator,
}) {
  const [run, setRun] = useState(0);
  const [tick, setTick] = useState(0);
  const [reduced, setReduced] = useState(false);
  const answerAt = 15 + Math.ceil(workDuration / 40);
  const end = answerAt + Math.ceil(answer.length / 2);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    const update = () => setReduced(query.matches);
    update();
    query.addEventListener("change", update);
    return () => query.removeEventListener("change", update);
  }, []);
  useEffect(() => {
    if (reduced || tick >= end) return;
    const timer = window.setTimeout(() => setTick((value) => value + 1), 40);
    return () => window.clearTimeout(timer);
  }, [tick, end, reduced]);
  const thinking = !reduced && tick < 15;
  const text = reduced
    ? answer
    : answer.slice(0, Math.max(0, (tick - answerAt) * 2));
  const done = reduced || tick >= end;
  const progress = reduced
    ? 1
    : Math.min(1, Math.max(0, (tick - 15) / Math.max(1, answerAt - 15)));
  const inlineActivity = parts.some((part) => part.type === "activity");
  const visibleParts = thinking
    ? parts
        .filter((part) => part.type === "activity")
        .map((part) => ({
          ...part,
          event: {
            ...part.event,
            state: "active",
            label: "is thinking",
            meta: undefined,
            description: undefined,
            children: undefined,
          },
        }))
    : parts;
  const response = {
    id: "activity-response",
    actor: "assistant",
    author: activityAgent,
    status: done ? "complete" : "streaming",
    parts: [
      ...visibleParts,
      {
        type: "text",
        id: "answer",
        text,
        state: done ? "complete" : "streaming",
      },
    ],
  };
  return (
    <div
      data-activity-playback={
        thinking ? "thinking" : done ? "complete" : "streaming"
      }
    >
      <ActivityConversationTurn
        prompt={prompt}
        response={response}
        composer={composer}
        footer={done ? footer : null}
        renderers={renderers}
        participants={participants2}
        onReplay={() => {
          onReplay?.();
          setRun((value) => value + 1);
          setTick(0);
        }}
      >
        {thinking && !inlineActivity ? pendingIndicator : null}
        <div key={run} hidden={thinking}>
          {typeof children === "function" ? children(progress) : children}
        </div>
      </ActivityConversationTurn>
    </div>
  );
}

function ActivityDemoTurn(props) {
  return (
    <ActivityPlayback {...props} pendingIndicator={<ThinkingActivity />} />
  );
}

var weekly = [
  {
    id: "gather",
    label: "Gather changes",
    status: "complete",
  },
  {
    id: "draft",
    label: "Draft summary",
    status: "active",
  },
  {
    id: "review",
    label: "Review next steps",
    status: "pending",
  },
];

```

#### Long task label

Task copy wraps while each status indicator stays in the same narrow lane.

todo-list-long-task-label-8.jsx

```jsx
import { useEffect, useId, useState } from "react";
import {
  Activity,
  ActivityLine,
  ActivityTitle,
} from "@/components/ui/activity";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
  Conversation,
  ConversationContent,
  ConversationItem,
} from "@/components/ui/conversation";
import { Ellipsis } from "@/components/ui/loader";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageFooter,
  MessageHeader,
} from "@/components/ui/message";
import { MessageParts } from "@/components/ui/message-parts";
import { TodoList } from "@/components/ui/todo-list";

export default function Example() {
  const items = [
    {
      id: "long",
      status: "active",
      label:
        "Compare the rollout notes with the customer feedback and flag any change that needs an owner before the weekly update is shared",
    },
  ];
  return (
    <ActivityDemoTurn
      prompt="Review the rollout notes."
      answer="The review plan retains the full task description."
    >
      <div
        style={{
          width: "100%",
          maxInlineSize: 360,
        }}
      >
        <TodoList title="Review plan" items={items} defaultOpen />
      </div>
    </ActivityDemoTurn>
  );
}

var user = {
  id: "user",
  name: "You",
  kind: "human",
};

var activityAgent = {
  id: "release-assistant",
  name: "Release assistant",
  kind: "agent",
};

var participants = [user, activityAgent];

function ThinkingActivity() {
  return (
    <Activity status="active">
      <ActivityLine state="active">
        <ActivityTitle>
          Thinking
          <Ellipsis />
        </ActivityTitle>
      </ActivityLine>
    </Activity>
  );
}

function ActivityConversationTurn({
  prompt,
  response,
  children,
  composer,
  footer,
  renderers,
  onReplay,
  pendingIndicator,
  participants: roster = participants,
}) {
  const turnId = useId();
  const request = {
    id: `${turnId}-prompt`,
    actor: "user",
    author: user,
    parts: [
      {
        type: "text",
        text: prompt,
      },
    ],
  };
  const hasActivity = response.parts.some((part) => part.type === "activity");
  const thinking =
    response.status === "streaming" &&
    !children &&
    !response.parts.some(
      (part) => part.type !== "text" || part.text.length > 0,
    );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-4)",
        width: 560,
        maxWidth: "100%",
      }}
    >
      <Conversation
        label="Activity conversation"
        currentUserId={user.id}
        participants={roster}
        initialPosition="start"
        follow="never"
        style={{
          "--conversation-height": "auto",
        }}
      >
        <ConversationContent>
          <ConversationItem id={request.id} message={request}>
            <Message actor="user">
              <MessageBody>
                <MessageParts parts={request.parts} />
              </MessageBody>
            </Message>
          </ConversationItem>
          <ConversationItem id={`${turnId}-response`} message={response}>
            <Message
              actor="assistant"
              status={response.status}
              className="ui-activity-demo-message"
            >
              <MessageAvatar
                style={
                  hasActivity
                    ? {
                        marginBlockStart:
                          "calc((var(--space-8) - var(--space-6)) / 2)",
                      }
                    : undefined
                }
              >
                <Avatar
                  name={response.author?.name ?? activityAgent.name}
                  kind="agent"
                  seed={response.author?.id ?? activityAgent.id}
                  aria-hidden="true"
                />
              </MessageAvatar>
              <MessageContent>
                {!hasActivity ? (
                  <MessageHeader>
                    {response.author?.name ?? activityAgent.name}
                  </MessageHeader>
                ) : null}
                <MessageBody>
                  <div
                    style={{
                      display: "grid",
                      gridTemplateColumns: "minmax(0, 1fr)",
                      gap: "var(--space-2)",
                    }}
                  >
                    {thinking ? undefined : null}
                    {children}
                    <MessageParts
                      parts={response.parts}
                      renderers={renderers}
                      activityLabel={
                        hasActivity && roster.length > 2 ? (
                          <MessageHeader render={<ActivityTitle />}>
                            {response.author?.name ?? activityAgent.name}
                          </MessageHeader>
                        ) : undefined
                      }
                    />
                  </div>
                </MessageBody>
                <MessageFooter>
                  {footer}
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onReplay}
                  >
                    Replay
                  </Button>
                </MessageFooter>
              </MessageContent>
            </Message>
          </ConversationItem>
        </ConversationContent>
      </Conversation>
      {composer}
    </div>
  );
}

function ActivityPlayback({
  prompt,
  answer,
  children,
  composer,
  footer,
  renderers,
  workDuration = 1200,
  onReplay,
  participants: participants2,
  parts = [],
  pendingIndicator,
}) {
  const [run, setRun] = useState(0);
  const [tick, setTick] = useState(0);
  const [reduced, setReduced] = useState(false);
  const answerAt = 15 + Math.ceil(workDuration / 40);
  const end = answerAt + Math.ceil(answer.length / 2);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    const update = () => setReduced(query.matches);
    update();
    query.addEventListener("change", update);
    return () => query.removeEventListener("change", update);
  }, []);
  useEffect(() => {
    if (reduced || tick >= end) return;
    const timer = window.setTimeout(() => setTick((value) => value + 1), 40);
    return () => window.clearTimeout(timer);
  }, [tick, end, reduced]);
  const thinking = !reduced && tick < 15;
  const text = reduced
    ? answer
    : answer.slice(0, Math.max(0, (tick - answerAt) * 2));
  const done = reduced || tick >= end;
  const progress = reduced
    ? 1
    : Math.min(1, Math.max(0, (tick - 15) / Math.max(1, answerAt - 15)));
  const inlineActivity = parts.some((part) => part.type === "activity");
  const visibleParts = thinking
    ? parts
        .filter((part) => part.type === "activity")
        .map((part) => ({
          ...part,
          event: {
            ...part.event,
            state: "active",
            label: "is thinking",
            meta: undefined,
            description: undefined,
            children: undefined,
          },
        }))
    : parts;
  const response = {
    id: "activity-response",
    actor: "assistant",
    author: activityAgent,
    status: done ? "complete" : "streaming",
    parts: [
      ...visibleParts,
      {
        type: "text",
        id: "answer",
        text,
        state: done ? "complete" : "streaming",
      },
    ],
  };
  return (
    <div
      data-activity-playback={
        thinking ? "thinking" : done ? "complete" : "streaming"
      }
    >
      <ActivityConversationTurn
        prompt={prompt}
        response={response}
        composer={composer}
        footer={done ? footer : null}
        renderers={renderers}
        participants={participants2}
        onReplay={() => {
          onReplay?.();
          setRun((value) => value + 1);
          setTick(0);
        }}
      >
        {thinking && !inlineActivity ? pendingIndicator : null}
        <div key={run} hidden={thinking}>
          {typeof children === "function" ? children(progress) : children}
        </div>
      </ActivityConversationTurn>
    </div>
  );
}

function ActivityDemoTurn(props) {
  return (
    <ActivityPlayback {...props} pendingIndicator={<ThinkingActivity />} />
  );
}

```

#### Caller-owned status update

The caller changes item data after its own action. TodoList reflects the new data and does not own that transition.

todo-list-caller-owned-status-update-9.jsx

```jsx
import { useEffect, useId, useState } from "react";
import {
  Activity,
  ActivityLine,
  ActivityTitle,
} from "@/components/ui/activity";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
  Conversation,
  ConversationContent,
  ConversationItem,
} from "@/components/ui/conversation";
import { Ellipsis } from "@/components/ui/loader";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageFooter,
  MessageHeader,
} from "@/components/ui/message";
import { MessageParts } from "@/components/ui/message-parts";
import { useState as useState4 } from "react";
import { TodoList } from "@/components/ui/todo-list";
import { Button as Button2 } from "@/components/ui/button";

export default function Example() {
  const [items, setItems] = useState4(weekly);
  return (
    <ActivityDemoTurn
      onReplay={() => setItems(weekly)}
      prompt="Draft the weekly update."
      answer="The weekly update plan is recorded above; unfinished steps remain visible."
    >
      <div
        style={{
          display: "grid",
          gap: "var(--space-3)",
        }}
      >
        <TodoList title="Weekly update" items={items} defaultOpen />
        <Button2
          type="button"
          size="sm"
          variant="ghost"
          onClick={() =>
            setItems((current) =>
              current.map((item) =>
                item.id === "draft"
                  ? {
                      ...item,
                      status: "complete",
                    }
                  : item,
              ),
            )
          }
        >
          Confirm draft
        </Button2>
      </div>
    </ActivityDemoTurn>
  );
}

var user = {
  id: "user",
  name: "You",
  kind: "human",
};

var activityAgent = {
  id: "release-assistant",
  name: "Release assistant",
  kind: "agent",
};

var participants = [user, activityAgent];

function ThinkingActivity() {
  return (
    <Activity status="active">
      <ActivityLine state="active">
        <ActivityTitle>
          Thinking
          <Ellipsis />
        </ActivityTitle>
      </ActivityLine>
    </Activity>
  );
}

function ActivityConversationTurn({
  prompt,
  response,
  children,
  composer,
  footer,
  renderers,
  onReplay,
  pendingIndicator,
  participants: roster = participants,
}) {
  const turnId = useId();
  const request = {
    id: `${turnId}-prompt`,
    actor: "user",
    author: user,
    parts: [
      {
        type: "text",
        text: prompt,
      },
    ],
  };
  const hasActivity = response.parts.some((part) => part.type === "activity");
  const thinking =
    response.status === "streaming" &&
    !children &&
    !response.parts.some(
      (part) => part.type !== "text" || part.text.length > 0,
    );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-4)",
        width: 560,
        maxWidth: "100%",
      }}
    >
      <Conversation
        label="Activity conversation"
        currentUserId={user.id}
        participants={roster}
        initialPosition="start"
        follow="never"
        style={{
          "--conversation-height": "auto",
        }}
      >
        <ConversationContent>
          <ConversationItem id={request.id} message={request}>
            <Message actor="user">
              <MessageBody>
                <MessageParts parts={request.parts} />
              </MessageBody>
            </Message>
          </ConversationItem>
          <ConversationItem id={`${turnId}-response`} message={response}>
            <Message
              actor="assistant"
              status={response.status}
              className="ui-activity-demo-message"
            >
              <MessageAvatar
                style={
                  hasActivity
                    ? {
                        marginBlockStart:
                          "calc((var(--space-8) - var(--space-6)) / 2)",
                      }
                    : undefined
                }
              >
                <Avatar
                  name={response.author?.name ?? activityAgent.name}
                  kind="agent"
                  seed={response.author?.id ?? activityAgent.id}
                  aria-hidden="true"
                />
              </MessageAvatar>
              <MessageContent>
                {!hasActivity ? (
                  <MessageHeader>
                    {response.author?.name ?? activityAgent.name}
                  </MessageHeader>
                ) : null}
                <MessageBody>
                  <div
                    style={{
                      display: "grid",
                      gridTemplateColumns: "minmax(0, 1fr)",
                      gap: "var(--space-2)",
                    }}
                  >
                    {thinking ? undefined : null}
                    {children}
                    <MessageParts
                      parts={response.parts}
                      renderers={renderers}
                      activityLabel={
                        hasActivity && roster.length > 2 ? (
                          <MessageHeader render={<ActivityTitle />}>
                            {response.author?.name ?? activityAgent.name}
                          </MessageHeader>
                        ) : undefined
                      }
                    />
                  </div>
                </MessageBody>
                <MessageFooter>
                  {footer}
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onReplay}
                  >
                    Replay
                  </Button>
                </MessageFooter>
              </MessageContent>
            </Message>
          </ConversationItem>
        </ConversationContent>
      </Conversation>
      {composer}
    </div>
  );
}

function ActivityPlayback({
  prompt,
  answer,
  children,
  composer,
  footer,
  renderers,
  workDuration = 1200,
  onReplay,
  participants: participants2,
  parts = [],
  pendingIndicator,
}) {
  const [run, setRun] = useState(0);
  const [tick, setTick] = useState(0);
  const [reduced, setReduced] = useState(false);
  const answerAt = 15 + Math.ceil(workDuration / 40);
  const end = answerAt + Math.ceil(answer.length / 2);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    const update = () => setReduced(query.matches);
    update();
    query.addEventListener("change", update);
    return () => query.removeEventListener("change", update);
  }, []);
  useEffect(() => {
    if (reduced || tick >= end) return;
    const timer = window.setTimeout(() => setTick((value) => value + 1), 40);
    return () => window.clearTimeout(timer);
  }, [tick, end, reduced]);
  const thinking = !reduced && tick < 15;
  const text = reduced
    ? answer
    : answer.slice(0, Math.max(0, (tick - answerAt) * 2));
  const done = reduced || tick >= end;
  const progress = reduced
    ? 1
    : Math.min(1, Math.max(0, (tick - 15) / Math.max(1, answerAt - 15)));
  const inlineActivity = parts.some((part) => part.type === "activity");
  const visibleParts = thinking
    ? parts
        .filter((part) => part.type === "activity")
        .map((part) => ({
          ...part,
          event: {
            ...part.event,
            state: "active",
            label: "is thinking",
            meta: undefined,
            description: undefined,
            children: undefined,
          },
        }))
    : parts;
  const response = {
    id: "activity-response",
    actor: "assistant",
    author: activityAgent,
    status: done ? "complete" : "streaming",
    parts: [
      ...visibleParts,
      {
        type: "text",
        id: "answer",
        text,
        state: done ? "complete" : "streaming",
      },
    ],
  };
  return (
    <div
      data-activity-playback={
        thinking ? "thinking" : done ? "complete" : "streaming"
      }
    >
      <ActivityConversationTurn
        prompt={prompt}
        response={response}
        composer={composer}
        footer={done ? footer : null}
        renderers={renderers}
        participants={participants2}
        onReplay={() => {
          onReplay?.();
          setRun((value) => value + 1);
          setTick(0);
        }}
      >
        {thinking && !inlineActivity ? pendingIndicator : null}
        <div key={run} hidden={thinking}>
          {typeof children === "function" ? children(progress) : children}
        </div>
      </ActivityConversationTurn>
    </div>
  );
}

function ActivityDemoTurn(props) {
  return (
    <ActivityPlayback {...props} pendingIndicator={<ThinkingActivity />} />
  );
}

var weekly = [
  {
    id: "gather",
    label: "Gather changes",
    status: "complete",
  },
  {
    id: "draft",
    label: "Draft summary",
    status: "active",
  },
  {
    id: "review",
    label: "Review next steps",
    status: "pending",
  },
];

```

### Placement

#### Inside composer

Place the list in Composer.secondary. The Composer owns the containing surface and padding; the list adds neither.

todo-list-inside-composer-10.jsx

```jsx
import { useEffect, useId, useState } from "react";
import {
  Activity,
  ActivityLine,
  ActivityTitle,
} from "@/components/ui/activity";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
  Conversation,
  ConversationContent,
  ConversationItem,
} from "@/components/ui/conversation";
import { Ellipsis } from "@/components/ui/loader";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageFooter,
  MessageHeader,
} from "@/components/ui/message";
import { MessageParts } from "@/components/ui/message-parts";
import { TodoList } from "@/components/ui/todo-list";
import {
  forwardRef,
  useEffect as useEffect2,
  useRef,
  useState as useState3,
} from "react";
import { Plus } from "lucide-react";
import {
  Composer,
  ComposerAction,
  ComposerAttachments,
  ComposerInput,
  ComposerSubmit,
  ComposerToolbar,
} from "@/components/ui/composer";
import { FileUpload } from "@/components/ui/file-upload";
import { useState as useState2 } from "react";
import { Check, ChevronDown } from "lucide-react";
import { Select } from "@/components/ui/select";
import { TooltipHint } from "@/components/ui/tooltip";

export default function Example() {
  return (
    <ActivityDemoTurn
      prompt="Draft the weekly update."
      answer="The weekly plan is attached to your draft."
      composer={
        <ChatComposer
          onSubmit={() => undefined}
          secondary={
            <TodoList title="Weekly update" items={weekly} defaultOpen />
          }
        />
      }
    >
      {null}
    </ActivityDemoTurn>
  );
}

var user = {
  id: "user",
  name: "You",
  kind: "human",
};

var activityAgent = {
  id: "release-assistant",
  name: "Release assistant",
  kind: "agent",
};

var participants = [user, activityAgent];

function ThinkingActivity() {
  return (
    <Activity status="active">
      <ActivityLine state="active">
        <ActivityTitle>
          Thinking
          <Ellipsis />
        </ActivityTitle>
      </ActivityLine>
    </Activity>
  );
}

function ActivityConversationTurn({
  prompt,
  response,
  children,
  composer,
  footer,
  renderers,
  onReplay,
  pendingIndicator,
  participants: roster = participants,
}) {
  const turnId = useId();
  const request = {
    id: `${turnId}-prompt`,
    actor: "user",
    author: user,
    parts: [
      {
        type: "text",
        text: prompt,
      },
    ],
  };
  const hasActivity = response.parts.some((part) => part.type === "activity");
  const thinking =
    response.status === "streaming" &&
    !children &&
    !response.parts.some(
      (part) => part.type !== "text" || part.text.length > 0,
    );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-4)",
        width: 560,
        maxWidth: "100%",
      }}
    >
      <Conversation
        label="Activity conversation"
        currentUserId={user.id}
        participants={roster}
        initialPosition="start"
        follow="never"
        style={{
          "--conversation-height": "auto",
        }}
      >
        <ConversationContent>
          <ConversationItem id={request.id} message={request}>
            <Message actor="user">
              <MessageBody>
                <MessageParts parts={request.parts} />
              </MessageBody>
            </Message>
          </ConversationItem>
          <ConversationItem id={`${turnId}-response`} message={response}>
            <Message
              actor="assistant"
              status={response.status}
              className="ui-activity-demo-message"
            >
              <MessageAvatar
                style={
                  hasActivity
                    ? {
                        marginBlockStart:
                          "calc((var(--space-8) - var(--space-6)) / 2)",
                      }
                    : undefined
                }
              >
                <Avatar
                  name={response.author?.name ?? activityAgent.name}
                  kind="agent"
                  seed={response.author?.id ?? activityAgent.id}
                  aria-hidden="true"
                />
              </MessageAvatar>
              <MessageContent>
                {!hasActivity ? (
                  <MessageHeader>
                    {response.author?.name ?? activityAgent.name}
                  </MessageHeader>
                ) : null}
                <MessageBody>
                  <div
                    style={{
                      display: "grid",
                      gridTemplateColumns: "minmax(0, 1fr)",
                      gap: "var(--space-2)",
                    }}
                  >
                    {thinking ? undefined : null}
                    {children}
                    <MessageParts
                      parts={response.parts}
                      renderers={renderers}
                      activityLabel={
                        hasActivity && roster.length > 2 ? (
                          <MessageHeader render={<ActivityTitle />}>
                            {response.author?.name ?? activityAgent.name}
                          </MessageHeader>
                        ) : undefined
                      }
                    />
                  </div>
                </MessageBody>
                <MessageFooter>
                  {footer}
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onReplay}
                  >
                    Replay
                  </Button>
                </MessageFooter>
              </MessageContent>
            </Message>
          </ConversationItem>
        </ConversationContent>
      </Conversation>
      {composer}
    </div>
  );
}

function ActivityPlayback({
  prompt,
  answer,
  children,
  composer,
  footer,
  renderers,
  workDuration = 1200,
  onReplay,
  participants: participants2,
  parts = [],
  pendingIndicator,
}) {
  const [run, setRun] = useState(0);
  const [tick, setTick] = useState(0);
  const [reduced, setReduced] = useState(false);
  const answerAt = 15 + Math.ceil(workDuration / 40);
  const end = answerAt + Math.ceil(answer.length / 2);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    const update = () => setReduced(query.matches);
    update();
    query.addEventListener("change", update);
    return () => query.removeEventListener("change", update);
  }, []);
  useEffect(() => {
    if (reduced || tick >= end) return;
    const timer = window.setTimeout(() => setTick((value) => value + 1), 40);
    return () => window.clearTimeout(timer);
  }, [tick, end, reduced]);
  const thinking = !reduced && tick < 15;
  const text = reduced
    ? answer
    : answer.slice(0, Math.max(0, (tick - answerAt) * 2));
  const done = reduced || tick >= end;
  const progress = reduced
    ? 1
    : Math.min(1, Math.max(0, (tick - 15) / Math.max(1, answerAt - 15)));
  const inlineActivity = parts.some((part) => part.type === "activity");
  const visibleParts = thinking
    ? parts
        .filter((part) => part.type === "activity")
        .map((part) => ({
          ...part,
          event: {
            ...part.event,
            state: "active",
            label: "is thinking",
            meta: undefined,
            description: undefined,
            children: undefined,
          },
        }))
    : parts;
  const response = {
    id: "activity-response",
    actor: "assistant",
    author: activityAgent,
    status: done ? "complete" : "streaming",
    parts: [
      ...visibleParts,
      {
        type: "text",
        id: "answer",
        text,
        state: done ? "complete" : "streaming",
      },
    ],
  };
  return (
    <div
      data-activity-playback={
        thinking ? "thinking" : done ? "complete" : "streaming"
      }
    >
      <ActivityConversationTurn
        prompt={prompt}
        response={response}
        composer={composer}
        footer={done ? footer : null}
        renderers={renderers}
        participants={participants2}
        onReplay={() => {
          onReplay?.();
          setRun((value) => value + 1);
          setTick(0);
        }}
      >
        {thinking && !inlineActivity ? pendingIndicator : null}
        <div key={run} hidden={thinking}>
          {typeof children === "function" ? children(progress) : children}
        </div>
      </ActivityConversationTurn>
    </div>
  );
}

function ActivityDemoTurn(props) {
  return (
    <ActivityPlayback {...props} pendingIndicator={<ThinkingActivity />} />
  );
}

var MODEL_OPTIONS = [
  {
    value: "chatgpt-sol-6-1",
    label: "Sol 6.1",
  },
  {
    value: "chatgpt-sol-6",
    label: "Sol 6",
  },
  {
    value: "chatgpt-luna-6",
    label: "Luna 6",
  },
];

function ModelSelect({
  disabled,
  value: controlledValue,
  onValueChange,
  options = MODEL_OPTIONS,
} = {}) {
  const [uncontrolledValue, setUncontrolledValue] = useState2(
    () => options.find((item) => !item.disabled)?.value ?? null,
  );
  const value =
    controlledValue === undefined ? uncontrolledValue : controlledValue;
  const fullLabel =
    options.find((item) => item.value === value)?.label ?? "Choose a model";
  const change = (next) => {
    if (controlledValue === undefined && next) setUncontrolledValue(next);
    onValueChange?.(next);
  };
  return (
    <Select.Root
      items={options}
      value={value}
      onValueChange={change}
      disabled={disabled}
    >
      <TooltipHint content={fullLabel}>
        <Select.Trigger
          compact
          variant="ghost"
          className="model-select__trigger"
          aria-label="Model"
          aria-description={fullLabel}
        >
          <Select.Value placeholder="Choose a model" />
          <Select.Icon>
            <ChevronDown size={14} aria-hidden="true" />
          </Select.Icon>
        </Select.Trigger>
      </TooltipHint>
      <Select.Portal>
        <Select.Positioner>
          <Select.Popup className="model-select__popup" aria-label="Models">
            {options.map((item) => (
              <Select.Item
                key={item.value}
                value={item.value}
                disabled={item.disabled}
              >
                <Select.ItemText>{item.label}</Select.ItemText>
                <Select.ItemIndicator>
                  <Check size={14} aria-hidden="true" />
                </Select.ItemIndicator>
              </Select.Item>
            ))}
          </Select.Popup>
        </Select.Positioner>
      </Select.Portal>
    </Select.Root>
  );
}

function fileFromNative(file, id, url) {
  return {
    id,
    name: file.name,
    mediaType: file.type || undefined,
    size: file.size,
    url,
    status: "ready",
  };
}

var ChatComposer = forwardRef(function ChatComposer2(
  {
    defaultValue = "",
    defaultAttachments = [],
    value,
    onValueChange,
    status = "ready",
    feedbackPlacement = "inline",
    initialRows,
    maxRows,
    disabled,
    readOnly,
    error,
    description,
    secondary,
    attachmentSize = "sm",
    onSubmit,
    onStop,
    onRetry,
  },
  ref,
) {
  const fileCounter = useRef(0);
  const objectUrls = useRef(/* @__PURE__ */ new Map());
  const pendingUrls = useRef(/* @__PURE__ */ new Map());
  const acknowledgedFiles = useRef(/* @__PURE__ */ new WeakMap());
  const mounted = useRef(true);
  const [files, setFiles] = useState3(defaultAttachments);
  const filesRef = useRef(files);
  const [model, setModel] = useState3(MODEL_OPTIONS[0].value);
  useEffect2(() => {
    mounted.current = true;
    return () => {
      mounted.current = false;
      for (const url of objectUrls.current.values()) URL.revokeObjectURL(url);
      objectUrls.current.clear();
      pendingUrls.current.clear();
      acknowledgedFiles.current = /* @__PURE__ */ new WeakMap();
    };
  }, []);
  const updateFiles = (next) => {
    const resolved = typeof next === "function" ? next(filesRef.current) : next;
    filesRef.current = resolved;
    setFiles(resolved);
  };
  const releaseUrl = (file) => {
    if (!file.url || pendingUrls.current.has(file.id)) return;
    const url = objectUrls.current.get(file.id);
    if (url) {
      objectUrls.current.delete(file.id);
      URL.revokeObjectURL(url);
    }
  };
  const remove = (file) => {
    updateFiles((current) => current.filter((item) => item.id !== file.id));
    releaseUrl(file);
  };
  const submit = async (submission) => {
    const submittedIds = new Set(submission.attachments.map((file) => file.id));
    const submittedFiles = new Map(
      filesRef.current
        .filter((file) => submittedIds.has(file.id))
        .map((file) => [file.id, file]),
    );
    for (const file of submission.attachments) {
      if (file.url) pendingUrls.current.set(file.id, file.url);
    }
    try {
      await onSubmit(submission, {
        model,
      });
      for (const id of submittedIds) pendingUrls.current.delete(id);
      if (!mounted.current) return;
      for (const [id, file] of submittedFiles) {
        if (!filesRef.current.some((item) => item.id === id)) releaseUrl(file);
      }
      acknowledgedFiles.current.set(submission, submittedFiles);
    } catch (error2) {
      for (const file of submission.attachments) {
        pendingUrls.current.delete(file.id);
        const captured = submittedFiles.get(file.id) ?? file;
        if (!filesRef.current.some((current) => current.id === file.id))
          releaseUrl(captured);
      }
      throw error2;
    }
  };
  const submitted = (submission) => {
    const captured = acknowledgedFiles.current.get(submission);
    acknowledgedFiles.current.delete(submission);
    if (!captured || !mounted.current) return;
    updateFiles((current) => current.filter((file) => !captured.has(file.id)));
  };
  return (
    <FileUpload.Root
      multiple
      disabled={disabled || readOnly}
      aria-label="Message files"
      onFilesSelect={({ accepted }) => {
        const selected = accepted.map((file) => {
          fileCounter.current += 1;
          const previewable =
            /^(image\/(png|jpeg|webp|gif|avif)|application\/pdf|text\/(plain|csv))$/.test(
              file.type,
            );
          const url =
            previewable && typeof URL.createObjectURL === "function"
              ? URL.createObjectURL(file)
              : undefined;
          if (url)
            objectUrls.current.set(`local-file-${fileCounter.current}`, url);
          return fileFromNative(file, `local-file-${fileCounter.current}`, url);
        });
        if (selected.length)
          updateFiles((current) => [...current, ...selected]);
      }}
    >
      <Composer
        ref={ref}
        defaultValue={defaultValue}
        value={value}
        onValueChange={onValueChange}
        attachments={files}
        status={status}
        feedbackPlacement={feedbackPlacement}
        initialRows={initialRows}
        maxRows={maxRows}
        disabled={disabled}
        readOnly={readOnly}
        error={error}
        description={description}
        onStop={onStop}
        onRetry={onRetry}
        onSubmit={submit}
        onSubmitted={submitted}
        secondary={secondary}
        attachmentContent={
          <ComposerAttachments size={attachmentSize} onRemove={remove} />
        }
      >
        <ComposerInput placeholder="Ask a follow-up…" />
        <ComposerToolbar>
          <ComposerToolbar.Start>
            <FileUpload.Trigger
              render={
                <ComposerAction aria-label="Attach files" icon={<Plus />} />
              }
            />
          </ComposerToolbar.Start>
          <ComposerToolbar.End>
            <ModelSelect
              disabled={disabled || readOnly}
              value={model}
              onValueChange={(value2) => {
                if (value2) setModel(value2);
              }}
            />
            <ComposerSubmit />
          </ComposerToolbar.End>
        </ComposerToolbar>
        <FileUpload.Input />
      </Composer>
    </FileUpload.Root>
  );
});

var weekly = [
  {
    id: "gather",
    label: "Gather changes",
    status: "complete",
  },
  {
    id: "draft",
    label: "Draft summary",
    status: "active",
  },
  {
    id: "review",
    label: "Review next steps",
    status: "pending",
  },
];

```

todo-list-inside-composer-10.css

```css
/* apps/web/src/demos/library/model-select.css */
.model-select__trigger {
  gap: var(--space-2);
  min-inline-size: 0;
  max-inline-size: calc(100vw - (var(--space-4) * 2));
}
.ui-popup.ui-select-popup.model-select__popup {
  max-inline-size: calc(100vw - (var(--space-4) * 2));
}
.ui-select-trigger.model-select__trigger[data-compact] {
  max-inline-size: min(100%, 272px, calc(100vw - (var(--space-4) * 2)));
}

```

#### Outside composer

The list is a bare tree. The surrounding page supplies the surface, so no card wrapper is added.

todo-list-outside-composer-11.jsx

```jsx
import { useEffect, useId, useState } from "react";
import {
  Activity,
  ActivityLine,
  ActivityTitle,
} from "@/components/ui/activity";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
  Conversation,
  ConversationContent,
  ConversationItem,
} from "@/components/ui/conversation";
import { Ellipsis } from "@/components/ui/loader";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageFooter,
  MessageHeader,
} from "@/components/ui/message";
import { MessageParts } from "@/components/ui/message-parts";
import { TodoList } from "@/components/ui/todo-list";
import {
  forwardRef,
  useEffect as useEffect2,
  useRef,
  useState as useState3,
} from "react";
import { Plus } from "lucide-react";
import {
  Composer,
  ComposerAction,
  ComposerAttachments,
  ComposerInput,
  ComposerSubmit,
  ComposerToolbar,
} from "@/components/ui/composer";
import { FileUpload } from "@/components/ui/file-upload";
import { useState as useState2 } from "react";
import { Check, ChevronDown } from "lucide-react";
import { Select } from "@/components/ui/select";
import { TooltipHint } from "@/components/ui/tooltip";

export default function Example() {
  return (
    <ActivityDemoTurn
      prompt="Draft the weekly update."
      answer="The weekly plan stays above the draft editor."
      composer={
        <div
          style={{
            display: "grid",
            gap: "var(--space-4)",
          }}
        >
          <TodoList title="Weekly update" items={weekly} />
          <ChatComposer onSubmit={() => undefined} />
        </div>
      }
    >
      {null}
    </ActivityDemoTurn>
  );
}

var user = {
  id: "user",
  name: "You",
  kind: "human",
};

var activityAgent = {
  id: "release-assistant",
  name: "Release assistant",
  kind: "agent",
};

var participants = [user, activityAgent];

function ThinkingActivity() {
  return (
    <Activity status="active">
      <ActivityLine state="active">
        <ActivityTitle>
          Thinking
          <Ellipsis />
        </ActivityTitle>
      </ActivityLine>
    </Activity>
  );
}

function ActivityConversationTurn({
  prompt,
  response,
  children,
  composer,
  footer,
  renderers,
  onReplay,
  pendingIndicator,
  participants: roster = participants,
}) {
  const turnId = useId();
  const request = {
    id: `${turnId}-prompt`,
    actor: "user",
    author: user,
    parts: [
      {
        type: "text",
        text: prompt,
      },
    ],
  };
  const hasActivity = response.parts.some((part) => part.type === "activity");
  const thinking =
    response.status === "streaming" &&
    !children &&
    !response.parts.some(
      (part) => part.type !== "text" || part.text.length > 0,
    );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-4)",
        width: 560,
        maxWidth: "100%",
      }}
    >
      <Conversation
        label="Activity conversation"
        currentUserId={user.id}
        participants={roster}
        initialPosition="start"
        follow="never"
        style={{
          "--conversation-height": "auto",
        }}
      >
        <ConversationContent>
          <ConversationItem id={request.id} message={request}>
            <Message actor="user">
              <MessageBody>
                <MessageParts parts={request.parts} />
              </MessageBody>
            </Message>
          </ConversationItem>
          <ConversationItem id={`${turnId}-response`} message={response}>
            <Message
              actor="assistant"
              status={response.status}
              className="ui-activity-demo-message"
            >
              <MessageAvatar
                style={
                  hasActivity
                    ? {
                        marginBlockStart:
                          "calc((var(--space-8) - var(--space-6)) / 2)",
                      }
                    : undefined
                }
              >
                <Avatar
                  name={response.author?.name ?? activityAgent.name}
                  kind="agent"
                  seed={response.author?.id ?? activityAgent.id}
                  aria-hidden="true"
                />
              </MessageAvatar>
              <MessageContent>
                {!hasActivity ? (
                  <MessageHeader>
                    {response.author?.name ?? activityAgent.name}
                  </MessageHeader>
                ) : null}
                <MessageBody>
                  <div
                    style={{
                      display: "grid",
                      gridTemplateColumns: "minmax(0, 1fr)",
                      gap: "var(--space-2)",
                    }}
                  >
                    {thinking ? undefined : null}
                    {children}
                    <MessageParts
                      parts={response.parts}
                      renderers={renderers}
                      activityLabel={
                        hasActivity && roster.length > 2 ? (
                          <MessageHeader render={<ActivityTitle />}>
                            {response.author?.name ?? activityAgent.name}
                          </MessageHeader>
                        ) : undefined
                      }
                    />
                  </div>
                </MessageBody>
                <MessageFooter>
                  {footer}
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onReplay}
                  >
                    Replay
                  </Button>
                </MessageFooter>
              </MessageContent>
            </Message>
          </ConversationItem>
        </ConversationContent>
      </Conversation>
      {composer}
    </div>
  );
}

function ActivityPlayback({
  prompt,
  answer,
  children,
  composer,
  footer,
  renderers,
  workDuration = 1200,
  onReplay,
  participants: participants2,
  parts = [],
  pendingIndicator,
}) {
  const [run, setRun] = useState(0);
  const [tick, setTick] = useState(0);
  const [reduced, setReduced] = useState(false);
  const answerAt = 15 + Math.ceil(workDuration / 40);
  const end = answerAt + Math.ceil(answer.length / 2);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    const update = () => setReduced(query.matches);
    update();
    query.addEventListener("change", update);
    return () => query.removeEventListener("change", update);
  }, []);
  useEffect(() => {
    if (reduced || tick >= end) return;
    const timer = window.setTimeout(() => setTick((value) => value + 1), 40);
    return () => window.clearTimeout(timer);
  }, [tick, end, reduced]);
  const thinking = !reduced && tick < 15;
  const text = reduced
    ? answer
    : answer.slice(0, Math.max(0, (tick - answerAt) * 2));
  const done = reduced || tick >= end;
  const progress = reduced
    ? 1
    : Math.min(1, Math.max(0, (tick - 15) / Math.max(1, answerAt - 15)));
  const inlineActivity = parts.some((part) => part.type === "activity");
  const visibleParts = thinking
    ? parts
        .filter((part) => part.type === "activity")
        .map((part) => ({
          ...part,
          event: {
            ...part.event,
            state: "active",
            label: "is thinking",
            meta: undefined,
            description: undefined,
            children: undefined,
          },
        }))
    : parts;
  const response = {
    id: "activity-response",
    actor: "assistant",
    author: activityAgent,
    status: done ? "complete" : "streaming",
    parts: [
      ...visibleParts,
      {
        type: "text",
        id: "answer",
        text,
        state: done ? "complete" : "streaming",
      },
    ],
  };
  return (
    <div
      data-activity-playback={
        thinking ? "thinking" : done ? "complete" : "streaming"
      }
    >
      <ActivityConversationTurn
        prompt={prompt}
        response={response}
        composer={composer}
        footer={done ? footer : null}
        renderers={renderers}
        participants={participants2}
        onReplay={() => {
          onReplay?.();
          setRun((value) => value + 1);
          setTick(0);
        }}
      >
        {thinking && !inlineActivity ? pendingIndicator : null}
        <div key={run} hidden={thinking}>
          {typeof children === "function" ? children(progress) : children}
        </div>
      </ActivityConversationTurn>
    </div>
  );
}

function ActivityDemoTurn(props) {
  return (
    <ActivityPlayback {...props} pendingIndicator={<ThinkingActivity />} />
  );
}

var MODEL_OPTIONS = [
  {
    value: "chatgpt-sol-6-1",
    label: "Sol 6.1",
  },
  {
    value: "chatgpt-sol-6",
    label: "Sol 6",
  },
  {
    value: "chatgpt-luna-6",
    label: "Luna 6",
  },
];

function ModelSelect({
  disabled,
  value: controlledValue,
  onValueChange,
  options = MODEL_OPTIONS,
} = {}) {
  const [uncontrolledValue, setUncontrolledValue] = useState2(
    () => options.find((item) => !item.disabled)?.value ?? null,
  );
  const value =
    controlledValue === undefined ? uncontrolledValue : controlledValue;
  const fullLabel =
    options.find((item) => item.value === value)?.label ?? "Choose a model";
  const change = (next) => {
    if (controlledValue === undefined && next) setUncontrolledValue(next);
    onValueChange?.(next);
  };
  return (
    <Select.Root
      items={options}
      value={value}
      onValueChange={change}
      disabled={disabled}
    >
      <TooltipHint content={fullLabel}>
        <Select.Trigger
          compact
          variant="ghost"
          className="model-select__trigger"
          aria-label="Model"
          aria-description={fullLabel}
        >
          <Select.Value placeholder="Choose a model" />
          <Select.Icon>
            <ChevronDown size={14} aria-hidden="true" />
          </Select.Icon>
        </Select.Trigger>
      </TooltipHint>
      <Select.Portal>
        <Select.Positioner>
          <Select.Popup className="model-select__popup" aria-label="Models">
            {options.map((item) => (
              <Select.Item
                key={item.value}
                value={item.value}
                disabled={item.disabled}
              >
                <Select.ItemText>{item.label}</Select.ItemText>
                <Select.ItemIndicator>
                  <Check size={14} aria-hidden="true" />
                </Select.ItemIndicator>
              </Select.Item>
            ))}
          </Select.Popup>
        </Select.Positioner>
      </Select.Portal>
    </Select.Root>
  );
}

function fileFromNative(file, id, url) {
  return {
    id,
    name: file.name,
    mediaType: file.type || undefined,
    size: file.size,
    url,
    status: "ready",
  };
}

var ChatComposer = forwardRef(function ChatComposer2(
  {
    defaultValue = "",
    defaultAttachments = [],
    value,
    onValueChange,
    status = "ready",
    feedbackPlacement = "inline",
    initialRows,
    maxRows,
    disabled,
    readOnly,
    error,
    description,
    secondary,
    attachmentSize = "sm",
    onSubmit,
    onStop,
    onRetry,
  },
  ref,
) {
  const fileCounter = useRef(0);
  const objectUrls = useRef(/* @__PURE__ */ new Map());
  const pendingUrls = useRef(/* @__PURE__ */ new Map());
  const acknowledgedFiles = useRef(/* @__PURE__ */ new WeakMap());
  const mounted = useRef(true);
  const [files, setFiles] = useState3(defaultAttachments);
  const filesRef = useRef(files);
  const [model, setModel] = useState3(MODEL_OPTIONS[0].value);
  useEffect2(() => {
    mounted.current = true;
    return () => {
      mounted.current = false;
      for (const url of objectUrls.current.values()) URL.revokeObjectURL(url);
      objectUrls.current.clear();
      pendingUrls.current.clear();
      acknowledgedFiles.current = /* @__PURE__ */ new WeakMap();
    };
  }, []);
  const updateFiles = (next) => {
    const resolved = typeof next === "function" ? next(filesRef.current) : next;
    filesRef.current = resolved;
    setFiles(resolved);
  };
  const releaseUrl = (file) => {
    if (!file.url || pendingUrls.current.has(file.id)) return;
    const url = objectUrls.current.get(file.id);
    if (url) {
      objectUrls.current.delete(file.id);
      URL.revokeObjectURL(url);
    }
  };
  const remove = (file) => {
    updateFiles((current) => current.filter((item) => item.id !== file.id));
    releaseUrl(file);
  };
  const submit = async (submission) => {
    const submittedIds = new Set(submission.attachments.map((file) => file.id));
    const submittedFiles = new Map(
      filesRef.current
        .filter((file) => submittedIds.has(file.id))
        .map((file) => [file.id, file]),
    );
    for (const file of submission.attachments) {
      if (file.url) pendingUrls.current.set(file.id, file.url);
    }
    try {
      await onSubmit(submission, {
        model,
      });
      for (const id of submittedIds) pendingUrls.current.delete(id);
      if (!mounted.current) return;
      for (const [id, file] of submittedFiles) {
        if (!filesRef.current.some((item) => item.id === id)) releaseUrl(file);
      }
      acknowledgedFiles.current.set(submission, submittedFiles);
    } catch (error2) {
      for (const file of submission.attachments) {
        pendingUrls.current.delete(file.id);
        const captured = submittedFiles.get(file.id) ?? file;
        if (!filesRef.current.some((current) => current.id === file.id))
          releaseUrl(captured);
      }
      throw error2;
    }
  };
  const submitted = (submission) => {
    const captured = acknowledgedFiles.current.get(submission);
    acknowledgedFiles.current.delete(submission);
    if (!captured || !mounted.current) return;
    updateFiles((current) => current.filter((file) => !captured.has(file.id)));
  };
  return (
    <FileUpload.Root
      multiple
      disabled={disabled || readOnly}
      aria-label="Message files"
      onFilesSelect={({ accepted }) => {
        const selected = accepted.map((file) => {
          fileCounter.current += 1;
          const previewable =
            /^(image\/(png|jpeg|webp|gif|avif)|application\/pdf|text\/(plain|csv))$/.test(
              file.type,
            );
          const url =
            previewable && typeof URL.createObjectURL === "function"
              ? URL.createObjectURL(file)
              : undefined;
          if (url)
            objectUrls.current.set(`local-file-${fileCounter.current}`, url);
          return fileFromNative(file, `local-file-${fileCounter.current}`, url);
        });
        if (selected.length)
          updateFiles((current) => [...current, ...selected]);
      }}
    >
      <Composer
        ref={ref}
        defaultValue={defaultValue}
        value={value}
        onValueChange={onValueChange}
        attachments={files}
        status={status}
        feedbackPlacement={feedbackPlacement}
        initialRows={initialRows}
        maxRows={maxRows}
        disabled={disabled}
        readOnly={readOnly}
        error={error}
        description={description}
        onStop={onStop}
        onRetry={onRetry}
        onSubmit={submit}
        onSubmitted={submitted}
        secondary={secondary}
        attachmentContent={
          <ComposerAttachments size={attachmentSize} onRemove={remove} />
        }
      >
        <ComposerInput placeholder="Ask a follow-up…" />
        <ComposerToolbar>
          <ComposerToolbar.Start>
            <FileUpload.Trigger
              render={
                <ComposerAction aria-label="Attach files" icon={<Plus />} />
              }
            />
          </ComposerToolbar.Start>
          <ComposerToolbar.End>
            <ModelSelect
              disabled={disabled || readOnly}
              value={model}
              onValueChange={(value2) => {
                if (value2) setModel(value2);
              }}
            />
            <ComposerSubmit />
          </ComposerToolbar.End>
        </ComposerToolbar>
        <FileUpload.Input />
      </Composer>
    </FileUpload.Root>
  );
});

var weekly = [
  {
    id: "gather",
    label: "Gather changes",
    status: "complete",
  },
  {
    id: "draft",
    label: "Draft summary",
    status: "active",
  },
  {
    id: "review",
    label: "Review next steps",
    status: "pending",
  },
];

```

todo-list-outside-composer-11.css

```css
/* apps/web/src/demos/library/model-select.css */
.model-select__trigger {
  gap: var(--space-2);
  min-inline-size: 0;
  max-inline-size: calc(100vw - (var(--space-4) * 2));
}
.ui-popup.ui-select-popup.model-select__popup {
  max-inline-size: calc(100vw - (var(--space-4) * 2));
}
.ui-select-trigger.model-select__trigger[data-compact] {
  max-inline-size: min(100%, 272px, calc(100vw - (var(--space-4) * 2)));
}

```

##### Transcript plan

Use the same list in a transcript without a Composer surface.

todo-list-transcript-plan-12.jsx

```jsx
import { useEffect, useId, useState } from "react";
import {
  Activity,
  ActivityLine,
  ActivityTitle,
} from "@/components/ui/activity";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
  Conversation,
  ConversationContent,
  ConversationItem,
} from "@/components/ui/conversation";
import { Ellipsis } from "@/components/ui/loader";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageFooter,
  MessageHeader,
} from "@/components/ui/message";
import { MessageParts } from "@/components/ui/message-parts";
import { TodoList } from "@/components/ui/todo-list";

export default function Example() {
  return (
    <ActivityDemoTurn
      prompt="Plan the rollout."
      answer="The rollout plan keeps its steps and subtasks together."
    >
      <TodoList title="Rollout plan" items={weekly} defaultOpen />
    </ActivityDemoTurn>
  );
}

var user = {
  id: "user",
  name: "You",
  kind: "human",
};

var activityAgent = {
  id: "release-assistant",
  name: "Release assistant",
  kind: "agent",
};

var participants = [user, activityAgent];

function ThinkingActivity() {
  return (
    <Activity status="active">
      <ActivityLine state="active">
        <ActivityTitle>
          Thinking
          <Ellipsis />
        </ActivityTitle>
      </ActivityLine>
    </Activity>
  );
}

function ActivityConversationTurn({
  prompt,
  response,
  children,
  composer,
  footer,
  renderers,
  onReplay,
  pendingIndicator,
  participants: roster = participants,
}) {
  const turnId = useId();
  const request = {
    id: `${turnId}-prompt`,
    actor: "user",
    author: user,
    parts: [
      {
        type: "text",
        text: prompt,
      },
    ],
  };
  const hasActivity = response.parts.some((part) => part.type === "activity");
  const thinking =
    response.status === "streaming" &&
    !children &&
    !response.parts.some(
      (part) => part.type !== "text" || part.text.length > 0,
    );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-4)",
        width: 560,
        maxWidth: "100%",
      }}
    >
      <Conversation
        label="Activity conversation"
        currentUserId={user.id}
        participants={roster}
        initialPosition="start"
        follow="never"
        style={{
          "--conversation-height": "auto",
        }}
      >
        <ConversationContent>
          <ConversationItem id={request.id} message={request}>
            <Message actor="user">
              <MessageBody>
                <MessageParts parts={request.parts} />
              </MessageBody>
            </Message>
          </ConversationItem>
          <ConversationItem id={`${turnId}-response`} message={response}>
            <Message
              actor="assistant"
              status={response.status}
              className="ui-activity-demo-message"
            >
              <MessageAvatar
                style={
                  hasActivity
                    ? {
                        marginBlockStart:
                          "calc((var(--space-8) - var(--space-6)) / 2)",
                      }
                    : undefined
                }
              >
                <Avatar
                  name={response.author?.name ?? activityAgent.name}
                  kind="agent"
                  seed={response.author?.id ?? activityAgent.id}
                  aria-hidden="true"
                />
              </MessageAvatar>
              <MessageContent>
                {!hasActivity ? (
                  <MessageHeader>
                    {response.author?.name ?? activityAgent.name}
                  </MessageHeader>
                ) : null}
                <MessageBody>
                  <div
                    style={{
                      display: "grid",
                      gridTemplateColumns: "minmax(0, 1fr)",
                      gap: "var(--space-2)",
                    }}
                  >
                    {thinking ? undefined : null}
                    {children}
                    <MessageParts
                      parts={response.parts}
                      renderers={renderers}
                      activityLabel={
                        hasActivity && roster.length > 2 ? (
                          <MessageHeader render={<ActivityTitle />}>
                            {response.author?.name ?? activityAgent.name}
                          </MessageHeader>
                        ) : undefined
                      }
                    />
                  </div>
                </MessageBody>
                <MessageFooter>
                  {footer}
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onReplay}
                  >
                    Replay
                  </Button>
                </MessageFooter>
              </MessageContent>
            </Message>
          </ConversationItem>
        </ConversationContent>
      </Conversation>
      {composer}
    </div>
  );
}

function ActivityPlayback({
  prompt,
  answer,
  children,
  composer,
  footer,
  renderers,
  workDuration = 1200,
  onReplay,
  participants: participants2,
  parts = [],
  pendingIndicator,
}) {
  const [run, setRun] = useState(0);
  const [tick, setTick] = useState(0);
  const [reduced, setReduced] = useState(false);
  const answerAt = 15 + Math.ceil(workDuration / 40);
  const end = answerAt + Math.ceil(answer.length / 2);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    const update = () => setReduced(query.matches);
    update();
    query.addEventListener("change", update);
    return () => query.removeEventListener("change", update);
  }, []);
  useEffect(() => {
    if (reduced || tick >= end) return;
    const timer = window.setTimeout(() => setTick((value) => value + 1), 40);
    return () => window.clearTimeout(timer);
  }, [tick, end, reduced]);
  const thinking = !reduced && tick < 15;
  const text = reduced
    ? answer
    : answer.slice(0, Math.max(0, (tick - answerAt) * 2));
  const done = reduced || tick >= end;
  const progress = reduced
    ? 1
    : Math.min(1, Math.max(0, (tick - 15) / Math.max(1, answerAt - 15)));
  const inlineActivity = parts.some((part) => part.type === "activity");
  const visibleParts = thinking
    ? parts
        .filter((part) => part.type === "activity")
        .map((part) => ({
          ...part,
          event: {
            ...part.event,
            state: "active",
            label: "is thinking",
            meta: undefined,
            description: undefined,
            children: undefined,
          },
        }))
    : parts;
  const response = {
    id: "activity-response",
    actor: "assistant",
    author: activityAgent,
    status: done ? "complete" : "streaming",
    parts: [
      ...visibleParts,
      {
        type: "text",
        id: "answer",
        text,
        state: done ? "complete" : "streaming",
      },
    ],
  };
  return (
    <div
      data-activity-playback={
        thinking ? "thinking" : done ? "complete" : "streaming"
      }
    >
      <ActivityConversationTurn
        prompt={prompt}
        response={response}
        composer={composer}
        footer={done ? footer : null}
        renderers={renderers}
        participants={participants2}
        onReplay={() => {
          onReplay?.();
          setRun((value) => value + 1);
          setTick(0);
        }}
      >
        {thinking && !inlineActivity ? pendingIndicator : null}
        <div key={run} hidden={thinking}>
          {typeof children === "function" ? children(progress) : children}
        </div>
      </ActivityConversationTurn>
    </div>
  );
}

function ActivityDemoTurn(props) {
  return (
    <ActivityPlayback {...props} pendingIndicator={<ThinkingActivity />} />
  );
}

var weekly = [
  {
    id: "gather",
    label: "Gather changes",
    status: "complete",
  },
  {
    id: "draft",
    label: "Draft summary",
    status: "active",
  },
  {
    id: "review",
    label: "Review next steps",
    status: "pending",
  },
];

```

#### Inside activity

A plan inside a larger run is a child node. The parent Activity owns the branch rail; the plan adds one level of tasks beneath it.

todo-list-inside-activity-13.jsx

```jsx
import { useEffect, useId, useState } from "react";
import {
  Activity,
  ActivityLine,
  ActivityTitle,
} from "@/components/ui/activity";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
  Conversation,
  ConversationContent,
  ConversationItem,
} from "@/components/ui/conversation";
import { Ellipsis } from "@/components/ui/loader";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageFooter,
  MessageHeader,
} from "@/components/ui/message";
import { MessageParts } from "@/components/ui/message-parts";
import { TodoList } from "@/components/ui/todo-list";
import {
  Activity as Activity2,
  ActivitySummary,
  ActivityContent,
} from "@/components/ui/activity";

export default function Example() {
  return (
    <ActivityDemoTurn
      prompt="Prepare the weekly update."
      answer="The recorded steps are shown above for review."
    >
      <Activity2 defaultOpen status="active">
        <ActivitySummary state="active">
          Preparing the weekly update
        </ActivitySummary>
        <ActivityContent>
          <TodoList title="Weekly update" items={weekly} defaultOpen />
        </ActivityContent>
      </Activity2>
    </ActivityDemoTurn>
  );
}

var user = {
  id: "user",
  name: "You",
  kind: "human",
};

var activityAgent = {
  id: "release-assistant",
  name: "Release assistant",
  kind: "agent",
};

var participants = [user, activityAgent];

function ThinkingActivity() {
  return (
    <Activity status="active">
      <ActivityLine state="active">
        <ActivityTitle>
          Thinking
          <Ellipsis />
        </ActivityTitle>
      </ActivityLine>
    </Activity>
  );
}

function ActivityConversationTurn({
  prompt,
  response,
  children,
  composer,
  footer,
  renderers,
  onReplay,
  pendingIndicator,
  participants: roster = participants,
}) {
  const turnId = useId();
  const request = {
    id: `${turnId}-prompt`,
    actor: "user",
    author: user,
    parts: [
      {
        type: "text",
        text: prompt,
      },
    ],
  };
  const hasActivity = response.parts.some((part) => part.type === "activity");
  const thinking =
    response.status === "streaming" &&
    !children &&
    !response.parts.some(
      (part) => part.type !== "text" || part.text.length > 0,
    );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-4)",
        width: 560,
        maxWidth: "100%",
      }}
    >
      <Conversation
        label="Activity conversation"
        currentUserId={user.id}
        participants={roster}
        initialPosition="start"
        follow="never"
        style={{
          "--conversation-height": "auto",
        }}
      >
        <ConversationContent>
          <ConversationItem id={request.id} message={request}>
            <Message actor="user">
              <MessageBody>
                <MessageParts parts={request.parts} />
              </MessageBody>
            </Message>
          </ConversationItem>
          <ConversationItem id={`${turnId}-response`} message={response}>
            <Message
              actor="assistant"
              status={response.status}
              className="ui-activity-demo-message"
            >
              <MessageAvatar
                style={
                  hasActivity
                    ? {
                        marginBlockStart:
                          "calc((var(--space-8) - var(--space-6)) / 2)",
                      }
                    : undefined
                }
              >
                <Avatar
                  name={response.author?.name ?? activityAgent.name}
                  kind="agent"
                  seed={response.author?.id ?? activityAgent.id}
                  aria-hidden="true"
                />
              </MessageAvatar>
              <MessageContent>
                {!hasActivity ? (
                  <MessageHeader>
                    {response.author?.name ?? activityAgent.name}
                  </MessageHeader>
                ) : null}
                <MessageBody>
                  <div
                    style={{
                      display: "grid",
                      gridTemplateColumns: "minmax(0, 1fr)",
                      gap: "var(--space-2)",
                    }}
                  >
                    {thinking ? undefined : null}
                    {children}
                    <MessageParts
                      parts={response.parts}
                      renderers={renderers}
                      activityLabel={
                        hasActivity && roster.length > 2 ? (
                          <MessageHeader render={<ActivityTitle />}>
                            {response.author?.name ?? activityAgent.name}
                          </MessageHeader>
                        ) : undefined
                      }
                    />
                  </div>
                </MessageBody>
                <MessageFooter>
                  {footer}
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onReplay}
                  >
                    Replay
                  </Button>
                </MessageFooter>
              </MessageContent>
            </Message>
          </ConversationItem>
        </ConversationContent>
      </Conversation>
      {composer}
    </div>
  );
}

function ActivityPlayback({
  prompt,
  answer,
  children,
  composer,
  footer,
  renderers,
  workDuration = 1200,
  onReplay,
  participants: participants2,
  parts = [],
  pendingIndicator,
}) {
  const [run, setRun] = useState(0);
  const [tick, setTick] = useState(0);
  const [reduced, setReduced] = useState(false);
  const answerAt = 15 + Math.ceil(workDuration / 40);
  const end = answerAt + Math.ceil(answer.length / 2);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    const update = () => setReduced(query.matches);
    update();
    query.addEventListener("change", update);
    return () => query.removeEventListener("change", update);
  }, []);
  useEffect(() => {
    if (reduced || tick >= end) return;
    const timer = window.setTimeout(() => setTick((value) => value + 1), 40);
    return () => window.clearTimeout(timer);
  }, [tick, end, reduced]);
  const thinking = !reduced && tick < 15;
  const text = reduced
    ? answer
    : answer.slice(0, Math.max(0, (tick - answerAt) * 2));
  const done = reduced || tick >= end;
  const progress = reduced
    ? 1
    : Math.min(1, Math.max(0, (tick - 15) / Math.max(1, answerAt - 15)));
  const inlineActivity = parts.some((part) => part.type === "activity");
  const visibleParts = thinking
    ? parts
        .filter((part) => part.type === "activity")
        .map((part) => ({
          ...part,
          event: {
            ...part.event,
            state: "active",
            label: "is thinking",
            meta: undefined,
            description: undefined,
            children: undefined,
          },
        }))
    : parts;
  const response = {
    id: "activity-response",
    actor: "assistant",
    author: activityAgent,
    status: done ? "complete" : "streaming",
    parts: [
      ...visibleParts,
      {
        type: "text",
        id: "answer",
        text,
        state: done ? "complete" : "streaming",
      },
    ],
  };
  return (
    <div
      data-activity-playback={
        thinking ? "thinking" : done ? "complete" : "streaming"
      }
    >
      <ActivityConversationTurn
        prompt={prompt}
        response={response}
        composer={composer}
        footer={done ? footer : null}
        renderers={renderers}
        participants={participants2}
        onReplay={() => {
          onReplay?.();
          setRun((value) => value + 1);
          setTick(0);
        }}
      >
        {thinking && !inlineActivity ? pendingIndicator : null}
        <div key={run} hidden={thinking}>
          {typeof children === "function" ? children(progress) : children}
        </div>
      </ActivityConversationTurn>
    </div>
  );
}

function ActivityDemoTurn(props) {
  return (
    <ActivityPlayback {...props} pendingIndicator={<ThinkingActivity />} />
  );
}

var weekly = [
  {
    id: "gather",
    label: "Gather changes",
    status: "complete",
  },
  {
    id: "draft",
    label: "Draft summary",
    status: "active",
  },
  {
    id: "review",
    label: "Review next steps",
    status: "pending",
  },
];

```

#### Grouped queue

Partition the same task records into status groups. The queue summary keeps one completion count; each group is a child node and its tasks are grandchildren on their own rail.

todo-list-grouped-queue-14.jsx

```jsx
import { useEffect, useId, useState } from "react";
import {
  Activity,
  ActivityLine,
  ActivityTitle,
} from "@/components/ui/activity";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
  Conversation,
  ConversationContent,
  ConversationItem,
} from "@/components/ui/conversation";
import { Ellipsis } from "@/components/ui/loader";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageFooter,
  MessageHeader,
} from "@/components/ui/message";
import { MessageParts } from "@/components/ui/message-parts";
import { TodoList } from "@/components/ui/todo-list";

export default function Example() {
  const groups = [
    {
      id: "remaining",
      title: "To do",
      items: weekly.filter((item) => item.status !== "complete"),
    },
    {
      id: "completed",
      title: "Completed",
      items: weekly.filter((item) => item.status === "complete"),
    },
  ];
  return (
    <ActivityDemoTurn
      prompt="Work through the release."
      answer="Gathered changes are complete. The draft and review remain in the queue."
    >
      <TodoList title="Release work queue" groups={groups} defaultOpen />
    </ActivityDemoTurn>
  );
}

var user = {
  id: "user",
  name: "You",
  kind: "human",
};

var activityAgent = {
  id: "release-assistant",
  name: "Release assistant",
  kind: "agent",
};

var participants = [user, activityAgent];

function ThinkingActivity() {
  return (
    <Activity status="active">
      <ActivityLine state="active">
        <ActivityTitle>
          Thinking
          <Ellipsis />
        </ActivityTitle>
      </ActivityLine>
    </Activity>
  );
}

function ActivityConversationTurn({
  prompt,
  response,
  children,
  composer,
  footer,
  renderers,
  onReplay,
  pendingIndicator,
  participants: roster = participants,
}) {
  const turnId = useId();
  const request = {
    id: `${turnId}-prompt`,
    actor: "user",
    author: user,
    parts: [
      {
        type: "text",
        text: prompt,
      },
    ],
  };
  const hasActivity = response.parts.some((part) => part.type === "activity");
  const thinking =
    response.status === "streaming" &&
    !children &&
    !response.parts.some(
      (part) => part.type !== "text" || part.text.length > 0,
    );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-4)",
        width: 560,
        maxWidth: "100%",
      }}
    >
      <Conversation
        label="Activity conversation"
        currentUserId={user.id}
        participants={roster}
        initialPosition="start"
        follow="never"
        style={{
          "--conversation-height": "auto",
        }}
      >
        <ConversationContent>
          <ConversationItem id={request.id} message={request}>
            <Message actor="user">
              <MessageBody>
                <MessageParts parts={request.parts} />
              </MessageBody>
            </Message>
          </ConversationItem>
          <ConversationItem id={`${turnId}-response`} message={response}>
            <Message
              actor="assistant"
              status={response.status}
              className="ui-activity-demo-message"
            >
              <MessageAvatar
                style={
                  hasActivity
                    ? {
                        marginBlockStart:
                          "calc((var(--space-8) - var(--space-6)) / 2)",
                      }
                    : undefined
                }
              >
                <Avatar
                  name={response.author?.name ?? activityAgent.name}
                  kind="agent"
                  seed={response.author?.id ?? activityAgent.id}
                  aria-hidden="true"
                />
              </MessageAvatar>
              <MessageContent>
                {!hasActivity ? (
                  <MessageHeader>
                    {response.author?.name ?? activityAgent.name}
                  </MessageHeader>
                ) : null}
                <MessageBody>
                  <div
                    style={{
                      display: "grid",
                      gridTemplateColumns: "minmax(0, 1fr)",
                      gap: "var(--space-2)",
                    }}
                  >
                    {thinking ? undefined : null}
                    {children}
                    <MessageParts
                      parts={response.parts}
                      renderers={renderers}
                      activityLabel={
                        hasActivity && roster.length > 2 ? (
                          <MessageHeader render={<ActivityTitle />}>
                            {response.author?.name ?? activityAgent.name}
                          </MessageHeader>
                        ) : undefined
                      }
                    />
                  </div>
                </MessageBody>
                <MessageFooter>
                  {footer}
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onReplay}
                  >
                    Replay
                  </Button>
                </MessageFooter>
              </MessageContent>
            </Message>
          </ConversationItem>
        </ConversationContent>
      </Conversation>
      {composer}
    </div>
  );
}

function ActivityPlayback({
  prompt,
  answer,
  children,
  composer,
  footer,
  renderers,
  workDuration = 1200,
  onReplay,
  participants: participants2,
  parts = [],
  pendingIndicator,
}) {
  const [run, setRun] = useState(0);
  const [tick, setTick] = useState(0);
  const [reduced, setReduced] = useState(false);
  const answerAt = 15 + Math.ceil(workDuration / 40);
  const end = answerAt + Math.ceil(answer.length / 2);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    const update = () => setReduced(query.matches);
    update();
    query.addEventListener("change", update);
    return () => query.removeEventListener("change", update);
  }, []);
  useEffect(() => {
    if (reduced || tick >= end) return;
    const timer = window.setTimeout(() => setTick((value) => value + 1), 40);
    return () => window.clearTimeout(timer);
  }, [tick, end, reduced]);
  const thinking = !reduced && tick < 15;
  const text = reduced
    ? answer
    : answer.slice(0, Math.max(0, (tick - answerAt) * 2));
  const done = reduced || tick >= end;
  const progress = reduced
    ? 1
    : Math.min(1, Math.max(0, (tick - 15) / Math.max(1, answerAt - 15)));
  const inlineActivity = parts.some((part) => part.type === "activity");
  const visibleParts = thinking
    ? parts
        .filter((part) => part.type === "activity")
        .map((part) => ({
          ...part,
          event: {
            ...part.event,
            state: "active",
            label: "is thinking",
            meta: undefined,
            description: undefined,
            children: undefined,
          },
        }))
    : parts;
  const response = {
    id: "activity-response",
    actor: "assistant",
    author: activityAgent,
    status: done ? "complete" : "streaming",
    parts: [
      ...visibleParts,
      {
        type: "text",
        id: "answer",
        text,
        state: done ? "complete" : "streaming",
      },
    ],
  };
  return (
    <div
      data-activity-playback={
        thinking ? "thinking" : done ? "complete" : "streaming"
      }
    >
      <ActivityConversationTurn
        prompt={prompt}
        response={response}
        composer={composer}
        footer={done ? footer : null}
        renderers={renderers}
        participants={participants2}
        onReplay={() => {
          onReplay?.();
          setRun((value) => value + 1);
          setTick(0);
        }}
      >
        {thinking && !inlineActivity ? pendingIndicator : null}
        <div key={run} hidden={thinking}>
          {typeof children === "function" ? children(progress) : children}
        </div>
      </ActivityConversationTurn>
    </div>
  );
}

function ActivityDemoTurn(props) {
  return (
    <ActivityPlayback {...props} pendingIndicator={<ThinkingActivity />} />
  );
}

var weekly = [
  {
    id: "gather",
    label: "Gather changes",
    status: "complete",
  },
  {
    id: "draft",
    label: "Draft summary",
    status: "active",
  },
  {
    id: "review",
    label: "Review next steps",
    status: "pending",
  },
];

```

#### Nested tasks

Each items level becomes one deeper activity rail.

todo-list-nested-tasks-15.jsx

```jsx
import { useEffect, useId, useState } from "react";
import {
  Activity,
  ActivityLine,
  ActivityTitle,
} from "@/components/ui/activity";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import {
  Conversation,
  ConversationContent,
  ConversationItem,
} from "@/components/ui/conversation";
import { Ellipsis } from "@/components/ui/loader";
import {
  Message,
  MessageAvatar,
  MessageBody,
  MessageContent,
  MessageFooter,
  MessageHeader,
} from "@/components/ui/message";
import { MessageParts } from "@/components/ui/message-parts";
import { TodoList } from "@/components/ui/todo-list";

export default function Example() {
  const items = [
    {
      id: "review",
      label: "Review the release",
      status: "active",
      items: [
        {
          id: "notes",
          label: "Read release notes",
          status: "complete",
        },
        {
          id: "peers",
          label: "Check peer ranges",
          status: "active",
        },
      ],
    },
  ];
  return (
    <ActivityDemoTurn
      prompt="Review the release."
      answer="The release review is recorded above. Some work may still need attention."
    >
      <TodoList title="Release review" items={items} defaultOpen />
    </ActivityDemoTurn>
  );
}

var user = {
  id: "user",
  name: "You",
  kind: "human",
};

var activityAgent = {
  id: "release-assistant",
  name: "Release assistant",
  kind: "agent",
};

var participants = [user, activityAgent];

function ThinkingActivity() {
  return (
    <Activity status="active">
      <ActivityLine state="active">
        <ActivityTitle>
          Thinking
          <Ellipsis />
        </ActivityTitle>
      </ActivityLine>
    </Activity>
  );
}

function ActivityConversationTurn({
  prompt,
  response,
  children,
  composer,
  footer,
  renderers,
  onReplay,
  pendingIndicator,
  participants: roster = participants,
}) {
  const turnId = useId();
  const request = {
    id: `${turnId}-prompt`,
    actor: "user",
    author: user,
    parts: [
      {
        type: "text",
        text: prompt,
      },
    ],
  };
  const hasActivity = response.parts.some((part) => part.type === "activity");
  const thinking =
    response.status === "streaming" &&
    !children &&
    !response.parts.some(
      (part) => part.type !== "text" || part.text.length > 0,
    );
  return (
    <div
      data-preview-wide
      style={{
        display: "grid",
        gap: "var(--space-4)",
        width: 560,
        maxWidth: "100%",
      }}
    >
      <Conversation
        label="Activity conversation"
        currentUserId={user.id}
        participants={roster}
        initialPosition="start"
        follow="never"
        style={{
          "--conversation-height": "auto",
        }}
      >
        <ConversationContent>
          <ConversationItem id={request.id} message={request}>
            <Message actor="user">
              <MessageBody>
                <MessageParts parts={request.parts} />
              </MessageBody>
            </Message>
          </ConversationItem>
          <ConversationItem id={`${turnId}-response`} message={response}>
            <Message
              actor="assistant"
              status={response.status}
              className="ui-activity-demo-message"
            >
              <MessageAvatar
                style={
                  hasActivity
                    ? {
                        marginBlockStart:
                          "calc((var(--space-8) - var(--space-6)) / 2)",
                      }
                    : undefined
                }
              >
                <Avatar
                  name={response.author?.name ?? activityAgent.name}
                  kind="agent"
                  seed={response.author?.id ?? activityAgent.id}
                  aria-hidden="true"
                />
              </MessageAvatar>
              <MessageContent>
                {!hasActivity ? (
                  <MessageHeader>
                    {response.author?.name ?? activityAgent.name}
                  </MessageHeader>
                ) : null}
                <MessageBody>
                  <div
                    style={{
                      display: "grid",
                      gridTemplateColumns: "minmax(0, 1fr)",
                      gap: "var(--space-2)",
                    }}
                  >
                    {thinking ? undefined : null}
                    {children}
                    <MessageParts
                      parts={response.parts}
                      renderers={renderers}
                      activityLabel={
                        hasActivity && roster.length > 2 ? (
                          <MessageHeader render={<ActivityTitle />}>
                            {response.author?.name ?? activityAgent.name}
                          </MessageHeader>
                        ) : undefined
                      }
                    />
                  </div>
                </MessageBody>
                <MessageFooter>
                  {footer}
                  <Button
                    type="button"
                    variant="outline"
                    size="sm"
                    onClick={onReplay}
                  >
                    Replay
                  </Button>
                </MessageFooter>
              </MessageContent>
            </Message>
          </ConversationItem>
        </ConversationContent>
      </Conversation>
      {composer}
    </div>
  );
}

function ActivityPlayback({
  prompt,
  answer,
  children,
  composer,
  footer,
  renderers,
  workDuration = 1200,
  onReplay,
  participants: participants2,
  parts = [],
  pendingIndicator,
}) {
  const [run, setRun] = useState(0);
  const [tick, setTick] = useState(0);
  const [reduced, setReduced] = useState(false);
  const answerAt = 15 + Math.ceil(workDuration / 40);
  const end = answerAt + Math.ceil(answer.length / 2);
  useEffect(() => {
    const query = window.matchMedia("(prefers-reduced-motion: reduce)");
    const update = () => setReduced(query.matches);
    update();
    query.addEventListener("change", update);
    return () => query.removeEventListener("change", update);
  }, []);
  useEffect(() => {
    if (reduced || tick >= end) return;
    const timer = window.setTimeout(() => setTick((value) => value + 1), 40);
    return () => window.clearTimeout(timer);
  }, [tick, end, reduced]);
  const thinking = !reduced && tick < 15;
  const text = reduced
    ? answer
    : answer.slice(0, Math.max(0, (tick - answerAt) * 2));
  const done = reduced || tick >= end;
  const progress = reduced
    ? 1
    : Math.min(1, Math.max(0, (tick - 15) / Math.max(1, answerAt - 15)));
  const inlineActivity = parts.some((part) => part.type === "activity");
  const visibleParts = thinking
    ? parts
        .filter((part) => part.type === "activity")
        .map((part) => ({
          ...part,
          event: {
            ...part.event,
            state: "active",
            label: "is thinking",
            meta: undefined,
            description: undefined,
            children: undefined,
          },
        }))
    : parts;
  const response = {
    id: "activity-response",
    actor: "assistant",
    author: activityAgent,
    status: done ? "complete" : "streaming",
    parts: [
      ...visibleParts,
      {
        type: "text",
        id: "answer",
        text,
        state: done ? "complete" : "streaming",
      },
    ],
  };
  return (
    <div
      data-activity-playback={
        thinking ? "thinking" : done ? "complete" : "streaming"
      }
    >
      <ActivityConversationTurn
        prompt={prompt}
        response={response}
        composer={composer}
        footer={done ? footer : null}
        renderers={renderers}
        participants={participants2}
        onReplay={() => {
          onReplay?.();
          setRun((value) => value + 1);
          setTick(0);
        }}
      >
        {thinking && !inlineActivity ? pendingIndicator : null}
        <div key={run} hidden={thinking}>
          {typeof children === "function" ? children(progress) : children}
        </div>
      </ActivityConversationTurn>
    </div>
  );
}

function ActivityDemoTurn(props) {
  return (
    <ActivityPlayback {...props} pendingIndicator={<ThinkingActivity />} />
  );
}

```

## API reference

Todo list properties

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| title (required) | string | — | Task plan name shown in the disclosure summary. |
| items | readonly TodoItem[] | — | Ordered display-only tasks. Omit when groups is supplied. Empty arrays render no panel. |
| groups | readonly TodoGroup[] | — | Labeled sections of the same task records. Takes precedence over items. Each group owns a stable id, a title and its ordered items. |
| open | boolean | — | Controls the disclosure state. |
| defaultOpen | boolean | false | Sets the initial disclosure state when uncontrolled. |
| onOpenChange | (open: boolean, details?: unknown) => void | — | Receives disclosure changes from the canonical Collapsible. |
| ...divProps | HTMLAttributes<HTMLDivElement> | — | Native root attributes, including className and id. |

TodoItem fields

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| id (required) | string | — | Stable key for the task row. |
| label (required) | string | — | Readable task text; long labels wrap. |
| status (required) | pending \| active \| complete \| error \| cancelled | — | Caller-owned display status. Only complete contributes to progress. |
| description | string | — | Optional task detail or failure reason. |
| items | readonly TodoItem[] | — | Optional subtasks. Each array level becomes one deeper activity rail. |

TodoList and AgentTodoList export the same implementation. Both import surfaces ship in the todo-list registry item. Item status also accepts error and cancelled; optional description and nested items stay caller-owned. The tree composes Activity, ActivityTrigger, ActivityContent and ActivityList; the summary glyph is the circle Progress.Clock. No visible state words are added: the glyph and shimmer carry state, and assistive text names it.
