Reference Repositories
- TanStack AI - Framework and adapters for AI chat, streaming, tools, and provider integrations
Upstream Grounding
When TanStack AI behavior, createChat, streamed message parts, tool calling, approvals, provider adapters, or Svelte bindings affect correctness, ask DeepWiki a narrow question against TanStack/ai before relying on memory. Use it to orient, then verify decisive details against local installed types, source, or official docs before changing code.
Skip DeepWiki for repo-local chat persistence and UI patterns already visible in the app.
When to Apply This Skill
Use this pattern when you need to:
- Build or refactor chat state based on
createChat. - Convert persisted workspace messages to or from TanStack AI
UIMessagevalues. - Render
MessagePart, tool-call, or tool-result parts. - Bridge workspace actions into TanStack AI tools.
- Debug streamed responses, reload behavior, stop behavior, or tool approvals.
Package Boundaries
- Server activity functions live in
@tanstack/ai:chat, generation helpers, stream conversion, model-message conversion, and server tool definitions. - Client lifecycle lives in
@tanstack/ai-client: chat client state, stream processing, tool approval plumbing, and client tool results. - Svelte runes integration lives in
@tanstack/ai-svelte:createChat,fetchServerSentEvents, and Svelte-friendly reactive state. - Import provider adapters from their specific packages for tree shaking, such as
@tanstack/ai-openaior@tanstack/ai-anthropic.
Streaming And Tool Calls
- Prefer
toServerSentEventsResponseon the server andfetchServerSentEventson the client for chat streams. - Treat AG-UI stream chunks and
MessagePartvariants as a discriminated stream protocol. Render every known part deliberately and keep an unknown fallback for forward compatibility. - Use
StreamProcessorwhen replaying, debugging, or transforming stream chunks outside the normal chat client. - Approval flow uses the approval id. Do not assume it is the same as the tool call id.
- After a client tool produces a result, continue the chat through the TanStack AI client path instead of manually appending a fake assistant response.
- In Svelte components that own a chat instance, call
chat.stop()or dispose the owner on unmount when a stream may still be active. - Use
aiEventClientobservability events when diagnosing stream, adapter, or tool behavior.
Local Anchors
apps/tab-manager/src/lib/chat/chat-state.svelte.tsshows Svelte chat state, streaming, and tool approval handling, with the conversation list derived from the handle registry.apps/tab-manager/src/lib/chat/persistence.tsowns the device-local IndexedDB chat store behindChatClientPersistence.apps/opensidian/src/lib/chat/ui-message.tsshows the persisted-message to TanStack-message boundary for workspace-backed chat history.packages/workspace/src/ai/tool-bridge.tsconverts workspace actions into client tools and serializable server tool definitions.