@assistant-ui/cloud-ai-sdk#
Part of assistant-ui monorepo. See root AGENTS.md for build commands.
React hooks bridging Vercel AI SDK (useChat) with assistant-cloud persistence. Works without the full @assistant-ui/react runtime.
Structure#
src/
βββ chat/
β βββ useCloudChat.ts # Main hook β orchestrates cloud + AI SDK
β βββ useCloudChatCore.ts # React lifecycle wrapper for CloudChatCore
β βββ useChatRegistry.ts # Manages Chat instances by thread/session key
β βββ ChatRegistry.ts # Chat instance store (non-React)
β βββ MessagePersistence.ts # Encodes/decodes UIMessage for cloud storage
βββ core/
β βββ CloudChatCore.ts # Orchestrator β persistence, thread creation, title gen
β βββ ThreadSessionManager.ts # Deduplicates concurrent thread creation
β βββ TitlePolicy.ts # One-time auto-title for new threads
βββ threads/
β βββ useThreads.ts # Thread list CRUD hook
β βββ generateThreadTitle.ts # Cloud API call for title generation
βββ types.ts # Shared types (UseCloudChatOptions, ChatMeta, etc.)
βββ index.ts # Public exports
Key Concepts#
Auto-cloud singleton β Created from NEXT_PUBLIC_ASSISTANT_BASE_URL env var at module load. Enables zero-config anonymous auth.
Two-layer pattern β useCloudChatCore (React lifecycle) wraps CloudChatCore (pure logic). The hook manages creation, syncing, and cleanup of the core instance across renders.
Chat registry β ChatRegistry + useChatRegistry manage multiple chat instances keyed by thread or session ID. Switching threads reuses existing instances.
Thread auto-creation β First message triggers thread creation in the transport layer. ThreadSessionManager deduplicates concurrent creation promises (no duplicates).
External vs internal threads β useCloudChat() creates its own useThreads internally. Pass { threads } from an external useThreads() to share thread state across components (e.g., sidebar + chat).
Title generation β Happens automatically as a side effect of message persistence (onFinish), not an explicit API call. TitlePolicy ensures it fires only once per thread.