Template demos (Try it)
Status: Landed in #358 (merged 2026-10-03 into branch templates, stacked on #345; closes #312). Templates stack (#345 waves 1–2) merged to main 2026-10-04. Verified live on side env templates.
Plan of record: docs/plans/templates.md (Demo section). Shared wire shapes: @brilliant/service-contracts/demo.
A template is a shareable, installable snapshot of a published workspace. Try it opens a 30-minute demo of the latest ready version: sample data only, no real tenant, then the visitor can Install into their own tenant. Chat history and real app data are never copied.
Flow
- Visitor opens
/t/<slug>#k=<key>on the studio host (template-share SSR page; Try needs the fragment key). - Try posts Turnstile + key to the control plane → mints a version-bound demo JWT (
aud: brilliant-demo). - Browser lands on
demo.<studio domain>/<versionId>/(side envs:<dispatch>/demo/<versionId>/). - Dispatch swaps the query token for an HttpOnly cookie path-scoped to that version, injects a synthetic admin context + countdown / Install banner, and loads the demo script from the demos dispatch namespace.
- The template runtime has no D1; SQL goes over
HttpDatabaseAdaptertoservices/demo-data(one Durable Object per session), with onlyx-brilliant-demo-tokenforwarded.
Install from the demo (#486, merged 2026-10-05): Try opens the demo URL with the same #k=<key> fragment, and the banner's Install link points at the configured studio (DEMO_STUDIO_ORIGIN) /install/<slug> carrying that fragment, and the banner script wraps history.pushState / replaceState so same-origin client-router changes keep the fragment through reload. Without a whole 22-character key the link stays the keyless /t/<slug> page, labelled "Install: full link needed". Contract share-key-fragment-only-handoff. Details: Template & app data.
Limits: 3 starts per IP per hour, 50 live demos per template. Sessions last 30 minutes (DEMO_SESSION_SECONDS).
Pieces
| Piece | Path / binding | Role |
|---|---|---|
| Start / mint | apps/control-plane/src/templates/demo.ts | Turnstile + link key → demo JWT; rate limits |
| Share / Try UI | apps/template-share | /t/<slug> landing; Try button loads Turnstile |
| Demo host | services/dispatch src/demo/* | Cookie, banner, script load, ended / wrong-version pages |
| Demo script | Conductor publish step → WFP namespace brilliant-demos / brilliant-demos-stg | Name tpl-<versionId>; BRILLIANT_DEMO=1; no D1 |
| Session data | services/demo-data | One DO per sid; seed from sample data; ~10 MB cap; alarm wipe at expiry |
| Token / claims | packages/capabilities demo-token.ts + service-contracts/demo | HS256 with BRILLIANT_TOKEN_KEY; sid, ver, aud |
| Sample seed | Version snapshot + sample-data.ts | Owners rewritten to demo-<sid> so private-by-default collections show rows |
Published apps never load the demo module (dynamic import). User tokens are never accepted as demo tokens (and the reverse).
Origins and cookies
| Env | Demo origin |
|---|---|
| Staging / prod | demo.<studio domain>/ via Pulumi WorkersCustomDomain on dispatch (e.g. demo.app.brilliant.rocks once studio is app.…) |
| Side env | Dispatch workers.dev under /demo/<versionId>/ (DEMO_ORIGIN) |
cloudflare-ids must include cloudflare-ids.dispatchNamespaces.demos and origins.demo. The renderer fails closed without them.
Demos are a sibling subdomain of the studio, so cookie-authenticated writes with Sec-Fetch-Site: same-site or cross-site get 403 cross_site_write (control plane + admin). Helper: packages/capabilities cross-site-write.ts. Session cookies use __Host- (via #318); #400 (merged) stops accepting the unprefixed name over https so a sibling cannot plant brilliant_session either. See Control plane — Session cookie host-prefix. Header stripping in dispatch doesn't stop demo script writing document.cookie with Domain=<apex>, so #463 (merged 2026-10-05, part of #458) moves the OAuth login-flow cookies (brilliant_auth_state, brilliant_auth_return, brilliant_login_attr, brilliant_app_auth_state) to __Host- too, closing a login-CSRF path. Moving demos off the studio's registrable domain is a pending infra follow-up (#468). See Control plane — Login-flow cookies host-prefix.
Publish & retire
On each template version publish, the Workflow builds the demo bundle as a non-fatal step. When a newer version is ready, the previous demo script is retired 30 minutes later so in-flight sessions can finish. Old versionId URLs show that a newer version exists; expired tokens show the ended page; a token for another version is 410.
Share card (OG)
/t/<slug>/og.png captures a fresh sample-data demo session only when the page carries dispatch’s banner. Otherwise the card is text-only (never the owner’s real workspace thumbnails).
This OG path waits for data its own way (not conductor’s page-settled helper from #373). Unifying the two is #384. Workspace thumbs / /w/:id/screenshot settle behaviour: Conductor — Screenshots wait for data.
Infra & rollout (staging / prod)
Pulumi (infra/pulumi/src/demo.ts): demos dispatch namespace, demo.<studio> custom domain, Turnstile widget → secret brilliant/<env>/turnstile (TURNSTILE_SITE_KEY / TURNSTILE_SECRET, merged by secrets:push). Side envs use Cloudflare’s documented always-pass Turnstile test keys.
Order:
infra.yml(pulumi up) — namespace, domain, widget,dispatchNamespaces.demos,origins.demosecrets:push(TURNSTILE_*optional until step 1)- Deploy: demo-data → dispatch → template-share → conductor (template image changes) → control plane (
deploy.ymlruns demo-data before control plane)
Applied on the side-templates stack during development; templates stack is on main (2026-10-04) — staging/prod follow infra.yml / deploy order above.