UNPKG

@wavequery/conductor

Version:
58 lines 1.71 kB
import { EventEmitter } from "events"; import { toolConfigSchema } from "@/types/schemas/tool-config"; export class BaseTool extends 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 { 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)); } } //# sourceMappingURL=base-tool.js.map