autoclaw 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +42 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8,6 +8,11 @@ import * as fs from 'fs';
|
|
|
8
8
|
import * as path from 'path';
|
|
9
9
|
import * as os from 'os';
|
|
10
10
|
import { fileURLToPath } from 'url';
|
|
11
|
+
// Handle Ctrl+C gracefully
|
|
12
|
+
process.on('SIGINT', () => {
|
|
13
|
+
console.log(chalk.cyan("\n\nGoodbye! (Interrupted)"));
|
|
14
|
+
process.exit(0);
|
|
15
|
+
});
|
|
11
16
|
const GLOBAL_CONFIG_DIR = path.join(os.homedir(), '.autoclaw');
|
|
12
17
|
const GLOBAL_CONFIG_FILE = path.join(GLOBAL_CONFIG_DIR, 'setting.json');
|
|
13
18
|
const LOCAL_CONFIG_FILE = path.join(process.cwd(), '.autoclaw', 'setting.json');
|
|
@@ -195,20 +200,44 @@ async function runChat(options) {
|
|
|
195
200
|
const agent = new Agent(apiKey, baseURL, model, fullConfig);
|
|
196
201
|
console.log(chalk.green(`Agent initialized with model: ${model}`));
|
|
197
202
|
console.log(chalk.gray("Type 'exit' or 'quit' to leave."));
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
203
|
+
// Main chat loop
|
|
204
|
+
try {
|
|
205
|
+
while (true) {
|
|
206
|
+
const { userInput } = await inquirer.prompt([
|
|
207
|
+
{
|
|
208
|
+
type: 'input',
|
|
209
|
+
name: 'userInput',
|
|
210
|
+
message: 'You >'
|
|
211
|
+
}
|
|
212
|
+
]);
|
|
213
|
+
if (userInput.toLowerCase() === 'exit' || userInput.toLowerCase() === 'quit') {
|
|
214
|
+
console.log(chalk.cyan("Goodbye!"));
|
|
215
|
+
break;
|
|
204
216
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
break;
|
|
217
|
+
if (userInput.trim() === '')
|
|
218
|
+
continue;
|
|
219
|
+
await agent.chat(userInput);
|
|
209
220
|
}
|
|
210
|
-
if (userInput.trim() === '')
|
|
211
|
-
continue;
|
|
212
|
-
await agent.chat(userInput);
|
|
213
221
|
}
|
|
222
|
+
catch (err) {
|
|
223
|
+
// Check for Inquirer interruption error (Ctrl+C often causes this)
|
|
224
|
+
if (err.message && (err.message.includes('User force closed') || err.message.includes('Prompt was canceled'))) {
|
|
225
|
+
console.log(chalk.cyan("\nGoodbye!"));
|
|
226
|
+
process.exit(0);
|
|
227
|
+
}
|
|
228
|
+
throw err; // Re-throw real errors to be caught by main().catch
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
// Global error handler
|
|
232
|
+
main().catch(err => {
|
|
233
|
+
if (err.message && (err.message.includes('User force closed') || err.message.includes('Prompt was canceled'))) {
|
|
234
|
+
console.log(chalk.cyan("\nGoodbye!"));
|
|
235
|
+
process.exit(0);
|
|
236
|
+
}
|
|
237
|
+
console.error(chalk.red("Fatal Error:"), err);
|
|
238
|
+
process.exit(1);
|
|
239
|
+
});
|
|
240
|
+
async function main() {
|
|
241
|
+
// Just a wrapper to keep the promise chain clean if needed,
|
|
242
|
+
// but currently logic is triggered by program.parse()
|
|
214
243
|
}
|