UNPKG

acp-ws

Version:

基于 WebSocket 的智能体通信库,提供智能体身份管理和实时通信功能

37 lines (36 loc) 987 B
import { AgentCP } from './agentcp'; import { AgentWS } from './agentws'; class AgentManager { constructor() { this.agentCP = null; this.agentWS = null; } static getInstance() { if (!AgentManager.instance) { AgentManager.instance = new AgentManager(); } return AgentManager.instance; } initACP(apiUrl, seedPassword = "") { this.agentCP = new AgentCP(apiUrl, seedPassword); return this.agentCP; } initAWS(aid, config) { const { messageServer, messageSignature } = config; this.agentWS = new AgentWS(aid, messageServer, messageSignature); return this.agentWS; } acp() { if (!this.agentCP) { throw new Error("AgentCP未初始化"); } return this.agentCP; } aws() { if (!this.agentWS) { throw new Error("AgentWS未初始化"); } return this.agentWS; } } export { AgentManager };