mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 01:28:27 +00:00
refactor(onboard): unify auth-choice aliases and provider flags
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import type { AuthChoice, OnboardOptions } from "../../onboard-types.js";
|
||||
import { ONBOARD_PROVIDER_AUTH_FLAGS } from "../../onboard-provider-auth-flags.js";
|
||||
|
||||
type AuthChoiceFlag = {
|
||||
flag: keyof AuthChoiceFlagOptions;
|
||||
optionKey: keyof AuthChoiceFlagOptions;
|
||||
authChoice: AuthChoice;
|
||||
label: string;
|
||||
};
|
||||
@@ -26,36 +27,12 @@ type AuthChoiceFlagOptions = Pick<
|
||||
| "opencodeZenApiKey"
|
||||
| "xaiApiKey"
|
||||
| "litellmApiKey"
|
||||
| "qianfanApiKey"
|
||||
| "customBaseUrl"
|
||||
| "customModelId"
|
||||
| "customApiKey"
|
||||
>;
|
||||
|
||||
const AUTH_CHOICE_FLAG_MAP = [
|
||||
{ flag: "anthropicApiKey", authChoice: "apiKey", label: "--anthropic-api-key" },
|
||||
{ flag: "geminiApiKey", authChoice: "gemini-api-key", label: "--gemini-api-key" },
|
||||
{ flag: "openaiApiKey", authChoice: "openai-api-key", label: "--openai-api-key" },
|
||||
{ flag: "openrouterApiKey", authChoice: "openrouter-api-key", label: "--openrouter-api-key" },
|
||||
{ flag: "aiGatewayApiKey", authChoice: "ai-gateway-api-key", label: "--ai-gateway-api-key" },
|
||||
{
|
||||
flag: "cloudflareAiGatewayApiKey",
|
||||
authChoice: "cloudflare-ai-gateway-api-key",
|
||||
label: "--cloudflare-ai-gateway-api-key",
|
||||
},
|
||||
{ flag: "moonshotApiKey", authChoice: "moonshot-api-key", label: "--moonshot-api-key" },
|
||||
{ flag: "kimiCodeApiKey", authChoice: "kimi-code-api-key", label: "--kimi-code-api-key" },
|
||||
{ flag: "syntheticApiKey", authChoice: "synthetic-api-key", label: "--synthetic-api-key" },
|
||||
{ flag: "veniceApiKey", authChoice: "venice-api-key", label: "--venice-api-key" },
|
||||
{ flag: "togetherApiKey", authChoice: "together-api-key", label: "--together-api-key" },
|
||||
{ flag: "zaiApiKey", authChoice: "zai-api-key", label: "--zai-api-key" },
|
||||
{ flag: "xiaomiApiKey", authChoice: "xiaomi-api-key", label: "--xiaomi-api-key" },
|
||||
{ flag: "xaiApiKey", authChoice: "xai-api-key", label: "--xai-api-key" },
|
||||
{ flag: "minimaxApiKey", authChoice: "minimax-api", label: "--minimax-api-key" },
|
||||
{ flag: "opencodeZenApiKey", authChoice: "opencode-zen", label: "--opencode-zen-api-key" },
|
||||
{ flag: "huggingfaceApiKey", authChoice: "huggingface-api-key", label: "--huggingface-api-key" },
|
||||
{ flag: "litellmApiKey", authChoice: "litellm-api-key", label: "--litellm-api-key" },
|
||||
] satisfies ReadonlyArray<AuthChoiceFlag>;
|
||||
|
||||
export type AuthChoiceInference = {
|
||||
choice?: AuthChoice;
|
||||
matches: AuthChoiceFlag[];
|
||||
@@ -67,9 +44,13 @@ function hasStringValue(value: unknown): boolean {
|
||||
|
||||
// Infer auth choice from explicit provider API key flags.
|
||||
export function inferAuthChoiceFromFlags(opts: OnboardOptions): AuthChoiceInference {
|
||||
const matches: AuthChoiceFlag[] = AUTH_CHOICE_FLAG_MAP.filter(({ flag }) =>
|
||||
hasStringValue(opts[flag]),
|
||||
);
|
||||
const matches: AuthChoiceFlag[] = ONBOARD_PROVIDER_AUTH_FLAGS.filter(({ optionKey }) =>
|
||||
hasStringValue(opts[optionKey]),
|
||||
).map((flag) => ({
|
||||
optionKey: flag.optionKey,
|
||||
authChoice: flag.authChoice,
|
||||
label: flag.cliFlag,
|
||||
}));
|
||||
|
||||
if (
|
||||
hasStringValue(opts.customBaseUrl) ||
|
||||
@@ -77,7 +58,7 @@ export function inferAuthChoiceFromFlags(opts: OnboardOptions): AuthChoiceInfere
|
||||
hasStringValue(opts.customApiKey)
|
||||
) {
|
||||
matches.push({
|
||||
flag: "customBaseUrl",
|
||||
optionKey: "customBaseUrl",
|
||||
authChoice: "custom-api-key",
|
||||
label: "--custom-base-url/--custom-model-id/--custom-api-key",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user