gateway_chat_startup.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """Frontend startup checks shared by classic chat and top-level one-shot."""
  2. from __future__ import annotations
  3. import os
  4. def ensure_launch_provider(args) -> bool:
  5. from hermes_cli.gateway_chat import bypass_launch
  6. if bypass_launch(args):
  7. # The owner freezes code defaults for this launch; the profile is the thing under
  8. # investigation, so the client must not probe or repair it either.
  9. return True
  10. from hermes_cli.main import _first_run_setup_guard, _has_any_provider_configured
  11. # A resumed/remote session owns its provider policy. Explicit endpoint/key
  12. # launches can also be usable without a configured local profile.
  13. if (
  14. getattr(args, "resume", None)
  15. or os.environ.get("HERMES_TUI_GATEWAY_URL", "").strip()
  16. or getattr(args, "base_url", None)
  17. or getattr(args, "api_key", None)
  18. ):
  19. return True
  20. from hermes_cli.free_tier_bootstrap import run_bootstrap
  21. run_bootstrap(announce=False)
  22. if _has_any_provider_configured():
  23. return True
  24. _first_run_setup_guard(args)
  25. return False
  26. def launch_gateway_chat(args) -> int:
  27. try:
  28. from hermes_cli.main import _confirm_startup_expensive_model_override
  29. from hermes_cli.gateway_chat import launch_from_args, bypass_launch
  30. # Consent belongs before discovery/admission, even with --yolo. A bypass launch has
  31. # no profile-derived model/provider to guard and must not read config.yaml here.
  32. if not bypass_launch(args):
  33. _confirm_startup_expensive_model_override(args)
  34. return launch_from_args(args)
  35. except ImportError as exc:
  36. from hermes_constants import emit_partial_update_hint
  37. if emit_partial_update_hint(exc):
  38. return 1
  39. raise