* 初始化 Agent 和所有管理器
()
| 105 | * 初始化 Agent 和所有管理器 |
| 106 | */ |
| 107 | public async init(): Promise<void> { |
| 108 | if (this.isInitialized) { |
| 109 | throw new Error('Agent 已经初始化'); |
| 110 | } |
| 111 | |
| 112 | if (this.isDestroyed) { |
| 113 | throw new Error('Agent 已被销毁,无法重新初始化'); |
| 114 | } |
| 115 | |
| 116 | this.log('初始化 Agent...'); |
| 117 | |
| 118 | try { |
| 119 | // 初始化 LLM 管理器 |
| 120 | if (this.config.llm) { |
| 121 | await this.llmManager.init(); |
| 122 | } |
| 123 | |
| 124 | // 初始化组件管理器 |
| 125 | await this.componentManager.init(); |
| 126 | |
| 127 | this.isInitialized = true; |
| 128 | this.log('Agent 初始化完成'); |
| 129 | this.emit('initialized'); |
| 130 | } catch (error) { |
| 131 | this.log(`初始化失败: ${error}`); |
| 132 | throw error; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * 销毁 Agent 和所有管理器 |
no test coverage detected