feat(nous): tell a governed org its model choice is restricted
The gateway omits a policy-blocked model from `/v1/models` rather than marking it, so after the preceding commits a restricted model is simply absent from the pickers. That reads as "Hermes does not support this" instead of "your organization disallows it". Show one line when the org is governed, in the two flows where a user picks a model. It enumerates nothing: model policy is an allowlist, so an org admitting a handful of models blocks the whole rest of the catalog, and graying hundreds of rows would be a worse UI than omitting them. Driven by the `policy_present` claim, which is tri-state — the line shows only when it is explicitly true, because an absent claim means an older mint rather than an unrestricted org. The claim is stamped at mint time, so the line can lag a policy change by up to the access token's lifetime. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9438,6 +9438,11 @@ def _login_nous(args, pconfig: ProviderConfig) -> None:
|
||||
)
|
||||
_portal = auth_state.get("portal_base_url", "")
|
||||
if model_ids:
|
||||
from hermes_cli.nous_account import nous_policy_notice
|
||||
|
||||
_policy_notice = nous_policy_notice()
|
||||
if _policy_notice:
|
||||
print(_policy_notice)
|
||||
print(f"Showing {len(model_ids)} curated models — use \"Enter custom model name\" for others.")
|
||||
selected_model = _prompt_model_selection(
|
||||
model_ids, pricing=pricing,
|
||||
|
||||
@@ -581,6 +581,11 @@ def _model_flow_nous(config, current_model="", args=None):
|
||||
print(unavailable_message or f"Upgrade at {_url} to access paid models.")
|
||||
return
|
||||
|
||||
from hermes_cli.nous_account import nous_policy_notice
|
||||
|
||||
_policy_notice = nous_policy_notice()
|
||||
if _policy_notice:
|
||||
print(_policy_notice)
|
||||
print(
|
||||
f'Showing {len(model_ids)} curated models — use "Enter custom model name" for others.'
|
||||
)
|
||||
|
||||
@@ -427,6 +427,27 @@ def nous_policy_present() -> Optional[bool]:
|
||||
return None
|
||||
|
||||
|
||||
def nous_policy_notice() -> str:
|
||||
"""A one-line notice for an org that restricts model choice, else ``""``.
|
||||
|
||||
Under the gateway's policy filter a blocked model is omitted rather than
|
||||
marked, which reads as "Hermes does not support this" instead of "your org
|
||||
disallows it". This says which it is without enumerating anything: model
|
||||
policy is an allowlist, so an org that admits a handful of models blocks
|
||||
the whole rest of the catalog, and listing those would be a worse UI than
|
||||
omitting them.
|
||||
|
||||
Silent unless the claim is explicitly true — absent means an older mint,
|
||||
not an unrestricted org.
|
||||
"""
|
||||
if nous_policy_present() is not True:
|
||||
return ""
|
||||
return (
|
||||
"Your organization restricts which models are available — "
|
||||
"models outside its policy are not listed."
|
||||
)
|
||||
|
||||
|
||||
def _fresh_account_info(
|
||||
*,
|
||||
state: dict[str, Any],
|
||||
|
||||
@@ -157,3 +157,30 @@ class TestNousPolicyPresent:
|
||||
def test_undecodable_token_is_unknown(self, monkeypatch):
|
||||
self._patch_token(monkeypatch, "not-a-jwt")
|
||||
assert nous_policy_present() is None
|
||||
|
||||
|
||||
class TestNousPolicyNotice:
|
||||
"""A governed org is told its choice is restricted, rather than left to
|
||||
read an omitted model as one Hermes does not support."""
|
||||
|
||||
def _patch(self, monkeypatch, present):
|
||||
monkeypatch.setattr(account_mod, "nous_policy_present", lambda: present)
|
||||
|
||||
def test_shows_a_line_for_a_governed_org(self, monkeypatch):
|
||||
self._patch(monkeypatch, True)
|
||||
assert "restricts which models" in account_mod.nous_policy_notice()
|
||||
|
||||
@pytest.mark.parametrize("present", [False, None])
|
||||
def test_silent_otherwise(self, monkeypatch, present):
|
||||
"""Absent is an older mint, not an unrestricted org — either way there
|
||||
is nothing truthful to say."""
|
||||
self._patch(monkeypatch, present)
|
||||
assert account_mod.nous_policy_notice() == ""
|
||||
|
||||
def test_names_no_models(self, monkeypatch):
|
||||
"""Policy is an allowlist, so the blocked set is most of the catalog;
|
||||
the notice must not try to enumerate it."""
|
||||
self._patch(monkeypatch, True)
|
||||
notice = account_mod.nous_policy_notice()
|
||||
assert "/" not in notice, f"looks like it names a model: {notice}"
|
||||
assert len(notice.splitlines()) == 1
|
||||
|
||||
@@ -217,3 +217,23 @@ class TestNousPrefetch:
|
||||
)
|
||||
slugs = ms._collect_authed_provider_slugs({}, {"nous": list(CURATED)}, [])
|
||||
assert "nous" not in slugs
|
||||
|
||||
|
||||
class TestPolicyNoticeIsShown:
|
||||
"""The notice reaches the two flows where a user picks a model."""
|
||||
|
||||
def test_login_prints_it(self, monkeypatch, tmp_path, policy, capsys):
|
||||
import hermes_cli.nous_account as account_mod
|
||||
|
||||
monkeypatch.setattr(account_mod, "nous_policy_present", lambda: True)
|
||||
TestLoginNous()._run(monkeypatch, tmp_path)
|
||||
assert "restricts which models" in capsys.readouterr().out
|
||||
|
||||
def test_login_silent_for_an_ungoverned_org(
|
||||
self, monkeypatch, tmp_path, no_policy, capsys
|
||||
):
|
||||
import hermes_cli.nous_account as account_mod
|
||||
|
||||
monkeypatch.setattr(account_mod, "nous_policy_present", lambda: False)
|
||||
TestLoginNous()._run(monkeypatch, tmp_path)
|
||||
assert "restricts which models" not in capsys.readouterr().out
|
||||
|
||||
Reference in New Issue
Block a user