Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Bot avatars show what their bot is doing, using `open-bot-avatar` 0.3.0: three hopping dots while it thinks, bent over the work while it writes, searches, remembers, or uses tools, an exclamation mark while it retries, a short celebration when a reply finishes, and waiting in a group chat while it answers next. Live avatars ease from one state to the next instead of restarting. The `/avatars` page previews every state. Paused bots and disabled automations no longer show a dimmed, still avatar.
- A bot's details in the web chat show **Usage**: tokens and cost for each model and tool its bot chat has used, with a total. Job panes now include tool costs, such as intent checks, in their cost.
- When a bot's model can't read images and no vision model is set, the web chat warns as soon as an image is attached and links to the bot's profile and the vision model setting. The server refuses such a message before recording a turn, so the error shows once, names the bot, and the message goes back to the composer. `GET /v1/models` returns `images` for each model.
- Pinned conversations are saved on the account, so every app shows the same pins in the same order. The session returns them as `pinnedConversations`, `update-user` saves the whole list (up to nine `agent:<id>` or `group:<id>` keys), and `/v1/events` sends a `pins` event to the account's open apps when they change. On the web, pin or unpin a bot chat or group chat from its **More** menu in the sidebar, and drag pins in the **Pinned** section to reorder them.
Expand Down
2 changes: 1 addition & 1 deletion THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Open Bot Avatar

Web avatars use `open-bot-avatar` 0.2.0, by Dominik Scholz, under the MIT License. The generation prompt in `apps/web/features/avatars/generate-avatar-prompt.txt` is copied from `DominikScholz/open-bot-avatar`, commit `386cd20258ae48f2e75345ce3c05e046e04d6ad7`, `skills/generate-avatar/references/system-prompt.md`.
Web avatars use `open-bot-avatar` 0.3.0, by Dominik Scholz, under the MIT License. The generation prompt in `apps/web/features/avatars/generate-avatar-prompt.txt` is copied from `DominikScholz/open-bot-avatar`, commit `386cd20258ae48f2e75345ce3c05e046e04d6ad7`, `skills/generate-avatar/references/system-prompt.md`.

