AI manager error

Wappler 7.9.3
macOS 15.7.5
Nodejs Project

Openrouter AI API connected to bedrock ai api throws this error.
Same API working fine in openclaude, jcode etc.

Does this error happen after specific tool calls, happens it always after the first response or is it more random?

It happens always

@Priya_Sharma I was facing the same issue. If you are using the Wappler AI Manager with OpenRouter (or certain OpenAI-compatible models) and encountering a silent crash or an error stating TypeError: Cannot read properties of undefined (reading 'filter'), here is why it happens and how to fix it.

The Cause:
The bug occurs in Wappler's internal chatClient.js streaming file. The code expects the incoming AI payload to contain a tool_calls property. When a model returns a standard text response without any tool execution, this property is completely missing (undefined). Wappler then tries to execute .filter() on it and crashes.

How to Fix It:

  1. Close Wappler.

  2. Locate the chatClient.js file on your machine:

    • Windows: C:\Users\<YourUser>\AppData\Local\Wappler\resources\app\Shared\DMXzone\dmxAppCreator\UI\ai\chatClient.js

    • macOS: Right-click Wappler in Applications -> Show Package Contents -> /Contents/Resources/app/Shared/DMXzone/dmxAppCreator/UI/ai/chatClient.js

  3. Find line 236, which currently looks like this:

    javascript

    snapshot.tool_calls = snapshot.tool_calls.filter(tc => tc != null);
    
    
  4. Change it to include an empty array fallback using optional chaining/logical OR:

    javascript

    snapshot.tool_calls = (snapshot.tool_calls || []).filter(tc => tc != null);
    
    
  5. Save the file and restart Wappler.

Thanks for the solution, will fix it for the next update. The AI solution works but his description about the cause isn't. It is actual a bug in the OpenRouter API which sends a duplicate finish_reason chunk in the stream. On finish the tool_calls array is removed from the snapshot, due to the duplicate finish it is called a second time after it was removed causing the error in Wappler.

1 Like