aura-web/src/pages/AgentEditor/constants.ts

90 lines
4.2 KiB
TypeScript

import { KnowledgeStatus, SkillType } from '../../api';
export const DEFAULT_AVATAR = 'https://static.svipdata.com/hoyidata/materials/B7lNeTYQM1_0/materials.jpg';
export const PRESET_AVATARS: string[] = [
'https://static.svipdata.com/images/mock-dev-user-id/a1ed5d166a9bcda1.png',
'https://static.svipdata.com/images/mock-dev-user-id/da4d3c387956cd91.png',
'https://static.svipdata.com/images/mock-dev-user-id/9f3eff849389bdd3.png',
'https://static.svipdata.com/images/mock-dev-user-id/0bdcc398dd0423ca.png',
'https://static.svipdata.com/images/mock-dev-user-id/18e35c04462fc56c.png',
'https://static.svipdata.com/images/mock-dev-user-id/7a4d55fc295e65ce.png',
'https://static.svipdata.com/images/mock-dev-user-id/5755088edf226f3c.png',
'https://static.svipdata.com/images/mock-dev-user-id/5ec020c29804a8cd.png',
'https://static.svipdata.com/images/mock-dev-user-id/31265f843ca7099b.png',
'https://static.svipdata.com/images/mock-dev-user-id/f4a2df94f05ed9f6.png',
'https://static.svipdata.com/images/mock-dev-user-id/dfec7aa91c1c5144.png',
'https://static.svipdata.com/images/mock-dev-user-id/fa8ca9d432b555bd.png',
'https://static.svipdata.com/images/mock-dev-user-id/796e8ba7f5781bb0.png',
'https://static.svipdata.com/images/mock-dev-user-id/12a397b565a1ce78.png',
'https://static.svipdata.com/images/mock-dev-user-id/15f78f9a3e0d120c.png',
'https://static.svipdata.com/images/mock-dev-user-id/3ec3ff2af8d61123.png',
'https://static.svipdata.com/images/mock-dev-user-id/ef90579ba571476e.png',
'https://static.svipdata.com/images/mock-dev-user-id/c555806777e127ec.png',
'https://static.svipdata.com/images/mock-dev-user-id/40778045ad8c2620.png',
'https://static.svipdata.com/hoyidata/materials/PkM0iQCaAY_0/materials.png',
'https://static.svipdata.com/hoyidata/materials/tmPDm2FhJY_1/materials.png',
'https://static.svipdata.com/hoyidata/materials/hNCyP4RvJL_2/materials.png',
'https://static.svipdata.com/hoyidata/materials/l2OMyoIVff_3/materials.png',
'https://static.svipdata.com/hoyidata/materials/CINYRp0JJS_4/materials.png',
'https://static.svipdata.com/hoyidata/materials/oUFVVgRpJa_5/materials.png',
'https://static.svipdata.com/hoyidata/materials/WZccHWHK40_6/materials.png',
'https://static.svipdata.com/hoyidata/materials/sLmZKx5GoI_7/materials.png',
'https://static.svipdata.com/hoyidata/materials/ZPHkYQHOE0_8/materials.png',
'https://static.svipdata.com/hoyidata/materials/kpMcS2ekGq_9/materials.png',
'https://static.svipdata.com/hoyidata/materials/1vkwcmV5MC_10/materials.png',
'https://static.svipdata.com/hoyidata/materials/nLLWLA0eLZ_11/materials.png',
];
export const STATUS_TAG: Record<KnowledgeStatus, { color: string; text: string }> = {
pending: { color: 'default', text: '待处理' },
indexing: { color: 'processing', text: '索引中…' },
ready: { color: 'success', text: '已就绪' },
failed: { color: 'error', text: '失败' },
};
export const TYPE_TAG: Record<SkillType, { color: string; icon: string; label: string }> = {
prompt: { color: 'blue', icon: '📝', label: 'Prompt' },
http: { color: 'green', icon: '🌐', label: 'HTTP' },
js: { color: 'volcano', icon: '⚙️', label: 'JS' },
};
export const isImageUrl = (url: string | undefined) => url?.startsWith('http') || url?.startsWith('/');
// parseModelSelectionItem 将多种模型结构统一提取为模型 ID。
const parseModelSelectionItem = (item: any) => {
if (!item) {
return '';
}
if (typeof item === 'string') {
return item;
}
if (typeof item === 'object' && item.model?.id) {
return String(item.model.id);
}
if (typeof item === 'object' && item.id) {
return String(item.id);
}
return String(item);
};
// parseModelSelections 负责把接口返回的模型配置统一转换为模型 ID 列表。
export const parseModelSelections = (value?: unknown) => {
if (Array.isArray(value)) {
return value.map(parseModelSelectionItem).filter(Boolean);
}
// 尝试解析 JSON 格式
try {
const parsed = JSON.parse(String(value || '[]'));
if (Array.isArray(parsed)) {
return parsed.map(parseModelSelectionItem).filter(Boolean);
}
} catch {
// 兼容旧格式:逗号分隔的字符串
}
return String(value || '')
.split(',')
.map((item) => item.trim())
.filter(Boolean);
};