Skip to content

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.

tsx
import { Timeline, Composer } 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>
    );
}

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 ​

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 scope

The 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 ​

The package is licensed under FSL-1.1-MIT.

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