Build an AI chat interface
Separate conversation views from model transport and application policy.
What does the chat UI own?
Ghost's Chat provides composable conversation views, message parts, and composer surfaces. Your application owns the conversation data and decides what messages mean. The UI does not call a model, store transcripts, enforce policy, or execute tools merely because a control is visible.
Start with the reader's task: a support exchange, a read-only transcript, or a tool-assisted workflow. Keep speaker identity and message order stable. Render streaming as the data arrives, but do not mistake a completed network request for a useful final answer. Show connection errors and recovery where the caller can actually retry. For observable operations, use Activity; it is Ghost's owner for trace-like steps, not a second chat transcript.
Should I use an SDK adapter?
Use the SDK-free view when you already own message state or use a custom transport. Add an adapter when its supported SDK hook and commands fit your application. Ghost documents optional AI adapters and AI integrations; the base chat data contract does not require a vendor runtime.
| Layer | Owns |
|---|---|
| Chat view | Rendering supplied messages, content, and composer interaction |
| Adapter | Mapping supported SDK data and exposing native commands |
| Application | Transport choice, policy, persistence, tool execution, and user disclosure |
The Vercel AI SDK and TanStack AI have distinct hooks, message shapes, and command behavior. An adapter preserves those differences; it does not make their capabilities interchangeable. See the AI runtime overview before choosing an integration. SDKs are optional dependencies, not hidden requirements of the core views.
MessageEdit owns a local draft, not transcript persistence. A native SDK edit command may replace later history; offer edit-and-regenerate only when the host supplies a targeted callback that preserves unrelated messages and replaces the explicitly linked reply. Otherwise, leave that action unavailable.
How should tool approval and cancellation work?
Keep approval separate from execution. A user approving a requested action is not proof that the action ran; show its result only after the application reports it. Keep tool identity and arguments associated with the request, and let policy decide what needs confirmation. If an SDK's current command needs a particular request ID or revision, use the adapter's documented native input.
Cancellation is a command to the active runtime or transport. Preserve partial history and indicate that work stopped; do not display cancellation as success. Unknown tool capabilities should remain unknown rather than being guessed from callback presence. Activity can render caller-provided status, but does not perform retry or cancellation itself.
What if the assistant appears stuck or repeats work?
Separate transport state from application state. Confirm that the runtime emits updates, the adapter maps the current version's shape, and the view receives stable message IDs. A retry command may target only the latest answer in one runtime while another supports a specific message. Keep failure status actionable without implying that Ghost supplies a server-side retry.
Follow the copyable examples on Chat, Activity, and Blocks. Install source with Installation; package exports and CSS setup differ from registry source. Avoid copying a demo's deterministic local transport and presenting it as a production connection.