import { ReactNode } from 'react'; /** * @icos-react/chat-mobile 公共类型定义 * 针对移动端 750px 设计稿,纯 React 无 antd 依赖 */ /** 消息角色 */ type MessageRole = 'user' | 'assistant'; /** 消息状态 */ type MessageStatus = 'loading' | 'success' | 'error' | 'stopped'; /** 消息推荐问题 */ interface SuggestedQuestion { id: string; text: string; } /** 数据来源 */ interface ParaSource { type: string; title: string; claims?: { score: number; }; link?: string | null; reason?: string | null; icon?: string | null; } /** 单条消息 */ interface ChatMessage { id: string; role: MessageRole; content: string; timestamp: number; status?: MessageStatus; /** AI 回复中携带的推荐问题列表 */ suggestedQuestions?: SuggestedQuestion[]; /** 为 true 时不渲染操作按钮(复制等) */ hideActions?: boolean; /** SSE 流中返回的数据来源 */ para?: ParaSource[]; } /** 快捷功能卡片 */ interface QuickAction { id: string; title: string; description: string; /** 图标:图片 URL 或 React 节点 */ icon?: string | ReactNode; onClick?: () => void; /** 点击快捷按钮后 AI 回复的引导文字 */ responseText?: string; /** 点击快捷按钮后展示的相关问题列表(占位) */ questions?: string[]; /** 该快捷按钮对应的场景码,会通过请求 header 传递给后端 */ sceneCode?: string; } /** API 配置 */ interface ApiConfig { url: string; method?: 'POST' | 'GET'; headers?: Record; body?: Record; } /** SSE 流中的事件 action 项 */ interface EventAction { type: string; anchorId?: string; data?: any; [key: string]: any; } /** 消息操作回调 */ interface MessageActionCallbacks { onCopy?: (message: ChatMessage) => void; onAudio?: (message: ChatMessage) => void; onLike?: (message: ChatMessage) => void; onDislike?: (message: ChatMessage) => void; onShare?: (message: ChatMessage) => void; onRegenerate?: (message: ChatMessage) => void; } /** ChatTriggerBar 组件 Props */ interface ChatTriggerBarProps { /** * 点击右侧 AI 图标:打开 ChatSheet 并进入语音模式 */ onOpenAssistant?: () => void; /** * 在输入框中回车或点击发送按钮提交文字时的回调。 * 若提供,文字提交后将清空输入框。 */ onSubmitText?: (text: string) => void; /** 占位符文字,默认"查找点位、资源、事件" */ placeholder?: string; /** 自定义 className */ className?: string; } /** 地图页助手预览条(Figma 5965-5518) */ interface AssistantPreviewProps { /** AI 助手名称,用于标题「智能助手{name},为您服务」 */ assistantName?: string; /** 点击向右箭头展开全屏 */ onExpand: () => void; /** 从预览条发送文字后展开,并触发此回调(由外层打开 ChatSheet 并自动发送) */ onExpandWithText?: (text: string) => void; /** 自定义头像 URL,默认使用包内 profile.png */ profileSrc?: string; backgroundSrc?: string; arrowSrc?: string; className?: string; } /** ChatSheet 组件 Props */ interface ChatSheetProps { /** 是否显示 */ visible: boolean; /** 关闭回调 */ onClose: () => void; /** API 配置 */ apiConfig?: ApiConfig; /** 标题(导航栏中间文字) */ title?: string; /** 为 true 时不渲染顶部导航栏(返回按钮与标题) */ hideNavbar?: boolean; /** AI 助手名称,默认"小亦" */ assistantName?: string; /** 快捷功能卡片 */ quickActions?: QuickAction[]; /** 历史消息 */ initialMessages?: ChatMessage[]; /** 消息操作回调 */ messageActions?: MessageActionCallbacks; /** 某条 AI 消息产生了位置/事件结果时回调(用于地图交互) */ onEventResult?: (data: unknown, messageId: string) => void; /** * 打开时自动发送的首条用户消息(如从 AssistantPreview 输入)。 * 发送完成后请在外层清空并调用 onSendOnOpenConsumed。 */ sendOnOpen?: string; /** sendOnOpen 已消费回调(用于父组件清空 state,避免重复发送) */ onSendOnOpenConsumed?: () => void; /** 欢迎页头像,默认包内 profile.png */ avatarUrl?: string; /** 快捷按钮点击回调 */ onQuickActionClick?: (action: QuickAction) => void; /** SSE 流中解析到 action 事件时回调(与 largemodel 的 onEventChange 对齐) */ onEventChange?: (data: EventAction[], messageId: string) => void; /** 宿主按 messageId#anchorId 注入的自定义渲染内容,用于替换消息中的 [ANCHOR:xxx] 占位 */ eventContent?: Record; /** 打开时 InputBar 是否自动进入语音模式(按住说话),默认 true */ initialVoiceMode?: boolean; /** 外部控制收起状态:为 true 时将 sheet 切到 collapsed 模式 */ collapsed?: boolean; /** AI 单轮消息流式结束后回调(status 变为 success/error/stopped) */ onMessageDone?: (messageId: string) => void; /** * 点击「数据来源」参考链接时的回调;由宿主(如 mobile-app)实现打开逻辑。 * 未提供时,有 link 的条目不可点击。 */ onParaSourceClick?: (source: ParaSource) => void; /** 自定义 className */ className?: string; } export { ApiConfig, AssistantPreviewProps, ChatMessage, ChatSheetProps, ChatTriggerBarProps, EventAction, MessageActionCallbacks, MessageRole, MessageStatus, ParaSource, QuickAction, SuggestedQuestion };