# AI data and commands

Know what a message, tool result, or command represents in the UI.

## Read messages and parts

ChatMessage requires id, actor (user, assistant, system) and ordered parts. Optional status is queued, streaming, complete, stopped or error. createdAt accepts Date or string; serialize dates explicitly for storage. metadata carries application records. Ghost does not validate your persisted database schema.

ChatPart discriminates text, file, source, citation anchor, tool, reasoning summary, activity, input request, custom data, error and unknown content. Preserve meaningful IDs for tools, files, sources and requests; assign stable IDs to changing text/custom parts too. Array order records transcript order. The default [Message composition](/ai-elements/message) can group user attachments separately. Do not regroup all tools or sources ahead of interleaved text unless your product explicitly calls for that composition.

Adapters keep message IDs and merge tool results where their calls appeared. Text and reasoning summaries without IDs get separate numbered IDs within each category. Growing text and new parts of other types preserve those IDs.

The AI SDK can supply reasoning IDs. TanStack thinking parts use append order. If summaries can be inserted or reordered, supply durable IDs. Duplicate summary IDs produce diagnostics. Invalid tool IDs or states become errors or read-only content. Keep the original SDK record if your app needs fields that the view drops.

## Track tool approval and execution

ToolPart.state describes input, approval, running, output, error or cancellation. Its approval has a separate ID and pending/approved/denied state. An approved request does not mean a tool ran or succeeded. AI SDK output-available with preliminary: true projects as running while retaining the preview payload; only a final output is output-ready. Use the output/error state reported by the executing application. Never run a tool because a component became visible or because an approval callback exists.

Pass a live request getter to bindApproval so an old view can’t approve a replacement request. The AI SDK uses its approval callback and current tool. TanStack v1 uses a bound tool-approval interrupt and the current interrupt list and resume state. See the [TanStack approval lifecycle](/libraries/ai-runtime-tanstack#approval).

Authorize and persist tool actions on the server, and make repeated requests safe. For clarification, supply a request ID and a nonnegative revision. The binding prevents duplicate answers for that revision. Your app acknowledges the answer.

The optional [chat runtime](/libraries/ai-runtime) checks that commands still apply to the current conversation. The SDK or app continues to hold conversation state.

## Check available commands

A ChatController needs a status and a send(ComposerSubmission) command. Show Stop, Retry, Edit, and tool approval when their commands are available.

editAndResubmit follows the SDK’s rules and may replace later messages. To edit one message and regenerate only its linked reply, target those two records and preserve all other IDs, order, parts, and files. Ignore duplicate or stale completions.

A stop request can close the stream while a remote tool is still running. Show cancellation when the owner confirms it. Use thread identity and revision to ignore late results.

Adapter capability flags describe native normalization/command support. activity: false means no automatic SDK activity stream: caller-provided activityEvents still render through the same canonical Activity view. attachments: false means outbound attachment conversion is application-owned; normalized inbound files can still render. Both default send bindings reject nonempty attachments. nativeReasoning: false does not authorize exposing private reasoning.

## Map custom data

Use mapData for custom data, mapInputRequest to ask a question, and mapAuthor or mapDelivery to show identity or delivery status. Only classify content as a reasoning summary if the provider or app explicitly exposes it as one. Ghost omits unclassified reasoning.

MessageParts.renderers replaces rendering by part type and receives the ordered-part context. Dispatch a data part by its name in your renderer; keep application-specific schemas outside the core union. Preserve the existing view parts and user-controlled disclosure when replacing a snapshot. Use lower-level [Message](/ai-elements/message), [Tool](/ai-elements/tool), [Activity](/ai-elements/activity) or [Citation](/ai-elements/citation) parts when the default renderer does not fit your layout.

## Imports and troubleshooting

Import contracts from @collectivecreation/ghost-ui/chat-model; import MessagePartsProps and PartRenderer from the message-parts component subpath. [SDK integrations](/libraries/ai-integrations) describes adapters. A hidden reasoning summary usually needs explicit classification. An unknown tool result usually lacks a matching earlier call. Missing actions usually mean an unsupported or absent command; do not manufacture an action to hide that gap.
