//#region src/agent/tools/search/providers/bing-api.ts
/** Azure Bing Web Search API (global endpoint; works without a proxy from many regions). */
var BingApiProvider = class {
	name = "bing-api";
	constructor(apiKey) {
		this.apiKey = apiKey;
	}
	isAvailable() {
		return this.apiKey.length > 0;
	}
	async search(query, count, signal) {
		if (!this.isAvailable()) throw new Error("Bing Search API key not configured");
		const url = new URL("https://api.bing.microsoft.com/v7.0/search");
		url.searchParams.set("q", query);
		url.searchParams.set("count", String(Math.min(count, 50)));
		const response = await fetch(url, {
			headers: { "Ocp-Apim-Subscription-Key": this.apiKey },
			signal
		});
		if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
		return ((await response.json()).webPages?.value ?? []).map((r) => ({
			title: r.name ?? "",
			url: r.url ?? "",
			description: truncateDesc(r.snippet),
			source: this.name
		}));
	}
};
function truncateDesc(s) {
	if (!s) return "";
	if (s.length <= 400) return s;
	return `${s.slice(0, 400)}…`;
}
//#endregion
export { BingApiProvider };

//# sourceMappingURL=bing-api.js.map