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

Function loadConfig

src/config/loader.ts:31–90  ·  view source on GitHub ↗
(flags: GlobalFlags)

Source from the content-addressed store, hash-verified

29}
30
31export function loadConfig(flags: GlobalFlags): Config {
32 const file = readConfigFile();
33
34 const apiKey = flags.apiKey || undefined;
35 const fileApiKey = file.api_key;
36
37 const explicitRegion = (flags.region as string) || process.env.MINIMAX_REGION || undefined;
38 if (explicitRegion && !(explicitRegion in REGIONS)) {
39 throw new CLIError(
40 `Invalid region "${explicitRegion}". Valid values: ${Object.keys(REGIONS).join(', ')}`,
41 ExitCode.USAGE,
42 );
43 }
44
45 const cachedRegion = file.region;
46 const region = (explicitRegion || cachedRegion || 'global') as Region;
47
48 const activeKey = apiKey || fileApiKey;
49 const needsRegionDetection = !explicitRegion
50 && (!cachedRegion || (activeKey !== undefined && activeKey !== file.api_key));
51
52 const baseUrl = flags.baseUrl
53 || process.env.MINIMAX_BASE_URL
54 || file.base_url
55 || file.oauth?.resource_url
56 || REGIONS[region]
57 || REGIONS.global;
58
59 const output: OutputFormat = detectOutputFormat(
60 flags.output || process.env.MINIMAX_OUTPUT || file.output,
61 );
62
63 const envTimeout = process.env.MINIMAX_TIMEOUT ? Number(process.env.MINIMAX_TIMEOUT) : undefined;
64 const validEnvTimeout = envTimeout !== undefined && Number.isFinite(envTimeout) && envTimeout > 0
65 ? envTimeout : undefined;
66 const timeout = flags.timeout ?? validEnvTimeout ?? file.timeout ?? 300;
67
68 return {
69 apiKey,
70 fileApiKey,
71 fileRegion: file.region,
72 configPath: getConfigPath(),
73 region,
74 baseUrl,
75 output,
76 timeout,
77 defaultTextModel: file.default_text_model,
78 defaultSpeechModel: file.default_speech_model,
79 defaultVideoModel: file.default_video_model,
80 defaultMusicModel: file.default_music_model,
81 verbose: flags.verbose || process.env.MINIMAX_VERBOSE === '1',
82 quiet: flags.quiet || false,
83 noColor: flags.noColor || process.env.NO_COLOR !== undefined || !process.stdout.isTTY,
84 yes: flags.yes || false,
85 dryRun: flags.dryRun || false,
86 nonInteractive: flags.nonInteractive || false,
87 async: flags.async || false,
88 needsRegionDetection,

Callers 3

loader.test.tsFile · 0.90
mainFunction · 0.90
constructorMethod · 0.90

Calls 3

detectOutputFormatFunction · 0.90
getConfigPathFunction · 0.90
readConfigFileFunction · 0.85

Tested by

no test coverage detected