Agent views
@adecore/agents-react holds the React views of agent chats: the thread, the composer, approvals and questions, the agent CLIs and their accounts, and what they cost. It runs in the page and talks to a host of chats, such as @adecore/agents, over the requests and events of @adecore/agent-contracts.
import { Timeline, Composer } from '@adecore/agents-react/chat/ui';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>
);
}The demos run on an in-memory host with two CLIs, three accounts and a chat two turns in. Send a message and it answers a word at a time; mention a check or a test and it asks for permission first. Nothing leaves the page.
What it does
- Draws a chat: the timeline of its thread, the composer that writes to it, and the prompts for the approvals and questions it waits on.
- Offers the parts for a layout of your own: messages and code, diffs, subagents, limits and smaller parts.
- Draws what an agent publishes in a reply: UI blocks and visuals.
- Shows the settings of the CLIs and their accounts in the providers pane, with marks and a model picker.
- Shows what the CLIs cost on the usage page, with its charts and tiles and the plan limits.
- Keeps drafts and preferences across a reload.
How it fits together
your app ChatHostProvider words, files, navigation
|
scope ChatScopeContext one per host of chats
| transport requests and events
| ChatClient writes them into the stores
|
views Timeline, Composer, ... read the stores of their scopeThe views read a chat from a store, never from the wire. A ChatClient fills the store from a ChatTransport, which reaches the host. A ChatScope bundles the two with an id in context, so two hosts get two scopes whose threads never mix.
What it leaves to the app
The package starts no process and registers no channel. The app hands it a port to the host, and decides what only it can know through a ChatHostProvider: where a file opens, how a toast shows, which words name its own commands. A field the app leaves out leaves its part out. Import @adecore/agents only in the process that runs the chats, never in the page.
Where to next
- Getting started installs the package, its CSS and its words, connects a scope to the host and renders a first chat.
- Host adapters lists what a
ChatHostProvidertakes and what each part does without it. - Chat client and state covers opening, sending, reconnecting and reading the stores.
- Persistence covers drafts, preferences and their storage keys.
- Testing shows a host in memory like the one these demos use.
- Timeline, Composer, Prompts, Messages and code, Diffs, Subagents, Limits, Chat parts, Attachments and mentions, Intelligent UI and Visuals cover the views of a chat.
- Providers pane, Model picker and Agent marks cover the CLIs and their accounts.
- Usage page, Charts and tiles and Plan limits cover what the CLIs cost.
- Reference lists every export of every entry point.
The package is licensed under FSL-1.1-MIT.