fix(cas): restore in-widget PDF/document citation preview#110
Open
scottcmg wants to merge 1 commit into
Open
Conversation
Register a CitationClick pre-hook that fetches the auth-gated source document with the SDK token and previews it in-widget, instead of navigating to the ECS reference URL (which 401s on a plain open). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
📊 Coverage Report
|
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.
Problem
Clicking a document citation in the sources opened the source's reference URL in a new tab, which 401s — the URL is auth-gated and a plain navigation carries no bearer token. Document citations should open an in-widget preview instead.
Root cause
The widget registered no
CitationClickpre-hook, so the chat component fell back to its default behavior —window.open(download_url)— for document citations. That URL requires anAuthorizationheader the browser doesn't send.Fix
Register a
CitationClickpre-hook that intercepts document citations:citationFile.ts— fetches the download URL with the SDK's bearer token, wraps the response in a blob-backedFile, and falls back to an extension-based MIME type (the reference endpoint always returnsapplication/octet-stream). Resolves relative URLs against the SDK base URL; caches by URL (failures aren't cached).CitationPreviewDialog.tsx— renders the file via ablob:object URL:<iframe>for PDF/text (with#page=N),<img>for images, plus loading/error states and a download button. Object URLs are revoked on cleanup.ConversationalAgentChat.tsx— wires the pre-hook (via a ref so it always uses a fresh token). Document citations fetch + preview and returnfalse(suppressing the default open); URL citations returntrueand open normally. A race guard keys pending fetches to the clicked citation.i18n keys added to
en+keyslocales.Testing
citationFile.test.ts— bearer header, MIME fallback, relative-URL resolution, no-cache-on-failure.false); URL citation falls through (true).tscclean, production build succeeds.🤖 Generated with Claude Code