Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
/**
* 分享双方的头像:只用对方账号的头像与昵称(产品规则 §6)。头像缺失或加载失败时显示昵称首字。
*/
import { useEffect, useState } from 'react';
import { cn } from '@/lib/utils';
import { shareAvatarInitial } from './providerShareFormat';
export function ShareAvatar({
displayName,
avatarUrl,
size = 'md',
className,
}: {
displayName: string;
avatarUrl: string | null | undefined;
size?: 'xs' | 'sm' | 'md' | 'lg';
className?: string;
}) {
const [failed, setFailed] = useState(false);
useEffect(() => setFailed(false), [avatarUrl]);
const frame = cn(
'inline-flex shrink-0 items-center justify-center overflow-hidden rounded-full',
size === 'xs' && 'h-5 w-5 text-10',
size === 'sm' && 'h-7 w-7 text-12',
size === 'md' && 'h-8 w-8 text-13',
size === 'lg' && 'h-10 w-10 text-15',
className,
);
if (avatarUrl && !failed) {
return (
<img
src={avatarUrl}
alt=""
aria-hidden="true"
referrerPolicy="no-referrer"
draggable={false}
className={cn(frame, 'object-cover')}
onError={() => setFailed(true)}
/>
);
}
// 有的主题里 chip 色与卡片底几乎一样(cindy-dark 甚至更暗),细边保证首字头像在任何底色上都是一个圆。
return (
<span
aria-hidden="true"
className={cn(
frame,
'select-none border border-[var(--border-default)] bg-[var(--surface-chip)] font-medium text-[var(--text-primary)]',
)}
>
{shareAvatarInitial(displayName)}
</span>
);
}