Repository navigation
AC5: ai-chatbot becomes an Orun baseline - #6
Merged
Merged
Conversation
The repository is now a baseline on the Cloudflare + Supabase (Lumen) conventions, built the way cirrus-baseline v22 builds a product: in ONE landing, after saas-starter (SA5). - blueprint.yaml (the card): requires [github, cloudflare, supabase]; six brokered keys as a preview (CLOUDFLARE_API_TOKEN workers-deploy, CLOUDFLARE_HYPERDRIVE_TOKEN hyperdrive-edit, CLOUDFLARE_R2_TOKEN r2-data, CLOUDFLARE_ACCOUNT_ID account-id, SUPABASE_ACCESS_TOKEN management-access, SUPABASE_ORG_ID org-id); programme 01-product, 02-docs; two Supabase projects (stage and prod) stated as the owner's prerequisite. No model key: no platform brokers an AI vendor. - repo-blueprint.yaml: 01-product places every module, retouches, brands, re-tenants, strips the work tree, defers promotion and dev's push lanes, links, reconciles one key per hook and lands one PR; it awaits the convergence, SUPABASE_PROJECT_REF / _DB_PASSWORD / _DB_URL and WIRING_CLOUDFLARE_HYPERDRIVE / _R2 on stage and prod, and /ping plus /api/health (every page redirects a visitor with no session to the guest sign-in, and the probe wants a 200). 02-docs is hook-only. - One convergence keeps the order: supabase -> cloudflare-hyperdrive -> db-migrate -> web and cloudflare-r2 -> web per environment, every edge `mode: enforced` on github-push-main with an advisory modeRule for pull requests. The R2 root applies with its own r2-data key, not the deploy token. - Workers AI is the default model provider: an `AI` binding in the committed wrangler config, workers-ai-provider 4.0.0 (AI SDK 7), Kimi K2.6 for the chat and tools, GLM 4.7 Flash for titles. The AI Gateway's models are offered only with AI_GATEWAY_API_KEY; the picker shows exactly what can answer, and a request for an unavailable model gets the default. Workers AI's errors show in the chat; the suggestions tool returns its structured-output error to the model. next dev alone opens the platform proxy, and the static-assets cache is populated by a copy, so a build needs no Cloudflare credential. - The session key is AUTH_SECRET or one the database generated (migration 020_app_secrets, app_private): Auth.js initialised lazily, the proxy and the guest route reading the same key. The session cookie's name is chosen as Auth.js chooses it, so the built Worker served over http no longer loops on the guest sign-in. - Row-level security on all seven tables in public (030, guarded), with tests/db's PGlite guard test. - apps/web/wrangler.jsonc committed as the fixture render; build renders every lane (dev from the fixture); /api/health; the lib/site.ts name seam; metadataBase the product's own origin (NEXT_PUBLIC_SITE_URL from SITE_URL or the workers.dev URL), the "Deploy with Vercel" call to action gone; stack-tectonic 0.19.0; checks.yml on pull requests only with `git diff --exit-code` after wire:fixture; ci.yml's linked gate at v2.78.4. - .baseline/, the rename engine (the upstream vercel/ai-chatbot link and every migration protected), the bootstrap helpers, the deployment-record hook, ai/context/, the phase pages, BOOTSTRAP.md, baseline.yml, tag.yml. - testing/: manifest, phases, coverage, rebrand, retouch, bootstrap-defer, wire, leak, placement and e2e (the migrations applied by the lane's own steps to a local Postgres with Supabase's roles; the web lane built in the staged tree; wrangler dev with a stand-in AI binding — Workers AI cannot be called offline — a guest, a streamed chat, persisted and listed, an attachment through local R2, a registration and sign-in, and anon / authenticated reading none of it). - The as-built status is ai-chatbot's again (AC4 had merged rag-chatbot's). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AuyckrXahuAVgdmxamUUtk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AC5 (task AC-6): Vercel's Next.js AI Chatbot on Cloudflare Workers + Supabase becomes an Orun baseline on the Lumen conventions that takes a new chatbot from nothing to live on stage and prod in ONE landing (cirrus-baseline v22's shape), following saas-starter (sourceplane/saas-starter#6) for the supabase → hyperdrive → db-migrate → web chain, the database's own session key and RLS, blob-starter for the R2 root's own
r2-datakey, and kv-redis-starter for the committed wrangler config. A fresh product chats on Workers AI with no model key and signs guests in and registers users with no AUTH_SECRET.What was added
The card and the build
blueprint.yaml: inputs (reponame, productname, productdomain, githuborg, subdomain);requires.integrations: [github, cloudflare, supabase]; six brokered keys as a preview —CLOUDFLARE_API_TOKEN(workers-deploy),CLOUDFLARE_HYPERDRIVE_TOKEN(hyperdrive-edit),CLOUDFLARE_R2_TOKEN(r2-data),CLOUDFLARE_ACCOUNT_ID(account-id),SUPABASE_ACCESS_TOKEN(management-access),SUPABASE_ORG_ID(org-id); programme01-product,02-docs;expectedMinutes: 20. The description and BOOTSTRAP state the owner's prerequisite: two Supabase projects (stage, prod — the free plan's limit). No AI vendor key is asked for.repo-blueprint.yaml:01-productplaces every module (26). Post hooks: retouch, git-init, stage, rebrand, orun-workspace,work-tree --strip,promotion --defer,dev-lanes --defer, restage, rebrand-verify, pnpm lockfile,orun.repo/ensure@v1, link, oneorun.integrations/reconcile@v1per key (6),orun.pr/land@v1.orun.run/watch@v1on the merge sha;orun.secrets/exists@v1forSUPABASE_PROJECT_REF,SUPABASE_DB_PASSWORD,SUPABASE_DB_URL,WIRING_CLOUDFLARE_HYPERDRIVE,WIRING_CLOUDFLARE_R2on stage and prod;orun.http/probe@v1on/pingand/api/healthfor both. Not/: every chatbot page redirects a visitor with no session to the guest sign-in (307), and the probe wants a 200 (checked against orun's probe locally).02-docsis hook-only: restore promotion and dev-lanes, render the deployment record (which model provider serves, from/api/health), land, probe.Infra before app (enforced on
github-push-main, advisory on PRs)supabase → cloudflare-hyperdrive → db-migrate → web, andcloudflare-r2 → web, per environment.cloudflare-r2root now applies with its ownCLOUDFLARE_R2_TOKEN(r2-data), not the deploy token. The Supabase root publishes Lumen's three outputs only; Lumen's provider lock files on all three roots. stack-tectonic 0.19.0.Workers AI is the default model provider
AIbinding in the committed wrangler config;workers-ai-provider4.0.0 (AI SDK 7 /@ai-sdk/provider4). Chat and tools:@cf/moonshotai/kimi-k2.6(default); titles:@cf/zai-org/glm-4.7-flash, thinking off.AI_GATEWAY_API_KEY./api/modelsreturns what can answer; the picker shows exactly that; a request for an unavailable model gets the default. Workers AI errors show in the chat; the suggestions tool (structured output) returns its error to the model rather than failing the response.next devalone opens wrangler's platform proxy (the AI binding has no local mode and would make every build ask for a Cloudflare credential), and the static-assets cache is populated by a copy (scripts/populate-static-assets-cache.mjs) instead ofpopulateCache local, for the same reason.The session key, RLS and the rest of the app
lib/auth-secret.ts:AUTH_SECRET, else the key migration020_app_secretsgenerated intoapp_private.secrets(not exposed by the Data API). Auth.js is initialised lazily so its config can await it; the proxy and the guest route read the same key over the same Hyperdrive binding, once per isolate (/pingand/api/healthanswer before that read).lib/auth-cookie.ts: the session cookie's__Secure-name is chosen as Auth.js chooses it. Upstream's!isDevelopmentEnvironmentmade the built Worker served over http (wrangler dev) loop on the guest sign-in.030_row_level_security(guarded) on all seven tables;.enableRLS()inschema.ts; drizzle twins.apps/web/wrangler.jsonccommitted (GENERATED banner); the build renders every lane (--fixture wiring.fixture.json --fixture-envs dev); Checks runsgit diff --exit-codeafterwire:fixture./api/health;lib/site.tsname seam;metadataBaseis the product's origin (NEXT_PUBLIC_SITE_URLfromSITE_URLor the workers.dev URL, rebranded) instead ofchat.vercel.ai; the header's "Deploy with Vercel" CTA is gone; the sign-in page says "Powered by Workers AI". Redis stays optional (no resumable streams / IP limit without it).Factory
.baseline/,tooling/rebrand(protectsgithub.com/vercel/ai-chatbotand every migration),tooling/bootstrap,tooling/wire(kv-redis-starter's),hooks/render-deployment-docs.sh,ai/context,docs/phases,BOOTSTRAP.md,baseline.yml,tag.yml;ci.yml's linked gate at v2.78.4;checks.ymlon pull requests only.testing/: manifest, phases, coverage, rebrand, retouch, bootstrap-defer, wire, leak, placement, e2e;testing/lib/fake-ai/(the e2e's Workers AI stand-in).How it was verified
Everything ran locally on the committed head (
76d9dd2) with no model key and noAUTH_SECRETanywhere; the tree was clean before and after.pnpm install --frozen-lockfile,wire:fixturethengit diff --exit-code(clean), typecheck, lint (biome: 0 errors; eslint clean), test — tests/web 47 passed in 10 files (new:models,proxy,auth-secret,health,wrangler-config), tests/db 10 passed in 2 files (new:row-level-securityin PGlite, the drizzle-twin check) — and build on Turbopack with no Cloudflare credential.Sam's Chat & Answers; thevercel/ai-chatbotlink and migrations protected), retouch, bootstrap-defer, wire — all pass.wrangler.jsoncthe fixture render binding AI; the product's ownorun plan --trigger github-push-mainorderssupabase → cloudflare-hyperdrive → db-migrate → webandcloudflare-r2 → web, every edge enforced, stage and prod side by side, nothing on dev; the PR plan holds the same edges advisory (checked at ≥ v2.78.4); the plan resolves exactly the 6 minted keys and all 5 published ones; the build bakes the product's own origin; a--resumeis a no-op.000_control_baseline 010_initial 020_app_secrets 030_row_level_securityto a local Postgres with Supabase's roles through the Management-API stand-in, a second apply is a no-op, the PR plan verifies checksums offline; the web lane's install,verify-app-structure,build-app(re-rendered from both stage wiring documents),verify-build-output,deploy-dry-runin the staged tree on Turbopack; thenwrangler devwith the AI binding pointed at a deterministic stand-in (testing/lib/fake-ai/, a WorkerEntrypoint answeringrun()like Workers AI's binding):/ping,/api/health);/→ guest sign-in → a session that Auth.js's owndecodeopens with the database's key;/titled with the product name; og/twitter image URLs onhttps://acme-chatbot-hq-web-stage.acme.workers.dev, nothing pointing at Vercel;/login,/register, a 404,/api/models(Workers AI only);/api/chatstreamed back (11 deltas) from@cf/moonshotai/kimi-k2.6, titled byglm-4.7-flash, persisted (Chat + 4 messages) and listed in/api/history; a gateway model with no key answered by the default Workers AI model;postgresneither superuser nor BYPASSRLS;anonandauthenticatedsee 0 users, chats and messages and cannot write;app_privateclosed to them.orun new --statusat v2.58.11, v2.78.4, 2.79.0;orun validate;orun work checkclean;terraform init -backend=false && validateon the three roots (v1.15.3).Verified only offline / not verified: a real Workers AI model (ids, tool calls, structured output); the Supabase, Hyperdrive and R2 applies, db-migrate against a real project, a real deploy and its probes. A
GET /logs a Next/React prerender-resume mismatch (React falls back to client rendering); a build ofmainlogs the same line — recorded as risk AC-O, not introduced here.Open / owner items
r2-data, butweb'swrangler deployattaches theBLOBbinding with theworkers-deploytoken (Workers Scripts + KV). Whether that token may bind R2 is unverified live — same open risk as blob-starter and commerce.AI_GATEWAY_API_KEY(gateway models),REDIS_URL,AUTH_SECRET(rotation),SITE_URL(custom domain).🤖 Generated with Claude Code
https://claude.ai/code/session_01AuyckrXahuAVgdmxamUUtk
Generated by Claude Code