tfrere HF Staff Cursor commited on
Commit
27abbe5
·
1 Parent(s): 3afbbdf

feat(embed-studio): make agent-generated charts theme-aware

Browse files

The iframe already supports live light/dark swap via CSS variables and
a postMessage(setTheme) hot-swap, but the LLM kept generating charts
that hardcode colours into SVG attributes (fill="#333", stroke="black",
...). Those values can't be overridden by the parent's data-theme
attribute, so the chart looked correct on whatever theme the model
guessed and broken on the other one.

Two complementary fixes:

1. Forward the current theme (light/dark) from EmbedStudio through
useEmbedChat into the request context, and surface it in the
system prompt as a "Current theme" section. The model now knows
which background it's painting against and can self-correct.

2. Rewrite the "Colors & theming" section of the embed system prompt
with a concrete CSS pattern (scoped .d3-* rules driving fill/stroke
via var(--text-color), --axis-color, --grid-color, ...) and an
explicit ban on hardcoded SVG colour attributes. Add a hint about
window.__chartRerender for JS-driven palettes.

No public API change - the new context.theme field is opt-in and the
backend gracefully falls back to no theme block when it's missing.

Co-authored-by: Cursor <cursoragent@cursor.com>

4 files changed +100 -10
Files changed (4)
backend/src/agent/embed-chat.ts+3
backend/src/agent/embed-system-prompt.ts+82-8
frontend/src/components/EmbedStudio.tsx+1-1
frontend/src/hooks/useEmbedChat.ts+14-1