From eabf0e772a0b02feaa4e3362ca78af5b322e795f Mon Sep 17 00:00:00 2001 From: tsingliu <410869548@qq.com> Date: Sun, 8 Feb 2026 14:06:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/index.ts b/src/index.ts index 612d708..34a49c0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,8 +8,6 @@ import * as fs from 'fs'; import * as path from 'path'; import * as os from 'os'; import { fileURLToPath } from 'url'; -import { createInterface } from 'node:readline/promises'; -import { stdin as input, stdout as output } from 'node:process'; // Handle Ctrl+C gracefully function handleExit() { @@ -392,20 +390,16 @@ async function runChat(queryParts: string[], options: any) { } // Main chat loop - const rl = createInterface({ input, output }); - try { while (true) { - let userInput: string; - try { - userInput = await rl.question(chalk.green('? ') + 'You > '); - } catch (err: any) { - if (err.code === 'ABORT_ERR') { - console.log(chalk.cyan("\nGoodbye!")); - break; + const { userInput } = await inquirer.prompt([ + { + type: 'input', + name: 'userInput', + message: 'You >', + prefix: chalk.green('?') } - throw err; - } + ]); if (userInput.toLowerCase() === 'exit' || userInput.toLowerCase() === 'quit') { console.log(chalk.cyan("Goodbye!")); @@ -417,14 +411,11 @@ async function runChat(queryParts: string[], options: any) { await agent.chat(userInput); } } catch (err: any) { - if (err.name === 'AbortError' || err.code === 'ABORT_ERR') { - // Handled inside loop mostly, but just in case + if (err.message && (err.message.includes('User force closed') || err.message.includes('Prompt was canceled'))) { console.log(chalk.cyan("\nGoodbye!")); } else { console.error(chalk.red("Error in chat loop:"), err); } - } finally { - rl.close(); } }