{
  "schema_version": "1.0",
  "nodes": [
    {
      "id": "summary",
      "type": "input/text",
      "label": "Book summary",
      "parameters": {
        "text": "La brevità della vita — Seneca (De brevitate vitae, 49 d.C. circa)\n\nSeneca scrive all'amico Paolino, prefetto dell'annona di Roma, per rispondere a un lamento antico: la vita è troppo breve. Non è così, sostiene: la vita è abbastanza lunga per chi sa usarla; siamo noi a renderla breve, sprecandola.\n\nGran parte del tempo se ne va in occupazioni che non abbiamo scelto: inseguire incarichi e ricchezze, servire l'ambizione altrui, affollare le anticamere dei potenti, riempire le giornate di impegni che non lasciano spazio a noi stessi. Difendiamo con cura i nostri beni e i nostri confini, ma regaliamo il tempo a chiunque lo chieda, come se non valesse nulla, mentre è l'unico bene davvero nostro e l'unico che nessuno può restituirci.\n\nChi vive rimandando — «a cinquant'anni mi ritirerò, a sessanta sarò libero da ogni incarico» — perde il presente per un futuro incerto. Il presente è brevissimo, il futuro dubbio; solo il passato è sicuro, ma lo possiede davvero soltanto chi non lo ha sprecato e può ripercorrerlo senza rimpianti.\n\nGli unici davvero liberi, per Seneca, sono coloro che dedicano tempo alla riflessione e allo studio: conversando con i grandi pensatori del passato, fanno propri tutti i secoli e allungano la vita invece di consumarla. L'invito finale a Paolino è di lasciare gli affari pubblici prima che sia tardi e riservare la parte migliore della vita a ciò che conta.",
        "multiline": true,
        "required": true
      }
    },
    {
      "id": "work",
      "type": "input/json_value",
      "label": "Facts of the work",
      "parameters": {
        "required": true
      }
    },
    {
      "id": "summarizer",
      "type": "ai/text_generation",
      "label": "Build the illustrated summary",
      "parameters": {
        "system_prompt": "You turn the summary of a book or an essay into a one-page visual summary for a reading app.\nThe reader already has the summary: the page helps to see its structure at a glance and to remember it.\n\nRules:\n- Write in the language of the summary (Italian here), clear and concrete, as a good teacher would; no hype, no exclamation marks.\n- Use only what the summary says: never invent facts, dates, names or quotations. Do not quote the author: the page prints a verified quotation of its own.\n- Never repeat the same sentence in two places: the big idea, the three steps, the key ideas and the actions each say something new.\n- Keep strictly within the character limits below: they are the space on the printed page, and a text over its limit stops the page.\n\nReturn one JSON object and nothing else:\n- \"big_idea\": 40 to 130 characters: the whole work in one sentence.\n- \"step_1\", \"step_2\", \"step_3\": at most 38 characters each (count them): the line of reasoning in three steps (the problem, the turning point, the conclusion), each a short phrase.\n- \"key_ideas\": 4 to 6 objects, in the order of the work, each with \"tag\" (at most 16 characters, one or two words naming the theme, e.g. \"Il presente\"), \"title\" (at most 40 characters) and \"text\" (60 to 118 characters) explaining the idea, and \"scene\" (in English, 40 to 260 characters): what a small square picture of this idea shows — one or two symbolic objects in a simple setting, different from the other ideas; describe only the scene, never a style, colours or technique; no people, no text.\n- \"actions\": exactly 3 objects with \"text\" (20 to 80 characters): something the reader can try tomorrow, concrete and small, in the second person singular.\n- \"illustration_prompt\": in English, at most 600 characters, for an image model: a square editorial illustration that evokes the central idea with one or two symbolic objects (for example an hourglass, a path, a window at dawn), flat shapes with soft grain, a limited palette of deep navy, terracotta, sand and warm cream, plenty of calm space, full bleed to every edge with no border, frame or margin, no people, no text, no letters, no logos.",
        "response_format": "json_object",
        "temperature": 0.4,
        "max_tokens": 4000
      }
    },
    {
      "id": "summary_contract",
      "type": "utility/json_schema_validate",
      "label": "Summary fits the page",
      "parameters": {
        "schema_source": "inline",
        "schema_definition": {
          "$schema": "https://json-schema.org/draft/2020-12/schema",
          "type": "object",
          "additionalProperties": false,
          "required": [
            "big_idea",
            "step_1",
            "step_2",
            "step_3",
            "key_ideas",
            "actions",
            "illustration_prompt"
          ],
          "properties": {
            "big_idea": {
              "type": "string",
              "minLength": 40,
              "maxLength": 150,
              "description": "The whole work in one sentence."
            },
            "step_1": {
              "type": "string",
              "minLength": 8,
              "maxLength": 44,
              "description": "The argument in three steps: the problem."
            },
            "step_2": {
              "type": "string",
              "minLength": 8,
              "maxLength": 44,
              "description": "The turning point."
            },
            "step_3": {
              "type": "string",
              "minLength": 8,
              "maxLength": 44,
              "description": "The conclusion."
            },
            "key_ideas": {
              "type": "array",
              "minItems": 4,
              "maxItems": 6,
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "tag",
                  "title",
                  "text",
                  "scene"
                ],
                "properties": {
                  "tag": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 18,
                    "description": "One or two words naming the theme."
                  },
                  "title": {
                    "type": "string",
                    "minLength": 10,
                    "maxLength": 44
                  },
                  "text": {
                    "type": "string",
                    "minLength": 60,
                    "maxLength": 130
                  },
                  "scene": {
                    "type": "string",
                    "minLength": 40,
                    "maxLength": 300,
                    "description": "In English: what the small picture of this idea shows (objects and setting, no style)."
                  }
                }
              }
            },
            "actions": {
              "type": "array",
              "minItems": 3,
              "maxItems": 3,
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "text"
                ],
                "properties": {
                  "text": {
                    "type": "string",
                    "minLength": 20,
                    "maxLength": 90
                  }
                }
              }
            },
            "illustration_prompt": {
              "type": "string",
              "minLength": 80,
              "maxLength": 600
            }
          }
        },
        "mode": "fail"
      }
    },
    {
      "id": "illustration_prompt",
      "type": "utility/extract",
      "label": "Illustration prompt",
      "parameters": {
        "path": "illustration_prompt",
        "expected_type": "text",
        "on_missing": "fail"
      }
    },
    {
      "id": "illustration",
      "type": "ai/text_to_image",
      "label": "Draw the main illustration",
      "parameters": {
        "aspect_ratio": "1_1",
        "variants": 1
      }
    },
    {
      "id": "ideas",
      "type": "enumerate/json",
      "label": "One key idea at a time",
      "parameters": {
        "jsonConfig": {
          "arrayPath": "key_ideas",
          "properties": [
            {
              "sourcePath": "tag",
              "outputPort": "tag",
              "outputType": "text",
              "selected": true
            },
            {
              "sourcePath": "title",
              "outputPort": "title",
              "outputType": "text",
              "selected": true
            },
            {
              "sourcePath": "text",
              "outputPort": "text",
              "outputType": "text",
              "selected": true
            },
            {
              "sourcePath": "scene",
              "outputPort": "scene",
              "outputType": "text",
              "selected": true
            }
          ]
        },
        "emptyBehavior": "fail",
        "absentBehavior": "fail"
      }
    },
    {
      "id": "idea_prompt",
      "type": "text/template",
      "label": "Picture instruction",
      "parameters": {
        "template": "Create a new square illustration in exactly the same visual style as the reference image: the same flat shapes with soft grain, the same limited palette of deep navy, terracotta, sand and warm cream, the same soft light and calm empty space.\nDo not copy the objects or the composition of the reference image.\nShow only this scene: [scene]\nFull bleed to every edge: no border, frame or margin.\nNo people, no text, no letters, no logos.",
        "placeholders": [
          {
            "name": "scene",
            "inputPort": "scene"
          }
        ]
      }
    },
    {
      "id": "idea_picture",
      "type": "ai/image_transform",
      "label": "Draw the idea in the same style",
      "parameters": {
        "aspect_ratio": "1:1"
      }
    },
    {
      "id": "illustrated_ideas",
      "type": "aggregate/json",
      "label": "Ideas with their pictures",
      "parameters": {
        "jsonAggregateConfig": {
          "columns": [
            {
              "name": "tag",
              "inputPort": "tag",
              "type": "text"
            },
            {
              "name": "title",
              "inputPort": "title",
              "type": "text"
            },
            {
              "name": "text",
              "inputPort": "text",
              "type": "text"
            },
            {
              "name": "image",
              "inputPort": "image",
              "type": "image"
            }
          ]
        },
        "outputName": "illustrated_ideas",
        "emptyBehavior": "fail"
      }
    },
    {
      "id": "render",
      "type": "design/template_render",
      "label": "Compose the page",
      "parameters": {
        "template_id": "__TEMPLATE_ID__",
        "template_revision": "__TEMPLATE_REVISION__",
        "output": "both",
        "page_selection": "all",
        "missing_policy": "fail_required",
        "overflow_policy": "template",
        "max_repeat": 6
      }
    },
    {
      "id": "page_pdf",
      "type": "output/pdf",
      "label": "Illustrated summary — PDF",
      "parameters": {
        "output_name": "summary_pdf"
      }
    },
    {
      "id": "page_image",
      "type": "output/image",
      "label": "Illustrated summary — image",
      "parameters": {
        "output_name": "summary_image"
      }
    },
    {
      "id": "summary_output",
      "type": "output/json",
      "label": "Approved summary",
      "parameters": {
        "output_name": "summary_json"
      }
    },
    {
      "id": "ideas_output",
      "type": "output/json",
      "label": "Ideas with their pictures",
      "parameters": {
        "output_name": "illustrated_ideas"
      }
    },
    {
      "id": "layout_report",
      "type": "output/json",
      "label": "Layout report",
      "parameters": {
        "output_name": "layout_report"
      }
    },
    {
      "id": "illustration_output",
      "type": "output/image",
      "label": "Main illustration",
      "parameters": {
        "output_name": "illustration"
      }
    }
  ],
  "connections": [
    {
      "from_node": "summary",
      "from_output": "text",
      "to_node": "summarizer",
      "to_input": "prompt"
    },
    {
      "from_node": "summarizer",
      "from_output": "json",
      "to_node": "summary_contract",
      "to_input": "document"
    },
    {
      "from_node": "summary_contract",
      "from_output": "normalized_json",
      "to_node": "illustration_prompt",
      "to_input": "json"
    },
    {
      "from_node": "illustration_prompt",
      "from_output": "value",
      "to_node": "illustration",
      "to_input": "prompt"
    },
    {
      "from_node": "summary_contract",
      "from_output": "normalized_json",
      "to_node": "ideas",
      "to_input": "json"
    },
    {
      "from_node": "ideas",
      "from_output": "scene",
      "to_node": "idea_prompt",
      "to_input": "scene"
    },
    {
      "from_node": "idea_prompt",
      "from_output": "result",
      "to_node": "idea_picture",
      "to_input": "prompt"
    },
    {
      "from_node": "illustration",
      "from_output": "result",
      "to_node": "idea_picture",
      "to_input": "images_0"
    },
    {
      "from_node": "ideas",
      "from_output": "tag",
      "to_node": "illustrated_ideas",
      "to_input": "tag"
    },
    {
      "from_node": "ideas",
      "from_output": "title",
      "to_node": "illustrated_ideas",
      "to_input": "title"
    },
    {
      "from_node": "ideas",
      "from_output": "text",
      "to_node": "illustrated_ideas",
      "to_input": "text"
    },
    {
      "from_node": "idea_picture",
      "from_output": "result",
      "to_node": "illustrated_ideas",
      "to_input": "image"
    },
    {
      "from_node": "summary_contract",
      "from_output": "normalized_json",
      "to_node": "render",
      "to_input": "data_0"
    },
    {
      "from_node": "work",
      "from_output": "json",
      "to_node": "render",
      "to_input": "data_1"
    },
    {
      "from_node": "illustration",
      "from_output": "result",
      "to_node": "render",
      "to_input": "illustration"
    },
    {
      "from_node": "illustrated_ideas",
      "from_output": "result",
      "to_node": "render",
      "to_input": "key_ideas"
    },
    {
      "from_node": "render",
      "from_output": "pdf",
      "to_node": "page_pdf",
      "to_input": "pdf"
    },
    {
      "from_node": "render",
      "from_output": "image",
      "to_node": "page_image",
      "to_input": "image"
    },
    {
      "from_node": "summary_contract",
      "from_output": "normalized_json",
      "to_node": "summary_output",
      "to_input": "json"
    },
    {
      "from_node": "illustrated_ideas",
      "from_output": "result",
      "to_node": "ideas_output",
      "to_input": "json"
    },
    {
      "from_node": "render",
      "from_output": "layout_report",
      "to_node": "layout_report",
      "to_input": "json"
    },
    {
      "from_node": "illustration",
      "from_output": "result",
      "to_node": "illustration_output",
      "to_input": "image"
    }
  ],
  "layout": {
    "nodes": {
      "summary": {
        "x": 0,
        "y": 0
      },
      "work": {
        "x": 0,
        "y": 520
      },
      "summarizer": {
        "x": 420,
        "y": 0
      },
      "summary_contract": {
        "x": 840,
        "y": 0
      },
      "illustration_prompt": {
        "x": 1260,
        "y": 0
      },
      "illustration": {
        "x": 1680,
        "y": 0
      },
      "ideas": {
        "x": 1260,
        "y": 320
      },
      "idea_prompt": {
        "x": 1680,
        "y": 360
      },
      "idea_picture": {
        "x": 2100,
        "y": 300
      },
      "illustrated_ideas": {
        "x": 2520,
        "y": 300
      },
      "render": {
        "x": 2940,
        "y": 420
      },
      "page_pdf": {
        "x": 3380,
        "y": 360
      },
      "page_image": {
        "x": 3380,
        "y": 520
      },
      "summary_output": {
        "x": 1260,
        "y": -260
      },
      "ideas_output": {
        "x": 2940,
        "y": 120
      },
      "layout_report": {
        "x": 3380,
        "y": 680
      },
      "illustration_output": {
        "x": 2100,
        "y": -220
      }
    }
  }
}
