Files
baji-vc/gateway/README.md
T

28 lines
6.5 KiB
Markdown

# LAN Voice gateway — recoverable source archive
This directory contains the actual deployed SPARK-2 source, not just an Android-side patch. `SOURCE_MANIFEST.json` identifies the source files by SHA256, the observed code version, interpreter and dependency versions. No `.runtime`, chat/history/diagnostic data, token/Cookie, voice reference audio, model, private key, cache or venv is included. Existing Android `app/` is unchanged by archiving.
`gateway.py` is the dialogue gateway; `app.py` is the separate VAD API. `guest_sessions.py`, `vad.py`, `history.py`, `persona_resolver.py`, `segmentation.py`, `protocol.py`, `tts_debug.py` and `face_context.py` are restored alongside them. Public lore is in `personas/`, browser source in `web/`, tests in `tests/`. Upstream documentation, if present, is preserved separately under `docs/UPSTREAM_README.md`. Legacy scripts may contain deployment-specific addresses/paths: they are source records, not portable install commands.
## Restore on a suitable server
1. Read `SOURCE_MANIFEST.json`. Create a venv using a compatible Python/platform, then install `requirements.lock` (exact installed distribution versions from the deployed gateway interpreter). This is a version lock, not a hash-locked wheel bundle; wheels and system libraries must be available for the target platform. Nothing here downloads a model automatically. `requirements.txt`, if upstream supplied one, records the original direct requirements.
2. Run `python scripts/check-archive.py` **from this directory**, or invoke it by absolute/relative path from the repository root; it fixes the import/cwd paths itself. Tests run in a temporary directory with synthetic persona IDs, no live service, credentials or history. The model-dependent Silero check is explicitly skipped. To run the full VAD test separately, provision the authorized external model first. No model service is restarted by tests.
3. Provision the existing approved Silero CPU model externally at `models/silero_vad.onnx`; verify its SHA256 against `app.EXPECTED_HASH` before service startup. Restore existing ASR/TTS/Qwen endpoints/registered voice resources separately. Large models and voice reference recordings are intentionally outside this source backup.
4. Copy `env.example` into a **private untracked** environment file and replace the secret placeholders. Keep it out of Git and shell logs. Generate/provision the HTTPS certificate and private key outside Git; the private key is never part of this archive. Do not change Android trust/token merely to make a test pass.
5. Create `.runtime/personas/` from `config/personas/*.json.example`, replacing voice IDs with existing registered voice IDs. For active-profile default selection, create `.runtime/active_profile.json` from `config/active_profile.json.example`. These examples deliberately contain no deployed profile/runtime information. Public persona lore in `personas/` is required. `.runtime/history.sqlite3` is initialized by the service; production history is not backed up here.
6. Review the LAN origin/source allowlist, fixed backend endpoint addresses and registered default voice in the source for the target network. They reflect the actual deployed implementation; paths such as `/home/gorios-spark-2/...` in legacy scripts are **not** assumed valid on another server. Use the placeholder-based `deploy/gateway.service.example` for new deployments, replacing paths explicitly.
7. From this directory, start the gateway with the existing private environment loaded, e.g. `.venv/bin/python -m uvicorn gateway:app --host 0.0.0.0 --port 5011 --ssl-certfile <PRIVATE_CERT_PATH> --ssl-keyfile <PRIVATE_KEY_PATH>`. LAN open mode is only for the trusted LAN/WG source allowlist, never public Internet exposure. Install a reviewed user service from the example if needed. Do not start duplicate gateway instances alongside the existing busy lock owner.
8. Verify HTTPS health and authorized Origin/auth/hello/history, then run one bounded public-sample protocol check. Real Android speaker playback still needs a real phone; nonempty backend PCM does not prove audible output.
The v0.4.0 repair/context protocol and evidence boundaries are documented in `../docs/VOICE_REPAIR_040.md`. Archive and future deployments use this workspace's scripts with hash, backup, tests and busy checks. Archiving itself does not deploy or restart anything.
The 0.5.0 canonical source adds `reply_emotion.py`: one-system structured provider reply, validated one-turn role expression and reply-only speech/history. See `../docs/REPLY_EMOTION_050.md`. `scripts/deploy-gateway-source.py` in the repository root tests this complete source tree, hash-fences deployed modules, backs up and restarts only the gateway. Use that script for current releases; historical `backend/gateway.patch` is not the current restore source. `SOURCE_MANIFEST.json` includes current hashes and retained original provenance; a legacy 0.7.1 health version does not advertise feature completeness, so inspect hello capabilities.
`llm_provider.py` preserves the configurable OpenAI-compatible provider interface: `LAN_LLM_BASE_URL`, `LAN_LLM_MODEL`, private `LAN_LLM_API_KEY` (Authorization header only), and optional JSON-object `LAN_LLM_CHAT_TEMPLATE_KWARGS`. Missing configuration defaults to local `http://127.0.0.1:8888/v1`, `qwen3.8-27b`, thinking disabled. Non-Qwen model defaults omit Qwen kwargs; explicit kwargs stay local to that provider. The provider's original default budget is 64; the structured dialogue explicitly requests 160. There is no automatic failover or retry. Doubao's `doubao-seed-2-1-pro` is a LiteLLM alias, not evidence of actual model weights.
`SOURCE_MANIFEST.json.provider_baseline` records the latest observed SPARK2 hashes before this merge, including gateway `d088bedcf5c0accd4712e06202f6ced8ab155aad57a5b05683724efa346326ce`. Deployment fences against these hashes, not the superseded historical patch. Historical `scripts/deploy-gateway.py` is disabled. The existing unit and private environment loading relationships are backed up only on the server and checked unchanged. All Python sources/tests and original modes are backed up; only gateway is restarted after isolated tests and repeated source/busy checks. Use `scripts/rollback-gateway-source.py` for this exact deployment.
Portable archive checks skip only the omitted Silero artifact. On the existing server, run `python scripts/check-archive.py --vad-model /absolute/path/to/models/silero_vad.onnx` for the full suite, with checksum verification and an isolated read-only artifact link. This never downloads or changes a model or online service.