UNPKG

tlnt

Version:

TLNT - HMS-Powered Multi-Agent Platform with Government Agency Analysis, Deep Research, and Enterprise-Ready Deployment. Self-optimizing multi-domain AI agent with continuous learning and enterprise-grade performance monitoring.

387 lines 15.1 kB
/** * HMS-Powered Agent Hub * * Enhanced AgentHub that uses HMS-NET and HMS-NFO APIs instead of local LLM keys * Provides full agent orchestration, data processing, and research capabilities */ import { EventEmitter } from 'events'; import HMSIntegratedClient from '../services/hmsIntegratedClient.js'; export class HMSAgentHub extends EventEmitter { skills = new Map(); telemetrySpans = new Map(); hmsClient; config; initialized = false; startTime = Date.now(); constructor(config) { super(); this.setMaxListeners(100); // Default configuration with production URLs this.config = { hms: { hmsNet: { baseURL: process.env.HMS_NET_URL || 'https://kädəfī.com', apiKey: process.env.HMS_NET_API_KEY, timeout: 30000, }, hmsNfo: { baseURL: process.env.HMS_NFO_URL || 'https://kōdəfī.com', apiKey: process.env.HMS_NFO_API_KEY, timeout: 30000, }, }, fallbackToMock: true, enableTelemetry: true, ...config, }; this.hmsClient = new HMSIntegratedClient(this.config.hms); } async initialize() { if (this.initialized) return; console.log('🚀 Initializing HMS-powered Agent Hub...'); try { // Check HMS system health const health = await this.hmsClient.healthCheck(); console.log(`HMS-NET: ${health.hmsNet.available ? '✅' : '❌'} ${health.hmsNet.status}`); console.log(`HMS-NFO: ${health.hmsNfo.available ? '✅' : '❌'} ${health.hmsNfo.status}`); console.log(`Integrated: ${health.integrated ? '✅' : '❌'}`); if (!health.integrated && !this.config.fallbackToMock) { throw new Error('HMS systems unavailable and fallback disabled'); } // Register HMS-enhanced skills await this.registerHMSSkills(); this.initialized = true; this.emit('initialized'); console.log('✅ HMS Agent Hub initialized successfully'); } catch (error) { console.error('❌ HMS Agent Hub initialization failed:', error); if (this.config.fallbackToMock) { console.log('🔄 Falling back to mock skills...'); await this.registerMockSkills(); this.initialized = true; this.emit('initialized'); } else { throw error; } } } async registerHMSSkills() { // Enhanced chat skill using HMS APIs this.register({ name: 'chat', description: 'HMS-powered chat with integrated research and agent orchestration', version: '2.0.0', async run(ctx, args) { const { prompt, includeResearch, agentType } = args; try { const request = { prompt, context: ctx.metadata, agentType: agentType || 'general', includeResearch: includeResearch || false, }; const response = await ctx.hmsClient.chat(request); return { success: true, data: response.response, metadata: { agentUsed: response.agentUsed, processingTime: response.processingTime, confidence: response.confidence, researchContext: response.researchContext, hmsEnabled: true, }, }; } catch (error) { return { success: false, error: { message: `HMS chat failed: ${error instanceof Error ? error.message : String(error)}`, code: 'HMS_CHAT_ERROR', }, }; } }, }); // Agency analysis skill this.register({ name: 'analyze-agency', description: 'Government agency issue analysis with HMS integration', version: '2.0.0', async run(ctx, args) { const { agencyName, issueTopic, state, agencyType, createWorkflow } = args; try { const result = await ctx.hmsClient.analyzeAgency(agencyName, issueTopic, { state, agencyType, createWorkflow: createWorkflow || false, }); return { success: true, data: { analysis: result.analysis, recommendations: result.recommendations, hmsComponents: result.hmsComponents, workflowId: result.workflowId, }, metadata: { agencyName, issueTopic, state, hmsEnabled: true, }, }; } catch (error) { return { success: false, error: { message: `Agency analysis failed: ${error instanceof Error ? error.message : String(error)}`, code: 'HMS_AGENCY_ERROR', }, }; } }, }); // Deep research skill this.register({ name: 'deep-research', description: 'CoRT-powered deep research with HMS-NFO integration', version: '2.0.0', async run(ctx, args) { const { topic, depth, breadth, createAgent } = args; try { const result = await ctx.hmsClient.performDeepResearch(topic, { depth: depth || 3, breadth: breadth || 5, createAgent: createAgent || false, }); return { success: true, data: { research: result.research, insights: result.insights, sources: result.sources, agentId: result.agentId, }, metadata: { topic, depth: depth || 3, breadth: breadth || 5, hmsEnabled: true, }, }; } catch (error) { return { success: false, error: { message: `Deep research failed: ${error instanceof Error ? error.message : String(error)}`, code: 'HMS_RESEARCH_ERROR', }, }; } }, }); // System status skill const startTime = this.startTime; this.register({ name: 'system-status', description: 'HMS system status and health monitoring', version: '2.0.0', async run(ctx, args) { try { const status = await ctx.hmsClient.getSystemStatus(); const health = await ctx.hmsClient.healthCheck(); return { success: true, data: { health: health.integrated ? 'healthy' : 'degraded', hmsNet: health.hmsNet, hmsNfo: health.hmsNfo, agents: status.agents, workflows: status.workflows, etlStatus: status.etlStatus, uptime: Math.round((Date.now() - startTime) / 1000), }, metadata: { timestamp: new Date().toISOString(), hmsEnabled: true, }, }; } catch (error) { return { success: false, error: { message: `System status check failed: ${error instanceof Error ? error.message : String(error)}`, code: 'HMS_STATUS_ERROR', }, }; } }, }); } async registerMockSkills() { console.log('⚠️ Registering mock skills (HMS unavailable)'); this.register({ name: 'chat', description: 'Mock chat functionality (HMS fallback)', version: '1.0.0-mock', async run(ctx, args) { const { prompt } = args; const response = `Mock Response: ${prompt}\n\n⚠️ This is a fallback response. HMS services are currently unavailable. The full HMS integration would provide:\n\n• Agent orchestration via HMS-NET\n• Data processing and ETL via HMS-NFO\n• Deep research with CoRT analysis\n• Government agency analysis\n• Real-time collaboration capabilities\n\nPlease check HMS system status or configure HMS endpoints.`; return { success: true, data: response, metadata: { model: 'mock', hmsEnabled: false, fallback: true, }, }; }, }); const startTime = this.startTime; this.register({ name: 'system-status', description: 'Mock system status', version: '1.0.0-mock', async run() { return { success: true, data: { health: 'mock', hmsNet: { available: false, status: 'unavailable' }, hmsNfo: { available: false, status: 'unavailable' }, agents: 0, workflows: 0, uptime: Math.round((Date.now() - startTime) / 1000), }, metadata: { hmsEnabled: false, fallback: true, }, }; }, }); } register(skill) { this.skills.set(skill.name, skill); this.emit('skillRegistered', skill); } async execute(skillName, context, args) { const skill = this.skills.get(skillName); if (!skill) { return { success: false, error: { message: `Skill '${skillName}' not found`, code: 'SKILL_NOT_FOUND', }, }; } // Create HMS-enhanced context const hmsContext = { ...context, hmsClient: this.hmsClient, }; // Start telemetry if enabled const spanId = this.config.enableTelemetry ? this.startTelemetrySpan(skillName, args) : undefined; try { const result = await skill.run(hmsContext, args); if (spanId) { this.endTelemetrySpan(spanId, result); } return result; } catch (error) { const errorResult = { success: false, error: { message: error instanceof Error ? error.message : String(error), code: 'SKILL_EXECUTION_ERROR', }, }; if (spanId) { this.endTelemetrySpan(spanId, errorResult); } return errorResult; } } async healthCheck() { try { const hmsHealth = await this.hmsClient.healthCheck(); const systemStatus = await this.hmsClient.getSystemStatus(); const status = hmsHealth.integrated ? 'healthy' : (hmsHealth.hmsNet.available || hmsHealth.hmsNfo.available) ? 'degraded' : 'unhealthy'; return { status, hmsNet: hmsHealth.hmsNet.available, hmsNfo: hmsHealth.hmsNfo.available, integrated: hmsHealth.integrated, details: { skillCount: this.skills.size, uptime: Math.round((Date.now() - this.startTime) / 1000), lastCheck: new Date().toISOString(), agents: systemStatus.agents, workflows: systemStatus.workflows, }, }; } catch (error) { return { status: 'unhealthy', hmsNet: false, hmsNfo: false, integrated: false, details: { skillCount: this.skills.size, uptime: Math.round((Date.now() - this.startTime) / 1000), lastCheck: new Date().toISOString(), agents: 0, workflows: 0, }, }; } } listSkills() { return Array.from(this.skills.values()).map(skill => ({ name: skill.name, description: skill.description, version: skill.version, })); } startTelemetrySpan(skillName, args) { const spanId = `span_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; const span = { spanId, skillName, startTime: Date.now(), args, }; this.telemetrySpans.set(spanId, span); return spanId; } endTelemetrySpan(spanId, result) { const span = this.telemetrySpans.get(spanId); if (span) { span.endTime = Date.now(); span.duration = span.endTime - span.startTime; span.success = result.success; span.result = result; this.emit('telemetry', span); this.telemetrySpans.delete(spanId); } } // Direct access to HMS client for advanced operations get hms() { return this.hmsClient; } } export default HMSAgentHub; //# sourceMappingURL=hmsAgentHub.js.map