- React
- Vue
- Lynx
- iOS
- Android
Drag a block. With the keyboard: Space picks it up, the arrow keys move it, Space puts it down, Escape puts it back.
- Claude Agent SDK
- LangGraph
- AI SDK
- Mastra
- AG-UI
UI, for two.
Your UI and your AI, finally on the same page.
Abstract
Today chat and GUI are two worlds: an agent either works the interface through screenshots, or leaves its results in a chat bubble. CoUI keeps UI = f(state), and gives the state two writers, the person and the agent. Every key keeps one layer per writer; the person’s shows on top, so an agent can never cover what a person set: its value waits underneath for approval. Three hooks that mirror useState, useRef and useCallback declare what the agent may read, write, point at and call; the store turns them into three fixed tools and a context any agent framework can take. CoUI is a library, not a framework: no server of its own, no wire protocol, no chat UI.
UI = f(state)
state = human ?? agent ?? initialcf. React: one writer1One state, two writers.
UI = f(state) stays. Only who can write the state changes: the person writes one layer, the agent another, and the person’s is on top.
A person sees, points, drags, editsWrites the human layer, always on top
| initial | agent | human | |
|---|---|---|---|
| maxPrice | null | 80 | 100 |
| kind | "all" | "shoes" | — |
| cart | [ ] | — | — |
| compare | [ ] | [p2,p3] | — |
- useCoState('maxPrice', null)
- useCoRef(product.id, name)
- useCoCallback('addToCart', fn)
- needsApproval
Two layers per key; the human’s showsApproval, take over and hand back are three readings of the two
setcallpointnever changestate:
maxPrice = 100 (by: human;
80 waiting)
kind = "shoes" (by: agent)
on screen:
#p1 Runner X, $112 <- pointing
callbacks:
addToCart({ id })
(needs approval)An agent reads the context, calls three fixed toolsWrites the agent layer, which never covers the human’s
- set maxPrice 100
- set maxPrice 80
- set kind "shoes"
- undo
- maxPrice shows 80
The person undoes their own step, and the agent’s latest value shows. Each side has its own undo.
| CoUI | React | Does |
|---|---|---|
useCoState | useState | State both the person and the agent read and write; each writes its own layer, the person’s on top. |
useCoRef | useRef | Makes an element something to point at: the person with the cursor, the agent with the point tool. |
useCoCallback | useCallback | A callback the person can click and the agent can call; with needsApproval, the agent’s calls wait. |
<CoUIProvider>, useCoUI | Context | The scope, and what is waiting, who points where, and the history undone per actor. |
2Nine moves, one surface.
Collaboration happens where the work is, not in a chat box beside it. The person is solid yellow-orange; the agent is violet, dotted while its value waits underneath.
01Point & sayCore
Point at it and say "this". The cursor gives the reference; the chat does not have to describe which one.
02Drag & dropCore
Drag a thing from the interface into the chat as context, or drag what the agent made back into the interface.
03Type & highlightSystem 1
While you type, the agent marks in the interface which part it understood you to mean.
04Select & askCore
Select a few things and ask, right there. The selection is the scope.
05Propose & reviewCore
The agent's change appears in place, dotted. It becomes solid only once you accept it.
06Watch & take overStretch
Watch the agent's cursor work step by step; take over at any point, and hand it back.
07Generate in placeStretch
A missing piece of interface is generated where it belongs, in the layout, not in a chat bubble.
08Undo by authorCore
History is kept by who did what: undo only the agent's steps.
09Point backCore
The agent points too: at something it objects to, or to ask “is this the one you mean?”. 01 and 09 are two directions of one state.
| Use case | Scene | Moves |
|---|---|---|
| ShoppingCore | “Anything cheaper?” Point at a pair of shoes; the agent filters to ≤ $80 and writes a comparison into the page. Adding to the cart waits for you. | 01 Point & say07 Generate in place05 Propose & review |
| DashboardCore | Point at a dip and ask why; the answer is a new chart on the board. The date filter is one CoState both write. | 01 Point & say07 Generate in place05 Propose & review |
| CalendarCoreSystem 1 | The agent draws free slots on the calendar, and points at one to object; pick one, or drag the meeting yourself. Sending invites waits for you. | 05 Propose & review09 Point back02 Drag & drop |
| InboxCore | “I’m off this week”: the mails on screen are sorted again; the one you sorted yourself stays. One key a mail; only mounted rows reach the agent. | 08 Undo by author |
| Photo retouchCore | “Like dusk, warmer” moves eleven sliders as one undo group; the one you set by hand keeps your value, the agent’s waits underneath. | 08 Undo by author |
| DocsSystem 1 | Select a sentence and drag along a few ways to say it, each with its probability; dragging previews, letting go decides. | 03 Type & highlight |
| Design canvasSystem 1Stretch | Select two cards and ask to align them; the new positions show dotted. Three generated hero directions are choices to drag in. | 04 Select & ask05 Propose & review02 Drag & drop |
| Agentic IDEStretch | Point at a broken button in the preview; the agent finds its line and proposes the fix as a diff. Code is long text: a next step. | 01 Point & say05 Propose & review06 Watch & take over |
3Works with what you have.
A library, not a framework: hooks for your UI framework, three tools and a context for your agent framework. No server, no protocol, no chat UI of its own.
function Shop({ products }: { products: Product[] }) { const [filter, setFilter, layers] = useCoState( 'filter', { maxPrice: null as number | null }, '商品筛选条件') const [addToCart, approvals] = useCoCallback( 'addToCart', ({ id }: { id: string }) => cart.add(id), { describe: '把一个商品加入购物车', schema: z.object({ id: z.string() }), needsApproval: true }, ) const visible = products.filter( (p) => filter.maxPrice == null || p.price <= filter.maxPrice) return ( <> <PriceSlider value={filter.maxPrice} onChange={(maxPrice) => setFilter({ maxPrice })} /> {layers.by === 'agent' && <Badge>agent 加的筛选</Badge>} {layers.approval && <Proposal {...layers.approval} />} {visible.map((p) => <ProductCard key={p.id} product={p} onAdd={() => addToCart({ id: p.id })} />)} {approvals.map((a) => <Confirm key={a.id} onApprove={a.approve} onReject={a.reject} />)} </> )}function ProductCard({ product, onAdd }: { product: Product; onAdd(): void }) { const ref = useCoRef<HTMLDivElement>(product.id, `${product.name}, $${product.price}`) return <div ref={ref}>{product.name} <button onClick={onAdd}>加入购物车</button></div>}// client: AI SDK's useChat, with the store's three fixed toolsconst store = useCoStore()const chat = useChat({ sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls, onToolCall: async ({ toolCall }) => chat.addToolOutput({ tool: toolCall.toolName, toolCallId: toolCall.toolCallId, output: await store.agent.execute({ id: toolCall.toolCallId, name: toolCall.toolName, input: toolCall.input, }), }),})function send(text: string) { const context = store.agent.context(seen.current) // full once, then a delta seen.current = context.version chat.sendMessage({ text, metadata: { coui: context.text } })}// server: your route; CoUI adds the tools and the context, nothing elseconst result = streamText({ model, messages: await convertToModelMessages(withCoContext(messages)), tools: coTools, // set, call, point})Draft: the API follows the design doc and will change.