Skip to content

The agent that grows with you

fix(desktop): scope custom provider settings to the active profile

Brooklyn Nicholson1e6a7b3315fc
diff --git a/apps/desktop/src/hermes.ts b/apps/desktop/src/hermes.ts
index 24a31273317..a80dd621dee 100644
--- a/apps/desktop/src/hermes.ts
+++ b/apps/desktop/src/hermes.ts
@@ -912,12 +912,14 @@ export function validateProviderCredential(
export function getCustomEndpoints(): Promise<CustomEndpointsResponse> {
return window.hermesDesktop.api<CustomEndpointsResponse>({
+ ...profileScoped(),
path: '/api/providers/custom-endpoints'
})
}
export function saveCustomEndpoint(endpoint: CustomEndpointUpdate): Promise<CustomEndpointsResponse> {
return window.hermesDesktop.api<CustomEndpointsResponse>({
+ ...profileScoped(),
path: '/api/providers/custom-endpoints',
method: 'POST',
body: endpoint
@@ -934,6 +936,7 @@ export function validateCustomEndpoint(endpoint: CustomEndpointUpdate): Promise<
export function activateCustomEndpoint(id: string): Promise<{ ok: boolean; provider: string; model: string }> {
return window.hermesDesktop.api<{ ok: boolean; provider: string; model: string }>({
+ ...profileScoped(),
path: `/api/providers/custom-endpoints/${encodeURIComponent(id)}/activate`,
method: 'POST'
})
@@ -941,6 +944,7 @@ export function activateCustomEndpoint(id: string): Promise<{ ok: boolean; provi
export function deleteCustomEndpoint(id: string): Promise<CustomEndpointsResponse> {
return window.hermesDesktop.api<CustomEndpointsResponse>({
+ ...profileScoped(),
path: `/api/providers/custom-endpoints/${encodeURIComponent(id)}`,
method: 'DELETE'
})
diff --git a/hermes_cli/web_server.py b/hermes_cli/web_server.py
index 1628c13a184..beabd6aa139 100644
--- a/hermes_cli/web_server.py
+++ b/hermes_cli/web_server.py
@@ -7501,23 +7501,33 @@ def _write_custom_endpoint(cfg: Dict[str, Any], body: CustomEndpointUpdate) -> T
@app.get("/api/providers/custom-endpoints")
-def list_custom_endpoints():
- """Return configured OpenAI-compatible custom endpoints for Desktop."""
+def list_custom_endpoints(profile: Optional[str] = None):
+ """Return configured OpenAI-compatible custom endpoints for Desktop.
+
+ Scoped to the requested profile's config.yaml (issue: custom providers
+ only landing in the default profile): the desktop settings UI targets the
+ active profile, so read/write must resolve that profile's home rather than
+ the process-level HERMES_HOME. Mirrors ``/api/config``'s profile scoping.
+ """
try:
- return _custom_endpoint_response(load_config())
+ with _config_profile_scope(profile):
+ return _custom_endpoint_response(load_config())
+ except HTTPException:
+ raise
except Exception:
_log.exception("GET /api/providers/custom-endpoints failed")
raise HTTPException(status_code=500, detail="Failed to list custom endpoints")
@app.post("/api/providers/custom-endpoints")
-def upsert_custom_endpoint(body: CustomEndpointUpdate):
+def upsert_custom_endpoint(body: CustomEndpointUpdate, profile: Optional[str] = None):
"""Create or update a v12+ ``providers`` custom endpoint entry."""
try:
- cfg = load_config()
- endpoint_id, _entry = _write_custom_endpoint(cfg, body)
- save_config(cfg)
- response = _custom_endpoint_response(cfg)
+ with _config_profile_scope(profile):
+ cfg = load_config()
+ endpoint_id, _entry = _write_custom_endpoint(cfg, body)
+ save_config(cfg)
+ response = _custom_endpoint_response(cfg)
response["ok"] = True
response["id"] = endpoint_id
return response
@@ -7529,30 +7539,31 @@ def upsert_custom_endpoint(body: CustomEndpointUpdate):
@app.post("/api/providers/custom-endpoints/{endpoint_id}/activate")
-def activate_custom_endpoint(endpoint_id: str):
+def activate_custom_endpoint(endpoint_id: str, profile: Optional[str] = None):
"""Set a configured custom endpoint as the default model provider."""
try:
- cfg = load_config()
- provider_key = _custom_endpoint_id(endpoint_id)
- providers = cfg.get("providers")
- entry = providers.get(provider_key) if isinstance(providers, dict) else None
- if not isinstance(entry, dict):
- raise HTTPException(status_code=404, detail="custom endpoint not found")
-
- models = _models_from_custom_endpoint_entry(entry)
- model = str(entry.get("model") or (models[0] if models else "")).strip()
- base_url = str(entry.get("base_url") or "").strip()
- if not model or not base_url:
- raise HTTPException(status_code=400, detail="custom endpoint is incomplete")
-
- model_cfg = _apply_main_model_assignment(cfg.get("model", {}), provider_key, model, base_url)
- if entry.get("key_env"):
- model_cfg["key_env"] = entry["key_env"]
- model_cfg.pop("api_key", None)
- elif entry.get("api_key"):
- model_cfg["api_key"] = entry["api_key"]
- cfg["model"] = model_cfg
- save_config(cfg)
+ with _config_profile_scope(profile):
+ cfg = load_config()
+ provider_key = _custom_endpoint_id(endpoint_id)
+ providers = cfg.get("providers")
+ entry = providers.get(provider_key) if isinstance(providers, dict) else None
+ if not isinstance(entry, dict):
+ raise HTTPException(status_code=404, detail="custom endpoint not found")
+
+ models = _models_from_custom_endpoint_entry(entry)
+ model = str(entry.get("model") or (models[0] if models else "")).strip()
+ base_url = str(entry.get("base_url") or "").strip()
+ if not model or not base_url:
+ raise HTTPException(status_code=400, detail="custom endpoint is incomplete")
+
+ model_cfg = _apply_main_model_assignment(cfg.get("model", {}), provider_key, model, base_url)
+ if entry.get("key_env"):
+ model_cfg["key_env"] = entry["key_env"]
+ model_cfg.pop("api_key", None)
+ elif entry.get("api_key"):
+ model_cfg["api_key"] = entry["api_key"]
+ cfg["model"] = model_cfg
+ save_config(cfg)
return {"ok": True, "provider": provider_key, "model": model}
except HTTPException:
raise
@@ -7562,20 +7573,21 @@ def activate_custom_endpoint(endpoint_id: str):
@app.delete("/api/providers/custom-endpoints/{endpoint_id}")
-def delete_custom_endpoint(endpoint_id: str):
+def delete_custom_endpoint(endpoint_id: str, profile: Optional[str] = None):
"""Remove a configured custom endpoint from ``providers``."""
try:
- cfg = load_config()
- provider_key = _custom_endpoint_id(endpoint_id)
- providers = cfg.get("providers")
- if not isinstance(providers, dict) or provider_key not in providers:
- raise HTTPException(status_code=404, detail="custom endpoint not found")
- providers.pop(provider_key, None)
- cfg["providers"] = providers
- _detach_main_model_from_provider(cfg, provider_key)
- remove_env_value(custom_endpoint_key_env(provider_key))
- save_config(cfg)
- response = _custom_endpoint_response(cfg)
+ with _config_profile_scope(profile):
+ cfg = load_config()
+ provider_key = _custom_endpoint_id(endpoint_id)
+ providers = cfg.get("providers")
+ if not isinstance(providers, dict) or provider_key not in providers:
+ raise HTTPException(status_code=404, detail="custom endpoint not found")
+ providers.pop(provider_key, None)
+ cfg["providers"] = providers
+ _detach_main_model_from_provider(cfg, provider_key)
+ remove_env_value(custom_endpoint_key_env(provider_key))
+ save_config(cfg)
+ response = _custom_endpoint_response(cfg)
response["ok"] = True
return response
except HTTPException:
diff --git a/tests/hermes_cli/test_web_server.py b/tests/hermes_cli/test_web_server.py
index 8ab221730de..246f82d051e 100644
--- a/tests/hermes_cli/test_web_server.py
+++ b/tests/hermes_cli/test_web_server.py
@@ -1578,6 +1578,53 @@ class TestWebServerEndpoints:
assert not get_env_value(env_var), "deleted endpoint's key still in .env"
+ def test_custom_endpoint_save_scopes_to_the_requested_profile(self):
+ """``?profile=<name>`` must write into that profile's config.yaml.
+
+ The desktop settings UI targets the active profile, so a custom
+ endpoint saved while a non-default profile is selected has to land in
+ that profile's config — not the dashboard process's default home.
+ Before this fix the handlers ran bare ``load_config``/``save_config``,
+ so every custom provider silently landed in the default profile and
+ never appeared for the profile the user was actually configuring.
+ """
+ from hermes_constants import (
+ set_hermes_home_override,
+ reset_hermes_home_override,
+ )
+ from hermes_cli import profiles as profiles_mod
+ from hermes_cli.config import load_config
+
+ worker_home = profiles_mod.get_profile_dir("worker")
+ worker_home.mkdir(parents=True)
+
+ assert self.client.post(
+ "/api/providers/custom-endpoints?profile=worker",
+ json={
+ "id": "worker-proxy",
+ "name": "Worker Proxy",
+ "base_url": "https://llm.worker.example/v1",
+ "model": "worker/model-1",
+ },
+ ).status_code == 200
+
+ # The default (dashboard) profile must NOT have received the endpoint.
+ assert "worker-proxy" not in (load_config().get("providers") or {})
+
+ # The worker profile's own config.yaml must carry it.
+ token = set_hermes_home_override(str(worker_home))
+ try:
+ worker_cfg = load_config()
+ finally:
+ reset_hermes_home_override(token)
+ assert "worker-proxy" in (worker_cfg.get("providers") or {})
+
+ # And it comes back through the scoped GET, not the unscoped one.
+ scoped = self.client.get("/api/providers/custom-endpoints?profile=worker").json()
+ assert any(e["id"] == "worker-proxy" for e in scoped["endpoints"])
+ default_list = self.client.get("/api/providers/custom-endpoints").json()
+ assert not any(e["id"] == "worker-proxy" for e in default_list["endpoints"])
+
def test_custom_endpoint_save_keeps_the_api_key_out_of_config(self):
"""The key belongs in .env behind key_env, never in config.yaml (#69449)."""