//#region src/agent/tools/search/providers/searxng.ts
var SearXNGProvider = class {
	name = "searxng";
	constructor(baseUrl) {
		this.baseUrl = baseUrl;
	}
	isAvailable() {
		return this.baseUrl.length > 0;
	}
	async search(query, count, signal) {
		if (!this.isAvailable()) throw new Error("SearXNG base URL not configured");
		const url = new URL("search", ensureTrailingSlashOrigin(this.baseUrl));
		url.searchParams.set("q", query);
		url.searchParams.set("format", "json");
		url.searchParams.set("categories", "general");
		const response = await fetch(url, { signal });
		if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
		return ((await response.json()).results ?? []).slice(0, count).map((r) => ({
			title: r.title ?? "",
			url: r.url ?? "",
			description: truncateDesc(r.content),
			source: this.name
		}));
	}
};
function ensureTrailingSlashOrigin(base) {
	try {
		return new URL(base).toString().replace(/\/?$/, "/");
	} catch {
		return base.endsWith("/") ? base : `${base}/`;
	}
}
function truncateDesc(s) {
	if (!s) return "";
	if (s.length <= 400) return s;
	return `${s.slice(0, 400)}…`;
}
//#endregion
export { SearXNGProvider };

//# sourceMappingURL=searxng.js.map