Skip to content
Source
Sign inSign up
jherr/labs-buddy

jherr/labs-buddy

README.md

Buddy

Animated avatar buddies for the web. A buddy is a static avatar plus a set of short looping video clips — one per pose (idle, thinking, talking, celebrating). A small state machine swaps clips as your app changes, so the character reacts to what it's doing.

Render one with a hook, let your customers build their own, and ship app-specific poses inside a single portable file.

Read the docs →

Meet Rocky

Rocky Maestro is the dealer from the cards example. He started life as a regular buddy with the standard poses:

Rocky idle
idle
Rocky greeting
greeting
Rocky thinking
thinking
Rocky talking
talking
Rocky done
done

Then the poker game augmented him with its own custom poses. They're generated from the same avatar and carried inside his .buddy file, so any app that loads Rocky gets them:

Rocky shuffling
dealer_shuffle
Rocky dealing
dealer_deal
Rocky collecting chips
dealer_collect
Rocky celebrating
dealer_celebrate
Rocky raising
player_raise
Rocky folding
player_fold
Rocky winning
player_win

The avatar is also a seed for other art. The game generates its card back and face cards from Rocky's avatar image (examples/cards/scripts/gen-card-art.mjs):

Rocky's avatar
avatar
→ Card back
card back
Jack
jack
Queen
queen
King
king

What you can build

  • A reactive assistant avatar that thinks while it waits and talks while it answers
  • A builder where your customers design and AI-generate their own buddies
  • Characters that carry app-specific poses — a card dealer that shuffles, a player that peeks
  • A library of shareable .buddy files users can upload and download

Install

# render & control a buddy
pnpm add @tanstack/buddy-react @tanstack/buddy-file

# embed the builder UI in your app
pnpm add @tanstack/buddy-ui @tanstack/buddy-server

React is shown throughout; Solid (@tanstack/buddy-solid) and Vue (@tanstack/buddy-vue) share the same shape with idiomatic wrappers.

Consuming & controlling a buddy

Load a .buddy, feed its clips to useBuddy, and drive the pose. A requested pose with no clip falls back to the resting pose, so a half-built buddy still renders.

import { getBuddy } from '@tanstack/buddy-file/browser'
import { useBuddy, BuddyAvatar } from '@tanstack/buddy-react'

const buddy = await getBuddy('/library/meemers.buddy')

function Meemers() {
  const { buddyProps, setPose } = useBuddy({
    avatarUrl: buddy.avatarUrl,
    clips: buddy.poseUrls,   // { idle, thinking, talking, … }
    homePose: buddy.homePose,
    name: buddy.meta.name,
  })

  return (
    <>
      <BuddyAvatar {...buddyProps} size={200} name="Meemers" status="Thinking…" />
      <button onClick={() => setPose('talking', { for: 2500 })}>Talk</button>
    </>
  )
}

→ Consuming a Buddy

Backgrounds & effects

Drop animated scenery around a buddy with the layers prop: animated backgrounds behind the character, effects in front, all inside the same bubble. It's pure app presentation, nothing is baked into the .buddy file, and the pose keeps playing underneath.

<BuddyAvatar {...buddyProps} background="#0f172a" layers={[{ preset: 'aurora' }, { preset: 'sparkles' }]} />
Sleep Zzz effect
glyphs-z
Aurora background
aurora
Starfield background
starfield
Sparkles effect
sparkles
Confetti effect
confetti
Snowfall effect
snow

Ten animated backgrounds and eleven effects ship as presets, or bring your own media. They show best over a transparent buddy, and respect prefers-reduced-motion.

→ Animated Layers

Letting customers create buddies

Mount the builder in your app and point it at endpoints backed by @tanstack/buddy-server. Customers describe a character, generate an avatar, add poses, chat with it, and save it.

import { BuddyProvider, BuddyBuilder } from '@tanstack/buddy-ui'
import '@tanstack/buddy-ui/styles.css'

