本地 RAG 知识库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

125 lines
2.9 KiB

/**
* ChatbotSDK 核心类型定义
*/
/** SDK 初始化配置 */
export interface SDKConfig {
// === 必传参数 ===
/** 集成标识 → 后端 chatId 参数 + 数据隔离 key */
integrateId: string;
/** 后端 API 域名 */
requestDomain: string;
// === 用户标识 ===
/** 宿主用户标识 → 后端 accountId 参数 */
userId?: string;
/** 客服角色 ID */
roleId?: number;
// === 知识库 ===
/** 默认知识库分类 ID */
categoryId?: number;
/** 是否显示知识库下拉切换 */
showCategorySwitch?: boolean;
// === UI 配置 ===
/** 弹窗标题文字,默认 "AI 智能助手" */
title?: string;
/** 弹窗宽度(px),默认 380 */
width?: number;
/** 悬浮按钮位置,默认 "right-bottom" */
position?: 'left-bottom' | 'right-bottom';
/** 主色调,默认 "#4F46E5" */
primaryColor?: string;
/** 悬浮按钮图标(可传 URL 或 SVG 字符串) */
launcherIcon?: string;
/** 是否显示清空对话按钮,默认 true */
showClear?: boolean;
/** 是否显示管理面板,默认 false */
showAdminPanel?: boolean;
// === 行为配置 ===
/** 是否启用流式输出,默认 true */
streaming?: boolean;
/** 界面语言,默认 "zh-CN" */
locale?: string;
/** 是否输出调试日志,默认 true */
debug?: boolean;
}
/** 解析后的完整配置(所有可选字段已填充默认值) */
export interface ResolvedConfig {
integrateId: string;
requestDomain: string;
userId?: string;
roleId?: number;
categoryId?: number;
showCategorySwitch: boolean;
title: string;
width: number;
position: 'left-bottom' | 'right-bottom';
primaryColor: string;
launcherIcon: string;
showClear: boolean;
showAdminPanel: boolean;
streaming: boolean;
locale: string;
debug: boolean;
}
/** 聊天消息 */
export interface ChatMessage {
/** 消息唯一 ID */
id: string;
/** 角色:user 或 ai */
role: 'user' | 'ai';
/** 消息文本内容 */
content: string;
/** 时间戳(毫秒) */
timestamp: number;
/** 可选:RAG 引用来源 */
sources?: RagSource[];
}
/** RAG 引用来源 */
export interface RagSource {
documentId: string;
title: string;
sourceName: string;
chunkIndex: number;
score: number;
snippet: string;
}
/** 本地缓存数据结构 */
export interface CacheData {
messages: ChatMessage[];
updatedAt: number;
}
/** SDK 公开 API 接口 */
export interface ChatbotSDKInstance {
/** 初始化 SDK */
init(config: SDKConfig): void;
/** 销毁 SDK 实例 */
destroy(): void;
/** 打开聊天窗口 */
open(): void;
/** 关闭聊天窗口 */
close(): void;
/** 切换窗口显示/隐藏 */
toggle(): void;
/** 清空当前会话历史 */
clearHistory(): void;
}
/** 后端 API 响应通用结构 */
export interface ApiResponse<T = unknown> {
success: boolean;
message?: string;
data?: T;
total?: number;
page?: number;
size?: number;
pages?: number;
}