From 0d0d40e2197c65da573f8add8f0b081566ae23ad Mon Sep 17 00:00:00 2001 From: Danny Stocker Date: Mon, 1 Dec 2025 08:10:36 +0100 Subject: [PATCH] feat: emit verbose client info when --verbose/--debug set --- openwebui_cli/http.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/openwebui_cli/http.py b/openwebui_cli/http.py index 4ce133e..c98bcd8 100644 --- a/openwebui_cli/http.py +++ b/openwebui_cli/http.py @@ -99,12 +99,17 @@ def create_client( if timeout is None: timeout = config.defaults.timeout - return httpx.Client( + client = httpx.Client( base_url=effective_uri, headers=headers, timeout=timeout, ) + if _is_verbose_enabled(): + _emit_verbose_config(effective_uri, headers, timeout) + + return client + def create_async_client( profile: str | None = None, @@ -153,12 +158,17 @@ def create_async_client( if timeout is None: timeout = config.defaults.timeout - return httpx.AsyncClient( + client = httpx.AsyncClient( base_url=effective_uri, headers=headers, timeout=timeout, ) + if _is_verbose_enabled(): + _emit_verbose_config(effective_uri, headers, timeout, async_client=True) + + return client + def handle_response(response: httpx.Response) -> dict[str, Any]: """ @@ -264,9 +274,24 @@ def _is_verbose_enabled() -> bool: try: import typer - ctx = typer.get_current_context(silent=True) + ctx = typer.core.TyperGroup.get_current_context(silent=True) # type: ignore[attr-defined] if ctx and isinstance(ctx.obj, dict): return bool(ctx.obj.get("verbose")) except Exception: return False return False + + +def _emit_verbose_config( + uri: str, headers: dict[str, str], timeout: float, async_client: bool = False +) -> None: + """Emit basic client config when verbose is enabled.""" + try: + Console().log( + f"[bold cyan]openwebui-cli[/bold cyan] client init " + f"(async={async_client}) uri={uri} timeout={timeout}s " + f"auth={'yes' if 'Authorization' in headers else 'no'}" + ) + except Exception: + # Do not break execution if logging fails + pass