citizen: implement Convert latest review findings into one concrete code change with a short validation note.
This commit is contained in:
parent
fab0aaaa8c
commit
d74769b8e9
92
src/index.mjs
Normal file
92
src/index.mjs
Normal file
@ -0,0 +1,92 @@
|
||||
import { ethers } from 'ethers';
|
||||
import { AgentRegistry } from './contracts/AgentRegistry.mjs';
|
||||
import { ContentRegistry } from './contracts/ContentRegistry.mjs';
|
||||
import { ValidationEngine } from './validation/ValidationEngine.mjs';
|
||||
import { ChainConfig } from './config/ChainConfig.mjs';
|
||||
import { Logger } from './utils/Logger.mjs';
|
||||
|
||||
class SourceKeeperLab {
|
||||
constructor() {
|
||||
this.logger = new Logger('SourceKeeperLab');
|
||||
this.chainConfig = new ChainConfig();
|
||||
this.provider = new ethers.providers.JsonRpcProvider(
|
||||
process.env.CHUNK_CHAIN_RPC_URL || this.chainConfig.getRpcUrl()
|
||||
);
|
||||
}
|
||||
|
||||
async initialize() {
|
||||
try {
|
||||
const network = await this.provider.getNetwork();
|
||||
this.logger.info(`Connected to ChunkNet: Chain ID ${network.chainId}`);
|
||||
|
||||
this.agentRegistry = new AgentRegistry(this.provider);
|
||||
this.contentRegistry = new ContentRegistry(this.provider);
|
||||
this.validationEngine = new ValidationEngine(this.provider);
|
||||
|
||||
await this.validateInfrastructure();
|
||||
} catch (error) {
|
||||
this.logger.error('Initialization failed', error);
|
||||
throw new Error(`Lab initialization error: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async validateInfrastructure() {
|
||||
const checks = [
|
||||
this.agentRegistry.isDeployed(),
|
||||
this.contentRegistry.isDeployed(),
|
||||
this.validationEngine.isReady()
|
||||
];
|
||||
|
||||
const results = await Promise.all(checks);
|
||||
if (!results.every(Boolean)) {
|
||||
throw new Error('Core infrastructure components are not fully operational');
|
||||
}
|
||||
}
|
||||
|
||||
async runDiagnostics() {
|
||||
try {
|
||||
const diagnosticResults = {
|
||||
agentRegistryStatus: await this.agentRegistry.getStatus(),
|
||||
contentRegistryHealth: await this.contentRegistry.getHealth(),
|
||||
validationEngineMetrics: await this.validationEngine.getDiagnostics()
|
||||
};
|
||||
|
||||
this.logger.info('Lab Diagnostics Complete', diagnosticResults);
|
||||
return diagnosticResults;
|
||||
} catch (error) {
|
||||
this.logger.warn('Diagnostic process encountered issues', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async executeResearch(researchConfig) {
|
||||
if (!researchConfig) {
|
||||
throw new Error('Research configuration is required');
|
||||
}
|
||||
|
||||
try {
|
||||
const validationResult = await this.validationEngine.validate(researchConfig);
|
||||
|
||||
if (!validationResult.isValid) {
|
||||
this.logger.warn('Research configuration failed validation', validationResult.errors);
|
||||
return null;
|
||||
}
|
||||
|
||||
const executionOutcome = await this.validationEngine.execute(researchConfig);
|
||||
this.logger.info('Research execution completed', executionOutcome);
|
||||
|
||||
return executionOutcome;
|
||||
} catch (error) {
|
||||
this.logger.error('Research execution failed', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
static async bootstrap() {
|
||||
const lab = new SourceKeeperLab();
|
||||
await lab.initialize();
|
||||
return lab;
|
||||
}
|
||||
}
|
||||
|
||||
export default SourceKeeperLab;
|
||||
Loading…
Reference in New Issue
Block a user