//#region src/agent/tools/search/providers/brave.ts
var BraveProvider = class {
	name = "brave";
	constructor(apiKey) {
		this.apiKey = apiKey;
	}
	isAvailable() {
		return this.apiKey.length > 0;
	}
	async search(query, count, signal) {
		if (!this.isAvailable()) throw new Error("Brave Search API key not configured");
		const url = `https://api.search.brave.com/res/v1/web/search?q=${encodeURIComponent(query)}&count=${count}`;
		const response = await fetch(url, {
			headers: {
				"X-Subscription-Token": this.apiKey,
				Accept: "application/json"
			},
			signal
		});
		if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
		return ((await response.json()).web?.results ?? []).map((r) => ({
			title: r.title ?? "",
			url: r.url ?? "",
			description: truncateDesc(r.description),
			source: this.name
		}));
	}
};
function truncateDesc(s) {
	if (!s) return "";
	if (s.length <= 400) return s;
	return `${s.slice(0, 400)}…`;
}
//#endregion
export { BraveProvider };

//# sourceMappingURL=brave.js.map