Skip to content

Host adapters ​

A ChatHostProvider hands the views under it what only the app can decide. Render one around everything that draws a chat. Keep its host in a constant, because the provider reads it once, on mount. One host may serve several scopes, so a function about one scope gets its scopeId.

tsx
import { ChatHostProvider, type ChatHostLayer } from '@adecore/agents-react';

const CHAT_HOST: ChatHostLayer = {
    notify: (toast) => showToast(toast),
    useStreaming: () => useSettings((settings) => settings.streaming)
};

createRoot(element).render(
    <ChatHostProvider host={CHAT_HOST}>
        <App />
    </ChatHostProvider>
);

useChatHost() returns the host of the nearest provider, or the defaults outside one.

A field whose name starts with use is a React hook. The provider throws when it gets another host object later, since a mounted view would then call other hooks. Hand stable functions and let the hooks read your own state. To swap the host, give the provider a new key.

A part that loads later ​

A nested provider starts from the host above it and replaces the fields it sets. A field that is an object on both sides, such as attachments or prompts, is merged one level down, so a layer sets the one function it changes (a ChatHostLayer types that); a layer that sets such a field to null replaces the whole object. A part of the app that loads later renders its own provider around what it draws. Views outside it keep the host they mounted with.

tsx
const WORKSPACE_HOST: ChatHostLayer = {
    useTimelineFind,
    attachments: { actions: saveActions }
};

export function Workspace() {
    return (
        <ChatHostProvider host={WORKSPACE_HOST}>
            <Panels />
        </ChatHostProvider>
    );
}

Fields ​

