UNPKG

@wavequery/conductor

Version:
62 lines 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseTool = void 0; const events_1 = require("events"); const tool_config_1 = require("@/types/schemas/tool-config"); class BaseTool extends events_1.EventEmitter { constructor(config) { super(); this.validateConfig(config); this.config = config; this.metadata = { name: config.name, description: config.description, version: config.version, author: config.author, }; } get name() { return this.config.name; } get description() { return this.config.description; } get input() { return this.config.input; } validateConfig(config) { try { tool_config_1.toolConfigSchema.parse(config); } catch (error) { throw new Error(`Invalid tool configuration: ${error.message}`); } } createContext() { return { sessionId: Math.random().toString(36).substring(7), timestamp: new Date(), }; } async executeWithRetry(fn, maxRetries = this.config.limits?.maxRetries || 3) { let lastError; for (let attempt = 1; attempt <= maxRetries; attempt++) { try { return await fn(); } catch (error) { lastError = error; this.emit("retry", { attempt, error, tool: this.name }); if (attempt < maxRetries) { await this.delay(Math.pow(2, attempt) * 1000); // Exponential backoff } } } throw lastError; } delay(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); } } exports.BaseTool = BaseTool; //# sourceMappingURL=base-tool.js.map