{
  "name": "Claude Memory API",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "claude-memory",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        200,
        300
      ],
      "id": "wh-001",
      "name": "Webhook"
    },
    {
      "parameters": {
        "jsCode": "const body = $input.first().json.body || $input.first().json;\nreturn [{ json: { action: body.action, key: body.key, value: body.value, category: body.category || 'general', tags: body.tags || [], importance: body.importance || 5, query: body.query, body: body } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        420,
        300
      ],
      "id": "pr-001",
      "name": "Parse Request"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.action }}",
                    "rightValue": "save",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "save"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.action }}",
                    "rightValue": "retrieve",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "retrieve"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.action }}",
                    "rightValue": "search",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "search"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.action }}",
                    "rightValue": "list",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "list"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.action }}",
                    "rightValue": "delete",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "delete"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        640,
        300
      ],
      "id": "sw-001",
      "name": "Switch Action"
    },
    {
      "parameters": {
        "operation": "upsert",
        "tableId": "claude_memory",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "key",
              "fieldValue": "={{ $json.key }}"
            },
            {
              "fieldId": "value",
              "fieldValue": "={{ $json.value }}"
            },
            {
              "fieldId": "category",
              "fieldValue": "={{ $json.category }}"
            },
            {
              "fieldId": "tags",
              "fieldValue": "={{ $json.tags }}"
            },
            {
              "fieldId": "importance",
              "fieldValue": "={{ $json.importance }}"
            }
          ]
        },
        "conflictType": "key"
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        900,
        60
      ],
      "id": "sv-001",
      "name": "Save Memory",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "getAll",
        "tableId": "claude_memory",
        "returnAll": false,
        "limit": 1,
        "filterType": "string",
        "filterString": "key=eq.{{ $json.key }}"
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        900,
        180
      ],
      "id": "rt-001",
      "name": "Retrieve Memory",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "getAll",
        "tableId": "claude_memory",
        "returnAll": false,
        "limit": 20,
        "filterType": "string",
        "filterString": "value=ilike.*{{ $json.query }}*"
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        900,
        300
      ],
      "id": "sr-001",
      "name": "Search Memory",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "getAll",
        "tableId": "claude_memory",
        "returnAll": false,
        "limit": 50
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        900,
        420
      ],
      "id": "ls-001",
      "name": "List Memory",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "delete",
        "tableId": "claude_memory",
        "filterType": "string",
        "filterString": "key=eq.{{ $json.key }}"
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        900,
        540
      ],
      "id": "dl-001",
      "name": "Delete Memory",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\nconst data = items.map(item => item.json);\nconst action = $('Parse Request').first().json.action;\n\nreturn [{\n  json: {\n    success: true,\n    action: action,\n    data: data.length === 1 ? data[0] : data,\n    count: data.length,\n    timestamp: new Date().toISOString()\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1140,
        300
      ],
      "id": "br-001",
      "name": "Build Response"
    },
    {
      "parameters": {
        "respondWith": "allIncomingItems",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1360,
        300
      ],
      "id": "rw-001",
      "name": "Respond to Webhook"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Parse Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Request": {
      "main": [
        [
          {
            "node": "Switch Action",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch Action": {
      "main": [
        [
          {
            "node": "Save Memory",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Retrieve Memory",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Search Memory",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "List Memory",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Delete Memory",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Memory": {
      "main": [
        [
          {
            "node": "Build Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve Memory": {
      "main": [
        [
          {
            "node": "Build Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Memory": {
      "main": [
        [
          {
            "node": "Build Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Memory": {
      "main": [
        [
          {
            "node": "Build Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Memory": {
      "main": [
        [
          {
            "node": "Build Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Response": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}