fix(backend/copilot): drop encrypted_content from web_search snippet

Anthropic's web_search_result ships an opaque encrypted_content blob
meant for citation round-tripping, not display.  Using it as the
snippet surfaced base64 gibberish to the frontend and to the LLM.
There is no plain-text snippet field in the current beta; drop it
and rely on the model's text blocks with citations for prose.
This commit is contained in:
majdyz
2026-04-22 00:28:13 +07:00
parent 642b9c29c6
commit 1dfc75520d
2 changed files with 17 additions and 6 deletions

View File

@@ -183,13 +183,20 @@ def _extract_results(resp: Any, *, limit: int) -> tuple[list[WebSearchResult], i
continue
if len(results) >= limit:
break
# Anthropic's ``web_search_result`` exposes only
# ``title``/``url``/``page_age`` plus an opaque
# ``encrypted_content`` blob that is meant for citation
# round-tripping, not for display — it is base64-ish
# binary and would show as gibberish if surfaced to the
# model or the frontend. There is no plain-text snippet
# field in the current beta; callers get the readable
# text via the model's ``text`` blocks with citations,
# not via this list. Leave ``snippet`` empty.
results.append(
WebSearchResult(
title=getattr(item, "title", "") or "",
url=getattr(item, "url", "") or "",
snippet=getattr(item, "encrypted_content", None)
or getattr(item, "page_content", "")
or "",
snippet="",
page_age=getattr(item, "page_age", None),
)
)

View File

@@ -64,13 +64,17 @@ class TestExtractResults:
"""The extractor is the only Anthropic-response-shape contact point;
pin its behaviour so an API shape change surfaces here first."""
def test_extracts_title_url_snippet_and_page_age(self):
def test_extracts_title_url_page_age_and_drops_encrypted_snippet(self):
# Anthropic's ``web_search_result`` ships an opaque
# ``encrypted_content`` blob that is not safe to surface —
# the extractor must drop it (snippet=="") regardless of
# whether the blob is non-empty.
resp = _fake_anthropic_response(
results=[
{
"title": "Kimi K2.6 launch",
"url": "https://example.com/kimi",
"snippet": "Moonshot released K2.6 on 2026-04-20.",
"snippet": "EiJjbGF1ZGUtZW5jcnlwdGVkLWJsb2I=",
"page_age": "1 day",
},
{
@@ -85,7 +89,7 @@ class TestExtractResults:
assert len(out) == 2
assert out[0].title == "Kimi K2.6 launch"
assert out[0].url == "https://example.com/kimi"
assert out[0].snippet.startswith("Moonshot released")
assert out[0].snippet == ""
assert out[0].page_age == "1 day"
assert out[1].snippet == ""