🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(work): redesign the product gallery (#18055)
Arvin Xu098beec2b4ee
diff --git a/locales/en-US/file.json b/locales/en-US/file.jsonindex f9ab6b168c2..5da051a22ca 100644--- a/locales/en-US/file.json+++ b/locales/en-US/file.json@@ -258,12 +258,30 @@"uploadDock.uploadStatus.processing": "Uploading","uploadDock.uploadStatus.success": "Upload completed","uploadDock.uploadStatus.uploading": "Uploading",+ "work.agentEmpty.desc": "Choose another agent to see their work.",+ "work.agentEmpty.title": "No work from this agent",+ "work.agentFilter.all": "All",+ "work.count_one": "{{count}} work",+ "work.count_other": "{{count}} works",+ "work.createdAt": "Created {{date}}",+ "work.date.today": "Today",+ "work.date.yesterday": "Yesterday","work.empty.desc": "Works your agents produce — tasks, documents, Linear and GitHub items — will collect here.","work.empty.title": "No works yet",+ "work.fromTopic": "{{topic}}","work.group": "Works","work.loadError": "Something went wrong while loading works.","work.loadErrorTitle": "Couldn’t load works","work.loadMoreError": "Failed to load more works.","work.retry": "Retry",- "work.topicGroup.other": "Other"+ "work.topicGroup.other": "Other",+ "work.totalCost": "Total cost {{cost}}",+ "work.type.document": "Document",+ "work.type.file": "File",+ "work.type.githubIssue": "GitHub Issue",+ "work.type.githubPullRequest": "GitHub PR",+ "work.type.linearDocument": "Linear Document",+ "work.type.linearIssue": "Linear Issue",+ "work.type.task": "Task",+ "work.updatedAt": "Updated {{date}}"}diff --git a/locales/zh-CN/file.json b/locales/zh-CN/file.jsonindex 74df49f4268..36851e32a64 100644--- a/locales/zh-CN/file.json+++ b/locales/zh-CN/file.json@@ -258,12 +258,30 @@"uploadDock.uploadStatus.processing": "正在上传","uploadDock.uploadStatus.success": "上传完成","uploadDock.uploadStatus.uploading": "正在上传",+ "work.agentEmpty.desc": "请选择其他 Agent 查看其产物。",+ "work.agentEmpty.title": "这个 Agent 暂无产物",+ "work.agentFilter.all": "全部",+ "work.count_one": "{{count}} 个产物",+ "work.count_other": "{{count}} 个产物",+ "work.createdAt": "创建于 {{date}}",+ "work.date.today": "今天",+ "work.date.yesterday": "昨天","work.empty.desc": "Agent 产出的交付物(任务、文档、Linear 与 GitHub 条目)都会汇聚在这里。","work.empty.title": "还没有产物",+ "work.fromTopic": "{{topic}}","work.group": "产物","work.loadError": "加载产物时出错了。","work.loadErrorTitle": "无法加载产物","work.loadMoreError": "加载更多产物失败。","work.retry": "重试",- "work.topicGroup.other": "其他"+ "work.topicGroup.other": "其他",+ "work.totalCost": "累计开销 {{cost}}",+ "work.type.document": "文档",+ "work.type.file": "文件",+ "work.type.githubIssue": "GitHub Issue",+ "work.type.githubPullRequest": "GitHub PR",+ "work.type.linearDocument": "Linear 文档",+ "work.type.linearIssue": "Linear Issue",+ "work.type.task": "任务",+ "work.updatedAt": "更新于 {{date}}"}diff --git a/packages/database/src/models/work/__tests__/queries.test.ts b/packages/database/src/models/work/__tests__/queries.test.tsindex db507c3991e..6ff708fa177 100644--- a/packages/database/src/models/work/__tests__/queries.test.ts+++ b/packages/database/src/models/work/__tests__/queries.test.ts@@ -271,6 +271,11 @@ describe('WorkModel · queries', () => {await workModel.registerExternal({changeType: 'created',+ cumulativeUsage: {+ capturedAt: '2026-08-08T06:30:00.000Z',+ cost: { total: 0.012 },+ usage: { llm: { tokens: { input: 900, output: 300, total: 1200 } } },+ },identifier: 'lobehub/lobehub#7',patchFields: ['identifier', 'title'],resourceId: 'lobehub/lobehub#7',@@ -298,6 +303,11 @@ describe('WorkModel · queries', () => {const byResource = new Map(workspace.items.map((item) => [item.resourceId, item]));expect(byResource.get('lobehub/lobehub#7')).toMatchObject({+ event: {+ cumulativeUsage: {+ usage: { llm: { tokens: { total: 1200 } } },+ },+ },originTopicId: titledTopicId,originTopicTitle: 'Origin topic',});diff --git a/packages/database/src/models/work/internal.ts b/packages/database/src/models/work/internal.tsindex 883e450277f..a25666b91d7 100644--- a/packages/database/src/models/work/internal.ts+++ b/packages/database/src/models/work/internal.ts@@ -6,6 +6,7 @@ import type {WorkListBaseItem,WorkListItem,WorkSummaryItem,+ WorkSummaryVersionPreview,WorkVersionEventItem,WorkVersionPreview,} from '@lobechat/types';@@ -118,6 +119,7 @@ export const currentVersionEventSelection = {changeType: currentVersions.changeType,createdAt: currentVersions.createdAt,cumulativeCost: currentVersions.cumulativeCost,+ cumulativeUsage: currentVersions.cumulativeUsage,id: currentVersions.id,messageId: currentVersions.messageId,metadata: currentVersions.metadata,@@ -169,7 +171,7 @@ export const eventWorkListFields = {};export interface TaskWorkSummaryQueryRow {- event: WorkVersionPreview;+ event: WorkSummaryVersionPreview;/** Live-coalesced task columns; `deleted` flags a missing live row. */task: TaskWorkListItem['task'] & { deleted: TaskWorkListItem['taskDeleted'] };version: TaskWorkSummaryItem['version'];@@ -266,7 +268,7 @@ export interface WorkConversationRowParams {* for non-task rows by the LEFT JOIN).*/export interface WorkspaceSummaryQueryRow {- event: WorkVersionPreview;+ event: WorkSummaryVersionPreview;task: TaskWorkSummaryQueryRow['task'];version: TaskWorkSummaryItem['version'];work: WorkListBaseItem;diff --git a/packages/locales/src/default/file.ts b/packages/locales/src/default/file.tsindex 320f2f58f0d..60bbc9a9e2a 100644--- a/packages/locales/src/default/file.ts+++ b/packages/locales/src/default/file.ts@@ -276,12 +276,30 @@ export default {'work.empty.desc':'Works your agents produce — tasks, documents, Linear and GitHub items — will collect here.','work.empty.title': 'No works yet',+ 'work.agentEmpty.desc': 'Choose another agent to see their work.',+ 'work.agentEmpty.title': 'No work from this agent',+ 'work.agentFilter.all': 'All',+ 'work.createdAt': 'Created {{date}}',+ 'work.count_one': '{{count}} work',+ 'work.count_other': '{{count}} works',+ 'work.date.today': 'Today',+ 'work.date.yesterday': 'Yesterday',+ 'work.fromTopic': '{{topic}}','work.group': 'Works','work.loadError': 'Something went wrong while loading works.','work.loadErrorTitle': 'Couldn’t load works','work.loadMoreError': 'Failed to load more works.','work.retry': 'Retry',+ 'work.type.document': 'Document',+ 'work.type.file': 'File',+ 'work.type.githubIssue': 'GitHub Issue',+ 'work.type.githubPullRequest': 'GitHub PR',+ 'work.type.linearDocument': 'Linear Document',+ 'work.type.linearIssue': 'Linear Issue',+ 'work.type.task': 'Task',+ 'work.updatedAt': 'Updated {{date}}','work.topicGroup.other': 'Other',+ 'work.totalCost': 'Total cost {{cost}}','uploadDock.body.collapse': 'Collapse','uploadDock.header.cancelAll': 'Cancel all','uploadDock.body.item.cancel': 'Cancel',diff --git a/packages/types/src/work.ts b/packages/types/src/work.tsindex 151615546dd..dd7131d05c4 100644--- a/packages/types/src/work.ts+++ b/packages/types/src/work.ts@@ -220,26 +220,29 @@ export type WorkVersionEventItem =| TaskWorkVersionEventItem;export type WorkVersionEventMap = Record<string, WorkVersionEventItem[]>;+export type WorkSummaryVersionPreview = WorkVersionPreview &+ Pick<WorkVersionItem, 'cumulativeUsage'>;+export interface TaskWorkSummaryItem extends TaskWorkListItem {- event: WorkVersionPreview;+ event: WorkSummaryVersionPreview;totalCost: number | null;version: Pick<WorkVersionItem, 'createdAt' | 'id' | 'version'> | null;}export interface DocumentWorkSummaryItem extends DocumentWorkListItem {- event: WorkVersionPreview;+ event: WorkSummaryVersionPreview;totalCost: number | null;version: Pick<WorkVersionItem, 'createdAt' | 'id' | 'version'> | null;}export interface ExternalWorkSummaryItem extends ExternalWorkListItem {- event: WorkVersionPreview;+ event: WorkSummaryVersionPreview;totalCost: number | null;version: Pick<WorkVersionItem, 'createdAt' | 'id' | 'version'> | null;}export interface FileWorkSummaryItem extends FileWorkListItem {- event: WorkVersionPreview;+ event: WorkSummaryVersionPreview;totalCost: number | null;version: Pick<WorkVersionItem, 'createdAt' | 'id' | 'version'> | null;}diff --git a/src/features/WorkGallery/WorkPreview.tsx b/src/features/WorkGallery/WorkPreview.tsxnew file mode 100644index 00000000000..39fd1f40df3--- /dev/null+++ b/src/features/WorkGallery/WorkPreview.tsx@@ -0,0 +1,220 @@+'use client';++import type { WorkSummaryItem } from '@lobechat/types';+import { Github } from '@lobehub/icons';+import { Flexbox, Tag, Text } from '@lobehub/ui';+import { createStaticStyles, cssVar } from 'antd-style';+import { CheckCircle2Icon, GitPullRequestIcon } from 'lucide-react';+import { memo } from 'react';+import { useTranslation } from 'react-i18next';++import { getWorkTypeDescriptor } from '@/features/Work/descriptors';+import LinearIcon from '@/features/Work/icons/LinearIcon';++const styles = createStaticStyles(({ css }) => ({+ cover: css`+ position: relative;++ overflow: hidden;++ height: clamp(160px, 15vw, 220px);+ margin: 7px;+ border-radius: 11px;++ background: ${cssVar.colorFillQuaternary};+ `,+ coverBadge: css`+ position: absolute;+ z-index: 2;+ inset-block-start: 9px;+ inset-inline-start: 9px;++ display: grid;+ place-items: center;++ width: 34px;+ height: 34px;+ border: 1px solid ${cssVar.colorBorderSecondary};+ border-radius: 10px;++ color: ${cssVar.colorText};++ background: color-mix(in srgb, ${cssVar.colorBgElevated} 88%, transparent);+ backdrop-filter: blur(12px);+ `,+ grid: css`+ position: absolute;+ inset: 0;++ opacity: 0.22;+ background-image:+ linear-gradient(${cssVar.colorBorderSecondary} 1px, transparent 1px),+ linear-gradient(90deg, ${cssVar.colorBorderSecondary} 1px, transparent 1px);+ background-size: 20px 20px;+ `,+ linearBody: css`+ padding: 20px;+ `,+ linearId: css`+ font-size: 10px;+ font-weight: 650;+ color: ${cssVar.colorTextTertiary};+ letter-spacing: 0.04em;+ `,+ linearTitle: css`+ overflow: hidden;+ display: -webkit-box;+ -webkit-box-orient: vertical;+ -webkit-line-clamp: 2;++ margin-block-start: 7px;++ font-size: 13px;+ font-weight: 700;+ line-height: 1.4;+ `,+ mockWindow: css`+ position: absolute;+ inset: 26px;++ overflow: hidden;++ border: 1px solid ${cssVar.colorBorderSecondary};+ border-radius: 9px;++ background: ${cssVar.colorBgContainer};+ `,+ previewDescription: css`+ overflow: hidden;+ display: -webkit-box;+ -webkit-box-orient: vertical;+ -webkit-line-clamp: 2;++ margin-block-start: 8px;++ font-size: 9px;+ line-height: 1.55;+ color: ${cssVar.colorTextSecondary};+ `,+ previewBody: css`+ box-sizing: border-box;+ height: 100%;+ padding-block: 20px 28px;+ padding-inline: 20px;+ `,+ previewIdentifier: css`+ font-size: 9px;+ font-weight: 650;+ color: ${cssVar.colorTextTertiary};+ `,+ previewTitle: css`+ overflow: hidden;+ display: -webkit-box;+ -webkit-box-orient: vertical;+ -webkit-line-clamp: 2;++ margin-block-start: 7px;++ font-size: 12px;+ font-weight: 700;+ line-height: 1.45;+ `,+ status: css`+ position: absolute;+ z-index: 2;+ inset-block-start: 12px;+ inset-inline-end: 12px;+ `,+ taskBody: css`+ padding: 20px;+ `,+}));++const getStatusColor = (status?: string | null) => {+ const normalized = status?.toLowerCase();+ if (!normalized) return undefined;+ if (normalized.includes('done') || normalized.includes('complete') || normalized === 'merged')+ return 'success';+ if (normalized.includes('review') || normalized.includes('progress')) return 'warning';+ if (normalized.includes('open') || normalized.includes('todo')) return 'info';+ return undefined;+};++interface WorkPreviewProps {+ item: WorkSummaryItem;+ title: string;+}++const WorkPreview = memo<WorkPreviewProps>(({ item, title }) => {+ const { t } = useTranslation('file');+ const descriptor = getWorkTypeDescriptor(item);+ const DescriptorIcon = descriptor.getIcon(item);+ const description = descriptor.getDescription(item);+ const identifier = descriptor.getIdentifier(item);+ const displayIdentifier =+ item.resourceType.startsWith('github_') && identifier?.includes('#')+ ? `#${identifier.split('#').at(-1)}`+ : identifier;+ const previewIdentifier =+ item.resourceType === 'document' ? t('work.type.document') : displayIdentifier;+ const isGithub = item.resourceType.startsWith('github_');+ const isLinear = item.resourceType.startsWith('linear_');+ const taskStatus = item.resourceType === 'task' ? item.task.status : null;+ const status = item.status || taskStatus;++ return (+ <div className={styles.cover}>+ <div className={styles.grid} />+ <div className={styles.mockWindow}>+ {isLinear ? (+ <div className={styles.linearBody}>+ <Flexbox horizontal align={'center'} justify={'space-between'}>+ <span className={styles.linearId}>{identifier}</span>+ </Flexbox>+ <div className={styles.linearTitle}>{title}</div>+ <div className={styles.previewDescription}>{description}</div>+ </div>+ ) : item.resourceType === 'task' ? (+ <Flexbox className={styles.taskBody} gap={10}>+ <Flexbox horizontal align={'center'} gap={8}>+ <CheckCircle2Icon color={cssVar.colorSuccess} size={22} />+ <Text strong>{title}</Text>+ </Flexbox>+ <div className={styles.previewDescription}>{description}</div>+ </Flexbox>+ ) : (+ <div className={styles.previewBody}>+ <Flexbox horizontal align={'center'} gap={6}>+ {item.resourceType === 'github_pull_request' && (+ <GitPullRequestIcon color={cssVar.colorTextTertiary} size={11} />+ )}+ <span className={styles.previewIdentifier}>+ {previewIdentifier || item.resourceType}+ </span>+ </Flexbox>+ <div className={styles.previewTitle}>{title}</div>+ <div className={styles.previewDescription}>{description}</div>+ </div>+ )}+ </div>+ <div className={styles.coverBadge}>+ {isGithub ? (+ <Github size={18} />+ ) : isLinear ? (+ <LinearIcon size={18} />+ ) : (+ <DescriptorIcon size={17} />+ )}+ </div>+ {!isLinear && !isGithub && status && (+ <Tag className={styles.status} color={getStatusColor(status)} size={'small'}>+ {status}+ </Tag>+ )}+ </div>+ );+});++WorkPreview.displayName = 'WorkPreview';++export default WorkPreview;diff --git a/src/features/WorkGallery/WorkPreviewCard.tsx b/src/features/WorkGallery/WorkPreviewCard.tsxindex f140135f1be..43d5c42272f 100644--- a/src/features/WorkGallery/WorkPreviewCard.tsx+++ b/src/features/WorkGallery/WorkPreviewCard.tsx@@ -1,136 +1,269 @@'use client';import type { WorkSummaryItem } from '@lobechat/types';-import { Flexbox, Tag, Text } from '@lobehub/ui';-import { createStaticStyles, cx } from 'antd-style';+import { formatTokenNumber } from '@lobechat/utils/format';+import { Avatar, Flexbox, Tag } from '@lobehub/ui';+import { createStaticStyles, cssVar, cx } from 'antd-style';import { Trash2Icon } from 'lucide-react';import { memo } from 'react';import { useTranslation } from 'react-i18next';+import { formatTaskItemDate } from '@/features/AgentTasks/features/formatTaskItemDate';+import { useAgentDisplayMeta } from '@/features/AgentTasks/shared/useAgentDisplayMeta';import { getWorkTypeDescriptor } from '@/features/Work/descriptors';import { formatWorkVersionCost } from '@/utils/workVersionCost';-const styles = createStaticStyles(({ css, cssVar }) => ({+import WorkPreview from './WorkPreview';++const styles = createStaticStyles(({ css }) => ({+ agentAvatar: css`+ align-self: flex-start;+ margin-block-start: 2px;+ `,+ agentName: css`+ overflow: hidden;+ flex: none;++ max-width: 64px;++ font-size: 12px;+ font-weight: 600;+ text-overflow: ellipsis;+ white-space: nowrap;+ `,card: css`+ position: relative;+overflow: hidden;+border: 1px solid ${cssVar.colorBorderSecondary};- border-radius: 12px;- background: ${cssVar.colorBgElevated};+ border-radius: 16px;++ background: ${cssVar.colorBgContainer};++ transition:+ transform ${cssVar.motionDurationFast},+ border-color ${cssVar.motionDurationFast},+ box-shadow ${cssVar.motionDurationFast};+ `,+ cardInfo: css`+ padding-block: 8px 12px;+ padding-inline: 12px;`,clickable: css`cursor: pointer;&:hover {- background: ${cssVar.colorFillQuaternary};+ border-color: ${cssVar.colorBorder};}`,- cost: css`- flex-shrink: 0;- color: ${cssVar.colorTextTertiary};+ footer: css`+ overflow: hidden;+ margin-block-start: 8px;`,- header: css`- padding-block: 10px;- padding-inline: 12px;- border-block-end: 1px solid ${cssVar.colorBorderSecondary};+ identityMeta: css`+ flex: 1;+ min-width: 0;`,- icon: css`- flex-shrink: 0;-- width: 26px;- height: 26px;- border-radius: 6px;+ identifier: css`+ overflow: hidden;- color: ${cssVar.colorTextSecondary};+ min-width: 0;- background: ${cssVar.colorFillTertiary};+ font-size: 11px;+ color: ${cssVar.colorTextTertiary};+ text-overflow: ellipsis;+ white-space: nowrap;`,- preview: css`+ metaRow: css`+ min-width: 0;+ `,+ meta: css`+ flex: none;+ font-size: 10px;+ color: ${cssVar.colorTextTertiary};+ `,+ originTopic: css`overflow: hidden;- display: -webkit-box;- -webkit-box-orient: vertical;- -webkit-line-clamp: 6;- min-height: 108px;- padding-block: 12px;- padding-inline: 12px;+ min-width: 0;- font-size: 12px;- line-height: 1.6;+ font-size: 11px;color: ${cssVar.colorTextTertiary};- word-break: break-word;+ text-overflow: ellipsis;+ white-space: nowrap;`,title: css`- min-width: 0;- font-size: 14px;- font-weight: 500;+ overflow: hidden;++ margin-block-start: 5px;++ font-size: 15px;+ font-weight: 650;+ line-height: 1.4;+ text-overflow: ellipsis;+ white-space: nowrap;+ `,+ type: css`+ font-size: 11px;+ color: ${cssVar.colorTextTertiary};+ `,+ usage: css`+ flex: none;++ margin-inline-start: auto;++ font-size: 10px;+ color: ${cssVar.colorTextSecondary};+ white-space: nowrap;`,}));+const isRecord = (value: unknown): value is Record<string, unknown> =>+ typeof value === 'object' && value !== null;++const getTotalTokens = (item: WorkSummaryItem): number | null => {+ const usage = item.event.cumulativeUsage?.usage;+ if (!isRecord(usage) || !isRecord(usage.llm) || !isRecord(usage.llm.tokens)) return null;++ const total = usage.llm.tokens.total;+ return typeof total === 'number' && Number.isFinite(total) && total > 0 ? total : null;+};+interface WorkPreviewCardProps {item: WorkSummaryItem;- /** The gallery owns navigation (no chat portal on the resource page). */onOpen: (item: WorkSummaryItem) => void;}-/**- * Gallery cell for the resource page's 产物 view: a vertical card with a- * header row (type icon + title + cost) and a content-preview body, mirroring- * the library page's file cards. The preview is the Work's write-time- * description slice — the in-chat `WorkSummaryCard` stays the compact- * one-line variant.- */-const WorkPreviewCard = memo<WorkPreviewCardProps>(({ item, onOpen }) => {- const { t } = useTranslation('chat');- const cost = formatWorkVersionCost(item.totalCost);+const workTypeKey = (item: WorkSummaryItem) => {+ switch (item.resourceType) {+ case 'document': {+ return 'work.type.document';+ }+ case 'file': {+ return 'work.type.file';+ }+ case 'github_issue': {+ return 'work.type.githubIssue';+ }+ case 'github_pull_request': {+ return 'work.type.githubPullRequest';+ }+ case 'linear_document': {+ return 'work.type.linearDocument';+ }+ case 'linear_issue': {+ return 'work.type.linearIssue';+ }+ case 'task': {+ return 'work.type.task';+ }+ }+};+const WorkPreviewCard = memo<WorkPreviewCardProps>(({ item, onOpen }) => {+ const { t, i18n } = useTranslation(['chat', 'common', 'file']);+ const agent = useAgentDisplayMeta(item.originAgentId);const descriptor = getWorkTypeDescriptor(item);- const Icon = descriptor.getIcon(item);const title =descriptor.getTitle(item)?.trim() ||descriptor.getIdentifier(item) ||item.resourceId ||item.id;- const description = descriptor.getDescription(item);- // Same clickability gating as WorkSummaryCard: no open target or an orphaned- // (deleted-task) Work renders inert. The gallery has no chat portal, so a- // filePreview target is only actionable here through its persisted URL- // fallback — without one the card must not offer a dead click.+ const identifier = descriptor.getIdentifier(item);+ const displayIdentifier =+ item.resourceType.startsWith('github_') && identifier?.includes('#')+ ? `#${identifier.split('#').at(-1)}`+ : identifier;const taskDeleted = item.resourceType === 'task' && item.taskDeleted;const openTarget = descriptor.getOpenTarget(item);const actionable = !!openTarget && (openTarget.kind !== 'filePreview' || !!openTarget.url);const clickable = actionable && !taskDeleted;+ const eventDate = item.event.changeType === 'created' ? item.createdAt : item.updatedAt;+ const eventAt = formatTaskItemDate(eventDate, {+ formatOtherYear: t('time.formatOtherYear', { ns: 'common' }),+ formatThisYear: t('time.formatThisYear', { ns: 'common' }),+ locale: i18n.language,+ });+ const eventTime = t(item.event.changeType === 'created' ? 'work.createdAt' : 'work.updatedAt', {+ date: eventAt,+ ns: 'file',+ });+ const totalTokens = getTotalTokens(item);+ const cost = formatWorkVersionCost(item.totalCost);return (<FlexboxclassName={cx(styles.card, clickable && styles.clickable)}onClick={clickable ? () => onOpen(item) : undefined}>- <Flexbox horizontal align={'center'} className={styles.header} gap={8}>- <Flexbox align={'center'} className={styles.icon} justify={'center'}>- <Icon size={15} />- </Flexbox>- <Flexbox horizontal align={'center'} flex={1} gap={8} style={{ minWidth: 0 }}>- <Text ellipsis className={styles.title}>- {title}- </Text>+ <WorkPreview item={item} title={title} />+ <div className={styles.cardInfo}>+ <Flexbox horizontal align={'center'} className={styles.metaRow} gap={6}>+ <span className={styles.type}>{t(workTypeKey(item), { ns: 'file' })}</span>+ {displayIdentifier &&+ item.resourceType !== 'document' &&+ item.resourceType !== 'github_pull_request' &&+ item.resourceType !== 'linear_issue' && (+ <Flexbox horizontal align={'center'} className={styles.identifier} gap={3}>+ {displayIdentifier}+ </Flexbox>+ )}+ {item.resourceType === 'github_issue' && item.status && (+ <Tag size={'small'} style={{ marginInlineStart: 'auto' }}>+ {item.status}+ </Tag>+ )}{taskDeleted && (<Tag color={'warning'} icon={<Trash2Icon size={12} />} size={'small'}>- {t('workingPanel.works.taskDeleted')}+ {t('workingPanel.works.taskDeleted', { ns: 'chat' })}</Tag>)}</Flexbox>- {cost && (- <Text- code- className={styles.cost}- fontSize={12}- title={t('workingPanel.works.totalCost', { cost })}- >- {cost}- </Text>- )}- </Flexbox>- <div className={styles.preview}>{description}</div>+ <div className={styles.title}>{title}</div>+ <Flexbox horizontal align={'baseline'} className={styles.footer} gap={7}>+ {agent && (+ <>+ <Avatar+ emojiScaleWithBackground+ avatar={agent.avatar}+ background={agent.backgroundColor}+ className={styles.agentAvatar}+ shape={'square'}+ size={24}+ />+ <Flexbox className={styles.identityMeta} gap={1}>+ <Flexbox horizontal align={'baseline'} gap={7}>+ <span className={styles.agentName}>{agent.title}</span>+ <span className={styles.meta}>{eventTime}</span>+ </Flexbox>+ {item.originTopicTitle && (+ <div className={styles.originTopic}>+ {t('work.fromTopic', { ns: 'file', topic: item.originTopicTitle })}+ </div>+ )}+ </Flexbox>+ </>+ )}+ {!agent && (+ <Flexbox className={styles.identityMeta} gap={1}>+ <span className={styles.meta}>{eventTime}</span>+ {item.originTopicTitle && (+ <div className={styles.originTopic}>+ {t('work.fromTopic', { ns: 'file', topic: item.originTopicTitle })}+ </div>+ )}+ </Flexbox>+ )}+ {(totalTokens || cost) && (+ <span className={styles.usage}>+ {[totalTokens ? `${formatTokenNumber(totalTokens)} tokens` : null, cost]+ .filter(Boolean)+ .join(' · ')}+ </span>+ )}+ </Flexbox>+ </div></Flexbox>);});diff --git a/src/features/WorkGallery/index.tsx b/src/features/WorkGallery/index.tsxindex 30badc6c823..67ae02455ce 100644--- a/src/features/WorkGallery/index.tsx+++ b/src/features/WorkGallery/index.tsx@@ -1,87 +1,89 @@'use client';import type { WorkSummaryItem } from '@lobechat/types';-import { Center, Empty, Flexbox, Skeleton, Text } from '@lobehub/ui';-import { createStaticStyles, cssVar } from 'antd-style';+import { Avatar, Center, Empty, Flexbox, Skeleton } from '@lobehub/ui';+import { Button } from '@lobehub/ui/base-ui';+import { createStaticStyles, cssVar, cx } from 'antd-style';import { PackageOpenIcon, TriangleAlertIcon } from 'lucide-react';-import { memo, useCallback, useEffect, useMemo, useRef } from 'react';+import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';-import { formatTaskItemDate } from '@/features/AgentTasks/features/formatTaskItemDate';import { taskDetailPath } from '@/features/AgentTasks/shared/taskDetailPath';+import { useAgentDisplayMeta } from '@/features/AgentTasks/shared/useAgentDisplayMeta';import { openDocumentModal } from '@/features/DocumentModal/loader';import { getWorkTypeDescriptor, isSafeExternalUrl } from '@/features/Work/descriptors';import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';+import { useFetchAgentList } from '@/hooks/useFetchAgentList';+import { formatWorkVersionCost } from '@/utils/workVersionCost';import type { WorkGalleryKey } from './const';import { useWorkspaceWorksInfinite } from './hooks';import WorkPreviewCard from './WorkPreviewCard';const styles = createStaticStyles(({ css }) => ({+ agentFilter: css`+ flex: none;++ padding-inline: 5px 10px;+ border: 1px solid transparent;+ border-radius: 999px;++ color: ${cssVar.colorTextSecondary};+ `,+ agentFilterActive: css`+ border-color: ${cssVar.colorBorder};+ color: ${cssVar.colorText};+ background: ${cssVar.colorFillQuaternary};+ `,+ cardList: css`+ display: grid;+ grid-template-columns: repeat(3, minmax(280px, 1fr));+ gap: 16px;+ width: 100%;++ @media (width <= 920px) {+ grid-template-columns: repeat(2, minmax(280px, 1fr));+ }++ @media (width <= 620px) {+ grid-template-columns: minmax(0, 1fr);+ }+ `,container: css`height: 100%;`,- header: css`- flex: none;- padding-block: 16px 8px;- padding-inline: 24px;+ emptyState: css`+ height: 100%;+ min-height: 320px;`,- scroll: css`- overflow: hidden auto;- flex: 1;+ filterBar: css`+ scrollbar-width: none;- min-height: 0;- padding-block: 8px 24px;+ overflow: auto hidden;+ flex: none;++ padding-block: 12px 10px;padding-inline: 24px;- `,- // Single-column stack (not a grid): cards keep the library page's fixed- // proportions and read top-to-bottom within each topic group.- cardList: css`- display: flex;- flex-direction: column;- gap: 12px;- width: 100%;- max-width: 420px;+ &::-webkit-scrollbar {+ display: none;+ }`,- groupDate: css`+ groupCount: css`flex: none;font-size: 12px;color: ${cssVar.colorTextTertiary};`,groupHeader: css`display: flex;- gap: 16px;+ gap: 10px;align-items: baseline;- justify-content: space-between;-margin-block-end: 12px;`,groupTitle: css`- overflow: hidden;-- font-size: 16px;+ font-size: 14px;font-weight: 600;color: ${cssVar.colorText};- text-overflow: ellipsis;- white-space: nowrap;- `,- // Loading placeholder shell that mirrors `WorkPreviewCard` so the skeleton- // lays out as vertical preview cards in the same grid.- skeletonCard: css`- display: flex;- flex-direction: column;- gap: 12px;-- padding: 12px;- border: 1px solid ${cssVar.colorBorderSecondary};- border-radius: 12px;-- background: ${cssVar.colorBgElevated};- `,- emptyState: css`- height: 100%;- min-height: 320px;`,loadMoreError: css`display: flex;@@ -113,41 +115,62 @@ const styles = createStaticStyles(({ css }) => ({color: ${cssVar.colorText};}`,+ scroll: css`+ overflow: hidden auto;+ flex: 1;++ min-height: 0;+ padding-block: 8px 24px;+ padding-inline: 24px;+ `,+ skeletonCard: css`+ aspect-ratio: 0.9;+ padding: 12px;+ border: 1px solid ${cssVar.colorBorderSecondary};+ border-radius: 16px;++ background: ${cssVar.colorBgContainer};+ `,}));-/** Card-shaped loading placeholders laid out in the same grid as real cards. */+interface AgentFilterProps {+ active: boolean;+ agentId: string;+ onSelect: (agentId: string) => void;+}++const AgentFilter = memo<AgentFilterProps>(({ active, agentId, onSelect }) => {+ const agent = useAgentDisplayMeta(agentId);+ if (!agent) return null;++ return (+ <Button+ className={cx(styles.agentFilter, active && styles.agentFilterActive)}+ size={'small'}+ type={'text'}+ icon={+ <Avatar+ emojiScaleWithBackground+ avatar={agent.avatar}+ background={agent.backgroundColor}+ shape={'square'}+ size={20}+ />+ }+ onClick={() => onSelect(agentId)}+ >+ {agent.title}+ </Button>+ );+});++AgentFilter.displayName = 'AgentFilter';+const SkeletonCards = memo<{ count: number }>(({ count }) => (<div className={styles.cardList}>{Array.from({ length: count }).map((_, index) => (<div className={styles.skeletonCard} key={index}>- <Flexbox horizontal align={'center'} gap={8}>- <Skeleton.Button- active- size={'small'}- style={{ borderRadius: 6, height: 26, maxWidth: 26, minWidth: 26 }}- />- <Skeleton.Button- active- block- size={'small'}- style={{ borderRadius: 4, height: 14, maxWidth: '60%' }}- />- </Flexbox>- <Flexbox gap={8}>- <Skeleton.Button active block size={'small'} style={{ borderRadius: 4, height: 12 }} />- <Skeleton.Button- active- block- size={'small'}- style={{ borderRadius: 4, height: 12, maxWidth: '80%', opacity: 0.7 }}- />- <Skeleton.Button- active- block- size={'small'}- style={{ borderRadius: 4, height: 12, maxWidth: '55%', opacity: 0.4 }}- />- </Flexbox>+ <Skeleton active paragraph={{ rows: 6 }} /></div>))}</div>@@ -155,76 +178,63 @@ const SkeletonCards = memo<{ count: number }>(({ count }) => (SkeletonCards.displayName = 'SkeletonCards';-/**- * Initial-load placeholder mirroring the final layout: topic-group sections,- * each with a title/date header row above its card grid — not a bare card pile.- */-const SkeletonGroups = memo(() => (- <Flexbox gap={32}>- {[3, 2].map((count, index) => (- <div key={index}>- <div className={styles.groupHeader}>- <Skeleton.Button- active- size={'small'}- style={{ borderRadius: 4, height: 16, minWidth: 160, width: 160 }}- />- <Skeleton.Button- active- size={'small'}- style={{ borderRadius: 4, height: 12, minWidth: 48, opacity: 0.5, width: 48 }}- />- </div>- <SkeletonCards count={count} />- </div>- ))}- </Flexbox>-));--SkeletonGroups.displayName = 'SkeletonGroups';-interface WorkGalleryProps {galleryKey: WorkGalleryKey;}-/**- * The resource page's 产物 content area: a cross-topic, cursor-paginated flow- * of Work previews grouped by origin topic. Renders `WorkPreviewCard` with an- * `onOpen` that navigates without the chat portal (task → standalone detail- * route, document → global preview modal, external skill works (linear /- * github) → external link).- */const WorkGallery = memo<WorkGalleryProps>(({ galleryKey }) => {const { t, i18n } = useTranslation('file');const navigate = useWorkspaceAwareNavigate();+ const [activeAgentId, setActiveAgentId] = useState<string | null>(null);+ useFetchAgentList();const { items, error, hasMore, isLoadingInitial, isLoadingMore, loadMore, reload } =useWorkspaceWorksInfinite(galleryKey);- // Group the flat (updatedAt desc) page stream by origin topic. First- // appearance decides group order, so groups sort by their newest work; later- // pages can still append older works into an already-rendered group.+ const agentIds = useMemo(+ () => [...new Set(items.map((item) => item.originAgentId).filter(Boolean))] as string[],+ [items],+ );+ const filteredItems = useMemo(+ () => (activeAgentId ? items.filter((item) => item.originAgentId === activeAgentId) : items),+ [activeAgentId, items],+ );const groups = useMemo(() => {- const byKey = new Map<- string,- { items: WorkSummaryItem[]; newestAt: Date; title: string | null }- >();- for (const item of items) {- // Deleted-topic and non-conversation works share one trailing bucket per- // render order; their titles are gone, so finer keys would only produce- // several identical "other" sections.- const key = item.originTopicId ?? '__no_topic__';- const group = byKey.get(key);+ const today = new Date();+ const yesterday = new Date(today);+ yesterday.setDate(today.getDate() - 1);+ const dateKey = (date: Date) =>+ `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;+ const todayKey = dateKey(today);+ const yesterdayKey = dateKey(yesterday);+ const byDate = new Map<string, { items: WorkSummaryItem[]; title: string }>();++ for (const item of filteredItems) {+ const date = new Date(item.updatedAt);+ const key = dateKey(date);+ const title =+ key === todayKey+ ? t('work.date.today')+ : key === yesterdayKey+ ? t('work.date.yesterday')+ : new Intl.DateTimeFormat(i18n.language, {+ day: 'numeric',+ month: 'short',+ year: date.getFullYear() === today.getFullYear() ? undefined : 'numeric',+ }).format(date);+ const group = byDate.get(key);if (group) group.items.push(item);- else- byKey.set(key, {- items: [item],- newestAt: item.updatedAt,- title: item.originTopicTitle ?? null,- });+ else byDate.set(key, { items: [item], title });}- return [...byKey.entries()].map(([key, group]) => ({ key, ...group }));- }, [items]);++ return [...byDate.entries()].map(([key, group]) => ({+ key,+ ...group,+ totalCost: formatWorkVersionCost(+ group.items.reduce((total, item) => total + (item.totalCost || 0), 0),+ ),+ }));+ }, [filteredItems, i18n.language, t]);const handleOpen = useCallback((item: WorkSummaryItem) => {@@ -236,24 +246,16 @@ const WorkGallery = memo<WorkGalleryProps>(({ galleryKey }) => {void openDocumentModal(openTarget.documentId);return;}- // external skill works (linear / github): external link (URL-less cards- // yield no target above).case 'external': {- // Defense in depth: only ever hand http(s) to shell.openExternal.if (isSafeExternalUrl(openTarget.url))window.open(openTarget.url, '_blank', 'noopener,noreferrer');return;}- // file works: the gallery lives outside the conversation UI, so the- // FilePreview chat portal isn't available — fall back to opening the- // persisted file URL like the pre-portal behavior.case 'filePreview': {if (isSafeExternalUrl(openTarget.url))window.open(openTarget.url, '_blank', 'noopener,noreferrer');return;}- // task: no external URL — the standalone detail route resolves the same- // identifier-or-id the chat portal uses.case 'task': {navigate(taskDetailPath(openTarget.identifier));}@@ -262,25 +264,21 @@ const WorkGallery = memo<WorkGalleryProps>(({ galleryKey }) => {[navigate],);- // Infinite scroll: load the next page when a sentinel near the list's end- // scrolls into view (rootMargin pre-fetches before the user hits the bottom).const sentinelRef = useRef<HTMLDivElement>(null);useEffect(() => {- const el = sentinelRef.current;- if (!el || !hasMore) return;- const io = new IntersectionObserver(+ const element = sentinelRef.current;+ if (!element || !hasMore) return;+ const observer = new IntersectionObserver((entries) => {if (entries[0]?.isIntersecting && hasMore && !isLoadingMore) loadMore();},{ rootMargin: '240px' },);- io.observe(el);- return () => io.disconnect();+ observer.observe(element);+ return () => observer.disconnect();}, [hasMore, isLoadingMore, loadMore]);const renderBody = () => {- // A failed first fetch must read as an error with a retry — not masquerade- // as an empty "no works" page.if (error && items.length === 0)return (<Center className={styles.emptyState} gap={12}>@@ -295,7 +293,7 @@ const WorkGallery = memo<WorkGalleryProps>(({ galleryKey }) => {</Center>);- if (isLoadingInitial && items.length === 0) return <SkeletonGroups />;+ if (isLoadingInitial && items.length === 0) return <SkeletonCards count={8} />;if (items.length === 0)return (@@ -308,37 +306,41 @@ const WorkGallery = memo<WorkGalleryProps>(({ galleryKey }) => {</Center>);+ if (filteredItems.length === 0)+ return (+ <Center className={styles.emptyState}>+ <Empty description={t('work.agentEmpty.desc')} title={t('work.agentEmpty.title')} />+ </Center>+ );+return (<><Flexbox gap={32}>{groups.map((group) => (- <div key={group.key}>+ <section key={group.key}><div className={styles.groupHeader}>- <span className={styles.groupTitle}>- {group.title ?? t('work.topicGroup.other')}- </span>- <span className={styles.groupDate}>- {formatTaskItemDate(group.newestAt, {- formatOtherYear: t('time.formatOtherYear', { ns: 'common' }),- formatThisYear: t('time.formatThisYear', { ns: 'common' }),- locale: i18n.language,- })}+ <span className={styles.groupTitle}>{group.title}</span>+ <span className={styles.groupCount}>+ {t('work.count', { count: group.items.length })}</span>+ {group.totalCost && (+ <span className={styles.groupCount}>+ {t('work.totalCost', { cost: group.totalCost })}+ </span>+ )}</div><div className={styles.cardList}>{group.items.map((item) => (<WorkPreviewCard item={item} key={item.id} onOpen={handleOpen} />))}</div>- </div>+ </section>))}</Flexbox>- {/* Sentinel drives infinite scroll; keep it mounted so the observer can- re-fire after each page appends. */}<div aria-hidden ref={sentinelRef} style={{ height: 1 }} />{isLoadingMore ? (<Flexbox style={{ marginBlockStart: 12 }}>- <SkeletonCards count={2} />+ <SkeletonCards count={4} /></Flexbox>) : error ? (<div className={styles.loadMoreError}>@@ -354,11 +356,26 @@ const WorkGallery = memo<WorkGalleryProps>(({ galleryKey }) => {return (<Flexbox className={styles.container}>- <div className={styles.header}>- <Text strong style={{ fontSize: 16 }}>- {t('work.group')}- </Text>- </div>+ {agentIds.length > 0 && (+ <Flexbox horizontal align={'center'} className={styles.filterBar} gap={4}>+ <Button+ className={cx(styles.agentFilter, !activeAgentId && styles.agentFilterActive)}+ size={'small'}+ type={'text'}+ onClick={() => setActiveAgentId(null)}+ >+ {t('work.agentFilter.all')}+ </Button>+ {agentIds.map((agentId) => (+ <AgentFilter+ active={activeAgentId === agentId}+ agentId={agentId}+ key={agentId}+ onSelect={setActiveAgentId}+ />+ ))}+ </Flexbox>+ )}<Flexbox className={styles.scroll}>{renderBody()}</Flexbox></Flexbox>);