FieldWithout itWhat it is for
notify(toast)Nothing is shownA toast: errors, successes, and a deletion with an undo action.
actionsEvery action is a request on the scope's transportA ChatActions of your own. See Actions.
searchFiles(scopeId, cwd, query, limit)No @ file pickerRelative paths under cwd for the composer's picker.
attachmentsNo previews; reading rejectsuseUrl for a URL to an attached file's bytes, read for the bytes as a Blob.
ReadImageNothing under a tool that read an imageA component that draws the image at path.
MarkdownImageAn image in a reply loads its target as writtenA component that draws the image at path, a file a reply names, absolute or under the chat's cwd.
ModelViewA model shows as a row with its name and captionA component that draws the 3D model of a Model block from UiModelViewProps.
intelligentUiChoices stay closed, live values and links stay as first readsendChoice, query, link, openLink, openUrl and subscribe for Intelligent UI blocks.
fileLinksPaths in a reply stay texttarget(text, cwd, scopeId) finds a FileRef; open(cwd, ref, scopeId) opens it.
codeLight, github-light and github-darkuseMode() for light or dark, useThemes() for the Shiki themes, custom for your own themes. Optional syntaxWorker(), highlighter() and editor(), see Diff syntax worker.
useStreaming()wordsHow a reply appears while it streams: words, blocks or whole.
useSendDelivery()queueWhat Send does while a turn runs: queue waits for the turn to end, steer hands the message to the running turn. Option or Alt picks the other one.
useHidesToolCalls(scopeId, chatId)falseLeave tool lines out of a thread and a subagent's work. Generated images and the turn's duration stay.
commandLooksEvery shell call reads as itselfPrograms of your own drawn as tools of their own in a thread. See Programs as tools.
toolLooksEvery MCP call reads as its CLI names itMCP servers of your own whose tools are drawn as tools of their own. See MCP servers as tools.
useTimelineFind(options)No find in a threadFind in a thread: you get the rows and refs, you hand back a TimelineFind with the bar to draw.
dictationPlainTextarea, no dictation buttonA Textarea for written answers, and an editor extension plus a control for the composer.
promptsNo prompts of your ownApprovals or questions of your own beside a chat's. See Prompts.
useReferableChats()No chats in the # pickerOther chats a message may point at, as { id, title }.
useReferables(scopeId, chatId)The chats of useReferableChatsWhat a message may point at with #, as Referables: items of Referable (id, name, a ReferableKind, detail?, group of canvas or views) and chatsOnly. A reply that writes #Name exactly draws a chip too; an ambiguous name stays text.
ReferenceIconThe mark of the reference's kind (REFERENCE_ICONS)A component that draws the mark of a # reference from ReferenceIconProps (id, kind, size, className?), such as an icon a person picked. The composer draws it outside the provider, so it reads no context.
outsideReference(scopeId, id)The chip reads as goneWhat a chip's id still stands for when it is no Referable, such as a sender from outside, as an OutsideReference: an icon and an open callback, or null to open nothing. The chip keeps the name its message gave.
openLogin(scopeId, kind, accountId, name)No log in buttonRuns a CLI's own login somewhere a command can run, such as a terminal.
useLoginBlocked(scopeId)Login is always possibleWhy a login cannot start right now, or null.
useCanReorderAccounts(scopeId)The host keeps the orderWhether the host answers accounts.reorder, which shows the drag handles in Providers.
useCanShareAccountConfig(scopeId)No switch to share the default account's setupWhether the host answers accounts.shareConfig, which shows the switch on an extra account of a CLI in sharedConfigKinds. Left out, the switch stays hidden.
useAccountRule(scopeId, chatId)Every account that is on is offeredPer CLI, the account a chat's project starts on and the accounts it never offers.
runProviderCommand(scopeId, kind, command)Install page offers Copy onlyRuns an install or sign-in command where a person sees it, such as a terminal on the scope's machine.
useMachinePlatform(scopeId)The system of the pagedarwin, linux or win32 of the scope's machine, whose install command the install page shows first.
providerKeyNote(variable)NothingA sentence after an environment key the install page asks for. null adds none.
useProjectLook(scopeId, projectId)The folder's own nameA project's name and mark on the usage page.
useMachineLabel(scopeId)A version requirement names no machineThe machine's name, for "Requires Claude Code 2.1 or later on <machine>".
useChatPlace(chatId)Links to other chats lead nowhereWhere another chat is (title, go()), for a fork's way back. A null title is a chat that is gone.
useContextSources(chatId)NothingWhat a chat may read besides its folder, named under an empty thread.
useWelcome(chatId)falseOpen an empty chat on a greeting with the composer under it.
tasksNo tasksuseTasks and useTask: the tasks behind subagent rows your app opened itself.
useTaskRow(row)The standard rowA row of your own for such a task, from a HostTaskRow; null keeps the standard row.
confirmRuns at oncestopSubagents and stopTask get a run to call once a person confirmed.
fork(chatId, turnId)No fork actionOffers a fork after a turn; where it lands is up to you.
openNewChat(scopeId, chatId)Mod+Alt+Enter sends the other way, like Alt+EnterAfter Mod+Alt+Enter sent a message, opens a new chat with the same CLI, model and settings and focuses its composer.
openSettings(section)NothingOpens your settings on providers or agents.
useResumeAtReset(scopeId)trueWhether a chat may go on by itself once the limit it stopped on lifts.
useComposerPlaceholder(scopeId, chatId)The chat's ownThe first words of an empty composer.
useUnknownItemWords()"Update the app to see this." and its request versionUnknownItemWords (item, request) for the row of an item from a newer host, such as naming your app. See Newer hosts.
ComposerSlotNothingA control of your own in the composer's row, with insert(text) to type into the draft.
ComposerHeaderSlotNothingA bar of your own at the top of the composer's card, above the text.
useComposerStatus(scopeId, chatId)No lineItems of your own on a line under the composer's card, such as a branch. See Slots and cards.
useSkills(scopeId, chatId)Only the CLI's skillsHostSkills ({ name, title, description, icon }) of your own after $, above the CLI's. See Pickers and pasting.
SubagentSlotOne flyoutChips of your own for a chat's subagents over the composer.
useThreadCards(scopeId, chatId)No cardsCards of your own between the messages, each { id, at, render }.
useReplyAuthor(scopeId, chatId)The agent is named for screen readers onlyA header over each reply: { name, mark? }.
saidByA note line{ name, mark? } for what you told the agent in front of a prompt (a note with said), drawn as a message under that name.
visualsNo visuals in a threadA VisualHost. See Visuals.
accentsNo colorsThe colors an account may wear: all, the featured ones, a label and the current accent.
isApplePlatform(), isAppShortcut(event)From @adecore/ui; no shortcutWhich modifier is Mod, and keys the app keeps even while the composer has focus.

A default leaves a part out; it is not a policy. A view's disabled stops nothing, so the host checks every request itself.

Some fields take a type of their own:

  • useTimelineFind gets TimelineFindOptions: the chat, the frame, the thread and its scroller.
  • dictation holds a Textarea that takes the props of a textarea plus a buttonClassName, and a composer control with ComposerDictationProps: the editor, the row it sits in and whether it is disabled.
  • useChatPlace returns a ChatPlace, { title, go() }.
  • tasks returns a SubagentTask per row: its status, when it started and settled, and paused while it waits out a limit.
  • useTaskRow gets a HostTaskRow: the scope, the chat whose thread holds the row, the row's item, its SubagentTask, its TaskRowState (the task's state, or waiting while the agent waits on a person), whether it is open and onPress, which opens the agent's conversation. To keep the row's own line and add to it, draw TaskRowHead from @adecore/agents-react/chat/ui, whose line takes the place of the words under the task.
  • useThreadCards returns ThreadCards, and useReplyAuthor a ReplyAuthor.
  • accents lists choices as { id, color }.
  • ComposerHeaderSlot gets ComposerHeaderSlotProps, and SubagentSlot gets SubagentSlotProps.

Actions ​

