UNPKG

snow-flow

Version:

Snow-Flow v3.2.0: Complete ServiceNow Enterprise Suite with 180+ MCP Tools. ATF Testing, Knowledge Management, Service Catalog, Change Management with CAB scheduling, Virtual Agent chatbots with NLU, Performance Analytics KPIs, Flow Designer automation, A

227 lines โ€ข 7.75 kB
"use strict"; /** * Base Agent Class * Common functionality for all ServiceNow specialist agents */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseAgent = void 0; const queen_memory_1 = require("../queen/queen-memory"); const crypto = __importStar(require("crypto")); class BaseAgent { constructor(config) { this.messageQueue = []; this.id = config.id || this.generateAgentId(config.type); this.type = config.type; this.status = 'idle'; this.capabilities = config.capabilities; this.mcpTools = config.mcpTools; this.debugMode = config.debugMode || false; // Initialize memory system this.memory = new queen_memory_1.QueenMemorySystem(config.memoryPath); if (this.debugMode) { console.log(`๐Ÿค– ${this.type} agent initialized with ID: ${this.id}`); } } /** * Validate agent can handle the task * Can be overridden by specific agents */ async canHandle(instruction) { // Default implementation checks if instruction mentions agent capabilities const lowerInstruction = instruction.toLowerCase(); return this.capabilities.some(capability => lowerInstruction.includes(capability.toLowerCase().split(' ')[0])); } /** * Store artifact in shared memory for other agents */ async storeArtifact(artifact) { const key = `artifact_${artifact.type}_${artifact.name}`; await this.memory.storeInContext(key, artifact); if (this.debugMode) { console.log(`๐Ÿ“ฆ Stored artifact: ${key}`); } } /** * Retrieve artifact from shared memory */ async getArtifact(type, name) { const key = `artifact_${type}_${name}`; return await this.memory.getFromContext(key); } /** * Report progress to Queen Agent */ async reportProgress(message, percentage) { const progressKey = `progress_${this.id}`; await this.memory.storeInContext(progressKey, { agentId: this.id, agentType: this.type, message, percentage, timestamp: new Date() }); if (this.debugMode) { console.log(`๐Ÿ“Š ${this.type}: ${message} (${percentage}%)`); } } /** * Send message to another agent */ sendMessage(to, type, content) { const message = { from: this.id, to, type, content, timestamp: new Date() }; // Store in shared memory for recipient const messageKey = `message_${to}_${Date.now()}`; this.memory.storeInContext(messageKey, message); if (this.debugMode) { console.log(`๐Ÿ“จ Message sent from ${this.id} to ${to}: ${type}`); } } /** * Retrieve messages for this agent */ async getMessages() { const _messagePrefix = `message_${this.id}_`; const messages = []; // This is a simplified implementation // In a real system, we'd query the memory system more efficiently return messages; } /** * Handle coordination with other agents */ async coordinateWith(agentType, request) { const coordinationKey = `coordination_${this.id}_${agentType}_${Date.now()}`; await this.memory.storeInContext(coordinationKey, { from: this.id, toType: agentType, request, timestamp: new Date() }); // Wait for response (simplified) const responseKey = `${coordinationKey}_response`; let attempts = 0; while (attempts < 30) { // 30 second timeout const response = await this.memory.getFromContext(responseKey); if (response) { return response; } await new Promise(resolve => setTimeout(resolve, 1000)); attempts++; } throw new Error(`Coordination timeout with ${agentType}`); } /** * Log activity for learning */ async logActivity(action, success, details) { const learningKey = `agent_activity_${this.type}_${action}`; await this.memory.storeLearning(learningKey, JSON.stringify({ agentId: this.id, action, success, details, timestamp: new Date() }), success ? 0.9 : 0.3); } /** * Update agent status */ setStatus(status) { this.status = status; const statusKey = `agent_status_${this.id}`; this.memory.storeInContext(statusKey, { agentId: this.id, status, timestamp: new Date() }); } /** * Check if agent should work with another agent */ shouldCoordinate(otherAgentType) { // Define coordination rules // Simplified coordination rules after flow-builder removal const coordinationRules = { 'researcher': ['script-writer', 'researcher'], 'script-writer': ['tester', 'app-architect'], 'widget-creator': ['researcher', 'ui-ux-specialist'], 'app-architect': ['script-writer', 'integration-specialist'], 'tester': ['script-writer', 'security-specialist'], 'integration-specialist': ['app-architect', 'script-writer'] }; return coordinationRules[this.type]?.includes(otherAgentType) || false; } /** * Generate unique agent ID */ generateAgentId(type) { const timestamp = Date.now().toString(36); const random = crypto.randomBytes(4).toString('hex'); return `${type}_${timestamp}_${random}`; } /** * Get agent information */ getInfo() { return { id: this.id, type: this.type, status: this.status, capabilities: this.capabilities, mcpTools: this.mcpTools, task: this.task }; } /** * Cleanup agent resources */ async cleanup() { // Clean up any resources this.messageQueue = []; this.status = 'idle'; if (this.debugMode) { console.log(`๐Ÿงน ${this.type} agent ${this.id} cleaned up`); } } } exports.BaseAgent = BaseAgent; //# sourceMappingURL=base-agent.js.map