fix(init): 确保 Registry 在服务启动时正确初始化
- AgentRegistry: 在构造函数中同步初始化预设 Agent - AgentRegistry: 添加 isInitialized() 方法 - initCore(): 添加 ProviderRegistry.init() 调用 - initCore(): 添加 AgentRegistry.init() 调用 修复用户配置(Provider、Agent)重启后丢失的问题
This commit is contained in:
@@ -13,23 +13,33 @@ export class AgentRegistry {
|
||||
private userConfig: AgentConfigFile | null = null;
|
||||
private initialized = false;
|
||||
|
||||
constructor() {
|
||||
// 同步初始化预设 Agent(无需等待 init())
|
||||
this.initPresetAgents();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化 - 加载预设和用户配置
|
||||
* 同步初始化预设 Agent
|
||||
*/
|
||||
private initPresetAgents(): void {
|
||||
for (const [name, agentConfig] of Object.entries(presetAgents)) {
|
||||
this.agents.set(name, { ...agentConfig, name });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 完整初始化 - 加载用户配置
|
||||
* 用户配置可以覆盖预设 Agent 的设置
|
||||
*/
|
||||
async init(workdir: string): Promise<void> {
|
||||
if (this.initialized) return;
|
||||
|
||||
// 1. 注册预设 Agent
|
||||
for (const [name, agentConfig] of Object.entries(presetAgents)) {
|
||||
this.agents.set(name, { ...agentConfig, name });
|
||||
}
|
||||
|
||||
// 2. 加载用户配置
|
||||
// 加载用户配置
|
||||
this.userConfig = await loadAgentConfig(workdir);
|
||||
if (this.userConfig) {
|
||||
this.globalConfig = this.userConfig.defaults ?? null;
|
||||
|
||||
// 注册用户自定义 Agent
|
||||
// 注册用户自定义 Agent(可以覆盖预设)
|
||||
if (this.userConfig.agents) {
|
||||
for (const [name, config] of Object.entries(this.userConfig.agents)) {
|
||||
this.agents.set(name, { ...config, name });
|
||||
@@ -40,6 +50,13 @@ export class AgentRegistry {
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否已完整初始化(包括用户配置)
|
||||
*/
|
||||
isInitialized(): boolean {
|
||||
return this.initialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Agent(应用权限合并)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user