优化体验
This commit is contained in:
parent
91d744aa1e
commit
eabf0e772a
1 changed files with 8 additions and 17 deletions
25
src/index.ts
25
src/index.ts
|
|
@ -8,8 +8,6 @@ import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { createInterface } from 'node:readline/promises';
|
|
||||||
import { stdin as input, stdout as output } from 'node:process';
|
|
||||||
|
|
||||||
// Handle Ctrl+C gracefully
|
// Handle Ctrl+C gracefully
|
||||||
function handleExit() {
|
function handleExit() {
|
||||||
|
|
@ -392,20 +390,16 @@ async function runChat(queryParts: string[], options: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main chat loop
|
// Main chat loop
|
||||||
const rl = createInterface({ input, output });
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
let userInput: string;
|
const { userInput } = await inquirer.prompt([
|
||||||
try {
|
{
|
||||||
userInput = await rl.question(chalk.green('? ') + 'You > ');
|
type: 'input',
|
||||||
} catch (err: any) {
|
name: 'userInput',
|
||||||
if (err.code === 'ABORT_ERR') {
|
message: 'You >',
|
||||||
console.log(chalk.cyan("\nGoodbye!"));
|
prefix: chalk.green('?')
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
throw err;
|
]);
|
||||||
}
|
|
||||||
|
|
||||||
if (userInput.toLowerCase() === 'exit' || userInput.toLowerCase() === 'quit') {
|
if (userInput.toLowerCase() === 'exit' || userInput.toLowerCase() === 'quit') {
|
||||||
console.log(chalk.cyan("Goodbye!"));
|
console.log(chalk.cyan("Goodbye!"));
|
||||||
|
|
@ -417,14 +411,11 @@ async function runChat(queryParts: string[], options: any) {
|
||||||
await agent.chat(userInput);
|
await agent.chat(userInput);
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err.name === 'AbortError' || err.code === 'ABORT_ERR') {
|
if (err.message && (err.message.includes('User force closed') || err.message.includes('Prompt was canceled'))) {
|
||||||
// Handled inside loop mostly, but just in case
|
|
||||||
console.log(chalk.cyan("\nGoodbye!"));
|
console.log(chalk.cyan("\nGoodbye!"));
|
||||||
} else {
|
} else {
|
||||||
console.error(chalk.red("Error in chat loop:"), err);
|
console.error(chalk.red("Error in chat loop:"), err);
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
rl.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue