Files

39 lines
9.7 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.
Release 0.5.1 adds finite parser reason/recovery branch, finish_reason and optional token usage diagnostics without changing provider, prompt, 160-token dialogue budget, TTS voice or request count. Damaged structure is called truncated only when the provider explicitly reported length. Existing 0.5.0 clients continue to receive neutral/0 for fallback; the new UI labels it undetermined, shows model neutral only during playback and retains the previous played reply separately. New TTS diagnostic metadata keeps input_chars instead of the speech body; existing conversation history and the actual reply-only TTS request retain their original function. Old diagnostic reports remain accepted. See ../docs/CAMERA_EMOTION_051.md.
Gateway 0.7.2 repairs the observed 0.5.1 `non_json/plain_text/stop` fallback by supporting `LAN_LLM_STRUCTURED_OUTPUT=prompt|json_schema`. Unset defaults to schema only for the verified exact tuple `http://127.0.0.1:8888/v1`, `qwen3.8-27b`, `{"enable_thinking":false}`; other URLs/models/kwargs default to prompt. This is deployment capability selection, not a model-name heuristic. Explicit schema opt-in requires endpoint verification. When switching to Doubao, use `prompt` or unset the mode and use its own kwargs; Doubao schema decoding remains unverified. Unsupported schema requests fail once; no automatic retry or provider failover occurs. `response_format` uses only an object with reply string, emotion enum, intensity integer enum, required fields and additionalProperties=false. Cross-field semantics remain parser-validated.
Persona format rules now explicitly bind only spoken `reply`, preserving style/content/safety while removing the competing outer JSON prohibition. One system and the 160-token budget remain. JSON/labels still never enter speech or history, and each parsed reply uses one streaming TTS generator. Health/hello and numeric metrics expose the format mode; optional diagnostics remain compatible with the 0.5.1 APK. No Android update is needed. See ../docs/STRUCTURED_REPLY_072.md for compatibility evidence, rollout and limitations.
Deployment uses `deployment_baseline` in SOURCE_MANIFEST as the reviewed live hash fence, including the two whitelisted public persona lore JSON files. Ignored records no longer override the expected baseline. Backups retain all Python sources/tests, public persona lore, permissions and private unit/environment relationships on the server. The rollback script restores exactly the deployment whitelist and refuses busy/source/environment conflicts.
Gateway0.7.3 / Android0.5.2 refines reply-intent rules with seven semantic examples and adds bounded camera/frame/transmission diagnostics. FaceContext emits finite receive/use reason/counters in per-turn metrics; counters are cumulative for the current socket, cue/use reason describes the current snapshot. Camera criteria and models remain unchanged. New diagnostic reports add camera_analysis (current/last run) and face_transmission (activity lifetime) snapshots; old reports are accepted. Each camera and transmission summary is limited to one per10s plus final camera stop summary. See ../docs/EMOTION_CAMERA_052.md for actual public-case results and test limits. Retained0.5.1 APK needs an update to0.5.2/code10 to supply the new camera fields.