Skip to content

Timeline ​

The thread of one chat, with the composer docked under it. It needs a ChatScopeContext and a chat opened in that scope.

tsx
import { Timeline } from '@adecore/agents-react/chat/ui';
tsx
import { useChatScope } from '@adecore/agents-react';
import { useSubagentTrail } from '@adecore/agents-react/chat';
import { AccountPill, Composer, LimitPill, SubagentBreadcrumb, SubagentTitleCrumb, SubagentTimeline, Timeline } from '@adecore/agents-react/chat/ui';
import { AgentIcon } from '@adecore/agents-react/providers';
import { useChatRow } from '@adecore/agents-react/state';
import { useEffect } from 'react';
import { DEMO_CHAT } from '../shared/agents-host.ts';
import { AgentDemo } from '../shared/agents.tsx';

function Chat() {
    const scope = useChatScope();
    const info = useChatRow(DEMO_CHAT, (row) => row?.info);
    const { trail } = useSubagentTrail(DEMO_CHAT);
    const open = trail.at(-1);

    useEffect(() => {
        void scope.chats.open(DEMO_CHAT, {});

        return () => void scope.chats.detach(DEMO_CHAT);
    }, [scope]);

    return (
        <div className="flex h-[640px] w-full flex-col overflow-hidden rounded-lg border border-border bg-surface">
            <header className="flex h-10 shrink-0 items-center gap-2 border-b border-border px-3">
                <AgentIcon kind={info?.provider ?? 'claude'} />
                <SubagentTitleCrumb chatId={DEMO_CHAT} className="text-sm font-medium">
                    <span className="truncate text-sm font-medium">Retry for fetchJson</span>
                </SubagentTitleCrumb>
                <SubagentBreadcrumb chatId={DEMO_CHAT} />
                <span className="ml-auto flex items-center gap-1.5">
                    <LimitPill chatId={DEMO_CHAT} />
                    <AccountPill chatId={DEMO_CHAT} />
                </span>
            </header>
            <Timeline
                chatId={DEMO_CHAT}
                overlay={open && <SubagentTimeline key={open.toolUseId} chatId={DEMO_CHAT} toolUseId={open.toolUseId} />}
                composer={
                    info && (
                        <Composer
                            chatId={DEMO_CHAT}
                            info={info}
                            focused={false}
                            disabled={false}
                            providerFixed={false}
                            onSend={(text, extras) => void scope.chats.send(DEMO_CHAT, text, extras)}
                            onRetarget={(provider, selection) => scope.chats.retarget(DEMO_CHAT, provider, selection)}
                        />
                    )
                }
            />
        </div>
    );
}

/* Send a message that mentions a check to see an approval; any other message gets a reply. */
export default function ChatDemo() {
    return (
        <AgentDemo>
            <Chat />
        </AgentDemo>
    );
}
tsx
<Timeline chatId={chatId} composer={<Composer chatId={chatId} info={info} {...composerProps} />} />

The timeline fills its parent and scrolls on its own. Every flex parent down to it needs min-h-0, or it has no height. An empty chat shows the model and folder, or a greeting when the host's useWelcome says so.

What it draws ​

  • Consecutive tool calls fold into one line ("Read 2 files"). A finished turn folds behind its duration and a summary.
  • The files a turn changed gather in one card under its reply. A subagent's work hangs under its row.
  • A page an agent published stands above its reply when the host draws visuals.
  • A folded thought shows its heading. While a turn runs, its latest thought stands over the call it led to.
  • An unknown tool draws with a wrench and the first string of its input.
  • An opened call shows its input (a shell command as itself, other input as key value lines) and its output in muted monospace. A failure shows in the error color or names the exit code.
  • A shell command draws in the code theme, and code embedded in it (bash -lc, python3 -c, a heredoc) in its own language. embeddedCode(command) finds those stretches.
  • A long path is cut in the middle (MiddleTruncate), with the whole path on a tooltip.

The timeline draws only the rows on screen. The thread follows new text while scrolled to the end and loads older pages near the top. A scrubber along the edge marks every message and bookmark. Each mark is one of three kinds: a message of the person (person), a turn the host opened with the results of tasks (wake), or a message with a bookmark (bookmark).

Code outside the thread can move it. jumpToTimelineTurn(key, turnId, target) scrolls a chat's thread to a turn, its prompt or its changed files (a TurnTarget, prompt or changes). It returns false when no thread of that chat is on screen, and the jump then waits for the next one. stepTimelineMessage(key, direction) moves to the previous or next message. A thread of your own takes jumps with registerTurnJumper(key, jump), which returns its release.

Hovering a message shows bookmark, fork (with a host fork) and copy. A right click adds copy as code or Markdown, and the reading width in a view of its own. Selecting text in a reply offers to quote it into the composer.

Programs as tools ​

