MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / runChatCommand

Function runChatCommand

apps/cli/src/ai/chat-command.ts:340–374  ·  view source on GitHub ↗
(options: ChatCommandOptions, deps: ChatCommandDeps)

Source from the content-addressed store, hash-verified

338}
339
340export async function runChatCommand(options: ChatCommandOptions, deps: ChatCommandDeps): Promise<void> {
341 const stdout = deps.stdout ?? process.stdout
342 const stderr = deps.stderr ?? process.stderr
343
344 if (options.question?.trim()) {
345 const result = await runChatTurn({ ...options, question: options.question.trim() }, deps)
346 if (options.json) {
347 write(stdout, `${JSON.stringify(result, null, 2)}\n`)
348 } else if (options.stream === false) {
349 write(stdout, `${result.answer}\n`)
350 }
351 return
352 }
353
354 const rl = createInterface({
355 input: deps.stdin ?? process.stdin,
356 output: stdout as Writable,
357 })
358
359 try {
360 let aiChatId = options.aiChatId
361 while (true) {
362 const question = (await rl.question('chatlab> ')).trim()
363 if (!question || question === 'exit' || question === 'quit') break
364 try {
365 const result = await runChatTurn({ ...options, aiChatId, question, json: false, stream: true }, deps)
366 aiChatId = result.aiChatId
367 } catch (error) {
368 write(stderr, `${error instanceof Error ? error.message : String(error)}\n`)
369 }
370 }
371 } finally {
372 rl.close()
373 }
374}

Callers 2

cli.tsFile · 0.85

Calls 3

runChatTurnFunction · 0.85
writeFunction · 0.70
closeMethod · 0.65

Tested by

no test coverage detected