fix(web-search): fix empty snippets in Brave LLM Context mode

Brave's /res/v1/llm/context endpoint returns snippets as plain strings,
not { text: string } objects. The existing code applied .map(s => s.text)
which accessed .text on strings (returning undefined), causing all
snippets to be filtered out.

Update the type definition and snippet extraction to handle plain strings
directly.

Fixes #41370
This commit is contained in:
770120041
2026-03-09 15:26:59 -04:00
committed by Ayaan Zaidi
parent 1720174757
commit 07f43dbfb1

View File

@@ -272,8 +272,7 @@ type BraveSearchResponse = {
};
};
type BraveLlmContextSnippet = { text: string };
type BraveLlmContextResult = { url: string; title: string; snippets: BraveLlmContextSnippet[] };
type BraveLlmContextResult = { url: string; title: string; snippets: string[] };
type BraveLlmContextResponse = {
grounding: { generic?: BraveLlmContextResult[] };
sources?: { url?: string; hostname?: string; date?: string }[];
@@ -1481,7 +1480,7 @@ async function runBraveLlmContextSearch(params: {
const mapped = genericResults.map((entry) => ({
url: entry.url ?? "",
title: entry.title ?? "",
snippets: (entry.snippets ?? []).map((s) => s.text ?? "").filter(Boolean),
snippets: (entry.snippets ?? []).filter((s) => typeof s === "string" && s.length > 0),
siteName: resolveSiteName(entry.url) || undefined,
}));