MCPcopy
hub / github.com/MiniMax-AI/cli / detectRegion

Function detectRegion

src/config/detect-region.ts:42–65  ·  view source on GitHub ↗
(apiKey: string)

Source from the content-addressed store, hash-verified

40}
41
42export async function detectRegion(apiKey: string): Promise<Region> {
43 process.stderr.write("Detecting region...");
44 const regions = Object.keys(REGIONS) as Region[];
45 const results = await Promise.all(
46 regions.map(async (r) => ({
47 region: r,
48 ok: await probeRegion(r, apiKey, 5000),
49 })),
50 );
51 const match = results.find((r) => r.ok);
52 if (!match) {
53 process.stderr.write(" failed\n");
54 process.stderr.write(
55 `Warning: API key failed validation against all regions (global, cn).\n` +
56 ` This usually means the API key is invalid or the network is blocking requests.\n` +
57 ` Falling back to 'global'. Subsequent requests may fail.\n` +
58 ` Run 'mmx auth status' to verify your credentials.\n`,
59 );
60 return "global";
61 }
62 const detected: Region = match.region;
63 process.stderr.write(` ${detected}\n`);
64 return detected;
65}
66
67export async function saveDetectedRegion(region: Region): Promise<void> {
68 const existing = readConfigFile() as Record<string, unknown>;

Callers 3

mainFunction · 0.90
loginWithApiKeyFunction · 0.90

Calls 1

probeRegionFunction · 0.85

Tested by

no test coverage detected