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(contacts): lay out the agent contact card like an IM profile (#22877)

Arvin Xu36f47e972b05
diff --git a/locales/en-US/common.json b/locales/en-US/common.json
index 360721bdc19..42e1510f596 100644
--- a/locales/en-US/common.json
+++ b/locales/en-US/common.json
@@ -187,6 +187,8 @@
"contacts.editProfile": "Edit profile",
"contacts.empty": "None yet",
"contacts.groups": "Groups",
+ "contacts.info.bio": "Bio",
+ "contacts.info.handle": "Handle",
"contacts.info.mail": "Email",
"contacts.info.sendMail": "Send email",
"contacts.noDescription": "No description yet",
@@ -196,6 +198,8 @@
"contacts.sort.title": "Name",
"contacts.sort.tooltip": "Sort",
"contacts.sort.updatedAt": "Recently updated",
+ "contacts.view": "View",
+ "contacts.viewProfile": "View profile",
"continue": "Continue",
"copy": "Copy",
"copyFail": "Copy failed",
diff --git a/locales/zh-CN/common.json b/locales/zh-CN/common.json
index 1e3946d4795..c2efc40ae15 100644
--- a/locales/zh-CN/common.json
+++ b/locales/zh-CN/common.json
@@ -187,6 +187,8 @@
"contacts.editProfile": "编辑档案",
"contacts.empty": "暂无",
"contacts.groups": "群组",
+ "contacts.info.bio": "简介",
+ "contacts.info.handle": "标识",
"contacts.info.mail": "邮箱",
"contacts.info.sendMail": "发邮件",
"contacts.noDescription": "还没有简介",
@@ -196,6 +198,8 @@
"contacts.sort.title": "名称",
"contacts.sort.tooltip": "排序",
"contacts.sort.updatedAt": "最近更新",
+ "contacts.view": "查看",
+ "contacts.viewProfile": "查看资料",
"continue": "继续",
"copy": "复制",
"copyFail": "复制失败",
diff --git a/packages/locales/src/default/common.ts b/packages/locales/src/default/common.ts
index 97d6ed0e897..17d77502e57 100644
--- a/packages/locales/src/default/common.ts
+++ b/packages/locales/src/default/common.ts
@@ -436,11 +436,15 @@ export default {
'contacts.editProfile': 'Edit profile',
'contacts.empty': 'None yet',
'contacts.groups': 'Groups',
+ 'contacts.info.bio': 'Bio',
+ 'contacts.info.handle': 'Handle',
'contacts.info.mail': 'Email',
'contacts.info.sendMail': 'Send email',
'contacts.noDescription': 'No description yet',
'contacts.notFound': 'This contact no longer exists or is not visible to you',
'contacts.sendMessage': 'Send message',
+ 'contacts.view': 'View',
+ 'contacts.viewProfile': 'View profile',
'contacts.pinned': 'Pinned',
'contacts.sort.title': 'Name',
'contacts.sort.tooltip': 'Sort',
diff --git a/src/features/ContactList/ContactDetail.tsx b/src/features/ContactList/ContactDetail.tsx
index 8c904a1c843..588827e920f 100644
--- a/src/features/ContactList/ContactDetail.tsx
+++ b/src/features/ContactList/ContactDetail.tsx
@@ -1,10 +1,18 @@
'use client';
-import { Button, cx, Empty, Flexbox, Skeleton, Text } from '@lobehub/ui';
+import { cx, DropdownMenu, Empty, Flexbox, Icon, Skeleton, Text } from '@lobehub/ui';
import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
import * as stylex from '@stylexjs/stylex';
-import { MessageCircleIcon, PencilLineIcon, UserRoundXIcon } from 'lucide-react';
-import { type CSSProperties, memo } from 'react';
+import type { LucideIcon } from 'lucide-react';
+import {
+ MessageCircleIcon,
+ MoreHorizontalIcon,
+ PencilLineIcon,
+ SquareArrowOutUpRightIcon,
+ UserRoundIcon,
+ UserRoundXIcon,
+} from 'lucide-react';
+import { type CSSProperties, memo, type Ref } from 'react';
import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router';
@@ -14,8 +22,12 @@ import { coverPattern } from '@/features/AgentViewAll/coverColor';
import { resolveAgentBadge } from '@/features/AgentViewAll/resolveAgentBadge';
import SidebarItemAvatar from '@/features/AgentViewAll/SidebarItemAvatar';
import { useAgentCoverColor } from '@/features/AgentViewAll/useAgentCoverColor';
+import { useChannelsEnabled } from '@/features/Channels/useChannelsEnabled';
+import { useAgentConversationLink } from '@/features/MessageList/useAgentConversationLink';
import NavHeader from '@/features/NavHeader';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
+import WorkspaceLink from '@/features/Workspace/WorkspaceLink';
+import { useCopyAgentIdMenuItem } from '@/hooks/useCopyAgentIdMenuItem';
import { ContactInfo } from './ContactInfo';
import { type ContactCardState, useContactCard } from './useContactCard';
@@ -44,19 +56,37 @@ const styles = stylex.create({
avatar: {
marginBlockStart: `-${AVATAR_SIZE / 2}px`,
},
- description: {
- fontSize: '14px',
- lineHeight: '22px',
- color: cssVar.colorTextSecondary,
- whiteSpace: 'pre-wrap',
- },
- placeholder: {
- fontSize: '14px',
- color: cssVar.colorTextQuaternary,
+ actions: {
+ display: 'grid',
+ gridAutoColumns: 'minmax(0, 1fr)',
+ gridAutoFlow: 'column',
+ gap: '8px',
+ width: '100%',
+ marginBlockStart: '16px',
},
- slug: {
- fontSize: '13px',
- color: cssVar.colorTextTertiary,
+ // An IM-profile action: icon over label, the whole tile clickable.
+ tile: {
+ display: 'flex',
+ flexDirection: 'column',
+ alignItems: 'center',
+ justifyContent: 'center',
+ gap: '4px',
+ paddingBlock: '12px',
+ paddingInline: '8px',
+ borderWidth: 0,
+ borderRadius: '12px',
+ fontFamily: 'inherit',
+ fontSize: '12px',
+ lineHeight: '18px',
+ color: cssVar.colorText,
+ textDecoration: 'none',
+ cursor: 'pointer',
+ backgroundColor: {
+ 'default': cssVar.colorFillTertiary,
+ ':hover': cssVar.colorFillSecondary,
+ },
+ transitionProperty: 'background-color',
+ transitionDuration: '0.15s',
},
state: {
paddingBlock: '48px',
@@ -66,12 +96,56 @@ const styles = stylex.create({
},
});
+const TileContent = ({ icon, label }: { icon: LucideIcon; label: string }) => (
+ <>
+ <Icon icon={icon} size={20} />
+ <span>{label}</span>
+ </>
+);
+
+// Takes the ref and props a DropdownMenu trigger hands its child.
+const MenuTile = ({
+ className,
+ label,
+ ref,
+ ...rest
+}: {
+ className?: string;
+ label: string;
+ ref?: Ref<HTMLButtonElement>;
+}) => (
+ <button
+ ref={ref}
+ type="button"
+ {...rest}
+ className={cx(stylex.props(styles.tile).className, className)}
+ >
+ <TileContent icon={MoreHorizontalIcon} label={label} />
+ </button>
+);
+
const ContactCard = memo<Extract<ContactCardState, { status: 'ready' }>>(
({ canEdit, chatUrl, item, profileUrl, role, slug, title }) => {
const { t } = useTranslation('common');
const navigate = useWorkspaceAwareNavigate();
const badge = resolveAgentBadge(item);
const coverColor = useAgentCoverColor(item, badge.cover, !!badge.coverImage);
+ const isGroup = item.type === 'group';
+ const agentId = isGroup ? undefined : item.id;
+ // With Channels on, "Message" opens the direct Channel and "View" the Agent's own page;
+ // without them both would land on that page, so only "Message" is offered.
+ const channelsEnabled = useChannelsEnabled();
+ const message = useAgentConversationLink(agentId, chatUrl);
+ const copyIdItem = useCopyAgentIdMenuItem(agentId);
+ const moreItems = [
+ {
+ icon: canEdit ? PencilLineIcon : UserRoundIcon,
+ key: 'profile',
+ label: t(canEdit ? 'contacts.editProfile' : 'contacts.viewProfile'),
+ onClick: () => navigate(profileUrl),
+ },
+ ...(copyIdItem ? [copyIdItem] : []),
+ ];
return (
<>
@@ -97,7 +171,7 @@ const ContactCard = memo<Extract<ContactCardState, { status: 'ready' }>>(
stylex.props(styles.avatar).className,
cardStyles.avatarRing,
!badge.cover && cardStyles.avatarPlain,
- item.type === 'group' && cardStyles.avatarRingGroup,
+ isGroup && cardStyles.avatarRingGroup,
)}
>
<SidebarItemAvatar item={item} shape={'circle'} size={AVATAR_SIZE - 6} />
@@ -111,33 +185,29 @@ const ContactCard = memo<Extract<ContactCardState, { status: 'ready' }>>(
>
{title}
</Text>
- {(role || slug) && (
- <Flexbox horizontal align={'center'} gap={8} justify={'center'}>
- {role && (
- <span className={cardStyles.role} title={role}>
- {role}
- </span>
- )}
- {slug && <span {...stylex.props(styles.slug)}>@{slug}</span>}
- </Flexbox>
+ {role && (
+ <span className={cardStyles.role} title={role}>
+ {role}
+ </span>
)}
- {item.description ? (
- <span {...stylex.props(styles.description)}>{item.description}</span>
- ) : (
- <span {...stylex.props(styles.placeholder)}>{t('contacts.noDescription')}</span>
- )}
- <Flexbox horizontal gap={8} justify={'center'} style={{ marginBlockStart: 16 }}>
- <Button icon={MessageCircleIcon} type={'primary'} onClick={() => navigate(chatUrl)}>
- {t('contacts.sendMessage')}
- </Button>
- {canEdit && (
- <Button icon={PencilLineIcon} onClick={() => navigate(profileUrl)}>
- {t('contacts.editProfile')}
- </Button>
+ <div {...stylex.props(styles.actions)}>
+ <WorkspaceLink
+ to={message.url}
+ onClick={message.onClick}
+ {...stylex.props(styles.tile)}
+ >
+ <TileContent icon={MessageCircleIcon} label={t('contacts.sendMessage')} />
+ </WorkspaceLink>
+ {agentId && channelsEnabled && (
+ <WorkspaceLink to={chatUrl} {...stylex.props(styles.tile)}>
+ <TileContent icon={SquareArrowOutUpRightIcon} label={t('contacts.view')} />
+ </WorkspaceLink>
)}
- </Flexbox>
- {/* Groups own no addresses; only agents carry contact info. */}
- {item.type !== 'group' && <ContactInfo agentId={item.id} />}
+ <DropdownMenu items={moreItems}>
+ <MenuTile label={t('more')} />
+ </DropdownMenu>
+ </div>
+ <ContactInfo agentId={agentId} description={item.description} slug={slug} />
</Flexbox>
</>
);
@@ -147,10 +217,10 @@ const ContactCard = memo<Extract<ContactCardState, { status: 'ready' }>>(
ContactCard.displayName = 'ContactCard';
/**
- * A contact's card beside the Contacts list: the agents-wall badge widened into
- * a profile header, with "Send message" into its chat and, for editors, "Edit
- * profile". Opening a contact only previews it — the chat and the edit surface
- * are one click on.
+ * A contact's card beside the Contacts list, laid out like an IM profile: the
+ * agents-wall badge widened into a header, Message / View / More actions, and an
+ * info list with the handle, mail addresses and bio. Opening a contact only
+ * previews it — the conversation and the profile are one click on.
*/
const ContactDetail = memo<{ id: string }>(({ id }) => {
const { t } = useTranslation('common');
diff --git a/src/features/ContactList/ContactInfo.tsx b/src/features/ContactList/ContactInfo.tsx
index e268e71ffda..4c77b6aa83d 100644
--- a/src/features/ContactList/ContactInfo.tsx
+++ b/src/features/ContactList/ContactInfo.tsx
@@ -9,17 +9,19 @@ import { useTranslation } from 'react-i18next';
import { useAgentAccounts } from '@/features/AgentMail/useAgentIdentity';
+import { contactInfoRows } from './contactInfoRows';
+
const styles = stylex.create({
list: {
overflow: 'hidden',
- marginBlockStart: '24px',
+ marginBlockStart: '8px',
borderRadius: '12px',
width: '100%',
textAlign: 'start',
backgroundColor: cssVar.colorFillQuaternary,
},
row: {
- paddingBlock: '10px',
+ paddingBlock: '12px',
paddingInline: '16px',
},
divided: {
@@ -38,42 +40,61 @@ const styles = stylex.create({
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
},
+ bio: {
+ lineHeight: '22px',
+ whiteSpace: 'pre-wrap',
+ overflowWrap: 'anywhere',
+ },
});
+const LABELS = {
+ bio: 'contacts.info.bio',
+ handle: 'contacts.info.handle',
+ mail: 'contacts.info.mail',
+} as const;
+
/**
- * How to reach an agent outside LobeHub, like the numbers and addresses on a
- * phone contact: today the mail addresses it owns. Absent while loading, on a
- * failed read, and for agents without one, so the card never shows an empty box.
+ * The contact's info list, like the username, numbers and bio on a phone contact: its handle,
+ * the mail addresses it owns and its bio. Groups pass no `agentId`, since they own no addresses.
+ * Rows it has nothing for are left out, so the card never shows an empty box.
*/
-export const ContactInfo = memo<{ agentId: string }>(({ agentId }) => {
+export const ContactInfo = memo<{
+ agentId?: string;
+ description?: string | null;
+ slug?: string | null;
+}>(({ agentId, description, slug }) => {
const { t } = useTranslation('common');
- const { data } = useAgentAccounts(agentId);
- const mails = (data ?? []).filter(
- (account) => account.kind === 'mail' && account.status !== 'revoked',
- );
+ const { data } = useAgentAccounts(agentId ?? '');
+ const rows = contactInfoRows({ accounts: data, description, slug });
- if (mails.length === 0) return null;
+ if (rows.length === 0) return null;
return (
<div {...stylex.props(styles.list)}>
- {mails.map((account, index) => (
+ {rows.map((row, index) => (
<Flexbox
horizontal
align={'center'}
gap={8}
- key={account.id}
+ key={row.key}
{...stylex.props(styles.row, index > 0 && styles.divided)}
>
<Flexbox flex={1} gap={2} style={{ minWidth: 0 }}>
- <span {...stylex.props(styles.label)}>{t('contacts.info.mail')}</span>
- <span title={account.identifier} {...stylex.props(styles.value)}>
- {account.identifier}
- </span>
+ <span {...stylex.props(styles.label)}>{t(LABELS[row.kind])}</span>
+ {row.kind === 'bio' ? (
+ <span {...stylex.props(styles.value, styles.bio)}>{row.value}</span>
+ ) : (
+ <span title={row.value} {...stylex.props(styles.value)}>
+ {row.value}
+ </span>
+ )}
</Flexbox>
- <CopyButton content={account.identifier} size={'small'} />
- <a aria-label={t('contacts.info.sendMail')} href={`mailto:${account.identifier}`}>
- <ActionIcon icon={MailIcon} size={'small'} title={t('contacts.info.sendMail')} />
- </a>
+ {row.kind !== 'bio' && <CopyButton content={row.value} size={'small'} />}
+ {row.kind === 'mail' && (
+ <a aria-label={t('contacts.info.sendMail')} href={`mailto:${row.value}`}>
+ <ActionIcon icon={MailIcon} size={'small'} title={t('contacts.info.sendMail')} />
+ </a>
+ )}
</Flexbox>
))}
</div>
diff --git a/src/features/ContactList/contactInfoRows.test.ts b/src/features/ContactList/contactInfoRows.test.ts
new file mode 100644
index 00000000000..b7af867e85a
--- /dev/null
+++ b/src/features/ContactList/contactInfoRows.test.ts
@@ -0,0 +1,31 @@
+import { describe, expect, it } from 'vitest';
+
+import { contactInfoRows } from './contactInfoRows';
+
+describe('contactInfoRows', () => {
+ it('lists the handle, every live mailbox and the bio, in that order', () => {
+ expect(
+ contactInfoRows({
+ accounts: [
+ { id: 'a1', identifier: '[email protected]', kind: 'mail', status: 'revoked' },
+ { id: 'a2', identifier: '0xabc', kind: 'wallet', status: 'active' },
+ { id: 'a3', identifier: '[email protected]', kind: 'mail', status: 'active' },
+ { id: 'a4', identifier: '[email protected]', kind: 'mail', status: 'provisioning' },
+ ],
+ description: 'Ships the lobe.id release\n',
+ slug: 'lobe-id',
+ }),
+ ).toEqual([
+ { key: 'handle', kind: 'handle', value: '@lobe-id' },
+ { key: 'a3', kind: 'mail', value: '[email protected]' },
+ { key: 'a4', kind: 'mail', value: '[email protected]' },
+ { key: 'bio', kind: 'bio', value: 'Ships the lobe.id release' },
+ ]);
+ });
+
+ it('leaves out what the contact has nothing for', () => {
+ // A group, or another member's agent: no handle shown and no accounts listed.
+ expect(contactInfoRows({ accounts: [], description: ' ', slug: null })).toEqual([]);
+ expect(contactInfoRows({})).toEqual([]);
+ });
+});
diff --git a/src/features/ContactList/contactInfoRows.ts b/src/features/ContactList/contactInfoRows.ts
new file mode 100644
index 00000000000..2a2db939392
--- /dev/null
+++ b/src/features/ContactList/contactInfoRows.ts
@@ -0,0 +1,33 @@
+export type ContactInfoRow =
+ | { key: string; kind: 'handle'; value: string }
+ | { key: string; kind: 'mail'; value: string }
+ | { key: string; kind: 'bio'; value: string };
+
+/**
+ * The rows of a contact's info list, like the username, numbers and bio on a phone contact:
+ * the handle, then every mail address the agent still owns, then its bio. A row the contact has
+ * nothing for is left out rather than shown as "not set". The account read is scoped to the
+ * caller, so another member's agent simply lists no mail rows.
+ */
+export const contactInfoRows = ({
+ accounts,
+ description,
+ slug,
+}: {
+ accounts?: { id: string; identifier: string; kind: string; status: string }[];
+ description?: string | null;
+ slug?: string | null;
+}): ContactInfoRow[] => {
+ const rows: ContactInfoRow[] = [];
+ if (slug) rows.push({ key: 'handle', kind: 'handle', value: `@${slug}` });
+
+ for (const account of accounts ?? []) {
+ if (account.kind === 'mail' && account.status !== 'revoked')
+ rows.push({ key: account.id, kind: 'mail', value: account.identifier });
+ }
+
+ const bio = description?.trim();
+ if (bio) rows.push({ key: 'bio', kind: 'bio', value: bio });
+
+ return rows;
+};