mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 13:20:43 +00:00
feat(searxng): pass through image result urls
This commit is contained in:
@@ -39,6 +39,53 @@ describe("searxng client", () => {
|
||||
).toEqual([{ title: "One", url: "https://example.com/1", content: "A" }]);
|
||||
});
|
||||
|
||||
it("preserves img_src from image search results", () => {
|
||||
expect(
|
||||
__testing.parseSearxngResponseText(
|
||||
JSON.stringify({
|
||||
results: [
|
||||
{
|
||||
title: "Kitten",
|
||||
url: "https://example.com/kitten",
|
||||
content: "A cute kitten",
|
||||
img_src: "https://cdn.example.com/kitten.jpg",
|
||||
},
|
||||
{
|
||||
title: "No Image",
|
||||
url: "https://example.com/text",
|
||||
content: "Text only",
|
||||
},
|
||||
{
|
||||
title: "Bad Image",
|
||||
url: "https://example.com/bad",
|
||||
img_src: { url: "https://cdn.example.com/bad.jpg" },
|
||||
},
|
||||
],
|
||||
}),
|
||||
10,
|
||||
),
|
||||
).toEqual([
|
||||
{
|
||||
title: "Kitten",
|
||||
url: "https://example.com/kitten",
|
||||
content: "A cute kitten",
|
||||
img_src: "https://cdn.example.com/kitten.jpg",
|
||||
},
|
||||
{
|
||||
title: "No Image",
|
||||
url: "https://example.com/text",
|
||||
content: "Text only",
|
||||
img_src: undefined,
|
||||
},
|
||||
{
|
||||
title: "Bad Image",
|
||||
url: "https://example.com/bad",
|
||||
content: undefined,
|
||||
img_src: undefined,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("drops malformed result rows instead of failing the whole response", () => {
|
||||
expect(
|
||||
__testing.parseSearxngResponseText(
|
||||
|
||||
@@ -40,6 +40,7 @@ type SearxngResult = {
|
||||
url: string;
|
||||
title: string;
|
||||
content?: string;
|
||||
img_src?: string;
|
||||
};
|
||||
|
||||
type SearxngResponse = {
|
||||
@@ -51,7 +52,12 @@ function normalizeSearxngResult(value: unknown): SearxngResult | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
const candidate = value as { url?: unknown; title?: unknown; content?: unknown };
|
||||
const candidate = value as {
|
||||
url?: unknown;
|
||||
title?: unknown;
|
||||
content?: unknown;
|
||||
img_src?: unknown;
|
||||
};
|
||||
if (typeof candidate.url !== "string" || typeof candidate.title !== "string") {
|
||||
return null;
|
||||
}
|
||||
@@ -60,6 +66,7 @@ function normalizeSearxngResult(value: unknown): SearxngResult | null {
|
||||
url: candidate.url,
|
||||
title: candidate.title,
|
||||
content: typeof candidate.content === "string" ? candidate.content : undefined,
|
||||
img_src: typeof candidate.img_src === "string" ? candidate.img_src : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -254,6 +261,7 @@ export async function runSearxngSearch(params: {
|
||||
url: result.url,
|
||||
snippet: result.content ? wrapWebContent(result.content, "web_search") : "",
|
||||
siteName: resolveSiteName(result.url) || undefined,
|
||||
img_src: result.img_src || undefined,
|
||||
})),
|
||||
} satisfies Record<string, unknown>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user