System Roles
Supabase is the backend database and account system:- account creation and login
- Supabase Auth user identity
- user profiles
- billing customer, subscription, license, and entitlement records
- managed AI plan and quota records
- managed AI usage ledger
- HTTP endpoints for managed AI
- Supabase JWT verification through the project JWKS endpoint
- request validation
- feature registry and prompt/model selection
- quota enforcement
- OpenAI Responses API calls
- normalized app-facing responses
Reading with Flex..., a Flex success message, or a Flex-to-Fast retry message when the Appearance setting for routing detail is enabled. Hiding routing detail changes only the UI wording; it does not change the execution tier request or retry behavior.
Runtime Flow
Endpoints
The first Worker endpoints are:POST /v1/ai/responses accepts a Scritorio feature request:
chapter_summaryact_summary
GET /v1/ai/usage/me returns the signed-in user’s current managed AI period, cap, hard limit, estimated used amount, remaining amount, and token totals.
Database Tables
Managed AI uses two Supabase tables:ai_user_plansai_usage_events
ai_user_plans stores the user’s current managed AI plan, status, included monthly cap, hard limit, and usage period.
ai_usage_events is an append-only usage ledger for managed AI calls. It stores user id, local project/document identifiers, feature id, provider, model, OpenAI request id when available, token counts, estimated cost, status, and error code.
Both tables have row level security enabled. Authenticated users can read only their own rows. The Worker writes rows with the Supabase service role key, which must never be shipped to the desktop app.
For development, the Worker creates a dev_managed_ai plan for an authenticated user when the user first calls managed AI or requests usage.
Worker Configuration
The desktop app needs only public values:Security Rules
- The desktop app never receives
OPENAI_API_KEY. - The desktop app never receives
SUPABASE_SERVICE_ROLE_KEY. - The Worker never trusts a client-provided
user_id. - User identity is derived from the verified Supabase JWT
sub. - The client requests Scritorio features, not arbitrary provider settings.
- Manuscript text is not stored in the usage ledger.
- Usage rows store metadata and token/cost accounting, not full prompts.