{
  "name": "Vorlux AI | AI Model Regression Monitor (Auto-Fallback)",
  "nodes": [
    {
      "id": "c042ff58-786b-4a41-a8d1-10ba00c349ac",
      "name": "Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        220,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 1440
            }
          ]
        }
      }
    },
    {
      "id": "c36d601a-2eff-4221-88b7-de1f24cbf759",
      "name": "Fetch Data",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        300
      ],
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/admin/ai-providers/metrics",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "87b9319e-4623-40e6-8abd-199535429d15",
      "name": "Process",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        740,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const m=$input.first().json.data||{};\nconst issues=[];\nfor(const[name,d] of Object.entries(m)){if(d.avgLatencyMs>10000)issues.push({model:name,issue:'High latency',val:d.avgLatencyMs+'ms'});if(d.errorRate>0.1)issues.push({model:name,issue:'Error rate',val:Math.round(d.errorRate*100)+'%'});}\nreturn [{json:{issues,hasRegression:issues.length>0,checked:Object.keys(m).length}}];"
      }
    },
    {
      "id": "241bcc9f-2a9f-4e60-ba4e-eba1273097dd",
      "name": "Post Discord",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        980,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_OPS_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.embeds ? $json : {embeds:[{title:$json.mood||$json.status||\"Update\",description:JSON.stringify($json).substring(0,500),color:5793266}]}) }}",
        "options": {
          "timeout": 10000
        }
      }
    },
    {
      "id": "41a8ee7f-689a-4547-a4a4-cddcf37e8034",
      "name": "Activate Fallback",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1180,
        300
      ],
      "notes": "Switches to fallback model when regression detected",
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/admin/ai-providers/fallback",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"regressions\":{{ JSON.stringify($json.issues) }},\"action\":\"activate_fallback\"}",
        "options": {
          "timeout": 15000
        }
      }
    }
  ],
  "connections": {
    "Schedule": {
      "main": [
        [
          {
            "node": "Fetch Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Data": {
      "main": [
        [
          {
            "node": "Process",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process": {
      "main": [
        [
          {
            "node": "Post Discord",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true
  }
}