From 78859a22e1c91c823ba98a3d4ab88120b57283f4 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Fri, 7 Nov 2025 16:11:45 +0000 Subject: [PATCH] improve: address code review suggestions - Replace lowercase fallback with safer default (keep original model ID) - Harden endpoint detection using proper URL parsing - Support both minimaxi.com and minimax.com China domains - Add explanatory comments about China vs international model ID differences --- src/api/providers/minimax.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/api/providers/minimax.ts b/src/api/providers/minimax.ts index 8347e10898..38297b24b4 100644 --- a/src/api/providers/minimax.ts +++ b/src/api/providers/minimax.ts @@ -16,7 +16,17 @@ export class MiniMaxHandler extends BaseOpenAiCompatibleProvider constructor(options: ApiHandlerOptions) { const baseURL = options.minimaxBaseUrl ?? "https://api.minimax.io/v1" - const isChinaEndpoint = baseURL.includes("minimaxi.com") + // Detect China endpoint by parsing the hostname + // China endpoint uses different model IDs than international endpoint + let isChinaEndpoint = false + try { + const url = new URL(baseURL) + // Check for known China domains: minimaxi.com or minimax.com (as mentioned in issue) + isChinaEndpoint = url.hostname.endsWith("minimaxi.com") || url.hostname.endsWith("minimax.com") + } catch { + // If URL parsing fails, fall back to simple check + isChinaEndpoint = baseURL.includes("minimaxi.com") + } super({ ...options, @@ -43,11 +53,13 @@ export class MiniMaxHandler extends BaseOpenAiCompatibleProvider // Map model IDs for China endpoint - they use different model names let apiModelId = modelId as string if (this.isChinaEndpoint) { + // China endpoint requires different model IDs than the international endpoint + // MiniMax uses different naming conventions for their China-hosted models const chinaModelMapping: Record = { "MiniMax-M2": "abab7-chat", "MiniMax-M2-Stable": "abab7-chat-hd", } - apiModelId = chinaModelMapping[modelId] || modelId.toLowerCase() + apiModelId = chinaModelMapping[modelId] ?? modelId } // Centralized cap: clamp to 20% of the context window (unless provider-specific exceptions apply) @@ -84,11 +96,13 @@ export class MiniMaxHandler extends BaseOpenAiCompatibleProvider // Map model IDs for China endpoint let apiModelId = modelId as string if (this.isChinaEndpoint) { + // China endpoint requires different model IDs than the international endpoint + // MiniMax uses different naming conventions for their China-hosted models const chinaModelMapping: Record = { "MiniMax-M2": "abab7-chat", "MiniMax-M2-Stable": "abab7-chat-hd", } - apiModelId = chinaModelMapping[modelId] || modelId.toLowerCase() + apiModelId = chinaModelMapping[modelId] ?? modelId } try {