mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 19:48:27 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -22,14 +22,18 @@ async function resolveApiKeyFromProfiles(params: {
|
||||
});
|
||||
for (const profileId of order) {
|
||||
const cred = store.profiles[profileId];
|
||||
if (cred?.type !== "api_key") continue;
|
||||
if (cred?.type !== "api_key") {
|
||||
continue;
|
||||
}
|
||||
const resolved = await resolveApiKeyForProfile({
|
||||
cfg: params.cfg,
|
||||
store,
|
||||
profileId,
|
||||
agentDir: params.agentDir,
|
||||
});
|
||||
if (resolved?.apiKey) return resolved.apiKey;
|
||||
if (resolved?.apiKey) {
|
||||
return resolved.apiKey;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -45,10 +49,14 @@ export async function resolveNonInteractiveApiKey(params: {
|
||||
allowProfile?: boolean;
|
||||
}): Promise<{ key: string; source: NonInteractiveApiKeySource } | null> {
|
||||
const flagKey = params.flagValue?.trim();
|
||||
if (flagKey) return { key: flagKey, source: "flag" };
|
||||
if (flagKey) {
|
||||
return { key: flagKey, source: "flag" };
|
||||
}
|
||||
|
||||
const envResolved = resolveEnvApiKey(params.provider);
|
||||
if (envResolved?.apiKey) return { key: envResolved.apiKey, source: "env" };
|
||||
if (envResolved?.apiKey) {
|
||||
return { key: envResolved.apiKey, source: "env" };
|
||||
}
|
||||
|
||||
if (params.allowProfile ?? true) {
|
||||
const profileKey = await resolveApiKeyFromProfiles({
|
||||
@@ -56,7 +64,9 @@ export async function resolveNonInteractiveApiKey(params: {
|
||||
cfg: params.cfg,
|
||||
agentDir: params.agentDir,
|
||||
});
|
||||
if (profileKey) return { key: profileKey, source: "profile" };
|
||||
if (profileKey) {
|
||||
return { key: profileKey, source: "profile" };
|
||||
}
|
||||
}
|
||||
|
||||
const profileHint =
|
||||
|
||||
@@ -58,7 +58,9 @@ export async function runNonInteractiveOnboardingLocal(params: {
|
||||
runtime,
|
||||
baseConfig,
|
||||
});
|
||||
if (!nextConfigAfterAuth) return;
|
||||
if (!nextConfigAfterAuth) {
|
||||
return;
|
||||
}
|
||||
nextConfig = nextConfigAfterAuth;
|
||||
|
||||
const gatewayBasePort = resolveGatewayPort(baseConfig);
|
||||
@@ -68,7 +70,9 @@ export async function runNonInteractiveOnboardingLocal(params: {
|
||||
runtime,
|
||||
defaultPort: gatewayBasePort,
|
||||
});
|
||||
if (!gatewayResult) return;
|
||||
if (!gatewayResult) {
|
||||
return;
|
||||
}
|
||||
nextConfig = gatewayResult.nextConfig;
|
||||
|
||||
nextConfig = applyNonInteractiveSkillsConfig({ nextConfig, opts, runtime });
|
||||
|
||||
@@ -77,8 +77,12 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
envVar: "ANTHROPIC_API_KEY",
|
||||
runtime,
|
||||
});
|
||||
if (!resolved) return null;
|
||||
if (resolved.source !== "profile") await setAnthropicApiKey(resolved.key);
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
if (resolved.source !== "profile") {
|
||||
await setAnthropicApiKey(resolved.key);
|
||||
}
|
||||
return applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "anthropic:default",
|
||||
provider: "anthropic",
|
||||
@@ -150,8 +154,12 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
envVar: "GEMINI_API_KEY",
|
||||
runtime,
|
||||
});
|
||||
if (!resolved) return null;
|
||||
if (resolved.source !== "profile") await setGeminiApiKey(resolved.key);
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
if (resolved.source !== "profile") {
|
||||
await setGeminiApiKey(resolved.key);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "google:default",
|
||||
provider: "google",
|
||||
@@ -169,8 +177,12 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
envVar: "ZAI_API_KEY",
|
||||
runtime,
|
||||
});
|
||||
if (!resolved) return null;
|
||||
if (resolved.source !== "profile") await setZaiApiKey(resolved.key);
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
if (resolved.source !== "profile") {
|
||||
await setZaiApiKey(resolved.key);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "zai:default",
|
||||
provider: "zai",
|
||||
@@ -188,8 +200,12 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
envVar: "XIAOMI_API_KEY",
|
||||
runtime,
|
||||
});
|
||||
if (!resolved) return null;
|
||||
if (resolved.source !== "profile") await setXiaomiApiKey(resolved.key);
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
if (resolved.source !== "profile") {
|
||||
await setXiaomiApiKey(resolved.key);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "xiaomi:default",
|
||||
provider: "xiaomi",
|
||||
@@ -208,7 +224,9 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
runtime,
|
||||
allowProfile: false,
|
||||
});
|
||||
if (!resolved) return null;
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
const key = resolved.key;
|
||||
const result = upsertSharedEnvVar({ key: "OPENAI_API_KEY", value: key });
|
||||
process.env.OPENAI_API_KEY = key;
|
||||
@@ -225,8 +243,12 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
envVar: "OPENROUTER_API_KEY",
|
||||
runtime,
|
||||
});
|
||||
if (!resolved) return null;
|
||||
if (resolved.source !== "profile") await setOpenrouterApiKey(resolved.key);
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
if (resolved.source !== "profile") {
|
||||
await setOpenrouterApiKey(resolved.key);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "openrouter:default",
|
||||
provider: "openrouter",
|
||||
@@ -244,8 +266,12 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
envVar: "AI_GATEWAY_API_KEY",
|
||||
runtime,
|
||||
});
|
||||
if (!resolved) return null;
|
||||
if (resolved.source !== "profile") await setVercelAiGatewayApiKey(resolved.key);
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
if (resolved.source !== "profile") {
|
||||
await setVercelAiGatewayApiKey(resolved.key);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "vercel-ai-gateway:default",
|
||||
provider: "vercel-ai-gateway",
|
||||
@@ -263,8 +289,12 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
envVar: "MOONSHOT_API_KEY",
|
||||
runtime,
|
||||
});
|
||||
if (!resolved) return null;
|
||||
if (resolved.source !== "profile") await setMoonshotApiKey(resolved.key);
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
if (resolved.source !== "profile") {
|
||||
await setMoonshotApiKey(resolved.key);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "moonshot:default",
|
||||
provider: "moonshot",
|
||||
@@ -282,8 +312,12 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
envVar: "KIMI_API_KEY",
|
||||
runtime,
|
||||
});
|
||||
if (!resolved) return null;
|
||||
if (resolved.source !== "profile") await setKimiCodingApiKey(resolved.key);
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
if (resolved.source !== "profile") {
|
||||
await setKimiCodingApiKey(resolved.key);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "kimi-coding:default",
|
||||
provider: "kimi-coding",
|
||||
@@ -301,8 +335,12 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
envVar: "SYNTHETIC_API_KEY",
|
||||
runtime,
|
||||
});
|
||||
if (!resolved) return null;
|
||||
if (resolved.source !== "profile") await setSyntheticApiKey(resolved.key);
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
if (resolved.source !== "profile") {
|
||||
await setSyntheticApiKey(resolved.key);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "synthetic:default",
|
||||
provider: "synthetic",
|
||||
@@ -320,8 +358,12 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
envVar: "VENICE_API_KEY",
|
||||
runtime,
|
||||
});
|
||||
if (!resolved) return null;
|
||||
if (resolved.source !== "profile") await setVeniceApiKey(resolved.key);
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
if (resolved.source !== "profile") {
|
||||
await setVeniceApiKey(resolved.key);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "venice:default",
|
||||
provider: "venice",
|
||||
@@ -343,8 +385,12 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
envVar: "MINIMAX_API_KEY",
|
||||
runtime,
|
||||
});
|
||||
if (!resolved) return null;
|
||||
if (resolved.source !== "profile") await setMinimaxApiKey(resolved.key);
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
if (resolved.source !== "profile") {
|
||||
await setMinimaxApiKey(resolved.key);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "minimax:default",
|
||||
provider: "minimax",
|
||||
@@ -355,7 +401,9 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
return applyMinimaxApiConfig(nextConfig, modelId);
|
||||
}
|
||||
|
||||
if (authChoice === "minimax") return applyMinimaxConfig(nextConfig);
|
||||
if (authChoice === "minimax") {
|
||||
return applyMinimaxConfig(nextConfig);
|
||||
}
|
||||
|
||||
if (authChoice === "opencode-zen") {
|
||||
const resolved = await resolveNonInteractiveApiKey({
|
||||
@@ -366,8 +414,12 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
envVar: "OPENCODE_API_KEY (or OPENCODE_ZEN_API_KEY)",
|
||||
runtime,
|
||||
});
|
||||
if (!resolved) return null;
|
||||
if (resolved.source !== "profile") await setOpencodeZenApiKey(resolved.key);
|
||||
if (!resolved) {
|
||||
return null;
|
||||
}
|
||||
if (resolved.source !== "profile") {
|
||||
await setOpencodeZenApiKey(resolved.key);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "opencode:default",
|
||||
provider: "opencode",
|
||||
|
||||
@@ -15,7 +15,9 @@ export async function installGatewayDaemonNonInteractive(params: {
|
||||
gatewayToken?: string;
|
||||
}) {
|
||||
const { opts, runtime, port, gatewayToken } = params;
|
||||
if (!opts.installDaemon) return;
|
||||
if (!opts.installDaemon) {
|
||||
return;
|
||||
}
|
||||
|
||||
const daemonRuntimeRaw = opts.daemonRuntime ?? DEFAULT_GATEWAY_DAEMON_RUNTIME;
|
||||
const systemdAvailable =
|
||||
|
||||
@@ -41,14 +41,20 @@ export function applyNonInteractiveGatewayConfig(params: {
|
||||
// Tighten config to safe combos:
|
||||
// - If Tailscale is on, force loopback bind (the tunnel handles external access).
|
||||
// - If using Tailscale Funnel, require password auth.
|
||||
if (tailscaleMode !== "off" && bind !== "loopback") bind = "loopback";
|
||||
if (tailscaleMode === "funnel" && authMode !== "password") authMode = "password";
|
||||
if (tailscaleMode !== "off" && bind !== "loopback") {
|
||||
bind = "loopback";
|
||||
}
|
||||
if (tailscaleMode === "funnel" && authMode !== "password") {
|
||||
authMode = "password";
|
||||
}
|
||||
|
||||
let nextConfig = params.nextConfig;
|
||||
let gatewayToken = opts.gatewayToken?.trim() || undefined;
|
||||
|
||||
if (authMode === "token") {
|
||||
if (!gatewayToken) gatewayToken = randomToken();
|
||||
if (!gatewayToken) {
|
||||
gatewayToken = randomToken();
|
||||
}
|
||||
nextConfig = {
|
||||
...nextConfig,
|
||||
gateway: {
|
||||
|
||||
@@ -18,7 +18,9 @@ export function logNonInteractiveOnboardingJson(params: {
|
||||
skipSkills?: boolean;
|
||||
skipHealth?: boolean;
|
||||
}) {
|
||||
if (!params.opts.json) return;
|
||||
if (!params.opts.json) {
|
||||
return;
|
||||
}
|
||||
params.runtime.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
|
||||
@@ -8,7 +8,9 @@ export function applyNonInteractiveSkillsConfig(params: {
|
||||
runtime: RuntimeEnv;
|
||||
}) {
|
||||
const { nextConfig, opts, runtime } = params;
|
||||
if (opts.skipSkills) return nextConfig;
|
||||
if (opts.skipSkills) {
|
||||
return nextConfig;
|
||||
}
|
||||
|
||||
const nodeManager = opts.nodeManager ?? "npm";
|
||||
if (!["npm", "pnpm", "bun"].includes(nodeManager)) {
|
||||
|
||||
Reference in New Issue
Block a user