<BuddyProvider endpoints={{ library: '/api/buddies' }}>
  <BuddyBuilder />
</BuddyProvider>
// server route — POST /api/ai/avatar
import { aiFromRequest, generateAvatar } from '@tanstack/buddy-server'

const ai = aiFromRequest(request, 'image', body.provider) // provider + key (BYOK or env)
if (ai instanceof Response) return ai                      // 401: ask the user for a key
const { avatarDataUri } = await generateAvatar({ prompt, imageDataUri, ai })

→ Letting Customers Create Buddies

AI providers & bring-your-own-key

Generation runs on TanStack AI, so you can pick the provider per job:

JobProviders (default first)
AvatarsGemini (Nano Banana 2), OpenAI (gpt-image-2), fal (Nano Banana 2)
Pose clipsGemini (Omni Flash), fal (Seedance Lite)
Personality & chatAnthropic (Claude Haiku), OpenAI, Gemini

OpenAI isn't offered for clips because its video API (Sora) was shut down in September 2026.

Keys come from either place:

  • Server keys. Set GEMINI_API_KEY (or GOOGLE_API_KEY), OPENAI_API_KEY, FAL_KEY and/or ANTHROPIC_API_KEY in the server's environment.
  • Users' own keys (BYOK). The builder's AI keys button lets each person pick providers and paste their own keys. Keys stay in the browser (encrypted with a passkey where supported, otherwise held in memory for the session) and are sent per request as x-byok-<provider> headers. They're never saved on the server. When a request needs a key nobody has supplied, the server answers 401 byok_missing and the builder prompts for it.

A user's key always wins over the server's. Set BUDDY_BYOK_ONLY=true to ignore server keys entirely, which makes a public deployment safe from running up your bill. BUDDY_IMAGE_PROVIDER, BUDDY_VIDEO_PROVIDER and BUDDY_TEXT_PROVIDER set the server's default provider for each job.

Uploading a buddy

A .buddy is one portable zip. Load a user's file in the browser, or persist it to your library server-side.

import { loadBuddyFromFile } from '@tanstack/buddy-file/browser'
const buddy = await loadBuddyFromFile(file) // → render with useBuddy
// server — POST /api/library (the canonical save; validates + rejects bad uploads)
import { saveBuddy } from '@tanstack/buddy-server'
import { nodeFsStorage } from '@tanstack/buddy-server/node'
const storage = nodeFsStorage({ dir: 'public/library', source: 'local', baseUrl: '/library' })
const { url } = await saveBuddy(storage, crypto.randomUUID(), bytes)

→ Uploading a Buddy

Custom poses

Give a buddy app-specific poses, carried inside its .buddy metadata. Pair each with a standard fallback so it degrades gracefully until the clip is generated.

import { resolvePose } from '@tanstack/buddy-core'

// custom clip if present → the fallback pose → home
setPose(resolvePose(buddy.poseUrls, 'player_look', 'thinking'), { for: 1500 })

In an app, augmentation is a server operation on ingestion (augmentBuddyOnIngest) — the customer holds the canonical buddy, the receiving server augments its own copy.

→ Custom Poses

Packages

PackageRole
@tanstack/buddy-coreFramework-agnostic pose controller + DOM renderer
@tanstack/buddy-react / -solid / -vueuseBuddy hook + BuddyAvatar component
@tanstack/buddy-fileRead, write, and cache .buddy files
@tanstack/buddy-uiDrop-in builder UI (<BuddyProvider> + <BuddyBuilder>)
@tanstack/buddy-serverAI generation + library storage, framework-agnostic

→ Packages reference

Repo layout

packages/   the @tanstack/buddy-* libraries
apps/       buddy-builder (the builder app + CLI scripts), framework examples
examples/   cards — a poker/blackjack demo of custom poses
docs/        the documentation (start at getting-started/overview.md)

This is a pnpm monorepo — use pnpm, not npm.

pnpm install
pnpm dev     # runs the builder at http://localhost:3000

Guides