{
  "name": "Vorlux AI | Smart Backlog Autofill",
  "nodes": [
    {
      "id": "00938268-581e-4a97-9881-7a530bfe1aa5",
      "name": "Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        220,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 1440
            }
          ]
        }
      }
    },
    {
      "id": "0afdf98f-ebf6-4949-acb9-dfcefdd2a4e5",
      "name": "Fetch Data",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        300
      ],
      "parameters": {
        "method": "GET",
        "url": "={{$env.VORLUX_HUB_URL}}/api/tasks?status=pending&limit=1",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "5cf4c682-9bfb-4810-be5e-1c1c2d7617af",
      "name": "Process",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        740,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const pending = $input.first().json.total || $input.first().json.data?.length || 0;\nconst needsFill = pending < 5;\nif (!needsFill) return [{json: {pending, needsFill: false, generated: 0}}];\n\n// Generate smart tasks based on what categories are underrepresented\nconst hubUrl = $env.VORLUX_HUB_URL || 'http://localhost:3010';\nlet categoryGaps = [];\ntry {\n  const res = await fetch(hubUrl + '/api/tasks/category-stats');\n  const stats = await res.json();\n  const categories = stats.data || {};\n  const targetPerCategory = 3;\n  for (const [cat, count] of Object.entries(categories)) {\n    if (count < targetPerCategory) {\n      categoryGaps.push({category: cat, deficit: targetPerCategory - count});\n    }\n  }\n} catch {}\n\n// Default categories if API fails\nif (!categoryGaps.length) {\n  categoryGaps = [\n    {category: 'content', deficit: 2},\n    {category: 'community', deficit: 1},\n    {category: 'streaming', deficit: 1},\n    {category: 'tech', deficit: 1}\n  ];\n}\n\nreturn [{json: {pending, needsFill: true, categoryGaps, tasksToGenerate: Math.min(5, categoryGaps.reduce((s, c) => s + c.deficit, 0))}}];"
      },
      "notes": "Checks backlog level and identifies underrepresented categories"
    },
    {
      "id": "00ac8237-f24a-494a-a358-2133751e7110",
      "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
        }
      }
    }
  ],
  "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
  }
}