Skip to content

fix(deep-dive): extract citations from metadata.citedPages#103

Merged
tessak22 merged 3 commits into
mainfrom
fix/deep-dive-citations
May 30, 2026
Merged

fix(deep-dive): extract citations from metadata.citedPages#103
tessak22 merged 3 commits into
mainfrom
fix/deep-dive-citations

Conversation

@tessak22

Copy link
Copy Markdown
Owner

Summary

  • The Tabstack API returns sources as metadata.citedPages[]{url, title} on the complete SSE event — not as a top-level citations array. extractCitations only checked data.citations, so the Citations section in the Deep Dive report was always empty even when the report text contained [1][2][3] markers.
  • extractCitations in lib/tabstack/research.ts now falls back to metadata.citedPages when data.citations is absent/empty, mapping urlsource_url and titleclaim.
  • Removes the duplicate extractResult / extractCitations implementations from app/api/deep-dive/route.ts and imports the canonical versions from research.ts instead.

Test plan

  • Run a Deep Dive on any competitor — Citations section should now appear below the report with numbered sources matching the [1][2][3] inline markers
  • Verify each citation shows the page title as the claim and links to the source URL
  • npm run typecheck passes

tessak22 added 3 commits May 29, 2026 19:26
The Tabstack API returns sources as metadata.citedPages[]{url, title}
on the complete event, not as a top-level citations array. extractCitations
was only checking data.citations so always returned [].

Also removes the duplicate extractResult/extractCitations functions from
the deep-dive route and imports the canonical versions from research.ts.
- Extract isSafeHttpUrl helper to deduplicate URL validation logic
- Make metadata.citedPages the primary citation source (what the API
  actually returns) and data.citations the forward-compat fallback
- Drop explicit source_text: undefined in citedPages path (field is optional)
- Remove dead local ResearchCitation type from route.ts
- Add 4 tests covering citedPages extraction, claim/title fallback,
  priority over data.citations, and URL safety filtering
…e invalid

If every citedPages entry fails URL validation, the previous code returned []
immediately without checking the data.citations fallback. Now only returns
from the citedPages branch when at least one valid citation is extracted.
@tessak22 tessak22 merged commit cdeb885 into main May 30, 2026
1 of 2 checks passed
@tessak22 tessak22 deleted the fix/deep-dive-citations branch May 30, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant