fix: AgentList 展示模型名称而非JSON

main
sp mac bookpro 2605 2026-06-08 15:13:27 +08:00
parent 85090899e6
commit 0832930bcb
1 changed files with 37 additions and 2 deletions

View File

@ -37,6 +37,41 @@ export default function AgentList() {
}; };
const isImageUrl = (url: string) => url?.startsWith('http') || url?.startsWith('/'); const isImageUrl = (url: string) => url?.startsWith('http') || url?.startsWith('/');
const getModelLabel = (value: unknown) => {
if (Array.isArray(value)) {
const names = value
.map((item: any) => (typeof item === 'string' ? item : item?.name))
.map((v) => String(v || '').trim())
.filter(Boolean);
return names.join('、');
}
if (typeof value !== 'string') {
return '';
}
const raw = value.trim();
if (!raw) {
return '';
}
try {
const parsed = JSON.parse(raw);
if (Array.isArray(parsed)) {
const names = parsed
.map((item: any) => (typeof item === 'string' ? item : item?.name))
.map((v) => String(v || '').trim())
.filter(Boolean);
return names.join('、');
}
} catch {
}
if (raw.includes(',')) {
return raw
.split(',')
.map((s) => s.trim())
.filter(Boolean)
.join('、');
}
return raw;
};
const publicCount = useMemo(() => list.filter((a) => a.visibility === 'public').length, [list]); const publicCount = useMemo(() => list.filter((a) => a.visibility === 'public').length, [list]);
const teamCount = useMemo(() => list.filter((a) => a.visibility === 'team').length, [list]); const teamCount = useMemo(() => list.filter((a) => a.visibility === 'team').length, [list]);
@ -208,10 +243,10 @@ export default function AgentList() {
</Tag> </Tag>
)} )}
{a.model && ( {getModelLabel(a.model) && (
<Tag bordered={false} style={{ background: 'var(--color-brand-soft)', color: 'var(--color-brand)', borderRadius: 999, margin: 0, maxWidth: '100%' }}> <Tag bordered={false} style={{ background: 'var(--color-brand-soft)', color: 'var(--color-brand)', borderRadius: 999, margin: 0, maxWidth: '100%' }}>
<span style={{ display: 'inline-block', maxWidth: 190, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}> <span style={{ display: 'inline-block', maxWidth: 190, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{a.model} {getModelLabel(a.model)}
</span> </span>
</Tag> </Tag>
)} )}