{
  "name": "General Parsing Agent",
  "nodes": [
    {
      "id": "ManualTrigger",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        200,
        200
      ]
    },
    {
      "id": "WebhookTrigger",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        200,
        0
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "parse",
        "responseMode": "onReceived",
        "options": {
          "binaryData": true
        }
      }
    },
    {
      "id": "FolderWatch",
      "name": "Watch Folder",
      "type": "n8n-nodes-base.watchFilesystem",
      "typeVersion": 1,
      "position": [
        200,
        400
      ],
      "parameters": {
        "path": "/srv/dev-disk-by-uuid-537f57a7-b319-4227-9798-8ebfd4681f71/data/huntdata/inbox",
        "polling": true,
        "interval": 60
      }
    },
    {
      "id": "LoadFile",
      "name": "Load File",
      "type": "n8n-nodes-base.readBinaryFile",
      "typeVersion": 1,
      "position": [
        450,
        400
      ],
      "parameters": {
        "filePath": "={{$json[\"path\"]}}"
      }
    },
    {
      "id": "NormalizeInput",
      "name": "Normalize Input",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        700,
        200
      ],
      "parameters": {
        "functionCode": "return [{ binary: { data: items[0].binary?.data || items[0].binary?.file } }];"
      }
    },
    {
      "id": "SendToParser",
      "name": "Send to Parser",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        950,
        200
      ],
      "parameters": {
        "url": "http://pdfparser:8777/parse",
        "method": "POST",
        "sendBinaryData": true,
        "binaryPropertyName": "data"
      }
    },
    {
      "id": "SaveJSON",
      "name": "Save JSON",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        1200,
        200
      ],
      "parameters": {
        "fileName": "={{$now.toISO()}}.json",
        "filePath": "/srv/dev-disk-by-uuid-537f57a7-b319-4227-9798-8ebfd4681f71/data/huntdata/parsed",
        "dataPropertyName": "data"
      }
    },
    {
      "id": "OptionalLLM",
      "name": "LLM Summary (On Demand)",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1450,
        200
      ],
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$json[\"summarize\"]}}",
              "value2": true
            }
          ]
        }
      }
    },
    {
      "id": "LLMCall",
      "name": "Call LLM",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1700,
        100
      ],
      "parameters": {
        "url": "http://ollama:11434/api/generate",
        "method": "POST",
        "jsonParameters": true,
        "body": {
          "model": "llama3",
          "prompt": "Summarize the following parsed document:\\n\\n{{$json}}"
        }
      }
    },
    {
      "id": "ReturnResponse",
      "name": "Return Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1700,
        300
      ],
      "parameters": {
        "responseBody": "={{$json}}"
      }
    }
  ],
  "connections": {
    "ManualTrigger": {
      "main": [
        [
          {
            "node": "NormalizeInput",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WebhookTrigger": {
      "main": [
        [
          {
            "node": "NormalizeInput",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "FolderWatch": {
      "main": [
        [
          {
            "node": "LoadFile",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LoadFile": {
      "main": [
        [
          {
            "node": "NormalizeInput",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NormalizeInput": {
      "main": [
        [
          {
            "node": "SendToParser",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SendToParser": {
      "main": [
        [
          {
            "node": "SaveJSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SaveJSON": {
      "main": [
        [
          {
            "node": "OptionalLLM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OptionalLLM": {
      "main": [
        [
          {
            "node": "LLMCall",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "ReturnResponse",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LLMCall": {
      "main": [
        [
          {
            "node": "ReturnResponse",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}