mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-25 17:18:11 +00:00
fix(config): add a collision-safe env var name for custom endpoint keys
Both the Desktop panel and the CLI setup flow need somewhere in .env to put a custom endpoint's API key. Deriving the name from the endpoint's hostname collapses two servers on one machine onto a single slot, and every IP-based local endpoint slugs to a digit-leading name that save_env_value rejects outright. Key off the endpoint's own identity and keep a fixed prefix. Co-authored-by: asorry75 <33794789+asorry75@users.noreply.github.com> Co-authored-by: webtecnica <75556242+webtecnica@users.noreply.github.com>
This commit is contained in:
parent
bb4765d21c
commit
bfe7460c79
1 changed files with 19 additions and 0 deletions
|
|
@ -8209,6 +8209,25 @@ def save_env_value(key: str, value: str):
|
|||
invalidate_env_cache()
|
||||
|
||||
|
||||
def custom_endpoint_key_env(identity: str) -> str:
|
||||
"""Env var name holding a custom endpoint's API key.
|
||||
|
||||
``identity`` is whatever names the endpoint on the calling path — the
|
||||
Desktop panel's endpoint id, or ``host:port`` for the CLI setup flow.
|
||||
Two properties matter:
|
||||
|
||||
- It keys off the endpoint's own identity, not just its hostname, so two
|
||||
endpoints on one host (``127.0.0.1:8000`` and ``:8001``) get separate
|
||||
slots instead of the second save clobbering the first's credential.
|
||||
- The fixed ``HERMES_CUSTOM_`` prefix keeps the result a valid POSIX name
|
||||
even when the slug starts with a digit, which every IP-based local
|
||||
endpoint does (``127.0.0.1`` → ``127_0_0_1``). ``save_env_value``
|
||||
rejects digit-leading names outright.
|
||||
"""
|
||||
slug = re.sub(r"[^A-Z0-9]+", "_", str(identity or "").upper()).strip("_")
|
||||
return f"HERMES_CUSTOM_{slug}_API_KEY" if slug else "HERMES_CUSTOM_API_KEY"
|
||||
|
||||
|
||||
def remove_env_value(key: str) -> bool:
|
||||
"""Remove a key from ~/.hermes/.env and os.environ.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue