AI-21AINew, October 21, 2026
AI Conversation Branches
A chat where editing a message starts a new branch. A small tree beside it shows every version, and you can jump between them.
Usage
Pass your conversation as messages, each with the parent it follows; two messages with the same parent are a fork. Editing a question starts a new branch and calls reply with the edit and the messages above it on that branch. Return the reply, a Promise of it, or a stream of deltas, and it writes in with a caret; a throw shows the error's message. onChange hands you every message once a branch's reply is in, ready to save.
"use client";
import AIBranches, { type BranchMessage } from "@/components/kokonutui/ai-branches";
export function Thread({ messages, save }: { messages: BranchMessage[]; save: (m: BranchMessage[]) => void }) {
return (
<AIBranches
messages={messages}
onChange={save}
reply={async function* (prompt, history, signal) {
const res = await fetch("/api/chat", {
method: "POST",
body: JSON.stringify({
messages: [...history, { role: "user", text: prompt }].map((m) => ({ role: m.role, content: m.text })),
}),
signal,
});
if (!(res.ok && res.body)) {
throw new Error("Couldn't reach the model. Try again.");
}
const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
while (true) {
const { done, value } = await reader.read();
if (done) return;
yield value;
}
}}
title="Trip planning"
/>
);
}The route streams with streamText({ model, messages }).toTextStreamResponse().
PROSlash Command Menu and more like it are in Kokonut UI Pro
Installation
AI Conversation Branches is a free, open-source React component in the Kokonut UI AI collection. Add it with the shadcn CLI, which copies the source into components/kokonutui/ai-branches.tsx, so the code is yours to change.
npx shadcn@latest add @kokonutui/ai-branchesOr add it by hand: install its packages, then copy the source from Copy code above into components/kokonutui/ai-branches.tsx.
npm install lucide-react motionProps
titlestringDefault "Trip planning"messagesBranchMessage[]Default demo dataEvery message on every branch, read once on mount. Siblings form a fork.
reply(prompt: string, history: BranchMessage[], signal: AbortSignal) => BranchReplyDefault demo dataWrites the reply to an edited message. It gets the edit and the messages above it on that branch, and returns the reply, a Promise of it, or a stream of deltas (like the AI SDK's textStream). Throw and the reply shows the error's message. Demo text when omitted.
onChange(messages: BranchMessage[]) => voidEvery message on every branch, once a new branch's reply is in.
classNamestringExtra classes for the root element.
BranchMessage
idrequiredstringrolerequired"user" | "assistant"textrequiredstringparentstringId of the message this one answers or follows. Leave out for the first.
BranchReply
A reply: the text, a Promise of it, or a stream of text deltas.
type BranchReply = string | Promise<string> | AsyncIterable<string>;Dependencies
| Needs | Version | Comes from |
|---|---|---|
lucide-react | ^0.556.0 | npm, installed by the CLI |
motion | ^12.23.25 | npm, installed by the CLI |
cn from lib/utils.ts | shadcn init | |
| React | 19 | Your app |
| Tailwind CSS | 4 | Your app |
No provider, font or global CSS to set up: the file works as soon as it lands.
AI Token Alternatives
An answer where every unsure word shows what else the model weighed. Pick another word and the reply writes itself again from there.
AI Agent Lanes
A lead agent hands work to sub-agents that run side by side. Each gets a lane of tool calls, and you can scrub through the whole run.

