style: apply oxfmt formatting
This commit is contained in:
parent
b76f983941
commit
8a2878f67f
@ -5,14 +5,8 @@ import {
|
|||||||
normalizeApiKeyInput,
|
normalizeApiKeyInput,
|
||||||
validateApiKeyInput,
|
validateApiKeyInput,
|
||||||
} from "./auth-choice.api-key.js";
|
} from "./auth-choice.api-key.js";
|
||||||
import type {
|
import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js";
|
||||||
ApplyAuthChoiceParams,
|
import { buildTokenProfileId, validateAnthropicSetupToken } from "./auth-token.js";
|
||||||
ApplyAuthChoiceResult,
|
|
||||||
} from "./auth-choice.apply.js";
|
|
||||||
import {
|
|
||||||
buildTokenProfileId,
|
|
||||||
validateAnthropicSetupToken,
|
|
||||||
} from "./auth-token.js";
|
|
||||||
import {
|
import {
|
||||||
applyAuthProfileConfig,
|
applyAuthProfileConfig,
|
||||||
ensureAuthProfileStore,
|
ensureAuthProfileStore,
|
||||||
@ -29,10 +23,9 @@ export async function applyAuthChoiceAnthropic(
|
|||||||
) {
|
) {
|
||||||
let nextConfig = params.config;
|
let nextConfig = params.config;
|
||||||
await params.prompter.note(
|
await params.prompter.note(
|
||||||
[
|
["Run `claude setup-token` in your terminal.", "Then paste the generated token below."].join(
|
||||||
"Run `claude setup-token` in your terminal.",
|
"\n",
|
||||||
"Then paste the generated token below.",
|
),
|
||||||
].join("\n"),
|
|
||||||
"Anthropic setup-token",
|
"Anthropic setup-token",
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -71,10 +64,7 @@ export async function applyAuthChoiceAnthropic(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (params.authChoice === "apiKey") {
|
if (params.authChoice === "apiKey") {
|
||||||
if (
|
if (params.opts?.tokenProvider && params.opts.tokenProvider !== "anthropic") {
|
||||||
params.opts?.tokenProvider &&
|
|
||||||
params.opts.tokenProvider !== "anthropic"
|
|
||||||
) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,10 +73,7 @@ export async function applyAuthChoiceAnthropic(
|
|||||||
const envKey = process.env.ANTHROPIC_API_KEY?.trim();
|
const envKey = process.env.ANTHROPIC_API_KEY?.trim();
|
||||||
|
|
||||||
if (params.opts?.token) {
|
if (params.opts?.token) {
|
||||||
await setAnthropicApiKey(
|
await setAnthropicApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir);
|
||||||
normalizeApiKeyInput(params.opts.token),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
hasCredential = true;
|
hasCredential = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,10 +109,7 @@ export async function applyAuthChoiceAnthropic(
|
|||||||
message: "Enter Anthropic API key",
|
message: "Enter Anthropic API key",
|
||||||
validate: validateApiKeyInput,
|
validate: validateApiKeyInput,
|
||||||
});
|
});
|
||||||
await setAnthropicApiKey(
|
await setAnthropicApiKey(normalizeApiKeyInput(String(key)), params.agentDir);
|
||||||
normalizeApiKeyInput(String(key)),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||||
profileId: "anthropic:default",
|
profileId: "anthropic:default",
|
||||||
|
|||||||
@ -1,17 +1,11 @@
|
|||||||
import {
|
import { ensureAuthProfileStore, resolveAuthProfileOrder } from "../agents/auth-profiles.js";
|
||||||
ensureAuthProfileStore,
|
|
||||||
resolveAuthProfileOrder,
|
|
||||||
} from "../agents/auth-profiles.js";
|
|
||||||
import { resolveEnvApiKey } from "../agents/model-auth.js";
|
import { resolveEnvApiKey } from "../agents/model-auth.js";
|
||||||
import {
|
import {
|
||||||
formatApiKeyPreview,
|
formatApiKeyPreview,
|
||||||
normalizeApiKeyInput,
|
normalizeApiKeyInput,
|
||||||
validateApiKeyInput,
|
validateApiKeyInput,
|
||||||
} from "./auth-choice.api-key.js";
|
} from "./auth-choice.api-key.js";
|
||||||
import type {
|
import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js";
|
||||||
ApplyAuthChoiceParams,
|
|
||||||
ApplyAuthChoiceResult,
|
|
||||||
} from "./auth-choice.apply.js";
|
|
||||||
import { applyDefaultModelChoice } from "./auth-choice.default-model.js";
|
import { applyDefaultModelChoice } from "./auth-choice.default-model.js";
|
||||||
import {
|
import {
|
||||||
applyGoogleGeminiModelDefault,
|
applyGoogleGeminiModelDefault,
|
||||||
@ -103,12 +97,8 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
store,
|
store,
|
||||||
provider: "openrouter",
|
provider: "openrouter",
|
||||||
});
|
});
|
||||||
const existingProfileId = profileOrder.find((profileId) =>
|
const existingProfileId = profileOrder.find((profileId) => Boolean(store.profiles[profileId]));
|
||||||
Boolean(store.profiles[profileId]),
|
const existingCred = existingProfileId ? store.profiles[existingProfileId] : undefined;
|
||||||
);
|
|
||||||
const existingCred = existingProfileId
|
|
||||||
? store.profiles[existingProfileId]
|
|
||||||
: undefined;
|
|
||||||
let profileId = "openrouter:default";
|
let profileId = "openrouter:default";
|
||||||
let mode: "api_key" | "oauth" | "token" = "api_key";
|
let mode: "api_key" | "oauth" | "token" = "api_key";
|
||||||
let hasCredential = false;
|
let hasCredential = false;
|
||||||
@ -124,15 +114,8 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
hasCredential = true;
|
hasCredential = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "openrouter") {
|
||||||
!hasCredential &&
|
await setOpenrouterApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir);
|
||||||
params.opts?.token &&
|
|
||||||
params.opts?.tokenProvider === "openrouter"
|
|
||||||
) {
|
|
||||||
await setOpenrouterApiKey(
|
|
||||||
normalizeApiKeyInput(params.opts.token),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
hasCredential = true;
|
hasCredential = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,10 +138,7 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
message: "Enter OpenRouter API key",
|
message: "Enter OpenRouter API key",
|
||||||
validate: validateApiKeyInput,
|
validate: validateApiKeyInput,
|
||||||
});
|
});
|
||||||
await setOpenrouterApiKey(
|
await setOpenrouterApiKey(normalizeApiKeyInput(String(key)), params.agentDir);
|
||||||
normalizeApiKeyInput(String(key)),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
hasCredential = true;
|
hasCredential = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,10 +174,7 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
params.opts?.token &&
|
params.opts?.token &&
|
||||||
params.opts?.tokenProvider === "vercel-ai-gateway"
|
params.opts?.tokenProvider === "vercel-ai-gateway"
|
||||||
) {
|
) {
|
||||||
await setVercelAiGatewayApiKey(
|
await setVercelAiGatewayApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir);
|
||||||
normalizeApiKeyInput(params.opts.token),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
hasCredential = true;
|
hasCredential = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,9 +187,7 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
store,
|
store,
|
||||||
provider: "vercel-ai-gateway",
|
provider: "vercel-ai-gateway",
|
||||||
});
|
});
|
||||||
const existingProfileId = profileOrder.find((pid) =>
|
const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid]));
|
||||||
Boolean(store.profiles[pid]),
|
|
||||||
);
|
|
||||||
let profileId = "vercel-ai-gateway:default";
|
let profileId = "vercel-ai-gateway:default";
|
||||||
|
|
||||||
if (existingProfileId) {
|
if (existingProfileId) {
|
||||||
@ -242,10 +217,7 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
message: "Enter Vercel AI Gateway API key",
|
message: "Enter Vercel AI Gateway API key",
|
||||||
validate: validateApiKeyInput,
|
validate: validateApiKeyInput,
|
||||||
});
|
});
|
||||||
await setVercelAiGatewayApiKey(
|
await setVercelAiGatewayApiKey(normalizeApiKeyInput(String(key)), params.agentDir);
|
||||||
normalizeApiKeyInput(String(key)),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||||
profileId,
|
profileId,
|
||||||
@ -278,9 +250,7 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
store,
|
store,
|
||||||
provider: "moonshot",
|
provider: "moonshot",
|
||||||
});
|
});
|
||||||
const existingProfileId = profileOrder.find((pid) =>
|
const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid]));
|
||||||
Boolean(store.profiles[pid]),
|
|
||||||
);
|
|
||||||
let profileId = "moonshot:default";
|
let profileId = "moonshot:default";
|
||||||
let hasCredential = false;
|
let hasCredential = false;
|
||||||
|
|
||||||
@ -296,15 +266,8 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "moonshot") {
|
||||||
!hasCredential &&
|
await setMoonshotApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir);
|
||||||
params.opts?.token &&
|
|
||||||
params.opts?.tokenProvider === "moonshot"
|
|
||||||
) {
|
|
||||||
await setMoonshotApiKey(
|
|
||||||
normalizeApiKeyInput(params.opts.token),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
hasCredential = true;
|
hasCredential = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,10 +290,7 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
message: "Enter Moonshot API key",
|
message: "Enter Moonshot API key",
|
||||||
validate: validateApiKeyInput,
|
validate: validateApiKeyInput,
|
||||||
});
|
});
|
||||||
await setMoonshotApiKey(
|
await setMoonshotApiKey(normalizeApiKeyInput(String(key)), params.agentDir);
|
||||||
normalizeApiKeyInput(String(key)),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
hasCredential = true;
|
hasCredential = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,9 +326,7 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
store,
|
store,
|
||||||
provider: "kimi-code",
|
provider: "kimi-code",
|
||||||
});
|
});
|
||||||
const existingProfileId = profileOrder.find((pid) =>
|
const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid]));
|
||||||
Boolean(store.profiles[pid]),
|
|
||||||
);
|
|
||||||
let profileId = "kimi-code:default";
|
let profileId = "kimi-code:default";
|
||||||
let hasCredential = false;
|
let hasCredential = false;
|
||||||
|
|
||||||
@ -384,15 +342,8 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "kimi-code") {
|
||||||
!hasCredential &&
|
await setKimiCodeApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir);
|
||||||
params.opts?.token &&
|
|
||||||
params.opts?.tokenProvider === "kimi-code"
|
|
||||||
) {
|
|
||||||
await setKimiCodeApiKey(
|
|
||||||
normalizeApiKeyInput(params.opts.token),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
hasCredential = true;
|
hasCredential = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,10 +374,7 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
message: "Enter Kimi Code API key",
|
message: "Enter Kimi Code API key",
|
||||||
validate: validateApiKeyInput,
|
validate: validateApiKeyInput,
|
||||||
});
|
});
|
||||||
await setKimiCodeApiKey(
|
await setKimiCodeApiKey(normalizeApiKeyInput(String(key)), params.agentDir);
|
||||||
normalizeApiKeyInput(String(key)),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
hasCredential = true;
|
hasCredential = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,9 +411,7 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
store,
|
store,
|
||||||
provider: "google",
|
provider: "google",
|
||||||
});
|
});
|
||||||
const existingProfileId = profileOrder.find((pid) =>
|
const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid]));
|
||||||
Boolean(store.profiles[pid]),
|
|
||||||
);
|
|
||||||
let profileId = "google:default";
|
let profileId = "google:default";
|
||||||
let hasCredential = false;
|
let hasCredential = false;
|
||||||
|
|
||||||
@ -481,15 +427,8 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "google") {
|
||||||
!hasCredential &&
|
await setGeminiApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir);
|
||||||
params.opts?.token &&
|
|
||||||
params.opts?.tokenProvider === "google"
|
|
||||||
) {
|
|
||||||
await setGeminiApiKey(
|
|
||||||
normalizeApiKeyInput(params.opts.token),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
hasCredential = true;
|
hasCredential = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -549,9 +488,7 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
store,
|
store,
|
||||||
provider: "zai",
|
provider: "zai",
|
||||||
});
|
});
|
||||||
const existingProfileId = profileOrder.find((pid) =>
|
const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid]));
|
||||||
Boolean(store.profiles[pid]),
|
|
||||||
);
|
|
||||||
let profileId = "zai:default";
|
let profileId = "zai:default";
|
||||||
let hasCredential = false;
|
let hasCredential = false;
|
||||||
|
|
||||||
@ -567,15 +504,8 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "zai") {
|
||||||
!hasCredential &&
|
await setZaiApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir);
|
||||||
params.opts?.token &&
|
|
||||||
params.opts?.tokenProvider === "zai"
|
|
||||||
) {
|
|
||||||
await setZaiApiKey(
|
|
||||||
normalizeApiKeyInput(params.opts.token),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
hasCredential = true;
|
hasCredential = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,9 +555,7 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
...config.agents?.defaults?.models,
|
...config.agents?.defaults?.models,
|
||||||
[ZAI_DEFAULT_MODEL_REF]: {
|
[ZAI_DEFAULT_MODEL_REF]: {
|
||||||
...config.agents?.defaults?.models?.[ZAI_DEFAULT_MODEL_REF],
|
...config.agents?.defaults?.models?.[ZAI_DEFAULT_MODEL_REF],
|
||||||
alias:
|
alias: config.agents?.defaults?.models?.[ZAI_DEFAULT_MODEL_REF]?.alias ?? "GLM",
|
||||||
config.agents?.defaults?.models?.[ZAI_DEFAULT_MODEL_REF]
|
|
||||||
?.alias ?? "GLM",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -652,9 +580,7 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
store,
|
store,
|
||||||
provider: "synthetic",
|
provider: "synthetic",
|
||||||
});
|
});
|
||||||
const existingProfileId = profileOrder.find((pid) =>
|
const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid]));
|
||||||
Boolean(store.profiles[pid]),
|
|
||||||
);
|
|
||||||
let profileId = "synthetic:default";
|
let profileId = "synthetic:default";
|
||||||
let hasCredential = false;
|
let hasCredential = false;
|
||||||
|
|
||||||
@ -670,15 +596,8 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "synthetic") {
|
||||||
!hasCredential &&
|
await setSyntheticApiKey(String(params.opts.token).trim(), params.agentDir);
|
||||||
params.opts?.token &&
|
|
||||||
params.opts?.tokenProvider === "synthetic"
|
|
||||||
) {
|
|
||||||
await setSyntheticApiKey(
|
|
||||||
String(params.opts.token).trim(),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
hasCredential = true;
|
hasCredential = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -724,9 +643,7 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
store,
|
store,
|
||||||
provider: "venice",
|
provider: "venice",
|
||||||
});
|
});
|
||||||
const existingProfileId = profileOrder.find((pid) =>
|
const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid]));
|
||||||
Boolean(store.profiles[pid]),
|
|
||||||
);
|
|
||||||
let profileId = "venice:default";
|
let profileId = "venice:default";
|
||||||
let hasCredential = false;
|
let hasCredential = false;
|
||||||
|
|
||||||
@ -742,15 +659,8 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "venice") {
|
||||||
!hasCredential &&
|
await setVeniceApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir);
|
||||||
params.opts?.token &&
|
|
||||||
params.opts?.tokenProvider === "venice"
|
|
||||||
) {
|
|
||||||
await setVeniceApiKey(
|
|
||||||
normalizeApiKeyInput(params.opts.token),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
hasCredential = true;
|
hasCredential = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -819,9 +729,7 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
store,
|
store,
|
||||||
provider: "opencode",
|
provider: "opencode",
|
||||||
});
|
});
|
||||||
const existingProfileId = profileOrder.find((pid) =>
|
const existingProfileId = profileOrder.find((pid) => Boolean(store.profiles[pid]));
|
||||||
Boolean(store.profiles[pid]),
|
|
||||||
);
|
|
||||||
let profileId = "opencode:default";
|
let profileId = "opencode:default";
|
||||||
let hasCredential = false;
|
let hasCredential = false;
|
||||||
|
|
||||||
@ -837,15 +745,8 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "opencode") {
|
||||||
!hasCredential &&
|
await setOpencodeZenApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir);
|
||||||
params.opts?.token &&
|
|
||||||
params.opts?.tokenProvider === "opencode"
|
|
||||||
) {
|
|
||||||
await setOpencodeZenApiKey(
|
|
||||||
normalizeApiKeyInput(params.opts.token),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
hasCredential = true;
|
hasCredential = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -877,10 +778,7 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
message: "Enter OpenCode Zen API key",
|
message: "Enter OpenCode Zen API key",
|
||||||
validate: validateApiKeyInput,
|
validate: validateApiKeyInput,
|
||||||
});
|
});
|
||||||
await setOpencodeZenApiKey(
|
await setOpencodeZenApiKey(normalizeApiKeyInput(String(key)), params.agentDir);
|
||||||
normalizeApiKeyInput(String(key)),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
hasCredential = true;
|
hasCredential = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,7 @@
|
|||||||
import { githubCopilotLoginCommand } from "../providers/github-copilot-auth.js";
|
import { githubCopilotLoginCommand } from "../providers/github-copilot-auth.js";
|
||||||
declare const process: any;
|
declare const process: any;
|
||||||
import type {
|
import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js";
|
||||||
ApplyAuthChoiceParams,
|
import { applyAuthProfileConfig, ensureAuthProfileStore } from "./onboard-auth.js";
|
||||||
ApplyAuthChoiceResult,
|
|
||||||
} from "./auth-choice.apply.js";
|
|
||||||
import {
|
|
||||||
applyAuthProfileConfig,
|
|
||||||
ensureAuthProfileStore,
|
|
||||||
} from "./onboard-auth.js";
|
|
||||||
|
|
||||||
export async function applyAuthChoiceGitHubCopilot(
|
export async function applyAuthChoiceGitHubCopilot(
|
||||||
params: ApplyAuthChoiceParams,
|
params: ApplyAuthChoiceParams,
|
||||||
@ -45,10 +39,7 @@ export async function applyAuthChoiceGitHubCopilot(
|
|||||||
try {
|
try {
|
||||||
await githubCopilotLoginCommand({ yes: true }, params.runtime);
|
await githubCopilotLoginCommand({ yes: true }, params.runtime);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await params.prompter.note(
|
await params.prompter.note(`GitHub Copilot login failed: ${String(err)}`, "GitHub Copilot");
|
||||||
`GitHub Copilot login failed: ${String(err)}`,
|
|
||||||
"GitHub Copilot",
|
|
||||||
);
|
|
||||||
return { config: nextConfig };
|
return { config: nextConfig };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,10 +53,7 @@ export async function applyAuthChoiceGitHubCopilot(
|
|||||||
try {
|
try {
|
||||||
await githubCopilotLoginCommand({ yes: true }, params.runtime);
|
await githubCopilotLoginCommand({ yes: true }, params.runtime);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await params.prompter.note(
|
await params.prompter.note(`GitHub Copilot login failed: ${String(err)}`, "GitHub Copilot");
|
||||||
`GitHub Copilot login failed: ${String(err)}`,
|
|
||||||
"GitHub Copilot",
|
|
||||||
);
|
|
||||||
return { config: nextConfig };
|
return { config: nextConfig };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,10 +81,7 @@ export async function applyAuthChoiceGitHubCopilot(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
await params.prompter.note(
|
await params.prompter.note(`Default model set to ${model}`, "Model configured");
|
||||||
`Default model set to ${model}`,
|
|
||||||
"Model configured",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { config: nextConfig };
|
return { config: nextConfig };
|
||||||
|
|||||||
@ -4,10 +4,7 @@ import {
|
|||||||
normalizeApiKeyInput,
|
normalizeApiKeyInput,
|
||||||
validateApiKeyInput,
|
validateApiKeyInput,
|
||||||
} from "./auth-choice.api-key.js";
|
} from "./auth-choice.api-key.js";
|
||||||
import type {
|
import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js";
|
||||||
ApplyAuthChoiceParams,
|
|
||||||
ApplyAuthChoiceResult,
|
|
||||||
} from "./auth-choice.apply.js";
|
|
||||||
import { applyDefaultModelChoice } from "./auth-choice.default-model.js";
|
import { applyDefaultModelChoice } from "./auth-choice.default-model.js";
|
||||||
import {
|
import {
|
||||||
applyAuthProfileConfig,
|
applyAuthProfileConfig,
|
||||||
@ -38,9 +35,7 @@ export async function applyAuthChoiceMiniMax(
|
|||||||
params.authChoice === "minimax-api-lightning"
|
params.authChoice === "minimax-api-lightning"
|
||||||
) {
|
) {
|
||||||
const modelId =
|
const modelId =
|
||||||
params.authChoice === "minimax-api-lightning"
|
params.authChoice === "minimax-api-lightning" ? "MiniMax-M2.1-lightning" : "MiniMax-M2.1";
|
||||||
? "MiniMax-M2.1-lightning"
|
|
||||||
: "MiniMax-M2.1";
|
|
||||||
let hasCredential = false;
|
let hasCredential = false;
|
||||||
|
|
||||||
const store = ensureAuthProfileStore(params.agentDir, {
|
const store = ensureAuthProfileStore(params.agentDir, {
|
||||||
@ -74,10 +69,7 @@ export async function applyAuthChoiceMiniMax(
|
|||||||
message: "Enter MiniMax API key",
|
message: "Enter MiniMax API key",
|
||||||
validate: validateApiKeyInput,
|
validate: validateApiKeyInput,
|
||||||
});
|
});
|
||||||
await setMinimaxApiKey(
|
await setMinimaxApiKey(normalizeApiKeyInput(String(key)), params.agentDir);
|
||||||
normalizeApiKeyInput(String(key)),
|
|
||||||
params.agentDir,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||||
profileId: "minimax:default",
|
profileId: "minimax:default",
|
||||||
@ -91,8 +83,7 @@ export async function applyAuthChoiceMiniMax(
|
|||||||
setDefaultModel: params.setDefaultModel,
|
setDefaultModel: params.setDefaultModel,
|
||||||
defaultModel: modelRef,
|
defaultModel: modelRef,
|
||||||
applyDefaultConfig: (config) => applyMinimaxApiConfig(config, modelId),
|
applyDefaultConfig: (config) => applyMinimaxApiConfig(config, modelId),
|
||||||
applyProviderConfig: (config) =>
|
applyProviderConfig: (config) => applyMinimaxApiProviderConfig(config, modelId),
|
||||||
applyMinimaxApiProviderConfig(config, modelId),
|
|
||||||
noteAgentModel,
|
noteAgentModel,
|
||||||
prompter: params.prompter,
|
prompter: params.prompter,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
import { isRemoteEnvironment } from "./oauth-env.js";
|
import { isRemoteEnvironment } from "./oauth-env.js";
|
||||||
declare const process: any;
|
declare const process: any;
|
||||||
import type {
|
import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js";
|
||||||
ApplyAuthChoiceParams,
|
|
||||||
ApplyAuthChoiceResult,
|
|
||||||
} from "./auth-choice.apply.js";
|
|
||||||
import { loginChutes } from "./chutes-oauth.js";
|
import { loginChutes } from "./chutes-oauth.js";
|
||||||
import { createVpsAwareOAuthHandlers } from "./oauth-flow.js";
|
import { createVpsAwareOAuthHandlers } from "./oauth-flow.js";
|
||||||
import {
|
import {
|
||||||
@ -20,10 +17,8 @@ export async function applyAuthChoiceOAuth(
|
|||||||
let nextConfig = params.config;
|
let nextConfig = params.config;
|
||||||
const isRemote = isRemoteEnvironment();
|
const isRemote = isRemoteEnvironment();
|
||||||
const redirectUri =
|
const redirectUri =
|
||||||
process.env.CHUTES_OAUTH_REDIRECT_URI?.trim() ||
|
process.env.CHUTES_OAUTH_REDIRECT_URI?.trim() || "http://127.0.0.1:1456/oauth-callback";
|
||||||
"http://127.0.0.1:1456/oauth-callback";
|
const scopes = process.env.CHUTES_OAUTH_SCOPES?.trim() || "openid profile chutes:invoke";
|
||||||
const scopes =
|
|
||||||
process.env.CHUTES_OAUTH_SCOPES?.trim() || "openid profile chutes:invoke";
|
|
||||||
const clientId =
|
const clientId =
|
||||||
process.env.CHUTES_CLIENT_ID?.trim() ||
|
process.env.CHUTES_CLIENT_ID?.trim() ||
|
||||||
String(
|
String(
|
||||||
@ -38,9 +33,7 @@ export async function applyAuthChoiceOAuth(
|
|||||||
const store = ensureAuthProfileStore(params.agentDir, {
|
const store = ensureAuthProfileStore(params.agentDir, {
|
||||||
allowKeychainPrompt: false,
|
allowKeychainPrompt: false,
|
||||||
});
|
});
|
||||||
const existingProfileId = Object.keys(store.profiles).find((id) =>
|
const existingProfileId = Object.keys(store.profiles).find((id) => id.startsWith("chutes:"));
|
||||||
id.startsWith("chutes:"),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (existingProfileId) {
|
if (existingProfileId) {
|
||||||
const existing = store.profiles[existingProfileId];
|
const existing = store.profiles[existingProfileId];
|
||||||
|
|||||||
@ -9,10 +9,7 @@ import {
|
|||||||
normalizeApiKeyInput,
|
normalizeApiKeyInput,
|
||||||
validateApiKeyInput,
|
validateApiKeyInput,
|
||||||
} from "./auth-choice.api-key.js";
|
} from "./auth-choice.api-key.js";
|
||||||
import type {
|
import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js";
|
||||||
ApplyAuthChoiceParams,
|
|
||||||
ApplyAuthChoiceResult,
|
|
||||||
} from "./auth-choice.apply.js";
|
|
||||||
import { createVpsAwareOAuthHandlers } from "./oauth-flow.js";
|
import { createVpsAwareOAuthHandlers } from "./oauth-flow.js";
|
||||||
import {
|
import {
|
||||||
applyAuthProfileConfig,
|
applyAuthProfileConfig,
|
||||||
|
|||||||
@ -11,14 +11,8 @@ import type { MoltbotConfig } from "../config/config.js";
|
|||||||
import { enablePluginInConfig } from "../plugins/enable.js";
|
import { enablePluginInConfig } from "../plugins/enable.js";
|
||||||
import { resolvePluginProviders } from "../plugins/providers.js";
|
import { resolvePluginProviders } from "../plugins/providers.js";
|
||||||
import type { ProviderAuthMethod, ProviderPlugin } from "../plugins/types.js";
|
import type { ProviderAuthMethod, ProviderPlugin } from "../plugins/types.js";
|
||||||
import type {
|
import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js";
|
||||||
ApplyAuthChoiceParams,
|
import { applyAuthProfileConfig, ensureAuthProfileStore } from "./onboard-auth.js";
|
||||||
ApplyAuthChoiceResult,
|
|
||||||
} from "./auth-choice.apply.js";
|
|
||||||
import {
|
|
||||||
applyAuthProfileConfig,
|
|
||||||
ensureAuthProfileStore,
|
|
||||||
} from "./onboard-auth.js";
|
|
||||||
import { openUrl } from "./onboard-helpers.js";
|
import { openUrl } from "./onboard-helpers.js";
|
||||||
import { createVpsAwareOAuthHandlers } from "./oauth-flow.js";
|
import { createVpsAwareOAuthHandlers } from "./oauth-flow.js";
|
||||||
import { isRemoteEnvironment } from "./oauth-env.js";
|
import { isRemoteEnvironment } from "./oauth-env.js";
|
||||||
@ -37,23 +31,16 @@ function resolveProviderMatch(
|
|||||||
): ProviderPlugin | null {
|
): ProviderPlugin | null {
|
||||||
const normalized = normalizeProviderId(rawProvider);
|
const normalized = normalizeProviderId(rawProvider);
|
||||||
return (
|
return (
|
||||||
providers.find(
|
providers.find((provider) => normalizeProviderId(provider.id) === normalized) ??
|
||||||
(provider) => normalizeProviderId(provider.id) === normalized,
|
|
||||||
) ??
|
|
||||||
providers.find(
|
providers.find(
|
||||||
(provider) =>
|
(provider) =>
|
||||||
provider.aliases?.some(
|
provider.aliases?.some((alias) => normalizeProviderId(alias) === normalized) ?? false,
|
||||||
(alias) => normalizeProviderId(alias) === normalized,
|
|
||||||
) ?? false,
|
|
||||||
) ??
|
) ??
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function pickAuthMethod(
|
function pickAuthMethod(provider: ProviderPlugin, rawMethod?: string): ProviderAuthMethod | null {
|
||||||
provider: ProviderPlugin,
|
|
||||||
rawMethod?: string,
|
|
||||||
): ProviderAuthMethod | null {
|
|
||||||
const raw = rawMethod?.trim();
|
const raw = rawMethod?.trim();
|
||||||
if (!raw) return null;
|
if (!raw) return null;
|
||||||
const normalized = raw.toLowerCase();
|
const normalized = raw.toLowerCase();
|
||||||
@ -98,12 +85,9 @@ function applyDefaultModel(cfg: MoltbotConfig, model: string): MoltbotConfig {
|
|||||||
...cfg.agents?.defaults,
|
...cfg.agents?.defaults,
|
||||||
models,
|
models,
|
||||||
model: {
|
model: {
|
||||||
...(existingModel &&
|
...(existingModel && typeof existingModel === "object" && "fallbacks" in existingModel
|
||||||
typeof existingModel === "object" &&
|
|
||||||
"fallbacks" in existingModel
|
|
||||||
? {
|
? {
|
||||||
fallbacks: (existingModel as { fallbacks?: string[] })
|
fallbacks: (existingModel as { fallbacks?: string[] }).fallbacks,
|
||||||
.fallbacks,
|
|
||||||
}
|
}
|
||||||
: undefined),
|
: undefined),
|
||||||
primary: model,
|
primary: model,
|
||||||
@ -134,12 +118,9 @@ export async function applyAuthChoicePluginProvider(
|
|||||||
const defaultAgentId = resolveDefaultAgentId(nextConfig);
|
const defaultAgentId = resolveDefaultAgentId(nextConfig);
|
||||||
const agentDir =
|
const agentDir =
|
||||||
params.agentDir ??
|
params.agentDir ??
|
||||||
(agentId === defaultAgentId
|
(agentId === defaultAgentId ? resolveMoltbotAgentDir() : resolveAgentDir(nextConfig, agentId));
|
||||||
? resolveMoltbotAgentDir()
|
|
||||||
: resolveAgentDir(nextConfig, agentId));
|
|
||||||
const workspaceDir =
|
const workspaceDir =
|
||||||
resolveAgentWorkspaceDir(nextConfig, agentId) ??
|
resolveAgentWorkspaceDir(nextConfig, agentId) ?? resolveDefaultAgentWorkspaceDir();
|
||||||
resolveDefaultAgentWorkspaceDir();
|
|
||||||
|
|
||||||
const providers = resolvePluginProviders({
|
const providers = resolvePluginProviders({
|
||||||
config: nextConfig,
|
config: nextConfig,
|
||||||
@ -156,10 +137,7 @@ export async function applyAuthChoicePluginProvider(
|
|||||||
|
|
||||||
const method = pickAuthMethod(provider, options.methodId) ?? provider.auth[0];
|
const method = pickAuthMethod(provider, options.methodId) ?? provider.auth[0];
|
||||||
if (!method) {
|
if (!method) {
|
||||||
await params.prompter.note(
|
await params.prompter.note(`${options.label} auth method missing.`, options.label);
|
||||||
`${options.label} auth method missing.`,
|
|
||||||
options.label,
|
|
||||||
);
|
|
||||||
return { config: nextConfig };
|
return { config: nextConfig };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,9 +145,7 @@ export async function applyAuthChoicePluginProvider(
|
|||||||
allowKeychainPrompt: false,
|
allowKeychainPrompt: false,
|
||||||
});
|
});
|
||||||
const existingProfiles = Object.entries(store.profiles).filter(
|
const existingProfiles = Object.entries(store.profiles).filter(
|
||||||
([, p]) =>
|
([, p]) => normalizeProviderId((p as any).provider) === normalizeProviderId(options.providerId),
|
||||||
normalizeProviderId((p as any).provider) ===
|
|
||||||
normalizeProviderId(options.providerId),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (existingProfiles.length > 0) {
|
if (existingProfiles.length > 0) {
|
||||||
@ -188,16 +164,11 @@ export async function applyAuthChoicePluginProvider(
|
|||||||
profileId,
|
profileId,
|
||||||
provider: profile.provider,
|
provider: profile.provider,
|
||||||
mode: (profile.type === "token" ? "token" : profile.type) as any,
|
mode: (profile.type === "token" ? "token" : profile.type) as any,
|
||||||
...("email" in profile && profile.email
|
...("email" in profile && profile.email ? { email: profile.email as string } : {}),
|
||||||
? { email: profile.email as string }
|
|
||||||
: {}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (params.setDefaultModel && provider.models?.models?.[0]?.id) {
|
if (params.setDefaultModel && provider.models?.models?.[0]?.id) {
|
||||||
nextConfig = applyDefaultModel(
|
nextConfig = applyDefaultModel(nextConfig, provider.models.models[0].id);
|
||||||
nextConfig,
|
|
||||||
provider.models.models[0].id,
|
|
||||||
);
|
|
||||||
} else if (params.agentId && provider.models?.models?.[0]?.id) {
|
} else if (params.agentId && provider.models?.models?.[0]?.id) {
|
||||||
agentModelOverride = provider.models.models[0].id;
|
agentModelOverride = provider.models.models[0].id;
|
||||||
}
|
}
|
||||||
@ -236,8 +207,7 @@ export async function applyAuthChoicePluginProvider(
|
|||||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||||
profileId: profile.profileId,
|
profileId: profile.profileId,
|
||||||
provider: profile.credential.provider,
|
provider: profile.credential.provider,
|
||||||
mode:
|
mode: profile.credential.type === "token" ? "token" : profile.credential.type,
|
||||||
profile.credential.type === "token" ? "token" : profile.credential.type,
|
|
||||||
...("email" in profile.credential && profile.credential.email
|
...("email" in profile.credential && profile.credential.email
|
||||||
? { email: profile.credential.email }
|
? { email: profile.credential.email }
|
||||||
: {}),
|
: {}),
|
||||||
@ -247,10 +217,7 @@ export async function applyAuthChoicePluginProvider(
|
|||||||
if (result.defaultModel) {
|
if (result.defaultModel) {
|
||||||
if (params.setDefaultModel) {
|
if (params.setDefaultModel) {
|
||||||
nextConfig = applyDefaultModel(nextConfig, result.defaultModel);
|
nextConfig = applyDefaultModel(nextConfig, result.defaultModel);
|
||||||
await params.prompter.note(
|
await params.prompter.note(`Default model set to ${result.defaultModel}`, "Model configured");
|
||||||
`Default model set to ${result.defaultModel}`,
|
|
||||||
"Model configured",
|
|
||||||
);
|
|
||||||
} else if (params.agentId) {
|
} else if (params.agentId) {
|
||||||
agentModelOverride = result.defaultModel;
|
agentModelOverride = result.defaultModel;
|
||||||
await params.prompter.note(
|
await params.prompter.note(
|
||||||
|
|||||||
@ -44,83 +44,77 @@ async function waitForLocalCallback(params: {
|
|||||||
}): Promise<{ code: string; state: string }> {
|
}): Promise<{ code: string; state: string }> {
|
||||||
const redirectUrl = new URL(params.redirectUri);
|
const redirectUrl = new URL(params.redirectUri);
|
||||||
if (redirectUrl.protocol !== "http:") {
|
if (redirectUrl.protocol !== "http:") {
|
||||||
throw new Error(
|
throw new Error(`Chutes OAuth redirect URI must be http:// (got ${params.redirectUri})`);
|
||||||
`Chutes OAuth redirect URI must be http:// (got ${params.redirectUri})`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
const hostname = redirectUrl.hostname || "127.0.0.1";
|
const hostname = redirectUrl.hostname || "127.0.0.1";
|
||||||
const port = redirectUrl.port ? Number.parseInt(redirectUrl.port, 10) : 80;
|
const port = redirectUrl.port ? Number.parseInt(redirectUrl.port, 10) : 80;
|
||||||
const expectedPath = redirectUrl.pathname || "/";
|
const expectedPath = redirectUrl.pathname || "/";
|
||||||
|
|
||||||
return await new Promise<{ code: string; state: string }>(
|
return await new Promise<{ code: string; state: string }>((resolve, reject) => {
|
||||||
(resolve, reject) => {
|
// @ts-ignore
|
||||||
// @ts-ignore
|
let timeout: NodeJS.Timeout | null = null;
|
||||||
let timeout: NodeJS.Timeout | null = null;
|
const server = createServer((req: any, res: any) => {
|
||||||
const server = createServer((req: any, res: any) => {
|
try {
|
||||||
try {
|
const requestUrl = new URL(req.url ?? "/", redirectUrl.origin);
|
||||||
const requestUrl = new URL(req.url ?? "/", redirectUrl.origin);
|
if (requestUrl.pathname !== expectedPath) {
|
||||||
if (requestUrl.pathname !== expectedPath) {
|
res.statusCode = 404;
|
||||||
res.statusCode = 404;
|
res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
||||||
res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
res.end("Not found");
|
||||||
res.end("Not found");
|
return;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
if (timeout) clearTimeout(timeout);
|
||||||
server.close();
|
server.close();
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
}
|
||||||
server.listen(port, hostname, () => {
|
});
|
||||||
params.onProgress?.(
|
|
||||||
`Waiting for OAuth callback on ${redirectUrl.origin}${expectedPath}…`,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
timeout = setTimeout(() => {
|
server.once("error", (err: any) => {
|
||||||
try {
|
if (timeout) clearTimeout(timeout);
|
||||||
server.close();
|
server.close();
|
||||||
} catch {}
|
reject(err);
|
||||||
reject(new Error("OAuth callback timeout"));
|
});
|
||||||
}, params.timeoutMs);
|
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: {
|
export async function loginChutes(params: {
|
||||||
@ -135,8 +129,7 @@ export async function loginChutes(params: {
|
|||||||
fetchFn?: typeof fetch;
|
fetchFn?: typeof fetch;
|
||||||
}): Promise<OAuthCredentials> {
|
}): Promise<OAuthCredentials> {
|
||||||
const createPkce = params.createPkce ?? generateChutesPkce;
|
const createPkce = params.createPkce ?? generateChutesPkce;
|
||||||
const createState =
|
const createState = params.createState ?? (() => randomBytes(16).toString("hex"));
|
||||||
params.createState ?? (() => randomBytes(16).toString("hex"));
|
|
||||||
|
|
||||||
const { verifier, challenge } = createPkce();
|
const { verifier, challenge } = createPkce();
|
||||||
const state = createState();
|
const state = createState();
|
||||||
|
|||||||
@ -3,10 +3,7 @@ export {
|
|||||||
SYNTHETIC_DEFAULT_MODEL_ID,
|
SYNTHETIC_DEFAULT_MODEL_ID,
|
||||||
SYNTHETIC_DEFAULT_MODEL_REF,
|
SYNTHETIC_DEFAULT_MODEL_REF,
|
||||||
} from "../agents/synthetic-models.js";
|
} from "../agents/synthetic-models.js";
|
||||||
export {
|
export { VENICE_DEFAULT_MODEL_ID, VENICE_DEFAULT_MODEL_REF } from "../agents/venice-models.js";
|
||||||
VENICE_DEFAULT_MODEL_ID,
|
|
||||||
VENICE_DEFAULT_MODEL_REF,
|
|
||||||
} from "../agents/venice-models.js";
|
|
||||||
export {
|
export {
|
||||||
applyAuthProfileConfig,
|
applyAuthProfileConfig,
|
||||||
applyKimiCodeConfig,
|
applyKimiCodeConfig,
|
||||||
|
|||||||
@ -1,10 +1,7 @@
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
declare const process: any;
|
declare const process: any;
|
||||||
import {
|
import { resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../../agents/agent-scope.js";
|
||||||
resolveAgentWorkspaceDir,
|
|
||||||
resolveDefaultAgentId,
|
|
||||||
} from "../../agents/agent-scope.js";
|
|
||||||
import type { ChannelPluginCatalogEntry } from "../../channels/plugins/catalog.js";
|
import type { ChannelPluginCatalogEntry } from "../../channels/plugins/catalog.js";
|
||||||
import type { MoltbotConfig } from "../../config/config.js";
|
import type { MoltbotConfig } from "../../config/config.js";
|
||||||
import { createSubsystemLogger } from "../../logging/subsystem.js";
|
import { createSubsystemLogger } from "../../logging/subsystem.js";
|
||||||
@ -53,10 +50,7 @@ function resolveLocalPath(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addPluginLoadPath(
|
function addPluginLoadPath(cfg: MoltbotConfig, pluginPath: string): MoltbotConfig {
|
||||||
cfg: MoltbotConfig,
|
|
||||||
pluginPath: string,
|
|
||||||
): MoltbotConfig {
|
|
||||||
const existing = cfg.plugins?.load?.paths ?? [];
|
const existing = cfg.plugins?.load?.paths ?? [];
|
||||||
const merged = Array.from(new Set([...existing, pluginPath]));
|
const merged = Array.from(new Set([...existing, pluginPath]));
|
||||||
return {
|
return {
|
||||||
@ -91,12 +85,11 @@ async function promptInstallChoice(params: {
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
: [];
|
: [];
|
||||||
const options: Array<{ value: InstallChoice; label: string; hint?: string }> =
|
const options: Array<{ value: InstallChoice; label: string; hint?: string }> = [
|
||||||
[
|
{ value: "npm", label: `Download from npm (${entry.install.npmSpec})` },
|
||||||
{ value: "npm", label: `Download from npm (${entry.install.npmSpec})` },
|
...localOptions,
|
||||||
...localOptions,
|
{ value: "skip", label: "Skip for now" },
|
||||||
{ value: "skip", label: "Skip for now" },
|
];
|
||||||
];
|
|
||||||
const initialValue: InstallChoice =
|
const initialValue: InstallChoice =
|
||||||
defaultChoice === "local" && !localPath ? "npm" : defaultChoice;
|
defaultChoice === "local" && !localPath ? "npm" : defaultChoice;
|
||||||
return await prompter.select<InstallChoice>({
|
return await prompter.select<InstallChoice>({
|
||||||
@ -205,8 +198,7 @@ export function reloadOnboardingPluginRegistry(params: {
|
|||||||
workspaceDir?: string;
|
workspaceDir?: string;
|
||||||
}): void {
|
}): void {
|
||||||
const workspaceDir =
|
const workspaceDir =
|
||||||
params.workspaceDir ??
|
params.workspaceDir ?? resolveAgentWorkspaceDir(params.cfg, resolveDefaultAgentId(params.cfg));
|
||||||
resolveAgentWorkspaceDir(params.cfg, resolveDefaultAgentId(params.cfg));
|
|
||||||
const log = createSubsystemLogger("plugins");
|
const log = createSubsystemLogger("plugins");
|
||||||
loadMoltbotPlugins({
|
loadMoltbotPlugins({
|
||||||
config: params.cfg,
|
config: params.cfg,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user