sf-agent-framework
Version:
AI Agent Orchestration Framework for Salesforce Development - Two-phase architecture with 70% context reduction
167 lines (144 loc) • 3.8 kB
JavaScript
/**
* Simulation Module for SF-Agent Framework
* Main entry point for simulation functionality
*/
const SimulationEngine = require('./simulation-engine');
const PersonaEngine = require('./persona-engine');
const ProgressTracker = require('./progress-tracker');
const VisualizationEngine = require('./visualization-engine');
// Singleton instance
let simulationInstance = null;
/**
* Get or create simulation engine instance
*/
function getSimulationEngine(options = {}) {
if (!simulationInstance) {
simulationInstance = new SimulationEngine(options);
}
return simulationInstance;
}
/**
* Initialize simulation with configuration
*/
async function initializeSimulation(config = {}) {
const engine = getSimulationEngine(config);
await engine.initialize();
return engine;
}
/**
* Integration helper for orchestrators
*/
class OrchestratorSimulation {
constructor(orchestratorId, options = {}) {
this.orchestratorId = orchestratorId;
this.engine = getSimulationEngine(options);
this.initialized = false;
}
/**
* Initialize simulation for orchestrator
*/
async initialize() {
if (!this.initialized) {
await this.engine.initialize();
this.initialized = true;
}
}
/**
* Start workflow with simulation
*/
async startWorkflow(workflowData, teamData) {
await this.initialize();
// Generate workflow ID
const workflowId = `${this.orchestratorId}-${Date.now()}`;
// Start simulation parallel to actual work
const simulation = await this.engine.startSimulation(workflowId, workflowData, teamData);
return {
workflowId,
simulation,
updateProgress: (data) => this.updateProgress(workflowId, data),
complete: () => this.completeWorkflow(workflowId),
error: (err) => this.handleError(workflowId, err),
};
}
/**
* Update progress from actual work
*/
updateProgress(workflowId, progressData) {
this.engine.updateActualProgress(workflowId, progressData);
}
/**
* Complete workflow
*/
completeWorkflow(workflowId) {
this.engine.updateActualProgress(workflowId, {
progress: 100,
status: 'complete',
});
}
/**
* Handle error
*/
handleError(workflowId, error) {
this.engine.updateActualProgress(workflowId, {
error: error.message || error,
status: 'error',
});
}
/**
* Check if simulation is enabled
*/
isEnabled() {
return this.engine.isEnabled();
}
/**
* Toggle simulation
*/
toggle(enabled) {
this.engine.toggleSimulation(enabled);
}
}
/**
* Command handler for simulation control
*/
class SimulationCommands {
constructor() {
this.engine = getSimulationEngine();
}
/**
* Handle simulation-related commands
*/
async handleCommand(command, args) {
switch (command) {
case 'simulation-on':
this.engine.toggleSimulation(true);
return 'Simulation enabled';
case 'simulation-off':
this.engine.toggleSimulation(false);
return 'Simulation disabled';
case 'simulation-status':
return {
enabled: this.engine.isEnabled(),
activeSimulations: this.engine.activeSimulations.size,
visualizationType: this.engine.options.visualizationType,
};
case 'simulation-visual':
if (args[0]) {
this.engine.options.visualizationType = args[0]; // ascii, text, or none
return `Visualization set to: ${args[0]}`;
}
return 'Please specify: ascii, text, or none';
default:
return null;
}
}
}
module.exports = {
SimulationEngine,
PersonaEngine,
ProgressTracker,
VisualizationEngine,
OrchestratorSimulation,
SimulationCommands,
getSimulationEngine,
initializeSimulation,
};