import type { WebSearchResult } from '@/lib/types/web-search'; /** * Format search results into a markdown context block for LLM prompts. */ export function formatSearchResultsAsContext(result: WebSearchResult): string { if (!result.answer && result.sources.length === 0) { return ''; } const lines: string[] = []; if (result.answer) { lines.push(result.answer); lines.push(''); } if (result.sources.length > 0) { lines.push('Sources:'); for (const src of result.sources) { lines.push(`- [${src.title}](${src.url}): ${src.content.slice(0, 200)}`); } } return lines.join('\n'); }