Adapters
Turn native chat records into messages and connect supported commands.
Choose a normalizer, adapter, or store bridge
A normalizer turns native records into ChatMessage[]. Use an adapter when the view also needs commands such as send or stop. Use a store bridge to subscribe to a state store you already have. The SDK or your app still runs the model and tools.
| You already have | Use | State owner |
|---|---|---|
| Canonical messages | Direct view props | Application |
| Native records | chat-normalizers | Native client/application |
| A React SDK hook | useChatAdapter(adapter, hook, options) | SDK hook |
| A subscribed store | createChatRuntimeStore(source) | Existing store |
| An AG-UI client | createAgUiRuntime(client, options) | @ag-ui/client |
See runtime architecture for a complete store example and choose a runtime for native hook recipes. All paths render the same Message parts; there is no provider-specific view tree.
Convert messages
Import pure normalizers from @collectivecreation/ghost-ui/chat-normalizers. Pass records in order. The normalizers keep native IDs. If a record has no ID, provide getId(record) using a key that survives reordering and re-renders. This entry works without React or an SDK.
mapPart(part, message) returns a canonical part, null to deliberately omit it, or undefined for the built-in mapping. Raw reasoning is withheld unless classifyReasoning(part) explicitly returns provider-summary or application-summary. Keep secrets out of all client snapshots, including metadata.
| Function | Input |
|---|---|
normalizeLangChainMessages | BaseMessage instances or serialized message state, including removal records |
normalizeAgUiMessages | Native AG-UI client's reconstructed messages |
normalizeEveMessages | Eve hook's reconstructed messages |
normalizeOpenCodeMessages | SDK session.messages() records with info and parts |
normalizeOpenRouterItems | Ordered replacement items from the Agent SDK |
normalizeAdkEvents | Ordered ADK events; partial previews coalesce until the authoritative segment |
normalizeA2aMessages / normalizeA2aTask | A2A v1 messages / task with status, history and artifacts |
normalizeManagedAgentEvents | Ordered buffered session facts, replayed or tailed |
normalizeAssistantStreamMessage(id, value) | Message assembled by assistant-stream |
replaceChatRecordsById(records, getId) | Latest record per ID at its first insertion position |
Unknown content becomes an explicit unknown or data part. Native non-reasoning parts and metadata remain available for an application renderer; the native source remains authoritative. Normalization does not guarantee every native feature has a default visual representation.
Render custom content
Use MessageParts.renderers to show an app-specific part. The example checks a plan’s shape before rendering it with Todo list. Keep the part and task IDs stable when their contents change.
To produce that part from native content, validate it first, then return your app’s data part from mapPart. Check what custom content the native protocol can carry.
Bind native commands
Implement ChatAdapter<TBinding>.getSnapshot(binding, options) for another hook. Return canonical messages, identity, a ChatController and truthful capability declarations. The custom adapter example shows the full interface. Ghost's React binding guards current context and pending commands; do not rebuild that guard in each SDK integration.
Bind each command to an equivalent operation. Keep checkpoint forks, task reruns, permissions, and artifact actions on the native client when they have a different meaning. Convert attachments explicitly. Treat approval acknowledgement and execution results as separate events.
Troubleshoot missing content or actions
A missing message usually means a missing stable ID or a changed native shape. A visible unsupported-content notice means you need a deliberate mapPart or MessageParts.renderers choice. A disabled action can come from native availability or application policy; inspect both. See stability before upgrading an SDK.