A shell call reads as Bash and its command. To draw a program of your own as a tool, hand the host a commandLooks list with one CommandLook per program. A call that runs it shows its Mark, its brand, the label describe returns and the command from word detailFrom on.

tsx
import type { CommandLook } from '@adecore/agents-react';

const DEPLOY: CommandLook = {
    program: 'deploy',
    brand: 'Deploy',
    Mark: ({ size }) => <RocketIcon size={size} />,
    describe: ([target]) =>
        target === undefined
            ? null
            : {
                  label: target === 'preview' ? 'Preview' : 'Production',
                  detailFrom: 1,
                  group: { key: target, sentence: (count) => `Deployed ${count} times` },
                  fold: ['--message'],
                  languages: { '--query': 'sql' }
              },
    useNames: () => (word, option) => (word === 'web-1' && option === '--site' ? { name: 'Website' } : null)
};

A program matches only where the shell runs it, by its last path segment, so grep deploy stays a shell call. So does a command longer than EMBEDDED_CODE_LIMIT. The other programs of the line follow in a tag (+ sleep, grep).

  • fold options get their value shortened, languages options get it highlighted.
  • useNames is a hook. Its function gets each non-option word with the option before it, and may return a display name. The word stays on a tooltip and in find.
  • Calls of one look with the same group.key read as that group's sentence. Calls under different keys use the look's own sentence.
  • sent draws a call as a message the agent sent to another node, with the node's chip, its text and how it went, and the call one click away. The timeline asks it only for a line that is exactly that one call, with no word the shell fills in. Returning null leaves the call a tool line. A folded turn counts such messages in its summary.

The opened call still shows the whole command. matchCommandLook(command, looks) returns what a row draws, for a find of your own: the words a host may name come back as offsets into the detail.

describe returns a CommandLookMatch, and useNames a CommandName for a word: a name, an optional icon, and optionally the id of a node it stands for. sent gets a CommandLookCall (the words, a heredoc, the state and the output) and returns a CommandLookSent: the node it went to, the text and how it went.

MCP servers as tools ​

An agent that calls a tool of your own MCP server shows the name its CLI gives it. To draw those calls as tools of your own, hand the host a toolLooks list with one ToolLook per server. describe gets the tool's name on its server and the arguments it got, and returns the label, a lead and the fields to show.

tsx
import type { ToolLook } from '@adecore/agents-react';

const DEPLOY_SERVER: ToolLook = {
    server: 'deploy',
    brand: 'Deploy',
    Mark: ({ size }) => <RocketIcon size={size} />,
    describe: (tool) =>
        tool.startsWith('site_')
            ? {
                  label: 'Site',
                  lead: tool.slice(5),
                  fields: ['site', 'message'],
                  group: { key: 'site', sentence: (count) => `Deployed ${count} times` }
              }
            : null,
    useNames: () => (word, field) => (word === 'web-1' && field === 'site' ? { name: 'Website' } : null),
    sent: ({ tool, input, state }) =>
        tool === 'notify' && typeof input.to === 'string' && typeof input.text === 'string'
            ? {
                  to: input.to,
                  text: input.text,
                  state: state === 'running' ? 'sending' : state === 'error' ? 'failed' : 'delivered'
              }
            : null
};

A call of site_deploy reads Deploy Site deploy site=Website message="Ship it". Each value is a word useNames may name, with its field as the option. A long value is cut after 40 characters, and an object reads as {…}.

  • Every CLI's shape matches: mcp__deploy__site_deploy, deploy/site_deploy, a Grok use_tool call that names deploy__site_deploy, and an ACP call of an agent that marks no server, titled deploy__site_deploy, deploy_site_deploy or deploy-site_deploy. mcpCallOf(item, servers) reads the server, the tool and its arguments out of any of them, with the answer taken out of the envelope a CLI wraps it in.
  • A name that says its server wins over a title: mcp__other__write titled deploy-site_deploy is no call of deploy. The timeline tries the servers longest name first, so mcp__deploy__site__push goes to a server deploy__site before deploy. A title only counts on a generic ACP row (Tool, or a Read without a file_path).
  • group, sentence and sent work as they do for a CommandLook. sent gets the tool, its input, its state and its answer.
  • A shell line goes to commandLooks first. lookRunOf(item, commandLooks, toolLooks) returns what a row draws for either.
  • describe returns a ToolLookMatch, and sent gets a ToolLookCall. mcpCallOf returns the call read out of an item. A Look is either kind of look.
  • sentMessageOf(item, commandLooks, toolLooks?) returns the message a call sent as its look reads it, or null. summarizeGroup(tools, commandLooks?, toolLooks?) returns the sentence for a run of calls: "Read 4 files", "Ran 2 commands", or the sentence of a look all of them are runs of.

Reading width ​

