From 8a2878f67f42e7f5b3a8b3baf7698e5cfa81c9c8 Mon Sep 17 00:00:00 2001 From: Nattapong Tapachoom Date: Wed, 28 Jan 2026 09:10:47 +0700 Subject: [PATCH] style: apply oxfmt formatting --- src/commands/auth-choice.apply.anthropic.ts | 32 +--- .../auth-choice.apply.api-providers.ts | 172 ++++-------------- .../auth-choice.apply.github-copilot.ts | 25 +-- src/commands/auth-choice.apply.minimax.ts | 17 +- src/commands/auth-choice.apply.oauth.ts | 15 +- src/commands/auth-choice.apply.openai.ts | 5 +- .../auth-choice.apply.plugin-provider.ts | 63 ++----- src/commands/chutes-oauth.ts | 129 +++++++------ src/commands/onboard-auth.ts | 5 +- src/commands/onboarding/plugin-install.ts | 24 +-- 10 files changed, 142 insertions(+), 345 deletions(-) diff --git a/src/commands/auth-choice.apply.anthropic.ts b/src/commands/auth-choice.apply.anthropic.ts index 13c5cea9e..d9b2cca75 100644 --- a/src/commands/auth-choice.apply.anthropic.ts +++ b/src/commands/auth-choice.apply.anthropic.ts @@ -5,14 +5,8 @@ import { normalizeApiKeyInput, validateApiKeyInput, } from "./auth-choice.api-key.js"; -import type { - ApplyAuthChoiceParams, - ApplyAuthChoiceResult, -} from "./auth-choice.apply.js"; -import { - buildTokenProfileId, - validateAnthropicSetupToken, -} from "./auth-token.js"; +import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js"; +import { buildTokenProfileId, validateAnthropicSetupToken } from "./auth-token.js"; import { applyAuthProfileConfig, ensureAuthProfileStore, @@ -29,10 +23,9 @@ export async function applyAuthChoiceAnthropic( ) { let nextConfig = params.config; await params.prompter.note( - [ - "Run `claude setup-token` in your terminal.", - "Then paste the generated token below.", - ].join("\n"), + ["Run `claude setup-token` in your terminal.", "Then paste the generated token below."].join( + "\n", + ), "Anthropic setup-token", ); @@ -71,10 +64,7 @@ export async function applyAuthChoiceAnthropic( } if (params.authChoice === "apiKey") { - if ( - params.opts?.tokenProvider && - params.opts.tokenProvider !== "anthropic" - ) { + if (params.opts?.tokenProvider && params.opts.tokenProvider !== "anthropic") { return null; } @@ -83,10 +73,7 @@ export async function applyAuthChoiceAnthropic( const envKey = process.env.ANTHROPIC_API_KEY?.trim(); if (params.opts?.token) { - await setAnthropicApiKey( - normalizeApiKeyInput(params.opts.token), - params.agentDir, - ); + await setAnthropicApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir); hasCredential = true; } @@ -122,10 +109,7 @@ export async function applyAuthChoiceAnthropic( message: "Enter Anthropic API key", validate: validateApiKeyInput, }); - await setAnthropicApiKey( - normalizeApiKeyInput(String(key)), - params.agentDir, - ); + await setAnthropicApiKey(normalizeApiKeyInput(String(key)), params.agentDir); } nextConfig = applyAuthProfileConfig(nextConfig, { profileId: "anthropic:default", diff --git a/src/commands/auth-choice.apply.api-providers.ts b/src/commands/auth-choice.apply.api-providers.ts index 47ba312db..83bbbcd38 100644 --- a/src/commands/auth-choice.apply.api-providers.ts +++ b/src/commands/auth-choice.apply.api-providers.ts @@ -1,17 +1,11 @@ -import { - ensureAuthProfileStore, - resolveAuthProfileOrder, -} from "../agents/auth-profiles.js"; +import { ensureAuthProfileStore, resolveAuthProfileOrder } from "../agents/auth-profiles.js"; import { resolveEnvApiKey } from "../agents/model-auth.js"; import { formatApiKeyPreview, normalizeApiKeyInput, validateApiKeyInput, } from "./auth-choice.api-key.js"; -import type { - ApplyAuthChoiceParams, - ApplyAuthChoiceResult, -} from "./auth-choice.apply.js"; +import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js"; import { applyDefaultModelChoice } from "./auth-choice.default-model.js"; import { applyGoogleGeminiModelDefault, @@ -103,12 +97,8 @@ export async function applyAuthChoiceApiProviders( store, provider: "openrouter", }); - const existingProfileId = profileOrder.find((profileId) => - Boolean(store.profiles[profileId]), - ); - const existingCred = existingProfileId - ? store.profiles[existingProfileId] - : undefined; + const existingProfileId = profileOrder.find((profileId) => Boolean(store.profiles[profileId])); + const existingCred = existingProfileId ? store.profiles[existingProfileId] : undefined; let profileId = "openrouter:default"; let mode: "api_key" | "oauth" | "token" = "api_key"; let hasCredential = false; @@ -124,15 +114,8 @@ export async function applyAuthChoiceApiProviders( hasCredential = true; } - if ( - !hasCredential && - params.opts?.token && - params.opts?.tokenProvider === "openrouter" - ) { - await setOpenrouterApiKey( - normalizeApiKeyInput(params.opts.token), - params.agentDir, - ); + if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "openrouter") { + await setOpenrouterApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir); hasCredential = true; } @@ -155,10 +138,7 @@ export async function applyAuthChoiceApiProviders( message: "Enter OpenRouter API key", validate: validateApiKeyInput, }); - await setOpenrouterApiKey( - normalizeApiKeyInput(String(key)), - params.agentDir, - ); + await setOpenrouterApiKey(normalizeApiKeyInput(String(key)), params.agentDir); hasCredential = true; } @@ -194,10 +174,7 @@ export async function applyAuthChoiceApiProviders( params.opts?.token && params.opts?.tokenProvider === "vercel-ai-gateway" ) { - await setVercelAiGatewayApiKey( - normalizeApiKeyInput(params.opts.token), - params.agentDir, - ); + await setVercelAiGatewayApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir); hasCredential = true; } @@ -210,9 +187,7 @@ export async function applyAuthChoiceApiProviders( store, provider: "vercel-ai-gateway", }); - const existingProfileId = profileOrder.find((pid) => - Boolean(store.profiles[pid]), - ); + const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid])); let profileId = "vercel-ai-gateway:default"; if (existingProfileId) { @@ -242,10 +217,7 @@ export async function applyAuthChoiceApiProviders( message: "Enter Vercel AI Gateway API key", validate: validateApiKeyInput, }); - await setVercelAiGatewayApiKey( - normalizeApiKeyInput(String(key)), - params.agentDir, - ); + await setVercelAiGatewayApiKey(normalizeApiKeyInput(String(key)), params.agentDir); } nextConfig = applyAuthProfileConfig(nextConfig, { profileId, @@ -278,9 +250,7 @@ export async function applyAuthChoiceApiProviders( store, provider: "moonshot", }); - const existingProfileId = profileOrder.find((pid) => - Boolean(store.profiles[pid]), - ); + const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid])); let profileId = "moonshot:default"; let hasCredential = false; @@ -296,15 +266,8 @@ export async function applyAuthChoiceApiProviders( } } - if ( - !hasCredential && - params.opts?.token && - params.opts?.tokenProvider === "moonshot" - ) { - await setMoonshotApiKey( - normalizeApiKeyInput(params.opts.token), - params.agentDir, - ); + if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "moonshot") { + await setMoonshotApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir); hasCredential = true; } @@ -327,10 +290,7 @@ export async function applyAuthChoiceApiProviders( message: "Enter Moonshot API key", validate: validateApiKeyInput, }); - await setMoonshotApiKey( - normalizeApiKeyInput(String(key)), - params.agentDir, - ); + await setMoonshotApiKey(normalizeApiKeyInput(String(key)), params.agentDir); hasCredential = true; } @@ -366,9 +326,7 @@ export async function applyAuthChoiceApiProviders( store, provider: "kimi-code", }); - const existingProfileId = profileOrder.find((pid) => - Boolean(store.profiles[pid]), - ); + const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid])); let profileId = "kimi-code:default"; let hasCredential = false; @@ -384,15 +342,8 @@ export async function applyAuthChoiceApiProviders( } } - if ( - !hasCredential && - params.opts?.token && - params.opts?.tokenProvider === "kimi-code" - ) { - await setKimiCodeApiKey( - normalizeApiKeyInput(params.opts.token), - params.agentDir, - ); + if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "kimi-code") { + await setKimiCodeApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir); hasCredential = true; } @@ -423,10 +374,7 @@ export async function applyAuthChoiceApiProviders( message: "Enter Kimi Code API key", validate: validateApiKeyInput, }); - await setKimiCodeApiKey( - normalizeApiKeyInput(String(key)), - params.agentDir, - ); + await setKimiCodeApiKey(normalizeApiKeyInput(String(key)), params.agentDir); hasCredential = true; } @@ -463,9 +411,7 @@ export async function applyAuthChoiceApiProviders( store, provider: "google", }); - const existingProfileId = profileOrder.find((pid) => - Boolean(store.profiles[pid]), - ); + const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid])); let profileId = "google:default"; let hasCredential = false; @@ -481,15 +427,8 @@ export async function applyAuthChoiceApiProviders( } } - if ( - !hasCredential && - params.opts?.token && - params.opts?.tokenProvider === "google" - ) { - await setGeminiApiKey( - normalizeApiKeyInput(params.opts.token), - params.agentDir, - ); + if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "google") { + await setGeminiApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir); hasCredential = true; } @@ -549,9 +488,7 @@ export async function applyAuthChoiceApiProviders( store, provider: "zai", }); - const existingProfileId = profileOrder.find((pid) => - Boolean(store.profiles[pid]), - ); + const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid])); let profileId = "zai:default"; let hasCredential = false; @@ -567,15 +504,8 @@ export async function applyAuthChoiceApiProviders( } } - if ( - !hasCredential && - params.opts?.token && - params.opts?.tokenProvider === "zai" - ) { - await setZaiApiKey( - normalizeApiKeyInput(params.opts.token), - params.agentDir, - ); + if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "zai") { + await setZaiApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir); hasCredential = true; } @@ -625,9 +555,7 @@ export async function applyAuthChoiceApiProviders( ...config.agents?.defaults?.models, [ZAI_DEFAULT_MODEL_REF]: { ...config.agents?.defaults?.models?.[ZAI_DEFAULT_MODEL_REF], - alias: - config.agents?.defaults?.models?.[ZAI_DEFAULT_MODEL_REF] - ?.alias ?? "GLM", + alias: config.agents?.defaults?.models?.[ZAI_DEFAULT_MODEL_REF]?.alias ?? "GLM", }, }, }, @@ -652,9 +580,7 @@ export async function applyAuthChoiceApiProviders( store, provider: "synthetic", }); - const existingProfileId = profileOrder.find((pid) => - Boolean(store.profiles[pid]), - ); + const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid])); let profileId = "synthetic:default"; let hasCredential = false; @@ -670,15 +596,8 @@ export async function applyAuthChoiceApiProviders( } } - if ( - !hasCredential && - params.opts?.token && - params.opts?.tokenProvider === "synthetic" - ) { - await setSyntheticApiKey( - String(params.opts.token).trim(), - params.agentDir, - ); + if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "synthetic") { + await setSyntheticApiKey(String(params.opts.token).trim(), params.agentDir); hasCredential = true; } @@ -724,9 +643,7 @@ export async function applyAuthChoiceApiProviders( store, provider: "venice", }); - const existingProfileId = profileOrder.find((pid) => - Boolean(store.profiles[pid]), - ); + const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid])); let profileId = "venice:default"; let hasCredential = false; @@ -742,15 +659,8 @@ export async function applyAuthChoiceApiProviders( } } - if ( - !hasCredential && - params.opts?.token && - params.opts?.tokenProvider === "venice" - ) { - await setVeniceApiKey( - normalizeApiKeyInput(params.opts.token), - params.agentDir, - ); + if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "venice") { + await setVeniceApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir); hasCredential = true; } @@ -819,9 +729,7 @@ export async function applyAuthChoiceApiProviders( store, provider: "opencode", }); - const existingProfileId = profileOrder.find((pid) => - Boolean(store.profiles[pid]), - ); + const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid])); let profileId = "opencode:default"; let hasCredential = false; @@ -837,15 +745,8 @@ export async function applyAuthChoiceApiProviders( } } - if ( - !hasCredential && - params.opts?.token && - params.opts?.tokenProvider === "opencode" - ) { - await setOpencodeZenApiKey( - normalizeApiKeyInput(params.opts.token), - params.agentDir, - ); + if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "opencode") { + await setOpencodeZenApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir); hasCredential = true; } @@ -877,10 +778,7 @@ export async function applyAuthChoiceApiProviders( message: "Enter OpenCode Zen API key", validate: validateApiKeyInput, }); - await setOpencodeZenApiKey( - normalizeApiKeyInput(String(key)), - params.agentDir, - ); + await setOpencodeZenApiKey(normalizeApiKeyInput(String(key)), params.agentDir); hasCredential = true; } diff --git a/src/commands/auth-choice.apply.github-copilot.ts b/src/commands/auth-choice.apply.github-copilot.ts index b6347143c..1ce4ee05a 100644 --- a/src/commands/auth-choice.apply.github-copilot.ts +++ b/src/commands/auth-choice.apply.github-copilot.ts @@ -1,13 +1,7 @@ import { githubCopilotLoginCommand } from "../providers/github-copilot-auth.js"; declare const process: any; -import type { - ApplyAuthChoiceParams, - ApplyAuthChoiceResult, -} from "./auth-choice.apply.js"; -import { - applyAuthProfileConfig, - ensureAuthProfileStore, -} from "./onboard-auth.js"; +import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js"; +import { applyAuthProfileConfig, ensureAuthProfileStore } from "./onboard-auth.js"; export async function applyAuthChoiceGitHubCopilot( params: ApplyAuthChoiceParams, @@ -45,10 +39,7 @@ export async function applyAuthChoiceGitHubCopilot( try { await githubCopilotLoginCommand({ yes: true }, params.runtime); } catch (err) { - await params.prompter.note( - `GitHub Copilot login failed: ${String(err)}`, - "GitHub Copilot", - ); + await params.prompter.note(`GitHub Copilot login failed: ${String(err)}`, "GitHub Copilot"); return { config: nextConfig }; } } @@ -62,10 +53,7 @@ export async function applyAuthChoiceGitHubCopilot( try { await githubCopilotLoginCommand({ yes: true }, params.runtime); } catch (err) { - await params.prompter.note( - `GitHub Copilot login failed: ${String(err)}`, - "GitHub Copilot", - ); + await params.prompter.note(`GitHub Copilot login failed: ${String(err)}`, "GitHub Copilot"); return { config: nextConfig }; } } @@ -93,10 +81,7 @@ export async function applyAuthChoiceGitHubCopilot( }, }, }; - await params.prompter.note( - `Default model set to ${model}`, - "Model configured", - ); + await params.prompter.note(`Default model set to ${model}`, "Model configured"); } return { config: nextConfig }; diff --git a/src/commands/auth-choice.apply.minimax.ts b/src/commands/auth-choice.apply.minimax.ts index 406a0a72d..1ab600866 100644 --- a/src/commands/auth-choice.apply.minimax.ts +++ b/src/commands/auth-choice.apply.minimax.ts @@ -4,10 +4,7 @@ import { normalizeApiKeyInput, validateApiKeyInput, } from "./auth-choice.api-key.js"; -import type { - ApplyAuthChoiceParams, - ApplyAuthChoiceResult, -} from "./auth-choice.apply.js"; +import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js"; import { applyDefaultModelChoice } from "./auth-choice.default-model.js"; import { applyAuthProfileConfig, @@ -38,9 +35,7 @@ export async function applyAuthChoiceMiniMax( params.authChoice === "minimax-api-lightning" ) { const modelId = - params.authChoice === "minimax-api-lightning" - ? "MiniMax-M2.1-lightning" - : "MiniMax-M2.1"; + params.authChoice === "minimax-api-lightning" ? "MiniMax-M2.1-lightning" : "MiniMax-M2.1"; let hasCredential = false; const store = ensureAuthProfileStore(params.agentDir, { @@ -74,10 +69,7 @@ export async function applyAuthChoiceMiniMax( message: "Enter MiniMax API key", validate: validateApiKeyInput, }); - await setMinimaxApiKey( - normalizeApiKeyInput(String(key)), - params.agentDir, - ); + await setMinimaxApiKey(normalizeApiKeyInput(String(key)), params.agentDir); } nextConfig = applyAuthProfileConfig(nextConfig, { profileId: "minimax:default", @@ -91,8 +83,7 @@ export async function applyAuthChoiceMiniMax( setDefaultModel: params.setDefaultModel, defaultModel: modelRef, applyDefaultConfig: (config) => applyMinimaxApiConfig(config, modelId), - applyProviderConfig: (config) => - applyMinimaxApiProviderConfig(config, modelId), + applyProviderConfig: (config) => applyMinimaxApiProviderConfig(config, modelId), noteAgentModel, prompter: params.prompter, }); diff --git a/src/commands/auth-choice.apply.oauth.ts b/src/commands/auth-choice.apply.oauth.ts index f928dcc12..1137d7074 100644 --- a/src/commands/auth-choice.apply.oauth.ts +++ b/src/commands/auth-choice.apply.oauth.ts @@ -1,9 +1,6 @@ import { isRemoteEnvironment } from "./oauth-env.js"; declare const process: any; -import type { - ApplyAuthChoiceParams, - ApplyAuthChoiceResult, -} from "./auth-choice.apply.js"; +import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js"; import { loginChutes } from "./chutes-oauth.js"; import { createVpsAwareOAuthHandlers } from "./oauth-flow.js"; import { @@ -20,10 +17,8 @@ export async function applyAuthChoiceOAuth( let nextConfig = params.config; const isRemote = isRemoteEnvironment(); const redirectUri = - process.env.CHUTES_OAUTH_REDIRECT_URI?.trim() || - "http://127.0.0.1:1456/oauth-callback"; - const scopes = - process.env.CHUTES_OAUTH_SCOPES?.trim() || "openid profile chutes:invoke"; + process.env.CHUTES_OAUTH_REDIRECT_URI?.trim() || "http://127.0.0.1:1456/oauth-callback"; + const scopes = process.env.CHUTES_OAUTH_SCOPES?.trim() || "openid profile chutes:invoke"; const clientId = process.env.CHUTES_CLIENT_ID?.trim() || String( @@ -38,9 +33,7 @@ export async function applyAuthChoiceOAuth( const store = ensureAuthProfileStore(params.agentDir, { allowKeychainPrompt: false, }); - const existingProfileId = Object.keys(store.profiles).find((id) => - id.startsWith("chutes:"), - ); + const existingProfileId = Object.keys(store.profiles).find((id) => id.startsWith("chutes:")); if (existingProfileId) { const existing = store.profiles[existingProfileId]; diff --git a/src/commands/auth-choice.apply.openai.ts b/src/commands/auth-choice.apply.openai.ts index adb86fa7a..830b0ea01 100644 --- a/src/commands/auth-choice.apply.openai.ts +++ b/src/commands/auth-choice.apply.openai.ts @@ -9,10 +9,7 @@ import { normalizeApiKeyInput, validateApiKeyInput, } from "./auth-choice.api-key.js"; -import type { - ApplyAuthChoiceParams, - ApplyAuthChoiceResult, -} from "./auth-choice.apply.js"; +import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js"; import { createVpsAwareOAuthHandlers } from "./oauth-flow.js"; import { applyAuthProfileConfig, diff --git a/src/commands/auth-choice.apply.plugin-provider.ts b/src/commands/auth-choice.apply.plugin-provider.ts index b2ffff7de..23cc12080 100644 --- a/src/commands/auth-choice.apply.plugin-provider.ts +++ b/src/commands/auth-choice.apply.plugin-provider.ts @@ -11,14 +11,8 @@ import type { MoltbotConfig } from "../config/config.js"; import { enablePluginInConfig } from "../plugins/enable.js"; import { resolvePluginProviders } from "../plugins/providers.js"; import type { ProviderAuthMethod, ProviderPlugin } from "../plugins/types.js"; -import type { - ApplyAuthChoiceParams, - ApplyAuthChoiceResult, -} from "./auth-choice.apply.js"; -import { - applyAuthProfileConfig, - ensureAuthProfileStore, -} from "./onboard-auth.js"; +import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js"; +import { applyAuthProfileConfig, ensureAuthProfileStore } from "./onboard-auth.js"; import { openUrl } from "./onboard-helpers.js"; import { createVpsAwareOAuthHandlers } from "./oauth-flow.js"; import { isRemoteEnvironment } from "./oauth-env.js"; @@ -37,23 +31,16 @@ function resolveProviderMatch( ): ProviderPlugin | null { const normalized = normalizeProviderId(rawProvider); return ( - providers.find( - (provider) => normalizeProviderId(provider.id) === normalized, - ) ?? + providers.find((provider) => normalizeProviderId(provider.id) === normalized) ?? providers.find( (provider) => - provider.aliases?.some( - (alias) => normalizeProviderId(alias) === normalized, - ) ?? false, + provider.aliases?.some((alias) => normalizeProviderId(alias) === normalized) ?? false, ) ?? null ); } -function pickAuthMethod( - provider: ProviderPlugin, - rawMethod?: string, -): ProviderAuthMethod | null { +function pickAuthMethod(provider: ProviderPlugin, rawMethod?: string): ProviderAuthMethod | null { const raw = rawMethod?.trim(); if (!raw) return null; const normalized = raw.toLowerCase(); @@ -98,12 +85,9 @@ function applyDefaultModel(cfg: MoltbotConfig, model: string): MoltbotConfig { ...cfg.agents?.defaults, models, model: { - ...(existingModel && - typeof existingModel === "object" && - "fallbacks" in existingModel + ...(existingModel && typeof existingModel === "object" && "fallbacks" in existingModel ? { - fallbacks: (existingModel as { fallbacks?: string[] }) - .fallbacks, + fallbacks: (existingModel as { fallbacks?: string[] }).fallbacks, } : undefined), primary: model, @@ -134,12 +118,9 @@ export async function applyAuthChoicePluginProvider( const defaultAgentId = resolveDefaultAgentId(nextConfig); const agentDir = params.agentDir ?? - (agentId === defaultAgentId - ? resolveMoltbotAgentDir() - : resolveAgentDir(nextConfig, agentId)); + (agentId === defaultAgentId ? resolveMoltbotAgentDir() : resolveAgentDir(nextConfig, agentId)); const workspaceDir = - resolveAgentWorkspaceDir(nextConfig, agentId) ?? - resolveDefaultAgentWorkspaceDir(); + resolveAgentWorkspaceDir(nextConfig, agentId) ?? resolveDefaultAgentWorkspaceDir(); const providers = resolvePluginProviders({ config: nextConfig, @@ -156,10 +137,7 @@ export async function applyAuthChoicePluginProvider( const method = pickAuthMethod(provider, options.methodId) ?? provider.auth[0]; if (!method) { - await params.prompter.note( - `${options.label} auth method missing.`, - options.label, - ); + await params.prompter.note(`${options.label} auth method missing.`, options.label); return { config: nextConfig }; } @@ -167,9 +145,7 @@ export async function applyAuthChoicePluginProvider( allowKeychainPrompt: false, }); const existingProfiles = Object.entries(store.profiles).filter( - ([, p]) => - normalizeProviderId((p as any).provider) === - normalizeProviderId(options.providerId), + ([, p]) => normalizeProviderId((p as any).provider) === normalizeProviderId(options.providerId), ); if (existingProfiles.length > 0) { @@ -188,16 +164,11 @@ export async function applyAuthChoicePluginProvider( profileId, provider: profile.provider, mode: (profile.type === "token" ? "token" : profile.type) as any, - ...("email" in profile && profile.email - ? { email: profile.email as string } - : {}), + ...("email" in profile && profile.email ? { email: profile.email as string } : {}), }); if (params.setDefaultModel && provider.models?.models?.[0]?.id) { - nextConfig = applyDefaultModel( - nextConfig, - provider.models.models[0].id, - ); + nextConfig = applyDefaultModel(nextConfig, provider.models.models[0].id); } else if (params.agentId && provider.models?.models?.[0]?.id) { agentModelOverride = provider.models.models[0].id; } @@ -236,8 +207,7 @@ export async function applyAuthChoicePluginProvider( nextConfig = applyAuthProfileConfig(nextConfig, { profileId: profile.profileId, provider: profile.credential.provider, - mode: - profile.credential.type === "token" ? "token" : profile.credential.type, + mode: profile.credential.type === "token" ? "token" : profile.credential.type, ...("email" in profile.credential && profile.credential.email ? { email: profile.credential.email } : {}), @@ -247,10 +217,7 @@ export async function applyAuthChoicePluginProvider( if (result.defaultModel) { if (params.setDefaultModel) { nextConfig = applyDefaultModel(nextConfig, result.defaultModel); - await params.prompter.note( - `Default model set to ${result.defaultModel}`, - "Model configured", - ); + await params.prompter.note(`Default model set to ${result.defaultModel}`, "Model configured"); } else if (params.agentId) { agentModelOverride = result.defaultModel; await params.prompter.note( diff --git a/src/commands/chutes-oauth.ts b/src/commands/chutes-oauth.ts index 13d4c337c..cf12971b3 100644 --- a/src/commands/chutes-oauth.ts +++ b/src/commands/chutes-oauth.ts @@ -44,83 +44,77 @@ async function waitForLocalCallback(params: { }): Promise<{ code: string; state: string }> { const redirectUrl = new URL(params.redirectUri); if (redirectUrl.protocol !== "http:") { - throw new Error( - `Chutes OAuth redirect URI must be http:// (got ${params.redirectUri})`, - ); + throw new Error(`Chutes OAuth redirect URI must be http:// (got ${params.redirectUri})`); } const hostname = redirectUrl.hostname || "127.0.0.1"; const port = redirectUrl.port ? Number.parseInt(redirectUrl.port, 10) : 80; const expectedPath = redirectUrl.pathname || "/"; - return await new Promise<{ code: string; state: string }>( - (resolve, reject) => { - // @ts-ignore - let timeout: NodeJS.Timeout | null = null; - const server = createServer((req: any, res: any) => { - try { - const requestUrl = new URL(req.url ?? "/", redirectUrl.origin); - if (requestUrl.pathname !== expectedPath) { - res.statusCode = 404; - res.setHeader("Content-Type", "text/plain; charset=utf-8"); - res.end("Not found"); - return; - } - - const code = requestUrl.searchParams.get("code")?.trim(); - const state = requestUrl.searchParams.get("state")?.trim(); - - if (!code) { - res.statusCode = 400; - res.setHeader("Content-Type", "text/plain; charset=utf-8"); - res.end("Missing code"); - return; - } - if (!state || state !== params.expectedState) { - res.statusCode = 400; - res.setHeader("Content-Type", "text/plain; charset=utf-8"); - res.end("Invalid state"); - return; - } - - res.statusCode = 200; - res.setHeader("Content-Type", "text/html; charset=utf-8"); - res.end( - [ - "", - "", - "

Chutes OAuth complete

", - "

You can close this window and return to moltbot.

", - ].join(""), - ); - if (timeout) clearTimeout(timeout); - server.close(); - resolve({ code, state }); - } catch (err) { - if (timeout) clearTimeout(timeout); - server.close(); - reject(err); + return await new Promise<{ code: string; state: string }>((resolve, reject) => { + // @ts-ignore + let timeout: NodeJS.Timeout | null = null; + const server = createServer((req: any, res: any) => { + try { + const requestUrl = new URL(req.url ?? "/", redirectUrl.origin); + if (requestUrl.pathname !== expectedPath) { + res.statusCode = 404; + res.setHeader("Content-Type", "text/plain; charset=utf-8"); + res.end("Not found"); + return; } - }); - server.once("error", (err: any) => { + const code = requestUrl.searchParams.get("code")?.trim(); + const state = requestUrl.searchParams.get("state")?.trim(); + + if (!code) { + res.statusCode = 400; + res.setHeader("Content-Type", "text/plain; charset=utf-8"); + res.end("Missing code"); + return; + } + if (!state || state !== params.expectedState) { + res.statusCode = 400; + res.setHeader("Content-Type", "text/plain; charset=utf-8"); + res.end("Invalid state"); + return; + } + + res.statusCode = 200; + res.setHeader("Content-Type", "text/html; charset=utf-8"); + res.end( + [ + "", + "", + "

Chutes OAuth complete

", + "

You can close this window and return to moltbot.

", + ].join(""), + ); + if (timeout) clearTimeout(timeout); + server.close(); + resolve({ code, state }); + } catch (err) { if (timeout) clearTimeout(timeout); server.close(); reject(err); - }); - server.listen(port, hostname, () => { - params.onProgress?.( - `Waiting for OAuth callback on ${redirectUrl.origin}${expectedPath}…`, - ); - }); + } + }); - timeout = setTimeout(() => { - try { - server.close(); - } catch {} - reject(new Error("OAuth callback timeout")); - }, params.timeoutMs); - }, - ); + server.once("error", (err: any) => { + if (timeout) clearTimeout(timeout); + server.close(); + reject(err); + }); + server.listen(port, hostname, () => { + params.onProgress?.(`Waiting for OAuth callback on ${redirectUrl.origin}${expectedPath}…`); + }); + + timeout = setTimeout(() => { + try { + server.close(); + } catch {} + reject(new Error("OAuth callback timeout")); + }, params.timeoutMs); + }); } export async function loginChutes(params: { @@ -135,8 +129,7 @@ export async function loginChutes(params: { fetchFn?: typeof fetch; }): Promise { const createPkce = params.createPkce ?? generateChutesPkce; - const createState = - params.createState ?? (() => randomBytes(16).toString("hex")); + const createState = params.createState ?? (() => randomBytes(16).toString("hex")); const { verifier, challenge } = createPkce(); const state = createState(); diff --git a/src/commands/onboard-auth.ts b/src/commands/onboard-auth.ts index 19ee5bcfe..cf3ff1d2c 100644 --- a/src/commands/onboard-auth.ts +++ b/src/commands/onboard-auth.ts @@ -3,10 +3,7 @@ export { SYNTHETIC_DEFAULT_MODEL_ID, SYNTHETIC_DEFAULT_MODEL_REF, } from "../agents/synthetic-models.js"; -export { - VENICE_DEFAULT_MODEL_ID, - VENICE_DEFAULT_MODEL_REF, -} from "../agents/venice-models.js"; +export { VENICE_DEFAULT_MODEL_ID, VENICE_DEFAULT_MODEL_REF } from "../agents/venice-models.js"; export { applyAuthProfileConfig, applyKimiCodeConfig, diff --git a/src/commands/onboarding/plugin-install.ts b/src/commands/onboarding/plugin-install.ts index dd3b7aa97..32b6ff860 100644 --- a/src/commands/onboarding/plugin-install.ts +++ b/src/commands/onboarding/plugin-install.ts @@ -1,10 +1,7 @@ import fs from "node:fs"; import path from "node:path"; declare const process: any; -import { - resolveAgentWorkspaceDir, - resolveDefaultAgentId, -} from "../../agents/agent-scope.js"; +import { resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../../agents/agent-scope.js"; import type { ChannelPluginCatalogEntry } from "../../channels/plugins/catalog.js"; import type { MoltbotConfig } from "../../config/config.js"; import { createSubsystemLogger } from "../../logging/subsystem.js"; @@ -53,10 +50,7 @@ function resolveLocalPath( return null; } -function addPluginLoadPath( - cfg: MoltbotConfig, - pluginPath: string, -): MoltbotConfig { +function addPluginLoadPath(cfg: MoltbotConfig, pluginPath: string): MoltbotConfig { const existing = cfg.plugins?.load?.paths ?? []; const merged = Array.from(new Set([...existing, pluginPath])); return { @@ -91,12 +85,11 @@ async function promptInstallChoice(params: { }, ] : []; - const options: Array<{ value: InstallChoice; label: string; hint?: string }> = - [ - { value: "npm", label: `Download from npm (${entry.install.npmSpec})` }, - ...localOptions, - { value: "skip", label: "Skip for now" }, - ]; + const options: Array<{ value: InstallChoice; label: string; hint?: string }> = [ + { value: "npm", label: `Download from npm (${entry.install.npmSpec})` }, + ...localOptions, + { value: "skip", label: "Skip for now" }, + ]; const initialValue: InstallChoice = defaultChoice === "local" && !localPath ? "npm" : defaultChoice; return await prompter.select({ @@ -205,8 +198,7 @@ export function reloadOnboardingPluginRegistry(params: { workspaceDir?: string; }): void { const workspaceDir = - params.workspaceDir ?? - resolveAgentWorkspaceDir(params.cfg, resolveDefaultAgentId(params.cfg)); + params.workspaceDir ?? resolveAgentWorkspaceDir(params.cfg, resolveDefaultAgentId(params.cfg)); const log = createSubsystemLogger("plugins"); loadMoltbotPlugins({ config: params.cfg,