/** * AIChatWidget SDK v2 —— 类型定义(供 TypeScript / VS Code / Cursor 等 IDE 自动补全) * * 接入方式:在网站 前贴一行 * * * 或程序化初始化: * * * * 免注册免 token:data-card 指向主人自己的助理,人设/知识库在助理设置里改,网站代码不动。 */ /** 气泡位置 */ export type AIChatWidgetPosition = 'right' | 'left'; /** 内置文案语言 */ export type AIChatWidgetLocale = 'zh' | 'en'; /** 初始化 / 重配选项 */ export interface AIChatWidgetOptions { /** 助理 ID(cardId)。主人后台「分享」处可见。 */ card?: string; /** 面板标题 */ title?: string; /** 打开面板时的欢迎语 */ welcome?: string; /** 气泡位置,默认 'right' */ position?: AIChatWidgetPosition; /** 主题色(任意 CSS 颜色) */ color?: string; /** 内置文案语言,默认 'zh' */ locale?: AIChatWidgetLocale; } /** 生效中的配置(只读快照) */ export interface AIChatWidgetConfig { card: string; title: string; position: AIChatWidgetPosition; locale: AIChatWidgetLocale; } /** 服务端下发的站点配置 */ export interface AIChatWidgetServerConfig { title: string; welcome: string; autoReply: boolean; } /** 聊天接口返回 */ export interface AIChatWidgetChatResult { /** AI 回复正文 */ reply: string; /** 是否判定需要转人工 */ handoff: boolean; /** 是否应展示留资卡 */ contactCard: boolean; /** 线索意向分级:low | mid | high */ intent?: string; /** 线索打分 0-100 */ leadScore?: number; } /** 留资接口返回 */ export interface AIChatWidgetLeadResult { saved: boolean; } /** 消息事件载荷 */ export interface AIChatWidgetMessageEvent { role: 'user' | 'ai'; content: string; } /** 留资事件载荷 */ export interface AIChatWidgetLeadEvent { contact: string; } /** 转人工事件载荷 */ export interface AIChatWidgetHandoffEvent { reason: string; } /** 错误事件载荷 */ export interface AIChatWidgetErrorEvent { /** 脱敏后的用户可见文案(只说类型,如「数据库错误」「服务异常」),可直接上屏 */ message: string; /** 原始错误信息,仅供调试/日志,请勿直接展示给终端用户 */ raw: string; } /** 全局 SDK 对象 */ export interface AIChatWidgetAPI { /** SDK 版本号 */ readonly version: string; /** 集成文档地址 */ readonly docs: string; /** 当前生效配置(只读) */ readonly config: AIChatWidgetConfig; /** 初始化 / 重配 */ init(options?: AIChatWidgetOptions): void; /** 打开面板 */ open(): void; /** 关闭面板 */ close(): void; /** 切换面板 */ toggle(): void; /** 代替用户发一条消息 */ send(text: string): Promise; /** 热切换助理(换人设不用改网站代码) */ setCard(cardId: string): string; /** 清空本地会话记录 */ reset(): void; /** 从页面上完全移除 */ destroy(): void; } declare global { interface Window { /** AI 客服挂件(挂在 window 上) */ AIChatWidget: AIChatWidgetAPI; } interface WindowEventMap { 'aichat:open': CustomEvent>; 'aichat:close': CustomEvent>; 'aichat:message': CustomEvent; 'aichat:lead': CustomEvent; 'aichat:handoff': CustomEvent; 'aichat:error': CustomEvent; } }