Skip to content

Add "Ask a follow-up" chat drawer on report pages#1036

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

Add "Ask a follow-up" chat drawer on report pages#1036
SakshiKekre wants to merge 3 commits into
mainfrom
feat/report-chat-drawer

Conversation

@SakshiKekre
Copy link
Copy Markdown
Collaborator

@SakshiKekre SakshiKekre commented May 13, 2026

Summary

  • New ChatDrawer component embeds policyengine-uk-chat as an iframe inside a Sheet.
  • New icon button in ReportActionButtons opens the drawer.
  • ReportOutputLayout exposes an opt-in chatScenarioContext prop; when set, the button renders and the chat is seeded with the report's scenario.

How seeding works

The drawer constructs the iframe URL with two query params:

  • scenario_context=<plain-English summary> — the chat reads this on mount and forwards it to its /chat/message backend, where it lands in the system prompt after the cache breakpoints (so it doesn't bust the prompt cache).
  • model_backend=uk_python — pins the chat to the Python engine, the same one PE-API uses, so numerical answers are comparable to the report.

This depends on the chat-side scenario_context support in policyengine-uk-chat#51. Until that merges, the drawer still works — the chat just won't pick up the context.

Try it

Set NEXT_PUBLIC_UK_CHAT_ORIGIN to a chat preview URL when running locally:

NEXT_PUBLIC_UK_CHAT_ORIGIN=https://policyengine-uk-chat-git-feat-model-backend-selector-policy-engine.vercel.app bun run dev

Then pass any non-empty chatScenarioContext to a ReportOutputLayout instance — the button appears.

Not in scope here

  • Wiring callers of ReportOutputLayout to actually compose a chatScenarioContext from real report data — that's the next PR (per-report-type formatter).
  • Auth-sharing with the chat. The iframe runs anonymously for now.

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 13, 2026 9:32am
policyengine-calculator Ready Ready Preview, Comment May 13, 2026 9:32am
policyengine-calculator-next Ready Ready Preview, Comment May 13, 2026 9:32am
policyengine-website Ready Ready Preview, Comment May 13, 2026 9:32am

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>
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