Skip to content

fix(cas): restore in-widget PDF/document citation preview#110

Open
scottcmg wants to merge 1 commit into
developfrom
fix/citation-pdf-preview
Open

fix(cas): restore in-widget PDF/document citation preview#110
scottcmg wants to merge 1 commit into
developfrom
fix/citation-pdf-preview

Conversation

@scottcmg

@scottcmg scottcmg commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

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 CitationClick pre-hook, so the chat component fell back to its default behavior — window.open(download_url) — for document citations. That URL requires an Authorization header the browser doesn't send.

Fix

Register a CitationClick pre-hook that intercepts document citations:

  • citationFile.ts — fetches the download URL with the SDK's bearer token, wraps the response in a blob-backed File, and falls back to an extension-based MIME type (the reference endpoint always returns application/octet-stream). Resolves relative URLs against the SDK base URL; caches by URL (failures aren't cached).
  • CitationPreviewDialog.tsx — renders the file via a blob: 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 return false (suppressing the default open); URL citations return true and open normally. A race guard keys pending fetches to the clicked citation.

i18n keys added to en + keys locales.

Testing

  • citationFile.test.ts — bearer header, MIME fallback, relative-URL resolution, no-cache-on-failure.
  • Pre-hook behavior tests — document citation intercepted (false); URL citation falls through (true).
  • Full suite: 222/222 pass. tsc clean, production build succeeds.
  • Manually verified against a live PDF citation in the standalone chat service.

🤖 Generated with Claude Code

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>
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

📊 Coverage Report

Package Line Coverage
datatable 88.29%
multi-file-upload 87.27%
conversational-agent-chat 87.93%
validation-station 97.97%

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