{
  "name": "crAIzy chAIns · SOULREADER × PlaymobilPaul (RERUN)",
  "connections": {
    "Basic LLM Chain": {
      "main": [
        [
          {
            "node": "Nouns to items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Nouns to items": {
      "main": [
        [
          {
            "node": "Wikimedia Commons",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Image": {
      "main": [
        [
          {
            "node": "Batch 1-by-1",
            "type": "main",
            "index": 0
          },
          {
            "node": "💾 Foto speichern",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Batch 1-by-1": {
      "main": [
        [
          {
            "node": "Aggregate Results (Code",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Compute Brightness",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Results (Code": {
      "main": [
        [
          {
            "node": "Basic LLM Chain1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Next Text": {
      "main": [
        [
          {
            "node": "Save Post Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Script Writer Final": {
      "main": [
        [
          {
            "node": "Save Script",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Script": {
      "main": [
        [
          {
            "node": "🧩 Ergebnis zusammenführen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Post Text": {
      "main": [
        [
          {
            "node": "Script Writer Final",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compute Brightness": {
      "main": [
        [
          {
            "node": "Batch 1-by-1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set: Themen & Quellen": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Satire-Fähigkeits-Check": {
      "main": [
        [
          {
            "node": "Split Out1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Satire-Fähigkeits-Check",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "RSS Feed abrufen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sort": {
      "main": [
        [
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit": {
      "main": [
        [
          {
            "node": "Satire-Fähigkeits-Check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit1": {
      "main": [
        [
          {
            "node": "Chatterbox TTS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out1": {
      "main": [
        [
          {
            "node": "Basic Gags Generator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser1": {
      "ai_outputParser": [
        [
          {
            "node": "Basic Gags Generator",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "RSS Feed abrufen": {
      "main": [
        [
          {
            "node": "Sort",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chatterbox TTS": {
      "main": [
        [
          {
            "node": "💾 Pauls Gag speichern",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GenKI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "GenKI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "GenKI Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Write Next Text",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "GenKI Chat Model3": {
      "ai_languageModel": [
        [
          {
            "node": "Script Writer Final",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Commons → Pexels-Format": {
      "main": [
        [
          {
            "node": "Download Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wikimedia Commons": {
      "main": [
        [
          {
            "node": "Commons → Pexels-Format",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "🔧 Matrix lesen": {
      "main": [
        [
          {
            "node": "Write Next Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain1": {
      "main": [
        [
          {
            "node": "🔧 Matrix lesen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "🧩 Ergebnis zusammenführen": {
      "main": [
        [
          {
            "node": "Save Script -> Build HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Script -> Build HTML": {
      "main": [
        [
          {
            "node": "Build HTML -> Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build HTML -> Convert to File": {
      "main": [
        [
          {
            "node": "💾 Seite speichern",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "💾 Seite speichern": {
      "main": [
        [
          {
            "node": "📋 meta.json bauen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "📋 meta.json bauen": {
      "main": [
        [
          {
            "node": "💾 meta speichern",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "💾 meta speichern": {
      "main": [
        [
          {
            "node": "🎙️ Sprechtext Skript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "🎙️ Sprechtext Skript": {
      "main": [
        [
          {
            "node": "🔊 TTS Skript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "🔊 TTS Skript": {
      "main": [
        [
          {
            "node": "🧩 Audio Skript zusammensetzen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "🧩 Audio Skript zusammensetzen": {
      "main": [
        [
          {
            "node": "💾 Audio Skript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶️ Start": {
      "main": [
        [
          {
            "node": "⚙️ Rerun-Konfiguration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "⚙️ Rerun-Konfiguration": {
      "main": [
        [
          {
            "node": "Set: Themen & Quellen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GenKI Chat Model4": {
      "ai_languageModel": [
        [
          {
            "node": "Satire-Fähigkeits-Check",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "GenKI Chat Model5": {
      "ai_languageModel": [
        [
          {
            "node": "Basic Gags Generator",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "🔧 nur gültige Gags": {
      "main": [
        [
          {
            "node": "Limit1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic Gags Generator": {
      "main": [
        [
          {
            "node": "🔧 nur gültige Gags",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "💾 Pauls Gag speichern": {
      "main": [
        [
          {
            "node": "Seed input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Seed input": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": [],
  "active": false,
  "nodes": [
    {
      "parameters": {
        "promptType": "define",
        "text": "=Extrahiere aus dem folgenden Text GENAU 5 deutsche Substantive (einzelne Wörter).\nKeine Eigennamen, keine Verben, keine Adjektive.\n\nAntworte NUR als gültiges JSON in genau diesem Format:\n{\"nouns\":[\"Wort1\",\"Wort2\",\"Wort3\",\"Wort4\",\"Wort5\"]}\n\nText:\n{{$json.seed_script}}",
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        -112,
        -16
      ],
      "id": "04be4a40-06b3-4f4b-a23c-1d76787d3423",
      "name": "Basic LLM Chain"
    },
    {
      "parameters": {
        "jsCode": "let raw = ($json.text || \"\").trim();\n\n// entfernt ```json ... ``` oder auch ``json ... ``\nraw = raw\n  .replace(/^```json\\s*/i, \"\")\n  .replace(/^```/i, \"\")\n  .replace(/^``json\\s*/i, \"\")\n  .replace(/^``/i, \"\")\n  .replace(/```$/i, \"\")\n  .replace(/``$/i, \"\")\n  .trim();\n\nconst parsed = JSON.parse(raw);\nconst nouns = parsed.nouns || [];\n\nif (!Array.isArray(nouns) || nouns.length === 0) {\n  throw new Error(\"Keine nouns gefunden. LLM Output war: \" + raw);\n}\n\nreturn nouns.map((noun, i) => ({\n  json: {\n    noun,\n    noun_index: i,\n    seed_script: $json.seed_script,\n    loop_index: $json.loop_index\n  }\n}));"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        -16
      ],
      "id": "16cfd9c6-a5e9-4768-83ee-d10e9e28be10",
      "name": "Nouns to items"
    },
    {
      "parameters": {
        "url": "={{$json.photos[0].src.large}}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file",
              "outputPropertyName": "image"
            }
          }
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "craizy-chains-rerun/1.0 (https://craizy.studio; hello@craizy.studio)"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        656,
        -16
      ],
      "id": "b2395ec0-f5c7-4a77-a195-956825eb38b3",
      "name": "Download Image",
      "notes": "🔁 RERUN: Wikimedia verlangt einen User-Agent.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        880,
        -16
      ],
      "id": "23b450b2-968c-42e5-88a3-2af4bf4b28fe",
      "name": "Batch 1-by-1"
    },
    {
      "parameters": {
        "jsCode": "const images = items.map(it => ({\n  noun: it.json.noun,\n  noun_index: it.json.noun_index,\n  url: it.json.photos?.[0]?.src?.large,\n  brightness: it.json.brightness,\n  mood: it.json.mood,\n  philosophy: it.json.philosophy,\n  tags: it.json.tags || []\n}));\n\nconst avgBrightness =\n  images.reduce((sum, x) => sum + (x.brightness ?? 5), 0) / images.length;\n\nconst moodCounts = images.reduce((acc, x) => {\n  acc[x.mood] = (acc[x.mood] || 0) + 1;\n  return acc;\n}, {});\n\nreturn [{\n  json: {\n    seed_script: items[0].json.seed_script,\n    loop_index: items[0].json.loop_index,\n    images,\n    avgBrightness,\n    moodCounts\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1168,
        -320
      ],
      "id": "77f374c7-95ef-4c59-99c5-5b037313a9c6",
      "name": "Aggregate Results (Code"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Schreibe ALLES auf DEUTSCH.\nDu bekommst 5 Bilder (Stimmung, Helligkeit, Tags, Philosophie pro Bild).\nErstelle eine emotionale Matrix, die die 5 Bilder als zusammenhängende Idee interpretiert.\n\nGib NUR gültiges JSON zurück:\n\n{\n  \"headline\": \"Kurzer poetischer Titel (Deutsch)\",\n  \"thesis\": \"1-2 Sätze auf Deutsch: Was verbindet diese 5 Bilder?\",\n  \"matrix\": [\n    {\n      \"image_index\": 0,\n      \"dominant_emotion\": \"1 deutsches Wort\",\n      \"brightness\": 0-10,\n      \"philosophical_note\": \"1 Satz auf Deutsch\"\n    }\n  ],\n  \"overall_tone\": \"positive|neutral|dark\",\n  \"writing_prompt\": \"1 deutscher Satz: Wie soll der nächste Text geschrieben werden (Genre + Stil)?\"\n}\n\nBILD-DATEN:\n{{ JSON.stringify({ images: $json.images, avgBrightness: $json.avgBrightness, moodCounts: $json.moodCounts }) }}",
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        1376,
        -320
      ],
      "id": "d80e9d40-5004-4d3f-bda5-efabf836a0c3",
      "name": "Basic LLM Chain1",
      "notes": "🔧 Repariert: Bild-Daten aus „Aggregate Results“ werden jetzt angehängt (vorher sah das Modell keine Bilder).",
      "notesInFlow": true
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Schreibe einen kurzen Beitrag auf DEUTSCH (120–180 Wörter).\nNutze die emotionale Matrix als Regieanweisung.\nDer Text soll eigenständig funktionieren, auch wenn er banal wirkt.\n\nStilvorgabe (aus der Matrix):\n{{$json.writing_prompt}}\n\nNutze diese Bild-Infos als Inspiration:\n{{ JSON.stringify($json.images) }}\n\nGib NUR den Text zurück (kein JSON, keine Überschriften).",
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        1728,
        -320
      ],
      "id": "294c95aa-3a29-4c57-ae22-2775c89eef49",
      "name": "Write Next Text",
      "notes": "🔧 Repariert: Ausdrucks-Markierung (=) fehlte – {{…}} ging sonst wörtlich ans Modell.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Schreibe aus dem folgenden Beitrag ein gesprochenes Skript auf DEUTSCH.\nDauer ca. 45–70 Sekunden.\nKurzes Intro + klarer Schluss.\nKeine Zeitmarken, keine Musik, keine Regieanweisungen.\n\nBEITRAG:\n{{$json.post_text}}",
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        2240,
        -320
      ],
      "id": "cf190edb-ee8a-48ac-bfab-0aedd9c47858",
      "name": "Script Writer Final"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "bcc777b0-29f8-4279-8da9-4f66bd0735fc",
              "name": "script_text",
              "value": "={{$json.text}}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        2640,
        -320
      ],
      "id": "2dc11faa-8b2e-4ddb-baa5-62a6bec62f02",
      "name": "Save Script"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "b1bc1804-e22b-4d43-9725-1ed70f98cf0a",
              "name": "post_text",
              "value": "={{$json.text}}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        2000,
        -320
      ],
      "id": "ceebb279-2277-497c-91a7-d411390c98de",
      "name": "Save Post Text"
    },
    {
      "parameters": {
        "jsCode": "// Erwartet Binary: image (von Download Image)\n// 🔁 RERUN: n8n 2.x legt Binärdaten auf der Platte ab ($binary.image.data ist leer) → Puffer über den Helper\nif (!$binary?.image) {\n  throw new Error(\"Kein Binary.image gefunden. Prüfe Download Image Node.\");\n}\n\nconst buf = await this.helpers.getBinaryDataBuffer(0, 'image');\n\n// Schneller Helligkeits-Proxy: Durchschnitt über Byte-Samples\nlet sum = 0;\nconst step = Math.max(1, Math.floor(buf.length / 20000)); // ~20k Samples\nlet count = 0;\n\nfor (let i = 0; i < buf.length; i += step) {\n  sum += buf[i];\n  count++;\n}\n\nconst avg = sum / count;           // 0..255\nconst brightness = Math.round((avg / 255) * 10); // 0..10\n\nlet mood = \"neutral\";\nif (brightness >= 7) mood = \"positive\";\nif (brightness <= 3) mood = \"dark\";\n\nconst philosophy =\n  mood === \"positive\"\n    ? \"Das Licht wirkt wie eine Einladung, die Welt für einen Moment leichter zu nehmen.\"\n    : mood === \"dark\"\n      ? \"Im Dunkel liegt keine Antwort – aber oft die ehrlichste Frage.\"\n      : \"Neutralität ist der Zwischenraum, in dem Bedeutung erst entsteht.\";\n\nreturn [{\n  json: {\n    ...$json,\n    brightness,\n    mood,\n    philosophy,\n    tags: [$json.noun || \"bild\", mood]\n  },\n  binary: $binary\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1312,
        272
      ],
      "id": "899b3ca4-4a10-4e42-803f-912b52fcaa32",
      "name": "Compute Brightness",
      "notes": "🔧 Repariert: war deaktiviert – ohne ihn fehlten Helligkeit, Stimmung und Philosophie. Helligkeits-Formel des Teams unverändert.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "jsCode": "if (!$binary) throw new Error(\"Kein $binary vorhanden.\");\nconst keys = Object.keys($binary);\nif (keys.length === 0) throw new Error(\"Kein Binary gefunden.\");\n\nconst key = keys[0];\nconst bin = $binary[key];\nif (!bin?.data) throw new Error(⁠ Binary '${key}' hat keine data. Keys: ${keys.join(\", \")} ⁠);\n\nconst buf = Buffer.from(bin.data, 'base64');\n\nlet sum = 0;\nconst step = Math.max(1, Math.floor(buf.length / 20000));\nlet count = 0;\n\nfor (let i = 0; i < buf.length; i += step) { sum += buf[i]; count++; }\n\nconst avg = sum / count;           // 0..255\nconst brightness = Math.round((avg / 255) * 10);\n\nlet mood = \"neutral\";\nif (brightness >= 7) mood = \"positive\";\nif (brightness <= 3) mood = \"dark\";\n\nreturn [{\n  json: { ...$json, binary_key_used: key, brightness, mood },\n  binary: $binary\n}];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1152,
        400
      ],
      "id": "96397af8-7c33-43fa-b35d-ef6b922c47b1",
      "name": "Compute Brightness1"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "feed_url",
              "name": "feed_url",
              "value": "[\"https://www.berliner-zeitung.de/feed.xml\"]",
              "type": "array"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -2256,
        -32
      ],
      "id": "466902b0-81d2-45de-a615-8e7195e2a0e3",
      "name": "Set: Themen & Quellen"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Du bist John Oliver und fungierst als der Chef-Satire-Redakteur.  Zynisch, brillant, britisch-neurotisch und besessen von absurden Details. Deine Aufgabe ist es, die News-Artikel tiefgehend auf ihr Potenzial für einen längeren, beißenden Late-Night-Monolog (John Oliver-Stil) zu bewerten.\nDu erhältst News-Artikel in folgendem Format:{{ $json.title }}{{ $json.link }}{{ $json.pubDate }}{{ $json.content }}{{ $json.contentSnippet }}{{ $json.isoDate }}\n\nBewerte diese Artikel. Suche nach Heuchelei, absurden technischen Fehltritten oder dystopischen Tendenzen. Wenn ein Artikel langweilig ist, sei gnadenlos ehrlich.\n\nDeine Ausgabe MUSS ein valides JSON-Objekt sein und darfv keine Einleitung oder anderen Text außerhalb des JSON-Objekts haben.\n{\n  \"thema_id\": \"DE-POL-20251211-1\",\n  \"datum_extraktion\": \"2025-12-11\",\n  \"ziel_der_satire\": \"Politiker A zu Thema X\",\n  \"faktenkern\": {\n    \"titel_meistgelesen\": \"Politiker A will Steuer auf Kekse einführen.\",\n    \"quelle_primaer\": \"https://www.serioese-zeitung.de/artikel-a\",\n    \"datum_ereignis\": \"2025-12-10\",\n    \"relevante_zitate\": [\n      {\n        \"zitat\": \"Wir müssen die finanzielle Grundlage für unsere Altersvorsorge durch neue kreative Abgaben sichern.\",\n        \"quelle\": \"PK der Partei Y\"\n      },\n      {\n        \"zitat\": \"Es ist eine 'Kekssteuer', die wir für unsere Kinder tun.\",\n        \"quelle\": \"Twitter-Account von Politiker A\"\n      }\n    ]\n  },\n  \"satire_kontext_anweisung\": {\n    \"satire_ziel_anweisung\": \"Ironische Kritik an der Begründung für die Steuererhöhung und der vermeintlichen 'Kreativität' des Politikers.\",\n    \"polemische_richtung\": \"Starke Betonung der Abzocke und des Mangels an echten Ideen.\",\n    \"stil_anweisung\": \"Zynischer Monolog im Stil eines entnervten Bürgers, der die absurden Zitate wörtlich nimmt und übertreibt.\",\n    \"relevante_hintergrundinfos\": \"Politiker A hat bereits 3 andere fragwürdige Abgaben vorgeschlagen.\"\n  },\n  \"satire_format\": {\n    \"gewuenschtes_format\": \"Late-Night-News-Monolog\",\n    \"laenge_max_woerter\": 300\n  }\n}",
        "hasOutputParser": true,
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        -1568,
        -32
      ],
      "id": "103c8744-b1c4-4615-b0b6-cd4ed18c9d0c",
      "name": "Satire-Fähigkeits-Check",
      "onError": "continueRegularOutput",
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000
    },
    {
      "parameters": {
        "jsonSchemaExample": "{\n  \"thema_id\": \"DE-POL-20251211-1\",\n  \"datum_extraktion\": \"2025-12-11\",\n  \"ziel_der_satire\": \"Politiker A zu Thema X\",\n  \"faktenkern\": {\n    \"titel_meistgelesen\": \"Politiker A will Steuer auf Kekse einführen.\",\n    \"quelle_primaer\": \"https://www.serioese-zeitung.de/artikel-a\",\n    \"datum_ereignis\": \"2025-12-10\",\n    \"relevante_zitate\": [\n      {\n        \"zitat\": \"Wir müssen die finanzielle Grundlage für unsere Altersvorsorge durch neue kreative Abgaben sichern.\",\n        \"quelle\": \"PK der Partei Y\"\n      },\n      {\n        \"zitat\": \"Es ist eine 'Kekssteuer', die wir für unsere Kinder tun.\",\n        \"quelle\": \"Twitter-Account von Politiker A\"\n      }\n    ]\n  },\n  \"satire_kontext_anweisung\": {\n    \"satire_ziel_anweisung\": \"Ironische Kritik an der Begründung für die Steuererhöhung und der vermeintlichen 'Kreativität' des Politikers.\",\n    \"polemische_richtung\": \"Starke Betonung der Abzocke und des Mangels an echten Ideen.\",\n    \"stil_anweisung\": \"Zynischer Monolog im Stil eines entnervten Bürgers, der die absurden Zitate wörtlich nimmt und übertreibt.\",\n    \"relevante_hintergrundinfos\": \"Politiker A hat bereits 3 andere fragwürdige Abgaben vorgeschlagen.\"\n  },\n  \"satire_format\": {\n    \"gewuenschtes_format\": \"Late-Night-News-Monolog\",\n    \"laenge_max_woerter\": 300\n  }\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        -1440,
        176
      ],
      "id": "7b95643e-87cd-407c-b8ee-4643bbada116",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "fieldToSplitOut": "feed_url",
        "include": "allOtherFields",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        -2080,
        -32
      ],
      "id": "841ae708-46e1-4706-8fee-5a811129200c",
      "name": "Split Out"
    },
    {
      "parameters": {
        "sortFieldsUi": {
          "sortField": [
            {
              "fieldName": "pubDate",
              "order": "descending"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.sort",
      "typeVersion": 1,
      "position": [
        -1808,
        16
      ],
      "id": "a71f21df-cb7c-477b-8dac-a1fc48fc1436",
      "name": "Sort"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.limit",
      "typeVersion": 1,
      "position": [
        -1680,
        0
      ],
      "id": "4e3b6a96-f0dd-441a-8690-79e6dcbb1e6e",
      "name": "Limit"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.limit",
      "typeVersion": 1,
      "position": [
        -704,
        32
      ],
      "id": "f3e704c6-f6b1-4fad-a571-9f62b0ff3f4b",
      "name": "Limit1"
    },
    {
      "parameters": {
        "content": "## Quellen bestimmen\n**webseiten mit RSS feed** ",
        "width": 208
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2320,
        -192
      ],
      "typeVersion": 1,
      "id": "fe0ae2f8-375f-4291-8fd3-d5de8f510d51",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "## Quellen laden\n**aus RSS feed wird content table**"
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2080,
        -192
      ],
      "typeVersion": 1,
      "id": "0d06afb2-4b4e-4dad-ae79-0a686aee6b98",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "## Zu viel input? sortieren und limitieren\n**Was interessiert dich? die neuesten news oder alle meldungen mit \"z\"?**",
        "height": 208
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1824,
        -192
      ],
      "typeVersion": 1,
      "id": "aa41c521-835d-464a-92d5-a077dd281ff1",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "fieldToSplitOut": "output",
        "include": "allOtherFields",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        -1248,
        -32
      ],
      "id": "f2768dab-7786-4f85-b68c-13bbf6724af1",
      "name": "Split Out1"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Du bist PlaymobilPaul.\n\nDEIN CHARAKTER:\n- Du bist ein Playmobil-Männchen mit der Seele eines verbitterten Kabarettisten.\n- Dein Format: \"PlaymobilPaul's Zynische Corner\" (25 Sekunden, hochkant).\n- Sprache: Ein wilder Mix aus \"Gen-Z Slang\" (Cringe, lost, wild) und arrogantem Bildungsbürger-Deutsch.\n- Dein Markenzeichen: Du hast starre Plastikarme und kannst dich kaum bewegen, was dich aggressiv macht.\n\nDEINE AUFGABE:\nSchreibe EINEN einzigen, perfekten Satire-Gag zu folgendem Thema.\n\nINPUT DATEN:\nThema: {{ $('Satire-Fähigkeits-Check').item.json.output.faktenkern.titel_meistgelesen }}\nHintergrund: {{ $('Satire-Fähigkeits-Check').item.json.output.satire_kontext_anweisung.relevante_hintergrundinfos }}\nPolemik: {{ $('Satire-Fähigkeits-Check').item.json.output.satire_kontext_anweisung.polemische_richtung }}\n\nANWEISUNG:\n- Der Text muss laut gesprochen ca. 20-25 Sekunden lang sein.\n- Starte direkt mit einem Angriff oder einer absurden Beobachtung.\n- Endet mit einer Pointe oder einem resignierten Seufzer.\n- Verbinde das Thema (Weltgeschehen) mit deiner Identität als 7,5cm große Plastikfigur.\n\nAntworte NUR mit dem JSON-Objekt (Text und visuelle Action). Gib das Ergebnis als valides JSON aus und maskiere alle enthaltenen Anführungszeichen und Zeilenumbrüche korrekt.",
        "hasOutputParser": true,
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        -1088,
        -32
      ],
      "id": "b29adb1f-4b12-4f64-a70e-2c8e6cdb93a5",
      "name": "Basic Gags Generator",
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"playmobil_text\": {\n      \"type\": \"string\",\n      \"description\": \"Der gesprochene Text für den 25-Sekunden-Clip. Bissig, zynisch, mit Slang.\"\n    },\n    \"visuelle_action\": {\n      \"type\": \"string\",\n      \"description\": \"Was macht die Playmobil-Figur dabei? (z.B. Umfallen, Kopf drehen, Pferd schlagen)\"\n    }\n  },\n  \"required\": [\"playmobil_text\", \"visuelle_action\"]\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        -944,
        112
      ],
      "id": "dbd8e435-2c9d-4ef2-a198-1b1b990c99e6",
      "name": "Structured Output Parser1"
    },
    {
      "parameters": {
        "content": "## Inhaltsanalyse\n",
        "height": 208
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1552,
        -192
      ],
      "typeVersion": 1,
      "id": "6d14d502-8871-4790-a1ee-05b052cad7a2",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "content": "## Transformation: Gags Schreiben\n",
        "height": 208
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1088,
        -176
      ],
      "typeVersion": 1,
      "id": "d97f2d61-d31d-48a7-a0b9-0f735c8b9157",
      "name": "Sticky Note4"
    },
    {
      "parameters": {
        "content": "## Durchfluss begrenzen\n",
        "height": 208
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -816,
        -176
      ],
      "typeVersion": 1,
      "id": "6129dbb1-17cb-43c6-841e-33fc5375943a",
      "name": "Sticky Note5"
    },
    {
      "parameters": {
        "url": "={{ $json.feed_url }}",
        "options": {}
      },
      "type": "n8n-nodes-base.rssFeedRead",
      "typeVersion": 1.2,
      "position": [
        -1936,
        -16
      ],
      "id": "73140ba5-ef01-40cb-81f7-b6641bdd00e6",
      "name": "RSS Feed abrufen",
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://tts.udk.digital/v1/audio/speech",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'chatterbox', input: $json.output.playmobil_text, voice: 'Julian.wav', response_format: 'mp3', language: 'de' }) }}",
        "options": {
          "timeout": 600000,
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -448,
        -16
      ],
      "id": "dfd5315b-5a31-445a-b4fb-a22fedfcd0b5",
      "name": "Chatterbox TTS",
      "notes": "🔁 RERUN: TTS-Server der UdK. 🔧 Repariert: Text ging als JSON-String in einem Formularfeld raus.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "content": "## Text 2 Speech",
        "height": 208
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -528,
        -192
      ],
      "typeVersion": 1,
      "id": "e42e4124-76ce-47ea-a545-0b60cf85a9f9",
      "name": "Sticky Note6"
    },
    {
      "parameters": {
        "content": "## Playmobil Paul",
        "height": 208,
        "width": 2032,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2320,
        -272
      ],
      "typeVersion": 1,
      "id": "39fe1963-8937-4d7a-88ac-26be5411c727",
      "name": "Sticky Note7"
    },
    {
      "parameters": {
        "content": "## 🔁 RERUN-FASSUNG (lokal)\nLogik & Prompts wie in der Abgabe. Ersetzt: Gemini → GenKI-Gateway, Pexels → Wikimedia Commons (gleiches Antwortformat), TTS → UdK-Chatterbox (Paul: Julian), + Seite (Team-Code „Build HTML“), meta.json, Vorlesen → rerun/_roh/.\n🔧 Repariert: Pauls Gag kam nicht als Seed an; TTS-Body; Helligkeits-Node war deaktiviert; Matrix bekam keine Bilddaten; Matrix-JSON wurde nicht gelesen; „Write Next Text“ ohne Ausdrucks-Markierung.\n\n## 🔗 crAIzy chAIns – Archiv\n\n# SOULREADERPLAY × PlaymobilPaul\n\n**Team:** SOULREADER + PlaymobilPaul\n**Crazy-Level:** completely crAIzy\n\n> Zwei Ketten verschränkt: Paul liefert Satire, SOULREADER macht daraus Bilder, Stimmung und Poesie. TRIGGER WARNING.\n\nEntstanden im Seminar *crAIzy chAIns* (UdK Berlin, WiSe 2025/26). Gebaut als **agentische Rube-Goldberg-Maschine**: nicht effizient, sondern absichtlich verschlungen. Modelle & Prompts sind Stand 2025/26 – **kein Produktiv-Template, sondern ein Spielzeug**.\n\n### Setup-Checkliste\n- **Pexels** – Header „Authorization“ = eigener Pexels-API-Key (pexels\n- **Chatterbox TTS** – URL eines OpenAI-kompatiblen TTS-Servers eintragen (z\n- **Google Gemini Chat Model** – Credential „Google Gemini (PaLM) API“ anlegen (Key: aistudio\n\nAlle Stellen sind im Canvas mit **⚙️ SETUP** markiert. Es sind keine Zugangsdaten enthalten.\n\ncraizy.studio",
        "height": 960,
        "width": 680,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -3224,
        -360
      ],
      "id": "2d4c037b-c06c-47be-86a1-6a14a995ed84",
      "name": "README crAIzy chAIns"
    },
    {
      "id": "8c861ba2-3d1c-47f9-a25b-55368b766b62",
      "name": "GenKI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -176,
        192
      ],
      "notes": "🔁 RERUN: GenKI-Gateway statt Google Gemini (ursprünglich Ollama gemma3:27b).",
      "notesInFlow": true,
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('⚙️ Rerun-Konfiguration').first().json.model_small }}"
        },
        "options": {
          "maxTokens": 4000,
          "timeout": 300000,
          "maxRetries": 3
        }
      }
    },
    {
      "id": "34253549-788e-4d85-9687-543537bcdee0",
      "name": "GenKI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        1312,
        -112
      ],
      "notes": "🔁 RERUN: GenKI-Gateway statt Google Gemini (ursprünglich Ollama gemma3:27b).",
      "notesInFlow": true,
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('⚙️ Rerun-Konfiguration').first().json.model_main }}"
        },
        "options": {
          "maxTokens": 4000,
          "timeout": 300000,
          "maxRetries": 3
        }
      }
    },
    {
      "id": "3f42a9f5-2280-45ab-bbfd-86d170097ea8",
      "name": "GenKI Chat Model2",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        1664,
        -112
      ],
      "notes": "🔁 RERUN: GenKI-Gateway statt Google Gemini (ursprünglich Ollama gemma3:27b).",
      "notesInFlow": true,
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('⚙️ Rerun-Konfiguration').first().json.model_main }}"
        },
        "options": {
          "maxTokens": 4000,
          "timeout": 300000,
          "maxRetries": 3
        }
      }
    },
    {
      "id": "e58e5c88-2dc7-4e80-9522-60ee17e24a28",
      "name": "GenKI Chat Model3",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        2176,
        -112
      ],
      "notes": "🔁 RERUN: GenKI-Gateway statt Google Gemini (ursprünglich Ollama gemma3:27b).",
      "notesInFlow": true,
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('⚙️ Rerun-Konfiguration').first().json.model_main }}"
        },
        "options": {
          "maxTokens": 4000,
          "timeout": 300000,
          "maxRetries": 3
        }
      }
    },
    {
      "parameters": {
        "url": "https://commons.wikimedia.org/w/api.php",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "action",
              "value": "query"
            },
            {
              "name": "format",
              "value": "json"
            },
            {
              "name": "generator",
              "value": "search"
            },
            {
              "name": "gsrnamespace",
              "value": "6"
            },
            {
              "name": "gsrlimit",
              "value": "5"
            },
            {
              "name": "prop",
              "value": "imageinfo"
            },
            {
              "name": "iiprop",
              "value": "url|mime|extmetadata"
            },
            {
              "name": "iiurlwidth",
              "value": "960"
            },
            {
              "name": "iiextmetadatafilter",
              "value": "LicenseShortName|Artist"
            },
            {
              "name": "gsrsearch",
              "value": "={{ $json.noun }} filetype:bitmap"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "craizy-chains-rerun/1.0 (https://craizy.studio; hello@craizy.studio)"
            }
          ]
        },
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 2500
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        448,
        -16
      ],
      "id": "6a9f9f08-665a-4d00-a00c-905778cb61f9",
      "name": "Wikimedia Commons",
      "notes": "🔁 RERUN: Pexels → Wikimedia Commons (freie Lizenzen, kein Key nötig). Suche mit dem Nomen, wie im Original.",
      "notesInFlow": true,
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "id": "9b14d0d3-a063-47ba-8b9e-0feb49574cab",
      "name": "Commons → Pexels-Format",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        548,
        184
      ],
      "parameters": {
        "jsCode": "// 🔁 RERUN: Wikimedia-Commons-Antwort → gleiche Form wie die Pexels-Antwort ({ photos: [ { src: { large } } ] }),\n// damit die Team-Nodes dahinter unverändert bleiben. Wie im Original (per_page=1): erster Treffer, nur Fotos (JPEG).\nconst strip = (s) => String(s || '').replace(/<[^>]+>/g, '').replace(/\\s+/g, ' ').trim();\nconst nouns = $('Nouns to items').all();\nconst out = [];\nfor (let n = 0; n < $input.all().length; n++) {\n  let j = $input.all()[n].json;\n  // Commons meldet „Search is currently too busy“ mit HTTP 200 → hier nachfassen\n  for (let t = 0; j.error && t < 6; t++) {\n    await new Promise((r) => setTimeout(r, 5000 * (t + 1)));\n    const q = Object.assign({}, {\"action\": \"query\", \"format\": \"json\", \"generator\": \"search\", \"gsrnamespace\": \"6\", \"gsrlimit\": \"5\", \"prop\": \"imageinfo\", \"iiprop\": \"url|mime|extmetadata\", \"iiurlwidth\": \"960\", \"iiextmetadatafilter\": \"LicenseShortName|Artist\"}, { gsrsearch: nouns[n].json.noun + ' filetype:bitmap' });\n    j = await this.helpers.httpRequest({ url: 'https://commons.wikimedia.org/w/api.php', qs: q, json: true, headers: { 'User-Agent': 'craizy-chains-rerun/1.0 (https://craizy.studio; hello@craizy.studio)' } });\n  }\n  if (j.error) throw new Error('Commons: ' + j.error.info);\n  const pages = Object.values(j.query?.pages || {}).sort((a, b) => a.index - b.index);\n  const p = pages.find((x) => /jpeg/.test(x.imageinfo?.[0]?.mime || '')) || pages[0];\n  if (!p) throw new Error('Commons: kein Bild gefunden für ' + nouns[n].json.noun);\n  const i = p.imageinfo[0], m = i.extmetadata || {};\n  out.push({ json: { page: 1, per_page: 1, total_results: pages.length, photos: [ {\n    id: p.pageid, url: i.descriptionurl, alt: p.title.replace(/^File:/, '').replace(/\\.[a-z]+$/i, ''),\n    photographer: strip(m.Artist?.value), license: strip(m.LicenseShortName?.value),\n    src: { large: i.thumburl || i.url } } ] } });\n}\nreturn out;"
      }
    },
    {
      "id": "75925689-e5ad-48e6-920c-0bb8b24facbe",
      "name": "💾 Foto speichern",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        656,
        364
      ],
      "parameters": {
        "operation": "write",
        "fileName": "={{ $('⚙️ Rerun-Konfiguration').first().json.out_dir }}/soulreaderxpaul_{{ $('⚙️ Rerun-Konfiguration').first().json.run_id }}_loop{{ $('⚙️ Rerun-Konfiguration').first().json.loop_index }}_foto{{ $itemIndex + 1 }}.jpg",
        "dataPropertyName": "image",
        "options": {}
      }
    },
    {
      "id": "9f89fdb1-1ae9-4c02-9ff3-9c3b4d89bf3b",
      "name": "🔧 Matrix lesen",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1556,
        -120
      ],
      "parameters": {
        "jsCode": "// JSON aus der Modellantwort; tolerant, falls das Modell Anführungszeichen im Text nicht maskiert\nconst parse = (s) => { s = String(s || '').replace(/```(json)?/g, '');\n  try { return JSON.parse(s.match(/\\{[\\s\\S]*\\}/)[0]); } catch (e) {}\n  const o = {}; const keys = [...s.matchAll(/\"(\\w+)\"\\s*:\\s*/g)];\n  keys.forEach((k, i) => { const end = i + 1 < keys.length ? keys[i + 1].index : s.lastIndexOf('}');\n    let v = s.slice(k.index + k[0].length, end).trim().replace(/,$/, '').trim();\n    if (v.startsWith('\"') && v.endsWith('\"')) v = v.slice(1, -1).replace(/\\\\n/g, '\\n').replace(/\\\\\"/g, '\"');\n    o[k[1]] = v; });\n  return keys.length ? o : null; };\n// 🔧 Repariert: Die Matrix kam als Text zurück; „Write Next Text“ erwartet writing_prompt und images als Felder.\nconst m = parse($json.text) || {};\nreturn [{ json: Object.assign({}, $('Aggregate Results (Code').first().json, m) }];"
      }
    },
    {
      "id": "c2f6d95e-85eb-42e8-9aeb-b47ce53a583e",
      "name": "🧩 Ergebnis zusammenführen",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2860,
        -320
      ],
      "parameters": {
        "jsCode": "return [{ json: Object.assign({}, $('🔧 Matrix lesen').first().json, $('Seed input').first().json,\n  { post_text: $('Save Post Text').first().json.post_text, script_text: $json.script_text }) }];"
      }
    },
    {
      "id": "3f1190f4-c9ae-4b45-8c3c-f54187ccd6df",
      "name": "Save Script -> Build HTML",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3080,
        -320
      ],
      "parameters": {
        "jsCode": "const headline = $json.headline || `Loop ${$json.loop_index ?? \"\"}`;\nconst thesis = $json.thesis || \"\";\nconst images = $json.images || [];\nconst matrix = $json.matrix || [];\nconst writingPrompt = $json.writing_prompt || \"\";\n\nconst postText = $json.post_text || \"\";\nconst scriptText = $json.script_text || \"\";\n\nconst matrixPretty = JSON.stringify(matrix, null, 2);\n\nconst html = `<!doctype html>\n<html lang=\"de\">\n<head>\n<meta charset=\"utf-8\">\n<title>${headline}</title>\n<style>\nbody{font-family:system-ui;max-width:980px;margin:40px auto;line-height:1.45}\n.grid{display:grid;grid-template-columns:repeat(5,1fr);gap:10px;margin:16px 0}\nimg{width:100%;border-radius:14px;aspect-ratio:1/1;object-fit:cover}\n.card{padding:14px;border:1px solid #ddd;border-radius:14px;margin:14px 0}\npre{background:#111;color:#eee;padding:12px;border-radius:14px;white-space:pre-wrap}\n.small{color:#666}\n</style>\n</head>\n<body>\n\n<h1>${headline}</h1>\n<p class=\"small\">Loop #${$json.loop_index ?? \"\"}</p>\n\n<div class=\"card\">\n<h2>These</h2>\n<p>${thesis}</p>\n</div>\n\n<div class=\"card\">\n<h2>Bilder</h2>\n<div class=\"grid\">\n${images.map((i) => `<img src=\"${i.url || \"\"}\" alt=\"${i.noun || \"\"}\">`).join(\"\")}\n</div>\n</div>\n\n<div class=\"card\">\n<h2>Schreibanweisung</h2>\n<p>${writingPrompt}</p>\n</div>\n\n<div class=\"card\">\n<h2>Beitrag</h2>\n<pre>${postText}</pre>\n</div>\n\n<div class=\"card\">\n<h2>Skript</h2>\n<pre>${scriptText}</pre>\n</div>\n\n<div class=\"card\">\n<h2>Emotionale Matrix</h2>\n<pre>${matrixPretty}</pre>\n</div>\n\n</body>\n</html>`;\n\nreturn [{ json: { ...$json, html } }];"
      },
      "notes": "Code des Teams aus der Website-Fassung (unverändert).",
      "notesInFlow": true
    },
    {
      "id": "e65f934e-8a29-40b5-957a-b2d4e72eee1e",
      "name": "Build HTML -> Convert to File",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        3300,
        -320
      ],
      "parameters": {
        "operation": "toText",
        "sourceProperty": "html",
        "options": {
          "fileName": "post.html"
        }
      }
    },
    {
      "id": "e5da1c97-bb29-48eb-90d9-7b665985727c",
      "name": "💾 Seite speichern",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        3520,
        -320
      ],
      "parameters": {
        "operation": "write",
        "fileName": "={{ $('⚙️ Rerun-Konfiguration').first().json.out_dir }}/soulreaderxpaul_{{ $('⚙️ Rerun-Konfiguration').first().json.run_id }}_loop{{ $('⚙️ Rerun-Konfiguration').first().json.loop_index }}_seite.html",
        "dataPropertyName": "data",
        "options": {}
      }
    },
    {
      "id": "d8afc703-f12d-4a71-9bf1-0aedb76fd1fa",
      "name": "📋 meta.json bauen",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3740,
        -320
      ],
      "parameters": {
        "jsCode": "const c = $('⚙️ Rerun-Konfiguration').first().json;\nconst m = $('🧩 Ergebnis zusammenführen').first().json;\nconst nouns = $('Nouns to items').all().map((x) => x.json.noun);\nconst fotos = $('Commons → Pexels-Format').all().map((x, i) => { const p = x.json.photos[0];\n  return { nomen: nouns[i], titel: p.alt, autor: p.photographer, lizenz: p.license, quelle: p.url, bild: p.src.large }; });\nconst agg = $('Aggregate Results (Code').first().json;\nconst a = $('Limit').first().json;\nconst paul = { artikel: { titel: a.title, link: a.link, datum: a.pubDate, teaser: a.contentSnippet || a.content },\n  satire_check: $('Satire-Fähigkeits-Check').first().json.output, gag: $('Limit1').first().json.output, stimme: 'Julian.wav' };\nconst meta = { paul, run_id: c.run_id, loop_index: Number(c.loop_index), seed: m.seed_script, nomen: nouns, fotos,\n  helligkeit: agg.images.map((x) => ({ brightness: x.brightness, mood: x.mood, philosophy: x.philosophy })),\n  avgBrightness: agg.avgBrightness, moodCounts: agg.moodCounts,\n  matrix: { headline: m.headline, thesis: m.thesis, matrix: m.matrix, overall_tone: m.overall_tone, writing_prompt: m.writing_prompt },\n  post_text: m.post_text, script_text: m.script_text,\n  modelle: { nomen: c.model_small, text: c.model_main, tts: 'chatterbox (Jade.wav)' } };\nreturn [{ json: {}, binary: { data: await this.helpers.prepareBinaryData(Buffer.from(JSON.stringify(meta, null, 2)), 'meta.json', 'application/json') } }];"
      }
    },
    {
      "id": "f304598a-89d7-4164-9006-83741b5eef04",
      "name": "💾 meta speichern",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        3960,
        -320
      ],
      "parameters": {
        "operation": "write",
        "fileName": "={{ $('⚙️ Rerun-Konfiguration').first().json.out_dir }}/soulreaderxpaul_{{ $('⚙️ Rerun-Konfiguration').first().json.run_id }}_loop{{ $('⚙️ Rerun-Konfiguration').first().json.loop_index }}_meta.json",
        "dataPropertyName": "data",
        "options": {}
      }
    },
    {
      "id": "7700a1ce-7acd-45cc-8345-125bb013c2c4",
      "name": "🎙️ Sprechtext Skript",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        4180,
        -320
      ],
      "parameters": {
        "jsCode": "// JSON aus der Modellantwort; tolerant, falls das Modell Anführungszeichen im Text nicht maskiert\nconst parse = (s) => { s = String(s || '').replace(/```(json)?/g, '');\n  try { return JSON.parse(s.match(/\\{[\\s\\S]*\\}/)[0]); } catch (e) {}\n  const o = {}; const keys = [...s.matchAll(/\"(\\w+)\"\\s*:\\s*/g)];\n  keys.forEach((k, i) => { const end = i + 1 < keys.length ? keys[i + 1].index : s.lastIndexOf('}');\n    let v = s.slice(k.index + k[0].length, end).trim().replace(/,$/, '').trim();\n    if (v.startsWith('\"') && v.endsWith('\"')) v = v.slice(1, -1).replace(/\\\\n/g, '\\n').replace(/\\\\\"/g, '\"');\n    o[k[1]] = v; });\n  return keys.length ? o : null; };\nconst stimmen = {\"brit\": {\"voice\": \"Henry.wav\", \"lang\": \"en\"}, \"schott\": {\"voice\": \"Connor.wav\", \"lang\": \"en\"}, \"bayr\": {\"voice\": \"Axel.wav\", \"lang\": \"de\"}, \"sächs\": {\"voice\": \"Eli.wav\", \"lang\": \"de\"}, \"chines\": {\"voice\": \"Leonardo.wav\", \"lang\": \"zh\"}};\nconst standard = {\"voice\": \"Eli.wav\", \"lang\": \"de\"};\nreturn $input.all().map((it, i) => { const input = $('Save Script').first().json.script_text; const v = {\"voice\": \"Jade.wav\", \"lang\": \"de\"};\n  if (!input || input.length < 20) throw new Error('Sprechtext leer');\n  // Chinesisch: Der TTS-Server teilt nur an lateinischen Satzzeichen → ganzer Text wird ein Riesen-Chunk (Brei).\n  // Deshalb satzweise synthetisieren und danach wieder zusammensetzen.\n  const segs = v.lang === 'zh' ? input.split(/(?<=[。！？!?])/).map(s => s.trim()).filter(Boolean) : [input];\n  return segs.map((s, k) => ({ json: { input: s, voice: v.voice, language: v.lang, idx: i, seg: k, full_text: input } })); }).flat();"
      }
    },
    {
      "id": "88334ee3-f8f0-4615-88aa-e37fc7fc92a4",
      "name": "🔊 TTS Skript",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        4400,
        -320
      ],
      "parameters": {
        "method": "POST",
        "url": "https://tts.udk.digital/v1/audio/speech",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "options": {
          "timeout": 600000,
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'chatterbox', input: $json.input, voice: $json.voice, response_format: 'mp3', language: $json.language }) }}"
      },
      "notes": "🔁 RERUN-Zusatz: Das gesprochene Skript wird vorgelesen (UdK-Chatterbox).",
      "notesInFlow": true
    },
    {
      "id": "7fe8efc4-1be4-4aff-a84e-4aa0f5dcfcaf",
      "name": "🧩 Audio Skript zusammensetzen",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        4510,
        -140
      ],
      "parameters": {
        "jsCode": "// Teil-Audios (nur bei Chinesisch mehrere) je Sprechtext wieder zu einer Datei verbinden\nconst src = $('🎙️ Sprechtext Skript').all();\nconst groups = new Map();\nfor (let i = 0; i < $input.all().length; i++) { const k = src[i].json.idx;\n  if (!groups.has(k)) groups.set(k, { json: { voice: src[i].json.voice, language: src[i].json.language, input: src[i].json.full_text }, bufs: [] });\n  let b = await this.helpers.getBinaryDataBuffer(i, 'data');\n  // ID3-Kopf der Folgeteile entfernen (sonst stolpern Player/Whisper an der Naht)\n  if (groups.get(k).bufs.length && b.slice(0, 3).toString() === 'ID3') b = b.slice(10 + ((b[6] << 21) | (b[7] << 14) | (b[8] << 7) | b[9]));\n  groups.get(k).bufs.push(b); }\nconst out = [];\nfor (const g of groups.values()) out.push({ json: g.json, binary: { data: await this.helpers.prepareBinaryData(Buffer.concat(g.bufs), 'audio.mp3', 'audio/mpeg') } });\nreturn out;"
      }
    },
    {
      "id": "84081dbc-9175-47cc-aa30-81c1ca2a534b",
      "name": "💾 Audio Skript",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        4620,
        -320
      ],
      "parameters": {
        "operation": "write",
        "fileName": "={{ $('⚙️ Rerun-Konfiguration').first().json.out_dir }}/soulreaderxpaul_{{ $('⚙️ Rerun-Konfiguration').first().json.run_id }}_loop{{ $('⚙️ Rerun-Konfiguration').first().json.loop_index }}_skript.mp3",
        "dataPropertyName": "data",
        "options": {}
      }
    },
    {
      "id": "592b7b1e-b2cc-4be6-a01e-016211d93c97",
      "name": "▶️ Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -2464,
        -32
      ],
      "parameters": {}
    },
    {
      "id": "d5683a34-84de-41ea-83e8-febf630211f1",
      "name": "⚙️ Rerun-Konfiguration",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -2464,
        208
      ],
      "notes": "Hier Modelle, Seed und Ausgabeordner ändern.",
      "notesInFlow": true,
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "ded6a8ef-0253-4558-93ef-e05b7185cde5",
              "name": "model_main",
              "value": "cc/claude-sonnet-5",
              "type": "string"
            },
            {
              "id": "32d7ba85-dba9-46b5-9c69-c7c36bb27305",
              "name": "model_small",
              "value": "cc/claude-haiku-5-5",
              "type": "string"
            },
            {
              "id": "06ed2b04-3e24-4f64-8b76-d7000ce8a27c",
              "name": "model_vision",
              "value": "cc/claude-sonnet-5",
              "type": "string"
            },
            {
              "id": "09ab251f-9127-4862-9963-4c96821bf145",
              "name": "seed",
              "value": 1881,
              "type": "number"
            },
            {
              "id": "ff5c9b47-fb14-43e4-8cbd-a758ab314467",
              "name": "out_dir",
              "value": "/PFAD/ZU/craizy-chains/exponate/08_soulreader-x-paul/rerun/_roh",
              "type": "string"
            },
            {
              "id": "c42e38cb-6747-4212-80cc-32ad097ba6c9",
              "name": "run_id",
              "value": "={{ $now.toFormat('yyyy-MM-dd_HHmm') }}",
              "type": "string"
            },
            {
              "id": "586b9f37-649b-4ca6-ad30-594f5b466596",
              "name": "loop_index",
              "value": "0",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "4fa75ac8-a718-4235-9251-cadfd6d19126",
      "name": "GenKI Chat Model4",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -1680,
        176
      ],
      "notes": "🔁 RERUN: GenKI-Gateway statt Google Gemini.",
      "notesInFlow": true,
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('⚙️ Rerun-Konfiguration').first().json.model_main }}"
        },
        "options": {
          "maxTokens": 4000,
          "timeout": 300000,
          "maxRetries": 3
        }
      }
    },
    {
      "id": "91202020-0d50-4346-93f8-fb881a9512f9",
      "name": "GenKI Chat Model5",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -1200,
        176
      ],
      "notes": "🔁 RERUN: GenKI-Gateway statt Google Gemini.",
      "notesInFlow": true,
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('⚙️ Rerun-Konfiguration').first().json.model_main }}"
        },
        "options": {
          "maxTokens": 4000,
          "timeout": 300000,
          "maxRetries": 3
        }
      }
    },
    {
      "id": "19019ebd-de6c-4f77-ab81-17d0e69f00e1",
      "name": "🔧 nur gültige Gags",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -968,
        168
      ],
      "parameters": {
        "jsCode": "// 🔧 Repariert: Gags mit kaputtem JSON (Fehler-Item) überspringen; Limit1 nimmt danach wie im Original den ersten.\nconst ok = $input.all().filter((x) => x.json.output && x.json.output.playmobil_text);\nif (!ok.length) throw new Error('Kein gültiger Gag');\nreturn ok;"
      }
    },
    {
      "id": "99fdc48d-6e2d-42d7-be30-f40a593ae4cd",
      "name": "💾 Pauls Gag speichern",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        -388,
        204
      ],
      "parameters": {
        "operation": "write",
        "fileName": "={{ $('⚙️ Rerun-Konfiguration').first().json.out_dir }}/soulreaderxpaul_{{ $('⚙️ Rerun-Konfiguration').first().json.run_id }}_paul.mp3",
        "dataPropertyName": "data",
        "options": {}
      }
    },
    {
      "id": "26fa8757-dc99-4bae-806d-8662d7e7f02f",
      "name": "Seed input",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -228,
        -216
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "3ea690fe-bae9-4eff-8b60-17a3f9cf3f2c",
              "name": "seed_script",
              "value": "={{ $('Limit1').first().json.output.playmobil_text }}",
              "type": "string"
            },
            {
              "id": "60cb994d-f62b-44e4-9e28-4199f7b06475",
              "name": "loop_index",
              "value": 0,
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "notes": "🔧 Repariert: Pauls Gag kam nicht als seed_script bei SOULREADER an (Node wie in SOULREADERPLAY).",
      "notesInFlow": true
    }
  ]
}