UNPKG

@meldscience/meld

Version:

pipeable one-shot prompt scripting toolkit

54 lines 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Oneshotcat = void 0; const oneshot_1 = require("./oneshot"); const meld_1 = require("./meld"); const anthropic_1 = require("./providers/anthropic"); const config_1 = require("./config"); const fs_1 = require("fs"); const errors_1 = require("./errors"); class Oneshotcat { constructor(options) { this.options = options; } async process() { // Check if input file exists if (!(0, fs_1.existsSync)(this.options.inputFile)) { throw new errors_1.ToolError(`Input file not found: ${this.options.inputFile}`, 'FILE_NOT_FOUND'); } // Process the prompt script const { content: processedContent, errors } = await (0, meld_1.processMeldFile)({ inputPath: this.options.inputFile, workspacePath: process.cwd() }); // Create a temporary file for the processed content const tempFile = '.temp-oneshot-expanded.md'; (0, fs_1.writeFileSync)(tempFile, processedContent); // If there are errors, include them in the output if (errors.length > 0) { const errorContent = errors.map(error => `Error: ${error}`).join('\n'); (0, fs_1.writeFileSync)(tempFile, processedContent + '\n\n' + errorContent); } // Load config and create provider const config = (0, config_1.loadConfig)(); const provider = new anthropic_1.AnthropicProvider(config.anthropicApiKey || ''); // Then send to AI const oneshot = new oneshot_1.Oneshot({ model: this.options.model || 'claude-3', promptFile: tempFile, system: this.options.system, systemFile: this.options.systemFile }, provider); const responses = await oneshot.process(); // Clean up temp file (0, fs_1.unlinkSync)(tempFile); // Format response to match expected structure return responses.map(({ variation, systemPrompt, response }) => ({ variation, systemPrompt, response })); } } exports.Oneshotcat = Oneshotcat; //# sourceMappingURL=oneshotcat.js.map