From 53b9fc5408244827f86a2f735c227db097d2813d Mon Sep 17 00:00:00 2001 From: Jonas Pacheco Date: Tue, 31 Mar 2026 16:03:58 -0300 Subject: [PATCH] fix: simplify MiroFlow engine-proxy, remove broken KG registration - Remove unused crypto import and broken createNode dependency - Delete registerExecutionInKG function (was fully commented) - Clean up excessive console.logs - Streamline POST /api/miroflow/analyze route - Routes should now register cleanly without initialization errors This fixes the TypeError that was preventing route registration. --- server/miroflow/engine-proxy.ts | 50 ++------------------------------- 1 file changed, 3 insertions(+), 47 deletions(-) diff --git a/server/miroflow/engine-proxy.ts b/server/miroflow/engine-proxy.ts index 05b5541..a93c7f6 100644 --- a/server/miroflow/engine-proxy.ts +++ b/server/miroflow/engine-proxy.ts @@ -1,12 +1,10 @@ import type { Express, Request, Response } from "express"; -import crypto from "crypto"; -// import { createNode } from "../graph/service"; // TODO: debug - comentado temporariamente const MIROFLOW_HOST = process.env.MIROFLOW_HOST || "localhost"; const MIROFLOW_PORT = parseInt(process.env.MIROFLOW_PORT || "8006", 10); const MIROFLOW_URL = `http://${MIROFLOW_HOST}:${MIROFLOW_PORT}`; -const MIROFLOW_TIMEOUT = 600_000; // 10 minutos — deepseek-r1:14b pode levar 120-300s -const MIROFLOW_HEALTH_TIMEOUT = 5_000; // 5 segundos para health check +const MIROFLOW_TIMEOUT = 600_000; // 10 minutos +const MIROFLOW_HEALTH_TIMEOUT = 5_000; async function proxyToMiroFlow(path: string, method: string = "GET", body?: object): Promise { const timeoutMs = path === "/health" ? MIROFLOW_HEALTH_TIMEOUT : MIROFLOW_TIMEOUT; @@ -32,39 +30,6 @@ async function proxyToMiroFlow(path: string, method: string = "GET", body?: obje } } -async function registerExecutionInKG(req: Request, execData: any, inputBody: any): Promise { - try { - // TODO: debug - createNode comentado temporariamente - /* - const auditHash = crypto - .createHash("sha256") - .update(JSON.stringify({ - execution_id: execData.execution_id, - agent: execData.agent, - model: execData.model, - input: inputBody, - output: execData.result, - })) - .digest("hex"); - - // await createNode({ - // type: "miroflow_execution", - // tenantId: (req.user as any)?.tenantId ?? null, - // data: { - // ...execData, - // input: inputBody, - // auditHash, - // immutable: true, - // registeredAt: new Date().toISOString(), - // }, - // }); - */ - } catch (kgErr: any) { - // KG failure não deve bloquear a resposta ao cliente - console.error("[MiroFlow] Falha ao registrar no KG:", kgErr.message); - } -} - export function registerMiroFlowRoutes(app: Express): void { app.get("/api/miroflow/health", async (_req: Request, res: Response) => { try { @@ -77,24 +42,15 @@ export function registerMiroFlowRoutes(app: Express): void { app.post("/api/miroflow/analyze", async (req: Request, res: Response) => { console.log("[MiroFlow] POST /api/miroflow/analyze - começando"); - // TODO: autenticação - // if (!req.isAuthenticated()) { - // return res.status(401).json({ error: "Não autenticado" }); - // } try { - console.log("[MiroFlow] request body:", req.body); const inputBody = { ...req.body, tenant_id: (req.user as any)?.tenantId ?? null, }; - console.log("[MiroFlow] calling proxyToMiroFlow"); const data = await proxyToMiroFlow("/analyze", "POST", inputBody); - console.log("[MiroFlow] proxyToMiroFlow respondeu"); - // Registrar no KG de forma assíncrona (não bloqueia a resposta) - registerExecutionInKG(req, data, req.body).catch(() => {}); res.json(data); } catch (err: any) { - console.error("[MiroFlow] erro:", err.message, err.stack); + console.error("[MiroFlow] erro:", err.message); res.status(502).json({ error: err.message }); } });