MCPcopy Create free account
hub / github.com/echoVic/blade-code / registerComponent

Method registerComponent

src/agent/ComponentManager.ts:117–140  ·  view source on GitHub ↗

* 注册组件

(component: BaseComponent)

Source from the content-addressed store, hash-verified

115 * 注册组件
116 */
117 public async registerComponent(component: BaseComponent): Promise<void> {
118 const id = component.getId();
119
120 if (this.components.has(id)) {
121 throw new Error(`组件 "${id}" 已存在`);
122 }
123
124 this.components.set(id, component);
125 this.log(`组件 "${id}" 已注册`);
126 this.emit('componentRegistered', { id, component });
127
128 // 如果管理器已初始化且启用自动初始化,立即初始化新组件
129 if (this.isInitialized && this.config.autoInit) {
130 try {
131 await component.init();
132 this.log(`组件 "${id}" 已自动初始化`);
133 this.emit('componentInitialized', { id, component });
134 } catch (error) {
135 this.log(`组件 "${id}" 自动初始化失败: ${error}`);
136 this.emit('componentInitializationFailed', { id, component, error: error as Error });
137 throw error;
138 }
139 }
140 }
141
142 /**
143 * 获取组件

Callers 2

registerComponentsMethod · 0.95

Calls 5

logMethod · 0.95
hasMethod · 0.80
setMethod · 0.80
emitMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected