/** * MateChat 提示项接口 */ export interface MateChatPromptItem { value: string label: string iconConfig?: { name: string color?: string } desc?: string } /** * MateChat 配置接口 */ export interface MateChatConfig { /** * 可选密码,如果存在则需要密码验证 */ password?: string /** * FastGPT 应用 ID */ appId: string /** * FastGPT API Key */ appKey: string /** * 介绍文案 */ description: string[] /** * 首屏推荐问题列表 */ introPrompt: MateChatPromptItem[] /** * 底部快捷问题列表 */ simplePrompt: MateChatPromptItem[] /** * 客服名称 */ serviceName: string /** * 是否使用流式对话 */ useStream: boolean /** * 背景渐变颜色(CSS linear-gradient 字符串) * 如果不提供,使用默认蓝白渐变 */ backgroundGradient?: string } /** * 配置中心返回的多个配置对象 * key 为配置名称,value 为 MateChatConfig */ export type MateChatConfigs = Record // ==================== API 相关类型定义 ==================== /** * 聊天消息接口 */ export interface ChatMessage { role: 'user' | 'assistant' | 'system' content: string } /** * 聊天请求参数接口 */ export interface ChatCompletionsRequest { chatId: string stream: boolean detail: boolean messages: ChatMessage[] variables?: object customUid?: string } /** * 聊天响应使用情况接口 */ export interface ChatUsage { prompt_tokens: number completion_tokens: number total_tokens: number } /** * 聊天响应选择项接口 */ export interface ChatChoice { message: { role: 'assistant' content: string } finish_reason: string index: number } /** * 聊天响应接口 */ export interface ChatCompletionsResponse { id: string model: string usage: ChatUsage choices: ChatChoice[] } /** * 业务层聊天结果 */ export interface ChatBizResult { /** * normal: 普通回复 * transfer: 转人工 */ type: 'normal' | 'transfer' /** * 大模型原始返回内容 */ content: string } /** * 流式对话回调 */ export interface ChatStreamCallbacks { /** * 每次收到 FastGPT SSE 的增量内容时触发 */ onMessage?: (chunk: string) => void /** * 流结束时触发(包括收到 [DONE] 或正常读取结束) */ onComplete?: () => void /** * 请求或解析发生异常时触发 */ onError?: (error: unknown) => void } /** * 历史会话项接口 */ export interface ChatHistoryItem { chatId: string updateTime: string appId: string customTitle: string title: string top: boolean [key: string]: any } /** * 历史会话查询请求参数接口 */ export interface GetHistoriesRequest { appId: string outLinkUid: string offset: number pageSize: number source: string } /** * 历史会话查询响应接口 */ export interface GetHistoriesResponse { code: number statusText: string message: string data: { list: ChatHistoryItem[] total: number } } /** * 历史会话记录项接口 */ export interface ChatRecordItem { _id: string dataId: string hideInUI: boolean obj: 'Human' | 'AI' value: Array<{ type: string text: { content: string } }> customFeedbacks: any[] time: string durationSeconds?: number llmModuleAccount?: number totalQuoteList?: any[] historyPreviewLength?: number [key: string]: any } /** * 获取历史会话记录请求参数接口 */ export interface GetPaginationRecordsRequest { appId: string chatId: string offset: number pageSize: number loadCustomFeedbacks: boolean } /** * 获取历史会话记录响应接口 */ export interface GetPaginationRecordsResponse { code: number statusText: string message: string data: { list: ChatRecordItem[] total: number } } // ==================== MateChat 组件内部类型 ==================== /** * MateChat 组件内部使用的消息结构 */ export interface MateChatMessage { from: 'user' | 'model' | 'service' content: string loading?: boolean /** * 是否启用打字机效果 * - true: 启用打字机 * - false 或未定义: 不启用打字机 */ typing?: boolean } export interface MateChatOptionItem { value?: string label: string desc?: string send?: string } export interface MateChatOptionsMessage { msgType: 'options' msg?: string options: MateChatOptionItem[] direction?: 'horizontal' | 'vertical' variant?: 'default' | 'shortcut' }