Files
hermes-agent/hermes_cli/web_routers/chat_ws_errors.py
Bear Huddleston b5eb5ee7a8 feat(webapp): carry the browser-hosted Desktop's server pieces from #93508
Carried from BearHuddleston's #93508 onto main. The Webapp relay and the
profile-incarnation fence stay out: carried code follows main's
named-profile rule and refuses a missing or deleted profile home.

- Webapp routes: one-use launch tickets, window handoff, and gateway
  WebSocket tickets minted for the signed-in browser
- Browser surface policy and the SPA document policy
- A host terminal for the browser that survives reconnects
- Staged browser uploads and file tickets; file.attach takes a staged upload
- hermes sessions adopt
- Webapp bundle build helpers and the renderer freshness check
- Regenerated gateway contracts

Co-authored-by: emozilla <emozilla@nousresearch.com>
2026-10-25 03:22:14 -07:00

49 lines
2.1 KiB
Python

"""User-facing copy for dashboard chat (``/api/pty``) start failures.
``pty_ws`` writes one red line into the terminal and closes with 1011 when the
``hermes --tui`` child cannot be spawned. The exception text alone is either
raw errno noise (``[Errno 2] No such file or directory: 'node'``), a bare exit
code (``SystemExit(1)`` after ``_make_tui_argv`` already printed to the server
log), or empty (``RegistryFull``). Turn each into what happened + what to do.
"""
from __future__ import annotations
from fastapi import HTTPException
from hermes_cli.pty_session import RegistryFull
CHAT_NEEDS_NODE = (
"{surface} could not start: Hermes needs Node.js to run the terminal chat. "
"Install Node 18+ (for example from nodejs.org) and reopen this tab."
)
CHAT_TOO_MANY_TERMINALS = (
"{surface} could not start: too many chat terminals are open in other tabs. "
"Close one and click Start new session."
)
CHAT_PROFILE_UNKNOWN = "{surface} could not start: {detail} Pick another profile from the switcher and reopen this tab."
CHAT_START_FAILED = "{surface} could not start: {detail} Check the server log (`hermes dashboard` terminal) and click Start new session."
def _node_missing(exc: BaseException) -> bool:
text = str(exc)
return isinstance(exc, SystemExit) or "'node'" in text or "'npm'" in text or "Node.js" in text
def chat_start_failure_message(exc: BaseException, *, surface: str = "Chat") -> str:
"""One plain sentence for the terminal pane; never the bare exception."""
if isinstance(exc, RegistryFull):
return CHAT_TOO_MANY_TERMINALS.format(surface=surface)
if isinstance(exc, HTTPException):
return CHAT_PROFILE_UNKNOWN.format(surface=surface, detail=_sentence(str(exc.detail)))
if _node_missing(exc):
return CHAT_NEEDS_NODE.format(surface=surface)
return CHAT_START_FAILED.format(surface=surface, detail=_sentence(str(exc) or type(exc).__name__))
def _sentence(text: str) -> str:
text = text.strip()
if not text:
return "the terminal process could not be launched."
return text if text.endswith((".", "!", "?")) else f"{text}."