From 43a971168ee9d6dec43e204ea663e373ccbf557d Mon Sep 17 00:00:00 2001 From: octo-patch <266937838+octo-patch@users.noreply.github.com> Date: Wed, 29 Jul 2026 14:15:14 +0000 Subject: [PATCH] fix(reflection): recognize MiniMax regional endpoint and align provider id inferProviderFromBaseURL only matched the global api.minimax.io host and returned "minimax-portal", while an explicit "minimax/" reference resolves the provider id to "minimax". The regional api.minimaxi.com host was not matched at all, so a bare model name (e.g. MiniMax-M3, MiniMax-M2.7) resolved to a different provider id depending on the configured region. Match both api.minimax.io and api.minimaxi.com with the existing "." + suffix spoofing guard and return "minimax" so bare-name reflection configuration is region-independent and consistent with the explicit modelRef path. Extend the regression test to cover both regional hosts and spoofing protection. --- index.ts | 7 ++++-- test/infer-provider-from-baseurl.test.mjs | 26 ++++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/index.ts b/index.ts index 4d1955d99..acf07e4e4 100644 --- a/index.ts +++ b/index.ts @@ -1178,14 +1178,17 @@ function splitProviderModel(modelRef: string): { provider?: string; model?: stri /** * When modelRef is a bare name (no / prefix), infer provider from baseURL. - * Use "." + suffix to prevent fake-minimax.io subdomain spoofing. + * Use "." + suffix to prevent host spoofing (e.g. fake-minimax.io). Both + * MiniMax regional endpoints (minimax.io / minimaxi.com) map to the same + * "minimax" provider id used by the explicit modelRef path (e.g. + * "minimax/MiniMax-M3"), so a bare model name resolves consistently. */ export function inferProviderFromBaseURL(baseURL: string | undefined): string | undefined { if (!baseURL) return undefined; try { const url = new URL(baseURL); const hostname = url.hostname.toLowerCase(); - if (hostname.endsWith(".minimax.io")) return "minimax-portal"; + if (hostname.endsWith(".minimax.io") || hostname.endsWith(".minimaxi.com")) return "minimax"; if (hostname.endsWith(".openai.com")) return "openai"; if (hostname.endsWith(".anthropic.com")) return "anthropic"; return undefined; diff --git a/test/infer-provider-from-baseurl.test.mjs b/test/infer-provider-from-baseurl.test.mjs index 72aec3c37..88c93b1a2 100644 --- a/test/infer-provider-from-baseurl.test.mjs +++ b/test/infer-provider-from-baseurl.test.mjs @@ -19,9 +19,24 @@ const { inferProviderFromBaseURL } = indexModule; describe("inferProviderFromBaseURL - PR #713 regression", () => { describe("URL hostname inference", () => { - it("baseURL with minimax.io returns minimax-portal", () => { + it("baseURL with minimax.io returns minimax", () => { const result = inferProviderFromBaseURL("https://api.minimax.io/v1"); - assert.strictEqual(result, "minimax-portal"); + assert.strictEqual(result, "minimax"); + }); + + it("baseURL with minimax.io anthropic endpoint returns minimax", () => { + const result = inferProviderFromBaseURL("https://api.minimax.io/anthropic"); + assert.strictEqual(result, "minimax"); + }); + + it("baseURL with minimaxi.com (regional endpoint) returns minimax", () => { + const result = inferProviderFromBaseURL("https://api.minimaxi.com/v1"); + assert.strictEqual(result, "minimax"); + }); + + it("baseURL with minimaxi.com anthropic endpoint returns minimax", () => { + const result = inferProviderFromBaseURL("https://api.minimaxi.com/anthropic"); + assert.strictEqual(result, "minimax"); }); it("baseURL with openai.com returns openai", () => { @@ -41,6 +56,11 @@ describe("inferProviderFromBaseURL - PR #713 regression", () => { assert.strictEqual(result, undefined); }); + it("fake-minimaxi.com should NOT match (subdomain spoofing protection)", () => { + const result = inferProviderFromBaseURL("https://fake-minimaxi.com"); + assert.strictEqual(result, undefined); + }); + it("null returns undefined", () => { assert.strictEqual(inferProviderFromBaseURL(null), undefined); }); @@ -57,7 +77,7 @@ describe("inferProviderFromBaseURL - PR #713 regression", () => { describe("URL path variations", () => { it("handles baseURL with deep path", () => { const result = inferProviderFromBaseURL("https://api.minimax.io/v1/chat/completions"); - assert.strictEqual(result, "minimax-portal"); + assert.strictEqual(result, "minimax"); }); it("handles baseURL without path", () => {