{
  "name": "SlideAI \u2014 05 Design Pipeline",
  "active": false,
  "nodes": [
    {
      "id": "ewt-d",
      "name": "When Called by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "parameters": {}
    },
    {
      "id": "get-slides-d",
      "name": "Get Slides for Design",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        280,
        0
      ],
      "parameters": {
        "url": "=https://yqpvjtwldnkoersgqoti.supabase.co/rest/v1/slides?project_id=eq.{{ $json.project_id }}&select=id,slide_type,has_image_slot&order=order_index",
        "method": "GET",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "supabaseApi",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Prefer",
              "value": "return=representation"
            }
          ]
        },
        "options": {}
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "id": "prep-design-prompt",
      "name": "Prepare Design Prompt",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        560,
        0
      ],
      "parameters": {
        "jsCode": "\nconst slides = items.map(i=>i.json);\nconst input  = $('When Called by Another Workflow').first().json;\nconst prompt = `Assign a layout and accent colour to each slide.\\nSlides: ${JSON.stringify(slides.map(s=>({id:s.id,slide_type:s.slide_type,has_image_slot:s.has_image_slot})))}\\n\\nLayout options: centered|left-aligned|two-column|full-image|stats-grid|quote-large\\nReturn JSON array: [{\"id\":\"\",\"layout\":\"\",\"accent_color\":\"#hexcode\"}]`;\nreturn [{ json: { project_id: input.project_id, slides, prompt } }];\n",
        "mode": "runOnceForAllItems"
      }
    },
    {
      "id": "design-review",
      "name": "Design Review Agent \u2014 Groq",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        840,
        0
      ],
      "parameters": {
        "url": "https://api.groq.com/openai/v1/chat/completions",
        "method": "POST",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "groqApi",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "string",
        "body": "={{ JSON.stringify({ model: 'llama-3.3-70b-versatile', temperature: 0.7, max_tokens: 4096, messages: [{ role: 'system', content: \"You are a presentation design expert. Return JSON array only. No markdown.\" }, { role: 'user', content: =$json.prompt }] }) }}",
        "options": {}
      },
      "credentials": {
        "groqApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "id": "image-handler",
      "name": "Image Handler Agent",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1120,
        0
      ],
      "parameters": {
        "jsCode": "\nconst raw  = items[0].json.choices?.[0]?.message?.content??'[]';\nlet designs;\ntry { designs=JSON.parse(raw.replace(/```json?\\n?/g,'').replace(/```/g,'').trim()); }\ncatch(e){ designs=[]; }\nreturn designs.map(d=>({ json: {...d, image_url: null} }));\n",
        "mode": "runOnceForAllItems"
      }
    },
    {
      "id": "upd-slide-design",
      "name": "Update Slide Design \u2014 Supabase",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1400,
        0
      ],
      "parameters": {
        "url": "=https://yqpvjtwldnkoersgqoti.supabase.co/rest/v1/slides?id=eq.{{ $json.id }}",
        "method": "PATCH",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "supabaseApi",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Prefer",
              "value": "return=representation"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "string",
        "body": "={\"layout\":\"{{ $json.layout }}\",\"accent_color\":\"{{ $json.accent_color }}\"}",
        "options": {}
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "When Called by Another Workflow": {
      "main": [
        [
          {
            "node": "Get Slides for Design",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Slides for Design": {
      "main": [
        [
          {
            "node": "Prepare Design Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Design Prompt": {
      "main": [
        [
          {
            "node": "Design Review Agent \u2014 Groq",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Design Review Agent \u2014 Groq": {
      "main": [
        [
          {
            "node": "Image Handler Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Image Handler Agent": {
      "main": [
        [
          {
            "node": "Update Slide Design \u2014 Supabase",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}