4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
118 lines
3.6 KiB
Python
118 lines
3.6 KiB
Python
"""Provider metadata for browser-assisted LLM auth setup."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Literal
|
|
|
|
from surfaces.cli.wizard.config import PROVIDER_BY_VALUE, SUPPORTED_PROVIDERS, ProviderOption
|
|
|
|
AuthKind = Literal["api_key", "cli_subscription"]
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ProviderAuthProfile:
|
|
"""User-facing auth metadata for one provider setup path."""
|
|
|
|
name: str
|
|
provider_value: str
|
|
label: str
|
|
kind: AuthKind
|
|
aliases: tuple[str, ...] = ()
|
|
setup_url: str | None = None
|
|
auth_hint: str = ""
|
|
|
|
@property
|
|
def all_names(self) -> tuple[str, ...]:
|
|
return (self.name, self.provider_value, *self.aliases)
|
|
|
|
|
|
_API_KEY_SETUP_URLS: dict[str, str] = {
|
|
"anthropic": "https://console.anthropic.com/settings/keys",
|
|
"openai": "https://platform.openai.com/api-keys",
|
|
"openrouter": "https://openrouter.ai/keys",
|
|
"deepseek": "https://platform.deepseek.com/api_keys",
|
|
"gemini": "https://aistudio.google.com/app/apikey",
|
|
"nvidia": "https://build.nvidia.com/",
|
|
"minimax": "https://intl.minimaxi.com/user-center/basic-information/interface-key",
|
|
"groq": "https://console.groq.com/keys",
|
|
}
|
|
|
|
|
|
_SUBSCRIPTION_PROFILES: tuple[ProviderAuthProfile, ...] = (
|
|
ProviderAuthProfile(
|
|
name="chatgpt",
|
|
provider_value="codex",
|
|
label="ChatGPT subscription via Codex CLI",
|
|
kind="cli_subscription",
|
|
aliases=("openai-chatgpt", "openai-codex", "codex-cli"),
|
|
setup_url="https://github.com/openai/codex",
|
|
auth_hint="Run: codex login",
|
|
),
|
|
ProviderAuthProfile(
|
|
name="claude",
|
|
provider_value="claude-code",
|
|
label="Anthropic subscription via Claude Code CLI",
|
|
kind="cli_subscription",
|
|
aliases=(
|
|
"claude-ai",
|
|
"claude-subscription",
|
|
"anthropic-subscription",
|
|
"anthropic-claude",
|
|
"claude-code-cli",
|
|
),
|
|
setup_url="https://github.com/anthropics/claude-code",
|
|
auth_hint="Run: claude auth login",
|
|
),
|
|
)
|
|
|
|
|
|
def _api_key_profiles() -> tuple[ProviderAuthProfile, ...]:
|
|
profiles: list[ProviderAuthProfile] = []
|
|
for provider in SUPPORTED_PROVIDERS:
|
|
if provider.credential_kind != "api_key":
|
|
continue
|
|
profiles.append(
|
|
ProviderAuthProfile(
|
|
name=provider.value,
|
|
provider_value=provider.value,
|
|
label=provider.label
|
|
if provider.label.lower().endswith("api key")
|
|
else f"{provider.label} API key",
|
|
kind="api_key",
|
|
setup_url=_API_KEY_SETUP_URLS.get(provider.value),
|
|
auth_hint=f"Paste {provider.api_key_env}",
|
|
)
|
|
)
|
|
return tuple(profiles)
|
|
|
|
|
|
def iter_auth_profiles() -> tuple[ProviderAuthProfile, ...]:
|
|
"""Return all supported auth setup paths."""
|
|
return (*_SUBSCRIPTION_PROFILES, *_api_key_profiles())
|
|
|
|
|
|
def resolve_auth_profile(raw_name: str) -> ProviderAuthProfile:
|
|
"""Resolve a user-supplied provider/auth alias to an auth profile."""
|
|
normalized = raw_name.strip().lower()
|
|
if not normalized:
|
|
raise KeyError(raw_name)
|
|
for profile in iter_auth_profiles():
|
|
if normalized in {name.lower() for name in profile.all_names}:
|
|
return profile
|
|
raise KeyError(raw_name)
|
|
|
|
|
|
def provider_for_profile(profile: ProviderAuthProfile) -> ProviderOption:
|
|
"""Return the wizard provider option for an auth profile."""
|
|
return PROVIDER_BY_VALUE[profile.provider_value]
|
|
|
|
|
|
__all__ = [
|
|
"AuthKind",
|
|
"ProviderAuthProfile",
|
|
"iter_auth_profiles",
|
|
"provider_for_profile",
|
|
"resolve_auth_profile",
|
|
]
|