refactor(commands): dedupe moonshot non-interactive auth

This commit is contained in:
Peter Steinberger
2026-02-15 06:41:22 +00:00
parent 6c7a7d910a
commit 99da4c8d56

View File

@@ -453,7 +453,9 @@ export async function applyNonInteractiveAuthChoice(params: {
});
}
if (authChoice === "moonshot-api-key") {
const applyMoonshotApiKeyChoice = async (
applyConfig: (cfg: OpenClawConfig) => OpenClawConfig,
): Promise<OpenClawConfig | null> => {
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") {