Adding an Interactive Rive Mascot to assistant-ui and shadcn AI Chat Components
By the Charmotion team · Updated · How we write guides

Add the Rive React runtime to your assistant-ui or shadcn AI chat, load one .riv mascot file with a mood number input, and map the chat's state to that number: wave on the welcome screen, think while the reply streams, and turn sad on an error. Both libraries copy their code into your project.
Key takeaways
- Install @rive-app/react-canvas and load one .riv file that has a mood number input.
- assistant-ui exposes Welcome and ToolFallback slots on Thread, which are the natural places for a mascot.
- The shadcn AI Elements Chat pattern is copied in with the CLI, so you edit the avatar area directly.
- Keep the chat-to-mood mapping in one function so every state change happens in one place.
- Fix the canvas size and offer a still fallback to protect layout and reduced-motion users.
Already have a character or logo? See examples in real app screens: splash, onboarding, loading and empty-state screens, with the animation that plays in each.
Why put a Rive mascot in an AI chat interface?
A chat screen has a few states a person can read at a glance: an empty thread, a reply that is still arriving, a tool call that is running, and a failed request. A mascot that changes with those states shows what the app is doing without a spinner or extra text. The same character can greet on the welcome screen, look thoughtful while the model works and look sad when a request fails.
This guide shows how to add an animated Rive mascot to assistant-ui or shadcn AI chat components, with code for each. It covers the install steps, the mapping from chat state to mood, placement in each library and the performance details that matter on a chat page.
Rive fits this job because one .riv file holds every state. Rive's runtimes are open source and play any .riv file, so the character loads once and changes state from code. You do not swap GIFs or stack videos for each reply.
How do assistant-ui and shadcn AI Elements differ for a mascot?
Both give you chat components you own, but they split the work differently.
| assistant-ui | shadcn/ui AI Elements | |
|---|---|---|
| Base | Unstyled React primitives from @assistant-ui/react, plus styled elements such as Thread | Patterns composed from shadcn/ui components, such as the Chat pattern |
| How code arrives | Styled elements are copied into components/assistant-ui/elements; primitives and runtimes are npm dependencies | Copied into your project with the shadcn CLI; no package to install |
| Runtime | useChatRuntime from @assistant-ui/ai-sdk, passed to AssistantRuntimeProvider | Any chat hook you choose; the Vercel AI SDK's useChat is a common choice |
| Where the mascot goes | Welcome and ToolFallback slots on Thread | The avatar area inside the copied Message code |
The Vercel AI Elements project is being folded into shadcn/ui, and the timing of its retirement is covered in the FAQ below. Projects that already copied components from elements.ai-sdk.dev do not need to migrate in order to add a mascot.
If you build the chat inside an AI app generator first, the setup differs, so see adding a Rive mascot in Bolt.new, v0 and Replit or adding a Rive mascot to a Lovable app.
How do you add a Rive mascot to an assistant-ui thread?
Start with the library. Use init in an existing project. Use create to scaffold a new Next.js app. Thread and other styled elements land in components/assistant-ui/elements, while the primitives and runtime are npm dependencies you can update with the CLI.
npx assistant-ui@latest init
npx assistant-ui@latest create my-chatNext, install the Rive React runtime. The package exposes a useRive hook that returns a Rive instance and a component to render. The Canvas2D build is the one Rive recommends for most apps unless you need a WebGL renderer.
npm install @rive-app/react-canvasPut the file at public/mascot.riv. A file that names its state machine CharacterStateMachine and its number input mood matches the component below. If your file uses other names, change the two constants. Size the canvas with a class in your own stylesheet, for example a 160 pixel square, so the layout holds while the file loads.
'use client';
import { useEffect } from 'react';
import { useRive, useStateMachineInput } from '@rive-app/react-canvas';
const STATE_MACHINE = 'CharacterStateMachine';
export function Mascot({ mood = 0 }: { mood?: number }) {
const { rive, RiveComponent } = useRive({
src: '/mascot.riv',
stateMachines: STATE_MACHINE,
autoplay: true,
});
const moodInput = useStateMachineInput(rive, STATE_MACHINE, 'mood');
useEffect(() => {
if (moodInput) moodInput.value = mood;
}, [moodInput, mood]);
return <RiveComponent />;
}The useStateMachineInput hook still works, but the Rive React docs mark it deprecated in favour of data binding hooks. The same .riv can also expose a number property called mood on CharacterViewModelMachine, so you can move to data binding later without changing the animation.
Now connect the thread. Build the runtime with useChatRuntime from @assistant-ui/ai-sdk, pair it with an AssistantChatTransport, and pass it to AssistantRuntimeProvider. Render Thread inside that provider, and place the mascot inside the same tree so the state you pass down reaches it.
Thread accepts component overrides. Replace the Welcome slot with a component that shows the mascot at mood 2, the wave, so the new-chat screen greets the user. Replace the ToolFallback slot with a component that shows the mascot at mood 5, loading, while a tool without a registered UI runs. The rest of the thread stays as the library ships it.
How do you map chat state to mascot moods?
The mood numbers are fixed: idle 0, happy 1, wave 2, thinking 3, sad 4, loading 5, listening 6, talking 7, sleeping 8, attention 9. Moods blend into each other, so a change in the middle of a stream looks smooth rather than cut. Characters have no one-shot triggers, so show success with happy and an error with sad.
| Chat state | Mood | Number |
|---|---|---|
| Welcome screen, no messages | wave | 2 |
| User is typing | listening | 6 |
| Reply started, no text yet | thinking | 3 |
| Reply text is streaming | talking | 7 |
| Tool runs without its own UI | loading | 5 |
| Reply finished | happy, then idle | 1, then 0 |
| Request failed | sad | 4 |
Keep the mapping in one function rather than spreading it across components. Your chat hook's status values feed the function, and the mascot only receives a number.
export function moodFor(state: string): number {
switch (state) {
case 'welcome': return 2;
case 'typing': return 6;
case 'thinking': return 3;
case 'talking': return 7;
case 'tool': return 5;
case 'done': return 1;
case 'error': return 4;
default: return 0;
}
}A short delay after a reply finishes lets the happy state show before the mascot returns to idle. The timing is a product choice, so tune it on a real device. For the broader state design, see animating a chat avatar from streaming events.
How do you add an animated Rive mascot to a shadcn AI chat?
The shadcn AI Elements Chat pattern is a composition of Message Scroller, Message, Bubble and Input Group. The docs install those pieces with one CLI command, and the code lands in your project:
pnpm dlx shadcn@latest add message-scroller message bubble input-groupPlacement matters for a mascot. The docs say the person's message serves as the scroll anchor, so a new question settles near the top while the reply streams in beneath it. A mascot placed above the message list can push that layout around. Put it where the assistant's avatar sits, inside the copied Message code, and give it a fixed size.
Because the code is yours, edit the Message source directly. Render your Mascot in the assistant avatar position, pass it the mood from the function in the previous section, and read the copied files for their current props instead of copying an older snippet from a tutorial.
Each pattern is copied in rather than installed as a package, so an update means re-running the CLI for the component you want. Keep your mascot wrapper in its own file so it survives that update.
How do you keep the mascot fast, accessible and calm?
A chat page renders often, so the mascot should cost little. These rules matter most:
- Mount one canvas per visible mascot. Do not create a new Rive instance for each message bubble.
- Fix the size. Give the canvas a set width and height so the layout does not shift when the file loads.
- Lazy-load below the fold. A mascot in the header should load with the page; one in a side panel can wait.
- Load the runtime once. The Rive WASM module loads from the default unpkg CDN unless you host it yourself, and both options are in the Rive docs.
- Keep it decorative. Pair the mascot with text that says the same thing, such as a status line that reads Thinking, and keep the canvas out of the reading order.
- Offer a still fallback. Export a transparent poster frame for each animation and use it in place of the moving file when prefers-reduced-motion is set.
For the motion rules behind that fallback, see accessible animation and reduced motion.
Where does the .riv file come from?
You can make the file in the Rive editor. On Rive's Free plan, exported files play a Rive splash screen, and paid plans export without it, so read whether Rive is free before you ship.
If you have one finished character image and no animator, Charmotion can produce the file. The image must be one character facing the viewer with visible eyes and mouth, since sketches, photos and busy scenes are refused without a charge. You pick the animations (idle is always included), and the output is one .riv with CharacterStateMachine and a mood input, plus paste-ready React code, a README and an AI_README for coding assistants.
Plans and credit amounts are on the Charmotion pricing page. For the chatbot side of the work, see chatbot avatar animation.
Add an interactive Rive mascot to an assistant-ui or shadcn AI chat
- Set up the chat library. Run npx assistant-ui@latest init in an existing project, or add the shadcn Chat pattern with pnpm dlx shadcn@latest add message-scroller message bubble input-group.
- Install the Rive React runtime. Run npm install @rive-app/react-canvas and place your .riv file in public/.
- Build the Mascot component. Load the file with useRive, bind the mood input on CharacterStateMachine, and mark the component as a client component in Next.js.
- Map chat state to mood numbers. Write one function that turns runtime states into mood numbers, such as 2 for the welcome screen, 3 for thinking, 7 for talking and 4 for an error.
- Place the mascot in the chat. For assistant-ui, override the Welcome and ToolFallback slots on Thread. For shadcn, render the mascot in the avatar area of the copied Message source.
- Test each state. Send a message, force a failed request, and check that the mascot changes mood at each step and returns to idle.
Frequently asked questions
Can I use a Rive mascot with the Vercel AI SDK without assistant-ui?
Yes. The Rive React runtime does not depend on a chat library. Read the request state from your chat hook, pass it through the same moodFor function, and give the number to the mascot. The runtime needs only a canvas and a .riv file, so the mascot works the same way in any React chat.
Is the Vercel AI Elements project being retired?
Its README says it will be deprecated at the end of November 2026 and replaced by AI Elements from shadcn/ui. Projects that copied components from elements.ai-sdk.dev keep working, according to the shadcn docs. Check the repository before you start a new project, because the retirement date is a stated plan.
Will a Rive mascot slow down a chat page?
It adds the Rive runtime and one .riv file. Keep the file small, load it once, set a fixed canvas size and lazy-load it when it sits below the fold. The real cost depends on your file and your bundle, so measure the page before and after you add it.
Does the mascot need a Rive account?
No. Rive's runtimes are open source and play any .riv file, so a website does not need an account to show one. You need an account only to edit the file in the Rive editor. Exported files on Rive's Free plan play a splash screen, so check the current terms before you ship.
Sources
- Thread (assistant-ui docs), assistant-ui
- Components concept (assistant-ui docs), assistant-ui
- AI Elements (shadcn/ui docs), shadcn/ui
- Chat pattern (shadcn/ui docs), shadcn/ui
- Rive React runtime overview, Rive
- Vercel AI Elements (README), Vercel (GitHub)