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

Function run

src/commands/text/chat.ts:179–325  ·  view source on GitHub ↗
(config: Config, flags: GlobalFlags)

Source from the content-addressed store, hash-verified

177 'mmx text chat --message "Hello" --output json',
178 ],
179 async run(config: Config, flags: GlobalFlags) {
180 const { system, messages: parsedMessages } = parseMessages(flags);
181 let messages = parsedMessages;
182
183 if (messages.length === 0) {
184 if (isInteractive({ nonInteractive: config.nonInteractive })) {
185 const hint = await promptText({
186 message: 'Enter your message:',
187 });
188 if (!hint) {
189 process.stderr.write('Chat cancelled.\n');
190 process.exit(1);
191 }
192 messages = [{ role: 'user', content: hint }];
193 } else {
194 failIfMissing('message', 'mmx text chat --message <text>');
195 }
196 }
197
198 const model = (flags.model as string)
199 || config.defaultTextModel
200 || 'MiniMax-M2.7';
201 const format = detectOutputFormat(config.output);
202 const shouldStream = flags.stream === true || (
203 flags.stream === undefined
204 && format !== 'json'
205 && process.stdout.isTTY
206 );
207
208 const body: ChatRequest = {
209 model,
210 messages,
211 max_tokens: (flags.maxTokens as number) ?? 4096,
212 stream: shouldStream,
213 };
214
215 if (system) body.system = system;
216 if (flags.temperature !== undefined) body.temperature = flags.temperature as number;
217 if (flags.topP !== undefined) body.top_p = flags.topP as number;
218
219 if (flags.tool) {
220 const tools = (flags.tool as string[]).map(t => {
221 try {
222 return JSON.parse(t);
223 } catch {
224 // Not JSON — treat as file path
225 try {
226 const raw = readFileSync(t, 'utf-8');
227 return JSON.parse(raw);
228 } catch {
229 throw new CLIError(
230 `Invalid tool definition: "${t}" is neither valid JSON nor a readable file.`,
231 ExitCode.USAGE,
232 );
233 }
234 }
235 });
236 body.tools = tools;

Callers

nothing calls this directly

Calls 12

startMethod · 0.95
stopMethod · 0.95
isInteractiveFunction · 0.90
promptTextFunction · 0.90
failIfMissingFunction · 0.90
detectOutputFormatFunction · 0.90
formatOutputFunction · 0.90
chatEndpointFunction · 0.90
requestFunction · 0.90
parseSSEFunction · 0.90
parseMessagesFunction · 0.85
extractTextFunction · 0.85

Tested by

no test coverage detected