import { runInRequestScope, getRequestScope } from '../core/request-scope.js';
export async function handleSearch(ctx, searchEngine, config) {
    const searchOptions = ctx.body;
    const { toolRules, ...cleanOptions } = searchOptions;
    const executeSearch = async () => {
        const results = await searchEngine.search(cleanOptions, ctx.userId, ctx.auth, config.discovery.scopeFiltering);
        return { results };
    };
    if (toolRules && !getRequestScope()?.toolRules) {
        return runInRequestScope({ toolRules }, executeSearch);
    }
    return executeSearch();
}
export async function handleSearchQuery(ctx, searchEngine, config) {
    const query = ctx.query.query || ctx.query.keyword || '';
    const results = await searchEngine.search({ query }, ctx.userId, ctx.auth, config.discovery.scopeFiltering);
    return { results };
}
//# sourceMappingURL=search.handler.js.map