Handle `uncommon-route provider `.
(args: list[str])
| 220 | |
| 221 | |
| 222 | def cmd_provider(args: list[str]) -> None: |
| 223 | """Handle `uncommon-route provider <subcommand>`.""" |
| 224 | if not args: |
| 225 | args = ["list"] |
| 226 | |
| 227 | sub = args[0] |
| 228 | |
| 229 | if sub == "list": |
| 230 | cfg = load_providers() |
| 231 | if not cfg.providers: |
| 232 | print(" No providers configured") |
| 233 | print() |
| 234 | print(" Add one: uncommon-route provider add <name> <api_key>") |
| 235 | print(" Example: uncommon-route provider add deepseek sk-...") |
| 236 | return |
| 237 | print(f" Configured providers ({len(cfg.providers)}):") |
| 238 | for name, entry in cfg.providers.items(): |
| 239 | key_preview = entry.api_key[:8] + "..." if len(entry.api_key) > 8 else "***" |
| 240 | plan_str = f" [{entry.plan}]" if entry.plan else "" |
| 241 | print(f" {name}: {key_preview}{plan_str}") |
| 242 | print(f" URL: {entry.base_url}") |
| 243 | print(f" Models: {', '.join(entry.models)}") |
| 244 | |
| 245 | elif sub == "add": |
| 246 | if len(args) < 3: |
| 247 | print("Usage: uncommon-route provider add <name> <api_key> [--plan <plan>] [--url <base_url>] [--models <model1,model2>]", file=sys.stderr) |
| 248 | print(f" Known providers: {', '.join(KNOWN_BASE_URLS.keys())}", file=sys.stderr) |
| 249 | sys.exit(1) |
| 250 | name = args[1] |
| 251 | api_key = args[2] |
| 252 | plan = "" |
| 253 | if "--plan" in args: |
| 254 | idx = args.index("--plan") |
| 255 | if idx + 1 < len(args): |
| 256 | plan = args[idx + 1] |
| 257 | base_url = None |
| 258 | if "--url" in args: |
| 259 | idx = args.index("--url") |
| 260 | if idx + 1 < len(args): |
| 261 | base_url = args[idx + 1] |
| 262 | models = None |
| 263 | if "--models" in args: |
| 264 | idx = args.index("--models") |
| 265 | if idx + 1 < len(args): |
| 266 | models = [ |
| 267 | item.strip() |
| 268 | for item in args[idx + 1].split(",") |
| 269 | if item.strip() |
| 270 | ] |
| 271 | |
| 272 | cfg = add_provider(name, api_key, base_url=base_url, models=models, plan=plan) |
| 273 | models = cfg.providers[name].models |
| 274 | print(f" Added provider: {name}") |
| 275 | if models: |
| 276 | print(f" Models: {', '.join(models)}") |
| 277 | |
| 278 | resolved_url = base_url or KNOWN_BASE_URLS.get(name, "") |
| 279 | if resolved_url: |