{
  "name": "Vorlux AI | AI Blog Post Generator (Multi-Pass)",
  "nodes": [
    {
      "id": "4c429218-6b3c-4b89-b159-d372b9860248",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        220,
        300
      ],
      "webhookId": "28a026e9-c377-44ba-b735-1c7f17040f67",
      "parameters": {
        "httpMethod": "POST",
        "path": "generate-blog",
        "options": {
          "responseMode": "lastNode"
        }
      }
    },
    {
      "id": "0fa16e2b-4ddc-4bcc-a1a9-ef22a8d42406",
      "name": "Generate",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/orchestrator/execute",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"agentId\":\"content-writer\",\"action\":\"generate_blog\",\"params\":{\"keywords\":\"{{ $json.body?.keywords || $json.keywords }}\",\"length\":1500}}",
        "options": {
          "timeout": 120000
        }
      }
    },
    {
      "id": "86724b5a-ae2c-4740-b038-f1e9bac02989",
      "name": "Quality Gate",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        700,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const r=$input.first().json.data?.result||'';const wc=r.split(/\\s+/).length;return [{json:{content:r,wordCount:wc,passed:wc>=400&&r.includes('#')}}];"
      }
    },
    {
      "id": "49ce56a6-89b9-4f59-aa45-007b5a992688",
      "name": "Save",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        940,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/blog/posts",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"title\":\"{{ $json.body?.keywords || \"Draft\" }}\",\"content\":{{ JSON.stringify($json.content) }},\"status\":\"draft\"}",
        "options": {
          "timeout": 15000
        }
      }
    },
    {
      "id": "d9b50c51-6612-4722-9ecc-15ee5f4e38e2",
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1180,
        300
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ok:$json.passed,words:$json.wordCount}) }}"
      }
    },
    {
      "id": "4c7960b8-b76d-47b5-b6de-a119fa048ffe",
      "name": "AI Review",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        940,
        160
      ],
      "notes": "Second pass: content-writer reviews and enhances the draft",
      "parameters": {
        "method": "POST",
        "url": "={{$env.VORLUX_HUB_URL}}/api/orchestrator/execute",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"agentId\":\"content-writer\",\"action\":\"review_and_enhance\",\"params\":{\"content\":{{ JSON.stringify($json.content) }},\"instructions\":\"Review this article. Fix any factual errors, add more specific examples, ensure headers are used, and expand thin sections. Return the improved version.\"}}",
        "options": {
          "timeout": 120000
        }
      }
    },
    {
      "id": "ca6bba6b-6f1c-4442-bbe1-6dcf5012470b",
      "name": "Enhanced QA",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1180,
        160
      ],
      "notes": "Final quality check: word count, headers, links, readability",
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const enhanced = $input.first().json.data?.result || $input.first().json.content || '';\nconst wc = enhanced.split(/\\s+/).length;\nconst headers = (enhanced.match(/^#{1,3}\\s/gm) || []).length;\nconst hasCode = enhanced.includes('```');\nconst paragraphs = enhanced.split(/\\n\\n/).filter(Boolean).length;\nconst score = (wc >= 800 ? 3 : wc >= 400 ? 2 : 1) + (headers >= 3 ? 2 : 1) + (paragraphs >= 5 ? 1 : 0) + (hasCode ? 1 : 0);\nreturn [{json: {content: enhanced, wordCount: wc, headers, paragraphs, qualityScore: score, maxScore: 7, passed: score >= 4}}];"
      }
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Generate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate": {
      "main": [
        [
          {
            "node": "Quality Gate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Quality Gate": {
      "main": [
        [
          {
            "node": "AI Review",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Review": {
      "main": [
        [
          {
            "node": "Enhanced QA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enhanced QA": {
      "main": [
        [
          {
            "node": "Save",
            "type": "main",
            "index": 0
          },
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true
  }
}