Spaces:
Sleeping
Sleeping
Commit ·
0d07c0a
1
Parent(s): 2cc8683
apply changes
Browse files
server.js
CHANGED
|
@@ -13,7 +13,7 @@ const { Server: SocketIO } = require("socket.io");
|
|
| 13 |
|
| 14 |
const dev = process.env.NODE_ENV !== "production";
|
| 15 |
const hostname = process.env.HOSTNAME || "0.0.0.0";
|
| 16 |
-
const port = parseInt(process.env.PORT || "
|
| 17 |
|
| 18 |
const app = next({ dev, hostname, port });
|
| 19 |
const handle = app.getRequestHandler();
|
|
@@ -56,6 +56,42 @@ app.prepare().then(() => {
|
|
| 56 |
socket.leave(`rag:${sessionId}`);
|
| 57 |
});
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
socket.on("disconnect", (reason) => {
|
| 60 |
console.log(`[Socket.io] Client disconnected: ${socket.id} (${reason})`);
|
| 61 |
});
|
|
|
|
| 13 |
|
| 14 |
const dev = process.env.NODE_ENV !== "production";
|
| 15 |
const hostname = process.env.HOSTNAME || "0.0.0.0";
|
| 16 |
+
const port = parseInt(process.env.PORT || "3001", 10);
|
| 17 |
|
| 18 |
const app = next({ dev, hostname, port });
|
| 19 |
const handle = app.getRequestHandler();
|
|
|
|
| 56 |
socket.leave(`rag:${sessionId}`);
|
| 57 |
});
|
| 58 |
|
| 59 |
+
// Agent session — same room scheme so agent thoughts stream to the client
|
| 60 |
+
socket.on("join_agent_session", (sessionId) => {
|
| 61 |
+
socket.join(`rag:${sessionId}`);
|
| 62 |
+
console.log(`[Socket.io] ${socket.id} joined agent session ${sessionId}`);
|
| 63 |
+
});
|
| 64 |
+
|
| 65 |
+
socket.on("leave_agent_session", (sessionId) => {
|
| 66 |
+
socket.leave(`rag:${sessionId}`);
|
| 67 |
+
});
|
| 68 |
+
|
| 69 |
+
// HITL — the frontend sends the human's reply to a guidance request
|
| 70 |
+
socket.on("human_reply", ({ sessionId, reply }) => {
|
| 71 |
+
console.log(
|
| 72 |
+
`[Socket.io] human_reply for session ${sessionId}: ${(reply || "").slice(0, 80)}`,
|
| 73 |
+
);
|
| 74 |
+
|
| 75 |
+
// Resolve the pending guidance Promise in the agent
|
| 76 |
+
const pendingMap = globalThis.__pendingGuidance;
|
| 77 |
+
if (pendingMap && typeof pendingMap.get === "function") {
|
| 78 |
+
const pending = pendingMap.get(sessionId);
|
| 79 |
+
if (pending && typeof pending.resolve === "function") {
|
| 80 |
+
pending.resolve({
|
| 81 |
+
sessionId,
|
| 82 |
+
thoughtId: pending.request?.thoughtId ?? 0,
|
| 83 |
+
reply: reply || "No reply provided.",
|
| 84 |
+
timestamp: new Date().toISOString(),
|
| 85 |
+
});
|
| 86 |
+
pendingMap.delete(sessionId);
|
| 87 |
+
} else {
|
| 88 |
+
console.warn(
|
| 89 |
+
`[Socket.io] No pending guidance for session ${sessionId}`,
|
| 90 |
+
);
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
});
|
| 94 |
+
|
| 95 |
socket.on("disconnect", (reason) => {
|
| 96 |
console.log(`[Socket.io] Client disconnected: ${socket.id} (${reason})`);
|
| 97 |
});
|