Files
de-praxis/docs/server-control.md
juli b5d8e36d90 Start the relay despite refused narrator settings, and explain start-up errors
Adding LLM_ALLOWED_HOSTS, as the hosting guide suggests, without the host
of an already saved narrator backend stopped the whole relay from
starting. The relay now starts with narration off, says why, and keeps the
saved values on show in the panel, which won't save them until they're
fixed. Backend calls also check the host policy themselves, so the
Studio's rewording can't reach a host the policy no longer allows.

Bad numeric variables (MAX_ROOMS, ROOM_TTL_HOURS, the rate limits,
LLM_MAX_CONCURRENT, MAX_CAMPAIGNS), an invalid first-start LLM_URL, an
unreadable settings or MCP key file and a port already in use now print
one line naming the problem instead of a stack trace. MAX_CAMPAIGNS was
silently ignored when it wasn't a number.
2026-10-25 18:12:42 +01:00

119 lines
12 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Server control room
The server includes a themed web control panel. It ships in the server distribution and needs no separate frontend build, hosting service, or JavaScript runtime.
[Dark control panel](../assets/branding/server-control-preview.png), [light login](../assets/branding/server-login-light.png), and [generation controls](../assets/branding/server-generation-controls.png), captured during isolated browser QA against a disposable mock inference backend.
## Open the panel
Start the server with JDK 17:
```sh
./gradlew -PserverOnly :server:installDist
./server/build/install/server/bin/server
```
Open **http://127.0.0.1:1337/admin**. On first start, the server creates a private `admin.key` inside `DATA_DIR` (default `./data`). Its startup message shows the file's location, without printing the key. Copy the key from that file into the panel's login field.
For deployments that supply their own secret, set `ADMIN_TOKEN` to at least 24 printable characters. This replaces file-based authentication for that process. The admin key is separate from player tokens and backend API keys.
Navigation and settings remain hidden until the server verifies the admin key. The panel uses the bundled cassette artwork and offers System, Dark CRT, and Light Archive themes; the theme choice persists across visits.
The browser remembers operator clearance for the current tab session. **Lock console** clears it and clears the form. The panel does not download or display the saved backend API key. Use HTTPS or an SSH tunnel when administering across an untrusted network.
Admin routes default to local connections only. For testing from another device on a trusted LAN, run:
```sh
./server/bin/server --lan --lan-admin
# Equivalent: LAN_MODE=true LAN_ADMIN_ACCESS=true ./server/bin/server
```
Use the printed `http://<relay-IP>:1337/admin` URL, or substitute your configured port. The IP must be this relay's numeric destination address; DNS hostnames are deliberately not accepted. Retrieve the admin key from `DATA_DIR/admin.key` on the server (default `data/admin.key`), or use your configured `ADMIN_TOKEN`. All settings and backend operations still require this key. LAN mode uses plaintext HTTP, so use it only on a trusted local network. `--lan-admin` requires `--lan`; it cannot be combined with `PUBLIC_ORIGIN`, trusted proxy settings or HTTPS `ADMIN_REMOTE_ACCESS`. Do not set `ADMIN_REMOTE_ACCESS=true` for LAN testing.
For internet hosting, use the [private SSH access and HTTPS proxy layout](internet-hosting.md); the public proxy deliberately does not expose this panel. Backend tests/model discovery are rate-limited, so wait after repeated diagnostics return `429`.
## Configure inference
1. Choose a connection profile (llama.cpp, LM Studio, native Ollama, or custom) and its backend API protocol.
2. Enter the complete generation endpoint, reachable **from the server**, such as `http://127.0.0.1:8081/v1/chat/completions` or native Ollama `http://127.0.0.1:11434/api/chat`.
3. Use **Find models** to query the corresponding `/models` route (native Ollama uses `/api/tags`), or enter a model ID manually. Some compatible backends do not implement model discovery; manual entry still works.
4. Enter an API key if required. A blank field preserves the existing key. **Clear saved key** removes it when the configuration is saved.
5. Use **Test backend** to generate a small sample from the current form, without saving it. This intentionally contacts the selected backend, even when LLM narration is currently disabled.
6. Enable LLM narration and save the configuration.
Generation controls include:
| Setting | Behavior |
| --- | --- |
| Context length | Native Ollama sends `options.num_ctx` (1,024–262,144 tokens). Other protocols manage capacity on the inference server; llama.cpp uses startup `--ctx-size`. |
| Thinking | Default leaves the backend unchanged. Native Ollama accepts on/off or model-supported levels. llama.cpp uses chat-template controls for on/off and `reasoning_effort` for levels. Compatible APIs receive `reasoning_effort` for an explicit selection. Unsupported model options can make a probe fail. |
| Output tokens | 32–8,192 tokens. Reasoning models may share this budget with thinking; increase it and the timeout when needed. The existing 30-second maximum request deadline still applies. |
| Story history | Send the latest 0–200 entries within a 500–64,000-character budget. Zero entries sends current campaign state without previous log entries. These limits do not change model context capacity. |
| Sampling | Temperature, top-p and optional nonnegative seed. Native Ollama and llama.cpp also expose top-k and repeat penalty. |
Separate backend thinking fields are ignored, and completed inline `<think>` blocks are removed before narration reaches players. Empty or unfinished reasoning output falls back to the scripted narration. A seed does not guarantee identical output across backends or hardware.
These controls follow the [Ollama chat API](https://docs.ollama.com/api/chat), [Ollama request options](https://github.com/ollama/ollama/blob/main/docs/api.md), and [llama.cpp server API](https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md). Model and template support varies; test a draft before saving it.
Generation settings and style direction apply to the next narration call. In-flight calls finish with the settings they captured when they started. The fixed narration contract keeps rolls, objectives, and game outcomes authoritative; style direction adds atmosphere within that contract.
Settings are written atomically to `DATA_DIR/server-settings.json`, including any backend key, with owner-only file permissions on supported filesystems. This file is private, not encrypted. Preserve the data directory across server upgrades. `LLM_URL`, `LLM_MODEL`, and `LLM_API_KEY` seed settings only when no saved settings file exists; saved configuration takes precedence on later starts. If the saved settings are no longer accepted, for example after you add `LLM_ALLOWED_HOSTS` without their backend host, the relay still starts, with narration off, and prints why. Fix the settings in the panel to turn narration back on.
## Relay status and crew intake
The overview shows active crews, recorded transmissions, server uptime, and successful/fallback narration counts. Counters reset on server restart; rooms and configuration persist. Probe requests do not count as game narration.
The crew manifest includes room code, phase, crew count, round, and remaining pressure. It excludes player credentials and pending action text. **Accept new transmissions** controls new room creation; turning it off lets existing rooms continue, including joining a lobby that already exists.
Changes apply without restarting. Revision checks reject saves from a stale browser tab; use **Discard changes** to reload the current saved configuration before editing again.
## Campaign library
**Campaign library** (`/admin/campaigns`) lists the built-in campaigns and every imported `.dpc` package. Choose which ones players can start (**Offer** / **Hide**), which is listed first (**Make default**), export any of them, and delete imported ones. Imports are validated before anything is stored; a newer version replaces the current one, the same version must have identical content, and an older one needs **Allow replacing a newer version**. Rooms keep the exact copy they started with under `DATA_DIR/campaigns/pinned/`, so changes never affect a game in progress; **Remove unused old versions** deletes copies no room uses. `MAX_CAMPAIGNS` (default 50) limits the library size.
**Catalogs** lets the relay follow catalog URLs (an `index.json`, see [campaign-format.md](campaign-format.md#sharing-packages-and-catalogs)). Each followed catalog shows its campaigns as new, installed, or with an update; **Install** and **Update** download the package, check it against the catalog's SHA-256 and import it like an upload. An update keeps a hidden campaign hidden. Downloads are made by the relay: http(s) only, no redirects, 1 MiB per index and 5 MiB per package. Up to 10 catalogs can be followed.
## Studio
**Studio** (`/admin/studio`) edits a campaign as forms or as JSON, validates it on every change, and shows a flow graph with unreachable parts marked. Open a template or any library campaign to start. **Play-test** runs the document on the relay's engine with one seat per operator; force the next die roll to test both outcomes, and watch the full state in the inspector. Play-tests stay in memory for up to an hour (8 at a time). **Simulate** plays up to 5,000 games as experts, newcomers or random players and reports how often each ending occurs. **Save to library** stores the campaign (built-in ids are protected; the same version can be saved again while you work), and **Download** gives the `.dpc` or `.json`. If an inference backend is configured, selecting text offers rewordings. The open document is kept as a draft in the browser.
## Admin API
The **MCP access** section issues server-generated API keys for connected campaign-writing assistants. Choose read/validate/preview, draft editing, publication, and relay-status permissions separately. Secrets are shown once, expire, and can be revoked here. See the [MCP connection and authoring guide](mcp.md).
All `/admin/api/*` endpoints require `Authorization: Bearer <admin key>`. Writes require `Content-Type: application/json`. The browser uses only same-origin requests; no CORS access is enabled.
| Method | Endpoint | Purpose |
| --- | --- | --- |
| GET | `/admin/api/settings` | Redacted saved settings and revision |
| POST | `/admin/api/settings` | Validate and save settings |
| GET | `/admin/api/status` | Uptime, narrator counters, room summaries |
| POST | `/admin/api/probe` | Test draft settings with one generation |
| POST | `/admin/api/models` | Discover model IDs using draft settings |
| GET | `/admin/api/campaigns` | Library entries with room counts |
| POST | `/admin/api/campaigns/import` | Import a base64 `.dpc` (`data`, `enable`, `allowDowngrade`) |
| POST | `/admin/api/campaigns/{id}/state` | Offer/hide (`enabled`) or make default (`default`) |
| GET | `/admin/api/campaigns/{id}/export`, `/source` | The `.dpc` package or the campaign JSON |
| POST | `/admin/api/campaigns/{id}/delete`, `/admin/api/campaigns/cleanup` | Delete an import; remove unused pinned copies |
| GET | `/admin/api/catalogs` | Followed catalogs with each campaign's status |
| POST | `/admin/api/catalogs/add`, `/remove`, `/browse` | Follow, unfollow or preview a catalog (`url`) |
| POST | `/admin/api/catalogs/install` | Install or update `id` from catalog `url` |
| POST | `/admin/api/studio/check`, `/simulate`, `/save`, `/pack` | Validate with flow graph, simulate, save to library, build a `.dpc` |
| GET | `/admin/api/studio/templates` | Starting templates |
| POST | `/admin/api/studio/playtest`, `/playtest/{id}/act`, `/playtest/{id}/close` | Start, play and end a play-test (`GET /playtest/{id}` reads it) |
| POST | `/admin/api/studio/suggest` | Rewordings from the inference backend |
| GET / POST | `/admin/api/mcp/keys` | List key metadata / issue a scoped expiring key |
| POST | `/admin/api/mcp/revoke` | Revoke a key by ID |
The panel serves its CSS, JavaScript, and branding locally under `/admin/`. A restrictive content security policy disallows external scripts, external assets, and framing. Backend requests happen on the Kotlin server, so backend credentials stay out of browser requests to inference services.
## Verification
```sh
./gradlew -PserverOnly :server:test :server:distZip
node --check server/src/main/resources/admin/app.js
python3 scripts/smoke.py http://127.0.0.1:1337
```
Automated tests cover admin authentication, credential redaction and retention/removal, settings persistence, stale-write rejection, URL and generation-limit validation, runtime narration updates, model discovery, and pausing only new rooms. Existing campaign and narration tests remain in place. Generation tests cover protocol-specific payloads, history limits, thinking-output filtering, and legacy configuration defaults. Browser QA uses an isolated data directory and a disposable mock backend; it does not certify a particular inference model.