Inside a parent with the class chat-column, the rows and composer stand in a centered column. Its width is the person's reading width in the chat preferences: narrow (640px), comfortable (768px, default) or full. The right click menu offers them; a settings page can too, with CHAT_READING_WIDTHS, readingWidthLabel, readingWidthHint and rememberReadingWidth from @adecore/agents-react/chat. Without chat-column the thread takes the width it has. SubagentTimeline follows the same width.

Props ​

PropType
chatIdstringThe chat in the scope.
composerReactNodeDocked at the bottom of the frame, over the end of the thread.
overlayReactNodeCovers the thread down to the composer. The thread keeps its scroll position and the composer stays usable.

The overlay is where a subagent's conversation goes. A row's open button sets the chat's trail (useSubagentTrail); draw a SubagentTimeline for its last step:

tsx
const { trail } = useSubagentTrail(chatId);
const open = trail.at(-1);

<Timeline chatId={chatId} composer={composer} overlay={open && <SubagentTimeline key={open.toolUseId} chatId={chatId} toolUseId={open.toolUseId} />} />;

File references ​

A FileRef has a path, an optional one-based line and column, an inclusive endLine and directory. The host's fileLinks.target(text, cwd, scopeId) and fileLinks.open(cwd, ref, scopeId) get the thread's scope, or null outside a ChatScopeContext.

A file link records its place, scope and cwd, so the menu opens what the link pointed at even after the cwd changed. A subagent's conversation uses its own cwd. useFileLinkCwd() reads the cwd for a renderer of your own, and openFileLink(cwd, ref, scopeId) hands a link to the host.

Streaming ​

The host's useStreaming() picks how a reply appears: a word at a time with a fade (words), a Markdown block at a time (blocks), or all at once (whole). An open code fence highlights as it grows. Only the growing reply's row redraws; see reading the stores.

Find ​

The thread has no find of its own. The host's useTimelineFind(options) gets the rows, refs to the frame, thread and scroller, and callbacks to open a fold and scroll to a row. It returns a TimelineFind with the bar to draw, the hit rows and the current hit. The options object stays stable until the rows change, so an effect may depend on it. A FindReveal opens a fold for a hit inside it, by item and ChatFindField: the line that always shows (summary), the text of a message (text), or what shows only once a row is opened (output).

BookmarkSubmenu({ chatId }) lists a chat's bookmarks in thread order, each a jump to its message with rename and remove, for a menu of your own. It draws nothing without bookmarks.

Rows ​

The Timeline draws each TimelineRow itself. These rows are exported from @adecore/agents-react/chat/ui: ReportRow, NoteRow, AgentTurnRow, CompactionRow, WorkRow, WorkGroupRow, WorkingRow, TaskRow, WorkflowRow and ForksRow. TaskRowHead is the line of a TaskRow alone, for a host that draws a task's row itself (useTaskRow). A workflow's agent line is exported as WorkflowAgentLine, for a column of phases of your own (subagents). deriveTimelineRows(items, options) turns items into rows as the timeline does.

tsx
import type { ChatToolItem } from '@adecore/agent-contracts';
import { liveWorkflowPhase, summarizeGroup, workflowPhases, workflowPhaseState, workflowPhaseTime } from '@adecore/agents-react/chat';
import {
    AgentTurnRow,
    CompactionRow,
    NoteRow,
    ReportRow,
    WorkGroupRow,
    WorkingRow,
    WorkRow,
    ForksRow,
    TaskRow,
    WorkflowAgentLine,
    WorkflowRow
} from '@adecore/agents-react/chat/ui';
import { formatElapsedShort } from '@adecore/ui/format';
import { useState } from 'react';
import { NOW, chatItems, taskRows, workflowTool } from '../shared/agents-data.ts';
import { DEMO_CHAT, demoChats, forkChats } from '../shared/agents-host.ts';
import { AgentDemo } from '../shared/agents.tsx';

const tools = chatItems().filter((item): item is ChatToolItem => item.kind === 'tool');
const reads = tools.filter((tool) => tool.name === 'Read' || tool.name === 'Grep');
const workflow = workflowTool();
const tasks = taskRows();

function WorkflowPhases() {
    const [picked, setPicked] = useState<number | null>(null);
    const running = workflow.state === 'running';
    const phases = workflowPhases(workflow.workflow!, running);
    const live = liveWorkflowPhase(phases, running);

    return (
        <div className="flex w-80 flex-col gap-2 rounded-lg border border-border p-2">
            {phases.map((phase) => {
                const { settled, total } = workflowPhaseState(phase);
                const time = workflowPhaseTime(phase);

                return (
                    <section key={phase.key}>
                        <div className="flex h-7 min-w-0 items-center gap-2 text-xs">
                            <span className="min-w-0 grow truncate font-medium text-text">{phase.title}</span>
                            <span className="shrink-0 text-text-faint tabular-nums">
                                {settled}/{total}
                                {time !== null && time.endedAt !== null && ` · ${formatElapsedShort(time.endedAt - time.startedAt)}`}
                            </span>
                        </div>
                        {phase.key === live &&
                            phase.agents.map((view) => (
                                <WorkflowAgentLine
                                    key={view.agent.index}
                                    view={view}
                                    provider="claude"
                                    selected={picked === view.agent.index}
                                    onOpen={() => setPicked(view.agent.index)}
                                />
                            ))}
                    </section>
                );
            })}
        </div>
    );
}

