feat(tui): auto-correct base URL if required path suffix is missing

Providers that need /v1 (lmstudio, llamacpp, qwen) now declare a
url_suffix field. The AI settings save action appends it automatically
and notifies the user if they entered a URL without it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
curo1305
2026-05-19 00:56:37 +02:00
parent a523fa61a3
commit fd6313acd9
2 changed files with 13 additions and 0 deletions
+9
View File
@@ -171,6 +171,15 @@ class _AITab(VerticalScroll):
base_url = self.query_one("#ai-base-url", Input).value.strip() or None
api_key = self.query_one("#ai-key", Input).value.strip()
if base_url and provider.url_suffix and not base_url.rstrip("/").endswith(provider.url_suffix):
base_url = base_url.rstrip("/") + provider.url_suffix
self.query_one("#ai-base-url", Input).value = base_url
self.app.notify(
f"Base URL must end with '{provider.url_suffix}' for {provider.display_name} — corrected automatically.",
severity="warning",
timeout=6,
)
cfg = load_config()
cfg.ai.provider_id = provider_id
cfg.ai.model = model
+4
View File
@@ -9,6 +9,7 @@ class Provider:
default_model: str
litellm_prefix: str
base_url: str | None = None
url_suffix: str | None = None # required path suffix for custom base URLs (e.g. "/v1")
key_env_var: str | None = None
connectivity_check: str | None = None
group: str = "Cloud"
@@ -23,6 +24,7 @@ PROVIDERS: list[Provider] = [
default_model="local-model",
litellm_prefix="openai/",
base_url="http://localhost:1234/v1",
url_suffix="/v1",
connectivity_check="http://localhost:1234/v1/models",
group="Local",
),
@@ -43,6 +45,7 @@ PROVIDERS: list[Provider] = [
default_model="local-model",
litellm_prefix="openai/",
base_url="http://localhost:8080/v1",
url_suffix="/v1",
connectivity_check="http://localhost:8080/v1/models",
group="Local",
),
@@ -90,6 +93,7 @@ PROVIDERS: list[Provider] = [
default_model="openai/qwen-plus",
litellm_prefix="openai/",
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
url_suffix="/v1",
key_env_var="DASHSCOPE_API_KEY",
group="Cloud",
),