Migrations
Migration to v0.12
Major Architecture Change: Unified State API
Version 0.12 introduces a complete rewrite of the state management system with a more consistent API.
Breaking Changes
1. Context Hooks Replaced with Unified State API
All individual context hooks have been replaced with a single useAssistantState hook and useAssistantApi for actions.
What changed
The following hooks have been removed:
Removed Hooks:
useMessageUtils→ UseuseAssistantState(({ message }) => message.isHovering)/useAssistantState(({ message }) => message.isCopied)useMessageUtilsStore→ UseuseAssistantApi()withapi.message().setIsHovering()/api.message().setIsCopied()useToolUIs→ UseuseAssistantState(({ tools }) => tools)anduseAssistantApi()withapi.tools()useToolUIsStore→ UseuseAssistantApi()withapi.tools()
Deprecated Hooks:
useAssistantRuntime→ UseuseAssistantApi()useThread→ UseuseAssistantState(({ thread }) => thread)useThreadRuntime→ UseuseAssistantApi()withapi.thread()useMessage→ UseuseAssistantState(({ message }) => message)useMessageRuntime→ UseuseAssistantApi()withapi.message()useComposer→ UseuseAssistantState(({ composer }) => composer)useComposerRuntime→ UseuseAssistantApi()withapi.composer()useEditComposer→ UseuseAssistantState(({ message }) => message.composer)useThreadListItem→ UseuseAssistantState(({ threadListItem }) => threadListItem)useThreadListItemRuntime→ UseuseAssistantApi()withapi.threadListItem()useMessagePart→ UseuseAssistantState(({ part }) => part)useMessagePartRuntime→ UseuseAssistantApi()withapi.part()useAttachment→ UseuseAssistantState(({ attachment }) => attachment)useAttachmentRuntime→ UseuseAssistantApi()withapi.attachment()useThreadModelContext/useThreadModelConfig→ UseuseAssistantState(({ thread }) => thread.modelContext)useThreadComposer→ UseuseAssistantState(({ thread }) => thread.composer)useThreadList→ UseuseAssistantState(({ threads }) => threads)
Migration Examples
Before:
import {
useThread,
useThreadRuntime,
useComposer,
useComposerRuntime,
useMessage,
useMessageRuntime,
} from "@assistant-ui/react";
function MyComponent() {
// Reading state
const messages = useThread((t) => t.messages);
const isRunning = useThread((t) => t.isRunning);
const composerText = useComposer((c) => c.text);
const messageRole = useMessage((m) => m.role);
// Using runtime for actions
const threadRuntime = useThreadRuntime();
const composerRuntime = useComposerRuntime();
const messageRuntime = useMessageRuntime();
const handleSend = () => {
composerRuntime.send();
};
const handleReload = () => {
messageRuntime.reload();
};
const handleCancel = () => {
threadRuntime.cancelRun();
};
return null;
}After:
import { useAssistantState, useAssistantApi } from "@assistant-ui/react";
function MyComponent() {
// Reading state - all through single hook
const messages = useAssistantState(({ thread }) => thread.messages);
const isRunning = useAssistantState(({ thread }) => thread.isRunning);
const composerText = useAssistantState(({ composer }) => composer.text);
const messageRole = useAssistantState(({ message }) => message.role);
// Using API for actions
const api = useAssistantApi();
const handleSend = () => {
api.composer().send();
};
const handleReload = () => {
api.message().reload();
};
const handleCancel = () => {
api.thread().cancelRun();
};
return null;
}Getting Help
If you encounter issues during migration:
- Check the updated API documentation for detailed examples
- Review the example applications in the repository
- Report issues at https://github.com/assistant-ui/assistant-ui/issues