Files
wehub-resource-sync c48612c494
CI / E2E Tests (push) Has been cancelled
CI / Lint, Typecheck & Unit Tests (push) Has been cancelled
Docs Build / Build docs site (push) Has been cancelled
Publish @openmaic packages / Build, validate & publish (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:23 +08:00

27 lines
632 B
TypeScript

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');
}