```text
MIT License
Expand Down
12 changes: 9 additions & 3 deletions apps/docs/content/getting-started/first-bot.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ JSON response into **Import**. The copied prompt includes your description.
Crumble doesn't call a model from the avatar editor. A bot can also suggest its
own definition in chat for you to import.

The `/avatars` page previews idle, working, and sleeping states. Select a bot
and click **Save avatar to bot** to apply your choice. Sleeping avatars use a
dimmed still image. Live avatars respect your system's reduced-motion setting.
The `/avatars` page previews the idle, thinking, working, waiting, blocked,
and done states. Select a bot and click **Save avatar to bot** to apply your
choice. Live avatars respect your system's reduced-motion setting.

An avatar shows what its bot is doing. While the bot thinks, its body turns
into three hopping dots. While it writes, searches, remembers, or uses tools, it
bends over the work. When it retries, it shows an exclamation mark. When a reply
finishes, it celebrates for a few seconds. In a group chat, a bot that answers
next waits its turn.

Bots without a saved definition get a fresh gallery avatar with default colors.
The bot ID selects the shape; previous avatar shapes and colors don't affect it.
Expand Down
2 changes: 1 addition & 1 deletion apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"effect": "4.0.6",
"hono": "4.13.13",
"microsandbox": "0.7.8",
"open-bot-avatar": "0.2.0",
"open-bot-avatar": "0.3.0",
"pele": "1.9.0",
"pkijs": "4.0.0",
"railway": "3.16.0",
Expand Down
13 changes: 1 addition & 12 deletions apps/web/components/bot-avatar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Window } from "happy-dom";
import { act } from "react";
import { defaultAvatarDefinition } from "@crumble/server/contract/avatar";

test("static and live avatars update geometry, moods and colors, stop sleeping, and honor reduced motion", async () => {
test("static and live avatars update geometry, moods and colors, and honor reduced motion", async () => {
const window = new Window();
const globals = Object.getOwnPropertyDescriptors(globalThis);
const frames = new Map<number, FrameRequestCallback>();
Expand Down Expand Up @@ -82,17 +82,6 @@ test("static and live avatars update geometry, moods and colors, stop sleeping,
for (const fn of changes) fn();
await tick();
expect(frames.size).toBe(1);
await act(async () =>
root.render(<BotAvatar bot={bot} live state="sleeping" />),
);
expect(container.querySelector("[data-avatar-scene]")).toBeNull();
expect(container.querySelector("img")!.src).toBe(idle);
expect(
Number(
container.querySelector<HTMLElement>("[data-state]")!.style.opacity,
),
).toBeLessThan(1);
expect(frames.size).toBe(0);

const next = {
...bot,
Expand Down
43 changes: 25 additions & 18 deletions apps/web/components/bot-avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { type CSSProperties, useLayoutEffect, useMemo, useRef } from "react";
import { renderAvatarSvg } from "open-bot-avatar";
import { mountAvatar } from "open-bot-avatar/dom";
import { type AvatarState, renderAvatarSvg } from "open-bot-avatar";
import { type MountedAvatar, mountAvatar } from "open-bot-avatar/dom";
import type { BotAvatarDefinition } from "@crumble/server/contract/avatar";
import { cn } from "@/lib/utils";

export type BotState = "idle" | "working" | "sleeping";
export type BotState = AvatarState;

export type AvatarBot = { id: string; avatar: BotAvatarDefinition };

Expand All @@ -20,23 +20,35 @@ export function botStyle(color: string) {
function useLiveAvatar(
still: boolean,
look: BotAvatarDefinition,
mood: "thinking" | "idle",
state: AvatarState,
) {
const host = useRef<HTMLSpanElement>(null);
const avatar = useRef<MountedAvatar | null>(null);
const latest = useRef(state);

useLayoutEffect(() => {
if (still || !host.current) return;

const avatar = mountAvatar(host.current, {
const mounted = mountAvatar(host.current, {
...look,
mood,
state: latest.current,
reducedMotion: "system",
followPointer: true,
label: "",
});

return () => avatar.destroy();
}, [still, look, mood]);
avatar.current = mounted;

return () => {
mounted.destroy();
avatar.current = null;
};
}, [still, look]);

useLayoutEffect(() => {
latest.current = state;
avatar.current?.update({ state });
}, [state]);

return host;
}
Expand All @@ -57,33 +69,28 @@ export function BotAvatar({
}) {
const look = bot.avatar;

const still = !live || state === "sleeping";
const mood = state === "working" ? "thinking" : "idle";
const host = useLiveAvatar(still, look, mood);
const still = !live;
const host = useLiveAvatar(still, look, state);

const svg = useMemo(
() =>
still
? renderAvatarSvg(look.definition, {
color: look.color,
eyeColor: look.eyeColor,
motion: mood,
state,
reducedMotion: true,
})
: "",
[still, look, mood],
[still, look, state],
);

return (
<span
aria-hidden="true"
data-state={state}
className={cn("inline-block shrink-0", className)}
style={{
width: size,
height: size,
opacity: state === "sleeping" ? 0.45 : 1,
}}
style={{ width: size, height: size }}
>
{still ? (
<img
Expand Down
6 changes: 1 addition & 5 deletions apps/web/features/automations/automations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,7 @@ function AutomationName({
}) {
return (
<div className="flex min-w-0 items-center gap-3">
<BotAvatar
bot={bot}
size={28}
state={schedule.enabled ? "idle" : "sleeping"}
/>
<BotAvatar bot={bot} size={28} />
<div className="flex min-w-0 flex-col">
<span className="flex min-w-0 items-center gap-1.5">
<span className="truncate font-medium">{schedule.name}</span>
Expand Down
11 changes: 6 additions & 5 deletions apps/web/features/avatars/avatars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
invalidateBots,
} from "@/features/bots/api";
import { send } from "@/lib/api";
import { BotAvatar, type BotState } from "@/components/bot-avatar";
import { STATES } from "open-bot-avatar";
import { BotAvatar } from "@/components/bot-avatar";
import { AvatarEditor } from "./avatar-editor";

function useAvatarDraft() {
Expand Down Expand Up @@ -50,15 +51,15 @@ function useAvatarDraft() {

function AvatarStatePreviews({ value }: { value: BotAvatarDefinition }) {
return (
<div className="grid grid-cols-3 gap-4">
{(["idle", "working", "sleeping"] satisfies BotState[]).map((state) => (
<div className="mx-auto flex max-w-92 flex-wrap justify-center gap-4">
{STATES.map((state) => (
<div
key={state}
className="flex flex-col items-center gap-2 text-sm capitalize"
className="flex w-20 flex-col items-center gap-2 text-sm capitalize"
>
<BotAvatar
bot={{ id: "preview", avatar: value }}
size={96}
size={80}
live
state={state}
/>
Expand Down
44 changes: 33 additions & 11 deletions apps/web/features/bot-chat/avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
import { useEffect, useRef, useState } from "react";
import {
type AvatarBot,
type BotState,
BotAvatar,
} from "@/components/bot-avatar";
import type { Bot } from "@/features/bots/api";
import { isBusy, useWorking } from "./working";
import { type Working, isBusy, useWorking, workingAvatar } from "./working";

const avatarState = (
enabled: boolean,
working: ReturnType<typeof useWorking>,
): BotState => {
if (!enabled) return "sleeping";
const DONE_MS = 4000;

return isBusy(working) ? "working" : "idle";
};
function useJustFinished(working: Working) {
const [finished, setFinished] = useState(false);
const previous = useRef(working);

useEffect(() => {
const was = previous.current;

previous.current = working;

if (!isBusy(was) || working !== "idle") {
setFinished(false);

return;
}

setFinished(true);

const timer = setTimeout(() => setFinished(false), DONE_MS);

return () => clearTimeout(timer);
}, [working]);

return finished;
}

const avatarState = (working: Working, finished: boolean): BotState =>
finished ? "done" : workingAvatar(working);

export function LiveBotAvatar({
bot,
size,
className,
}: {
bot: AvatarBot & Pick<Bot, "enabled">;
bot: AvatarBot;
size: number;
className?: string;
}) {
const working = useWorking(bot.id);
const finished = useJustFinished(working);

const state = avatarState(bot.enabled, working);
const state = avatarState(working, finished);

return (
<BotAvatar
Expand Down
9 changes: 7 additions & 2 deletions apps/web/features/bot-chat/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useChatJobs } from "@/features/jobs/chat-jobs";
import { send } from "@/lib/api";
import { BotAvatar, botColor, botStyle } from "@/components/bot-avatar";
import { LiveBotAvatar } from "./avatar";
import { workingLabel, useWorking } from "./working";
import { isBusy, workingAvatar, workingLabel, useWorking } from "./working";
import {
type Conversation,
ConversationEmpty,
Expand Down Expand Up @@ -280,7 +280,12 @@ function WorkingStatus({ bot }: { bot: Bot }) {

return (
<div className="flex items-center gap-2.5">
<BotAvatar bot={bot} size={32} live state="working" />
<BotAvatar
bot={bot}
size={32}
live
state={isBusy(activity) ? workingAvatar(activity) : "working"}
/>
<span className="animate-pulse text-sm text-muted-foreground">
{workingLabel[activity]}…
</span>
Expand Down
9 changes: 9 additions & 0 deletions apps/web/features/bot-chat/working.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useSyncExternalStore } from "react";
import { type ChatSnapshot, chatQuery } from "@/features/chat/api";
import { queryClient } from "@/lib/api";
import { type Bot } from "@/features/bots/api";
import type { BotState } from "@/components/bot-avatar";

export type Working = ChatSnapshot["working"];

Expand All @@ -19,6 +20,14 @@ export function useWorking(id: string) {
export const isBusy = (working: Working) =>
working !== "idle" && working !== "failed";

export const workingAvatar = (working: Working): BotState => {
if (working === "thinking") return "thinking";

if (working === "struggling") return "blocked";

return isBusy(working) ? "working" : "idle";
};

export const workingLabel: Record<Working, string> = {
idle: "Working",
thinking: "Thinking",
Expand Down
10 changes: 8 additions & 2 deletions apps/web/features/group-chats/groups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
} from "./api";
import type { Message } from "@/features/chat/api";
import { call, queryClient, send } from "@/lib/api";
import { BotAvatar, botColor } from "@/components/bot-avatar";
import { BotAvatar, type BotState, botColor } from "@/components/bot-avatar";
import { ConfirmDeleteContent, MobileSidebarTrigger } from "@/components/page";
import {
ConversationEmpty,
Expand Down Expand Up @@ -78,6 +78,12 @@ const MEMBER_STATUS = {
idle: "is here",
};

const memberAvatar = (status: keyof typeof MEMBER_STATUS): BotState => {
if (status === "running") return "working";

return status === "queued" ? "waiting" : "idle";
};

const groupConversation = (
id: string,
): ConversationTarget<GroupChatSnapshot> => {
Expand Down Expand Up @@ -124,7 +130,7 @@ function GroupHeader({
<BotAvatar
bot={member}
size={26}
state={status === "running" ? "working" : "idle"}
state={memberAvatar(status)}
className={cn(status === "disabled" && "opacity-40")}
/>
</TooltipTrigger>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"cmdk": "1.1.1",
"cn": "0.5.0",
"cuelume": "0.2.8",
"open-bot-avatar": "0.2.0",
"open-bot-avatar": "0.3.0",
"pele": "1.9.0",
"react": "19.3.1",
"react-dom": "19.3.1",
Expand Down
6 changes: 3 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading