Skip to content

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

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

Add UK chat integration (drawer on reports + standalone page)#1036
SakshiKekre wants to merge 6 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. Seeded with the report's scenario context so the assistant knows what the user is looking at.
  2. Alternative — banner CTA above the UK Reports table that takes the user to the chat as a full-page multizone child at `policyengine.org/uk/chat`.

Why two paths

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.

Supplement (drawer)

  • `ChatDrawer` component + trigger from `ReportActionButtons`
  • Scenario context composer in `ReportOutput.page.tsx` (UK-only)
  • Iframe with shared URL builder (`app/src/utils/chatUrl.ts`)

Alternative (multizone)

  • New entry in `website/src/data/appZoneRoutes.ts`: `/uk/chat → policyengine-uk-chat.vercel.app`
  • Banner CTA (`AskChatCta`) above the Reports table on UK only — tinted teal banner with sparkle icon and "New" badge
  • Banner navigates to the website host via `window.location.href` (calculator-app and website are separate Vercel projects)

Switched from an iframe page to a Vercel rewrite per CLAUDE.md guidance: cross-origin iframes blank out for Next.js apps (BAILOUT_TO_CLIENT_SIDE_RENDERING). Multizone is the convention used by every other zone app in this codebase.

Why combined PR

Both surfaces are part of the same product story ("uk-chat integrated into app-v2"). The supplement and alternative share the same chat backend, the same scenario-context plumbing on the chat side (uk-chat #51), and the same env-var setup. One PR keeps the integration story unified.

Follow-up: shell compliance

The chat app currently renders standalone — no PolicyEngine header/nav. The shell audit skips the chat destination for now. Tracked separately: ship a PolicyEngine-compliant header in the chat repo so the shell audit passes and the chat feels native at `policyengine.org/uk/chat`.

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. Must be scoped to Preview env (not just Production).

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 renders full-page
  • Navigate to /us/reports → banner does NOT render (UK-gated)
  • /uk/chat on the website preview serves the chat app (rewrite works)
  • Shell audit unit tests pass (`node --test .github/scripts/audit-app-zone-shell.test.mjs`)

Deferred

  • Shell compliance in the chat repo (follow-up PR)
  • US support (separate spike, uk-chat #54)
  • In-builder "Just ask" affordance
  • 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 Jun 2, 2026 4:56pm
policyengine-calculator Ready Ready Preview, Comment Jun 2, 2026 4:56pm
policyengine-calculator-next Ready Ready Preview, Comment Jun 2, 2026 4:56pm
policyengine-website Ready Ready Preview, Comment Jun 2, 2026 4:56pm

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.
The previous commit added /uk/chat as a Next.js page in the calculator app
embedding the chat via iframe. Per CLAUDE.md, cross-origin iframes are
broken-by-design for Next.js apps (BAILOUT_TO_CLIENT_SIDE_RENDERING
renders blank). Switching to a Vercel rewrite is the convention this
codebase already uses for every other zone app — see appZoneRoutes.ts.

What changes:
- Add /uk/chat → policyengine-uk-chat.vercel.app entry in appZoneRoutes.
- Delete the standalone iframe page (Chat.page.tsx, the Next.js wrapper,
  the Vite-router entry). Reports-page banner now navigates to the
  website host (policyengine.org/uk/chat) via window.location.href,
  which the rewrite serves directly.
- Skip the chat destination in the shell audit until the chat repo
  ships its own PolicyEngine-shell-compliant header. Tracked separately.

ChatDrawer (supplement) keeps using the chatUrl helper since it still
needs an iframe.
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