fix(fal): extend whitespace-only FAL_KEY handling to all call sites

Follow-up to PR #2504. The original fix covered the two direct FAL_KEY
checks in image_generation_tool but left four other call sites intact,
including the managed-gateway gate where a whitespace-only FAL_KEY
falsely claimed 'user has direct FAL' and *skipped* the Nous managed
gateway fallback entirely.

Introduce fal_key_is_configured() in tools/tool_backend_helpers.py as a
single source of truth (consults os.environ, falls back to .env for
CLI-setup paths) and route every FAL_KEY presence check through it:
  - tools/image_generation_tool.py : _resolve_managed_fal_gateway,
    image_generate_tool's upfront check, check_fal_api_key
  - hermes_cli/nous_subscription.py : direct_fal detection, selected
    toolset gating, tools_ready map
  - hermes_cli/tools_config.py     : image_gen needs-setup check

Verified by extending tests/tools/test_image_generation_env.py and by
E2E exercising whitespace + managed-gateway composition directly.
This commit is contained in:
Teknium 2026-04-21 01:59:15 -07:00 committed by Teknium
parent 77061ac995
commit 2e722ee29a
4 changed files with 35 additions and 13 deletions

View file

@ -119,3 +119,24 @@ def prefers_gateway(config_section: str) -> bool:
except Exception:
pass
return False
def fal_key_is_configured() -> bool:
"""Return True when FAL_KEY is set to a non-whitespace value.
Consults both ``os.environ`` and ``~/.hermes/.env`` (via
``hermes_cli.config.get_env_value`` when available) so tool-side
checks and CLI setup-time checks agree. A whitespace-only value
is treated as unset everywhere.
"""
value = os.getenv("FAL_KEY")
if value is None:
# Fall back to the .env file for CLI paths that may run before
# dotenv is loaded into os.environ.
try:
from hermes_cli.config import get_env_value
value = get_env_value("FAL_KEY")
except Exception:
value = None
return bool(value and value.strip())