fix(deep-dive): extract citations from metadata.citedPages#103
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
metadata.citedPages[]{url, title}on thecompleteSSE event — not as a top-levelcitationsarray.extractCitationsonly checkeddata.citations, so the Citations section in the Deep Dive report was always empty even when the report text contained[1][2][3]markers.extractCitationsinlib/tabstack/research.tsnow falls back tometadata.citedPageswhendata.citationsis absent/empty, mappingurl→source_urlandtitle→claim.extractResult/extractCitationsimplementations fromapp/api/deep-dive/route.tsand imports the canonical versions fromresearch.tsinstead.Test plan
[1][2][3]inline markersnpm run typecheckpasses