export const calculatorTool = {
    name: 'calculator',
    description: 'Perform mathematical calculations. Input should be a valid mathematical expression.',
    parameters: {
        type: 'object',
        properties: {
            expression: {
                type: 'string',
                description: 'Mathematical expression to evaluate (e.g., "2 + 2", "sqrt(16)", "10 * 5")',
            },
        },
        required: ['expression'],
    },
    execute: async (args) => {
        try {
            const sanitized = args.expression.replace(/[^0-9+\-*/().\s]/g, '');
            const result = Function(`"use strict"; return (${sanitized})`)();
            return { result, expression: args.expression };
        }
        catch (error) {
            return { error: `Invalid expression: ${error.message}`, expression: args.expression };
        }
    },
};
export const webSearchTool = {
    name: 'web_search',
    description: 'Search the web for information. Requires a search API key to be configured.',
    parameters: {
        type: 'object',
        properties: {
            query: {
                type: 'string',
                description: 'Search query',
            },
        },
        required: ['query'],
    },
    execute: async (args) => {
        return {
            error: 'Web search not configured. Add a search API key to enable this tool.',
            query: args.query
        };
    },
};
export const currentTimeTool = {
    name: 'get_current_time',
    description: 'Get the current date and time in ISO format.',
    parameters: {
        type: 'object',
        properties: {},
        required: [],
    },
    execute: async () => {
        return {
            time: new Date().toISOString(),
            timestamp: Date.now(),
            timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
        };
    },
};
export const fileReadTool = {
    name: 'read_file',
    description: 'Read the contents of a file. Only works with files in allowed directories.',
    parameters: {
        type: 'object',
        properties: {
            path: {
                type: 'string',
                description: 'Path to the file to read',
            },
        },
        required: ['path'],
    },
    execute: async (args) => {
        return {
            error: 'File reading not implemented. Requires secure file system access.',
            path: args.path,
        };
    },
};
export const toolRegistry = {
    calculator: calculatorTool,
    web_search: webSearchTool,
    get_current_time: currentTimeTool,
    read_file: fileReadTool,
};
export function getTool(name) {
    return toolRegistry[name];
}
export function listTools() {
    return Object.values(toolRegistry);
}
export async function executeTool(toolName, args) {
    const tool = getTool(toolName);
    if (!tool) {
        throw new Error(`Tool not found: ${toolName}`);
    }
    return await tool.execute(args);
}
export function formatToolsForOpenAI(tools) {
    return tools.map(tool => ({
        type: 'function',
        function: {
            name: tool.name,
            description: tool.description,
            parameters: tool.parameters,
        },
    }));
}
//# sourceMappingURL=tools.js.map