forked from johntango/AgentLoop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
75 lines (63 loc) · 1.86 KB
/
Copy pathserver.js
File metadata and controls
75 lines (63 loc) · 1.86 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
74
75
const path = require("path");
const express = require("express");
const { runAgentLoop } = require("./lib/agent");
const {
readProgress,
getProgressSummary,
markTopicComplete
} = require("./lib/progressStore");
const app = express();
const PORT = Number(process.env.PORT) || 3000;
app.use(express.json({ limit: "1mb" }));
app.use(express.static(path.join(__dirname, "public")));
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "public", "index.html"));
});
app.get("/api/progress", async (req, res) => {
try {
const progress = await readProgress();
res.json(getProgressSummary(progress));
} catch (error) {
res.status(500).json({
error: "Failed to read progress.",
details: String(error.message || error)
});
}
});
app.post("/api/complete", async (req, res) => {
const topic = typeof req.body?.topic === "string" ? req.body.topic.trim() : "";
if (!topic) {
return res.status(400).json({ error: "Topic is required." });
}
try {
const progress = await markTopicComplete(topic);
return res.json({
reply: `Marked \"${topic}\" complete.`,
progress
});
} catch (error) {
return res.status(500).json({
error: "Failed to update progress.",
details: String(error.message || error)
});
}
});
app.post("/api/message", async (req, res) => {
const message = typeof req.body?.message === "string" ? req.body.message.trim() : "";
if (!message) {
return res.status(400).json({ error: "Message is required." });
}
try {
const result = await runAgentLoop(message);
return res.json(result);
} catch (error) {
return res.status(500).json({
error: "Agent request failed.",
details: String(error.message || error)
});
}
});
app.listen(PORT, () => {
// eslint-disable-next-line no-console
console.log(`Server running at http://localhost:${PORT}`);
});