UI — client CLI

Shared Typer client CLI factory for Klea packages.

File: klea_utils/ui/cli.py

Copyright 2026 Ankur Sinha Author: Ankur Sinha <sanjay DOT ankur AT gmail DOT com>

klea_utils.ui.cli.make_client_app(*, label: str, server_url_default: str, app_module: str, tui_app_name: str, web_app_name: str, web_entry: str, config_env_var: str | None = None, config_dir: str | Path | None = None, template_writer: Callable[[Path], Path] | None = None) Typer[source]

Create a Typer app for a Klea user client (cli + web).

The app exposes cli / web subcommands for the terminal and NiceGUI clients respectively, each carrying its own options so --help on a subcommand lists everything it accepts. Invoked with no subcommand the app prints its usage help. All package-specific values are passed as parameters, so the rag and code entry points stay thin wrappers.

Both subcommands accept --profile: the value is validated and forwarded to a spawned local server through config_env_var (see klea_utils.api.server.configure_profile()), so the config file is chosen per invocation. A profile only applies to a server the client spawns itself; reusing an already-running server or pointing at a remote host ignores it with a warning. The special profile template scaffolds a new config and exits.

Parameters:
  • label – Short package name used in help text (e.g. "RAG")

  • server_url_default – Default server URL (e.g. "http://127.0.0.1:8005")

  • app_module – Uvicorn module string for the server this client talks to (e.g. "klea_rag.api.main:app")

  • tui_app_name – Log identity for the terminal client (e.g. "klea-rag-tui")

  • web_app_name – Log identity for the web client (e.g. "klea-rag-web")

  • web_entry – Module string of the app’s NiceGUI entry point (the app.py launched by the web subcommand, e.g. "klea_rag.ui.web.app")

  • config_env_var – Environment variable that carries the config file name into the spawned server (e.g. "KLEA_RAG_APP_CONFIG_FILE")

  • config_dir – Config directory searched after the working directory when validating --profile

  • template_writer – Callable that writes a config template into the working directory for --profile template

Returns:

A typer.Typer app for use as a CLI entry point