Surface page and content-block citation regions from Anthropic - #1099
Conversation
citationAnnotations only built a text-span region for char_location citations, so page_location and content_block_location citations lost their region data (start/end page number and start/end block index respectively). Map all three location types to a text-span region, matching the Python client which builds a TextSpanRegion for each. Both the streaming and non-streaming paths route citations through this helper, so both benefit.
There was a problem hiding this comment.
🟢 Approval recommended
The changes and tests are complete with no unresolved review issues.
Pull request overview
Adds support for Anthropic page-based and content-block-based citation regions.
Changes:
- Maps page numbers and block indices to annotated regions.
- Adds tests for both citation types.
File summaries
| File | Description |
|---|---|
provider/anthropicprovider/agent.go |
Adds region mapping for page and content-block citations. |
provider/anthropicprovider/agent_test.go |
Tests the new citation region behavior. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Scope: user-visible behavior (bug fix; no exported API change)
|
Anthropic citations report the cited span in one of three ways depending on the source: character offsets (
char_location), PDF page numbers (page_location), or content-block indices (content_block_location).citationAnnotationsonly built aTextSpanAnnotatedRegionforchar_location, so page- and block-located citations arrived with no region data even though the SDKTextCitationUnionexposesStartPageNumber/EndPageNumberandStartBlockIndex/EndBlockIndex.This mirrors the Python client (
_parse_citations_from_anthropic), which builds aTextSpanRegionfor each of the three location types.Change
page_location(page numbers) andcontent_block_location(block indices) to a text-span region, alongside the existingchar_locationhandling.Both the streaming and non-streaming paths route citations through
citationAnnotations, so both are fixed.Tests
TestPageLocationCitationsBecomeAnnotatedRegionsandTestContentBlockLocationCitationsBecomeAnnotatedRegions: assert the region indices are surfaced. Both fail before the change (AnnotatedRegionsis nil), pass after.