|
| 1 | +import { AUTH_CHOICE_LEGACY_ALIASES_FOR_CLI } from "./auth-choice-legacy.js"; |
| 2 | +import { ONBOARD_PROVIDER_AUTH_FLAGS } from "./onboard-provider-auth-flags.js"; |
| 3 | +import type { AuthChoice, AuthChoiceGroupId } from "./onboard-types.js"; |
| 4 | + |
| 5 | +export type { AuthChoiceGroupId }; |
| 6 | + |
| 7 | +export type AuthChoiceOption = { |
| 8 | + value: AuthChoice; |
| 9 | + label: string; |
| 10 | + hint?: string; |
| 11 | +}; |
| 12 | +export type AuthChoiceGroup = { |
| 13 | + value: AuthChoiceGroupId; |
| 14 | + label: string; |
| 15 | + hint?: string; |
| 16 | + options: AuthChoiceOption[]; |
| 17 | +}; |
| 18 | + |
| 19 | +export const AUTH_CHOICE_GROUP_DEFS: { |
| 20 | + value: AuthChoiceGroupId; |
| 21 | + label: string; |
| 22 | + hint?: string; |
| 23 | + choices: AuthChoice[]; |
| 24 | +}[] = [ |
| 25 | + { |
| 26 | + value: "openai", |
| 27 | + label: "OpenAI", |
| 28 | + hint: "Codex OAuth + API key", |
| 29 | + choices: ["openai-codex", "openai-api-key"], |
| 30 | + }, |
| 31 | + { |
| 32 | + value: "anthropic", |
| 33 | + label: "Anthropic", |
| 34 | + hint: "setup-token + API key", |
| 35 | + choices: ["token", "apiKey"], |
| 36 | + }, |
| 37 | + { |
| 38 | + value: "chutes", |
| 39 | + label: "Chutes", |
| 40 | + hint: "OAuth", |
| 41 | + choices: ["chutes"], |
| 42 | + }, |
| 43 | + { |
| 44 | + value: "minimax", |
| 45 | + label: "MiniMax", |
| 46 | + hint: "M2.5 (recommended)", |
| 47 | + choices: ["minimax-global-oauth", "minimax-global-api", "minimax-cn-oauth", "minimax-cn-api"], |
| 48 | + }, |
| 49 | + { |
| 50 | + value: "moonshot", |
| 51 | + label: "Moonshot AI (Kimi K2.5)", |
| 52 | + hint: "Kimi K2.5 + Kimi Coding", |
| 53 | + choices: ["moonshot-api-key", "moonshot-api-key-cn", "kimi-code-api-key"], |
| 54 | + }, |
| 55 | + { |
| 56 | + value: "google", |
| 57 | + label: "Google", |
| 58 | + hint: "Gemini API key + OAuth", |
| 59 | + choices: ["gemini-api-key", "google-gemini-cli"], |
| 60 | + }, |
| 61 | + { |
| 62 | + value: "xai", |
| 63 | + label: "xAI (Grok)", |
| 64 | + hint: "API key", |
| 65 | + choices: ["xai-api-key"], |
| 66 | + }, |
| 67 | + { |
| 68 | + value: "mistral", |
| 69 | + label: "Mistral AI", |
| 70 | + hint: "API key", |
| 71 | + choices: ["mistral-api-key"], |
| 72 | + }, |
| 73 | + { |
| 74 | + value: "volcengine", |
| 75 | + label: "Volcano Engine", |
| 76 | + hint: "API key", |
| 77 | + choices: ["volcengine-api-key"], |
| 78 | + }, |
| 79 | + { |
| 80 | + value: "byteplus", |
| 81 | + label: "BytePlus", |
| 82 | + hint: "API key", |
| 83 | + choices: ["byteplus-api-key"], |
| 84 | + }, |
| 85 | + { |
| 86 | + value: "openrouter", |
| 87 | + label: "OpenRouter", |
| 88 | + hint: "API key", |
| 89 | + choices: ["openrouter-api-key"], |
| 90 | + }, |
| 91 | + { |
| 92 | + value: "kilocode", |
| 93 | + label: "Kilo Gateway", |
| 94 | + hint: "API key (OpenRouter-compatible)", |
| 95 | + choices: ["kilocode-api-key"], |
| 96 | + }, |
| 97 | + { |
| 98 | + value: "qwen", |
| 99 | + label: "Qwen", |
| 100 | + hint: "OAuth", |
| 101 | + choices: ["qwen-portal"], |
| 102 | + }, |
| 103 | + { |
| 104 | + value: "zai", |
| 105 | + label: "Z.AI", |
| 106 | + hint: "GLM Coding Plan / Global / CN", |
| 107 | + choices: ["zai-coding-global", "zai-coding-cn", "zai-global", "zai-cn"], |
| 108 | + }, |
| 109 | + { |
| 110 | + value: "qianfan", |
| 111 | + label: "Qianfan", |
| 112 | + hint: "API key", |
| 113 | + choices: ["qianfan-api-key"], |
| 114 | + }, |
| 115 | + { |
| 116 | + value: "modelstudio", |
| 117 | + label: "Alibaba Cloud Model Studio", |
| 118 | + hint: "Coding Plan API key (CN / Global)", |
| 119 | + choices: ["modelstudio-api-key-cn", "modelstudio-api-key"], |
| 120 | + }, |
| 121 | + { |
| 122 | + value: "copilot", |
| 123 | + label: "Copilot", |
| 124 | + hint: "GitHub + local proxy", |
| 125 | + choices: ["github-copilot", "copilot-proxy"], |
| 126 | + }, |
| 127 | + { |
| 128 | + value: "ai-gateway", |
| 129 | + label: "Vercel AI Gateway", |
| 130 | + hint: "API key", |
| 131 | + choices: ["ai-gateway-api-key"], |
| 132 | + }, |
| 133 | + { |
| 134 | + value: "opencode", |
| 135 | + label: "OpenCode", |
| 136 | + hint: "Shared API key for Zen + Go catalogs", |
| 137 | + choices: ["opencode-zen", "opencode-go"], |
| 138 | + }, |
| 139 | + { |
| 140 | + value: "xiaomi", |
| 141 | + label: "Xiaomi", |
| 142 | + hint: "API key", |
| 143 | + choices: ["xiaomi-api-key"], |
| 144 | + }, |
| 145 | + { |
| 146 | + value: "synthetic", |
| 147 | + label: "Synthetic", |
| 148 | + hint: "Anthropic-compatible (multi-model)", |
| 149 | + choices: ["synthetic-api-key"], |
| 150 | + }, |
| 151 | + { |
| 152 | + value: "together", |
| 153 | + label: "Together AI", |
| 154 | + hint: "API key", |
| 155 | + choices: ["together-api-key"], |
| 156 | + }, |
| 157 | + { |
| 158 | + value: "huggingface", |
| 159 | + label: "Hugging Face", |
| 160 | + hint: "Inference API (HF token)", |
| 161 | + choices: ["huggingface-api-key"], |
| 162 | + }, |
| 163 | + { |
| 164 | + value: "venice", |
| 165 | + label: "Venice AI", |
| 166 | + hint: "Privacy-focused (uncensored models)", |
| 167 | + choices: ["venice-api-key"], |
| 168 | + }, |
| 169 | + { |
| 170 | + value: "litellm", |
| 171 | + label: "LiteLLM", |
| 172 | + hint: "Unified LLM gateway (100+ providers)", |
| 173 | + choices: ["litellm-api-key"], |
| 174 | + }, |
| 175 | + { |
| 176 | + value: "cloudflare-ai-gateway", |
| 177 | + label: "Cloudflare AI Gateway", |
| 178 | + hint: "Account ID + Gateway ID + API key", |
| 179 | + choices: ["cloudflare-ai-gateway-api-key"], |
| 180 | + }, |
| 181 | + { |
| 182 | + value: "custom", |
| 183 | + label: "Custom Provider", |
| 184 | + hint: "Any OpenAI or Anthropic compatible endpoint", |
| 185 | + choices: ["custom-api-key"], |
| 186 | + }, |
| 187 | +]; |
| 188 | + |
| 189 | +const PROVIDER_AUTH_CHOICE_OPTION_HINTS: Partial<Record<AuthChoice, string>> = { |
| 190 | + "litellm-api-key": "Unified gateway for 100+ LLM providers", |
| 191 | + "cloudflare-ai-gateway-api-key": "Account ID + Gateway ID + API key", |
| 192 | + "venice-api-key": "Privacy-focused inference (uncensored models)", |
| 193 | + "together-api-key": "Access to Llama, DeepSeek, Qwen, and more open models", |
| 194 | + "huggingface-api-key": "Inference Providers — OpenAI-compatible chat", |
| 195 | + "opencode-zen": "Shared OpenCode key; curated Zen catalog", |
| 196 | + "opencode-go": "Shared OpenCode key; Kimi/GLM/MiniMax Go catalog", |
| 197 | +}; |
| 198 | + |
| 199 | +const PROVIDER_AUTH_CHOICE_OPTION_LABELS: Partial<Record<AuthChoice, string>> = { |
| 200 | + "moonshot-api-key": "Kimi API key (.ai)", |
| 201 | + "moonshot-api-key-cn": "Kimi API key (.cn)", |
| 202 | + "kimi-code-api-key": "Kimi Code API key (subscription)", |
| 203 | + "cloudflare-ai-gateway-api-key": "Cloudflare AI Gateway", |
| 204 | + "opencode-zen": "OpenCode Zen catalog", |
| 205 | + "opencode-go": "OpenCode Go catalog", |
| 206 | +}; |
| 207 | + |
| 208 | +function buildProviderAuthChoiceOptions(): AuthChoiceOption[] { |
| 209 | + return ONBOARD_PROVIDER_AUTH_FLAGS.map((flag) => ({ |
| 210 | + value: flag.authChoice, |
| 211 | + label: PROVIDER_AUTH_CHOICE_OPTION_LABELS[flag.authChoice] ?? flag.description, |
| 212 | + ...(PROVIDER_AUTH_CHOICE_OPTION_HINTS[flag.authChoice] |
| 213 | + ? { hint: PROVIDER_AUTH_CHOICE_OPTION_HINTS[flag.authChoice] } |
| 214 | + : {}), |
| 215 | + })); |
| 216 | +} |
| 217 | + |
| 218 | +export const BASE_AUTH_CHOICE_OPTIONS: ReadonlyArray<AuthChoiceOption> = [ |
| 219 | + { |
| 220 | + value: "token", |
| 221 | + label: "Anthropic token (paste setup-token)", |
| 222 | + hint: "run `claude setup-token` elsewhere, then paste the token here", |
| 223 | + }, |
| 224 | + { |
| 225 | + value: "openai-codex", |
| 226 | + label: "OpenAI Codex (ChatGPT OAuth)", |
| 227 | + }, |
| 228 | + { value: "chutes", label: "Chutes (OAuth)" }, |
| 229 | + ...buildProviderAuthChoiceOptions(), |
| 230 | + { |
| 231 | + value: "moonshot-api-key-cn", |
| 232 | + label: "Kimi API key (.cn)", |
| 233 | + }, |
| 234 | + { |
| 235 | + value: "github-copilot", |
| 236 | + label: "GitHub Copilot (GitHub device login)", |
| 237 | + hint: "Uses GitHub device flow", |
| 238 | + }, |
| 239 | + { value: "gemini-api-key", label: "Google Gemini API key" }, |
| 240 | + { |
| 241 | + value: "google-gemini-cli", |
| 242 | + label: "Google Gemini CLI OAuth", |
| 243 | + hint: "Unofficial flow; review account-risk warning before use", |
| 244 | + }, |
| 245 | + { value: "zai-api-key", label: "Z.AI API key" }, |
| 246 | + { |
| 247 | + value: "zai-coding-global", |
| 248 | + label: "Coding-Plan-Global", |
| 249 | + hint: "GLM Coding Plan Global (api.z.ai)", |
| 250 | + }, |
| 251 | + { |
| 252 | + value: "zai-coding-cn", |
| 253 | + label: "Coding-Plan-CN", |
| 254 | + hint: "GLM Coding Plan CN (open.bigmodel.cn)", |
| 255 | + }, |
| 256 | + { |
| 257 | + value: "zai-global", |
| 258 | + label: "Global", |
| 259 | + hint: "Z.AI Global (api.z.ai)", |
| 260 | + }, |
| 261 | + { |
| 262 | + value: "zai-cn", |
| 263 | + label: "CN", |
| 264 | + hint: "Z.AI CN (open.bigmodel.cn)", |
| 265 | + }, |
| 266 | + { |
| 267 | + value: "xiaomi-api-key", |
| 268 | + label: "Xiaomi API key", |
| 269 | + }, |
| 270 | + { |
| 271 | + value: "minimax-global-oauth", |
| 272 | + label: "MiniMax Global — OAuth (minimax.io)", |
| 273 | + hint: "Only supports OAuth for the coding plan", |
| 274 | + }, |
| 275 | + { |
| 276 | + value: "minimax-global-api", |
| 277 | + label: "MiniMax Global — API Key (minimax.io)", |
| 278 | + hint: "sk-api- or sk-cp- keys supported", |
| 279 | + }, |
| 280 | + { |
| 281 | + value: "minimax-cn-oauth", |
| 282 | + label: "MiniMax CN — OAuth (minimaxi.com)", |
| 283 | + hint: "Only supports OAuth for the coding plan", |
| 284 | + }, |
| 285 | + { |
| 286 | + value: "minimax-cn-api", |
| 287 | + label: "MiniMax CN — API Key (minimaxi.com)", |
| 288 | + hint: "sk-api- or sk-cp- keys supported", |
| 289 | + }, |
| 290 | + { value: "qwen-portal", label: "Qwen OAuth" }, |
| 291 | + { |
| 292 | + value: "copilot-proxy", |
| 293 | + label: "Copilot Proxy (local)", |
| 294 | + hint: "Local proxy for VS Code Copilot models", |
| 295 | + }, |
| 296 | + { value: "apiKey", label: "Anthropic API key" }, |
| 297 | + { |
| 298 | + value: "opencode-zen", |
| 299 | + label: "OpenCode Zen catalog", |
| 300 | + hint: "Claude, GPT, Gemini via opencode.ai/zen", |
| 301 | + }, |
| 302 | + { value: "qianfan-api-key", label: "Qianfan API key" }, |
| 303 | + { |
| 304 | + value: "modelstudio-api-key-cn", |
| 305 | + label: "Coding Plan API Key for China (subscription)", |
| 306 | + hint: "Endpoint: coding.dashscope.aliyuncs.com", |
| 307 | + }, |
| 308 | + { |
| 309 | + value: "modelstudio-api-key", |
| 310 | + label: "Coding Plan API Key for Global/Intl (subscription)", |
| 311 | + hint: "Endpoint: coding-intl.dashscope.aliyuncs.com", |
| 312 | + }, |
| 313 | + { value: "custom-api-key", label: "Custom Provider" }, |
| 314 | +]; |
| 315 | + |
| 316 | +export function formatStaticAuthChoiceChoicesForCli(params?: { |
| 317 | + includeSkip?: boolean; |
| 318 | + includeLegacyAliases?: boolean; |
| 319 | +}): string { |
| 320 | + const includeSkip = params?.includeSkip ?? true; |
| 321 | + const includeLegacyAliases = params?.includeLegacyAliases ?? false; |
| 322 | + const values = BASE_AUTH_CHOICE_OPTIONS.map((opt) => opt.value); |
| 323 | + |
| 324 | + if (includeSkip) { |
| 325 | + values.push("skip"); |
| 326 | + } |
| 327 | + if (includeLegacyAliases) { |
| 328 | + values.push(...AUTH_CHOICE_LEGACY_ALIASES_FOR_CLI); |
| 329 | + } |
| 330 | + |
| 331 | + return values.join("|"); |
| 332 | +} |
0 commit comments