Chat parts
Smaller pieces of the thread and composer, for a header, card or chat list of your own. Each reads the chat from its scope.
tsx
import type { StatusWord } from '@adecore/agents-react/chat';
import { ChatActivity, StatusIcon, AccountPill, ImageThumb, UploadThumb, WelcomeGreeting } from '@adecore/agents-react/chat/ui';
import type { ReactNode } from 'react';
import { NOW, PICTURE, chatInfo, chatItems } from '../shared/agents-data.ts';
import { DEMO_CHAT } from '../shared/agents-host.ts';
import { AgentDemo } from '../shared/agents.tsx';
const WORDS: StatusWord[] = ['running', 'paused', 'done', 'failed', 'cancelled'];
/* The demo chat with a helper agent behind it and a test watcher running in the background, under a second account. */
function busyChat() {
return {
[DEMO_CHAT]: {
info: chatInfo(DEMO_CHAT, {
account: 'claude-work',
background: [{ id: 'shell-1', kind: 'shell' as const, description: 'Watch the tests', command: 'bun test --watch', startedAt: NOW - 120_000 }]
}),
items: chatItems()
}
};
}
function Row({ label, children }: { label: string; children: ReactNode }) {
return (
<div className="flex items-center gap-4">
<span className="w-36 shrink-0 text-xs text-text-muted">{label}</span>
<div className="flex min-w-0 flex-wrap items-center gap-2">{children}</div>
</div>
);
}
export default function ChatPartsDemo() {
return (
<AgentDemo chats={busyChat}>
<div className="flex w-full flex-col gap-4">
<WelcomeGreeting chatId={DEMO_CHAT} />
<Row label="ChatActivity">
<ChatActivity chatId={DEMO_CHAT} />
</Row>
<Row label="StatusIcon">
{WORDS.map((word) => (
<span key={word} className="flex items-center gap-1 text-xs">
<StatusIcon word={word} /> {word}
</span>
))}
</Row>
<Row label="AccountPill">
<AccountPill chatId={DEMO_CHAT} />
</Row>
<Row label="UploadThumb, ImageThumb">
<UploadThumb upload={PICTURE} />
<ImageThumb
source={{ url: `data:${PICTURE.mime};base64,${PICTURE.data}`, failure: null }}
alt={PICTURE.name}
className="size-16 object-cover"
/>
<ImageThumb source={{ url: null, failure: 'The host keeps no file under this id.' }} alt="Missing" />
</Row>
</div>
</AgentDemo>
);
}| Component | Import | |
|---|---|---|
ChatActivity({ chatId }) | @adecore/agents-react/chat/ui | The line over the composer: the chat's subagents and its background commands, each with a flyout. Nothing while there are none. |
StatusIcon({ word }) | @adecore/agents-react/chat/ui | The mark of a StatusWord: running, paused, done, failed or cancelled. |
AccountPill({ chatId }) | @adecore/agents-react/chat/ui | The account a chat runs under, only while its CLI has a choice of accounts. |
UploadThumb({ upload }) | @adecore/agents-react/chat/ui | An image the composer holds, drawn from a thumbnail made in the page. |
ImageThumb({ source, ... }) | @adecore/agents-react/chat/ui | An image that opens in a lightbox. source is { url, failure }; without a URL it shows its failure. aspect (width over height) reserves its space before the bytes arrive, actions go in the lightbox header, and open with onOpenChange control it. |
WelcomeGreeting({ chatId, now? }) | @adecore/agents-react/chat/ui | The greeting over an empty chat, by the part of the day. |
statusLookOf(word) returns the look of a StatusWord: its icon, tone and whether it spins. taskStatusWord(task) returns a task's word (paused while it waits out a limit), from the task's status and whether it is paused.
imageForDisplay(blob) from @adecore/agents-react/images converts HEIC or HEIF to PNG and returns other blobs as they are. Call it before making a display URL or reading pixels; the decoder loads lazily.
DisplayImage from @adecore/agents-react/chat/ui takes native image props and decodes HEIC or HEIF when the browser cannot. Remote images must allow cross-origin reads.