{
  "schema_version": "1.0",
  "nodes": [
    {
      "id": "programme",
      "type": "input/json_value",
      "label": "Programma della rassegna",
      "parameters": {
        "required": true
      }
    },
    {
      "id": "programme_text",
      "type": "utility/extract",
      "label": "Programma come testo",
      "parameters": {
        "path": "$",
        "expected_type": "json",
        "on_missing": "fail"
      }
    },
    {
      "id": "brief",
      "type": "text/template",
      "label": "Programma per la redazione",
      "parameters": {
        "template": "PROGRAMMA DELLA RASSEGNA (JSON)\n[programme]",
        "placeholders": [
          {
            "name": "programme",
            "inputPort": "programme"
          }
        ]
      }
    },
    {
      "id": "writer",
      "type": "ai/text_generation",
      "label": "Scrivi l'invito e l'idea di illustrazione",
      "parameters": {
        "system_prompt": "Sei la redazione di Cortile Aperto, associazione culturale di Bologna. Ricevi il programma di una rassegna estiva di incontri con autori (JSON).\nRispondi SOLO con un oggetto JSON con due chiavi:\n- \"intro\": 2-3 frasi in italiano (tra 160 e 320 caratteri) che invitano il quartiere alla rassegna. Tono caldo, semplice, concreto. Usa solo i fatti del programma: non inventare nomi, date, ospiti, sponsor o servizi. La locandina stampa già a parte le serate, il luogo, l'ingresso e il piano pioggia: non ripeterli, racconta invece perché vale la pena venire.\n- \"image_prompt\": in inglese, la descrizione di un'illustrazione editoriale piatta e quadrata che richiami il tema della rassegna (campo \"theme\"): palette calda (verde bosco, ocra, terracotta, crema), a tutta pagina fino ai bordi (niente cornice, bordo o passe-partout), nessun testo, lettera o numero nell'immagine.",
        "response_format": "json_object",
        "temperature": 0.6,
        "max_tokens": 900
      }
    },
    {
      "id": "copy_contract",
      "type": "utility/json_schema_validate",
      "label": "Le parole stanno nella locandina",
      "parameters": {
        "schema_source": "inline",
        "schema_definition": "{\"type\":\"object\",\"additionalProperties\":false,\"required\":[\"intro\",\"image_prompt\"],\"properties\":{\"intro\":{\"type\":\"string\",\"minLength\":120,\"maxLength\":340},\"image_prompt\":{\"type\":\"string\",\"minLength\":40,\"maxLength\":700}}}",
        "mode": "fail"
      }
    },
    {
      "id": "image_prompt",
      "type": "utility/extract",
      "label": "Idea di illustrazione",
      "parameters": {
        "path": "image_prompt",
        "expected_type": "text",
        "on_missing": "fail"
      }
    },
    {
      "id": "painter",
      "type": "ai/text_to_image",
      "label": "Disegna l'illustrazione",
      "parameters": {
        "prompt": "editorial illustration",
        "aspect_ratio": "1_1"
      }
    },
    {
      "id": "evening_rows",
      "type": "enumerate/json",
      "label": "Una serata alla volta",
      "parameters": {
        "jsonConfig": {
          "arrayPath": "evenings",
          "properties": [
            {
              "sourcePath": "date",
              "outputPort": "date",
              "outputType": "text",
              "selected": true,
              "label": "date"
            },
            {
              "sourcePath": "time",
              "outputPort": "time",
              "outputType": "text",
              "selected": true,
              "label": "time"
            },
            {
              "sourcePath": "author",
              "outputPort": "author",
              "outputType": "text",
              "selected": true,
              "label": "author"
            },
            {
              "sourcePath": "book",
              "outputPort": "book",
              "outputType": "text",
              "selected": true,
              "label": "book"
            }
          ]
        },
        "emptyBehavior": "fail"
      }
    },
    {
      "id": "line",
      "type": "text/template",
      "label": "Riga del programma",
      "parameters": {
        "template": "[date] · ore [time] — [author], «[book]»",
        "placeholders": [
          {
            "name": "date",
            "inputPort": "date"
          },
          {
            "name": "time",
            "inputPort": "time"
          },
          {
            "name": "author",
            "inputPort": "author"
          },
          {
            "name": "book",
            "inputPort": "book"
          }
        ]
      }
    },
    {
      "id": "evenings",
      "type": "aggregate/json",
      "label": "Elenco serate",
      "parameters": {
        "jsonAggregateConfig": {
          "columns": [
            {
              "name": "line",
              "inputPort": "line",
              "type": "text"
            }
          ]
        },
        "outputName": "evenings",
        "emptyBehavior": "fail"
      }
    },
    {
      "id": "render",
      "type": "design/template_render",
      "label": "Componi la locandina",
      "parameters": {
        "output": "both",
        "page_selection": "all",
        "missing_policy": "fail_required",
        "overflow_policy": "template",
        "max_repeat": 6,
        "template_revision": "__TEMPLATE_REVISION__",
        "template_id": "__TEMPLATE_ID__"
      }
    },
    {
      "id": "poster_pdf",
      "type": "output/pdf",
      "label": "Locandina — PDF",
      "parameters": {
        "output_name": "poster_pdf"
      }
    },
    {
      "id": "poster_image",
      "type": "output/image",
      "label": "Locandina — immagine",
      "parameters": {
        "output_name": "poster_image"
      }
    },
    {
      "id": "copy_output",
      "type": "output/json",
      "label": "Parole approvate",
      "parameters": {
        "output_name": "poster_copy"
      }
    }
  ],
  "connections": [
    {
      "from_node": "programme",
      "from_output": "json",
      "to_node": "programme_text",
      "to_input": "json"
    },
    {
      "from_node": "programme_text",
      "from_output": "value",
      "to_node": "brief",
      "to_input": "programme"
    },
    {
      "from_node": "brief",
      "from_output": "result",
      "to_node": "writer",
      "to_input": "prompt"
    },
    {
      "from_node": "writer",
      "from_output": "json",
      "to_node": "copy_contract",
      "to_input": "document"
    },
    {
      "from_node": "copy_contract",
      "from_output": "normalized_json",
      "to_node": "image_prompt",
      "to_input": "json"
    },
    {
      "from_node": "image_prompt",
      "from_output": "value",
      "to_node": "painter",
      "to_input": "prompt"
    },
    {
      "from_node": "programme",
      "from_output": "json",
      "to_node": "evening_rows",
      "to_input": "json"
    },
    {
      "from_node": "evening_rows",
      "from_output": "date",
      "to_node": "line",
      "to_input": "date"
    },
    {
      "from_node": "evening_rows",
      "from_output": "time",
      "to_node": "line",
      "to_input": "time"
    },
    {
      "from_node": "evening_rows",
      "from_output": "author",
      "to_node": "line",
      "to_input": "author"
    },
    {
      "from_node": "evening_rows",
      "from_output": "book",
      "to_node": "line",
      "to_input": "book"
    },
    {
      "from_node": "line",
      "from_output": "result",
      "to_node": "evenings",
      "to_input": "line"
    },
    {
      "from_node": "copy_contract",
      "from_output": "normalized_json",
      "to_node": "render",
      "to_input": "data"
    },
    {
      "from_node": "programme",
      "from_output": "json",
      "to_node": "render",
      "to_input": "data"
    },
    {
      "from_node": "evenings",
      "from_output": "result",
      "to_node": "render",
      "to_input": "evenings"
    },
    {
      "from_node": "painter",
      "from_output": "result",
      "to_node": "render",
      "to_input": "illustration"
    },
    {
      "from_node": "render",
      "from_output": "pdf",
      "to_node": "poster_pdf",
      "to_input": "pdf"
    },
    {
      "from_node": "render",
      "from_output": "image",
      "to_node": "poster_image",
      "to_input": "image"
    },
    {
      "from_node": "copy_contract",
      "from_output": "normalized_json",
      "to_node": "copy_output",
      "to_input": "json"
    }
  ],
  "layout": {
    "nodes": {
      "programme": {
        "x": 0,
        "y": 300
      },
      "programme_text": {
        "x": 420,
        "y": 0
      },
      "brief": {
        "x": 840,
        "y": 0
      },
      "writer": {
        "x": 1260,
        "y": 0
      },
      "copy_contract": {
        "x": 1680,
        "y": 0
      },
      "image_prompt": {
        "x": 2100,
        "y": 200
      },
      "painter": {
        "x": 2520,
        "y": 200
      },
      "evening_rows": {
        "x": 420,
        "y": 600
      },
      "line": {
        "x": 840,
        "y": 600
      },
      "evenings": {
        "x": 1260,
        "y": 600
      },
      "render": {
        "x": 2940,
        "y": 400
      },
      "poster_pdf": {
        "x": 3380,
        "y": 320
      },
      "poster_image": {
        "x": 3380,
        "y": 480
      },
      "copy_output": {
        "x": 2100,
        "y": -160
      }
    }
  }
}
