Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat(avatar): swap procedural avatars for boring-avatars (beam + marble) (#391)

Gener03abc4486aa3
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 21aee08ea..fe1ecc266 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -372,6 +372,9 @@ importers:
better-auth:
specifier: ^1.6.23
+ boring-avatars:
+ specifier: ^2.0.4
class-variance-authority:
specifier: ^0.7.1
version: 0.7.1
@@ -4119,6 +4122,12 @@ packages:
resolution: {integrity: sha512-oP5VkATKlNwcgvxi0vM0p/D3n2C3EReYVX+DNYs5TjZFn/oQt2j+4sVJtSMr18pdRr8wjTcBl6LoV+FUwzPmNA==}
engines: {node: '>=18'}
+ resolution: {integrity: sha512-xhZO/w/6aFmRfkaWohcl2NfyIy87gK5SBbys8kctZeTGF1Apjpv/10pfUuv+YEfVPkESU/h2Y6tt/Dwp+bIZPw==}
+ peerDependencies:
+ react: '>=18.0.0'
+ react-dom: '>=18.0.0'
+
resolution: {integrity: sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg==}
@@ -12130,6 +12139,11 @@ snapshots:
transitivePeerDependencies:
- supports-color
+ dependencies:
+ react: 19.2.7
+ react-dom: 19.2.7([email protected])
+
diff --git a/src/web/package.json b/src/web/package.json
index a5aedcd58..fb7c94b8c 100644
--- a/src/web/package.json
+++ b/src/web/package.json
@@ -59,6 +59,7 @@
"@types/mdx": "^2.0.14",
"@xyflow/react": "^12.11.1",
"better-auth": "^1.6.23",
+ "boring-avatars": "^2.0.4",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"driver.js": "^1.7.0",
diff --git a/src/web/src/app/(app)/w/[slug]/home/page.tsx b/src/web/src/app/(app)/w/[slug]/home/page.tsx
index d2bb9e457..6a5d10cbe 100644
--- a/src/web/src/app/(app)/w/[slug]/home/page.tsx
+++ b/src/web/src/app/(app)/w/[slug]/home/page.tsx
@@ -44,7 +44,7 @@ import {
PopoverTrigger,
} from "@/components/ui/popover";
import { AgentPreviewCard } from "@/components/agent-preview-card";
-import { AnimatedAvatar, parseAvatarUrl } from "@/components/avatar";
+import { AnimatedAvatar } from "@/components/avatar";
import {
createAgentLink,
updateAgentLink,
@@ -602,17 +602,7 @@ function MobileAgentList({ onAgentClick }: { onAgentClick?: (agent: Agent) => vo
}
}}
>
- {(() => {
- const avatarConfig = parseAvatarUrl(agent.avatar_url);
- if (avatarConfig) {
- return <AnimatedAvatar config={avatarConfig} size={36} className="shrink-0 rounded-xl" isHovered={false} isWorking={isOnline && (activeTaskCounts[agent.id] ?? 0) > 0} />;
- }
- return (
- <div className="flex items-center justify-center size-9 rounded-xl bg-secondary text-secondary-foreground text-sm font-medium shrink-0">
- {agent.name.charAt(0).toUpperCase()}
- </div>
- );
- })()}
+ <AnimatedAvatar seed={agent.id} avatarUrl={agent.avatar_url} size={36} className="shrink-0 rounded-xl" isHovered={false} isWorking={isOnline && (activeTaskCounts[agent.id] ?? 0) > 0} />
<div className="min-w-0 flex-1">
<AgentPreviewCard
agent={agent}
diff --git a/src/web/src/app/(app)/w/[slug]/issues/page.tsx b/src/web/src/app/(app)/w/[slug]/issues/page.tsx
index 8a4b33c89..434ff9d26 100644
--- a/src/web/src/app/(app)/w/[slug]/issues/page.tsx
+++ b/src/web/src/app/(app)/w/[slug]/issues/page.tsx
@@ -12,7 +12,8 @@ import type { TaskApi } from "@alook/shared";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { Skeleton } from "@/components/ui/skeleton";
-import { AvatarRenderer, parseAvatarUrl } from "@/components/avatar";
+import { BoringAvatar } from "@/components/avatar";
+import { resolveAvatar } from "@/lib/avatar/resolve";
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from "@/components/ui/context-menu";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { cn } from "@/lib/utils";
@@ -37,18 +38,11 @@ function formatDate(value: string | null) {
}
function AgentAvatar({ agent, size = 24 }: { agent?: Agent | null; size?: number }) {
- const avatarConfig = parseAvatarUrl(agent?.avatar_url);
- if (avatarConfig) {
- return <AvatarRenderer config={avatarConfig} size={size} className="shrink-0 rounded-full" />;
+ const resolved = resolveAvatar(agent?.avatar_url, agent?.id || agent?.name || "?");
+ if (resolved.kind === "photo") {
+ return <img src={resolved.url} alt={agent?.name ?? ""} className="shrink-0 rounded-full object-cover" style={{ width: size, height: size }} />;
}
- return (
- <span
- className="flex shrink-0 items-center justify-center rounded-full border border-border bg-muted text-[11px] font-medium text-muted-foreground"
- style={{ width: size, height: size }}
- >
- {(agent?.name ?? "?").slice(0, 1).toUpperCase()}
- </span>
- );
+ return <BoringAvatar seed={resolved.seed} size={size} className="shrink-0 rounded-full" />;
}
function IssueCard({
diff --git a/src/web/src/app/(app)/w/[slug]/traces/[traceId]/page.tsx b/src/web/src/app/(app)/w/[slug]/traces/[traceId]/page.tsx
index 28ad44580..b5a11ad90 100644
--- a/src/web/src/app/(app)/w/[slug]/traces/[traceId]/page.tsx
+++ b/src/web/src/app/(app)/w/[slug]/traces/[traceId]/page.tsx
@@ -9,7 +9,8 @@ import { getTrace, type TraceTask } from "@/lib/api";
import { trackThreadViewed } from "@/lib/analytics";
import { Skeleton } from "@/components/ui/skeleton";
import { ArrowLeft } from "lucide-react";
-import { AvatarRenderer, parseAvatarUrl } from "@/components/avatar";
+import { BoringAvatar } from "@/components/avatar";
+import { resolveAvatar } from "@/lib/avatar/resolve";
function relativeTime(dateStr: string): string {
const date = new Date(dateStr);
@@ -64,17 +65,12 @@ const STATUS_LABELS: Record<string, string> = {
superseded: "Cancelled",
};
-function AgentAvatar({ name, avatarUrl, size = 14 }: { name?: string; avatarUrl?: string | null; size?: number }) {
- const config = parseAvatarUrl(avatarUrl);
- if (config) return <AvatarRenderer config={config} size={size} className="rounded-full shrink-0" />;
- return (
- <span
- className="flex items-center justify-center rounded-full bg-secondary text-[8px] font-medium shrink-0"
- style={{ width: size, height: size }}
- >
- {(name ?? "?").charAt(0).toUpperCase()}
- </span>
- );
+function AgentAvatar({ name, avatarUrl, seed, size = 14 }: { name?: string; avatarUrl?: string | null; seed?: string; size?: number }) {
+ const resolved = resolveAvatar(avatarUrl, seed || name || "?");
+ if (resolved.kind === "photo") {
+ return <img src={resolved.url} alt={name ?? ""} className="rounded-full shrink-0 object-cover" style={{ width: size, height: size }} />;
+ }
+ return <BoringAvatar seed={resolved.seed} size={size} className="rounded-full shrink-0" />;
}
interface TreeNode extends TraceTask {
@@ -129,7 +125,7 @@ function TaskNode({ node, slug }: { node: TreeNode; slug: string }) {
style={{ paddingLeft: `${1 + node.depth * 1.5}rem` }}
>
<div className="flex items-center gap-2">
- <AgentAvatar name={node.agent?.name} avatarUrl={node.agent?.avatarUrl} size={32} />
+ <AgentAvatar name={node.agent?.name} avatarUrl={node.agent?.avatarUrl} seed={node.agent_id} size={32} />
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2 min-w-0">
<span className="text-sm text-foreground truncate flex-1 min-w-0">
diff --git a/src/web/src/app/(app)/w/[slug]/traces/page.tsx b/src/web/src/app/(app)/w/[slug]/traces/page.tsx
index d672f3e9b..963aad696 100644
--- a/src/web/src/app/(app)/w/[slug]/traces/page.tsx
+++ b/src/web/src/app/(app)/w/[slug]/traces/page.tsx
@@ -16,7 +16,8 @@ import {
SelectItem,
} from "@/components/ui/select";
import { GitBranch, RefreshCw } from "lucide-react";
-import { AvatarRenderer, parseAvatarUrl } from "@/components/avatar";
+import { BoringAvatar } from "@/components/avatar";
+import { resolveAvatar } from "@/lib/avatar/resolve";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip";
@@ -72,17 +73,12 @@ function StatusDot({ status }: { status: string }) {
return <span className={`size-1.5 rounded-full shrink-0 ${colorClass}`} />;
}
-function AgentAvatar({ name, avatarUrl, size = 14 }: { name?: string; avatarUrl?: string | null; size?: number }) {
- const config = parseAvatarUrl(avatarUrl);
- if (config) return <AvatarRenderer config={config} size={size} className="rounded-full shrink-0" />;
- return (
- <span
- className="flex items-center justify-center rounded-full bg-secondary text-[8px] font-medium shrink-0"
- style={{ width: size, height: size }}
- >
- {(name ?? "?").charAt(0).toUpperCase()}
- </span>
- );
+function AgentAvatar({ name, avatarUrl, seed, size = 14 }: { name?: string; avatarUrl?: string | null; seed?: string; size?: number }) {
+ const resolved = resolveAvatar(avatarUrl, seed || name || "?");
+ if (resolved.kind === "photo") {
+ return <img src={resolved.url} alt={name ?? ""} className="rounded-full shrink-0 object-cover" style={{ width: size, height: size }} />;
+ }
+ return <BoringAvatar seed={resolved.seed} size={size} className="rounded-full shrink-0" />;
}
function TraceRow({ trace, slug }: { trace: TraceListItem; slug: string }) {
@@ -131,7 +127,7 @@ function TraceRow({ trace, slug }: { trace: TraceListItem; slug: string }) {
<span className="flex items-center">
{trace.helper_agents.map((h, i) => (
<span key={h.id} className={i > 0 ? "-ml-1" : ""}>
- <AgentAvatar name={h.name} avatarUrl={h.avatarUrl} />
+ <AgentAvatar name={h.name} avatarUrl={h.avatarUrl} seed={h.id} />
</span>
))}
</span>
@@ -321,7 +317,7 @@ export default function TracesPage() {
{agents.map((a) => (
<SelectItem key={a.id} value={a.id}>
<span className="flex items-center gap-2">
- <AgentAvatar name={a.name} avatarUrl={a.avatar_url} />
+ <AgentAvatar name={a.name} avatarUrl={a.avatar_url} seed={a.id} />
{a.name}
</span>
</SelectItem>
diff --git a/src/web/src/app/api/agents/recruit/route.test.ts b/src/web/src/app/api/agents/recruit/route.test.ts
index ad68a4197..de3f502f6 100644
--- a/src/web/src/app/api/agents/recruit/route.test.ts
+++ b/src/web/src/app/api/agents/recruit/route.test.ts
@@ -10,9 +10,8 @@ vi.mock("unique-names-generator", () => ({
uniqueNamesGenerator: vi.fn(() => "Robin"),
names: [],
}));
-vi.mock("@/components/avatar", () => ({
- randomConfig: vi.fn(() => ({})),
- serializeAvatarConfig: vi.fn(() => "avatar-url"),
+vi.mock("@/lib/avatar/seed-url", () => ({
+ randomBeamAvatar: vi.fn(() => "avatar-url"),
}));
const mockGetAgent = vi.fn();
diff --git a/src/web/src/app/api/agents/recruit/route.ts b/src/web/src/app/api/agents/recruit/route.ts
index f354c203e..89805a9ae 100644
--- a/src/web/src/app/api/agents/recruit/route.ts
+++ b/src/web/src/app/api/agents/recruit/route.ts
@@ -9,7 +9,7 @@ import { writeJSON, writeError, parseBody } from "@/lib/middleware/helpers";
import { agentToResponse, agentLinkToResponse } from "@/lib/api/responses";
import { invalidate, cached, cacheKeys } from "@/lib/cache";
import { broadcastToUser } from "@/lib/broadcast";
-import { randomConfig, serializeAvatarConfig } from "@/components/avatar";
+import { randomBeamAvatar } from "@/lib/avatar/seed-url";
function generateUniqueHandleFromSet(
handleSet: Set<string>,
@@ -82,7 +82,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
maxConcurrentTasks: 6,
ownerId: ctx.userId,
emailHandle: handle,
- avatarUrl: serializeAvatarConfig(randomConfig()),
+ avatarUrl: randomBeamAvatar(),
});
const link = await queries.agentLink.create(db, {
diff --git a/src/web/src/app/api/studios/route.test.ts b/src/web/src/app/api/studios/route.test.ts
index c0ff73aa6..eab34043f 100644
--- a/src/web/src/app/api/studios/route.test.ts
+++ b/src/web/src/app/api/studios/route.test.ts
@@ -4,9 +4,8 @@ vi.mock("@opennextjs/cloudflare", () => ({
getCloudflareContext: vi.fn(() => ({ env: { DB: {} } })),
}));
-vi.mock("@/components/avatar", () => ({
- randomConfig: vi.fn(() => ({ shape: "circle", color: "#ff0000" })),
- serializeAvatarConfig: vi.fn(() => "generated-avatar-config"),
+vi.mock("@/lib/avatar/seed-url", () => ({
+ randomBeamAvatar: vi.fn(() => "generated-avatar-config"),
}));
const mockCreateAgent = vi.fn();
diff --git a/src/web/src/app/api/studios/route.ts b/src/web/src/app/api/studios/route.ts
index 694c61d3c..f5d0f8051 100644
--- a/src/web/src/app/api/studios/route.ts
+++ b/src/web/src/app/api/studios/route.ts
@@ -7,7 +7,7 @@ import { withAuth } from "@/lib/middleware/auth";
import { withWorkspaceMember } from "@/lib/middleware/workspace";
import { writeJSON, writeError, parseBody } from "@/lib/middleware/helpers";
import { agentToResponse, workspaceToResponse, agentLinkToResponse } from "@/lib/api/responses";
-import { randomConfig, serializeAvatarConfig } from "@/components/avatar";
+import { randomBeamAvatar } from "@/lib/avatar/seed-url";
import { TaskService } from "@/lib/services/task";
import { invalidate, cached, cacheKeys } from "@/lib/cache";
@@ -139,7 +139,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
maxConcurrentTasks: 6,
ownerId: ctx.userId,
emailHandle: handle,
- avatarUrl: member.avatar_url || serializeAvatarConfig(randomConfig()),
+ avatarUrl: member.avatar_url || randomBeamAvatar(),
});
if (ctx.email) {
diff --git a/src/web/src/components/agent-chat/agent-chat-view.tsx b/src/web/src/components/agent-chat/agent-chat-view.tsx
index e9104f52d..fc6b0a401 100644
--- a/src/web/src/components/agent-chat/agent-chat-view.tsx
+++ b/src/web/src/components/agent-chat/agent-chat-view.tsx
@@ -81,7 +81,6 @@ import { MessageItem, AgentRow } from "@/components/agent-chat/message-list";
import { useAgentChatSheet } from "@/contexts/agent-chat-sheet-context";
import { PresenceLine } from "@/components/agent-chat/presence-line";
import { MenuToggleIcon } from "@/components/agent-chat/menu-toggle-icon";
-import { parseAvatarUrl } from "@/components/avatar";
import {
MENTION_COMPONENTS,
NapSeparator,
@@ -351,8 +350,8 @@ export function AgentChatView({
});
}, [subscribeWs, fetchThreadSummaries]);
- const agentAvatarConfig = useMemo(
- () => parseAvatarUrl(agents.find((a) => a.id === agentId)?.avatar_url ?? null),
+ const agentAvatarUrl = useMemo(
+ () => agents.find((a) => a.id === agentId)?.avatar_url ?? null,
[agents, agentId],
);
// First name only — presence copy reads socially ("Maya is typing…").
@@ -772,7 +771,7 @@ export function AgentChatView({
mentionComponents={MENTION_COMPONENTS}
groupPosition="solo"
agentName={agentName}
- agentAvatarConfig={agentAvatarConfig}
+ agentAvatarSeed={agentId} agentAvatarUrl={agentAvatarUrl}
isThreadRoot
/>
</div>
@@ -860,7 +859,7 @@ export function AgentChatView({
<AgentRow
groupPosition={artifactPos}
agentName={agentName}
- config={agentAvatarConfig}
+ seed={agentId} avatarUrl={agentAvatarUrl}
forceSpacer={!isHead}
>
<ArtifactCard
@@ -909,7 +908,7 @@ export function AgentChatView({
groupPosition={pos ?? "solo"}
provider={runtimeProvider}
agentName={agentName}
- agentAvatarConfig={agentAvatarConfig}
+ agentAvatarSeed={agentId} agentAvatarUrl={agentAvatarUrl}
isSendFailed={failedSends.has(msg.id)}
onRetrySend={handleRetrySend}
onQuote={handleQuoteMessage}
diff --git a/src/web/src/components/agent-chat/event-cards/email-card.tsx b/src/web/src/components/agent-chat/event-cards/email-card.tsx
index 0fba1aa89..46285bf72 100644
--- a/src/web/src/components/agent-chat/event-cards/email-card.tsx
+++ b/src/web/src/components/agent-chat/event-cards/email-card.tsx
@@ -1,6 +1,6 @@
import React, { useState, useCallback } from "react";
import { relativeTime } from "@/lib/time";
-import { AnimatedAvatar, parseAvatarUrl, type AvatarConfig } from "@/components/avatar";
+import { AnimatedAvatar } from "@/components/avatar";
import { ChevronRight, MessageSquare } from "lucide-react";
import { Sheet, SheetContent } from "@/components/ui/sheet";
import { useLongPress } from "@/hooks/use-long-press";
@@ -33,7 +33,7 @@ export function EmailCard({
onAgentChatOpen?: (agentId: string, targetConvId: string) => void;
touchAction?: { label: string; onClick: () => void } | null;
}) {
- const [resolvedAgent, setResolvedAgent] = useState<{ name: string; avatarConfig: AvatarConfig | null } | null>(null);
+ const [resolvedAgent, setResolvedAgent] = useState<{ id: string; name: string; avatarUrl: string | null } | null>(null);
const [hoverResolved, setHoverResolved] = useState(false);
const [touchSheetOpen, setTouchSheetOpen] = useState(false);
@@ -46,7 +46,7 @@ export function EmailCard({
setHoverResolved(true);
const agent = agents?.find((a: Agent) => a.email_handle === internalHandle);
if (agent) {
- setResolvedAgent({ name: agent.name, avatarConfig: parseAvatarUrl(agent.avatar_url) });
+ setResolvedAgent({ id: agent.id, name: agent.name, avatarUrl: agent.avatar_url });
}
}, [isInternal, hoverResolved, agents, internalHandle]);
return (
@@ -122,9 +122,7 @@ export function EmailCard({
}}
className="flex items-center gap-2 py-1 pl-0.5 pr-2 bg-(--paper) border border-(--border) rounded-full shadow-md hover:bg-(--secondary) cursor-pointer whitespace-nowrap"
>
- {resolvedAgent.avatarConfig && (
- <AnimatedAvatar config={resolvedAgent.avatarConfig} size={20} isHovered={false} className="rounded-full" />
- )}
+ <AnimatedAvatar seed={resolvedAgent.id} avatarUrl={resolvedAgent.avatarUrl} size={20} isHovered={false} className="rounded-full" />
<span className="text-[0.62rem] font-semibold opacity-80">{resolvedAgent.name}</span>
<ChevronRight className="w-2.5 h-2.5 text-muted-foreground/45 -ml-1" />
</span>
diff --git a/src/web/src/components/agent-chat/message-list.tsx b/src/web/src/components/agent-chat/message-list.tsx
index cecc50fd9..83d586356 100644
--- a/src/web/src/components/agent-chat/message-list.tsx
+++ b/src/web/src/components/agent-chat/message-list.tsx
@@ -10,7 +10,7 @@ import { mermaid, cjk, math } from "@/lib/streamdown-plugins";
import { highlightMentions } from "@/lib/highlight-mentions";
import { TaskStream } from "@/components/task-stream";
import { RuntimeErrorBlock } from "@/components/agent-chat/runtime-error-block";
-import { AnimatedAvatar, type AvatarConfig } from "@/components/avatar";
+import { AnimatedAvatar } from "@/components/avatar";
import { FileText, Flag, Copy, Check, MessageSquareQuote, MessageSquare, Image as ImageIcon } from "lucide-react";
import { getArtifactThumbnailUrl } from "@/components/artifact-content-renderer";
import type { PendingFile } from "@/hooks/use-file-attachments";
@@ -81,7 +81,8 @@ export interface MessageItemProps {
provider?: string | null;
/** Agent display name + avatar, for the agent-side IM bubbles and system cards. */
agentName: string;
- agentAvatarConfig: AvatarConfig | null;
+ agentAvatarSeed: string;
+ agentAvatarUrl?: string | null;
/** This optimistic user message failed to send — show the inline retry affordance. */
isSendFailed?: boolean;
onRetrySend?: (messageId: string) => void;
@@ -263,13 +264,15 @@ function ImageAttachmentCards({
export function AgentRow({
groupPosition,
agentName,
- config,
+ seed,
+ avatarUrl,
forceSpacer = false,
children,
}: {
groupPosition: GroupPosition;
agentName: string;
- config: AvatarConfig | null;
+ seed: string;
+ avatarUrl?: string | null;
forceSpacer?: boolean;
children: React.ReactNode;
}) {
@@ -277,14 +280,13 @@ export function AgentRow({
return (
<MessageCluster
avatar={
- config ? (
- <AnimatedAvatar
- config={config}
- size={AVATAR_SIZE}
- className="rounded-md"
- isHovered={false}
- />
- ) : null
+ <AnimatedAvatar
+ seed={seed}
+ avatarUrl={avatarUrl}
+ size={AVATAR_SIZE}
+ className="rounded-md"
+ isHovered={false}
+ />
}
name={agentName}
position={effectivePosition}
@@ -437,7 +439,8 @@ export const MessageItem = memo(function MessageItem({
groupPosition = "solo",
provider,
agentName,
- agentAvatarConfig,
+ agentAvatarSeed,
+ agentAvatarUrl,
isSendFailed,
onPendingImageClick,
onRetrySend,
@@ -566,7 +569,7 @@ export const MessageItem = memo(function MessageItem({
className={cn("group/msg", isFlagged && "bg-muted/30 rounded-lg px-2 -mx-2")}
{...(isTaskDone ? { "data-quote-source": true } : {})}
>
- <AgentRow groupPosition={groupPosition} agentName={agentName} config={agentAvatarConfig}>
+ <AgentRow groupPosition={groupPosition} agentName={agentName} seed={agentAvatarSeed} avatarUrl={agentAvatarUrl}>
<div
className="relative min-w-0 w-fit max-w-full"
{...(isTaskDone ? bubblePressHandlers : {})}
@@ -765,7 +768,7 @@ export const MessageItem = memo(function MessageItem({
}
return (
<div data-message-id={msg.id} {...(msg.task_id ? { "data-task-id": msg.task_id } : {})}>
- <AgentRow groupPosition={groupPosition} agentName={agentName} config={agentAvatarConfig}>
+ <AgentRow groupPosition={groupPosition} agentName={agentName} seed={agentAvatarSeed} avatarUrl={agentAvatarUrl}>
{card}
</AgentRow>
</div>
@@ -800,7 +803,7 @@ export const MessageItem = memo(function MessageItem({
data-quote-source
{...(msg.task_id ? { "data-task-id": msg.task_id } : {})}
>
- <AgentRow groupPosition={groupPosition} agentName={agentName} config={agentAvatarConfig}>
+ <AgentRow groupPosition={groupPosition} agentName={agentName} seed={agentAvatarSeed} avatarUrl={agentAvatarUrl}>
{msg.metadata?.error_source === "runtime" ? (
// A failure is a real message, not a bubble — surface it plainly
// with Retry. The action toolbar pins to the OPEN-side (left) top
diff --git a/src/web/src/components/agent-create-form.tsx b/src/web/src/components/agent-create-form.tsx
index 3580a4270..76e71ad9e 100644
--- a/src/web/src/components/agent-create-form.tsx
+++ b/src/web/src/components/agent-create-form.tsx
@@ -14,12 +14,8 @@ import {
type CustomEmailData,
} from "@/components/custom-email-form";
import { useWorkspace } from "@/contexts/workspace-context";
-import {
- type AvatarConfig,
- AvatarPickerDialog,
- randomConfig,
- serializeAvatarConfig,
-} from "@/components/avatar";
+import { AvatarPickerDialog } from "@/components/avatar";
+import { serializeBeamSeed } from "@/lib/avatar/seed-url";
import { uniqueNamesGenerator, names } from "unique-names-generator";
import {
type AgentCreateFieldErrors,
@@ -47,8 +43,8 @@ interface AgentCreateFormProps {
saving: boolean;
}
-// Stable initial config to avoid hydration mismatch (randomConfig uses Math.random)
-const INITIAL_AVATAR: AvatarConfig = { shape: "circle", eye: "dots", nose: "dot", bg: 0 };
+// Stable initial seed to avoid hydration mismatch (real seed is rerolled on mount)
+const INITIAL_AVATAR = serializeBeamSeed("initial");
async function runTour() {
const waitForElement = (selector: string, timeout = 3000) =>
@@ -133,14 +129,14 @@ export function AgentCreateForm({
null
);
const [model, setModel] = useState("");
- const [avatarConfig, setAvatarConfig] = useState<AvatarConfig>(INITIAL_AVATAR);
+ const [avatarUrl, setAvatarUrl] = useState<string>(INITIAL_AVATAR);
// Randomize avatar and name on client mount to avoid hydration mismatch
const avatarInitialized = useRef(false);
useEffect(() => {
if (!avatarInitialized.current) {
avatarInitialized.current = true;
- setAvatarConfig(randomConfig());
+ setAvatarUrl(serializeBeamSeed(crypto.randomUUID()));
setName(uniqueNamesGenerator({ dictionaries: [names], length: 1, style: "capital" }));
}
}, []);
@@ -208,7 +204,7 @@ export function AgentCreateForm({
runtime_config: model ? { model } : {},
custom_email:
customEmailGetDataRef.current?.() ?? customEmailData ?? undefined,
- avatar_url: serializeAvatarConfig(avatarConfig),
+ avatar_url: avatarUrl,
});
};
@@ -216,8 +212,8 @@ export function AgentCreateForm({
<div className="flex-1 min-h-0 overflow-y-auto thin-scrollbar">
<form onSubmit={handleSubmit} noValidate className="mx-auto max-w-md flex flex-col gap-4 px-8 pt-8 pb-6">
<AvatarPickerDialog
- config={avatarConfig}
- onChange={setAvatarConfig}
+ value={avatarUrl}
+ onChange={setAvatarUrl}
/>
<GeneralFields
name={name}
diff --git a/src/web/src/components/agent-edit-form.tsx b/src/web/src/components/agent-edit-form.tsx
index 858a81223..1d8970222 100644
--- a/src/web/src/components/agent-edit-form.tsx
+++ b/src/web/src/components/agent-edit-form.tsx
@@ -22,13 +22,8 @@ import {
AllowedSendersTab,
AgentAccessTab,
} from "@/components/agent-form-fields";
-import {
- type AvatarConfig,
- AvatarPickerDialog,
- DEFAULT_CONFIG,
- parseAvatarUrl,
- serializeAvatarConfig,
-} from "@/components/avatar";
+import { AvatarPickerDialog } from "@/components/avatar";
+import { serializeBeamSeed, parseBeamSeed } from "@/lib/avatar/seed-url";
const MAX_INSTRUCTION_LENGTH = 50_000;
const DEBOUNCE_MS = 500;
@@ -146,8 +141,8 @@ export function AgentEditForm({
const [name, setName] = useState(agent.name ?? "");
const [description, setDescription] = useState(agent.description ?? "");
const [runtimeId, setRuntimeId] = useState(agent.runtime_id ?? "");
- const [avatarConfig, setAvatarConfig] = useState<AvatarConfig>(
- () => parseAvatarUrl(agent.avatar_url) ?? DEFAULT_CONFIG
+ const [avatarUrl, setAvatarUrl] = useState<string>(
+ () => parseBeamSeed(agent.avatar_url) ? agent.avatar_url! : serializeBeamSeed(agent.id),
);
const [model, setModel] = useState(() => {
const rc = agent.runtime_config;
@@ -263,7 +258,7 @@ export function AgentEditForm({
description,
runtime_id: runtimeId,
runtime_config: model ? { model } : {},
- avatar_url: serializeAvatarConfig(avatarConfig),
+ avatar_url: avatarUrl,
});
};
@@ -344,8 +339,8 @@ export function AgentEditForm({
{activeTab === "general" && (
<>
<AvatarPickerDialog
- config={avatarConfig}
- onChange={setAvatarConfig}
+ value={avatarUrl}
+ onChange={setAvatarUrl}
/>
<GeneralFields
name={name}
diff --git a/src/web/src/components/agent-preview-card.tsx b/src/web/src/components/agent-preview-card.tsx
index a53a1281e..8dd26966a 100644
--- a/src/web/src/components/agent-preview-card.tsx
+++ b/src/web/src/components/agent-preview-card.tsx
@@ -5,7 +5,7 @@ import { toAlookAddress } from "@alook/shared";
import type { Agent } from "@alook/shared";
import { Check, Copy } from "lucide-react";
import { toast } from "sonner";
-import { AnimatedAvatar, parseAvatarUrl } from "@/components/avatar";
+import { AnimatedAvatar } from "@/components/avatar";
import { AgentStatusBadge } from "@/components/agent-status-badge";
import { cn } from "@/lib/utils";
@@ -44,15 +44,7 @@ export function AgentPreviewCard({
return (
<div className="flex items-center gap-2 p-0">
{(() => {
- const avatarConfig = parseAvatarUrl(agent.avatar_url);
- if (avatarConfig) {
- return <AnimatedAvatar config={avatarConfig} size={32} className="shrink-0 rounded-xl" isHovered={isHovered ?? false} isWorking={!!isOnline && (activeTaskCount ?? 0) > 0} />;
- }
- return (
- <div className="flex items-center justify-center size-8 rounded-xl bg-secondary text-secondary-foreground text-xs font-medium shrink-0">
- {agent.name.charAt(0).toUpperCase()}
- </div>
- );
+ return <AnimatedAvatar seed={agent.id} avatarUrl={agent.avatar_url} size={32} className="shrink-0 rounded-xl" isHovered={isHovered ?? false} isWorking={!!isOnline && (activeTaskCount ?? 0) > 0} />;
})()}
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2">
diff --git a/src/web/src/components/app-sidebar.tsx b/src/web/src/components/app-sidebar.tsx
index 7d654dbaf..845de25fe 100644
--- a/src/web/src/components/app-sidebar.tsx
+++ b/src/web/src/components/app-sidebar.tsx
@@ -21,7 +21,6 @@ import {
ContextMenuItem,
ContextMenuSeparator,
} from "@/components/ui/context-menu";
-import { parseAvatarUrl } from "@/components/avatar";
import { AnimatedAvatar } from "@/components/avatar/animated-avatar";
import { DndContext, closestCenter, MouseSensor, TouchSensor, useSensor, useSensors, DragOverlay, type DragEndEvent, type DragStartEvent, type DragOverEvent } from "@dnd-kit/core";
import { restrictToVerticalAxis } from "@dnd-kit/modifiers";
@@ -565,15 +564,7 @@ export function AppSidebar({ onNavigate }: { onNavigate?: () => void } = {}) {
{dragActiveAgent ? (
<div className="opacity-80">
{(() => {
- const avatarConfig = parseAvatarUrl(dragActiveAgent.avatar_url);
- if (avatarConfig) {
- return <AnimatedAvatar config={avatarConfig} size={40} className="rounded-xl" isHovered={false} />;
- }
- return (
- <div className="flex items-center justify-center size-10 rounded-xl bg-secondary text-sm font-medium">
- {dragActiveAgent.name.charAt(0).toUpperCase()}
- </div>
- );
+ return <AnimatedAvatar seed={dragActiveAgent.id} avatarUrl={dragActiveAgent.avatar_url} size={40} className="rounded-xl" isHovered={false} />;
})()}
</div>
) : dragActiveFolder ? (
diff --git a/src/web/src/components/avatar/agent-avatar.test.ts b/src/web/src/components/avatar/agent-avatar.test.ts
index f35473a71..0ff979ab2 100644
--- a/src/web/src/components/avatar/agent-avatar.test.ts
+++ b/src/web/src/components/avatar/agent-avatar.test.ts
@@ -1,10 +1,14 @@
import { describe, it, expect } from "vitest"
import { AgentAvatar } from "./agent-avatar"
-import { AvatarRenderer, serializeAvatarConfig, DEFAULT_CONFIG } from "./avatar-parts"
+import { BoringAvatar } from "./boring-avatar"
+import { serializeBeamSeed } from "@/lib/avatar/seed-url"
+
+// A legacy procedural config value (the format the removed engine used to
+// store) — the renderer must ignore it and fall back to an id-seeded beam.
+const LEGACY_CONFIG = 'avatar:{"shape":"book","eye":"happy","nose":"dash","bg":1}'
type ImgEl = { type: "img"; props: { src: string; alt: string; style: { width: number; height: number } } }
-type SpanEl = { type: "span"; props: { children: string; style: { width: number; height: number } } }
-type RendererEl = { type: typeof AvatarRenderer; props: { size: number } }
+type BeamEl = { type: typeof BoringAvatar; props: { seed: string; size: number } }
describe("AgentAvatar", () => {
it("renders an <img> for a photo URL (https)", () => {
@@ -24,22 +28,29 @@ describe("AgentAvatar", () => {
expect(el.props.src).toBe("/api/community/bots/b1/avatar")
})
- it("renders AvatarRenderer for a procedural avatar: config", () => {
- const url = serializeAvatarConfig(DEFAULT_CONFIG)
- const el = AgentAvatar({ name: "Bot", avatarUrl: url, size: 32 }) as unknown as RendererEl
- expect(el.type).toBe(AvatarRenderer)
+ it("renders beam with the stored seed for a avatar:beam value", () => {
+ const el = AgentAvatar({ name: "Bot", avatarUrl: serializeBeamSeed("seed-123"), seed: "agent-1", size: 32 }) as unknown as BeamEl
+ expect(el.type).toBe(BoringAvatar)
+ expect(el.props.seed).toBe("seed-123")
expect(el.props.size).toBe(32)
})
- it("falls back to the initial-letter span when avatarUrl is null/undefined", () => {
- const el = AgentAvatar({ name: "Zara", avatarUrl: null, size: 32 }) as unknown as SpanEl
- expect(el.type).toBe("span")
- expect(el.props.children).toBe("Z")
+ it("ignores a legacy avatar:{shape…} config and beams by the fallback seed", () => {
+ const el = AgentAvatar({ name: "Bot", avatarUrl: LEGACY_CONFIG, seed: "agent-1", size: 32 }) as unknown as BeamEl
+ expect(el.type).toBe(BoringAvatar)
+ expect(el.props.seed).toBe("agent-1")
+ })
+
+ it("beams by the id seed when avatarUrl is null", () => {
+ const el = AgentAvatar({ name: "Zara", avatarUrl: null, seed: "agent-9", size: 32 }) as unknown as BeamEl
+ expect(el.type).toBe(BoringAvatar)
+ expect(el.props.seed).toBe("agent-9")
})
- it("falls back to '?' when both name and avatarUrl are missing", () => {
- const el = AgentAvatar({}) as unknown as SpanEl
- expect(el.type).toBe("span")
- expect(el.props.children).toBe("?")
+ it("falls back to name as seed when no id, and '?' when nothing", () => {
+ const byName = AgentAvatar({ name: "Zara", avatarUrl: null }) as unknown as BeamEl
+ expect(byName.props.seed).toBe("Zara")
+ const empty = AgentAvatar({}) as unknown as BeamEl
+ expect(empty.props.seed).toBe("?")
})
})
diff --git a/src/web/src/components/avatar/agent-avatar.tsx b/src/web/src/components/avatar/agent-avatar.tsx
index 04c149322..f23af2b06 100644
--- a/src/web/src/components/avatar/agent-avatar.tsx
+++ b/src/web/src/components/avatar/agent-avatar.tsx
@@ -1,26 +1,21 @@
"use client";
-import { AvatarRenderer, parseAvatarUrl, isPhotoAvatarUrl } from "./avatar-parts";
+import { BoringAvatar } from "./boring-avatar";
+import { resolveAvatar } from "@/lib/avatar/resolve";
-export function AgentAvatar({ name, avatarUrl, size = 32 }: { name?: string | null; avatarUrl?: string | null; size?: number }) {
- if (isPhotoAvatarUrl(avatarUrl)) {
+export function AgentAvatar({ name, avatarUrl, seed, size = 32 }: { name?: string | null; avatarUrl?: string | null; seed?: string | null; size?: number }) {
+ // Prefer a stable id as the beam seed; fall back to the name when no id is
+ // available (rename would then shift the face — a known tradeoff).
+ const resolved = resolveAvatar(avatarUrl, seed || name || "?");
+ if (resolved.kind === "photo") {
return (
<img
- src={avatarUrl!}
+ src={resolved.url}
alt={name ?? ""}
className="rounded-full shrink-0 object-cover"
style={{ width: size, height: size }}
/>
);
}
- const config = parseAvatarUrl(avatarUrl);
- if (config) return <AvatarRenderer config={config} size={size} className="rounded-full shrink-0" />;
- return (
- <span
- className="flex items-center justify-center rounded-full bg-secondary text-xs font-medium shrink-0"
- style={{ width: size, height: size }}
- >
- {(name ?? "?").charAt(0).toUpperCase()}
- </span>
- );
+ return <BoringAvatar seed={resolved.seed} size={size} className="rounded-full shrink-0" />;
}
diff --git a/src/web/src/components/avatar/animated-avatar.tsx b/src/web/src/components/avatar/animated-avatar.tsx
index 88a1a5307..502a1b01a 100644
--- a/src/web/src/components/avatar/animated-avatar.tsx
+++ b/src/web/src/components/avatar/animated-avatar.tsx
@@ -1,30 +1,24 @@
"use client";
import { useEffect, useRef, useState } from "react";
-import { AvatarRenderer } from "./avatar-parts";
-import type { AvatarConfig } from "./avatar-parts";
-
-const ANIMATIONS = [
- "avatar-anim-shape-bounce",
- "avatar-anim-head-tilt",
- "avatar-anim-shake",
- "avatar-anim-wobble",
- "avatar-anim-pulse",
- "avatar-anim-spin",
- "avatar-anim-jelly",
- "avatar-anim-float",
- "avatar-anim-nod",
-] as const;
+import { BoringAvatar } from "./boring-avatar";
+import { resolveAvatar } from "@/lib/avatar/resolve";
+
+// beam is a static SVG with no animatable internal parts, so only the
+// container-level animations survive the migration off the procedural
+// renderer (shape/eye/nose-targeted anims are dropped — see plan tradeoff).
+const ANIMATIONS = ["avatar-anim-pulse", "avatar-anim-float"] as const;
interface AnimatedAvatarProps {
- config: AvatarConfig;
+ seed: string;
+ avatarUrl?: string | null;
size?: number;
className?: string;
isHovered: boolean;
isWorking?: boolean;
}
-export function AnimatedAvatar({ config, size, className, isHovered, isWorking }: AnimatedAvatarProps) {
+export function AnimatedAvatar({ seed, avatarUrl, size, className, isHovered, isWorking }: AnimatedAvatarProps) {
const [animClass, setAnimClass] = useState<string | null>(null);
const lastPickRef = useRef(-1);
@@ -55,9 +49,14 @@ export function AnimatedAvatar({ config, size, className, isHovered, isWorking }
return () => clearInterval(interval);
}, [isHovered, isWorking]);
+ const resolved = resolveAvatar(avatarUrl, seed);
return (
<div className={animClass ?? undefined}>
- <AvatarRenderer config={config} size={size} className={className} />
+ {resolved.kind === "photo" ? (
+ <img src={resolved.url} alt="" className={`object-cover ${className ?? ""}`} style={{ width: size, height: size }} />
+ ) : (
+ <BoringAvatar seed={resolved.seed} size={size} className={className} />
+ )}
</div>
);
}
diff --git a/src/web/src/components/avatar/avatar-generator.tsx b/src/web/src/components/avatar/avatar-generator.tsx
deleted file mode 100644
index 5e444f8c0..000000000
--- a/src/web/src/components/avatar/avatar-generator.tsx
+++ /dev/null
@@ -1,363 +0,0 @@
-"use client";
-
-import { useState, useCallback, useEffect, useRef } from "react";
-import {
- type AvatarConfig,
- AvatarRenderer,
- Shapes,
- Eyes,
- Noses,
- BG_COLORS,
- SHAPE_KEYS,
- EYE_KEYS,
- NOSE_KEYS,
- PRESETS,
- randomConfig,
-} from "./avatar-parts";
-import { cn } from "@/lib/utils";
-import { Kbd } from "@/components/ui/kbd";
-import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip";
-
-// ─────────────────────────────────────────────────────────────
-// CYCLER — left/right carousel for picking a part
-// ─────────────────────────────────────────────────────────────
-function Cycler<K extends string>({
- label,
- keys,
- value,
- onChange,
- renderThumb,
- mobile = false,
-}: {
- label: string;
- keys: K[];
- value: K;
- onChange: (v: K) => void;
- renderThumb: (key: K) => React.ReactNode;
- mobile?: boolean;
-}) {
- const idx = keys.indexOf(value);
- const go = (delta: number) =>
- onChange(keys[(idx + delta + keys.length) % keys.length]!);
-
- const prev = keys[(idx - 1 + keys.length) % keys.length]!;
- const next = keys[(idx + 1) % keys.length]!;
-
- return (
- <div className="flex items-center gap-2">
- <span className="w-12 text-xs font-medium text-muted-foreground shrink-0">
- {label}
- </span>
- <button
- type="button"
- onClick={() => go(-1)}
- className={cn(
- "flex items-center justify-center rounded-md hover:bg-accent transition-colors",
- mobile ? "size-10" : "size-7"
- )}
- >
- <svg viewBox="0 0 24 24" width="16" height="16">
- <path
- d="M15 5 L8 12 L15 19"
- fill="none"
- stroke="currentColor"
- strokeWidth="2.4"
- strokeLinecap="round"
- strokeLinejoin="round"
- />
- </svg>
- </button>
- <div className="flex items-center gap-1 flex-1 justify-center">
- <button
- type="button"
- onClick={() => go(-1)}
- className="opacity-30 hover:opacity-60 transition-opacity"
- tabIndex={-1}
- >
- {renderThumb(prev)}
- </button>
- <button
- type="button"
- onClick={() => go(1)}
- className="border-2 border-primary rounded-lg p-1"
- >
- {renderThumb(value)}
- </button>
- <button
- type="button"
- onClick={() => go(1)}
- className="opacity-30 hover:opacity-60 transition-opacity"
- tabIndex={-1}
- >
- {renderThumb(next)}
- </button>
- </div>
- <button
- type="button"
- onClick={() => go(1)}
- className={cn(
- "flex items-center justify-center rounded-md hover:bg-accent transition-colors",
- mobile ? "size-10" : "size-7"
- )}
- >
- <svg viewBox="0 0 24 24" width="16" height="16">
- <path
- d="M9 5 L16 12 L9 19"
- fill="none"
- stroke="currentColor"
- strokeWidth="2.4"
- strokeLinecap="round"
- strokeLinejoin="round"
- />
- </svg>
- </button>
- </div>
- );
-}
-
-// ─────────────────────────────────────────────────────────────
-// AVATAR GENERATOR
-// ─────────────────────────────────────────────────────────────
-interface AvatarGeneratorProps {
- config: AvatarConfig;
- onChange: (config: AvatarConfig) => void;
- /** "horizontal" puts preview left + controls right; default is vertical stack */
- layout?: "vertical" | "horizontal";
- /** Mobile mode — smaller preview, bigger touch targets, 3-col grid */
- mobile?: boolean;
-}
-
-export function AvatarGenerator({ config, onChange, layout = "vertical", mobile = false }: AvatarGeneratorProps) {
- const [tab, setTab] = useState<"presets" | "custom">("presets");
-
- const setField = useCallback(
- <K extends keyof AvatarConfig>(key: K, value: AvatarConfig[K]) => {
- onChange({ ...config, [key]: value });
- },
- [config, onChange]
- );
-
- // Shake animation on config change
- const [shaking, setShaking] = useState(false);
- const prevConfigRef = useRef(config);
- useEffect(() => {
- if (
- prevConfigRef.current.shape !== config.shape ||
- prevConfigRef.current.eye !== config.eye ||
- prevConfigRef.current.nose !== config.nose ||
- prevConfigRef.current.bg !== config.bg
- ) {
- setShaking(true);
- const timer = setTimeout(() => setShaking(false), 450);
- prevConfigRef.current = config;
- return () => clearTimeout(timer);
- }
- }, [config]);
-
-
- // Spacebar shortcut for random in horizontal (dialog) mode
- useEffect(() => {
- if (layout !== "horizontal") return;
- const handler = (e: KeyboardEvent) => {
- if (e.code === "Space" && e.target === document.body) {
- e.preventDefault();
- onChange(randomConfig());
- }
- };
- window.addEventListener("keydown", handler);
- return () => window.removeEventListener("keydown", handler);
- }, [layout, onChange]);
-
- const renderShapeThumb = (key: string) => (
- <svg viewBox="0 0 200 200" width="40" height="40">
- <rect width="200" height="200" rx="56" fill="hsl(var(--muted))" />
- <g transform="translate(100,100) scale(0.8) translate(-100,-100)">
- {Shapes[key]?.render()}
- </g>
- </svg>
- );
- const renderNoseThumb = (key: string) => (
- <svg viewBox="-14 -10 28 20" width="36" height="24">
- {Noses[key]?.render("currentColor")}
- </svg>
- );
- const renderEyeThumb = (key: string) => (
- <svg viewBox="-18 -10 36 20" width="44" height="24">
- {Eyes[key]?.render(8, "currentColor")}
- </svg>
- );
-
- const isHorizontal = layout === "horizontal";
-
- const previewSize = isHorizontal ? 220 : mobile ? 120 : 160;
-
- const preview = (
- <div className={cn(
- "flex flex-col items-center gap-3 rounded-2xl bg-muted/30",
- mobile ? "p-3" : "p-4",
- isHorizontal ? "w-70 shrink-0 justify-center" : ""
- )}>
- <div className={cn("rounded-2xl", shaking && "animate-[shake_0.45s_cubic-bezier(.36,.07,.19,.97)]")}>
- <AvatarRenderer config={config} size={previewSize} />
- </div>
- <button
- type="button"
- onClick={() => onChange(randomConfig())}
- className="inline-flex items-center gap-2 rounded-full bg-foreground px-4 py-2 text-sm font-medium text-background hover:bg-foreground/80 transition-colors"
- >
- <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
- <rect x="2" y="2" width="20" height="20" rx="3" />
- <circle cx="8" cy="8" r="1.5" fill="currentColor" />
- <circle cx="16" cy="8" r="1.5" fill="currentColor" />
- <circle cx="8" cy="16" r="1.5" fill="currentColor" />
- <circle cx="16" cy="16" r="1.5" fill="currentColor" />
- <circle cx="12" cy="12" r="1.5" fill="currentColor" />
- </svg>
- Random
- {isHorizontal && (
- <Kbd className="ml-1 bg-background/20 text-[10px] text-inherit">Space</Kbd>
- )}
- </button>
- </div>
- );
-
- const controls = (
- <div className={cn(
- "flex flex-col gap-3 flex-1 min-w-0",
- isHorizontal && "rounded-2xl bg-muted/30 p-4 h-95"
- )}>
- {/* Tabs */}
- <div className="flex border-b border-border">
- <button
- type="button"
- onClick={() => setTab("presets")}
- className={cn(
- "flex-1 pb-2 text-sm font-medium text-center transition-colors border-b-2",
- tab === "presets"
- ? "border-primary text-foreground"
- : "border-transparent text-muted-foreground hover:text-foreground"
- )}
- >
- ★ Presets
- </button>
- <button
- type="button"
- onClick={() => setTab("custom")}
- className={cn(
- "flex-1 pb-2 text-sm font-medium text-center transition-colors border-b-2",
- tab === "custom"
- ? "border-primary text-foreground"
- : "border-transparent text-muted-foreground hover:text-foreground"
- )}
- >
- ⚙ Custom
- </button>
- </div>
-
- {/* Tab content — fixed height so dialog doesn't resize on tab switch */}
- <div className={cn("flex-1 min-h-0", isHorizontal && "overflow-y-auto thin-scrollbar")}>
- {tab === "presets" && (
- <div className={cn("grid gap-2", mobile ? "grid-cols-3" : "grid-cols-4")}>
- {PRESETS.map((p) => {
- const isActive =
- p.config.shape === config.shape &&
- p.config.eye === config.eye &&
- p.config.nose === config.nose &&
- p.config.bg === config.bg;
- return (
- <button
- key={p.name}
- type="button"
- onClick={() => onChange(p.config)}
- className={cn(
- "flex items-center justify-center rounded-xl border p-2 transition-all",
- isActive
- ? "border-primary border-2 bg-primary/5 shadow-sm"
- : "border-border bg-background hover:border-primary/40"
- )}
- >
- <AvatarRenderer config={p.config} size={56} />
- </button>
- );
- })}
- </div>
- )}
-
- {tab === "custom" && (
- <div className="flex flex-col gap-4">
- <Cycler
- label="Shape"
- keys={SHAPE_KEYS}
- value={config.shape}
- onChange={(v) => setField("shape", v)}
- renderThumb={renderShapeThumb}
- mobile={mobile}
- />
- <Cycler
- label="Nose"
- keys={NOSE_KEYS}
- value={config.nose}
- onChange={(v) => setField("nose", v)}
- renderThumb={renderNoseThumb}
- mobile={mobile}
- />
- <Cycler
- label="Eyes"
- keys={EYE_KEYS}
- value={config.eye}
- onChange={(v) => setField("eye", v)}
- renderThumb={renderEyeThumb}
- mobile={mobile}
- />
-
- {/* Background colors */}
- <div>
- <div className="mb-2 text-xs font-medium text-muted-foreground">
- Color
- </div>
- <div className={cn("flex flex-wrap p-1", mobile ? "gap-3" : "gap-2")}>
- {BG_COLORS.map((c, i) => (
- <Tooltip key={c.value}>
- <TooltipTrigger
- render={
- <button
- type="button"
- onClick={() => setField("bg", i)}
- className={cn(
- "rounded-full transition-shadow",
- mobile ? "size-8" : "size-7",
- config.bg === i
- ? "ring-2 ring-primary/50 ring-offset-2"
- : "ring-1 ring-border"
- )}
- style={{ background: `linear-gradient(135deg, ${c.gradient[0]}, ${c.gradient[1]}, ${c.gradient[2]})` }}
- />
- }
- />
- <TooltipContent>{c.name}</TooltipContent>
- </Tooltip>
- ))}
- </div>
- </div>
- </div>
- )}
- </div>
- </div>
- );
-
- if (isHorizontal) {
- return (
- <div className="flex gap-4">
- {preview}
- {controls}
- </div>
- );
- }
-
- return (
- <div className="flex flex-col gap-4">
- {preview}
- {controls}
- </div>
- );
-}
diff --git a/src/web/src/components/avatar/avatar-parts.test.ts b/src/web/src/components/avatar/avatar-parts.test.ts
deleted file mode 100644
index 2f4925184..000000000
--- a/src/web/src/components/avatar/avatar-parts.test.ts
+++ /dev/null
@@ -1,160 +0,0 @@
-import { describe, it, expect } from "vitest"
-import type React from "react"
-import { renderToStaticMarkup } from "react-dom/server"
-import {
- Shapes,
- Eyes,
- Noses,
- BG_COLORS,
- SHAPE_KEYS,
- EYE_KEYS,
- NOSE_KEYS,
- PRESETS,
- randomConfig,
- configFromName,
- isPhotoAvatarUrl,
-} from "./avatar-parts"
-
-const NEW_SHAPE_KEYS = [
- "chat", "shield", "heart", "star", "diamond", "cloud",
- "pentagon", "octagon", "bolt", "flag", "leaf", "drop",
- "triangle", "crown", "gem", "moon", "trophy", "rocket",
-]
-const NEW_EYE_KEYS = [
- "cat", "glasses", "heart", "star", "surprised", "sparkle",
- "square", "cross", "triangle", "target", "puppy", "angry",
-]
-const NEW_NOSE_KEYS = ["grin", "gasp", "zigzag", "pucker", "smirk"]
-
-describe("Shapes", () => {
- it("includes every new shape key", () => {
- for (const key of NEW_SHAPE_KEYS) expect(SHAPE_KEYS).toContain(key)
- })
-
- it("every shape renders without throwing and has a valid face box", () => {
- for (const key of SHAPE_KEYS) {
- const shape = Shapes[key]!
- expect(() => shape.render()).not.toThrow()
- expect(typeof shape.face.cx).toBe("number")
- expect(typeof shape.face.cy).toBe("number")
- expect(shape.face.w).toBeGreaterThan(0)
- }
- })
-})
-
-describe("Eyes", () => {
- it("includes every new eye key", () => {
- for (const key of NEW_EYE_KEYS) expect(EYE_KEYS).toContain(key)
- })
-
- it("every eye renders without throwing", () => {
- for (const key of EYE_KEYS) {
- const eyeDef = Eyes[key]!
- expect(() => eyeDef.render(16, "#27272a")).not.toThrow()
- }
- })
-})
-
-describe("Noses", () => {
- it("includes every new nose key", () => {
- for (const key of NEW_NOSE_KEYS) expect(NOSE_KEYS).toContain(key)
- })
-
- it("every nose renders without throwing", () => {
- for (const key of NOSE_KEYS) {
- const noseDef = Noses[key]!
- expect(() => noseDef.render("#27272a")).not.toThrow()
- }
- })
-})
-
-describe("BG_COLORS", () => {
- it("has at least the 16 newly added palette entries (8 + 8 across two rounds)", () => {
- expect(BG_COLORS.length).toBeGreaterThanOrEqual(28)
- })
-
- it("every entry has a 3-stop gradient and a face color", () => {
- for (const c of BG_COLORS) {
- expect(c.gradient).toHaveLength(3)
- expect(typeof c.faceColor).toBe("string")
- expect(c.faceColor.length).toBeGreaterThan(0)
- }
- })
-})
-
-describe("randomConfig", () => {
- it("always returns keys/index present in the (expanded) lookup tables", () => {
- for (let i = 0; i < 50; i++) {
- const cfg = randomConfig()
- expect(SHAPE_KEYS).toContain(cfg.shape)
- expect(EYE_KEYS).toContain(cfg.eye)
- expect(NOSE_KEYS).toContain(cfg.nose)
- expect(cfg.bg).toBeGreaterThanOrEqual(0)
- expect(cfg.bg).toBeLessThan(BG_COLORS.length)
- }
- })
-})
-
-describe("configFromName", () => {
- it("is deterministic for the same name", () => {
- expect(configFromName("alook-bot")).toEqual(configFromName("alook-bot"))
- })
-
- it("always returns keys/index present in the (expanded) lookup tables", () => {
- for (const name of ["alice", "bob", "charlie", "delta-agent", "email-bot", "z"]) {
- const cfg = configFromName(name)
- expect(SHAPE_KEYS).toContain(cfg.shape)
- expect(EYE_KEYS).toContain(cfg.eye)
- expect(NOSE_KEYS).toContain(cfg.nose)
- expect(cfg.bg).toBeGreaterThanOrEqual(0)
- expect(cfg.bg).toBeLessThan(BG_COLORS.length)
- }
- })
-})
-
-describe("PRESETS", () => {
- it("every preset references valid shape/eye/nose keys and a valid bg index", () => {
- for (const preset of PRESETS) {
- expect(SHAPE_KEYS).toContain(preset.config.shape)
- expect(EYE_KEYS).toContain(preset.config.eye)
- expect(NOSE_KEYS).toContain(preset.config.nose)
- expect(preset.config.bg).toBeGreaterThanOrEqual(0)
- expect(preset.config.bg).toBeLessThan(BG_COLORS.length)
- }
- })
-
- it("includes the new presets built from the new parts", () => {
- const names = PRESETS.map((p) => p.name)
- expect(names).toEqual(
- expect.arrayContaining([
- "Chat", "Guard", "Adore", "Shine", "Energy", "Milestone", "Growth", "Flow",
- "Champion", "Royalty", "Launch", "Night", "Sharp", "Precious",
- ])
- )
- })
-})
-
-describe("isPhotoAvatarUrl", () => {
- it("recognizes https URLs, http URLs, and leading-/ routable paths as photos", () => {
- expect(isPhotoAvatarUrl("https://cdn.example.com/a.png")).toBe(true)
- expect(isPhotoAvatarUrl("http://cdn.example.com/a.png")).toBe(true)
- expect(isPhotoAvatarUrl("/api/community/users/u1/avatar")).toBe(true)
- })
-
- it("rejects null, undefined, empty string, and avatar: configs", () => {
- expect(isPhotoAvatarUrl(null)).toBe(false)
- expect(isPhotoAvatarUrl(undefined)).toBe(false)
- expect(isPhotoAvatarUrl("")).toBe(false)
- expect(isPhotoAvatarUrl("avatar:shape=star")).toBe(false)
- })
-})
-
-describe("star shape", () => {
- it("uses rounded (curved) corners instead of sharp straight-line points", () => {
- const markup = renderToStaticMarkup(Shapes.star!.render() as React.ReactElement)
- const d = markup.match(/d="([^"]+)"/)?.[1] ?? ""
- expect(d).toContain("Q")
- // A pure straight-edge polygon star would have no curve commands at all.
- expect(d.match(/Q/g)?.length).toBeGreaterThanOrEqual(10)
- })
-})
diff --git a/src/web/src/components/avatar/avatar-parts.tsx b/src/web/src/components/avatar/avatar-parts.tsx
deleted file mode 100644
index 55c066623..000000000
--- a/src/web/src/components/avatar/avatar-parts.tsx
+++ /dev/null
@@ -1,758 +0,0 @@
-import { useId } from "react";
-import type { ReactNode } from "react";
-
-// ─────────────────────────────────────────────────────────────
-// STYLE CONSTANTS
-// ─────────────────────────────────────────────────────────────
-const SHAPE_FILL = "rgba(255,255,255,0.92)";
-const SHAPE_STROKE = "rgba(255,255,255,0.95)";
-const SHAPE_SW = 3.5;
-const DEFAULT_FACE_COLOR = "#27272a";
-
-const shapeStyle = { fill: SHAPE_FILL, stroke: SHAPE_STROKE, strokeWidth: SHAPE_SW };
-
-// ─────────────────────────────────────────────────────────────
-// GEOMETRY HELPERS — build rounded-corner polygon paths (used for
-// star/pentagon/octagon/bolt so every vertex reads as soft, not spiky)
-// ─────────────────────────────────────────────────────────────
-type Point = [number, number];
-
-function pointDist(a: Point, b: Point): number {
- return Math.hypot(b[0] - a[0], b[1] - a[1]);
-}
-
-function lerpTowards(from: Point, to: Point, distance: number): Point {
- const d = pointDist(from, to);
- if (d === 0) return from;
- const t = Math.min(distance, d) / d;
- return [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t];
-}
-
-function fmtPoint([x, y]: Point): string {
- return `${x.toFixed(1)} ${y.toFixed(1)}`;
-}
-
-function roundedPolygonPath(pts: Point[], radius: number | ((i: number) => number)): string {
- const n = pts.length;
- const d: string[] = [];
- for (let i = 0; i < n; i++) {
- const prev = pts[(i - 1 + n) % n]!;
- const curr = pts[i]!;
- const next = pts[(i + 1) % n]!;
- const r = typeof radius === "function" ? radius(i) : radius;
- const pa = lerpTowards(curr, prev, r);
- const pb = lerpTowards(curr, next, r);
- d.push(i === 0 ? `M${fmtPoint(pa)}` : `L${fmtPoint(pa)}`);
- d.push(`Q${fmtPoint(curr)} ${fmtPoint(pb)}`);
- }
- d.push("Z");
- return d.join(" ");
-}
-
-function polygonPoints(cx: number, cy: number, radii: number[], startDeg: number): Point[] {
- const step = 360 / radii.length;
- return radii.map((r, i) => {
- const a = ((startDeg + i * step) * Math.PI) / 180;
- return [cx + r * Math.cos(a), cy + r * Math.sin(a)];
- });
-}
-
-const STAR_PATH = roundedPolygonPath(
- polygonPoints(100, 100, [74, 36, 74, 36, 74, 36, 74, 36, 74, 36], -90),
- (i) => (i % 2 === 0 ? 15 : 9)
-);
-const PENTAGON_PATH = roundedPolygonPath(polygonPoints(100, 104, [74, 74, 74, 74, 74], -90), 16);
-const OCTAGON_PATH = roundedPolygonPath(polygonPoints(100, 100, new Array(8).fill(72), -67.5), 14);
-const BOLT_PATH = roundedPolygonPath(
- [[112, 28], [66, 104], [96, 104], [82, 174], [140, 92], [108, 92]],
- 7
-);
-const TRIANGLE_PATH = roundedPolygonPath(polygonPoints(100, 110, [80, 80, 80], -90), 20);
-const CROWN_PATH = roundedPolygonPath(
- [[40, 130], [54, 60], [74, 100], [100, 40], [126, 100], [146, 60], [160, 130], [160, 172], [40, 172]],
- (i) => (i === 7 || i === 8 ? 12 : 7)
-);
-const GEM_PATH = roundedPolygonPath(
- [[58, 66], [86, 38], [114, 38], [142, 66], [100, 172]],
- 9
-);
-const MOON_PATH = "M163.8 105.6 A63.75 63.75 0 1 1 94.4 36.3 A49.6 49.6 0 0 0 163.8 105.6 Z";
-
-// ─────────────────────────────────────────────────────────────
-// PALETTES
-// ─────────────────────────────────────────────────────────────
-export interface ColorOption {
- name: string;
- value: string;
- gradient: [string, string, string];
- faceColor: string;
-}
-
-export const BG_COLORS: ColorOption[] = [
- { name: "Purple", value: "#a855f7", gradient: ["#c084fc", "#a855f7", "#7c3aed"], faceColor: "#2e1065" },
- { name: "Teal", value: "#14b8a6", gradient: ["#5eead4", "#14b8a6", "#0d9488"], faceColor: "#134e4a" },
- { name: "Orange", value: "#f97316", gradient: ["#fdba74", "#f97316", "#c2410c"], faceColor: "#7c2d12" },
- { name: "Blue", value: "#3b82f6", gradient: ["#93c5fd", "#3b82f6", "#1d4ed8"], faceColor: "#1e3a5f" },
- { name: "Pink", value: "#f472b6", gradient: ["#fda4af", "#f472b6", "#be185d"], faceColor: "#831843" },
- { name: "Yellow", value: "#eab308", gradient: ["#fde047", "#eab308", "#a16207"], faceColor: "#713f12" },
- { name: "Green", value: "#22c55e", gradient: ["#86efac", "#22c55e", "#15803d"], faceColor: "#14532d" },
- { name: "Beige", value: "#d6ccb8", gradient: ["#e8e0d4", "#d6ccb8", "#b8a990"], faceColor: "#57534e" },
- { name: "Red", value: "#ef4444", gradient: ["#fca5a5", "#ef4444", "#991b1b"], faceColor: "#7f1d1d" },
- { name: "Lake Blue", value: "#6366f1", gradient: ["#a5b4fc", "#6366f1", "#3730a3"], faceColor: "#312e81" },
- { name: "Gray", value: "#9ca3af", gradient: ["#d4d4d8", "#9ca3af", "#6b7280"], faceColor: "#374151" },
- { name: "Deep Purple", value: "#8b5cf6", gradient: ["#c4b5fd", "#8b5cf6", "#5b21b6"], faceColor: "#3b0764" },
- { name: "Coral", value: "#fb7185", gradient: ["#fecdd3", "#fb7185", "#be123c"], faceColor: "#881337" },
- { name: "Mint", value: "#2dd4bf", gradient: ["#99f6e4", "#2dd4bf", "#0f766e"], faceColor: "#134e4a" },
- { name: "Indigo", value: "#4f46e5", gradient: ["#a5b4fc", "#4f46e5", "#3730a3"], faceColor: "#1e1b4b" },
- { name: "Rose", value: "#e11d48", gradient: ["#fda4af", "#e11d48", "#881337"], faceColor: "#4c0519" },
- { name: "Amber", value: "#f59e0b", gradient: ["#fcd34d", "#f59e0b", "#b45309"], faceColor: "#78350f" },
- { name: "Cyan", value: "#06b6d4", gradient: ["#67e8f9", "#06b6d4", "#0e7490"], faceColor: "#164e63" },
- { name: "Slate", value: "#64748b", gradient: ["#cbd5e1", "#64748b", "#334155"], faceColor: "#1e293b" },
- { name: "Lime", value: "#84cc16", gradient: ["#d9f99d", "#84cc16", "#4d7c0f"], faceColor: "#365314" },
- { name: "Sky", value: "#0ea5e9", gradient: ["#7dd3fc", "#0ea5e9", "#0369a1"], faceColor: "#0c4a6e" },
- { name: "Fuchsia", value: "#d946ef", gradient: ["#f0abfc", "#d946ef", "#a21caf"], faceColor: "#4a044e" },
- { name: "Emerald", value: "#059669", gradient: ["#6ee7b7", "#059669", "#047857"], faceColor: "#022c22" },
- { name: "Sand", value: "#d4a373", gradient: ["#f0dcc4", "#d4a373", "#a67c52"], faceColor: "#4a2e17" },
- { name: "Copper", value: "#c2703d", gradient: ["#e8b088", "#c2703d", "#8a4a1f"], faceColor: "#431f0a" },
- { name: "Charcoal", value: "#52525b", gradient: ["#a1a1aa", "#52525b", "#27272a"], faceColor: "#18181b" },
- { name: "Denim", value: "#4a7ba6", gradient: ["#93b8d4", "#4a7ba6", "#2c5170"], faceColor: "#16283a" },
- { name: "Plum", value: "#8e4585", gradient: ["#d8a8d1", "#8e4585", "#5c2a55"], faceColor: "#2e1330" },
-];
-
-// ─────────────────────────────────────────────────────────────
-// SHAPES (rounded silhouettes only)
-// ─────────────────────────────────────────────────────────────
-export interface ShapeDef {
- name: string;
- face: { cx: number; cy: number; w: number };
- render: () => ReactNode;
-}
-
-export const Shapes: Record<string, ShapeDef> = {
- circle: {
- name: "Circle",
- face: { cx: 100, cy: 100, w: 80 },
- render: () => <circle cx="100" cy="100" r="66" {...shapeStyle} />,
- },
- rounded: {
- name: "Rounded",
- face: { cx: 100, cy: 100, w: 90 },
- render: () => <rect x="30" y="30" width="140" height="140" rx="32" {...shapeStyle} />,
- },
- hexagon: {
- name: "Hexagon",
- face: { cx: 100, cy: 100, w: 86 },
- render: () => (
- <path d="M100 32 C108 32 114 35 120 39 L155 60 C161 64 165 70 165 78 L165 122 C165 130 161 136 155 140 L120 161 C114 165 108 168 100 168 C92 168 86 165 80 161 L45 140 C39 136 35 130 35 122 L35 78 C35 70 39 64 45 60 L80 39 C86 35 92 32 100 32 Z" {...shapeStyle} />
- ),
- },
- task: {
- name: "Task",
- face: { cx: 100, cy: 100, w: 80 },
- render: () => <rect x="34" y="34" width="132" height="132" rx="24" {...shapeStyle} />,
- },
- book: {
- name: "Book",
- face: { cx: 100, cy: 100, w: 80 },
- render: () => (
- <path d="M42 162 L42 88 C42 54 68 34 100 34 C132 34 158 54 158 88 L158 162 C158 166 154 170 150 170 L50 170 C46 170 42 166 42 162 Z" {...shapeStyle} />
- ),
- },
- mail: {
- name: "Mail",
- face: { cx: 100, cy: 100, w: 86 },
- render: () => <rect x="28" y="54" width="144" height="92" rx="46" {...shapeStyle} />,
- },
- calendar: {
- name: "Calendar",
- face: { cx: 100, cy: 100, w: 80 },
- render: () => (
- <path d="M100 34 C138 34 166 52 166 80 C166 94 158 106 158 118 C158 148 138 166 100 166 C62 166 42 148 42 118 C42 106 34 94 34 80 C34 52 62 34 100 34 Z" {...shapeStyle} />
- ),
- },
- bulb: {
- name: "Bulb",
- face: { cx: 100, cy: 104, w: 76 },
- render: () => <ellipse cx="100" cy="104" rx="58" ry="66" {...shapeStyle} />,
- },
- folder: {
- name: "Folder",
- face: { cx: 102, cy: 108, w: 80 },
- render: () => (
- <path d="M62 144 C40 144 32 128 36 116 C32 104 40 90 54 88 C56 72 70 60 88 62 C100 50 118 50 132 58 C144 52 162 60 162 76 C172 82 174 98 166 108 C172 120 164 136 150 140 Z" {...shapeStyle} />
- ),
- },
- mountain: {
- name: "Mountain",
- face: { cx: 100, cy: 100, w: 76 },
- render: () => (
- <path d="M92 36 C120 32 156 48 164 78 C172 108 156 148 124 160 C92 172 48 156 38 124 C28 92 62 40 92 36 Z" {...shapeStyle} />
- ),
- },
- chat: {
- name: "Chat",
- face: { cx: 100, cy: 86, w: 76 },
- render: () => (
- <path d="M54 34 L146 34 C162 34 174 46 174 62 L174 118 C174 134 162 146 146 146 L90 146 L58 176 L54 146 C38 146 26 134 26 118 L26 62 C26 46 38 34 54 34 Z" {...shapeStyle} />
- ),
- },
- shield: {
- name: "Shield",
- face: { cx: 100, cy: 94, w: 74 },
- render: () => (
- <path d="M100 30 L156 50 C160 52 162 56 162 60 L162 96 C162 132 136 158 100 172 C64 158 38 132 38 96 L38 60 C38 56 40 52 44 50 Z" {...shapeStyle} />
- ),
- },
- heart: {
- name: "Heart",
- face: { cx: 100, cy: 92, w: 78 },
- render: () => (
- <path d="M100 168 C40 128 24 92 34 66 C44 40 78 34 100 62 C122 34 156 40 166 66 C176 92 160 128 100 168 Z" {...shapeStyle} />
- ),
- },
- star: {
- name: "Star",
- face: { cx: 100, cy: 100, w: 60 },
- render: () => <path d={STAR_PATH} {...shapeStyle} />,
- },
- diamond: {
- name: "Diamond",
- face: { cx: 100, cy: 103, w: 78 },
- render: () => (
- <path d="M100 26 C106 26 111 29 115 34 L168 92 C174 98 174 108 168 114 L115 172 C111 177 106 180 100 180 C94 180 89 177 85 172 L32 114 C26 108 26 98 32 92 L85 34 C89 29 94 26 100 26 Z" {...shapeStyle} />
- ),
- },
- cloud: {
- name: "Cloud",
- face: { cx: 100, cy: 106, w: 80 },
- render: () => (
- <path d="M60 140 C42 140 30 126 30 110 C30 96 40 84 54 82 C58 62 76 48 98 48 C118 48 134 60 140 78 C158 78 172 92 172 110 C172 126 160 138 144 140 Z" {...shapeStyle} />
- ),
- },
- pentagon: {
- name: "Pentagon",
- face: { cx: 100, cy: 106, w: 76 },
- render: () => <path d={PENTAGON_PATH} {...shapeStyle} />,
- },
- octagon: {
- name: "Octagon",
- face: { cx: 100, cy: 100, w: 82 },
- render: () => <path d={OCTAGON_PATH} {...shapeStyle} />,
- },
- bolt: {
- name: "Bolt",
- face: { cx: 103, cy: 90, w: 66 },
- render: () => <path d={BOLT_PATH} {...shapeStyle} />,
- },
- flag: {
- name: "Flag",
- face: { cx: 100, cy: 84, w: 76 },
- render: () => (
- <path d="M62 30 L138 30 C146 30 152 36 152 44 L152 150 L100 122 L48 150 L48 44 C48 36 54 30 62 30 Z" {...shapeStyle} />
- ),
- },
- leaf: {
- name: "Leaf",
- face: { cx: 103, cy: 102, w: 76 },
- render: () => (
- <path d="M100 26 C136 44 162 74 162 108 C162 144 132 172 104 176 C98 177 92 174 92 168 C68 160 48 136 44 108 C40 74 64 44 100 26 Z" {...shapeStyle} />
- ),
- },
- drop: {
- name: "Drop",
- face: { cx: 100, cy: 122, w: 74 },
- render: () => (
- <path d="M100 28 C130 66 152 96 152 124 C152 152 128 172 100 172 C72 172 48 152 48 124 C48 96 70 66 100 28 Z" {...shapeStyle} />
- ),
- },
- triangle: {
- name: "Triangle",
- face: { cx: 100, cy: 122, w: 64 },
- render: () => <path d={TRIANGLE_PATH} {...shapeStyle} />,
- },
- crown: {
- name: "Crown",
- face: { cx: 100, cy: 150, w: 72 },
- render: () => <path d={CROWN_PATH} {...shapeStyle} />,
- },
- gem: {
- name: "Gem",
- face: { cx: 100, cy: 86, w: 64 },
- render: () => <path d={GEM_PATH} {...shapeStyle} />,
- },
- moon: {
- name: "Moon",
- face: { cx: 86, cy: 82, w: 40 },
- render: () => <path d={MOON_PATH} {...shapeStyle} />,
- },
- trophy: {
- name: "Trophy",
- face: { cx: 100, cy: 72, w: 76 },
- render: () => (
- <path d="M54 34 L146 34 C146 34 150 34 150 40 C150 78 130 104 108 110 L108 128 L134 128 C140 128 144 132 144 138 L144 158 C144 164 140 168 134 168 L66 168 C60 168 56 164 56 158 L56 138 C56 132 60 128 66 128 L92 128 L92 110 C70 104 50 78 50 40 C50 34 54 34 54 34 Z" {...shapeStyle} />
- ),
- },
- rocket: {
- name: "Rocket",
- face: { cx: 100, cy: 88, w: 54 },
- render: () => (
- <g>
- <path d="M100 30 C118 30 132 62 132 96 C132 108 128 118 124 126 L124 150 L76 150 L76 126 C72 118 68 108 68 96 C68 62 82 30 100 30 Z" {...shapeStyle} />
- <path d="M68 118 C50 118 40 140 44 158 C52 148 62 140 74 138 Z" {...shapeStyle} />
- <path d="M132 118 C150 118 160 140 156 158 C148 148 138 140 126 138 Z" {...shapeStyle} />
- </g>
- ),
- },
-};
-
-export const SHAPE_KEYS = Object.keys(Shapes);
-
-// ─────────────────────────────────────────────────────────────
-// NOSES (mouths)
-// ─────────────────────────────────────────────────────────────
-export interface NoseDef {
- name: string;
- render: (color?: string) => ReactNode;
-}
-
-export const Noses: Record<string, NoseDef> = {
- dot: {
- name: "Dot",
- render: (c = DEFAULT_FACE_COLOR) => <circle cx="0" cy="0" r="4.5" fill={c} />,
- },
- dash: {
- name: "Dash",
- render: (c = DEFAULT_FACE_COLOR) => <line x1="-10" y1="0" x2="10" y2="0" stroke={c} strokeWidth="5" strokeLinecap="round" />,
- },
- hookL: {
- name: "Hook",
- render: (c = DEFAULT_FACE_COLOR) => <path d="M-11 0 Q-5.5 7 0 1.5 Q5.5 7 11 0" fill="none" stroke={c} strokeWidth="4.5" strokeLinecap="round" strokeLinejoin="round" />,
- },
- smile: {
- name: "Smile",
- render: (c = DEFAULT_FACE_COLOR) => <path d="M-11 0 Q0 11 11 0" fill="none" stroke={c} strokeWidth="5" strokeLinecap="round" />,
- },
- caret: {
- name: "Caret",
- render: (c = DEFAULT_FACE_COLOR) => (
- <g>
- <path d="M-10 0 Q0 8 10 0" fill="none" stroke={c} strokeWidth="4.5" strokeLinecap="round" />
- <ellipse cx="3" cy="6" rx="4" ry="4.5" fill="#f472b6" />
- </g>
- ),
- },
- arrow: {
- name: "Arrow",
- render: (c = DEFAULT_FACE_COLOR) => <ellipse cx="0" cy="0" rx="6" ry="7.5" fill={c} />,
- },
- oh: {
- name: "o",
- render: (c = DEFAULT_FACE_COLOR) => <ellipse cx="0" cy="0" rx="7" ry="7.5" fill="none" stroke={c} strokeWidth="4.5" />,
- },
- grin: {
- name: "Grin",
- render: (c = DEFAULT_FACE_COLOR) => (
- <g>
- <path d="M-11 0 Q0 10 11 0" fill="none" stroke={c} strokeWidth="5" strokeLinecap="round" />
- <line x1="-7" y1="4" x2="7" y2="4" stroke={c} strokeWidth="3" strokeLinecap="round" />
- </g>
- ),
- },
- gasp: {
- name: "Gasp",
- render: (c = DEFAULT_FACE_COLOR) => <rect x="-6" y="-2" width="12" height="13" rx="6" fill={c} />,
- },
- zigzag: {
- name: "Zigzag",
- render: (c = DEFAULT_FACE_COLOR) => (
- <path d="M-11 0 L-5 4 L1 -3 L7 4 L11 0" fill="none" stroke={c} strokeWidth="4.5" strokeLinecap="round" strokeLinejoin="round" />
- ),
- },
- pucker: {
- name: "Pucker",
- render: (c = DEFAULT_FACE_COLOR) => <path d="M-3 -5 Q4 -5 4 0 Q4 5 -3 5 Q2 0 -3 -5 Z" fill={c} />,
- },
- smirk: {
- name: "Smirk",
- render: (c = DEFAULT_FACE_COLOR) => (
- <path d="M-9 2 Q-2 2 3 -5 L11 -5" fill="none" stroke={c} strokeWidth="4.5" strokeLinecap="round" strokeLinejoin="round" />
- ),
- },
-};
-
-export const NOSE_KEYS = Object.keys(Noses);
-
-// ─────────────────────────────────────────────────────────────
-// EYES
-// ─────────────────────────────────────────────────────────────
-export interface EyeDef {
- name: string;
- render: (dx: number, color?: string) => ReactNode;
-}
-
-const eye = (l: (c: string) => ReactNode, r?: (c: string) => ReactNode) => {
- const rFn = r ?? l;
- const EyePair = (dx: number, c = DEFAULT_FACE_COLOR) => (
- <g>
- <g transform={`translate(${-dx}, 0)`}>{l(c)}</g>
- <g transform={`translate(${dx}, 0)`}>{rFn(c)}</g>
- </g>
- );
- EyePair.displayName = "EyePair";
- return EyePair;
-};
-
-export const Eyes: Record<string, EyeDef> = {
- dots: {
- name: "Dots",
- render: eye((c) => <circle cx="0" cy="0" r="7" fill={c} />),
- },
- big: {
- name: "Big",
- render: eye((c) => (
- <g>
- <circle cx="0" cy="0" r="10" fill={c} />
- <circle cx="2.5" cy="-3" r="3.5" fill="rgba(255,255,255,0.9)" />
- </g>
- )),
- },
- rings: {
- name: "Rings",
- render: eye((c) => <ellipse cx="0" cy="0" rx="8.5" ry="9.5" fill="none" stroke={c} strokeWidth="4.5" />),
- },
- arches: {
- name: "Arches",
- render: eye((c) => <path d="M-10 2 Q0 -9 10 2" fill="none" stroke={c} strokeWidth="5" strokeLinecap="round" />),
- },
- lines: {
- name: "Lines",
- render: eye((c) => <path d="M-10 0 Q0 -6 10 0" fill="none" stroke={c} strokeWidth="5" strokeLinecap="round" />),
- },
- happy: {
- name: "Happy",
- render: eye((c) => <path d="M-10 5 Q0 -11 10 5" fill="none" stroke={c} strokeWidth="5" strokeLinecap="round" />),
- },
- sleepy: {
- name: "Sleepy",
- render: eye((c) => <path d="M-10 -2 Q0 8 10 -2" fill="none" stroke={c} strokeWidth="5" strokeLinecap="round" />),
- },
- shy: {
- name: "Shy",
- render: eye((c) => <ellipse cx="0" cy="0" rx="8.5" ry="9.5" fill={c} />),
- },
- wink: {
- name: "Wink",
- render: (dx: number, c = DEFAULT_FACE_COLOR) => (
- <g>
- <g transform={`translate(${-dx}, 0)`}><circle cx="0" cy="0" r="7" fill={c} /></g>
- <g transform={`translate(${dx}, 0)`}><path d="M-10 2 Q0 -9 10 2" fill="none" stroke={c} strokeWidth="5" strokeLinecap="round" /></g>
- </g>
- ),
- },
- cat: {
- name: "Cat",
- render: (dx: number, c = DEFAULT_FACE_COLOR) => (
- <g>
- <g transform={`translate(${-dx}, 0)`}>
- <path d="M-11 2 C-11 -6 -2 -10 7 -6 C12 -3 10 4 4 6 C-3 9 -11 8 -11 2 Z" fill={c} />
- </g>
- <g transform={`translate(${dx}, 0) scale(-1, 1)`}>
- <path d="M-11 2 C-11 -6 -2 -10 7 -6 C12 -3 10 4 4 6 C-3 9 -11 8 -11 2 Z" fill={c} />
- </g>
- </g>
- ),
- },
- glasses: {
- name: "Glasses",
- render: (dx: number, c = DEFAULT_FACE_COLOR) => (
- <g>
- <line x1={-dx + 9} y1="0" x2={dx - 9} y2="0" stroke={c} strokeWidth="3.5" />
- <g transform={`translate(${-dx}, 0)`}><circle cx="0" cy="0" r="9" fill="none" stroke={c} strokeWidth="4.5" /></g>
- <g transform={`translate(${dx}, 0)`}><circle cx="0" cy="0" r="9" fill="none" stroke={c} strokeWidth="4.5" /></g>
- </g>
- ),
- },
- heart: {
- name: "Heart",
- render: eye(() => (
- <path
- d="M0 5 C-6 0 -10 -4 -6 -8 C-3 -10 0 -8 0 -6 C0 -8 3 -10 6 -8 C10 -4 6 0 0 5 Z"
- fill="#f472b6"
- />
- )),
- },
- star: {
- name: "Star",
- render: eye((c) => (
- <path d="M0 -9 C1 -3 3 -1 9 0 C3 1 1 3 0 9 C-1 3 -3 1 -9 0 C-3 -1 -1 -3 0 -9 Z" fill={c} />
- )),
- },
- surprised: {
- name: "Surprised",
- render: eye((c) => (
- <g>
- <circle cx="0" cy="0" r="11" fill="none" stroke={c} strokeWidth="4" />
- <circle cx="0" cy="0" r="4" fill={c} />
- </g>
- )),
- },
- sparkle: {
- name: "Sparkle",
- render: eye((c) => (
- <g>
- <circle cx="0" cy="0" r="9" fill={c} />
- <path
- d="M3 -7 C3.5 -4 4 -3.5 7 -3 C4 -2.5 3.5 -2 3 1 C2.5 -2 2 -2.5 -1 -3 C2 -3.5 2.5 -4 3 -7 Z"
- fill="rgba(255,255,255,0.9)"
- />
- </g>
- )),
- },
- square: {
- name: "Square",
- render: eye((c) => <rect x="-7" y="-7" width="14" height="14" rx="4" fill={c} />),
- },
- cross: {
- name: "Cross",
- render: eye((c) => (
- <g>
- <line x1="-7" y1="-7" x2="7" y2="7" stroke={c} strokeWidth="4" strokeLinecap="round" />
- <line x1="-7" y1="7" x2="7" y2="-7" stroke={c} strokeWidth="4" strokeLinecap="round" />
- </g>
- )),
- },
- triangle: {
- name: "Triangle",
- render: eye((c) => <path d="M0 -9 Q2 -9 3 -7 L8 6 Q9 8 7 8 L-7 8 Q-9 8 -8 6 L-3 -7 Q-2 -9 0 -9 Z" fill={c} />),
- },
- target: {
- name: "Target",
- render: eye((c) => (
- <g>
- <circle cx="0" cy="0" r="9" fill="none" stroke={c} strokeWidth="2.5" />
- <circle cx="0" cy="0" r="4" fill="none" stroke={c} strokeWidth="2.5" />
- </g>
- )),
- },
- puppy: {
- name: "Puppy",
- render: eye((c) => (
- <g>
- <ellipse cx="0" cy="1" rx="9" ry="10" fill={c} />
- <circle cx="-3" cy="-4" r="3" fill="rgba(255,255,255,0.9)" />
- <circle cx="3.5" cy="1" r="1.8" fill="rgba(255,255,255,0.7)" />
- </g>
- )),
- },
- angry: {
- name: "Angry",
- render: (dx: number, c = DEFAULT_FACE_COLOR) => (
- <g>
- <g transform={`translate(${-dx}, 0)`}><path d="M-8 -6 L8 2" stroke={c} strokeWidth="5" strokeLinecap="round" /></g>
- <g transform={`translate(${dx}, 0) scale(-1, 1)`}><path d="M-8 -6 L8 2" stroke={c} strokeWidth="5" strokeLinecap="round" /></g>
- </g>
- ),
- },
-};
-
-export const EYE_KEYS = Object.keys(Eyes);
-
-// ─────────────────────────────────────────────────────────────
-// AVATAR CONFIG
-// ─────────────────────────────────────────────────────────────
-export interface AvatarConfig {
- shape: string;
- eye: string;
- nose: string;
- bg: number;
-}
-
-export const DEFAULT_CONFIG: AvatarConfig = {
- shape: "book",
- eye: "happy",
- nose: "dash",
- bg: 1,
-};
-
-// ─────────────────────────────────────────────────────────────
-// PRESETS
-// ─────────────────────────────────────────────────────────────
-export interface Preset {
- name: string;
- config: AvatarConfig;
-}
-
-export const PRESETS: Preset[] = [
- { name: "Task", config: { shape: "task", nose: "dot", eye: "dots", bg: 0 } },
- { name: "Notes", config: { shape: "book", nose: "dash", eye: "happy", bg: 1 } },
- { name: "Mail", config: { shape: "mail", nose: "smile", eye: "dots", bg: 3 } },
- { name: "Schedule", config: { shape: "calendar", nose: "dot", eye: "dots", bg: 4 } },
- { name: "Idea", config: { shape: "bulb", nose: "oh", eye: "rings", bg: 5 } },
- { name: "Project", config: { shape: "folder", nose: "dash", eye: "lines", bg: 7 } },
- { name: "Goal", config: { shape: "mountain", nose: "caret", eye: "arches", bg: 8 } },
- { name: "Dream", config: { shape: "circle", nose: "smile", eye: "shy", bg: 11 } },
- { name: "Organize", config: { shape: "rounded", nose: "dot", eye: "sleepy", bg: 6 } },
- { name: "Explore", config: { shape: "hexagon", nose: "hookL", eye: "wink", bg: 9 } },
- { name: "Focus", config: { shape: "task", nose: "caret", eye: "lines", bg: 2 } },
- { name: "Collect", config: { shape: "book", nose: "oh", eye: "rings", bg: 10 } },
- { name: "Chat", config: { shape: "chat", nose: "grin", eye: "surprised", bg: 12 } },
- { name: "Guard", config: { shape: "shield", nose: "smirk", eye: "glasses", bg: 18 } },
- { name: "Adore", config: { shape: "heart", nose: "pucker", eye: "heart", bg: 15 } },
- { name: "Shine", config: { shape: "star", nose: "gasp", eye: "sparkle", bg: 16 } },
- { name: "Energy", config: { shape: "bolt", nose: "zigzag", eye: "big", bg: 5 } },
- { name: "Milestone", config: { shape: "flag", nose: "smile", eye: "happy", bg: 26 } },
- { name: "Growth", config: { shape: "leaf", nose: "dot", eye: "sleepy", bg: 22 } },
- { name: "Flow", config: { shape: "drop", nose: "oh", eye: "shy", bg: 20 } },
- { name: "Champion", config: { shape: "trophy", nose: "grin", eye: "puppy", bg: 16 } },
- { name: "Royalty", config: { shape: "crown", nose: "smirk", eye: "target", bg: 21 } },
- { name: "Launch", config: { shape: "rocket", nose: "gasp", eye: "cross", bg: 8 } },
- { name: "Night", config: { shape: "moon", nose: "dash", eye: "square", bg: 14 } },
- { name: "Sharp", config: { shape: "triangle", nose: "zigzag", eye: "angry", bg: 25 } },
- { name: "Precious", config: { shape: "gem", nose: "oh", eye: "sparkle", bg: 17 } },
-];
-
-// ─────────────────────────────────────────────────────────────
-// RANDOM CONFIG
-// ─────────────────────────────────────────────────────────────
-function pick<T>(arr: T[]): T {
- return arr[Math.floor(Math.random() * arr.length)]!;
-}
-
-export function randomConfig(): AvatarConfig {
- return {
- shape: pick(SHAPE_KEYS),
- eye: pick(EYE_KEYS),
- nose: pick(NOSE_KEYS),
- bg: Math.floor(Math.random() * BG_COLORS.length),
- };
-}
-
-// ─────────────────────────────────────────────────────────────
-// DETERMINISTIC CONFIG FROM NAME
-// ─────────────────────────────────────────────────────────────
-function hashStr(s: string): number {
- let h = 0;
- for (let i = 0; i < s.length; i++) {
- h = ((h << 5) - h + s.charCodeAt(i)) | 0;
- }
- return Math.abs(h);
-}
-
-export function configFromName(name: string): AvatarConfig {
- const h = hashStr(name.toLowerCase());
- return {
- shape: SHAPE_KEYS[h % SHAPE_KEYS.length]!,
- eye: EYE_KEYS[(h >>> 4) % EYE_KEYS.length]!,
- nose: NOSE_KEYS[(h >>> 8) % NOSE_KEYS.length]!,
- bg: (h >>> 12) % BG_COLORS.length,
- };
-}
-
-// ─────────────────────────────────────────────────────────────
-// AVATAR RENDERER
-// ─────────────────────────────────────────────────────────────
-interface AvatarRendererProps {
- config: AvatarConfig;
- size?: number;
- className?: string;
-}
-
-export function AvatarRenderer({ config, size = 200, className }: AvatarRendererProps) {
- const uid = useId().replace(/:/g, "");
- const sh = Shapes[config.shape] ?? Shapes.book!;
- const ey = Eyes[config.eye];
- const no = Noses[config.nose];
- const bgEntry = BG_COLORS[config.bg] ?? BG_COLORS[0]!;
- const [g0, g1, g2] = bgEntry.gradient;
- const faceColor = bgEntry.faceColor;
-
- const { cx, cy, w } = sh.face;
- const eyeDx = Math.max(13, w * 0.24);
- const eyeY = cy - Math.max(12, w * 0.16);
-
- return (
- <svg
- viewBox="0 0 200 200"
- width={size}
- height={size}
- className={className}
- style={{ display: "block" }}
- >
- <defs>
- <linearGradient id={`bg-${uid}`} x1="0%" y1="0%" x2="100%" y2="100%">
- <stop offset="0%" stopColor={g0} />
- <stop offset="50%" stopColor={g1} />
- <stop offset="100%" stopColor={g2} />
- </linearGradient>
- <radialGradient id={`gl-${uid}`} cx="30%" cy="25%" r="60%">
- <stop offset="0%" stopColor="rgba(255,255,255,0.32)" />
- <stop offset="100%" stopColor="rgba(255,255,255,0)" />
- </radialGradient>
- <filter id={`sh-${uid}`} x="-10%" y="-5%" width="120%" height="130%">
- <feDropShadow dx="0" dy="3" stdDeviation="4" floodColor="rgba(0,0,0,0.18)" />
- </filter>
- </defs>
- <rect x="0" y="0" width="200" height="200" rx="56" fill={`url(#bg-${uid})`} />
- <rect x="0" y="0" width="200" height="200" rx="56" fill={`url(#gl-${uid})`} />
- <g transform="translate(100,100) scale(0.8) translate(-100,-100)">
- <g data-avatar-shape="" filter={`url(#sh-${uid})`}>{sh.render()}</g>
- {ey && <g transform={`translate(${cx}, ${eyeY})`}><g data-avatar-eyes="">{ey.render(eyeDx, faceColor)}</g></g>}
- {no && <g transform={`translate(${cx}, ${cy + 7})`}><g data-avatar-nose="">{no.render(faceColor)}</g></g>}
- </g>
- </svg>
- );
-}
-
-// ─────────────────────────────────────────────────────────────
-// SERIALIZE / DESERIALIZE
-// ─────────────────────────────────────────────────────────────
-const AVATAR_PREFIX = "avatar:";
-
-export function serializeAvatarConfig(config: AvatarConfig): string {
- return AVATAR_PREFIX + JSON.stringify(config);
-}
-
-function isValidAvatarConfig(obj: unknown): obj is AvatarConfig {
- if (typeof obj !== "object" || obj === null) return false;
- const rec = obj as Record<string, unknown>;
- return (
- typeof rec.shape === "string" &&
- typeof rec.eye === "string" &&
- typeof rec.nose === "string" &&
- typeof rec.bg === "number"
- );
-}
-
-export function parseAvatarUrl(avatarUrl: string | null | undefined): AvatarConfig | null {
- if (!avatarUrl || !avatarUrl.startsWith(AVATAR_PREFIX)) return null;
- try {
- const parsed = JSON.parse(avatarUrl.slice(AVATAR_PREFIX.length));
- if (isValidAvatarConfig(parsed)) return parsed;
- if (typeof parsed === "object" && parsed !== null && "outline" in parsed) {
- return DEFAULT_CONFIG;
- }
- return null;
- } catch {
- return null;
- }
-}
-
-// ─────────────────────────────────────────────────────────────
-// PHOTO AVATAR DETECTION — same leading-`/`/`https://`/`http://` check as
-// community `avatar.tsx`'s private `isUrl`, duplicated intentionally rather
-// than cross-imported: `components/avatar/` is the generic module,
-// `components/community/avatar.tsx` is community-specific, and the reverse
-// import would invert that layering.
-// ─────────────────────────────────────────────────────────────
-export function isPhotoAvatarUrl(url: string | null | undefined): boolean {
- return !!url && (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("/"));
-}
-
-// ─────────────────────────────────────────────────────────────
-// AVATAR DRAFT — the dual-mode draft used by `BotAvatarPickerDialog`.
-// `file` is null when re-opening an *existing* photo untouched (edit); a
-// real `File` once freshly cropped this session.
-// ─────────────────────────────────────────────────────────────
-export type AvatarDraft =
- | { kind: "procedural"; image: string }
- | { kind: "photo"; file: File | null; previewUrl: string };
diff --git a/src/web/src/components/avatar/avatar-picker-dialog.tsx b/src/web/src/components/avatar/avatar-picker-dialog.tsx
index d21c77f8c..964e009ac 100644
--- a/src/web/src/components/avatar/avatar-picker-dialog.tsx
+++ b/src/web/src/components/avatar/avatar-picker-dialog.tsx
@@ -1,75 +1,50 @@
"use client";
import { useState } from "react";
-import {
- Dialog,
- DialogTrigger,
- DialogContent,
- DialogHeader,
- DialogTitle,
-} from "@/components/ui/dialog";
-import { type AvatarConfig, AvatarRenderer } from "./avatar-parts";
-import { AvatarGenerator } from "./avatar-generator";
-import { useIsMobile } from "@/hooks/use-mobile";
+import { Shuffle } from "lucide-react";
+import { BoringAvatar } from "./boring-avatar";
+import { serializeBeamSeed, parseBeamSeed } from "@/lib/avatar/seed-url";
interface AvatarPickerDialogProps {
- config: AvatarConfig;
- onChange: (config: AvatarConfig) => void;
+ /** Stored avatar value (`avatar:beam:{seed}` or a photo URL). */
+ value: string | null;
+ /** Emits the new stored value (`avatar:beam:{seed}`). */
+ onChange: (value: string) => void;
}
-export function AvatarPickerDialog({ config, onChange }: AvatarPickerDialogProps) {
- const [open, setOpen] = useState(false);
- const [draft, setDraft] = useState<AvatarConfig>(config);
- const isMobile = useIsMobile();
+function randomSeed(): string {
+ return crypto.randomUUID();
+}
+
+/**
+ * Beam avatar picker: a preview + a "shuffle" button that rerolls the seed.
+ * boring-avatars has no editable model (shape/eye/nose), so "generate" is just
+ * a fresh random seed; the chosen seed persists as `avatar:beam:{seed}`.
+ */
+export function AvatarPickerDialog({ value, onChange }: AvatarPickerDialogProps) {
+ const [seed, setSeed] = useState<string>(() => parseBeamSeed(value) ?? randomSeed());
+
+ const shuffle = () => {
+ const next = randomSeed();
+ setSeed(next);
+ onChange(serializeBeamSeed(next));
+ };
return (
- <Dialog
- open={open}
- onOpenChange={(nextOpen) => {
- if (nextOpen) setDraft(config);
- setOpen(nextOpen);
- }}
- >
- <div className="flex justify-center">
- <DialogTrigger
- render={
- <button
- type="button"
- className="rounded-2xl bg-background p-2 shadow-sm border border-border hover:border-primary/40 transition-colors cursor-pointer"
- />
- }
- >
- <AvatarRenderer config={config} size={80} />
- </DialogTrigger>
+ <div className="flex flex-col items-center gap-3">
+ <div className="rounded-2xl bg-background p-2 shadow-sm border border-border">
+ <span className="block size-20 overflow-hidden rounded-2xl">
+ <BoringAvatar seed={seed} size={80} className="size-full" />
+ </span>
</div>
-
- <DialogContent className={
- isMobile
- ? "top-auto left-0 translate-x-0 translate-y-0 bottom-0 max-w-full sm:max-w-full w-full rounded-b-none rounded-t-xl max-h-[85dvh] overflow-y-auto pb-[env(safe-area-inset-bottom)]"
- : "sm:max-w-180"
- }>
- <DialogHeader>
- <DialogTitle>Choose Avatar</DialogTitle>
- </DialogHeader>
- <AvatarGenerator
- config={draft}
- layout={isMobile ? "vertical" : "horizontal"}
- onChange={(next) => {
- setDraft(next);
- onChange(next);
- }}
- mobile={isMobile}
- />
- {isMobile && (
- <button
- type="button"
- onClick={() => setOpen(false)}
- className="w-full rounded-xl bg-primary py-3 text-sm font-medium text-primary-foreground hover:bg-primary/90 transition-colors"
- >
- Done
- </button>
- )}
- </DialogContent>
- </Dialog>
+ <button
+ type="button"
+ onClick={shuffle}
+ className="inline-flex items-center gap-1.5 rounded-lg border border-border bg-background px-3 py-1.5 text-sm font-medium hover:bg-accent transition-colors cursor-pointer"
+ >
+ <Shuffle className="size-3.5" />
+ Shuffle
+ </button>
+ </div>
);
}
diff --git a/src/web/src/components/avatar/boring-avatar.tsx b/src/web/src/components/avatar/boring-avatar.tsx
new file mode 100644
index 000000000..2c6e29b83
--- /dev/null
+++ b/src/web/src/components/avatar/boring-avatar.tsx
@@ -0,0 +1,41 @@
+"use client";
+
+import Avatar from "boring-avatars";
+import { paletteFromSeed } from "@/lib/avatar/boring-palettes";
+
+/**
+ * The single wrapper around boring-avatars. Every generated avatar/gradient in
+ * the app renders through here so the library stays isolated behind one
+ * component. `seed` maps to boring-avatars' `name` prop (deterministic), and
+ * the palette is chosen deterministically from the same seed.
+ *
+ * `beam` (default) is the face fallback; `marble` is the gradient background
+ * used for server/channel icons and the profile banner.
+ */
+export function BoringAvatar({
+ seed,
+ size = 40,
+ variant = "beam",
+ square = false,
+ className,
+ preserveAspectRatio,
+}: {
+ seed: string;
+ size?: number | string;
+ variant?: "beam" | "marble";
+ square?: boolean;
+ className?: string;
+ preserveAspectRatio?: string;
+}) {
+ return (
+ <Avatar
+ size={size}
+ name={seed}
+ variant={variant}
+ colors={paletteFromSeed(seed)}
+ square={square}
+ className={className}
+ preserveAspectRatio={preserveAspectRatio}
+ />
+ );
+}
diff --git a/src/web/src/components/avatar/bot-avatar-picker-dialog.tsx b/src/web/src/components/avatar/bot-avatar-picker-dialog.tsx
index 390abb327..fab8ce347 100644
--- a/src/web/src/components/avatar/bot-avatar-picker-dialog.tsx
+++ b/src/web/src/components/avatar/bot-avatar-picker-dialog.tsx
@@ -1,7 +1,7 @@
"use client";
import { useEffect, useRef, useState } from "react";
-import { Camera } from "lucide-react";
+import { Camera, Shuffle } from "lucide-react";
import {
Dialog,
DialogTrigger,
@@ -14,15 +14,9 @@ import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs";
import { ImageCropDialog } from "@/components/community/image-crop-dialog";
import { validateIconSourceFile } from "@/lib/community/image-crop";
import { toast } from "sonner";
-import {
- type AvatarConfig,
- type AvatarDraft,
- AvatarRenderer,
- DEFAULT_CONFIG,
- parseAvatarUrl,
- serializeAvatarConfig,
-} from "./avatar-parts";
-import { AvatarGenerator } from "./avatar-generator";
+import { type AvatarDraft, isPhotoAvatarUrl } from "./photo";
+import { BoringAvatar } from "./boring-avatar";
+import { serializeBeamSeed, parseBeamSeed } from "@/lib/avatar/seed-url";
import { useIsMobile } from "@/hooks/use-mobile";
interface BotAvatarPickerDialogProps {
@@ -32,11 +26,15 @@ interface BotAvatarPickerDialogProps {
type PhotoDraft = { file: File | null; previewUrl: string };
+function randomSeed(): string {
+ return crypto.randomUUID();
+}
+
/**
- * Dual-mode ("Generate" | "Photo") bot avatar picker. A NEW component —
- * `AvatarPickerDialog` itself is untouched; it's also used by the unrelated
- * workspace-agent feature (`agent-create-form.tsx` / `agent-edit-form.tsx`)
- * on the procedural-only `{ config, onChange }` contract.
+ * Dual-mode ("Generate" | "Photo") bot avatar picker. "Generate" is a beam
+ * avatar with a shuffle button (boring-avatars has no editable model); the
+ * chosen seed persists as `avatar:beam:{seed}`. `AvatarPickerDialog` (the
+ * workspace-agent picker) is the single-mode variant.
*/
export function BotAvatarPickerDialog({ image, onChange }: BotAvatarPickerDialogProps) {
const [open, setOpen] = useState(false);
@@ -44,37 +42,25 @@ export function BotAvatarPickerDialog({ image, onChange }: BotAvatarPickerDialog
const fileInputRef = useRef<HTMLInputElement>(null);
const [pendingCropSrc, setPendingCropSrc] = useState<{ src: string; fileName: string } | null>(null);
- // `image` can be a persisted URL (http/https/leading-`/`), or — echoed back
- // from this session's own `onChange({ kind: "photo", previewUrl })` — a
- // `blob:` object URL, which `isPhotoAvatarUrl` deliberately doesn't
- // recognize (it's not a value the DB ever stores). Anything that isn't the
- // `avatar:` procedural prefix is a photo here, blob URL included.
- const isPhoto = (url: string | null) => !!url && parseAvatarUrl(url) === null;
+ // A photo is anything that's a real URL (http/https/leading-`/`) or a
+ // session-local `blob:` preview — NOT a `avatar:beam:{seed}` value, which is
+ // the procedural (generated) case.
+ const isPhoto = (url: string | null) => !!url && !parseBeamSeed(url) && (isPhotoAvatarUrl(url) || url.startsWith("blob:"));
const [tab, setTab] = useState<"generate" | "photo">(isPhoto(image) ? "photo" : "generate");
- const [draftConfig, setDraftConfig] = useState<AvatarConfig>(
- () => parseAvatarUrl(image) ?? DEFAULT_CONFIG,
- );
+ const [seed, setSeed] = useState<string>(() => parseBeamSeed(image) ?? randomSeed());
const [photoDraft, setPhotoDraft] = useState<PhotoDraft | null>(
() => (isPhoto(image) ? { file: null, previewUrl: image! } : null),
);
- // Tracks which draft last won — the active tab decides which one wins on
- // Save, not which one was most recently edited (plan: "whichever tab
- // you're on when you hit Create/Save wins").
const [activeKind, setActiveKind] = useState<"procedural" | "photo">(
isPhoto(image) ? "photo" : "procedural",
);
- // Keeps the trigger-button preview (the "identity anchor") honest when
- // `image` changes from *outside* this component — e.g. the parent
- // randomizing the draft on dialog mount — without waiting for the user to
- // open the inner popup first (that resync only happened in `onOpenChange`
- // below). Idempotent against this component's own `onChange` echoes: the
- // parent hands back exactly the string this component just emitted, so
- // re-parsing it here reproduces the same state.
+ // Keep the trigger preview honest when `image` changes from outside this
+ // component. Idempotent against this component's own `onChange` echoes.
useEffect(() => {
const nowPhoto = isPhoto(image);
- setDraftConfig(parseAvatarUrl(image) ?? DEFAULT_CONFIG);
+ setSeed(parseBeamSeed(image) ?? randomSeed());
setPhotoDraft((prev) =>
nowPhoto
? prev && prev.previewUrl === image
@@ -85,13 +71,20 @@ export function BotAvatarPickerDialog({ image, onChange }: BotAvatarPickerDialog
setActiveKind(nowPhoto ? "photo" : "procedural");
}, [image]);
- const emitForTab = (nextTab: "generate" | "photo", config: AvatarConfig, photo: PhotoDraft | null) => {
+ const shuffle = () => {
+ const next = randomSeed();
+ setSeed(next);
+ setActiveKind("procedural");
+ onChange({ kind: "procedural", image: serializeBeamSeed(next) });
+ };
+
+ const emitForTab = (nextTab: "generate" | "photo", currentSeed: string, photo: PhotoDraft | null) => {
if (nextTab === "photo" && photo) {
setActiveKind("photo");
onChange({ kind: "photo", file: photo.file, previewUrl: photo.previewUrl });
} else {
setActiveKind("procedural");
- onChange({ kind: "procedural", image: serializeAvatarConfig(config) });
+ onChange({ kind: "procedural", image: serializeBeamSeed(currentSeed) });
}
};
@@ -117,14 +110,8 @@ export function BotAvatarPickerDialog({ image, onChange }: BotAvatarPickerDialog
onOpenChange={(nextOpen) => {
if (nextOpen) {
const nowPhoto = isPhoto(image);
- const config = parseAvatarUrl(image) ?? DEFAULT_CONFIG;
- setDraftConfig(config);
+ setSeed(parseBeamSeed(image) ?? randomSeed());
if (nowPhoto) {
- // Reopening with the *same* previewUrl this instance already
- // holds (the round-trip through the parent's `avatarDraft`)
- // must not clobber a real `File` back to `null` — only reset
- // when `image` genuinely changed (e.g. first open on an
- // existing persisted photo, or a different URL entirely).
setPhotoDraft((prev) =>
prev && prev.previewUrl === image ? prev : { file: null, previewUrl: image! },
);
@@ -149,7 +136,9 @@ export function BotAvatarPickerDialog({ image, onChange }: BotAvatarPickerDialog
{triggerPreview ? (
<img src={triggerPreview} alt="" className="size-20 rounded-2xl object-cover" />
) : (
- <AvatarRenderer config={draftConfig} size={80} />
+ <span className="block size-20 overflow-hidden rounded-2xl">
+ <BoringAvatar seed={seed} size={80} className="size-full" />
+ </span>
)}
</DialogTrigger>
</div>
@@ -157,7 +146,7 @@ export function BotAvatarPickerDialog({ image, onChange }: BotAvatarPickerDialog
<DialogContent className={
isMobile
? "top-auto left-0 translate-x-0 translate-y-0 bottom-0 max-w-full sm:max-w-full w-full rounded-b-none rounded-t-xl max-h-[85dvh] overflow-y-auto thin-scrollbar pb-[env(safe-area-inset-bottom)]"
- : "sm:max-w-180"
+ : "sm:max-w-120"
}>
<DialogHeader>
<DialogTitle>Choose Avatar</DialogTitle>
@@ -167,7 +156,7 @@ export function BotAvatarPickerDialog({ image, onChange }: BotAvatarPickerDialog
onValueChange={(v) => {
const nextTab = v as "generate" | "photo";
setTab(nextTab);
- emitForTab(nextTab, draftConfig, photoDraft);
+ emitForTab(nextTab, seed, photoDraft);
}}
>
<TabsList className="mx-auto">
@@ -175,16 +164,15 @@ export function BotAvatarPickerDialog({ image, onChange }: BotAvatarPickerDialog
<TabsTrigger value="photo">Photo</TabsTrigger>
</TabsList>
<TabsContent value="generate">
- <AvatarGenerator
- config={draftConfig}
- layout={isMobile ? "vertical" : "horizontal"}
- onChange={(next) => {
- setDraftConfig(next);
- setActiveKind("procedural");
- onChange({ kind: "procedural", image: serializeAvatarConfig(next) });
- }}
- mobile={isMobile}
- />
+ <div className="flex flex-col items-center gap-3 py-6">
+ <span className="block size-32 overflow-hidden rounded-full">
+ <BoringAvatar seed={seed} size={128} className="size-full" />
+ </span>
+ <Button type="button" variant="secondary" size="sm" onClick={shuffle}>
+ <Shuffle className="size-3.5" />
+ Shuffle
+ </Button>
+ </div>
</TabsContent>
<TabsContent value="photo">
<div className="flex flex-col items-center gap-3 py-6">
diff --git a/src/web/src/components/avatar/index.ts b/src/web/src/components/avatar/index.ts
index a2edf432f..bc8435f5f 100644
--- a/src/web/src/components/avatar/index.ts
+++ b/src/web/src/components/avatar/index.ts
@@ -1,15 +1,7 @@
-export {
- type AvatarConfig,
- type AvatarDraft,
- AvatarRenderer,
- DEFAULT_CONFIG,
- serializeAvatarConfig,
- parseAvatarUrl,
- randomConfig,
- configFromName,
- isPhotoAvatarUrl,
-} from "./avatar-parts";
+export { type AvatarDraft, isPhotoAvatarUrl } from "./photo";
+export { BoringAvatar } from "./boring-avatar";
+export { MarbleBackground } from "./marble-background";
export { AnimatedAvatar } from "./animated-avatar";
export { AvatarPickerDialog } from "./avatar-picker-dialog";
export { BotAvatarPickerDialog } from "./bot-avatar-picker-dialog";
diff --git a/src/web/src/components/avatar/marble-background.tsx b/src/web/src/components/avatar/marble-background.tsx
new file mode 100644
index 000000000..a5a0569e3
--- /dev/null
+++ b/src/web/src/components/avatar/marble-background.tsx
@@ -0,0 +1,20 @@
+"use client";
+
+import { BoringAvatar } from "./boring-avatar";
+
+/**
+ * A seeded marble gradient that fills its positioned parent — the SVG
+ * replacement for the old `style={{ background: gradientFromSeed(id) }}`.
+ *
+ * Render it as the first child of a `relative overflow-hidden` container; the
+ * letter/content that used to sit on the CSS gradient stays on top. `object-fit`
+ * doesn't apply to an inline `<svg>`, so we size the SVG to 100% and let the
+ * container clip it.
+ */
+export function MarbleBackground({ seed }: { seed: string }) {
+ return (
+ <span aria-hidden className="pointer-events-none absolute inset-0 [&>svg]:size-full">
+ <BoringAvatar seed={seed} variant="marble" square size="100%" preserveAspectRatio="none" />
+ </span>
+ );
+}
diff --git a/src/web/src/components/avatar/photo.ts b/src/web/src/components/avatar/photo.ts
new file mode 100644
index 000000000..7903c2a6a
--- /dev/null
+++ b/src/web/src/components/avatar/photo.ts
@@ -0,0 +1,13 @@
+// Photo-avatar detection + the dual-mode draft used by the bot picker. These
+// outlived the procedural avatar engine (removed in favor of boring-avatars):
+// a stored avatar value is either a real photo URL or a `avatar:beam:{seed}`.
+
+export function isPhotoAvatarUrl(url: string | null | undefined): boolean {
+ return !!url && (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("/"));
+}
+
+// `file` is null when re-opening an existing photo untouched (edit); a real
+// `File` once freshly cropped this session.
+export type AvatarDraft =
+ | { kind: "procedural"; image: string }
+ | { kind: "photo"; file: File | null; previewUrl: string };
diff --git a/src/web/src/components/canvas/active-tasks-float.tsx b/src/web/src/components/canvas/active-tasks-float.tsx
index 52f7b1fd7..77617d9e5 100644
--- a/src/web/src/components/canvas/active-tasks-float.tsx
+++ b/src/web/src/components/canvas/active-tasks-float.tsx
@@ -6,22 +6,18 @@ import { X } from "lucide-react";
import { useAgentContext } from "@/contexts/agent-context";
import { useWorkspace } from "@/contexts/workspace-context";
import { useIsMobile } from "@/hooks/use-mobile";
-import { AvatarRenderer, parseAvatarUrl } from "@/components/avatar";
+import { BoringAvatar } from "@/components/avatar";
+import { resolveAvatar } from "@/lib/avatar/resolve";
import type { WorkspaceActiveTask } from "@/lib/api";
import { relativeTime } from "@/lib/time";
import { useAgentChatSheet } from "@/contexts/agent-chat-sheet-context";
-function AgentAvatar({ name, avatarUrl, size = 20 }: { name?: string; avatarUrl?: string | null; size?: number }) {
- const config = parseAvatarUrl(avatarUrl);
- if (config) return <AvatarRenderer config={config} size={size} className="rounded-full shrink-0" />;
- return (
- <span
- className="flex items-center justify-center rounded-full bg-secondary text-[7px] font-medium shrink-0"
- style={{ width: size, height: size }}
- >
- {(name ?? "?").charAt(0).toUpperCase()}
- </span>
- );
+function AgentAvatar({ name, avatarUrl, seed, size = 20 }: { name?: string; avatarUrl?: string | null; seed?: string; size?: number }) {
+ const resolved = resolveAvatar(avatarUrl, seed || name || "?");
+ if (resolved.kind === "photo") {
+ return <img src={resolved.url} alt={name ?? ""} className="rounded-full shrink-0 object-cover" style={{ width: size, height: size }} />;
+ }
+ return <BoringAvatar seed={resolved.seed} size={size} className="rounded-full shrink-0" />;
}
function TaskRow({
@@ -52,7 +48,7 @@ function TaskRow({
className="flex items-center gap-2 px-3 py-2 hover:bg-accent/50 transition-colors cursor-pointer rounded-md"
>
<div className="relative shrink-0">
- <AgentAvatar name={task.agent?.name} avatarUrl={task.agent?.avatarUrl} size={24} />
+ <AgentAvatar name={task.agent?.name} avatarUrl={task.agent?.avatarUrl} seed={task.agent_id} size={24} />
<span
className={`absolute -bottom-1 -right-1 size-2 rounded-full ring-2 ring-background ${
isRunning ? "bg-primary animate-pulse" : "bg-muted-foreground/40"
diff --git a/src/web/src/components/canvas/agent-chat-sheet.tsx b/src/web/src/components/canvas/agent-chat-sheet.tsx
index 3385c2f3a..2ae9ea082 100644
--- a/src/web/src/components/canvas/agent-chat-sheet.tsx
+++ b/src/web/src/components/canvas/agent-chat-sheet.tsx
@@ -12,7 +12,7 @@ import {
} from "@/components/ui/sheet";
import { toAlookAddress } from "@alook/shared";
import type { Agent } from "@alook/shared";
-import { AnimatedAvatar, parseAvatarUrl } from "@/components/avatar";
+import { AnimatedAvatar } from "@/components/avatar";
import { useAgentContext } from "@/contexts/agent-context";
import { useWorkspace } from "@/contexts/workspace-context";
import { ChannelBar } from "@/components/channel-bar";
@@ -102,13 +102,10 @@ export function AgentChatSheet({ open, onOpenChange, agentId, agent, targetConvI
<SheetHeader>
<div className="flex items-center gap-3 pr-16">
{agent && (() => {
- const avatarConfig = parseAvatarUrl(agent.avatar_url);
const rt = runtimes.find((r) => r.id === agent.runtime_id);
const isOnline = rt?.status === "online";
const isWorking = !!isOnline && (activeTaskCounts[agent.id] ?? 0) > 0;
- return avatarConfig ? (
- <AnimatedAvatar config={avatarConfig} size={28} className="shrink-0 rounded-lg" isHovered={false} isWorking={isWorking} />
- ) : null;
+ return <AnimatedAvatar seed={agent.id} avatarUrl={agent.avatar_url} size={28} className="shrink-0 rounded-lg" isHovered={false} isWorking={isWorking} />;
})()}
<div className="flex items-baseline gap-2 min-w-0">
<SheetTitle className="truncate shrink-0">
diff --git a/src/web/src/components/canvas/link-sidecar.tsx b/src/web/src/components/canvas/link-sidecar.tsx
index 335480455..b2285b9fe 100644
--- a/src/web/src/components/canvas/link-sidecar.tsx
+++ b/src/web/src/components/canvas/link-sidecar.tsx
@@ -12,7 +12,8 @@ import { Button } from "@/components/ui/button";
import { MarkdownEditor } from "@/components/ui/markdown-editor";
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip";
import { Trash2 } from "lucide-react";
-import { AvatarRenderer, parseAvatarUrl } from "@/components/avatar";
+import { BoringAvatar } from "@/components/avatar";
+import { resolveAvatar } from "@/lib/avatar/resolve";
import { ConfirmDialog } from "@/components/ui/confirm-dialog";
const DEBOUNCE_MS = 500;
@@ -105,15 +106,11 @@ export function LinkSidecar({
const renderAvatar = (agent: Agent | undefined) => {
if (!agent) return null;
- const avatarConfig = parseAvatarUrl(agent.avatar_url);
- if (avatarConfig) {
- return <AvatarRenderer config={avatarConfig} size={32} className="shrink-0 rounded-xl" />;
+ const resolved = resolveAvatar(agent.avatar_url, agent.id || agent.name || "?");
+ if (resolved.kind === "photo") {
+ return <img src={resolved.url} alt={agent.name} className="shrink-0 rounded-xl object-cover" style={{ width: 32, height: 32 }} />;
}
- return (
- <div className="flex items-center justify-center size-8 rounded-xl bg-secondary text-secondary-foreground text-xs font-medium shrink-0">
- {agent.name.charAt(0).toUpperCase()}
- </div>
- );
+ return <BoringAvatar seed={resolved.seed} size={32} className="shrink-0 rounded-xl" />;
};
return (
diff --git a/src/web/src/components/canvas/upcoming-events-float.tsx b/src/web/src/components/canvas/upcoming-events-float.tsx
index 459f88c56..b027bf088 100644
--- a/src/web/src/components/canvas/upcoming-events-float.tsx
+++ b/src/web/src/components/canvas/upcoming-events-float.tsx
@@ -6,21 +6,17 @@ import { CalendarDays, X } from "lucide-react";
import { useAgentContext } from "@/contexts/agent-context";
import { useWorkspace } from "@/contexts/workspace-context";
import { useIsMobile } from "@/hooks/use-mobile";
-import { AvatarRenderer, parseAvatarUrl } from "@/components/avatar";
+import { BoringAvatar } from "@/components/avatar";
+import { resolveAvatar } from "@/lib/avatar/resolve";
import { listCalendarEvents } from "@/lib/api";
import type { CalendarEvent } from "@alook/shared";
-function AgentAvatar({ name, avatarUrl, size = 20 }: { name?: string; avatarUrl?: string | null; size?: number }) {
- const config = parseAvatarUrl(avatarUrl);
- if (config) return <AvatarRenderer config={config} size={size} className="rounded-full shrink-0" />;
- return (
- <span
- className="flex items-center justify-center rounded-full bg-secondary text-[7px] font-medium shrink-0"
- style={{ width: size, height: size }}
- >
- {(name ?? "?").charAt(0).toUpperCase()}
- </span>
- );
+function AgentAvatar({ name, avatarUrl, seed, size = 20 }: { name?: string; avatarUrl?: string | null; seed?: string; size?: number }) {
+ const resolved = resolveAvatar(avatarUrl, seed || name || "?");
+ if (resolved.kind === "photo") {
+ return <img src={resolved.url} alt={name ?? ""} className="rounded-full shrink-0 object-cover" style={{ width: size, height: size }} />;
+ }
+ return <BoringAvatar seed={resolved.seed} size={size} className="rounded-full shrink-0" />;
}
interface AgentEventSummary {
@@ -124,7 +120,7 @@ export function UpcomingEventsFloat() {
href={`/w/${slug}/calendar`}
className="flex items-center gap-2 px-3 py-2 hover:bg-accent/50 transition-colors cursor-pointer rounded-md"
>
- <AgentAvatar name={summary.agentName} avatarUrl={summary.avatarUrl} size={22} />
+ <AgentAvatar name={summary.agentName} avatarUrl={summary.avatarUrl} seed={summary.agentId} size={22} />
<span className="flex-1 text-sm truncate">{summary.agentName}</span>
<span className="text-xs text-muted-foreground shrink-0">
{summary.count} event{summary.count !== 1 ? "s" : ""}
diff --git a/src/web/src/components/community/avatar.test.ts b/src/web/src/components/community/avatar.test.ts
index bd3019cb1..cff793974 100644
--- a/src/web/src/components/community/avatar.test.ts
+++ b/src/web/src/components/community/avatar.test.ts
@@ -2,13 +2,14 @@ import { describe, it, expect } from "vitest"
import { createElement } from "react"
import { renderToStaticMarkup } from "react-dom/server"
import { Avatar } from "./avatar"
+import { serializeBeamSeed } from "@/lib/avatar/seed-url"
// React's `useId` embeds a per-render counter (`_R_1_`, `_R_2_`, …) into the
-// SVG gradient/filter ids, so two independent renders never match byte-for-byte
-// even when the derived shape is identical. Strip those so equality checks
+// SVG mask/gradient ids, so two independent renders never match byte-for-byte
+// even when the derived avatar is identical. Strip those so equality checks
// compare the derived avatar, not the render ordinal.
function normalize(html: string): string {
- return html.replace(/_R_[0-9a-z]+_/g, "_ID_")
+ return html.replace(/_R_[0-9a-z]+_/g, "_ID_").replace(/\bmarble_[0-9a-z]+\b/g, "id").replace(/#[0-9a-z]+_ID_/g, "#_ID_")
}
function render(props: Parameters<typeof Avatar>[0]): string {
@@ -16,23 +17,29 @@ function render(props: Parameters<typeof Avatar>[0]): string {
}
describe("Avatar seed contract", () => {
- it("derives a shape avatar from the seed", () => {
+ it("renders a beam svg from the seed", () => {
const html = render({ label: "Ada", seed: "usr_1" })
- expect(html).toContain("data-avatar-shape")
+ expect(html).toContain("<svg")
expect(html).not.toContain('data-slot="avatar-fallback"')
})
- it("drops to a single-letter fallback when no seed is given, never synthesising a shape", () => {
+ it("drops to a single-letter fallback when no seed is given, never synthesising a beam", () => {
const html = render({ label: "Ada" })
expect(html).toContain('data-slot="avatar-fallback"')
expect(html).toContain(">A<")
- expect(html).not.toContain("data-avatar-shape")
+ expect(html).not.toContain("<svg")
})
it("treats an empty-string seed the same as no seed (letter fallback)", () => {
const html = render({ label: "Ada", seed: "" })
expect(html).toContain('data-slot="avatar-fallback"')
- expect(html).not.toContain("data-avatar-shape")
+ expect(html).not.toContain("<svg")
+ })
+
+ it("honors an explicit avatar:beam seed in the label", () => {
+ const html = render({ label: serializeBeamSeed("beam-xyz") })
+ expect(html).toContain("<svg")
+ expect(html).not.toContain('data-slot="avatar-fallback"')
})
it("is stable for the same seed", () => {
@@ -41,13 +48,13 @@ describe("Avatar seed contract", () => {
)
})
- it("keeps the same shape when the display name changes but the seed is stable", () => {
+ it("keeps the same avatar when the display name changes but the seed is stable", () => {
const before = normalize(render({ label: "Ada", seed: "usr_1" }))
const afterRename = normalize(render({ label: "Adelaide", seed: "usr_1" }))
expect(afterRename).toBe(before)
})
- it("produces different shapes for different seeds", () => {
+ it("produces different avatars for different seeds", () => {
const a = normalize(render({ label: "Ada", seed: "usr_1" }))
const b = normalize(render({ label: "Ada", seed: "usr_2" }))
expect(a).not.toBe(b)
diff --git a/src/web/src/components/community/avatar.tsx b/src/web/src/components/community/avatar.tsx
index 36fda3651..3b6cce0c3 100644
--- a/src/web/src/components/community/avatar.tsx
+++ b/src/web/src/components/community/avatar.tsx
@@ -1,6 +1,7 @@
import type React from "react"
import { Avatar as UiAvatar, AvatarImage, AvatarFallback, AvatarBadge } from "@/components/ui/avatar"
-import { AvatarRenderer, parseAvatarUrl, configFromName } from "@/components/avatar"
+import { BoringAvatar } from "@/components/avatar"
+import { parseBeamSeed } from "@/lib/avatar/seed-url"
import { avatarInitial } from "@/lib/community/avatar"
import type { Presence } from "./_types"
@@ -38,19 +39,21 @@ export function Avatar({ label, seed, src, size = 40, dim = false, presence, rin
ringColor?: string
}) {
const safeLabel = label || "?"
- const avatarConfig = parseAvatarUrl(safeLabel)
const imageUrl = src || (isUrl(safeLabel) ? safeLabel : undefined)
- const fallbackConfig = !imageUrl && !avatarConfig && seed ? configFromName(seed) : null
- const hasGenerated = !!avatarConfig || !!fallbackConfig
+ // Beam seed: an explicit `avatar:beam:{seed}` stored in `label` wins;
+ // otherwise the stable `seed` id. Legacy `avatar:{shape…}` configs are not
+ // honored — they resolve to null here and fall through to the id seed. When
+ // there's neither, we drop to a plain letter (a beam is never derived from a
+ // display name).
+ const beamSeed = !imageUrl ? (parseBeamSeed(safeLabel) ?? seed) : undefined
- // Priority: image URL > explicit avatar-config (avatar:{...}) > name-derived
- // fallback config > single letter. Radix `AvatarFallback` renders whenever
- // no `AvatarImage` is present, so we must NOT emit it when we've already
- // drawn a shape avatar via `<span><AvatarRenderer/></span>` — otherwise both
- // stack on top of each other (see the "two-avatar-in-one-place" bug).
+ // Priority: image URL > beam (from stored seed or id) > single letter. Radix
+ // `AvatarFallback` renders whenever no `AvatarImage` is present, so we must
+ // NOT emit it when we've already drawn a beam via `<span><BoringAvatar/></span>`
+ // — otherwise both stack on top of each other (the "two-avatar-in-one-place" bug).
return (
<UiAvatar
- className={hasGenerated && !imageUrl ? "after:hidden" : "bg-muted"}
+ className={beamSeed ? "after:hidden" : "bg-muted"}
style={{ width: size, height: size, opacity: dim ? 0.4 : 1 }}
>
{imageUrl ? (
@@ -60,18 +63,9 @@ export function Avatar({ label, seed, src, size = 40, dim = false, presence, rin
{avatarInitial(safeLabel)}
</AvatarFallback>
</>
- ) : avatarConfig ? (
- // Shape avatar from the picker's serialized `avatar:{...}` config.
+ ) : beamSeed ? (
<span className="size-full rounded-full overflow-hidden">
- <AvatarRenderer config={avatarConfig} size={size} className="size-full" />
- </span>
- ) : fallbackConfig ? (
- // No image, no picker config — synthesize a shape avatar from the
- // stable `seed` id (matches the design system's shape-avatar
- // aesthetic). Without a seed we skip this and render the plain letter
- // below, so a shape avatar is never derived from a display name.
- <span className="size-full rounded-full overflow-hidden">
- <AvatarRenderer config={fallbackConfig} size={size} className="size-full" />
+ <BoringAvatar seed={beamSeed} size={size} className="size-full" />
</span>
) : (
<AvatarFallback className="font-medium" style={{ fontSize: size * 0.4 }}>
diff --git a/src/web/src/components/community/bots/create-bot-sheet.tsx b/src/web/src/components/community/bots/create-bot-sheet.tsx
index 915f88da7..680abfd3a 100644
--- a/src/web/src/components/community/bots/create-bot-sheet.tsx
+++ b/src/web/src/components/community/bots/create-bot-sheet.tsx
@@ -15,12 +15,8 @@ import {
} from "@/components/ui/sheet"
import { Button } from "@/components/ui/button"
import { Label } from "@/components/ui/label"
-import {
- type AvatarConfig,
- type AvatarDraft,
- randomConfig,
- serializeAvatarConfig,
-} from "@/components/avatar"
+import { type AvatarDraft } from "@/components/avatar"
+import { serializeBeamSeed } from "@/lib/avatar/seed-url"
import { ProviderLogo } from "@/components/provider-logo"
import { useMachines } from "@/hooks/community/use-machines"
import { useCreateBot, useUploadBotAvatar } from "@/hooks/community/use-bots"
@@ -33,13 +29,8 @@ import {
import { uniqueNamesGenerator, names } from "unique-names-generator"
import { cn } from "@/lib/utils"
-// Stable initial config avoids hydration mismatch (randomConfig uses Math.random).
-const INITIAL_AVATAR: AvatarConfig = {
- shape: "circle",
- eye: "dots",
- nose: "dot",
- bg: 0,
-}
+// Stable initial seed avoids hydration mismatch (real seed is rerolled on mount).
+const INITIAL_AVATAR = serializeBeamSeed("initial")
function randomBotName(): string {
return uniqueNamesGenerator({ dictionaries: [names], length: 1, style: "capital" })
@@ -62,7 +53,7 @@ export function CreateBotSheet({
const [fieldErrors, setFieldErrors] = useState<BotCreateFieldErrors>({})
const [avatarDraft, setAvatarDraft] = useState<AvatarDraft>({
kind: "procedural",
- image: serializeAvatarConfig(INITIAL_AVATAR),
+ image: INITIAL_AVATAR,
})
const selectedMachine = machines.find((m) => m.id === machineId)
@@ -94,7 +85,7 @@ export function CreateBotSheet({
if (initializedFor.current) return
initializedFor.current = true
setName(randomBotName())
- setAvatarDraft({ kind: "procedural", image: serializeAvatarConfig(randomConfig()) })
+ setAvatarDraft({ kind: "procedural", image: serializeBeamSeed(crypto.randomUUID()) })
setDescription("")
setMachineId("")
setRuntime("")
diff --git a/src/web/src/components/community/bots/edit-bot-sheet.tsx b/src/web/src/components/community/bots/edit-bot-sheet.tsx
index 9f53f5f67..d7772009b 100644
--- a/src/web/src/components/community/bots/edit-bot-sheet.tsx
+++ b/src/web/src/components/community/bots/edit-bot-sheet.tsx
@@ -14,26 +14,19 @@ import {
} from "@/components/ui/sheet"
import { Button } from "@/components/ui/button"
import {
- type AvatarConfig,
type AvatarDraft,
isPhotoAvatarUrl,
- serializeAvatarConfig,
} from "@/components/avatar"
+import { serializeBeamSeed, parseBeamSeed } from "@/lib/avatar/seed-url"
import { useUpdateBot, useUploadBotAvatar, type BotSummary } from "@/hooks/community/use-bots"
import { BotFormFields } from "./bot-form-fields"
import { uniqueNamesGenerator, names } from "unique-names-generator"
-const DEFAULT_AVATAR: AvatarConfig = {
- shape: "circle",
- eye: "dots",
- nose: "dot",
- bg: 0,
-}
-
function draftFromBot(bot: BotSummary): AvatarDraft {
- return isPhotoAvatarUrl(bot.image)
- ? { kind: "photo", file: null, previewUrl: bot.image! }
- : { kind: "procedural", image: bot.image ?? serializeAvatarConfig(DEFAULT_AVATAR) }
+ if (isPhotoAvatarUrl(bot.image)) return { kind: "photo", file: null, previewUrl: bot.image! }
+ // A stored beam seed persists; a legacy `avatar:{shape…}` config or null
+ // falls back to a beam seeded by the bot id.
+ return { kind: "procedural", image: parseBeamSeed(bot.image) ? bot.image! : serializeBeamSeed(bot.id) }
}
export function EditBotSheet({
@@ -54,7 +47,7 @@ export function EditBotSheet({
const [description, setDescription] = useState(bot?.description ?? "")
const [nameError, setNameError] = useState<string | undefined>(undefined)
const [avatarDraft, setAvatarDraft] = useState<AvatarDraft>(() =>
- bot ? draftFromBot(bot) : { kind: "procedural", image: serializeAvatarConfig(DEFAULT_AVATAR) },
+ bot ? draftFromBot(bot) : { kind: "procedural", image: serializeBeamSeed("initial") },
)
const update = useUpdateBot()
const uploadBotAvatar = useUploadBotAvatar()
diff --git a/src/web/src/components/community/channel-header.tsx b/src/web/src/components/community/channel-header.tsx
index e5970be14..273527404 100644
--- a/src/web/src/components/community/channel-header.tsx
+++ b/src/web/src/components/community/channel-header.tsx
@@ -14,7 +14,7 @@ import { ChannelIcon } from "./channel-icon"
import { EntityIcon } from "./entity-icon"
import { SlugHint } from "./slug-hint"
import { previewSlug } from "@/lib/community/slug-preview"
-import { gradientFromSeed } from "@/lib/community/gradient-from-seed"
+import { MarbleBackground } from "@/components/avatar"
import type { RightPanel } from "./_types"
// Skeleton header for the loading frame between route change and channel
@@ -166,15 +166,14 @@ function ChannelOverflowMenu({
export function ServerCrumb({ id, name, icon, size = 5, className = "" }: { id: string; name: string; icon: string | null; size?: 5 | 7; className?: string }) {
return (
<span
- // No icon → the same deterministic gradient fallback used by the rail
+ // No icon → the same deterministic marble fallback used by the rail
// (`sortable-server.tsx`) and folder rows, so a server reads as "the
// same server" everywhere it shows up, not a flat generic tile here.
- style={icon ? undefined : { background: gradientFromSeed(id) }}
- className={`grid shrink-0 place-items-center overflow-hidden rounded-md font-semibold ${icon ? "bg-secondary text-foreground" : "text-white [text-shadow:0_1px_2px_rgb(0_0_0/0.35)]"} ${size === 7 ? "size-7 text-xs" : "size-5 text-[0.625rem]"} ${className}`}
+ className={`relative grid shrink-0 place-items-center overflow-hidden rounded-md font-semibold ${icon ? "bg-secondary text-foreground" : "text-white [text-shadow:0_1px_2px_rgb(0_0_0/0.35)]"} ${size === 7 ? "size-7 text-xs" : "size-5 text-[0.625rem]"} ${className}`}
aria-label={name}
title={name}
>
- {icon ? <img src={icon} alt="" className="size-full object-cover" /> : avatarInitial(name)}
+ {icon ? <img src={icon} alt="" className="size-full object-cover" /> : <><MarbleBackground seed={id} /><span className="relative">{avatarInitial(name)}</span></>}
</span>
)
}
diff --git a/src/web/src/components/community/profile-card.tsx b/src/web/src/components/community/profile-card.tsx
index 706af5225..506e52eb0 100644
--- a/src/web/src/components/community/profile-card.tsx
+++ b/src/web/src/components/community/profile-card.tsx
@@ -5,11 +5,11 @@ import { MessagesSquare, Shield } from "lucide-react"
import { Popover, PopoverTrigger, PopoverContent } from "@/components/ui/popover"
import { Badge } from "@/components/ui/badge"
import { Avatar } from "./avatar"
+import { MarbleBackground } from "@/components/avatar"
import { StatusEditor, hasStatus } from "./status-editor"
import type { Profile } from "./_types"
import type { Breakpoint } from "@/hooks/use-mobile"
import { useCommunityWsStore } from "@/stores/community/ws"
-import { gradientFromSeed } from "@/lib/community/gradient-from-seed"
import { tid } from "@/lib/community/testids"
// Merge rule for the card's status pill: overlay wins over seed. The overlay
@@ -64,11 +64,13 @@ export function ProfileCard({ data, x, y, bp, onClose, onMessage, isSelf, onUpda
if (mobile) onClose()
else close()
}
- const gradient = gradientFromSeed(data.userId ?? data.name)
const card = (
<>
- {/* banner */}
- <div className="-m-2 mb-0 h-16 rounded-t-lg" style={{ background: gradient }} />
+ {/* banner — seeded marble fill, clipped by the wide-bar container
+ (object-fit doesn't apply to an inline <svg>, so the SVG fills 100%). */}
+ <div className="relative -m-2 mb-0 h-16 overflow-hidden rounded-t-lg">
+ <MarbleBackground seed={data.userId ?? data.name} />
+ </div>
<div className="px-2 pb-2">
{/* `pl-4` — the card body below has its own `p-4`, so its text sits
16px in from this row's container; without matching padding here
diff --git a/src/web/src/components/community/rail-folder.tsx b/src/web/src/components/community/rail-folder.tsx
index 549fa98fe..3775d4aed 100644
--- a/src/web/src/components/community/rail-folder.tsx
+++ b/src/web/src/components/community/rail-folder.tsx
@@ -5,7 +5,7 @@ import { CSS } from "@dnd-kit/utilities"
import { ContextMenu, ContextMenuTrigger, ContextMenuContent, ContextMenuItem } from "@/components/ui/context-menu"
import { RailIndicator } from "./rail-indicator"
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip"
-import { gradientFromSeed } from "@/lib/community/gradient-from-seed"
+import { MarbleBackground } from "@/components/avatar"
import type { FolderServer } from "./_types"
export function RailFolder({
@@ -48,13 +48,12 @@ export function RailFolder({
return s ? (
<span
key={s.id}
- style={s.icon ? undefined : { background: gradientFromSeed(s.id) }}
className={[
- "grid aspect-square place-items-center overflow-hidden rounded-sm text-[7px] font-semibold",
+ "relative grid aspect-square place-items-center overflow-hidden rounded-sm text-[7px] font-semibold",
s.icon ? "bg-card text-muted-foreground" : "text-white [text-shadow:0_1px_1px_rgb(0_0_0/0.35)]",
].join(" ")}
>
- {s.icon ? <img src={s.icon} alt={s.name} className="size-full object-cover" /> : s.initial}
+ {s.icon ? <img src={s.icon} alt={s.name} className="size-full object-cover" /> : <><MarbleBackground seed={s.id} /><span className="relative">{s.initial}</span></>}
</span>
) : (
<span key={i} className="aspect-square rounded-sm bg-card/50" />
diff --git a/src/web/src/components/community/server-rail.tsx b/src/web/src/components/community/server-rail.tsx
index a2291ff68..0aa703c0d 100644
--- a/src/web/src/components/community/server-rail.tsx
+++ b/src/web/src/components/community/server-rail.tsx
@@ -15,7 +15,7 @@ import { SortableServer } from "./sortable-server"
import { RailFolder } from "./rail-folder"
import { CreateServerDialog } from "./create-server-dialog"
import { useRailOrder, isFolderKey, extractFolderId } from "./use-rail-order"
-import { gradientFromSeed } from "@/lib/community/gradient-from-seed"
+import { MarbleBackground } from "@/components/avatar"
import type { Server, CommunityFolder, MobileZone, View } from "./_types"
export const ServerRail = memo(function ServerRail({
@@ -221,13 +221,12 @@ export const ServerRail = memo(function ServerRail({
return s ? (
<span
key={s.id}
- style={s.icon ? undefined : { background: gradientFromSeed(s.id) }}
className={[
- "grid aspect-square place-items-center overflow-hidden rounded-sm text-[7px] font-semibold",
+ "relative grid aspect-square place-items-center overflow-hidden rounded-sm text-[7px] font-semibold",
s.icon ? "bg-card text-muted-foreground" : "text-white [text-shadow:0_1px_1px_rgb(0_0_0/0.35)]",
].join(" ")}
>
- {s.icon ? <img src={s.icon} alt={s.name} className="size-full object-cover" /> : s.initial}
+ {s.icon ? <img src={s.icon} alt={s.name} className="size-full object-cover" /> : <><MarbleBackground seed={s.id} /><span className="relative">{s.initial}</span></>}
</span>
) : (
<span key={idx} className="aspect-square rounded-sm bg-card/50" />
@@ -241,13 +240,12 @@ export const ServerRail = memo(function ServerRail({
const icon = s.icon
return (
<div
- style={icon ? undefined : { background: gradientFromSeed(s.id) }}
className={[
- "grid size-10 place-items-center overflow-hidden rounded-xl text-sm font-semibold shadow-(--e2)",
+ "relative grid size-10 place-items-center overflow-hidden rounded-xl text-sm font-semibold shadow-(--e2)",
icon ? "bg-secondary text-foreground" : "text-white [text-shadow:0_1px_2px_rgb(0_0_0/0.35)]",
].join(" ")}
>
- {icon ? <img src={icon} alt={s.name} className="size-full object-cover" /> : s.initial}
+ {icon ? <img src={icon} alt={s.name} className="size-full object-cover" /> : <><MarbleBackground seed={s.id} /><span className="relative">{s.initial}</span></>}
</div>
)
})()}
diff --git a/src/web/src/components/community/sortable-server.tsx b/src/web/src/components/community/sortable-server.tsx
index 4dc8a70a6..90dae9ed0 100644
--- a/src/web/src/components/community/sortable-server.tsx
+++ b/src/web/src/components/community/sortable-server.tsx
@@ -8,7 +8,7 @@ import { RailIndicator } from "./rail-indicator"
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip"
import { ConfirmDialog } from "@/components/ui/confirm-dialog"
import { NumberTicker } from "@/components/ui/number-ticker"
-import { gradientFromSeed } from "@/lib/community/gradient-from-seed"
+import { MarbleBackground } from "@/components/avatar"
import { tid } from "@/lib/community/testids"
import type { Server } from "./_types"
@@ -35,9 +35,8 @@ export function SortableServer({ server, active, onClick, onLeave, onOpenSetting
onClick={active ? undefined : onClick}
{...attributes}
{...listeners}
- style={server.icon ? undefined : { background: gradientFromSeed(server.id) }}
className={[
- "grid size-10 touch-none place-items-center overflow-hidden text-sm font-semibold transition-all duration-150 active:cursor-grabbing",
+ "relative grid size-10 touch-none place-items-center overflow-hidden text-sm font-semibold transition-all duration-150 active:cursor-grabbing",
active ? "cursor-default rounded-xl" : "cursor-pointer rounded-[18px] hover:rounded-xl",
server.icon
? active ? "bg-primary text-primary-foreground" : "bg-card hover:bg-primary hover:text-primary-foreground"
@@ -47,7 +46,7 @@ export function SortableServer({ server, active, onClick, onLeave, onOpenSetting
{server.icon ? (
<img src={server.icon} alt={server.name} className="size-full object-cover" />
) : (
- server.initial
+ <><MarbleBackground seed={server.id} /><span className="relative">{server.initial}</span></>
)}
</button>
{server.mentions > 0 && (
diff --git a/src/web/src/components/home/architecture-overview.tsx b/src/web/src/components/home/architecture-overview.tsx
index 3c55b9571..1e7b41f47 100644
--- a/src/web/src/components/home/architecture-overview.tsx
+++ b/src/web/src/components/home/architecture-overview.tsx
@@ -13,8 +13,8 @@ import { useScriptedTimeline, type TimelineStep } from "./demo-pad/use-scripted-
gsap.registerPlugin(ScrollTrigger);
const ARCH_AGENTS: AgentInfo[] = [
- { name: "Planner", email: "[email protected]", config: { shape: "hexagon", eye: "dots", nose: "dash", bg: 5 } },
- { name: "Coder", email: "[email protected]", config: { shape: "task", eye: "happy", nose: "dot", bg: 0 } },
+ { name: "Planner", email: "[email protected]", seed: "demo-planner" },
+ { name: "Coder", email: "[email protected]", seed: "demo-coder" },
];
const ARCH_CONFIG: DashboardConfig = { agents: ARCH_AGENTS };
diff --git a/src/web/src/components/home/demo-pad/demo-dashboard.tsx b/src/web/src/components/home/demo-pad/demo-dashboard.tsx
index 17a5f6302..a67d21d02 100644
--- a/src/web/src/components/home/demo-pad/demo-dashboard.tsx
+++ b/src/web/src/components/home/demo-pad/demo-dashboard.tsx
@@ -6,14 +6,14 @@ import { MessageCluster } from "@/components/chat-primitives/message-cluster";
import { PresenceLine } from "@/components/agent-chat/presence-line";
import { EmailCard } from "@/components/agent-chat/event-cards/email-card";
import { AnimatedAvatar } from "@/components/avatar/animated-avatar";
-import { AvatarRenderer, type AvatarConfig } from "@/components/avatar/avatar-parts";
+import { BoringAvatar } from "@/components/avatar/boring-avatar";
import { Logo } from "@/components/logo";
import { cn } from "@/lib/utils";
export interface AgentInfo {
name: string;
email: string;
- config: AvatarConfig;
+ seed: string;
}
export interface DashboardStep {
@@ -69,7 +69,7 @@ export function DemoDashboard({ state, config, className }: { state: DashboardSt
: "ring-transparent hover:ring-border/60",
)}
>
- <AvatarRenderer config={a.config} size={32} />
+ <BoringAvatar seed={a.seed} size={32} />
</div>
);
})}
@@ -121,7 +121,7 @@ export function DemoDashboard({ state, config, className }: { state: DashboardSt
<MessageCluster
avatar={
<div className="size-6.5 rounded-lg overflow-hidden">
- <AnimatedAvatar config={agent.config} size={26} isHovered={false} isWorking={state.isWorking} />
+ <AnimatedAvatar seed={agent.seed} size={26} isHovered={false} isWorking={state.isWorking} />
</div>
}
name={agent.name}
@@ -136,7 +136,7 @@ export function DemoDashboard({ state, config, className }: { state: DashboardSt
<MessageCluster
avatar={
<div className="size-6.5 rounded-lg overflow-hidden">
- <AnimatedAvatar config={agent.config} size={26} isHovered={false} isWorking={false} />
+ <AnimatedAvatar seed={agent.seed} size={26} isHovered={false} isWorking={false} />
</div>
}
name={agent.name}
@@ -164,7 +164,7 @@ export function DemoDashboard({ state, config, className }: { state: DashboardSt
<MessageCluster
avatar={
<div className="size-6.5 rounded-lg overflow-hidden">
- <AnimatedAvatar config={agent.config} size={26} isHovered={false} isWorking={state.isWorking} />
+ <AnimatedAvatar seed={agent.seed} size={26} isHovered={false} isWorking={state.isWorking} />
</div>
}
name={agent.name}
diff --git a/src/web/src/components/home/demo-pad/demo-mobile.tsx b/src/web/src/components/home/demo-pad/demo-mobile.tsx
index b268fd88e..d22c7cd03 100644
--- a/src/web/src/components/home/demo-pad/demo-mobile.tsx
+++ b/src/web/src/components/home/demo-pad/demo-mobile.tsx
@@ -3,7 +3,7 @@
import { ArrowUp, Home, CalendarDays, CircleDot } from "lucide-react";
import { MessageBubble } from "@/components/chat-primitives/message-bubble";
import { AnimatedAvatar } from "@/components/avatar/animated-avatar";
-import { AvatarRenderer } from "@/components/avatar/avatar-parts";
+import { BoringAvatar } from "@/components/avatar/boring-avatar";
import { Logo } from "@/components/logo";
import { cn } from "@/lib/utils";
import type { DashboardState, DashboardConfig } from "./demo-dashboard";
@@ -35,7 +35,7 @@ export function DemoMobile({ state, config, className }: { state: DashboardState
isActive && "shadow-[inset_0_0_0_1.5px_hsl(var(--primary))]",
)}
>
- <AvatarRenderer config={a.config} size={16} />
+ <BoringAvatar seed={a.seed} size={16} />
</div>
);
})}
@@ -96,7 +96,7 @@ export function DemoMobile({ state, config, className }: { state: DashboardState
<div className="flex items-start gap-1">
{(groupPosition === "solo" || groupPosition === "first") ? (
<div className="size-4 rounded overflow-hidden shrink-0 mt-1">
- <AnimatedAvatar config={agent.config} size={16} isHovered={false} isWorking={state.isWorking} />
+ <AnimatedAvatar seed={agent.seed} size={16} isHovered={false} isWorking={state.isWorking} />
</div>
) : (
<div className="w-4 shrink-0" />
diff --git a/src/web/src/components/home/demo-pad/use-case-scripts.ts b/src/web/src/components/home/demo-pad/use-case-scripts.ts
index 343073c49..76892d5be 100644
--- a/src/web/src/components/home/demo-pad/use-case-scripts.ts
+++ b/src/web/src/components/home/demo-pad/use-case-scripts.ts
@@ -2,13 +2,13 @@ import type { DashboardStep, AgentInfo } from "./demo-dashboard";
import type { UseCaseScript } from "./use-case-demo";
/* ─── Agent Configs ─── */
-const SALES: AgentInfo = { name: "Sales", email: "[email protected]", config: { shape: "hexagon", eye: "dots", nose: "dash", bg: 5 } };
-const PLANNER: AgentInfo = { name: "Planner", email: "[email protected]", config: { shape: "hexagon", eye: "dots", nose: "dash", bg: 5 } };
-const CODER: AgentInfo = { name: "Coder", email: "[email protected]", config: { shape: "task", eye: "happy", nose: "dot", bg: 0 } };
-const REVIEWER: AgentInfo = { name: "Reviewer", email: "[email protected]", config: { shape: "circle", eye: "arches", nose: "smile", bg: 8 } };
-const MARKETER: AgentInfo = { name: "Marketer", email: "[email protected]", config: { shape: "mail", eye: "dots", nose: "smile", bg: 3 } };
-const OPS: AgentInfo = { name: "Ops", email: "[email protected]", config: { shape: "folder", eye: "lines", nose: "dash", bg: 7 } };
-const ASSISTANT: AgentInfo = { name: "Assistant", email: "[email protected]", config: { shape: "bulb", eye: "rings", nose: "oh", bg: 11 } };
+const SALES: AgentInfo = { name: "Sales", email: "[email protected]", seed: "demo-sales" };
+const PLANNER: AgentInfo = { name: "Planner", email: "[email protected]", seed: "demo-planner" };
+const CODER: AgentInfo = { name: "Coder", email: "[email protected]", seed: "demo-coder" };
+const REVIEWER: AgentInfo = { name: "Reviewer", email: "[email protected]", seed: "demo-reviewer" };
+const MARKETER: AgentInfo = { name: "Marketer", email: "[email protected]", seed: "demo-marketer" };
+const OPS: AgentInfo = { name: "Ops", email: "[email protected]", seed: "demo-ops" };
+const ASSISTANT: AgentInfo = { name: "Assistant", email: "[email protected]", seed: "demo-assistant" };
/* ═══════════════════════════════════════════
1. Lead Auto Follow-up
diff --git a/src/web/src/components/issues/issue-sheet.tsx b/src/web/src/components/issues/issue-sheet.tsx
index ba7ae39a7..f658425ed 100644
--- a/src/web/src/components/issues/issue-sheet.tsx
+++ b/src/web/src/components/issues/issue-sheet.tsx
@@ -43,7 +43,8 @@ import { formatSize } from "@/components/agent-chat/artifact-sheet";
import { isTerminalIssueStatus, toAlookAddress } from "@alook/shared";
import type { TraceTask } from "@/lib/api";
import { updateIssue } from "@/lib/api";
-import { AvatarRenderer, parseAvatarUrl } from "@/components/avatar";
+import { BoringAvatar } from "@/components/avatar";
+import { resolveAvatar } from "@/lib/avatar/resolve";
import { ConfirmDialog } from "@/components/ui/confirm-dialog";
import { Kbd } from "@/components/ui/kbd";
import { AutoResizeTextarea } from "@/components/ui/auto-resize-textarea";
@@ -67,18 +68,11 @@ function statusLabel(status: string) {
// --- Sub-components ---
function AgentAvatar({ agent, size = 24 }: { agent?: Agent | null; size?: number }) {
- const avatarConfig = parseAvatarUrl(agent?.avatar_url);
- if (avatarConfig) {
- return <AvatarRenderer config={avatarConfig} size={size} className="shrink-0 rounded-full" />;
+ const resolved = resolveAvatar(agent?.avatar_url, agent?.id || agent?.name || "?");
+ if (resolved.kind === "photo") {
+ return <img src={resolved.url} alt={agent?.name ?? ""} className="shrink-0 rounded-full object-cover" style={{ width: size, height: size }} />;
}
- return (
- <span
- className="flex shrink-0 items-center justify-center rounded-full border border-border bg-muted text-[11px] font-medium text-muted-foreground"
- style={{ width: size, height: size }}
- >
- {(agent?.name ?? "?").slice(0, 1).toUpperCase()}
- </span>
- );
+ return <BoringAvatar seed={resolved.seed} size={size} className="shrink-0 rounded-full" />;
}
function AgentIdentity({ agent, size = 24 }: { agent: Agent; size?: number }) {
diff --git a/src/web/src/components/mobile-top-bar.tsx b/src/web/src/components/mobile-top-bar.tsx
index 5370dc32b..28ffb9cd5 100644
--- a/src/web/src/components/mobile-top-bar.tsx
+++ b/src/web/src/components/mobile-top-bar.tsx
@@ -5,7 +5,7 @@ import { CalendarDays, CircleDot, Home } from "lucide-react";
import { useSidebarTrigger } from "@/components/workspace-shell";
import { useAgentContext } from "@/contexts/agent-context";
import { useWorkspace } from "@/contexts/workspace-context";
-import { AnimatedAvatar, parseAvatarUrl } from "@/components/avatar";
+import { AnimatedAvatar } from "@/components/avatar";
import { Logo } from "@/components/logo";
import { Skeleton } from "@/components/ui/skeleton";
import { cn } from "@/lib/utils";
@@ -107,7 +107,6 @@ export function MobileTopBar() {
const runtime = runtimes.find((r) => r.id === agent.runtime_id);
const isOnline = runtime?.status === "online";
const isActive = activeAgentId === agent.id;
- const avatarConfig = parseAvatarUrl(agent.avatar_url);
return (
<button
@@ -120,13 +119,7 @@ export function MobileTopBar() {
)}
>
<div className="size-7">
- {avatarConfig ? (
- <AnimatedAvatar config={avatarConfig} size={28} className="rounded-full" isHovered={false} />
- ) : (
- <div className="size-7 rounded-full bg-muted flex items-center justify-center text-[10px] font-medium">
- {agent.name.charAt(0).toUpperCase()}
- </div>
- )}
+ <AnimatedAvatar seed={agent.id} avatarUrl={agent.avatar_url} size={28} className="rounded-full" isHovered={false} />
</div>
<span
className={cn(
diff --git a/src/web/src/components/sidebar/agent-sidebar-button.tsx b/src/web/src/components/sidebar/agent-sidebar-button.tsx
index b65a79fec..2e556930a 100644
--- a/src/web/src/components/sidebar/agent-sidebar-button.tsx
+++ b/src/web/src/components/sidebar/agent-sidebar-button.tsx
@@ -12,7 +12,6 @@ import {
} from "@/components/ui/context-menu";
import { AgentPreviewCard } from "@/components/agent-preview-card";
import { Popover, PopoverTrigger, PopoverContent } from "@/components/ui/popover";
-import { parseAvatarUrl } from "@/components/avatar";
import { AnimatedAvatar } from "@/components/avatar/animated-avatar";
export function AgentSidebarButton({
@@ -70,13 +69,7 @@ export function AgentSidebarButton({
/>
}
>
- {(() => {
- const avatarConfig = parseAvatarUrl(agent.avatar_url);
- if (avatarConfig) {
- return <AnimatedAvatar config={avatarConfig} size={40} className="rounded-xl" isHovered={false} />;
- }
- return agent.name.charAt(0).toUpperCase();
- })()}
+ <AnimatedAvatar seed={agent.id} avatarUrl={agent.avatar_url} size={40} className="rounded-xl" isHovered={false} />
<span className={cn(
"absolute bottom-0 right-0 size-2 rounded-full ring-2 ring-background",
isOnline ? "bg-status-online" : "bg-status-offline"
diff --git a/src/web/src/components/sidebar/folder-collapsed.tsx b/src/web/src/components/sidebar/folder-collapsed.tsx
index 6d5274054..8965435ba 100644
--- a/src/web/src/components/sidebar/folder-collapsed.tsx
+++ b/src/web/src/components/sidebar/folder-collapsed.tsx
@@ -2,7 +2,6 @@
import type { Agent } from "@alook/shared";
import type { AgentFolder } from "@/hooks/use-agent-folders";
-import { parseAvatarUrl } from "@/components/avatar";
import { AnimatedAvatar } from "@/components/avatar/animated-avatar";
import { cn } from "@/lib/utils";
@@ -40,7 +39,6 @@ export function FolderCollapsed({
>
<div className="relative flex items-center justify-center" style={{ width: 30, height: 20 }}>
{displayed.map((agent, i) => {
- const avatarConfig = parseAvatarUrl(agent.avatar_url);
const offset = i * 6;
return (
<div
@@ -53,13 +51,7 @@ export function FolderCollapsed({
zIndex: i + 1,
}}
>
- {avatarConfig ? (
- <AnimatedAvatar config={avatarConfig} size={20} className="rounded-full" isHovered={false} />
- ) : (
- <div className="flex items-center justify-center size-full bg-muted text-[8px] font-medium">
- {agent.name.charAt(0).toUpperCase()}
- </div>
- )}
+ <AnimatedAvatar seed={agent.id} avatarUrl={agent.avatar_url} size={20} className="rounded-full" isHovered={false} />
</div>
);
})}
diff --git a/src/web/src/components/studio-onboarding/scenario-presets.ts b/src/web/src/components/studio-onboarding/scenario-presets.ts
index f7aa57955..f94298cbc 100644
--- a/src/web/src/components/studio-onboarding/scenario-presets.ts
+++ b/src/web/src/components/studio-onboarding/scenario-presets.ts
@@ -205,7 +205,7 @@ export const SCENARIO_PRESETS: ScenarioPreset[] = [
import { uniqueNamesGenerator, names } from "unique-names-generator";
import { nanoid } from "nanoid";
-import { randomConfig, serializeAvatarConfig } from "@/components/avatar";
+import { randomBeamAvatar } from "@/lib/avatar/seed-url";
export function shuffleMembers(count: number): { uid: string; name: string; avatarUrl: string }[] {
const used = new Set<string>();
@@ -221,7 +221,7 @@ export function shuffleMembers(count: number): { uid: string; name: string; avat
result.push({
uid: nanoid(),
name,
- avatarUrl: serializeAvatarConfig(randomConfig()),
+ avatarUrl: randomBeamAvatar(),
});
}
return result;
diff --git a/src/web/src/components/studio-onboarding/team-preview.tsx b/src/web/src/components/studio-onboarding/team-preview.tsx
index ad078cb43..c1c5462c4 100644
--- a/src/web/src/components/studio-onboarding/team-preview.tsx
+++ b/src/web/src/components/studio-onboarding/team-preview.tsx
@@ -4,7 +4,8 @@ import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { RefreshCw } from "lucide-react";
-import { AvatarRenderer, parseAvatarUrl } from "@/components/avatar";
+import { BoringAvatar } from "@/components/avatar";
+import { resolveAvatar } from "@/lib/avatar/resolve";
import {
Select,
SelectTrigger,
@@ -66,17 +67,15 @@ export function TeamPreview({
)}
>
{members.map((m, i) => {
- const avatarConfig = m.avatarUrl ? parseAvatarUrl(m.avatarUrl) : null;
+ const resolved = resolveAvatar(m.avatarUrl, m.name || "?");
return (
<Card key={i} size="sm" className="flex flex-col px-3 py-4 gap-2 h-full">
{/* Header: avatar + name/badge */}
<div className="flex items-center gap-2">
- {avatarConfig ? (
- <AvatarRenderer config={avatarConfig} size={36} className="rounded-xl shrink-0" />
+ {resolved.kind === "photo" ? (
+ <img src={resolved.url} alt={m.name} className="size-9 rounded-xl object-cover shrink-0" />
) : (
- <div className="size-9 rounded-xl bg-muted flex items-center justify-center text-sm font-semibold shrink-0">
- {m.name.charAt(0)}
- </div>
+ <BoringAvatar seed={resolved.seed} size={36} className="rounded-xl shrink-0" />
)}
<div className="flex flex-col items-start gap-1">
<span className="text-sm font-medium">{m.name}</span>
diff --git a/src/web/src/lib/avatar/boring-palettes.test.ts b/src/web/src/lib/avatar/boring-palettes.test.ts
new file mode 100644
index 000000000..61b81b071
--- /dev/null
+++ b/src/web/src/lib/avatar/boring-palettes.test.ts
@@ -0,0 +1,24 @@
+import { describe, it, expect } from "vitest"
+import { PALETTES, paletteFromSeed } from "./boring-palettes"
+
+describe("paletteFromSeed", () => {
+ it("is deterministic for the same seed", () => {
+ expect(paletteFromSeed("usr_1")).toBe(paletteFromSeed("usr_1"))
+ })
+
+ it("returns a palette that is a member of PALETTES (reference equality)", () => {
+ const p = paletteFromSeed("usr_42")
+ expect(PALETTES).toContain(p)
+ })
+
+ it("spreads across more than one palette over many seeds", () => {
+ const seen = new Set(
+ Array.from({ length: 60 }, (_, i) => paletteFromSeed(`seed_${i}`)),
+ )
+ expect(seen.size).toBeGreaterThan(1)
+ })
+
+ it("first palette is the official boringavatars.com sample", () => {
+ expect(PALETTES[0]).toEqual(["#00686c", "#32c2b9", "#edecb3", "#fad928", "#ff9915"])
+ })
+})
diff --git a/src/web/src/lib/avatar/boring-palettes.ts b/src/web/src/lib/avatar/boring-palettes.ts
new file mode 100644
index 000000000..c088a1ae2
--- /dev/null
+++ b/src/web/src/lib/avatar/boring-palettes.ts
@@ -0,0 +1,51 @@
+/**
+ * Color palettes for boring-avatars, chosen deterministically per seed.
+ *
+ * Set 0 is the official boringavatars.com sample palette; the rest are the
+ * opening entries of Matt DesLauriers' Nice Color Palettes (the same source
+ * boringavatars.com's own playground samples from). Colors are used as-is for
+ * this vibe-check phase — DESIGN.md's desaturation rule is a deliberate
+ * follow-up, not applied here.
+ *
+ * Selection reuses the same hash + mulberry32 PRNG as `gradient-from-seed.ts`
+ * so the "looks random, never flickers" behavior matches the rest of the app.
+ */
+
+export const PALETTES: readonly (readonly string[])[] = [
+ ["#00686c", "#32c2b9", "#edecb3", "#fad928", "#ff9915"],
+ ["#69d2e7", "#a7dbd8", "#e0e4cc", "#f38630", "#fa6900"],
+ ["#fe4365", "#fc9d9a", "#f9cdad", "#c8c8a9", "#83af9b"],
+ ["#ecd078", "#d95b43", "#c02942", "#542437", "#53777a"],
+ ["#556270", "#4ecdc4", "#c7f464", "#ff6b6b", "#c44d58"],
+ ["#774f38", "#e08e79", "#f1d4af", "#ece5ce", "#c5e0dc"],
+ ["#e8ddcb", "#cdb380", "#036564", "#033649", "#031634"],
+ ["#490a3d", "#bd1550", "#e97f02", "#f8ca00", "#8a9b0f"],
+ ["#594f4f", "#547980", "#45ada8", "#9de0ad", "#e5fcc2"],
+ ["#00a0b0", "#6a4a3c", "#cc333f", "#eb6841", "#edc951"],
+ ["#e94e77", "#d68189", "#c6a49a", "#c6e5d9", "#f4ead5"],
+ ["#3fb8af", "#7fc7af", "#dad8a7", "#ff9e9d", "#ff3d7f"],
+ ["#00a8c6", "#40c0cb", "#f9f2e7", "#aee239", "#8fbe00"],
+] as const
+
+function hashStr(s: string): number {
+ let h = 0
+ for (let i = 0; i < s.length; i++) h = ((h << 5) - h + s.charCodeAt(i)) | 0
+ return Math.abs(h)
+}
+
+function mulberry32(seed: number): () => number {
+ let a = seed
+ return () => {
+ a = (a + 0x6d2b79f5) | 0
+ let t = Math.imul(a ^ (a >>> 15), 1 | a)
+ t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296
+ }
+}
+
+/** One palette from `PALETTES`, chosen deterministically by `seed`. */
+export function paletteFromSeed(seed: string): string[] {
+ const rand = mulberry32(hashStr(seed))
+ const idx = Math.floor(rand() * PALETTES.length)
+ return PALETTES[idx] as string[]
+}
diff --git a/src/web/src/lib/avatar/resolve.test.ts b/src/web/src/lib/avatar/resolve.test.ts
new file mode 100644
index 000000000..c879daa31
--- /dev/null
+++ b/src/web/src/lib/avatar/resolve.test.ts
@@ -0,0 +1,37 @@
+import { describe, it, expect } from "vitest"
+import { resolveAvatar } from "./resolve"
+import { serializeBeamSeed } from "./seed-url"
+
+describe("resolveAvatar", () => {
+ it("resolves a photo URL (https) to photo", () => {
+ expect(resolveAvatar("https://cdn.example.com/a.png", "id_1")).toEqual({
+ kind: "photo",
+ url: "https://cdn.example.com/a.png",
+ })
+ })
+
+ it("resolves a routable leading-/ URL to photo", () => {
+ expect(resolveAvatar("/api/community/users/u1/avatar", "id_1")).toEqual({
+ kind: "photo",
+ url: "/api/community/users/u1/avatar",
+ })
+ })
+
+ it("resolves a avatar:beam value to beam with the stored seed", () => {
+ expect(resolveAvatar(serializeBeamSeed("seed-x"), "id_1")).toEqual({
+ kind: "beam",
+ seed: "seed-x",
+ })
+ })
+
+ it("ignores a legacy avatar:{shape…} config and beams by the fallback seed", () => {
+ expect(
+ resolveAvatar('avatar:{"shape":"star","eye":"happy","nose":"dot","bg":3}', "id_1"),
+ ).toEqual({ kind: "beam", seed: "id_1" })
+ })
+
+ it("beams by the fallback seed for null/undefined", () => {
+ expect(resolveAvatar(null, "id_1")).toEqual({ kind: "beam", seed: "id_1" })
+ expect(resolveAvatar(undefined, "id_1")).toEqual({ kind: "beam", seed: "id_1" })
+ })
+})
diff --git a/src/web/src/lib/avatar/resolve.ts b/src/web/src/lib/avatar/resolve.ts
new file mode 100644
index 000000000..16165fe80
--- /dev/null
+++ b/src/web/src/lib/avatar/resolve.ts
@@ -0,0 +1,24 @@
+/**
+ * Resolves a stored avatar value into what to render.
+ *
+ * Priority: a real photo URL wins; then a `avatar:beam:{seed}` value renders
+ * beam with its stored seed; everything else — null, or a legacy
+ * `avatar:{shape…}` config that we deliberately no longer honor — falls back
+ * to an id-seeded beam.
+ */
+import { isPhotoAvatarUrl } from "@/components/avatar/photo"
+import { parseBeamSeed } from "./seed-url"
+
+export type ResolvedAvatar =
+ | { kind: "photo"; url: string }
+ | { kind: "beam"; seed: string }
+
+export function resolveAvatar(
+ value: string | null | undefined,
+ fallbackSeed: string,
+): ResolvedAvatar {
+ if (isPhotoAvatarUrl(value)) return { kind: "photo", url: value! }
+ const beamSeed = parseBeamSeed(value)
+ if (beamSeed) return { kind: "beam", seed: beamSeed }
+ return { kind: "beam", seed: fallbackSeed }
+}
diff --git a/src/web/src/lib/avatar/seed-url.test.ts b/src/web/src/lib/avatar/seed-url.test.ts
new file mode 100644
index 000000000..a86195f39
--- /dev/null
+++ b/src/web/src/lib/avatar/seed-url.test.ts
@@ -0,0 +1,26 @@
+import { describe, it, expect } from "vitest"
+import { serializeBeamSeed, parseBeamSeed } from "./seed-url"
+
+describe("seed-url", () => {
+ it("round-trips seed → url → seed", () => {
+ expect(parseBeamSeed(serializeBeamSeed("usr_1"))).toBe("usr_1")
+ expect(parseBeamSeed(serializeBeamSeed("a-b-c-uuid"))).toBe("a-b-c-uuid")
+ })
+
+ it("serializes with the avatar:beam: prefix", () => {
+ expect(serializeBeamSeed("x")).toBe("avatar:beam:x")
+ })
+
+ it("returns null for non-beam values", () => {
+ expect(parseBeamSeed(null)).toBeNull()
+ expect(parseBeamSeed(undefined)).toBeNull()
+ expect(parseBeamSeed("")).toBeNull()
+ expect(parseBeamSeed("https://cdn.example.com/a.png")).toBeNull()
+ expect(parseBeamSeed("/api/community/users/u1/avatar")).toBeNull()
+ expect(parseBeamSeed('avatar:{"shape":"star","eye":"happy","nose":"dot","bg":3}')).toBeNull()
+ })
+
+ it("returns null for an empty seed after the prefix", () => {
+ expect(parseBeamSeed("avatar:beam:")).toBeNull()
+ })
+})
diff --git a/src/web/src/lib/avatar/seed-url.ts b/src/web/src/lib/avatar/seed-url.ts
new file mode 100644
index 000000000..94e077751
--- /dev/null
+++ b/src/web/src/lib/avatar/seed-url.ts
@@ -0,0 +1,25 @@
+/**
+ * Serialization for the beam-avatar stored value: `avatar:beam:{seed}`.
+ *
+ * Stored in the same `user.image` / `agent.avatarUrl` TEXT column that used to
+ * hold the legacy `avatar:{shape,eye,nose,bg}` config. The two prefixes
+ * (`avatar:beam:` vs `avatar:{`) are distinguishable, and the renderer only
+ * honors this one — legacy configs fall through to an id-seeded beam.
+ */
+
+const BEAM_PREFIX = "avatar:beam:"
+
+export function serializeBeamSeed(seed: string): string {
+ return BEAM_PREFIX + seed
+}
+
+export function parseBeamSeed(url: string | null | undefined): string | null {
+ if (!url || !url.startsWith(BEAM_PREFIX)) return null
+ const seed = url.slice(BEAM_PREFIX.length)
+ return seed.length > 0 ? seed : null
+}
+
+/** A stored beam value with a fresh random seed — for newly-created entities. */
+export function randomBeamAvatar(): string {
+ return serializeBeamSeed(crypto.randomUUID())
+}
diff --git a/src/web/src/lib/community/gradient-from-seed.test.ts b/src/web/src/lib/community/gradient-from-seed.test.ts
deleted file mode 100644
index fce473cbe..000000000
--- a/src/web/src/lib/community/gradient-from-seed.test.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-import { describe, it, expect } from "vitest"
-import { BG_COLORS } from "@/components/avatar/avatar-parts"
-import { gradientFromSeed, gradientColorsFromSeed, gradientAngleFromSeed } from "./gradient-from-seed"
-
-const PRESET_VALUES = new Set(BG_COLORS.map((c) => c.value))
-
-describe("gradientColorsFromSeed", () => {
- it("picks three colors from the agent avatar preset palette", () => {
- const colors = gradientColorsFromSeed("seed_abc")
- expect(colors).toHaveLength(3)
- for (const c of colors) expect(PRESET_VALUES.has(c)).toBe(true)
- })
-
- it("picks three distinct colors", () => {
- const colors = gradientColorsFromSeed("seed_xyz")
- expect(new Set(colors).size).toBe(3)
- })
-
- it("is deterministic for the same seed", () => {
- expect(gradientColorsFromSeed("seed_1")).toEqual(gradientColorsFromSeed("seed_1"))
- })
-
- it("varies across different seeds", () => {
- const a = gradientColorsFromSeed("seed_1")
- const b = gradientColorsFromSeed("seed_2")
- expect(a).not.toEqual(b)
- })
-})
-
-describe("gradientAngleFromSeed", () => {
- it("returns a degree value within [0, 360)", () => {
- for (const seed of ["seed_abc", "seed_xyz", "seed_1", "seed_2"]) {
- const angle = gradientAngleFromSeed(seed)
- expect(angle).toBeGreaterThanOrEqual(0)
- expect(angle).toBeLessThan(360)
- expect(Number.isInteger(angle)).toBe(true)
- }
- })
-
- it("is deterministic for the same seed", () => {
- expect(gradientAngleFromSeed("seed_1")).toBe(gradientAngleFromSeed("seed_1"))
- })
-
- it("varies across different seeds", () => {
- const angles = new Set(["seed_1", "seed_2", "seed_3", "seed_4"].map(gradientAngleFromSeed))
- expect(angles.size).toBeGreaterThan(1)
- })
-})
-
-describe("gradientFromSeed", () => {
- it("builds a linear-gradient CSS value from a seeded angle and three preset colors", () => {
- const css = gradientFromSeed("seed_abc")
- expect(css).toMatch(/^linear-gradient\(\d+deg, .+, .+, .+\)$/)
- const [c0, c1, c2] = gradientColorsFromSeed("seed_abc")
- const angle = gradientAngleFromSeed("seed_abc")
- expect(css).toBe(`linear-gradient(${angle}deg, ${c0}, ${c1}, ${c2})`)
- })
-
- it("is deterministic for the same seed", () => {
- expect(gradientFromSeed("seed_1")).toBe(gradientFromSeed("seed_1"))
- })
-})
diff --git a/src/web/src/lib/community/gradient-from-seed.ts b/src/web/src/lib/community/gradient-from-seed.ts
deleted file mode 100644
index e0d0ec7ef..000000000
--- a/src/web/src/lib/community/gradient-from-seed.ts
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Deterministic fallback gradient, seeded by a stable id.
- *
- * Draws three distinct colors (and a gradient angle) from the same preset
- * palette used by the agent avatar generator (`BG_COLORS`) so every fallback
- * visual — server icons, the profile-card banner — shares one design
- * language. Everything is seeded, so it looks random across ids but never
- * flickers between renders/reloads.
- */
-import { BG_COLORS } from "@/components/avatar/avatar-parts"
-
-function hashStr(s: string): number {
- let h = 0
- for (let i = 0; i < s.length; i++) h = ((h << 5) - h + s.charCodeAt(i)) | 0
- return Math.abs(h)
-}
-
-// mulberry32 — small, fast seeded PRNG. A raw `hash % length` would bias
-// consecutive picks toward nearby indices; this gives an even spread.
-function mulberry32(seed: number): () => number {
- let a = seed
- return () => {
- a = (a + 0x6d2b79f5) | 0
- let t = Math.imul(a ^ (a >>> 15), 1 | a)
- t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t
- return ((t ^ (t >>> 14)) >>> 0) / 4294967296
- }
-}
-
-/** Three distinct preset colors from `BG_COLORS`, seeded by `seed`. */
-export function gradientColorsFromSeed(seed: string): [string, string, string] {
- const rand = mulberry32(hashStr(seed))
- const pool = BG_COLORS.map((c) => c.value)
- const picked: string[] = []
- for (let i = 0; i < 3 && pool.length > 0; i++) {
- const idx = Math.floor(rand() * pool.length)
- picked.push(pool.splice(idx, 1)[0]!)
- }
- return picked as [string, string, string]
-}
-
-// Salted separately from the color pick so the angle doesn't move in lockstep
-// with color choice (two seeds with the same colors can still differ).
-export function gradientAngleFromSeed(seed: string): number {
- const rand = mulberry32(hashStr(`${seed}:angle`))
- return Math.floor(rand() * 360)
-}
-
-/** CSS `background` value for a seeded fallback gradient. */
-export function gradientFromSeed(seed: string): string {
- const [c0, c1, c2] = gradientColorsFromSeed(seed)
- const angle = gradientAngleFromSeed(seed)
- return `linear-gradient(${angle}deg, ${c0}, ${c1}, ${c2})`
-}
diff --git a/src/web/src/test/e2e-ui/15-mention-scope.spec.ts b/src/web/src/test/e2e-ui/15-mention-scope.spec.ts
new file mode 100644
index 000000000..e35ee81a1
--- /dev/null
+++ b/src/web/src/test/e2e-ui/15-mention-scope.spec.ts
@@ -0,0 +1,198 @@
+import { test, expect, userId } from "./_fixtures/community-fixture"
+import { tid } from "./_fixtures/testids"
+import { composerEditable } from "./_fixtures/actions"
+import {
+ seedServer,
+ seedChannel,
+ seedCategory,
+ seedChannelMember,
+ seedJoinServer,
+ seedMessage,
+ seedThread,
+ seedForumPost,
+ seedDm,
+ memberInfo,
+} from "./_fixtures/seed"
+
+// Journey 15 — @-mention CANDIDATE SCOPE (distinct from journey 13, which pins
+// mention serialization/disambiguation). Scope is a 2-D cross:
+// privacy (category `private` flag — public == top-level, NO third state)
+// × channel type (top-level channel / thread / forum post)
+// backed by `composerMembers` in c/channels/[serverId]/[channelId]/page.tsx.
+//
+// public/top-level ANY type → whole server roster (servers/:id/members)
+// private channel/post → that unit's audience (channels/:id/members)
+// private thread → PARENT channel's audience
+// new forum post → no @ (plain textarea)
+// 1:1 DM → no @ popup at all
+//
+// Fixture: alice (owner) + bob + carol all join the server. The public channel
+// sees everyone; the private channel's audience is alice+bob ONLY — carol is
+// the negative probe (present in public, absent in private). See
+// plans/e2e-mention-scope.md.
+test.describe.serial("mentions — candidate scope", () => {
+ let serverId: string
+ let publicChannelId: string
+ let privateChannelId: string
+ let privateForumId: string
+ let privatePostId: string
+ let threadId: string
+ let alice: { id: string; discriminator: string }
+ let bob: { id: string; discriminator: string }
+ let carol: { id: string; discriminator: string }
+
+ test.beforeAll(async () => {
+ serverId = await seedServer("alice", `Scope ${Date.now()}`)
+ await seedJoinServer("alice", "bob", serverId)
+ await seedJoinServer("alice", "carol", serverId)
+ alice = await memberInfo("alice", serverId, userId("alice"))
+ bob = await memberInfo("alice", serverId, userId("bob"))
+ carol = await memberInfo("alice", serverId, userId("carol"))
+
+ // Public/uncategorized text channel — audience is the whole server.
+ publicChannelId = await seedChannel("alice", serverId, "public-scope")
+
+ // Private category holding a private text channel (audience alice+bob) and
+ // a private forum with one post (audience alice+bob). Carol is excluded from
+ // BOTH — she stays a server member but is not in the private units.
+ const privateCatId = await seedCategory("alice", serverId, `priv-${Date.now()}`, { private: true })
+ privateChannelId = await seedChannel("alice", serverId, "private-scope", "text", privateCatId)
+ await seedChannelMember("alice", privateChannelId, userId("bob"))
+
+ privateForumId = await seedChannel("alice", serverId, "private-forum", "forum", privateCatId)
+ privatePostId = await seedForumPost("alice", privateForumId, `Post ${Date.now()}`, "post body")
+ await seedChannelMember("alice", privatePostId, userId("bob"))
+
+ // A thread rooted on a message in the private channel — its scope is the
+ // PARENT channel's audience (alice+bob), NOT its own participant set.
+ const parentMsgId = await seedMessage("alice", privateChannelId, `thread parent ${Date.now()}`)
+ threadId = await seedThread("alice", parentMsgId, `Thread ${Date.now()}`)
+ })
+
+ // Open the @-popup in the current composer and return the option locators. The
+ // popup keys each row (members AND @everyone/@here) off its item id — a member
+ // row id is the server-member row id (identical in server + channel lists), a
+ // virtual row id is the literal "everyone"/"here".
+ async function openMentionPopup(page: import("@playwright/test").Page) {
+ const editable = composerEditable(page)
+ await editable.click()
+ await editable.pressSequentially("@")
+ return {
+ everyone: page.getByTestId(tid.mentionOption("everyone")),
+ here: page.getByTestId(tid.mentionOption("here")),
+ bob: page.getByTestId(tid.mentionOption(bob.id)),
+ carol: page.getByTestId(tid.mentionOption(carol.id)),
+ channelToken: page.getByTestId(tid.mentionOption("channel")),
+ }
+ }
+
+ test("public top-level channel → whole server roster (bob AND carol), backed by servers/:id/members", async ({ asUser }) => {
+ const { page } = await asUser("alice")
+ // The channel-members endpoint must NOT be hit for a public channel — the
+ // popup roster comes from the server list. Assert its absence by watching
+ // requests for the whole journey.
+ const channelMembersCalls: string[] = []
+ page.on("request", (r) => {
+ if (/\/api\/community\/channels\/[^/]+\/members(\?|$)/.test(r.url())) channelMembersCalls.push(r.url())
+ })
+
+ await page.goto(`/c/channels/${serverId}/${publicChannelId}`)
+ await page.waitForURL(new RegExp(publicChannelId), { timeout: 20_000, waitUntil: "commit" })
+
+ const opt = await openMentionPopup(page)
+ // Assert a KNOWN-PRESENT row first (roster arrived), THEN the wider claim —
+ // so a slow roster load can't false-pass an absence check.
+ await expect(opt.bob).toBeVisible({ timeout: 15_000 })
+ await expect(opt.carol).toBeVisible({ timeout: 15_000 })
+ await expect(opt.everyone).toBeVisible()
+ await expect(opt.here).toBeVisible()
+ // Self (alice) is filtered out of the popup at the composer — keyed by her
+ // server-member row id (the same id the popup options use), not her userId.
+ await expect(page.getByTestId(tid.mentionOption(alice.id))).toHaveCount(0)
+ // No @channel token exists in the model.
+ await expect(opt.channelToken).toHaveCount(0)
+
+ // The public roster came from servers/:id/members, never channels/:id/members.
+ expect(channelMembersCalls).toHaveLength(0)
+ })
+
+ test("private channel → audience only (bob present, carol absent), backed by channels/:id/members", async ({ asUser }) => {
+ const { page } = await asUser("alice")
+ const channelMembersReq = page.waitForRequest(
+ (r) => new RegExp(`/api/community/channels/${privateChannelId}/members`).test(r.url()),
+ { timeout: 20_000 },
+ )
+
+ await page.goto(`/c/channels/${serverId}/${privateChannelId}`)
+ await page.waitForURL(new RegExp(privateChannelId), { timeout: 20_000, waitUntil: "commit" })
+
+ // Private scope is backed by the channel-members endpoint.
+ await channelMembersReq
+
+ const opt = await openMentionPopup(page)
+ await expect(opt.bob).toBeVisible({ timeout: 15_000 })
+ await expect(opt.everyone).toBeVisible()
+ await expect(opt.here).toBeVisible()
+ // Carol is a server member but NOT in this private channel's audience.
+ await expect(opt.carol).toHaveCount(0)
+ })
+
+ test("thread in private channel → PARENT channel audience (bob mentionable though not a participant)", async ({ asUser }) => {
+ const { page } = await asUser("alice")
+ await page.goto(`/c/channels/${serverId}/${threadId}`)
+ await page.waitForURL(new RegExp(threadId), { timeout: 20_000, waitUntil: "commit" })
+
+ const opt = await openMentionPopup(page)
+ // Bob is in the PARENT channel's audience; a thread has no roster of its own,
+ // so bob is mentionable here even though he isn't a thread participant yet.
+ await expect(opt.bob).toBeVisible({ timeout: 15_000 })
+ await expect(opt.everyone).toBeVisible()
+ // Carol is outside the parent channel's audience.
+ await expect(opt.carol).toHaveCount(0)
+ })
+
+ test("forum post reply → post audience (bob present, carol absent)", async ({ asUser }) => {
+ const { page } = await asUser("alice")
+ await page.goto(`/c/channels/${serverId}/${privatePostId}`)
+ await page.waitForURL(new RegExp(privatePostId), { timeout: 20_000, waitUntil: "commit" })
+
+ const opt = await openMentionPopup(page)
+ await expect(opt.bob).toBeVisible({ timeout: 15_000 })
+ await expect(opt.everyone).toBeVisible()
+ await expect(opt.carol).toHaveCount(0)
+ })
+
+ test("new forum post composer has no @ autocomplete (plain textarea)", async ({ asUser }) => {
+ const { page } = await asUser("alice")
+ await page.goto(`/c/channels/${serverId}/${privateForumId}`)
+ await page.waitForURL(new RegExp(privateForumId), { timeout: 20_000, waitUntil: "commit" })
+
+ // Open the create-post form.
+ await page.getByRole("button", { name: "New Post" }).click()
+ const body = page.getByPlaceholder("Enter a message…")
+ await expect(body).toBeVisible({ timeout: 10_000 })
+ // It's a real <textarea>, not a TipTap contenteditable.
+ expect(await body.evaluate((el) => el.tagName)).toBe("TEXTAREA")
+
+ // Typing @ yields no mention popup options at all.
+ await body.click()
+ await body.pressSequentially("@bob")
+ await expect(page.getByTestId(tid.mentionOption(bob.id))).toHaveCount(0)
+ await expect(page.getByTestId(tid.mentionOption("everyone"))).toHaveCount(0)
+ })
+
+ test("1:1 DM composer has no @ popup at all (no members, no everyone/here)", async ({ asUser }) => {
+ const dmId = await seedDm("alice", userId("bob"))
+ const { page } = await asUser("alice")
+ await page.goto(`/c/me/${dmId}`)
+ await page.waitForURL(new RegExp(dmId), { timeout: 20_000, waitUntil: "commit" })
+
+ const editable = composerEditable(page)
+ await editable.click()
+ await editable.pressSequentially("@")
+ // DM context short-circuits the ranker → zero options, and no virtual rows.
+ await expect(page.getByTestId(tid.mentionOption(bob.id))).toHaveCount(0)
+ await expect(page.getByTestId(tid.mentionOption("everyone"))).toHaveCount(0)
+ await expect(page.getByTestId(tid.mentionOption("here"))).toHaveCount(0)
+ })
+})
diff --git a/src/web/src/test/e2e-ui/_fixtures/seed.ts b/src/web/src/test/e2e-ui/_fixtures/seed.ts
index a06430c72..6d7aee1fc 100644
--- a/src/web/src/test/e2e-ui/_fixtures/seed.ts
+++ b/src/web/src/test/e2e-ui/_fixtures/seed.ts
@@ -44,12 +44,35 @@ export async function seedServer(owner: UserKey, name: string): Promise<string>
return data.server.id
}
-export async function seedChannel(owner: UserKey, serverId: string, name: string, type?: "text" | "forum"): Promise<string> {
- const res = await post(owner, `/api/community/servers/${serverId}/channels`, { name, type })
+export async function seedChannel(
+ owner: UserKey,
+ serverId: string,
+ name: string,
+ type?: "text" | "forum",
+ categoryId?: string,
+): Promise<string> {
+ const res = await post(owner, `/api/community/servers/${serverId}/channels`, { name, type, categoryId })
const data = (await res.json()) as { channel: { id: string } }
return data.channel.id
}
+// Create a category (optionally private) and return its id. A private category
+// is what turns its channels' @-mention scope from server-wide to the channel
+// audience — the whole point of the scope spec.
+export async function seedCategory(
+ owner: UserKey,
+ serverId: string,
+ name: string,
+ opts?: { private?: boolean },
+): Promise<string> {
+ const res = await post(owner, `/api/community/servers/${serverId}/categories`, {
+ name,
+ private: opts?.private,
+ })
+ const data = (await res.json()) as { category: { id: string } }
+ return data.category.id
+}
+
// Server membership comes from joining via invite (channels/[id]/members is
// only for private-category channels and requires prior server membership).
// Owner mints an invite, the joiner accepts it. Idempotent-ish: an
@@ -156,6 +179,15 @@ export async function seedForumPost(
return data.post.id
}
+// Create a thread rooted on an existing message. Returns the thread's own
+// child-channel id. A thread has NO roster of its own — its @-mention scope is
+// the PARENT channel's audience — which is exactly what the scope spec probes.
+export async function seedThread(author: UserKey, messageId: string, name: string): Promise<string> {
+ const res = await post(author, `/api/community/messages/${messageId}/threads`, { name })
+ const data = (await res.json()) as { id: string }
+ return data.id
+}
+
export async function createInvite(owner: UserKey, serverId: string): Promise<string> {
const res = await post(owner, `/api/community/servers/${serverId}/invites`, {})
const data = (await res.json()) as { invite: { token: string } }