"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebSearchTool = void 0;
const zod_1 = require("zod");
const ai_1 = require("ai");
const travily_1 = require("../travily");
const webSearchToolInputSchema = zod_1.z.object({
    query: zod_1.z.string(),
    topic: zod_1.z.enum(["general", "news"]).describe("The category of the search.news is useful for retrieving real-time updates, particularly about politics, sports, and major current events covered by mainstream media sources. general is for broader, more general-purpose searches that may include a wide range of sources."),
    include_answer: zod_1.z.boolean().describe("Include an LLM-generated answer to the provided query. basic or true returns a quick answer. advanced returns a more detailed answer."),
    max_results: zod_1.z.number().default(5).describe("The maximum number of search results to return. Should be between 1 and 20."),
    time_range: zod_1.z.enum(["day", "week", "month", "year", "d", "w", "m", "y"]).default("day").describe("The time range back from the current date to filter results. Useful when looking for sources that have published data"),
    days: zod_1.z.number().default(7).describe("The number of days to look back for results. This is useful when looking for sources that have published data in the last few days."),
    search_depth: zod_1.z.enum(["basic", "advanced"]).default("basic").describe("The depth of the search. basic returns a quick answer. advanced returns a more detailed answer."),
});
class WebSearchTool {
    constructor() {
        this.travily = new travily_1.Travily();
        this.tool = (0, ai_1.tool)({
            description: "Search the web for information",
            inputSchema: webSearchToolInputSchema,
            execute: async (parameters) => {
                const searchParams = {
                    query: parameters.query,
                    topic: parameters.topic,
                    include_answer: parameters.include_answer,
                    max_results: parameters.max_results,
                    time_range: parameters.time_range,
                    days: parameters.days,
                    search_depth: parameters.search_depth,
                };
                return await this.travily.search(searchParams);
            },
        });
    }
}
exports.WebSearchTool = WebSearchTool;
