
//#region src/live_search.ts
/**
* Merge search parameters from instance defaults, tool definition
* and per-call overrides.
*
* Precedence (lowest → highest):
*   1. tool-level configuration (e.g. from xaiLiveSearch)
*   2. instance-level defaults
*   3. per-call overrides passed via `searchParameters`
*/
function mergeSearchParams(instanceParams, callParams, toolParams) {
	if (!instanceParams && !callParams && !toolParams) return void 0;
	return {
		...toolParams ?? {},
		...instanceParams ?? {},
		...callParams ?? {}
	};
}
/**
* Build the `search_parameters` payload to send to the xAI API
* from high-level `XAISearchParameters`.
*/
function buildSearchParametersPayload(params) {
	if (!params) return void 0;
	const payload = { mode: params.mode ?? "auto" };
	if (params.max_search_results !== void 0) payload.max_search_results = params.max_search_results;
	if (params.from_date !== void 0) payload.from_date = params.from_date;
	if (params.to_date !== void 0) payload.to_date = params.to_date;
	if (params.return_citations !== void 0) payload.return_citations = params.return_citations;
	if (params.sources && params.sources.length > 0) payload.sources = params.sources;
	return payload;
}
/**
* Filter out xAI built-in tools (like `live_search`) from a tools array.
* Used before sending the request to the xAI API, since built-in tools
* are controlled via `search_parameters` instead.
*/
function filterXAIBuiltInTools(payload) {
	if (!payload?.tools) return void 0;
	const filtered = payload.tools.filter((tool) => {
		if (tool == null || typeof tool !== "object") return true;
		if (!("type" in tool)) return true;
		if (!payload?.excludedTypes?.length) return true;
		return !payload.excludedTypes.includes(tool.type);
	});
	return filtered.length > 0 ? filtered : void 0;
}

//#endregion
exports.buildSearchParametersPayload = buildSearchParametersPayload;
exports.filterXAIBuiltInTools = filterXAIBuiltInTools;
exports.mergeSearchParams = mergeSearchParams;
//# sourceMappingURL=live_search.cjs.map