n8n-nodes-ai-agent-raevon 2.2.0 → 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.0",
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": [
@@ -811,7 +811,32 @@ class BetterAiAgent {
811
811
  let finalOutput = result.text;
812
812
  if (outputParser) {
813
813
  try {
814
- finalOutput = await outputParser.parse(result.text);
814
+ // Strip markdown code fences that LLMs often wrap JSON in
815
+ let cleanText = result.text.trim();
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, '');
839
+ finalOutput = await outputParser.parse(cleanText);
815
840
  console.log('✅ Output parsed through output parser');
816
841
  } catch (parseErr) {
817
842
  console.warn('⚠️ Output parser failed, returning raw text:', parseErr.message);