{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "950b05f0-f34f-4cce-aa1c-108560e7c1c1",
      "name": "Get Workflow",
      "type": "n8n-nodes-base.n8n",
      "position": [
        688,
        240
      ],
      "parameters": {
        "operation": "get",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.workflow.id }}"
        },
        "requestOptions": {}
      },
      "credentials": {
        "n8nApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "05a9e46e-3919-4b78-8683-9306ad96abea",
      "name": "Get Execution",
      "type": "n8n-nodes-base.n8n",
      "position": [
        912,
        240
      ],
      "parameters": {
        "options": {},
        "resource": "execution",
        "operation": "get",
        "executionId": "={{ $json.execution.id }}",
        "requestOptions": {}
      },
      "credentials": {
        "n8nApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "fdfdb487-ecf1-432b-abc0-611d779c5edf",
      "name": "Find Workflow",
      "type": "n8n-nodes-base.supabase",
      "position": [
        1472,
        320
      ],
      "parameters": {
        "limit": 1,
        "filters": {
          "conditions": [
            {
              "keyName": "n8n_workflow_id",
              "keyValue": "={{ $json.n8n_workflow_id }}",
              "condition": "eq"
            }
          ]
        },
        "tableId": "workflows",
        "operation": "getAll"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "7ebe8c3b-abab-4172-8e8b-a9ee486d2f49",
      "name": "Workflow Exists?",
      "type": "n8n-nodes-base.if",
      "position": [
        1696,
        240
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "8b3411c2-a260-4ce2-a260-6dda83a9fac0",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $input.first().json.workflow_id !== undefined }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "60ca18c6-b6ec-4347-a76a-e0f55dc43814",
      "name": "Insert Error",
      "type": "n8n-nodes-base.supabase",
      "position": [
        1920,
        144
      ],
      "parameters": {
        "tableId": "errors",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "workflow_id",
              "fieldValue": "={{ $('Find Workflow').item.json.workflow_id }}"
            },
            {
              "fieldId": "error_message",
              "fieldValue": "={{ $('Structure Error Data').item.json.error_message }}"
            },
            {
              "fieldId": "error_stack",
              "fieldValue": "={{ $('Structure Error Data').item.json.error_stack }}"
            },
            {
              "fieldId": "failed_node",
              "fieldValue": "={{ $('Structure Error Data').item.json.failed_node }}"
            },
            {
              "fieldId": "execution_id",
              "fieldValue": "={{ $('Structure Error Data').item.json.execution_id }}"
            },
            {
              "fieldId": "execution_url",
              "fieldValue": "={{ $('Structure Error Data').item.json.execution_url }}"
            },
            {
              "fieldId": "workflow_json",
              "fieldValue": "={{ $('Structure Error Data').item.json.workflow_json }}"
            },
            {
              "fieldId": "execution_data",
              "fieldValue": "={{ $('Structure Error Data').item.json.execution_data }}"
            }
          ]
        }
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0b99e408-3d1b-48f5-9ba8-d5836ddf00e9",
      "name": "Create Workflow",
      "type": "n8n-nodes-base.supabase",
      "position": [
        1920,
        336
      ],
      "parameters": {
        "tableId": "workflows",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "n8n_workflow_id",
              "fieldValue": "={{ $('Structure Error Data').item.json.n8n_workflow_id }}"
            },
            {
              "fieldId": "workflow_name",
              "fieldValue": "={{ $('Structure Error Data').item.json.workflow_name }}"
            }
          ]
        }
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6c7c77be-3624-46c5-a731-f86b2014d747",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2480,
        240
      ],
      "parameters": {
        "text": "=STEP 1: Use Context7 to search n8n documentation for: {{ $('Structure Error Data').item.json.failed_node }} node and error: {{ $('Structure Error Data').item.json.error_message }}\n\nSTEP 2: Analyze this n8n workflow error and provide a fix:\n\nWorkflow: {{ $('Structure Error Data').item.json.workflow_name }}\nFailed Node: {{ $('Structure Error Data').item.json.failed_node }}\nError: {{ $('Structure Error Data').item.json.error_message }}\n\nStack Trace:\n{{ $('Structure Error Data').item.json.error_stack }}\n\n``` OPTIONAL\nFull Workflow Structure:\n{{ $('Structure Error Data').item.json.workflow_json }}\n\nFull Execution Data:\n{{ $('Structure Error Data').item.json.execution_data }}\n``` OPTIONAL\n\nProvide:\n1. Root cause (2 sentences max)\n2. Specific fix (1 action with field names in backticks)  \n3. Prevention tip (1 sentence)\n\nKeep under 200 words.",
        "options": {
          "systemMessage": "=You are an n8n debugging specialist. \n\nCritical: You MUST use the Context7 tool to search official n8n documentation before providing any analysis. \n\nDo not respond without consulting the documentation.\n\nAfter researching via Context7, provide:\n\nCause:\n[2 sentences explaining what happened]\n\nFix:\n[One specific action with field names in `backticks`]\n\nPrevention:\n[One tip to avoid this]\n\nKeep under 200 words total."
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "3d08e9fe-fd4c-4167-b741-94f639bb374c",
      "name": "OpenRouter",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        2480,
        448
      ],
      "parameters": {
        "model": "anthropic/claude-sonnet-4",
        "options": {
          "maxTokens": 1000,
          "temperature": 0.3
        }
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1827da8b-9e2f-44ae-a51d-b39cb6591d0f",
      "name": "Context7",
      "type": "@n8n/n8n-nodes-langchain.mcpClientTool",
      "position": [
        2624,
        448
      ],
      "parameters": {
        "include": "selected",
        "options": {
          "timeout": 60000
        },
        "endpointUrl": "https://mcp.context7.com/mcp",
        "includeTools": [
          "resolve-library-id",
          "get-library-docs"
        ],
        "authentication": "headerAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "88590c63-17da-4955-8b70-39d1d7e51ee6",
      "name": "Save Analysis",
      "type": "n8n-nodes-base.supabase",
      "position": [
        2832,
        240
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "keyName": "error_id",
              "keyValue": "={{ $('Insert Error').item.json.error_id }}",
              "condition": "eq"
            }
          ]
        },
        "tableId": "errors",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "ai_analysis",
              "fieldValue": "={{ $('AI Agent').item.json.output }}"
            }
          ]
        },
        "operation": "update"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5dbf9eb2-e44b-47a0-8c77-eed45e88b07f",
      "name": "Format Notification",
      "type": "n8n-nodes-base.code",
      "position": [
        3168,
        240
      ],
      "parameters": {
        "jsCode": "const workflow = $('Find Workflow').item.json || $('Create Workflow').item.json;\nconst error = $('Insert Error').item.json;\nconst aiAnalysis = $('AI Agent').item.json.output;\n\nreturn [{\n  json: {    \n    workflow_name: workflow.workflow_name,\n    failed_node: error.failed_node,\n    error_message: error.error_message.substring(0, 300),\n    execution_url: error.execution_url,\n    ai_analysis: aiAnalysis,\n    error_id: error.error_id\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "315f1c62-c0bb-4ccf-8a1b-9aeafcc58a2a",
      "name": "Mark Notified",
      "type": "n8n-nodes-base.supabase",
      "position": [
        3824,
        240
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "keyName": "error_id",
              "keyValue": "={{ $('Insert Error').item.json.error_id }}",
              "condition": "eq"
            }
          ]
        },
        "tableId": "errors",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "notified",
              "fieldValue": true
            }
          ]
        },
        "operation": "update"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "da434f3e-644a-423d-aba8-4e5c13998250",
      "name": "Workflow Error",
      "type": "n8n-nodes-base.errorTrigger",
      "position": [
        464,
        240
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "eac72671-c9b9-4861-a519-d4e3738a5eac",
      "name": "Workflow Creation",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        2144,
        416
      ],
      "parameters": {
        "options": {}
      },
      "executeOnce": false,
      "typeVersion": 3
    },
    {
      "id": "c1905ec0-4323-4803-9b3d-3d7f79410a5f",
      "name": "Send Error Email",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        3600,
        240
      ],
      "parameters": {
        "html": "={{ $json.html_body }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "=Workflow Error: {{ $json.workflow_name }}"
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "5cbf6716-a734-4778-a760-bc5e615614ce",
      "name": "Update Statistics",
      "type": "n8n-nodes-base.supabase",
      "position": [
        2144,
        144
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "keyName": "workflow_id",
              "keyValue": "={{ $('Find Workflow').item.json.workflow_id }}",
              "condition": "eq"
            }
          ]
        },
        "tableId": "workflows",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "error_count",
              "fieldValue": "={{ ($('Find Workflow').item.json.error_count || 0) + 1 }}"
            },
            {
              "fieldId": "last_error_at",
              "fieldValue": "={{ $now.toISO() }}"
            }
          ]
        },
        "operation": "update"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "274a73ba-157b-40ad-856d-b09a181c2d94",
      "name": "Build HTML",
      "type": "n8n-nodes-base.code",
      "position": [
        3376,
        240
      ],
      "parameters": {
        "jsCode": "// Build Clean HTML Email\nconst data = $input.first().json;\n\n// Convert markdown bold to HTML and style section headers\nlet aiAnalysis = data.ai_analysis || '';\n\n// Remove AI preambles (multiple variations)\naiAnalysis = aiAnalysis.replace(/Based on (my research of )?the n8n documentation[,.]? I can now (provide the analysis|analyze your error)[:\\s]*/gi, '');\n\n// Replace **text** with <strong>text</strong>\naiAnalysis = aiAnalysis.replace(/\\*\\*(.+?)\\*\\*/g, '<strong>$1</strong>');\n\n// Convert ALL backticks to styled inline code\naiAnalysis = aiAnalysis.replace(/`+([^`]+?)`+/g, '<code style=\"background-color: #f3f4f6; padding: 3px 6px; border-radius: 3px; border: 1px solid #e5e5e5; font-family: \\'Courier New\\', monospace; font-size: 13px; color: #dc2626; white-space: nowrap;\">$1</code>');\n\n// Style section headers (both bold and plain)\nlet isFirstHeader = true;\naiAnalysis = aiAnalysis.replace(/(^|\\n)\\s*(?:<strong>)?(Root Cause|Cause|Fix|Prevention):(?:<\\/strong>)?/gim, function(match, prefix, header) {\n  const margin = isFirstHeader ? '0 0 6px 0' : '24px 0 6px 0';\n  isFirstHeader = false;\n  return prefix + '<p style=\"margin: ' + margin + '; font-size: 11px; color: #737373; font-weight: 600; text-transform: uppercase; letter-spacing: 1px;\">' + header + '</p>';\n});\n\n// Clean up any stray backticks\naiAnalysis = aiAnalysis.replace(/`/g, '');\n\nconst html = `\n<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"utf-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n</head>\n<body style=\"margin: 0; padding: 0; font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; background-color: #fafafa;\">\n  \n  <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"background-color: #fafafa;\">\n    <tr>\n      <td align=\"center\" style=\"padding: 48px 20px;\">\n        \n        <table width=\"600\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"background-color: #ffffff; border: 1px solid #e5e5e5;\">\n          \n          <tr>\n            <td style=\"padding: 40px 40px 32px 40px; border-bottom: 3px solid #ef4444;\">\n              <h1 style=\"margin: 0; font-size: 20px; font-weight: 600; color: #171717; letter-spacing: -0.5px;\">\n                Workflow Error\n              </h1>\n            </td>\n          </tr>\n          \n          <tr>\n            <td style=\"padding: 32px 40px 0 40px;\">\n              <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n                <tr>\n                  <td style=\"padding: 16px 20px; background-color: #fafafa; border-left: 3px solid #171717;\">\n                    <p style=\"margin: 0; font-size: 16px; font-weight: 600; color: #171717; letter-spacing: -0.3px;\">\n                      RAG Workflow\n                    </p>\n                  </td>\n                </tr>\n              </table>\n            </td>\n          </tr>\n          \n          <tr>\n            <td style=\"padding: 32px 40px;\">\n              <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n                <tr>\n                  <td style=\"padding-bottom: 20px;\">\n                    <p style=\"margin: 0; font-size: 11px; color: #737373; font-weight: 600; text-transform: uppercase; letter-spacing: 1px;\">\n                      Failed Node\n                    </p>\n                    <p style=\"margin: 6px 0 0 0; font-size: 14px; color: #404040; line-height: 1.6;\">\n                      ${data.failed_node}\n                    </p>\n                  </td>\n                </tr>\n                <tr>\n                  <td style=\"padding-top: 8px;\">\n                    <p style=\"margin: 0; font-size: 11px; color: #737373; font-weight: 600; text-transform: uppercase; letter-spacing: 1px;\">\n                      Error Message\n                    </p>\n                    <p style=\"margin: 6px 0 0 0; font-size: 14px; color: #404040; line-height: 1.6;\">\n                      ${data.error_message}\n                    </p>\n                  </td>\n                </tr>\n              </table>\n            </td>\n          </tr>\n          \n          <tr>\n            <td style=\"padding: 0 40px;\">\n              <div style=\"border-top: 1px solid #e5e5e5;\"></div>\n            </td>\n          </tr>\n          \n          <tr>\n            <td style=\"padding: 32px 40px;\">\n              <div style=\"font-size: 14px; color: #404040; line-height: 1.6;\">${aiAnalysis}</div>\n            </td>\n          </tr>\n          \n          <tr>\n            <td style=\"padding: 0 40px 40px 40px;\">\n              <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n                <tr>\n                  <td style=\"background-color: #171717;\">\n                    <a href=\"${data.execution_url}\" style=\"display: inline-block; padding: 14px 28px; font-size: 14px; font-weight: 600; color: #ffffff; text-decoration: none; letter-spacing: 0.3px;\">\n                      View Execution Details\n                    </a>\n                  </td>\n                </tr>\n              </table>\n            </td>\n          </tr>\n          \n          <tr>\n            <td style=\"padding: 24px 40px; background-color: #fafafa; border-top: 1px solid #e5e5e5;\">\n              <p style=\"margin: 0; font-size: 11px; color: #a3a3a3; letter-spacing: 0.3px;\">\n                Error ID: ${data.error_id}\n              </p>\n            </td>\n          </tr>\n          \n        </table>\n        \n      </td>\n    </tr>\n  </table>\n  \n</body>\n</html>\n`;\n\nreturn [{\n  json: {\n    ...data,\n    html_body: html\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "74b4bb97-9dbd-48a6-a03c-7a24ecc28694",
      "name": "Main Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        336,
        -944
      ],
      "parameters": {
        "width": 480,
        "height": 832,
        "content": "# AI-Powered Error Monitor\n\nAutomatically capture, analyze, and debug workflow failures using AI-powered insights from official n8n documentation.\n\n## How it works\n\n**Error Capture** \u2192 Triggered on any workflow failure, fetches complete error details and execution data\n\n**Smart Storage** \u2192 Logs errors in Supabase with workflow tracking and statistics\n\n**AI Analysis** \u2192 Claude Sonnet 4 searches official n8n docs via Context7, then diagnoses the root cause and suggests specific fixes\n\n**Email Notification** \u2192 Sends beautifully formatted email with error details, AI analysis, and direct link to failed execution\n\n## What you get\n\n\u2713 Root cause analysis in plain English\n\u2713 Specific fix instructions with field names\n\u2713 Prevention tips to avoid future errors\n\u2713 Error statistics and pattern tracking\n\u2713 Professional HTML email notifications\n\n## Requirements\n\n\u2022 Supabase account with database setup\n\u2022 OpenRouter API key (Claude Sonnet 4)\n\u2022 Context7 API key (n8n docs search)\n\u2022 SMTP email credentials\n\u2022 n8n API access enabled\n\n**Setup time:** 15 minutes"
      },
      "typeVersion": 1
    },
    {
      "id": "43530829-f23f-41df-b9bd-b2f116d9790c",
      "name": "Supabase Setup",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -432,
        512
      ],
      "parameters": {
        "color": 3,
        "width": 720,
        "height": 832,
        "content": "# Supabase Setup\n\nCopy this SQL into your Supabase SQL Editor and run it.\n\n**What this creates:**\n\u2022 `workflows` table - tracks each monitored workflow with error statistics\n\u2022 `errors` table - stores error details, stack traces, and AI analysis\n\u2022 Performance indexes for fast lookups\n\u2022 Row-level security enabled\n\n```\n-- Workflows: tracks monitored workflows\nCREATE TABLE workflows (\n  workflow_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),\n  n8n_workflow_id TEXT UNIQUE NOT NULL,\n  workflow_name TEXT NOT NULL,\n  error_count INTEGER DEFAULT 0,\n  last_error_at TIMESTAMPTZ,\n  created_at TIMESTAMPTZ DEFAULT now()\n);\n\n-- Errors: stores error details and AI analysis\nCREATE TABLE errors (\n  error_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),\n  workflow_id UUID REFERENCES workflows(workflow_id),\n  error_message TEXT NOT NULL,\n  error_stack TEXT,\n  failed_node TEXT NOT NULL,\n  execution_id TEXT NOT NULL,\n  execution_url TEXT,\n  workflow_json JSONB,\n  execution_data JSONB,\n  ai_analysis TEXT,\n  notified BOOLEAN DEFAULT false,\n  created_at TIMESTAMPTZ DEFAULT now()\n);\n\n-- Indexes\nCREATE INDEX idx_workflows_n8n_id ON workflows(n8n_workflow_id);\nCREATE INDEX idx_errors_workflow_id ON errors(workflow_id);\nCREATE INDEX idx_errors_created_at ON errors(created_at DESC);\n\n-- Security\nALTER TABLE workflows ENABLE ROW LEVEL SECURITY;\nALTER TABLE errors ENABLE ROW LEVEL SECURITY;\n```"
      },
      "typeVersion": 1
    },
    {
      "id": "e410a3f2-9c98-4445-9fd0-51846d8caa48",
      "name": "Setup Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -432,
        -944
      ],
      "parameters": {
        "color": 3,
        "width": 720,
        "height": 1408,
        "content": "# Setup Instructions\n\n## 1. Enable n8n API Access\n\n**Settings \u2192 API** \u2192 Enable API access\n\n**Create Credential:**\n- Type: n8n API\n- API Key: Copy from Settings \u2192 API\n- Base URL: Your n8n instance URL\n\n## 2. Supabase Database\n\n**Run the SQL** from \"Supabase Setup\"\n\n**Create Credential:**\n- Type: Supabase API\n- Host: Project URL (Settings \u2192 API)\n- Service Role Secret: `service_role` key (not anon)\n\n## 3. OpenRouter (Claude Sonnet 4)\n\n**Get API Key:** https://openrouter.ai/keys\n\n**Create Credential:**\n- Type: OpenRouter API\n- API Key: Paste your key\n\n**Cost:** ~$0.01 per error analysis\n\n## 4. Context7 (n8n Docs)\n\n**Get API Key:** https://context7.com\n\n**Create Credential:**\n- Type: Header Auth\n- Name: `Authorization`\n- Value: `Bearer YOUR_TOKEN_HERE`\n\n## 5. Email (SMTP server)\n\n**Update Email Node:**\n- Change `fromEmail` to your email\n- Change `toEmail` to where you want alerts\n- Configure SMTP credentials for your provider\n\n## 6. Activate Error Workflow\n\n**Activate this workflow** (toggle to ON)\n\nThen for EACH workflow you want to monitor:\n1. Open the workflow\n2. **Settings \u2192 Error Workflow**\n3. Select \"AI-Powered Error Monitor\"\n4. Save the workflow\n\n### Done! Errors trigger automatic AI analysis."
      },
      "typeVersion": 1
    },
    {
      "id": "b035b185-ab51-4736-b304-7d7b1160743a",
      "name": "Step 1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        336,
        -64
      ],
      "parameters": {
        "color": 7,
        "width": 992,
        "height": 728,
        "content": "## Step 1: Capture Error\n\nTriggered automatically when any workflow fails:\n\n- **Error Trigger** \u2192 Catches the failure\n- **Get Workflow** \u2192 Fetches workflow structure via n8n API\n- **Get Execution** \u2192 Retrieves execution details and stack trace\n- **Error Data** \u2192 Structures all error information for processing"
      },
      "typeVersion": 1
    },
    {
      "id": "f6e2b757-0255-4e5f-bebe-8ca536a014bb",
      "name": "Step 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1328,
        -64
      ],
      "parameters": {
        "color": 7,
        "width": 1024,
        "height": 728,
        "content": "## Step 2: Check Database\n\nLooks up workflow in Supabase:\n\n- **Find Workflow** \u2192 Searches for existing workflow record\n- **Workflow Exists?** \u2192 Routes to appropriate action\n- **Insert Error** \u2192 Logs error for existing workflow\n- **Create Workflow** \u2192 Creates new workflow entry if not found\n- **Update Statistics** \u2192 Increments error count and timestamp"
      },
      "typeVersion": 1
    },
    {
      "id": "449ec517-08e2-4618-bc52-824d8ab69775",
      "name": "Step 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3024,
        -64
      ],
      "parameters": {
        "color": 7,
        "width": 1024,
        "height": 728,
        "content": "## Step 4: Send Notification\n\nFormats and sends detailed error email:\n\n- **Format Notification** \u2192 Prepares error data for email\n- **Build HTML** \u2192 Creates professional styled email\n- **Send Error Email** \u2192 Delivers via SMTP\n- **Mark Notified** \u2192 Updates database to prevent duplicates"
      },
      "typeVersion": 1
    },
    {
      "id": "e98adab4-7ff4-4a5d-b57b-aaac2bb5b650",
      "name": "Step ",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2352,
        -64
      ],
      "parameters": {
        "color": 7,
        "width": 672,
        "height": 728,
        "content": "## Step 3: AI Analysis\n\nSmart debugging with Context7 n8n docs:\n\n- **AI Agent** \u2192 Analyzes error using Claude Sonnet 4\n- **Context7** \u2192 Searches official n8n documentation first\n- **OpenRouter** \u2192 Provides Claude Sonnet 4 access\n- **Save Analysis** \u2192 Stores AI-generated fix in database"
      },
      "typeVersion": 1
    },
    {
      "id": "25b4a579-1918-4910-883d-638fd0549357",
      "name": "Structure Error Data",
      "type": "n8n-nodes-base.code",
      "position": [
        1136,
        240
      ],
      "parameters": {
        "jsCode": "const errorTrigger = $('Workflow Error').item.json;\nconst workflowData = $('Get Workflow').item.json;\nconst executionData = $('Get Execution').item.json;\n\nreturn [{\n  json: {\n    n8n_workflow_id: errorTrigger.workflow.id,\n    workflow_name: errorTrigger.workflow.name,\n    error_message: errorTrigger.execution.error.message || 'Unknown error',\n    error_stack: errorTrigger.execution.error.stack || '',\n    failed_node: errorTrigger.execution.lastNodeExecuted || 'Unknown',\n    execution_id: errorTrigger.execution.id || 'manual',\n    execution_url: errorTrigger.execution.url || '',\n    workflow_json: JSON.stringify(workflowData),\n    execution_data: JSON.stringify(executionData)\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "c634d27a-3cd5-444e-9026-369a3be2e325",
      "name": "Quick Customization",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4096,
        -144
      ],
      "parameters": {
        "color": 6,
        "width": 560,
        "height": 896,
        "content": "# Optional Customization\n\n## Switch to Slack/Discord\n\n**1. Remove** the \"Build HTML\" node\n\n**2. Add** your preferred communication node (Slack, Discord, etc.)\n\n**3. Connect** \"Format Notification\" \u2192 Your Node \u2192 \"Mark Notified\"\n\n**4. Use this message expression:**\n\n```\n\ud83d\udea8 Workflow Error: {{ $json.workflow_name }}\n\n\u274c Failed Node: {{ $json.failed_node }}\n\n\ud83d\udcac Error Message: {{ $json.error_message }}\n\n\ud83e\udd16 AI Analysis: {{ $json.ai_analysis }}\n\n\ud83d\udd17 Execution: {{ $json.execution_url }}\n\n\ud83d\udcca Error ID: {{ $json.error_id }}\n```\n---\n\n## Reduce Token Cost (~50% savings)\n\n**In the AI Agent node, remove these lines from the user prompt:**\n\n```\nFull Workflow Structure:\n{{ $('Error Data').item.json.workflow_json }}\n\nFull Execution Data:\n{{ $('Error Data').item.json.execution_data }}\n```\n\n**Keep:** Complex multi-branch workflows\n\n**Remove:** Simple workflows, testing nodes"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Save Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Context7": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Build HTML": {
      "main": [
        [
          {
            "node": "Send Error Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get Workflow": {
      "main": [
        [
          {
            "node": "Get Execution",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Error": {
      "main": [
        [
          {
            "node": "Update Statistics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find Workflow": {
      "main": [
        [
          {
            "node": "Workflow Exists?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Execution": {
      "main": [
        [
          {
            "node": "Structure Error Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Analysis": {
      "main": [
        [
          {
            "node": "Format Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Error": {
      "main": [
        [
          {
            "node": "Get Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Workflow": {
      "main": [
        [
          {
            "node": "Workflow Creation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Error Email": {
      "main": [
        [
          {
            "node": "Mark Notified",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Exists?": {
      "main": [
        [
          {
            "node": "Insert Error",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Statistics": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Creation": {
      "main": [
        [],
        [
          {
            "node": "Find Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Notification": {
      "main": [
        [
          {
            "node": "Build HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structure Error Data": {
      "main": [
        [
          {
            "node": "Find Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}