feat: add Moonshot auth choice
This commit is contained in:
@@ -14,6 +14,8 @@
|
|||||||
- Docs: explain MiniMax vs MiniMax Lightning (speed vs cost) and restore LM Studio example.
|
- Docs: explain MiniMax vs MiniMax Lightning (speed vs cost) and restore LM Studio example.
|
||||||
- Docs: add Cerebras GLM 4.6/4.7 config example (OpenAI-compatible endpoint).
|
- Docs: add Cerebras GLM 4.6/4.7 config example (OpenAI-compatible endpoint).
|
||||||
- Onboarding/CLI: group model/auth choice by provider and label Z.AI as GLM 4.7.
|
- Onboarding/CLI: group model/auth choice by provider and label Z.AI as GLM 4.7.
|
||||||
|
- Onboarding/Docs: add Moonshot AI (Kimi K2) auth choice + config example.
|
||||||
|
- CLI/Onboarding: prompt to reuse detected API keys for Moonshot/MiniMax/Z.AI/Gemini/Anthropic/OpenCode.
|
||||||
- Auto-reply: add compact `/model` picker (models + available providers) and show provider endpoints in `/model status`.
|
- Auto-reply: add compact `/model` picker (models + available providers) and show provider endpoints in `/model status`.
|
||||||
- Plugins: add extension loader (tools/RPC/CLI/services), discovery paths, and config schema + Control UI labels (uiHints).
|
- Plugins: add extension loader (tools/RPC/CLI/services), discovery paths, and config schema + Control UI labels (uiHints).
|
||||||
- Plugins: add `clawdbot plugins install` (path/tgz/npm), plus `list|info|enable|disable|doctor` UX.
|
- Plugins: add `clawdbot plugins install` (path/tgz/npm), plus `list|info|enable|disable|doctor` UX.
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ export function resolveEnvApiKey(provider: string): EnvApiKeyResult | null {
|
|||||||
cerebras: "CEREBRAS_API_KEY",
|
cerebras: "CEREBRAS_API_KEY",
|
||||||
xai: "XAI_API_KEY",
|
xai: "XAI_API_KEY",
|
||||||
openrouter: "OPENROUTER_API_KEY",
|
openrouter: "OPENROUTER_API_KEY",
|
||||||
|
moonshot: "MOONSHOT_API_KEY",
|
||||||
minimax: "MINIMAX_API_KEY",
|
minimax: "MINIMAX_API_KEY",
|
||||||
mistral: "MISTRAL_API_KEY",
|
mistral: "MISTRAL_API_KEY",
|
||||||
opencode: "OPENCODE_API_KEY",
|
opencode: "OPENCODE_API_KEY",
|
||||||
|
|||||||
@@ -179,6 +179,29 @@ describe("cli program", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("passes moonshot api key to onboard", async () => {
|
||||||
|
const program = buildProgram();
|
||||||
|
await program.parseAsync(
|
||||||
|
[
|
||||||
|
"onboard",
|
||||||
|
"--non-interactive",
|
||||||
|
"--auth-choice",
|
||||||
|
"moonshot-api-key",
|
||||||
|
"--moonshot-api-key",
|
||||||
|
"sk-moonshot-test",
|
||||||
|
],
|
||||||
|
{ from: "user" },
|
||||||
|
);
|
||||||
|
expect(onboardCommand).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
nonInteractive: true,
|
||||||
|
authChoice: "moonshot-api-key",
|
||||||
|
moonshotApiKey: "sk-moonshot-test",
|
||||||
|
}),
|
||||||
|
runtime,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("passes zai api key to onboard", async () => {
|
it("passes zai api key to onboard", async () => {
|
||||||
const program = buildProgram();
|
const program = buildProgram();
|
||||||
await program.parseAsync(
|
await program.parseAsync(
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ export function buildProgram() {
|
|||||||
.option("--mode <mode>", "Wizard mode: local|remote")
|
.option("--mode <mode>", "Wizard mode: local|remote")
|
||||||
.option(
|
.option(
|
||||||
"--auth-choice <choice>",
|
"--auth-choice <choice>",
|
||||||
"Auth: setup-token|claude-cli|token|openai-codex|openai-api-key|openrouter-api-key|codex-cli|antigravity|gemini-api-key|zai-api-key|apiKey|minimax-api|opencode-zen|skip",
|
"Auth: setup-token|claude-cli|token|openai-codex|openai-api-key|openrouter-api-key|moonshot-api-key|codex-cli|antigravity|gemini-api-key|zai-api-key|apiKey|minimax-api|opencode-zen|skip",
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
"--token-provider <id>",
|
"--token-provider <id>",
|
||||||
@@ -283,6 +283,7 @@ export function buildProgram() {
|
|||||||
.option("--anthropic-api-key <key>", "Anthropic API key")
|
.option("--anthropic-api-key <key>", "Anthropic API key")
|
||||||
.option("--openai-api-key <key>", "OpenAI API key")
|
.option("--openai-api-key <key>", "OpenAI API key")
|
||||||
.option("--openrouter-api-key <key>", "OpenRouter API key")
|
.option("--openrouter-api-key <key>", "OpenRouter API key")
|
||||||
|
.option("--moonshot-api-key <key>", "Moonshot API key")
|
||||||
.option("--gemini-api-key <key>", "Gemini API key")
|
.option("--gemini-api-key <key>", "Gemini API key")
|
||||||
.option("--zai-api-key <key>", "Z.AI API key")
|
.option("--zai-api-key <key>", "Z.AI API key")
|
||||||
.option("--minimax-api-key <key>", "MiniMax API key")
|
.option("--minimax-api-key <key>", "MiniMax API key")
|
||||||
@@ -330,6 +331,7 @@ export function buildProgram() {
|
|||||||
| "openai-codex"
|
| "openai-codex"
|
||||||
| "openai-api-key"
|
| "openai-api-key"
|
||||||
| "openrouter-api-key"
|
| "openrouter-api-key"
|
||||||
|
| "moonshot-api-key"
|
||||||
| "codex-cli"
|
| "codex-cli"
|
||||||
| "antigravity"
|
| "antigravity"
|
||||||
| "gemini-api-key"
|
| "gemini-api-key"
|
||||||
@@ -348,6 +350,7 @@ export function buildProgram() {
|
|||||||
anthropicApiKey: opts.anthropicApiKey as string | undefined,
|
anthropicApiKey: opts.anthropicApiKey as string | undefined,
|
||||||
openaiApiKey: opts.openaiApiKey as string | undefined,
|
openaiApiKey: opts.openaiApiKey as string | undefined,
|
||||||
openrouterApiKey: opts.openrouterApiKey as string | undefined,
|
openrouterApiKey: opts.openrouterApiKey as string | undefined,
|
||||||
|
moonshotApiKey: opts.moonshotApiKey as string | undefined,
|
||||||
geminiApiKey: opts.geminiApiKey as string | undefined,
|
geminiApiKey: opts.geminiApiKey as string | undefined,
|
||||||
zaiApiKey: opts.zaiApiKey as string | undefined,
|
zaiApiKey: opts.zaiApiKey as string | undefined,
|
||||||
minimaxApiKey: opts.minimaxApiKey as string | undefined,
|
minimaxApiKey: opts.minimaxApiKey as string | undefined,
|
||||||
|
|||||||
@@ -80,4 +80,16 @@ describe("buildAuthChoiceOptions", () => {
|
|||||||
|
|
||||||
expect(options.some((opt) => opt.value === "minimax-api")).toBe(true);
|
expect(options.some((opt) => opt.value === "minimax-api")).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("includes Moonshot auth choice", () => {
|
||||||
|
const store: AuthProfileStore = { version: 1, profiles: {} };
|
||||||
|
const options = buildAuthChoiceOptions({
|
||||||
|
store,
|
||||||
|
includeSkip: false,
|
||||||
|
includeClaudeCliIfMissing: true,
|
||||||
|
platform: "darwin",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(options.some((opt) => opt.value === "moonshot-api-key")).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export type AuthChoiceGroupId =
|
|||||||
| "anthropic"
|
| "anthropic"
|
||||||
| "google"
|
| "google"
|
||||||
| "openrouter"
|
| "openrouter"
|
||||||
|
| "moonshot"
|
||||||
| "zai"
|
| "zai"
|
||||||
| "opencode-zen"
|
| "opencode-zen"
|
||||||
| "minimax";
|
| "minimax";
|
||||||
@@ -58,6 +59,12 @@ const AUTH_CHOICE_GROUP_DEFS: {
|
|||||||
hint: "API key",
|
hint: "API key",
|
||||||
choices: ["openrouter-api-key"],
|
choices: ["openrouter-api-key"],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
value: "moonshot",
|
||||||
|
label: "Moonshot AI",
|
||||||
|
hint: "Kimi K2 preview",
|
||||||
|
choices: ["moonshot-api-key"],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
value: "zai",
|
value: "zai",
|
||||||
label: "Z.AI (GLM 4.7)",
|
label: "Z.AI (GLM 4.7)",
|
||||||
@@ -159,6 +166,7 @@ export function buildAuthChoiceOptions(params: {
|
|||||||
});
|
});
|
||||||
options.push({ value: "openai-api-key", label: "OpenAI API key" });
|
options.push({ value: "openai-api-key", label: "OpenAI API key" });
|
||||||
options.push({ value: "openrouter-api-key", label: "OpenRouter API key" });
|
options.push({ value: "openrouter-api-key", label: "OpenRouter API key" });
|
||||||
|
options.push({ value: "moonshot-api-key", label: "Moonshot AI API key" });
|
||||||
options.push({
|
options.push({
|
||||||
value: "antigravity",
|
value: "antigravity",
|
||||||
label: "Google Antigravity (Claude Opus 4.5, Gemini 3, etc.)",
|
label: "Google Antigravity (Claude Opus 4.5, Gemini 3, etc.)",
|
||||||
|
|||||||
@@ -41,15 +41,19 @@ import {
|
|||||||
applyMinimaxApiProviderConfig,
|
applyMinimaxApiProviderConfig,
|
||||||
applyMinimaxConfig,
|
applyMinimaxConfig,
|
||||||
applyMinimaxProviderConfig,
|
applyMinimaxProviderConfig,
|
||||||
|
applyMoonshotConfig,
|
||||||
|
applyMoonshotProviderConfig,
|
||||||
applyOpencodeZenConfig,
|
applyOpencodeZenConfig,
|
||||||
applyOpencodeZenProviderConfig,
|
applyOpencodeZenProviderConfig,
|
||||||
applyOpenrouterConfig,
|
applyOpenrouterConfig,
|
||||||
applyOpenrouterProviderConfig,
|
applyOpenrouterProviderConfig,
|
||||||
applyZaiConfig,
|
applyZaiConfig,
|
||||||
|
MOONSHOT_DEFAULT_MODEL_REF,
|
||||||
OPENROUTER_DEFAULT_MODEL_REF,
|
OPENROUTER_DEFAULT_MODEL_REF,
|
||||||
setAnthropicApiKey,
|
setAnthropicApiKey,
|
||||||
setGeminiApiKey,
|
setGeminiApiKey,
|
||||||
setMinimaxApiKey,
|
setMinimaxApiKey,
|
||||||
|
setMoonshotApiKey,
|
||||||
setOpencodeZenApiKey,
|
setOpencodeZenApiKey,
|
||||||
setOpenrouterApiKey,
|
setOpenrouterApiKey,
|
||||||
setZaiApiKey,
|
setZaiApiKey,
|
||||||
@@ -439,6 +443,38 @@ export async function applyAuthChoice(params: {
|
|||||||
agentModelOverride = OPENROUTER_DEFAULT_MODEL_REF;
|
agentModelOverride = OPENROUTER_DEFAULT_MODEL_REF;
|
||||||
await noteAgentModel(OPENROUTER_DEFAULT_MODEL_REF);
|
await noteAgentModel(OPENROUTER_DEFAULT_MODEL_REF);
|
||||||
}
|
}
|
||||||
|
} else if (params.authChoice === "moonshot-api-key") {
|
||||||
|
let hasCredential = false;
|
||||||
|
const envKey = resolveEnvApiKey("moonshot");
|
||||||
|
if (envKey) {
|
||||||
|
const useExisting = await params.prompter.confirm({
|
||||||
|
message: `Use existing MOONSHOT_API_KEY (${envKey.source})?`,
|
||||||
|
initialValue: true,
|
||||||
|
});
|
||||||
|
if (useExisting) {
|
||||||
|
await setMoonshotApiKey(envKey.apiKey, params.agentDir);
|
||||||
|
hasCredential = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasCredential) {
|
||||||
|
const key = await params.prompter.text({
|
||||||
|
message: "Enter Moonshot API key",
|
||||||
|
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||||
|
});
|
||||||
|
await setMoonshotApiKey(String(key).trim(), params.agentDir);
|
||||||
|
}
|
||||||
|
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||||
|
profileId: "moonshot:default",
|
||||||
|
provider: "moonshot",
|
||||||
|
mode: "api_key",
|
||||||
|
});
|
||||||
|
if (params.setDefaultModel) {
|
||||||
|
nextConfig = applyMoonshotConfig(nextConfig);
|
||||||
|
} else {
|
||||||
|
nextConfig = applyMoonshotProviderConfig(nextConfig);
|
||||||
|
agentModelOverride = MOONSHOT_DEFAULT_MODEL_REF;
|
||||||
|
await noteAgentModel(MOONSHOT_DEFAULT_MODEL_REF);
|
||||||
|
}
|
||||||
} else if (params.authChoice === "openai-codex") {
|
} else if (params.authChoice === "openai-codex") {
|
||||||
const isRemote = isRemoteEnvironment();
|
const isRemote = isRemoteEnvironment();
|
||||||
await params.prompter.note(
|
await params.prompter.note(
|
||||||
@@ -651,11 +687,25 @@ export async function applyAuthChoice(params: {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (params.authChoice === "gemini-api-key") {
|
} else if (params.authChoice === "gemini-api-key") {
|
||||||
const key = await params.prompter.text({
|
let hasCredential = false;
|
||||||
message: "Enter Gemini API key",
|
const envKey = resolveEnvApiKey("google");
|
||||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
if (envKey) {
|
||||||
});
|
const useExisting = await params.prompter.confirm({
|
||||||
await setGeminiApiKey(String(key).trim(), params.agentDir);
|
message: `Use existing GEMINI_API_KEY (${envKey.source})?`,
|
||||||
|
initialValue: true,
|
||||||
|
});
|
||||||
|
if (useExisting) {
|
||||||
|
await setGeminiApiKey(envKey.apiKey, params.agentDir);
|
||||||
|
hasCredential = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasCredential) {
|
||||||
|
const key = await params.prompter.text({
|
||||||
|
message: "Enter Gemini API key",
|
||||||
|
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||||
|
});
|
||||||
|
await setGeminiApiKey(String(key).trim(), params.agentDir);
|
||||||
|
}
|
||||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||||
profileId: "google:default",
|
profileId: "google:default",
|
||||||
provider: "google",
|
provider: "google",
|
||||||
@@ -675,11 +725,25 @@ export async function applyAuthChoice(params: {
|
|||||||
await noteAgentModel(GOOGLE_GEMINI_DEFAULT_MODEL);
|
await noteAgentModel(GOOGLE_GEMINI_DEFAULT_MODEL);
|
||||||
}
|
}
|
||||||
} else if (params.authChoice === "zai-api-key") {
|
} else if (params.authChoice === "zai-api-key") {
|
||||||
const key = await params.prompter.text({
|
let hasCredential = false;
|
||||||
message: "Enter Z.AI API key",
|
const envKey = resolveEnvApiKey("zai");
|
||||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
if (envKey) {
|
||||||
});
|
const useExisting = await params.prompter.confirm({
|
||||||
await setZaiApiKey(String(key).trim(), params.agentDir);
|
message: `Use existing ZAI_API_KEY (${envKey.source})?`,
|
||||||
|
initialValue: true,
|
||||||
|
});
|
||||||
|
if (useExisting) {
|
||||||
|
await setZaiApiKey(envKey.apiKey, params.agentDir);
|
||||||
|
hasCredential = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasCredential) {
|
||||||
|
const key = await params.prompter.text({
|
||||||
|
message: "Enter Z.AI API key",
|
||||||
|
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||||
|
});
|
||||||
|
await setZaiApiKey(String(key).trim(), params.agentDir);
|
||||||
|
}
|
||||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||||
profileId: "zai:default",
|
profileId: "zai:default",
|
||||||
provider: "zai",
|
provider: "zai",
|
||||||
@@ -714,11 +778,25 @@ export async function applyAuthChoice(params: {
|
|||||||
await noteAgentModel(ZAI_DEFAULT_MODEL_REF);
|
await noteAgentModel(ZAI_DEFAULT_MODEL_REF);
|
||||||
}
|
}
|
||||||
} else if (params.authChoice === "apiKey") {
|
} else if (params.authChoice === "apiKey") {
|
||||||
const key = await params.prompter.text({
|
let hasCredential = false;
|
||||||
message: "Enter Anthropic API key",
|
const envKey = process.env.ANTHROPIC_API_KEY?.trim();
|
||||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
if (envKey) {
|
||||||
});
|
const useExisting = await params.prompter.confirm({
|
||||||
await setAnthropicApiKey(String(key).trim(), params.agentDir);
|
message: "Use existing ANTHROPIC_API_KEY (env)?",
|
||||||
|
initialValue: true,
|
||||||
|
});
|
||||||
|
if (useExisting) {
|
||||||
|
await setAnthropicApiKey(envKey, params.agentDir);
|
||||||
|
hasCredential = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasCredential) {
|
||||||
|
const key = await params.prompter.text({
|
||||||
|
message: "Enter Anthropic API key",
|
||||||
|
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||||
|
});
|
||||||
|
await setAnthropicApiKey(String(key).trim(), params.agentDir);
|
||||||
|
}
|
||||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||||
profileId: "anthropic:default",
|
profileId: "anthropic:default",
|
||||||
provider: "anthropic",
|
provider: "anthropic",
|
||||||
@@ -729,11 +807,25 @@ export async function applyAuthChoice(params: {
|
|||||||
params.authChoice === "minimax-api"
|
params.authChoice === "minimax-api"
|
||||||
) {
|
) {
|
||||||
const modelId = "MiniMax-M2.1";
|
const modelId = "MiniMax-M2.1";
|
||||||
const key = await params.prompter.text({
|
let hasCredential = false;
|
||||||
message: "Enter MiniMax API key",
|
const envKey = resolveEnvApiKey("minimax");
|
||||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
if (envKey) {
|
||||||
});
|
const useExisting = await params.prompter.confirm({
|
||||||
await setMinimaxApiKey(String(key).trim(), params.agentDir);
|
message: `Use existing MINIMAX_API_KEY (${envKey.source})?`,
|
||||||
|
initialValue: true,
|
||||||
|
});
|
||||||
|
if (useExisting) {
|
||||||
|
await setMinimaxApiKey(envKey.apiKey, params.agentDir);
|
||||||
|
hasCredential = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasCredential) {
|
||||||
|
const key = await params.prompter.text({
|
||||||
|
message: "Enter MiniMax API key",
|
||||||
|
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||||
|
});
|
||||||
|
await setMinimaxApiKey(String(key).trim(), params.agentDir);
|
||||||
|
}
|
||||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||||
profileId: "minimax:default",
|
profileId: "minimax:default",
|
||||||
provider: "minimax",
|
provider: "minimax",
|
||||||
@@ -764,11 +856,25 @@ export async function applyAuthChoice(params: {
|
|||||||
].join("\n"),
|
].join("\n"),
|
||||||
"OpenCode Zen",
|
"OpenCode Zen",
|
||||||
);
|
);
|
||||||
const key = await params.prompter.text({
|
let hasCredential = false;
|
||||||
message: "Enter OpenCode Zen API key",
|
const envKey = resolveEnvApiKey("opencode");
|
||||||
validate: (value) => (value?.trim() ? undefined : "Required"),
|
if (envKey) {
|
||||||
});
|
const useExisting = await params.prompter.confirm({
|
||||||
await setOpencodeZenApiKey(String(key).trim(), params.agentDir);
|
message: `Use existing OPENCODE_API_KEY (${envKey.source})?`,
|
||||||
|
initialValue: true,
|
||||||
|
});
|
||||||
|
if (useExisting) {
|
||||||
|
await setOpencodeZenApiKey(envKey.apiKey, params.agentDir);
|
||||||
|
hasCredential = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!hasCredential) {
|
||||||
|
const key = await params.prompter.text({
|
||||||
|
message: "Enter OpenCode Zen API key",
|
||||||
|
validate: (value) => (value?.trim() ? undefined : "Required"),
|
||||||
|
});
|
||||||
|
await setOpencodeZenApiKey(String(key).trim(), params.agentDir);
|
||||||
|
}
|
||||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||||
profileId: "opencode:default",
|
profileId: "opencode:default",
|
||||||
provider: "opencode",
|
provider: "opencode",
|
||||||
@@ -807,6 +913,8 @@ export function resolvePreferredProviderForAuthChoice(
|
|||||||
return "openai";
|
return "openai";
|
||||||
case "openrouter-api-key":
|
case "openrouter-api-key":
|
||||||
return "openrouter";
|
return "openrouter";
|
||||||
|
case "moonshot-api-key":
|
||||||
|
return "moonshot";
|
||||||
case "gemini-api-key":
|
case "gemini-api-key":
|
||||||
return "google";
|
return "google";
|
||||||
case "zai-api-key":
|
case "zai-api-key":
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ export const MINIMAX_HOSTED_MODEL_ID = "MiniMax-M2.1";
|
|||||||
const DEFAULT_MINIMAX_CONTEXT_WINDOW = 200000;
|
const DEFAULT_MINIMAX_CONTEXT_WINDOW = 200000;
|
||||||
const DEFAULT_MINIMAX_MAX_TOKENS = 8192;
|
const DEFAULT_MINIMAX_MAX_TOKENS = 8192;
|
||||||
export const MINIMAX_HOSTED_MODEL_REF = `minimax/${MINIMAX_HOSTED_MODEL_ID}`;
|
export const MINIMAX_HOSTED_MODEL_REF = `minimax/${MINIMAX_HOSTED_MODEL_ID}`;
|
||||||
|
const MOONSHOT_BASE_URL = "https://api.moonshot.ai/v1";
|
||||||
|
export const MOONSHOT_DEFAULT_MODEL_ID = "kimi-k2-0905-preview";
|
||||||
|
const MOONSHOT_DEFAULT_CONTEXT_WINDOW = 256000;
|
||||||
|
const MOONSHOT_DEFAULT_MAX_TOKENS = 8192;
|
||||||
|
export const MOONSHOT_DEFAULT_MODEL_REF = `moonshot/${MOONSHOT_DEFAULT_MODEL_ID}`;
|
||||||
// Pricing: MiniMax doesn't publish public rates. Override in models.json for accurate costs.
|
// Pricing: MiniMax doesn't publish public rates. Override in models.json for accurate costs.
|
||||||
const MINIMAX_API_COST = {
|
const MINIMAX_API_COST = {
|
||||||
input: 15,
|
input: 15,
|
||||||
@@ -30,6 +35,12 @@ const MINIMAX_LM_STUDIO_COST = {
|
|||||||
cacheRead: 0,
|
cacheRead: 0,
|
||||||
cacheWrite: 0,
|
cacheWrite: 0,
|
||||||
};
|
};
|
||||||
|
const MOONSHOT_DEFAULT_COST = {
|
||||||
|
input: 0,
|
||||||
|
output: 0,
|
||||||
|
cacheRead: 0,
|
||||||
|
cacheWrite: 0,
|
||||||
|
};
|
||||||
|
|
||||||
const MINIMAX_MODEL_CATALOG = {
|
const MINIMAX_MODEL_CATALOG = {
|
||||||
"MiniMax-M2.1": { name: "MiniMax M2.1", reasoning: false },
|
"MiniMax-M2.1": { name: "MiniMax M2.1", reasoning: false },
|
||||||
@@ -74,6 +85,18 @@ function buildMinimaxApiModelDefinition(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildMoonshotModelDefinition(): ModelDefinitionConfig {
|
||||||
|
return {
|
||||||
|
id: MOONSHOT_DEFAULT_MODEL_ID,
|
||||||
|
name: "Kimi K2 0905 Preview",
|
||||||
|
reasoning: false,
|
||||||
|
input: ["text"],
|
||||||
|
cost: MOONSHOT_DEFAULT_COST,
|
||||||
|
contextWindow: MOONSHOT_DEFAULT_CONTEXT_WINDOW,
|
||||||
|
maxTokens: MOONSHOT_DEFAULT_MAX_TOKENS,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export async function writeOAuthCredentials(
|
export async function writeOAuthCredentials(
|
||||||
provider: OAuthProvider,
|
provider: OAuthProvider,
|
||||||
creds: OAuthCredentials,
|
creds: OAuthCredentials,
|
||||||
@@ -130,6 +153,19 @@ export async function setMinimaxApiKey(key: string, agentDir?: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function setMoonshotApiKey(key: string, agentDir?: string) {
|
||||||
|
// Write to the multi-agent path so gateway finds credentials on startup
|
||||||
|
upsertAuthProfile({
|
||||||
|
profileId: "moonshot:default",
|
||||||
|
credential: {
|
||||||
|
type: "api_key",
|
||||||
|
provider: "moonshot",
|
||||||
|
key,
|
||||||
|
},
|
||||||
|
agentDir: agentDir ?? resolveDefaultAgentDir(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export const ZAI_DEFAULT_MODEL_REF = "zai/glm-4.7";
|
export const ZAI_DEFAULT_MODEL_REF = "zai/glm-4.7";
|
||||||
export const OPENROUTER_DEFAULT_MODEL_REF = "openrouter/auto";
|
export const OPENROUTER_DEFAULT_MODEL_REF = "openrouter/auto";
|
||||||
|
|
||||||
@@ -233,6 +269,80 @@ export function applyOpenrouterConfig(cfg: ClawdbotConfig): ClawdbotConfig {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function applyMoonshotProviderConfig(
|
||||||
|
cfg: ClawdbotConfig,
|
||||||
|
): ClawdbotConfig {
|
||||||
|
const models = { ...cfg.agents?.defaults?.models };
|
||||||
|
models[MOONSHOT_DEFAULT_MODEL_REF] = {
|
||||||
|
...models[MOONSHOT_DEFAULT_MODEL_REF],
|
||||||
|
alias: models[MOONSHOT_DEFAULT_MODEL_REF]?.alias ?? "Kimi K2",
|
||||||
|
};
|
||||||
|
|
||||||
|
const providers = { ...cfg.models?.providers };
|
||||||
|
const existingProvider = providers.moonshot;
|
||||||
|
const existingModels = Array.isArray(existingProvider?.models)
|
||||||
|
? existingProvider.models
|
||||||
|
: [];
|
||||||
|
const defaultModel = buildMoonshotModelDefinition();
|
||||||
|
const hasDefaultModel = existingModels.some(
|
||||||
|
(model) => model.id === MOONSHOT_DEFAULT_MODEL_ID,
|
||||||
|
);
|
||||||
|
const mergedModels = hasDefaultModel
|
||||||
|
? existingModels
|
||||||
|
: [...existingModels, defaultModel];
|
||||||
|
const { apiKey: existingApiKey, ...existingProviderRest } =
|
||||||
|
(existingProvider ?? {}) as Record<string, unknown> as { apiKey?: string };
|
||||||
|
const resolvedApiKey =
|
||||||
|
typeof existingApiKey === "string" ? existingApiKey : undefined;
|
||||||
|
const normalizedApiKey = resolvedApiKey?.trim();
|
||||||
|
providers.moonshot = {
|
||||||
|
...existingProviderRest,
|
||||||
|
baseUrl: MOONSHOT_BASE_URL,
|
||||||
|
api: "openai-completions",
|
||||||
|
...(normalizedApiKey ? { apiKey: normalizedApiKey } : {}),
|
||||||
|
models: mergedModels.length > 0 ? mergedModels : [defaultModel],
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...cfg,
|
||||||
|
agents: {
|
||||||
|
...cfg.agents,
|
||||||
|
defaults: {
|
||||||
|
...cfg.agents?.defaults,
|
||||||
|
models,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
models: {
|
||||||
|
mode: cfg.models?.mode ?? "merge",
|
||||||
|
providers,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function applyMoonshotConfig(cfg: ClawdbotConfig): ClawdbotConfig {
|
||||||
|
const next = applyMoonshotProviderConfig(cfg);
|
||||||
|
const existingModel = next.agents?.defaults?.model;
|
||||||
|
return {
|
||||||
|
...next,
|
||||||
|
agents: {
|
||||||
|
...next.agents,
|
||||||
|
defaults: {
|
||||||
|
...next.agents?.defaults,
|
||||||
|
model: {
|
||||||
|
...(existingModel &&
|
||||||
|
"fallbacks" in (existingModel as Record<string, unknown>)
|
||||||
|
? {
|
||||||
|
fallbacks: (existingModel as { fallbacks?: string[] })
|
||||||
|
.fallbacks,
|
||||||
|
}
|
||||||
|
: undefined),
|
||||||
|
primary: MOONSHOT_DEFAULT_MODEL_REF,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function applyAuthProfileConfig(
|
export function applyAuthProfileConfig(
|
||||||
cfg: ClawdbotConfig,
|
cfg: ClawdbotConfig,
|
||||||
params: {
|
params: {
|
||||||
|
|||||||
@@ -34,12 +34,14 @@ import {
|
|||||||
applyAuthProfileConfig,
|
applyAuthProfileConfig,
|
||||||
applyMinimaxApiConfig,
|
applyMinimaxApiConfig,
|
||||||
applyMinimaxConfig,
|
applyMinimaxConfig,
|
||||||
|
applyMoonshotConfig,
|
||||||
applyOpencodeZenConfig,
|
applyOpencodeZenConfig,
|
||||||
applyOpenrouterConfig,
|
applyOpenrouterConfig,
|
||||||
applyZaiConfig,
|
applyZaiConfig,
|
||||||
setAnthropicApiKey,
|
setAnthropicApiKey,
|
||||||
setGeminiApiKey,
|
setGeminiApiKey,
|
||||||
setMinimaxApiKey,
|
setMinimaxApiKey,
|
||||||
|
setMoonshotApiKey,
|
||||||
setOpencodeZenApiKey,
|
setOpencodeZenApiKey,
|
||||||
setOpenrouterApiKey,
|
setOpenrouterApiKey,
|
||||||
setZaiApiKey,
|
setZaiApiKey,
|
||||||
@@ -284,6 +286,25 @@ export async function runNonInteractiveOnboarding(
|
|||||||
mode: "api_key",
|
mode: "api_key",
|
||||||
});
|
});
|
||||||
nextConfig = applyOpenrouterConfig(nextConfig);
|
nextConfig = applyOpenrouterConfig(nextConfig);
|
||||||
|
} else if (authChoice === "moonshot-api-key") {
|
||||||
|
const resolved = await resolveNonInteractiveApiKey({
|
||||||
|
provider: "moonshot",
|
||||||
|
cfg: baseConfig,
|
||||||
|
flagValue: opts.moonshotApiKey,
|
||||||
|
flagName: "--moonshot-api-key",
|
||||||
|
envVar: "MOONSHOT_API_KEY",
|
||||||
|
runtime,
|
||||||
|
});
|
||||||
|
if (!resolved) return;
|
||||||
|
if (resolved.source !== "profile") {
|
||||||
|
await setMoonshotApiKey(resolved.key);
|
||||||
|
}
|
||||||
|
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||||
|
profileId: "moonshot:default",
|
||||||
|
provider: "moonshot",
|
||||||
|
mode: "api_key",
|
||||||
|
});
|
||||||
|
nextConfig = applyMoonshotConfig(nextConfig);
|
||||||
} else if (authChoice === "minimax-cloud" || authChoice === "minimax-api") {
|
} else if (authChoice === "minimax-cloud" || authChoice === "minimax-api") {
|
||||||
const resolved = await resolveNonInteractiveApiKey({
|
const resolved = await resolveNonInteractiveApiKey({
|
||||||
provider: "minimax",
|
provider: "minimax",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export type AuthChoice =
|
|||||||
| "openai-codex"
|
| "openai-codex"
|
||||||
| "openai-api-key"
|
| "openai-api-key"
|
||||||
| "openrouter-api-key"
|
| "openrouter-api-key"
|
||||||
|
| "moonshot-api-key"
|
||||||
| "codex-cli"
|
| "codex-cli"
|
||||||
| "antigravity"
|
| "antigravity"
|
||||||
| "apiKey"
|
| "apiKey"
|
||||||
@@ -46,6 +47,7 @@ export type OnboardOptions = {
|
|||||||
anthropicApiKey?: string;
|
anthropicApiKey?: string;
|
||||||
openaiApiKey?: string;
|
openaiApiKey?: string;
|
||||||
openrouterApiKey?: string;
|
openrouterApiKey?: string;
|
||||||
|
moonshotApiKey?: string;
|
||||||
geminiApiKey?: string;
|
geminiApiKey?: string;
|
||||||
zaiApiKey?: string;
|
zaiApiKey?: string;
|
||||||
minimaxApiKey?: string;
|
minimaxApiKey?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user