{
  "id": "MiLAG4aMn8ed2teg",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "tags": [],
  "nodes": [
    {
      "id": "1a3cb530-5d35-464e-ac9a-9afbc2d9fa78",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -1904,
        -580
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "url"
            },
            {
              "name": "css_selector"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "dbab4f8e-a995-4be5-ac3e-8be3bce27695",
      "name": "Check Cache",
      "type": "n8n-nodes-base.code",
      "position": [
        -1680,
        -580
      ],
      "parameters": {
        "jsCode": "// Access workflow-level static data\nconst data = $getWorkflowStaticData('global');\n\n// 24 hours TTL\nconst TTL = 24 * 60 * 60 * 1000;\n\n// Check cache validity\nif (data.cachedValue && data.cachedValue[$input.first().json.url] && data.cachedValue[$input.first().json.url].timestamp && \n    (Date.now() - data.cachedValue[$input.first().json.url].timestamp) < TTL) {\n\treturn [{ json: { fromCache: true, data: data.cachedValue[$input.first().json.url].value, timestamp:  data.cachedValue[$input.first().json.url].timestamp},  }];\n}\n\n// Return null if cache is missing or expired\nreturn [{ json: { fromCache: false, data: null, timestamp: null } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "06c6c5c9-872d-4ab4-bacf-fe5d506791da",
      "name": "Write to Cache",
      "type": "n8n-nodes-base.code",
      "position": [
        -432,
        -456
      ],
      "parameters": {
        "jsCode": "var staticData = $getWorkflowStaticData('global');\n\nstaticData.cachedValue = staticData.cachedValue || {};\nstaticData.cachedValue[$('When Executed by Another Workflow').first().json.url] = {\n  value: $input.first().json.output.text,\n  timestamp: Date.now()\n};\n\n// Return null if cache is missing or expired\nreturn [staticData.cachedValue[$('When Executed by Another Workflow').first().json.url]];"
      },
      "typeVersion": 2
    },
    {
      "id": "d59cb478-8d7d-46d8-94c9-1280c5c9242e",
      "name": "Only Data",
      "type": "n8n-nodes-base.set",
      "position": [
        -432,
        -704
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "={\n  \"value\": {{ $json.data.toJsonString() }},\n  \"timestamp\": {{ $json.timestamp }}\n}"
      },
      "typeVersion": 3.4
    },
    {
      "id": "cc1b7578-3322-4a0a-8a52-a36a9a7e4aad",
      "name": "GET URL",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1232,
        -456
      ],
      "parameters": {
        "url": "={{ $('When Executed by Another Workflow').item.json.url }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "a4624e09-b7d4-4a34-a8f7-0f80f5c8f413",
      "name": "Extract HTML Content",
      "type": "n8n-nodes-base.html",
      "position": [
        -1008,
        -456
      ],
      "parameters": {
        "options": {},
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "data",
              "cssSelector": "={{ $('When Executed by Another Workflow').item.json.css_selector || \"body\" }}"
            }
          ]
        }
      },
      "typeVersion": 1.2,
      "alwaysOutputData": true
    },
    {
      "id": "fd84d54d-66a0-44b0-8e8e-625468c0a441",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -712,
        -232
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "9f4745fd-7eab-4d47-bce2-9c32a206c5c8",
      "name": "Summarization Chain",
      "type": "@n8n/n8n-nodes-langchain.chainSummarization",
      "position": [
        -784,
        -456
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 2.1
    },
    {
      "id": "257812ae-0a24-4f46-80d6-a6471647f899",
      "name": "Check Cache for Data",
      "type": "n8n-nodes-base.if",
      "position": [
        -1456,
        -580
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "fd1fb94e-edec-420d-9acb-496c40ad7b77",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.fromCache }}",
              "rightValue": "true"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "44887854-4043-41da-bad6-7ea11747065b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -832,
        -712
      ],
      "parameters": {
        "color": 3,
        "width": 320,
        "height": 624,
        "content": "## Summarization\nSummarize the selected webpage content here. This section fetches the page, extracts text from the provided CSS selector or the full body, sends it to the AI summarization chain, and stores the generated summary in cache for future requests.\n\n**Change Prompts and Model If Needed**\n"
      },
      "typeVersion": 1
    },
    {
      "id": "4bf84cc3-5056-4204-b368-2b4775136812",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2512,
        -880
      ],
      "parameters": {
        "width": 512,
        "height": 464,
        "content": "## Summerize WebPage\n\n### How it works\n\n1. The workflow is triggered by another workflow execution.\n2. It checks the cache for existing data to avoid redundant processing.\n3. If data is found, it outputs directly; otherwise, it fetches the webpage content.\n4. The content is extracted and summarized using AI.\n5. The summarized data is written to the cache for future use.\n\n### Setup steps\n\n- [ ] Ensure the necessary API credentials for the OpenAI Chat Model are available or change your model if needed.\n- [ ] Verify connection settings for HTTP requests are correctly configured\n- [ ] Configure workflow-level data caching settings\n\n### Customization\n\nConsider adjusting the cache duration or invalidation logic to optimize performance."
      },
      "typeVersion": 1
    },
    {
      "id": "36e89cfd-9d9d-4f34-961e-369ae7d4ef4e",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1960,
        -676
      ],
      "parameters": {
        "color": 7,
        "width": 656,
        "height": 256,
        "content": "## Trigger and Cache Check\n\nHandles the initial trigger and checks cache for pre-existing data."
      },
      "typeVersion": 1
    },
    {
      "id": "4013c588-edf3-4219-b62a-1b339f1de448",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1272,
        -568
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 272,
        "content": "## Data Fetch and Extraction\n\nFetches webpage content when cache misses and extracts HTML."
      },
      "typeVersion": 1
    },
    {
      "id": "0b388073-9321-42d8-bc38-63a8f8eaa5b1",
      "name": "Done",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -208,
        -580
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "8c4cf647-0942-4733-8b72-ab5caf68eced",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -472,
        -792
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 496,
        "content": "## Process and Ouput Data\n\n_If data is not cached before, cache data now._"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "0453e541-57ad-473b-86a7-d3280d12069b",
  "connections": {
    "GET URL": {
      "main": [
        [
          {
            "node": "Extract HTML Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Only Data": {
      "main": [
        [
          {
            "node": "Done",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Cache": {
      "main": [
        [
          {
            "node": "Check Cache for Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write to Cache": {
      "main": [
        [
          {
            "node": "Done",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Summarization Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Summarization Chain": {
      "main": [
        [
          {
            "node": "Write to Cache",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Cache for Data": {
      "main": [
        [
          {
            "node": "Only Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "GET URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract HTML Content": {
      "main": [
        [
          {
            "node": "Summarization Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Check Cache",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}