import React, { ReactNode } from 'react'; import { AiClient } from '../client/base'; import type { ChatbotMessageFields } from './XAiChatbot'; import type { Messages, SendContent, SessionData, ChatConfig, ThemeType } from "./"; /** * SDK 内部错误码(仅用于 SDK 自身可确定的错误场景) * 服务端返回的业务错误码会原样透传,接入方在 onError 中自行判断 * @enum {string} */ export declare enum ErrorCode { /** 网络异常 / HTTP 错误 / 超时等 */ NETWORK_ERROR = "NETWORK_ERROR", /** HTTP 401/403 认证失败 */ AUTH_ERROR = "AUTH_ERROR" } /** * 成功状态码枚举(SDK 内部生命周期事件) * @enum {string} */ export declare enum SuccessCode { /** 应用配置初始化成功 */ APP_CONFIG_INIT_SUCCESS = "APP_CONFIG_INIT_SUCCESS", /** 应用消息初始化成功 */ APP_MESSAGES_INIT_SUCCESS = "APP_MESSAGES_INIT_SUCCESS" } /** * 错误信息接口 * - SDK 自身错误:code 为 ErrorCode 枚举值 * - 服务端业务错误:code 为服务端原始 code(如 "XS010016"),由接入方自行解读 */ export interface Error { /** 错误码:SDK 内部 ErrorCode 或服务端原始 code */ code: string; /** 错误信息 */ message: string; /** 服务端原始响应(仅服务端业务错误时携带) */ raw?: Record; } /** * 成功信息接口 * @interface Success * @version 1.0.0 */ export interface Success { /** 成功状态码 */ code: SuccessCode; /** 成功信息 */ message: string; /** 成功数据 */ data?: any; } /** * XAiProvider 操作句柄接口 * @interface XAiProviderHandle * @version 1.0.0 */ export interface XAiProviderHandle { /** * 发送聊天消息 * @param content - 消息内容 * @type {(content: string) => void} * @version 1.0.0 */ chat: (content: SendContent) => void; /** * 停止聊天 * @type {() => void} * @version 1.0.0 */ stopChat: () => void; /** * 重新发送聊天 * @type {() => void} * @version 1.0.0 */ reChat: () => void; /** * 获取应用信息 * @returns {any} 应用信息对象 * @type {() => any} * @version 1.0.0 */ getAppInfo: () => any; /** * 获取消息列表 * @returns {Messages[]} 消息数组 * @type {() => Messages[]} * @version 1.0.0 */ getMessages: () => Messages[]; /** * 获取会话列表 * @returns {} */ getSessions: () => SessionData[]; /** * 重新设置当前会话 * @param id - 会话ID * @type {(id: string) => void} * @version 1.0.0 */ setCurrentSession: (id: string) => void; } export interface sessionConfig { /** * 是否展示会话列表 * @type {boolean} * @default false */ showSessionList?: boolean; } /** * XAiProvider 配置接口 * @interface XAiProviderConfig * @version 1.0.0 */ export interface XAiProviderConfig { /** * 应用唯一编号 * @type {string} * @default undefined * @version 1.0.0 */ appNo?: string; /** * 会话配置 * @type {sessionConfig} */ session?: sessionConfig; /** * 对话框配置 * @type {ChatConfig} */ chatProps?: ChatConfig; /** * 是否启用调试模式 * @type {boolean} * @default false * @version 1.0.0 */ debug?: boolean; } /** * XAiProvider 组件属性接口 * @interface XAiProviderProps * @version 1.0.0 */ export interface XAiProviderProps { /** * AI 服务地址 * @type {string} * @version 1.0.0 */ url: string; /** * 认证 token * @type {string} * @version 1.0.0 */ token: string; /** * 配置信息 * @type {XAiProviderConfig} * @default undefined * @version 1.0.0 */ config?: XAiProviderConfig; /** * Provider 唯一标识,用于区分多个 Provider 实例 * @type {string} * @default undefined * @version 1.0.0 */ providerId?: string; /** * Token 刷新回调 * @type {() => Promise} * @default undefined * @version 1.0.0 */ onRefreshToken?: () => Promise; /** * 应用无法正常渲染回调 * @type {(error: Error) => void} * @default undefined * @version 1.0.0 */ onError?: (error: Error) => void; /** * 应用正常渲染回调 * @type {(success: Success) => void} * @default undefined * @version 1.0.0 */ onSuccess?: (success: Success) => void; /** * 消息返回回调 * @type {(data: Messages) => void} * @default undefined * @version 1.0.0 */ onMessage?: (content: string, data: Messages) => void; /** * 子组件 * @type {ReactNode} * @version 1.0.0 */ children: ReactNode; } /** * XAiSDK 组件属性接口 * @interface XAiSDKProps * @extends XAiProviderProps * @version 1.0.0 */ export interface XAiSDKProps extends XAiProviderProps { /** * 主题类型 * @type {ThemeType} * @default 'default' * @version 1.0.0 */ theme?: ThemeType; /** * 组件属性配置 * @type {object} * @default undefined * @version 1.0.0 */ componentProps?: { /** * 组件ID * @type {string} * @default undefined * @version 1.0.0 */ id?: string; /** 支持任意 CSS 属性 */ [key: string]: any; }; } /** * XAi 上下文类型接口 * @interface XAiContextType * @extends Required * @version 1.0.0 */ export interface XAiContextType extends Required { /** * AI 客户端实例 * @type {AiClient | null} * @default null * @version 1.0.0 */ client: AiClient | null; /** * 认证令牌 * @type {string} * @version 1.0.0 */ token: string; /** * 加载状态 * @type {boolean} * @default false * @version 1.0.0 */ loading: boolean; /** * 错误信息 * @type {string | null} * @default null * @version 1.0.0 */ error: string | null; } /** * XAi 上下文对象 * @type {React.Context} * @version 1.0.0 */ export declare const XAiContext: React.Context;