-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
60 lines (48 loc) · 1.4 KB
/
index.ts
File metadata and controls
60 lines (48 loc) · 1.4 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
import readline from "node:readline/promises";
import { app } from "./src/app/graph";
import { printBanner, printMessage, printDivider } from "./src/cli/tui";
import { createLogger } from "./src/lib/logger";
const appLogger = createLogger("cli");
async function main() {
printBanner();
appLogger.info("Agent CLI started.");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
while (true) {
const userInput = await rl.question("\n> ");
if (userInput.toLowerCase() === "exit") break;
appLogger.info("User input received.");
try {
const finalState = await app.invoke(
{
messages: [{ role: "human", content: userInput }],
},
{
configurable: {
thread_id: "1",
},
},
);
appLogger.info("Agent response generated.");
const lastMessage = finalState.messages.at(-1);
if (lastMessage?.content) {
printMessage("AI:", lastMessage.content as string);
}
printDivider();
} catch (err) {
appLogger.error("Failed to process user input.", {
error: err instanceof Error ? err.message : String(err),
});
}
}
rl.close();
appLogger.info("Agent CLI stopped.");
}
main().catch((err) => {
appLogger.error("Fatal startup error.", {
error: err instanceof Error ? err.message : String(err),
});
process.exit(1);
});