separated in modules
This commit is contained in:
61
src/modules/1-intake/routes/simulator.js
Normal file
61
src/modules/1-intake/routes/simulator.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import express from "express";
|
||||
|
||||
import { addSseClient, removeSseClient } from "../../shared/sse.js";
|
||||
import { makeGetConversations } from "../../../controllers/conversations.js";
|
||||
import { makeListRuns, makeGetRunById } from "../../../controllers/runs.js";
|
||||
import { makeSimSend } from "../controllers/sim.js";
|
||||
import { makeGetConversationState } from "../../../controllers/conversationState.js";
|
||||
import { makeListMessages } from "../../../controllers/messages.js";
|
||||
import { makeSearchProducts } from "../../../controllers/products.js";
|
||||
import { makeDeleteConversation, makeDeleteUser, makeListUsers, makeRetryLast } from "../../../controllers/admin.js";
|
||||
|
||||
function nowIso() {
|
||||
return new Date().toISOString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Endpoints consumidos por el frontend (UI / simulador).
|
||||
* Mantiene exactamente los mismos paths que existían en `index.js`.
|
||||
*/
|
||||
export function createSimulatorRouter({ tenantId }) {
|
||||
const router = express.Router();
|
||||
const getTenantId = () => tenantId;
|
||||
|
||||
/**
|
||||
* --- SSE endpoint ---
|
||||
*/
|
||||
router.get("/stream", (req, res) => {
|
||||
res.setHeader("Content-Type", "text/event-stream");
|
||||
res.setHeader("Cache-Control", "no-cache");
|
||||
res.setHeader("Connection", "keep-alive");
|
||||
res.flushHeaders?.();
|
||||
|
||||
res.write(`event: hello\ndata: ${JSON.stringify({ ts: nowIso() })}\n\n`);
|
||||
addSseClient(res);
|
||||
|
||||
req.on("close", () => {
|
||||
removeSseClient(res);
|
||||
res.end();
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* --- UI data endpoints ---
|
||||
*/
|
||||
router.post("/sim/send", makeSimSend());
|
||||
|
||||
router.get("/conversations", makeGetConversations(getTenantId));
|
||||
router.get("/conversations/state", makeGetConversationState(getTenantId));
|
||||
router.delete("/conversations/:chat_id", makeDeleteConversation(getTenantId));
|
||||
router.post("/conversations/:chat_id/retry-last", makeRetryLast(getTenantId));
|
||||
router.get("/messages", makeListMessages(getTenantId));
|
||||
router.get("/products", makeSearchProducts(getTenantId));
|
||||
router.get("/users", makeListUsers(getTenantId));
|
||||
router.delete("/users/:chat_id", makeDeleteUser(getTenantId));
|
||||
|
||||
router.get("/runs", makeListRuns(getTenantId));
|
||||
router.get("/runs/:run_id", makeGetRunById(getTenantId));
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user