/** * AI 历史记录的类型(对应后端 `ai_chat_list.chat_type`)。 * * 契约见 `docs/ai-history-contract.md`:类型由后端在生成成功时判定,前端只负责展示与筛选。 * 旧数据没有 `chat_type`,按聊天处理。 */ export type AiChatType = | 'chat' | 'writing' | 'image' | 'creative' | 'activity_outline'; /** 类型的中文名(徽标与后台表格共用) */ export const AI_CHAT_TYPE_LABELS: Record = { chat: '聊天', writing: '写作', image: '图片', creative: '创意', activity_outline: '活动策划' }; /** 筛选下拉的可选项(不含「全部」,由使用方按需补充) */ export const AI_CHAT_TYPE_OPTIONS: { label: string; value: AiChatType }[] = [ { label: '聊天', value: 'chat' }, { label: '写作', value: 'writing' }, { label: '图片', value: 'image' }, { label: '创意', value: 'creative' }, { label: '活动策划', value: 'activity_outline' } ]; /** 把后端返回值收敛到已知类型,缺失或未知一律按聊天处理 */ export function resolveAiChatType(value?: string | null): AiChatType { const type = String(value || '').trim() as AiChatType; return type in AI_CHAT_TYPE_LABELS ? type : 'chat'; } /** 直接取中文名,用于模板与表格列 */ export function getAiChatTypeLabel(value?: string | null): string { return AI_CHAT_TYPE_LABELS[resolveAiChatType(value)]; }