style: apply oxfmt formatting

This commit is contained in:
Nattapong Tapachoom 2026-01-28 09:10:47 +07:00
parent b76f983941
commit 8a2878f67f
10 changed files with 142 additions and 345 deletions

View File

@ -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",

View File

@ -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;
}

View File

@ -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 };

View File

@ -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,
});

View File

@ -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];

View File

@ -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,

View File

@ -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(

View File

@ -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(
[
"<!doctype html>",
"<html><head><meta charset='utf-8' /></head>",
"<body><h2>Chutes OAuth complete</h2>",
"<p>You can close this window and return to moltbot.</p></body></html>",
].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(
[
"<!doctype html>",
"<html><head><meta charset='utf-8' /></head>",
"<body><h2>Chutes OAuth complete</h2>",
"<p>You can close this window and return to moltbot.</p></body></html>",
].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<OAuthCredentials> {
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();

View File

@ -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,

View File

@ -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<InstallChoice>({
@ -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,