From 99da4c8d569d11b4a8fe283db32df526f4bd7604 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 06:41:22 +0000 Subject: [PATCH] refactor(commands): dedupe moonshot non-interactive auth --- .../local/auth-choice.ts | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/commands/onboard-non-interactive/local/auth-choice.ts b/src/commands/onboard-non-interactive/local/auth-choice.ts index 9ba6bfd64..23a5d370d 100644 --- a/src/commands/onboard-non-interactive/local/auth-choice.ts +++ b/src/commands/onboard-non-interactive/local/auth-choice.ts @@ -453,7 +453,9 @@ export async function applyNonInteractiveAuthChoice(params: { }); } - if (authChoice === "moonshot-api-key") { + const applyMoonshotApiKeyChoice = async ( + applyConfig: (cfg: OpenClawConfig) => OpenClawConfig, + ): Promise => { const resolved = await resolveNonInteractiveApiKey({ provider: "moonshot", cfg: baseConfig, @@ -473,30 +475,15 @@ export async function applyNonInteractiveAuthChoice(params: { provider: "moonshot", mode: "api_key", }); - return applyMoonshotConfig(nextConfig); + return applyConfig(nextConfig); + }; + + if (authChoice === "moonshot-api-key") { + return await applyMoonshotApiKeyChoice(applyMoonshotConfig); } if (authChoice === "moonshot-api-key-cn") { - const resolved = await resolveNonInteractiveApiKey({ - provider: "moonshot", - cfg: baseConfig, - flagValue: opts.moonshotApiKey, - flagName: "--moonshot-api-key", - envVar: "MOONSHOT_API_KEY", - runtime, - }); - if (!resolved) { - return null; - } - if (resolved.source !== "profile") { - await setMoonshotApiKey(resolved.key); - } - nextConfig = applyAuthProfileConfig(nextConfig, { - profileId: "moonshot:default", - provider: "moonshot", - mode: "api_key", - }); - return applyMoonshotConfigCn(nextConfig); + return await applyMoonshotApiKeyChoice(applyMoonshotConfigCn); } if (authChoice === "kimi-code-api-key") {