Skip to content

Add UK chat integration (drawer on reports + standalone page)#1036

Open
SakshiKekre wants to merge 5 commits into
mainfrom
feat/report-chat-drawer
Open

Add UK chat integration (drawer on reports + standalone page)#1036
SakshiKekre wants to merge 5 commits into
mainfrom
feat/report-chat-drawer

Conversation

@SakshiKekre
Copy link
Copy Markdown
Collaborator

@SakshiKekre SakshiKekre commented May 13, 2026

What

Adds two surfaces for policyengine-uk-chat in app-v2:

  1. Supplement — "Ask a follow-up" drawer on UK report-output pages (the original PR). Seeded with the report's scenario context so the assistant knows what the user is looking at.
  2. Alternative — standalone `/uk/chat` page reachable from a banner CTA above the Reports table. For users who want to ask a policy question without building a report first.

Both surfaces share `buildChatUrl()` (in `app/src/utils/chatUrl.ts`) so the iframe URL / model_backend / Vercel bypass-token plumbing lives in one place.

What's in the diff

Supplement (already there from earlier commits):

  • `ChatDrawer` component + trigger from `ReportActionButtons`
  • Scenario context composer in `ReportOutput.page.tsx` (UK-only)

Alternative (new):

  • `Chat.page.tsx` — full-page chat iframe with a brief intro
  • `AskChatCta` — tinted banner with sparkle icon + "New" badge, sits above the Reports table on UK only
  • Route at `/:countryId/chat` (Vite `CalculatorRouter` + Next.js `calculator-app` wrapper)
  • Shared `chatUrl.ts` utility (refactored out of ChatDrawer)

Why two surfaces

The eval framing in uk-chat #52 treats supplement and alternative as two distinct product positionings. Shipping both lets us collect signal on which one users actually engage with — without committing to either as the canonical placement.

Preview / env

  • Frontend: Vercel preview deploy for this PR
  • Chat backend: `NEXT_PUBLIC_UK_CHAT_ORIGIN` env var; defaults to production chat. Point it at a uk-chat PR preview to demo against in-flight chat changes.
  • Bypass token: `NEXT_PUBLIC_UK_CHAT_BYPASS_TOKEN` if targeting a Vercel-protected preview.

Test plan

  • Open a UK report → drawer trigger renders → opens chat with scenario context
  • Navigate to /uk/reports → see banner CTA above table → click navigates to /uk/chat → chat iframe loads
  • Navigate to /us/reports → banner does NOT render (UK-gated)
  • Navigate to /us/chat directly → page renders but chat won't help on US queries (acceptable for now; backend doesn't model US)
  • Both surfaces hit the same chat origin via shared util

Deferred

  • US support — needs US chat backend (separate spike, uk-chat #54)
  • In-builder "Just ask" affordance — separate follow-up; touches the report builder surface
  • Nav-level Chat entry — wait for engagement signal first

Renders an icon button in ReportActionButtons that opens a Sheet
containing an iframe to policyengine-uk-chat. The chat receives the
report's scenario as a scenario_context URL param so the assistant
knows what report the user is looking at.

Opt-in: pass chatScenarioContext to ReportOutputLayout. Without it, no
button renders. Defaults to prod chat URL; override with
VITE_UK_CHAT_ORIGIN to point at a preview.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
policyengine-app-v2 Ready Ready Preview, Comment May 28, 2026 9:07pm
policyengine-calculator Ready Ready Preview, Comment May 28, 2026 9:07pm
policyengine-calculator-next Ready Ready Preview, Comment May 28, 2026 9:07pm
policyengine-website Ready Ready Preview, Comment May 28, 2026 9:07pm

Request Review

CI failures were from leaning on import.meta.env (Vite-only) in code
that's also built by Next.js for calculator-app. Switch to
NEXT_PUBLIC_UK_CHAT_ORIGIN — works in Next.js natively, no shim. Also
collapse the icon import to one line to satisfy prettier.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Composes a minimal scenario context (country, year, label, model/data
version) and passes it to ReportOutputLayout. Restricts to UK reports —
the chat backend doesn't model US policy. With this, the "Ask a
follow-up" button now actually renders on UK report pages.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When NEXT_PUBLIC_UK_CHAT_BYPASS_TOKEN is set, the iframe URL carries
the Vercel "Protection Bypass for Automation" secret so the embedded
chat preview deploy serves through deployment protection. samesitenone
on set-bypass-cookie is required for the cookie to flow on cross-origin
iframe requests. Empty / unset in production where the chat is public.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Complements the existing report-page drawer with the alternative positioning:
a full-page chat surface for users who want to ask without building a report.

- New shared util chatUrl.ts — buildChatUrl + iframe sandbox constant.
  Both ChatDrawer (supplement) and the new Chat.page (alternative) consume
  it so any URL/bypass-token tweak lives in one place.
- ChatDrawer refactored to use the shared util.
- New Chat.page renders the chat iframe full-height with a brief intro.
  Reachable at /:countryId/chat via both the Vite-era CalculatorRouter and
  the Next.js route wrapper in calculator-app.
- New AskChatCta — tinted banner with sparkle icon + "New" badge on
  Reports.page (UK-only). Sits above the table, doesn't compete with the
  primary "Create report" action.
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