@hashgraphonline/standards-agent-kit
Version:
A modular SDK for building on-chain autonomous agents using Hashgraph Online Standards, including HCS-10 for agent discovery and communication. https://hol.org
176 lines (143 loc) • 7.15 kB
text/typescript
import { AIAgentCapability } from '@hashgraphonline/standards-sdk';
/**
* Valid input types for parsing tags or capabilities
*/
type ParseInput = string | number[] | string[] | AIAgentCapability[];
/**
* Maps natural language terms to AIAgentCapability enum values
*/
export class NaturalLanguageMapper {
private static readonly CAPABILITY_MAPPINGS: Record<string, AIAgentCapability[]> = {
'ai': [AIAgentCapability.TEXT_GENERATION],
'artificial intelligence': [AIAgentCapability.TEXT_GENERATION],
'chat': [AIAgentCapability.TEXT_GENERATION],
'conversation': [AIAgentCapability.TEXT_GENERATION],
'text': [AIAgentCapability.TEXT_GENERATION],
'text generation': [AIAgentCapability.TEXT_GENERATION],
'image': [AIAgentCapability.IMAGE_GENERATION],
'picture': [AIAgentCapability.IMAGE_GENERATION],
'visual': [AIAgentCapability.IMAGE_GENERATION],
'photo': [AIAgentCapability.IMAGE_GENERATION],
'audio': [AIAgentCapability.AUDIO_GENERATION],
'sound': [AIAgentCapability.AUDIO_GENERATION],
'voice': [AIAgentCapability.AUDIO_GENERATION],
'speech': [AIAgentCapability.AUDIO_GENERATION],
'video': [AIAgentCapability.VIDEO_GENERATION],
'movie': [AIAgentCapability.VIDEO_GENERATION],
'animation': [AIAgentCapability.VIDEO_GENERATION],
'code': [AIAgentCapability.CODE_GENERATION],
'programming': [AIAgentCapability.CODE_GENERATION],
'development': [AIAgentCapability.CODE_GENERATION],
'coding': [AIAgentCapability.CODE_GENERATION],
'translate': [AIAgentCapability.LANGUAGE_TRANSLATION],
'translation': [AIAgentCapability.LANGUAGE_TRANSLATION],
'language': [AIAgentCapability.LANGUAGE_TRANSLATION],
'summarize': [AIAgentCapability.SUMMARIZATION_EXTRACTION],
'summary': [AIAgentCapability.SUMMARIZATION_EXTRACTION],
'extract': [AIAgentCapability.SUMMARIZATION_EXTRACTION],
'extraction': [AIAgentCapability.SUMMARIZATION_EXTRACTION],
'knowledge': [AIAgentCapability.KNOWLEDGE_RETRIEVAL],
'search': [AIAgentCapability.KNOWLEDGE_RETRIEVAL],
'retrieve': [AIAgentCapability.KNOWLEDGE_RETRIEVAL],
'lookup': [AIAgentCapability.KNOWLEDGE_RETRIEVAL],
'data': [AIAgentCapability.DATA_INTEGRATION],
'data processing': [AIAgentCapability.DATA_INTEGRATION],
'data integration': [AIAgentCapability.DATA_INTEGRATION],
'etl': [AIAgentCapability.DATA_INTEGRATION],
'market': [AIAgentCapability.MARKET_INTELLIGENCE],
'trading': [AIAgentCapability.MARKET_INTELLIGENCE],
'finance': [AIAgentCapability.MARKET_INTELLIGENCE],
'financial': [AIAgentCapability.MARKET_INTELLIGENCE],
'analytics': [AIAgentCapability.TRANSACTION_ANALYTICS],
'analysis': [AIAgentCapability.TRANSACTION_ANALYTICS],
'analyze': [AIAgentCapability.TRANSACTION_ANALYTICS],
'transactions': [AIAgentCapability.TRANSACTION_ANALYTICS],
'audit': [AIAgentCapability.SMART_CONTRACT_AUDIT],
'contract': [AIAgentCapability.SMART_CONTRACT_AUDIT],
'smart contract': [AIAgentCapability.SMART_CONTRACT_AUDIT],
'governance': [AIAgentCapability.GOVERNANCE_FACILITATION],
'voting': [AIAgentCapability.GOVERNANCE_FACILITATION],
'dao': [AIAgentCapability.GOVERNANCE_FACILITATION],
'security': [AIAgentCapability.SECURITY_MONITORING],
'monitoring': [AIAgentCapability.SECURITY_MONITORING],
'threat': [AIAgentCapability.SECURITY_MONITORING],
'compliance': [AIAgentCapability.COMPLIANCE_ANALYSIS],
'regulatory': [AIAgentCapability.COMPLIANCE_ANALYSIS],
'regulation': [AIAgentCapability.COMPLIANCE_ANALYSIS],
'fraud': [AIAgentCapability.FRAUD_DETECTION],
'detection': [AIAgentCapability.FRAUD_DETECTION],
'anomaly': [AIAgentCapability.FRAUD_DETECTION],
'coordination': [AIAgentCapability.MULTI_AGENT_COORDINATION],
'multi-agent': [AIAgentCapability.MULTI_AGENT_COORDINATION],
'orchestration': [AIAgentCapability.MULTI_AGENT_COORDINATION],
'api': [AIAgentCapability.API_INTEGRATION],
'integration': [AIAgentCapability.API_INTEGRATION],
'webhook': [AIAgentCapability.API_INTEGRATION],
'workflow': [AIAgentCapability.WORKFLOW_AUTOMATION],
'automation': [AIAgentCapability.WORKFLOW_AUTOMATION],
'process': [AIAgentCapability.WORKFLOW_AUTOMATION],
};
/**
* Parse natural language text and extract capability values
*/
static parseCapabilities(text: string): AIAgentCapability[] {
if (!text) {return [AIAgentCapability.TEXT_GENERATION];}
const normalizedText = text.toLowerCase();
const capabilities = new Set<AIAgentCapability>();
for (const [term, caps] of Object.entries(this.CAPABILITY_MAPPINGS)) {
if (normalizedText.includes(term)) {
caps.forEach(cap => capabilities.add(cap));
}
}
if (capabilities.size === 0) {
capabilities.add(AIAgentCapability.TEXT_GENERATION);
}
return Array.from(capabilities);
}
/**
* Parse tags/capabilities from various input formats
*/
static parseTagsOrCapabilities(input: ParseInput): AIAgentCapability[] {
if (Array.isArray(input) && input.every(item => typeof item === 'number')) {
return input;
}
if (Array.isArray(input) && input.every(item => typeof item === 'string')) {
const capabilities = new Set<AIAgentCapability>();
input.forEach(term => {
this.parseCapabilities(term).forEach(cap => capabilities.add(cap));
});
return Array.from(capabilities);
}
if (typeof input === 'string') {
return this.parseCapabilities(input);
}
return [AIAgentCapability.TEXT_GENERATION];
}
/**
* Convert capability enum to human-readable name
*/
static getCapabilityName(capability: AIAgentCapability): string {
const names: Record<AIAgentCapability, string> = {
[]: 'Text Generation',
[]: 'Image Generation',
[]: 'Audio Generation',
[]: 'Video Generation',
[]: 'Code Generation',
[]: 'Language Translation',
[]: 'Summarization & Extraction',
[]: 'Knowledge Retrieval',
[]: 'Data Integration',
[]: 'Market Intelligence',
[]: 'Transaction Analytics',
[]: 'Smart Contract Audit',
[]: 'Governance Facilitation',
[]: 'Security Monitoring',
[]: 'Compliance Analysis',
[]: 'Fraud Detection',
[]: 'Multi-Agent Coordination',
[]: 'API Integration',
[]: 'Workflow Automation',
};
return names[capability] || 'Unknown Capability';
}
}