Update backend status handling and improve user notifications

- Enhanced documentation to clarify the transition from 'Idle' to 'ready (running)' for backend states, improving user understanding of system readiness.
- Updated logging messages in the notification system to reflect the new backend status terminology, ensuring accurate feedback during operations.
- Refined access link collection logic to better handle tunneled and non-tunneled scenarios, enhancing user experience.
- Improved tests to validate the new backend status handling and ensure accurate reporting of access links and notifications.
This commit is contained in:
Leonid Pershin
2026-08-21 09:53:48 +03:00
parent 281ae15b12
commit 3e0a51cac4
11 changed files with 173 additions and 116 deletions
+47 -52
View File
@@ -39,60 +39,56 @@ def resolve_llm_runtime(cfg: Config) -> str:
def collect_access_links(cfg: Config, *, tunneled: bool) -> list[AccessLink]:
"""Build the list of user-facing endpoints (unit-tested).
When ``tunneled`` is False, still lists the same localhost URLs with a
«после tunnel» note — useful mid-``up`` before SSH forward is up.
"""
"""Build the list of user-facing endpoints (unit-tested)."""
links: list[AccessLink] = []
swarm = bool(getattr(cfg, "enable_swarmui", True))
soon = "" if tunneled else "после tunnel"
if swarm:
port = cfg.swarmui_local_port
base = f"http://127.0.0.1:{port}"
links.extend(
[
AccessLink("SwarmUI UI", base, soon or "браузер"),
AccessLink("SwarmUI API", f"{base}/API/", soon or "HTTP JSON"),
AccessLink("SwarmUI MCP", f"{base}/mcp", soon or "Cursor mcp.json"),
]
)
runtime = resolve_llm_runtime(cfg)
if runtime == "ollama":
o = cfg.ollama_local_port
links.extend(
[
if tunneled:
if swarm:
port = cfg.swarmui_local_port
base = f"http://127.0.0.1:{port}"
links.extend(
[
AccessLink("SwarmUI UI", base, "браузер"),
AccessLink("SwarmUI API", f"{base}/API/", "HTTP JSON"),
AccessLink("SwarmUI MCP", f"{base}/mcp", "Cursor mcp.json"),
]
)
runtime = resolve_llm_runtime(cfg)
if runtime == "ollama":
o = cfg.ollama_local_port
links.extend(
[
AccessLink(
"Ollama API",
f"http://127.0.0.1:{o}",
f"OLLAMA_HOST=http://127.0.0.1:{o}",
),
AccessLink(
"Ollama tags",
f"http://127.0.0.1:{o}/api/tags",
"список моделей",
),
AccessLink(
"Ollama chat",
f"http://127.0.0.1:{o}/api/chat",
"POST generate",
),
]
)
if not links:
links.append(
AccessLink(
"Ollama API",
f"http://127.0.0.1:{o}",
soon or f"OLLAMA_HOST=http://127.0.0.1:{o}",
),
AccessLink(
"Ollama tags",
f"http://127.0.0.1:{o}/api/tags",
soon or "список моделей",
),
AccessLink(
"Ollama chat",
f"http://127.0.0.1:{o}/api/chat",
soon or "POST generate",
),
]
)
if not links:
"Туннель",
"gpu-rent tunnel",
"нет сервисов — ENABLE_SWARMUI / LLM_RUNTIME",
)
)
else:
links.append(
AccessLink(
"Туннель",
"gpu-rent tunnel",
"нет сервисов — ENABLE_SWARMUI / LLM_RUNTIME",
)
)
elif not tunneled:
links.append(
AccessLink(
"Сейчас",
"ждём Idle → туннель",
"не открывай :7801 на ноутбуке — только :17801 после tunnel",
"gpu-rent tunnel --open",
"локальные URL появятся после tunnel",
)
)
return links
@@ -147,7 +143,7 @@ def render_access_panel(
if host:
subtitle.append(f" · VM {host}", style="dim")
else:
subtitle.append("URL ниже — после Idle откроется туннель", style="yellow")
subtitle.append("облако готово, туннеля нет", style="yellow")
if host:
subtitle.append(f" · FIP {host}", style="dim")
@@ -199,12 +195,11 @@ def print_access_card(
*,
tunneled: bool = True,
host: str | None = None,
title: str = "gpu-rent · доступы",
console: Console | None = None,
log: Log | None = None,
) -> None:
"""Print Rich panel; fall back to plain lines if needed."""
panel = render_access_panel(cfg, tunneled=tunneled, host=host, title=title)
panel = render_access_panel(cfg, tunneled=tunneled, host=host)
if console is not None:
console.print()
console.print(panel)
@@ -213,7 +208,7 @@ def print_access_card(
if log is not None:
# Plain fallback for non-Rich loggers
log("")
log(f"══ {title} ══")
log("══ gpu-rent · доступы ══")
try:
notes = load_state().notes or {}
if notes.get("idle_killer") == "failed":