Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

custom-adapters.md

39 lines1.8 KB

1---
2title: Custom Chat UI Adapters
3id: typed-headless-ui-custom-adapters
4order: 5
5description: "Build a chat UI adapter for a framework that has none. @tanstack/ai-client/ui gives you the types and selectors. Your adapter adds components and reactivity."
6keywords:
7 - tanstack ai
8 - createChatUI
9 - custom adapter
10 - headless ui
11---
12​
13Build a chat UI adapter on `@tanstack/ai-client/ui`. That subpath exports the types and selectors. Your adapter adds the components.
14​
15## What the core gives you
16​
17Import from `@tanstack/ai-client/ui`, not from the main client entry:
18​
19- `selectChatUI`: matches tool results to tool calls, and splits list interrupts from inline interrupts.
20- `partTypeToKey`: turns a part type such as `tool-call` into a map key such as `toolCall`.
21- Option types for tools, generic interrupts, and `outputSchema`.
22​
23## What your adapter owns
24​
25- Native components and context.
26- Native reactivity.
27- Render callbacks, slots, or snippets.
28- Development warnings for missing map keys.
29​
30Do not add default markup. Do not add a new store. The app owns the chat instance, from `useAppChat` in `createChatHook`, or from `useChat` or `createChat`.
31​
32## Build it
33​
341. Call `selectChatUI({ messages, interrupts, inlineToolNames })`.
352. In automatic traversal, skip a `tool-result` part only when `matched` is `true`. Keep unmatched results.
363. Warn once for each missing runtime key in development. Each build tool detects development mode in a different way, so the adapter prints the warning.
374. Match the public names of the existing adapters: `Chat`, `Provider`, `Messages`, `Message`, `Part`, `Interrupts`, `Interrupt`, `useChatContext`, and `createChatHookContexts`.
38​
39The [React](./react), [Solid](./solid), [Vue](./vue), [Svelte](./svelte), and [Remix](./remix) adapters show those names in use.