Administration¶
Open Administration (/admin) from the rail or user menu. One page contains search usage, token usage, provider settings, storage and account access. Section links jump within the page. Provider controls keep their existing autosave behavior. Only approved, active admins can use the page and reporting endpoints.
New signups receive the user role and wait for admin approval. Signup returns a user record with is_approved: false and status: pending; it does not issue access or refresh tokens. The web and mobile apps show a waiting screen. Password login and token refresh require both approval and an active account.
First admin¶
Run migrations, register the intended admin through the application, then run this command on the server with the IAM database environment configured:
docker compose -f docker-compose.yml -f docker-compose.server.yml exec loryth-iam-api loryth-iam promote-admin <username>
For a package-local installation, use uv run loryth-iam promote-admin <username> from server/services/loryth-iam. The command approves that existing account and grants the admin role. Public signup never grants admin access, including the first signup. The worker still starts with loryth-iam without a subcommand.
The IAM migration keeps previously registered, pending or active users approved and active. Inactive and deleted accounts remain blocked. Existing accounts keep the user role until an operator promotes an admin.
Review signups¶
Sign in as an admin and open Account access on the Administration page. Review the user's name, role, and access state, then select Approve. The account can now sign in with its existing password and retains the user role. Approval is safe to repeat. Inactive accounts cannot be reactivated through this action.
The users list, approval endpoint, and delete endpoint require an approved, active admin. An admin cannot delete their own account. /user/me returns the signed-in user's current role and approval state after checking the signed token, expiry, issuer, audience, and current database record.
DeepSeek settings¶
Open Providers on the Administration page. Configure the DeepSeek model and API key. Model presets save immediately. Custom model ids and API keys save when you leave the input or press Enter; they do not save while you type. Custom model ids must be nonblank. Each section shows saving progress, a brief saved confirmation, or an error with a retry button. Changes take effect on the next chat reply, including existing conversations. A blank API-key field preserves the saved key. Removing a saved key requires inline confirmation and falls back to DEEPSEEK_API_KEY if the server has one.
Deepgram uses the same controls. Web search choices save immediately when the provider is configured. Mojeek without a configured key waits until you commit its API key, then saves the provider and key together. Brave requires its server key before it can be selected for use.
Before saving API keys, configure LORYTH_SETTINGS_KEY on the AI API and worker with a Fernet key. Generate one from the AI package:
Keep the key in private server configuration and back it up separately from the database. Keep it stable across restarts and workers. The database contains the encrypted API key; the API only returns whether a key is configured. The browser receives a saved key only when an admin chooses Show or Copy. Losing or changing the encryption key prevents the saved key from being read. Settings remains available and marks that key as unreadable. Restore the server key, replace the saved API key after configuring a valid encryption key, or remove the saved key from Settings. Chat reports that configuration is missing until recovery; it does not silently use the environment key.
When no settings have been saved, DEEPSEEK_MODEL defaults to deepseek-flash. The fixed DeepSeek provider URL remains server configuration so a settings edit cannot redirect a saved key to an arbitrary endpoint.
AI routes validate the bearer token through IAM on each request. Set LORYTH_IAM_URL to the internal IAM URL (default http://loryth-iam-api:8000). Requests fail closed if IAM is unavailable. All AI admin endpoints require the current admin role, and a supplied X-User-Id must match the signed-in user. These checks cover IAM user management and the AI service; other service APIs still need their own access checks before public use.
Validation¶
Run the IAM and AI package checks with make format, make lint, and make test. The AI provider tests use a simulated DeepSeek response; they do not spend tokens.
For the browser flow, start the web app with its IAM and AI proxies configured and provide an approved admin. From ui/:
BASE_URL=http://localhost:3000 ADMIN_USERNAME=<username> ADMIN_PASSWORD=<SECRET_VALUE> pnpm --filter @loryth-ui/web-app exec playwright test tests/e2e/admin.spec.ts --project chromium --no-deps
The test registers a pending user, checks blocked login, approves the user through Administration page, saves and reloads the model setting, and checks regular-user access denial in both the UI and APIs. It restores the previous model setting. Use a disposable database: the test leaves its newly approved user in place. Set REVIEW_SCREENSHOTS_DIR to a directory under .scratch/ to capture the flow.
Usage and storage¶
The usage period covers the last 7, 30 or 90 UTC calendar days, including today. Charts support pointer and keyboard selection of a day's exact counts. Reports refresh each minute while the page is visible; Refresh reloads all admin sections. Storage shows file buckets, database sizes and the total of available sizes.
Search usage separates searches from outbound HTTP attempts, including retries and redirects. Provider rows show successes, failures and returned results. Watch metadata and local nutrition reference lookups do not call the general web search service and are excluded. Calls rejected before selecting a provider are excluded.
Token usage includes Pi chat calls through the model proxy and journal completions. It shows provider-reported prompt, completion and total tokens, grouped by day, configured model and source. Cached tokens are a subset of prompt tokens; reasoning tokens are a subset of completion tokens. Requests without valid usage counts remain visible as missing counts and are excluded from token totals. Interrupted streams may not deliver the provider's final usage frame. The proxy requests uncompressed responses; unexpectedly encoded responses retain their original forwarding behavior but cannot supply usage counts.
Tracking begins with this release (v16-search-usage.sql and v17-token-usage.sql). No older chats are backfilled. Each report shows the first recorded request date. Usage rows contain provider/model identifiers, UTC timestamps, counts and outcomes; they contain no queries, prompts, replies, user IDs or keys. Failed requests remain counted even when the request transaction rolls back. Reporting write failures log a warning without failing an otherwise successful search or completion. Counts describe this installation's requests and may differ from provider billing.
Session renewal and seeding¶
Web and native sign-in store the access/refresh pair. Protected JSON requests renew an expired access token once, sharing a renewal across concurrent requests. Refresh still requires an approved, active account. Sign-out clears the pair.
The seed tool requires an existing approved admin, including for --grocery-only. Set SEED_ADMIN_USERNAME and SEED_ADMIN_PASSWORD in its private environment; sylox seed forwards those environment variables. The tool signs in as the admin, creates or locates the demo user, approves it, and sends the admin session with AI policy requests. It never promotes an account automatically. See the seed guide for commands.