feat(desktop): Nous free tier on Hermes Desktop (#105260)
* feat(desktop): free-tier state over RPC, status routes that name it, and a sign-in that keeps connectors The desktop learns about the Nous free tier by reading local auth state (pull): free_tier.status answers has_guest / enabled / carries_inference / notice_pending with zero network, and free_tier.ack_notice persists the one-time notice flag on the identity itself. setup.runtime_check reports free_tier for the selected route; /api/portal, the Nous card in /api/providers/oauth and billing.state carry free_tier (billing answers the free tier locally instead of a portal call that can only fail). The free-tier picker row carries an explicit free_tier_row flag and is never priced or locked. POST /api/providers/oauth/nous/start over a free-tier identity registers the connector transfer and returns its code and consent URL; the poller waits for the transfer before the token grant, persists the account, runs settle_after_upgrade, and the poll response gains reason, account_email and model. * feat(desktop): free tier on Hermes Desktop: ready screen, notice strip, status chip, Billing view, one sign-in dialog The renderer reads the free tier from free_tier.status (pull) into one store; the first-launch intro is the same state rendered two ways, keyed on the backend's one-time flag: the onboarding overlay opens on a ready screen when the free tier carries inference, else a one-time strip above the composer. Settings > Billing gains a free_tier view (notice with one Sign in, Plan / Model / Connectors summary, plan card, footnote; no payment or usage rows). A status-bar chip names the tier and model while it carries inference. Every entry point opens one claimed sign-in dialog that drives the extended oauth/nous route and maps the poll's status and reason to the ruled screens; Done settles billing, model options, providers and re-homes a session still on nous/welcome. The picker badge also fires on free_tier_row. Docs: Desktop section in the free-tier guide, AGENTS notes. * fix(desktop): free_tier.status starts the free tier's background setup when no identity exists A served backend has no session-setup moment like the CLI's, so beside an explicit provider the free tier was never set up on the desktop: no connectors, no notice strip. The first status read now starts the same one-attempt background setup; the call itself never waits. * fix(desktop): one Sign in on the Billing page; Settings > Providers names the free tier, never Connected The free-tier plan card is the what-you-get text alone (the notice carries the page's one Sign in). The Nous provider row reads Nous · free tier with a Free tier tag while the identity is the free tier, instead of Nous Portal · Connected. * fix(desktop): Settings > Providers never files the free tier under Connected * fix(desktop): the intro's shape is keyed on the route, not on the identity free_tier.status reports available (an identity exists and the tier is on); whether inference runs on the free tier is setup.runtime_check.free_tier, keyed on the resolved endpoint. The ready screen shows when that route is the free tier; the composer strip when the user's own provider carries inference. An own-key install used to get the ready screen. * docs(desktop): say what the free-tier chip is keyed on * fix(desktop): the featured Nous row's pitch on the free tier says what signing in adds * fix(desktop): a cancelled or superseded sign-in attempt can no longer change the identity or hide the intro Four lifecycle holes from review. The Nous poller checks the session's cancelled flag after the transfer wait, after the token grant, and once more under the session lock together with the save, so a sign-in the user abandoned never persists. The renderer's sign-in store carries an attempt generation that every continuation checks after each await, so a poll from a closed attempt cannot publish over the one on screen (and its backend session is cancelled). The ready screen comes down only after the backend recorded the acknowledgement. A composer still mounted takes over the notice claim when its owner unmounts. One thin test per hole.
This commit is contained in:
@@ -198,8 +198,15 @@ def _oauth_poller(label: str):
|
||||
try:
|
||||
fn(session_id, sess)
|
||||
with _oauth_sessions_lock:
|
||||
sess["status"] = "approved"
|
||||
_log.info("oauth/device: %s login completed (session=%s)", label, session_id)
|
||||
# A body that already settled the session (a sign-in the user declined in the
|
||||
# browser is ``denied`` with a ``reason``) keeps its verdict.
|
||||
settled = sess["status"] != "pending"
|
||||
if not settled:
|
||||
sess["status"] = "approved"
|
||||
if settled:
|
||||
_log.info("oauth/device: %s login ended %s (session=%s)", label, sess["status"], session_id)
|
||||
else:
|
||||
_log.info("oauth/device: %s login completed (session=%s)", label, session_id)
|
||||
except Exception as e:
|
||||
_log.warning("%s device-code poll failed (session=%s): %s", label, session_id, e)
|
||||
with _oauth_sessions_lock:
|
||||
@@ -209,19 +216,71 @@ def _oauth_poller(label: str):
|
||||
return deco
|
||||
|
||||
|
||||
def _settle_promotion_failure(sess: Dict[str, Any], outcome: Dict[str, Any]) -> None:
|
||||
"""Record a transfer that did not complete on the session: ``denied`` when the user rejected it in
|
||||
the browser, else ``error``; ``reason`` and the ruled copy ride along for the renderer."""
|
||||
from hermes_cli import anon_auth
|
||||
status = str(outcome.get("status") or "unknown")
|
||||
reason = "timeout" if status == "timeout" else str(outcome.get("reason") or status)
|
||||
message = (anon_auth.UPGRADE_TIMED_OUT if reason == "timeout"
|
||||
else anon_auth.UPGRADE_REASON_COPY.get(reason, anon_auth.UPGRADE_NOT_COMPLETED))
|
||||
with _oauth_sessions_lock:
|
||||
sess["status"] = "denied" if reason == "user_declined" else "error"
|
||||
sess["reason"] = reason
|
||||
sess["error_message"] = message
|
||||
if reason in anon_auth._RETIRED_REASONS:
|
||||
anon_auth.clear_dead_guest("retired")
|
||||
|
||||
|
||||
@_oauth_poller("nous")
|
||||
def _nous_poller(session_id: str, sess: Dict[str, Any]) -> None:
|
||||
"""Background poller that drives a Nous device-code flow to completion."""
|
||||
"""Background poller that drives a Nous device-code flow to completion.
|
||||
|
||||
A session started over a free-tier identity carries ``claim_code``: the transfer of that identity's
|
||||
connectors into the account is watched first (``wait_for_promotion``), and only a completed
|
||||
transfer is followed by the token grant, so an install never loses its connectors to a sign-in the
|
||||
user did not confirm. Every completion then runs ``settle_after_upgrade`` so a config still on the
|
||||
free tier's route moves to the account's host and model; ``account_email`` and ``model`` land on
|
||||
the session for the poll response.
|
||||
"""
|
||||
from hermes_cli.web_server_profiles import _profile_scope
|
||||
from hermes_cli.auth import _poll_for_token, persist_nous_credentials, refresh_nous_oauth_from_state
|
||||
from hermes_cli import anon_auth
|
||||
import httpx
|
||||
portal_base_url, client_id = sess["portal_base_url"], sess["client_id"]
|
||||
claim_code = str(sess.get("claim_code") or "")
|
||||
outcome: Dict[str, Any] = {}
|
||||
|
||||
def _cancelled() -> bool:
|
||||
# The user abandoned this sign-in (DELETE /sessions/{id}) while this thread was blocked
|
||||
# on the portal: nothing it learns afterwards may reach the auth store.
|
||||
with _oauth_sessions_lock:
|
||||
if sess.get("cancelled"):
|
||||
sess["status"] = "cancelled"
|
||||
return True
|
||||
return False
|
||||
|
||||
with httpx.Client(timeout=httpx.Timeout(15.0), headers={"Accept": "application/json"}) as client:
|
||||
expires_in = max(60, int(sess["expires_at"] - time.time()))
|
||||
if claim_code:
|
||||
try:
|
||||
outcome = anon_auth.wait_for_promotion(
|
||||
client, portal_base_url, claim_code, expires_in=expires_in, interval=int(sess["interval"]))
|
||||
except anon_auth.AnonCredentialDead:
|
||||
outcome = {"status": "voided", "reason": "account_retired"}
|
||||
if _cancelled():
|
||||
return
|
||||
if str(outcome.get("status")) != "completed":
|
||||
with _profile_scope(_oauth_session_profile(session_id)):
|
||||
_settle_promotion_failure(sess, outcome)
|
||||
return
|
||||
token_data = _poll_for_token(
|
||||
client=client, portal_base_url=portal_base_url, client_id=client_id,
|
||||
device_code=sess["device_code"], expires_in=max(60, int(sess["expires_at"] - time.time())),
|
||||
device_code=sess["device_code"], expires_in=expires_in,
|
||||
poll_interval=sess["interval"],
|
||||
)
|
||||
if _cancelled():
|
||||
return
|
||||
# Same post-processing as _nous_device_code_login (validate/refresh JWT)
|
||||
now = datetime.now(timezone.utc)
|
||||
token_ttl = int(token_data.get("expires_in") or 0)
|
||||
@@ -242,7 +301,19 @@ def _nous_poller(session_id: str, sess: Dict[str, Any]) -> None:
|
||||
}
|
||||
with _profile_scope(_oauth_session_profile(session_id)):
|
||||
full_state = refresh_nous_oauth_from_state(auth_state, timeout_seconds=15.0, force_refresh=False)
|
||||
persist_nous_credentials(full_state)
|
||||
if claim_code:
|
||||
full_state["auth_method"] = anon_auth.UPGRADED_AUTH_METHOD
|
||||
# The final cancellation check and the save share the session lock, so a cancel cannot
|
||||
# land between them; the settle step (which may contact the portal) runs after the lock.
|
||||
with _oauth_sessions_lock:
|
||||
if sess.get("cancelled"):
|
||||
sess["status"] = "cancelled"
|
||||
return
|
||||
persist_nous_credentials(full_state)
|
||||
settled = anon_auth.settle_after_upgrade(full_state)
|
||||
with _oauth_sessions_lock:
|
||||
sess["account_email"] = str(outcome.get("account_email") or "") or None
|
||||
sess["model"] = settled.get("model") or None
|
||||
|
||||
|
||||
@_oauth_poller("minimax")
|
||||
|
||||
Reference in New Issue
Block a user