{
  "nodes": [
    {
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -4896,
        320
      ]
    },
    {
      "name": "Webhook: Custom Range",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -4960,
        512
      ]
    },
    {
      "name": "Run Config",
      "type": "n8n-nodes-base.code",
      "position": [
        -4512,
        432
      ]
    },
    {
      "name": "Fetch Sales",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -4288,
        432
      ]
    },
    {
      "name": "Fetch Delivery",
      "type": "n8n-nodes-base.airtable",
      "position": [
        -4064,
        432
      ]
    },
    {
      "name": "Fetch People Ops",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -3840,
        432
      ]
    },
    {
      "name": "Clean Sources",
      "type": "n8n-nodes-base.code",
      "position": [
        -3632,
        432
      ]
    },
    {
      "name": "Upsert Sales Records",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -3408,
        304
      ]
    },
    {
      "name": "Upsert Delivery Records",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -3184,
        304
      ]
    },
    {
      "name": "Upsert People Records",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -2960,
        304
      ]
    },
    {
      "name": "Compute Metrics",
      "type": "n8n-nodes-base.code",
      "position": [
        -2752,
        304
      ]
    },
    {
      "name": "Create Run",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -2304,
        304
      ]
    },
    {
      "name": "Build Analysis Prompt",
      "type": "n8n-nodes-base.code",
      "position": [
        -2096,
        128
      ]
    },
    {
      "name": "Claude: Analyse",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        -1952,
        0
      ]
    },
    {
      "name": "Claude Sonnet",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "position": [
        -1856,
        208
      ]
    },
    {
      "name": "Parse Insights",
      "type": "n8n-nodes-base.code",
      "position": [
        -1616,
        0
      ]
    },
    {
      "name": "Build Supabase Payloads",
      "type": "n8n-nodes-base.code",
      "position": [
        -1424,
        112
      ]
    },
    {
      "name": "Insert Metrics",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1216,
        80
      ]
    },
    {
      "name": "Insert Warnings",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -976,
        64
      ]
    },
    {
      "name": "Insert Insights",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -752,
        64
      ]
    },
    {
      "name": "Complete Run",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -528,
        64
      ]
    },
    {
      "name": "Mark Run Failed",
      "type": "n8n-nodes-base.code",
      "position": [
        -1456,
        720
      ]
    },
    {
      "name": "Close Failed Run",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1200,
        720
      ]
    },
    {
      "name": "Loop Over Periods",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -432,
        496
      ]
    },
    {
      "name": "All Periods Complete",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -224,
        192
      ]
    },
    {
      "name": "Find Prior Insight",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        112,
        288
      ]
    },
    {
      "name": "Decide Reuse",
      "type": "n8n-nodes-base.code",
      "position": [
        320,
        288
      ]
    },
    {
      "name": "Reuse Insight?",
      "type": "n8n-nodes-base.if",
      "position": [
        544,
        288
      ]
    },
    {
      "name": "Fetch Run Digest",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        0,
        0
      ]
    },
    {
      "name": "Build Digest",
      "type": "n8n-nodes-base.code",
      "position": [
        224,
        0
      ]
    },
    {
      "name": "Send Digest",
      "type": "n8n-nodes-base.gmail",
      "position": [
        448,
        0
      ]
    },
    {
      "name": "Record Alert Sent",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        672,
        0
      ]
    },
    {
      "name": "Close Abandoned Runs",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -4640,
        208
      ]
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Close Abandoned Runs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook: Custom Range": {
      "main": [
        [
          {
            "node": "Run Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Config": {
      "main": [
        [
          {
            "node": "Fetch Sales",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Sales": {
      "main": [
        [
          {
            "node": "Fetch Delivery",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Delivery": {
      "main": [
        [
          {
            "node": "Fetch People Ops",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch People Ops": {
      "main": [
        [
          {
            "node": "Clean Sources",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean Sources": {
      "main": [
        [
          {
            "node": "Upsert Sales Records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert Sales Records": {
      "main": [
        [
          {
            "node": "Upsert Delivery Records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert Delivery Records": {
      "main": [
        [
          {
            "node": "Upsert People Records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert People Records": {
      "main": [
        [
          {
            "node": "Compute Metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compute Metrics": {
      "main": [
        [
          {
            "node": "Loop Over Periods",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Run": {
      "main": [
        [
          {
            "node": "Find Prior Insight",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Analysis Prompt": {
      "main": [
        [
          {
            "node": "Claude: Analyse",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claude: Analyse": {
      "main": [
        [
          {
            "node": "Parse Insights",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Mark Run Failed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claude Sonnet": {
      "ai_languageModel": [
        [
          {
            "node": "Claude: Analyse",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Parse Insights": {
      "main": [
        [
          {
            "node": "Build Supabase Payloads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Supabase Payloads": {
      "main": [
        [
          {
            "node": "Insert Metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Metrics": {
      "main": [
        [
          {
            "node": "Insert Warnings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Warnings": {
      "main": [
        [
          {
            "node": "Insert Insights",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Insights": {
      "main": [
        [
          {
            "node": "Complete Run",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mark Run Failed": {
      "main": [
        [
          {
            "node": "Close Failed Run",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Periods": {
      "main": [
        [
          {
            "node": "All Periods Complete",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Run",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Complete Run": {
      "main": [
        [
          {
            "node": "Loop Over Periods",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Close Failed Run": {
      "main": [
        [
          {
            "node": "Loop Over Periods",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find Prior Insight": {
      "main": [
        [
          {
            "node": "Decide Reuse",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decide Reuse": {
      "main": [
        [
          {
            "node": "Reuse Insight?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reuse Insight?": {
      "main": [
        [
          {
            "node": "Build Supabase Payloads",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Build Analysis Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "All Periods Complete": {
      "main": [
        [
          {
            "node": "Fetch Run Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Run Digest": {
      "main": [
        [
          {
            "node": "Build Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Digest": {
      "main": [
        [
          {
            "node": "Send Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Digest": {
      "main": [
        [
          {
            "node": "Record Alert Sent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Close Abandoned Runs": {
      "main": [
        [
          {
            "node": "Run Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
