/**
 * Miscellaneous Tool Adapters
 *
 * ITool-compliant adapters for BrowserTool and ReasoningTool operations.
 * These adapters wrap the existing tools to conform to the formal ITool
 * interface for use with the FormalToolRegistry.
 */
import { BrowserTool, ReasoningTool } from '../index.js';
// ============================================================================
// Shared Tool Instances
// ============================================================================
let browserInstance = null;
let reasoningInstance = null;
function getBrowser() {
    if (!browserInstance) {
        browserInstance = new BrowserTool();
    }
    return browserInstance;
}
function getReasoning() {
    if (!reasoningInstance) {
        reasoningInstance = new ReasoningTool();
    }
    return reasoningInstance;
}
/**
 * Reset the shared instances (for testing)
 */
export function resetMiscInstances() {
    browserInstance = null;
    reasoningInstance = null;
}
// ============================================================================
// BrowserExecuteTool
// ============================================================================
/**
 * BrowserExecuteTool - ITool adapter for browser automation
 */
export class BrowserExecuteTool {
    name = 'browser';
    description = 'Automate web browser interactions including navigation, clicking, form filling, and screenshots';
    async execute(input) {
        const params = {
            action: input.action,
            url: input.url,
            selector: input.selector,
            value: input.value,
            script: input.script,
            timeout: input.timeout,
            screenshotOptions: input.screenshotOptions,
            scrollOptions: input.scrollOptions,
        };
        return await getBrowser().execute(params);
    }
    getSchema() {
        return {
            name: this.name,
            description: this.description,
            parameters: {
                type: 'object',
                properties: {
                    action: {
                        type: 'string',
                        description: 'Browser action to perform',
                        enum: [
                            'navigate',
                            'click',
                            'fill',
                            'screenshot',
                            'getText',
                            'getHtml',
                            'evaluate',
                            'waitForSelector',
                            'getLinks',
                            'getForms',
                            'submit',
                            'select',
                            'hover',
                            'scroll',
                            'goBack',
                            'goForward',
                            'reload',
                            'close',
                        ],
                    },
                    url: {
                        type: 'string',
                        description: 'URL to navigate to (for navigate action)',
                    },
                    selector: {
                        type: 'string',
                        description: 'CSS selector for element operations',
                    },
                    value: {
                        type: 'string',
                        description: 'Value for fill/select operations',
                    },
                    script: {
                        type: 'string',
                        description: 'JavaScript code for evaluate action',
                    },
                    timeout: {
                        type: 'number',
                        description: 'Timeout in milliseconds',
                    },
                    screenshotOptions: {
                        type: 'object',
                        description: 'Options for screenshot action',
                    },
                    scrollOptions: {
                        type: 'object',
                        description: 'Options for scroll action',
                    },
                },
                required: ['action'],
            },
        };
    }
    validate(input) {
        if (typeof input !== 'object' || input === null) {
            return { valid: false, errors: ['Input must be an object'] };
        }
        const data = input;
        if (typeof data.action !== 'string' || data.action.trim() === '') {
            return { valid: false, errors: ['action must be a non-empty string'] };
        }
        const validActions = [
            'navigate',
            'click',
            'fill',
            'screenshot',
            'getText',
            'getHtml',
            'evaluate',
            'waitForSelector',
            'getLinks',
            'getForms',
            'submit',
            'select',
            'hover',
            'scroll',
            'goBack',
            'goForward',
            'reload',
            'close',
        ];
        if (!validActions.includes(data.action)) {
            return { valid: false, errors: [`Unknown action: ${data.action}`] };
        }
        return { valid: true };
    }
    getMetadata() {
        return {
            name: this.name,
            description: this.description,
            category: 'web',
            keywords: ['browser', 'web', 'automation', 'playwright', 'screenshot', 'scrape'],
            priority: 5,
            requiresConfirmation: true,
            modifiesFiles: false,
            makesNetworkRequests: true,
        };
    }
    isAvailable() {
        return true;
    }
    async dispose() {
        if (browserInstance) {
            await browserInstance.close();
            browserInstance = null;
        }
    }
}
// ============================================================================
// ReasoningExecuteTool
// ============================================================================
/**
 * ReasoningExecuteTool - ITool adapter for Tree-of-Thought reasoning
 */
export class ReasoningExecuteTool {
    name = 'reason';
    description = 'Solve complex problems using Tree-of-Thought reasoning (MCTS) for planning, analysis, and difficult algorithmic problems';
    async execute(input) {
        return await getReasoning().execute({
            problem: input.problem,
            context: input.context,
            mode: input.mode,
            constraints: input.constraints,
        });
    }
    getSchema() {
        return {
            name: this.name,
            description: this.description,
            parameters: {
                type: 'object',
                properties: {
                    problem: {
                        type: 'string',
                        description: 'The problem statement or question to solve',
                    },
                    context: {
                        type: 'string',
                        description: 'Additional context or background information',
                    },
                    mode: {
                        type: 'string',
                        description: 'Depth of reasoning (default: medium)',
                        enum: ['shallow', 'medium', 'deep', 'exhaustive'],
                    },
                    constraints: {
                        type: 'array',
                        description: 'List of constraints that must be satisfied',
                        items: { type: 'string' },
                    },
                },
                required: ['problem'],
            },
        };
    }
    validate(input) {
        if (typeof input !== 'object' || input === null) {
            return { valid: false, errors: ['Input must be an object'] };
        }
        const data = input;
        if (typeof data.problem !== 'string' || data.problem.trim() === '') {
            return { valid: false, errors: ['problem must be a non-empty string'] };
        }
        return { valid: true };
    }
    getMetadata() {
        return {
            name: this.name,
            description: this.description,
            category: 'utility',
            keywords: ['reasoning', 'mcts', 'tree-of-thought', 'problem-solving', 'planning'],
            priority: 4,
            modifiesFiles: false,
            makesNetworkRequests: true,
        };
    }
    isAvailable() {
        return true;
    }
}
// ============================================================================
// Factory Function
// ============================================================================
/**
 * Create all miscellaneous tool instances
 */
export function createMiscTools() {
    return [
        new BrowserExecuteTool(),
        new ReasoningExecuteTool(),
    ];
}
//# sourceMappingURL=misc-tools.js.map