Skip to content

Native AI theme editor on /sites/[id] (feature 3/3)#8

Draft
gndclouds wants to merge 1 commit into
mainfrom
cursor/native-ai-theme-editor
Draft

Native AI theme editor on /sites/[id] (feature 3/3)#8
gndclouds wants to merge 1 commit into
mainfrom
cursor/native-ai-theme-editor

Conversation

@gndclouds
Copy link
Copy Markdown
Member

Summary

Promotes the existing Anthropic-backed theme generator — which today only runs once during admin site creation — into a first-class native editor on every site's settings page. Owners can describe the look they want, the model returns a cohesive color + font palette, the tokens are written to the site, and a rebuild is queued automatically.

This is feature 3 of 3 from `docs/features.md`. Template consolidation is intentionally not in this PR (per the decision to skip archiving for now); only the AI editor ships here.

This PR does not depend on PRs 1 / 2 — it branches straight off main and can ship independently.

What changed

  • `src/app/api/sites/[id]/theme/ai/route.ts` — new owner-scoped POST. Reuses `generateAiSiteTheme()` and applies the same plan gate as the existing `/theme` PUT (admin / friend / pro / studio). With `apply: true` (default) it writes `themeColors` + `themeFonts` and queues `buildSite(id)` via `after()`.
  • `src/components/site-ai-theme-box.tsx` — prompt textarea + Apply button, inline error / "Applied · rebuild queued" feedback, and per-browser prompt history in localStorage (top 8). Clicking a previous prompt drops it back into the textarea for iteration ("the same, but darker").
  • `src/app/sites/[id]/page.tsx` — drops the AI box above the existing `theme.css` / `styles.css` editor on the Theme tab, so users can describe a vibe and then nudge the result by hand without leaving the page.

Why this shape

  • `docs/features.md` lists a "prompt history" question; this PR resolves it lightweight (per-browser localStorage) rather than adding a `themePromptHistory` JSON column. Easy to migrate to the DB later when it earns a feature.
  • Cost guardrail question is resolved by the plan gate — only paid plans (or admin/friend) reach the endpoint.
  • The AI does NOT propose custom CSS to end users in this PR (`generateAiSiteTheme` still returns it, but the editor surfaces only colors + fonts). Custom CSS is editable in the dedicated `styles.css` tab.

Test plan

  • As a Pro user, open the Theme tab on a site; AI box renders above the existing editor.
  • Type a vibe ("warm, serif, mid-century book"), click Apply → API returns 200, site updates, rebuild queued, theme.css editor below picks up the new values.
  • As a free user, AI box renders the upgrade hint instead of the input.
  • Without `ANTHROPIC_API_KEY`, endpoint returns 503 with `ai_unconfigured` — error shows inline in the box.
  • After applying, refresh the page: prompt history still listed; clicking an old prompt repopulates the textarea.

Open follow-ups (not in this PR)

  • Template consolidation (kept out per scoping decision).
  • Persisting prompt history on the site row in the DB so it follows the user across browsers.
  • Diff-mode AI prompts ("only change the body font").

Made with Cursor

Promotes the existing Anthropic-backed theme generator (previously admin-only,
used once on site create) into a first-class native editor on the site
settings page. Owners can iterate on their look by typing a prompt; the model
returns colors + fonts, the tokens are written to the site, and a rebuild is
queued — all in one round trip.

Changes
- src/app/api/sites/[id]/theme/ai/route.ts: owner-scoped POST. Reuses
  generateAiSiteTheme() but gates on the same plan rule as the existing
  /theme PUT (admin/friend/pro/studio). With `apply: true` (default) it
  writes themeColors/themeFonts and triggers buildSite() via after().
- src/components/site-ai-theme-box.tsx: prompt + apply UI, inline error +
  "Applied · rebuild queued" feedback, and a per-browser prompt history
  (localStorage, top 8) for iterative "the same, but darker" tweaks. No
  schema change in v1.
- src/app/sites/[id]/page.tsx: drops the AI box above the existing
  theme.css / styles.css editor on the Theme tab, so users can describe a
  vibe and then nudge the result by hand.

Template consolidation from docs/features.md is intentionally NOT in this
PR — leaving the existing template surface in place for now.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 11, 2026

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

Project Deployment Actions Updated (UTC)
tiny-garden Ready Ready Preview, Comment May 11, 2026 8:28pm

Request Review

@gndclouds
Copy link
Copy Markdown
Member Author

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