-1

Ok i have an ongoing problem with a project I'm working on. I made an ElectronJS app that I'm going to be installing in the users desktop. This electron app will communicate with an MCP server via Axios, It will be sending the chat messages from the app to a database (the electron app is a Claude-like app where you chat with a LLM. The LLM I'm using is Ollama). The MCP server and the database live on Docker containers. When the app sends the message, its also send the message to a dashboard which also has its own docker container. What I'm noticing is that the chat app is too slow and its not sending the message to the dashboard. The code for the saveLog function is below. It has a little bit of React.js too.

I think most people know how Electron works but i'll explain it and hope that anybody can help me. Electron uses 2 files for what's called Inter-Process Communication. The 2 important files here are the Preload.js and Main.js. I posted them below for reference. My Docker containers are running on ports 3000 as the dashboard and Ollama is using 11434. Basically the app file is the front end of Electron and uses the function saveLog thats from the sentinelAPI. Savelog connects via preload to the ipcRenderer which connects to the ipcMain handler which fires the log_responses function.

App.tsx

const handleSendMessage = async (text: string) => {
    if (!text || !text.trim()) return;
    if (!activeChat) return;

    // Add user message to UI
    addMessage(activeChat.id,
      {
        role: 'user',
        content: text.trim(),
        timestamp: Date.now()
      });

    try {
      const response = await (window as any).sentinelAPI.askAI(text.trim());

      if (response.success && response.answer) {
        addMessage(activeChat.id,
          {
            role: 'assistant',
            content: response.answer,
            timestamp: Date.now()
          });

        await (window as any).sentinelAPI.saveLog({
          timeStamp: new Date().toISOString(),
          userId: 'Lawyer_user_1',
          prompt: text.trim(),
          matter_id: 'GENERAL',
          response_text: response.answer,
        }).catch((e: any) => console.error("Log failed:", e));
      }
    } catch (error) {
      addMessage(activeChat.id, {
        role: 'assistant',
        content: "System: Connection lost.",
        timestamp: Date.now()
      });
    }
  };

Preload.js

const { contextBridge, ipcRenderer } = require("electron");


contextBridge.exposeInMainWorld('sentinelAPI', {
    // file system access
    openFolder: () => ipcRenderer.invoke('dialog:openDirectory'),

    // mcp communication
    callMCPTool: (serverName, toolName, args) => 
        ipcRenderer.invoke('mcp:call-tool', { serverName, toolName, args }),

    //  billing/stripe
    openExternalLink: (url) => ipcRenderer.send('open-external', url),

    // ask ai thingy
    askAI: (query) => ipcRenderer.invoke('sentinel:query', query),

    // save the logs of the prompts
    saveLog: (logData) => ipcRenderer.invoke('log_responses', logData)


});

main.js

// saveLog tool invoke
ipcMain.handle("log_responses", async (event, logData) => {
    try {
        //const SERVER_URL = `http://localhost:3000/api/logs`;

        const cleanData = {
        timeStamp: new Date().toISOString(),
        userId: logData.userId || 'Lawyer_user_1',
        prompt_text: logData.prompt || 'No Prompt',
        response_text: logData.response_text || 'No Response',
        matter_id: logData.matter_id || 'GENERAL'
    };

        axios.post('http://localhost:3000/api/logs', cleanData, { timeout: 3000 })
        .then(() => console.log("✅ Log synced to dashboard"))
        .catch(() => console.log("⚠️ Dashboard busy (Log ignored for demo)"));

    // 3. IMMEDIATELY return success to the UI so it doesn't freeze
    return { success: true };
    } catch (error) {
        console.log("audit log failed: ", error);
        return { error: "Failed to connect to Law Firm" };
    }

});
2
  • 1
    "too slow" isn't exactly an actionable problem statement, it's too ambiguous and subjective. "not sending the message to the dashboard" sounds more like something readers could objectively help with though. Please edit to more clearly define the specific problem you need help with. Include all relevant code (see minimal reproducible example), any complete error messages/stacktraces, and debugging logs and details from any investigation. This will help readers better understand what you are asking. Commented 3 hours ago
  • Regardless of what's wrong, your explanation of Electron IPC isn't correct. Commented 2 hours ago

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.