Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ’„ style(agents): eight cover textures, and show the profile cover image on badge cards (#21868)

Arvin Xu13d053208d7a
diff --git a/src/features/AgentViewAll/AgentCard.tsx b/src/features/AgentViewAll/AgentCard.tsx
index 53c2af97c47..16fc6219331 100644
--- a/src/features/AgentViewAll/AgentCard.tsx
+++ b/src/features/AgentViewAll/AgentCard.tsx
@@ -19,6 +19,7 @@ import WorkspaceLink from '@/features/Workspace/WorkspaceLink';
import AgentPendant from './AgentPendant';
import type { AgentRowAuthor } from './AgentRow';
+import { coverPattern } from './coverColor';
import ItemActions from './ItemActions';
import { resolveAgentBadge } from './resolveAgentBadge';
import SidebarItemAvatar from './SidebarItemAvatar';
@@ -58,8 +59,15 @@ export const cardStyles = createStaticStyles(({ css, cssVar }) => ({
`,
// Identity texture, not artwork: a straight-edged band tinted from the
// agent's avatar (see useAgentCoverColor), mixed toward the container color
- // so it stays calm in both themes, with a faint dot grid on top.
+ // so it stays calm in both themes, with a faint texture on top picked from
+ // the agent id (see coverPattern). Every texture is drawn in the container
+ // color at low alpha: dots in --cover-ink, strokes in the lighter
+ // --cover-line, and dense strokes in --cover-faint, so none outshouts another.
cover: css`
+ --cover-ink: color-mix(in srgb, ${cssVar.colorBgContainer} 30%, transparent);
+ --cover-line: color-mix(in srgb, ${cssVar.colorBgContainer} 22%, transparent);
+ --cover-faint: color-mix(in srgb, ${cssVar.colorBgContainer} 15%, transparent);
+
position: absolute;
inset-block-start: 0;
inset-inline: 0;
@@ -72,14 +80,79 @@ export const cardStyles = createStaticStyles(({ css, cssVar }) => ({
var(--agent-cover, ${cssVar.colorFill}) 72%,
${cssVar.colorBgContainer}
);
- background-image: radial-gradient(
- color-mix(in srgb, ${cssVar.colorBgContainer} 30%, transparent) 1px,
- transparent 1.5px
- );
+ background-image: radial-gradient(var(--cover-ink) 1px, transparent 1.5px);
background-size: 10px 10px;
/* The sampled color fades in over the neutral band. */
transition: background-color 0.3s;
+
+ /* An uploaded profile cover replaces both the tint and the texture. */
+ &[data-cover-image] {
+ background-position: center;
+ background-size: cover;
+ }
+
+ &[data-pattern='grid'] {
+ background-image:
+ linear-gradient(var(--cover-faint) 1px, transparent 1px),
+ linear-gradient(90deg, var(--cover-faint) 1px, transparent 1px);
+ background-size: 16px 16px;
+ }
+
+ &[data-pattern='stripes'] {
+ background-image: repeating-linear-gradient(
+ 45deg,
+ var(--cover-line) 0 1px,
+ transparent 1px 8px
+ );
+ background-size: auto;
+ }
+
+ &[data-pattern='crosshatch'] {
+ background-image:
+ repeating-linear-gradient(45deg, var(--cover-line) 0 1px, transparent 1px 10px),
+ repeating-linear-gradient(-45deg, var(--cover-line) 0 1px, transparent 1px 10px);
+ background-size: auto;
+ }
+
+ /* Concentric arcs from the top-right corner, away from the avatar. */
+ &[data-pattern='rings'] {
+ background-image: repeating-radial-gradient(
+ circle at 100% 0,
+ var(--cover-line) 0 1px,
+ transparent 1px 10px
+ );
+ background-size: auto;
+ }
+
+ &[data-pattern='stagger'] {
+ background-image:
+ radial-gradient(var(--cover-ink) 1.5px, transparent 2px),
+ radial-gradient(var(--cover-ink) 1.5px, transparent 2px);
+ background-position:
+ 0 0,
+ 8px 8px;
+ background-size: 16px 16px;
+ }
+
+ &[data-pattern='lines'] {
+ background-image: repeating-linear-gradient(
+ 0deg,
+ var(--cover-faint) 0 1px,
+ transparent 1px 8px
+ );
+ background-size: auto;
+ }
+
+ &[data-pattern='scales'] {
+ background-image: radial-gradient(
+ circle at 50% 0,
+ transparent 6px,
+ var(--cover-line) 6px 7px,
+ transparent 7px
+ );
+ background-size: 14px 8px;
+ }
`,
avatarRing: css`
position: relative;
@@ -91,8 +164,11 @@ export const cardStyles = createStaticStyles(({ css, cssVar }) => ({
border-radius: 50%;
/* Neutral face plate for emoji avatars without a background color;
- images and colored avatars paint over it. */
- background: ${cssVar.colorFillTertiary};
+ images and colored avatars paint over it. The fill is translucent, so it
+ sits on an opaque card-color base: a cover image would show through it. */
+ background:
+ linear-gradient(${cssVar.colorFillTertiary}, ${cssVar.colorFillTertiary}),
+ ${cssVar.colorBgContainer};
background-clip: padding-box;
`,
// Group avatars are a square member grid; a circle would clip its corners.
@@ -248,7 +324,7 @@ const AgentCard = memo<AgentCardProps>(({ item, onToggleSidebar, owner, sidebarH
const displayTitle = agentDisplayName(item, t('agentViewAll.untitled'));
const roleTag = agentSecondaryDisplayName(item);
const badge = resolveAgentBadge(item);
- const coverColor = useAgentCoverColor(item, badge.cover);
+ const coverColor = useAgentCoverColor(item, badge.cover, !!badge.coverImage);
const [anchor, setAnchor] = useState<HTMLElement | null>(null);
// Right-click support β€” same bridge as AgentRow: the hook-bearing menu
@@ -274,7 +350,16 @@ const AgentCard = memo<AgentCardProps>(({ item, onToggleSidebar, owner, sidebarH
<Block clickable className={cardStyles.card} height={'100%'} variant={'outlined'}>
<div
className={cardStyles.cover}
- style={{ '--agent-cover': coverColor } as CSSProperties}
+ data-cover-image={badge.coverImage ? '' : undefined}
+ data-pattern={badge.coverImage ? undefined : coverPattern(item)}
+ style={
+ {
+ '--agent-cover': coverColor,
+ 'backgroundImage': badge.coverImage
+ ? `url(${JSON.stringify(badge.coverImage)})`
+ : undefined,
+ } as CSSProperties
+ }
/>
<AgentPendant bottom={badge.bottom} top={badge.top}>
<span
diff --git a/src/features/AgentViewAll/coverColor.test.ts b/src/features/AgentViewAll/coverColor.test.ts
index 6f0fc1cf1a1..aa3ba200079 100644
--- a/src/features/AgentViewAll/coverColor.test.ts
+++ b/src/features/AgentViewAll/coverColor.test.ts
@@ -2,7 +2,13 @@ import { DEFAULT_AVATAR } from '@lobechat/const';
import type { SidebarAgentItem } from '@lobechat/types';
import { describe, expect, it } from 'vitest';
-import { coverImageSrc, pickDominantColor, seedCoverColor } from './coverColor';
+import {
+ AGENT_COVER_PATTERNS,
+ coverImageSrc,
+ coverPattern,
+ pickDominantColor,
+ seedCoverColor,
+} from './coverColor';
const agent = (overrides: Partial<SidebarAgentItem> = {}): SidebarAgentItem => ({
id: 'agt_1',
@@ -69,3 +75,16 @@ describe('seedCoverColor', () => {
expect(seedCoverColor(agent())).toBe(seedCoverColor(agent({ title: 'Renamed' })));
});
});
+
+describe('coverPattern', () => {
+ it('is stable per agent id', () => {
+ expect(coverPattern(agent())).toBe(coverPattern(agent({ title: 'Renamed' })));
+ });
+
+ it('spreads agents across every texture', () => {
+ const seen = new Set(
+ Array.from({ length: 200 }, (_, i) => coverPattern(agent({ id: `agt_${i}` }))),
+ );
+ expect([...seen].sort()).toEqual([...AGENT_COVER_PATTERNS].sort());
+ });
+});
diff --git a/src/features/AgentViewAll/coverColor.ts b/src/features/AgentViewAll/coverColor.ts
index 3793f575b1b..16ab0e1e533 100644
--- a/src/features/AgentViewAll/coverColor.ts
+++ b/src/features/AgentViewAll/coverColor.ts
@@ -27,6 +27,37 @@ const SEED_COLORS: Record<AgentAvatarColor, string> = {
export const seedCoverColor = (item: SidebarAgentItem): string =>
SEED_COLORS[getAgentAvatarTraits(item.id).color];
+export const AGENT_COVER_PATTERNS = [
+ 'dots',
+ 'grid',
+ 'stripes',
+ 'crosshatch',
+ 'rings',
+ 'stagger',
+ 'lines',
+ 'scales',
+] as const;
+
+export type AgentCoverPattern = (typeof AGENT_COVER_PATTERNS)[number];
+
+/** FNV-1a: a small, stable string hash. */
+const hashString = (text: string): number => {
+ let hash = 0x81_1c_9d_c5;
+ for (let i = 0; i < text.length; i++) {
+ hash ^= text.charCodeAt(i);
+ hash = Math.imul(hash, 0x01_00_01_93);
+ }
+
+ return hash >>> 0;
+};
+
+/**
+ * Cover texture derived from the agent id. Hashed separately from the color
+ * (salted), so two agents that share a color still read apart.
+ */
+export const coverPattern = (item: SidebarAgentItem): AgentCoverPattern =>
+ AGENT_COVER_PATTERNS[hashString(`cover-pattern:${item.id}`) % AGENT_COVER_PATTERNS.length];
+
/** The uploaded image worth sampling, if the avatar is one. */
export const coverImageSrc = (item: SidebarAgentItem): string | undefined => {
const { avatar } = item;
diff --git a/src/features/AgentViewAll/resolveAgentBadge.test.ts b/src/features/AgentViewAll/resolveAgentBadge.test.ts
index e4bc81174d7..f77b40109b9 100644
--- a/src/features/AgentViewAll/resolveAgentBadge.test.ts
+++ b/src/features/AgentViewAll/resolveAgentBadge.test.ts
@@ -25,6 +25,18 @@ describe('resolveAgentBadge', () => {
expect(resolveAgentBadge(agent({ backgroundColor: 'rgba(0, 0, 0, 0)' })).cover).toBeUndefined();
});
+ it('treats an image background as the cover image, not a color', () => {
+ for (const url of [
+ 'https://cdn.example.com/cover.png',
+ '/f/cover.png',
+ 'data:image/png;base64,AA',
+ ]) {
+ const badge = resolveAgentBadge(agent({ backgroundColor: url }));
+ expect(badge.coverImage).toBe(url);
+ expect(badge.cover).toBeUndefined();
+ }
+ });
+
it('marks only builtin agents with a chip', () => {
expect(resolveAgentBadge(agent({ slug: 'inbox' })).bottom).toBe('official');
expect(resolveAgentBadge(agent({ pinned: true, slug: 'inbox' })).bottom).toBe('official');
diff --git a/src/features/AgentViewAll/resolveAgentBadge.ts b/src/features/AgentViewAll/resolveAgentBadge.ts
index c934a645da7..c4bc61b0db9 100644
--- a/src/features/AgentViewAll/resolveAgentBadge.ts
+++ b/src/features/AgentViewAll/resolveAgentBadge.ts
@@ -2,6 +2,7 @@ import { BUILTIN_AGENT_SLUGS } from '@lobechat/builtin-agents';
import type { SidebarAgentItem } from '@lobechat/types';
import { usableBackground } from '@/components/Avatar/fallback';
+import { resolveAgentBackground } from '@/features/AgentProfileArtwork/utils';
const BUILTIN_SLUGS = new Set<string>(Object.values(BUILTIN_AGENT_SLUGS));
@@ -23,6 +24,8 @@ export interface AgentBadge {
bottom?: AgentBottomPendant;
/** Cover color the agent picked; absent lets the card derive one from the avatar. */
cover?: string;
+ /** Profile cover image the agent uploaded; shown as-is instead of a tinted band. */
+ coverImage?: string;
/** Arch badge above the avatar, reserved for event / limited agents. */
top?: AgentTopPendant;
}
@@ -30,17 +33,23 @@ export interface AgentBadge {
/**
* Data-driven badge decorations for the agent list's badge wall. Most agents
* resolve to nothing, so the wall doesn't turn into a sticker board:
- * - cover: the avatar background color the agent picked, if it is a real one;
+ * - cover: the profile cover image, else the background color the agent picked;
* - bottom chip: only builtin agents, reading "official";
* - top arch: only agents carrying an event / limited label.
*/
export const resolveAgentBadge = (item: SidebarAgentItem): AgentBadge => {
const badge: AgentBadge = {};
- // The swatch picker's "default" entry stores a transparent color, which means
- // "no color chosen" β€” same rule as the avatar fallback.
- const cover = usableBackground(item.backgroundColor);
- if (cover) badge.cover = cover;
+ // `backgroundColor` now stores the profile cover image (see
+ // resolveAgentBackground); only legacy rows still hold a color. The swatch
+ // picker's "default" entry stores a transparent color, which means "no color
+ // chosen" β€” same rule as the avatar fallback.
+ const coverImage = resolveAgentBackground(item.backgroundColor);
+ if (coverImage) badge.coverImage = coverImage;
+ else {
+ const cover = usableBackground(item.backgroundColor);
+ if (cover) badge.cover = cover;
+ }
if (item.slug && BUILTIN_SLUGS.has(item.slug)) badge.bottom = 'official';
diff --git a/src/features/AgentViewAll/useAgentCoverColor.ts b/src/features/AgentViewAll/useAgentCoverColor.ts
index 7f2729c5c65..df13b5b89ef 100644
--- a/src/features/AgentViewAll/useAgentCoverColor.ts
+++ b/src/features/AgentViewAll/useAgentCoverColor.ts
@@ -11,10 +11,15 @@ import { coverImageSrc, sampledImageColor, sampleImageColor, seedCoverColor } fr
* avatar image, then the color of its generated character (from the id).
*
* Returns `undefined` while an image is still being sampled, so the card shows
- * a neutral band rather than flashing an unrelated seed color first.
+ * a neutral band rather than flashing an unrelated seed color first, and when
+ * the card shows a profile cover image instead (`hasCoverImage`), which needs none.
*/
-export const useAgentCoverColor = (item: SidebarAgentItem, picked?: string): string | undefined => {
- const src = picked ? undefined : coverImageSrc(item);
+export const useAgentCoverColor = (
+ item: SidebarAgentItem,
+ picked?: string,
+ hasCoverImage?: boolean,
+): string | undefined => {
+ const src = picked || hasCoverImage ? undefined : coverImageSrc(item);
const [, rerender] = useState(0);
useEffect(() => {
@@ -31,6 +36,7 @@ export const useAgentCoverColor = (item: SidebarAgentItem, picked?: string): str
}, [src]);
if (picked) return picked;
+ if (hasCoverImage) return undefined;
if (!src) return seedCoverColor(item);
const sampled = sampledImageColor(src);