refactor: 优化代码结构并修复类型问题
- 移除未使用的TabPane组件 - 修复类型定义和导入方式 - 优化mock数据源的环境变量判断逻辑 - 更新文档结构并归档旧文件 - 添加新的UI组件和Memo组件 - 调整API路径和响应处理
This commit is contained in:
@@ -1,40 +1,114 @@
|
||||
import { logger } from '../../utils/logger';
|
||||
import { FeatureGovernanceService } from '../governance/FeatureGovernanceService';
|
||||
import { SERVICE_CONFIGS, ServiceConfig } from '../../config/serviceConfig';
|
||||
|
||||
export interface DomainModule {
|
||||
name: string;
|
||||
priority: number;
|
||||
init: () => Promise<void>;
|
||||
isAgi?: boolean; // 是否属于重型 AGI 模块
|
||||
isAgi?: boolean;
|
||||
config?: ServiceConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* [ARCH_LIGHT_01] 领域注册中心 (Domain Registry)
|
||||
* @description 核心逻辑:解耦 index.ts 中的服务初始化,支持按优先级、按领域、按 AGI 降级策略进行加载。
|
||||
*/
|
||||
class ServiceStateManager {
|
||||
private static instance: ServiceStateManager;
|
||||
private enabledServices: Set<string>;
|
||||
private initializedServices: Set<string> = new Set();
|
||||
private failedServices: Map<string, string> = new Map();
|
||||
|
||||
private constructor() {
|
||||
this.enabledServices = new Set(
|
||||
SERVICE_CONFIGS.filter(s => s.enabled).map(s => s.name)
|
||||
);
|
||||
}
|
||||
|
||||
static getInstance(): ServiceStateManager {
|
||||
if (!this.instance) {
|
||||
this.instance = new ServiceStateManager();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
isEnabled(name: string): boolean {
|
||||
return this.enabledServices.has(name);
|
||||
}
|
||||
|
||||
enable(name: string): void {
|
||||
this.enabledServices.add(name);
|
||||
}
|
||||
|
||||
disable(name: string): void {
|
||||
this.enabledServices.delete(name);
|
||||
}
|
||||
|
||||
markInitialized(name: string): void {
|
||||
this.initializedServices.add(name);
|
||||
this.failedServices.delete(name);
|
||||
}
|
||||
|
||||
markFailed(name: string, error: string): void {
|
||||
this.failedServices.set(name, error);
|
||||
}
|
||||
|
||||
getStatus(): {
|
||||
enabled: string[];
|
||||
initialized: string[];
|
||||
failed: Map<string, string>;
|
||||
} {
|
||||
return {
|
||||
enabled: Array.from(this.enabledServices),
|
||||
initialized: Array.from(this.initializedServices),
|
||||
failed: new Map(this.failedServices),
|
||||
};
|
||||
}
|
||||
|
||||
getAllServices(): Array<{
|
||||
name: string;
|
||||
enabled: boolean;
|
||||
initialized: boolean;
|
||||
error?: string;
|
||||
config?: ServiceConfig;
|
||||
}> {
|
||||
return SERVICE_CONFIGS.map(config => ({
|
||||
name: config.name,
|
||||
enabled: this.enabledServices.has(config.name),
|
||||
initialized: this.initializedServices.has(config.name),
|
||||
error: this.failedServices.get(config.name),
|
||||
config,
|
||||
}));
|
||||
}
|
||||
|
||||
setEnabledServices(services: string[]): void {
|
||||
this.enabledServices = new Set(services);
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceStateManager = ServiceStateManager.getInstance();
|
||||
|
||||
export class DomainRegistry {
|
||||
private static modules: DomainModule[] = [];
|
||||
|
||||
/**
|
||||
* 注册领域模块
|
||||
*/
|
||||
static register(module: DomainModule) {
|
||||
this.modules.push(module);
|
||||
const config = SERVICE_CONFIGS.find(s => s.name === module.name);
|
||||
this.modules.push({ ...module, config });
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行全量初始化
|
||||
*/
|
||||
static async bootstrap(tenantId?: string) {
|
||||
// 1. 按优先级排序 (低值优先)
|
||||
const sortedModules = [...this.modules].sort((a, b) => a.priority - b.priority);
|
||||
|
||||
// 2. 检查 AGI 基础模式开关 (如果开启,则跳过重型 AGI 模块)
|
||||
const isAgiBaseMode = await FeatureGovernanceService.isEnabled('CORE_AGI_BASE_MODE', tenantId);
|
||||
|
||||
logger.info(`[DomainRegistry] Bootstrapping ${sortedModules.length} modules... (AGI Base Mode: ${isAgiBaseMode})`);
|
||||
const state = ServiceStateManager.getInstance();
|
||||
const enabledCount = sortedModules.filter(m => state.isEnabled(m.name)).length;
|
||||
|
||||
logger.info(`[DomainRegistry] Bootstrapping ${enabledCount}/${sortedModules.length} modules... (AGI Base Mode: ${isAgiBaseMode})`);
|
||||
|
||||
for (const module of sortedModules) {
|
||||
if (!state.isEnabled(module.name)) {
|
||||
logger.info(`[DomainRegistry] Skipping disabled module: ${module.name}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (module.isAgi && isAgiBaseMode) {
|
||||
logger.warn(`[DomainRegistry] Skipping Heavy AGI module: ${module.name} (Base Mode Active)`);
|
||||
continue;
|
||||
@@ -42,33 +116,47 @@ export class DomainRegistry {
|
||||
|
||||
try {
|
||||
await module.init();
|
||||
state.markInitialized(module.name);
|
||||
logger.info(`[DomainRegistry] Module initialized: ${module.name}`);
|
||||
} catch (err: any) {
|
||||
logger.error(`[DomainRegistry] Module ${module.name} failed to initialize: ${err.message}`);
|
||||
// 核心模块失败应抛出异常,非核心模块可继续
|
||||
if (module.priority < 10) throw err;
|
||||
} catch (err: unknown) {
|
||||
const errorMessage = err instanceof Error ? err.message : String(err);
|
||||
logger.error(`[DomainRegistry] Module ${module.name} failed to initialize: ${errorMessage}`);
|
||||
state.markFailed(module.name, errorMessage);
|
||||
if (module.priority < 10) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.info('✅ [DomainRegistry] Bootstrap completed successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 预定义优先级常量
|
||||
*/
|
||||
static Priority = {
|
||||
CORE_INFRA: 0, // 核心基础设施 (DB, Cache, Governance)
|
||||
SECURITY: 5, // 安全与身份 (Auth, DID, ZKP)
|
||||
RUNTIME: 10, // 运行时引擎 (AsyncEngine, PluginMgr)
|
||||
BIZ_DOMAIN: 20, // 业务领域 (Orders, Products, Trade)
|
||||
AGI_HEAVY: 50, // 重型 AGI (Evolution, RCA, XAI)
|
||||
SUPPORT: 100 // 辅助支撑 (Logistics, Tax, Sync)
|
||||
CORE_INFRA: 0,
|
||||
SECURITY: 5,
|
||||
RUNTIME: 10,
|
||||
BIZ_DOMAIN: 20,
|
||||
AGI_HEAVY: 50,
|
||||
SUPPORT: 100
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取所有已注册的领域模块
|
||||
*/
|
||||
static getDomains(): DomainModule[] {
|
||||
return [...this.modules];
|
||||
}
|
||||
|
||||
static getServiceStatus() {
|
||||
return ServiceStateManager.getInstance().getAllServices();
|
||||
}
|
||||
|
||||
static setEnabledServices(services: string[]): void {
|
||||
ServiceStateManager.getInstance().setEnabledServices(services);
|
||||
}
|
||||
|
||||
static enableService(name: string): void {
|
||||
ServiceStateManager.getInstance().enable(name);
|
||||
}
|
||||
|
||||
static disableService(name: string): void {
|
||||
ServiceStateManager.getInstance().disable(name);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user