import { WEB_SEARCH_TOOL_SCHEMA } from '@pellux/goodvibes-sdk/platform/tools/web-search/schema';
export function createWebSearchTool(service) {
    return {
        definition: {
            name: 'web_search',
            description: 'Search the web through a provider-backed search layer.'
                + ' Returns normalized ranked results, optional instant-answer data, and optional fetched evidence.',
            parameters: WEB_SEARCH_TOOL_SCHEMA,
            sideEffects: ['network'],
            concurrency: 'parallel',
            supportsProgress: true,
            supportsStreamingOutput: true,
        },
        async execute(args) {
            const query = typeof args.query === 'string' ? args.query.trim() : '';
            if (!query)
                return { success: false, error: 'Missing query' };
            const output = await service.search({
                query,
                ...(typeof args.providerId === 'string' ? { providerId: args.providerId } : {}),
                ...(typeof args.maxResults === 'number' ? { maxResults: args.maxResults } : {}),
                ...(typeof args.verbosity === 'string' ? { verbosity: args.verbosity } : {}),
                ...(typeof args.region === 'string' ? { region: args.region } : {}),
                ...(typeof args.safeSearch === 'string' ? { safeSearch: args.safeSearch } : {}),
                ...(typeof args.timeRange === 'string' ? { timeRange: args.timeRange } : {}),
                ...(typeof args.includeInstantAnswer === 'boolean' ? { includeInstantAnswer: args.includeInstantAnswer } : {}),
                ...(typeof args.includeEvidence === 'boolean' ? { includeEvidence: args.includeEvidence } : {}),
                ...(typeof args.evidenceTopN === 'number' ? { evidenceTopN: args.evidenceTopN } : {}),
                ...(typeof args.evidenceExtract === 'string' ? { evidenceExtract: args.evidenceExtract } : {}),
            });
            return { success: true, output: JSON.stringify(output) };
        },
    };
}