function Rows() {
    const [expanded, setExpanded] = useState(false);
    const [openTask, setOpenTask] = useState<string | null>(null);

    return (
        <div className="chat-thread flex w-full max-w-2xl flex-col gap-3">
            <WorkRow tool={tools.find((tool) => tool.name === 'Bash')!} />
            <WorkGroupRow tools={reads} summary={summarizeGroup(reads)} expanded={expanded} onToggle={() => setExpanded(!expanded)} />
            <WorkingRow startedAt={NOW - 14_000} />
            <WorkflowRow chatId={DEMO_CHAT} tool={workflow} workflow={workflow.workflow!} />
            <WorkflowPhases />
            <div>
                {tasks.map(({ item, task }) => (
                    <TaskRow
                        key={item.id}
                        chatId={DEMO_CHAT}
                        item={item}
                        task={task}
                        open={openTask === item.id}
                        onPress={() => setOpenTask(openTask === item.id ? null : item.id)}
                    />
                ))}
            </div>
            <ForksRow chatId={DEMO_CHAT} turnId="turn-1" />
            <NoteRow id="note-info" level="info" text="The chat moved to the account Work." />
            <NoteRow id="note-warning" level="warning" text="The CLI restarted and resumed the conversation." />
            <NoteRow id="note-error" level="error" text="The CLI exited with code 1." />
            <CompactionRow preTokens={96_300} />
            <AgentTurnRow label="The helper agent finished" />
            <ReportRow id="report" text="Three callers: `barometer.ts` and `thermometer.ts` catch errors, `station.ts` does not." />
        </div>
    );
}

export default function RowsDemo() {
    return (
        <AgentDemo chats={() => ({ ...demoChats(), ...forkChats() })}>
            <Rows />
        </AgentDemo>
    );
}

WorkRow takes an optional icon, label and failed to name a call in your own words. toolSummary(name, input) from @adecore/agents-react/chat is the one line that says what a call is about: the command, the file or the pattern.

A subagent's row is a SubagentBranch: its item, the work the thread kept of it, and the agents it opened in turn. The changed files of a turn note it when the turn ended on another branch than it started on, so its diff also holds what came in with the move. handbackReportOf(item) returns the report a subagent's handback call carries, or null for any other item.

recentChatMessages(items, order, limit) returns the last messages of a chat: up to limit of them (role, text and time) and whether there were more. It leaves out a subagent's replies, which belong to its own conversation. recentSubagentMessages(items, limit) does the same for a subagent's conversation.

Generated images ​

GeneratedImageRow({ chatId, tool }) draws a tool call named ImageGeneration (IMAGE_GENERATION_TOOL). It stays out of tool groups and out of a finished turn's fold. The row shows the image's size and dimensions over a thumbnail that opens in the lightbox. Its menu copies the revised prompt and holds the host's attachments.actions. Open and Save to project come from the host's attachments and the menu leaves them out without it. Missing bytes leave an empty square with the reason on a tooltip.

A failure is a failed tool line with the reason. generatedImageView(tool) returns generating, failed or ready, and attachmentAspect(attachment) the width over height.

tsx
import { GeneratedImageRow } from '@adecore/agents-react/chat/ui';
import { generatedImageTools } from '../shared/agents-data.ts';
import { DEMO_CHAT } from '../shared/agents-host.ts';
import { AgentDemo } from '../shared/agents.tsx';

const tools = generatedImageTools();

export default function GeneratedImageDemo() {
    return (
        <AgentDemo>
            <div className="chat-thread flex w-full max-w-2xl flex-col gap-3">
                <GeneratedImageRow chatId={DEMO_CHAT} tool={tools.ready} />
                <GeneratedImageRow chatId={DEMO_CHAT} tool={tools.transparent} />
                <GeneratedImageRow chatId={DEMO_CHAT} tool={tools.generating} />
                <GeneratedImageRow chatId={DEMO_CHAT} tool={tools.missing} />
                <GeneratedImageRow chatId={DEMO_CHAT} tool={tools.failed} />
                <GeneratedImageRow chatId={DEMO_CHAT} tool={tools.tooLarge} />
            </div>
        </AgentDemo>
    );
}

The right click menu belongs to the Timeline. Prefer the whole Timeline unless your app owns grouping and scrolling.

Licenses and third-party notices are listed in each package.