/** * @file SDK 类型声明文件 * @description 仅导出用户需要的类型接口,不包含内部实现细节 */ /** 文件上传返回结构 */ export interface IFileUploadRes { /** 文件id */ file_id: string; /** 对话id */ conversation_id: string; } /** 用户偏好数据 */ export interface IUserPreferencesData { user_profile: { /** 个性化指令 */ instructions: string; /** 位置信息 */ location_info: { province: string; city: string; district: string; }; }; } /** 取消请求参数 */ export interface IAbortRequestParams { message_id: string; } /** form data 上传成功结果 */ export interface IUploadedFileInfo { /** 文件id */ file_id: string; /** 文件路径 */ storage_location: string; /** 上传结果的bos url */ presigned_url: string; /** 创建/更新时间 */ created_at: string; /** 文件名 */ filename: string; size: number; /** 更新时间 */ updated_at: string; message?: string; } /** 对话文件恢复拉取接口返回 */ export interface ISessionHistoryFilesRes { data: IUploadedFileInfo[]; has_more: boolean; } /** 对话消息拉取接口参数 */ export interface ISessionHistoryDataReq { /** 应用id */ appId?: string; /** 会话id */ sessionId: string; /** 终端用户id */ end_user_id?: string; /** 页码 */ pageNum?: number; } /** 历史对话json数据interface */ export interface IHistoryChatItem { role: 'user' | 'assistant'; /** query内容 */ text: string; /** 文件id */ attachments: string[]; /** 完善interface */ content: any; /** 轮次id,用于标识一轮对话 */ turn_id: string; /** 历史消息的状态 */ status: 'cancelled' | 'completed' | 'failed'; /** 请求id */ request_id: string; } /** 对话列表请求参数结构ForClientService */ export interface IConversationListReq { agent_code: string; end_user_id?: string; start_time?: string; end_time?: string; is_truncated?: boolean; page: number; limit: number; } /** 对话列表元素结构 */ export interface IConversationItem { id: string; app_id: string; /** 任务状态: 运行中/已结束/已完成待查看(待查看为前端人工刷的状态,用于运行中到已完成的提醒) */ status: 'running' | 'completed' | 'completedPendingReview'; /** bce-request-id */ request_id: string; user_id: string; title: string; metadata: Record; end_user_id: string; external_session_id: string; created_at: string; updated_at: string; } /** 会话状态条目 */ export interface IConversationStatus { conversation_id: string; status: 'running' | 'completed'; } /** SDK模式下的客户端服务接口 */ export interface IClientService { /** SSE 对话流式接口 */ agentSpaceRun: ( param: any, callbacks: { /** 接受到消息的回调 */ onMessage: (message: string) => void; /** 任务执行完成的回调 */ onCompleted: () => void; /** 任务执行错误的回调 */ onError: (error: Error) => void; }, options?: { abortController?: AbortController; headers?: HeadersInit; } ) => void; /** SSE 恢复对话接口 */ recoverChat: ( param: any, callbacks: { onMessage: (message: string) => void; onCompleted: () => void; onError: (error: Error) => void; }, options?: { abortController?: AbortController; headers?: HeadersInit; } ) => void; /** 文件上传 */ uploadFile(file: File, conversationId: string): Promise; /** 获取用户偏好 */ getUserPreferences(appId: string): Promise; /** 保存用户偏好 */ saveUserPreferences(appId: string, preferences: IUserPreferencesData): Promise; /** 拉取历史对话消息 */ fetchChatHistory(params: ISessionHistoryDataReq): Promise; /** 获取上传文件信息 */ getUploadFileInfo(fileIds: string[]): Promise; /** 取消请求 */ sendAbortRequest(param: IAbortRequestParams): Promise; /** 获取历史记录列表 */ fetchHistoryChatList(params: IConversationListReq): Promise<{data: IConversationItem[]; has_more: boolean}>; /** 获取会话状态 */ fetchChatStatus(conversationIds: string[]): Promise<{data: IConversationStatus[]}>; /** 更新会话标题 */ updateChatTitle(id: string, title: string, end_user_id?: string): Promise<{success: boolean}>; /** 删除历史对话 */ deleteHistoryChat(chatId: string): Promise<{success: boolean; deleted_count: number}>; /** 语音识别 - 将音频转换为文本 */ speechToText(file: Blob, appId: string): Promise; } /** SDK 初始化函数 */ export declare function init(dom: HTMLDivElement, clientService: IClientService): Promise;