Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
73 lines (60 loc) · 1.99 KB
/
Copy pathindex.js
File metadata and controls
73 lines (60 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* CashGuardian CLI entry point.
*/
const readline = require("node:readline");
const dotenv = require("dotenv");
const { handleQuery } = require("./agent/queryAgent");
dotenv.config();
const BANNER = [
"\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557",
"\u2551 CashGuardian CLI \ud83d\udcbc \u2551",
"\u2551 Talk to your finances in plain English \u2551",
"\u2551 Powered by free AI | Indian SME Edition \u2551",
"\u255a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255d",
'Type your question or "help". Type "exit" to quit.',
""
].join("\n");
/**
* Starts the interactive CLI session.
* @returns {void}
*/
function startCli() {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: "> "
});
console.log(BANNER);
rl.prompt();
rl.on("line", async (line) => {
const input = line.trim();
if (!input) {
rl.prompt();
return;
}
if (input.toLowerCase() === "exit") {
rl.close();
return;
}
try {
const response = await handleQuery(input);
console.log(response);
} catch (error) {
console.log("Something went wrong while processing your request.");
}
rl.prompt();
});
rl.on("SIGINT", () => {
rl.close();
});
rl.on("close", () => {
console.log("CashGuardian session ended.");
process.exit(0);
});
}
if (require.main === module) {
startCli();
}
module.exports = {
startCli
};