Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Model badge on bot avatars (frontend, pairs with #554) (#560)

Oleksandr Ivanchenko83493fc72065
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index a2403d2f..e2ae941a 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -77,7 +77,8 @@ import { ManageTeamModal } from './components/ManageTeamModal';
import { playSfx } from './audio/chiptune';
import { haptic, messageHaptic } from './haptics';
import { Toasts, Toast } from './components/Toasts';
-import { clearAllTurns, resetTurns, turnEnded, turnStarted } from './kwantActivity';
+import { clearAllTurns, forgetLastRuns, resetTurns, turnEnded, turnRunsOn, turnStarted } from './kwantActivity';
+import { setBadgeBots, setBadgeEngines } from './modelBadgeData';
import { setKnownBots } from './botLooks';
import { clearMoods, moodOutput, moodTurnEnded, moodTurnStarted, restingUntil, setMoodNeedsYou, setMoodResting } from './kwantMood';
import { browserTabDoc, createTabSignal, needsYouCount } from './tabSignal';
@@ -1223,6 +1224,10 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({
}
break;
}
+ case 'turn_runs_on':
+ // The engine and model a turn runs on: at its start, and again when it fails over (model badge).
+ if (event.data?.kwant_id) turnRunsOn(event.data.kwant_id, event.data);
+ break;
case 'thread_updated':
case 'ThreadUpdated': {
const t: Thread | undefined = event.data?.thread;
@@ -3625,6 +3630,13 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({
const spriteOf = useCallback((id: string) => kwants.find((k) => k.id === id)?.avatar_sprite, [kwants]);
// Avatars that only know a bot's title or name look its saved style up here.
useEffect(() => setKnownBots(kwants), [kwants]);
+ // The model badge on each bot's avatar: its pick and last reply's engine (which now carries what a
+ // turn that just ended ran on), and which engines can run.
+ useEffect(() => {
+ setBadgeBots(kwants);
+ forgetLastRuns();
+ }, [kwants]);
+ useEffect(() => setBadgeEngines(engines.engines), [engines.engines]);
// What the empty chat shows: a bot's home, #general's, or nothing special for a team or other channel.
const chatHome: ChatHome = currentKwant
diff --git a/frontend/src/components/BotActionCard.tsx b/frontend/src/components/BotActionCard.tsx
index 2e98880a..647da6b4 100644
--- a/frontend/src/components/BotActionCard.tsx
+++ b/frontend/src/components/BotActionCard.tsx
@@ -59,7 +59,7 @@ export const BotActionCard: React.FC<BotActionCardProps> = ({ meta, messageId, k
return (
<section data-message-id={messageId} aria-labelledby={headingId} className={`flex items-start gap-3.5 w-full max-w-5xl rounded-xl ${flash ? 'kw-flash' : ''}`}>
- <ModernAvatar role={kwantName} name={kwantName} size={34} kwantId={kwantId} />
+ <ModernAvatar role={kwantName} name={kwantName} size={34} kwantId={kwantId} modelBadge={false} />
<div className={`flex-1 min-w-0 max-w-2xl rounded-2xl rounded-tl-sm border bg-zinc-900/60 shadow-sm ${border}`}>
<div className="px-4 pt-3 pb-2 space-y-1.5">
<span className="flex items-center gap-1.5 text-[11px] font-medium text-zinc-400">
diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsx
index 4dcf91d6..da968382 100644
--- a/frontend/src/components/ChatView.tsx
+++ b/frontend/src/components/ChatView.tsx
@@ -1490,6 +1490,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
name={displayName}
size={36}
kwantId={replyKwantId}
+ modelBadge={false}
/>
</span>
</span>
@@ -1509,7 +1510,7 @@ export const ChatView: React.FC<ChatViewProps> = ({
name={displayName}
at={msg.created_at}
sentToTelegram={sentToTelegram(parseMetaObject(msg.meta))}
- avatar={<span className={routed && freshTrack.current.fresh.has(msg.id) ? 'kws-handoff inline-flex' : 'inline-flex'}><ModernAvatar role={title} name={displayName} size={20} kwantId={replyKwantId} /></span>}
+ avatar={<span className={routed && freshTrack.current.fresh.has(msg.id) ? 'kws-handoff inline-flex' : 'inline-flex'}><ModernAvatar role={title} name={displayName} size={20} kwantId={replyKwantId} modelBadge={false} /></span>}
ranOn={ranOn}
account={account}
tokens={tokens}
diff --git a/frontend/src/components/ConnectionSuggestionCard.tsx b/frontend/src/components/ConnectionSuggestionCard.tsx
index a778c4fb..24f59271 100644
--- a/frontend/src/components/ConnectionSuggestionCard.tsx
+++ b/frontend/src/components/ConnectionSuggestionCard.tsx
@@ -59,7 +59,7 @@ export const ConnectionSuggestionView: React.FC<ConnectionSuggestionViewProps> =
aria-labelledby={headingId}
className={`flex items-start gap-3.5 w-full max-w-5xl rounded-xl ${flash ? 'kw-flash' : ''}`}
>
- <ModernAvatar role={kwantName} name={kwantName} size={34} kwantId={kwantId} />
+ <ModernAvatar role={kwantName} name={kwantName} size={34} kwantId={kwantId} modelBadge={false} />
<div className={`flex-1 min-w-0 max-w-2xl rounded-2xl rounded-tl-sm border bg-zinc-900/60 shadow-sm ${border}`}>
<div className="px-4 pt-3 pb-2 space-y-1.5">
<span className="flex items-center gap-1.5 text-[11px] font-medium text-zinc-400">
diff --git a/frontend/src/components/EngineMark.tsx b/frontend/src/components/EngineMark.tsx
new file mode 100644
index 00000000..fc8faa82
--- /dev/null
+++ b/frontend/src/components/EngineMark.tsx
@@ -0,0 +1,36 @@
+// A model provider's mark, monochrome (currentColor), for the model badge on a bot's avatar.
+// Sources and terms (autonomy/model-badge/impl.md "## Pixel frontend"):
+// - Anthropic, OpenAI, Ollama: Simple Icons 16.37 (CC0-1.0), https://simpleicons.org
+// - xAI: LobeHub icons-static-svg 1.102 "xai" (MIT), https://github.com/lobehub/lobe-icons
+// - Custom API: lucide's Cpu; Laya: the ✦ the app already uses for Laya.
+// Each mark only names the provider a bot runs on (nominative use); no new package.
+import React from 'react';
+import { Cpu } from 'lucide-react';
+import type { BadgeMark } from '../engines';
+
+const PATHS: Partial<Record<BadgeMark, string>> = {
+ claude: 'M17.3041 3.541h-3.6718l6.696 16.918H24Zm-10.6082 0L0 20.459h3.7442l1.3693-3.5527h7.0052l1.3693 3.5528h3.7442L10.5363 3.5409Zm-.3712 10.2232 2.2914-5.9456 2.2914 5.9456Z',
+ codex: 'M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z',
+ grok: 'M6.469 8.776L16.512 23h-4.464L2.005 8.776H6.47zm-.004 7.9l2.233 3.164L6.467 23H2l4.465-6.324zM22 2.582V23h-3.659V7.764L22 2.582zM22 1l-9.952 14.095-2.233-3.163L17.533 1H22z',
+ ollama: 'M16.361 10.26a.894.894 0 0 0-.558.47l-.072.148.001.207c0 .193.004.217.059.353.076.193.152.312.291.448.24.238.51.3.872.205a.86.86 0 0 0 .517-.436.752.752 0 0 0 .08-.498c-.064-.453-.33-.782-.724-.897a1.06 1.06 0 0 0-.466 0zm-9.203.005c-.305.096-.533.32-.65.639a1.187 1.187 0 0 0-.06.52c.057.309.31.59.598.667.362.095.632.033.872-.205.14-.136.215-.255.291-.448.055-.136.059-.16.059-.353l.001-.207-.072-.148a.894.894 0 0 0-.565-.472 1.02 1.02 0 0 0-.474.007Zm4.184 2c-.131.071-.223.25-.195.383.031.143.157.288.353.407.105.063.112.072.117.136.004.038-.01.146-.029.243-.02.094-.036.194-.036.222.002.074.07.195.143.253.064.052.076.054.255.059.164.005.198.001.264-.03.169-.082.212-.234.15-.525-.052-.243-.042-.28.087-.355.137-.08.281-.219.324-.314a.365.365 0 0 0-.175-.48.394.394 0 0 0-.181-.033c-.126 0-.207.03-.355.124l-.085.053-.053-.032c-.219-.13-.259-.145-.391-.143a.396.396 0 0 0-.193.032zm.39-2.195c-.373.036-.475.05-.654.086-.291.06-.68.195-.951.328-.94.46-1.589 1.226-1.787 2.114-.04.176-.045.234-.045.53 0 .294.005.357.043.524.264 1.16 1.332 2.017 2.714 2.173.3.033 1.596.033 1.896 0 1.11-.125 2.064-.727 2.493-1.571.114-.226.169-.372.22-.602.039-.167.044-.23.044-.523 0-.297-.005-.355-.045-.531-.288-1.29-1.539-2.304-3.072-2.497a6.873 6.873 0 0 0-.855-.031zm.645.937a3.283 3.283 0 0 1 1.44.514c.223.148.537.458.671.662.166.251.26.508.303.82.02.143.01.251-.043.482-.08.345-.332.705-.672.957a3.115 3.115 0 0 1-.689.348c-.382.122-.632.144-1.525.138-.582-.006-.686-.01-.853-.042-.57-.107-1.022-.334-1.35-.68-.264-.28-.385-.535-.45-.946-.03-.192.025-.509.137-.776.136-.326.488-.73.836-.963.403-.269.934-.46 1.422-.512.187-.02.586-.02.773-.002zm-5.503-11a1.653 1.653 0 0 0-.683.298C5.617.74 5.173 1.666 4.985 2.819c-.07.436-.119 1.04-.119 1.503 0 .544.064 1.24.155 1.721.02.107.031.202.023.208a8.12 8.12 0 0 1-.187.152 5.324 5.324 0 0 0-.949 1.02 5.49 5.49 0 0 0-.94 2.339 6.625 6.625 0 0 0-.023 1.357c.091.78.325 1.438.727 2.04l.13.195-.037.064c-.269.452-.498 1.105-.605 1.732-.084.496-.095.629-.095 1.294 0 .67.009.803.088 1.266.095.555.288 1.143.503 1.534.071.128.243.393.264.407.007.003-.014.067-.046.141a7.405 7.405 0 0 0-.548 1.873c-.062.417-.071.552-.071.991 0 .56.031.832.148 1.279L3.42 24h1.478l-.05-.091c-.297-.552-.325-1.575-.068-2.597.117-.472.25-.819.498-1.296l.148-.29v-.177c0-.165-.003-.184-.057-.293a.915.915 0 0 0-.194-.25 1.74 1.74 0 0 1-.385-.543c-.424-.92-.506-2.286-.208-3.451.124-.486.329-.918.544-1.154a.787.787 0 0 0 .223-.531c0-.195-.07-.355-.224-.522a3.136 3.136 0 0 1-.817-1.729c-.14-.96.114-2.005.69-2.834.563-.814 1.353-1.336 2.237-1.475.199-.033.57-.028.776.01.226.04.367.028.512-.041.179-.085.268-.19.374-.431.093-.215.165-.333.36-.576.234-.29.46-.489.822-.729.413-.27.884-.467 1.352-.561.17-.035.25-.04.569-.04.319 0 .398.005.569.04a4.07 4.07 0 0 1 1.914.997c.117.109.398.457.488.602.034.057.095.177.132.267.105.241.195.346.374.43.14.068.286.082.503.045.343-.058.607-.053.943.016 1.144.23 2.14 1.173 2.581 2.437.385 1.108.276 2.267-.296 3.153-.097.15-.193.27-.333.419-.301.322-.301.722-.001 1.053.493.539.801 1.866.708 3.036-.062.772-.26 1.463-.533 1.854a2.096 2.096 0 0 1-.224.258.916.916 0 0 0-.194.25c-.054.109-.057.128-.057.293v.178l.148.29c.248.476.38.823.498 1.295.253 1.008.231 2.01-.059 2.581a.845.845 0 0 0-.044.098c0 .006.329.009.732.009h.73l.02-.074.036-.134c.019-.076.057-.3.088-.516.029-.217.029-1.016 0-1.258-.11-.875-.295-1.57-.597-2.226-.032-.074-.053-.138-.046-.141.008-.005.057-.074.108-.152.376-.569.607-1.284.724-2.228.031-.26.031-1.378 0-1.628-.083-.645-.182-1.082-.348-1.525a6.083 6.083 0 0 0-.329-.7l-.038-.064.131-.194c.402-.604.636-1.262.727-2.04a6.625 6.625 0 0 0-.024-1.358 5.512 5.512 0 0 0-.939-2.339 5.325 5.325 0 0 0-.95-1.02 8.097 8.097 0 0 1-.186-.152.692.692 0 0 1 .023-.208c.208-1.087.201-2.443-.017-3.503-.19-.924-.535-1.658-.98-2.082-.354-.338-.716-.482-1.15-.455-.996.059-1.8 1.205-2.116 3.01a6.805 6.805 0 0 0-.097.726c0 .036-.007.066-.015.066a.96.96 0 0 1-.149-.078A4.857 4.857 0 0 0 12 3.03c-.832 0-1.687.243-2.456.698a.958.958 0 0 1-.148.078c-.008 0-.015-.03-.015-.066a6.71 6.71 0 0 0-.097-.725C8.997 1.392 8.337.319 7.46.048a2.096 2.096 0 0 0-.585-.041Zm.293 1.402c.248.197.523.759.682 1.388.03.113.06.244.069.292.007.047.026.152.041.233.067.365.098.76.102 1.24l.002.475-.12.175-.118.178h-.278c-.324 0-.646.041-.954.124l-.238.06c-.033.007-.038-.003-.057-.144a8.438 8.438 0 0 1 .016-2.323c.124-.788.413-1.501.696-1.711.067-.05.079-.049.157.013zm9.825-.012c.17.126.358.46.498.888.28.854.36 2.028.212 3.145-.019.14-.024.151-.057.144l-.238-.06a3.693 3.693 0 0 0-.954-.124h-.278l-.119-.178-.119-.175.002-.474c.004-.669.066-1.19.214-1.772.157-.623.434-1.185.68-1.382.078-.062.09-.063.159-.012z',
+};
+
+export const MARK_NAME: Record<BadgeMark, string> = {
+ claude: 'Anthropic', codex: 'OpenAI', grok: 'xAI', ollama: 'Ollama', custom: 'Custom API', laya: 'Laya',
+};
+
+/** The mark at `size` px in the current text color. */
+export const EngineMark: React.FC<{ mark: BadgeMark; size: number }> = ({ mark, size }) => {
+ if (mark === 'custom') return <Cpu size={size} strokeWidth={2.25} aria-hidden="true" data-mark="custom" />;
+ if (mark === 'laya')
+ return (
+ <svg width={size} height={size} viewBox="0 0 24 24" aria-hidden="true" data-mark="laya">
+ <path fill="currentColor" d="M12 1.5c.6 5.6 4.9 9.9 10.5 10.5-5.6.6-9.9 4.9-10.5 10.5C11.4 16.9 7.1 12.6 1.5 12 7.1 11.4 11.4 7.1 12 1.5Z" />
+ </svg>
+ );
+ return (
+ <svg width={size} height={size} viewBox="0 0 24 24" aria-hidden="true" data-mark={mark}>
+ <path fill="currentColor" fillRule="evenodd" d={PATHS[mark]} />
+ </svg>
+ );
+};
diff --git a/frontend/src/components/ModernAvatar.tsx b/frontend/src/components/ModernAvatar.tsx
index 61ace9d0..6cfcb430 100644
--- a/frontend/src/components/ModernAvatar.tsx
+++ b/frontend/src/components/ModernAvatar.tsx
@@ -1,6 +1,9 @@
-import React, { useCallback, useSyncExternalStore } from 'react';
+import React, { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
import { HardHat, useDevModeOn } from './DevModeSwitch';
-import { isKwantWorking, subscribeKwant } from '../kwantActivity';
+import { isKwantWorking, lastRunOf, liveRunOf, subscribeKwant } from '../kwantActivity';
+import { modelBadgeFor, modelBadgeSize, type ModelBadge } from '../engines';
+import { badgeBotOf, badgeEngines, subscribeBadgeData } from '../modelBadgeData';
+import { EngineMark } from './EngineMark';
import { AvatarMood, useKwantMood, useKwantNotices } from './AvatarMood';
import { moodLabel, restingUntilOf } from '../kwantMood';
import { STATUS_DOT, STATUS_PRIORITY, statusText, type BotStatus } from '../botStatus';
@@ -16,6 +19,8 @@ interface ModernAvatarProps {
className?: string;
/** The kwant this avatar shows; it animates while that kwant is working on a turn. */
kwantId?: string;
+ /** The AI model badge (bottom-left) on avatars of 24 px and up; off for reply avatars in the chat. */
+ modelBadge?: boolean;
}
const noopUnsubscribe = () => undefined;
@@ -29,6 +34,86 @@ export const useKwantWorking = (kwantId: string | undefined): boolean => {
return useSyncExternalStore(subscribe, () => isKwantWorking(kwantId), () => false);
};
+/** The bot's model badge: its pinned engine, Laya's pick for the running reply, or its last reply's. */
+export const useModelBadge = (kwantId: string | undefined): ModelBadge | null => {
+ const subscribe = useCallback(
+ (onChange: () => void) => {
+ if (!kwantId) return noopUnsubscribe;
+ const a = subscribeKwant(kwantId, onChange);
+ const b = subscribeBadgeData(onChange);
+ return () => {
+ a();
+ b();
+ };
+ },
+ [kwantId],
+ );
+ const working = useSyncExternalStore(subscribe, () => isKwantWorking(kwantId), () => false);
+ const live = useSyncExternalStore(subscribe, () => liveRunOf(kwantId), () => undefined);
+ const last = useSyncExternalStore(subscribe, () => lastRunOf(kwantId), () => undefined);
+ const bot = useSyncExternalStore(subscribe, () => badgeBotOf(kwantId), () => undefined);
+ const engines = useSyncExternalStore(subscribe, badgeEngines, () => null);
+ return useMemo(
+ () => (bot ? modelBadgeFor(last ? { ...bot, last_ran_on: last } : bot, working ? live : null, engines) : null),
+ [bot, last, working, live, engines],
+ );
+};
+
+const prefersReducedMotion = () => typeof window !== 'undefined' && !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
+
+const BadgeFace: React.FC<{ badge: ModelBadge; glyph: number; className?: string }> = ({ badge, glyph, className = '' }) => (
+ <span
+ className={`kw-mb-layer ${badge.cantRun ? 'text-zinc-600' : badge.mark === 'laya' ? 'text-violet-300' : 'text-zinc-100'} ${className}`}
+ style={badge.resting ? { opacity: 0.6 } : undefined}
+ >
+ <EngineMark mark={badge.mark} size={glyph} />
+ </span>
+);
+
+/** Bottom-left, the mirror of the status dot. A changed mark cross-fades in 150 ms (instant under reduced motion). */
+export const AvatarModelBadge: React.FC<{ kwantId: string; size: number }> = ({ kwantId, size }) => {
+ const badge = useModelBadge(kwantId);
+ const d = modelBadgeSize(size);
+ const [leaving, setLeaving] = useState<ModelBadge | null>(null);
+ const shownRef = useRef<ModelBadge | null>(badge);
+ const key = badge?.key;
+ useEffect(() => {
+ const before = shownRef.current;
+ shownRef.current = badge;
+ if (!before || !badge || before.key === badge.key || prefersReducedMotion()) {
+ setLeaving(null);
+ return;
+ }
+ setLeaving(before);
+ const t = window.setTimeout(() => setLeaving(null), 150);
+ return () => window.clearTimeout(t);
+ // Only a new mark fades; a new label on the same mark doesn't.
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [key]);
+ if (!badge || !d) return null;
+ const glyph = Math.round(d * (badge.mark === 'custom' ? 0.7 : 0.64));
+ return (
+ <span
+ className={`kw-model-badge ring-2 ring-zinc-950 ${badge.cantRun ? 'bg-zinc-950' : 'bg-zinc-900'}`}
+ style={{ width: d, height: d }}
+ role="img"
+ aria-label={badge.label}
+ title={badge.label}
+ data-model-badge={badge.mark}
+ data-badge-resting={badge.resting || undefined}
+ data-badge-cant-run={badge.cantRun ?? undefined}
+ >
+ {leaving && <BadgeFace key={`out:${leaving.key}`} badge={leaving} glyph={glyph} className="kw-mb-out" />}
+ <BadgeFace key={badge.key} badge={badge} glyph={glyph} className={leaving ? 'kw-mb-in' : ''} />
+ {badge.resting && badge.auto && (
+ <span className="kw-mb-spark text-violet-300" style={{ fontSize: Math.max(8, Math.round(d * 0.55)) }} aria-hidden="true" data-badge-spark>
+ ✦
+ </span>
+ )}
+ </span>
+ );
+};
+
type Accessory =
| 'antenna' | 'spikes' | 'ears' | 'horns' | 'sprout' | 'crown' | 'visor'
| 'beret' | 'glasses' | 'goggles' | 'tie' | 'quill' | 'bulb'
@@ -347,6 +432,7 @@ export const ModernAvatar: React.FC<ModernAvatarProps> = ({
status,
className = '',
kwantId,
+ modelBadge = true,
}) => {
const working = useKwantWorking(kwantId);
// Never green (or idle grey) while a turn runs: the turn stream wins over a stale status.
@@ -407,6 +493,7 @@ export const ModernAvatar: React.FC<ModernAvatarProps> = ({
</svg>
<AvatarMood mood={mood} size={size} />
{hat && <HardHat />}
+ {modelBadge && kwantId && modelBadgeSize(size) !== null && <AvatarModelBadge kwantId={kwantId} size={size} />}
{shown && (
<>
<span className={`absolute bottom-0 right-0 w-2.5 h-2.5 rounded-full ring-2 ring-zinc-950 ${STATUS_DOT[shown]}`} aria-hidden="true" />
diff --git a/frontend/src/components/QuestionCard.tsx b/frontend/src/components/QuestionCard.tsx
index 1d017fbf..33e2fb08 100644
--- a/frontend/src/components/QuestionCard.tsx
+++ b/frontend/src/components/QuestionCard.tsx
@@ -110,7 +110,7 @@ export const QuestionCard: React.FC<QuestionCardProps> = ({ meta, messageId, kwa
aria-labelledby={headingId}
className={`flex items-start gap-3.5 w-full max-w-5xl rounded-xl ${flash ? 'kw-flash' : ''}`}
>
- <ModernAvatar role={kwantName} name={kwantName} size={34} kwantId={kwantId} />
+ <ModernAvatar role={kwantName} name={kwantName} size={34} kwantId={kwantId} modelBadge={false} />
<div
className={`flex-1 min-w-0 max-w-2xl rounded-2xl rounded-tl-sm border bg-zinc-900/60 shadow-sm ${
open ? 'border-amber-500/35' : 'border-zinc-800'
diff --git a/frontend/src/components/Sidebar.tsx b/frontend/src/components/Sidebar.tsx
index 53ede624..46628992 100644
--- a/frontend/src/components/Sidebar.tsx
+++ b/frontend/src/components/Sidebar.tsx
@@ -1,9 +1,9 @@
import React, { useCallback, useEffect, useState } from 'react';
import { Hash, Plus, CheckCircle2, ShieldCheck, KeyRound, Loader2, Users, ChevronDown, Settings, Settings2, X, Crown, UserPlus, Pencil, Inbox, Search, Split, Hand, MoreHorizontal, UserMinus, MessageSquare, KanbanSquare } from 'lucide-react';
-import { ModernAvatar } from './ModernAvatar';
+import { ModernAvatar, useModelBadge } from './ModernAvatar';
import { playSfx } from '../audio/chiptune';
import { badgeText } from '../away';
-import { canRunNow, engineTip, isUsable } from '../engines';
+import { canRunNow, engineTip, isUsable, type RunsOn } from '../engines';
import { statusOf, statusText, type BotStatus } from '../botStatus';
import { EnginesApi, useEngines } from '../useEngines';
import { claudeNeedsSignIn } from '../claudeLogin';
@@ -30,6 +30,16 @@ import { ReadyTeamsSidebarBox } from './ReadyTeamsEntry';
import { BudgetMeter, useBudgets } from './BotBudget';
import { PAUSED_ROW_LINE } from '../botBudget';
+/** A bot's name in its row; the tooltip says what it runs on in the same words as its avatar's model badge. */
+const BotName: React.FC<{ kwant: Kwant; className: string }> = ({ kwant: k, className }) => {
+ const badge = useModelBadge(k.id);
+ return (
+ <span data-bot-name className={className} title={`${k.name} · ${badge?.label ?? engineTip(k.preferred_model)}`}>
+ {k.name}
+ </span>
+ );
+};
+
export interface Kwant {
id: string;
name: string;
@@ -39,6 +49,8 @@ export interface Kwant {
avatar_sprite: string;
driver_type: string;
preferred_model: string;
+ /** What its newest reply ran on (GET /api/kwants, 0.9.6+); null when it never replied. */
+ last_ran_on?: RunsOn | null;
/** Pinned LLM profile; null uses the engine's default. */
profile_id?: string | null;
/** Whether turns may move to the engine's next profile when this one is out of usage. */
@@ -623,9 +635,7 @@ export const Sidebar: React.FC<SidebarProps> = ({
{/* The full name, on up to two lines (QA a), wrapping only between words or after a hyphen:
never inside a word ("Researche / r"). A word too long for the line ends in "…"; the
whole name and what it runs on are in the tooltip */}
- <span data-bot-name className={`min-w-0 text-body font-semibold leading-5 text-zinc-100 ${NAME_WRAP}`} title={`${k.name} · ${engineTip(k.preferred_model)}`}>
- {k.name}
- </span>
+ <BotName kwant={k} className={`min-w-0 text-body font-semibold leading-5 text-zinc-100 ${NAME_WRAP}`} />
{isLead && (
<span className="shrink-0 flex items-center gap-0.5 h-5 text-2xs uppercase tracking-wide text-amber-300" title={`Leads @${team!.name}`}>
<Crown size={10} aria-hidden="true" />
diff --git a/frontend/src/engines.ts b/frontend/src/engines.ts
index 9111ce25..3822fd67 100644
--- a/frontend/src/engines.ts
+++ b/frontend/src/engines.ts
@@ -360,3 +360,137 @@ export function engineSummary(e: EngineInfo, accounts: SummaryAccount[] = []): {
}
}
}
+
+// ---- The model badge on a bot's avatar (autonomy/model-badge/brief.md) ----
+
+/** What a turn runs on: the live `turn_runs_on` event, or a bot's `last_ran_on` from GET /api/kwants. */
+export interface RunsOn {
+ engine: string;
+ family?: string | null;
+ model?: string | null;
+ model_label?: string | null;
+ tier?: string | null;
+ /** "laya", "pinned" or "fallback" (the turn moved off the bot's first-choice account). */
+ picked_by?: string | null;
+ at?: string | null;
+}
+
+/** The mark drawn in the badge: a provider's, or Laya's ✦ for an auto bot that never ran. */
+export type BadgeMark = Family | 'laya';
+
+export interface ModelBadge {
+ mark: BadgeMark;
+ /** Auto and resting: the last reply's mark at 60%, with a ✦ in its corner. */
+ resting: boolean;
+ /** Laya picks this bot's model (the ✦ corner when resting). */
+ auto: boolean;
+ /** The engine can't run: signed out, switched off, or not on this computer at all (no CLI, key or
+ * server). Greyed out. */
+ cantRun: 'signed_out' | 'off' | 'not_set_up' | null;
+ /** Tooltip and aria-label; the name's tooltip in the bot list says the same. */
+ label: string;
+ /** Changes exactly when the mark changes, for the cross-fade. */
+ key: string;
+}
+
+const familyOfRun = (r: RunsOn): Family | null => {
+ if (r.family && FAMILIES.some((f) => f.id === r.family)) return r.family as Family;
+ return FAMILY_OF[r.engine as EngineId] ?? null;
+};
+
+/** "Claude · Haiku" for a turn, worded exactly like the reply's own ran-on line. */
+export function runsOnLabel(r: RunsOn, engines: EngineInfo[] | null = null): string {
+ const family = familyOfRun(r);
+ return ranOnLabel(JSON.stringify({ ran_on: { ...r, family: family ?? r.family } }), engines) ?? (family ? familyLabel(family).replace(/ \(.*\)$/, '') : r.engine);
+}
+
+/** The server's words for an engine that is signed in but out of usage ("Quota exceeded until 08:15 UTC"). */
+const isQuotaDetail = (detail: string | null | undefined): boolean => /quota exceeded|usage limit|out of usage/i.test(detail ?? '');
+
+/** Whether a family's engines can run now; why not when they can't. null while unknown. */
+function familyCantRun(family: Family, engines: EngineInfo[] | null): ModelBadge['cantRun'] {
+ if (!engines?.length) return null;
+ const mine = engines.filter((e) => FAMILY_OF[e.id] === family);
+ if (!mine.length || mine.some(isUsable)) return null;
+ if (mine.some((e) => e.enabled !== false && e.status === 'checking')) return null;
+ // Signed in but not ready right now (out of usage until it resets): failover still runs the bot, so it isn't greyed.
+ if (mine.some((e) => e.enabled !== false && e.status === 'ready')) return null;
+ // The server reports an engine that is signed in but out of usage as status 'error' with "Quota exceeded …"
+ // (drivers/engines.rs): it isn't signed out, and it runs again when the usage resets.
+ if (mine.some((e) => e.enabled !== false && e.status === 'error' && isQuotaDetail(e.detail))) return null;
+ // Off when every one that's here at all is switched off; otherwise it needs a sign-in (or a key).
+ const here = mine.filter((e) => e.status !== 'not_installed' || e.enabled === false);
+ if (!here.length) return 'not_set_up';
+ return here.every((e) => e.enabled === false || e.status === 'disabled') ? 'off' : 'signed_out';
+}
+
+/** pickLabel, with the model named the way a reply's ran-on line names it: "Claude · Sonnet", not "Claude · Claude Sonnet (latest)". */
+function shortPickLabel(value: string, engines: EngineInfo[] | null): string {
+ const full = pickLabel(value, engines);
+ const at = full.indexOf(' · ');
+ if (at < 0) return full;
+ const model = shortModelLabel(full.slice(at + 3), full.slice(0, at));
+ // An id that starts with the family's own name ("grok-4") reads as "Grok 4".
+ const fam = full.slice(0, at);
+ const m = model.toLowerCase().startsWith(fam.toLowerCase() + '-') ? `${fam} ${model.slice(fam.length + 1)}` : model;
+ // A bare id the engine list doesn't know yet ("sonnet") reads as a name.
+ return `${fam} · ${/^[a-z]+$/.test(m) ? m[0].toUpperCase() + m.slice(1) : m}`;
+}
+
+/**
+ * The badge for a bot: its pinned engine, or (auto) Laya's pick for the reply it's working on, else
+ * the engine of its last reply. `liveTurn` is the running turn's `turn_runs_on`, null when resting.
+ * null when there's nothing to show (no bot, or a pick this app can't read).
+ */
+export function modelBadgeFor(
+ kwant: { preferred_model?: string | null; last_ran_on?: RunsOn | null } | null | undefined,
+ liveTurn: RunsOn | null | undefined,
+ engines: EngineInfo[] | null = null,
+): ModelBadge | null {
+ if (!kwant) return null;
+ const pick = parsePick(kwant.preferred_model);
+ const auto = pick.family === 'auto';
+ if (liveTurn) {
+ const family = familyOfRun(liveTurn);
+ if (!family) return null;
+ const what = runsOnLabel(liveTurn, engines);
+ const label = liveTurn.picked_by === 'fallback'
+ ? `Moved to ${what} for this reply`
+ : auto
+ ? `Laya picked ${what} for this reply`
+ : `Runs on ${what}`;
+ return { mark: family, resting: false, auto, cantRun: null, label, key: `${family}:${liveTurn.model ?? ''}` };
+ }
+ if (auto) {
+ const last = kwant.last_ran_on;
+ const family = last ? familyOfRun(last) : null;
+ if (!last || !family) return { mark: 'laya', resting: false, auto, cantRun: null, label: 'Laya picks the model', key: 'laya' };
+ return {
+ mark: family,
+ resting: true,
+ auto,
+ cantRun: null,
+ label: `Laya picks the model. Last reply: ${runsOnLabel(last, engines)}`,
+ key: `${family}:${last.model ?? ''}:rest`,
+ };
+ }
+ const family = pick.family;
+ if (family === null || family === 'auto') return null;
+ const cantRun = familyCantRun(family, engines);
+ const suffix = cantRun ? ` · ${cantRun === 'not_set_up' ? 'not set up' : cantRun === 'off' ? 'off' : 'signed out'}` : '';
+ return {
+ mark: family,
+ resting: false,
+ auto,
+ cantRun,
+ label: `Runs on ${shortPickLabel(kwant.preferred_model ?? '', engines)}${suffix}`,
+ key: `${family}:${pick.model ?? ''}`,
+ };
+}
+
+/** The badge's diameter for an avatar of `size` px: none under 24, 14 at 28–34, larger on big avatars. */
+export function modelBadgeSize(size: number): number | null {
+ if (size < 24) return null;
+ if (size < 28) return 12;
+ return Math.max(14, Math.min(28, Math.round(size * 0.28)));
+}
diff --git a/frontend/src/kwantActivity.ts b/frontend/src/kwantActivity.ts
index c003957a..69f0714d 100644
--- a/frontend/src/kwantActivity.ts
+++ b/frontend/src/kwantActivity.ts
@@ -1,6 +1,8 @@
// Which kwants are working right now, from `turn_started` / `turn_ended` events. Avatars subscribe to
// their own kwant only, so a turn starting re-renders just the avatars of that kwant.
+import type { RunsOn } from './engines';
+
type Listener = () => void;
/** kwant id -> its running turns, by turn id (or context id from servers that don't send turn ids). */
@@ -9,6 +11,38 @@ const listeners = new Map<string, Set<Listener>>();
const notify = (kwantId: string) => listeners.get(kwantId)?.forEach((l) => l());
+// What each bot's running turn runs on (`turn_runs_on`), and, once it ends, what it last ran on until the
+// bot list is read again (which then carries it as `last_ran_on`). The avatar's model badge reads both.
+const liveRun = new Map<string, RunsOn>();
+const lastRun = new Map<string, RunsOn>();
+
+/** A turn started on (or failed over to) this engine and model. */
+export function turnRunsOn(kwantId: string, run: RunsOn): void {
+ if (!kwantId || !run?.engine) return;
+ liveRun.set(kwantId, { ...run, at: run.at ?? new Date().toISOString() });
+ notify(kwantId);
+}
+
+/** The bot is no longer working: its live engine becomes its last one. */
+function settleRun(kwantId: string): void {
+ const run = liveRun.get(kwantId);
+ if (!run) return;
+ liveRun.delete(kwantId);
+ lastRun.set(kwantId, run);
+}
+
+/** The bot list was read again, with each bot's `last_ran_on`: the ones kept here are no longer needed. */
+export function forgetLastRuns(): void {
+ const ids = Array.from(lastRun.keys());
+ lastRun.clear();
+ ids.forEach(notify);
+}
+
+/** The running turn's engine and model, or undefined while resting (or before the server says). */
+export const liveRunOf = (kwantId: string | undefined): RunsOn | undefined => (kwantId ? liveRun.get(kwantId) : undefined);
+/** What the bot ran on in a turn that ended since the bot list was last read. */
+export const lastRunOf = (kwantId: string | undefined): RunsOn | undefined => (kwantId ? lastRun.get(kwantId) : undefined);
+
const contextKey = (contextId: string | null | undefined) => contextId ?? '';
export function turnStarted(kwantId: string, contextId?: string | null): void {
@@ -23,10 +57,18 @@ export function turnStarted(kwantId: string, contextId?: string | null): void {
/** Ends a turn whatever its outcome; an unknown context clears the kwant entirely. */
export function turnEnded(kwantId: string, contextId?: string | null): void {
const set = active.get(kwantId);
- if (!set) return;
+ if (!set) {
+ // Its start went unseen (a reconnect): still let go of what it ran on.
+ if (liveRun.has(kwantId)) {
+ settleRun(kwantId);
+ notify(kwantId);
+ }
+ return;
+ }
if (!set.delete(contextKey(contextId))) set.clear();
if (set.size === 0) {
active.delete(kwantId);
+ settleRun(kwantId);
notify(kwantId);
}
}
@@ -35,6 +77,7 @@ export function turnEnded(kwantId: string, contextId?: string | null): void {
export function clearAllTurns(): void {
const ids = Array.from(active.keys());
active.clear();
+ ids.forEach(settleRun);
ids.forEach(notify);
}
@@ -47,6 +90,7 @@ export function resetTurns(running: Array<{ kwant_id: string; turn_id: string }>
set.add(t.turn_id);
active.set(t.kwant_id, set);
}
+ before.forEach((id) => active.has(id) || settleRun(id));
new Set([...before, ...active.keys()]).forEach(notify);
}
diff --git a/frontend/src/modelBadgeData.ts b/frontend/src/modelBadgeData.ts
new file mode 100644
index 00000000..87eff011
--- /dev/null
+++ b/frontend/src/modelBadgeData.ts
@@ -0,0 +1,39 @@
+// What the avatar's model badge needs besides the live turn: each bot's pick and last reply's engine
+// (from the app's bot list), and which engines can run (GET /api/engines). The app fills it, like botLooks.
+import type { EngineInfo, RunsOn } from './engines';
+
+export interface BadgeBot {
+ id: string;
+ preferred_model?: string | null;
+ /** From GET /api/kwants; missing on servers before 0.9.6, null for a bot that never replied. */
+ last_ran_on?: RunsOn | null;
+}
+
+let bots = new Map<string, BadgeBot>();
+let engines: EngineInfo[] | null = null;
+let rev = 0;
+const listeners = new Set<() => void>();
+const bump = () => {
+ rev += 1;
+ listeners.forEach((fn) => fn());
+};
+
+/** Replaces the known bots (the app calls it whenever its bot list changes). */
+export function setBadgeBots(list: readonly BadgeBot[]): void {
+ bots = new Map(list.map((b) => [b.id, b]));
+ bump();
+}
+
+export function setBadgeEngines(list: EngineInfo[] | null): void {
+ if (list === engines) return;
+ engines = list;
+ bump();
+}
+
+export const badgeBotOf = (id: string | undefined): BadgeBot | undefined => (id ? bots.get(id) : undefined);
+export const badgeEngines = (): EngineInfo[] | null => engines;
+export const badgeDataRev = (): number => rev;
+export function subscribeBadgeData(fn: () => void): () => void {
+ listeners.add(fn);
+ return () => void listeners.delete(fn);
+}
diff --git a/frontend/src/styles/modern.css b/frontend/src/styles/modern.css
index 42547842..ecffcb4e 100644
--- a/frontend/src/styles/modern.css
+++ b/frontend/src/styles/modern.css
@@ -779,6 +779,22 @@ a.kw-sticker:hover { transform: rotate(var(--kw-tilt)) scale(1.04); box-shadow:
@keyframes kw-dv-pop { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: none; } }
@keyframes kw-dv-caret { 0% { opacity: 1; } 50% { opacity: 0; } }
+/* The AI model badge, bottom-left on a bot's avatar: the mirror of the status dot (model-badge brief). */
+.kw-model-badge {
+ position: absolute; left: -2px; bottom: -2px; z-index: 2; border-radius: 9999px;
+ display: flex; align-items: center; justify-content: center;
+}
+.kw-mb-layer { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
+.kw-mb-spark { position: absolute; top: -3px; left: -6px; line-height: 1; text-shadow: 0 0 2px #09090b, 0 0 2px #09090b; }
+.kw-mb-in { animation: kw-mb-in 150ms ease-out both; }
+.kw-mb-out { animation: kw-mb-out 150ms ease-out both; }
+@keyframes kw-mb-in { from { opacity: 0; } }
+@keyframes kw-mb-out { to { opacity: 0; } }
+@media (prefers-reduced-motion: reduce) {
+ .kw-mb-in { animation: none; }
+ .kw-mb-out { display: none; }
+}
+
/* The hard hat: top-left on avatars of 28 px and up, so it never covers the status dot */
.kw-dev-hat {
position: absolute; left: -4px; top: -4px; width: 14px; height: 14px; border-radius: 9999px; z-index: 2;
diff --git a/frontend/tests/modelBadge.test.mjs b/frontend/tests/modelBadge.test.mjs
new file mode 100644
index 00000000..83b65b0c
--- /dev/null
+++ b/frontend/tests/modelBadge.test.mjs
@@ -0,0 +1,297 @@
+// 0.9.6: each bot's AI model on its avatar, live when Laya picks (autonomy/model-badge/brief.md, Pixel).
+// The rule (modelBadgeFor), the live store (turn_runs_on → turn_ended → last until the list refreshes),
+// and the badge as ModernAvatar draws it: size, tooltip, reduced motion, can't run, and the dev-mode hat.
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { readFileSync } from 'node:fs';
+import { JSDOM } from 'jsdom';
+import { loadBundled } from './bundle.mjs';
+
+const dom = new JSDOM('<!doctype html><html><body></body></html>', { url: 'http://localhost/', pretendToBeVisual: true });
+const g = globalThis;
+for (const k of ['window', 'document', 'navigator', 'HTMLElement', 'Element', 'Node', 'Event', 'MouseEvent', 'requestAnimationFrame', 'cancelAnimationFrame', 'getComputedStyle', 'localStorage', 'sessionStorage']) {
+ if (!(k in dom.window)) continue;
+ Object.defineProperty(g, k, { value: dom.window[k], configurable: true, writable: true });
+}
+let reduceMotion = false;
+g.window.matchMedia = (q) => ({ matches: q.includes('reduce') ? reduceMotion : false, media: q, addEventListener() {}, removeEventListener() {} });
+g.fetch = g.window.fetch = async () => new Response('{}', { status: 404 });
+
+const m = await loadBundled(`
+ export { default as React } from 'react';
+ export { createRoot } from 'react-dom/client';
+ export { flushSync } from 'react-dom';
+ export * from './src/engines';
+ export * from './src/kwantActivity';
+ export * from './src/modelBadgeData';
+ export { devStore, emptyState } from './src/devMode';
+ export { ModernAvatar } from './src/components/ModernAvatar';
+`);
+const { React, createRoot, flushSync } = m;
+const h = React.createElement;
+const settle = async (ms = 0) => new Promise((r) => setTimeout(r, ms));
+
+const ready = (id, extra = {}) => ({ id, name: id, kind: 'cli', status: 'ready', detail: null, version: null, models: [], checked_at: null, enabled: true, ready: true, ...extra });
+const ENGINES = [
+ ready('claude', { models: [{ id: 'sonnet', label: 'Sonnet', default: true }, { id: 'haiku', label: 'Haiku', default: false }] }),
+ ready('codex', { models: [{ id: 'gpt-6.1-sol', label: 'GPT-6.1 Sol', default: true }] }),
+ ready('grok', { models: [] }),
+];
+const run = (engine, model, model_label, picked_by) => ({ engine, family: engine, model, model_label, tier: null, picked_by });
+
+// ---- The rule: the brief's table ----
+
+test('pinned, not working: that engine\'s mark, "Runs on …"', () => {
+ const b = m.modelBadgeFor({ preferred_model: 'claude/sonnet', last_ran_on: null }, null, ENGINES);
+ assert.equal(b.mark, 'claude');
+ assert.equal(b.resting, false);
+ assert.equal(b.cantRun, null);
+ assert.equal(b.label, 'Runs on Claude · Sonnet');
+});
+
+test('pinned: the model is named like the reply\'s ran-on line, with the server\'s real labels', () => {
+ const real = [ready('claude', { models: [{ id: 'sonnet', label: 'Claude Sonnet (latest)', default: true }] }), ready('codex', { models: [{ id: 'gpt-5.5', label: 'GPT-5.5', default: true }] })];
+ assert.equal(m.modelBadgeFor({ preferred_model: 'claude/sonnet' }, null, real).label, 'Runs on Claude · Sonnet');
+ assert.equal(m.modelBadgeFor({ preferred_model: 'codex/gpt-5.5' }, null, real).label, 'Runs on Codex · GPT-5.5');
+ assert.equal(m.modelBadgeFor({ preferred_model: 'claude' }, null, real).label, 'Runs on Claude');
+});
+
+test('pinned, signed in but out of usage for now: not greyed (failover still runs it), and a bare model id reads as a name', () => {
+ // The real server shape (drivers/engines.rs): status 'error', "Quota exceeded until … UTC", no models.
+ const out = [{ ...ready('claude'), status: 'error', detail: 'Quota exceeded until 08:15 UTC', ready: false, models: [] }, ready('codex')];
+ const b = m.modelBadgeFor({ preferred_model: 'claude/sonnet' }, null, out);
+ assert.equal(b.cantRun, null);
+ assert.equal(b.label, 'Runs on Claude · Sonnet');
+ // The older shape (status 'ready', not ready now) still counts the same.
+ const old = [{ ...ready('claude'), ready: false, models: [] }, ready('codex')];
+ assert.equal(m.modelBadgeFor({ preferred_model: 'claude/sonnet' }, null, old).cantRun, null);
+});
+
+test('pinned, a failed check that is not about usage still reads as needing a sign-in', () => {
+ const failed = [{ ...ready('claude'), status: 'error', detail: 'claude exited with code 1', ready: false, models: [] }, ready('codex')];
+ assert.equal(m.modelBadgeFor({ preferred_model: 'claude/sonnet' }, null, failed).cantRun, 'signed_out');
+});
+
+test('pinned, working: the same mark; on failover the mark it moved to', () => {
+ const k = { preferred_model: 'claude/sonnet' };
+ const live = m.modelBadgeFor(k, run('claude', 'sonnet', 'Sonnet', 'pinned'), ENGINES);
+ assert.equal(live.mark, 'claude');
+ assert.equal(live.label, 'Runs on Claude · Sonnet');
+ const moved = m.modelBadgeFor(k, run('codex', 'gpt-6.1-sol', 'GPT-6.1 Sol', 'fallback'), ENGINES);
+ assert.equal(moved.mark, 'codex');
+ assert.equal(moved.label, 'Moved to Codex · GPT-6.1 Sol for this reply');
+});
+
+test('auto, resting: last reply\'s mark at 60% with the ✦ corner; never ran: Laya\'s ✦', () => {
+ const rest = m.modelBadgeFor({ preferred_model: 'auto', last_ran_on: run('claude', 'sonnet', 'Sonnet', 'laya') }, null, ENGINES);
+ assert.equal(rest.mark, 'claude');
+ assert.equal(rest.resting, true);
+ assert.equal(rest.auto, true);
+ assert.equal(rest.label, 'Laya picks the model. Last reply: Claude · Sonnet');
+ const never = m.modelBadgeFor({ preferred_model: 'auto', last_ran_on: null }, null, ENGINES);
+ assert.equal(never.mark, 'laya');
+ assert.equal(never.resting, false);
+ assert.equal(never.label, 'Laya picks the model');
+ // An older server without last_ran_on reads as never ran.
+ assert.equal(m.modelBadgeFor({ preferred_model: '' }, null, ENGINES).mark, 'laya');
+});
+
+test('auto, working: Laya\'s pick for this reply at full opacity', () => {
+ const b = m.modelBadgeFor({ preferred_model: 'auto', last_ran_on: run('claude', 'sonnet', 'Sonnet', 'laya') }, run('claude', 'haiku', 'Haiku', 'laya'), ENGINES);
+ assert.equal(b.mark, 'claude');
+ assert.equal(b.resting, false);
+ assert.equal(b.label, 'Laya picked Claude · Haiku for this reply');
+ assert.notEqual(b.key, m.modelBadgeFor({ preferred_model: 'auto', last_ran_on: run('claude', 'sonnet', 'Sonnet', 'laya') }, null, ENGINES).key);
+});
+
+test('can\'t run: greyed, and the tooltip says signed out, off or not set up', () => {
+ const out = ENGINES.map((e) => (e.id === 'claude' ? { ...e, status: 'signed_out', ready: false } : e));
+ const b = m.modelBadgeFor({ preferred_model: 'claude/sonnet' }, null, out);
+ assert.equal(b.cantRun, 'signed_out');
+ assert.equal(b.label, 'Runs on Claude · Sonnet · signed out');
+ const off = ENGINES.map((e) => (e.id === 'grok' ? { ...e, enabled: false } : e));
+ const o = m.modelBadgeFor({ preferred_model: 'grok' }, null, off);
+ assert.equal(o.cantRun, 'off');
+ assert.equal(o.label, 'Runs on Grok · off');
+ // Not on this computer at all (no CLI, no key): not set up.
+ const none = ENGINES.filter((e) => e.id !== 'grok').concat([{ ...ready('grok'), status: 'not_installed', ready: false }, { ...ready('xai_api'), kind: 'api', status: 'not_installed', ready: false }]);
+ const ns = m.modelBadgeFor({ preferred_model: 'grok' }, null, none);
+ assert.equal(ns.cantRun, 'not_set_up');
+ assert.equal(ns.label, 'Runs on Grok · not set up');
+ // An id that starts with the family's name reads as a name: "grok-4" → "Grok 4".
+ const gout = ENGINES.map((e) => (e.id === 'grok' ? { ...e, status: 'signed_out', ready: false } : e));
+ assert.equal(m.modelBadgeFor({ preferred_model: 'grok/grok-4' }, null, gout).label, 'Runs on Grok · Grok 4 · signed out');
+ // Still checking, or not loaded, isn't can't-run yet.
+ assert.equal(m.modelBadgeFor({ preferred_model: 'claude' }, null, null).cantRun, null);
+ assert.equal(m.modelBadgeFor({ preferred_model: 'claude' }, null, out.map((e) => (e.id === 'claude' ? { ...e, status: 'checking' } : e))).cantRun, null);
+});
+
+test('every engine has its mark: Ollama, Custom API; the API engines read as their family', () => {
+ assert.equal(m.modelBadgeFor({ preferred_model: 'local_ollama' }, null, null).mark, 'ollama');
+ assert.equal(m.modelBadgeFor({ preferred_model: 'custom:qwen' }, null, null).mark, 'custom');
+ assert.equal(m.modelBadgeFor({ preferred_model: 'auto' }, { engine: 'xai_api', family: null, model: 'grok-4.6', model_label: null, picked_by: 'laya' }, null).mark, 'grok');
+ assert.equal(m.modelBadgeFor(null, null, null), null);
+});
+
+test('size: hidden under 24 px, 14 px at 28–34 px, larger on big avatars', () => {
+ assert.equal(m.modelBadgeSize(20), null);
+ assert.equal(m.modelBadgeSize(23), null);
+ assert.equal(m.modelBadgeSize(24), 12);
+ for (const s of [28, 30, 32, 34]) assert.equal(m.modelBadgeSize(s), 14);
+ assert.ok(m.modelBadgeSize(72) > 14 && m.modelBadgeSize(96) >= m.modelBadgeSize(72));
+});
+
+// ---- The avatar ----
+
+const host = document.createElement('div');
+document.body.append(host);
+const root = createRoot(host);
+const draw = (props) => flushSync(() => root.render(h(m.ModernAvatar, { name: 'Ann', role: 'designer', kwantId: 'k1', size: 32, ...props })));
+const badge = () => host.querySelector('[data-model-badge]');
+const marks = () => [...host.querySelectorAll('[data-model-badge] [data-mark]')].map((e) => e.getAttribute('data-mark'));
+
+test('a live change: Claude, then Laya picks Grok, then failover to Codex; resting on Codex after', async () => {
+ reduceMotion = false;
+ m.setBadgeEngines(ENGINES);
+ m.setBadgeBots([{ id: 'k1', preferred_model: 'auto', last_ran_on: run('claude', 'sonnet', 'Sonnet', 'laya') }]);
+ draw();
+ assert.equal(badge().getAttribute('data-model-badge'), 'claude');
+ assert.ok(badge().hasAttribute('data-badge-resting'));
+ assert.ok(host.querySelector('[data-badge-spark]'), 'the ✦ corner while resting');
+ assert.equal(badge().getAttribute('aria-label'), 'Laya picks the model. Last reply: Claude · Sonnet');
+ assert.equal(badge().getAttribute('aria-live'), null, 'not announced on its own');
+
+ flushSync(() => {
+ m.turnStarted('k1', 'turn_1');
+ m.turnRunsOn('k1', run('grok', 'grok-4.6', null, 'laya'));
+ });
+ await settle();
+ assert.equal(badge().getAttribute('data-model-badge'), 'grok');
+ assert.equal(badge().hasAttribute('data-badge-resting'), false);
+ assert.equal(host.querySelector('[data-badge-spark]'), null);
+ assert.equal(badge().getAttribute('title'), 'Laya picked Grok · grok-4.6 for this reply');
+ // Mid-switch: both marks, the old fading out and the new fading in.
+ assert.deepEqual(marks(), ['claude', 'grok']);
+ assert.ok(host.querySelector('.kw-mb-out [data-mark="claude"]'));
+ assert.ok(host.querySelector('.kw-mb-in [data-mark="grok"]'));
+ await settle(200);
+ assert.deepEqual(marks(), ['grok'], 'the fade is over after 150 ms');
+
+ flushSync(() => m.turnRunsOn('k1', run('codex', 'gpt-6.1-sol', 'GPT-6.1 Sol', 'fallback')));
+ await settle();
+ assert.equal(badge().getAttribute('data-model-badge'), 'codex');
+ assert.equal(badge().getAttribute('title'), 'Moved to Codex · GPT-6.1 Sol for this reply');
+
+ flushSync(() => m.turnEnded('k1', 'turn_1'));
+ await settle(200);
+ assert.equal(badge().getAttribute('data-model-badge'), 'codex', 'rests on the engine it ended on');
+ assert.ok(badge().hasAttribute('data-badge-resting'));
+ assert.equal(badge().getAttribute('title'), 'Laya picks the model. Last reply: Codex · GPT-6.1 Sol');
+
+ // The bot list is read again: its last_ran_on takes over.
+ flushSync(() => {
+ m.setBadgeBots([{ id: 'k1', preferred_model: 'auto', last_ran_on: run('codex', 'gpt-6.1-sol', 'GPT-6.1 Sol', 'fallback') }]);
+ m.forgetLastRuns();
+ });
+ assert.equal(m.lastRunOf('k1'), undefined);
+ assert.equal(badge().getAttribute('data-model-badge'), 'codex');
+});
+
+test('reduced motion: the mark changes at once, with no fade', async () => {
+ reduceMotion = true;
+ m.setBadgeBots([{ id: 'k1', preferred_model: 'auto', last_ran_on: run('claude', 'sonnet', 'Sonnet', 'laya') }]);
+ draw();
+ flushSync(() => {
+ m.turnStarted('k1', 'turn_2');
+ m.turnRunsOn('k1', run('grok', 'grok-4.6', null, 'laya'));
+ });
+ await settle();
+ assert.deepEqual(marks(), ['grok']);
+ assert.equal(host.querySelector('.kw-mb-in, .kw-mb-out'), null);
+ const css = readFileSync(new URL('../src/styles/modern.css', import.meta.url), 'utf8');
+ assert.match(css, /@media \(prefers-reduced-motion: reduce\) \{\s*\.kw-mb-in \{ animation: none; \}\s*\.kw-mb-out \{ display: none; \}/);
+ flushSync(() => m.turnEnded('k1', 'turn_2'));
+ reduceMotion = false;
+});
+
+test('tooltip: the badge and the bot list\'s name say the same', () => {
+ m.setBadgeBots([{ id: 'k1', preferred_model: 'claude/sonnet', last_ran_on: null }]);
+ draw();
+ assert.equal(badge().getAttribute('title'), 'Runs on Claude · Sonnet');
+ assert.equal(badge().getAttribute('role'), 'img');
+ assert.equal(badge().getAttribute('aria-label'), badge().getAttribute('title'));
+ const sidebar = readFileSync(new URL('../src/components/Sidebar.tsx', import.meta.url), 'utf8');
+ assert.match(sidebar, /title=\{`\$\{k\.name\} · \$\{badge\?\.label \?\? engineTip\(k\.preferred_model\)\}`\}/);
+});
+
+test('hidden under 24 px, and on reply avatars in the chat', () => {
+ m.setBadgeBots([{ id: 'k1', preferred_model: 'claude', last_ran_on: null }]);
+ draw({ size: 20 });
+ assert.equal(badge(), null);
+ draw({ size: 23 });
+ assert.equal(badge(), null);
+ draw({ size: 24 });
+ assert.ok(badge());
+ draw({ size: 32, modelBadge: false });
+ assert.equal(badge(), null);
+ draw({ size: 32, kwantId: undefined });
+ assert.equal(badge(), null, 'no bot, no badge');
+ const chat = readFileSync(new URL('../src/components/ChatView.tsx', import.meta.url), 'utf8');
+ assert.match(chat, /size=\{20\} kwantId=\{replyKwantId\} modelBadge=\{false\}/);
+ // Every reply avatar with a bot id (the 36 px one beside each message too) opts out: the ran-on line names the model.
+ const replyAvatars = chat.match(/kwantId=\{replyKwantId\}[^/>]*/g) ?? [];
+ assert.ok(replyAvatars.length >= 2);
+ for (const a of replyAvatars) assert.match(a, /modelBadge=\{false\}/);
+ // The cards shown inside the chat stream (a question, a bot action, a connection suggestion) opt out too.
+ for (const f of ['QuestionCard', 'BotActionCard', 'ConnectionSuggestionCard']) {
+ const src = readFileSync(new URL(`../src/components/${f}.tsx`, import.meta.url), 'utf8');
+ const avatars = src.match(/<ModernAvatar\b[^>]*kwantId=[^>]*>/g) ?? [];
+ assert.ok(avatars.length >= 1, `${f} has a bot avatar`);
+ for (const a of avatars) assert.match(a, /modelBadge=\{false\}/, `${f}: no badge in the chat`);
+ }
+});
+
+test('dev mode: the hard hat (top-left) and the badge (bottom-left) never overlap', () => {
+ m.devStore._reset();
+ m.devStore.set('spc', { ...m.emptyState(), on: true });
+ m.devStore.setCurrent('spc');
+ m.setBadgeBots([{ id: 'k1', preferred_model: 'claude', last_ran_on: null }]);
+ const css = readFileSync(new URL('../src/styles/modern.css', import.meta.url), 'utf8');
+ const box = (sel) => {
+ const rule = css.match(new RegExp(`\\${sel} \\{([^}]*)\\}`))[1];
+ const n = (p) => { const v = rule.match(new RegExp(`(?:^|[\\s;])${p}:\\s*(-?\\d+)px`)); return v ? Number(v[1]) : null; };
+ return { left: n('left'), top: n('top'), bottom: n('bottom'), w: n('width') };
+ };
+ const hat = box('.kw-dev-hat');
+ const mb = box('.kw-model-badge');
+ for (const size of [28, 30, 32, 34, 48, 72, 96]) {
+ draw({ size });
+ assert.ok(host.querySelector('[data-dev-hat]'), `hat at ${size}`);
+ assert.ok(badge(), `badge at ${size}`);
+ const d = m.modelBadgeSize(size);
+ assert.equal(badge().style.width, `${d}px`);
+ const hatBottom = hat.top + hat.w;
+ const badgeTop = size - mb.bottom - d;
+ assert.ok(badgeTop > hatBottom, `at ${size}px the hat ends at ${hatBottom} and the badge starts at ${badgeTop}`);
+ }
+ m.devStore._reset();
+});
+
+test('can\'t run: the avatar\'s badge is greyed out', () => {
+ m.setBadgeEngines(ENGINES.map((e) => (e.id === 'claude' ? { ...e, status: 'signed_out', ready: false } : e)));
+ m.setBadgeBots([{ id: 'k1', preferred_model: 'claude/sonnet', last_ran_on: null }]);
+ draw();
+ assert.equal(badge().getAttribute('data-badge-cant-run'), 'signed_out');
+ assert.ok(host.querySelector('[data-model-badge] .text-zinc-600'));
+ assert.ok(badge().classList.contains('bg-zinc-950'), 'darker than the resting badge');
+ assert.equal(badge().getAttribute('title'), 'Runs on Claude · Sonnet · signed out');
+ flushSync(() => m.setBadgeEngines(ENGINES));
+ assert.equal(badge().hasAttribute('data-badge-cant-run'), false);
+});
+
+test('turn_runs_on for a turn whose start went unseen still lets go when it ends', () => {
+ m.turnRunsOn('k9', run('claude', 'haiku', 'Haiku', 'laya'));
+ m.turnEnded('k9', 'turn_x');
+ assert.equal(m.liveRunOf('k9'), undefined);
+ assert.equal(m.lastRunOf('k9').model, 'haiku');
+});
diff --git a/frontend/tests/quickWins.test.mjs b/frontend/tests/quickWins.test.mjs
index ce3e1f81..a80222f4 100644
--- a/frontend/tests/quickWins.test.mjs
+++ b/frontend/tests/quickWins.test.mjs
@@ -77,7 +77,8 @@ test('engineTip: the engine goes in the tooltip, Auto says Laya picks', () => {
test('sidebar rows carry no LAYA pill or engine badge; the engine is in the name tooltip', () => {
const src = readFileSync(new URL('../src/components/Sidebar.tsx', import.meta.url), 'utf8');
assert.doesNotMatch(src, />\s*Laya\s*</);
- assert.match(src, /title=\{`\$\{k\.name\} · \$\{engineTip\(k\.preferred_model\)\}`\}/);
+ // The name tooltip says what the avatar's model badge says, and the engine when there is no badge.
+ assert.match(src, /title=\{`\$\{k\.name\} · \$\{badge\?\.label \?\? engineTip\(k\.preferred_model\)\}`\}/);
// No account yet reads as a next step, not a warning.
assert.doesNotMatch(src, /Nothing can run here/);
});