openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Tauri bootstrap from config.toml and derive API/backend settings from core

Open senamakel opened this issue 7 months ago • 1 comments

Summary

The Tauri (desktop) app should not depend on a pile of build-time VITE_* values for where to reach the OpenHuman core and API. Users will choose the core JSON-RPC URL on the login screen (dedicated UI—not hand-editing config.toml or env files for normal use). After a successful RPC handshake to that sidecar, the app should pull the rest of the effective runtime settings from the core over JSON-RPC (e.g. api_url, and other client-appropriate fields) instead of hardcoding or duplicating them in the bundle.

config.toml remains the core/sidecar config on the machine (operator concern); end users do not configure the RPC URL there—they use the in-app control on login.

Current pain

  • app/src/utils/config.ts still leans on VITE_OPENHUMAN_CORE_RPC_URL, VITE_BACKEND_URL, and similar build inputs, so “same app binary, different deployment” is awkward.
  • Self-hosted / internal users need a discoverable, safe way to point the UI at the right core without a developer rebuild.
  • The core already exposes config via JSON-RPC (e.g. get_config_snapshot / openhuman.config_get — see src/openhuman/config/ops.rs); the renderer should treat RPC as the source of truth for downstream URLs after the user picks an RPC base URL.

Goals

  1. Login-screen RPC URL — A clear form field (or preset + custom URL) for the core JSON-RPC endpoint (e.g. http://127.0.0.1:7788/rpc or a remote sidecar), with validation (format, reachability) before proceeding.
  2. Persistence — Remember the last used RPC URL locally (Tauri store / localStorage / existing prefs pattern—implementation choice) with optional “reset to default.”
  3. Post-login config — After RPC works, call openhuman.config_get (or a slim ui_bootstrap) to fetch api_url and other safe client fields from the loaded Config (src/openhuman/config/schema/types.rs), so API server and friends come from core, not a second guess in the web bundle.
  4. Fallbacks — If RPC is unreachable, show actionable errors on the login step; do not silently use a stale backend.
  5. Minimize remaining VITE_* to true build constants (Sentry, etc.); document what stays compile-time.

Non-goals (initial)

  • Removing every VITE_* in a single PR — can be phased after the login + bootstrap path works.
  • Replacing OS keychain for auth tokens (separate work).

Solution direction (for implementation)

  • A. Login / welcome flow UI module: RPC URL field, “Test connection” (optional), continue to auth.
  • B. coreRpcClient / Tauri core_rpc_relay: use the user-selected base URL (saved pref) as the effective CORE_RPC_URL for the session, overriding the Vite default when set.
  • C. Single RPC method (or existing config_get) returns a stable, redacted JSON for the webview: apiUrl, feature flags, etc.
  • D. E2E / unit tests — Prefs + merge logic; at least one test that a custom RPC base is passed through to the client.

Acceptance criteria

  • [ ] User can set the RPC URL on the login screen; no config.toml user edit required for the common “point at my core” case.
  • [ ] Last-used URL is persisted and restored on next launch (unless cleared).
  • [ ] After a successful RPC connect, the app loads backend / API settings from core (not only from VITE_BACKEND_URL); document the precedence when both exist during migration.
  • [ ] Core is authoritative for api_url (and other exposed client fields) returned over RPC; no secrets in the payload; redact as needed.
  • [ ] Unit tests in app/ for URL persistence + config merge; E2E (if feasible) or integration test for login → config_get happy path.
  • [ ] Docs — User-facing: “Set your sidecar address on the login screen”; developer: what remains in .env vs runtime.

Related

  • app/src/utils/config.ts — CORE_RPC_URL, BACKEND_URL defaults
  • app/src/services/coreRpcClient.ts — effective RPC target
  • app/src-tauri/… — core_rpc_relay, window prefs if used for storage
  • Login / onboarding routes under app/src/pages/, AppRoutes.tsx — where to add the field
  • src/openhuman/config/ops.rs — get_config_snapshot, load_and_get_config_snapshot
  • src/openhuman/config/schema/types.rs — api_url, Config
  • tests/json_rpc_e2e.rs — openhuman.config_get

senamakel avatar Apr 26 '26 05:04 senamakel

Taking this. Going to start with the login-screen RPC URL field + persist, then swap coreRpcClient to read the saved value, then a small config_get call post-handshake to pull api_url from core. Will leave the broader VITE_* purge for a follow-up so this PR stays reviewable.

obchain avatar Apr 30 '26 06:04 obchain