UNPKG

@vooodooo/magic

Version:

Vooodooo - AI orchestration platform

106 lines 3.83 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlanSystem = void 0; exports.createPlanSystem = createPlanSystem; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); /** * System for managing planning templates and generation */ class PlanSystem { constructor(templatesDir) { this.templates = new Map(); this.templatesDir = templatesDir || path_1.default.resolve(process.cwd(), 'templates/plans'); this.loadTemplates(); } /** * Load all templates from the templates directory */ loadTemplates() { try { // Check if templates directory exists if (!fs_1.default.existsSync(this.templatesDir)) { console.warn(`Templates directory not found: ${this.templatesDir}`); return; } // Get all JSON files in the directory const templateFiles = fs_1.default.readdirSync(this.templatesDir) .filter(file => file.endsWith('.json') || file.endsWith('.md')); // Load each template for (const file of templateFiles) { try { const filePath = path_1.default.join(this.templatesDir, file); const content = fs_1.default.readFileSync(filePath, 'utf8'); // Generate template ID from filename const id = path_1.default.basename(file, path_1.default.extname(file)); // Store template this.templates.set(id, { id, name: id.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase()), content }); } catch (error) { console.error(`Error loading template ${file}:`, error); } } console.log(`Loaded ${this.templates.size} plan templates`); } catch (error) { console.error('Error loading templates:', error); } } /** * Get all available templates */ getTemplates() { return Array.from(this.templates.values()); } /** * Get a template by ID */ getTemplate(id) { return this.templates.get(id); } /** * Generate a plan from a template */ generatePlan(options) { try { // Get template const template = this.templates.get(options.templateId); if (!template) { throw new Error(`Template not found: ${options.templateId}`); } // Replace placeholders let content = template.content; for (const [key, value] of Object.entries(options.values)) { const placeholder = `{${key}}`; content = content.replace(new RegExp(placeholder, 'g'), value); } // Ensure directory exists const dir = path_1.default.dirname(options.outputPath); if (!fs_1.default.existsSync(dir)) { fs_1.default.mkdirSync(dir, { recursive: true }); } // Write plan fs_1.default.writeFileSync(options.outputPath, content, 'utf8'); console.log(`Generated plan: ${options.outputPath}`); } catch (error) { console.error('Error generating plan:', error); throw error; } } } exports.PlanSystem = PlanSystem; /** * Create a plan system */ function createPlanSystem(templatesDir) { return new PlanSystem(templatesDir); } //# sourceMappingURL=plan-system.js.map