feat(onboard): add ShengSuanYun Quick Start template
This commit is contained in:
1 parent
2b889b8408
commit
24d41de002
3 files changed
+195
-57
No files matched your search
@@ -304,7 +304,7 @@ A Base URL is the service address nanobot sends model requests to. Change it onl
|
||||
> - **Kimi Coding Plan**: Use `providers.kimiCoding` with `provider: "kimi_coding"` for Kimi's dedicated Anthropic Messages API endpoint. The endpoint requires a Claude-compatible `User-Agent`; nanobot sends `claude-code/0.1.0` by default, and you can override it with `extraHeaders.User-Agent` if your account requires a different value.
|
||||
> - **VolcEngine / BytePlus Coding Plan**: Subscription endpoints are configured through dedicated providers `volcengineCodingPlan` or `byteplusCodingPlan`, separate from the pay-per-use `volcengine` / `byteplus` providers.
|
||||
> - **OpenCode Zen / Go**: `providers.opencode` (canonical Zen), the legacy-compatible `providers.opencodeZen`, and `providers.opencodeGo` use the same `OPENCODE_API_KEY`, but route to different OpenCode gateways. These providers use OpenCode's OpenAI-compatible `chat/completions` endpoints; choose model IDs from that endpoint family.
|
||||
> - **ShengSuanYun (胜算云)**: Search for **ShengSuanYun Router** in **Add provider** to prefill the [Router API URL](https://lean.shengsuanyun.com/apidocs/guides/quick-start). Enter your API key and save the custom connection. Use the full model ID, for example `deepseek/deepseek-v4-flash`. Chat Completions is the default; select Responses in a preset's **Advanced options** only for a model that supports it.
|
||||
> - **ShengSuanYun (胜算云)**: Search for **ShengSuanYun Router** in **Add provider**, or select it under **Quick Start** in `nanobot onboard --wizard`. Both prefill the [Router API URL](https://lean.shengsuanyun.com/apidocs/guides/quick-start) for a custom connection. Enter your API key and use the full model ID, for example `deepseek/deepseek-v4-flash`. The wizard saves a separate model preset and keeps any configured default model. Chat Completions is the default; select Responses in a preset's **Advanced options** only for a model that supports it.
|
||||
> - **Zhipu Coding Plan**: If you're on Zhipu's coding plan, open the zhipu connection in **Settings → Models** and set its base URL to `https://open.bigmodel.cn/api/coding/paas/v4`.
|
||||
> - **Alibaba Cloud BaiLian**: The built-in `dashscope` provider already defaults to `https://dashscope.aliyuncs.com/compatible-mode/v1`; no endpoint override is needed for that service.
|
||||
> - **ModelScope**: The built-in `modelscope` provider already defaults to `https://api-inference.modelscope.cn/v1`; no endpoint override is needed for that service.
|
||||
|
||||
+74
-41
@@ -29,7 +29,7 @@ from nanobot.cli.models import (
|
||||
get_model_context_limit,
|
||||
)
|
||||
from nanobot.config.loader import get_config_path, load_config
|
||||
from nanobot.config.schema import Config, ModelPresetConfig
|
||||
from nanobot.config.schema import Config, ModelPresetConfig, ProviderAPIConfig, ProviderConfig
|
||||
from nanobot.providers.oauth_guidance import OAUTH_CLI_KIT_MISSING_MESSAGE
|
||||
|
||||
console = Console()
|
||||
@@ -77,6 +77,9 @@ _BACK_PRESSED = object()
|
||||
_MODEL_PRESET_CACHE: set[str] = set()
|
||||
|
||||
_QUICK_START_CUSTOM_PROVIDER_CHOICE = "Other OpenAI-compatible"
|
||||
_QUICK_START_SHENGSUANYUN = _QuickStartEndpointChoice(
|
||||
"ShengSuanYun Router (胜算云)", "https://router.shengsuanyun.com/api/v1",
|
||||
)
|
||||
_QUICK_START_OAUTH_PROVIDERS = {"openai_codex"}
|
||||
|
||||
_CLEAR_CHOICE = "Clear value"
|
||||
@@ -1385,17 +1388,28 @@ def _show_summary(config: Config) -> None:
|
||||
_pause()
|
||||
|
||||
|
||||
def _pause(message: str = "Press Enter to continue...") -> None:
|
||||
_get_questionary().text(message, default="").ask()
|
||||
def _pause(message: str = "Press Enter to continue...") -> bool:
|
||||
return _get_questionary().text(message, default="").ask() is not None
|
||||
|
||||
|
||||
def _set_primary_quick_start_preset(config: Config, provider_name: str, model: str) -> None:
|
||||
config.model_presets["primary"] = ModelPresetConfig(
|
||||
model=model,
|
||||
provider=provider_name,
|
||||
)
|
||||
config.agents.defaults.model_preset = "primary"
|
||||
_sync_preset_cache(config)
|
||||
def _shengsuanyun_quick_start_names(config: Config) -> tuple[str, str, str]:
|
||||
connections = config.providers.model_extra or {}
|
||||
keys = {key.replace("_", "-").lower() for key in connections}
|
||||
labels = {
|
||||
(provider.display_name or key.replace("_", " ").replace("-", " ")).strip().casefold()
|
||||
for key, provider in connections.items()
|
||||
if isinstance(provider, ProviderConfig)
|
||||
}
|
||||
presets = {name.casefold() for name in config.model_presets}
|
||||
index = 1
|
||||
while True:
|
||||
suffix = f"-{index}" if index > 1 else ""
|
||||
key = f"custom-shengsuanyun-router{suffix}"
|
||||
preset = f"shengsuanyun{suffix}"
|
||||
label = "ShengSuanYun Router" + (f" {index}" if suffix else "")
|
||||
if key not in keys and label.casefold() not in labels and preset not in presets:
|
||||
return key, preset, label
|
||||
index += 1
|
||||
|
||||
|
||||
def _show_quick_start_progress(active_step: int) -> None:
|
||||
@@ -1440,6 +1454,7 @@ def _get_quick_start_provider_choices() -> dict[str, str]:
|
||||
choices: dict[str, str] = {}
|
||||
for provider_name, info in _get_quick_start_provider_info().items():
|
||||
choices.setdefault(info.display_name, provider_name)
|
||||
choices[_QUICK_START_SHENGSUANYUN.label] = "custom"
|
||||
choices[_QUICK_START_CUSTOM_PROVIDER_CHOICE] = "custom"
|
||||
return choices
|
||||
|
||||
@@ -1564,7 +1579,7 @@ def _select_quick_start_api_base(
|
||||
return api_base, True
|
||||
|
||||
|
||||
def _configure_quick_start_provider(config: Config) -> bool | object:
|
||||
def _configure_quick_start_provider(config: Config) -> str | object:
|
||||
while True:
|
||||
_show_quick_start_progress(1)
|
||||
|
||||
@@ -1578,6 +1593,7 @@ def _configure_quick_start_provider(config: Config) -> bool | object:
|
||||
assert isinstance(answer, str)
|
||||
provider_name = provider_choices[answer]
|
||||
provider_info = _get_quick_start_provider_info().get(provider_name)
|
||||
shengsuanyun = answer == _QUICK_START_SHENGSUANYUN.label
|
||||
|
||||
api_base = provider_info.default_api_base if provider_info else ""
|
||||
base_was_prompted = False
|
||||
@@ -1594,18 +1610,20 @@ def _configure_quick_start_provider(config: Config) -> bool | object:
|
||||
|
||||
api_key: str | None = None
|
||||
if _quick_start_requires_api_key(provider_name, provider_info):
|
||||
api_key = _input_text(f"{answer} API key", "", "str")
|
||||
if api_key is _BACK_PRESSED:
|
||||
prompt = f"{answer} API key"
|
||||
key_answer = _input_secret(prompt) if shengsuanyun else _input_text(prompt, "", "str")
|
||||
if key_answer is _BACK_PRESSED:
|
||||
continue
|
||||
if api_key is None:
|
||||
if key_answer is None:
|
||||
return False
|
||||
api_key = api_key.strip()
|
||||
api_key = cast(str, key_answer).strip()
|
||||
if not api_key:
|
||||
console.print("[yellow]! API key is required for Quick Start[/yellow]")
|
||||
return False
|
||||
|
||||
if (
|
||||
provider_name not in _QUICK_START_ENDPOINT_CHOICES
|
||||
not shengsuanyun
|
||||
and provider_name not in _QUICK_START_ENDPOINT_CHOICES
|
||||
and _quick_start_requires_base_url(provider_name, provider_info)
|
||||
):
|
||||
api_base_result = _select_quick_start_api_base(provider_name, answer, provider_info)
|
||||
@@ -1618,13 +1636,22 @@ def _configure_quick_start_provider(config: Config) -> bool | object:
|
||||
api_base_result,
|
||||
)
|
||||
|
||||
provider_config = getattr(config.providers, provider_name, None)
|
||||
if provider_config is None:
|
||||
catalog_config = config.model_copy(deep=True)
|
||||
preset_name = "primary"
|
||||
if shengsuanyun:
|
||||
provider_name, preset_name, label = _shengsuanyun_quick_start_names(config)
|
||||
catalog_provider = ProviderConfig(
|
||||
display_name=label,
|
||||
api_base=_QUICK_START_SHENGSUANYUN.api_base,
|
||||
api=ProviderAPIConfig(supported_apis=("chat_completions", "responses")),
|
||||
)
|
||||
setattr(catalog_config.providers, provider_name, catalog_provider)
|
||||
else:
|
||||
catalog_provider = getattr(catalog_config.providers, provider_name, None)
|
||||
if catalog_provider is None:
|
||||
console.print(f"[red]Unknown provider: {provider_name}[/red]")
|
||||
return False
|
||||
|
||||
catalog_config = config.model_copy(deep=True)
|
||||
catalog_provider = getattr(catalog_config.providers, provider_name)
|
||||
if api_key is not None:
|
||||
catalog_provider.api_key = api_key
|
||||
if api_base and (base_was_prompted or not catalog_provider.api_base):
|
||||
@@ -1647,20 +1674,13 @@ def _configure_quick_start_provider(config: Config) -> bool | object:
|
||||
if not _quick_start_oauth_login(config, provider_name):
|
||||
return False
|
||||
|
||||
if api_key is not None:
|
||||
provider_config.api_key = api_key
|
||||
if api_base:
|
||||
if base_was_prompted:
|
||||
provider_config.api_base = api_base
|
||||
elif not provider_config.api_base:
|
||||
provider_config.api_base = api_base
|
||||
|
||||
_set_primary_quick_start_preset(
|
||||
config,
|
||||
provider_name,
|
||||
model,
|
||||
)
|
||||
return True
|
||||
defaults = config.agents.defaults
|
||||
if not shengsuanyun or (defaults.model_preset is None and config.get_provider() is None):
|
||||
defaults.model_preset = preset_name
|
||||
setattr(config.providers, provider_name, catalog_provider)
|
||||
config.model_presets[preset_name] = ModelPresetConfig(model=model, provider=provider_name)
|
||||
_sync_preset_cache(config)
|
||||
return preset_name
|
||||
|
||||
|
||||
def _enable_quick_start_websocket_defaults(config: Config) -> bool:
|
||||
@@ -1707,9 +1727,14 @@ def _enable_quick_start_websocket_defaults(config: Config) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def _show_quick_start_summary(config: Config) -> None:
|
||||
def _quick_start_websocket_enabled(config: Config) -> bool:
|
||||
websocket: Any = getattr(config.channels, "websocket", None)
|
||||
return bool(websocket and websocket.get("enabled"))
|
||||
|
||||
|
||||
def _show_quick_start_summary(config: Config, preset_name: str) -> None:
|
||||
_show_quick_start_progress(3)
|
||||
preset = config.model_presets.get("primary")
|
||||
preset = config.model_presets.get(preset_name)
|
||||
provider_label = "AI provider"
|
||||
credentials_ready = True
|
||||
credential_name = "API key"
|
||||
@@ -1735,8 +1760,11 @@ def _show_quick_start_summary(config: Config) -> None:
|
||||
|
||||
rows = [
|
||||
("Status", status),
|
||||
("WebSocket channel", "enabled"),
|
||||
("Model preset", preset_name),
|
||||
("WebSocket channel", "enabled" if _quick_start_websocket_enabled(config) else "disabled"),
|
||||
]
|
||||
if config.agents.defaults.model_preset != preset_name:
|
||||
rows.insert(2, ("Default model", f"unchanged (switch with /model {preset_name})"))
|
||||
_print_summary_panel(rows, "Quick Start")
|
||||
|
||||
|
||||
@@ -1750,14 +1778,19 @@ def _configure_quick_start(config: Config) -> bool:
|
||||
provider_result = _configure_quick_start_provider(draft)
|
||||
if provider_result is _BACK_PRESSED:
|
||||
return False
|
||||
if not provider_result:
|
||||
if not isinstance(provider_result, str):
|
||||
_pause()
|
||||
return False
|
||||
if not _enable_quick_start_websocket_defaults(draft):
|
||||
needs_websocket_setup = provider_result == "primary" or (
|
||||
draft.agents.defaults.model_preset == provider_result
|
||||
and not _quick_start_websocket_enabled(draft)
|
||||
)
|
||||
if needs_websocket_setup and not _enable_quick_start_websocket_defaults(draft):
|
||||
_pause()
|
||||
return False
|
||||
_show_quick_start_summary(draft)
|
||||
_pause("Press Enter to save and exit...")
|
||||
_show_quick_start_summary(draft, provider_result)
|
||||
if not _pause("Press Enter to save and exit..."):
|
||||
return False
|
||||
for field_name in type(config).model_fields:
|
||||
setattr(config, field_name, getattr(draft, field_name))
|
||||
return True
|
||||
|
||||
@@ -2,11 +2,13 @@ from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from typing import Any, cast
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
from prompt_toolkit.application import create_app_session
|
||||
from prompt_toolkit.input import create_pipe_input
|
||||
from prompt_toolkit.output import DummyOutput
|
||||
from pydantic import BaseModel, Field
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from nanobot.cli import onboard as onboard_wizard
|
||||
from nanobot.cli.onboard import (
|
||||
@@ -19,8 +21,11 @@ from nanobot.cli.onboard import (
|
||||
_input_text,
|
||||
run_onboard,
|
||||
)
|
||||
from nanobot.config.loader import merge_missing_defaults
|
||||
from nanobot.config import home as instance_home
|
||||
from nanobot.config import loader
|
||||
from nanobot.config.loader import load_config, merge_missing_defaults, save_config
|
||||
from nanobot.config.schema import Config, ModelPresetConfig
|
||||
from nanobot.providers.routing import resolve_provider_route
|
||||
from nanobot.utils.helpers import sync_workspace_templates
|
||||
|
||||
|
||||
@@ -953,7 +958,7 @@ class TestMainMenuInteraction:
|
||||
or True,
|
||||
)
|
||||
|
||||
assert onboard_wizard._configure_quick_start_provider(config) is True
|
||||
assert onboard_wizard._configure_quick_start_provider(config) == "primary"
|
||||
|
||||
assert oauth_calls == [(config, "openai_codex")]
|
||||
assert model_prompts == [
|
||||
@@ -1113,6 +1118,7 @@ class TestMainMenuInteraction:
|
||||
|
||||
def test_quick_start_summary_reports_missing_codex_oauth(self, monkeypatch):
|
||||
config = Config()
|
||||
config.channels.websocket = {"enabled": True}
|
||||
config.model_presets["primary"] = ModelPresetConfig(
|
||||
model="openai-codex/gpt-5.6-sol",
|
||||
provider="openai_codex",
|
||||
@@ -1131,7 +1137,7 @@ class TestMainMenuInteraction:
|
||||
lambda rows, _title: captured.setdefault("rows", rows),
|
||||
)
|
||||
|
||||
onboard_wizard._show_quick_start_summary(config)
|
||||
onboard_wizard._show_quick_start_summary(config, "primary")
|
||||
|
||||
rows = dict(captured["rows"])
|
||||
assert rows["Status"] == "OpenAI Codex OAuth login missing"
|
||||
@@ -1171,7 +1177,11 @@ class TestMainMenuInteraction:
|
||||
)
|
||||
monkeypatch.setattr(onboard_wizard, "_configure_pydantic_model", fail_websocket_config)
|
||||
monkeypatch.setattr(onboard_wizard, "_print_summary_panel", lambda *a, **kw: None)
|
||||
monkeypatch.setattr(onboard_wizard, "_pause", lambda message="": pause_messages.append(message))
|
||||
def pause(message=""):
|
||||
pause_messages.append(message)
|
||||
return True
|
||||
|
||||
monkeypatch.setattr(onboard_wizard, "_pause", pause)
|
||||
|
||||
assert onboard_wizard._configure_quick_start(config) is True
|
||||
|
||||
@@ -1271,7 +1281,7 @@ class TestMainMenuInteraction:
|
||||
|
||||
monkeypatch.setattr(onboard_wizard, "_input_model_with_autocomplete", fake_model_input)
|
||||
|
||||
assert onboard_wizard._configure_quick_start_provider(config) is True
|
||||
assert onboard_wizard._configure_quick_start_provider(config) == "primary"
|
||||
|
||||
assert model_prompts == [("Model ID", "", "openrouter")]
|
||||
assert config.providers.openrouter.api_key == "sk-or-test"
|
||||
@@ -1295,7 +1305,7 @@ class TestMainMenuInteraction:
|
||||
lambda *a, **kw: "llama3.2",
|
||||
)
|
||||
|
||||
assert onboard_wizard._configure_quick_start_provider(config) is True
|
||||
assert onboard_wizard._configure_quick_start_provider(config) == "primary"
|
||||
|
||||
assert config.providers.ollama.api_key is None
|
||||
assert config.providers.ollama.api_base == "http://localhost:11434/v1"
|
||||
@@ -1314,7 +1324,7 @@ class TestMainMenuInteraction:
|
||||
lambda *a, **kw: "gpt-4o-mini",
|
||||
)
|
||||
|
||||
assert onboard_wizard._configure_quick_start_provider(config) is True
|
||||
assert onboard_wizard._configure_quick_start_provider(config) == "primary"
|
||||
|
||||
assert config.providers.openai.api_key == "sk-openai-test"
|
||||
assert config.providers.openai.api_base is None
|
||||
@@ -1341,7 +1351,7 @@ class TestMainMenuInteraction:
|
||||
lambda *a, **kw: "gpt-4o-mini",
|
||||
)
|
||||
|
||||
assert onboard_wizard._configure_quick_start_provider(config) is True
|
||||
assert onboard_wizard._configure_quick_start_provider(config) == "primary"
|
||||
|
||||
assert selected_providers == ["DeepSeek", "OpenAI"]
|
||||
assert config.providers.deepseek.api_key is None
|
||||
@@ -1361,7 +1371,7 @@ class TestMainMenuInteraction:
|
||||
lambda *a, **kw: "glm-4.6",
|
||||
)
|
||||
|
||||
assert onboard_wizard._configure_quick_start_provider(config) is True
|
||||
assert onboard_wizard._configure_quick_start_provider(config) == "primary"
|
||||
|
||||
assert config.providers.zhipu.api_key == "zhipu-key"
|
||||
assert config.providers.zhipu.api_base == "https://open.bigmodel.cn/api/coding/paas/v4"
|
||||
@@ -1381,7 +1391,7 @@ class TestMainMenuInteraction:
|
||||
lambda *a, **kw: "MiniMax-M2",
|
||||
)
|
||||
|
||||
assert onboard_wizard._configure_quick_start_provider(config) is True
|
||||
assert onboard_wizard._configure_quick_start_provider(config) == "primary"
|
||||
|
||||
assert config.providers.minimax.api_key == "minimax-key"
|
||||
assert config.providers.minimax.api_base == "https://api.minimaxi.com/v1"
|
||||
@@ -1401,7 +1411,7 @@ class TestMainMenuInteraction:
|
||||
lambda *a, **kw: "step-3.5-flash",
|
||||
)
|
||||
|
||||
assert onboard_wizard._configure_quick_start_provider(config) is True
|
||||
assert onboard_wizard._configure_quick_start_provider(config) == "primary"
|
||||
|
||||
assert config.providers.stepfun.api_key == "stepfun-key"
|
||||
assert config.providers.stepfun.api_base == "https://api.stepfun.ai/step_plan/v1"
|
||||
@@ -1421,7 +1431,7 @@ class TestMainMenuInteraction:
|
||||
lambda *a, **kw: "mimo-v2.5-pro",
|
||||
)
|
||||
|
||||
assert onboard_wizard._configure_quick_start_provider(config) is True
|
||||
assert onboard_wizard._configure_quick_start_provider(config) == "primary"
|
||||
|
||||
assert config.providers.xiaomi_mimo.api_key == "mimo-key"
|
||||
assert config.providers.xiaomi_mimo.api_base == "https://token-plan-sgp.xiaomimimo.com/v1"
|
||||
@@ -1445,13 +1455,107 @@ class TestMainMenuInteraction:
|
||||
lambda *a, **kw: "custom-model",
|
||||
)
|
||||
|
||||
assert onboard_wizard._configure_quick_start_provider(config) is True
|
||||
assert onboard_wizard._configure_quick_start_provider(config) == "primary"
|
||||
|
||||
assert config.providers.custom.api_key == "sk-custom-test"
|
||||
assert config.providers.custom.api_base == "https://api.example.test/v1"
|
||||
assert config.model_presets["primary"].provider == "custom"
|
||||
assert config.model_presets["primary"].model == "custom-model"
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"existing, cancel_at",
|
||||
[(False, None), (True, None), (True, "model"), (True, "review")],
|
||||
ids=["first-run", "existing-setup", "cancel-model", "cancel-review"],
|
||||
)
|
||||
def test_shengsuanyun_quick_start_saves_separate_connection(
|
||||
self, tmp_path, monkeypatch, prompt_input, existing, cancel_at,
|
||||
):
|
||||
from nanobot.cli.commands import app
|
||||
|
||||
path = tmp_path / "config.json"
|
||||
monkeypatch.setattr(loader, "_current_config_path", None)
|
||||
monkeypatch.setattr(instance_home, "_home_path", None)
|
||||
if existing:
|
||||
old = Config.model_validate({
|
||||
"agents": {"defaults": {"workspace": str(tmp_path / "workspace"), "modelPreset": "primary"}},
|
||||
"providers": {
|
||||
"custom": {"apiBase": "https://old.example/v1", "apiKey": "old-key"},
|
||||
"Custom_ShengSuanYun_Router": {"apiBase": "https://other.example/v1"},
|
||||
},
|
||||
"modelPresets": {
|
||||
"primary": {"model": "old-model", "provider": "custom"},
|
||||
"shengsuanyun": {"model": "other-model", "provider": "Custom_ShengSuanYun_Router"},
|
||||
},
|
||||
"channels": {"websocket": {"enabled": True, "tokenIssueSecret": "old-password"}},
|
||||
})
|
||||
save_config(old, path)
|
||||
before = path.read_bytes()
|
||||
|
||||
model_id = "deepseek/example-model"
|
||||
model_url = "https://router.shengsuanyun.com/api/v1/models"
|
||||
calls = []
|
||||
|
||||
def get(url, **kwargs):
|
||||
calls.append((url, kwargs["headers"]["Authorization"]))
|
||||
return httpx.Response(200, request=httpx.Request("GET", url), json={"data": [{"id": model_id}]})
|
||||
|
||||
keys = ["\r", "\x1b[A" * 3 + "\r", "router-test-key\r"]
|
||||
if cancel_at == "model":
|
||||
keys.extend(["\x1b", "\x1b[D"])
|
||||
else:
|
||||
keys.append(f"{model_id}\r")
|
||||
if not existing:
|
||||
keys.append("webui-test-password\r")
|
||||
if cancel_at:
|
||||
keys.append("\x1b[A\r")
|
||||
inputs = iter(keys)
|
||||
ask_prompt = onboard_wizard._ask_prompt
|
||||
pause = onboard_wizard._pause
|
||||
|
||||
def ask_with_input(prompt):
|
||||
prompt_input.send_text(next(inputs))
|
||||
return ask_prompt(prompt)
|
||||
|
||||
def review_with_input(message):
|
||||
prompt_input.send_text("\x03" if cancel_at == "review" else "\r")
|
||||
return pause(message)
|
||||
|
||||
monkeypatch.setattr(httpx, "get", get)
|
||||
monkeypatch.setattr(onboard_wizard, "_ask_prompt", ask_with_input)
|
||||
monkeypatch.setattr(onboard_wizard, "_pause", review_with_input)
|
||||
monkeypatch.setattr(
|
||||
onboard_wizard._get_questionary(), "confirm",
|
||||
lambda *args, **kwargs: SimpleNamespace(ask=lambda: True),
|
||||
)
|
||||
|
||||
result = CliRunner().invoke(app, ["--home", str(tmp_path), "onboard", "--wizard"])
|
||||
assert result.exit_code == 0, result.output
|
||||
assert "router-test-key" not in result.output
|
||||
assert calls == [(model_url, "Bearer router-test-key")]
|
||||
if cancel_at:
|
||||
assert "Configuration discarded" in result.output
|
||||
assert path.read_bytes() == before
|
||||
return
|
||||
saved = load_config(path)
|
||||
preset_name = "shengsuanyun-2" if existing else "shengsuanyun"
|
||||
route = resolve_provider_route(saved, preset=saved.resolve_preset(preset_name))
|
||||
assert route.model == model_id
|
||||
assert route.provider_name == ("custom-shengsuanyun-router-2" if existing else "custom-shengsuanyun-router")
|
||||
assert route.provider_config is not None
|
||||
assert route.provider_config.api_base == model_url.removesuffix("/models")
|
||||
assert route.model_api is not None and route.model_api.preferred_api == "chat_completions"
|
||||
if existing:
|
||||
assert saved.resolve_preset() == old.resolve_preset()
|
||||
assert saved.agents.defaults.model_preset == "primary"
|
||||
assert saved.channels.websocket == old.channels.websocket
|
||||
for key, provider in (old.providers.model_extra or {}).items():
|
||||
assert getattr(saved.providers, key) == provider
|
||||
assert saved.providers.custom == old.providers.custom
|
||||
assert saved.model_presets["shengsuanyun"] == old.model_presets["shengsuanyun"]
|
||||
else:
|
||||
assert saved.agents.defaults.model_preset == preset_name
|
||||
assert saved.channels.websocket["enabled"] is True
|
||||
|
||||
def test_quick_start_provider_without_default_base_url_prompts_for_base(self, monkeypatch):
|
||||
config = Config()
|
||||
text_answers = iter(["azure-key", "https://azure.example.test/openai"])
|
||||
@@ -1465,7 +1569,7 @@ class TestMainMenuInteraction:
|
||||
lambda *a, **kw: "deployment-name",
|
||||
)
|
||||
|
||||
assert onboard_wizard._configure_quick_start_provider(config) is True
|
||||
assert onboard_wizard._configure_quick_start_provider(config) == "primary"
|
||||
|
||||
assert config.providers.azure_openai.api_key == "azure-key"
|
||||
assert config.providers.azure_openai.api_base == "https://azure.example.test/openai"
|
||||
@@ -1579,6 +1683,7 @@ class TestMainMenuInteraction:
|
||||
|
||||
def test_quick_start_summary_calls_out_missing_api_key(self, monkeypatch):
|
||||
config = Config()
|
||||
config.channels.websocket = {"enabled": True}
|
||||
config.model_presets["primary"] = ModelPresetConfig(
|
||||
model="deepseek-v4-flash",
|
||||
provider="deepseek",
|
||||
@@ -1593,7 +1698,7 @@ class TestMainMenuInteraction:
|
||||
lambda rows, _title: captured.setdefault("rows", rows),
|
||||
)
|
||||
|
||||
onboard_wizard._show_quick_start_summary(config)
|
||||
onboard_wizard._show_quick_start_summary(config, "primary")
|
||||
|
||||
rows = dict(captured["rows"])
|
||||
assert rows["Status"] == "DeepSeek API key missing"
|
||||
|
||||
Reference in new issue
Block a user