The views run every action on a chat through a ChatActions, from stop and compact to approvals and goals. Without the optional goal, the goal row offers no buttons. Without the optional toolOutput, a truncated tool output shows only its beginning. With actions: null, each action is the request of the same name on the scope's transport. useChatActions() and actionsOf(scope, host) return the set in use.

Your own set serves every scope under its provider and gets only chat ids, so it has to know which scope each chat is on. Send the same requests the transport would, and keep the code of a refusal.

Slots and cards ​

renderShellCodeBlock puts a small control of your own beside Copy on every top-level sh, bash or zsh fence in the chat's replies. The views never call it for a person's messages, thinking, tool output, reports, nested fences or a subagent's conversation. It gets a ShellCodeBlockContext with scopeId, chatId, itemId, language, code (the fence body exactly as written) and complete. complete turns true once the fence is closed and the reply stopped streaming. Check the command again in the host before it runs.

tsx
const CHAT_HOST: Partial<ChatHost> = {
    renderShellCodeBlock: (context) => context.complete
        ? <button onClick={() => previewCommand(context)}>Preview command</button>
        : null
};

ComposerSlot gets { scopeId, chatId, disabled, insert }. insert(text) types at the caret and focuses the editor. ComposerHeaderSlot gets { scopeId, chatId, disabled, focused }; keep its controls out of the tab order while focused is false. SubagentSlot gets { chatId, items } and draws only when there are subagents. A thread card has an id unique in the chat, an at on the clock of the items' createdAt, and a render() that runs while the card is on screen. Return the same array from useThreadCards while nothing changed, since a new array lays out every row again.

tsx
import { Button } from '@adecore/ui';
import type { ChatHost, ComposerSlotProps } from '@adecore/agents-react';

function InsertSelection({ disabled, insert }: ComposerSlotProps) {
    return (
        <Button size="sm" disabled={disabled} onClick={() => insert(editor.selectedText())}>
            Insert selection
        </Button>
    );
}

const CHAT_HOST: Partial<ChatHost> = { ComposerSlot: InsertSelection };

useComposerStatus returns ComposerStatusItems ({ id, icon, label, tooltip?, side?, details? }) for a line under the composer's card, lined up with the text in the box. Without items there is no line. An item with side: 'end' stands at the right. An item with details is a button that opens a popover with one row per ComposerStatusDetail ({ icon, label, detail?, hint?, mono?, muted? }).

tsx
import { GitBranch } from 'lucide-react';
import type { ChatHost, ComposerStatusItem } from '@adecore/agents-react';

function useBranchStatus(scopeId: string, chatId: string): readonly ComposerStatusItem[] {
    const branch = useBranchOf(scopeId, chatId);

    return branch === null ? [] : [{ id: 'branch', icon: GitBranch, label: branch, details: [{ icon: GitBranch, label: branch, mono: true }] }];
}

const CHAT_HOST: Partial<ChatHost> = { useComposerStatus: useBranchStatus };

Visuals ​

A thread draws the pages an agent published only when the host sets visuals. A VisualHost is { frameUrl, openLink(url), actions? }:

  • frameUrl is where you serve the sandbox host page, VISUAL_HOST_PAGE from @adecore/agent-contracts/visual.
  • openLink(url) opens an http or https link from a visual outside the app.
  • actions(scopeId, chatId, visual) returns HostMenuActions ({ id, label, icon?, disabled?, run() }) for the visual's menu, above Remove.
ts
import type { ChatHost } from '@adecore/agents-react';

const CHAT_HOST: Partial<ChatHost> = {
    visuals: {
        frameUrl: 'https://visuals.example.test/frame.html',
        openLink: (url) => openInBrowser(url)
    }
};

The frame reads a page's bytes through attachments.read; a stored page is an attachment whose id is the visual's. Never serve a stored page on the app's origin. Serving a page covers the origin and Content-Security-Policy, Visuals how a thread draws them.

Lazy modules ​

The diff views and a few heavy parts load on first use through lazyNamed of @adecore/ui, so they register with its prefetcher and report a failed open to its onLazyOpenError. The app wires those two once, for its own surfaces and the chat's alike. Lazy loading covers both.

Diff syntax worker ​

code.syntaxWorker returns a new worker for the diff syntax runtime. Its entry calls serveDiffSyntax(self) from @adecore/editor/shiki-worker. When the worker fails, pending and later requests run on the main thread. Without the factory, highlighting runs on the main thread with yields between blocks.

Every code object has one runtime, so nested providers that keep the same code share it. Changing a theme under an existing name needs a page reload. To add a theme while chats are open, add it to custom under a new name before useThemes() names it. Return the same array until a theme is added, since code blocks compare it between renders:

ts
const code = {
    useMode,
    useThemes,
    get custom() {
        return useCodeThemes.getState().themes;
    }
};

code.highlighter lends the page's Shiki highlighter to code blocks and the main-thread fallback, which never dispose it. Without it they load their own on first use.

code.editor returns the shared EditorEngine, which small EditDiff reviews then use. The host keeps the engine.

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