mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:30:43 +00:00
fix(minimax): share region auth builders
This commit is contained in:
@@ -53,6 +53,72 @@ describe("minimax provider hooks", () => {
|
||||
).toBe("native");
|
||||
});
|
||||
|
||||
it("keeps MiniMax auth setup metadata aligned across regions", async () => {
|
||||
const { providers } = await registerProviderPlugin({
|
||||
plugin: minimaxProviderPlugin,
|
||||
id: "minimax",
|
||||
name: "MiniMax Provider",
|
||||
});
|
||||
const apiProvider = requireRegisteredProvider(providers, "minimax");
|
||||
const portalProvider = requireRegisteredProvider(providers, "minimax-portal");
|
||||
|
||||
expect(
|
||||
apiProvider.auth.map((method) => ({
|
||||
id: method.id,
|
||||
label: method.label,
|
||||
hint: method.hint,
|
||||
choiceId: method.wizard?.choiceId,
|
||||
groupId: method.wizard?.groupId,
|
||||
groupHint: method.wizard?.groupHint,
|
||||
})),
|
||||
).toEqual([
|
||||
{
|
||||
id: "api-global",
|
||||
label: "MiniMax API key (Global)",
|
||||
hint: "Global endpoint - api.minimax.io",
|
||||
choiceId: "minimax-global-api",
|
||||
groupId: "minimax",
|
||||
groupHint: "M2.7 (recommended)",
|
||||
},
|
||||
{
|
||||
id: "api-cn",
|
||||
label: "MiniMax API key (CN)",
|
||||
hint: "CN endpoint - api.minimaxi.com",
|
||||
choiceId: "minimax-cn-api",
|
||||
groupId: "minimax",
|
||||
groupHint: "M2.7 (recommended)",
|
||||
},
|
||||
]);
|
||||
|
||||
expect(
|
||||
portalProvider.auth.map((method) => ({
|
||||
id: method.id,
|
||||
label: method.label,
|
||||
hint: method.hint,
|
||||
choiceId: method.wizard?.choiceId,
|
||||
groupId: method.wizard?.groupId,
|
||||
groupHint: method.wizard?.groupHint,
|
||||
})),
|
||||
).toEqual([
|
||||
{
|
||||
id: "oauth",
|
||||
label: "MiniMax OAuth (Global)",
|
||||
hint: "Global endpoint - api.minimax.io",
|
||||
choiceId: "minimax-global-oauth",
|
||||
groupId: "minimax",
|
||||
groupHint: "M2.7 (recommended)",
|
||||
},
|
||||
{
|
||||
id: "oauth-cn",
|
||||
label: "MiniMax OAuth (CN)",
|
||||
hint: "CN endpoint - api.minimaxi.com",
|
||||
choiceId: "minimax-cn-oauth",
|
||||
groupId: "minimax",
|
||||
groupHint: "M2.7 (recommended)",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("owns replay policy for Anthropic and OpenAI-compatible MiniMax transports", async () => {
|
||||
const { providers } = await registerProviderPlugin({
|
||||
plugin: minimaxProviderPlugin,
|
||||
|
||||
@@ -33,6 +33,11 @@ const MINIMAX_USAGE_ENV_VAR_KEYS = [
|
||||
"MINIMAX_CODING_API_KEY",
|
||||
"MINIMAX_API_KEY",
|
||||
] as const;
|
||||
const MINIMAX_WIZARD_GROUP = {
|
||||
groupId: "minimax",
|
||||
groupLabel: "MiniMax",
|
||||
groupHint: "M2.7 (recommended)",
|
||||
} as const;
|
||||
const HYBRID_ANTHROPIC_OPENAI_REPLAY_HOOKS = buildProviderReplayFamilyHooks({
|
||||
family: "hybrid-anthropic-openai",
|
||||
anthropicModelDropThinkingBlocks: true,
|
||||
@@ -48,6 +53,14 @@ function getDefaultBaseUrl(region: MiniMaxRegion): string {
|
||||
return region === "cn" ? DEFAULT_BASE_URL_CN : DEFAULT_BASE_URL_GLOBAL;
|
||||
}
|
||||
|
||||
function resolveMinimaxRegionLabel(region: MiniMaxRegion): string {
|
||||
return region === "cn" ? "CN" : "Global";
|
||||
}
|
||||
|
||||
function resolveMinimaxEndpointHint(region: MiniMaxRegion): string {
|
||||
return region === "cn" ? "CN endpoint - api.minimaxi.com" : "Global endpoint - api.minimax.io";
|
||||
}
|
||||
|
||||
function apiModelRef(modelId: string): string {
|
||||
return `${API_PROVIDER_ID}/${modelId}`;
|
||||
}
|
||||
@@ -102,7 +115,7 @@ function resolvePortalCatalog(ctx: ProviderCatalogContext) {
|
||||
|
||||
function createOAuthHandler(region: MiniMaxRegion) {
|
||||
const defaultBaseUrl = getDefaultBaseUrl(region);
|
||||
const regionLabel = region === "cn" ? "CN" : "Global";
|
||||
const regionLabel = resolveMinimaxRegionLabel(region);
|
||||
|
||||
return async (ctx: ProviderAuthContext): Promise<ProviderAuthResult> => {
|
||||
const progress = ctx.prompter.progress(`Starting MiniMax OAuth (${regionLabel})…`);
|
||||
@@ -169,6 +182,54 @@ function createOAuthHandler(region: MiniMaxRegion) {
|
||||
};
|
||||
}
|
||||
|
||||
function createMinimaxApiKeyMethod(region: MiniMaxRegion) {
|
||||
const regionLabel = resolveMinimaxRegionLabel(region);
|
||||
const endpointHint = resolveMinimaxEndpointHint(region);
|
||||
const isCn = region === "cn";
|
||||
return createProviderApiKeyAuthMethod({
|
||||
providerId: API_PROVIDER_ID,
|
||||
methodId: isCn ? "api-cn" : "api-global",
|
||||
label: `MiniMax API key (${regionLabel})`,
|
||||
hint: endpointHint,
|
||||
optionKey: "minimaxApiKey",
|
||||
flagName: "--minimax-api-key",
|
||||
envVar: "MINIMAX_API_KEY",
|
||||
promptMessage: isCn
|
||||
? "Enter MiniMax CN API key (sk-api- or sk-cp-)\nhttps://platform.minimaxi.com/user-center/basic-information/interface-key"
|
||||
: "Enter MiniMax API key (sk-api- or sk-cp-)\nhttps://platform.minimax.io/user-center/basic-information/interface-key",
|
||||
profileId: isCn ? "minimax:cn" : "minimax:global",
|
||||
allowProfile: false,
|
||||
defaultModel: apiModelRef(DEFAULT_MODEL),
|
||||
expectedProviders: isCn ? ["minimax", "minimax-cn"] : ["minimax"],
|
||||
applyConfig: (cfg) => (isCn ? applyMinimaxApiConfigCn(cfg) : applyMinimaxApiConfig(cfg)),
|
||||
wizard: {
|
||||
choiceId: isCn ? "minimax-cn-api" : "minimax-global-api",
|
||||
choiceLabel: `MiniMax API key (${regionLabel})`,
|
||||
choiceHint: endpointHint,
|
||||
...MINIMAX_WIZARD_GROUP,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function createMinimaxOAuthMethod(region: MiniMaxRegion) {
|
||||
const regionLabel = resolveMinimaxRegionLabel(region);
|
||||
const endpointHint = resolveMinimaxEndpointHint(region);
|
||||
const isCn = region === "cn";
|
||||
return {
|
||||
id: isCn ? "oauth-cn" : "oauth",
|
||||
label: `MiniMax OAuth (${regionLabel})`,
|
||||
hint: endpointHint,
|
||||
kind: "device_code" as const,
|
||||
wizard: {
|
||||
choiceId: isCn ? "minimax-cn-oauth" : "minimax-global-oauth",
|
||||
choiceLabel: `MiniMax OAuth (${regionLabel})`,
|
||||
choiceHint: endpointHint,
|
||||
...MINIMAX_WIZARD_GROUP,
|
||||
},
|
||||
run: createOAuthHandler(region),
|
||||
};
|
||||
}
|
||||
|
||||
export function registerMinimaxProviders(api: OpenClawPluginApi) {
|
||||
api.registerProvider({
|
||||
id: API_PROVIDER_ID,
|
||||
@@ -176,56 +237,7 @@ export function registerMinimaxProviders(api: OpenClawPluginApi) {
|
||||
hookAliases: ["minimax-cn"],
|
||||
docsPath: "/providers/minimax",
|
||||
envVars: ["MINIMAX_API_KEY"],
|
||||
auth: [
|
||||
createProviderApiKeyAuthMethod({
|
||||
providerId: API_PROVIDER_ID,
|
||||
methodId: "api-global",
|
||||
label: "MiniMax API key (Global)",
|
||||
hint: "Global endpoint - api.minimax.io",
|
||||
optionKey: "minimaxApiKey",
|
||||
flagName: "--minimax-api-key",
|
||||
envVar: "MINIMAX_API_KEY",
|
||||
promptMessage:
|
||||
"Enter MiniMax API key (sk-api- or sk-cp-)\nhttps://platform.minimax.io/user-center/basic-information/interface-key",
|
||||
profileId: "minimax:global",
|
||||
allowProfile: false,
|
||||
defaultModel: apiModelRef(DEFAULT_MODEL),
|
||||
expectedProviders: ["minimax"],
|
||||
applyConfig: (cfg) => applyMinimaxApiConfig(cfg),
|
||||
wizard: {
|
||||
choiceId: "minimax-global-api",
|
||||
choiceLabel: "MiniMax API key (Global)",
|
||||
choiceHint: "Global endpoint - api.minimax.io",
|
||||
groupId: "minimax",
|
||||
groupLabel: "MiniMax",
|
||||
groupHint: "M2.7 (recommended)",
|
||||
},
|
||||
}),
|
||||
createProviderApiKeyAuthMethod({
|
||||
providerId: API_PROVIDER_ID,
|
||||
methodId: "api-cn",
|
||||
label: "MiniMax API key (CN)",
|
||||
hint: "CN endpoint - api.minimaxi.com",
|
||||
optionKey: "minimaxApiKey",
|
||||
flagName: "--minimax-api-key",
|
||||
envVar: "MINIMAX_API_KEY",
|
||||
promptMessage:
|
||||
"Enter MiniMax CN API key (sk-api- or sk-cp-)\nhttps://platform.minimaxi.com/user-center/basic-information/interface-key",
|
||||
profileId: "minimax:cn",
|
||||
allowProfile: false,
|
||||
defaultModel: apiModelRef(DEFAULT_MODEL),
|
||||
expectedProviders: ["minimax", "minimax-cn"],
|
||||
applyConfig: (cfg) => applyMinimaxApiConfigCn(cfg),
|
||||
wizard: {
|
||||
choiceId: "minimax-cn-api",
|
||||
choiceLabel: "MiniMax API key (CN)",
|
||||
choiceHint: "CN endpoint - api.minimaxi.com",
|
||||
groupId: "minimax",
|
||||
groupLabel: "MiniMax",
|
||||
groupHint: "M2.7 (recommended)",
|
||||
},
|
||||
}),
|
||||
],
|
||||
auth: [createMinimaxApiKeyMethod("global"), createMinimaxApiKeyMethod("cn")],
|
||||
catalog: {
|
||||
order: "simple",
|
||||
run: async (ctx) => resolveApiCatalog(ctx),
|
||||
@@ -256,38 +268,7 @@ export function registerMinimaxProviders(api: OpenClawPluginApi) {
|
||||
catalog: {
|
||||
run: async (ctx) => resolvePortalCatalog(ctx),
|
||||
},
|
||||
auth: [
|
||||
{
|
||||
id: "oauth",
|
||||
label: "MiniMax OAuth (Global)",
|
||||
hint: "Global endpoint - api.minimax.io",
|
||||
kind: "device_code",
|
||||
wizard: {
|
||||
choiceId: "minimax-global-oauth",
|
||||
choiceLabel: "MiniMax OAuth (Global)",
|
||||
choiceHint: "Global endpoint - api.minimax.io",
|
||||
groupId: "minimax",
|
||||
groupLabel: "MiniMax",
|
||||
groupHint: "M2.7 (recommended)",
|
||||
},
|
||||
run: createOAuthHandler("global"),
|
||||
},
|
||||
{
|
||||
id: "oauth-cn",
|
||||
label: "MiniMax OAuth (CN)",
|
||||
hint: "CN endpoint - api.minimaxi.com",
|
||||
kind: "device_code",
|
||||
wizard: {
|
||||
choiceId: "minimax-cn-oauth",
|
||||
choiceLabel: "MiniMax OAuth (CN)",
|
||||
choiceHint: "CN endpoint - api.minimaxi.com",
|
||||
groupId: "minimax",
|
||||
groupLabel: "MiniMax",
|
||||
groupHint: "M2.7 (recommended)",
|
||||
},
|
||||
run: createOAuthHandler("cn"),
|
||||
},
|
||||
],
|
||||
auth: [createMinimaxOAuthMethod("global"), createMinimaxOAuthMethod("cn")],
|
||||
...MINIMAX_PROVIDER_HOOKS,
|
||||
isModernModelRef: ({ modelId }) => isMiniMaxModernModelId(modelId),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user