n8n-nodes-ai-agent-raevon 2.2.1 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-ai-agent-raevon",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "Universal AI Agent for n8n - works with ALL chat models, correct tool calling, intermediate webhook",
5
5
  "main": "src/BetterAiAgent.node.js",
6
6
  "files": [
@@ -814,6 +814,28 @@ class BetterAiAgent {
814
814
  // Strip markdown code fences that LLMs often wrap JSON in
815
815
  let cleanText = result.text.trim();
816
816
  cleanText = cleanText.replace(/^```(?:json)?\s*\n?/i, '').replace(/\n?```\s*$/i, '').trim();
817
+ // Remove invisible Unicode characters (zero-width spaces, RTL marks, BOM, etc.)
818
+ cleanText = cleanText.replace(/[\u0000-\u001F\u007F\u200B\u200C\u200D\u200E\u200F\u202A\u202B\u202C\u202D\u202E\u2060\u2061\u2062\u2063\uFEFF]/g, '');
819
+ // Remove leading text before JSON (e.g. "Here's the JSON:" or "The output is:")
820
+ const jsonStart = cleanText.indexOf('{');
821
+ const jsonArrayStart = cleanText.indexOf('[');
822
+ if (jsonStart === -1 && jsonArrayStart === -1) {
823
+ throw new Error('No JSON object or array found in model output');
824
+ }
825
+ const startIdx = jsonStart === -1 ? jsonArrayStart
826
+ : jsonArrayStart === -1 ? jsonStart
827
+ : Math.min(jsonStart, jsonArrayStart);
828
+ cleanText = cleanText.slice(startIdx);
829
+ // Remove trailing text after JSON (e.g. "Hope this helps!")
830
+ const lastClose = Math.max(cleanText.lastIndexOf('}'), cleanText.lastIndexOf(']'));
831
+ if (lastClose !== -1) {
832
+ cleanText = cleanText.slice(0, lastClose + 1);
833
+ }
834
+ // Remove trailing commas before closing braces/brackets
835
+ cleanText = cleanText.replace(/,\s*([\]}])/g, '$1');
836
+ // Remove single-line and multi-line comments
837
+ cleanText = cleanText.replace(/\/\/.*$/gm, '');
838
+ cleanText = cleanText.replace(/\/\*[\s\S]*?\*\//g, '');
817
839
  finalOutput = await outputParser.parse(cleanText);
818
840
  console.log('✅ Output parsed through output parser');
819
841
  } catch (parseErr) {