TanStack AI
Connect a TanStack AI chat and handle native tool approvals.
Connect TanStack AI
Install Ghost UI and its view dependencies, then add the matched TanStack v1 packages.
Pass your HTTP or AG-UI ConnectionAdapter to the example. TanStack uses it to send requests, receive the stream, and handle cancellation.
Commands and extension points
Keep messages and transport in TanStack’s hook. The adapter connects send, stop, and regeneration of the latest answer. Provide setMessages for local edit and resend. Editing truncates local history before resending, so reconcile saved history and failed resends in your app.
Supply the adapter's normalization options for deliberate part mappings and reasoning summaries. Supply runtime availability to disable actions for application policy. Attachments need the explicit outbound converter described in runtime integration; unsupported files are rejected rather than dropped.
Approve a native interrupt
Register the same tool definitions on client and server. For tools with a yes/no approval and no extra response fields, pass the native hook into this view. bindApproval({ interrupt, getCurrent }) checks the current interrupt ID, tool call, thread, interrupted run, generation, lifecycle and expiry before calling its native resolveInterrupt(approved). Keep a live getter; a saved handle cannot authorize a replacement run.
A decision can wait while other items in the batch are unanswered. The last valid decision submits the batch. Wait for the execution result before showing success. Use resolveInterrupt(false) to deny a tool and cancel() to cancel the item without a decision.
Use TanStack’s resolveInterrupts, clearResolution, retryInterrupts, and typed forms for batch review, recovery, or extra fields. Ghost’s boolean binding rejects required payloads and unknown decision schemas. Handle generic and unbound pauses in your app. Keep native errors visible when there’s no actionable item.
See the interactive native example, native approval forms and batch lifecycle.
Upgrade from TanStack 0.x
Upgrade the server and client together to the checked v1 versions. Replace the old Ghost binding { approvalId, addToolApprovalResponse, getCurrent } with { interrupt, getCurrent }, where interrupt is the matching bound tool-approval item from chat.interrupts. The new getter returns the current native interrupts and resuming values. A full-hook useChatAdapter(adapter, chat, options) binding supplies these directly; hand-picked bindings must include both to expose the shared approval command.
Forward parentRunId and resume on the server. Finish or discard 0.x pauses before upgrading because v1 uses a different wire format. Keep your previous app source, tool definitions, and lockfile together for rollback. The examples previously used @tanstack/ai@0.54.0, @tanstack/ai-client@0.31.1, and @tanstack/ai-react@0.24.1. See TanStack’s v1 migration guide for server changes and Migrate AI views for UI changes.
Troubleshooting and native APIs
A missing answer usually indicates a protocol/transport mismatch. Inspect native errors first, then capability support/availability. Keep one hook owner per context and advance the identity revision on replacement. Retain the native hook for capabilities whose semantics are richer than a generic message command.
TanStack AI documentation covers connection adapters, client tools and state. The AG-UI connection is optional; direct AG-UI preserves an existing HttpAgent client.
AG-UI through a TanStack connection
Keep this route when TanStack already owns your chat client. Supply your authenticated endpoint and real thread ID. The connection decodes AG-UI through TanStack; it does not adopt a second native AG-UI client. For an existing HttpAgent and its shared state, choose the direct client.