import { ACPMessageSessionResponse, ConnectionStatus, InviteStatus } from "./websocket"; /** * 代理身份信息接口 * @interface IAgentIdentity * @property {string} aid - 代理ID,用于唯一标识一个代理 * @property {string} privateKey - 代理的私钥,用于签名和加密 * @property {string} certPem - 代理的证书,PEM格式 */ interface IAgentIdentity { aid: string; privateKey: string; certPem: string; } /** * 连接配置接口 * @interface IConnectionConfig * @property {string} messageServer - 消息服务器地址 * @property {string} heartbeatServer - 心跳服务器地址 * @property {string} messageSignature - 消息签名 */ interface IConnectionConfig { messageServer: string; heartbeatServer: string; messageSignature: string; } /** * 代理控制平面接口 * @interface IAgentCP */ interface IAgentCP { /** * 导入代理身份 * @param {IAgentIdentity} identity - 代理身份信息 * @param {string} [seedPassword] - 种子密码(可选) * @returns {Promise} 导入是否成功 */ importAid(identity: IAgentIdentity, seedPassword?: string): Promise; /** * 加载访客身份 * @returns {Promise} 访客身份的AID */ loadGuestAid(): Promise; /** * 加载当前的代理身份 * @returns {Promise} 成功返回AID,失败返回null */ loadCurrentAid(): Promise; /** * 加载指定的代理身份 * @param {string} aid - 要加载的代理ID * @returns {Promise} 成功返回AID,失败返回null */ loadAid(aid: string): Promise; /** * 创建新的代理身份 * @param {string} aid - 新代理的ID * @returns {Promise} 创建的代理ID */ createAid(aid: string): Promise; /** * 上线代理,获取连接配置 * @returns {Promise} 连接配置信息 */ online(): Promise; /** * 加载指定代理的证书信息 * @param {string} aid - 要加载证书信息的代理ID * @returns {Promise<{privateKey: string, publicKey: string, csr: string, cert: string}>} 证书相关信息 * @throws {Error} 当证书信息不完整时抛出错误 */ getCertInfo(aid: string): Promise<{ privateKey: string; publicKey: string; csr: string; cert: string; } | null>; } /** * WebSocket代理接口 * @interface IAgentWS */ interface IAgentWS { /** * 启动WebSocket连接 * @returns {Promise} */ startWebSocket(): Promise; /** * 快捷连接到指定智能体,自动创建会话并发送邀请 * @param receiver 要连接的智能体ID * @param onSessionCreated 会话创建成功回调(可选) * @param onInviteStatus 邀请状态回调(可选) */ connectTo(receiver: string, onSessionCreated: ((sessionInfo: ACPMessageSessionResponse) => void) | null, onInviteStatus: ((status: InviteStatus) => void) | null): void; /** * 创建会话 * @param cb 会话创建回调函数 */ createSession(cb: (res: ACPMessageSessionResponse) => void): void; /** * 邀请智能体加入会话 * @param receiver 接收者智能体ID * @param sessionId 会话ID * @param identifyingCode 邀请码 * @param cb 邀请状态回调函数(可选) */ invite(receiver: string, sessionId: string, identifyingCode: string, cb: (((status: InviteStatus) => void) | null)): void; /** * 发送消息 * @param {string} msg - 要发送的消息内容 * @param {string} to - 接收者智能体ID * @param {string} sessionId - 会话ID * @param {string} identifyingCode - 邀请码 */ send(msg: string, to: string, sessionId: string, identifyingCode: string): void; /** * 注册连接状态变更回调 * @param {function} cb - 状态变更回调函数 * @param {ConnectionStatus} cb.status - 连接状态 */ onStatusChange(cb: (status: ConnectionStatus) => void): void; /** * 注册消息接收回调 * @param {function} cb - 消息接收回调函数 * @param {any} cb.message - 接收到的消息 */ onMessage(cb: (message: any) => void): void; /** * 断开WebSocket连接 */ disconnect(): void; } export { IAgentCP, IAgentWS, IAgentIdentity, IConnectionConfig };