//#region src/agent/tools/search/providers/tavily.ts
var TavilyProvider = class {
	name = "tavily";
	constructor(apiKey) {
		this.apiKey = apiKey;
	}
	isAvailable() {
		return this.apiKey.length > 0;
	}
	async search(query, count, signal) {
		if (!this.isAvailable()) throw new Error("Tavily API key not configured");
		const response = await fetch("https://api.tavily.com/search", {
			method: "POST",
			headers: { "Content-Type": "application/json" },
			body: JSON.stringify({
				api_key: this.apiKey,
				query,
				max_results: count,
				search_depth: "basic"
			}),
			signal
		});
		if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
		return ((await response.json()).results ?? []).map((r) => ({
			title: r.title ?? "",
			url: r.url ?? "",
			description: truncateDesc(r.content),
			source: this.name
		}));
	}
};
function truncateDesc(s) {
	if (!s) return "";
	if (s.length <= 400) return s;
	return `${s.slice(0, 400)}…`;
}
//#endregion
export { TavilyProvider };

//# sourceMappingURL=tavily.js.map