mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 08:51:23 +00:00
feat: add MiniMax OAuth plugin (#4521) (thanks @Maosghoul)
This commit is contained in:
@@ -52,7 +52,7 @@ const AUTH_CHOICE_GROUP_DEFS: {
|
||||
value: "minimax",
|
||||
label: "MiniMax",
|
||||
hint: "M2.1 (recommended)",
|
||||
choices: ["minimax-api", "minimax-api-lightning"],
|
||||
choices: ["minimax-portal", "minimax-api", "minimax-api-lightning"],
|
||||
},
|
||||
{
|
||||
value: "moonshot",
|
||||
@@ -175,6 +175,11 @@ export function buildAuthChoiceOptions(params: {
|
||||
value: "xiaomi-api-key",
|
||||
label: "Xiaomi API key",
|
||||
});
|
||||
options.push({
|
||||
value: "minimax-portal",
|
||||
label: "MiniMax OAuth",
|
||||
hint: "OAuth new users enjoy a 3-day free trial of the MiniMax Coding Plan!",
|
||||
});
|
||||
options.push({ value: "qwen-portal", label: "Qwen OAuth" });
|
||||
options.push({
|
||||
value: "copilot-proxy",
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
} from "./auth-choice.api-key.js";
|
||||
import type { ApplyAuthChoiceParams, ApplyAuthChoiceResult } from "./auth-choice.apply.js";
|
||||
import { applyDefaultModelChoice } from "./auth-choice.default-model.js";
|
||||
import { applyAuthChoicePluginProvider } from "./auth-choice.apply.plugin-provider.js";
|
||||
import {
|
||||
applyAuthProfileConfig,
|
||||
applyMinimaxApiConfig,
|
||||
@@ -29,6 +30,24 @@ export async function applyAuthChoiceMiniMax(
|
||||
"Model configured",
|
||||
);
|
||||
};
|
||||
if (params.authChoice === "minimax-portal") {
|
||||
// Let user choose between Global/CN endpoints
|
||||
const endpoint = await params.prompter.select({
|
||||
message: "Select MiniMax endpoint",
|
||||
options: [
|
||||
{ value: "oauth", label: "Global", hint: "OAuth for international users" },
|
||||
{ value: "oauth-cn", label: "CN", hint: "OAuth for users in China" },
|
||||
],
|
||||
});
|
||||
|
||||
return await applyAuthChoicePluginProvider(params, {
|
||||
authChoice: "minimax-portal",
|
||||
pluginId: "minimax-portal-auth",
|
||||
providerId: "minimax-portal",
|
||||
methodId: endpoint,
|
||||
label: "MiniMax",
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
params.authChoice === "minimax-cloud" ||
|
||||
|
||||
@@ -29,6 +29,7 @@ const PREFERRED_PROVIDER_BY_AUTH_CHOICE: Partial<Record<AuthChoice, string>> = {
|
||||
minimax: "lmstudio",
|
||||
"opencode-zen": "opencode",
|
||||
"qwen-portal": "qwen-portal",
|
||||
"minimax-portal": "minimax-portal",
|
||||
};
|
||||
|
||||
export function resolvePreferredProviderForAuthChoice(choice: AuthChoice): string | undefined {
|
||||
|
||||
@@ -588,6 +588,101 @@ describe("applyAuthChoice", () => {
|
||||
refresh: "refresh",
|
||||
});
|
||||
});
|
||||
|
||||
it("writes MiniMax credentials when selecting minimax-portal", async () => {
|
||||
tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-auth-"));
|
||||
process.env.OPENCLAW_STATE_DIR = tempStateDir;
|
||||
process.env.OPENCLAW_AGENT_DIR = path.join(tempStateDir, "agent");
|
||||
process.env.PI_CODING_AGENT_DIR = process.env.OPENCLAW_AGENT_DIR;
|
||||
|
||||
resolvePluginProviders.mockReturnValue([
|
||||
{
|
||||
id: "minimax-portal",
|
||||
label: "MiniMax",
|
||||
auth: [
|
||||
{
|
||||
id: "oauth",
|
||||
label: "MiniMax OAuth (Global)",
|
||||
kind: "device_code",
|
||||
run: vi.fn(async () => ({
|
||||
profiles: [
|
||||
{
|
||||
profileId: "minimax-portal:default",
|
||||
credential: {
|
||||
type: "oauth",
|
||||
provider: "minimax-portal",
|
||||
access: "access",
|
||||
refresh: "refresh",
|
||||
expires: Date.now() + 60 * 60 * 1000,
|
||||
},
|
||||
},
|
||||
],
|
||||
configPatch: {
|
||||
models: {
|
||||
providers: {
|
||||
"minimax-portal": {
|
||||
baseUrl: "https://api.minimax.io/anthropic",
|
||||
apiKey: "minimax-oauth",
|
||||
api: "anthropic-messages",
|
||||
models: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
defaultModel: "minimax-portal/MiniMax-M2.1",
|
||||
})),
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
const prompter: WizardPrompter = {
|
||||
intro: vi.fn(noopAsync),
|
||||
outro: vi.fn(noopAsync),
|
||||
note: vi.fn(noopAsync),
|
||||
select: vi.fn(async () => "oauth" as never),
|
||||
multiselect: vi.fn(async () => []),
|
||||
text: vi.fn(async () => ""),
|
||||
confirm: vi.fn(async () => false),
|
||||
progress: vi.fn(() => ({ update: noop, stop: noop })),
|
||||
};
|
||||
const runtime: RuntimeEnv = {
|
||||
log: vi.fn(),
|
||||
error: vi.fn(),
|
||||
exit: vi.fn((code: number) => {
|
||||
throw new Error(`exit:${code}`);
|
||||
}),
|
||||
};
|
||||
|
||||
const result = await applyAuthChoice({
|
||||
authChoice: "minimax-portal",
|
||||
config: {},
|
||||
prompter,
|
||||
runtime,
|
||||
setDefaultModel: true,
|
||||
});
|
||||
|
||||
expect(result.config.auth?.profiles?.["minimax-portal:default"]).toMatchObject({
|
||||
provider: "minimax-portal",
|
||||
mode: "oauth",
|
||||
});
|
||||
expect(result.config.agents?.defaults?.model?.primary).toBe("minimax-portal/MiniMax-M2.1");
|
||||
expect(result.config.models?.providers?.["minimax-portal"]).toMatchObject({
|
||||
baseUrl: "https://api.minimax.io/anthropic",
|
||||
apiKey: "minimax-oauth",
|
||||
});
|
||||
|
||||
const authProfilePath = authProfilePathFor(requireAgentDir());
|
||||
const raw = await fs.readFile(authProfilePath, "utf8");
|
||||
const parsed = JSON.parse(raw) as {
|
||||
profiles?: Record<string, { access?: string; refresh?: string; provider?: string }>;
|
||||
};
|
||||
expect(parsed.profiles?.["minimax-portal:default"]).toMatchObject({
|
||||
provider: "minimax-portal",
|
||||
access: "access",
|
||||
refresh: "refresh",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolvePreferredProviderForAuthChoice", () => {
|
||||
|
||||
@@ -432,7 +432,8 @@ export async function applyNonInteractiveAuthChoice(params: {
|
||||
authChoice === "oauth" ||
|
||||
authChoice === "chutes" ||
|
||||
authChoice === "openai-codex" ||
|
||||
authChoice === "qwen-portal"
|
||||
authChoice === "qwen-portal" ||
|
||||
authChoice === "minimax-portal"
|
||||
) {
|
||||
runtime.error("OAuth requires interactive mode.");
|
||||
runtime.exit(1);
|
||||
|
||||
@@ -28,6 +28,7 @@ export type AuthChoice =
|
||||
| "minimax"
|
||||
| "minimax-api"
|
||||
| "minimax-api-lightning"
|
||||
| "minimax-portal"
|
||||
| "opencode-zen"
|
||||
| "github-copilot"
|
||||
| "copilot-proxy"
|
||||
|
||||
Reference in New Issue
Block a user