import { default as wiki } from "wikipedia";
const DEFAULT_META_DATA = {
    name: "wikipedia_tool",
    description: "A tool that uses a query engine to search Wikipedia.",
    parameters: {
        type: "object",
        properties: {
            query: {
                type: "string",
                description: "The query to search for"
            },
            lang: {
                type: "string",
                description: "The language to search in",
                nullable: true
            }
        },
        required: [
            "query"
        ]
    }
};
export class WikipediaTool {
    DEFAULT_LANG = "en";
    metadata;
    constructor(params){
        this.metadata = params?.metadata || DEFAULT_META_DATA;
    }
    async loadData(page, lang = this.DEFAULT_LANG) {
        wiki.default.setLang(lang);
        const pageResult = await wiki.default.page(page, {
            autoSuggest: false
        });
        const content = await pageResult.content();
        return content;
    }
    async call({ query, lang = this.DEFAULT_LANG }) {
        const searchResult = await wiki.default.search(query);
        if (searchResult.results.length === 0) return "No search results.";
        return await this.loadData(searchResult.results[0].title, lang);
    }
}
